dsh-github-copilot 0.4.0-alpha.105 → 0.4.0-alpha.107
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 -1
- package/CHANGELOG.md +11 -0
- package/README.md +13 -9
- package/README.zh.md +13 -9
- package/deployment-baseline.json +9 -1
- package/docs/automatic-model-routing.md +29 -4
- package/docs/copilot-accounts.md +17 -1
- package/lib/client.js +477 -65
- package/lib/client.js.map +1 -1
- package/lib/index.js +232 -68
- package/lib/remote.js +43 -1
- package/lib/types/authorization-code-clipboard.d.ts +4 -0
- package/lib/types/client.d.ts +11 -3
- package/lib/types/context-evidence.d.ts +4 -4
- package/lib/types/copilot-accounts-card.d.ts +1 -0
- package/lib/types/copilot-accounts-remote.d.ts +1 -0
- package/lib/types/copilot-accounts-types.d.ts +1 -1
- package/lib/types/session-accounts-remote.d.ts +1 -0
- package/lib/types/turn-request-models.d.ts +55 -0
- package/lib/types/turn-selection-card.d.ts +10 -1
- package/lib/types/turn-selection-host.d.ts +2 -0
- package/lib/types/turn-selection-remote.d.ts +2 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1348,7 +1348,7 @@ var Budget = class {
|
|
|
1348
1348
|
if (this.consumed > ACCOUNT_MODEL_CATALOG_LIMITS.maxBytes) fail$1("CATALOG_TOO_LARGE", true);
|
|
1349
1349
|
}
|
|
1350
1350
|
};
|
|
1351
|
-
function record$
|
|
1351
|
+
function record$12(value, code) {
|
|
1352
1352
|
if (typeof value !== "object" || value === null || Array.isArray(value)) fail$1(code);
|
|
1353
1353
|
return value;
|
|
1354
1354
|
}
|
|
@@ -1401,11 +1401,11 @@ function normalizeModel(raw, id, options, budget) {
|
|
|
1401
1401
|
if (options.availableModelIds?.has(id) !== true) fail$1("MISSING_POLICY");
|
|
1402
1402
|
policySource = "account-available-id";
|
|
1403
1403
|
} else {
|
|
1404
|
-
if (text$2(field(record$
|
|
1404
|
+
if (text$2(field(record$12(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail$1("POLICY_NOT_ENABLED");
|
|
1405
1405
|
policySource = "server-enabled";
|
|
1406
1406
|
}
|
|
1407
|
-
const capabilities = record$
|
|
1408
|
-
const supports = record$
|
|
1407
|
+
const capabilities = record$12(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
|
|
1408
|
+
const supports = record$12(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
|
|
1409
1409
|
const streaming = field(supports, "streaming", budget);
|
|
1410
1410
|
if (streaming === false) fail$1("STREAMING_UNSUPPORTED");
|
|
1411
1411
|
if (streaming !== true) fail$1("INVALID_SUPPORTS");
|
|
@@ -1426,7 +1426,7 @@ function normalizeModel(raw, id, options, budget) {
|
|
|
1426
1426
|
if (selected === void 0) fail$1(unsupportedEndpointCount === 0 && endpoints.includes("ws:/responses") ? "WEBSOCKET_ONLY" : "UNSUPPORTED_ENDPOINTS");
|
|
1427
1427
|
const rawLimits = field(capabilities, "limits", budget);
|
|
1428
1428
|
if (rawLimits === void 0) fail$1("MISSING_LIMITS");
|
|
1429
|
-
const limits = record$
|
|
1429
|
+
const limits = record$12(rawLimits, "INVALID_LIMITS");
|
|
1430
1430
|
const maxContext = optionalPositive(limits, "max_context_window_tokens", "INVALID_LIMITS", budget);
|
|
1431
1431
|
const maxInputTokens = optionalPositive(limits, "max_prompt_tokens", "INVALID_LIMITS", budget);
|
|
1432
1432
|
if (maxContext === void 0 && maxInputTokens === void 0) fail$1("MISSING_CONTEXT_LIMIT");
|
|
@@ -1444,7 +1444,7 @@ function normalizeModel(raw, id, options, budget) {
|
|
|
1444
1444
|
if (vision === true) {
|
|
1445
1445
|
const rawVisionLimits = field(limits, "vision", budget);
|
|
1446
1446
|
if (rawVisionLimits !== void 0) {
|
|
1447
|
-
const rawMediaTypes = field(record$
|
|
1447
|
+
const rawMediaTypes = field(record$12(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
|
|
1448
1448
|
if (rawMediaTypes !== void 0) {
|
|
1449
1449
|
const mediaTypes = stringList(rawMediaTypes, ACCOUNT_MODEL_CATALOG_LIMITS.maxMediaTypes, 128, "INVALID_VISION_LIMITS", budget);
|
|
1450
1450
|
const mime = /^[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*\/[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*$/iu;
|
|
@@ -1506,7 +1506,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
|
|
|
1506
1506
|
fail$1("INVALID_JSON", true);
|
|
1507
1507
|
}
|
|
1508
1508
|
}
|
|
1509
|
-
const data = field(record$
|
|
1509
|
+
const data = field(record$12(raw, "INVALID_CATALOG"), "data", budget);
|
|
1510
1510
|
if (!Array.isArray(data)) fail$1("INVALID_CATALOG");
|
|
1511
1511
|
const count = field(data, "length", budget);
|
|
1512
1512
|
if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) fail$1("INVALID_CATALOG");
|
|
@@ -1529,7 +1529,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
|
|
|
1529
1529
|
for (let index = 0; index < count; index++) {
|
|
1530
1530
|
let id;
|
|
1531
1531
|
try {
|
|
1532
|
-
const candidate = record$
|
|
1532
|
+
const candidate = record$12(field(data, String(index), budget), "INVALID_MODEL");
|
|
1533
1533
|
const candidateId = text$2(field(candidate, "id", budget), ACCOUNT_MODEL_CATALOG_LIMITS.maxIdLength, "INVALID_ID", budget);
|
|
1534
1534
|
if (!identifier.test(candidateId)) fail$1("INVALID_ID");
|
|
1535
1535
|
id = candidateId;
|
|
@@ -2448,7 +2448,7 @@ const REQUEST_BODY_TIMEOUT_MARKER = "COPILOT_REQUEST_BODY_TIMEOUT: Copilot retur
|
|
|
2448
2448
|
function object$6(value) {
|
|
2449
2449
|
return typeof value === "object" && value !== null;
|
|
2450
2450
|
}
|
|
2451
|
-
function count$
|
|
2451
|
+
function count$3(value) {
|
|
2452
2452
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
2453
2453
|
}
|
|
2454
2454
|
/** Observe public native events only; never read request fields, mutate transport or imply remote receipt. */
|
|
@@ -2460,7 +2460,7 @@ function createRequestUploadObserver() {
|
|
|
2460
2460
|
let socket;
|
|
2461
2461
|
let connectionAmbiguous = false, socketBoundToRequest = false;
|
|
2462
2462
|
let alpn = "unavailable", nodeWritableBufferBytes;
|
|
2463
|
-
const elapsed = () => startedAt === void 0 ? void 0 : count$
|
|
2463
|
+
const elapsed = () => startedAt === void 0 ? void 0 : count$3(Math.round(performance.now() - startedAt));
|
|
2464
2464
|
const request = (data) => !closed && object$6(data) && object$6(data.request) ? requests.get(data.request) : void 0;
|
|
2465
2465
|
const connected = (data, boundToRequest = false) => {
|
|
2466
2466
|
if (closed || !object$6(data) || !object$6(data.socket)) return;
|
|
@@ -2495,7 +2495,7 @@ function createRequestUploadObserver() {
|
|
|
2495
2495
|
if (request(data) !== 1 || bodyWrite) return;
|
|
2496
2496
|
bodyWrite = true;
|
|
2497
2497
|
bodyWriteCompleteMs = elapsed();
|
|
2498
|
-
nodeWritableBufferBytes = count$
|
|
2498
|
+
nodeWritableBufferBytes = count$3(socket?.writableLength);
|
|
2499
2499
|
},
|
|
2500
2500
|
"undici:request:headers": (data) => {
|
|
2501
2501
|
if (request(data) === 1 && nativeResponseHeadersMs === void 0) nativeResponseHeadersMs = elapsed();
|
|
@@ -2545,16 +2545,16 @@ function formatRequestUploadEvidence(evidence) {
|
|
|
2545
2545
|
//#endregion
|
|
2546
2546
|
//#region lib/types/request-body-timeout.js
|
|
2547
2547
|
const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
|
|
2548
|
-
function record$
|
|
2548
|
+
function record$11(value) {
|
|
2549
2549
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2550
2550
|
}
|
|
2551
2551
|
/** Verified provider evidence, not guessed capabilities, token limits or network cause. */
|
|
2552
2552
|
async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
|
|
2553
2553
|
if (response.status !== 408 || signal?.aborted) return void 0;
|
|
2554
2554
|
const value = await readResponseErrorJson(response, signal);
|
|
2555
|
-
if (signal?.aborted || !record$
|
|
2555
|
+
if (signal?.aborted || !record$11(value)) return void 0;
|
|
2556
2556
|
const error = Object.hasOwn(value, "error") ? value.error : value;
|
|
2557
|
-
if (!record$
|
|
2557
|
+
if (!record$11(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;
|
|
2558
2558
|
const size = body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`;
|
|
2559
2559
|
const composition = formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs);
|
|
2560
2560
|
const upload = formatRequestUploadEvidence(dispatch?.upload);
|
|
@@ -2989,7 +2989,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
2989
2989
|
var package_default = {
|
|
2990
2990
|
name: "dsh-github-copilot",
|
|
2991
2991
|
description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
|
|
2992
|
-
version: "0.4.0-alpha.
|
|
2992
|
+
version: "0.4.0-alpha.107",
|
|
2993
2993
|
publishConfig: {
|
|
2994
2994
|
"access": "public",
|
|
2995
2995
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -4090,6 +4090,8 @@ var CopilotAccountsHost = class {
|
|
|
4090
4090
|
}
|
|
4091
4091
|
}).then(async (result) => {
|
|
4092
4092
|
if (result.status !== "authorized") return;
|
|
4093
|
+
this.operation = "verifying";
|
|
4094
|
+
this.notices = [];
|
|
4093
4095
|
const binding = this.capture(accountId);
|
|
4094
4096
|
const signal = AbortSignal.any([attemptSignal, AbortSignal.timeout(6e4)]);
|
|
4095
4097
|
const identity = await this.identity(binding, signal);
|
|
@@ -5225,14 +5227,14 @@ function isZeroContextUsage(usage) {
|
|
|
5225
5227
|
//#endregion
|
|
5226
5228
|
//#region lib/types/context-evidence.js
|
|
5227
5229
|
const COPILOT_CONTEXT_EVIDENCE = "githubCopilotContextEvidence";
|
|
5228
|
-
const count$
|
|
5230
|
+
const count$2 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
5229
5231
|
const routeSchema = z$1.object({
|
|
5230
5232
|
provider: z$1.string().min(1),
|
|
5231
5233
|
model: z$1.string().min(1)
|
|
5232
5234
|
}).strict();
|
|
5233
5235
|
const sampleSchema = z$1.object({
|
|
5234
|
-
tokens: count$
|
|
5235
|
-
seq: count$
|
|
5236
|
+
tokens: count$2,
|
|
5237
|
+
seq: count$2,
|
|
5236
5238
|
route: routeSchema
|
|
5237
5239
|
}).strict();
|
|
5238
5240
|
const ContextEvidenceSchema = z$1.object({
|
|
@@ -5248,14 +5250,14 @@ const ContextEvidenceSchema = z$1.object({
|
|
|
5248
5250
|
])
|
|
5249
5251
|
}).strict();
|
|
5250
5252
|
const usageSchema = z$1.object({
|
|
5251
|
-
inputTokens: count$
|
|
5252
|
-
outputTokens: count$
|
|
5253
|
-
cacheReadTokens: count$
|
|
5254
|
-
cacheWriteTokens: count$
|
|
5255
|
-
totalTokens: count$
|
|
5256
|
-
reasoningTokens: count$
|
|
5253
|
+
inputTokens: count$2,
|
|
5254
|
+
outputTokens: count$2,
|
|
5255
|
+
cacheReadTokens: count$2.optional(),
|
|
5256
|
+
cacheWriteTokens: count$2.optional(),
|
|
5257
|
+
totalTokens: count$2.optional(),
|
|
5258
|
+
reasoningTokens: count$2.optional()
|
|
5257
5259
|
});
|
|
5258
|
-
function record$
|
|
5260
|
+
function record$10(value) {
|
|
5259
5261
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5260
5262
|
}
|
|
5261
5263
|
function sameRoute$1(left, right) {
|
|
@@ -5274,10 +5276,10 @@ function initialContextEvidence() {
|
|
|
5274
5276
|
}
|
|
5275
5277
|
/** Read only counts and routing leaves; never message content or opaque replay. */
|
|
5276
5278
|
function foldContextEvidence(state, event) {
|
|
5277
|
-
if (!record$
|
|
5279
|
+
if (!record$10(event) || typeof event.type !== "string" || !record$10(event.data)) return state;
|
|
5278
5280
|
if (event.type === "request/header" || event.type === "model/selection") {
|
|
5279
|
-
const raw = event.type === "request/header" ? record$
|
|
5280
|
-
if (!record$
|
|
5281
|
+
const raw = event.type === "request/header" ? record$10(event.data.header) ? event.data.header.config : void 0 : event.data;
|
|
5282
|
+
if (!record$10(raw)) return {
|
|
5281
5283
|
...state,
|
|
5282
5284
|
route: null,
|
|
5283
5285
|
sample: null,
|
|
@@ -5316,7 +5318,7 @@ function foldContextEvidence(state, event) {
|
|
|
5316
5318
|
if (!copilot(state.route)) return state;
|
|
5317
5319
|
if (event.type === "assistant/message" && event.data.source !== void 0) {
|
|
5318
5320
|
const source = event.data.source;
|
|
5319
|
-
const parsed = routeSchema.safeParse(record$
|
|
5321
|
+
const parsed = routeSchema.safeParse(record$10(source) ? {
|
|
5320
5322
|
provider: source.provider,
|
|
5321
5323
|
model: source.model
|
|
5322
5324
|
} : source);
|
|
@@ -5332,13 +5334,13 @@ function foldContextEvidence(state, event) {
|
|
|
5332
5334
|
const settledUsage = usage !== void 0;
|
|
5333
5335
|
let terminal;
|
|
5334
5336
|
for (const entry of stream) {
|
|
5335
|
-
if (!record$
|
|
5337
|
+
if (!record$10(entry) || entry.type !== "chunk" || !record$10(entry.chunk)) continue;
|
|
5336
5338
|
if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
|
|
5337
5339
|
if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
|
|
5338
5340
|
}
|
|
5339
5341
|
if (usage === void 0) return state;
|
|
5340
5342
|
const parsed = usageSchema.safeParse(usage);
|
|
5341
|
-
if (!parsed.success || !count$
|
|
5343
|
+
if (!parsed.success || !count$2.safeParse(event.seq).success) return {
|
|
5342
5344
|
...state,
|
|
5343
5345
|
sample: null,
|
|
5344
5346
|
invalid: true,
|
|
@@ -5346,7 +5348,7 @@ function foldContextEvidence(state, event) {
|
|
|
5346
5348
|
};
|
|
5347
5349
|
const value = parsed.data;
|
|
5348
5350
|
const zero = isZeroContextUsage(value);
|
|
5349
|
-
const successful = record$
|
|
5351
|
+
const successful = record$10(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
|
|
5350
5352
|
if (zero && !successful) {
|
|
5351
5353
|
const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
|
|
5352
5354
|
return {
|
|
@@ -5366,7 +5368,7 @@ function foldContextEvidence(state, event) {
|
|
|
5366
5368
|
...state,
|
|
5367
5369
|
sample: {
|
|
5368
5370
|
tokens,
|
|
5369
|
-
seq: count$
|
|
5371
|
+
seq: count$2.parse(event.seq),
|
|
5370
5372
|
route: state.route
|
|
5371
5373
|
},
|
|
5372
5374
|
invalid: false,
|
|
@@ -5388,7 +5390,7 @@ const contextEvidenceDefinition = {
|
|
|
5388
5390
|
function installContextEvidence(ctx) {
|
|
5389
5391
|
ctx.inject(["sessionProjections"], (scope) => {
|
|
5390
5392
|
const registry = scope.get("sessionProjections");
|
|
5391
|
-
if (!record$
|
|
5393
|
+
if (!record$10(registry) || typeof registry.register !== "function") {
|
|
5392
5394
|
scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
|
|
5393
5395
|
return;
|
|
5394
5396
|
}
|
|
@@ -6421,7 +6423,7 @@ function buildAnthropicWireBody(request, cfg, model) {
|
|
|
6421
6423
|
}
|
|
6422
6424
|
//#endregion
|
|
6423
6425
|
//#region lib/types/responses-reasoning-text.js
|
|
6424
|
-
function record$
|
|
6426
|
+
function record$9(value) {
|
|
6425
6427
|
return typeof value === "object" && value !== null;
|
|
6426
6428
|
}
|
|
6427
6429
|
function responseIndex(value) {
|
|
@@ -6479,13 +6481,13 @@ var ResponsesReasoningText = class {
|
|
|
6479
6481
|
}
|
|
6480
6482
|
/** Only recognized public text fields are examined; no copying of the item. */
|
|
6481
6483
|
snapshot(item) {
|
|
6482
|
-
if (!record$
|
|
6484
|
+
if (!record$9(item) || item.type !== "reasoning") return "";
|
|
6483
6485
|
let delta = "";
|
|
6484
6486
|
for (const family of ["summary", "raw"]) {
|
|
6485
6487
|
const value = family === "summary" ? item.summary : item.content;
|
|
6486
6488
|
if (!Array.isArray(value)) continue;
|
|
6487
6489
|
for (const [index, part] of value.entries()) {
|
|
6488
|
-
if (!record$
|
|
6490
|
+
if (!record$9(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
|
|
6489
6491
|
delta += this.update(family, index, part.text, true);
|
|
6490
6492
|
}
|
|
6491
6493
|
}
|
|
@@ -8733,13 +8735,13 @@ function resolveCopilotResponsesReasoning(ctx, request, candidate) {
|
|
|
8733
8735
|
}
|
|
8734
8736
|
//#endregion
|
|
8735
8737
|
//#region lib/types/replay-recovery.js
|
|
8736
|
-
function record$
|
|
8738
|
+
function record$8(value) {
|
|
8737
8739
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8738
8740
|
}
|
|
8739
8741
|
function parsed(body) {
|
|
8740
8742
|
if (requestBodyEvidence(body, "openai-responses").state !== "complete" || body === void 0) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
|
|
8741
8743
|
const payload = JSON.parse(body);
|
|
8742
|
-
if (!record$
|
|
8744
|
+
if (!record$8(payload) || !Array.isArray(payload.input) || !payload.input.every(record$8)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
8743
8745
|
return {
|
|
8744
8746
|
input: payload.input,
|
|
8745
8747
|
payload
|
|
@@ -8835,7 +8837,7 @@ var ReplayRecoveryStore = class {
|
|
|
8835
8837
|
const value = hash(item);
|
|
8836
8838
|
return value === void 0 || !admitted.has(value);
|
|
8837
8839
|
}).length === decoded.input.length) return payload;
|
|
8838
|
-
if (!record$
|
|
8840
|
+
if (!record$8(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
8839
8841
|
const input = payload.input.filter((_, index) => {
|
|
8840
8842
|
const item = decoded.input[index];
|
|
8841
8843
|
const value = hash(item);
|
|
@@ -9035,7 +9037,7 @@ function installReplayRecovery(ctx, proof) {
|
|
|
9035
9037
|
}
|
|
9036
9038
|
//#endregion
|
|
9037
9039
|
//#region lib/types/agent-compaction.js
|
|
9038
|
-
function record$
|
|
9040
|
+
function record$7(value) {
|
|
9039
9041
|
return typeof value === "object" && value !== null;
|
|
9040
9042
|
}
|
|
9041
9043
|
/** Resolve the owning preset's service without reaching into Core's service registry. */
|
|
@@ -9043,7 +9045,7 @@ function agentCompaction(agent) {
|
|
|
9043
9045
|
if (typeof agent.ctx?.get !== "function") throw new LlmError("COPILOT_COMPACTION_AGENT_CONTEXT_UNAVAILABLE", "INVALID_REQUEST");
|
|
9044
9046
|
const presets = agent.ctx.get("agentPresets");
|
|
9045
9047
|
if (presets !== void 0) {
|
|
9046
|
-
if (!record$
|
|
9048
|
+
if (!record$7(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
|
|
9047
9049
|
const preset = presets.composedPreset(agent.ctx);
|
|
9048
9050
|
if (preset !== void 0) {
|
|
9049
9051
|
if (typeof preset !== "string" || preset.trim().length === 0) throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
|
|
@@ -9166,14 +9168,14 @@ function installCopilotCompactionPressure(ctx, callbacks) {
|
|
|
9166
9168
|
}
|
|
9167
9169
|
//#endregion
|
|
9168
9170
|
//#region lib/types/pre-step-pressure.js
|
|
9169
|
-
function record$
|
|
9171
|
+
function record$6(value) {
|
|
9170
9172
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9171
9173
|
}
|
|
9172
9174
|
function positive(value) {
|
|
9173
9175
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
9174
9176
|
}
|
|
9175
9177
|
function isEngine(value) {
|
|
9176
|
-
return record$
|
|
9178
|
+
return record$6(value) && record$6(value.config) && typeof value.compactIfNeeded === "function";
|
|
9177
9179
|
}
|
|
9178
9180
|
/**
|
|
9179
9181
|
* Prevent a continuing, unchanged route's known pressure from becoming an
|
|
@@ -9194,12 +9196,12 @@ function installCopilotPreStepPressure(ctx, callbacks) {
|
|
|
9194
9196
|
const header = agent.session.requestHeader();
|
|
9195
9197
|
if (header?.config.provider !== "github-copilot-preview" || !isPluginPreviewProvider(ctx, header.config.provider)) return decision;
|
|
9196
9198
|
const projections = ctx.get("sessionProjections");
|
|
9197
|
-
if (!record$
|
|
9199
|
+
if (!record$6(projections) || typeof projections.stateOf !== "function") {
|
|
9198
9200
|
unavailable();
|
|
9199
9201
|
return decision;
|
|
9200
9202
|
}
|
|
9201
9203
|
const selection = projections.stateOf(agent.session, "modelSelection");
|
|
9202
|
-
if (!record$
|
|
9204
|
+
if (!record$6(selection) || !Object.hasOwn(selection, "pending")) {
|
|
9203
9205
|
unavailable();
|
|
9204
9206
|
return decision;
|
|
9205
9207
|
}
|
|
@@ -9221,20 +9223,20 @@ function installCopilotPreStepPressure(ctx, callbacks) {
|
|
|
9221
9223
|
unavailable();
|
|
9222
9224
|
return decision;
|
|
9223
9225
|
}
|
|
9224
|
-
const policy = Array.isArray(config.modelPolicies) ? config.modelPolicies.find((value) => record$
|
|
9225
|
-
const retries = record$
|
|
9226
|
+
const policy = Array.isArray(config.modelPolicies) ? config.modelPolicies.find((value) => record$6(value) && value.provider === header.config.provider && value.model === header.config.model) : void 0;
|
|
9227
|
+
const retries = record$6(policy) ? policy.maxOverflowRetries ?? config.maxOverflowRetries : config.maxOverflowRetries;
|
|
9226
9228
|
if (retries === 0) return decision;
|
|
9227
9229
|
if (!positive(retries)) {
|
|
9228
9230
|
unavailable();
|
|
9229
9231
|
return decision;
|
|
9230
9232
|
}
|
|
9231
9233
|
const meter = ctx.get("tokenMeter");
|
|
9232
|
-
if (!record$
|
|
9234
|
+
if (!record$6(meter) || typeof meter.measure !== "function") {
|
|
9233
9235
|
unavailable();
|
|
9234
9236
|
return decision;
|
|
9235
9237
|
}
|
|
9236
9238
|
const measured = meter.measure(agent.session);
|
|
9237
|
-
if (!record$
|
|
9239
|
+
if (!record$6(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) {
|
|
9238
9240
|
unavailable();
|
|
9239
9241
|
return decision;
|
|
9240
9242
|
}
|
|
@@ -9352,17 +9354,17 @@ const TaskAssessmentSchema = z$1.object({
|
|
|
9352
9354
|
"insufficient-evidence"
|
|
9353
9355
|
])).max(7)
|
|
9354
9356
|
}).strict();
|
|
9355
|
-
function record$
|
|
9357
|
+
function record$5(value) {
|
|
9356
9358
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9357
9359
|
}
|
|
9358
9360
|
function text(message) {
|
|
9359
|
-
if (!record$
|
|
9360
|
-
return message.content.flatMap((block) => record$
|
|
9361
|
+
if (!record$5(message) || !Array.isArray(message.content)) return "";
|
|
9362
|
+
return message.content.flatMap((block) => record$5(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
|
|
9361
9363
|
}
|
|
9362
9364
|
function user(message) {
|
|
9363
|
-
if (!record$
|
|
9364
|
-
if (record$
|
|
9365
|
-
return message.role === "user" || record$
|
|
9365
|
+
if (!record$5(message)) return false;
|
|
9366
|
+
if (record$5(message.source) && message.source.kind === "model-selection") return false;
|
|
9367
|
+
return message.role === "user" || record$5(message.source) && message.source.kind === "user";
|
|
9366
9368
|
}
|
|
9367
9369
|
function difficult(current) {
|
|
9368
9370
|
return /\b(prove|proof|theorem|debug|investigate|diagnose)\b|证明|定理|调试|排查|根因|调查/iu.test(current);
|
|
@@ -9379,8 +9381,8 @@ function assessTaskLocally(messages) {
|
|
|
9379
9381
|
const last = messages.findLast(user);
|
|
9380
9382
|
const current = text(last).trim();
|
|
9381
9383
|
const history = messages.slice(0, last === void 0 ? 0 : messages.lastIndexOf(last));
|
|
9382
|
-
const hasWork = history.some((message) => record$
|
|
9383
|
-
const nonText = record$
|
|
9384
|
+
const hasWork = history.some((message) => record$5(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$5(message.source) && message.source.kind === "model"));
|
|
9385
|
+
const nonText = record$5(last) && Array.isArray(last.content) && last.content.some((block) => !record$5(block) || block.type !== "text");
|
|
9384
9386
|
if (!hasWork && !nonText && /^(hello|hi|hey|你好|您好|嗨)[!!。.\s]*$/iu.test(current)) return {
|
|
9385
9387
|
demand: "simple",
|
|
9386
9388
|
source: "local",
|
|
@@ -9422,7 +9424,7 @@ function assessTaskLocally(messages) {
|
|
|
9422
9424
|
/** Separate text-only projection for assessment; never mutates the chat request. */
|
|
9423
9425
|
function assessmentInput(messages) {
|
|
9424
9426
|
let omitted = false;
|
|
9425
|
-
const context = messages.filter((message) => !record$
|
|
9427
|
+
const context = messages.filter((message) => !record$5(message) || message.role !== "system" && message.role !== "developer" && !(record$5(message.source) && message.source.kind === "model-selection"));
|
|
9426
9428
|
const lastUser = context.findLastIndex(user);
|
|
9427
9429
|
const priorUser = context.slice(0, lastUser < 0 ? 0 : lastUser).findLastIndex(user);
|
|
9428
9430
|
const priority = [.../* @__PURE__ */ new Set([
|
|
@@ -9434,13 +9436,13 @@ function assessmentInput(messages) {
|
|
|
9434
9436
|
let length = 0;
|
|
9435
9437
|
for (const index of priority) {
|
|
9436
9438
|
const message = context[index];
|
|
9437
|
-
if (!record$
|
|
9439
|
+
if (!record$5(message)) {
|
|
9438
9440
|
omitted = true;
|
|
9439
9441
|
continue;
|
|
9440
9442
|
}
|
|
9441
9443
|
if (!Array.isArray(message.content)) omitted = true;
|
|
9442
9444
|
const content = text(message);
|
|
9443
|
-
if (Array.isArray(message.content) && message.content.some((block) => !record$
|
|
9445
|
+
if (Array.isArray(message.content) && message.content.some((block) => !record$5(block) || block.type !== "text")) omitted = true;
|
|
9444
9446
|
if (content.length > 1600) omitted = true;
|
|
9445
9447
|
const role = typeof message.role === "string" && [
|
|
9446
9448
|
"user",
|
|
@@ -9592,14 +9594,14 @@ var AutoModelRoutingError = class extends Error {
|
|
|
9592
9594
|
this.name = "AutoModelRoutingError";
|
|
9593
9595
|
}
|
|
9594
9596
|
};
|
|
9595
|
-
function record$
|
|
9597
|
+
function record$4(value) {
|
|
9596
9598
|
return typeof value === "object" && value !== null;
|
|
9597
9599
|
}
|
|
9598
9600
|
function userMessage(value) {
|
|
9599
|
-
if (!record$
|
|
9600
|
-
if (record$
|
|
9601
|
+
if (!record$4(value)) return false;
|
|
9602
|
+
if (record$4(value.source) && value.source.kind === "model-selection") return false;
|
|
9601
9603
|
if (value.role === "user") return true;
|
|
9602
|
-
return record$
|
|
9604
|
+
return record$4(value.source) && value.source.kind === "user";
|
|
9603
9605
|
}
|
|
9604
9606
|
function latestUserContent(messages) {
|
|
9605
9607
|
for (let index = messages.length - 1; index >= 0; index--) {
|
|
@@ -9610,9 +9612,9 @@ function latestUserContent(messages) {
|
|
|
9610
9612
|
}
|
|
9611
9613
|
function classifyAutoModelTurn(messages) {
|
|
9612
9614
|
let text = "";
|
|
9613
|
-
const requiresImage = messages.some((message) => record$
|
|
9615
|
+
const requiresImage = messages.some((message) => record$4(message) && Array.isArray(message.content) && message.content.some((block) => record$4(block) && block.type === "image" && block.offloaded !== true));
|
|
9614
9616
|
for (const block of latestUserContent(messages)) {
|
|
9615
|
-
if (!record$
|
|
9617
|
+
if (!record$4(block)) continue;
|
|
9616
9618
|
if (block.type === "text" && typeof block.text === "string") text += `${block.text}\n`;
|
|
9617
9619
|
}
|
|
9618
9620
|
const codeFenceCount = text.match(/```/gu)?.length ?? 0;
|
|
@@ -9662,7 +9664,7 @@ function resolveSeed(messages, context) {
|
|
|
9662
9664
|
if (typeof context?.seed === "string" && context.seed.length > 0) return fnv1a(context.seed);
|
|
9663
9665
|
if (context?.sessionId !== void 0) return fnv1a(`${context.sessionId}:${context.turn ?? 1}`);
|
|
9664
9666
|
let text = "";
|
|
9665
|
-
for (const block of latestUserContent(messages)) if (record$
|
|
9667
|
+
for (const block of latestUserContent(messages)) if (record$4(block) && typeof block.text === "string") text += block.text;
|
|
9666
9668
|
return fnv1a(text || "default-auto-seed");
|
|
9667
9669
|
}
|
|
9668
9670
|
function targetCategory(assessment, preference) {
|
|
@@ -9870,6 +9872,138 @@ var TurnSelectionStore = class {
|
|
|
9870
9872
|
}
|
|
9871
9873
|
};
|
|
9872
9874
|
//#endregion
|
|
9875
|
+
//#region lib/types/turn-request-models.js
|
|
9876
|
+
const TURN_REQUEST_MODELS = "githubCopilotTurnRequestModels";
|
|
9877
|
+
const count$1 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
9878
|
+
const route = z$1.object({
|
|
9879
|
+
provider: z$1.string().trim().min(1).max(1024),
|
|
9880
|
+
model: z$1.string().trim().min(1).max(1024)
|
|
9881
|
+
}).strict();
|
|
9882
|
+
const row = z$1.object({
|
|
9883
|
+
routes: z$1.array(route).max(32),
|
|
9884
|
+
incomplete: z$1.boolean()
|
|
9885
|
+
}).strict().extend({ turn: count$1 }).strict();
|
|
9886
|
+
const TurnRequestModelsStateSchema = z$1.object({
|
|
9887
|
+
active: z$1.object({
|
|
9888
|
+
turn: count$1,
|
|
9889
|
+
step: count$1.nullable()
|
|
9890
|
+
}).strict().nullable(),
|
|
9891
|
+
turns: z$1.array(row).max(128)
|
|
9892
|
+
}).strict();
|
|
9893
|
+
function record$3(value) {
|
|
9894
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9895
|
+
}
|
|
9896
|
+
const validCount = (value) => count$1.safeParse(value).success;
|
|
9897
|
+
function uncertain(state) {
|
|
9898
|
+
return {
|
|
9899
|
+
active: null,
|
|
9900
|
+
turns: state.turns.map((row) => row.turn === state.active?.turn ? {
|
|
9901
|
+
...row,
|
|
9902
|
+
routes: [],
|
|
9903
|
+
incomplete: true
|
|
9904
|
+
} : row)
|
|
9905
|
+
};
|
|
9906
|
+
}
|
|
9907
|
+
function foldTurnRequestModels(state, event) {
|
|
9908
|
+
if (!record$3(event)) return state;
|
|
9909
|
+
const lifecycle = [
|
|
9910
|
+
"turn/start",
|
|
9911
|
+
"turn/end",
|
|
9912
|
+
"step/start",
|
|
9913
|
+
"step/end"
|
|
9914
|
+
].includes(String(event.type));
|
|
9915
|
+
if (!record$3(event.data)) return lifecycle || event.type === "request/header" ? uncertain(state) : state;
|
|
9916
|
+
const data = event.data;
|
|
9917
|
+
if (lifecycle && (!validCount(data.turn) || event.type !== "turn/start" && state.active !== null && data.turn !== state.active.turn || String(event.type).startsWith("step/") && !validCount(data.step) || event.type === "step/start" && state.active?.step != null || event.type === "step/end" && state.active !== null && data.step !== state.active.step)) return uncertain(state);
|
|
9918
|
+
if (event.type === "turn/start" && validCount(data.turn)) return {
|
|
9919
|
+
active: {
|
|
9920
|
+
turn: data.turn,
|
|
9921
|
+
step: null
|
|
9922
|
+
},
|
|
9923
|
+
turns: [...state.turns.filter((row) => row.turn !== data.turn), {
|
|
9924
|
+
turn: data.turn,
|
|
9925
|
+
routes: [],
|
|
9926
|
+
incomplete: false
|
|
9927
|
+
}].slice(-128)
|
|
9928
|
+
};
|
|
9929
|
+
const active = state.active;
|
|
9930
|
+
if (!active) return state;
|
|
9931
|
+
if (event.type === "step/start" && data.turn === active.turn && validCount(data.step)) return {
|
|
9932
|
+
...state,
|
|
9933
|
+
active: {
|
|
9934
|
+
...active,
|
|
9935
|
+
step: data.step
|
|
9936
|
+
}
|
|
9937
|
+
};
|
|
9938
|
+
if (event.type === "step/end" && data.turn === active.turn && data.step === active.step) return {
|
|
9939
|
+
...state,
|
|
9940
|
+
active: {
|
|
9941
|
+
...active,
|
|
9942
|
+
step: null
|
|
9943
|
+
}
|
|
9944
|
+
};
|
|
9945
|
+
if (event.type === "turn/end" && data.turn === active.turn) return {
|
|
9946
|
+
...state,
|
|
9947
|
+
active: null
|
|
9948
|
+
};
|
|
9949
|
+
if (event.type !== "request/header" || active.step === null) return state;
|
|
9950
|
+
const config = record$3(data.header) ? data.header.config : void 0;
|
|
9951
|
+
const parsed = route.safeParse(record$3(config) && [
|
|
9952
|
+
"initial",
|
|
9953
|
+
"resume",
|
|
9954
|
+
"change",
|
|
9955
|
+
"series"
|
|
9956
|
+
].includes(String(data.reason)) ? {
|
|
9957
|
+
provider: config.provider,
|
|
9958
|
+
model: config.model
|
|
9959
|
+
} : void 0);
|
|
9960
|
+
return {
|
|
9961
|
+
...state,
|
|
9962
|
+
turns: state.turns.map((row) => {
|
|
9963
|
+
if (row.turn !== active.turn) return row;
|
|
9964
|
+
if (!parsed.success) return {
|
|
9965
|
+
...row,
|
|
9966
|
+
routes: [],
|
|
9967
|
+
incomplete: true
|
|
9968
|
+
};
|
|
9969
|
+
if (row.incomplete || row.routes.some((value) => value.provider === parsed.data.provider && value.model === parsed.data.model)) return row;
|
|
9970
|
+
if (row.routes.length >= 32) return {
|
|
9971
|
+
...row,
|
|
9972
|
+
routes: [],
|
|
9973
|
+
incomplete: true
|
|
9974
|
+
};
|
|
9975
|
+
return {
|
|
9976
|
+
...row,
|
|
9977
|
+
routes: [...row.routes, parsed.data]
|
|
9978
|
+
};
|
|
9979
|
+
})
|
|
9980
|
+
};
|
|
9981
|
+
}
|
|
9982
|
+
const turnRequestModelsDefinition = {
|
|
9983
|
+
key: TURN_REQUEST_MODELS,
|
|
9984
|
+
stateVersion: 1,
|
|
9985
|
+
stateSchema: TurnRequestModelsStateSchema,
|
|
9986
|
+
init: () => ({
|
|
9987
|
+
active: null,
|
|
9988
|
+
turns: []
|
|
9989
|
+
}),
|
|
9990
|
+
apply: foldTurnRequestModels
|
|
9991
|
+
};
|
|
9992
|
+
function installTurnRequestModels(ctx) {
|
|
9993
|
+
ctx.inject(["sessionProjections"], (scope) => {
|
|
9994
|
+
const registry = scope.get("sessionProjections");
|
|
9995
|
+
if (!record$3(registry) || typeof registry.register !== "function") {
|
|
9996
|
+
scope.logger.warn("[github-copilot] COPILOT_TURN_REQUEST_PROJECTION_UNAVAILABLE");
|
|
9997
|
+
return;
|
|
9998
|
+
}
|
|
9999
|
+
const remove = registry.register(turnRequestModelsDefinition);
|
|
10000
|
+
if (typeof remove !== "function") throw new Error("COPILOT_TURN_REQUEST_PROJECTION_DISPOSER_UNAVAILABLE");
|
|
10001
|
+
return () => {
|
|
10002
|
+
remove();
|
|
10003
|
+
};
|
|
10004
|
+
});
|
|
10005
|
+
}
|
|
10006
|
+
//#endregion
|
|
9873
10007
|
//#region lib/types/turn-selection-host.js
|
|
9874
10008
|
var __runInitializers = function(thisArg, initializers, value) {
|
|
9875
10009
|
var useValue = arguments.length > 2;
|
|
@@ -9911,15 +10045,20 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
|
|
|
9911
10045
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
9912
10046
|
done = true;
|
|
9913
10047
|
};
|
|
10048
|
+
function record$2(value) {
|
|
10049
|
+
return typeof value === "object" && value !== null;
|
|
10050
|
+
}
|
|
9914
10051
|
/** Public Host binding for the existing bounded, runtime-only decision store. */
|
|
9915
10052
|
let TurnSelectionController = (() => {
|
|
9916
10053
|
let _classSuper = TypertRemoteService;
|
|
9917
10054
|
let _instanceExtraInitializers = [];
|
|
9918
10055
|
let _get_decorators;
|
|
10056
|
+
let _requestedModels_decorators;
|
|
9919
10057
|
return class TurnSelectionController extends _classSuper {
|
|
9920
10058
|
static {
|
|
9921
10059
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
9922
10060
|
_get_decorators = [Remote];
|
|
10061
|
+
_requestedModels_decorators = [Remote];
|
|
9923
10062
|
__esDecorate(this, null, _get_decorators, {
|
|
9924
10063
|
kind: "method",
|
|
9925
10064
|
name: "get",
|
|
@@ -9931,6 +10070,17 @@ let TurnSelectionController = (() => {
|
|
|
9931
10070
|
},
|
|
9932
10071
|
metadata: _metadata
|
|
9933
10072
|
}, null, _instanceExtraInitializers);
|
|
10073
|
+
__esDecorate(this, null, _requestedModels_decorators, {
|
|
10074
|
+
kind: "method",
|
|
10075
|
+
name: "requestedModels",
|
|
10076
|
+
static: false,
|
|
10077
|
+
private: false,
|
|
10078
|
+
access: {
|
|
10079
|
+
has: (obj) => "requestedModels" in obj,
|
|
10080
|
+
get: (obj) => obj.requestedModels
|
|
10081
|
+
},
|
|
10082
|
+
metadata: _metadata
|
|
10083
|
+
}, null, _instanceExtraInitializers);
|
|
9934
10084
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
9935
10085
|
enumerable: true,
|
|
9936
10086
|
configurable: true,
|
|
@@ -9942,10 +10092,24 @@ let TurnSelectionController = (() => {
|
|
|
9942
10092
|
constructor(ctx, selections) {
|
|
9943
10093
|
super(ctx, "githubCopilotTurnSelection");
|
|
9944
10094
|
this.selections = selections;
|
|
10095
|
+
installTurnRequestModels(ctx);
|
|
9945
10096
|
}
|
|
9946
10097
|
get(agent, turn) {
|
|
9947
10098
|
return this.selections.get(agent, turn);
|
|
9948
10099
|
}
|
|
10100
|
+
requestedModels(agent, turn) {
|
|
10101
|
+
if (!Number.isSafeInteger(turn) || turn < 0) throw new Error("COPILOT_TURN_SELECTION_INVALID_TURN");
|
|
10102
|
+
const registry = this.ctx.get("sessionProjections");
|
|
10103
|
+
if (!record$2(registry) || typeof registry.stateOf !== "function") throw new Error("COPILOT_TURN_REQUEST_PROJECTION_UNAVAILABLE");
|
|
10104
|
+
const row = TurnRequestModelsStateSchema.parse(registry.stateOf(agent.session, TURN_REQUEST_MODELS)).turns.find((value) => value.turn === turn);
|
|
10105
|
+
return row ? {
|
|
10106
|
+
routes: row.routes,
|
|
10107
|
+
incomplete: row.incomplete
|
|
10108
|
+
} : {
|
|
10109
|
+
routes: [],
|
|
10110
|
+
incomplete: true
|
|
10111
|
+
};
|
|
10112
|
+
}
|
|
9949
10113
|
};
|
|
9950
10114
|
})();
|
|
9951
10115
|
//#endregion
|