sessionServerTools.ts ×9

Frontier kind: Joint frontier

unlabeled · c_f2b5e10f39be

5 tests · 21889 LOC · 87 files · introduces 1 test · 60 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
9 ranges60 lines · 1 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1874 ranges21889 lines · 87 files · Browse complete extent
All tests (intent)
5 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.

1 test introduced at this concept.

Introduced code

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

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

src/vs/platform/agentHost/node/shared/sessionServerTools.ts 60 introduced LOC · 9 ranges

Open complete file

794
795 /** Truncates {@link text} to {@link max} characters, appending an ellipsis when cut. */
796 > function truncateText(text: string, max: number): { text: string; truncated: boolean } { sessionServerTools.ts
797 > const trimmed = text.trim();
798 > if (trimmed.length <= max) {
799 > return { text: trimmed, truncated: false };
800 > }
801 return { text: `${trimmed.slice(0, Math.max(0, max - 1))}…`, truncated: true };
802 }
803
804 /** Reads the tool-call parts of a turn, newest-emitted last. */
805 > function toolCallsOf(parts: readonly ResponsePart[]): ToolCallState[] { sessionServerTools.ts
806 > return parts.filter((p): p is Extract<ResponsePart, { kind: ResponsePartKind.ToolCall }> => p.kind === ResponsePartKind.ToolCall).map(p => p.toolCall);
807 > }
808
809 /** Concatenated markdown text of a turn's response, in stream order. */
810 > function assistantTextOf(parts: readonly ResponsePart[]): string { sessionServerTools.ts
811 > return parts.filter((p): p is Extract<ResponsePart, { kind: ResponsePartKind.Markdown }> => p.kind === ResponsePartKind.Markdown).map(p => p.content).join('').trim();
812 > }
813
814 /** Reads a tool call's JSON input string, which is absent while still streaming. */
826
827 /** Maps a {@link TurnState} (or the in-progress active turn) to a display string. */
828 > function describeTurnState(state: TurnState | 'inProgress'): string { sessionServerTools.ts
829 > switch (state) {
830 > case TurnState.Complete: return 'complete';
831 > case TurnState.Cancelled: return 'cancelled';
832 > case TurnState.Error: return 'error';
833 > default: return 'inProgress';
834 > }
835 > }
836
837 interface ISerializedSessionContext {
847 /** Builds the compacted, model-facing session-context payload from a snapshot. */
848 export function serializeSessionContext(session: URI, chatId: string | undefined, snapshot: IChatContextSnapshot, detail: SessionContextDetail, transcriptLimit: number): string {
849 > const caps = contextCaps[detail]; sessionServerTools.ts
850 > let truncated = false;
851 > const trunc = (text: string, max: number): string | undefined => {
852 > if (max <= 0 || !text) {
853 return undefined;
854 }
855 > const result = truncateText(text, max); sessionServerTools.ts
856 > truncated = truncated || result.truncated;
857 > return result.text || undefined;
858 > };
859 >
860 > const entries: { message: Message; parts: readonly ResponsePart[]; state: TurnState | 'inProgress' }[] =
861 > snapshot.turns.map(t => ({ message: t.message, parts: t.responseParts, state: t.state }));
862 > if (snapshot.activeTurn) {
863 entries.push({ message: snapshot.activeTurn.message, parts: snapshot.activeTurn.responseParts, state: 'inProgress' });
864 }
865 > if (entries.length > transcriptLimit) { sessionServerTools.ts
866 truncated = true;
867 }
868 > const windowStart = Math.max(0, entries.length - transcriptLimit); sessionServerTools.ts
869 > const windowed = entries.slice(windowStart);
870 >
871 > const transcript: ISerializedContextTurn[] = windowed.map((entry, index): ISerializedContextTurn => {
872 > const user = trunc(entry.message.text, caps.user);
873 > const assistant = trunc(assistantTextOf(entry.parts), caps.assistant);
874 > const toolCalls = toolCallsOf(entry.parts);
875 > let serializedToolCalls: (string | { name: string; input?: string })[] | undefined;
876 > if (detail !== 'summary' && toolCalls.length > 0) {
877 serializedToolCalls = toolCalls.map(tc => {
878 if (caps.toolInput > 0) {
883 });
884 }
885 > return { sessionServerTools.ts
886 > turn: windowStart + index + 1,
887 > state: describeTurnState(entry.state),
888 > ...(user !== undefined ? { user } : {}),
889 > ...(assistant !== undefined ? { assistant } : {}),
890 > ...(serializedToolCalls ? { toolCalls: serializedToolCalls } : {}),
891 > };
892 > });
893 >
894 > const payload: ISerializedSessionContext = {
895 > session: session.toString(),
896 > openLink: buildOpenSessionLinkUri(session, chatId),
897 > detail,
898 > transcript,
899 > hasMoreHistory: snapshot.hasMoreHistory,
900 > truncated,
901 > };
902 > return JSON.stringify(payload);
903 > }
904
905 /** Reads and serializes the context of an existing session/chat. */