dsh-github-copilot 0.4.0-alpha.82 → 0.4.0-alpha.84
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 +1 -0
- package/CHANGELOG.md +12 -0
- package/README.md +11 -9
- package/README.zh.md +11 -9
- package/deployment-baseline.json +8 -1
- package/docs/auto-task-routing.md +24 -1
- package/docs/automatic-model-routing.md +8 -3
- package/docs/copilot-compaction.md +6 -0
- package/lib/client.js +2 -2
- package/lib/client.js.map +1 -1
- package/lib/index.js +302 -63
- package/lib/types/request-body-evidence.d.ts +32 -0
- package/lib/types/request-body-timeout.d.ts +2 -1
- package/package.json +1 -1
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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.
|
|
1850
|
+
var version = "0.4.0-alpha.84";
|
|
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$
|
|
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$
|
|
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$
|
|
4058
|
-
const right = object$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
4118
|
+
const record = object$5(leaf);
|
|
4119
4119
|
if (!record || !equalJson(record, leavesOf(record))) throw new Error();
|
|
4120
4120
|
}
|
|
4121
|
-
const models = object$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
4318
|
-
const defaultEffort = defaults === void 0 ? false : object$
|
|
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$
|
|
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$
|
|
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$
|
|
4352
|
-
const profile = (config.providers === void 0 ? void 0 : object$
|
|
4353
|
-
if (profile !== void 0) object$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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,207 @@ async function isCopilotInputItemScopeError(response, signal) {
|
|
|
5539
5539
|
return !signal?.aborted && isScopeError(body);
|
|
5540
5540
|
}
|
|
5541
5541
|
//#endregion
|
|
5542
|
+
//#region lib/types/request-body-evidence.js
|
|
5543
|
+
const REQUEST_BODY_EVIDENCE_LIMITS = Object.freeze({
|
|
5544
|
+
bytes: 16777216,
|
|
5545
|
+
values: 65536,
|
|
5546
|
+
tokens: 131072,
|
|
5547
|
+
depth: 64,
|
|
5548
|
+
keyCharacters: 128
|
|
5549
|
+
});
|
|
5550
|
+
function formatRequestBodyEvidence(evidence, responseHeadersMs) {
|
|
5551
|
+
const elapsed = responseHeadersMs === void 0 ? void 0 : Math.round(responseHeadersMs);
|
|
5552
|
+
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.";
|
|
5553
|
+
if (evidence.state !== "complete") return `Composition unavailable (${evidence.state}); no partial totals inferred. ${timing}`;
|
|
5554
|
+
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}`;
|
|
5555
|
+
}
|
|
5556
|
+
var EvidenceParseError = class extends Error {
|
|
5557
|
+
state;
|
|
5558
|
+
constructor(state) {
|
|
5559
|
+
super(state);
|
|
5560
|
+
this.state = state;
|
|
5561
|
+
}
|
|
5562
|
+
};
|
|
5563
|
+
function object$2(value) {
|
|
5564
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5565
|
+
}
|
|
5566
|
+
/** Diagnostic-only traversal of the original JSON spans; never reserializes or changes a request. */
|
|
5567
|
+
function requestBodyEvidence(body, protocol) {
|
|
5568
|
+
if (body === void 0) return { state: "unavailable" };
|
|
5569
|
+
const totalBytes = Buffer.byteLength(body, "utf8");
|
|
5570
|
+
if (totalBytes > REQUEST_BODY_EVIDENCE_LIMITS.bytes) return {
|
|
5571
|
+
state: "size-limit",
|
|
5572
|
+
totalBytes
|
|
5573
|
+
};
|
|
5574
|
+
let nesting = 0, tokens = 0;
|
|
5575
|
+
for (let index = 0; index < body.length; index++) {
|
|
5576
|
+
const character = body[index];
|
|
5577
|
+
if (character === "{" || character === "[") {
|
|
5578
|
+
if (++nesting > REQUEST_BODY_EVIDENCE_LIMITS.depth) return {
|
|
5579
|
+
state: "work-limit",
|
|
5580
|
+
totalBytes
|
|
5581
|
+
};
|
|
5582
|
+
tokens++;
|
|
5583
|
+
} else if (character === "}" || character === "]") nesting--;
|
|
5584
|
+
else if (character === "\"") {
|
|
5585
|
+
tokens++;
|
|
5586
|
+
while (++index < body.length) if (body[index] === "\\") index++;
|
|
5587
|
+
else if (body[index] === "\"") break;
|
|
5588
|
+
} else if (character !== " " && character !== "\n" && character !== "\r" && character !== " " && character !== ":" && character !== ",") {
|
|
5589
|
+
tokens++;
|
|
5590
|
+
while (index + 1 < body.length && !/[\s,\]}]/u.test(body[index + 1])) index++;
|
|
5591
|
+
}
|
|
5592
|
+
if (tokens > REQUEST_BODY_EVIDENCE_LIMITS.tokens) return {
|
|
5593
|
+
state: "work-limit",
|
|
5594
|
+
totalBytes
|
|
5595
|
+
};
|
|
5596
|
+
}
|
|
5597
|
+
let parsed;
|
|
5598
|
+
try {
|
|
5599
|
+
parsed = JSON.parse(body);
|
|
5600
|
+
} catch (error) {
|
|
5601
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
5602
|
+
return {
|
|
5603
|
+
state: "invalid-json",
|
|
5604
|
+
totalBytes
|
|
5605
|
+
};
|
|
5606
|
+
}
|
|
5607
|
+
const conversationKey = protocol === "openai-responses" ? "input" : "messages";
|
|
5608
|
+
const systemKey = protocol === "openai-responses" ? "instructions" : protocol === "anthropic-messages" ? "system" : void 0;
|
|
5609
|
+
if (!object$2(parsed) || !Array.isArray(parsed[conversationKey])) return {
|
|
5610
|
+
state: "unsupported-shape",
|
|
5611
|
+
totalBytes
|
|
5612
|
+
};
|
|
5613
|
+
let position = 0, values = 0, conversationBytes = 0, toolSchemaBytes = 0, systemBytes = 0;
|
|
5614
|
+
let imageBlockBytes = 0, opaqueReplayBytes = 0;
|
|
5615
|
+
const whitespace = () => {
|
|
5616
|
+
while (position < body.length && /\s/u.test(body[position])) position++;
|
|
5617
|
+
};
|
|
5618
|
+
const bytes = (start) => Buffer.byteLength(body.slice(start, position), "utf8");
|
|
5619
|
+
const stringEnd = () => {
|
|
5620
|
+
if (body[position++] !== "\"") throw new EvidenceParseError("invalid-json");
|
|
5621
|
+
while (position < body.length) {
|
|
5622
|
+
const character = body[position++];
|
|
5623
|
+
if (character === "\"") return;
|
|
5624
|
+
if (character === "\\") position++;
|
|
5625
|
+
}
|
|
5626
|
+
throw new EvidenceParseError("invalid-json");
|
|
5627
|
+
};
|
|
5628
|
+
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";
|
|
5629
|
+
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");
|
|
5630
|
+
const visit = (value, depth, location) => {
|
|
5631
|
+
if (++values > REQUEST_BODY_EVIDENCE_LIMITS.values || depth > REQUEST_BODY_EVIDENCE_LIMITS.depth) throw new EvidenceParseError("work-limit");
|
|
5632
|
+
whitespace();
|
|
5633
|
+
const start = position;
|
|
5634
|
+
let image = 0, replay = 0;
|
|
5635
|
+
if (Array.isArray(value)) {
|
|
5636
|
+
if (body[position++] !== "[") throw new EvidenceParseError("invalid-json");
|
|
5637
|
+
for (let index = 0; index < value.length; index++) {
|
|
5638
|
+
if (index > 0) {
|
|
5639
|
+
whitespace();
|
|
5640
|
+
if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
|
|
5641
|
+
}
|
|
5642
|
+
const child = visit(value[index], depth + 1, location);
|
|
5643
|
+
image += child.image;
|
|
5644
|
+
replay += child.replay;
|
|
5645
|
+
}
|
|
5646
|
+
whitespace();
|
|
5647
|
+
if (body[position++] !== "]") throw new EvidenceParseError("invalid-json");
|
|
5648
|
+
} else if (object$2(value)) {
|
|
5649
|
+
if (body[position++] !== "{") throw new EvidenceParseError("invalid-json");
|
|
5650
|
+
const imageBlock = location === "content" && isImage(value);
|
|
5651
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5652
|
+
whitespace();
|
|
5653
|
+
while (body[position] !== "}") {
|
|
5654
|
+
if (seen.size > 0) {
|
|
5655
|
+
if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
|
|
5656
|
+
whitespace();
|
|
5657
|
+
}
|
|
5658
|
+
const keyStart = position;
|
|
5659
|
+
stringEnd();
|
|
5660
|
+
if (position - keyStart > REQUEST_BODY_EVIDENCE_LIMITS.keyCharacters) throw new EvidenceParseError("work-limit");
|
|
5661
|
+
const key = JSON.parse(body.slice(keyStart, position));
|
|
5662
|
+
if (typeof key !== "string" || seen.has(key) || !Object.hasOwn(value, key)) throw new EvidenceParseError("invalid-json");
|
|
5663
|
+
seen.add(key);
|
|
5664
|
+
whitespace();
|
|
5665
|
+
if (body[position++] !== ":") throw new EvidenceParseError("invalid-json");
|
|
5666
|
+
whitespace();
|
|
5667
|
+
const childLocation = imageBlock ? "other" : depth === 0 && key === conversationKey ? "conversation" : key === "content" && (location === "conversation" || location === "content") && Array.isArray(value[key]) ? "content" : "other";
|
|
5668
|
+
const childStart = position, child = visit(value[key], depth + 1, childLocation);
|
|
5669
|
+
const childBytes = depth === 0 || isOpaque(value, key, location) && typeof value[key] === "string" ? bytes(childStart) : 0;
|
|
5670
|
+
if (depth === 0) {
|
|
5671
|
+
if (key === conversationKey) {
|
|
5672
|
+
conversationBytes = childBytes;
|
|
5673
|
+
imageBlockBytes = child.image;
|
|
5674
|
+
opaqueReplayBytes = child.replay;
|
|
5675
|
+
} else if ((key === "tools" || protocol === "openai-completions" && key === "functions") && Array.isArray(value[key])) toolSchemaBytes += childBytes;
|
|
5676
|
+
else if (key === systemKey && (typeof value[key] === "string" || Array.isArray(value[key]))) systemBytes += childBytes;
|
|
5677
|
+
}
|
|
5678
|
+
image += child.image;
|
|
5679
|
+
replay += isOpaque(value, key, location) && typeof value[key] === "string" ? childBytes : child.replay;
|
|
5680
|
+
whitespace();
|
|
5681
|
+
}
|
|
5682
|
+
position++;
|
|
5683
|
+
if (imageBlock) {
|
|
5684
|
+
image = bytes(start);
|
|
5685
|
+
replay = 0;
|
|
5686
|
+
}
|
|
5687
|
+
} else if (typeof value === "string") stringEnd();
|
|
5688
|
+
else {
|
|
5689
|
+
while (position < body.length && !/[\s,\]}]/u.test(body[position])) position++;
|
|
5690
|
+
if (position === start) throw new EvidenceParseError("invalid-json");
|
|
5691
|
+
}
|
|
5692
|
+
return {
|
|
5693
|
+
image,
|
|
5694
|
+
replay
|
|
5695
|
+
};
|
|
5696
|
+
};
|
|
5697
|
+
try {
|
|
5698
|
+
visit(parsed, 0, "root");
|
|
5699
|
+
whitespace();
|
|
5700
|
+
if (position !== body.length) return {
|
|
5701
|
+
state: "invalid-json",
|
|
5702
|
+
totalBytes
|
|
5703
|
+
};
|
|
5704
|
+
} catch (cause) {
|
|
5705
|
+
if (!(cause instanceof EvidenceParseError)) throw cause;
|
|
5706
|
+
return {
|
|
5707
|
+
state: cause.state,
|
|
5708
|
+
totalBytes
|
|
5709
|
+
};
|
|
5710
|
+
}
|
|
5711
|
+
const otherBytes = totalBytes - conversationBytes - toolSchemaBytes - systemBytes;
|
|
5712
|
+
const remainingConversationBytes = conversationBytes - imageBlockBytes - opaqueReplayBytes;
|
|
5713
|
+
if (otherBytes < 0 || remainingConversationBytes < 0) return {
|
|
5714
|
+
state: "invalid-json",
|
|
5715
|
+
totalBytes
|
|
5716
|
+
};
|
|
5717
|
+
return {
|
|
5718
|
+
state: "complete",
|
|
5719
|
+
totalBytes,
|
|
5720
|
+
conversationBytes,
|
|
5721
|
+
toolSchemaBytes,
|
|
5722
|
+
systemBytes,
|
|
5723
|
+
otherBytes,
|
|
5724
|
+
imageBlockBytes,
|
|
5725
|
+
opaqueReplayBytes,
|
|
5726
|
+
remainingConversationBytes
|
|
5727
|
+
};
|
|
5728
|
+
}
|
|
5729
|
+
//#endregion
|
|
5542
5730
|
//#region lib/types/request-body-timeout.js
|
|
5543
5731
|
const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
|
|
5544
5732
|
function record$5(value) {
|
|
5545
5733
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5546
5734
|
}
|
|
5547
5735
|
/** Verified provider evidence, not guessed capabilities, token limits or network cause. */
|
|
5548
|
-
async function requestBodyTimeoutDiagnostic(response, body, signal) {
|
|
5736
|
+
async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
|
|
5549
5737
|
if (response.status !== 408 || signal?.aborted) return void 0;
|
|
5550
5738
|
const value = await readResponseErrorJson(response, signal);
|
|
5551
|
-
if (!record$5(value)) return void 0;
|
|
5739
|
+
if (signal?.aborted || !record$5(value)) return void 0;
|
|
5552
5740
|
const error = Object.hasOwn(value, "error") ? value.error : value;
|
|
5553
5741
|
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,
|
|
5742
|
+
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).`} ${formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs)} 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
5743
|
}
|
|
5556
5744
|
//#endregion
|
|
5557
5745
|
//#region lib/types/copilot-stream-liveness.js
|
|
@@ -5897,15 +6085,20 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
5897
6085
|
guard.onRequestBodyTimeout?.(void 0);
|
|
5898
6086
|
liveness?.beginRequest(typeof init?.body === "string" ? init.body : void 0);
|
|
5899
6087
|
let response;
|
|
6088
|
+
const startedAt = performance.now();
|
|
5900
6089
|
try {
|
|
5901
6090
|
response = await fetch(input, init);
|
|
5902
6091
|
} catch (error) {
|
|
5903
6092
|
retry?.observe(void 0, 0);
|
|
5904
6093
|
throw error;
|
|
5905
6094
|
}
|
|
6095
|
+
const responseHeadersMs = performance.now() - startedAt;
|
|
5906
6096
|
retry?.observe(typeof init?.body === "string" ? init.body : void 0, response.status);
|
|
5907
6097
|
if (response.status === 408 && guard.onRequestBodyTimeout !== void 0) {
|
|
5908
|
-
const diagnostic = await requestBodyTimeoutDiagnostic(response, typeof init?.body === "string" ? init.body : void 0, lease.signal
|
|
6098
|
+
const diagnostic = await requestBodyTimeoutDiagnostic(response, typeof init?.body === "string" ? init.body : void 0, lease.signal, {
|
|
6099
|
+
protocol: entry.api,
|
|
6100
|
+
responseHeadersMs
|
|
6101
|
+
});
|
|
5909
6102
|
if (!lease.signal.aborted && !options.signal?.aborted) guard.onRequestBodyTimeout(diagnostic);
|
|
5910
6103
|
}
|
|
5911
6104
|
if (response.status === 401) {
|
|
@@ -6790,22 +6983,51 @@ function user(message) {
|
|
|
6790
6983
|
if (record$2(message.source) && message.source.kind === "model-selection") return false;
|
|
6791
6984
|
return message.role === "user" || record$2(message.source) && message.source.kind === "user";
|
|
6792
6985
|
}
|
|
6986
|
+
function difficult(current) {
|
|
6987
|
+
return /\b(prove|proof|theorem|debug|investigate|diagnose)\b|证明|定理|调试|排查|根因|调查/iu.test(current);
|
|
6988
|
+
}
|
|
6989
|
+
function continuation(current) {
|
|
6990
|
+
return /^(continue|please continue|go on|yes|ok|okay|继续|接着|嗯|好|好的|可以|执行吧|开始吧)[.!!。,,\s]*$/iu.test(current);
|
|
6991
|
+
}
|
|
6992
|
+
function boundedTransformation(current) {
|
|
6993
|
+
if (current.length > 1600) return false;
|
|
6994
|
+
const match = /^(?:convert the following (?:JSON to CSV|CSV to JSON)|sort the following lines|将以下 (?:JSON 转换为 CSV|CSV 转换为 JSON)|对以下行排序)[::][ \t]*\r?\n```[a-z]*\r?\n([\s\S]+)\r?\n```[ \t]*$/iu.exec(current);
|
|
6995
|
+
return match !== null && typeof match[1] === "string" && !match[1].includes("```");
|
|
6996
|
+
}
|
|
6793
6997
|
function assessTaskLocally(messages) {
|
|
6794
6998
|
const last = messages.findLast(user);
|
|
6795
6999
|
const current = text(last).trim();
|
|
6796
|
-
const
|
|
7000
|
+
const history = messages.slice(0, last === void 0 ? 0 : messages.lastIndexOf(last));
|
|
7001
|
+
const hasWork = history.some((message) => record$2(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$2(message.source) && message.source.kind === "model"));
|
|
6797
7002
|
const nonText = record$2(last) && Array.isArray(last.content) && last.content.some((block) => !record$2(block) || block.type !== "text");
|
|
6798
7003
|
if (!hasWork && !nonText && /^(hello|hi|hey|你好|您好|嗨)[!!。.\s]*$/iu.test(current)) return {
|
|
6799
7004
|
demand: "simple",
|
|
6800
7005
|
source: "local",
|
|
6801
7006
|
signals: ["isolated-greeting"]
|
|
6802
7007
|
};
|
|
6803
|
-
if (
|
|
7008
|
+
if (difficult(current)) return {
|
|
6804
7009
|
demand: "complex",
|
|
6805
7010
|
source: "local",
|
|
6806
7011
|
signals: ["reasoning", "investigation"]
|
|
6807
7012
|
};
|
|
6808
|
-
if (
|
|
7013
|
+
if (!hasWork && !nonText && boundedTransformation(current)) return {
|
|
7014
|
+
demand: "routine",
|
|
7015
|
+
source: "local",
|
|
7016
|
+
signals: ["bounded-transformation"]
|
|
7017
|
+
};
|
|
7018
|
+
if (continuation(current)) {
|
|
7019
|
+
const anchor = history.filter(user).slice(-12).findLast((message) => !continuation(text(message).trim()));
|
|
7020
|
+
if (anchor && difficult(text(anchor))) return {
|
|
7021
|
+
demand: "complex",
|
|
7022
|
+
source: "local",
|
|
7023
|
+
signals: [
|
|
7024
|
+
"continuation",
|
|
7025
|
+
"reasoning",
|
|
7026
|
+
"investigation"
|
|
7027
|
+
]
|
|
7028
|
+
};
|
|
7029
|
+
}
|
|
7030
|
+
if (continuation(current) || hasWork && current.length < 80) return {
|
|
6809
7031
|
demand: "unknown",
|
|
6810
7032
|
source: "local",
|
|
6811
7033
|
signals: ["continuation", "insufficient-evidence"]
|
|
@@ -6820,11 +7042,20 @@ function assessTaskLocally(messages) {
|
|
|
6820
7042
|
function assessmentInput(messages) {
|
|
6821
7043
|
let omitted = false;
|
|
6822
7044
|
const context = messages.filter((message) => !record$2(message) || message.role !== "system" && message.role !== "developer" && !(record$2(message.source) && message.source.kind === "model-selection"));
|
|
6823
|
-
|
|
6824
|
-
const
|
|
7045
|
+
const lastUser = context.findLastIndex(user);
|
|
7046
|
+
const priorUser = context.slice(0, lastUser < 0 ? 0 : lastUser).findLastIndex(user);
|
|
7047
|
+
const priority = [.../* @__PURE__ */ new Set([
|
|
7048
|
+
lastUser,
|
|
7049
|
+
priorUser,
|
|
7050
|
+
...context.map((_, index) => index).reverse()
|
|
7051
|
+
])].filter((index) => index >= 0);
|
|
7052
|
+
const rows = /* @__PURE__ */ new Map();
|
|
7053
|
+
let length = 0;
|
|
7054
|
+
for (const index of priority) {
|
|
7055
|
+
const message = context[index];
|
|
6825
7056
|
if (!record$2(message)) {
|
|
6826
7057
|
omitted = true;
|
|
6827
|
-
|
|
7058
|
+
continue;
|
|
6828
7059
|
}
|
|
6829
7060
|
if (!Array.isArray(message.content)) omitted = true;
|
|
6830
7061
|
const content = text(message);
|
|
@@ -6836,14 +7067,29 @@ function assessmentInput(messages) {
|
|
|
6836
7067
|
"tool",
|
|
6837
7068
|
"developer"
|
|
6838
7069
|
].includes(message.role) ? message.role : user(message) ? "user" : "context";
|
|
6839
|
-
|
|
7070
|
+
let prefix = content.slice(0, 1600);
|
|
7071
|
+
let row = JSON.stringify({
|
|
6840
7072
|
role,
|
|
6841
|
-
text:
|
|
7073
|
+
text: prefix
|
|
6842
7074
|
});
|
|
6843
|
-
|
|
6844
|
-
|
|
7075
|
+
while (row.length > 8e3) {
|
|
7076
|
+
omitted = true;
|
|
7077
|
+
prefix = prefix.slice(0, Math.floor(prefix.length / 2));
|
|
7078
|
+
row = JSON.stringify({
|
|
7079
|
+
role,
|
|
7080
|
+
text: prefix
|
|
7081
|
+
});
|
|
7082
|
+
}
|
|
7083
|
+
const added = row.length + (rows.size ? 1 : 0);
|
|
7084
|
+
if (rows.size >= 12 || length + added > 8e3) {
|
|
7085
|
+
omitted = true;
|
|
7086
|
+
continue;
|
|
7087
|
+
}
|
|
7088
|
+
rows.set(index, row);
|
|
7089
|
+
length += added;
|
|
7090
|
+
}
|
|
6845
7091
|
return {
|
|
6846
|
-
text:
|
|
7092
|
+
text: [...rows].sort(([left], [right]) => left - right).map(([, row]) => row).join("\n"),
|
|
6847
7093
|
omitted
|
|
6848
7094
|
};
|
|
6849
7095
|
}
|
|
@@ -6858,7 +7104,7 @@ var TaskAssessmentRevokedError = class extends Error {
|
|
|
6858
7104
|
async function assessAutoTask(messages, dependencies) {
|
|
6859
7105
|
const local = assessTaskLocally(messages);
|
|
6860
7106
|
if (dependencies.signal.aborted) throw dependencies.signal.reason;
|
|
6861
|
-
if (local.demand
|
|
7107
|
+
if (local.demand !== "unknown") return local;
|
|
6862
7108
|
if (!dependencies.enabled) return {
|
|
6863
7109
|
...local,
|
|
6864
7110
|
diagnostic: "disabled"
|
|
@@ -6901,13 +7147,6 @@ async function assessAutoTask(messages, dependencies) {
|
|
|
6901
7147
|
diagnostic: "context-omitted"
|
|
6902
7148
|
};
|
|
6903
7149
|
}
|
|
6904
|
-
if (local.demand === "complex" && parsed.data.demand !== "complex") {
|
|
6905
|
-
dependencies.diagnostic("COPILOT_AUTO_ASSESSMENT_INVALID_RESULT");
|
|
6906
|
-
return {
|
|
6907
|
-
...local,
|
|
6908
|
-
diagnostic: "invalid-result"
|
|
6909
|
-
};
|
|
6910
|
-
}
|
|
6911
7150
|
return {
|
|
6912
7151
|
...parsed.data,
|
|
6913
7152
|
source: "semantic"
|