agentHostConversationContext.ts ×3

Frontier kind: Code frontier

unlabeled · c_470a5d984150

717 tests · 10224 LOC · 36 files · introduces 0 tests · 57 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
3 ranges57 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
632 ranges10224 lines · 36 files · Browse complete extent
All tests (intent)
717 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: 57 introduced LOC across 3 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/agentHostConversationContext.ts 57 introduced LOC · 3 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostConversationContext.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 { ResponsePartKind, type ResponsePart, type Turn } from './state/sessionState.js';
7 >
8 > /**
9 > * Options for {@link buildConversationContext}.
10 > */
11 > export interface IConversationContextOptions {
12 > /**
13 > * Soft upper bound, in characters, for the conversation portion of the
14 > * produced context string. When the conversation exceeds this budget its
15 > * middle is removed (marked with `...`) via {@link truncateMiddle}. The
16 > * optional {@link framing} is always preserved in full and does not count
17 > * against this budget.
18 > */
19 > readonly maxChars: number;
20 >
21 > /**
22 > * Optional framing text prepended to the conversation (e.g. a note that the
23 > * conversation was branched from an earlier chat). Always preserved in full
24 > * — only the conversation is truncated to {@link maxChars}.
25 > */
26 > readonly framing?: string;
27 > }
28 >
29 > /**
30 > * Concatenates the normal textual (markdown) response parts of a turn into a
31 > * single string. Tool calls, reasoning, content references, and other
32 > * non-markdown parts are intentionally ignored so that only the assistant's
33 > * user-facing prose is included — this keeps utility-model prompts focused and
34 > * free of large tool payloads or subagent traces.
35 > */
36 > export function renderResponseMarkdown(parts: readonly ResponsePart[]): string {
37 const segments: string[] = [];
38 for (const part of parts) {
46 return segments.join('\n\n');
47 }
49 > /**
50 > * Builds a plain-text conversation context string from the given turns by
51 > * concatenating each turn's user request and the assistant's textual
52 > * (markdown) response. Only normal text response parts are considered — tool
53 > * calls, reasoning, subagent traces, and other parts are ignored (see
54 > * {@link renderResponseMarkdown}). The conversation is middle-truncated to
55 > * {@link IConversationContextOptions.maxChars} to bound model cost; any
56 > * {@link IConversationContextOptions.framing} is prepended afterwards and is
57 > * always preserved in full.
58 > *
59 > * @returns the context string, or `undefined` when no turn carries any text
60 > * worth including.
61 > */
62 > export function buildConversationContext(turns: readonly Turn[], options: IConversationContextOptions): string | undefined {
63 const blocks: string[] = [];
64 for (const turn of turns) {
79 return `${options.framing ?? ''}${truncatedConversation}`;
80 }
82 > /**
83 > * Truncates `text` to at most `maxChars` characters by removing the middle and
84 > * inserting a `...` marker, preserving the start and end.
85 > */
86 > export function truncateMiddle(text: string, maxChars: number): string {
87 if (text.length <= maxChars) {
88 return text;