codex-copilot-dx 0.9.39 → 0.9.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,6 +133,7 @@ function createRoutePerformance() {
133
133
  return {
134
134
  ttft: createHistogram(TTFT_EDGES_MS),
135
135
  tpot: createHistogram(TPOT_EDGES_US),
136
+ outputRate: { intervals: 0, milliseconds: 0, samples: 0 },
136
137
  requestTtft: createHistogram(TTFT_EDGES_MS),
137
138
  outputSources: { delta: 0, announcement: 0, snapshot: 0, runtime: 0 },
138
139
  preparation: Object.fromEntries(PREPARATION_STAGES.map((stage) => [stage, createHistogram(PREPARATION_EDGES_MS)])),
@@ -163,6 +164,14 @@ function routeSnapshot(route) {
163
164
  },
164
165
  ttft_ms: histogramSnapshot(route.ttft, "ms"),
165
166
  tpot_us: histogramSnapshot(route.tpot, "us"),
167
+ output_tokens_per_second: {
168
+ avg: route.outputRate.milliseconds > 0
169
+ ? Number((route.outputRate.intervals * 1000 / route.outputRate.milliseconds).toFixed(1)) : null,
170
+ samples: route.outputRate.samples,
171
+ unit: "token/s",
172
+ aggregation: "time_weighted_per_request",
173
+ estimated: true,
174
+ },
166
175
  request_ttft_ms: histogramSnapshot(route.requestTtft, "ms"),
167
176
  first_output_sources: { ...route.outputSources },
168
177
  timing_boundary: "gateway_observed",
@@ -195,6 +204,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
195
204
  const preparationMs = Object.fromEntries(PREPARATION_STAGES.map((stage) => [stage, 0]));
196
205
  let phase = "received";
197
206
  let attempts = 0;
207
+ const attemptTimings = [];
198
208
  let firstAttemptAt = null;
199
209
  let headersAt = null;
200
210
  let lastActivityAt = null;
@@ -221,15 +231,22 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
221
231
  if (finished) return;
222
232
  const time = now();
223
233
  attempts += 1;
234
+ if (attemptTimings.length === 3) attemptTimings.splice(1, 1);
235
+ attemptTimings.push({ attempt: attempts, started_ms: elapsed(time), headers_ms: null, http_status: null });
224
236
  firstAttemptAt ??= time;
225
237
  phase = "upstream_connection";
226
238
  if (streaming && upstreamStartedAt === null) upstreamStartedAt = time;
227
239
  },
228
- upstreamHeaders() {
240
+ upstreamHeaders(statusCode) {
229
241
  if (finished) return;
230
242
  headersAt = now();
231
243
  lastActivityAt = headersAt;
232
244
  phase = "upstream_response";
245
+ const attempt = attemptTimings.at(-1);
246
+ if (attempt) {
247
+ attempt.headers_ms = elapsed(headersAt);
248
+ attempt.http_status = Number.isInteger(statusCode) && statusCode >= 100 && statusCode <= 599 ? statusCode : null;
249
+ }
233
250
  },
234
251
  upstreamActivity() {
235
252
  if (finished) return;
@@ -249,6 +266,8 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
249
266
  setModel(value) {
250
267
  model = modelLabel(value);
251
268
  },
269
+ attemptCount() { return attempts; },
270
+ attemptTimings() { return attemptTimings.map(attempt => ({ ...attempt })); },
252
271
  observeContext(values) {
253
272
  if (finished || !values || typeof values !== "object") return;
254
273
  for (const key of Object.keys(context)) {
@@ -297,6 +316,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
297
316
  failed: failed || aborted || (terminalOutcome !== null && terminalOutcome !== "completed"),
298
317
  http_status: Number.isInteger(statusCode) && statusCode >= 100 && statusCode <= 599 ? statusCode : null,
299
318
  upstream_attempts: attempts,
319
+ attempts: attemptTimings.map(attempt => ({ ...attempt })),
300
320
  first_output_source: firstOutputSource,
301
321
  context: { ...context },
302
322
  timings_ms: {
@@ -321,6 +341,12 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
321
341
  observe(route.ttft, Math.max(0, firstOutputAt - upstreamStartedAt));
322
342
  if (outputTokens !== null && outputTokens >= 2) {
323
343
  observe(route.tpot, Math.max(0, ((finishedAt - firstOutputAt) * 1_000) / (outputTokens - 1)));
344
+ const milliseconds = finishedAt - firstOutputAt;
345
+ if (Number.isSafeInteger(outputTokens) && milliseconds > 0) {
346
+ route.outputRate.intervals += outputTokens - 1;
347
+ route.outputRate.milliseconds += milliseconds;
348
+ route.outputRate.samples += 1;
349
+ }
324
350
  }
325
351
  if (failed) route.errors_with_output += 1;
326
352
  else route.success_with_output += 1;
@@ -330,7 +356,7 @@ export function createStreamPerformanceMetrics({ now = () => performance.now(),
330
356
  snapshot() {
331
357
  return {
332
358
  by_route: Object.fromEntries(PERFORMANCE_ROUTES.map((name) => [name, routeSnapshot(routes[name])])),
333
- recent_requests: recentRequests.map((entry) => ({ ...entry, context: { ...entry.context }, timings_ms: { ...entry.timings_ms } })),
359
+ recent_requests: recentRequests.map((entry) => ({ ...entry, attempts: entry.attempts.map(attempt => ({ ...attempt })), context: { ...entry.context }, timings_ms: { ...entry.timings_ms } })),
334
360
  };
335
361
  },
336
362
  };
@@ -362,8 +388,8 @@ export function markUpstreamStarted(streaming = true) {
362
388
  tracker()?.upstreamStarted(streaming);
363
389
  }
364
390
 
365
- export function markUpstreamHeaders() {
366
- tracker()?.upstreamHeaders?.();
391
+ export function markUpstreamHeaders(statusCode) {
392
+ tracker()?.upstreamHeaders?.(statusCode);
367
393
  }
368
394
 
369
395
  export function markUpstreamActivity() {
@@ -386,9 +412,12 @@ export function markStreamFailure() {
386
412
  tracker()?.fail();
387
413
  }
388
414
 
389
- export function markResponseModel(model) {
415
+ export function markResponseModel(model, { requestedModel } = {}) {
390
416
  const context = currentRequestContext();
391
- if (context) context.model = model;
417
+ if (context) {
418
+ context.model = model;
419
+ if (requestedModel !== undefined) context.requestedModel = modelLabel(requestedModel);
420
+ }
392
421
  tracker()?.setModel?.(model);
393
422
  }
394
423
 
@@ -4,6 +4,7 @@ import { spawn } from "node:child_process";
4
4
  import { PassThrough, Writable } from "node:stream";
5
5
  import { Script } from "node:vm";
6
6
  import { windowsPowerShellEnvironment } from "./native-prediction-windows.mjs";
7
+ import { predictionProxyExpression } from "./prediction-pac.mjs";
7
8
 
8
9
  function failure(code) {
9
10
  return Object.assign(new Error(`Windows prediction network failed (${code}); existing company routes were preserved`), { code });
@@ -12,7 +13,7 @@ function failure(code) {
12
13
  export function companyPredictionPac(script, port) {
13
14
  if (typeof script !== "string" || Buffer.byteLength(script) > 1024 * 1024 || !Number.isInteger(port) || port < 1 || port > 65535) throw failure("proxy_pac_invalid");
14
15
  // Compile only for syntax validation; never execute a downloaded PAC in Node.
15
- const combined = `var ccdxCompanyRoute=(function(){\n${script}\n;return FindProxyForURL;})();\nfunction FindProxyForURL(url,host){var original=ccdxCompanyRoute(url,host);if(url.indexOf('https:')===0&&(host==='chatgpt.com'||host==='ab.chatgpt.com'))return 'PROXY 127.0.0.1:${port}; '+original;return original;}\n`;
16
+ const combined = `var ccdxCompanyRoute=(function(){\n${script}\n;return FindProxyForURL;})();\nfunction FindProxyForURL(url,host){var original=ccdxCompanyRoute(url,host);if(url.indexOf('https:')===0&&(host==='chatgpt.com'||host==='ab.chatgpt.com'))return ${predictionProxyExpression(port)}+'; '+original;return original;}\n`;
16
17
  try { new Script(combined); } catch { throw failure("proxy_pac_invalid"); }
17
18
  return combined;
18
19
  }