dsh-github-copilot 0.4.0-alpha.105 → 0.4.0-alpha.106
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 +5 -0
- package/README.md +8 -6
- package/README.zh.md +8 -6
- package/deployment-baseline.json +9 -1
- package/docs/automatic-model-routing.md +29 -4
- package/lib/client.js +147 -17
- package/lib/client.js.map +1 -1
- package/lib/index.js +230 -68
- package/lib/remote.js +38 -0
- package/lib/types/context-evidence.d.ts +4 -4
- 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.106",
|
|
2993
2993
|
publishConfig: {
|
|
2994
2994
|
"access": "public",
|
|
2995
2995
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -5225,14 +5225,14 @@ function isZeroContextUsage(usage) {
|
|
|
5225
5225
|
//#endregion
|
|
5226
5226
|
//#region lib/types/context-evidence.js
|
|
5227
5227
|
const COPILOT_CONTEXT_EVIDENCE = "githubCopilotContextEvidence";
|
|
5228
|
-
const count$
|
|
5228
|
+
const count$2 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
5229
5229
|
const routeSchema = z$1.object({
|
|
5230
5230
|
provider: z$1.string().min(1),
|
|
5231
5231
|
model: z$1.string().min(1)
|
|
5232
5232
|
}).strict();
|
|
5233
5233
|
const sampleSchema = z$1.object({
|
|
5234
|
-
tokens: count$
|
|
5235
|
-
seq: count$
|
|
5234
|
+
tokens: count$2,
|
|
5235
|
+
seq: count$2,
|
|
5236
5236
|
route: routeSchema
|
|
5237
5237
|
}).strict();
|
|
5238
5238
|
const ContextEvidenceSchema = z$1.object({
|
|
@@ -5248,14 +5248,14 @@ const ContextEvidenceSchema = z$1.object({
|
|
|
5248
5248
|
])
|
|
5249
5249
|
}).strict();
|
|
5250
5250
|
const usageSchema = z$1.object({
|
|
5251
|
-
inputTokens: count$
|
|
5252
|
-
outputTokens: count$
|
|
5253
|
-
cacheReadTokens: count$
|
|
5254
|
-
cacheWriteTokens: count$
|
|
5255
|
-
totalTokens: count$
|
|
5256
|
-
reasoningTokens: count$
|
|
5251
|
+
inputTokens: count$2,
|
|
5252
|
+
outputTokens: count$2,
|
|
5253
|
+
cacheReadTokens: count$2.optional(),
|
|
5254
|
+
cacheWriteTokens: count$2.optional(),
|
|
5255
|
+
totalTokens: count$2.optional(),
|
|
5256
|
+
reasoningTokens: count$2.optional()
|
|
5257
5257
|
});
|
|
5258
|
-
function record$
|
|
5258
|
+
function record$10(value) {
|
|
5259
5259
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5260
5260
|
}
|
|
5261
5261
|
function sameRoute$1(left, right) {
|
|
@@ -5274,10 +5274,10 @@ function initialContextEvidence() {
|
|
|
5274
5274
|
}
|
|
5275
5275
|
/** Read only counts and routing leaves; never message content or opaque replay. */
|
|
5276
5276
|
function foldContextEvidence(state, event) {
|
|
5277
|
-
if (!record$
|
|
5277
|
+
if (!record$10(event) || typeof event.type !== "string" || !record$10(event.data)) return state;
|
|
5278
5278
|
if (event.type === "request/header" || event.type === "model/selection") {
|
|
5279
|
-
const raw = event.type === "request/header" ? record$
|
|
5280
|
-
if (!record$
|
|
5279
|
+
const raw = event.type === "request/header" ? record$10(event.data.header) ? event.data.header.config : void 0 : event.data;
|
|
5280
|
+
if (!record$10(raw)) return {
|
|
5281
5281
|
...state,
|
|
5282
5282
|
route: null,
|
|
5283
5283
|
sample: null,
|
|
@@ -5316,7 +5316,7 @@ function foldContextEvidence(state, event) {
|
|
|
5316
5316
|
if (!copilot(state.route)) return state;
|
|
5317
5317
|
if (event.type === "assistant/message" && event.data.source !== void 0) {
|
|
5318
5318
|
const source = event.data.source;
|
|
5319
|
-
const parsed = routeSchema.safeParse(record$
|
|
5319
|
+
const parsed = routeSchema.safeParse(record$10(source) ? {
|
|
5320
5320
|
provider: source.provider,
|
|
5321
5321
|
model: source.model
|
|
5322
5322
|
} : source);
|
|
@@ -5332,13 +5332,13 @@ function foldContextEvidence(state, event) {
|
|
|
5332
5332
|
const settledUsage = usage !== void 0;
|
|
5333
5333
|
let terminal;
|
|
5334
5334
|
for (const entry of stream) {
|
|
5335
|
-
if (!record$
|
|
5335
|
+
if (!record$10(entry) || entry.type !== "chunk" || !record$10(entry.chunk)) continue;
|
|
5336
5336
|
if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
|
|
5337
5337
|
if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
|
|
5338
5338
|
}
|
|
5339
5339
|
if (usage === void 0) return state;
|
|
5340
5340
|
const parsed = usageSchema.safeParse(usage);
|
|
5341
|
-
if (!parsed.success || !count$
|
|
5341
|
+
if (!parsed.success || !count$2.safeParse(event.seq).success) return {
|
|
5342
5342
|
...state,
|
|
5343
5343
|
sample: null,
|
|
5344
5344
|
invalid: true,
|
|
@@ -5346,7 +5346,7 @@ function foldContextEvidence(state, event) {
|
|
|
5346
5346
|
};
|
|
5347
5347
|
const value = parsed.data;
|
|
5348
5348
|
const zero = isZeroContextUsage(value);
|
|
5349
|
-
const successful = record$
|
|
5349
|
+
const successful = record$10(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
|
|
5350
5350
|
if (zero && !successful) {
|
|
5351
5351
|
const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
|
|
5352
5352
|
return {
|
|
@@ -5366,7 +5366,7 @@ function foldContextEvidence(state, event) {
|
|
|
5366
5366
|
...state,
|
|
5367
5367
|
sample: {
|
|
5368
5368
|
tokens,
|
|
5369
|
-
seq: count$
|
|
5369
|
+
seq: count$2.parse(event.seq),
|
|
5370
5370
|
route: state.route
|
|
5371
5371
|
},
|
|
5372
5372
|
invalid: false,
|
|
@@ -5388,7 +5388,7 @@ const contextEvidenceDefinition = {
|
|
|
5388
5388
|
function installContextEvidence(ctx) {
|
|
5389
5389
|
ctx.inject(["sessionProjections"], (scope) => {
|
|
5390
5390
|
const registry = scope.get("sessionProjections");
|
|
5391
|
-
if (!record$
|
|
5391
|
+
if (!record$10(registry) || typeof registry.register !== "function") {
|
|
5392
5392
|
scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
|
|
5393
5393
|
return;
|
|
5394
5394
|
}
|
|
@@ -6421,7 +6421,7 @@ function buildAnthropicWireBody(request, cfg, model) {
|
|
|
6421
6421
|
}
|
|
6422
6422
|
//#endregion
|
|
6423
6423
|
//#region lib/types/responses-reasoning-text.js
|
|
6424
|
-
function record$
|
|
6424
|
+
function record$9(value) {
|
|
6425
6425
|
return typeof value === "object" && value !== null;
|
|
6426
6426
|
}
|
|
6427
6427
|
function responseIndex(value) {
|
|
@@ -6479,13 +6479,13 @@ var ResponsesReasoningText = class {
|
|
|
6479
6479
|
}
|
|
6480
6480
|
/** Only recognized public text fields are examined; no copying of the item. */
|
|
6481
6481
|
snapshot(item) {
|
|
6482
|
-
if (!record$
|
|
6482
|
+
if (!record$9(item) || item.type !== "reasoning") return "";
|
|
6483
6483
|
let delta = "";
|
|
6484
6484
|
for (const family of ["summary", "raw"]) {
|
|
6485
6485
|
const value = family === "summary" ? item.summary : item.content;
|
|
6486
6486
|
if (!Array.isArray(value)) continue;
|
|
6487
6487
|
for (const [index, part] of value.entries()) {
|
|
6488
|
-
if (!record$
|
|
6488
|
+
if (!record$9(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
|
|
6489
6489
|
delta += this.update(family, index, part.text, true);
|
|
6490
6490
|
}
|
|
6491
6491
|
}
|
|
@@ -8733,13 +8733,13 @@ function resolveCopilotResponsesReasoning(ctx, request, candidate) {
|
|
|
8733
8733
|
}
|
|
8734
8734
|
//#endregion
|
|
8735
8735
|
//#region lib/types/replay-recovery.js
|
|
8736
|
-
function record$
|
|
8736
|
+
function record$8(value) {
|
|
8737
8737
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8738
8738
|
}
|
|
8739
8739
|
function parsed(body) {
|
|
8740
8740
|
if (requestBodyEvidence(body, "openai-responses").state !== "complete" || body === void 0) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
|
|
8741
8741
|
const payload = JSON.parse(body);
|
|
8742
|
-
if (!record$
|
|
8742
|
+
if (!record$8(payload) || !Array.isArray(payload.input) || !payload.input.every(record$8)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
8743
8743
|
return {
|
|
8744
8744
|
input: payload.input,
|
|
8745
8745
|
payload
|
|
@@ -8835,7 +8835,7 @@ var ReplayRecoveryStore = class {
|
|
|
8835
8835
|
const value = hash(item);
|
|
8836
8836
|
return value === void 0 || !admitted.has(value);
|
|
8837
8837
|
}).length === decoded.input.length) return payload;
|
|
8838
|
-
if (!record$
|
|
8838
|
+
if (!record$8(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
8839
8839
|
const input = payload.input.filter((_, index) => {
|
|
8840
8840
|
const item = decoded.input[index];
|
|
8841
8841
|
const value = hash(item);
|
|
@@ -9035,7 +9035,7 @@ function installReplayRecovery(ctx, proof) {
|
|
|
9035
9035
|
}
|
|
9036
9036
|
//#endregion
|
|
9037
9037
|
//#region lib/types/agent-compaction.js
|
|
9038
|
-
function record$
|
|
9038
|
+
function record$7(value) {
|
|
9039
9039
|
return typeof value === "object" && value !== null;
|
|
9040
9040
|
}
|
|
9041
9041
|
/** Resolve the owning preset's service without reaching into Core's service registry. */
|
|
@@ -9043,7 +9043,7 @@ function agentCompaction(agent) {
|
|
|
9043
9043
|
if (typeof agent.ctx?.get !== "function") throw new LlmError("COPILOT_COMPACTION_AGENT_CONTEXT_UNAVAILABLE", "INVALID_REQUEST");
|
|
9044
9044
|
const presets = agent.ctx.get("agentPresets");
|
|
9045
9045
|
if (presets !== void 0) {
|
|
9046
|
-
if (!record$
|
|
9046
|
+
if (!record$7(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
|
|
9047
9047
|
const preset = presets.composedPreset(agent.ctx);
|
|
9048
9048
|
if (preset !== void 0) {
|
|
9049
9049
|
if (typeof preset !== "string" || preset.trim().length === 0) throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
|
|
@@ -9166,14 +9166,14 @@ function installCopilotCompactionPressure(ctx, callbacks) {
|
|
|
9166
9166
|
}
|
|
9167
9167
|
//#endregion
|
|
9168
9168
|
//#region lib/types/pre-step-pressure.js
|
|
9169
|
-
function record$
|
|
9169
|
+
function record$6(value) {
|
|
9170
9170
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9171
9171
|
}
|
|
9172
9172
|
function positive(value) {
|
|
9173
9173
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
9174
9174
|
}
|
|
9175
9175
|
function isEngine(value) {
|
|
9176
|
-
return record$
|
|
9176
|
+
return record$6(value) && record$6(value.config) && typeof value.compactIfNeeded === "function";
|
|
9177
9177
|
}
|
|
9178
9178
|
/**
|
|
9179
9179
|
* Prevent a continuing, unchanged route's known pressure from becoming an
|
|
@@ -9194,12 +9194,12 @@ function installCopilotPreStepPressure(ctx, callbacks) {
|
|
|
9194
9194
|
const header = agent.session.requestHeader();
|
|
9195
9195
|
if (header?.config.provider !== "github-copilot-preview" || !isPluginPreviewProvider(ctx, header.config.provider)) return decision;
|
|
9196
9196
|
const projections = ctx.get("sessionProjections");
|
|
9197
|
-
if (!record$
|
|
9197
|
+
if (!record$6(projections) || typeof projections.stateOf !== "function") {
|
|
9198
9198
|
unavailable();
|
|
9199
9199
|
return decision;
|
|
9200
9200
|
}
|
|
9201
9201
|
const selection = projections.stateOf(agent.session, "modelSelection");
|
|
9202
|
-
if (!record$
|
|
9202
|
+
if (!record$6(selection) || !Object.hasOwn(selection, "pending")) {
|
|
9203
9203
|
unavailable();
|
|
9204
9204
|
return decision;
|
|
9205
9205
|
}
|
|
@@ -9221,20 +9221,20 @@ function installCopilotPreStepPressure(ctx, callbacks) {
|
|
|
9221
9221
|
unavailable();
|
|
9222
9222
|
return decision;
|
|
9223
9223
|
}
|
|
9224
|
-
const policy = Array.isArray(config.modelPolicies) ? config.modelPolicies.find((value) => record$
|
|
9225
|
-
const retries = record$
|
|
9224
|
+
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;
|
|
9225
|
+
const retries = record$6(policy) ? policy.maxOverflowRetries ?? config.maxOverflowRetries : config.maxOverflowRetries;
|
|
9226
9226
|
if (retries === 0) return decision;
|
|
9227
9227
|
if (!positive(retries)) {
|
|
9228
9228
|
unavailable();
|
|
9229
9229
|
return decision;
|
|
9230
9230
|
}
|
|
9231
9231
|
const meter = ctx.get("tokenMeter");
|
|
9232
|
-
if (!record$
|
|
9232
|
+
if (!record$6(meter) || typeof meter.measure !== "function") {
|
|
9233
9233
|
unavailable();
|
|
9234
9234
|
return decision;
|
|
9235
9235
|
}
|
|
9236
9236
|
const measured = meter.measure(agent.session);
|
|
9237
|
-
if (!record$
|
|
9237
|
+
if (!record$6(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) {
|
|
9238
9238
|
unavailable();
|
|
9239
9239
|
return decision;
|
|
9240
9240
|
}
|
|
@@ -9352,17 +9352,17 @@ const TaskAssessmentSchema = z$1.object({
|
|
|
9352
9352
|
"insufficient-evidence"
|
|
9353
9353
|
])).max(7)
|
|
9354
9354
|
}).strict();
|
|
9355
|
-
function record$
|
|
9355
|
+
function record$5(value) {
|
|
9356
9356
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9357
9357
|
}
|
|
9358
9358
|
function text(message) {
|
|
9359
|
-
if (!record$
|
|
9360
|
-
return message.content.flatMap((block) => record$
|
|
9359
|
+
if (!record$5(message) || !Array.isArray(message.content)) return "";
|
|
9360
|
+
return message.content.flatMap((block) => record$5(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
|
|
9361
9361
|
}
|
|
9362
9362
|
function user(message) {
|
|
9363
|
-
if (!record$
|
|
9364
|
-
if (record$
|
|
9365
|
-
return message.role === "user" || record$
|
|
9363
|
+
if (!record$5(message)) return false;
|
|
9364
|
+
if (record$5(message.source) && message.source.kind === "model-selection") return false;
|
|
9365
|
+
return message.role === "user" || record$5(message.source) && message.source.kind === "user";
|
|
9366
9366
|
}
|
|
9367
9367
|
function difficult(current) {
|
|
9368
9368
|
return /\b(prove|proof|theorem|debug|investigate|diagnose)\b|证明|定理|调试|排查|根因|调查/iu.test(current);
|
|
@@ -9379,8 +9379,8 @@ function assessTaskLocally(messages) {
|
|
|
9379
9379
|
const last = messages.findLast(user);
|
|
9380
9380
|
const current = text(last).trim();
|
|
9381
9381
|
const history = messages.slice(0, last === void 0 ? 0 : messages.lastIndexOf(last));
|
|
9382
|
-
const hasWork = history.some((message) => record$
|
|
9383
|
-
const nonText = record$
|
|
9382
|
+
const hasWork = history.some((message) => record$5(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$5(message.source) && message.source.kind === "model"));
|
|
9383
|
+
const nonText = record$5(last) && Array.isArray(last.content) && last.content.some((block) => !record$5(block) || block.type !== "text");
|
|
9384
9384
|
if (!hasWork && !nonText && /^(hello|hi|hey|你好|您好|嗨)[!!。.\s]*$/iu.test(current)) return {
|
|
9385
9385
|
demand: "simple",
|
|
9386
9386
|
source: "local",
|
|
@@ -9422,7 +9422,7 @@ function assessTaskLocally(messages) {
|
|
|
9422
9422
|
/** Separate text-only projection for assessment; never mutates the chat request. */
|
|
9423
9423
|
function assessmentInput(messages) {
|
|
9424
9424
|
let omitted = false;
|
|
9425
|
-
const context = messages.filter((message) => !record$
|
|
9425
|
+
const context = messages.filter((message) => !record$5(message) || message.role !== "system" && message.role !== "developer" && !(record$5(message.source) && message.source.kind === "model-selection"));
|
|
9426
9426
|
const lastUser = context.findLastIndex(user);
|
|
9427
9427
|
const priorUser = context.slice(0, lastUser < 0 ? 0 : lastUser).findLastIndex(user);
|
|
9428
9428
|
const priority = [.../* @__PURE__ */ new Set([
|
|
@@ -9434,13 +9434,13 @@ function assessmentInput(messages) {
|
|
|
9434
9434
|
let length = 0;
|
|
9435
9435
|
for (const index of priority) {
|
|
9436
9436
|
const message = context[index];
|
|
9437
|
-
if (!record$
|
|
9437
|
+
if (!record$5(message)) {
|
|
9438
9438
|
omitted = true;
|
|
9439
9439
|
continue;
|
|
9440
9440
|
}
|
|
9441
9441
|
if (!Array.isArray(message.content)) omitted = true;
|
|
9442
9442
|
const content = text(message);
|
|
9443
|
-
if (Array.isArray(message.content) && message.content.some((block) => !record$
|
|
9443
|
+
if (Array.isArray(message.content) && message.content.some((block) => !record$5(block) || block.type !== "text")) omitted = true;
|
|
9444
9444
|
if (content.length > 1600) omitted = true;
|
|
9445
9445
|
const role = typeof message.role === "string" && [
|
|
9446
9446
|
"user",
|
|
@@ -9592,14 +9592,14 @@ var AutoModelRoutingError = class extends Error {
|
|
|
9592
9592
|
this.name = "AutoModelRoutingError";
|
|
9593
9593
|
}
|
|
9594
9594
|
};
|
|
9595
|
-
function record$
|
|
9595
|
+
function record$4(value) {
|
|
9596
9596
|
return typeof value === "object" && value !== null;
|
|
9597
9597
|
}
|
|
9598
9598
|
function userMessage(value) {
|
|
9599
|
-
if (!record$
|
|
9600
|
-
if (record$
|
|
9599
|
+
if (!record$4(value)) return false;
|
|
9600
|
+
if (record$4(value.source) && value.source.kind === "model-selection") return false;
|
|
9601
9601
|
if (value.role === "user") return true;
|
|
9602
|
-
return record$
|
|
9602
|
+
return record$4(value.source) && value.source.kind === "user";
|
|
9603
9603
|
}
|
|
9604
9604
|
function latestUserContent(messages) {
|
|
9605
9605
|
for (let index = messages.length - 1; index >= 0; index--) {
|
|
@@ -9610,9 +9610,9 @@ function latestUserContent(messages) {
|
|
|
9610
9610
|
}
|
|
9611
9611
|
function classifyAutoModelTurn(messages) {
|
|
9612
9612
|
let text = "";
|
|
9613
|
-
const requiresImage = messages.some((message) => record$
|
|
9613
|
+
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
9614
|
for (const block of latestUserContent(messages)) {
|
|
9615
|
-
if (!record$
|
|
9615
|
+
if (!record$4(block)) continue;
|
|
9616
9616
|
if (block.type === "text" && typeof block.text === "string") text += `${block.text}\n`;
|
|
9617
9617
|
}
|
|
9618
9618
|
const codeFenceCount = text.match(/```/gu)?.length ?? 0;
|
|
@@ -9662,7 +9662,7 @@ function resolveSeed(messages, context) {
|
|
|
9662
9662
|
if (typeof context?.seed === "string" && context.seed.length > 0) return fnv1a(context.seed);
|
|
9663
9663
|
if (context?.sessionId !== void 0) return fnv1a(`${context.sessionId}:${context.turn ?? 1}`);
|
|
9664
9664
|
let text = "";
|
|
9665
|
-
for (const block of latestUserContent(messages)) if (record$
|
|
9665
|
+
for (const block of latestUserContent(messages)) if (record$4(block) && typeof block.text === "string") text += block.text;
|
|
9666
9666
|
return fnv1a(text || "default-auto-seed");
|
|
9667
9667
|
}
|
|
9668
9668
|
function targetCategory(assessment, preference) {
|
|
@@ -9870,6 +9870,138 @@ var TurnSelectionStore = class {
|
|
|
9870
9870
|
}
|
|
9871
9871
|
};
|
|
9872
9872
|
//#endregion
|
|
9873
|
+
//#region lib/types/turn-request-models.js
|
|
9874
|
+
const TURN_REQUEST_MODELS = "githubCopilotTurnRequestModels";
|
|
9875
|
+
const count$1 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
9876
|
+
const route = z$1.object({
|
|
9877
|
+
provider: z$1.string().trim().min(1).max(1024),
|
|
9878
|
+
model: z$1.string().trim().min(1).max(1024)
|
|
9879
|
+
}).strict();
|
|
9880
|
+
const row = z$1.object({
|
|
9881
|
+
routes: z$1.array(route).max(32),
|
|
9882
|
+
incomplete: z$1.boolean()
|
|
9883
|
+
}).strict().extend({ turn: count$1 }).strict();
|
|
9884
|
+
const TurnRequestModelsStateSchema = z$1.object({
|
|
9885
|
+
active: z$1.object({
|
|
9886
|
+
turn: count$1,
|
|
9887
|
+
step: count$1.nullable()
|
|
9888
|
+
}).strict().nullable(),
|
|
9889
|
+
turns: z$1.array(row).max(128)
|
|
9890
|
+
}).strict();
|
|
9891
|
+
function record$3(value) {
|
|
9892
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9893
|
+
}
|
|
9894
|
+
const validCount = (value) => count$1.safeParse(value).success;
|
|
9895
|
+
function uncertain(state) {
|
|
9896
|
+
return {
|
|
9897
|
+
active: null,
|
|
9898
|
+
turns: state.turns.map((row) => row.turn === state.active?.turn ? {
|
|
9899
|
+
...row,
|
|
9900
|
+
routes: [],
|
|
9901
|
+
incomplete: true
|
|
9902
|
+
} : row)
|
|
9903
|
+
};
|
|
9904
|
+
}
|
|
9905
|
+
function foldTurnRequestModels(state, event) {
|
|
9906
|
+
if (!record$3(event)) return state;
|
|
9907
|
+
const lifecycle = [
|
|
9908
|
+
"turn/start",
|
|
9909
|
+
"turn/end",
|
|
9910
|
+
"step/start",
|
|
9911
|
+
"step/end"
|
|
9912
|
+
].includes(String(event.type));
|
|
9913
|
+
if (!record$3(event.data)) return lifecycle || event.type === "request/header" ? uncertain(state) : state;
|
|
9914
|
+
const data = event.data;
|
|
9915
|
+
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);
|
|
9916
|
+
if (event.type === "turn/start" && validCount(data.turn)) return {
|
|
9917
|
+
active: {
|
|
9918
|
+
turn: data.turn,
|
|
9919
|
+
step: null
|
|
9920
|
+
},
|
|
9921
|
+
turns: [...state.turns.filter((row) => row.turn !== data.turn), {
|
|
9922
|
+
turn: data.turn,
|
|
9923
|
+
routes: [],
|
|
9924
|
+
incomplete: false
|
|
9925
|
+
}].slice(-128)
|
|
9926
|
+
};
|
|
9927
|
+
const active = state.active;
|
|
9928
|
+
if (!active) return state;
|
|
9929
|
+
if (event.type === "step/start" && data.turn === active.turn && validCount(data.step)) return {
|
|
9930
|
+
...state,
|
|
9931
|
+
active: {
|
|
9932
|
+
...active,
|
|
9933
|
+
step: data.step
|
|
9934
|
+
}
|
|
9935
|
+
};
|
|
9936
|
+
if (event.type === "step/end" && data.turn === active.turn && data.step === active.step) return {
|
|
9937
|
+
...state,
|
|
9938
|
+
active: {
|
|
9939
|
+
...active,
|
|
9940
|
+
step: null
|
|
9941
|
+
}
|
|
9942
|
+
};
|
|
9943
|
+
if (event.type === "turn/end" && data.turn === active.turn) return {
|
|
9944
|
+
...state,
|
|
9945
|
+
active: null
|
|
9946
|
+
};
|
|
9947
|
+
if (event.type !== "request/header" || active.step === null) return state;
|
|
9948
|
+
const config = record$3(data.header) ? data.header.config : void 0;
|
|
9949
|
+
const parsed = route.safeParse(record$3(config) && [
|
|
9950
|
+
"initial",
|
|
9951
|
+
"resume",
|
|
9952
|
+
"change",
|
|
9953
|
+
"series"
|
|
9954
|
+
].includes(String(data.reason)) ? {
|
|
9955
|
+
provider: config.provider,
|
|
9956
|
+
model: config.model
|
|
9957
|
+
} : void 0);
|
|
9958
|
+
return {
|
|
9959
|
+
...state,
|
|
9960
|
+
turns: state.turns.map((row) => {
|
|
9961
|
+
if (row.turn !== active.turn) return row;
|
|
9962
|
+
if (!parsed.success) return {
|
|
9963
|
+
...row,
|
|
9964
|
+
routes: [],
|
|
9965
|
+
incomplete: true
|
|
9966
|
+
};
|
|
9967
|
+
if (row.incomplete || row.routes.some((value) => value.provider === parsed.data.provider && value.model === parsed.data.model)) return row;
|
|
9968
|
+
if (row.routes.length >= 32) return {
|
|
9969
|
+
...row,
|
|
9970
|
+
routes: [],
|
|
9971
|
+
incomplete: true
|
|
9972
|
+
};
|
|
9973
|
+
return {
|
|
9974
|
+
...row,
|
|
9975
|
+
routes: [...row.routes, parsed.data]
|
|
9976
|
+
};
|
|
9977
|
+
})
|
|
9978
|
+
};
|
|
9979
|
+
}
|
|
9980
|
+
const turnRequestModelsDefinition = {
|
|
9981
|
+
key: TURN_REQUEST_MODELS,
|
|
9982
|
+
stateVersion: 1,
|
|
9983
|
+
stateSchema: TurnRequestModelsStateSchema,
|
|
9984
|
+
init: () => ({
|
|
9985
|
+
active: null,
|
|
9986
|
+
turns: []
|
|
9987
|
+
}),
|
|
9988
|
+
apply: foldTurnRequestModels
|
|
9989
|
+
};
|
|
9990
|
+
function installTurnRequestModels(ctx) {
|
|
9991
|
+
ctx.inject(["sessionProjections"], (scope) => {
|
|
9992
|
+
const registry = scope.get("sessionProjections");
|
|
9993
|
+
if (!record$3(registry) || typeof registry.register !== "function") {
|
|
9994
|
+
scope.logger.warn("[github-copilot] COPILOT_TURN_REQUEST_PROJECTION_UNAVAILABLE");
|
|
9995
|
+
return;
|
|
9996
|
+
}
|
|
9997
|
+
const remove = registry.register(turnRequestModelsDefinition);
|
|
9998
|
+
if (typeof remove !== "function") throw new Error("COPILOT_TURN_REQUEST_PROJECTION_DISPOSER_UNAVAILABLE");
|
|
9999
|
+
return () => {
|
|
10000
|
+
remove();
|
|
10001
|
+
};
|
|
10002
|
+
});
|
|
10003
|
+
}
|
|
10004
|
+
//#endregion
|
|
9873
10005
|
//#region lib/types/turn-selection-host.js
|
|
9874
10006
|
var __runInitializers = function(thisArg, initializers, value) {
|
|
9875
10007
|
var useValue = arguments.length > 2;
|
|
@@ -9911,15 +10043,20 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
|
|
|
9911
10043
|
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
9912
10044
|
done = true;
|
|
9913
10045
|
};
|
|
10046
|
+
function record$2(value) {
|
|
10047
|
+
return typeof value === "object" && value !== null;
|
|
10048
|
+
}
|
|
9914
10049
|
/** Public Host binding for the existing bounded, runtime-only decision store. */
|
|
9915
10050
|
let TurnSelectionController = (() => {
|
|
9916
10051
|
let _classSuper = TypertRemoteService;
|
|
9917
10052
|
let _instanceExtraInitializers = [];
|
|
9918
10053
|
let _get_decorators;
|
|
10054
|
+
let _requestedModels_decorators;
|
|
9919
10055
|
return class TurnSelectionController extends _classSuper {
|
|
9920
10056
|
static {
|
|
9921
10057
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
9922
10058
|
_get_decorators = [Remote];
|
|
10059
|
+
_requestedModels_decorators = [Remote];
|
|
9923
10060
|
__esDecorate(this, null, _get_decorators, {
|
|
9924
10061
|
kind: "method",
|
|
9925
10062
|
name: "get",
|
|
@@ -9931,6 +10068,17 @@ let TurnSelectionController = (() => {
|
|
|
9931
10068
|
},
|
|
9932
10069
|
metadata: _metadata
|
|
9933
10070
|
}, null, _instanceExtraInitializers);
|
|
10071
|
+
__esDecorate(this, null, _requestedModels_decorators, {
|
|
10072
|
+
kind: "method",
|
|
10073
|
+
name: "requestedModels",
|
|
10074
|
+
static: false,
|
|
10075
|
+
private: false,
|
|
10076
|
+
access: {
|
|
10077
|
+
has: (obj) => "requestedModels" in obj,
|
|
10078
|
+
get: (obj) => obj.requestedModels
|
|
10079
|
+
},
|
|
10080
|
+
metadata: _metadata
|
|
10081
|
+
}, null, _instanceExtraInitializers);
|
|
9934
10082
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
9935
10083
|
enumerable: true,
|
|
9936
10084
|
configurable: true,
|
|
@@ -9942,10 +10090,24 @@ let TurnSelectionController = (() => {
|
|
|
9942
10090
|
constructor(ctx, selections) {
|
|
9943
10091
|
super(ctx, "githubCopilotTurnSelection");
|
|
9944
10092
|
this.selections = selections;
|
|
10093
|
+
installTurnRequestModels(ctx);
|
|
9945
10094
|
}
|
|
9946
10095
|
get(agent, turn) {
|
|
9947
10096
|
return this.selections.get(agent, turn);
|
|
9948
10097
|
}
|
|
10098
|
+
requestedModels(agent, turn) {
|
|
10099
|
+
if (!Number.isSafeInteger(turn) || turn < 0) throw new Error("COPILOT_TURN_SELECTION_INVALID_TURN");
|
|
10100
|
+
const registry = this.ctx.get("sessionProjections");
|
|
10101
|
+
if (!record$2(registry) || typeof registry.stateOf !== "function") throw new Error("COPILOT_TURN_REQUEST_PROJECTION_UNAVAILABLE");
|
|
10102
|
+
const row = TurnRequestModelsStateSchema.parse(registry.stateOf(agent.session, TURN_REQUEST_MODELS)).turns.find((value) => value.turn === turn);
|
|
10103
|
+
return row ? {
|
|
10104
|
+
routes: row.routes,
|
|
10105
|
+
incomplete: row.incomplete
|
|
10106
|
+
} : {
|
|
10107
|
+
routes: [],
|
|
10108
|
+
incomplete: true
|
|
10109
|
+
};
|
|
10110
|
+
}
|
|
9949
10111
|
};
|
|
9950
10112
|
})();
|
|
9951
10113
|
//#endregion
|