buildSessionEvents.ts ×4

Frontier kind: Code frontier

unlabeled · c_4ecffc3280fb

181 tests · 32652 LOC · 176 files · introduces 0 tests · 90 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
4 ranges90 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2702 ranges32652 lines · 176 files · Browse complete extent
All tests (intent)
181 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: 90 introduced LOC across 4 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/copilot/buildSessionEvents.ts 90 introduced LOC · 4 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- buildSessionEvents.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 type { SessionEvent } from '@github/copilot-sdk';
7 > import { generateUuid, isUUID } from '../../../../base/common/uuid.js';
8 > import { ResponsePartKind, ToolCallStatus, ToolResultContentType, TurnState, type ToolCallCompletedState, type ToolResultContent, type ToolResultSubagentContent, type Turn } from '../../common/state/sessionState.js';
9 >
10 > /**
11 > * Default schema version stamped on the synthesized `session.start` event.
12 > *
13 > * The Copilot SDK owns the authoritative event-format schema version; this
14 > * value is only meaningful when the resulting `events.jsonl` is actually
15 > * resumed by a CLI. It is irrelevant to the reconstruction performed by
16 > * {@link mapSessionEvents} (which ignores it), so unit tests can rely on the
17 > * default. Callers that write a log for real resume SHOULD pass the version the
18 > * target CLI expects.
19 > */
20 > const DEFAULT_SESSION_EVENT_SCHEMA_VERSION = 1;
21 >
22 > /**
23 > * Producer identifier stamped on the synthesized `session.start` event so a
24 > * migrated event log is attributable to this translation path rather than a
25 > * genuine agent run.
26 > */
27 > const MIGRATION_PRODUCER = 'vscode-copilot-migration';
28 >
29 > /**
30 > * Options controlling how {@link buildSessionEventsFromTurns} synthesizes a
31 > * Copilot SDK event log from VS Code turns.
32 > */
33 > export interface IBuildSessionEventsOptions {
34 > /** The target session id (stamped on the `session.start` event). */
35 > readonly sessionId: string;
36 > /** Working directory of the session, recorded on `session.start` context. */
37 > readonly workingDirectory?: string;
38 > /** Model id to attribute the synthesized assistant messages to, if known. */
39 > readonly model?: string;
40 > /** Copilot application version string for `session.start`. Defaults to `0.0.0`. */
41 > readonly copilotVersion?: string;
42 > /** Event-format schema version for `session.start`. See {@link DEFAULT_SESSION_EVENT_SCHEMA_VERSION}. */
43 > readonly schemaVersion?: number;
44 > /** Base time for the synthesized (monotonically increasing) event timestamps. Defaults to now. */
45 > readonly startTime?: Date;
46 > }
47 >
48 > /**
49 > * Translates a sequence of VS Code {@link Turn}s into a Copilot SDK
50 > * {@link SessionEvent} log (the on-disk `events.jsonl` shape), reversing the
51 > * reconstruction performed by `mapSessionEvents`.
52 > *
53 > * The result is a valid parent-linked event chain: a leading `session.start`
54 > * followed, per turn, by a `user.message` and the turn's response emitted in
55 > * order — assistant markdown/reasoning as `assistant.message` events and each
56 > * completed tool call as a `tool.execution_start` + `tool.execution_complete`
57 > * pair (preceded by a `subagent.started` when the tool call carries sub-agent
58 > * content, so the sub-agent name/description survive a resume). Assistant text
59 > * accumulated before a tool call is flushed as its own `assistant.message` so
60 > * the reconstructed part order matches the original.
61 > *
62 > * Every event envelope id must be a UUID (the Copilot runtime rejects non-UUID
63 > * event ids). A turn whose {@link Turn.id} is already a UUID reuses it as the
64 > * `user.message` envelope id, so the reconstructed turn keeps the same id the
65 > * SDK's fork / truncate RPCs address and the caller can seed matching protocol
66 > * turns; a non-UUID id is replaced with a minted UUID.
67 > *
68 > * Only completed tool calls are translated; streaming / pending tool states and
69 > * file-edit content (which lives in the session database) are not yet emitted.
70 > * A cancelled turn ({@link TurnState.Cancelled}) emits a trailing `abort` event
71 > * so it reconstructs as cancelled. Content refs and system notifications are
72 > * skipped.
73 > */
74 > export function buildSessionEventsFromTurns(turns: readonly Turn[], options: IBuildSessionEventsOptions): SessionEvent[] {
75 const events: SessionEvent[] = [];
76 let parentId: string | null = null;
242 return events;
243 }
245 > /** Concatenates the text of a completed tool call's textual result content blocks. */
246 function extractToolResultText(content: readonly ToolResultContent[] | undefined): string {
247 if (!content) {
256 return text;
257 }
259 > /**
260 > * Serializes SDK session events into the on-disk `events.jsonl` representation:
261 > * one JSON object per line, terminated by a newline so a subsequent append
262 > * starts on a fresh line. Returns the empty string for an empty event list.
263 > */
264 > export function serializeSessionEventsToJsonl(events: readonly SessionEvent[]): string {
265 if (events.length === 0) {
266 return '';
268 return events.map(event => JSON.stringify(event)).join('\n') + '\n';
269 }
271 > /**
272 > * Convenience combining {@link buildSessionEventsFromTurns} and
273 > * {@link serializeSessionEventsToJsonl}: turns the given VS Code turns directly
274 > * into the `events.jsonl` bytes to write for the target session.
275 > */
276 > export function buildSessionEventLogFromTurns(turns: readonly Turn[], options: IBuildSessionEventsOptions): string {
277 return serializeSessionEventsToJsonl(buildSessionEventsFromTurns(turns, options));
278 }