dsh-github-copilot 0.4.2-alpha.4 → 0.4.2-alpha.6

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.
@@ -1,4 +1,4 @@
1
- import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-CpyhNCSg.js";
1
+ import { a as DiagnosticsPendingSchema, c as DiagnosticsViewSchema, n as DIAGNOSTICS_OPERATIONS, r as DIAGNOSTICS_REASONS, s as DiagnosticsSnapshotSchema } from "./diagnostics-types-BDIc78T4.js";
2
2
  import { z } from "zod";
3
3
  //#region lib/types/diagnostics-analysis.js
4
4
  const RETENTION_MS = 12096e5;
@@ -113,6 +113,18 @@ const AUTO_ALLOCATION_DIAGNOSTIC_RETENTION_MS = 12096e5;
113
113
  const dayMs = 864e5;
114
114
  const integer$2 = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
115
115
  const version$1 = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
116
+ const assessmentOutcome = z.enum([
117
+ "local-known",
118
+ "local-unknown",
119
+ "semantic-known",
120
+ "semantic-unknown",
121
+ "disabled",
122
+ "unavailable",
123
+ "invalid-result",
124
+ "timeout",
125
+ "failed",
126
+ "context-omitted"
127
+ ]);
116
128
  const allocationRow = z.object({
117
129
  day: integer$2.multipleOf(dayMs),
118
130
  version: version$1,
@@ -136,6 +148,7 @@ const allocationRow = z.object({
136
148
  "unknown"
137
149
  ]),
138
150
  assessmentSource: z.enum(["local", "semantic"]),
151
+ assessmentOutcome: assessmentOutcome.optional(),
139
152
  method: z.enum(["weighted-distribution", "only-candidate"]),
140
153
  fallback: z.boolean(),
141
154
  highCost: z.boolean(),
@@ -167,6 +180,7 @@ const noFitRow = z.object({
167
180
  "unknown"
168
181
  ]),
169
182
  assessmentSource: z.enum(["local", "semantic"]),
183
+ assessmentOutcome: assessmentOutcome.optional(),
170
184
  decisions: integer$2.min(1)
171
185
  }).strict();
172
186
  const AutoAllocationDiagnosticsSchema = z.object({
@@ -197,7 +211,7 @@ function emptyAutoAllocationDiagnostics() {
197
211
  restarts: 0
198
212
  };
199
213
  }
200
- /** Profile-local rolling aggregates; no per-turn, Session, prompt, or outcome records. */
214
+ /** Profile-local rolling aggregates; no per-turn, Session, prompt, or execution-outcome records. */
201
215
  var AutoAllocationDiagnosticsCollector = class {
202
216
  version;
203
217
  changed;
@@ -229,10 +243,12 @@ var AutoAllocationDiagnosticsCollector = class {
229
243
  const now = this.wall();
230
244
  this.expire(now);
231
245
  const day = Math.floor(now / dayMs) * dayMs;
246
+ const assessment = explanation.assessment;
247
+ const outcome = assessment.diagnostic ?? (assessment.source === "local" ? assessment.demand === "unknown" ? "local-unknown" : "local-known" : assessment.demand === "unknown" ? "semantic-unknown" : "semantic-known");
232
248
  this.data.observationStart = this.data.observationStart === null ? day : Math.min(this.data.observationStart, day);
233
249
  this.data.observationEnd = this.data.observationEnd === null ? day : Math.max(this.data.observationEnd, day);
234
250
  if (explanation.method === "no-fit") {
235
- const row = this.data.noFitRows.find((item) => item.day === day && item.version === this.version && item.policyVersion === "high-cost-v1" && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source);
251
+ const row = this.data.noFitRows.find((item) => item.day === day && item.version === this.version && item.policyVersion === "high-cost-v1" && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome);
236
252
  if (row) row.decisions = this.add(row.decisions, 1);
237
253
  else if (this.data.rows.length + this.data.noFitRows.length < 1024) this.data.noFitRows.push({
238
254
  day,
@@ -242,6 +258,7 @@ var AutoAllocationDiagnosticsCollector = class {
242
258
  category: explanation.selectedCategory,
243
259
  demand: explanation.assessment.demand,
244
260
  assessmentSource: explanation.assessment.source,
261
+ assessmentOutcome: outcome,
245
262
  decisions: 1
246
263
  });
247
264
  else {
@@ -261,7 +278,7 @@ var AutoAllocationDiagnosticsCollector = class {
261
278
  }
262
279
  const allocation = parsed.data;
263
280
  for (const candidate of allocation.candidates) {
264
- const row = this.data.rows.find((item) => item.day === day && item.version === this.version && item.policyVersion === allocation.policyVersion && item.modelId === candidate.modelId && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.method === explanation.method && item.fallback === explanation.fallback && item.highCost === candidate.highCost && item.previous === candidate.previous && item.weight === candidate.weight);
281
+ const row = this.data.rows.find((item) => item.day === day && item.version === this.version && item.policyVersion === allocation.policyVersion && item.modelId === candidate.modelId && item.targetCategory === explanation.targetCategory && item.category === explanation.selectedCategory && item.demand === explanation.assessment.demand && item.assessmentSource === explanation.assessment.source && item.assessmentOutcome === outcome && item.method === explanation.method && item.fallback === explanation.fallback && item.highCost === candidate.highCost && item.previous === candidate.previous && item.weight === candidate.weight);
265
282
  if (row) {
266
283
  row.opportunities = this.add(row.opportunities, 1);
267
284
  row.expectedSelections = Math.min(Number.MAX_SAFE_INTEGER, row.expectedSelections + candidate.expectedShare);
@@ -277,6 +294,7 @@ var AutoAllocationDiagnosticsCollector = class {
277
294
  assessmentSource: explanation.assessment.source,
278
295
  method: explanation.method,
279
296
  fallback: explanation.fallback,
297
+ assessmentOutcome: outcome,
280
298
  highCost: candidate.highCost,
281
299
  previous: candidate.previous,
282
300
  weight: candidate.weight,
@@ -342,7 +360,9 @@ const composition = z.discriminatedUnion("state", [z.object({
342
360
  "size-limit",
343
361
  "work-limit",
344
362
  "invalid-json",
345
- "unsupported-shape"
363
+ "unsupported-shape",
364
+ "cancelled",
365
+ "time-limit"
346
366
  ]),
347
367
  totalBytes: integer$1.optional()
348
368
  }).strict()]);
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as GITHUB_COPILOT_PREVIEW_PROVIDER_ID, i as GITHUB_COPILOT_CREDENTIAL_KEY, n as GITHUB_COPILOT_AUTO_INTELLIGENCE_MODEL_ID, o as GITHUB_COPILOT_PROVIDER_ID, r as GITHUB_COPILOT_AUTO_MODEL_ID, s as autoModelPreference, t as GITHUB_COPILOT_AUTO_EFFICIENCY_MODEL_ID } from "./copilot-identity-DRZY_d2X.js";
2
- import { S as normalizeExcludedModelIds, _ as AutoAllocationSchema, b as ModelExclusionTurns, c as DiagnosticsViewSchema, d as diagnosticsReason, f as REQUEST_DIAGNOSTICS_RETENTION_MS, g as AUTO_ALLOCATION_POLICY, h as emptyAutoAllocationDiagnostics, i as DIAGNOSTICS_RETENTION_MS, l as diagnosticsBucket, m as AutoAllocationDiagnosticsCollector, o as DiagnosticsRowSchema, p as RequestDiagnosticSchema, s as DiagnosticsSnapshotSchema, u as diagnosticsOutcome, v as allocateAutoModel, x as excludedModelSet, y as normalizeHighCostModelIds } from "./diagnostics-types-CpyhNCSg.js";
2
+ import { S as normalizeExcludedModelIds, _ as AutoAllocationSchema, b as ModelExclusionTurns, c as DiagnosticsViewSchema, d as diagnosticsReason, f as REQUEST_DIAGNOSTICS_RETENTION_MS, g as AUTO_ALLOCATION_POLICY, h as emptyAutoAllocationDiagnostics, i as DIAGNOSTICS_RETENTION_MS, l as diagnosticsBucket, m as AutoAllocationDiagnosticsCollector, o as DiagnosticsRowSchema, p as RequestDiagnosticSchema, s as DiagnosticsSnapshotSchema, u as diagnosticsOutcome, v as allocateAutoModel, x as excludedModelSet, y as normalizeHighCostModelIds } from "./diagnostics-types-BDIc78T4.js";
3
3
  import { C as providerErrorMessage, D as onSettingsNamespaceUpdated, E as readCopilotCatalog, O as readConfigValue, S as isAbortError, T as isPluginPreviewProvider, _ as sameCandidates, a as COPILOT_HOSTED_SEARCH_PROVIDER_ID, b as currentSearchSelection, c as applyRequestAuth, d as ANTHROPIC_WEB_SEARCH_TOOL_TYPE, f as GITHUB_COPILOT_CREDENTIAL_KEY$1, g as candidatesForRoute, h as WEB_SEARCH_TOOL_TYPE, i as describeSearchBackend, k as readSettingsNamespace, l as normalizeRequestAuth, m as SearchPlan, n as routeSessionSearch, o as GITHUB_COPILOT_HOSTED_SEARCH_PROVIDER_ID, p as RESPONSES_WEB_SEARCH_TOOL_TYPE, r as DescribedSearchFallbackError, s as createTraditionalSearchProvider, t as isCopilotSearchSelection, u as providerRequestHeaders, v as currentChatRoute, w as readBounded, x as abortable$1, y as currentSearchInitiator } from "./search-routing-CV2hs8as.js";
4
4
  import { a as selectCompactionReasoning, i as resolveRequestBudgetPolicy, n as assessRequestBudget, r as calculateRequestBudget, t as DEFAULT_REQUEST_BUDGET_POLICY } from "./request-budget-DLY_aRq0.js";
5
5
  import { Remote, RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
@@ -16,12 +16,12 @@ import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
16
16
  import { credentialKey, credentialRef } from "@deepseek-ai/dsh-credentials";
17
17
  import { WebError } from "@deepseek-ai/dsh-web";
18
18
  import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "@earendil-works/pi-ai/api/github-copilot-headers";
19
+ import { setImmediate } from "node:timers/promises";
19
20
  import { AsyncLocalStorage } from "node:async_hooks";
20
21
  import { channel } from "node:diagnostics_channel";
21
22
  import { constants, gzip } from "node:zlib";
22
23
  import * as dshLlm from "@deepseek-ai/dsh-llm";
23
24
  import { CONTEXT_WINDOW_EXCEEDED_CODE, LlmError, ReasoningEffortId, attributionHeaders, boundContextSummary, callConfigEquals, contentHasImage, createUserMessage, isAgentLoopRequest, resolveImageAttachmentAccess, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
24
- import { setImmediate } from "node:timers/promises";
25
25
  import { Config as Config$1, PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
26
26
  import { estimateContextTokens, estimateMessageTokens } from "@earendil-works/pi-ai/utils/estimate";
27
27
  //#region lib/types/diagnostics-collector.js
@@ -59,6 +59,7 @@ var DiagnosticsCollector = class {
59
59
  autoAllocationEnabled = false;
60
60
  requestEnabled = false;
61
61
  requestHandles = /* @__PURE__ */ new Set();
62
+ requestGeneration = 0;
62
63
  lastWall = 0;
63
64
  autoAllocation;
64
65
  constructor(version, layer, changed = () => {}, wall = Date.now, mono = () => performance.now()) {
@@ -112,6 +113,7 @@ var DiagnosticsCollector = class {
112
113
  if (!Number.isSafeInteger(epoch)) throw new Error("COPILOT_DIAGNOSTICS_EPOCH_LIMIT");
113
114
  this.live.clear();
114
115
  this.requestHandles.clear();
116
+ this.requestGeneration++;
115
117
  this.autoAllocation.clear();
116
118
  this.data = {
117
119
  ...emptyDiagnostics(),
@@ -242,6 +244,7 @@ var DiagnosticsCollector = class {
242
244
  this.setRequestEnabled(false);
243
245
  }
244
246
  setRequestEnabled(enabled) {
247
+ if (this.requestEnabled !== enabled) this.requestGeneration++;
245
248
  if (this.requestEnabled && !enabled) for (const handle of this.requestHandles) handle.finish("interrupted", "unknown");
246
249
  this.requestEnabled = enabled;
247
250
  }
@@ -258,6 +261,8 @@ var DiagnosticsCollector = class {
258
261
  return;
259
262
  }
260
263
  const startedAt = this.wall(), startedMono = this.mono();
264
+ const generation = this.requestGeneration;
265
+ let retainedRow;
261
266
  const base = {
262
267
  ...start,
263
268
  version: this.version,
@@ -266,6 +271,32 @@ var DiagnosticsCollector = class {
266
271
  };
267
272
  let headers = {};
268
273
  const handle = {
274
+ isCurrent: () => this.requestEnabled && this.requestGeneration === generation && (this.requestHandles.has(handle) || retainedRow !== void 0 && retainedRow.startedAt > this.wall() - 864e5 && this.data.requests?.rows.includes(retainedRow) === true),
275
+ composition: (evidence) => {
276
+ if (!handle.isCurrent?.()) return;
277
+ const composition = RequestDiagnosticSchema.shape.composition.parse(evidence);
278
+ if (this.requestHandles.has(handle)) {
279
+ base.composition = composition;
280
+ return;
281
+ }
282
+ const current = this.data.requests;
283
+ if (!current || !retainedRow) return;
284
+ const next = {
285
+ ...retainedRow,
286
+ composition
287
+ };
288
+ const candidate = {
289
+ ...this.data,
290
+ requests: {
291
+ ...current,
292
+ rows: current.rows.map((row) => row === retainedRow ? next : row)
293
+ }
294
+ };
295
+ if (!DiagnosticsSnapshotSchema.safeParse(candidate).success) throw new Error("COPILOT_DIAGNOSTICS_CAPACITY");
296
+ this.data = candidate;
297
+ retainedRow = next;
298
+ this.changed();
299
+ },
269
300
  headers: (httpStatus, ms, upload) => {
270
301
  if (!this.requestHandles.has(handle)) return;
271
302
  headers = {
@@ -306,8 +337,10 @@ var DiagnosticsCollector = class {
306
337
  evicted: Math.min(Number.MAX_SAFE_INTEGER, current.evicted + evicted)
307
338
  }
308
339
  };
309
- if (DiagnosticsSnapshotSchema.safeParse(candidate).success) this.data = candidate;
310
- else current.dropped = Math.min(Number.MAX_SAFE_INTEGER, current.dropped + 1);
340
+ if (DiagnosticsSnapshotSchema.safeParse(candidate).success) {
341
+ this.data = candidate;
342
+ retainedRow = rows.includes(parsed.data) ? parsed.data : void 0;
343
+ } else current.dropped = Math.min(Number.MAX_SAFE_INTEGER, current.dropped + 1);
311
344
  this.changed();
312
345
  }
313
346
  };
@@ -460,7 +493,7 @@ const result$1 = strictRemoteCodec("dsh-github-copilot#DiagnosticsView", Diagnos
460
493
  var package_default = {
461
494
  name: "dsh-github-copilot",
462
495
  description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
463
- version: "0.4.2-alpha.4",
496
+ version: "0.4.2-alpha.6",
464
497
  releaseNotes: "CHANGELOG.md",
465
498
  publishConfig: {
466
499
  "access": "public",
@@ -3596,6 +3629,257 @@ async function isCopilotInputItemScopeError(response, signal) {
3596
3629
  //#region lib/types/request-body-timeout-marker.js
3597
3630
  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.";
3598
3631
  //#endregion
3632
+ //#region lib/types/request-body-composition.js
3633
+ const REQUEST_BODY_COMPOSITION_LIMITS = Object.freeze({
3634
+ ...REQUEST_BODY_EVIDENCE_LIMITS,
3635
+ bytes: 33554432,
3636
+ sliceCharacters: 65536,
3637
+ elapsedMs: 2e3,
3638
+ concurrent: 4
3639
+ });
3640
+ var ScanError = class extends Error {
3641
+ state;
3642
+ constructor(state) {
3643
+ super(state);
3644
+ this.state = state;
3645
+ }
3646
+ };
3647
+ let activeScans = 0;
3648
+ /** Only bounded keys/discriminators are decoded; payload values never form an object graph. */
3649
+ async function requestBodyComposition(payload, protocol, options = {}) {
3650
+ if (payload === void 0) return { state: "unavailable" };
3651
+ const body = payload;
3652
+ const totalBytes = Buffer.byteLength(body, "utf8");
3653
+ if (totalBytes > REQUEST_BODY_COMPOSITION_LIMITS.bytes) return {
3654
+ state: "size-limit",
3655
+ totalBytes
3656
+ };
3657
+ if (activeScans >= REQUEST_BODY_COMPOSITION_LIMITS.concurrent) return {
3658
+ state: "work-limit",
3659
+ totalBytes
3660
+ };
3661
+ activeScans++;
3662
+ const startedAt = performance.now();
3663
+ let position = 0, nextYield = 0, values = 0, tokens = 0;
3664
+ let conversationBytes = 0, toolSchemaBytes = 0, systemBytes = 0, imageBlockBytes = 0, opaqueReplayBytes = 0;
3665
+ let conversationArray = false;
3666
+ const conversationKey = protocol === "openai-responses" ? "input" : "messages";
3667
+ const systemKey = protocol === "openai-responses" ? "instructions" : protocol === "anthropic-messages" ? "system" : void 0;
3668
+ const check = () => {
3669
+ if (options.signal?.aborted || options.isCurrent?.() === false) throw new ScanError("cancelled");
3670
+ if (performance.now() - startedAt >= REQUEST_BODY_COMPOSITION_LIMITS.elapsedMs) throw new ScanError("time-limit");
3671
+ };
3672
+ function* checkpoint() {
3673
+ if (position >= nextYield) {
3674
+ nextYield = position + REQUEST_BODY_COMPOSITION_LIMITS.sliceCharacters;
3675
+ yield;
3676
+ check();
3677
+ }
3678
+ }
3679
+ const bytes = (span) => Buffer.byteLength(body.slice(span.start, span.end), "utf8");
3680
+ const blank = (code) => code === 32 || code === 9 || code === 10 || code === 13;
3681
+ function* whitespace() {
3682
+ while (blank(body.charCodeAt(position))) {
3683
+ position++;
3684
+ if (position >= nextYield) yield* checkpoint();
3685
+ }
3686
+ }
3687
+ function* string(decode, key = false) {
3688
+ if (++tokens > REQUEST_BODY_COMPOSITION_LIMITS.tokens) throw new ScanError("work-limit");
3689
+ const start = position++;
3690
+ while (position < body.length) {
3691
+ if (position >= nextYield) yield* checkpoint();
3692
+ const code = body.charCodeAt(position++);
3693
+ if (code === 34) {
3694
+ if (key && position - start > REQUEST_BODY_COMPOSITION_LIMITS.keyCharacters) throw new ScanError("work-limit");
3695
+ const span = {
3696
+ kind: "string",
3697
+ start,
3698
+ end: position,
3699
+ image: 0,
3700
+ replay: 0
3701
+ };
3702
+ if (decode && position - start <= REQUEST_BODY_COMPOSITION_LIMITS.keyCharacters) span.text = JSON.parse(body.slice(start, position));
3703
+ return span;
3704
+ }
3705
+ if (code < 32) throw new ScanError("invalid-json");
3706
+ if (code === 92) {
3707
+ const escaped = body[position++];
3708
+ if (escaped === "u") {
3709
+ if (!/^[a-fA-F0-9]{4}$/.test(body.slice(position, position + 4))) throw new ScanError("invalid-json");
3710
+ position += 4;
3711
+ } else if (escaped === void 0 || !"\"\\/bfnrt".includes(escaped)) throw new ScanError("invalid-json");
3712
+ }
3713
+ if (key && position - start > REQUEST_BODY_COMPOSITION_LIMITS.keyCharacters) throw new ScanError("work-limit");
3714
+ }
3715
+ throw new ScanError("invalid-json");
3716
+ }
3717
+ function* visit(depth, location, decode = false) {
3718
+ yield* checkpoint();
3719
+ if (++values > REQUEST_BODY_COMPOSITION_LIMITS.values || ++tokens > REQUEST_BODY_COMPOSITION_LIMITS.tokens || depth > REQUEST_BODY_COMPOSITION_LIMITS.depth) throw new ScanError("work-limit");
3720
+ yield* whitespace();
3721
+ const start = position, character = body[position];
3722
+ if (character === "\"") return yield* string(decode);
3723
+ if (character === "[") {
3724
+ position++;
3725
+ const result = {
3726
+ kind: "array",
3727
+ start,
3728
+ end: 0,
3729
+ image: 0,
3730
+ replay: 0
3731
+ };
3732
+ yield* whitespace();
3733
+ if (body[position] !== "]") while (true) {
3734
+ const child = yield* visit(depth + 1, location);
3735
+ result.image += child.image;
3736
+ result.replay += child.replay;
3737
+ yield* whitespace();
3738
+ if (body[position] === "]") break;
3739
+ if (body[position++] !== ",") throw new ScanError("invalid-json");
3740
+ }
3741
+ position++;
3742
+ result.end = position;
3743
+ return result;
3744
+ }
3745
+ if (character === "{") {
3746
+ position++;
3747
+ const result = {
3748
+ kind: "object",
3749
+ start,
3750
+ end: 0,
3751
+ image: 0,
3752
+ replay: 0,
3753
+ strings: /* @__PURE__ */ new Set()
3754
+ };
3755
+ const seen = /* @__PURE__ */ new Set();
3756
+ let source, imageUrl, output;
3757
+ let encrypted = 0, signature = 0, redacted = 0;
3758
+ yield* whitespace();
3759
+ if (body[position] !== "}") while (true) {
3760
+ if (body[position] !== "\"") throw new ScanError("invalid-json");
3761
+ const key = (yield* string(true, true)).text;
3762
+ if (seen.has(key)) throw new ScanError("invalid-json");
3763
+ seen.add(key);
3764
+ yield* whitespace();
3765
+ if (body[position++] !== ":") throw new ScanError("invalid-json");
3766
+ const content = (location === "conversation" || location === "content") && key === "content";
3767
+ const possibleOutput = protocol === "openai-responses" && location === "conversation" && key === "output";
3768
+ const child = yield* visit(depth + 1, depth === 0 && key === conversationKey ? "conversation" : content || possibleOutput ? "content" : "other", key === "type");
3769
+ if (key === "type") result.type = child.text;
3770
+ if (child.kind === "string" && [
3771
+ "data",
3772
+ "url",
3773
+ "image_url",
3774
+ "file_id"
3775
+ ].includes(key)) result.strings.add(key);
3776
+ if (key === "source") source = child;
3777
+ if (key === "image_url") imageUrl = child;
3778
+ if (content && child.kind === "array") {
3779
+ result.image += child.image;
3780
+ result.replay += child.replay;
3781
+ }
3782
+ if (possibleOutput && child.kind === "array") output = child;
3783
+ if (child.kind === "string") {
3784
+ if (location === "conversation" && key === "encrypted_content") encrypted = bytes(child);
3785
+ if (location === "content" && key === "signature") signature = bytes(child);
3786
+ if (location === "content" && key === "data") redacted = bytes(child);
3787
+ }
3788
+ if (depth === 0) {
3789
+ if (key === conversationKey) {
3790
+ conversationArray = child.kind === "array";
3791
+ if (conversationArray) {
3792
+ conversationBytes = bytes(child);
3793
+ imageBlockBytes = child.image;
3794
+ opaqueReplayBytes = child.replay;
3795
+ }
3796
+ } else if (child.kind === "array" && (key === "tools" || protocol === "openai-completions" && key === "functions")) toolSchemaBytes += bytes(child);
3797
+ else if (key === systemKey && (child.kind === "string" || child.kind === "array")) systemBytes += bytes(child);
3798
+ }
3799
+ yield* whitespace();
3800
+ if (body[position] === "}") break;
3801
+ if (body[position++] !== ",") throw new ScanError("invalid-json");
3802
+ yield* whitespace();
3803
+ }
3804
+ position++;
3805
+ result.end = position;
3806
+ if (output && result.type === "function_call_output") {
3807
+ result.image += output.image;
3808
+ result.replay += output.replay;
3809
+ }
3810
+ if (location === "content" && (protocol === "openai-responses" ? result.type === "input_image" && (result.strings.has("image_url") || result.strings.has("file_id")) : protocol === "openai-completions" ? result.type === "image_url" && imageUrl?.strings?.has("url") : result.type === "image" && source?.kind === "object" && (source.type === "base64" && source.strings?.has("data") || source.type === "url" && source.strings?.has("url")))) {
3811
+ result.image = bytes(result);
3812
+ result.replay = 0;
3813
+ } else if (protocol === "openai-responses" && location === "conversation" && result.type === "reasoning") result.replay += encrypted;
3814
+ else if (protocol === "anthropic-messages" && location === "content") {
3815
+ if (result.type === "thinking") result.replay += signature;
3816
+ if (result.type === "redacted_thinking") result.replay += redacted;
3817
+ }
3818
+ return result;
3819
+ }
3820
+ const literal = [
3821
+ "true",
3822
+ "false",
3823
+ "null"
3824
+ ].find((value) => body.startsWith(value, position));
3825
+ if (literal) position += literal.length;
3826
+ else {
3827
+ const numberStart = position;
3828
+ while (position < body.length && /[0-9eE+.-]/.test(body[position])) if (++position - numberStart > 128) throw new ScanError("work-limit");
3829
+ if (!/^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/.test(body.slice(numberStart, position))) throw new ScanError("invalid-json");
3830
+ }
3831
+ return {
3832
+ kind: "scalar",
3833
+ start,
3834
+ end: position,
3835
+ image: 0,
3836
+ replay: 0
3837
+ };
3838
+ }
3839
+ function* scan() {
3840
+ const root = yield* visit(0, "root");
3841
+ yield* whitespace();
3842
+ if (position !== body.length) throw new ScanError("invalid-json");
3843
+ if (root.kind !== "object" || !conversationArray) return {
3844
+ state: "unsupported-shape",
3845
+ totalBytes
3846
+ };
3847
+ const otherBytes = totalBytes - conversationBytes - toolSchemaBytes - systemBytes;
3848
+ const remainingConversationBytes = conversationBytes - imageBlockBytes - opaqueReplayBytes;
3849
+ if (otherBytes < 0 || remainingConversationBytes < 0) throw new ScanError("invalid-json");
3850
+ return {
3851
+ state: "complete",
3852
+ totalBytes,
3853
+ conversationBytes,
3854
+ toolSchemaBytes,
3855
+ systemBytes,
3856
+ otherBytes,
3857
+ imageBlockBytes,
3858
+ opaqueReplayBytes,
3859
+ remainingConversationBytes
3860
+ };
3861
+ }
3862
+ try {
3863
+ const scanner = scan();
3864
+ while (true) {
3865
+ const next = scanner.next();
3866
+ if (next.done) {
3867
+ check();
3868
+ return next.value;
3869
+ }
3870
+ await setImmediate();
3871
+ }
3872
+ } catch (error) {
3873
+ if (!(error instanceof ScanError)) throw error;
3874
+ return {
3875
+ state: error.state,
3876
+ totalBytes
3877
+ };
3878
+ } finally {
3879
+ activeScans--;
3880
+ }
3881
+ }
3882
+ //#endregion
3599
3883
  //#region lib/types/request-upload-evidence.js
3600
3884
  function object$6(value) {
3601
3885
  return typeof value === "object" && value !== null;
@@ -3710,7 +3994,9 @@ async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
3710
3994
  const compression = dispatch?.compression;
3711
3995
  const encoding = compression?.encoding === "gzip" ? ` Encoded body: ${compression.wireBytes} gzip bytes (prepared HTTP body, excluding transport framing; not confirmed delivered bytes). Lossless content encoding does not reduce context tokens or prove remote receipt.` : compression !== void 0 && compression.reason !== "disabled" ? ` Request compression not applied: ${compression.reason}; original request retained.` : "";
3712
3996
  const size = body === void 0 ? "Request body size unavailable." : `Request body${compression?.encoding === "gzip" ? " (original JSON)" : ""}: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`;
3713
- const composition = formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs, compression);
3997
+ const evidence = dispatch === void 0 ? { state: "unavailable" } : dispatch.composition !== void 0 ? await dispatch.composition : body !== void 0 && Buffer.byteLength(body, "utf8") > REQUEST_BODY_EVIDENCE_LIMITS.bytes ? await requestBodyComposition(body, dispatch.protocol, { signal }) : requestBodyEvidence(body, dispatch.protocol);
3998
+ if (signal?.aborted) return void 0;
3999
+ const composition = formatRequestBodyEvidence(evidence, dispatch?.responseHeadersMs, compression);
3714
4000
  const upload = formatRequestUploadEvidence(dispatch?.upload);
3715
4001
  return `${REQUEST_BODY_TIMEOUT_MARKER} ${size}${encoding} ${composition} ${upload} 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.`;
3716
4002
  }
@@ -4234,10 +4520,25 @@ function createAccountProvider(descriptors, guard, baseURL) {
4234
4520
  });
4235
4521
  });
4236
4522
  let response;
4523
+ let composition;
4237
4524
  const upload = guard.onRequestBodyTimeout === void 0 && requestDiagnostic === void 0 ? void 0 : createRequestUploadObserver();
4238
4525
  const startedAt = performance.now();
4239
4526
  try {
4240
- response = await (upload === void 0 ? fetch(dispatchInput, dispatchInit) : upload.run(() => fetch(dispatchInput, dispatchInit)));
4527
+ const fetching = upload === void 0 ? fetch(dispatchInput, dispatchInit) : upload.run(() => fetch(dispatchInput, dispatchInit));
4528
+ const handle = requestDiagnostic;
4529
+ if (handle?.composition && originalBody !== void 0 && Buffer.byteLength(originalBody, "utf8") > REQUEST_BODY_EVIDENCE_LIMITS.bytes) {
4530
+ composition = requestBodyComposition(originalBody, entry.api, {
4531
+ signal: options.signal,
4532
+ isCurrent: handle.isCurrent
4533
+ }).catch(() => {
4534
+ observeDiagnostics(() => {
4535
+ throw new Error("COPILOT_REQUEST_COMPOSITION_FAILED");
4536
+ });
4537
+ return { state: "unavailable" };
4538
+ });
4539
+ composition.then((evidence) => observeDiagnostics(() => handle.composition?.(evidence)));
4540
+ }
4541
+ response = await fetching;
4241
4542
  } catch (error) {
4242
4543
  observeDiagnostics(() => requestDiagnostic?.headers(void 0, void 0, upload?.snapshot()));
4243
4544
  observeDiagnostics(() => requestDiagnostic?.finish(diagnosticAborted() ? "cancelled" : "transport-error", abortReason()));
@@ -4254,6 +4555,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
4254
4555
  const diagnostic = await requestBodyTimeoutDiagnostic(response, originalBody, lease.signal, {
4255
4556
  protocol: entry.api,
4256
4557
  responseHeadersMs,
4558
+ ...composition === void 0 ? {} : { composition },
4257
4559
  ...upload === void 0 ? {} : { upload: upload.snapshot() },
4258
4560
  ...compression === void 0 ? {} : { compression }
4259
4561
  });
@@ -1,5 +1,5 @@
1
1
  import "./copilot-identity-DRZY_d2X.js";
2
- import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-CpyhNCSg.js";
2
+ import { d as diagnosticsReason, u as diagnosticsOutcome } from "./diagnostics-types-BDIc78T4.js";
3
3
  import { i as resolveRequestBudgetPolicy, r as calculateRequestBudget } from "./request-budget-DLY_aRq0.js";
4
4
  import z from "@deepseek-ai/schemastery";
5
5
  import { LlmError, createUserMessage } from "@deepseek-ai/dsh-llm";
package/lib/remote.js CHANGED
@@ -766,6 +766,18 @@ const AUTO_ALLOCATION_DIAGNOSTIC_MAX_ROWS = 1024;
766
766
  const dayMs = 864e5;
767
767
  const integer$2 = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
768
768
  const version$1 = z.string().max(64).regex(/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/);
769
+ const assessmentOutcome = z.enum([
770
+ "local-known",
771
+ "local-unknown",
772
+ "semantic-known",
773
+ "semantic-unknown",
774
+ "disabled",
775
+ "unavailable",
776
+ "invalid-result",
777
+ "timeout",
778
+ "failed",
779
+ "context-omitted"
780
+ ]);
769
781
  const allocationRow = z.object({
770
782
  day: integer$2.multipleOf(dayMs),
771
783
  version: version$1,
@@ -789,6 +801,7 @@ const allocationRow = z.object({
789
801
  "unknown"
790
802
  ]),
791
803
  assessmentSource: z.enum(["local", "semantic"]),
804
+ assessmentOutcome: assessmentOutcome.optional(),
792
805
  method: z.enum(["weighted-distribution", "only-candidate"]),
793
806
  fallback: z.boolean(),
794
807
  highCost: z.boolean(),
@@ -820,6 +833,7 @@ const noFitRow = z.object({
820
833
  "unknown"
821
834
  ]),
822
835
  assessmentSource: z.enum(["local", "semantic"]),
836
+ assessmentOutcome: assessmentOutcome.optional(),
823
837
  decisions: integer$2.min(1)
824
838
  }).strict();
825
839
  const AutoAllocationDiagnosticsSchema = z.object({
@@ -854,7 +868,9 @@ const composition = z.discriminatedUnion("state", [z.object({
854
868
  "size-limit",
855
869
  "work-limit",
856
870
  "invalid-json",
857
- "unsupported-shape"
871
+ "unsupported-shape",
872
+ "cancelled",
873
+ "time-limit"
858
874
  ]),
859
875
  totalBytes: integer$1.optional()
860
876
  }).strict()]);
@@ -33,6 +33,18 @@ export declare const AutoAllocationDiagnosticsSchema: z.ZodObject<{
33
33
  local: "local";
34
34
  semantic: "semantic";
35
35
  }>;
36
+ assessmentOutcome: z.ZodOptional<z.ZodEnum<{
37
+ disabled: "disabled";
38
+ unavailable: "unavailable";
39
+ "context-omitted": "context-omitted";
40
+ "invalid-result": "invalid-result";
41
+ timeout: "timeout";
42
+ failed: "failed";
43
+ "local-known": "local-known";
44
+ "local-unknown": "local-unknown";
45
+ "semantic-known": "semantic-known";
46
+ "semantic-unknown": "semantic-unknown";
47
+ }>>;
36
48
  method: z.ZodEnum<{
37
49
  "weighted-distribution": "weighted-distribution";
38
50
  "only-candidate": "only-candidate";
@@ -70,6 +82,18 @@ export declare const AutoAllocationDiagnosticsSchema: z.ZodObject<{
70
82
  local: "local";
71
83
  semantic: "semantic";
72
84
  }>;
85
+ assessmentOutcome: z.ZodOptional<z.ZodEnum<{
86
+ disabled: "disabled";
87
+ unavailable: "unavailable";
88
+ "context-omitted": "context-omitted";
89
+ "invalid-result": "invalid-result";
90
+ timeout: "timeout";
91
+ failed: "failed";
92
+ "local-known": "local-known";
93
+ "local-unknown": "local-unknown";
94
+ "semantic-known": "semantic-known";
95
+ "semantic-unknown": "semantic-unknown";
96
+ }>>;
73
97
  decisions: z.ZodNumber;
74
98
  }, z.core.$strict>>;
75
99
  observationStart: z.ZodNullable<z.ZodNumber>;
@@ -83,7 +107,7 @@ export declare const AutoAllocationDiagnosticsSchema: z.ZodObject<{
83
107
  }, z.core.$strict>;
84
108
  export type AutoAllocationDiagnostics = z.infer<typeof AutoAllocationDiagnosticsSchema>;
85
109
  export declare function emptyAutoAllocationDiagnostics(): AutoAllocationDiagnostics;
86
- /** Profile-local rolling aggregates; no per-turn, Session, prompt, or outcome records. */
110
+ /** Profile-local rolling aggregates; no per-turn, Session, prompt, or execution-outcome records. */
87
111
  export declare class AutoAllocationDiagnosticsCollector {
88
112
  private readonly version;
89
113
  private readonly changed;
@@ -19,6 +19,7 @@ export declare class DiagnosticsCollector {
19
19
  private autoAllocationEnabled;
20
20
  private requestEnabled;
21
21
  private readonly requestHandles;
22
+ private requestGeneration;
22
23
  private lastWall;
23
24
  private readonly autoAllocation;
24
25
  constructor(version: string, layer: 'client' | 'host', changed?: () => void, wall?: () => number, mono?: () => number);
@@ -57,6 +57,7 @@ export declare const diagnosticsDomain: {
57
57
  opportunities: number;
58
58
  expectedSelections: number;
59
59
  selections: number;
60
+ assessmentOutcome?: "disabled" | "unavailable" | "context-omitted" | "invalid-result" | "timeout" | "failed" | "local-known" | "local-unknown" | "semantic-known" | "semantic-unknown" | undefined;
60
61
  }[];
61
62
  noFitRows: {
62
63
  day: number;
@@ -67,6 +68,7 @@ export declare const diagnosticsDomain: {
67
68
  demand: "unknown" | "simple" | "routine" | "complex";
68
69
  assessmentSource: "local" | "semantic";
69
70
  decisions: number;
71
+ assessmentOutcome?: "disabled" | "unavailable" | "context-omitted" | "invalid-result" | "timeout" | "failed" | "local-known" | "local-unknown" | "semantic-known" | "semantic-unknown" | undefined;
70
72
  }[];
71
73
  observationStart: number | null;
72
74
  observationEnd: number | null;
@@ -97,11 +99,11 @@ export declare const diagnosticsDomain: {
97
99
  opaqueReplayBytes: number;
98
100
  remainingConversationBytes: number;
99
101
  } | {
100
- state: "unavailable" | "work-limit" | "size-limit" | "invalid-json" | "unsupported-shape";
102
+ state: "unavailable" | "work-limit" | "size-limit" | "invalid-json" | "unsupported-shape" | "cancelled" | "time-limit";
101
103
  totalBytes?: number | undefined;
102
104
  };
103
105
  encoding: "unknown" | "identity" | "gzip";
104
- outcome: "http-error" | "transport-error" | "stream-done" | "stream-error" | "cancelled" | "interrupted";
106
+ outcome: "cancelled" | "http-error" | "transport-error" | "stream-done" | "stream-error" | "interrupted";
105
107
  reason: "none" | "unknown" | "request-body-timeout" | "caller-abort" | "credential-changed" | "disposed" | "byte-idle-timeout" | "signal-abort";
106
108
  wireBytes?: number | undefined;
107
109
  upload?: {