dsh-github-copilot 0.4.2-alpha.3 → 0.4.2-alpha.5
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/AGENTS.md +2 -2
- package/CHANGELOG.md +28 -0
- package/README.md +18 -7
- package/README.zh.md +15 -7
- package/deployment-baseline.json +11 -1
- package/docs/copilot-compaction.md +1 -1
- package/docs/plugin-diagnostics.md +87 -8
- package/lib/client.js +166 -19
- package/lib/client.js.map +1 -1
- package/lib/diagnostics-analysis.js +4 -2
- package/lib/{diagnostics-types-Bl3QCfR0.js → diagnostics-types-Cd4BmeOe.js} +108 -13
- package/lib/index.js +527 -8
- package/lib/manual-compaction-recovery.js +1 -1
- package/lib/remote.js +115 -12
- package/lib/types/config.d.ts +6 -2
- package/lib/types/copilot-usage-remote.d.ts +1 -1
- package/lib/types/diagnostics-analysis.d.ts +1 -0
- package/lib/types/diagnostics-collector.d.ts +7 -0
- package/lib/types/diagnostics-host.d.ts +51 -1
- package/lib/types/diagnostics-remote.d.ts +3 -2
- package/lib/types/diagnostics-types.d.ts +187 -6
- package/lib/types/preview-provider.d.ts +6 -0
- package/lib/types/remote.d.ts +1 -1
- package/lib/types/request-body-composition.d.ts +17 -0
- package/lib/types/request-body-evidence.d.ts +2 -1
- package/lib/types/request-diagnostics.d.ts +196 -0
- package/package.json +1 -1
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 { _ as
|
|
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-Cd4BmeOe.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
|
|
@@ -57,6 +57,9 @@ var DiagnosticsCollector = class {
|
|
|
57
57
|
live = /* @__PURE__ */ new Set();
|
|
58
58
|
enabled = false;
|
|
59
59
|
autoAllocationEnabled = false;
|
|
60
|
+
requestEnabled = false;
|
|
61
|
+
requestHandles = /* @__PURE__ */ new Set();
|
|
62
|
+
requestGeneration = 0;
|
|
60
63
|
lastWall = 0;
|
|
61
64
|
autoAllocation;
|
|
62
65
|
constructor(version, layer, changed = () => {}, wall = Date.now, mono = () => performance.now()) {
|
|
@@ -77,6 +80,12 @@ var DiagnosticsCollector = class {
|
|
|
77
80
|
this.increment("interrupted", pending.count);
|
|
78
81
|
}
|
|
79
82
|
this.data.pending = [];
|
|
83
|
+
if (this.data.requests) {
|
|
84
|
+
const requests = this.data.requests;
|
|
85
|
+
requests.interruptedOnReopen = Math.min(Number.MAX_SAFE_INTEGER, (requests.interruptedOnReopen ?? 0) + (requests.pending ?? 0));
|
|
86
|
+
requests.pending = 0;
|
|
87
|
+
this.changed();
|
|
88
|
+
}
|
|
80
89
|
this.expire();
|
|
81
90
|
}
|
|
82
91
|
setEnabled(enabled) {
|
|
@@ -103,6 +112,8 @@ var DiagnosticsCollector = class {
|
|
|
103
112
|
const epoch = this.data.epoch + 1;
|
|
104
113
|
if (!Number.isSafeInteger(epoch)) throw new Error("COPILOT_DIAGNOSTICS_EPOCH_LIMIT");
|
|
105
114
|
this.live.clear();
|
|
115
|
+
this.requestHandles.clear();
|
|
116
|
+
this.requestGeneration++;
|
|
106
117
|
this.autoAllocation.clear();
|
|
107
118
|
this.data = {
|
|
108
119
|
...emptyDiagnostics(),
|
|
@@ -153,6 +164,13 @@ var DiagnosticsCollector = class {
|
|
|
153
164
|
this.increment("evicted", this.data.rows.length - kept.length);
|
|
154
165
|
if (kept.length !== this.data.rows.length) this.changed();
|
|
155
166
|
this.data.rows = kept;
|
|
167
|
+
const requests = this.data.requests;
|
|
168
|
+
if (requests) {
|
|
169
|
+
const retained = requests.rows.filter((row) => row.startedAt > now - REQUEST_DIAGNOSTICS_RETENTION_MS);
|
|
170
|
+
requests.evicted = Math.min(Number.MAX_SAFE_INTEGER, requests.evicted + requests.rows.length - retained.length);
|
|
171
|
+
if (retained.length !== requests.rows.length) this.changed();
|
|
172
|
+
requests.rows = retained;
|
|
173
|
+
}
|
|
156
174
|
}
|
|
157
175
|
add(operation, stage, metric, reason, bucket, count = 1, version = this.version) {
|
|
158
176
|
this.expire();
|
|
@@ -211,6 +229,10 @@ var DiagnosticsCollector = class {
|
|
|
211
229
|
}
|
|
212
230
|
return DiagnosticsSnapshotSchema.parse({
|
|
213
231
|
...this.data,
|
|
232
|
+
...this.data.requests ? { requests: {
|
|
233
|
+
...this.data.requests,
|
|
234
|
+
pending: this.requestHandles.size
|
|
235
|
+
} } : {},
|
|
214
236
|
autoAllocation: this.autoAllocation.snapshot(),
|
|
215
237
|
updatedAt: this.wall(),
|
|
216
238
|
pending
|
|
@@ -219,6 +241,115 @@ var DiagnosticsCollector = class {
|
|
|
219
241
|
close() {
|
|
220
242
|
this.setEnabled(false);
|
|
221
243
|
this.setAutoAllocationEnabled(false);
|
|
244
|
+
this.setRequestEnabled(false);
|
|
245
|
+
}
|
|
246
|
+
setRequestEnabled(enabled) {
|
|
247
|
+
if (this.requestEnabled !== enabled) this.requestGeneration++;
|
|
248
|
+
if (this.requestEnabled && !enabled) for (const handle of this.requestHandles) handle.finish("interrupted", "unknown");
|
|
249
|
+
this.requestEnabled = enabled;
|
|
250
|
+
}
|
|
251
|
+
beginRequest(start) {
|
|
252
|
+
if (!this.requestEnabled) return void 0;
|
|
253
|
+
const requests = this.data.requests ??= {
|
|
254
|
+
rows: [],
|
|
255
|
+
dropped: 0,
|
|
256
|
+
evicted: 0
|
|
257
|
+
};
|
|
258
|
+
if (this.requestHandles.size >= 128) {
|
|
259
|
+
requests.dropped = Math.min(Number.MAX_SAFE_INTEGER, requests.dropped + 1);
|
|
260
|
+
this.changed();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const startedAt = this.wall(), startedMono = this.mono();
|
|
264
|
+
const generation = this.requestGeneration;
|
|
265
|
+
let retainedRow;
|
|
266
|
+
const base = {
|
|
267
|
+
...start,
|
|
268
|
+
version: this.version,
|
|
269
|
+
startedAt,
|
|
270
|
+
model: /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/.test(start.model) ? start.model : "unknown"
|
|
271
|
+
};
|
|
272
|
+
let headers = {};
|
|
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
|
+
},
|
|
300
|
+
headers: (httpStatus, ms, upload) => {
|
|
301
|
+
if (!this.requestHandles.has(handle)) return;
|
|
302
|
+
headers = {
|
|
303
|
+
...httpStatus === void 0 ? {} : { httpStatus },
|
|
304
|
+
...ms === void 0 ? {} : { responseHeadersMs: Math.round(ms) },
|
|
305
|
+
...upload ? { upload } : {}
|
|
306
|
+
};
|
|
307
|
+
},
|
|
308
|
+
finish: (outcome, reason = "none") => {
|
|
309
|
+
if (!this.requestHandles.delete(handle)) return;
|
|
310
|
+
this.expire();
|
|
311
|
+
const current = this.data.requests;
|
|
312
|
+
if (!current) return;
|
|
313
|
+
const parsed = RequestDiagnosticSchema.safeParse({
|
|
314
|
+
...base,
|
|
315
|
+
...headers,
|
|
316
|
+
elapsedMs: Math.max(0, Math.round(this.mono() - startedMono)),
|
|
317
|
+
outcome,
|
|
318
|
+
reason
|
|
319
|
+
});
|
|
320
|
+
if (!parsed.success) {
|
|
321
|
+
current.dropped = Math.min(Number.MAX_SAFE_INTEGER, current.dropped + 1);
|
|
322
|
+
this.changed();
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const rows = [...current.rows, parsed.data];
|
|
326
|
+
const evicted = rows.length > 128 ? 1 : 0;
|
|
327
|
+
if (evicted) {
|
|
328
|
+
let oldest = 0;
|
|
329
|
+
for (let index = 1; index < rows.length; index++) if (rows[index].startedAt < rows[oldest].startedAt) oldest = index;
|
|
330
|
+
rows.splice(oldest, 1);
|
|
331
|
+
}
|
|
332
|
+
const candidate = {
|
|
333
|
+
...this.data,
|
|
334
|
+
requests: {
|
|
335
|
+
...current,
|
|
336
|
+
rows,
|
|
337
|
+
evicted: Math.min(Number.MAX_SAFE_INTEGER, current.evicted + evicted)
|
|
338
|
+
}
|
|
339
|
+
};
|
|
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);
|
|
344
|
+
this.changed();
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
this.requestHandles.add(handle);
|
|
348
|
+
this.changed();
|
|
349
|
+
return handle;
|
|
350
|
+
}
|
|
351
|
+
isRequestEnabled() {
|
|
352
|
+
return this.requestEnabled;
|
|
222
353
|
}
|
|
223
354
|
noteDropped() {
|
|
224
355
|
if (this.enabled) {
|
|
@@ -331,6 +462,15 @@ const result$1 = strictRemoteCodec("dsh-github-copilot#DiagnosticsView", Diagnos
|
|
|
331
462
|
codec: strictRemoteCodec("dsh-github-copilot#AutoAllocationDiagnosticsEnabled", z.boolean())
|
|
332
463
|
}]
|
|
333
464
|
},
|
|
465
|
+
{
|
|
466
|
+
method: "setRequestEnabled",
|
|
467
|
+
parameters: [{
|
|
468
|
+
name: "enabled",
|
|
469
|
+
wire: "enabled",
|
|
470
|
+
source: "json",
|
|
471
|
+
codec: strictRemoteCodec("dsh-github-copilot#RequestDiagnosticsEnabled", z.boolean())
|
|
472
|
+
}]
|
|
473
|
+
},
|
|
334
474
|
{
|
|
335
475
|
method: "recordClient",
|
|
336
476
|
parameters: [{
|
|
@@ -353,7 +493,7 @@ const result$1 = strictRemoteCodec("dsh-github-copilot#DiagnosticsView", Diagnos
|
|
|
353
493
|
var package_default = {
|
|
354
494
|
name: "dsh-github-copilot",
|
|
355
495
|
description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
|
|
356
|
-
version: "0.4.2-alpha.
|
|
496
|
+
version: "0.4.2-alpha.5",
|
|
357
497
|
releaseNotes: "CHANGELOG.md",
|
|
358
498
|
publishConfig: {
|
|
359
499
|
"access": "public",
|
|
@@ -648,6 +788,7 @@ let DiagnosticsController = (() => {
|
|
|
648
788
|
let _classSuper = TypertRemoteService;
|
|
649
789
|
let _instanceExtraInitializers = [];
|
|
650
790
|
let _get_decorators;
|
|
791
|
+
let _setRequestEnabled_decorators;
|
|
651
792
|
let _setEnabled_decorators;
|
|
652
793
|
let _setAutoAllocationEnabled_decorators;
|
|
653
794
|
let _clear_decorators;
|
|
@@ -656,6 +797,7 @@ let DiagnosticsController = (() => {
|
|
|
656
797
|
static {
|
|
657
798
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
658
799
|
_get_decorators = [Remote];
|
|
800
|
+
_setRequestEnabled_decorators = [Remote];
|
|
659
801
|
_setEnabled_decorators = [Remote];
|
|
660
802
|
_setAutoAllocationEnabled_decorators = [Remote];
|
|
661
803
|
_clear_decorators = [Remote];
|
|
@@ -671,6 +813,17 @@ let DiagnosticsController = (() => {
|
|
|
671
813
|
},
|
|
672
814
|
metadata: _metadata
|
|
673
815
|
}, null, _instanceExtraInitializers);
|
|
816
|
+
__esDecorate$9(this, null, _setRequestEnabled_decorators, {
|
|
817
|
+
kind: "method",
|
|
818
|
+
name: "setRequestEnabled",
|
|
819
|
+
static: false,
|
|
820
|
+
private: false,
|
|
821
|
+
access: {
|
|
822
|
+
has: (obj) => "setRequestEnabled" in obj,
|
|
823
|
+
get: (obj) => obj.setRequestEnabled
|
|
824
|
+
},
|
|
825
|
+
metadata: _metadata
|
|
826
|
+
}, null, _instanceExtraInitializers);
|
|
674
827
|
__esDecorate$9(this, null, _setEnabled_decorators, {
|
|
675
828
|
kind: "method",
|
|
676
829
|
name: "setEnabled",
|
|
@@ -728,6 +881,7 @@ let DiagnosticsController = (() => {
|
|
|
728
881
|
problem = "storage-unavailable";
|
|
729
882
|
enabled = false;
|
|
730
883
|
autoAllocationEnabled = false;
|
|
884
|
+
requestEnabled = false;
|
|
731
885
|
dirty = false;
|
|
732
886
|
persistedAt;
|
|
733
887
|
revision = 0;
|
|
@@ -745,8 +899,10 @@ let DiagnosticsController = (() => {
|
|
|
745
899
|
const value = ctx.get("settings")?.describe({ redactSecrets: true }).find((row) => row.ns === "github-copilot")?.value;
|
|
746
900
|
this.enabled = typeof value === "object" && value !== null && "diagnosticsEnabled" in value && value.diagnosticsEnabled === true;
|
|
747
901
|
this.autoAllocationEnabled = typeof value === "object" && value !== null && "autoAllocationDiagnosticsEnabled" in value && value.autoAllocationDiagnosticsEnabled === true;
|
|
902
|
+
this.requestEnabled = typeof value === "object" && value !== null && "requestDiagnosticsEnabled" in value && value.requestDiagnosticsEnabled === true;
|
|
748
903
|
this.collector.setEnabled(this.enabled && this.state === "ready");
|
|
749
904
|
this.collector.setAutoAllocationEnabled(this.autoAllocationEnabled && this.state === "ready");
|
|
905
|
+
this.collector.setRequestEnabled(this.requestEnabled && this.state === "ready");
|
|
750
906
|
if (!this.enabled) this.brackets.clear();
|
|
751
907
|
};
|
|
752
908
|
ctx.inject(["settings"], (scope) => {
|
|
@@ -777,6 +933,7 @@ let DiagnosticsController = (() => {
|
|
|
777
933
|
this.problem = error instanceof Error && error.message === "COPILOT_DIAGNOSTICS_PROFILE_UNAVAILABLE" ? "profile-unavailable" : typeof error === "object" && error !== null && "code" in error && (error.code === "invalid-record" || error.code === "malformed-medium" || error.code === "version-mismatch") ? "storage-invalid" : "storage-unavailable";
|
|
778
934
|
this.collector.setEnabled(false);
|
|
779
935
|
this.collector.setAutoAllocationEnabled(false);
|
|
936
|
+
this.collector.setRequestEnabled(false);
|
|
780
937
|
ctx.logger.warn("[github-copilot] COPILOT_DIAGNOSTICS_STORAGE_UNAVAILABLE");
|
|
781
938
|
}
|
|
782
939
|
if (this.closed) return;
|
|
@@ -874,6 +1031,7 @@ let DiagnosticsController = (() => {
|
|
|
874
1031
|
return {
|
|
875
1032
|
enabled: this.enabled,
|
|
876
1033
|
autoAllocationEnabled: this.autoAllocationEnabled,
|
|
1034
|
+
requestEnabled: this.requestEnabled,
|
|
877
1035
|
state: this.state,
|
|
878
1036
|
diagnostic: this.problem,
|
|
879
1037
|
...this.persistedAt === void 0 ? {} : { persistedAt: this.persistedAt },
|
|
@@ -881,6 +1039,30 @@ let DiagnosticsController = (() => {
|
|
|
881
1039
|
snapshot: this.collector.snapshot()
|
|
882
1040
|
};
|
|
883
1041
|
}
|
|
1042
|
+
async setRequestEnabled(enabled) {
|
|
1043
|
+
if (typeof enabled !== "boolean") throw new Error("COPILOT_DIAGNOSTICS_INVALID_CONTROL");
|
|
1044
|
+
if (this.settingsBusy) throw new Error("COPILOT_DIAGNOSTICS_CONTROL_BUSY");
|
|
1045
|
+
if (enabled && !this.domain) throw new Error("COPILOT_DIAGNOSTICS_STORAGE_UNAVAILABLE");
|
|
1046
|
+
this.settingsBusy = true;
|
|
1047
|
+
try {
|
|
1048
|
+
const settings = this.ctx.get("settings");
|
|
1049
|
+
const row = settings?.describe({ redactSecrets: true }).find((item) => item.ns === "github-copilot");
|
|
1050
|
+
if (!settings || !row) throw new Error("COPILOT_DIAGNOSTICS_SETTINGS_UNAVAILABLE");
|
|
1051
|
+
await settings.mutate("github-copilot", [{
|
|
1052
|
+
op: "set",
|
|
1053
|
+
path: ["requestDiagnosticsEnabled"],
|
|
1054
|
+
value: enabled
|
|
1055
|
+
}], row.revision);
|
|
1056
|
+
const saved = settings.describe({ redactSecrets: true }).find((item) => item.ns === "github-copilot")?.value;
|
|
1057
|
+
if (typeof saved !== "object" || saved === null || !("requestDiagnosticsEnabled" in saved) || saved.requestDiagnosticsEnabled !== enabled) throw new Error("COPILOT_DIAGNOSTICS_SETTINGS_COMMIT_UNCERTAIN");
|
|
1058
|
+
this.requestEnabled = enabled;
|
|
1059
|
+
this.collector.setRequestEnabled(enabled && this.state === "ready");
|
|
1060
|
+
await this.flush();
|
|
1061
|
+
return this.get();
|
|
1062
|
+
} finally {
|
|
1063
|
+
this.settingsBusy = false;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
884
1066
|
async setEnabled(enabled) {
|
|
885
1067
|
if (typeof enabled !== "boolean") throw new Error("COPILOT_DIAGNOSTICS_INVALID_CONTROL");
|
|
886
1068
|
if (this.settingsBusy) throw new Error("COPILOT_DIAGNOSTICS_CONTROL_BUSY");
|
|
@@ -3447,6 +3629,257 @@ async function isCopilotInputItemScopeError(response, signal) {
|
|
|
3447
3629
|
//#region lib/types/request-body-timeout-marker.js
|
|
3448
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.";
|
|
3449
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
|
|
3450
3883
|
//#region lib/types/request-upload-evidence.js
|
|
3451
3884
|
function object$6(value) {
|
|
3452
3885
|
return typeof value === "object" && value !== null;
|
|
@@ -3561,7 +3994,9 @@ async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
|
|
|
3561
3994
|
const compression = dispatch?.compression;
|
|
3562
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.` : "";
|
|
3563
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).`;
|
|
3564
|
-
const
|
|
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);
|
|
3565
4000
|
const upload = formatRequestUploadEvidence(dispatch?.upload);
|
|
3566
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.`;
|
|
3567
4002
|
}
|
|
@@ -4016,6 +4451,29 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
4016
4451
|
}
|
|
4017
4452
|
} : options.onPayload;
|
|
4018
4453
|
const fetch = options.fetch ?? globalThis.fetch;
|
|
4454
|
+
const streamId = randomUUID();
|
|
4455
|
+
let dispatchIndex = 0;
|
|
4456
|
+
let requestDiagnostic;
|
|
4457
|
+
let dispatchSignal;
|
|
4458
|
+
let diagnosticsFailed = false;
|
|
4459
|
+
const observeDiagnostics = (observe) => {
|
|
4460
|
+
try {
|
|
4461
|
+
return observe();
|
|
4462
|
+
} catch {
|
|
4463
|
+
if (!diagnosticsFailed) {
|
|
4464
|
+
diagnosticsFailed = true;
|
|
4465
|
+
guard.requestDiagnostics?.failed();
|
|
4466
|
+
}
|
|
4467
|
+
return;
|
|
4468
|
+
}
|
|
4469
|
+
};
|
|
4470
|
+
const abortReason = () => {
|
|
4471
|
+
if (options.signal?.aborted) return "caller-abort";
|
|
4472
|
+
if (lease.signal.reason instanceof ManagedWireAbortError) return lease.signal.reason.code === "COPILOT_PREVIEW_DISPOSED" ? "disposed" : "credential-changed";
|
|
4473
|
+
if (liveness?.signal.reason instanceof CopilotStreamIdleError) return "byte-idle-timeout";
|
|
4474
|
+
return lease.signal.aborted || dispatchSignal?.aborted ? "signal-abort" : "unknown";
|
|
4475
|
+
};
|
|
4476
|
+
const diagnosticAborted = () => lease.signal.aborted || options.signal?.aborted === true || liveness?.signal.aborted === true || dispatchSignal?.aborted === true;
|
|
4019
4477
|
const observeResponse = async (input, init) => {
|
|
4020
4478
|
guard.requestCheckpoint?.();
|
|
4021
4479
|
guard.onRequestBodyTimeout?.(void 0);
|
|
@@ -4043,28 +4501,73 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
4043
4501
|
compression = prepared.evidence;
|
|
4044
4502
|
}
|
|
4045
4503
|
lease.dispatch?.();
|
|
4504
|
+
dispatchSignal = dispatchInit?.signal ?? void 0;
|
|
4046
4505
|
liveness?.beginRequest(originalBody);
|
|
4506
|
+
dispatchIndex++;
|
|
4507
|
+
observeDiagnostics(() => requestDiagnostic?.finish("interrupted", "unknown"));
|
|
4508
|
+
requestDiagnostic = void 0;
|
|
4509
|
+
if (observeDiagnostics(() => guard.requestDiagnostics?.enabled())) requestDiagnostic = observeDiagnostics(() => {
|
|
4510
|
+
const wireBody = dispatchInit?.body;
|
|
4511
|
+
const wireBytes = typeof wireBody === "string" ? Buffer.byteLength(wireBody, "utf8") : ArrayBuffer.isView(wireBody) ? wireBody.byteLength : wireBody instanceof ArrayBuffer ? wireBody.byteLength : void 0;
|
|
4512
|
+
return guard.requestDiagnostics?.begin({
|
|
4513
|
+
streamId,
|
|
4514
|
+
dispatchIndex,
|
|
4515
|
+
model: model.id,
|
|
4516
|
+
protocol: entry.api,
|
|
4517
|
+
composition: requestBodyEvidence(originalBody, entry.api),
|
|
4518
|
+
encoding: compression?.encoding ?? (typeof wireBody === "string" && !new Headers(dispatchInit?.headers).has("content-encoding") ? "identity" : "unknown"),
|
|
4519
|
+
...wireBytes === void 0 ? {} : { wireBytes }
|
|
4520
|
+
});
|
|
4521
|
+
});
|
|
4047
4522
|
let response;
|
|
4048
|
-
|
|
4523
|
+
let composition;
|
|
4524
|
+
const upload = guard.onRequestBodyTimeout === void 0 && requestDiagnostic === void 0 ? void 0 : createRequestUploadObserver();
|
|
4049
4525
|
const startedAt = performance.now();
|
|
4050
4526
|
try {
|
|
4051
|
-
|
|
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;
|
|
4052
4542
|
} catch (error) {
|
|
4543
|
+
observeDiagnostics(() => requestDiagnostic?.headers(void 0, void 0, upload?.snapshot()));
|
|
4544
|
+
observeDiagnostics(() => requestDiagnostic?.finish(diagnosticAborted() ? "cancelled" : "transport-error", abortReason()));
|
|
4545
|
+
requestDiagnostic = void 0;
|
|
4053
4546
|
retry?.observe(void 0, 0);
|
|
4054
4547
|
throw error;
|
|
4055
4548
|
} finally {
|
|
4056
4549
|
upload?.close();
|
|
4057
4550
|
}
|
|
4058
4551
|
const responseHeadersMs = performance.now() - startedAt;
|
|
4552
|
+
observeDiagnostics(() => requestDiagnostic?.headers(response.status, responseHeadersMs, upload?.snapshot()));
|
|
4059
4553
|
retry?.observe(originalBody, response.status);
|
|
4060
|
-
if (response.status === 408 && guard.onRequestBodyTimeout !== void 0) {
|
|
4554
|
+
if (response.status === 408 && (guard.onRequestBodyTimeout !== void 0 || requestDiagnostic !== void 0)) {
|
|
4061
4555
|
const diagnostic = await requestBodyTimeoutDiagnostic(response, originalBody, lease.signal, {
|
|
4062
4556
|
protocol: entry.api,
|
|
4063
4557
|
responseHeadersMs,
|
|
4558
|
+
...composition === void 0 ? {} : { composition },
|
|
4064
4559
|
...upload === void 0 ? {} : { upload: upload.snapshot() },
|
|
4065
4560
|
...compression === void 0 ? {} : { compression }
|
|
4066
4561
|
});
|
|
4067
|
-
if (!lease.signal.aborted && !options.signal?.aborted) guard.onRequestBodyTimeout(diagnostic);
|
|
4562
|
+
if (!lease.signal.aborted && !options.signal?.aborted) guard.onRequestBodyTimeout?.(diagnostic);
|
|
4563
|
+
if (diagnostic !== void 0) {
|
|
4564
|
+
observeDiagnostics(() => requestDiagnostic?.finish("http-error", "request-body-timeout"));
|
|
4565
|
+
requestDiagnostic = void 0;
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
if (response.status >= 400) {
|
|
4569
|
+
observeDiagnostics(() => requestDiagnostic?.finish("http-error", "unknown"));
|
|
4570
|
+
requestDiagnostic = void 0;
|
|
4068
4571
|
}
|
|
4069
4572
|
if (response.status === 401) {
|
|
4070
4573
|
if (responses && await isCopilotInputItemScopeError(response, lease.signal)) {
|
|
@@ -4098,10 +4601,19 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
4098
4601
|
try {
|
|
4099
4602
|
for await (const event of native.streamSimple(model, context, wireOptions)) {
|
|
4100
4603
|
reportIdleFailure();
|
|
4604
|
+
if (event.type === "done") {
|
|
4605
|
+
observeDiagnostics(() => requestDiagnostic?.finish("stream-done"));
|
|
4606
|
+
requestDiagnostic = void 0;
|
|
4607
|
+
} else if (event.type === "error") {
|
|
4608
|
+
const cancelled = diagnosticAborted();
|
|
4609
|
+
observeDiagnostics(() => requestDiagnostic?.finish(cancelled ? "cancelled" : "stream-error", cancelled ? abortReason() : "unknown"));
|
|
4610
|
+
requestDiagnostic = void 0;
|
|
4611
|
+
}
|
|
4101
4612
|
if (event.type === "error" && event.reason === "aborted" && lease.signal.reason instanceof ManagedWireAbortError) guard.onWireAbort?.(lease.signal.reason.code);
|
|
4102
4613
|
yield event;
|
|
4103
4614
|
}
|
|
4104
4615
|
} finally {
|
|
4616
|
+
observeDiagnostics(() => requestDiagnostic?.finish("interrupted", "unknown"));
|
|
4105
4617
|
reportIdleFailure();
|
|
4106
4618
|
liveness?.dispose();
|
|
4107
4619
|
if (lease.signal.aborted || options.signal?.aborted) retry?.observe(void 0, 0);
|
|
@@ -6984,6 +7496,7 @@ function readInlineConfig(config) {
|
|
|
6984
7496
|
...config,
|
|
6985
7497
|
diagnosticsEnabled: readConfigValue(config.diagnosticsEnabled),
|
|
6986
7498
|
autoAllocationDiagnosticsEnabled: readConfigValue(config.autoAllocationDiagnosticsEnabled),
|
|
7499
|
+
requestDiagnosticsEnabled: readConfigValue(config.requestDiagnosticsEnabled),
|
|
6987
7500
|
continuationDefaultHistory: defaults === void 0 ? void 0 : Array.from(defaults, (row) => ({
|
|
6988
7501
|
enabled: row.enabled,
|
|
6989
7502
|
changedAt: row.changedAt
|
|
@@ -7017,6 +7530,7 @@ const MAX_TIMEOUT_MS = 2147483647;
|
|
|
7017
7530
|
const Config = z$1.object({
|
|
7018
7531
|
diagnosticsEnabled: z$1.boolean().default(false).hidden().volatile(),
|
|
7019
7532
|
autoAllocationDiagnosticsEnabled: z$1.boolean().default(false).hidden().volatile(),
|
|
7533
|
+
requestDiagnosticsEnabled: z$1.boolean().default(false).hidden().volatile(),
|
|
7020
7534
|
enabled: z$1.boolean().default(true),
|
|
7021
7535
|
providers: z$1.array(z$1.string()).default([]),
|
|
7022
7536
|
includeSources: z$1.boolean().default(true),
|
|
@@ -13585,6 +14099,11 @@ function createAccountRuntime(ctx, config, binding, exclusionTurns, replayRecove
|
|
|
13585
14099
|
const guard = {
|
|
13586
14100
|
...lifetime.guard(lease),
|
|
13587
14101
|
...hooks,
|
|
14102
|
+
requestDiagnostics: {
|
|
14103
|
+
enabled: () => ctx.get("githubCopilotDiagnostics")?.collector.isRequestEnabled() === true,
|
|
14104
|
+
begin: (start) => ctx.get("githubCopilotDiagnostics")?.collector.beginRequest(start),
|
|
14105
|
+
failed: () => ctx.logger.warn("[github-copilot] COPILOT_REQUEST_DIAGNOSTICS_FAILED")
|
|
14106
|
+
},
|
|
13588
14107
|
responsesRequestCompression: settings?.responsesRequestCompression === true && (template.transport === void 0 || template.transport === "sse"),
|
|
13589
14108
|
responsesOmitTemperature: settings?.responsesOmitTemperature === true,
|
|
13590
14109
|
onReplayFailure(error) {
|