dsh-github-copilot 0.4.0-alpha.92 → 0.4.0-alpha.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -0
- package/CHANGELOG.md +10 -0
- package/README.md +8 -8
- package/README.zh.md +8 -8
- package/deployment-baseline.json +22 -1
- package/docs/copilot-compaction.md +2 -0
- package/docs/model-compatibility-acceptance.md +54 -0
- package/lib/client.js +318 -123
- package/lib/client.js.map +1 -1
- package/lib/index.js +740 -423
- package/lib/remote.js +56 -4
- package/lib/types/preview-provider.d.ts +4 -0
- package/lib/types/replay-recovery-host.d.ts +27 -0
- package/lib/types/replay-recovery-remote.d.ts +13 -0
- package/lib/types/replay-recovery-types.d.ts +14 -0
- package/lib/types/replay-recovery-ui.d.ts +19 -0
- package/lib/types/replay-recovery.d.ts +15 -0
- package/lib/types/responses-replay-compat.d.ts +7 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -21,12 +21,12 @@ import { estimateContextTokens, estimateMessageTokens } from "@earendil-works/pi
|
|
|
21
21
|
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "@earendil-works/pi-ai/api/github-copilot-headers";
|
|
22
22
|
//#region lib/types/dual-model-host.js
|
|
23
23
|
/** Retired planner/executor entry points; retained policies stay enforceable without migration. */
|
|
24
|
-
var __runInitializers$
|
|
24
|
+
var __runInitializers$5 = function(thisArg, initializers, value) {
|
|
25
25
|
var useValue = arguments.length > 2;
|
|
26
26
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
27
27
|
return useValue ? value : void 0;
|
|
28
28
|
};
|
|
29
|
-
var __esDecorate$
|
|
29
|
+
var __esDecorate$5 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
30
30
|
function accept(f) {
|
|
31
31
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
32
32
|
return f;
|
|
@@ -272,7 +272,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
272
272
|
_view_decorators = [Remote];
|
|
273
273
|
_save_decorators = [Remote];
|
|
274
274
|
_create_decorators = [Remote];
|
|
275
|
-
__esDecorate$
|
|
275
|
+
__esDecorate$5(this, null, _view_decorators, {
|
|
276
276
|
kind: "method",
|
|
277
277
|
name: "view",
|
|
278
278
|
static: false,
|
|
@@ -283,7 +283,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
283
283
|
},
|
|
284
284
|
metadata: _metadata
|
|
285
285
|
}, null, _instanceExtraInitializers);
|
|
286
|
-
__esDecorate$
|
|
286
|
+
__esDecorate$5(this, null, _save_decorators, {
|
|
287
287
|
kind: "method",
|
|
288
288
|
name: "save",
|
|
289
289
|
static: false,
|
|
@@ -294,7 +294,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
294
294
|
},
|
|
295
295
|
metadata: _metadata
|
|
296
296
|
}, null, _instanceExtraInitializers);
|
|
297
|
-
__esDecorate$
|
|
297
|
+
__esDecorate$5(this, null, _create_decorators, {
|
|
298
298
|
kind: "method",
|
|
299
299
|
name: "create",
|
|
300
300
|
static: false,
|
|
@@ -312,7 +312,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
312
312
|
value: _metadata
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
|
-
owner = __runInitializers$
|
|
315
|
+
owner = __runInitializers$5(this, _instanceExtraInitializers);
|
|
316
316
|
lifetime = new AbortController();
|
|
317
317
|
creates = /* @__PURE__ */ new Map();
|
|
318
318
|
overlays = /* @__PURE__ */ new Map();
|
|
@@ -740,12 +740,12 @@ const SearchProviderCatalogSchema = z$1.object({
|
|
|
740
740
|
}).strict();
|
|
741
741
|
//#endregion
|
|
742
742
|
//#region lib/types/search-routing-host.js
|
|
743
|
-
var __runInitializers$
|
|
743
|
+
var __runInitializers$4 = function(thisArg, initializers, value) {
|
|
744
744
|
var useValue = arguments.length > 2;
|
|
745
745
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
746
746
|
return useValue ? value : void 0;
|
|
747
747
|
};
|
|
748
|
-
var __esDecorate$
|
|
748
|
+
var __esDecorate$4 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
749
749
|
function accept(f) {
|
|
750
750
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
751
751
|
return f;
|
|
@@ -788,7 +788,7 @@ let SearchRoutingController = (() => {
|
|
|
788
788
|
static {
|
|
789
789
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
790
790
|
_providers_decorators = [Remote];
|
|
791
|
-
__esDecorate$
|
|
791
|
+
__esDecorate$4(this, null, _providers_decorators, {
|
|
792
792
|
kind: "method",
|
|
793
793
|
name: "providers",
|
|
794
794
|
static: false,
|
|
@@ -808,7 +808,7 @@ let SearchRoutingController = (() => {
|
|
|
808
808
|
}
|
|
809
809
|
constructor(ctx) {
|
|
810
810
|
super(ctx, "githubCopilotSearchRouting");
|
|
811
|
-
__runInitializers$
|
|
811
|
+
__runInitializers$4(this, _instanceExtraInitializers);
|
|
812
812
|
}
|
|
813
813
|
providers() {
|
|
814
814
|
const unavailable = {
|
|
@@ -1250,12 +1250,12 @@ function normalizeCopilotUsage(input, observedAt) {
|
|
|
1250
1250
|
}
|
|
1251
1251
|
//#endregion
|
|
1252
1252
|
//#region lib/types/copilot-usage-host.js
|
|
1253
|
-
var __runInitializers$
|
|
1253
|
+
var __runInitializers$3 = function(thisArg, initializers, value) {
|
|
1254
1254
|
var useValue = arguments.length > 2;
|
|
1255
1255
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
1256
1256
|
return useValue ? value : void 0;
|
|
1257
1257
|
};
|
|
1258
|
-
var __esDecorate$
|
|
1258
|
+
var __esDecorate$3 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
1259
1259
|
function accept(f) {
|
|
1260
1260
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
1261
1261
|
return f;
|
|
@@ -1595,7 +1595,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
1595
1595
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
1596
1596
|
_get_decorators = [Remote];
|
|
1597
1597
|
_refresh_decorators = [Remote];
|
|
1598
|
-
__esDecorate$
|
|
1598
|
+
__esDecorate$3(this, null, _get_decorators, {
|
|
1599
1599
|
kind: "method",
|
|
1600
1600
|
name: "get",
|
|
1601
1601
|
static: false,
|
|
@@ -1606,7 +1606,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
1606
1606
|
},
|
|
1607
1607
|
metadata: _metadata
|
|
1608
1608
|
}, null, _instanceExtraInitializers);
|
|
1609
|
-
__esDecorate$
|
|
1609
|
+
__esDecorate$3(this, null, _refresh_decorators, {
|
|
1610
1610
|
kind: "method",
|
|
1611
1611
|
name: "refresh",
|
|
1612
1612
|
static: false,
|
|
@@ -1624,7 +1624,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
1624
1624
|
value: _metadata
|
|
1625
1625
|
});
|
|
1626
1626
|
}
|
|
1627
|
-
source = __runInitializers$
|
|
1627
|
+
source = __runInitializers$3(this, _instanceExtraInitializers);
|
|
1628
1628
|
constructor(ctx) {
|
|
1629
1629
|
super(ctx, "githubCopilotUsage");
|
|
1630
1630
|
const credentials = createGitHubCopilotCredentialStore(ctx);
|
|
@@ -1684,7 +1684,7 @@ const usageSchema = z$1.object({
|
|
|
1684
1684
|
totalTokens: count.optional(),
|
|
1685
1685
|
reasoningTokens: count.optional()
|
|
1686
1686
|
});
|
|
1687
|
-
function record$
|
|
1687
|
+
function record$9(value) {
|
|
1688
1688
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1689
1689
|
}
|
|
1690
1690
|
function sameRoute$1(left, right) {
|
|
@@ -1703,10 +1703,10 @@ function initialContextEvidence() {
|
|
|
1703
1703
|
}
|
|
1704
1704
|
/** Read only counts and routing leaves; never message content or opaque replay. */
|
|
1705
1705
|
function foldContextEvidence(state, event) {
|
|
1706
|
-
if (!record$
|
|
1706
|
+
if (!record$9(event) || typeof event.type !== "string" || !record$9(event.data)) return state;
|
|
1707
1707
|
if (event.type === "request/header" || event.type === "model/selection") {
|
|
1708
|
-
const raw = event.type === "request/header" ? record$
|
|
1709
|
-
if (!record$
|
|
1708
|
+
const raw = event.type === "request/header" ? record$9(event.data.header) ? event.data.header.config : void 0 : event.data;
|
|
1709
|
+
if (!record$9(raw)) return {
|
|
1710
1710
|
...state,
|
|
1711
1711
|
route: null,
|
|
1712
1712
|
sample: null,
|
|
@@ -1745,7 +1745,7 @@ function foldContextEvidence(state, event) {
|
|
|
1745
1745
|
if (!copilot(state.route)) return state;
|
|
1746
1746
|
if (event.type === "assistant/message" && event.data.source !== void 0) {
|
|
1747
1747
|
const source = event.data.source;
|
|
1748
|
-
const parsed = routeSchema.safeParse(record$
|
|
1748
|
+
const parsed = routeSchema.safeParse(record$9(source) ? {
|
|
1749
1749
|
provider: source.provider,
|
|
1750
1750
|
model: source.model
|
|
1751
1751
|
} : source);
|
|
@@ -1761,7 +1761,7 @@ function foldContextEvidence(state, event) {
|
|
|
1761
1761
|
const settledUsage = usage !== void 0;
|
|
1762
1762
|
let terminal;
|
|
1763
1763
|
for (const entry of stream) {
|
|
1764
|
-
if (!record$
|
|
1764
|
+
if (!record$9(entry) || entry.type !== "chunk" || !record$9(entry.chunk)) continue;
|
|
1765
1765
|
if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
|
|
1766
1766
|
if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
|
|
1767
1767
|
}
|
|
@@ -1775,7 +1775,7 @@ function foldContextEvidence(state, event) {
|
|
|
1775
1775
|
};
|
|
1776
1776
|
const value = parsed.data;
|
|
1777
1777
|
const zero = isZeroContextUsage(value);
|
|
1778
|
-
const successful = record$
|
|
1778
|
+
const successful = record$9(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
|
|
1779
1779
|
if (zero && !successful) {
|
|
1780
1780
|
const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
|
|
1781
1781
|
return {
|
|
@@ -1817,7 +1817,7 @@ const contextEvidenceDefinition = {
|
|
|
1817
1817
|
function installContextEvidence(ctx) {
|
|
1818
1818
|
ctx.inject(["sessionProjections"], (scope) => {
|
|
1819
1819
|
const registry = scope.get("sessionProjections");
|
|
1820
|
-
if (!record$
|
|
1820
|
+
if (!record$9(registry) || typeof registry.register !== "function") {
|
|
1821
1821
|
scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
|
|
1822
1822
|
return;
|
|
1823
1823
|
}
|
|
@@ -1831,7 +1831,7 @@ function installContextEvidence(ctx) {
|
|
|
1831
1831
|
//#endregion
|
|
1832
1832
|
//#region package.json
|
|
1833
1833
|
var name$1 = "dsh-github-copilot";
|
|
1834
|
-
var version = "0.4.0-alpha.
|
|
1834
|
+
var version = "0.4.0-alpha.94";
|
|
1835
1835
|
//#endregion
|
|
1836
1836
|
//#region lib/types/probe.js
|
|
1837
1837
|
/**
|
|
@@ -2843,7 +2843,7 @@ function buildAnthropicWireBody(request, cfg, model) {
|
|
|
2843
2843
|
}
|
|
2844
2844
|
//#endregion
|
|
2845
2845
|
//#region lib/types/responses-reasoning-text.js
|
|
2846
|
-
function record$
|
|
2846
|
+
function record$8(value) {
|
|
2847
2847
|
return typeof value === "object" && value !== null;
|
|
2848
2848
|
}
|
|
2849
2849
|
function responseIndex(value) {
|
|
@@ -2901,13 +2901,13 @@ var ResponsesReasoningText = class {
|
|
|
2901
2901
|
}
|
|
2902
2902
|
/** Only recognized public text fields are examined; no copying of the item. */
|
|
2903
2903
|
snapshot(item) {
|
|
2904
|
-
if (!record$
|
|
2904
|
+
if (!record$8(item) || item.type !== "reasoning") return "";
|
|
2905
2905
|
let delta = "";
|
|
2906
2906
|
for (const family of ["summary", "raw"]) {
|
|
2907
2907
|
const value = family === "summary" ? item.summary : item.content;
|
|
2908
2908
|
if (!Array.isArray(value)) continue;
|
|
2909
2909
|
for (const [index, part] of value.entries()) {
|
|
2910
|
-
if (!record$
|
|
2910
|
+
if (!record$8(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
|
|
2911
2911
|
delta += this.update(family, index, part.text, true);
|
|
2912
2912
|
}
|
|
2913
2913
|
}
|
|
@@ -4403,12 +4403,12 @@ function excludedModelSet(value) {
|
|
|
4403
4403
|
* Host-side bridge between the Models-page companion UI and DSH's neutral
|
|
4404
4404
|
* authorization, credential-record, and settings seams.
|
|
4405
4405
|
*/
|
|
4406
|
-
var __runInitializers$
|
|
4406
|
+
var __runInitializers$2 = function(thisArg, initializers, value) {
|
|
4407
4407
|
var useValue = arguments.length > 2;
|
|
4408
4408
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
4409
4409
|
return useValue ? value : void 0;
|
|
4410
4410
|
};
|
|
4411
|
-
var __esDecorate$
|
|
4411
|
+
var __esDecorate$2 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
4412
4412
|
function accept(f) {
|
|
4413
4413
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
4414
4414
|
return f;
|
|
@@ -4738,7 +4738,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4738
4738
|
_start_decorators = [Remote];
|
|
4739
4739
|
_cancel_decorators = [Remote];
|
|
4740
4740
|
_signOut_decorators = [Remote];
|
|
4741
|
-
__esDecorate$
|
|
4741
|
+
__esDecorate$2(this, null, _migrationStatus_decorators, {
|
|
4742
4742
|
kind: "method",
|
|
4743
4743
|
name: "migrationStatus",
|
|
4744
4744
|
static: false,
|
|
@@ -4749,7 +4749,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4749
4749
|
},
|
|
4750
4750
|
metadata: _metadata
|
|
4751
4751
|
}, null, _instanceExtraInitializers);
|
|
4752
|
-
__esDecorate$
|
|
4752
|
+
__esDecorate$2(this, null, _status_decorators, {
|
|
4753
4753
|
kind: "method",
|
|
4754
4754
|
name: "status",
|
|
4755
4755
|
static: false,
|
|
@@ -4760,7 +4760,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4760
4760
|
},
|
|
4761
4761
|
metadata: _metadata
|
|
4762
4762
|
}, null, _instanceExtraInitializers);
|
|
4763
|
-
__esDecorate$
|
|
4763
|
+
__esDecorate$2(this, null, _excludeModel_decorators, {
|
|
4764
4764
|
kind: "method",
|
|
4765
4765
|
name: "excludeModel",
|
|
4766
4766
|
static: false,
|
|
@@ -4771,7 +4771,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4771
4771
|
},
|
|
4772
4772
|
metadata: _metadata
|
|
4773
4773
|
}, null, _instanceExtraInitializers);
|
|
4774
|
-
__esDecorate$
|
|
4774
|
+
__esDecorate$2(this, null, _restoreModel_decorators, {
|
|
4775
4775
|
kind: "method",
|
|
4776
4776
|
name: "restoreModel",
|
|
4777
4777
|
static: false,
|
|
@@ -4782,7 +4782,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4782
4782
|
},
|
|
4783
4783
|
metadata: _metadata
|
|
4784
4784
|
}, null, _instanceExtraInitializers);
|
|
4785
|
-
__esDecorate$
|
|
4785
|
+
__esDecorate$2(this, null, _setModelExcluded_decorators, {
|
|
4786
4786
|
kind: "method",
|
|
4787
4787
|
name: "setModelExcluded",
|
|
4788
4788
|
static: false,
|
|
@@ -4793,7 +4793,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4793
4793
|
},
|
|
4794
4794
|
metadata: _metadata
|
|
4795
4795
|
}, null, _instanceExtraInitializers);
|
|
4796
|
-
__esDecorate$
|
|
4796
|
+
__esDecorate$2(this, null, _discoverModels_decorators, {
|
|
4797
4797
|
kind: "method",
|
|
4798
4798
|
name: "discoverModels",
|
|
4799
4799
|
static: false,
|
|
@@ -4804,7 +4804,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4804
4804
|
},
|
|
4805
4805
|
metadata: _metadata
|
|
4806
4806
|
}, null, _instanceExtraInitializers);
|
|
4807
|
-
__esDecorate$
|
|
4807
|
+
__esDecorate$2(this, null, _ensureModels_decorators, {
|
|
4808
4808
|
kind: "method",
|
|
4809
4809
|
name: "ensureModels",
|
|
4810
4810
|
static: false,
|
|
@@ -4815,7 +4815,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4815
4815
|
},
|
|
4816
4816
|
metadata: _metadata
|
|
4817
4817
|
}, null, _instanceExtraInitializers);
|
|
4818
|
-
__esDecorate$
|
|
4818
|
+
__esDecorate$2(this, null, _reconcile_decorators, {
|
|
4819
4819
|
kind: "method",
|
|
4820
4820
|
name: "reconcile",
|
|
4821
4821
|
static: false,
|
|
@@ -4826,7 +4826,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4826
4826
|
},
|
|
4827
4827
|
metadata: _metadata
|
|
4828
4828
|
}, null, _instanceExtraInitializers);
|
|
4829
|
-
__esDecorate$
|
|
4829
|
+
__esDecorate$2(this, null, _start_decorators, {
|
|
4830
4830
|
kind: "method",
|
|
4831
4831
|
name: "start",
|
|
4832
4832
|
static: false,
|
|
@@ -4837,7 +4837,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4837
4837
|
},
|
|
4838
4838
|
metadata: _metadata
|
|
4839
4839
|
}, null, _instanceExtraInitializers);
|
|
4840
|
-
__esDecorate$
|
|
4840
|
+
__esDecorate$2(this, null, _cancel_decorators, {
|
|
4841
4841
|
kind: "method",
|
|
4842
4842
|
name: "cancel",
|
|
4843
4843
|
static: false,
|
|
@@ -4848,7 +4848,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4848
4848
|
},
|
|
4849
4849
|
metadata: _metadata
|
|
4850
4850
|
}, null, _instanceExtraInitializers);
|
|
4851
|
-
__esDecorate$
|
|
4851
|
+
__esDecorate$2(this, null, _signOut_decorators, {
|
|
4852
4852
|
kind: "method",
|
|
4853
4853
|
name: "signOut",
|
|
4854
4854
|
static: false,
|
|
@@ -4866,7 +4866,7 @@ let GitHubCopilotAuthorizationController = (() => {
|
|
|
4866
4866
|
value: _metadata
|
|
4867
4867
|
});
|
|
4868
4868
|
}
|
|
4869
|
-
notices = (__runInitializers$
|
|
4869
|
+
notices = (__runInitializers$2(this, _instanceExtraInitializers), []);
|
|
4870
4870
|
failure;
|
|
4871
4871
|
reconciliationFailed = false;
|
|
4872
4872
|
attempt;
|
|
@@ -5264,203 +5264,687 @@ function resolveCopilotResponsesReasoning(ctx, request, candidate) {
|
|
|
5264
5264
|
throw new Error("COPILOT_RESPONSES_REASONING_CORE_REQUIRED");
|
|
5265
5265
|
}
|
|
5266
5266
|
//#endregion
|
|
5267
|
-
//#region lib/types/
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
throw new Error("COPILOT_MANAGED_ADVANCED_STREAM_UNSUPPORTED");
|
|
5281
|
-
},
|
|
5282
|
-
streamSimple: (model, context, options) => coreEventStream(provider.streamSimple(model, context, options))
|
|
5283
|
-
};
|
|
5284
|
-
}
|
|
5285
|
-
//#endregion
|
|
5286
|
-
//#region lib/types/response-error-body.js
|
|
5287
|
-
const maxErrorBytes = 8192;
|
|
5288
|
-
const errorReadTimeoutMs = 250;
|
|
5289
|
-
async function readError(reader) {
|
|
5290
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
5291
|
-
let bytes = 0, chunks = 0, text = "";
|
|
5292
|
-
while (true) {
|
|
5293
|
-
if (chunks++ > maxErrorBytes) return void 0;
|
|
5294
|
-
const chunk = await reader.read();
|
|
5295
|
-
if (chunk.done) break;
|
|
5296
|
-
bytes += chunk.value.byteLength;
|
|
5297
|
-
if (bytes > maxErrorBytes) return void 0;
|
|
5298
|
-
text += decoder.decode(chunk.value, { stream: true });
|
|
5299
|
-
}
|
|
5300
|
-
return JSON.parse(text + decoder.decode());
|
|
5301
|
-
}
|
|
5302
|
-
/** Optional classification evidence only; an unreadable clone leaves native handling unchanged. */
|
|
5303
|
-
async function readResponseErrorJson(response, signal) {
|
|
5304
|
-
if (signal?.aborted) return void 0;
|
|
5305
|
-
let reader;
|
|
5306
|
-
let timeout;
|
|
5307
|
-
let onAbort;
|
|
5308
|
-
try {
|
|
5309
|
-
const clone = response.clone();
|
|
5310
|
-
if (!clone.body) return void 0;
|
|
5311
|
-
reader = clone.body.getReader();
|
|
5312
|
-
const interrupted = new Promise((resolve) => {
|
|
5313
|
-
onAbort = () => resolve(void 0);
|
|
5314
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
5315
|
-
timeout = setTimeout(() => resolve(void 0), errorReadTimeoutMs);
|
|
5316
|
-
if (signal?.aborted) resolve(void 0);
|
|
5317
|
-
});
|
|
5318
|
-
const result = await Promise.race([readError(reader), interrupted]);
|
|
5319
|
-
return signal?.aborted ? void 0 : result;
|
|
5320
|
-
} catch {
|
|
5321
|
-
return;
|
|
5322
|
-
} finally {
|
|
5323
|
-
if (timeout !== void 0) clearTimeout(timeout);
|
|
5324
|
-
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
5325
|
-
if (reader) {
|
|
5326
|
-
try {
|
|
5327
|
-
reader.cancel().catch(() => {});
|
|
5328
|
-
} catch {}
|
|
5329
|
-
try {
|
|
5330
|
-
reader.releaseLock();
|
|
5331
|
-
} catch {}
|
|
5332
|
-
}
|
|
5333
|
-
}
|
|
5267
|
+
//#region lib/types/request-body-evidence.js
|
|
5268
|
+
const REQUEST_BODY_EVIDENCE_LIMITS = Object.freeze({
|
|
5269
|
+
bytes: 16777216,
|
|
5270
|
+
values: 65536,
|
|
5271
|
+
tokens: 131072,
|
|
5272
|
+
depth: 64,
|
|
5273
|
+
keyCharacters: 128
|
|
5274
|
+
});
|
|
5275
|
+
function formatRequestBodyEvidence(evidence, responseHeadersMs) {
|
|
5276
|
+
const elapsed = responseHeadersMs === void 0 ? void 0 : Math.round(responseHeadersMs);
|
|
5277
|
+
const timing = responseHeadersMs !== void 0 && responseHeadersMs >= 0 && elapsed !== void 0 && Number.isSafeInteger(elapsed) ? `Fetch-to-response-headers: ${elapsed} ms (round trip, not upload duration).` : "Fetch-to-response-headers timing unavailable.";
|
|
5278
|
+
if (evidence.state !== "complete") return `Composition unavailable (${evidence.state}); no partial totals inferred. ${timing}`;
|
|
5279
|
+
return `Composition (wire UTF-8 bytes): conversation ${evidence.conversationBytes}, tool definitions ${evidence.toolSchemaBytes}, top-level system/instructions ${evidence.systemBytes}, other/framing ${evidence.otherBytes}. Within conversation (disjoint subsets): image blocks ${evidence.imageBlockBytes}, opaque replay ${evidence.opaqueReplayBytes}, remaining ${evidence.remainingConversationBytes} (text/tool history, framing and unrecognized fields). Image blocks include URLs/references, not decoded image sizes; unknown encodings stay in remaining/other. ${timing}`;
|
|
5334
5280
|
}
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
"invalid-payload": "COPILOT_RESPONSES_REPLAY_INVALID_PAYLOAD: Copilot Responses payload has an invalid replay structure."
|
|
5341
|
-
};
|
|
5342
|
-
/** Fixed diagnostics only: never include provider bodies, IDs, arguments or replay content. */
|
|
5343
|
-
var CopilotResponsesReplayError = class extends Error {
|
|
5344
|
-
constructor(reason = "unsupported") {
|
|
5345
|
-
super(replayDiagnostics[reason]);
|
|
5346
|
-
this.name = "CopilotResponsesReplayError";
|
|
5281
|
+
var EvidenceParseError = class extends Error {
|
|
5282
|
+
state;
|
|
5283
|
+
constructor(state) {
|
|
5284
|
+
super(state);
|
|
5285
|
+
this.state = state;
|
|
5347
5286
|
}
|
|
5348
5287
|
};
|
|
5349
|
-
function
|
|
5350
|
-
|
|
5351
|
-
const prototype = Object.getPrototypeOf(value);
|
|
5352
|
-
return prototype === Object.prototype || prototype === null;
|
|
5353
|
-
}
|
|
5354
|
-
function nonemptyString(value) {
|
|
5355
|
-
return typeof value === "string" && value.trim().length > 0;
|
|
5356
|
-
}
|
|
5357
|
-
function emptyReasoningShell(item) {
|
|
5358
|
-
return item.type === "reasoning" && nonemptyString(item.id) && (item.status === void 0 || item.status === "completed") && Array.isArray(item.summary) && item.summary.length === 0 && (item.content === void 0 || Array.isArray(item.content) && item.content.length === 0) && item.encrypted_content === void 0 && Object.keys(item).every((key) => [
|
|
5359
|
-
"type",
|
|
5360
|
-
"id",
|
|
5361
|
-
"status",
|
|
5362
|
-
"summary",
|
|
5363
|
-
"content",
|
|
5364
|
-
"encrypted_content"
|
|
5365
|
-
].includes(key));
|
|
5366
|
-
}
|
|
5367
|
-
function normalizeItem(item) {
|
|
5368
|
-
if (!isRecord$1(item)) throw new CopilotResponsesReplayError("invalid-payload");
|
|
5369
|
-
if (item.type === "item_reference") throw new CopilotResponsesReplayError();
|
|
5370
|
-
if (emptyReasoningShell(item)) return void 0;
|
|
5371
|
-
if ((item.type === "message" || item.type === void 0) && (item.role === "user" || item.role === "system" || item.role === "developer")) return item;
|
|
5372
|
-
if (!Object.hasOwn(item, "id") || item.id === void 0) return item;
|
|
5373
|
-
if (!nonemptyString(item.id)) throw new CopilotResponsesReplayError("invalid-payload");
|
|
5374
|
-
if (!((item.status === void 0 || item.status === "completed") && (item.type === "message" && item.role === "assistant" && Array.isArray(item.content) || item.type === "function_call" && nonemptyString(item.call_id) && nonemptyString(item.name) && typeof item.arguments === "string" || item.type === "reasoning" && nonemptyString(item.encrypted_content)))) throw new CopilotResponsesReplayError();
|
|
5375
|
-
const normalized = { ...item };
|
|
5376
|
-
delete normalized.id;
|
|
5377
|
-
return normalized;
|
|
5288
|
+
function object$2(value) {
|
|
5289
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5378
5290
|
}
|
|
5379
|
-
/**
|
|
5380
|
-
function
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5291
|
+
/** Diagnostic-only traversal of the original JSON spans; never reserializes or changes a request. */
|
|
5292
|
+
function requestBodyEvidence(body, protocol) {
|
|
5293
|
+
if (body === void 0) return { state: "unavailable" };
|
|
5294
|
+
const totalBytes = Buffer.byteLength(body, "utf8");
|
|
5295
|
+
if (totalBytes > REQUEST_BODY_EVIDENCE_LIMITS.bytes) return {
|
|
5296
|
+
state: "size-limit",
|
|
5297
|
+
totalBytes
|
|
5298
|
+
};
|
|
5299
|
+
let nesting = 0, tokens = 0;
|
|
5300
|
+
for (let index = 0; index < body.length; index++) {
|
|
5301
|
+
const character = body[index];
|
|
5302
|
+
if (character === "{" || character === "[") {
|
|
5303
|
+
if (++nesting > REQUEST_BODY_EVIDENCE_LIMITS.depth) return {
|
|
5304
|
+
state: "work-limit",
|
|
5305
|
+
totalBytes
|
|
5306
|
+
};
|
|
5307
|
+
tokens++;
|
|
5308
|
+
} else if (character === "}" || character === "]") nesting--;
|
|
5309
|
+
else if (character === "\"") {
|
|
5310
|
+
tokens++;
|
|
5311
|
+
while (++index < body.length) if (body[index] === "\\") index++;
|
|
5312
|
+
else if (body[index] === "\"") break;
|
|
5313
|
+
} else if (character !== " " && character !== "\n" && character !== "\r" && character !== " " && character !== ":" && character !== ",") {
|
|
5314
|
+
tokens++;
|
|
5315
|
+
while (index + 1 < body.length && !/[\s,\]}]/u.test(body[index + 1])) index++;
|
|
5391
5316
|
}
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
}
|
|
5396
|
-
} catch (error) {
|
|
5397
|
-
if (error instanceof CopilotResponsesReplayError) throw error;
|
|
5398
|
-
throw new CopilotResponsesReplayError("invalid-payload");
|
|
5317
|
+
if (tokens > REQUEST_BODY_EVIDENCE_LIMITS.tokens) return {
|
|
5318
|
+
state: "work-limit",
|
|
5319
|
+
totalBytes
|
|
5320
|
+
};
|
|
5399
5321
|
}
|
|
5400
|
-
|
|
5401
|
-
const retryLifetimeMs = 6e4;
|
|
5402
|
-
const maxRetryBytes = 2097152;
|
|
5403
|
-
function cacheBytes(value) {
|
|
5404
|
-
let json;
|
|
5322
|
+
let parsed;
|
|
5405
5323
|
try {
|
|
5406
|
-
|
|
5407
|
-
} catch {
|
|
5408
|
-
|
|
5409
|
-
}
|
|
5410
|
-
if (json === void 0 || Buffer.byteLength(json, "utf8") > maxRetryBytes) return void 0;
|
|
5411
|
-
return json;
|
|
5412
|
-
}
|
|
5413
|
-
/** A single lease can admit one HTTP-verified retry at a time; it never reads durable history. */
|
|
5414
|
-
var ResponsesRetryReplay = class {
|
|
5415
|
-
snapshot;
|
|
5416
|
-
active = 0;
|
|
5417
|
-
disposed = false;
|
|
5418
|
-
dispose() {
|
|
5419
|
-
this.disposed = true;
|
|
5420
|
-
this.snapshot = void 0;
|
|
5421
|
-
}
|
|
5422
|
-
belongsTo(sessionId) {
|
|
5423
|
-
return this.snapshot?.sessionId === sessionId;
|
|
5424
|
-
}
|
|
5425
|
-
begin(context, signal, sessionId, modelId) {
|
|
5426
|
-
const contextBytes = cacheBytes(context);
|
|
5427
|
-
const overlapping = this.active++ !== 0;
|
|
5428
|
-
if (overlapping) this.snapshot = void 0;
|
|
5429
|
-
const previous = this.snapshot;
|
|
5430
|
-
if (previous !== void 0 && (signal !== previous.signal || signal?.aborted || previous.sessionId !== sessionId || previous.modelId !== modelId || previous.context !== contextBytes || Date.now() - previous.at >= retryLifetimeMs)) this.snapshot = void 0;
|
|
5431
|
-
const eligible = contextBytes !== void 0 && !overlapping && !this.disposed && !signal?.aborted && this.snapshot;
|
|
5432
|
-
let candidate;
|
|
5433
|
-
let payloadBytes;
|
|
5434
|
-
let finished = false;
|
|
5435
|
-
let observed = false;
|
|
5324
|
+
parsed = JSON.parse(body);
|
|
5325
|
+
} catch (error) {
|
|
5326
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
5436
5327
|
return {
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5328
|
+
state: "invalid-json",
|
|
5329
|
+
totalBytes
|
|
5330
|
+
};
|
|
5331
|
+
}
|
|
5332
|
+
const conversationKey = protocol === "openai-responses" ? "input" : "messages";
|
|
5333
|
+
const systemKey = protocol === "openai-responses" ? "instructions" : protocol === "anthropic-messages" ? "system" : void 0;
|
|
5334
|
+
if (!object$2(parsed) || !Array.isArray(parsed[conversationKey])) return {
|
|
5335
|
+
state: "unsupported-shape",
|
|
5336
|
+
totalBytes
|
|
5337
|
+
};
|
|
5338
|
+
let position = 0, values = 0, conversationBytes = 0, toolSchemaBytes = 0, systemBytes = 0;
|
|
5339
|
+
let imageBlockBytes = 0, opaqueReplayBytes = 0;
|
|
5340
|
+
const whitespace = () => {
|
|
5341
|
+
while (position < body.length && /\s/u.test(body[position])) position++;
|
|
5342
|
+
};
|
|
5343
|
+
const bytes = (start) => Buffer.byteLength(body.slice(start, position), "utf8");
|
|
5344
|
+
const stringEnd = () => {
|
|
5345
|
+
if (body[position++] !== "\"") throw new EvidenceParseError("invalid-json");
|
|
5346
|
+
while (position < body.length) {
|
|
5347
|
+
const character = body[position++];
|
|
5348
|
+
if (character === "\"") return;
|
|
5349
|
+
if (character === "\\") position++;
|
|
5350
|
+
}
|
|
5351
|
+
throw new EvidenceParseError("invalid-json");
|
|
5352
|
+
};
|
|
5353
|
+
const isImage = (value) => protocol === "anthropic-messages" ? value.type === "image" && object$2(value.source) && (value.source.type === "base64" && typeof value.source.data === "string" || value.source.type === "url" && typeof value.source.url === "string") : protocol === "openai-responses" ? value.type === "input_image" && (typeof value.image_url === "string" || typeof value.file_id === "string") : value.type === "image_url" && object$2(value.image_url) && typeof value.image_url.url === "string";
|
|
5354
|
+
const isOpaque = (parent, key, location) => protocol === "openai-responses" ? location === "conversation" && parent.type === "reasoning" && key === "encrypted_content" : location === "content" && protocol === "anthropic-messages" && (parent.type === "thinking" && key === "signature" || parent.type === "redacted_thinking" && key === "data");
|
|
5355
|
+
const visit = (value, depth, location) => {
|
|
5356
|
+
if (++values > REQUEST_BODY_EVIDENCE_LIMITS.values || depth > REQUEST_BODY_EVIDENCE_LIMITS.depth) throw new EvidenceParseError("work-limit");
|
|
5357
|
+
whitespace();
|
|
5358
|
+
const start = position;
|
|
5359
|
+
let image = 0, replay = 0;
|
|
5360
|
+
if (Array.isArray(value)) {
|
|
5361
|
+
if (body[position++] !== "[") throw new EvidenceParseError("invalid-json");
|
|
5362
|
+
for (let index = 0; index < value.length; index++) {
|
|
5363
|
+
if (index > 0) {
|
|
5364
|
+
whitespace();
|
|
5365
|
+
if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
|
|
5366
|
+
}
|
|
5367
|
+
const child = visit(value[index], depth + 1, location);
|
|
5368
|
+
image += child.image;
|
|
5369
|
+
replay += child.replay;
|
|
5370
|
+
}
|
|
5371
|
+
whitespace();
|
|
5372
|
+
if (body[position++] !== "]") throw new EvidenceParseError("invalid-json");
|
|
5373
|
+
} else if (object$2(value)) {
|
|
5374
|
+
if (body[position++] !== "{") throw new EvidenceParseError("invalid-json");
|
|
5375
|
+
const imageBlock = location === "content" && isImage(value);
|
|
5376
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5377
|
+
whitespace();
|
|
5378
|
+
while (body[position] !== "}") {
|
|
5379
|
+
if (seen.size > 0) {
|
|
5380
|
+
if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
|
|
5381
|
+
whitespace();
|
|
5382
|
+
}
|
|
5383
|
+
const keyStart = position;
|
|
5384
|
+
stringEnd();
|
|
5385
|
+
if (position - keyStart > REQUEST_BODY_EVIDENCE_LIMITS.keyCharacters) throw new EvidenceParseError("work-limit");
|
|
5386
|
+
const key = JSON.parse(body.slice(keyStart, position));
|
|
5387
|
+
if (typeof key !== "string" || seen.has(key) || !Object.hasOwn(value, key)) throw new EvidenceParseError("invalid-json");
|
|
5388
|
+
seen.add(key);
|
|
5389
|
+
whitespace();
|
|
5390
|
+
if (body[position++] !== ":") throw new EvidenceParseError("invalid-json");
|
|
5391
|
+
whitespace();
|
|
5392
|
+
const contentArray = key === "content" && (location === "conversation" || location === "content") || protocol === "openai-responses" && location === "conversation" && value.type === "function_call_output" && key === "output";
|
|
5393
|
+
const childLocation = imageBlock ? "other" : depth === 0 && key === conversationKey ? "conversation" : contentArray && Array.isArray(value[key]) ? "content" : "other";
|
|
5394
|
+
const childStart = position, child = visit(value[key], depth + 1, childLocation);
|
|
5395
|
+
const childBytes = depth === 0 || isOpaque(value, key, location) && typeof value[key] === "string" ? bytes(childStart) : 0;
|
|
5396
|
+
if (depth === 0) {
|
|
5397
|
+
if (key === conversationKey) {
|
|
5398
|
+
conversationBytes = childBytes;
|
|
5399
|
+
imageBlockBytes = child.image;
|
|
5400
|
+
opaqueReplayBytes = child.replay;
|
|
5401
|
+
} else if ((key === "tools" || protocol === "openai-completions" && key === "functions") && Array.isArray(value[key])) toolSchemaBytes += childBytes;
|
|
5402
|
+
else if (key === systemKey && (typeof value[key] === "string" || Array.isArray(value[key]))) systemBytes += childBytes;
|
|
5403
|
+
}
|
|
5404
|
+
image += child.image;
|
|
5405
|
+
replay += isOpaque(value, key, location) && typeof value[key] === "string" ? childBytes : child.replay;
|
|
5406
|
+
whitespace();
|
|
5407
|
+
}
|
|
5408
|
+
position++;
|
|
5409
|
+
if (imageBlock) {
|
|
5410
|
+
image = bytes(start);
|
|
5411
|
+
replay = 0;
|
|
5412
|
+
}
|
|
5413
|
+
} else if (typeof value === "string") stringEnd();
|
|
5414
|
+
else {
|
|
5415
|
+
while (position < body.length && !/[\s,\]}]/u.test(body[position])) position++;
|
|
5416
|
+
if (position === start) throw new EvidenceParseError("invalid-json");
|
|
5417
|
+
}
|
|
5418
|
+
return {
|
|
5419
|
+
image,
|
|
5420
|
+
replay
|
|
5421
|
+
};
|
|
5422
|
+
};
|
|
5423
|
+
try {
|
|
5424
|
+
visit(parsed, 0, "root");
|
|
5425
|
+
whitespace();
|
|
5426
|
+
if (position !== body.length) return {
|
|
5427
|
+
state: "invalid-json",
|
|
5428
|
+
totalBytes
|
|
5429
|
+
};
|
|
5430
|
+
} catch (cause) {
|
|
5431
|
+
if (!(cause instanceof EvidenceParseError)) throw cause;
|
|
5432
|
+
return {
|
|
5433
|
+
state: cause.state,
|
|
5434
|
+
totalBytes
|
|
5435
|
+
};
|
|
5436
|
+
}
|
|
5437
|
+
const otherBytes = totalBytes - conversationBytes - toolSchemaBytes - systemBytes;
|
|
5438
|
+
const remainingConversationBytes = conversationBytes - imageBlockBytes - opaqueReplayBytes;
|
|
5439
|
+
if (otherBytes < 0 || remainingConversationBytes < 0) return {
|
|
5440
|
+
state: "invalid-json",
|
|
5441
|
+
totalBytes
|
|
5442
|
+
};
|
|
5443
|
+
return {
|
|
5444
|
+
state: "complete",
|
|
5445
|
+
totalBytes,
|
|
5446
|
+
conversationBytes,
|
|
5447
|
+
toolSchemaBytes,
|
|
5448
|
+
systemBytes,
|
|
5449
|
+
otherBytes,
|
|
5450
|
+
imageBlockBytes,
|
|
5451
|
+
opaqueReplayBytes,
|
|
5452
|
+
remainingConversationBytes
|
|
5453
|
+
};
|
|
5454
|
+
}
|
|
5455
|
+
//#endregion
|
|
5456
|
+
//#region lib/types/replay-recovery.js
|
|
5457
|
+
function record$7(value) {
|
|
5458
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5459
|
+
}
|
|
5460
|
+
function parsed(body) {
|
|
5461
|
+
if (requestBodyEvidence(body, "openai-responses").state !== "complete" || body === void 0) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
|
|
5462
|
+
const payload = JSON.parse(body);
|
|
5463
|
+
if (!record$7(payload) || !Array.isArray(payload.input) || !payload.input.every(record$7)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
5464
|
+
return {
|
|
5465
|
+
input: payload.input,
|
|
5466
|
+
payload
|
|
5467
|
+
};
|
|
5468
|
+
}
|
|
5469
|
+
function hash(item) {
|
|
5470
|
+
if (item.type !== "reasoning" || typeof item.encrypted_content !== "string" || !item.encrypted_content) return void 0;
|
|
5471
|
+
if (item.status !== void 0 && item.status !== "completed") throw new Error("COPILOT_REPLAY_RECOVERY_INCOMPLETE_ITEM");
|
|
5472
|
+
return createHash("sha256").update(JSON.stringify(item)).digest("hex");
|
|
5473
|
+
}
|
|
5474
|
+
/** Host-lifetime opt-in only. Stores fingerprints, never request bodies or opaque replay. */
|
|
5475
|
+
var ReplayRecoveryStore = class {
|
|
5476
|
+
now;
|
|
5477
|
+
owners = /* @__PURE__ */ new Map();
|
|
5478
|
+
constructor(now = Date.now) {
|
|
5479
|
+
this.now = now;
|
|
5480
|
+
}
|
|
5481
|
+
current(owner, proof) {
|
|
5482
|
+
const state = this.owners.get(owner);
|
|
5483
|
+
if (state && (proof !== state.proof || this.now() - state.at >= 36e5)) {
|
|
5484
|
+
this.owners.delete(owner);
|
|
5485
|
+
return;
|
|
5486
|
+
}
|
|
5487
|
+
return state;
|
|
5488
|
+
}
|
|
5489
|
+
view(owner, proof) {
|
|
5490
|
+
const state = this.current(owner, proof);
|
|
5491
|
+
return state ? {
|
|
5492
|
+
state: state.enabled ? "enabled" : "available",
|
|
5493
|
+
revision: state.revision,
|
|
5494
|
+
itemCount: state.hashes.size,
|
|
5495
|
+
model: state.model
|
|
5496
|
+
} : { state: "unavailable" };
|
|
5497
|
+
}
|
|
5498
|
+
recordFailure(owner, proof, model, body) {
|
|
5499
|
+
const hashes = new Set(parsed(body).input.map(hash).filter((value) => value !== void 0));
|
|
5500
|
+
if (!hashes.size) return;
|
|
5501
|
+
const previous = this.current(owner, proof);
|
|
5502
|
+
if (previous?.model === model) for (const value of previous.hashes) hashes.add(value);
|
|
5503
|
+
if (hashes.size > 512) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_LIMIT");
|
|
5504
|
+
this.owners.set(owner, {
|
|
5505
|
+
proof,
|
|
5506
|
+
model,
|
|
5507
|
+
hashes,
|
|
5508
|
+
revision: randomUUID(),
|
|
5509
|
+
at: this.now(),
|
|
5510
|
+
enabled: false
|
|
5511
|
+
});
|
|
5512
|
+
if (this.owners.size > 64) this.owners.delete(this.owners.keys().next().value);
|
|
5513
|
+
}
|
|
5514
|
+
setEnabled(owner, proof, revision, enabled) {
|
|
5515
|
+
const state = this.current(owner, proof);
|
|
5516
|
+
if (!state || revision !== state.revision) throw new Error("COPILOT_REPLAY_RECOVERY_STALE_EVIDENCE");
|
|
5517
|
+
state.enabled = enabled;
|
|
5518
|
+
return this.view(owner, proof);
|
|
5519
|
+
}
|
|
5520
|
+
prepare(owner, proof, model) {
|
|
5521
|
+
const state = this.current(owner, proof);
|
|
5522
|
+
const admitted = state?.enabled && state.model === model ? state.hashes : void 0;
|
|
5523
|
+
return (payload) => {
|
|
5524
|
+
if (!admitted) return payload;
|
|
5525
|
+
if (this.current(owner, proof) !== state) throw new Error("COPILOT_REPLAY_RECOVERY_REVOKED");
|
|
5526
|
+
let body;
|
|
5527
|
+
try {
|
|
5528
|
+
body = JSON.stringify(payload);
|
|
5529
|
+
} catch {
|
|
5530
|
+
throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
5531
|
+
}
|
|
5532
|
+
const decoded = parsed(body);
|
|
5533
|
+
if (decoded.input.filter((item) => {
|
|
5534
|
+
const value = hash(item);
|
|
5535
|
+
return value === void 0 || !admitted.has(value);
|
|
5536
|
+
}).length === decoded.input.length) return payload;
|
|
5537
|
+
if (!record$7(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
|
|
5538
|
+
const input = payload.input.filter((_, index) => {
|
|
5539
|
+
const item = decoded.input[index];
|
|
5540
|
+
const value = hash(item);
|
|
5541
|
+
return value === void 0 || !admitted.has(value);
|
|
5542
|
+
});
|
|
5543
|
+
return {
|
|
5544
|
+
...payload,
|
|
5545
|
+
input
|
|
5546
|
+
};
|
|
5547
|
+
};
|
|
5548
|
+
}
|
|
5549
|
+
remove(owner) {
|
|
5550
|
+
this.owners.delete(owner);
|
|
5551
|
+
}
|
|
5552
|
+
clear() {
|
|
5553
|
+
this.owners.clear();
|
|
5554
|
+
}
|
|
5555
|
+
};
|
|
5556
|
+
//#endregion
|
|
5557
|
+
//#region lib/types/replay-recovery-host.js
|
|
5558
|
+
var __runInitializers$1 = function(thisArg, initializers, value) {
|
|
5559
|
+
var useValue = arguments.length > 2;
|
|
5560
|
+
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5561
|
+
return useValue ? value : void 0;
|
|
5562
|
+
};
|
|
5563
|
+
var __esDecorate$1 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
5564
|
+
function accept(f) {
|
|
5565
|
+
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
5566
|
+
return f;
|
|
5567
|
+
}
|
|
5568
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5569
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5570
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
5571
|
+
var _, done = false;
|
|
5572
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
5573
|
+
var context = {};
|
|
5574
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
5575
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
5576
|
+
context.addInitializer = function(f) {
|
|
5577
|
+
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
5578
|
+
extraInitializers.push(accept(f || null));
|
|
5579
|
+
};
|
|
5580
|
+
var result = (0, decorators[i])(kind === "accessor" ? {
|
|
5581
|
+
get: descriptor.get,
|
|
5582
|
+
set: descriptor.set
|
|
5583
|
+
} : descriptor[key], context);
|
|
5584
|
+
if (kind === "accessor") {
|
|
5585
|
+
if (result === void 0) continue;
|
|
5586
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
5587
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
5588
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
5589
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
5590
|
+
} else if (_ = accept(result)) {
|
|
5591
|
+
if (kind === "field") initializers.unshift(_);
|
|
5592
|
+
else descriptor[key] = _;
|
|
5593
|
+
}
|
|
5594
|
+
}
|
|
5595
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
5596
|
+
done = true;
|
|
5597
|
+
};
|
|
5598
|
+
let ReplayRecoveryController = (() => {
|
|
5599
|
+
let _classSuper = TypertRemoteService;
|
|
5600
|
+
let _instanceExtraInitializers = [];
|
|
5601
|
+
let _get_decorators;
|
|
5602
|
+
let _setEnabled_decorators;
|
|
5603
|
+
return class ReplayRecoveryController extends _classSuper {
|
|
5604
|
+
static {
|
|
5605
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
5606
|
+
_get_decorators = [Remote];
|
|
5607
|
+
_setEnabled_decorators = [Remote];
|
|
5608
|
+
__esDecorate$1(this, null, _get_decorators, {
|
|
5609
|
+
kind: "method",
|
|
5610
|
+
name: "get",
|
|
5611
|
+
static: false,
|
|
5612
|
+
private: false,
|
|
5613
|
+
access: {
|
|
5614
|
+
has: (obj) => "get" in obj,
|
|
5615
|
+
get: (obj) => obj.get
|
|
5616
|
+
},
|
|
5617
|
+
metadata: _metadata
|
|
5618
|
+
}, null, _instanceExtraInitializers);
|
|
5619
|
+
__esDecorate$1(this, null, _setEnabled_decorators, {
|
|
5620
|
+
kind: "method",
|
|
5621
|
+
name: "setEnabled",
|
|
5622
|
+
static: false,
|
|
5623
|
+
private: false,
|
|
5624
|
+
access: {
|
|
5625
|
+
has: (obj) => "setEnabled" in obj,
|
|
5626
|
+
get: (obj) => obj.setEnabled
|
|
5627
|
+
},
|
|
5628
|
+
metadata: _metadata
|
|
5629
|
+
}, null, _instanceExtraInitializers);
|
|
5630
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
5631
|
+
enumerable: true,
|
|
5632
|
+
configurable: true,
|
|
5633
|
+
writable: true,
|
|
5634
|
+
value: _metadata
|
|
5635
|
+
});
|
|
5636
|
+
}
|
|
5637
|
+
store = __runInitializers$1(this, _instanceExtraInitializers);
|
|
5638
|
+
proof;
|
|
5639
|
+
busy;
|
|
5640
|
+
constructor(ctx, store, proof, busy) {
|
|
5641
|
+
super(ctx, "githubCopilotReplayRecovery");
|
|
5642
|
+
this.store = store;
|
|
5643
|
+
this.proof = proof;
|
|
5644
|
+
this.busy = busy;
|
|
5645
|
+
}
|
|
5646
|
+
get(agent) {
|
|
5647
|
+
return this.store.view(agent.session, this.proof());
|
|
5648
|
+
}
|
|
5649
|
+
setEnabled(agent, revision, enabled) {
|
|
5650
|
+
if (this.busy.has(agent.session)) throw new Error("COPILOT_REPLAY_RECOVERY_TURN_ACTIVE");
|
|
5651
|
+
return this.store.setEnabled(agent.session, this.proof(), revision, enabled);
|
|
5652
|
+
}
|
|
5653
|
+
};
|
|
5654
|
+
})();
|
|
5655
|
+
function installReplayRecovery(ctx, proof) {
|
|
5656
|
+
const store = new ReplayRecoveryStore();
|
|
5657
|
+
const requests = /* @__PURE__ */ new WeakMap();
|
|
5658
|
+
const currentRequests = /* @__PURE__ */ new WeakMap();
|
|
5659
|
+
const busy = /* @__PURE__ */ new WeakSet();
|
|
5660
|
+
new ReplayRecoveryController(ctx, store, proof, busy);
|
|
5661
|
+
const removeRequest = ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
|
|
5662
|
+
const result = await next();
|
|
5663
|
+
if (!signal.aborted) {
|
|
5664
|
+
requests.set(signal, {
|
|
5665
|
+
session: agent.session,
|
|
5666
|
+
turn
|
|
5667
|
+
});
|
|
5668
|
+
currentRequests.set(agent.session, signal);
|
|
5669
|
+
busy.add(agent.session);
|
|
5670
|
+
}
|
|
5671
|
+
return result;
|
|
5672
|
+
});
|
|
5673
|
+
const removeEvents = ctx.on("session/event", (session, event) => {
|
|
5674
|
+
if (event.type === "turn/end") {
|
|
5675
|
+
busy.delete(session);
|
|
5676
|
+
currentRequests.delete(session);
|
|
5677
|
+
}
|
|
5678
|
+
});
|
|
5679
|
+
const removeAgent = ctx.on("agent/disposed", ({ agent }) => {
|
|
5680
|
+
store.remove(agent.session);
|
|
5681
|
+
busy.delete(agent.session);
|
|
5682
|
+
currentRequests.delete(agent.session);
|
|
5683
|
+
});
|
|
5684
|
+
let active = true;
|
|
5685
|
+
return {
|
|
5686
|
+
prepare(request) {
|
|
5687
|
+
if (!active || request.signal === void 0 || request.signal.aborted || request.purpose !== void 0 || request.provider !== "github-copilot-preview") return void 0;
|
|
5688
|
+
const binding = requests.get(request.signal);
|
|
5689
|
+
const currentProof = proof();
|
|
5690
|
+
if (!binding || binding.session.id !== request.sessionId || !busy.has(binding.session) || currentProof === void 0) return void 0;
|
|
5691
|
+
const transform = store.prepare(binding.session, currentProof, request.model);
|
|
5692
|
+
const current = () => active && !request.signal?.aborted && proof() === currentProof && currentRequests.get(binding.session) === request.signal && busy.has(binding.session);
|
|
5693
|
+
return {
|
|
5694
|
+
transform(payload) {
|
|
5695
|
+
if (!current()) throw new Error("COPILOT_REPLAY_RECOVERY_REVOKED");
|
|
5696
|
+
return transform(payload);
|
|
5697
|
+
},
|
|
5698
|
+
rejected(body) {
|
|
5699
|
+
if (!current()) return;
|
|
5700
|
+
try {
|
|
5701
|
+
store.recordFailure(binding.session, currentProof, request.model, body);
|
|
5702
|
+
} catch {
|
|
5703
|
+
ctx.logger.warn("[github-copilot] COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
|
|
5704
|
+
}
|
|
5705
|
+
}
|
|
5706
|
+
};
|
|
5707
|
+
},
|
|
5708
|
+
dispose() {
|
|
5709
|
+
active = false;
|
|
5710
|
+
removeRequest();
|
|
5711
|
+
removeEvents();
|
|
5712
|
+
removeAgent();
|
|
5713
|
+
store.clear();
|
|
5714
|
+
}
|
|
5715
|
+
};
|
|
5716
|
+
}
|
|
5717
|
+
//#endregion
|
|
5718
|
+
//#region lib/types/pi-provider-bridge.js
|
|
5719
|
+
/** Retain the same stream object after proving its public surface; only SDK-private nominal identity differs. */
|
|
5720
|
+
function coreEventStream(stream) {
|
|
5721
|
+
return stream;
|
|
5722
|
+
}
|
|
5723
|
+
/**
|
|
5724
|
+
* The published Core adapter consumes streamSimple. Do not pretend its older
|
|
5725
|
+
* protocol-specific clients are interchangeable with a newer SDK's clients.
|
|
5726
|
+
*/
|
|
5727
|
+
function coreProviderView(provider) {
|
|
5728
|
+
return {
|
|
5729
|
+
...provider,
|
|
5730
|
+
stream: () => {
|
|
5731
|
+
throw new Error("COPILOT_MANAGED_ADVANCED_STREAM_UNSUPPORTED");
|
|
5732
|
+
},
|
|
5733
|
+
streamSimple: (model, context, options) => coreEventStream(provider.streamSimple(model, context, options))
|
|
5734
|
+
};
|
|
5735
|
+
}
|
|
5736
|
+
//#endregion
|
|
5737
|
+
//#region lib/types/response-error-body.js
|
|
5738
|
+
const maxErrorBytes = 8192;
|
|
5739
|
+
const errorReadTimeoutMs = 250;
|
|
5740
|
+
async function readError(reader) {
|
|
5741
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
5742
|
+
let bytes = 0, chunks = 0, text = "";
|
|
5743
|
+
while (true) {
|
|
5744
|
+
if (chunks++ > maxErrorBytes) return void 0;
|
|
5745
|
+
const chunk = await reader.read();
|
|
5746
|
+
if (chunk.done) break;
|
|
5747
|
+
bytes += chunk.value.byteLength;
|
|
5748
|
+
if (bytes > maxErrorBytes) return void 0;
|
|
5749
|
+
text += decoder.decode(chunk.value, { stream: true });
|
|
5750
|
+
}
|
|
5751
|
+
return JSON.parse(text + decoder.decode());
|
|
5752
|
+
}
|
|
5753
|
+
/** Optional classification evidence only; an unreadable clone leaves native handling unchanged. */
|
|
5754
|
+
async function readResponseErrorJson(response, signal) {
|
|
5755
|
+
if (signal?.aborted) return void 0;
|
|
5756
|
+
let reader;
|
|
5757
|
+
let timeout;
|
|
5758
|
+
let onAbort;
|
|
5759
|
+
try {
|
|
5760
|
+
const clone = response.clone();
|
|
5761
|
+
if (!clone.body) return void 0;
|
|
5762
|
+
reader = clone.body.getReader();
|
|
5763
|
+
const interrupted = new Promise((resolve) => {
|
|
5764
|
+
onAbort = () => resolve(void 0);
|
|
5765
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
5766
|
+
timeout = setTimeout(() => resolve(void 0), errorReadTimeoutMs);
|
|
5767
|
+
if (signal?.aborted) resolve(void 0);
|
|
5768
|
+
});
|
|
5769
|
+
const result = await Promise.race([readError(reader), interrupted]);
|
|
5770
|
+
return signal?.aborted ? void 0 : result;
|
|
5771
|
+
} catch {
|
|
5772
|
+
return;
|
|
5773
|
+
} finally {
|
|
5774
|
+
if (timeout !== void 0) clearTimeout(timeout);
|
|
5775
|
+
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
5776
|
+
if (reader) {
|
|
5777
|
+
try {
|
|
5778
|
+
reader.cancel().catch(() => {});
|
|
5779
|
+
} catch {}
|
|
5780
|
+
try {
|
|
5781
|
+
reader.releaseLock();
|
|
5782
|
+
} catch {}
|
|
5783
|
+
}
|
|
5784
|
+
}
|
|
5785
|
+
}
|
|
5786
|
+
//#endregion
|
|
5787
|
+
//#region lib/types/responses-replay-compat.js
|
|
5788
|
+
const replayDiagnostics = {
|
|
5789
|
+
"scope-mismatch": "COPILOT_RESPONSES_REPLAY_SCOPE_MISMATCH: Copilot Responses input references belong to a different connection.",
|
|
5790
|
+
unsupported: "COPILOT_RESPONSES_REPLAY_UNSUPPORTED: Copilot Responses input cannot be replayed safely without connection-scoped references.",
|
|
5791
|
+
"invalid-payload": "COPILOT_RESPONSES_REPLAY_INVALID_PAYLOAD: Copilot Responses payload has an invalid replay structure."
|
|
5792
|
+
};
|
|
5793
|
+
/** Fixed diagnostics and bounded counts only; never retain request or replay content. */
|
|
5794
|
+
var CopilotResponsesReplayError = class extends Error {
|
|
5795
|
+
constructor(reason = "unsupported", dispatch) {
|
|
5796
|
+
super(replayDiagnostics[reason] + (reason === "scope-mismatch" && dispatch !== void 0 ? ` ${replayDispatchEvidence(dispatch)}` : ""));
|
|
5797
|
+
this.name = "CopilotResponsesReplayError";
|
|
5798
|
+
}
|
|
5799
|
+
};
|
|
5800
|
+
function replayDispatchEvidence(dispatch) {
|
|
5801
|
+
const presence = (value) => value === void 0 ? "unavailable" : value ? "present" : "absent";
|
|
5802
|
+
const headers = `sessionHeader=${presence(dispatch.sessionHeader)}, clientRequestHeader=${presence(dispatch.clientRequestHeader)}.`;
|
|
5803
|
+
const evidence = requestBodyEvidence(dispatch.body, "openai-responses");
|
|
5804
|
+
const unavailable = (state) => `Replay structure unavailable (${state}); no zero counts inferred. ${headers}`;
|
|
5805
|
+
if (evidence.state !== "complete" || dispatch.body === void 0) return unavailable(evidence.state);
|
|
5806
|
+
const payload = JSON.parse(dispatch.body);
|
|
5807
|
+
if (!isRecord$1(payload) || !Array.isArray(payload.input) || !payload.input.every(isRecord$1)) return unavailable("unsupported-shape");
|
|
5808
|
+
let directIds = 0, references = 0, encryptedReasoning = 0, otherItems = 0;
|
|
5809
|
+
for (const item of payload.input) {
|
|
5810
|
+
if (Object.hasOwn(item, "id")) directIds++;
|
|
5811
|
+
if (item.type === "item_reference") references++;
|
|
5812
|
+
if (item.type === "reasoning" && typeof item.encrypted_content === "string" && item.encrypted_content.length > 0) encryptedReasoning++;
|
|
5813
|
+
const known = typeof item.type === "string" && [
|
|
5814
|
+
"message",
|
|
5815
|
+
"reasoning",
|
|
5816
|
+
"function_call",
|
|
5817
|
+
"function_call_output",
|
|
5818
|
+
"item_reference"
|
|
5819
|
+
].includes(item.type);
|
|
5820
|
+
const message = item.type === void 0 && typeof item.role === "string" && [
|
|
5821
|
+
"user",
|
|
5822
|
+
"system",
|
|
5823
|
+
"developer",
|
|
5824
|
+
"assistant"
|
|
5825
|
+
].includes(item.role);
|
|
5826
|
+
if (!known && !message) otherItems++;
|
|
5827
|
+
}
|
|
5828
|
+
const previous = payload.previous_response_id;
|
|
5829
|
+
const previousResponse = previous === void 0 || previous === null || previous === "" ? "absent" : typeof previous === "string" ? "present" : "invalid";
|
|
5830
|
+
const store = payload.store === void 0 ? "absent" : typeof payload.store === "boolean" ? String(payload.store) : "invalid";
|
|
5831
|
+
return `Dispatched Responses structure: items=${payload.input.length}, directIds=${directIds}, references=${references}, encryptedReasoning=${encryptedReasoning}, otherItems=${otherItems}; previousResponse=${previousResponse}, store=${store}; ${headers} Counts do not identify the rejected item or prove opaque replay is portable. History, authorization and native retry policy are unchanged.`;
|
|
5832
|
+
}
|
|
5833
|
+
function isRecord$1(value) {
|
|
5834
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
5835
|
+
const prototype = Object.getPrototypeOf(value);
|
|
5836
|
+
return prototype === Object.prototype || prototype === null;
|
|
5837
|
+
}
|
|
5838
|
+
function nonemptyString(value) {
|
|
5839
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
5840
|
+
}
|
|
5841
|
+
function emptyReasoningShell(item) {
|
|
5842
|
+
return item.type === "reasoning" && nonemptyString(item.id) && (item.status === void 0 || item.status === "completed") && Array.isArray(item.summary) && item.summary.length === 0 && (item.content === void 0 || Array.isArray(item.content) && item.content.length === 0) && item.encrypted_content === void 0 && Object.keys(item).every((key) => [
|
|
5843
|
+
"type",
|
|
5844
|
+
"id",
|
|
5845
|
+
"status",
|
|
5846
|
+
"summary",
|
|
5847
|
+
"content",
|
|
5848
|
+
"encrypted_content"
|
|
5849
|
+
].includes(key));
|
|
5850
|
+
}
|
|
5851
|
+
function normalizeItem(item) {
|
|
5852
|
+
if (!isRecord$1(item)) throw new CopilotResponsesReplayError("invalid-payload");
|
|
5853
|
+
if (item.type === "item_reference") throw new CopilotResponsesReplayError();
|
|
5854
|
+
if (emptyReasoningShell(item)) return void 0;
|
|
5855
|
+
if ((item.type === "message" || item.type === void 0) && (item.role === "user" || item.role === "system" || item.role === "developer")) return item;
|
|
5856
|
+
if (!Object.hasOwn(item, "id") || item.id === void 0) return item;
|
|
5857
|
+
if (!nonemptyString(item.id)) throw new CopilotResponsesReplayError("invalid-payload");
|
|
5858
|
+
if (!((item.status === void 0 || item.status === "completed") && (item.type === "message" && item.role === "assistant" && Array.isArray(item.content) || item.type === "function_call" && nonemptyString(item.call_id) && nonemptyString(item.name) && typeof item.arguments === "string" || item.type === "reasoning" && nonemptyString(item.encrypted_content)))) throw new CopilotResponsesReplayError();
|
|
5859
|
+
const normalized = { ...item };
|
|
5860
|
+
delete normalized.id;
|
|
5861
|
+
return normalized;
|
|
5862
|
+
}
|
|
5863
|
+
/** Normalize only the outgoing managed Responses payload, never stored history/context. */
|
|
5864
|
+
function normalizeCopilotResponsesPayload(payload) {
|
|
5865
|
+
try {
|
|
5866
|
+
if (!isRecord$1(payload) || typeof payload.input !== "string" && !Array.isArray(payload.input)) throw new CopilotResponsesReplayError("invalid-payload");
|
|
5867
|
+
if (payload.previous_response_id !== void 0 && payload.previous_response_id !== null && payload.previous_response_id !== "") throw new CopilotResponsesReplayError(typeof payload.previous_response_id === "string" ? "unsupported" : "invalid-payload");
|
|
5868
|
+
if (typeof payload.input === "string") return payload;
|
|
5869
|
+
let changed = false;
|
|
5870
|
+
const input = [];
|
|
5871
|
+
for (const item of payload.input) {
|
|
5872
|
+
const normalized = normalizeItem(item);
|
|
5873
|
+
changed ||= normalized !== item;
|
|
5874
|
+
if (normalized !== void 0) input.push(normalized);
|
|
5875
|
+
}
|
|
5876
|
+
return changed ? {
|
|
5877
|
+
...payload,
|
|
5878
|
+
input
|
|
5879
|
+
} : payload;
|
|
5880
|
+
} catch (error) {
|
|
5881
|
+
if (error instanceof CopilotResponsesReplayError) throw error;
|
|
5882
|
+
throw new CopilotResponsesReplayError("invalid-payload");
|
|
5883
|
+
}
|
|
5884
|
+
}
|
|
5885
|
+
const retryLifetimeMs = 6e4;
|
|
5886
|
+
const maxRetryBytes = 2097152;
|
|
5887
|
+
function cacheBytes(value) {
|
|
5888
|
+
let json;
|
|
5889
|
+
try {
|
|
5890
|
+
json = JSON.stringify(value);
|
|
5891
|
+
} catch {
|
|
5892
|
+
return;
|
|
5893
|
+
}
|
|
5894
|
+
if (json === void 0 || Buffer.byteLength(json, "utf8") > maxRetryBytes) return void 0;
|
|
5895
|
+
return json;
|
|
5896
|
+
}
|
|
5897
|
+
/** A single lease can admit one HTTP-verified retry at a time; it never reads durable history. */
|
|
5898
|
+
var ResponsesRetryReplay = class {
|
|
5899
|
+
snapshot;
|
|
5900
|
+
active = 0;
|
|
5901
|
+
disposed = false;
|
|
5902
|
+
dispose() {
|
|
5903
|
+
this.disposed = true;
|
|
5904
|
+
this.snapshot = void 0;
|
|
5905
|
+
}
|
|
5906
|
+
belongsTo(sessionId) {
|
|
5907
|
+
return this.snapshot?.sessionId === sessionId;
|
|
5908
|
+
}
|
|
5909
|
+
begin(context, signal, sessionId, modelId) {
|
|
5910
|
+
const contextBytes = cacheBytes(context);
|
|
5911
|
+
const overlapping = this.active++ !== 0;
|
|
5912
|
+
if (overlapping) this.snapshot = void 0;
|
|
5913
|
+
const previous = this.snapshot;
|
|
5914
|
+
if (previous !== void 0 && (signal !== previous.signal || signal?.aborted || previous.sessionId !== sessionId || previous.modelId !== modelId || previous.context !== contextBytes || Date.now() - previous.at >= retryLifetimeMs)) this.snapshot = void 0;
|
|
5915
|
+
const eligible = contextBytes !== void 0 && !overlapping && !this.disposed && !signal?.aborted && this.snapshot;
|
|
5916
|
+
let candidate;
|
|
5917
|
+
let payloadBytes;
|
|
5918
|
+
let finished = false;
|
|
5919
|
+
let observed = false;
|
|
5920
|
+
return {
|
|
5921
|
+
normalize: (payload) => {
|
|
5922
|
+
if (this.disposed || signal?.aborted) throw new CopilotResponsesReplayError();
|
|
5923
|
+
const rawBytes = cacheBytes(payload);
|
|
5924
|
+
let normalized;
|
|
5925
|
+
let reused = false;
|
|
5926
|
+
try {
|
|
5927
|
+
normalized = normalizeCopilotResponsesPayload(payload);
|
|
5928
|
+
} catch (error) {
|
|
5929
|
+
if (!(error instanceof CopilotResponsesReplayError) || !eligible || !isRecord$1(payload) || !Array.isArray(payload.input) || !isRecord$1(eligible.raw) || !Array.isArray(eligible.raw.input)) {
|
|
5930
|
+
this.snapshot = void 0;
|
|
5931
|
+
throw error;
|
|
5932
|
+
}
|
|
5933
|
+
try {
|
|
5934
|
+
const prior = eligible.raw.input;
|
|
5935
|
+
if (payload.input.length !== prior.length) throw error;
|
|
5936
|
+
let references = 0;
|
|
5937
|
+
const restored = payload.input.map((item, index) => {
|
|
5938
|
+
if (!isRecord$1(item) || !Object.hasOwn(item, "id")) return item;
|
|
5939
|
+
const original = prior[index];
|
|
5940
|
+
if (!isRecord$1(original) || !nonemptyString(item.id) || original.id !== item.id || ![
|
|
5941
|
+
"reasoning",
|
|
5942
|
+
"message",
|
|
5943
|
+
"function_call"
|
|
5944
|
+
].includes(String(original.type)) || normalizeItem(original) === original) throw error;
|
|
5945
|
+
if (item.type === "item_reference") {
|
|
5946
|
+
if (Object.keys(item).length !== 2) throw error;
|
|
5947
|
+
} else if (item.type !== original.type || Object.keys(item).length >= Object.keys(original).length || Object.entries(item).some(([key, value]) => !Object.hasOwn(original, key) || cacheBytes(value) !== cacheBytes(original[key]))) throw error;
|
|
5464
5948
|
references++;
|
|
5465
5949
|
return original;
|
|
5466
5950
|
});
|
|
@@ -5526,194 +6010,6 @@ async function isCopilotInputItemScopeError(response, signal) {
|
|
|
5526
6010
|
//#region lib/types/request-body-timeout-marker.js
|
|
5527
6011
|
const REQUEST_BODY_TIMEOUT_MARKER = "COPILOT_REQUEST_BODY_TIMEOUT: Copilot returned HTTP 408 / user_request_timeout while reading the request body; this is not context-window overflow.";
|
|
5528
6012
|
//#endregion
|
|
5529
|
-
//#region lib/types/request-body-evidence.js
|
|
5530
|
-
const REQUEST_BODY_EVIDENCE_LIMITS = Object.freeze({
|
|
5531
|
-
bytes: 16777216,
|
|
5532
|
-
values: 65536,
|
|
5533
|
-
tokens: 131072,
|
|
5534
|
-
depth: 64,
|
|
5535
|
-
keyCharacters: 128
|
|
5536
|
-
});
|
|
5537
|
-
function formatRequestBodyEvidence(evidence, responseHeadersMs) {
|
|
5538
|
-
const elapsed = responseHeadersMs === void 0 ? void 0 : Math.round(responseHeadersMs);
|
|
5539
|
-
const timing = responseHeadersMs !== void 0 && responseHeadersMs >= 0 && elapsed !== void 0 && Number.isSafeInteger(elapsed) ? `Fetch-to-response-headers: ${elapsed} ms (round trip, not upload duration).` : "Fetch-to-response-headers timing unavailable.";
|
|
5540
|
-
if (evidence.state !== "complete") return `Composition unavailable (${evidence.state}); no partial totals inferred. ${timing}`;
|
|
5541
|
-
return `Composition (wire UTF-8 bytes): conversation ${evidence.conversationBytes}, tool definitions ${evidence.toolSchemaBytes}, top-level system/instructions ${evidence.systemBytes}, other/framing ${evidence.otherBytes}. Within conversation (disjoint subsets): image blocks ${evidence.imageBlockBytes}, opaque replay ${evidence.opaqueReplayBytes}, remaining ${evidence.remainingConversationBytes} (text/tool history, framing and unrecognized fields). Image blocks include URLs/references, not decoded image sizes; unknown encodings stay in remaining/other. ${timing}`;
|
|
5542
|
-
}
|
|
5543
|
-
var EvidenceParseError = class extends Error {
|
|
5544
|
-
state;
|
|
5545
|
-
constructor(state) {
|
|
5546
|
-
super(state);
|
|
5547
|
-
this.state = state;
|
|
5548
|
-
}
|
|
5549
|
-
};
|
|
5550
|
-
function object$2(value) {
|
|
5551
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5552
|
-
}
|
|
5553
|
-
/** Diagnostic-only traversal of the original JSON spans; never reserializes or changes a request. */
|
|
5554
|
-
function requestBodyEvidence(body, protocol) {
|
|
5555
|
-
if (body === void 0) return { state: "unavailable" };
|
|
5556
|
-
const totalBytes = Buffer.byteLength(body, "utf8");
|
|
5557
|
-
if (totalBytes > REQUEST_BODY_EVIDENCE_LIMITS.bytes) return {
|
|
5558
|
-
state: "size-limit",
|
|
5559
|
-
totalBytes
|
|
5560
|
-
};
|
|
5561
|
-
let nesting = 0, tokens = 0;
|
|
5562
|
-
for (let index = 0; index < body.length; index++) {
|
|
5563
|
-
const character = body[index];
|
|
5564
|
-
if (character === "{" || character === "[") {
|
|
5565
|
-
if (++nesting > REQUEST_BODY_EVIDENCE_LIMITS.depth) return {
|
|
5566
|
-
state: "work-limit",
|
|
5567
|
-
totalBytes
|
|
5568
|
-
};
|
|
5569
|
-
tokens++;
|
|
5570
|
-
} else if (character === "}" || character === "]") nesting--;
|
|
5571
|
-
else if (character === "\"") {
|
|
5572
|
-
tokens++;
|
|
5573
|
-
while (++index < body.length) if (body[index] === "\\") index++;
|
|
5574
|
-
else if (body[index] === "\"") break;
|
|
5575
|
-
} else if (character !== " " && character !== "\n" && character !== "\r" && character !== " " && character !== ":" && character !== ",") {
|
|
5576
|
-
tokens++;
|
|
5577
|
-
while (index + 1 < body.length && !/[\s,\]}]/u.test(body[index + 1])) index++;
|
|
5578
|
-
}
|
|
5579
|
-
if (tokens > REQUEST_BODY_EVIDENCE_LIMITS.tokens) return {
|
|
5580
|
-
state: "work-limit",
|
|
5581
|
-
totalBytes
|
|
5582
|
-
};
|
|
5583
|
-
}
|
|
5584
|
-
let parsed;
|
|
5585
|
-
try {
|
|
5586
|
-
parsed = JSON.parse(body);
|
|
5587
|
-
} catch (error) {
|
|
5588
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
5589
|
-
return {
|
|
5590
|
-
state: "invalid-json",
|
|
5591
|
-
totalBytes
|
|
5592
|
-
};
|
|
5593
|
-
}
|
|
5594
|
-
const conversationKey = protocol === "openai-responses" ? "input" : "messages";
|
|
5595
|
-
const systemKey = protocol === "openai-responses" ? "instructions" : protocol === "anthropic-messages" ? "system" : void 0;
|
|
5596
|
-
if (!object$2(parsed) || !Array.isArray(parsed[conversationKey])) return {
|
|
5597
|
-
state: "unsupported-shape",
|
|
5598
|
-
totalBytes
|
|
5599
|
-
};
|
|
5600
|
-
let position = 0, values = 0, conversationBytes = 0, toolSchemaBytes = 0, systemBytes = 0;
|
|
5601
|
-
let imageBlockBytes = 0, opaqueReplayBytes = 0;
|
|
5602
|
-
const whitespace = () => {
|
|
5603
|
-
while (position < body.length && /\s/u.test(body[position])) position++;
|
|
5604
|
-
};
|
|
5605
|
-
const bytes = (start) => Buffer.byteLength(body.slice(start, position), "utf8");
|
|
5606
|
-
const stringEnd = () => {
|
|
5607
|
-
if (body[position++] !== "\"") throw new EvidenceParseError("invalid-json");
|
|
5608
|
-
while (position < body.length) {
|
|
5609
|
-
const character = body[position++];
|
|
5610
|
-
if (character === "\"") return;
|
|
5611
|
-
if (character === "\\") position++;
|
|
5612
|
-
}
|
|
5613
|
-
throw new EvidenceParseError("invalid-json");
|
|
5614
|
-
};
|
|
5615
|
-
const isImage = (value) => protocol === "anthropic-messages" ? value.type === "image" && object$2(value.source) && (value.source.type === "base64" && typeof value.source.data === "string" || value.source.type === "url" && typeof value.source.url === "string") : protocol === "openai-responses" ? value.type === "input_image" && (typeof value.image_url === "string" || typeof value.file_id === "string") : value.type === "image_url" && object$2(value.image_url) && typeof value.image_url.url === "string";
|
|
5616
|
-
const isOpaque = (parent, key, location) => protocol === "openai-responses" ? location === "conversation" && parent.type === "reasoning" && key === "encrypted_content" : location === "content" && protocol === "anthropic-messages" && (parent.type === "thinking" && key === "signature" || parent.type === "redacted_thinking" && key === "data");
|
|
5617
|
-
const visit = (value, depth, location) => {
|
|
5618
|
-
if (++values > REQUEST_BODY_EVIDENCE_LIMITS.values || depth > REQUEST_BODY_EVIDENCE_LIMITS.depth) throw new EvidenceParseError("work-limit");
|
|
5619
|
-
whitespace();
|
|
5620
|
-
const start = position;
|
|
5621
|
-
let image = 0, replay = 0;
|
|
5622
|
-
if (Array.isArray(value)) {
|
|
5623
|
-
if (body[position++] !== "[") throw new EvidenceParseError("invalid-json");
|
|
5624
|
-
for (let index = 0; index < value.length; index++) {
|
|
5625
|
-
if (index > 0) {
|
|
5626
|
-
whitespace();
|
|
5627
|
-
if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
|
|
5628
|
-
}
|
|
5629
|
-
const child = visit(value[index], depth + 1, location);
|
|
5630
|
-
image += child.image;
|
|
5631
|
-
replay += child.replay;
|
|
5632
|
-
}
|
|
5633
|
-
whitespace();
|
|
5634
|
-
if (body[position++] !== "]") throw new EvidenceParseError("invalid-json");
|
|
5635
|
-
} else if (object$2(value)) {
|
|
5636
|
-
if (body[position++] !== "{") throw new EvidenceParseError("invalid-json");
|
|
5637
|
-
const imageBlock = location === "content" && isImage(value);
|
|
5638
|
-
const seen = /* @__PURE__ */ new Set();
|
|
5639
|
-
whitespace();
|
|
5640
|
-
while (body[position] !== "}") {
|
|
5641
|
-
if (seen.size > 0) {
|
|
5642
|
-
if (body[position++] !== ",") throw new EvidenceParseError("invalid-json");
|
|
5643
|
-
whitespace();
|
|
5644
|
-
}
|
|
5645
|
-
const keyStart = position;
|
|
5646
|
-
stringEnd();
|
|
5647
|
-
if (position - keyStart > REQUEST_BODY_EVIDENCE_LIMITS.keyCharacters) throw new EvidenceParseError("work-limit");
|
|
5648
|
-
const key = JSON.parse(body.slice(keyStart, position));
|
|
5649
|
-
if (typeof key !== "string" || seen.has(key) || !Object.hasOwn(value, key)) throw new EvidenceParseError("invalid-json");
|
|
5650
|
-
seen.add(key);
|
|
5651
|
-
whitespace();
|
|
5652
|
-
if (body[position++] !== ":") throw new EvidenceParseError("invalid-json");
|
|
5653
|
-
whitespace();
|
|
5654
|
-
const childLocation = imageBlock ? "other" : depth === 0 && key === conversationKey ? "conversation" : key === "content" && (location === "conversation" || location === "content") && Array.isArray(value[key]) ? "content" : "other";
|
|
5655
|
-
const childStart = position, child = visit(value[key], depth + 1, childLocation);
|
|
5656
|
-
const childBytes = depth === 0 || isOpaque(value, key, location) && typeof value[key] === "string" ? bytes(childStart) : 0;
|
|
5657
|
-
if (depth === 0) {
|
|
5658
|
-
if (key === conversationKey) {
|
|
5659
|
-
conversationBytes = childBytes;
|
|
5660
|
-
imageBlockBytes = child.image;
|
|
5661
|
-
opaqueReplayBytes = child.replay;
|
|
5662
|
-
} else if ((key === "tools" || protocol === "openai-completions" && key === "functions") && Array.isArray(value[key])) toolSchemaBytes += childBytes;
|
|
5663
|
-
else if (key === systemKey && (typeof value[key] === "string" || Array.isArray(value[key]))) systemBytes += childBytes;
|
|
5664
|
-
}
|
|
5665
|
-
image += child.image;
|
|
5666
|
-
replay += isOpaque(value, key, location) && typeof value[key] === "string" ? childBytes : child.replay;
|
|
5667
|
-
whitespace();
|
|
5668
|
-
}
|
|
5669
|
-
position++;
|
|
5670
|
-
if (imageBlock) {
|
|
5671
|
-
image = bytes(start);
|
|
5672
|
-
replay = 0;
|
|
5673
|
-
}
|
|
5674
|
-
} else if (typeof value === "string") stringEnd();
|
|
5675
|
-
else {
|
|
5676
|
-
while (position < body.length && !/[\s,\]}]/u.test(body[position])) position++;
|
|
5677
|
-
if (position === start) throw new EvidenceParseError("invalid-json");
|
|
5678
|
-
}
|
|
5679
|
-
return {
|
|
5680
|
-
image,
|
|
5681
|
-
replay
|
|
5682
|
-
};
|
|
5683
|
-
};
|
|
5684
|
-
try {
|
|
5685
|
-
visit(parsed, 0, "root");
|
|
5686
|
-
whitespace();
|
|
5687
|
-
if (position !== body.length) return {
|
|
5688
|
-
state: "invalid-json",
|
|
5689
|
-
totalBytes
|
|
5690
|
-
};
|
|
5691
|
-
} catch (cause) {
|
|
5692
|
-
if (!(cause instanceof EvidenceParseError)) throw cause;
|
|
5693
|
-
return {
|
|
5694
|
-
state: cause.state,
|
|
5695
|
-
totalBytes
|
|
5696
|
-
};
|
|
5697
|
-
}
|
|
5698
|
-
const otherBytes = totalBytes - conversationBytes - toolSchemaBytes - systemBytes;
|
|
5699
|
-
const remainingConversationBytes = conversationBytes - imageBlockBytes - opaqueReplayBytes;
|
|
5700
|
-
if (otherBytes < 0 || remainingConversationBytes < 0) return {
|
|
5701
|
-
state: "invalid-json",
|
|
5702
|
-
totalBytes
|
|
5703
|
-
};
|
|
5704
|
-
return {
|
|
5705
|
-
state: "complete",
|
|
5706
|
-
totalBytes,
|
|
5707
|
-
conversationBytes,
|
|
5708
|
-
toolSchemaBytes,
|
|
5709
|
-
systemBytes,
|
|
5710
|
-
otherBytes,
|
|
5711
|
-
imageBlockBytes,
|
|
5712
|
-
opaqueReplayBytes,
|
|
5713
|
-
remainingConversationBytes
|
|
5714
|
-
};
|
|
5715
|
-
}
|
|
5716
|
-
//#endregion
|
|
5717
6013
|
//#region lib/types/request-body-timeout.js
|
|
5718
6014
|
const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
|
|
5719
6015
|
function record$6(value) {
|
|
@@ -6063,7 +6359,8 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
6063
6359
|
if (lease.signal.aborted || options.signal?.aborted) throw new Error("COPILOT_MANAGED_ABORTED");
|
|
6064
6360
|
try {
|
|
6065
6361
|
const effective = replacement === void 0 ? payload : replacement;
|
|
6066
|
-
|
|
6362
|
+
const normalized = retry === void 0 ? normalizeCopilotResponsesPayload(effective) : retry.normalize(effective);
|
|
6363
|
+
return guard.recoverReplay === void 0 ? normalized : guard.recoverReplay(normalized);
|
|
6067
6364
|
} catch (error) {
|
|
6068
6365
|
if (error instanceof CopilotResponsesReplayError) reportReplayFailure(error);
|
|
6069
6366
|
throw error;
|
|
@@ -6073,6 +6370,12 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
6073
6370
|
const observeResponse = async (input, init) => {
|
|
6074
6371
|
guard.onRequestBodyTimeout?.(void 0);
|
|
6075
6372
|
liveness?.beginRequest(typeof init?.body === "string" ? init.body : void 0);
|
|
6373
|
+
const replayHeaders = responses && init?.headers !== void 0 ? new Headers(init.headers) : void 0;
|
|
6374
|
+
const replayDispatch = responses ? {
|
|
6375
|
+
body: typeof init?.body === "string" ? init.body : void 0,
|
|
6376
|
+
sessionHeader: replayHeaders?.has("session_id"),
|
|
6377
|
+
clientRequestHeader: replayHeaders?.has("x-client-request-id")
|
|
6378
|
+
} : void 0;
|
|
6076
6379
|
let response;
|
|
6077
6380
|
const startedAt = performance.now();
|
|
6078
6381
|
try {
|
|
@@ -6091,8 +6394,10 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
6091
6394
|
if (!lease.signal.aborted && !options.signal?.aborted) guard.onRequestBodyTimeout(diagnostic);
|
|
6092
6395
|
}
|
|
6093
6396
|
if (response.status === 401) {
|
|
6094
|
-
if (responses && await isCopilotInputItemScopeError(response, lease.signal))
|
|
6095
|
-
|
|
6397
|
+
if (responses && await isCopilotInputItemScopeError(response, lease.signal)) {
|
|
6398
|
+
guard.onReplayScopeRejected?.(replayDispatch?.body);
|
|
6399
|
+
reportReplayFailure(new CopilotResponsesReplayError("scope-mismatch", replayDispatch));
|
|
6400
|
+
} else unauthorized = true;
|
|
6096
6401
|
}
|
|
6097
6402
|
return liveness?.observe(response) ?? response;
|
|
6098
6403
|
};
|
|
@@ -8544,7 +8849,8 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
8544
8849
|
refreshRejected;
|
|
8545
8850
|
requestBudgetSettings;
|
|
8546
8851
|
accountModelSettings;
|
|
8547
|
-
|
|
8852
|
+
replayRecovery;
|
|
8853
|
+
constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery) {
|
|
8548
8854
|
super(optionsFor());
|
|
8549
8855
|
this.lifetime = lifetime;
|
|
8550
8856
|
this.optionsFor = optionsFor;
|
|
@@ -8552,6 +8858,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
8552
8858
|
this.refreshRejected = refreshRejected;
|
|
8553
8859
|
this.requestBudgetSettings = requestBudgetSettings;
|
|
8554
8860
|
this.accountModelSettings = accountModelSettings;
|
|
8861
|
+
this.replayRecovery = replayRecovery;
|
|
8555
8862
|
}
|
|
8556
8863
|
async listModels(provider) {
|
|
8557
8864
|
owned(provider);
|
|
@@ -8665,6 +8972,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
8665
8972
|
if (typeof mapping !== "string" || mapping.length === 0) throw failure("COPILOT_PREVIEW_REASONING_UNSUPPORTED", "INVALID_REQUEST");
|
|
8666
8973
|
}
|
|
8667
8974
|
let requestFailure;
|
|
8975
|
+
const recovery = owner.replayRecovery?.prepare(options);
|
|
8668
8976
|
let wireAbort;
|
|
8669
8977
|
let bodyTimeout;
|
|
8670
8978
|
let liveness;
|
|
@@ -8691,6 +8999,10 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
8691
8999
|
try {
|
|
8692
9000
|
const native = new PiAiAdapter(owner.optionsFor(lease, {
|
|
8693
9001
|
inspectRequest,
|
|
9002
|
+
...recovery === void 0 ? {} : {
|
|
9003
|
+
recoverReplay: recovery.transform,
|
|
9004
|
+
onReplayScopeRejected: recovery.rejected
|
|
9005
|
+
},
|
|
8694
9006
|
onWireAbort(code) {
|
|
8695
9007
|
wireAbort = code;
|
|
8696
9008
|
},
|
|
@@ -8830,6 +9142,10 @@ function apply$1(ctx, config = {}) {
|
|
|
8830
9142
|
const proofFor = (snapshot) => source.readSnapshot() === snapshot && snapshotProof !== void 0 && snapshotProof.expires > Date.now() ? displayProofFor(snapshot) : void 0;
|
|
8831
9143
|
const exclusionTurns = new ModelExclusionTurns();
|
|
8832
9144
|
const lifetime = new PreviewLifetime(store, source, proofFor, displayProofFor, (modelId) => excludedModels().has(modelId), exclusionTurns);
|
|
9145
|
+
const replayRecovery = installReplayRecovery(ctx, () => {
|
|
9146
|
+
if (snapshotProof === void 0 || snapshotProof.expires <= Date.now()) return void 0;
|
|
9147
|
+
return `${lifetime.revision}:${snapshotProof.accountKey}:${snapshotProof.tokenFingerprint}`;
|
|
9148
|
+
});
|
|
8833
9149
|
const removeStepListener = ctx.on("session/event", (session, event) => {
|
|
8834
9150
|
if (event.type === "step/start" || event.type === "turn/end") lifetime.clearSessionRetries(session.id);
|
|
8835
9151
|
if (event.type === "turn/end") exclusionTurns.end(session);
|
|
@@ -9055,7 +9371,7 @@ function apply$1(ctx, config = {}) {
|
|
|
9055
9371
|
if (!exclusionTurns.admit(agent.session, turn, model, signal, excludedModels())) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
|
|
9056
9372
|
}
|
|
9057
9373
|
});
|
|
9058
|
-
const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings));
|
|
9374
|
+
const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, replayRecovery));
|
|
9059
9375
|
let exclusionSignature = JSON.stringify([...excludedModels()]);
|
|
9060
9376
|
const removeSettings = onSettingsNamespaceUpdated(ctx, (namespace) => {
|
|
9061
9377
|
if (namespace !== "github-copilot") return;
|
|
@@ -9161,6 +9477,7 @@ function apply$1(ctx, config = {}) {
|
|
|
9161
9477
|
ctx.effect(() => () => {
|
|
9162
9478
|
lifetime.dispose();
|
|
9163
9479
|
removeStepListener();
|
|
9480
|
+
replayRecovery.dispose();
|
|
9164
9481
|
removeListener();
|
|
9165
9482
|
removeSettings();
|
|
9166
9483
|
removeAutoRoute();
|