chatAttachmentContext.ts ×3

Frontier kind: Code frontier

unlabeled · c_f7433f967e44

512 tests · 10213 LOC · 36 files · introduces 0 tests · 46 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
3 ranges46 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
632 ranges10213 lines · 36 files · Browse complete extent
All tests (intent)
512 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 46 introduced LOC across 3 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/state/chatAttachmentContext.ts 46 introduced LOC · 3 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- chatAttachmentContext.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { MessageAttachmentKind, ResponsePartKind, type MessageChatAttachment, type SimpleMessageAttachment, type Turn } from './protocol/state.js';
7 >
8 > /**
9 > * Model-facing preamble that frames the resolved transcript for the SDK. It is
10 > * intentionally hard-coded English (like Claude's `<system-reminder>` text):
11 > * this string is consumed by the model, not shown in the UI, so it must not be
12 > * localized.
13 > */
14 > const CHAT_TRANSCRIPT_PREAMBLE =
15 > 'The user referenced another chat in the same session. ' +
16 > 'The transcript below is that chat up to the selected turn, provided as background context. ' +
17 > 'Treat it as reference material that may or may not be relevant to the new question.';
18 >
19 > /**
20 > * Returns the referenced chat's turns bounded through {@link endTurn}, inclusive.
21 > * Throws when {@link endTurn} is not a retained completed turn.
22 > */
23 > export function boundChatTranscriptTurns(turns: readonly Turn[], endTurn: string): readonly Turn[] {
24 const index = turns.findIndex(t => t.id === endTurn);
25 if (index < 0) {
28 return turns.slice(0, index + 1);
29 }
31 > /**
32 > * Formats bounded transcript turns into a plain-text conversation for the
33 > * model. Only user message text and assistant markdown are rendered; tool
34 > * calls, reasoning, and other parts are omitted to keep the context bounded.
35 > *
36 > * This never expands nested attachments, so a {@link MessageChatAttachment}
37 > * referenced inside the source transcript is not recursively resolved.
38 > */
39 > export function formatChatTranscript(turns: readonly Turn[]): string {
40 const blocks: string[] = [];
41 for (const turn of turns) {
54 return blocks.join('\n\n');
55 }
57 > /**
58 > * Resolves a {@link MessageChatAttachment} into an SDK-compatible
59 > * {@link SimpleMessageAttachment}: the bounded transcript rendered as the
60 > * attachment's {@link SimpleMessageAttachment.modelRepresentation}. Every
61 > * provider adapter already inlines a `Simple` attachment's model
62 > * representation, so this keeps transcript formatting in one place instead of
63 > * duplicating it per agent.
64 > *
65 > * The resolution is non-recursive: it renders {@link sourceTurns} directly and
66 > * never re-resolves chat attachments found within them.
67 > */
68 > export function resolveChatAttachment(attachment: MessageChatAttachment, sourceTurns: readonly Turn[]): SimpleMessageAttachment {
69 const bounded = boundChatTranscriptTurns(sourceTurns, attachment.endTurn);
70 const transcript = formatChatTranscript(bounded);