chatStreamStats.ts ×6

Frontier kind: Code frontier

unlabeled · c_8358fc26b292

42 tests · 9174 LOC · 40 files · introduces 0 tests · 62 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
6 ranges62 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1465 ranges9174 lines · 40 files · Browse complete extent
All tests (intent)
42 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: 62 introduced LOC across 6 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/model/chatStreamStats.ts 62 introduced LOC · 6 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- chatStreamStats.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 { ILogService } from '../../../../../platform/log/common/log.js';
7 >
8 > export interface IChatStreamStats {
9 > impliedWordLoadRate: number;
10 > lastWordCount: number;
11 > }
12 >
13 > export interface IChatStreamStatsInternal extends IChatStreamStats {
14 > totalTime: number;
15 > lastUpdateTime: number;
16 > firstMarkdownTime: number | undefined;
17 > bootstrapActive: boolean;
18 > wordCountAtBootstrapExit: number | undefined;
19 > updatesWithNewWords: number;
20 > }
21 >
22 > export interface IChatStreamUpdate {
23 > totalWordCount: number;
24 > }
25 >
26 > const MIN_BOOTSTRAP_TOTAL_TIME = 250;
27 > const LARGE_BOOTSTRAP_MIN_TOTAL_TIME = 500;
28 > const MAX_INTERVAL_TIME = 250;
29 > const LARGE_UPDATE_MAX_INTERVAL_TIME = 1000;
30 > const WORDS_FOR_LARGE_CHUNK = 10;
31 > const MIN_UPDATES_FOR_STABLE_RATE = 2;
32 >
33 > /**
34 > * Estimates the loading rate of a chat response stream so that we can try to match the rendering rate to
35 > * the rate at which text is actually produced by the model. This can only be an estimate for various reasons-
36 > * reasoning summaries don't represent real generated tokens, we don't have full visibility into tool calls,
37 > * some model providers send text in large chunks rather than a steady stream, e.g. Gemini, we don't know about
38 > * latency between agent requests, etc.
39 > *
40 > * When the first text is received, we don't know how long it actually took to generate. So we apply an assumed
41 > * minimum time, until we have received enough data to make a stable estimate. This is the "bootstrap" phase.
42 > *
43 > * Since we don't have visibility into when the model started generated tool call args, or when the client was running
44 > * a tool, we ignore long pauses. The ignore period is longer for large chunks, since those naturally take longer
45 > * to generate anyway.
46 > *
47 > * After that, the word load rate is estimated using the words received since the end of the bootstrap phase.
48 > */
49 > export class ChatStreamStatsTracker {
50 > private _data: IChatStreamStatsInternal;
51 > private _publicData: IChatStreamStats;
52 >
53 > constructor(
54 @ILogService private readonly logService: ILogService
55 ) {
67 this._publicData = { impliedWordLoadRate: 0, lastWordCount: 0 };
68 }
70 > get data(): IChatStreamStats {
71 return this._publicData;
72 }
74 > get internalData(): IChatStreamStatsInternal {
75 return this._data;
76 }
78 > update(totals: IChatStreamUpdate): IChatStreamStats | undefined {
79 const { totalWordCount: wordCount } = totals;
80 if (wordCount === this._data.lastWordCount) {
141 return this._data;
142 }
144 > private trace(message: string): void {
145 this.logService.trace(`ChatStreamStatsTracker#update: ${message}`);
146 }