dsh-github-copilot 0.4.0-alpha.83 → 0.4.0-alpha.85

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.
package/lib/index.js CHANGED
@@ -193,12 +193,12 @@ function fail$1(reason, creation) {
193
193
  function creationOf(error) {
194
194
  return ownRemoteFailure(error)?.creation ?? "uncertain";
195
195
  }
196
- function object$5(value) {
196
+ function object$6(value) {
197
197
  return typeof value === "object" && value !== null && !Array.isArray(value);
198
198
  }
199
199
  function api$1(ctx, key, methods) {
200
200
  const value = ctx.get(key);
201
- return object$5(value) && methods.every((method) => typeof value[method] === "function") ? value : void 0;
201
+ return object$6(value) && methods.every((method) => typeof value[method] === "function") ? value : void 0;
202
202
  }
203
203
  function revision(value) {
204
204
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
@@ -223,7 +223,7 @@ const ERROR_REASONS = /* @__PURE__ */ new Set([
223
223
  /** Remote errors cross bundle/realm boundaries; constructor identity is not a protocol. */
224
224
  function ownRemoteFailure(error) {
225
225
  try {
226
- if (!object$5(error) || error.isDSHRemoteError !== true || error.code !== "copilot/dual-model" || !object$5(error.details)) return void 0;
226
+ if (!object$6(error) || error.isDSHRemoteError !== true || error.code !== "copilot/dual-model" || !object$6(error.details)) return void 0;
227
227
  const reason = error.details.reason;
228
228
  if (typeof reason !== "string" || !ERROR_REASONS.has(reason)) return void 0;
229
229
  const creation = error.details.creation;
@@ -239,7 +239,7 @@ function reasonOf(error, fallback) {
239
239
  const own = ownRemoteFailure(error);
240
240
  if (own) return own.reason;
241
241
  try {
242
- if (object$5(error) && error.code === "SETTINGS_CONFLICT") return "DUAL_MODEL_REVISION_CONFLICT";
242
+ if (object$6(error) && error.code === "SETTINGS_CONFLICT") return "DUAL_MODEL_REVISION_CONFLICT";
243
243
  } catch {}
244
244
  return fallback;
245
245
  }
@@ -367,7 +367,7 @@ let GitHubCopilotDualModel = (() => {
367
367
  }, { prepend: true });
368
368
  ctx.on("system-prompt/assemble", async (_assembly, context, next) => {
369
369
  const candidate = context.scope;
370
- if (!candidate || !object$5(candidate.session) || !object$5(candidate.session.header) || !dedicatedAddress(candidate)) return next();
370
+ if (!candidate || !object$6(candidate.session) || !object$6(candidate.session.header) || !dedicatedAddress(candidate)) return next();
371
371
  const rehydrating = !this.overlays.has(candidate);
372
372
  if (rehydrating) this.restore(candidate);
373
373
  const installed = this.overlays.get(candidate);
@@ -1847,7 +1847,7 @@ function installContextEvidence(ctx) {
1847
1847
  //#endregion
1848
1848
  //#region package.json
1849
1849
  var name$1 = "dsh-github-copilot";
1850
- var version = "0.4.0-alpha.83";
1850
+ var version = "0.4.0-alpha.85";
1851
1851
  //#endregion
1852
1852
  //#region lib/types/probe.js
1853
1853
  /**
@@ -4043,19 +4043,19 @@ var TemporaryRouteConflictError = class extends Error {
4043
4043
  this.name = "TemporaryRouteConflictError";
4044
4044
  }
4045
4045
  };
4046
- function object$4(value) {
4046
+ function object$5(value) {
4047
4047
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
4048
4048
  }
4049
4049
  function profileAt(value) {
4050
- return object$4(object$4(object$4(value)?.providers)?.["github-copilot"]);
4050
+ return object$5(object$5(object$5(value)?.providers)?.["github-copilot"]);
4051
4051
  }
4052
4052
  /** Bounded comparison; never stringify or copy unknown model extras or headers. */
4053
4053
  function equalJson(a, b, depth = 0) {
4054
4054
  if (a === b) return true;
4055
4055
  if (depth > 12) return false;
4056
4056
  if (Array.isArray(a) || Array.isArray(b)) return Array.isArray(a) && Array.isArray(b) && a.length <= 512 && a.length === b.length && a.every((value, i) => equalJson(value, b[i], depth + 1));
4057
- const left = object$4(a);
4058
- const right = object$4(b);
4057
+ const left = object$5(a);
4058
+ const right = object$5(b);
4059
4059
  if (!left || !right) return false;
4060
4060
  const keys = Object.keys(left);
4061
4061
  return keys.length <= 512 && keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && equalJson(left[key], right[key], depth + 1));
@@ -4064,7 +4064,7 @@ const MAX_BACKUP = 131072;
4064
4064
  function safeModels(value) {
4065
4065
  if (!Array.isArray(value) || value.length > 512) throw new TemporaryRouteConflictError();
4066
4066
  return value.map((entry) => {
4067
- const model = object$4(entry);
4067
+ const model = object$5(entry);
4068
4068
  if (!model || typeof model.id !== "string" || !/^[a-zA-Z0-9._:/-]{1,200}$/.test(model.id)) throw new TemporaryRouteConflictError();
4069
4069
  const overlay = temporaryGitHubCopilotModel(model.id, /* @__PURE__ */ new Map());
4070
4070
  if (overlay && Object.keys(model).some((key) => key !== "id" && key !== "api")) {
@@ -4095,10 +4095,10 @@ function readBackup(value) {
4095
4095
  if (value === void 0) return void 0;
4096
4096
  if (typeof value !== "string" || value.length > MAX_BACKUP) throw new TemporaryRouteConflictError("TEMPORARY_ROUTE_INVALID_BACKUP");
4097
4097
  try {
4098
- const decoded = object$4(JSON.parse(value));
4098
+ const decoded = object$5(JSON.parse(value));
4099
4099
  if (!decoded) throw new Error();
4100
4100
  if (decoded.version === void 0 || decoded.version === 2 && decoded.sourceEpoch === void 0) throw new TemporaryRouteConflictError("TEMPORARY_ROUTE_LEGACY_CONFLICT");
4101
- if (decoded.version !== 2 || typeof decoded.providerExisted !== "boolean" || typeof decoded.sourceEpoch !== "string" || !/^[a-f0-9-]{36}$/.test(decoded.sourceEpoch) || !Number.isSafeInteger(decoded.sourceRevision) || Number(decoded.sourceRevision) < 0 || !["overlay", "restoring"].includes(String(decoded.phase)) || !object$4(decoded.preimage) || !object$4(decoded.postimage) || !object$4(decoded.ownedHeaders) || Object.keys(decoded).some((key) => ![
4101
+ if (decoded.version !== 2 || typeof decoded.providerExisted !== "boolean" || typeof decoded.sourceEpoch !== "string" || !/^[a-f0-9-]{36}$/.test(decoded.sourceEpoch) || !Number.isSafeInteger(decoded.sourceRevision) || Number(decoded.sourceRevision) < 0 || !["overlay", "restoring"].includes(String(decoded.phase)) || !object$5(decoded.preimage) || !object$5(decoded.postimage) || !object$5(decoded.ownedHeaders) || Object.keys(decoded).some((key) => ![
4102
4102
  "version",
4103
4103
  "providerExisted",
4104
4104
  "preimage",
@@ -4115,15 +4115,15 @@ function readBackup(value) {
4115
4115
  decoded.postimage,
4116
4116
  ...decoded.phase === "restoring" ? [decoded.target] : []
4117
4117
  ]) {
4118
- const record = object$4(leaf);
4118
+ const record = object$5(leaf);
4119
4119
  if (!record || !equalJson(record, leavesOf(record))) throw new Error();
4120
4120
  }
4121
- const models = object$4(decoded.postimage)?.models ?? [];
4121
+ const models = object$5(decoded.postimage)?.models ?? [];
4122
4122
  const knownHeaders = Object.assign({}, ...models.flatMap((model) => {
4123
4123
  const overlay = temporaryGitHubCopilotModelFromProfile(model);
4124
4124
  return overlay ? [overlay.headers] : [];
4125
4125
  }));
4126
- if (!Object.entries(object$4(decoded.ownedHeaders)).every(([name, header]) => knownHeaders[name] === header)) throw new Error();
4126
+ if (!Object.entries(object$5(decoded.ownedHeaders)).every(([name, header]) => knownHeaders[name] === header)) throw new Error();
4127
4127
  if (decoded.removeProfile !== void 0 && typeof decoded.removeProfile !== "boolean") throw new Error();
4128
4128
  return decoded;
4129
4129
  } catch (error) {
@@ -4149,7 +4149,7 @@ function settingsSnapshot(settings) {
4149
4149
  hasOwnedSecrets,
4150
4150
  routeRevision: route.revision,
4151
4151
  markerRevision: marker.revision,
4152
- backup: readBackup(object$4(marker.value)?.temporaryRouteBackup)
4152
+ backup: readBackup(object$5(marker.value)?.temporaryRouteBackup)
4153
4153
  };
4154
4154
  }
4155
4155
  function assertOwned(current, backup) {
@@ -4182,7 +4182,7 @@ function leafOperations(current, target) {
4182
4182
  }]);
4183
4183
  }
4184
4184
  function ownedHeaderRemoval(current, backup) {
4185
- return Object.entries(object$4(current?.headers) ?? {}).flatMap(([name, value]) => Object.entries(backup.ownedHeaders).some(([ownedName, ownedValue]) => name.toLowerCase() === ownedName.toLowerCase() && value === ownedValue) ? [{
4185
+ return Object.entries(object$5(current?.headers) ?? {}).flatMap(([name, value]) => Object.entries(backup.ownedHeaders).some(([ownedName, ownedValue]) => name.toLowerCase() === ownedName.toLowerCase() && value === ownedValue) ? [{
4186
4186
  op: "unset",
4187
4187
  path: [
4188
4188
  "providers",
@@ -4204,7 +4204,7 @@ function wholeProfileOwned(snapshot, backup) {
4204
4204
  //#endregion
4205
4205
  //#region lib/types/migration-status.js
4206
4206
  const LIMIT = 1024;
4207
- function object$3(value) {
4207
+ function object$4(value) {
4208
4208
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("Invalid evidence");
4209
4209
  return value;
4210
4210
  }
@@ -4213,7 +4213,7 @@ function text$2(value) {
4213
4213
  return value;
4214
4214
  }
4215
4215
  function selection(value, omitDefaultEffort = false) {
4216
- const item = object$3(value);
4216
+ const item = object$4(value);
4217
4217
  const provider = text$2(item.provider), model = text$2(item.model), effort = item.reasoningEffort;
4218
4218
  if (effort !== void 0) text$2(effort);
4219
4219
  return {
@@ -4228,7 +4228,7 @@ function array(value) {
4228
4228
  }
4229
4229
  function api(ctx, name, methods) {
4230
4230
  try {
4231
- const candidate = object$3(ctx.get(name));
4231
+ const candidate = object$4(ctx.get(name));
4232
4232
  return methods.every((key) => typeof candidate[key] === "function") ? candidate : void 0;
4233
4233
  } catch {
4234
4234
  return;
@@ -4298,26 +4298,26 @@ function migrationStatus(ctx) {
4298
4298
  const rows = [], ids = /* @__PURE__ */ new Set();
4299
4299
  let complete = projections !== void 0;
4300
4300
  for (const candidate of array(call(agents, "list"))) {
4301
- const agent = object$3(candidate), id = text$2(agent.id), status = agent.status;
4301
+ const agent = object$4(candidate), id = text$2(agent.id), status = agent.status;
4302
4302
  if (ids.has(id) || status !== "idle" && status !== "running") throw new Error("Invalid agent inventory");
4303
4303
  ids.add(id);
4304
- const session = object$3(agent.session);
4304
+ const session = object$4(agent.session);
4305
4305
  if (text$2(session.id) !== id) throw new Error("Invalid agent identity");
4306
4306
  const header = call(session, "requestHeader");
4307
- const request = header === void 0 ? null : selection(object$3(header).config);
4307
+ const request = header === void 0 ? null : selection(object$4(header).config);
4308
4308
  let effective = null, source = "unknown";
4309
4309
  if (projections) {
4310
4310
  const state = call(projections, "stateOf", session, "modelSelection");
4311
4311
  if (state !== void 0) {
4312
- const pending = object$3(state).pending;
4312
+ const pending = object$4(state).pending;
4313
4313
  if (pending !== null) {
4314
4314
  effective = selection(pending);
4315
4315
  source = "pending";
4316
4316
  } else if (header !== void 0) {
4317
- const defaults = object$3(header).adapterDefaults;
4318
- const defaultEffort = defaults === void 0 ? false : object$3(defaults).reasoningEffort;
4317
+ const defaults = object$4(header).adapterDefaults;
4318
+ const defaultEffort = defaults === void 0 ? false : object$4(defaults).reasoningEffort;
4319
4319
  if (defaultEffort !== void 0 && typeof defaultEffort !== "boolean") throw new Error("Invalid adapter defaults");
4320
- effective = selection(object$3(header).config, defaultEffort === true);
4320
+ effective = selection(object$4(header).config, defaultEffort === true);
4321
4321
  source = "request-header";
4322
4322
  } else if (result.complete.defaultSelection) {
4323
4323
  effective = result.defaultSelection;
@@ -4341,23 +4341,23 @@ function migrationStatus(ctx) {
4341
4341
  const descriptors = array(call(settings, "describe", { redactSecrets: true }));
4342
4342
  const found = /* @__PURE__ */ new Set();
4343
4343
  for (const value of descriptors) {
4344
- const descriptor = object$3(value);
4344
+ const descriptor = object$4(value);
4345
4345
  const ns = text$2(descriptor.ns);
4346
4346
  if (ns !== "llm-pi-ai" && ns !== "github-copilot") continue;
4347
4347
  if (found.has(ns) || !Number.isSafeInteger(descriptor.revision) || descriptor.revision < 0) throw new Error("Invalid settings evidence");
4348
4348
  found.add(ns);
4349
4349
  }
4350
4350
  if (found.size !== 2) throw new Error("Unregistered settings");
4351
- const config = object$3(call(settings, "get", "llm-pi-ai"));
4352
- const profile = (config.providers === void 0 ? void 0 : object$3(config.providers))?.[GITHUB_COPILOT_PROVIDER_ID];
4353
- if (profile !== void 0) object$3(profile);
4351
+ const config = object$4(call(settings, "get", "llm-pi-ai"));
4352
+ const profile = (config.providers === void 0 ? void 0 : object$4(config.providers))?.[GITHUB_COPILOT_PROVIDER_ID];
4353
+ if (profile !== void 0) object$4(profile);
4354
4354
  result.capabilities.settingsCas = true;
4355
4355
  result.routes.nativeConfigured = profile !== void 0;
4356
4356
  } catch {}
4357
4357
  if (llm) try {
4358
4358
  const ids = /* @__PURE__ */ new Set();
4359
4359
  for (const value of array(call(llm, "listProviders"))) {
4360
- const id = text$2(object$3(value).id);
4360
+ const id = text$2(object$4(value).id);
4361
4361
  if (ids.has(id)) throw new Error("Invalid registry evidence");
4362
4362
  ids.add(id);
4363
4363
  }
@@ -4559,7 +4559,7 @@ function modelPreferencesView(ctx, accountModels, error) {
4559
4559
  if (!Number.isSafeInteger(descriptor.revision) || descriptor.revision < 0) return unavailable("COPILOT_MODEL_SETTINGS_INVALID");
4560
4560
  let excludedModelIds;
4561
4561
  try {
4562
- const raw = object$4(descriptor.value);
4562
+ const raw = object$5(descriptor.value);
4563
4563
  if (raw === void 0) return unavailable("COPILOT_MODEL_SETTINGS_INVALID");
4564
4564
  excludedModelIds = normalizeExcludedModelIds(raw.excludedModelIds);
4565
4565
  } catch {
@@ -4676,7 +4676,7 @@ async function repairGitHubCopilotProviderProfile(ctx) {
4676
4676
  try {
4677
4677
  await settings.mutate(namespace, operations, revision);
4678
4678
  } catch (error) {
4679
- if (object$4(error)?.code === "SETTINGS_CONFLICT") throw new TemporaryRouteConflictError();
4679
+ if (object$5(error)?.code === "SETTINGS_CONFLICT") throw new TemporaryRouteConflictError();
4680
4680
  throw error;
4681
4681
  }
4682
4682
  };
@@ -5102,7 +5102,7 @@ let GitHubCopilotAuthorizationController = (() => {
5102
5102
  }], current.revision);
5103
5103
  this.modelPreferenceFailure = void 0;
5104
5104
  } catch (cause) {
5105
- const record = object$4(cause);
5105
+ const record = object$5(cause);
5106
5106
  this.modelPreferenceFailure = record?.code === "SETTINGS_CONFLICT" || cause instanceof Error && /conflict/i.test(cause.message) ? "COPILOT_MODEL_EXCLUSION_CONFLICT" : "COPILOT_MODEL_EXCLUSION_SAVE_FAILED";
5107
5107
  }
5108
5108
  return view();
@@ -5247,7 +5247,7 @@ const levels = [
5247
5247
  "xhigh",
5248
5248
  "max"
5249
5249
  ];
5250
- function object$2(value) {
5250
+ function object$3(value) {
5251
5251
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
5252
5252
  }
5253
5253
  function unavailable() {
@@ -5256,18 +5256,18 @@ function unavailable() {
5256
5256
  /** Resolve only the selected model's declared/native efforts, with the same precedence as Core. */
5257
5257
  function resolveCopilotResponsesReasoning(ctx, request, candidate) {
5258
5258
  if (request.provider !== "github-copilot" || candidate.protocol !== "openai-responses" || candidate.model !== request.model) return unavailable();
5259
- const profile = object$2(object$2(object$2(readSettingsNamespace(ctx, "llm-pi-ai"))?.providers)?.["github-copilot"]);
5259
+ const profile = object$3(object$3(object$3(readSettingsNamespace(ctx, "llm-pi-ai"))?.providers)?.["github-copilot"]);
5260
5260
  const effort = request.reasoningEffort ?? profile?.reasoning;
5261
5261
  if (effort === void 0) return void 0;
5262
5262
  const level = levels.find((value) => value === effort);
5263
5263
  if (level === void 0 || profile === void 0) return unavailable();
5264
5264
  const configured = Array.isArray(profile.models) ? profile.models : [];
5265
- const entry = configured.length > 0 ? object$2(configured.find((value) => object$2(value)?.id === request.model)) : object$2(object$2(profile.modelOverrides)?.[request.model]);
5265
+ const entry = configured.length > 0 ? object$3(configured.find((value) => object$3(value)?.id === request.model)) : object$3(object$3(profile.modelOverrides)?.[request.model]);
5266
5266
  if (configured.length > 0 && entry === void 0) return unavailable();
5267
5267
  const declared = entry?.reasoningEfforts;
5268
5268
  if (declared !== void 0) {
5269
5269
  if (declared === false) return level === "off" ? void 0 : unavailable();
5270
- const mapping = object$2(declared);
5270
+ const mapping = object$3(declared);
5271
5271
  if (mapping === void 0) return unavailable();
5272
5272
  const wire = mapping[level];
5273
5273
  if (level === "off" && (wire === null || typeof wire === "string" && wire.length > 0)) return void 0;
@@ -5539,19 +5539,212 @@ async function isCopilotInputItemScopeError(response, signal) {
5539
5539
  return !signal?.aborted && isScopeError(body);
5540
5540
  }
5541
5541
  //#endregion
5542
+ //#region lib/types/request-body-timeout-marker.js
5543
+ const REQUEST_BODY_TIMEOUT_MARKER = "COPILOT_REQUEST_BODY_TIMEOUT: Copilot returned HTTP 408 / user_request_timeout while reading the request body; this is not context-window overflow.";
5544
+ //#endregion
5545
+ //#region lib/types/request-body-evidence.js
5546
+ const REQUEST_BODY_EVIDENCE_LIMITS = Object.freeze({
5547
+ bytes: 16777216,
5548
+ values: 65536,
5549
+ tokens: 131072,
5550
+ depth: 64,
5551
+ keyCharacters: 128
5552
+ });
5553
+ function formatRequestBodyEvidence(evidence, responseHeadersMs) {
5554
+ const elapsed = responseHeadersMs === void 0 ? void 0 : Math.round(responseHeadersMs);
5555
+ const timing = responseHeadersMs !== void 0 && responseHeadersMs >= 0 && elapsed !== void 0 && Number.isSafeInteger(elapsed) ? `Fetch-to-response-headers: ${elapsed} ms (round trip, not upload duration).` : "Fetch-to-response-headers timing unavailable.";
5556
+ if (evidence.state !== "complete") return `Composition unavailable (${evidence.state}); no partial totals inferred. ${timing}`;
5557
+ return `Composition (wire UTF-8 bytes): conversation ${evidence.conversationBytes}, tool definitions ${evidence.toolSchemaBytes}, top-level system/instructions ${evidence.systemBytes}, other/framing ${evidence.otherBytes}. Within conversation (disjoint subsets): image blocks ${evidence.imageBlockBytes}, opaque replay ${evidence.opaqueReplayBytes}, remaining ${evidence.remainingConversationBytes} (text/tool history, framing and unrecognized fields). Image blocks include URLs/references, not decoded image sizes; unknown encodings stay in remaining/other. ${timing}`;
5558
+ }
5559
+ var EvidenceParseError = class extends Error {
5560
+ state;
5561
+ constructor(state) {
5562
+ super(state);
5563
+ this.state = state;
5564
+ }
5565
+ };
5566
+ function object$2(value) {
5567
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5568
+ }
5569
+ /** Diagnostic-only traversal of the original JSON spans; never reserializes or changes a request. */
5570
+ function requestBodyEvidence(body, protocol) {
5571
+ if (body === void 0) return { state: "unavailable" };
5572
+ const totalBytes = Buffer.byteLength(body, "utf8");
5573
+ if (totalBytes > REQUEST_BODY_EVIDENCE_LIMITS.bytes) return {
5574
+ state: "size-limit",
5575
+ totalBytes
5576
+ };
5577
+ let nesting = 0, tokens = 0;
5578
+ for (let index = 0; index < body.length; index++) {
5579
+ const character = body[index];
5580
+ if (character === "{" || character === "[") {
5581
+ if (++nesting > REQUEST_BODY_EVIDENCE_LIMITS.depth) return {
5582
+ state: "work-limit",
5583
+ totalBytes
5584
+ };
5585
+ tokens++;
5586
+ } else if (character === "}" || character === "]") nesting--;
5587
+ else if (character === "\"") {
5588
+ tokens++;
5589
+ while (++index < body.length) if (body[index] === "\\") index++;
5590
+ else if (body[index] === "\"") break;
5591
+ } else if (character !== " " && character !== "\n" && character !== "\r" && character !== " " && character !== ":" && character !== ",") {
5592
+ tokens++;
5593
+ while (index + 1 < body.length && !/[\s,\]}]/u.test(body[index + 1])) index++;
5594
+ }
5595
+ if (tokens > REQUEST_BODY_EVIDENCE_LIMITS.tokens) return {
5596
+ state: "work-limit",
5597
+ totalBytes
5598
+ };
5599
+ }
5600
+ let parsed;
5601
+ try {
5602
+ parsed = JSON.parse(body);
5603
+ } catch (error) {
5604
+ if (!(error instanceof SyntaxError)) throw error;
5605
+ return {
5606
+ state: "invalid-json",
5607
+ totalBytes
5608
+ };
5609
+ }
5610
+ const conversationKey = protocol === "openai-responses" ? "input" : "messages";
5611
+ const systemKey = protocol === "openai-responses" ? "instructions" : protocol === "anthropic-messages" ? "system" : void 0;
5612
+ if (!object$2(parsed) || !Array.isArray(parsed[conversationKey])) return {
5613
+ state: "unsupported-shape",
5614
+ totalBytes
5615
+ };
5616
+ let position = 0, values = 0, conversationBytes = 0, toolSchemaBytes = 0, systemBytes = 0;
5617
+ let imageBlockBytes = 0, opaqueReplayBytes = 0;
5618
+ const whitespace = () => {
5619
+ while (position < body.length && /\s/u.test(body[position])) position++;
5620
+ };
5621
+ const bytes = (start) => Buffer.byteLength(body.slice(start, position), "utf8");
5622
+ const stringEnd = () => {
5623
+ if (body[position++] !== "\"") throw new EvidenceParseError("invalid-json");
5624
+ while (position < body.length) {
5625
+ const character = body[position++];
5626
+ if (character === "\"") return;
5627
+ if (character === "\\") position++;
5628
+ }
5629
+ throw new EvidenceParseError("invalid-json");
5630
+ };
5631
+ const isImage = (value) => protocol === "anthropic-messages" ? value.type === "image" && object$2(value.source) && (value.source.type === "base64" && typeof value.source.data === "string" || value.source.type === "url" && typeof value.source.url === "string") : protocol === "openai-responses" ? value.type === "input_image" && (typeof value.image_url === "string" || typeof value.file_id === "string") : value.type === "image_url" && object$2(value.image_url) && typeof value.image_url.url === "string";
5632
+ const isOpaque = (parent, key, location) => protocol === "openai-responses" ? location === "conversation" && parent.type === "reasoning" && key === "encrypted_content" : location === "content" && protocol === "anthropic-messages" && (parent.type === "thinking" && key === "signature" || parent.type === "redacted_thinking" && key === "data");
5633
+ const visit = (value, depth, location) => {
5634
+ if (++values > REQUEST_BODY_EVIDENCE_LIMITS.values || depth > REQUEST_BODY_EVIDENCE_LIMITS.depth) throw new EvidenceParseError("work-limit");
5635
+ whitespace();
5636
+ const start = position;
5637
+ let image = 0, replay = 0;
5638
+ if (Array.isArray(value)) {
5639
+ if (body[position++] !== "[") throw new EvidenceParseError("invalid-json");
5640
+ for (let index = 0; index < value.length; index++) {
5641
+ if (index > 0) {
5642
+ whitespace();
5643
+ if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
5644
+ }
5645
+ const child = visit(value[index], depth + 1, location);
5646
+ image += child.image;
5647
+ replay += child.replay;
5648
+ }
5649
+ whitespace();
5650
+ if (body[position++] !== "]") throw new EvidenceParseError("invalid-json");
5651
+ } else if (object$2(value)) {
5652
+ if (body[position++] !== "{") throw new EvidenceParseError("invalid-json");
5653
+ const imageBlock = location === "content" && isImage(value);
5654
+ const seen = /* @__PURE__ */ new Set();
5655
+ whitespace();
5656
+ while (body[position] !== "}") {
5657
+ if (seen.size > 0) {
5658
+ if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
5659
+ whitespace();
5660
+ }
5661
+ const keyStart = position;
5662
+ stringEnd();
5663
+ if (position - keyStart > REQUEST_BODY_EVIDENCE_LIMITS.keyCharacters) throw new EvidenceParseError("work-limit");
5664
+ const key = JSON.parse(body.slice(keyStart, position));
5665
+ if (typeof key !== "string" || seen.has(key) || !Object.hasOwn(value, key)) throw new EvidenceParseError("invalid-json");
5666
+ seen.add(key);
5667
+ whitespace();
5668
+ if (body[position++] !== ":") throw new EvidenceParseError("invalid-json");
5669
+ whitespace();
5670
+ const childLocation = imageBlock ? "other" : depth === 0 && key === conversationKey ? "conversation" : key === "content" && (location === "conversation" || location === "content") && Array.isArray(value[key]) ? "content" : "other";
5671
+ const childStart = position, child = visit(value[key], depth + 1, childLocation);
5672
+ const childBytes = depth === 0 || isOpaque(value, key, location) && typeof value[key] === "string" ? bytes(childStart) : 0;
5673
+ if (depth === 0) {
5674
+ if (key === conversationKey) {
5675
+ conversationBytes = childBytes;
5676
+ imageBlockBytes = child.image;
5677
+ opaqueReplayBytes = child.replay;
5678
+ } else if ((key === "tools" || protocol === "openai-completions" && key === "functions") && Array.isArray(value[key])) toolSchemaBytes += childBytes;
5679
+ else if (key === systemKey && (typeof value[key] === "string" || Array.isArray(value[key]))) systemBytes += childBytes;
5680
+ }
5681
+ image += child.image;
5682
+ replay += isOpaque(value, key, location) && typeof value[key] === "string" ? childBytes : child.replay;
5683
+ whitespace();
5684
+ }
5685
+ position++;
5686
+ if (imageBlock) {
5687
+ image = bytes(start);
5688
+ replay = 0;
5689
+ }
5690
+ } else if (typeof value === "string") stringEnd();
5691
+ else {
5692
+ while (position < body.length && !/[\s,\]}]/u.test(body[position])) position++;
5693
+ if (position === start) throw new EvidenceParseError("invalid-json");
5694
+ }
5695
+ return {
5696
+ image,
5697
+ replay
5698
+ };
5699
+ };
5700
+ try {
5701
+ visit(parsed, 0, "root");
5702
+ whitespace();
5703
+ if (position !== body.length) return {
5704
+ state: "invalid-json",
5705
+ totalBytes
5706
+ };
5707
+ } catch (cause) {
5708
+ if (!(cause instanceof EvidenceParseError)) throw cause;
5709
+ return {
5710
+ state: cause.state,
5711
+ totalBytes
5712
+ };
5713
+ }
5714
+ const otherBytes = totalBytes - conversationBytes - toolSchemaBytes - systemBytes;
5715
+ const remainingConversationBytes = conversationBytes - imageBlockBytes - opaqueReplayBytes;
5716
+ if (otherBytes < 0 || remainingConversationBytes < 0) return {
5717
+ state: "invalid-json",
5718
+ totalBytes
5719
+ };
5720
+ return {
5721
+ state: "complete",
5722
+ totalBytes,
5723
+ conversationBytes,
5724
+ toolSchemaBytes,
5725
+ systemBytes,
5726
+ otherBytes,
5727
+ imageBlockBytes,
5728
+ opaqueReplayBytes,
5729
+ remainingConversationBytes
5730
+ };
5731
+ }
5732
+ //#endregion
5542
5733
  //#region lib/types/request-body-timeout.js
5543
5734
  const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
5544
5735
  function record$5(value) {
5545
5736
  return typeof value === "object" && value !== null && !Array.isArray(value);
5546
5737
  }
5547
5738
  /** Verified provider evidence, not guessed capabilities, token limits or network cause. */
5548
- async function requestBodyTimeoutDiagnostic(response, body, signal) {
5739
+ async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
5549
5740
  if (response.status !== 408 || signal?.aborted) return void 0;
5550
5741
  const value = await readResponseErrorJson(response, signal);
5551
- if (!record$5(value)) return void 0;
5742
+ if (signal?.aborted || !record$5(value)) return void 0;
5552
5743
  const error = Object.hasOwn(value, "error") ? value.error : value;
5553
5744
  if (!record$5(error) || error.code !== "user_request_timeout" || error.message !== observedMessage || value.code !== void 0 && value.code !== error.code || value.message !== void 0 && value.message !== error.message) return void 0;
5554
- return `COPILOT_REQUEST_BODY_TIMEOUT: Copilot returned HTTP 408 / user_request_timeout while reading the request body; this is not context-window overflow. ${body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`} Native retry policy is unchanged. If retries exhaust, explicitly compact the conversation or reduce attachments/tool output before retrying; also check network/proxy health and GitHub service status. A larger client timeout does not change this server timeout. No history was trimmed or model switched.`;
5745
+ const size = body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`;
5746
+ const composition = formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs);
5747
+ return `${REQUEST_BODY_TIMEOUT_MARKER} ${size} ${composition} Native retry policy is unchanged. If retries exhaust, use these numbers to choose an explicit attachment/image-offload budget change or native compaction for compressible history; tool definitions and opaque replay may remain. Also check network/proxy health and GitHub service status. Composition alone does not establish a cause or supplier size limit. A larger client timeout does not change this server timeout. No history was trimmed or model switched.`;
5555
5748
  }
5556
5749
  //#endregion
5557
5750
  //#region lib/types/copilot-stream-liveness.js
@@ -5897,15 +6090,20 @@ function createAccountProvider(descriptors, guard, baseURL) {
5897
6090
  guard.onRequestBodyTimeout?.(void 0);
5898
6091
  liveness?.beginRequest(typeof init?.body === "string" ? init.body : void 0);
5899
6092
  let response;
6093
+ const startedAt = performance.now();
5900
6094
  try {
5901
6095
  response = await fetch(input, init);
5902
6096
  } catch (error) {
5903
6097
  retry?.observe(void 0, 0);
5904
6098
  throw error;
5905
6099
  }
6100
+ const responseHeadersMs = performance.now() - startedAt;
5906
6101
  retry?.observe(typeof init?.body === "string" ? init.body : void 0, response.status);
5907
6102
  if (response.status === 408 && guard.onRequestBodyTimeout !== void 0) {
5908
- const diagnostic = await requestBodyTimeoutDiagnostic(response, typeof init?.body === "string" ? init.body : void 0, lease.signal);
6103
+ const diagnostic = await requestBodyTimeoutDiagnostic(response, typeof init?.body === "string" ? init.body : void 0, lease.signal, {
6104
+ protocol: entry.api,
6105
+ responseHeadersMs
6106
+ });
5909
6107
  if (!lease.signal.aborted && !options.signal?.aborted) guard.onRequestBodyTimeout(diagnostic);
5910
6108
  }
5911
6109
  if (response.status === 401) {
@@ -0,0 +1,32 @@
1
+ export type RequestBodyProtocol = 'openai-responses' | 'openai-completions' | 'anthropic-messages';
2
+ export declare const REQUEST_BODY_EVIDENCE_LIMITS: Readonly<{
3
+ bytes: number;
4
+ values: 65536;
5
+ tokens: 131072;
6
+ depth: 64;
7
+ keyCharacters: 128;
8
+ }>;
9
+ export type RequestBodyEvidence = {
10
+ readonly state: 'complete';
11
+ readonly totalBytes: number;
12
+ readonly conversationBytes: number;
13
+ readonly toolSchemaBytes: number;
14
+ readonly systemBytes: number;
15
+ readonly otherBytes: number;
16
+ /** Disjoint subsets of conversationBytes, not additional payload bytes. */
17
+ readonly imageBlockBytes: number;
18
+ readonly opaqueReplayBytes: number;
19
+ readonly remainingConversationBytes: number;
20
+ } | {
21
+ readonly state: 'unavailable' | 'size-limit' | 'work-limit' | 'invalid-json' | 'unsupported-shape';
22
+ readonly totalBytes?: number;
23
+ };
24
+ export interface RequestBodyDispatchEvidence {
25
+ readonly protocol: RequestBodyProtocol;
26
+ /** Fetch invocation to response headers, not upload duration or clone-observation time. */
27
+ readonly responseHeadersMs: number;
28
+ }
29
+ export declare function formatRequestBodyEvidence(evidence: RequestBodyEvidence, responseHeadersMs?: number): string;
30
+ /** Diagnostic-only traversal of the original JSON spans; never reserializes or changes a request. */
31
+ export declare function requestBodyEvidence(body: string | undefined, protocol: RequestBodyProtocol): RequestBodyEvidence;
32
+ //# sourceMappingURL=request-body-evidence.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const REQUEST_BODY_TIMEOUT_MARKER = "COPILOT_REQUEST_BODY_TIMEOUT: Copilot returned HTTP 408 / user_request_timeout while reading the request body; this is not context-window overflow.";
2
+ //# sourceMappingURL=request-body-timeout-marker.d.ts.map
@@ -1,3 +1,4 @@
1
+ import type { RequestBodyDispatchEvidence } from './request-body-evidence.ts';
1
2
  /** Verified provider evidence, not guessed capabilities, token limits or network cause. */
2
- export declare function requestBodyTimeoutDiagnostic(response: Response, body?: string, signal?: AbortSignal): Promise<string | undefined>;
3
+ export declare function requestBodyTimeoutDiagnostic(response: Response, body?: string, signal?: AbortSignal, dispatch?: RequestBodyDispatchEvidence): Promise<string | undefined>;
3
4
  //# sourceMappingURL=request-body-timeout.d.ts.map
@@ -1,13 +1,29 @@
1
1
  export declare const TURN_USAGE_EVIDENCE_KEY = "github-copilot-turn-usage-evidence";
2
+ export interface TimeoutUsageDetail {
3
+ readonly step?: number;
4
+ readonly seq?: number;
5
+ readonly recovered: boolean;
6
+ }
2
7
  export interface TurnUsageEvidence {
3
8
  readonly ended: boolean;
4
9
  readonly hasStart: boolean;
5
10
  readonly localPreDispatchBlocks: number;
6
11
  readonly unreportedAttempts: number;
12
+ readonly requestBodyTimeouts?: number;
13
+ readonly timeoutDetails?: readonly TimeoutUsageDetail[];
14
+ }
15
+ interface PendingRetry {
16
+ readonly index: number;
17
+ readonly step: number;
18
+ readonly seq: number;
19
+ readonly phase: 'failed' | 'scheduled' | 'started';
20
+ readonly retryId?: string;
21
+ readonly retry?: number;
7
22
  }
8
23
  interface State {
9
24
  readonly turn: number;
10
25
  readonly value: TurnUsageEvidence;
26
+ readonly pending?: PendingRetry;
11
27
  }
12
28
  interface Match {
13
29
  readonly event: unknown;
@@ -27,12 +43,15 @@ export interface TurnUsageDiagnostic {
27
43
  readonly localPreDispatchBlocks: number;
28
44
  readonly unreportedAttempts: number;
29
45
  readonly incompleteHistory: boolean;
46
+ readonly requestBodyTimeouts?: number;
47
+ readonly timeoutDetails?: readonly TimeoutUsageDetail[];
30
48
  }
31
49
  /** Native completed-tail evidence gates the notice; native totals are never replaced. */
32
50
  export declare function turnUsageDiagnostic(turn: number, tail: unknown, evidence: unknown, copilot: boolean): TurnUsageDiagnostic | undefined;
33
- /** Diagnostic event counts only, not a competing usage total or billing projection. */
51
+ /** Bounded diagnostic evidence, not a competing usage total or billing projection. */
34
52
  export declare const turnUsageEvidenceDefinition: {
35
53
  kind: string;
54
+ stateVersion: number;
36
55
  match(event: unknown): {
37
56
  id: string;
38
57
  role: "start" | "update";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-github-copilot",
3
3
  "description": "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
4
- "version": "0.4.0-alpha.83",
4
+ "version": "0.4.0-alpha.85",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/",