copilotApiService.ts ×12

Frontier kind: Code frontier

unlabeled · c_77fda814b587

25 tests · 20236 LOC · 84 files · introduces 0 tests · 47 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges47 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1615 ranges20236 lines · 84 files · Browse complete extent
All tests (intent)
25 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: 47 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/shared/copilotApiService.ts 47 introduced LOC · 12 ranges

Open complete file

794 throw new Error('CAPI response has no body');
795 }
797 > yield* this._readSSE(response.body);
798 }
799
1158
1159 private async *_readSSE(body: ReadableStream<Uint8Array>): AsyncGenerator<Anthropic.MessageStreamEvent> {
1160 > const reader = body.getReader(); copilotApiService.ts
1161 > const decoder = new TextDecoder();
1162 > let buffer = '';
1163 >
1164 > try {
1165 > while (true) {
1166 > const { done, value } = await reader.read();
1167 > if (done) {
1168 break;
1169 }
1171 > buffer += decoder.decode(value, { stream: true });
1172 > const lines = buffer.split('\n');
1173 > buffer = lines.pop() ?? '';
1174 >
1175 > for (const line of lines) {
1176 > const event = this._parseDataLine(line);
1177 > if (event !== undefined) {
1178 yield event;
1179 if (event.type === 'message_stop') {
1193 }
1194 }
1195 > } finally { copilotApiService.ts
1196 > // Cancel the underlying stream so the HTTP connection is released
1197 > // even when the consumer abandons the generator early (break, throw,
1198 > // abort) or the stream ended on `message_stop` with bytes still in
1199 > // flight. `releaseLock` alone leaves the body half-read.
1200 > try {
1201 > await reader.cancel();
1202 > } catch {
1203 // ignore — cancellation is best-effort cleanup
1204 }
1205 > reader.releaseLock(); copilotApiService.ts
1206 > }
1207 > }
1208
1209 /**
1212 */
1213 private _parseDataLine(line: string): Anthropic.MessageStreamEvent | undefined {
1214 > if (!line.startsWith('data: ')) { copilotApiService.ts
1215 return undefined;
1216 }
1218 > const data = line.slice('data: '.length).trim();
1219 >
1220 > let parsed: unknown;
1221 > try {
1222 > parsed = JSON.parse(data);
1223 > } catch {
1224 this._logService.warn('[CopilotApiService] Failed to parse SSE data:', data);
1225 return undefined;
1226 }
1228 > if (typeof parsed !== 'object' || parsed === null) {
1229 return undefined;
1230 }
1232 > const record = parsed as Record<string, unknown>;
1233 > const type = record.type;
1234 > if (typeof type !== 'string') {
1235 return undefined;
1236 }
1238 > if (type === 'error') {
1239 // Preserve the upstream envelope verbatim when it conforms to the
1240 // Anthropic shape (so any extra fields propagate to Phase 2's
1272
1273 return parsed as Anthropic.MessageStreamEvent;
1275
1276 // #endregion