dsh-github-copilot 0.4.0-alpha.120 → 0.4.0-alpha.122
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 +21 -0
- package/CHANGELOG.md +6 -0
- package/README.md +8 -6
- package/README.zh.md +8 -6
- package/deployment-baseline.json +10 -1
- package/docs/auto-high-cost.md +22 -0
- package/docs/copilot-compaction.md +9 -0
- package/docs/manual-compaction-recovery.md +13 -0
- package/docs/session-continuation.md +25 -2
- package/lib/client.js +99 -5
- package/lib/client.js.map +1 -1
- package/lib/index.js +228 -37
- package/lib/manual-compaction-recovery.js +55 -13
- package/lib/remote.js +16 -1
- package/lib/types/background-compaction.d.ts +2 -2
- package/lib/types/compaction-continuation-ui.d.ts +11 -0
- package/lib/types/compaction-continuation.d.ts +48 -0
- package/lib/types/compaction-replay.d.ts +18 -0
- package/lib/types/manual-compaction-recovery.d.ts +2 -0
- package/lib/types/preview-route.d.ts +1 -0
- package/lib/types/session-continuation-host.d.ts +4 -1
- package/lib/types/session-continuation-types.d.ts +27 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1349,7 +1349,7 @@ var Budget = class {
|
|
|
1349
1349
|
if (this.consumed > ACCOUNT_MODEL_CATALOG_LIMITS.maxBytes) fail$1("CATALOG_TOO_LARGE", true);
|
|
1350
1350
|
}
|
|
1351
1351
|
};
|
|
1352
|
-
function record$
|
|
1352
|
+
function record$14(value, code) {
|
|
1353
1353
|
if (typeof value !== "object" || value === null || Array.isArray(value)) fail$1(code);
|
|
1354
1354
|
return value;
|
|
1355
1355
|
}
|
|
@@ -1402,11 +1402,11 @@ function normalizeModel(raw, id, options, budget) {
|
|
|
1402
1402
|
if (options.availableModelIds?.has(id) !== true) fail$1("MISSING_POLICY");
|
|
1403
1403
|
policySource = "account-available-id";
|
|
1404
1404
|
} else {
|
|
1405
|
-
if (text$2(field(record$
|
|
1405
|
+
if (text$2(field(record$14(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail$1("POLICY_NOT_ENABLED");
|
|
1406
1406
|
policySource = "server-enabled";
|
|
1407
1407
|
}
|
|
1408
|
-
const capabilities = record$
|
|
1409
|
-
const supports = record$
|
|
1408
|
+
const capabilities = record$14(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
|
|
1409
|
+
const supports = record$14(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
|
|
1410
1410
|
const streaming = field(supports, "streaming", budget);
|
|
1411
1411
|
if (streaming === false) fail$1("STREAMING_UNSUPPORTED");
|
|
1412
1412
|
if (streaming !== true) fail$1("INVALID_SUPPORTS");
|
|
@@ -1427,7 +1427,7 @@ function normalizeModel(raw, id, options, budget) {
|
|
|
1427
1427
|
if (selected === void 0) fail$1(unsupportedEndpointCount === 0 && endpoints.includes("ws:/responses") ? "WEBSOCKET_ONLY" : "UNSUPPORTED_ENDPOINTS");
|
|
1428
1428
|
const rawLimits = field(capabilities, "limits", budget);
|
|
1429
1429
|
if (rawLimits === void 0) fail$1("MISSING_LIMITS");
|
|
1430
|
-
const limits = record$
|
|
1430
|
+
const limits = record$14(rawLimits, "INVALID_LIMITS");
|
|
1431
1431
|
const maxContext = optionalPositive(limits, "max_context_window_tokens", "INVALID_LIMITS", budget);
|
|
1432
1432
|
const maxInputTokens = optionalPositive(limits, "max_prompt_tokens", "INVALID_LIMITS", budget);
|
|
1433
1433
|
if (maxContext === void 0 && maxInputTokens === void 0) fail$1("MISSING_CONTEXT_LIMIT");
|
|
@@ -1445,7 +1445,7 @@ function normalizeModel(raw, id, options, budget) {
|
|
|
1445
1445
|
if (vision === true) {
|
|
1446
1446
|
const rawVisionLimits = field(limits, "vision", budget);
|
|
1447
1447
|
if (rawVisionLimits !== void 0) {
|
|
1448
|
-
const rawMediaTypes = field(record$
|
|
1448
|
+
const rawMediaTypes = field(record$14(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
|
|
1449
1449
|
if (rawMediaTypes !== void 0) {
|
|
1450
1450
|
const mediaTypes = stringList(rawMediaTypes, ACCOUNT_MODEL_CATALOG_LIMITS.maxMediaTypes, 128, "INVALID_VISION_LIMITS", budget);
|
|
1451
1451
|
const mime = /^[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*\/[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*$/iu;
|
|
@@ -1507,7 +1507,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
|
|
|
1507
1507
|
fail$1("INVALID_JSON", true);
|
|
1508
1508
|
}
|
|
1509
1509
|
}
|
|
1510
|
-
const data = field(record$
|
|
1510
|
+
const data = field(record$14(raw, "INVALID_CATALOG"), "data", budget);
|
|
1511
1511
|
if (!Array.isArray(data)) fail$1("INVALID_CATALOG");
|
|
1512
1512
|
const count = field(data, "length", budget);
|
|
1513
1513
|
if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) fail$1("INVALID_CATALOG");
|
|
@@ -1530,7 +1530,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
|
|
|
1530
1530
|
for (let index = 0; index < count; index++) {
|
|
1531
1531
|
let id;
|
|
1532
1532
|
try {
|
|
1533
|
-
const candidate = record$
|
|
1533
|
+
const candidate = record$14(field(data, String(index), budget), "INVALID_MODEL");
|
|
1534
1534
|
const candidateId = text$2(field(candidate, "id", budget), ACCOUNT_MODEL_CATALOG_LIMITS.maxIdLength, "INVALID_ID", budget);
|
|
1535
1535
|
if (!identifier.test(candidateId)) fail$1("INVALID_ID");
|
|
1536
1536
|
id = candidateId;
|
|
@@ -2553,16 +2553,16 @@ function formatRequestUploadEvidence(evidence) {
|
|
|
2553
2553
|
//#endregion
|
|
2554
2554
|
//#region lib/types/request-body-timeout.js
|
|
2555
2555
|
const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
|
|
2556
|
-
function record$
|
|
2556
|
+
function record$13(value) {
|
|
2557
2557
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2558
2558
|
}
|
|
2559
2559
|
/** Verified provider evidence, not guessed capabilities, token limits or network cause. */
|
|
2560
2560
|
async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
|
|
2561
2561
|
if (response.status !== 408 || signal?.aborted) return void 0;
|
|
2562
2562
|
const value = await readResponseErrorJson(response, signal);
|
|
2563
|
-
if (signal?.aborted || !record$
|
|
2563
|
+
if (signal?.aborted || !record$13(value)) return void 0;
|
|
2564
2564
|
const error = Object.hasOwn(value, "error") ? value.error : value;
|
|
2565
|
-
if (!record$
|
|
2565
|
+
if (!record$13(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;
|
|
2566
2566
|
const size = body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`;
|
|
2567
2567
|
const composition = formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs);
|
|
2568
2568
|
const upload = formatRequestUploadEvidence(dispatch?.upload);
|
|
@@ -2998,7 +2998,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
2998
2998
|
var package_default = {
|
|
2999
2999
|
name: "dsh-github-copilot",
|
|
3000
3000
|
description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
|
|
3001
|
-
version: "0.4.0-alpha.
|
|
3001
|
+
version: "0.4.0-alpha.122",
|
|
3002
3002
|
publishConfig: {
|
|
3003
3003
|
"access": "public",
|
|
3004
3004
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -5341,7 +5341,7 @@ const usageSchema = z$1.object({
|
|
|
5341
5341
|
totalTokens: count$2.optional(),
|
|
5342
5342
|
reasoningTokens: count$2.optional()
|
|
5343
5343
|
});
|
|
5344
|
-
function record$
|
|
5344
|
+
function record$12(value) {
|
|
5345
5345
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5346
5346
|
}
|
|
5347
5347
|
function sameRoute$1(left, right) {
|
|
@@ -5360,10 +5360,10 @@ function initialContextEvidence() {
|
|
|
5360
5360
|
}
|
|
5361
5361
|
/** Read only counts and routing leaves; never message content or opaque replay. */
|
|
5362
5362
|
function foldContextEvidence(state, event) {
|
|
5363
|
-
if (!record$
|
|
5363
|
+
if (!record$12(event) || typeof event.type !== "string" || !record$12(event.data)) return state;
|
|
5364
5364
|
if (event.type === "request/header" || event.type === "model/selection") {
|
|
5365
|
-
const raw = event.type === "request/header" ? record$
|
|
5366
|
-
if (!record$
|
|
5365
|
+
const raw = event.type === "request/header" ? record$12(event.data.header) ? event.data.header.config : void 0 : event.data;
|
|
5366
|
+
if (!record$12(raw)) return {
|
|
5367
5367
|
...state,
|
|
5368
5368
|
route: null,
|
|
5369
5369
|
sample: null,
|
|
@@ -5402,7 +5402,7 @@ function foldContextEvidence(state, event) {
|
|
|
5402
5402
|
if (!copilot(state.route)) return state;
|
|
5403
5403
|
if (event.type === "assistant/message" && event.data.source !== void 0) {
|
|
5404
5404
|
const source = event.data.source;
|
|
5405
|
-
const parsed = routeSchema.safeParse(record$
|
|
5405
|
+
const parsed = routeSchema.safeParse(record$12(source) ? {
|
|
5406
5406
|
provider: source.provider,
|
|
5407
5407
|
model: source.model
|
|
5408
5408
|
} : source);
|
|
@@ -5418,7 +5418,7 @@ function foldContextEvidence(state, event) {
|
|
|
5418
5418
|
const settledUsage = usage !== void 0;
|
|
5419
5419
|
let terminal;
|
|
5420
5420
|
for (const entry of stream) {
|
|
5421
|
-
if (!record$
|
|
5421
|
+
if (!record$12(entry) || entry.type !== "chunk" || !record$12(entry.chunk)) continue;
|
|
5422
5422
|
if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
|
|
5423
5423
|
if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
|
|
5424
5424
|
}
|
|
@@ -5432,7 +5432,7 @@ function foldContextEvidence(state, event) {
|
|
|
5432
5432
|
};
|
|
5433
5433
|
const value = parsed.data;
|
|
5434
5434
|
const zero = isZeroContextUsage(value);
|
|
5435
|
-
const successful = record$
|
|
5435
|
+
const successful = record$12(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
|
|
5436
5436
|
if (zero && !successful) {
|
|
5437
5437
|
const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
|
|
5438
5438
|
return {
|
|
@@ -5474,7 +5474,7 @@ const contextEvidenceDefinition = {
|
|
|
5474
5474
|
function installContextEvidence(ctx) {
|
|
5475
5475
|
ctx.inject(["sessionProjections"], (scope) => {
|
|
5476
5476
|
const registry = scope.get("sessionProjections");
|
|
5477
|
-
if (!record$
|
|
5477
|
+
if (!record$12(registry) || typeof registry.register !== "function") {
|
|
5478
5478
|
scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
|
|
5479
5479
|
return;
|
|
5480
5480
|
}
|
|
@@ -6533,7 +6533,7 @@ function buildAnthropicWireBody(request, cfg, model) {
|
|
|
6533
6533
|
}
|
|
6534
6534
|
//#endregion
|
|
6535
6535
|
//#region lib/types/responses-reasoning-text.js
|
|
6536
|
-
function record$
|
|
6536
|
+
function record$11(value) {
|
|
6537
6537
|
return typeof value === "object" && value !== null;
|
|
6538
6538
|
}
|
|
6539
6539
|
function responseIndex(value) {
|
|
@@ -6591,13 +6591,13 @@ var ResponsesReasoningText = class {
|
|
|
6591
6591
|
}
|
|
6592
6592
|
/** Only recognized public text fields are examined; no copying of the item. */
|
|
6593
6593
|
snapshot(item) {
|
|
6594
|
-
if (!record$
|
|
6594
|
+
if (!record$11(item) || item.type !== "reasoning") return "";
|
|
6595
6595
|
let delta = "";
|
|
6596
6596
|
for (const family of ["summary", "raw"]) {
|
|
6597
6597
|
const value = family === "summary" ? item.summary : item.content;
|
|
6598
6598
|
if (!Array.isArray(value)) continue;
|
|
6599
6599
|
for (const [index, part] of value.entries()) {
|
|
6600
|
-
if (!record$
|
|
6600
|
+
if (!record$11(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
|
|
6601
6601
|
delta += this.update(family, index, part.text, true);
|
|
6602
6602
|
}
|
|
6603
6603
|
}
|
|
@@ -8936,13 +8936,13 @@ function resolveCopilotResponsesReasoning(ctx, request, candidate) {
|
|
|
8936
8936
|
}
|
|
8937
8937
|
//#endregion
|
|
8938
8938
|
//#region lib/types/replay-recovery.js
|
|
8939
|
-
function record$
|
|
8939
|
+
function record$10(value) {
|
|
8940
8940
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8941
8941
|
}
|
|
8942
8942
|
function parsed(body) {
|
|
8943
8943
|
if (requestBodyEvidence(body, "openai-responses").state !== "complete" || body === void 0) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
|
|
8944
8944
|
const payload = JSON.parse(body);
|
|
8945
|
-
if (!record$
|
|
8945
|
+
if (!record$10(payload) || !Array.isArray(payload.input) || !payload.input.every(record$10)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
8946
8946
|
return {
|
|
8947
8947
|
input: payload.input,
|
|
8948
8948
|
payload
|
|
@@ -9038,7 +9038,7 @@ var ReplayRecoveryStore = class {
|
|
|
9038
9038
|
const value = hash(item);
|
|
9039
9039
|
return value === void 0 || !admitted.has(value);
|
|
9040
9040
|
}).length === decoded.input.length) return payload;
|
|
9041
|
-
if (!record$
|
|
9041
|
+
if (!record$10(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
9042
9042
|
const input = payload.input.filter((_, index) => {
|
|
9043
9043
|
const item = decoded.input[index];
|
|
9044
9044
|
const value = hash(item);
|
|
@@ -9244,7 +9244,7 @@ const SESSION_CONTINUATION_LIMITS = Object.freeze({
|
|
|
9244
9244
|
ciphertextCodeUnits: 67108864,
|
|
9245
9245
|
chunkCodeUnits: 65536
|
|
9246
9246
|
});
|
|
9247
|
-
function record$
|
|
9247
|
+
function record$9(value) {
|
|
9248
9248
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9249
9249
|
}
|
|
9250
9250
|
/** One admitted turn; fingerprints never become durable history or account provenance. */
|
|
@@ -9257,7 +9257,7 @@ var SessionContinuationTurn = class {
|
|
|
9257
9257
|
async transform(payload, assertCurrent = () => {}) {
|
|
9258
9258
|
assertCurrent();
|
|
9259
9259
|
if (this.processing) throw new Error("COPILOT_CONTINUATION_PROCESSING_OVERLAP");
|
|
9260
|
-
if (!record$
|
|
9260
|
+
if (!record$9(payload) || !Array.isArray(payload.input) || payload.input.length > SESSION_CONTINUATION_LIMITS.inputItems) throw new Error("COPILOT_CONTINUATION_INVALID_PAYLOAD");
|
|
9261
9261
|
this.processing = true;
|
|
9262
9262
|
try {
|
|
9263
9263
|
const hashes = /* @__PURE__ */ new Map();
|
|
@@ -9268,7 +9268,7 @@ var SessionContinuationTurn = class {
|
|
|
9268
9268
|
assertCurrent();
|
|
9269
9269
|
}
|
|
9270
9270
|
const item = payload.input[index];
|
|
9271
|
-
if (!record$
|
|
9271
|
+
if (!record$9(item)) throw new Error("COPILOT_CONTINUATION_INVALID_PAYLOAD");
|
|
9272
9272
|
if (item.type !== "reasoning") continue;
|
|
9273
9273
|
const ciphertext = item.encrypted_content;
|
|
9274
9274
|
if (typeof ciphertext !== "string" || !ciphertext || item.status !== void 0 && item.status !== "completed") throw new Error("COPILOT_CONTINUATION_UNSUPPORTED_REASONING");
|
|
@@ -9303,6 +9303,21 @@ var SessionContinuationTurn = class {
|
|
|
9303
9303
|
};
|
|
9304
9304
|
//#endregion
|
|
9305
9305
|
//#region lib/types/session-continuation-types.js
|
|
9306
|
+
const COMPACTION_CONTINUATION = "githubCopilotCompactionLifecycle";
|
|
9307
|
+
const CompactionContinuationStatusSchema = z$1.object({
|
|
9308
|
+
id: z$1.string().min(1).max(256),
|
|
9309
|
+
state: z$1.enum([
|
|
9310
|
+
"running",
|
|
9311
|
+
"completed",
|
|
9312
|
+
"failed",
|
|
9313
|
+
"cancelled",
|
|
9314
|
+
"blocked"
|
|
9315
|
+
])
|
|
9316
|
+
}).strict();
|
|
9317
|
+
const CompactionContinuationLifecycleSchema = z$1.object({
|
|
9318
|
+
id: z$1.string().nullable(),
|
|
9319
|
+
running: z$1.boolean()
|
|
9320
|
+
}).strict();
|
|
9306
9321
|
const SessionContinuationPreferenceSchema = z$1.object({
|
|
9307
9322
|
sessionId: z$1.string().min(1).max(256).refine((value) => !/[\p{Cc}\p{Cf}]/u.test(value)),
|
|
9308
9323
|
version: z$1.literal(1),
|
|
@@ -9323,9 +9338,122 @@ z$1.object({
|
|
|
9323
9338
|
revision: z$1.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
9324
9339
|
activeTurnEnabled: z$1.boolean().optional(),
|
|
9325
9340
|
source: z$1.enum(["default", "session"]).optional(),
|
|
9326
|
-
nextTurnAuthorized: z$1.boolean().optional()
|
|
9341
|
+
nextTurnAuthorized: z$1.boolean().optional(),
|
|
9342
|
+
compaction: CompactionContinuationStatusSchema.optional()
|
|
9327
9343
|
}).strict();
|
|
9328
9344
|
//#endregion
|
|
9345
|
+
//#region lib/types/compaction-continuation.js
|
|
9346
|
+
const compactionContinuationDefinition = {
|
|
9347
|
+
key: COMPACTION_CONTINUATION,
|
|
9348
|
+
stateVersion: 1,
|
|
9349
|
+
stateSchema: CompactionContinuationLifecycleSchema,
|
|
9350
|
+
init: () => ({
|
|
9351
|
+
id: null,
|
|
9352
|
+
running: false
|
|
9353
|
+
}),
|
|
9354
|
+
apply(state, event) {
|
|
9355
|
+
if (event.type === "compaction/start") return {
|
|
9356
|
+
id: event.data.compactionId,
|
|
9357
|
+
running: true
|
|
9358
|
+
};
|
|
9359
|
+
if (event.type === "compaction/end" && event.data.compactionId === state.id) return {
|
|
9360
|
+
...state,
|
|
9361
|
+
running: false
|
|
9362
|
+
};
|
|
9363
|
+
return state;
|
|
9364
|
+
},
|
|
9365
|
+
wire: {
|
|
9366
|
+
viewSchema: CompactionContinuationLifecycleSchema,
|
|
9367
|
+
view: (state) => state
|
|
9368
|
+
}
|
|
9369
|
+
};
|
|
9370
|
+
function record$8(value) {
|
|
9371
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9372
|
+
}
|
|
9373
|
+
/** Native brackets authorize scope, never loss; the existing Session policy authorizes loss. */
|
|
9374
|
+
function installCompactionContinuation(ctx, enabled) {
|
|
9375
|
+
const operations = /* @__PURE__ */ new Map();
|
|
9376
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
9377
|
+
let disposed = false;
|
|
9378
|
+
const removeProjection = ctx.inject(["sessionProjections"], (scope) => {
|
|
9379
|
+
const registry = scope.get("sessionProjections");
|
|
9380
|
+
if (!record$8(registry) || typeof registry.register !== "function") throw new Error("COPILOT_CONTINUATION_COMPACTION_PROJECTION_UNAVAILABLE");
|
|
9381
|
+
const remove = registry.register(compactionContinuationDefinition);
|
|
9382
|
+
if (typeof remove !== "function") throw new Error("COPILOT_CONTINUATION_COMPACTION_PROJECTION_DISPOSER_UNAVAILABLE");
|
|
9383
|
+
return () => {
|
|
9384
|
+
remove();
|
|
9385
|
+
};
|
|
9386
|
+
});
|
|
9387
|
+
const removeEvents = ctx.on("session/event", (session, event) => {
|
|
9388
|
+
if (event.type === "compaction/start") {
|
|
9389
|
+
if (operations.size >= 64 || operations.has(session.id)) {
|
|
9390
|
+
ctx.logger.warn("COPILOT_CONTINUATION_COMPACTION_LIMIT");
|
|
9391
|
+
return;
|
|
9392
|
+
}
|
|
9393
|
+
operations.set(session.id, {
|
|
9394
|
+
session,
|
|
9395
|
+
id: event.data.compactionId,
|
|
9396
|
+
replaced: false
|
|
9397
|
+
});
|
|
9398
|
+
statuses.delete(session.id);
|
|
9399
|
+
}
|
|
9400
|
+
const operation = operations.get(session.id);
|
|
9401
|
+
if (!operation || operation.session !== session) return;
|
|
9402
|
+
if (event.type === "user/message" && event.data.source.kind === "compact-checkpoint" && event.data.source.compactionId === operation.id) operation.replaced = true;
|
|
9403
|
+
if (event.type !== "compaction/end" || event.data.compactionId !== operation.id) return;
|
|
9404
|
+
if (operation.enabled) statuses.set(session.id, {
|
|
9405
|
+
id: operation.id,
|
|
9406
|
+
state: event.data.error === void 0 && operation.replaced ? "completed" : operation.signal?.aborted ? "cancelled" : "failed"
|
|
9407
|
+
});
|
|
9408
|
+
else if (operation.enabled === false && typeof event.data.error === "string" && /(?:^|[^A-Z_])COPILOT_RESPONSES_REPLAY_SCOPE_MISMATCH(?:$|[^A-Z_])/.test(event.data.error)) statuses.set(session.id, {
|
|
9409
|
+
id: operation.id,
|
|
9410
|
+
state: "blocked"
|
|
9411
|
+
});
|
|
9412
|
+
operations.delete(session.id);
|
|
9413
|
+
while (statuses.size > 128) statuses.delete(statuses.keys().next().value);
|
|
9414
|
+
});
|
|
9415
|
+
const removeAgent = ctx.on("agent/disposed", ({ agent }) => {
|
|
9416
|
+
operations.delete(agent.session.id);
|
|
9417
|
+
statuses.delete(agent.session.id);
|
|
9418
|
+
});
|
|
9419
|
+
return {
|
|
9420
|
+
status(agent) {
|
|
9421
|
+
const operation = operations.get(agent.session.id);
|
|
9422
|
+
return operation?.enabled ? {
|
|
9423
|
+
id: operation.id,
|
|
9424
|
+
state: "running"
|
|
9425
|
+
} : statuses.get(agent.session.id);
|
|
9426
|
+
},
|
|
9427
|
+
prepare(request) {
|
|
9428
|
+
if (request.provider !== "github-copilot-preview" || request.purpose !== "compaction") return void 0;
|
|
9429
|
+
if (!request.sessionId || !request.signal) throw new Error("COPILOT_CONTINUATION_COMPACTION_SCOPE_UNAVAILABLE");
|
|
9430
|
+
const operation = operations.get(request.sessionId);
|
|
9431
|
+
if (!operation) throw new Error("COPILOT_CONTINUATION_COMPACTION_BOUNDARY_UNAVAILABLE");
|
|
9432
|
+
const agent = ctx.get("agents")?.get(request.sessionId);
|
|
9433
|
+
if (!agent || agent.session !== operation.session) throw new Error("COPILOT_CONTINUATION_COMPACTION_AGENT_UNAVAILABLE");
|
|
9434
|
+
const initiator = ctx.get("agents")?.currentInitiator();
|
|
9435
|
+
if (initiator && initiator !== agent) throw new Error("COPILOT_CONTINUATION_COMPACTION_SCOPE_MISMATCH");
|
|
9436
|
+
operation.enabled ??= enabled(agent);
|
|
9437
|
+
if (!operation.enabled) return void 0;
|
|
9438
|
+
if (operation.model !== void 0 && operation.model !== request.model) throw new Error("COPILOT_CONTINUATION_COMPACTION_MODEL_CHANGED");
|
|
9439
|
+
operation.model = request.model;
|
|
9440
|
+
operation.signal = request.signal;
|
|
9441
|
+
const assertCurrent = () => {
|
|
9442
|
+
if (disposed || request.signal.aborted || operation.signal !== request.signal || operations.get(request.sessionId) !== operation) throw new Error("COPILOT_CONTINUATION_REVOKED");
|
|
9443
|
+
};
|
|
9444
|
+
return (payload) => new SessionContinuationTurn().transform(payload, assertCurrent);
|
|
9445
|
+
},
|
|
9446
|
+
dispose() {
|
|
9447
|
+
disposed = true;
|
|
9448
|
+
removeEvents();
|
|
9449
|
+
removeAgent();
|
|
9450
|
+
removeProjection.dispose();
|
|
9451
|
+
operations.clear();
|
|
9452
|
+
statuses.clear();
|
|
9453
|
+
}
|
|
9454
|
+
};
|
|
9455
|
+
}
|
|
9456
|
+
//#endregion
|
|
9329
9457
|
//#region lib/types/session-continuation-host.js
|
|
9330
9458
|
var __runInitializers$1 = function(thisArg, initializers, value) {
|
|
9331
9459
|
var useValue = arguments.length > 2;
|
|
@@ -9455,11 +9583,13 @@ let SessionContinuationController = (() => {
|
|
|
9455
9583
|
active = __runInitializers$1(this, _instanceExtraInitializers);
|
|
9456
9584
|
once;
|
|
9457
9585
|
ready;
|
|
9458
|
-
|
|
9586
|
+
summaryStatus;
|
|
9587
|
+
constructor(ctx, active, once = /* @__PURE__ */ new Set(), ready = Promise.resolve(), summaryStatus = () => void 0) {
|
|
9459
9588
|
super(ctx, "githubCopilotSessionContinuation");
|
|
9460
9589
|
this.active = active;
|
|
9461
9590
|
this.once = once;
|
|
9462
9591
|
this.ready = ready;
|
|
9592
|
+
this.summaryStatus = summaryStatus;
|
|
9463
9593
|
}
|
|
9464
9594
|
async get(agent) {
|
|
9465
9595
|
await this.ready;
|
|
@@ -9467,12 +9597,14 @@ let SessionContinuationController = (() => {
|
|
|
9467
9597
|
if (!entry) throw new Error("COPILOT_CONTINUATION_SETTINGS_UNAVAILABLE");
|
|
9468
9598
|
const admission = this.active.get(agent.session);
|
|
9469
9599
|
const explicit = preferences(entry.value).find((row) => row.sessionId === agent.session.id);
|
|
9600
|
+
const compaction = this.summaryStatus(agent);
|
|
9470
9601
|
return {
|
|
9471
9602
|
enabled: resolveEnabled(agent, entry.value),
|
|
9472
9603
|
source: explicit ? "session" : "default",
|
|
9473
9604
|
nextTurnAuthorized: this.once.has(agent.session),
|
|
9474
9605
|
revision: entry.revision,
|
|
9475
|
-
...admission ? { activeTurnEnabled: admission.enabled } : {}
|
|
9606
|
+
...admission ? { activeTurnEnabled: admission.enabled } : {},
|
|
9607
|
+
...compaction ? { compaction } : {}
|
|
9476
9608
|
};
|
|
9477
9609
|
}
|
|
9478
9610
|
async set(agent, revision, enabled) {
|
|
@@ -9569,11 +9701,15 @@ function installSessionContinuation(ctx) {
|
|
|
9569
9701
|
const active = /* @__PURE__ */ new Map();
|
|
9570
9702
|
const once = /* @__PURE__ */ new Set();
|
|
9571
9703
|
const requests = /* @__PURE__ */ new WeakMap();
|
|
9704
|
+
let initialized = false;
|
|
9572
9705
|
const ready = (async () => {
|
|
9573
9706
|
const settings = ctx.get("settings");
|
|
9574
9707
|
const entry = settings?.describe({ redactSecrets: true }).find((row) => row.ns === "github-copilot");
|
|
9575
9708
|
if (!settings || !entry) throw new Error("COPILOT_CONTINUATION_SETTINGS_UNAVAILABLE");
|
|
9576
|
-
if (defaultHistory(entry.value).length)
|
|
9709
|
+
if (defaultHistory(entry.value).length) {
|
|
9710
|
+
initialized = true;
|
|
9711
|
+
return;
|
|
9712
|
+
}
|
|
9577
9713
|
await settings.mutate("github-copilot", [{
|
|
9578
9714
|
op: "set",
|
|
9579
9715
|
path: ["continuationDefaultHistory"],
|
|
@@ -9583,9 +9719,14 @@ function installSessionContinuation(ctx) {
|
|
|
9583
9719
|
}]
|
|
9584
9720
|
}], entry.revision);
|
|
9585
9721
|
if (!defaultHistory(readSettingsNamespace(ctx, "github-copilot")).length) throw new Error("COPILOT_CONTINUATION_COMMIT_UNCERTAIN");
|
|
9722
|
+
initialized = true;
|
|
9586
9723
|
})();
|
|
9587
9724
|
ready.catch(() => ctx.logger.warn("COPILOT_CONTINUATION_INITIALIZATION_FAILED"));
|
|
9588
|
-
|
|
9725
|
+
const summaries = installCompactionContinuation(ctx, (agent) => {
|
|
9726
|
+
if (!initialized) throw new Error("COPILOT_CONTINUATION_SETTINGS_UNAVAILABLE");
|
|
9727
|
+
return active.get(agent.session)?.persistentEnabled ?? resolveEnabled(agent, readSettingsNamespace(ctx, "github-copilot"));
|
|
9728
|
+
});
|
|
9729
|
+
new SessionContinuationController(ctx, active, once, ready, (agent) => summaries.status(agent));
|
|
9589
9730
|
const removeRequest = ctx.on("agent/request", async ({ agent, turn, step, signal }, next) => {
|
|
9590
9731
|
const result = await next();
|
|
9591
9732
|
if (signal.aborted || result.provider !== "github-copilot-preview") return result;
|
|
@@ -9595,10 +9736,12 @@ function installSessionContinuation(ctx) {
|
|
|
9595
9736
|
let admission = active.get(agent.session);
|
|
9596
9737
|
if (admission && admission.turn !== turn) throw new Error("COPILOT_CONTINUATION_TURN_UNSETTLED");
|
|
9597
9738
|
if (!admission) {
|
|
9739
|
+
const persistentEnabled = resolveEnabled(agent, readSettingsNamespace(ctx, "github-copilot"));
|
|
9598
9740
|
admission = {
|
|
9599
9741
|
turn,
|
|
9600
9742
|
step,
|
|
9601
|
-
enabled:
|
|
9743
|
+
enabled: persistentEnabled || once.has(agent.session),
|
|
9744
|
+
persistentEnabled,
|
|
9602
9745
|
filter: new SessionContinuationTurn(),
|
|
9603
9746
|
signal
|
|
9604
9747
|
};
|
|
@@ -9621,6 +9764,7 @@ function installSessionContinuation(ctx) {
|
|
|
9621
9764
|
return {
|
|
9622
9765
|
ready,
|
|
9623
9766
|
prepare(request) {
|
|
9767
|
+
if (request.purpose === "compaction") return summaries.prepare(request);
|
|
9624
9768
|
if (request.provider !== "github-copilot-preview" || request.purpose !== void 0 || !request.signal) return void 0;
|
|
9625
9769
|
const session = requests.get(request.signal);
|
|
9626
9770
|
const admission = session && active.get(session);
|
|
@@ -9635,6 +9779,7 @@ function installSessionContinuation(ctx) {
|
|
|
9635
9779
|
},
|
|
9636
9780
|
dispose() {
|
|
9637
9781
|
disposed = true;
|
|
9782
|
+
summaries.dispose();
|
|
9638
9783
|
removeRequest();
|
|
9639
9784
|
removeEvents();
|
|
9640
9785
|
removeAgent();
|
|
@@ -9644,6 +9789,49 @@ function installSessionContinuation(ctx) {
|
|
|
9644
9789
|
};
|
|
9645
9790
|
}
|
|
9646
9791
|
//#endregion
|
|
9792
|
+
//#region lib/types/compaction-replay.js
|
|
9793
|
+
/** Explicit manual consent lasts only for the native summarizer hook's exact signal. */
|
|
9794
|
+
var CompactionReplayRecovery = class {
|
|
9795
|
+
operations = /* @__PURE__ */ new Map();
|
|
9796
|
+
closed = false;
|
|
9797
|
+
async run(sessionId, model, signal, operation) {
|
|
9798
|
+
if (this.closed) throw new Error("COPILOT_COMPACTION_REPLAY_UNAVAILABLE");
|
|
9799
|
+
signal.throwIfAborted();
|
|
9800
|
+
if (this.operations.has(signal)) throw new Error("COPILOT_COMPACTION_REPLAY_OVERLAP");
|
|
9801
|
+
if (this.operations.size >= 64) throw new Error("COPILOT_COMPACTION_REPLAY_LIMIT");
|
|
9802
|
+
const authorization = {
|
|
9803
|
+
sessionId,
|
|
9804
|
+
model
|
|
9805
|
+
};
|
|
9806
|
+
this.operations.set(signal, authorization);
|
|
9807
|
+
try {
|
|
9808
|
+
return await operation();
|
|
9809
|
+
} finally {
|
|
9810
|
+
this.operations.delete(signal);
|
|
9811
|
+
}
|
|
9812
|
+
}
|
|
9813
|
+
prepare(request) {
|
|
9814
|
+
if (request.provider !== "github-copilot-preview" || request.purpose !== "compaction" || !request.signal) return void 0;
|
|
9815
|
+
const signal = request.signal;
|
|
9816
|
+
const authorization = this.operations.get(signal);
|
|
9817
|
+
if (!authorization || request.sessionId !== authorization.sessionId || request.model !== authorization.model) return void 0;
|
|
9818
|
+
const assertCurrent = () => {
|
|
9819
|
+
if (this.closed || signal.aborted || this.operations.get(signal) !== authorization) throw new Error("COPILOT_COMPACTION_REPLAY_REVOKED");
|
|
9820
|
+
};
|
|
9821
|
+
return (payload) => new SessionContinuationTurn().transform(payload, assertCurrent);
|
|
9822
|
+
}
|
|
9823
|
+
dispose() {
|
|
9824
|
+
this.closed = true;
|
|
9825
|
+
this.operations.clear();
|
|
9826
|
+
}
|
|
9827
|
+
};
|
|
9828
|
+
function installCompactionReplay(ctx) {
|
|
9829
|
+
const recovery = new CompactionReplayRecovery();
|
|
9830
|
+
ctx.provide("githubCopilotCompactionReplay", recovery);
|
|
9831
|
+
ctx.effect(() => () => recovery.dispose());
|
|
9832
|
+
return recovery;
|
|
9833
|
+
}
|
|
9834
|
+
//#endregion
|
|
9647
9835
|
//#region lib/types/agent-compaction.js
|
|
9648
9836
|
function record$7(value) {
|
|
9649
9837
|
return typeof value === "object" && value !== null;
|
|
@@ -11983,7 +12171,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
11983
12171
|
if (typeof mapping !== "string" || mapping.length === 0) throw failure("COPILOT_PREVIEW_REASONING_UNSUPPORTED", "INVALID_REQUEST");
|
|
11984
12172
|
}
|
|
11985
12173
|
let requestFailure;
|
|
11986
|
-
const recovery = owner.replayRecovery?.prepare(options);
|
|
12174
|
+
const recovery = options.purpose === "compaction" && model.api !== "openai-responses" ? void 0 : owner.replayRecovery?.prepare(options);
|
|
11987
12175
|
let wireAbort;
|
|
11988
12176
|
let bodyTimeout;
|
|
11989
12177
|
let liveness;
|
|
@@ -12375,6 +12563,7 @@ function createAccountRuntime(ctx, config, binding, exclusionTurns, replayRecove
|
|
|
12375
12563
|
const revision = lifetime.revision;
|
|
12376
12564
|
const proof = snapshotProof;
|
|
12377
12565
|
return Object.freeze({
|
|
12566
|
+
api: descriptor.api,
|
|
12378
12567
|
limits: Object.freeze({
|
|
12379
12568
|
contextWindow: descriptor.contextWindow,
|
|
12380
12569
|
maxTokens: descriptor.maxTokens,
|
|
@@ -12544,9 +12733,10 @@ function apply$1(ctx, config = {}) {
|
|
|
12544
12733
|
return runtimeFor(binding).proof();
|
|
12545
12734
|
});
|
|
12546
12735
|
const continuation = installSessionContinuation(ctx);
|
|
12736
|
+
const compactionReplay = installCompactionReplay(ctx);
|
|
12547
12737
|
const replayRecovery = {
|
|
12548
12738
|
prepare(request) {
|
|
12549
|
-
const portable = continuation.prepare(request);
|
|
12739
|
+
const portable = compactionReplay.prepare(request) ?? continuation.prepare(request);
|
|
12550
12740
|
const temporary = temporaryRecovery.prepare(request);
|
|
12551
12741
|
if (!portable) return temporary;
|
|
12552
12742
|
return {
|
|
@@ -12557,6 +12747,7 @@ function apply$1(ctx, config = {}) {
|
|
|
12557
12747
|
dispose() {
|
|
12558
12748
|
temporaryRecovery.dispose();
|
|
12559
12749
|
continuation.dispose();
|
|
12750
|
+
compactionReplay.dispose();
|
|
12560
12751
|
}
|
|
12561
12752
|
};
|
|
12562
12753
|
const initial = directoryRuntime();
|