src/vs/platform/agentHost/node/agentHostTurnTracker.ts

81 LOC · 81 covered · 0 uncovered · 14 ranges · 1049 concepts · 8 introducers · 506 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- agentSideEffects.ts ×51
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 { StopWatch } from '../../../base/common/stopwatch.js';
7 > import type { AgentHostModelTelemetryKind, AgentHostTelemetryReporter, AgentHostTurnResult, IAgentHostTurnFailure } from './agentHostTelemetryReporter.js';
8 >
9 > /** Per-turn timing state, keyed by `session:turnId`. */
10 > interface ITurnTiming {
11 > readonly stopWatch: StopWatch;
12 > readonly provider: string;
13 > readonly session: string;
14 > readonly model: string | undefined;
15 > readonly modelTelemetryKind: AgentHostModelTelemetryKind | undefined;
16 > readonly permissionLevel: string | undefined;
17 > firstProgressMs: number | undefined;
18 > }
19 >
20 > /**
21 > * Tracks per-turn timing for agent host sessions and reports a completion
22 > * event via the provided {@link AgentHostTelemetryReporter} when a turn ends.
23 > *
24 > * Lifecycle per turn:
25 > * 1. {@link turnStarted} — begins a stopwatch for the turn
26 > * 2. {@link markFirstProgress} — records elapsed time to first visible output
27 > * (only the first call per turn has an effect)
28 > * 3. {@link turnCompleted} — emits the telemetry event and clears state
29 > */
30 > export class AgentHostTurnTracker {
31 >
32 > private readonly _turnTimings = new Map<string, ITurnTiming>();
33 >
34 > constructor(private readonly _reporter: AgentHostTelemetryReporter) { }
35 >
36 > turnStarted(provider: string, session: string, turnId: string, model: string | undefined, modelTelemetryKind: AgentHostModelTelemetryKind | undefined, permissionLevel: string | undefined): void {
37 > const key = this._key(session, turnId); agentSideEffects.ts ×5
38 > this._turnTimings.set(key, {
39 > stopWatch: StopWatch.create(false),
40 > provider,
41 > session,
42 > model,
43 > modelTelemetryKind,
44 > permissionLevel,
45 > firstProgressMs: undefined,
46 > });
47 > }
49 > markFirstProgress(session: string, turnId: string): void {
50 > const timing = this._turnTimings.get(this._key(session, turnId)); agentHostTurnTracker.ts ×2
51 > if (timing && timing.firstProgressMs === undefined) {
52 > timing.firstProgressMs = timing.stopWatch.elapsed(); agentHostTurnTracker.ts ×1
53 > }
56 > turnCompleted(session: string, turnId: string, result: AgentHostTurnResult, failure?: IAgentHostTurnFailure): void {
57 > const key = this._key(session, turnId); agentHostTurnTracker.ts ×2
58 > const timing = this._turnTimings.get(key);
59 > if (!timing) {
61 > }
62 > this._turnTimings.delete(key); agentHostTelemetryReporter.ts ×3
63 >
64 > this._reporter.turnCompleted({
65 > provider: timing.provider,
66 > session: timing.session,
67 > turnId,
68 > timeToFirstProgress: timing.firstProgressMs,
69 > totalTime: timing.stopWatch.elapsed(),
70 > result,
71 > model: timing.model,
72 > modelTelemetryKind: timing.modelTelemetryKind,
73 > permissionLevel: timing.permissionLevel,
74 > failure,
75 > });
78 > private _key(session: string, turnId: string): string {
79 > return `${session}\0${turnId}`; agentHostTurnTracker.ts ×1
80 > }