buildSessionEvents.ts ×5

Frontier kind: Code frontier

unlabeled · c_97204b2cf5db

10 tests · 32751 LOC · 176 files · introduces 0 tests · 73 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
5 ranges73 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2713 ranges32751 lines · 176 files · Browse complete extent
All tests (intent)
10 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: 73 introduced LOC across 5 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/copilot/buildSessionEvents.ts 73 introduced LOC · 5 ranges

Open complete file

73 */
74 export function buildSessionEventsFromTurns(turns: readonly Turn[], options: IBuildSessionEventsOptions): SessionEvent[] {
75 > const events: SessionEvent[] = []; buildSessionEvents.ts
76 > let parentId: string | null = null;
77 >
78 > // Synthesize strictly increasing ISO timestamps so the event order on disk
79 > // is unambiguous even for turns that were originally seconds apart.
80 > let clock = (options.startTime ?? new Date()).getTime();
81 > const nextTimestamp = (): string => new Date(clock++).toISOString();
82 >
83 > const push = (event: SessionEvent): void => {
84 > events.push(event);
85 > parentId = event.id;
86 > };
87 >
88 > /** Emits the `tool.execution_start` + `tool.execution_complete` pair for a completed tool call. */
89 > const pushCompletedToolCall = (tc: ToolCallCompletedState): void => {
90 let toolArguments: Record<string, unknown> | undefined;
91 if (tc.toolInput) {
144 });
145 };
147 > push({
148 > id: generateUuid(),
149 > parentId,
150 > timestamp: nextTimestamp(),
151 > type: 'session.start',
152 > data: {
153 > sessionId: options.sessionId,
154 > copilotVersion: options.copilotVersion ?? '0.0.0',
155 > producer: MIGRATION_PRODUCER,
156 > startTime: nextTimestamp(),
157 > version: options.schemaVersion ?? DEFAULT_SESSION_EVENT_SCHEMA_VERSION,
158 > ...(options.model ? { selectedModel: options.model } : {}),
159 > ...(options.workingDirectory ? { context: { cwd: options.workingDirectory } } : {}),
160 > },
161 > });
162 >
163 > for (const turn of turns) {
164 > // Reuse the turn id as the user-message envelope id when it is already a
165 > // UUID (the runtime rejects non-UUID event ids) so the reconstructed turn
166 > // keeps the id the SDK's fork/truncate RPCs address and a caller can seed
167 > // a matching protocol turn; otherwise mint a fresh UUID.
168 > push({
169 > id: isUUID(turn.id) ? turn.id : generateUuid(),
170 > parentId,
171 > timestamp: nextTimestamp(),
172 > type: 'user.message',
173 > data: {
174 > content: turn.message.text,
175 > source: 'user',
176 > },
177 > });
178 >
179 > let markdown = '';
180 > let reasoning = '';
181 > const flushAssistantMessage = (): void => {
182 > if (!markdown && !reasoning) {
183 return;
184 }
191 content: markdown,
192 messageId: generateUuid(),
193 > ...(reasoning ? { reasoningText: reasoning } : {}), buildSessionEvents.ts
194 > ...(options.model ? { model: options.model } : {}),
195 > },
196 > });
197 > markdown = '';
198 > reasoning = '';
199 > };
200 >
201 > for (const part of turn.responseParts) {
202 if (part.kind === ResponsePartKind.Markdown) {
203 // Flush pending reasoning first: the reverse mapper emits reasoning
222 // Content refs and system notifications are not yet translated.
223 }
224 > flushAssistantMessage(); buildSessionEvents.ts
225 >
226 > // A cancelled turn reconstructs as `TurnState.Cancelled` only if the event
227 > // stream ends without a finalizing assistant message (the reverse mapper
228 > // defaults to cancelled and upgrades to complete on a final message). Emit
229 > // an explicit `abort` after the already-flushed content so the turn is
230 > // marked cancelled while keeping its text.
231 > if (turn.state === TurnState.Cancelled) {
232 push({
233 id: generateUuid(),
238 });
239 }
241 >
242 > return events;
243 > }
244
245 /** Concatenates the text of a completed tool call's textual result content blocks. */