dsh-github-copilot 0.4.0-alpha.103 → 0.4.0-alpha.104
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 +3 -1
- package/CHANGELOG.md +7 -0
- package/README.md +21 -11
- package/README.zh.md +19 -10
- package/deployment-baseline.json +22 -1
- package/docs/copilot-accounts.md +45 -23
- package/docs/copilot-usage.md +5 -3
- package/lib/client.js +322 -30
- package/lib/client.js.map +1 -1
- package/lib/index.js +912 -224
- package/lib/remote.js +67 -10
- package/lib/routed-web.js +1 -1
- package/lib/{search-routing-CqysPLve.js → search-routing-CHyF6TbO.js} +1 -1
- package/lib/types/config.d.ts +7 -2
- package/lib/types/copilot-accounts-host.d.ts +10 -2
- package/lib/types/copilot-usage-card.d.ts +17 -0
- package/lib/types/copilot-usage-host.d.ts +3 -0
- package/lib/types/preview-route.d.ts +1 -1
- package/lib/types/replay-recovery-host.d.ts +2 -2
- package/lib/types/session-accounts-controller.d.ts +18 -0
- package/lib/types/session-accounts-host.d.ts +32 -0
- package/lib/types/session-accounts-remote.d.ts +106 -0
- package/lib/types/session-accounts.d.ts +36 -0
- package/lib/types/turn-selection-card.d.ts +5 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as GITHUB_COPILOT_PREVIEW_PROVIDER_ID, i as GITHUB_COPILOT_CREDENTIAL_KEY, n as GITHUB_COPILOT_AUTO_INTELLIGENCE_MODEL_ID, o as GITHUB_COPILOT_PROVIDER_ID, r as GITHUB_COPILOT_AUTO_MODEL_ID, s as autoModelPreference, t as GITHUB_COPILOT_AUTO_EFFICIENCY_MODEL_ID } from "./copilot-identity-DRZY_d2X.js";
|
|
2
|
-
import { C as
|
|
2
|
+
import { C as providerErrorMessage, D as readSettingsNamespace, E as readConfigValue, O as isPluginPreviewProvider, S as isAbortError, T as onSettingsNamespaceUpdated, _ as sameCandidates, a as COPILOT_HOSTED_SEARCH_PROVIDER_ID, b as currentSearchSelection, c as applyRequestAuth, d as ANTHROPIC_WEB_SEARCH_TOOL_TYPE, f as GITHUB_COPILOT_CREDENTIAL_KEY$1, g as candidatesForRoute, h as WEB_SEARCH_TOOL_TYPE, i as describeSearchBackend, k as readCopilotCatalog, l as normalizeRequestAuth, m as SearchPlan, n as routeSessionSearch, o as GITHUB_COPILOT_HOSTED_SEARCH_PROVIDER_ID, p as RESPONSES_WEB_SEARCH_TOOL_TYPE, r as DescribedSearchFallbackError, s as createTraditionalSearchProvider, t as isCopilotSearchSelection, u as providerRequestHeaders, v as currentChatRoute, w as readBounded, x as abortable$1, y as currentSearchInitiator } from "./search-routing-CHyF6TbO.js";
|
|
3
3
|
import { a as selectCompactionReasoning, i as resolveRequestBudgetPolicy, n as assessRequestBudget, r as calculateRequestBudget, t as DEFAULT_REQUEST_BUDGET_POLICY } from "./request-budget-DLY_aRq0.js";
|
|
4
4
|
import AuthorizationService from "@deepseek-ai/dsh-authorization";
|
|
5
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -23,12 +23,12 @@ import { Config as Config$1, PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
|
23
23
|
import { estimateContextTokens, estimateMessageTokens } from "@earendil-works/pi-ai/utils/estimate";
|
|
24
24
|
//#region lib/types/dual-model-host.js
|
|
25
25
|
/** Retired planner/executor entry points; retained policies stay enforceable without migration. */
|
|
26
|
-
var __runInitializers$
|
|
26
|
+
var __runInitializers$7 = function(thisArg, initializers, value) {
|
|
27
27
|
var useValue = arguments.length > 2;
|
|
28
28
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
29
29
|
return useValue ? value : void 0;
|
|
30
30
|
};
|
|
31
|
-
var __esDecorate$
|
|
31
|
+
var __esDecorate$7 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
32
32
|
function accept(f) {
|
|
33
33
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
34
34
|
return f;
|
|
@@ -274,7 +274,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
274
274
|
_view_decorators = [Remote];
|
|
275
275
|
_save_decorators = [Remote];
|
|
276
276
|
_create_decorators = [Remote];
|
|
277
|
-
__esDecorate$
|
|
277
|
+
__esDecorate$7(this, null, _view_decorators, {
|
|
278
278
|
kind: "method",
|
|
279
279
|
name: "view",
|
|
280
280
|
static: false,
|
|
@@ -285,7 +285,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
285
285
|
},
|
|
286
286
|
metadata: _metadata
|
|
287
287
|
}, null, _instanceExtraInitializers);
|
|
288
|
-
__esDecorate$
|
|
288
|
+
__esDecorate$7(this, null, _save_decorators, {
|
|
289
289
|
kind: "method",
|
|
290
290
|
name: "save",
|
|
291
291
|
static: false,
|
|
@@ -296,7 +296,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
296
296
|
},
|
|
297
297
|
metadata: _metadata
|
|
298
298
|
}, null, _instanceExtraInitializers);
|
|
299
|
-
__esDecorate$
|
|
299
|
+
__esDecorate$7(this, null, _create_decorators, {
|
|
300
300
|
kind: "method",
|
|
301
301
|
name: "create",
|
|
302
302
|
static: false,
|
|
@@ -314,7 +314,7 @@ let GitHubCopilotDualModel = (() => {
|
|
|
314
314
|
value: _metadata
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
|
-
owner = __runInitializers$
|
|
317
|
+
owner = __runInitializers$7(this, _instanceExtraInitializers);
|
|
318
318
|
lifetime = new AbortController();
|
|
319
319
|
creates = /* @__PURE__ */ new Map();
|
|
320
320
|
overlays = /* @__PURE__ */ new Map();
|
|
@@ -742,12 +742,12 @@ const SearchProviderCatalogSchema = z$1.object({
|
|
|
742
742
|
}).strict();
|
|
743
743
|
//#endregion
|
|
744
744
|
//#region lib/types/search-routing-host.js
|
|
745
|
-
var __runInitializers$
|
|
745
|
+
var __runInitializers$6 = function(thisArg, initializers, value) {
|
|
746
746
|
var useValue = arguments.length > 2;
|
|
747
747
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
748
748
|
return useValue ? value : void 0;
|
|
749
749
|
};
|
|
750
|
-
var __esDecorate$
|
|
750
|
+
var __esDecorate$6 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
751
751
|
function accept(f) {
|
|
752
752
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
753
753
|
return f;
|
|
@@ -790,7 +790,7 @@ let SearchRoutingController = (() => {
|
|
|
790
790
|
static {
|
|
791
791
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
792
792
|
_providers_decorators = [Remote];
|
|
793
|
-
__esDecorate$
|
|
793
|
+
__esDecorate$6(this, null, _providers_decorators, {
|
|
794
794
|
kind: "method",
|
|
795
795
|
name: "providers",
|
|
796
796
|
static: false,
|
|
@@ -810,7 +810,7 @@ let SearchRoutingController = (() => {
|
|
|
810
810
|
}
|
|
811
811
|
constructor(ctx) {
|
|
812
812
|
super(ctx, "githubCopilotSearchRouting");
|
|
813
|
-
__runInitializers$
|
|
813
|
+
__runInitializers$6(this, _instanceExtraInitializers);
|
|
814
814
|
}
|
|
815
815
|
providers() {
|
|
816
816
|
const unavailable = {
|
|
@@ -2989,7 +2989,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
|
|
|
2989
2989
|
var package_default = {
|
|
2990
2990
|
name: "dsh-github-copilot",
|
|
2991
2991
|
description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
|
|
2992
|
-
version: "0.4.0-alpha.
|
|
2992
|
+
version: "0.4.0-alpha.104",
|
|
2993
2993
|
publishConfig: {
|
|
2994
2994
|
"access": "public",
|
|
2995
2995
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -3373,12 +3373,12 @@ const COPILOT_ACCOUNT_ID_PATTERN = /^(?:canonical|[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a
|
|
|
3373
3373
|
const GITHUB_ACCOUNT_LOGIN_PATTERN = /^[a-zA-Z0-9](?:[a-zA-Z0-9_-]*[a-zA-Z0-9])?$/u;
|
|
3374
3374
|
//#endregion
|
|
3375
3375
|
//#region lib/types/copilot-accounts-host.js
|
|
3376
|
-
var __runInitializers$
|
|
3376
|
+
var __runInitializers$5 = function(thisArg, initializers, value) {
|
|
3377
3377
|
var useValue = arguments.length > 2;
|
|
3378
3378
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
3379
3379
|
return useValue ? value : void 0;
|
|
3380
3380
|
};
|
|
3381
|
-
var __esDecorate$
|
|
3381
|
+
var __esDecorate$5 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3382
3382
|
function accept(f) {
|
|
3383
3383
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
3384
3384
|
return f;
|
|
@@ -3454,6 +3454,7 @@ var CopilotAccountsHost = class {
|
|
|
3454
3454
|
selectionSignature;
|
|
3455
3455
|
disposed = false;
|
|
3456
3456
|
leases = /* @__PURE__ */ new Set();
|
|
3457
|
+
accountLeases = /* @__PURE__ */ new Map();
|
|
3457
3458
|
identities = /* @__PURE__ */ new Map();
|
|
3458
3459
|
unavailableIdentities = /* @__PURE__ */ new Set();
|
|
3459
3460
|
listeners = /* @__PURE__ */ new Set();
|
|
@@ -3487,16 +3488,18 @@ var CopilotAccountsHost = class {
|
|
|
3487
3488
|
const signature = accountId;
|
|
3488
3489
|
const changed = this.selectionSignature !== void 0 && this.selectionSignature !== signature;
|
|
3489
3490
|
this.selectionSignature = signature;
|
|
3490
|
-
if (changed) this.revoke();
|
|
3491
|
+
if (changed) this.revoke(false);
|
|
3491
3492
|
return {
|
|
3492
3493
|
accountId,
|
|
3493
3494
|
revision: descriptor.revision
|
|
3494
3495
|
};
|
|
3495
3496
|
}
|
|
3496
|
-
revoke() {
|
|
3497
|
+
revoke(clearIdentity = true) {
|
|
3497
3498
|
this.generation++;
|
|
3498
|
-
|
|
3499
|
-
|
|
3499
|
+
if (clearIdentity) {
|
|
3500
|
+
this.identities.clear();
|
|
3501
|
+
this.unavailableIdentities.clear();
|
|
3502
|
+
}
|
|
3500
3503
|
for (const listener of this.listeners) listener();
|
|
3501
3504
|
}
|
|
3502
3505
|
selectionChanged() {
|
|
@@ -3522,6 +3525,10 @@ var CopilotAccountsHost = class {
|
|
|
3522
3525
|
this.listeners.delete(listener);
|
|
3523
3526
|
};
|
|
3524
3527
|
}
|
|
3528
|
+
cachedIdentity(accountId) {
|
|
3529
|
+
const cached = this.identities.get(accountId);
|
|
3530
|
+
return cached && Date.now() - cached.at < IDENTITY_TTL ? cached.identity : void 0;
|
|
3531
|
+
}
|
|
3525
3532
|
capture(accountId) {
|
|
3526
3533
|
const selected = this.selection();
|
|
3527
3534
|
const target = accountId === void 0 ? selected.accountId : id(accountId);
|
|
@@ -3536,19 +3543,48 @@ var CopilotAccountsHost = class {
|
|
|
3536
3543
|
}
|
|
3537
3544
|
});
|
|
3538
3545
|
}
|
|
3539
|
-
|
|
3546
|
+
/** A frozen turn owns a record, not the mutable profile default. */
|
|
3547
|
+
captureAccount(accountId) {
|
|
3548
|
+
const target = id(accountId);
|
|
3549
|
+
if (this.disposed) fail("COPILOT_ACCOUNTS_DISPOSED");
|
|
3550
|
+
return Object.freeze({
|
|
3551
|
+
accountId: target,
|
|
3552
|
+
key: recordKey(target),
|
|
3553
|
+
generation: 0,
|
|
3554
|
+
assertCurrent: () => {
|
|
3555
|
+
if (this.disposed) fail("COPILOT_ACCOUNTS_DISPOSED");
|
|
3556
|
+
}
|
|
3557
|
+
});
|
|
3558
|
+
}
|
|
3559
|
+
async validateAccount(binding) {
|
|
3560
|
+
const blocked = this.routeDiagnostic(false);
|
|
3561
|
+
if (blocked) fail(blocked);
|
|
3562
|
+
if (!(await this.membership()).some((row) => row.id === binding.accountId && row.configured)) fail("COPILOT_ACCOUNTS_SELECTED_MISSING");
|
|
3563
|
+
binding.assertCurrent();
|
|
3564
|
+
}
|
|
3565
|
+
acquire(signal, requireManaged = true, accountId) {
|
|
3540
3566
|
if (this.operation !== void 0 || this.ctx.get("authorization")?.describe(recordKey("canonical"))?.inFlight === true) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3541
3567
|
if (signal?.aborted) fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3542
|
-
const binding = this.capture();
|
|
3568
|
+
const binding = accountId === void 0 ? this.capture() : this.captureAccount(accountId);
|
|
3543
3569
|
if (requireManaged && binding.accountId !== "canonical") {
|
|
3544
3570
|
const blocked = this.routeDiagnostic(false);
|
|
3545
3571
|
if (blocked) fail(blocked);
|
|
3546
3572
|
}
|
|
3573
|
+
let leases = this.leases;
|
|
3574
|
+
if (accountId !== void 0) {
|
|
3575
|
+
let pinned = this.accountLeases.get(accountId);
|
|
3576
|
+
if (!pinned) {
|
|
3577
|
+
pinned = /* @__PURE__ */ new Set();
|
|
3578
|
+
this.accountLeases.set(accountId, pinned);
|
|
3579
|
+
}
|
|
3580
|
+
leases = pinned;
|
|
3581
|
+
}
|
|
3547
3582
|
const release = () => {
|
|
3548
|
-
|
|
3583
|
+
leases.delete(release);
|
|
3584
|
+
if (accountId !== void 0 && leases.size === 0) this.accountLeases.delete(accountId);
|
|
3549
3585
|
signal?.removeEventListener("abort", release);
|
|
3550
3586
|
};
|
|
3551
|
-
|
|
3587
|
+
leases.add(release);
|
|
3552
3588
|
signal?.addEventListener("abort", release, { once: true });
|
|
3553
3589
|
return {
|
|
3554
3590
|
binding,
|
|
@@ -3556,7 +3592,7 @@ var CopilotAccountsHost = class {
|
|
|
3556
3592
|
};
|
|
3557
3593
|
}
|
|
3558
3594
|
acquireCanonicalAuthorization() {
|
|
3559
|
-
if (this.busy()) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3595
|
+
if (this.busy() || this.accountLeases.get("canonical")?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3560
3596
|
const binding = this.capture();
|
|
3561
3597
|
if (binding.accountId !== "canonical") fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3562
3598
|
this.operation = "authorizing";
|
|
@@ -3578,7 +3614,7 @@ var CopilotAccountsHost = class {
|
|
|
3578
3614
|
const evidence = migrationStatus(this.ctx);
|
|
3579
3615
|
if (!evidence.complete.routes || includeActivity && (!evidence.complete.sessions || !evidence.complete.defaultSelection) || !evidence.capabilities.settingsCas) return "COPILOT_ACCOUNTS_EVIDENCE_INCOMPLETE";
|
|
3580
3616
|
if (evidence.routes.nativeConfigured || evidence.routes.nativeRegistered || !evidence.routes.managedRegistered || includeActivity && (evidence.defaultSelection?.provider === "github-copilot" || evidence.sessions.some((row) => row.effectiveSelection?.provider === "github-copilot" || row.activeRequestSelection?.provider === "github-copilot"))) return "COPILOT_ACCOUNTS_ROUTE_BLOCKED";
|
|
3581
|
-
if (includeActivity && evidence.sessions.some((row) => row.status === "running" && row.effectiveSelection?.provider === "github-copilot-preview")) return "COPILOT_ACCOUNTS_BUSY";
|
|
3617
|
+
if (!this.ctx.get("githubCopilotSessionAccounts") && includeActivity && evidence.sessions.some((row) => row.status === "running" && row.effectiveSelection?.provider === "github-copilot-preview")) return "COPILOT_ACCOUNTS_BUSY";
|
|
3582
3618
|
}
|
|
3583
3619
|
busy() {
|
|
3584
3620
|
return this.leases.size > 0 || this.operation !== void 0 || this.ctx.get("authorization")?.describe(recordKey("canonical"))?.inFlight === true;
|
|
@@ -3616,23 +3652,26 @@ var CopilotAccountsHost = class {
|
|
|
3616
3652
|
return rows;
|
|
3617
3653
|
}
|
|
3618
3654
|
async get() {
|
|
3655
|
+
return this.accountView();
|
|
3656
|
+
}
|
|
3657
|
+
async accountView(accountId) {
|
|
3619
3658
|
let activeAccountId = "canonical", revision;
|
|
3620
3659
|
let accounts = [], writable = false;
|
|
3621
3660
|
let problem;
|
|
3622
3661
|
try {
|
|
3623
3662
|
const selection = this.selection();
|
|
3624
|
-
activeAccountId = selection.accountId;
|
|
3663
|
+
activeAccountId = accountId === void 0 ? selection.accountId : id(accountId);
|
|
3625
3664
|
revision = selection.revision;
|
|
3626
3665
|
writable = true;
|
|
3627
3666
|
accounts = await this.membership();
|
|
3628
3667
|
const current = this.selection();
|
|
3629
|
-
if (current.accountId !==
|
|
3630
|
-
if (activeAccountId !== "canonical" && !accounts.some((row) => row.id === activeAccountId && row.configured)) fail("COPILOT_ACCOUNTS_SELECTED_MISSING");
|
|
3631
|
-
problem = (this.lastFailure === "COPILOT_ACCOUNTS_BUSY" ? void 0 : this.lastFailure) ?? this.routeDiagnostic() ?? (this.busy() ? "COPILOT_ACCOUNTS_BUSY" : void 0);
|
|
3668
|
+
if (current.accountId !== selection.accountId || current.revision !== revision) fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3669
|
+
if ((accountId !== void 0 || activeAccountId !== "canonical") && !accounts.some((row) => row.id === activeAccountId && row.configured)) fail("COPILOT_ACCOUNTS_SELECTED_MISSING");
|
|
3670
|
+
problem = (accountId !== void 0 || this.lastFailure === "COPILOT_ACCOUNTS_BUSY" ? void 0 : this.lastFailure) ?? this.routeDiagnostic() ?? (this.busy() ? "COPILOT_ACCOUNTS_BUSY" : void 0);
|
|
3632
3671
|
} catch (error) {
|
|
3633
3672
|
problem = diagnostic(error, "COPILOT_ACCOUNTS_CREDENTIALS_UNAVAILABLE");
|
|
3634
3673
|
}
|
|
3635
|
-
if (this.lastFailure === "COPILOT_ACCOUNTS_COMMIT_UNCERTAIN") problem = this.lastFailure;
|
|
3674
|
+
if (accountId === void 0 && this.lastFailure === "COPILOT_ACCOUNTS_COMMIT_UNCERTAIN") problem = this.lastFailure;
|
|
3636
3675
|
const recovery = problem === "COPILOT_ACCOUNTS_SELECTED_MISSING" && writable && this.routeDiagnostic() === void 0;
|
|
3637
3676
|
return {
|
|
3638
3677
|
state: problem ? "error" : "ready",
|
|
@@ -3745,6 +3784,27 @@ var CopilotAccountsHost = class {
|
|
|
3745
3784
|
}
|
|
3746
3785
|
return this.get();
|
|
3747
3786
|
}
|
|
3787
|
+
async viewForAccount(accountId) {
|
|
3788
|
+
return this.accountView(accountId);
|
|
3789
|
+
}
|
|
3790
|
+
async refreshIdentityFor(accountId) {
|
|
3791
|
+
const lease = this.acquire(void 0, false, accountId);
|
|
3792
|
+
try {
|
|
3793
|
+
await this.identity(lease.binding, AbortSignal.any([this.abort.signal, AbortSignal.timeout(TIMEOUT)]));
|
|
3794
|
+
} catch (error) {
|
|
3795
|
+
this.identities.delete(accountId);
|
|
3796
|
+
this.unavailableIdentities.add(accountId);
|
|
3797
|
+
return {
|
|
3798
|
+
...await this.viewForAccount(accountId),
|
|
3799
|
+
state: "error",
|
|
3800
|
+
switchable: false,
|
|
3801
|
+
diagnostic: diagnostic(error, "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE")
|
|
3802
|
+
};
|
|
3803
|
+
} finally {
|
|
3804
|
+
lease.release();
|
|
3805
|
+
}
|
|
3806
|
+
return this.viewForAccount(accountId);
|
|
3807
|
+
}
|
|
3748
3808
|
async validateModels(binding, signal) {
|
|
3749
3809
|
try {
|
|
3750
3810
|
if (this.dependencies.validateModels) return await this.dependencies.validateModels(binding, signal);
|
|
@@ -3830,9 +3890,10 @@ var CopilotAccountsHost = class {
|
|
|
3830
3890
|
}
|
|
3831
3891
|
async authorize(accountId, expectedRevision) {
|
|
3832
3892
|
let removeFlow;
|
|
3833
|
-
let fenced = false;
|
|
3893
|
+
let fenced = false, rejectedBusy = false;
|
|
3834
3894
|
try {
|
|
3835
3895
|
id(accountId);
|
|
3896
|
+
if (this.accountLeases.get(accountId)?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3836
3897
|
if (accountId === "canonical") fail("COPILOT_ACCOUNTS_AUTH_UNAVAILABLE");
|
|
3837
3898
|
const assertRevision = () => {
|
|
3838
3899
|
if (expectedRevision !== void 0 && this.selection().revision !== expectedRevision) fail("COPILOT_ACCOUNTS_CONFLICT");
|
|
@@ -3969,13 +4030,20 @@ var CopilotAccountsHost = class {
|
|
|
3969
4030
|
} catch (error) {
|
|
3970
4031
|
removeFlow?.();
|
|
3971
4032
|
this.lastFailure = diagnostic(error, "COPILOT_ACCOUNTS_AUTH_FAILED");
|
|
4033
|
+
rejectedBusy = this.lastFailure === "COPILOT_ACCOUNTS_BUSY";
|
|
3972
4034
|
if (fenced) {
|
|
3973
4035
|
this.operation = void 0;
|
|
3974
4036
|
this.attemptKey = void 0;
|
|
3975
4037
|
this.authorizationAbort = void 0;
|
|
3976
4038
|
}
|
|
3977
4039
|
}
|
|
3978
|
-
|
|
4040
|
+
const view = await this.get();
|
|
4041
|
+
return rejectedBusy ? {
|
|
4042
|
+
...view,
|
|
4043
|
+
state: "error",
|
|
4044
|
+
switchable: false,
|
|
4045
|
+
diagnostic: "COPILOT_ACCOUNTS_BUSY"
|
|
4046
|
+
} : view;
|
|
3979
4047
|
}
|
|
3980
4048
|
async cancel() {
|
|
3981
4049
|
this.authorizationAbort?.abort();
|
|
@@ -3983,12 +4051,13 @@ var CopilotAccountsHost = class {
|
|
|
3983
4051
|
return this.get();
|
|
3984
4052
|
}
|
|
3985
4053
|
async remove(accountId, expectedRevision) {
|
|
3986
|
-
let fenced = false;
|
|
4054
|
+
let fenced = false, rejectedBusy = false;
|
|
3987
4055
|
try {
|
|
3988
4056
|
id(accountId);
|
|
3989
4057
|
const before = this.selection();
|
|
3990
4058
|
if (!Number.isSafeInteger(expectedRevision) || expectedRevision !== before.revision) fail("COPILOT_ACCOUNTS_CONFLICT");
|
|
3991
4059
|
if (accountId === "canonical" || accountId === before.accountId) fail("COPILOT_ACCOUNTS_ACTIVE_REMOVE_BLOCKED");
|
|
4060
|
+
if (this.accountLeases.get(accountId)?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3992
4061
|
if (this.busy()) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3993
4062
|
this.operation = "switching";
|
|
3994
4063
|
fenced = true;
|
|
@@ -4003,14 +4072,22 @@ var CopilotAccountsHost = class {
|
|
|
4003
4072
|
this.lastFailure = void 0;
|
|
4004
4073
|
} catch (error) {
|
|
4005
4074
|
this.lastFailure = diagnostic(error, "COPILOT_ACCOUNTS_REMOVE_FAILED");
|
|
4075
|
+
rejectedBusy = this.lastFailure === "COPILOT_ACCOUNTS_BUSY";
|
|
4006
4076
|
} finally {
|
|
4007
4077
|
if (fenced) this.operation = void 0;
|
|
4008
4078
|
}
|
|
4009
|
-
|
|
4079
|
+
const view = await this.get();
|
|
4080
|
+
return rejectedBusy ? {
|
|
4081
|
+
...view,
|
|
4082
|
+
state: "error",
|
|
4083
|
+
switchable: false,
|
|
4084
|
+
diagnostic: "COPILOT_ACCOUNTS_BUSY"
|
|
4085
|
+
} : view;
|
|
4010
4086
|
}
|
|
4011
4087
|
async signOutActive() {
|
|
4012
4088
|
if (this.busy()) fail("COPILOT_ACCOUNTS_BUSY");
|
|
4013
4089
|
const binding = this.capture();
|
|
4090
|
+
if (this.accountLeases.get(binding.accountId)?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
4014
4091
|
if (binding.accountId === "canonical") fail("COPILOT_ACCOUNTS_ACTIVE_REMOVE_BLOCKED");
|
|
4015
4092
|
this.operation = "switching";
|
|
4016
4093
|
try {
|
|
@@ -4029,6 +4106,7 @@ var CopilotAccountsHost = class {
|
|
|
4029
4106
|
this.abort.abort();
|
|
4030
4107
|
this.revoke();
|
|
4031
4108
|
for (const release of this.leases) release();
|
|
4109
|
+
for (const leases of this.accountLeases.values()) for (const release of leases) release();
|
|
4032
4110
|
this.listeners.clear();
|
|
4033
4111
|
}
|
|
4034
4112
|
};
|
|
@@ -4060,7 +4138,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4060
4138
|
_reauthorize_decorators = [Remote];
|
|
4061
4139
|
_switchAccount_decorators = [Remote];
|
|
4062
4140
|
_removeAccount_decorators = [Remote];
|
|
4063
|
-
__esDecorate$
|
|
4141
|
+
__esDecorate$5(this, null, _get_decorators, {
|
|
4064
4142
|
kind: "method",
|
|
4065
4143
|
name: "get",
|
|
4066
4144
|
static: false,
|
|
@@ -4071,7 +4149,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4071
4149
|
},
|
|
4072
4150
|
metadata: _metadata
|
|
4073
4151
|
}, null, _instanceExtraInitializers);
|
|
4074
|
-
__esDecorate$
|
|
4152
|
+
__esDecorate$5(this, null, _refreshIdentity_decorators, {
|
|
4075
4153
|
kind: "method",
|
|
4076
4154
|
name: "refreshIdentity",
|
|
4077
4155
|
static: false,
|
|
@@ -4082,7 +4160,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4082
4160
|
},
|
|
4083
4161
|
metadata: _metadata
|
|
4084
4162
|
}, null, _instanceExtraInitializers);
|
|
4085
|
-
__esDecorate$
|
|
4163
|
+
__esDecorate$5(this, null, _add_decorators, {
|
|
4086
4164
|
kind: "method",
|
|
4087
4165
|
name: "add",
|
|
4088
4166
|
static: false,
|
|
@@ -4093,7 +4171,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4093
4171
|
},
|
|
4094
4172
|
metadata: _metadata
|
|
4095
4173
|
}, null, _instanceExtraInitializers);
|
|
4096
|
-
__esDecorate$
|
|
4174
|
+
__esDecorate$5(this, null, _cancel_decorators, {
|
|
4097
4175
|
kind: "method",
|
|
4098
4176
|
name: "cancel",
|
|
4099
4177
|
static: false,
|
|
@@ -4104,7 +4182,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4104
4182
|
},
|
|
4105
4183
|
metadata: _metadata
|
|
4106
4184
|
}, null, _instanceExtraInitializers);
|
|
4107
|
-
__esDecorate$
|
|
4185
|
+
__esDecorate$5(this, null, _reauthorize_decorators, {
|
|
4108
4186
|
kind: "method",
|
|
4109
4187
|
name: "reauthorize",
|
|
4110
4188
|
static: false,
|
|
@@ -4115,7 +4193,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4115
4193
|
},
|
|
4116
4194
|
metadata: _metadata
|
|
4117
4195
|
}, null, _instanceExtraInitializers);
|
|
4118
|
-
__esDecorate$
|
|
4196
|
+
__esDecorate$5(this, null, _switchAccount_decorators, {
|
|
4119
4197
|
kind: "method",
|
|
4120
4198
|
name: "switchAccount",
|
|
4121
4199
|
static: false,
|
|
@@ -4126,7 +4204,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4126
4204
|
},
|
|
4127
4205
|
metadata: _metadata
|
|
4128
4206
|
}, null, _instanceExtraInitializers);
|
|
4129
|
-
__esDecorate$
|
|
4207
|
+
__esDecorate$5(this, null, _removeAccount_decorators, {
|
|
4130
4208
|
kind: "method",
|
|
4131
4209
|
name: "removeAccount",
|
|
4132
4210
|
static: false,
|
|
@@ -4144,7 +4222,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4144
4222
|
value: _metadata
|
|
4145
4223
|
});
|
|
4146
4224
|
}
|
|
4147
|
-
host = __runInitializers$
|
|
4225
|
+
host = __runInitializers$5(this, _instanceExtraInitializers);
|
|
4148
4226
|
constructor(ctx) {
|
|
4149
4227
|
super(ctx, "githubCopilotAccounts");
|
|
4150
4228
|
this.host = new CopilotAccountsHost(ctx);
|
|
@@ -4179,12 +4257,12 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4179
4257
|
})();
|
|
4180
4258
|
//#endregion
|
|
4181
4259
|
//#region lib/types/copilot-usage-host.js
|
|
4182
|
-
var __runInitializers$
|
|
4260
|
+
var __runInitializers$4 = function(thisArg, initializers, value) {
|
|
4183
4261
|
var useValue = arguments.length > 2;
|
|
4184
4262
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
4185
4263
|
return useValue ? value : void 0;
|
|
4186
4264
|
};
|
|
4187
|
-
var __esDecorate$
|
|
4265
|
+
var __esDecorate$4 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
4188
4266
|
function accept(f) {
|
|
4189
4267
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
4190
4268
|
return f;
|
|
@@ -4528,7 +4606,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4528
4606
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
4529
4607
|
_get_decorators = [Remote];
|
|
4530
4608
|
_refresh_decorators = [Remote];
|
|
4531
|
-
__esDecorate$
|
|
4609
|
+
__esDecorate$4(this, null, _get_decorators, {
|
|
4532
4610
|
kind: "method",
|
|
4533
4611
|
name: "get",
|
|
4534
4612
|
static: false,
|
|
@@ -4539,7 +4617,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4539
4617
|
},
|
|
4540
4618
|
metadata: _metadata
|
|
4541
4619
|
}, null, _instanceExtraInitializers);
|
|
4542
|
-
__esDecorate$
|
|
4620
|
+
__esDecorate$4(this, null, _refresh_decorators, {
|
|
4543
4621
|
kind: "method",
|
|
4544
4622
|
name: "refresh",
|
|
4545
4623
|
static: false,
|
|
@@ -4557,7 +4635,8 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4557
4635
|
value: _metadata
|
|
4558
4636
|
});
|
|
4559
4637
|
}
|
|
4560
|
-
|
|
4638
|
+
accountSources = (__runInitializers$4(this, _instanceExtraInitializers), /* @__PURE__ */ new Map());
|
|
4639
|
+
source;
|
|
4561
4640
|
accountSignature;
|
|
4562
4641
|
sourceInitialized = false;
|
|
4563
4642
|
constructor(ctx) {
|
|
@@ -4567,11 +4646,30 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4567
4646
|
} });
|
|
4568
4647
|
ctx.on("credentials/record-updated", (key) => {
|
|
4569
4648
|
if (isActiveCopilotRecord(ctx, key)) this.source.invalidate();
|
|
4649
|
+
this.accountSources.get(key)?.invalidate();
|
|
4570
4650
|
});
|
|
4571
4651
|
onSettingsNamespaceUpdated(ctx, (namespace) => {
|
|
4572
4652
|
if (namespace === "github-copilot" || namespace === "llm-pi-ai") this.source.invalidate();
|
|
4573
4653
|
});
|
|
4574
|
-
ctx.effect(() => () =>
|
|
4654
|
+
ctx.effect(() => async () => {
|
|
4655
|
+
await this.source.dispose();
|
|
4656
|
+
await Promise.all([...this.accountSources.values()].map((source) => source.dispose()));
|
|
4657
|
+
this.accountSources.clear();
|
|
4658
|
+
});
|
|
4659
|
+
}
|
|
4660
|
+
forAccount(binding, force = false) {
|
|
4661
|
+
binding.assertCurrent();
|
|
4662
|
+
let source = this.accountSources.get(binding.key);
|
|
4663
|
+
if (!source) {
|
|
4664
|
+
if (this.accountSources.size >= 32) throw new Error("COPILOT_SESSION_ACCOUNTS_LIMIT");
|
|
4665
|
+
const credentials = createGitHubCopilotCredentialStore(this.ctx, GITHUB_COPILOT_PROVIDER_ID, binding);
|
|
4666
|
+
source = new CopilotUsageSource({
|
|
4667
|
+
accountId: binding.accountId,
|
|
4668
|
+
readCredential: () => credentials.read(GITHUB_COPILOT_PROVIDER_ID)
|
|
4669
|
+
});
|
|
4670
|
+
this.accountSources.set(binding.key, source);
|
|
4671
|
+
}
|
|
4672
|
+
return force ? source.refresh() : source.get();
|
|
4575
4673
|
}
|
|
4576
4674
|
createSource() {
|
|
4577
4675
|
const binding = activeCopilotBinding(this.ctx);
|
|
@@ -4608,6 +4706,402 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4608
4706
|
}
|
|
4609
4707
|
};
|
|
4610
4708
|
})();
|
|
4709
|
+
function invalid() {
|
|
4710
|
+
throw new Error("COPILOT_SESSION_ACCOUNTS_INVALID");
|
|
4711
|
+
}
|
|
4712
|
+
function parseSessionAccounts(value) {
|
|
4713
|
+
if (value === void 0) return [];
|
|
4714
|
+
if (!Array.isArray(value) || value.length > 2048) invalid();
|
|
4715
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4716
|
+
return value.map((row) => {
|
|
4717
|
+
if (typeof row !== "object" || row === null || Array.isArray(row) || Object.keys(row).some((key) => key !== "sessionId" && key !== "accountId") || typeof row.sessionId !== "string" || !row.sessionId || row.sessionId.length > 256 || /[\p{Cc}\p{Cf}]/u.test(row.sessionId) || seen.has(row.sessionId) || typeof row.accountId !== "string" || !COPILOT_ACCOUNT_ID_PATTERN.test(row.accountId)) invalid();
|
|
4718
|
+
seen.add(row.sessionId);
|
|
4719
|
+
return Object.freeze({
|
|
4720
|
+
sessionId: row.sessionId,
|
|
4721
|
+
accountId: row.accountId
|
|
4722
|
+
});
|
|
4723
|
+
});
|
|
4724
|
+
}
|
|
4725
|
+
function resolveSessionAccount(sessionId, preferences, globalAccountId) {
|
|
4726
|
+
if (!COPILOT_ACCOUNT_ID_PATTERN.test(globalAccountId)) invalid();
|
|
4727
|
+
const explicit = preferences.find((row) => row.sessionId === sessionId);
|
|
4728
|
+
return Object.freeze({
|
|
4729
|
+
accountId: explicit?.accountId ?? globalAccountId,
|
|
4730
|
+
source: explicit ? "session" : "global"
|
|
4731
|
+
});
|
|
4732
|
+
}
|
|
4733
|
+
/** Active turns are never evicted; bounded historical evidence may become unknown. */
|
|
4734
|
+
var SessionAccountTurns = class {
|
|
4735
|
+
active = /* @__PURE__ */ new Map();
|
|
4736
|
+
signals = /* @__PURE__ */ new WeakMap();
|
|
4737
|
+
history = /* @__PURE__ */ new Map();
|
|
4738
|
+
admit(agent, turn, signal, selection) {
|
|
4739
|
+
if (!Number.isSafeInteger(turn) || turn < 0 || signal.aborted) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_INVALID");
|
|
4740
|
+
const previous = this.active.get(agent);
|
|
4741
|
+
if (previous) {
|
|
4742
|
+
if (previous.turn !== turn) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_UNSETTLED");
|
|
4743
|
+
if (previous.signal !== signal) throw new Error("COPILOT_SESSION_ACCOUNT_SIGNAL_CHANGED");
|
|
4744
|
+
return previous;
|
|
4745
|
+
}
|
|
4746
|
+
const bound = this.signals.get(signal);
|
|
4747
|
+
if (bound && bound.agent !== agent) throw new Error("COPILOT_SESSION_ACCOUNT_SIGNAL_CHANGED");
|
|
4748
|
+
const admission = Object.freeze({
|
|
4749
|
+
...selection,
|
|
4750
|
+
turn,
|
|
4751
|
+
signal
|
|
4752
|
+
});
|
|
4753
|
+
this.active.set(agent, admission);
|
|
4754
|
+
this.signals.set(signal, {
|
|
4755
|
+
agent,
|
|
4756
|
+
admission
|
|
4757
|
+
});
|
|
4758
|
+
return admission;
|
|
4759
|
+
}
|
|
4760
|
+
record(agent, turn, identity) {
|
|
4761
|
+
const admission = this.active.get(agent);
|
|
4762
|
+
if (!admission || admission.turn !== turn) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_INVALID");
|
|
4763
|
+
let turns = this.history.get(agent);
|
|
4764
|
+
if (!turns) {
|
|
4765
|
+
turns = /* @__PURE__ */ new Map();
|
|
4766
|
+
this.history.set(agent, turns);
|
|
4767
|
+
if (this.history.size > 64) this.history.delete(this.history.keys().next().value);
|
|
4768
|
+
}
|
|
4769
|
+
if (!turns.has(turn)) turns.set(turn, Object.freeze({
|
|
4770
|
+
accountId: admission.accountId,
|
|
4771
|
+
source: admission.source,
|
|
4772
|
+
...identity ? { identity: Object.freeze({ ...identity }) } : {}
|
|
4773
|
+
}));
|
|
4774
|
+
if (turns.size > 128) turns.delete(turns.keys().next().value);
|
|
4775
|
+
}
|
|
4776
|
+
current(agent) {
|
|
4777
|
+
return this.active.get(agent);
|
|
4778
|
+
}
|
|
4779
|
+
forSignal(signal) {
|
|
4780
|
+
const entry = this.signals.get(signal);
|
|
4781
|
+
return entry && this.active.get(entry.agent) === entry.admission ? entry.admission : void 0;
|
|
4782
|
+
}
|
|
4783
|
+
evidence(agent, turn) {
|
|
4784
|
+
return this.history.get(agent)?.get(turn);
|
|
4785
|
+
}
|
|
4786
|
+
end(agent, turn) {
|
|
4787
|
+
const admission = this.active.get(agent);
|
|
4788
|
+
if (admission?.turn !== turn) return;
|
|
4789
|
+
this.signals.delete(admission.signal);
|
|
4790
|
+
this.active.delete(agent);
|
|
4791
|
+
}
|
|
4792
|
+
remove(agent) {
|
|
4793
|
+
const admission = this.active.get(agent);
|
|
4794
|
+
if (admission) this.signals.delete(admission.signal);
|
|
4795
|
+
this.active.delete(agent);
|
|
4796
|
+
this.history.delete(agent);
|
|
4797
|
+
}
|
|
4798
|
+
clear() {
|
|
4799
|
+
for (const admission of this.active.values()) this.signals.delete(admission.signal);
|
|
4800
|
+
this.active.clear();
|
|
4801
|
+
this.history.clear();
|
|
4802
|
+
}
|
|
4803
|
+
recordSignal(signal, identity) {
|
|
4804
|
+
const entry = this.signals.get(signal);
|
|
4805
|
+
if (entry && this.active.get(entry.agent) === entry.admission) this.record(entry.agent, entry.admission.turn, identity);
|
|
4806
|
+
}
|
|
4807
|
+
};
|
|
4808
|
+
//#endregion
|
|
4809
|
+
//#region lib/types/session-accounts-host.js
|
|
4810
|
+
/** Host-only routing owner; credentials remain in the existing account service. */
|
|
4811
|
+
var SessionAccountsHost = class {
|
|
4812
|
+
ctx;
|
|
4813
|
+
turns = new SessionAccountTurns();
|
|
4814
|
+
leases = /* @__PURE__ */ new Map();
|
|
4815
|
+
constructor(ctx) {
|
|
4816
|
+
this.ctx = ctx;
|
|
4817
|
+
}
|
|
4818
|
+
selected(agent) {
|
|
4819
|
+
const settings = readSettingsNamespace(this.ctx, "github-copilot");
|
|
4820
|
+
if (typeof settings !== "object" || settings === null) throw new Error("COPILOT_SESSION_ACCOUNTS_SETTINGS_UNAVAILABLE");
|
|
4821
|
+
const preferences = parseSessionAccounts("sessionAccounts" in settings ? settings.sessionAccounts : void 0);
|
|
4822
|
+
const global = this.ctx.get("githubCopilotAccounts")?.host.capture().accountId;
|
|
4823
|
+
if (!global) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4824
|
+
return resolveSessionAccount(agent.session.id, preferences, global);
|
|
4825
|
+
}
|
|
4826
|
+
admit(agent, turn, signal) {
|
|
4827
|
+
const existing = this.turns.current(agent.session);
|
|
4828
|
+
const selected = existing ?? this.selected(agent);
|
|
4829
|
+
if (existing) {
|
|
4830
|
+
const admission = this.turns.admit(agent.session, turn, signal, selected);
|
|
4831
|
+
return this.bindingForAccount(admission.accountId);
|
|
4832
|
+
}
|
|
4833
|
+
if (this.leases.size >= 2048) throw new Error("COPILOT_SESSION_ACCOUNTS_LIMIT");
|
|
4834
|
+
const lease = this.ctx.get("githubCopilotAccounts")?.host.acquire(void 0, true, selected.accountId);
|
|
4835
|
+
if (!lease) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4836
|
+
try {
|
|
4837
|
+
this.turns.admit(agent.session, turn, signal, selected);
|
|
4838
|
+
this.leases.set(agent.session, lease);
|
|
4839
|
+
return lease.binding;
|
|
4840
|
+
} catch (error) {
|
|
4841
|
+
lease.release();
|
|
4842
|
+
throw error;
|
|
4843
|
+
}
|
|
4844
|
+
}
|
|
4845
|
+
end(session, turn) {
|
|
4846
|
+
if (this.turns.current(session)?.turn !== turn) return;
|
|
4847
|
+
this.leases.get(session)?.release();
|
|
4848
|
+
this.leases.delete(session);
|
|
4849
|
+
this.turns.end(session, turn);
|
|
4850
|
+
}
|
|
4851
|
+
remove(session) {
|
|
4852
|
+
this.leases.get(session)?.release();
|
|
4853
|
+
this.leases.delete(session);
|
|
4854
|
+
this.turns.remove(session);
|
|
4855
|
+
}
|
|
4856
|
+
dispose() {
|
|
4857
|
+
for (const lease of this.leases.values()) lease.release();
|
|
4858
|
+
this.leases.clear();
|
|
4859
|
+
this.turns.clear();
|
|
4860
|
+
}
|
|
4861
|
+
bindingForAccount(accountId) {
|
|
4862
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
4863
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4864
|
+
return accounts.host.captureAccount(accountId);
|
|
4865
|
+
}
|
|
4866
|
+
recordRequest(signal) {
|
|
4867
|
+
const admission = signal === void 0 ? void 0 : this.turns.forSignal(signal);
|
|
4868
|
+
if (admission && signal) this.turns.recordSignal(signal, this.ctx.get("githubCopilotAccounts")?.host.cachedIdentity(admission.accountId));
|
|
4869
|
+
}
|
|
4870
|
+
requestBinding(signal) {
|
|
4871
|
+
const exact = signal === void 0 ? void 0 : this.turns.forSignal(signal);
|
|
4872
|
+
if (exact) return this.bindingForAccount(exact.accountId);
|
|
4873
|
+
const agents = this.ctx.get("agents");
|
|
4874
|
+
const agent = typeof agents?.currentInitiator === "function" ? agents.currentInitiator() : void 0;
|
|
4875
|
+
if (agent) {
|
|
4876
|
+
const admitted = this.turns.current(agent.session);
|
|
4877
|
+
if (admitted) return this.bindingForAccount(admitted.accountId);
|
|
4878
|
+
return this.bindingForAccount(this.selected(agent).accountId);
|
|
4879
|
+
}
|
|
4880
|
+
const binding = this.ctx.get("githubCopilotAccounts")?.host.capture();
|
|
4881
|
+
if (!binding) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4882
|
+
return this.bindingForAccount(binding.accountId);
|
|
4883
|
+
}
|
|
4884
|
+
async set(agent, accountId, revision) {
|
|
4885
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
4886
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4887
|
+
if (accountId !== null) {
|
|
4888
|
+
const binding = this.bindingForAccount(accountId);
|
|
4889
|
+
await accounts.host.validateAccount(binding);
|
|
4890
|
+
}
|
|
4891
|
+
const settings = this.ctx.get("settings");
|
|
4892
|
+
if (!settings) throw new Error("COPILOT_SESSION_ACCOUNTS_SETTINGS_UNAVAILABLE");
|
|
4893
|
+
const descriptor = settings.describe({ redactSecrets: true }).find((row) => row.ns === "github-copilot");
|
|
4894
|
+
if (!descriptor || descriptor.revision !== revision) throw new Error("COPILOT_ACCOUNTS_CONFLICT");
|
|
4895
|
+
const value = descriptor.value;
|
|
4896
|
+
const next = parseSessionAccounts(typeof value === "object" && value !== null && "sessionAccounts" in value ? value.sessionAccounts : void 0).filter((row) => row.sessionId !== agent.session.id);
|
|
4897
|
+
if (accountId !== null) next.push({
|
|
4898
|
+
sessionId: agent.session.id,
|
|
4899
|
+
accountId
|
|
4900
|
+
});
|
|
4901
|
+
if (next.length > 2048) throw new Error("COPILOT_SESSION_ACCOUNTS_LIMIT");
|
|
4902
|
+
await settings.mutate("github-copilot", [{
|
|
4903
|
+
op: "set",
|
|
4904
|
+
path: ["sessionAccounts"],
|
|
4905
|
+
value: next
|
|
4906
|
+
}], revision);
|
|
4907
|
+
const actual = this.selected(agent);
|
|
4908
|
+
if (actual.source !== (accountId === null ? "global" : "session") || accountId !== null && actual.accountId !== accountId) throw new Error("COPILOT_SESSION_ACCOUNTS_COMMIT_UNCERTAIN");
|
|
4909
|
+
}
|
|
4910
|
+
};
|
|
4911
|
+
//#endregion
|
|
4912
|
+
//#region lib/types/session-accounts-controller.js
|
|
4913
|
+
var __runInitializers$3 = function(thisArg, initializers, value) {
|
|
4914
|
+
var useValue = arguments.length > 2;
|
|
4915
|
+
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
4916
|
+
return useValue ? value : void 0;
|
|
4917
|
+
};
|
|
4918
|
+
var __esDecorate$3 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
4919
|
+
function accept(f) {
|
|
4920
|
+
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
4921
|
+
return f;
|
|
4922
|
+
}
|
|
4923
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4924
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
4925
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
4926
|
+
var _, done = false;
|
|
4927
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
4928
|
+
var context = {};
|
|
4929
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
4930
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
4931
|
+
context.addInitializer = function(f) {
|
|
4932
|
+
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
4933
|
+
extraInitializers.push(accept(f || null));
|
|
4934
|
+
};
|
|
4935
|
+
var result = (0, decorators[i])(kind === "accessor" ? {
|
|
4936
|
+
get: descriptor.get,
|
|
4937
|
+
set: descriptor.set
|
|
4938
|
+
} : descriptor[key], context);
|
|
4939
|
+
if (kind === "accessor") {
|
|
4940
|
+
if (result === void 0) continue;
|
|
4941
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
4942
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
4943
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
4944
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
4945
|
+
} else if (_ = accept(result)) {
|
|
4946
|
+
if (kind === "field") initializers.unshift(_);
|
|
4947
|
+
else descriptor[key] = _;
|
|
4948
|
+
}
|
|
4949
|
+
}
|
|
4950
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
4951
|
+
done = true;
|
|
4952
|
+
};
|
|
4953
|
+
let SessionAccountController = (() => {
|
|
4954
|
+
let _classSuper = TypertRemoteService;
|
|
4955
|
+
let _instanceExtraInitializers = [];
|
|
4956
|
+
let _get_decorators;
|
|
4957
|
+
let _set_decorators;
|
|
4958
|
+
let _refreshIdentity_decorators;
|
|
4959
|
+
let _usage_decorators;
|
|
4960
|
+
let _refreshUsage_decorators;
|
|
4961
|
+
let _turn_decorators;
|
|
4962
|
+
return class SessionAccountController extends _classSuper {
|
|
4963
|
+
static {
|
|
4964
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
4965
|
+
_get_decorators = [Remote];
|
|
4966
|
+
_set_decorators = [Remote];
|
|
4967
|
+
_refreshIdentity_decorators = [Remote];
|
|
4968
|
+
_usage_decorators = [Remote];
|
|
4969
|
+
_refreshUsage_decorators = [Remote];
|
|
4970
|
+
_turn_decorators = [Remote];
|
|
4971
|
+
__esDecorate$3(this, null, _get_decorators, {
|
|
4972
|
+
kind: "method",
|
|
4973
|
+
name: "get",
|
|
4974
|
+
static: false,
|
|
4975
|
+
private: false,
|
|
4976
|
+
access: {
|
|
4977
|
+
has: (obj) => "get" in obj,
|
|
4978
|
+
get: (obj) => obj.get
|
|
4979
|
+
},
|
|
4980
|
+
metadata: _metadata
|
|
4981
|
+
}, null, _instanceExtraInitializers);
|
|
4982
|
+
__esDecorate$3(this, null, _set_decorators, {
|
|
4983
|
+
kind: "method",
|
|
4984
|
+
name: "set",
|
|
4985
|
+
static: false,
|
|
4986
|
+
private: false,
|
|
4987
|
+
access: {
|
|
4988
|
+
has: (obj) => "set" in obj,
|
|
4989
|
+
get: (obj) => obj.set
|
|
4990
|
+
},
|
|
4991
|
+
metadata: _metadata
|
|
4992
|
+
}, null, _instanceExtraInitializers);
|
|
4993
|
+
__esDecorate$3(this, null, _refreshIdentity_decorators, {
|
|
4994
|
+
kind: "method",
|
|
4995
|
+
name: "refreshIdentity",
|
|
4996
|
+
static: false,
|
|
4997
|
+
private: false,
|
|
4998
|
+
access: {
|
|
4999
|
+
has: (obj) => "refreshIdentity" in obj,
|
|
5000
|
+
get: (obj) => obj.refreshIdentity
|
|
5001
|
+
},
|
|
5002
|
+
metadata: _metadata
|
|
5003
|
+
}, null, _instanceExtraInitializers);
|
|
5004
|
+
__esDecorate$3(this, null, _usage_decorators, {
|
|
5005
|
+
kind: "method",
|
|
5006
|
+
name: "usage",
|
|
5007
|
+
static: false,
|
|
5008
|
+
private: false,
|
|
5009
|
+
access: {
|
|
5010
|
+
has: (obj) => "usage" in obj,
|
|
5011
|
+
get: (obj) => obj.usage
|
|
5012
|
+
},
|
|
5013
|
+
metadata: _metadata
|
|
5014
|
+
}, null, _instanceExtraInitializers);
|
|
5015
|
+
__esDecorate$3(this, null, _refreshUsage_decorators, {
|
|
5016
|
+
kind: "method",
|
|
5017
|
+
name: "refreshUsage",
|
|
5018
|
+
static: false,
|
|
5019
|
+
private: false,
|
|
5020
|
+
access: {
|
|
5021
|
+
has: (obj) => "refreshUsage" in obj,
|
|
5022
|
+
get: (obj) => obj.refreshUsage
|
|
5023
|
+
},
|
|
5024
|
+
metadata: _metadata
|
|
5025
|
+
}, null, _instanceExtraInitializers);
|
|
5026
|
+
__esDecorate$3(this, null, _turn_decorators, {
|
|
5027
|
+
kind: "method",
|
|
5028
|
+
name: "turn",
|
|
5029
|
+
static: false,
|
|
5030
|
+
private: false,
|
|
5031
|
+
access: {
|
|
5032
|
+
has: (obj) => "turn" in obj,
|
|
5033
|
+
get: (obj) => obj.turn
|
|
5034
|
+
},
|
|
5035
|
+
metadata: _metadata
|
|
5036
|
+
}, null, _instanceExtraInitializers);
|
|
5037
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
5038
|
+
enumerable: true,
|
|
5039
|
+
configurable: true,
|
|
5040
|
+
writable: true,
|
|
5041
|
+
value: _metadata
|
|
5042
|
+
});
|
|
5043
|
+
}
|
|
5044
|
+
owner = __runInitializers$3(this, _instanceExtraInitializers);
|
|
5045
|
+
constructor(ctx, owner) {
|
|
5046
|
+
super(ctx, "githubCopilotSessionAccount");
|
|
5047
|
+
this.owner = owner;
|
|
5048
|
+
}
|
|
5049
|
+
async get(agent) {
|
|
5050
|
+
const selected = this.owner.selected(agent);
|
|
5051
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
5052
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
5053
|
+
const view = await accounts.host.viewForAccount(selected.accountId);
|
|
5054
|
+
const latest = this.owner.selected(agent);
|
|
5055
|
+
if (latest.accountId !== selected.accountId || latest.source !== selected.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
|
|
5056
|
+
const running = this.owner.turns.current(agent.session);
|
|
5057
|
+
return {
|
|
5058
|
+
...selected,
|
|
5059
|
+
globalAccountId: accounts.host.capture().accountId,
|
|
5060
|
+
accounts: view,
|
|
5061
|
+
...running ? { runningAccountId: running.accountId } : {}
|
|
5062
|
+
};
|
|
5063
|
+
}
|
|
5064
|
+
async set(agent, accountId, revision) {
|
|
5065
|
+
await this.owner.set(agent, accountId, revision);
|
|
5066
|
+
return this.get(agent);
|
|
5067
|
+
}
|
|
5068
|
+
async refreshIdentity(agent) {
|
|
5069
|
+
const selected = this.owner.selected(agent);
|
|
5070
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
5071
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
5072
|
+
const identity = await accounts.host.refreshIdentityFor(selected.accountId);
|
|
5073
|
+
const latest = await this.get(agent);
|
|
5074
|
+
if (latest.accountId !== selected.accountId || latest.source !== selected.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
|
|
5075
|
+
return {
|
|
5076
|
+
...latest,
|
|
5077
|
+
accounts: identity
|
|
5078
|
+
};
|
|
5079
|
+
}
|
|
5080
|
+
async readUsage(agent, force) {
|
|
5081
|
+
const selection = this.owner.selected(agent);
|
|
5082
|
+
const service = this.ctx.get("githubCopilotUsage");
|
|
5083
|
+
if (!service) throw new Error("COPILOT_USAGE_REMOTE_UNAVAILABLE");
|
|
5084
|
+
const result = await service.forAccount(this.owner.bindingForAccount(selection.accountId), force);
|
|
5085
|
+
const current = this.owner.selected(agent);
|
|
5086
|
+
if (current.accountId !== selection.accountId || current.source !== selection.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
|
|
5087
|
+
return result;
|
|
5088
|
+
}
|
|
5089
|
+
usage(agent) {
|
|
5090
|
+
return this.readUsage(agent, false);
|
|
5091
|
+
}
|
|
5092
|
+
refreshUsage(agent) {
|
|
5093
|
+
return this.readUsage(agent, true);
|
|
5094
|
+
}
|
|
5095
|
+
turn(agent, turn) {
|
|
5096
|
+
if (!Number.isSafeInteger(turn) || turn < 0) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_INVALID");
|
|
5097
|
+
const evidence = this.owner.turns.evidence(agent.session, turn);
|
|
5098
|
+
return evidence ? {
|
|
5099
|
+
state: "recorded",
|
|
5100
|
+
...evidence
|
|
5101
|
+
} : { state: "unknown" };
|
|
5102
|
+
}
|
|
5103
|
+
};
|
|
5104
|
+
})();
|
|
4611
5105
|
//#endregion
|
|
4612
5106
|
//#region lib/types/context-usage.js
|
|
4613
5107
|
/** All observed counters are zero, not proof that an attempted prompt was empty. */
|
|
@@ -5126,9 +5620,14 @@ const WebSearchRoutingConfigSchema = z.object({
|
|
|
5126
5620
|
function readInlineConfig(config) {
|
|
5127
5621
|
const exclusions = readConfigValue(config.excludedModelIds);
|
|
5128
5622
|
const bindings = readConfigValue(config.parentModelFollow);
|
|
5623
|
+
const accounts = readConfigValue(config.sessionAccounts);
|
|
5129
5624
|
return {
|
|
5130
5625
|
...config,
|
|
5131
5626
|
activeAccountId: readConfigValue(config.activeAccountId),
|
|
5627
|
+
sessionAccounts: accounts === void 0 ? void 0 : Array.from(accounts, (account) => ({
|
|
5628
|
+
sessionId: account.sessionId,
|
|
5629
|
+
accountId: account.accountId
|
|
5630
|
+
})),
|
|
5132
5631
|
excludedModelIds: exclusions === void 0 ? void 0 : Array.from(exclusions),
|
|
5133
5632
|
parentModelFollow: bindings === void 0 ? void 0 : Array.from(bindings, (binding) => ({
|
|
5134
5633
|
childSessionId: binding.childSessionId,
|
|
@@ -5158,6 +5657,10 @@ const Config = z.object({
|
|
|
5158
5657
|
accountModelFailureCooldownMs: z.number().step(1).min(0).max(MAX_TIMEOUT_MS).default(3e5),
|
|
5159
5658
|
excludedModelIds: z.array(z.string()).default([]).hidden().volatile(),
|
|
5160
5659
|
activeAccountId: z.string().hidden().volatile(),
|
|
5660
|
+
sessionAccounts: z.array(z.object({
|
|
5661
|
+
sessionId: z.string().min(1).max(256),
|
|
5662
|
+
accountId: z.string().min(1).max(36)
|
|
5663
|
+
})).default([]).hidden().volatile(),
|
|
5161
5664
|
followParentModel: z.boolean().default(false).volatile(),
|
|
5162
5665
|
autoSemanticAssessment: z.boolean().default(true),
|
|
5163
5666
|
parentModelFollow: z.array(z.object({
|
|
@@ -8341,15 +8844,15 @@ let ReplayRecoveryController = (() => {
|
|
|
8341
8844
|
this.busy = busy;
|
|
8342
8845
|
}
|
|
8343
8846
|
get(agent) {
|
|
8344
|
-
return this.store.view(agent.session, this.proof());
|
|
8847
|
+
return this.store.view(agent.session, this.proof(agent));
|
|
8345
8848
|
}
|
|
8346
8849
|
setEnabled(agent, revision, enabled) {
|
|
8347
8850
|
if (this.busy.has(agent.session)) throw new Error("COPILOT_REPLAY_RECOVERY_TURN_ACTIVE");
|
|
8348
|
-
return this.store.setEnabled(agent.session, this.proof(), revision, enabled);
|
|
8851
|
+
return this.store.setEnabled(agent.session, this.proof(agent), revision, enabled);
|
|
8349
8852
|
}
|
|
8350
8853
|
authorize(agent, revision, duration) {
|
|
8351
8854
|
if (this.busy.has(agent.session)) throw new Error("COPILOT_REPLAY_RECOVERY_TURN_ACTIVE");
|
|
8352
|
-
return this.store.authorize(agent.session, this.proof(), revision, duration);
|
|
8855
|
+
return this.store.authorize(agent.session, this.proof(agent), revision, duration);
|
|
8353
8856
|
}
|
|
8354
8857
|
};
|
|
8355
8858
|
})();
|
|
@@ -8388,10 +8891,10 @@ function installReplayRecovery(ctx, proof) {
|
|
|
8388
8891
|
prepare(request) {
|
|
8389
8892
|
if (!active || request.signal === void 0 || request.signal.aborted || request.purpose !== void 0 || request.provider !== "github-copilot-preview") return void 0;
|
|
8390
8893
|
const binding = requests.get(request.signal);
|
|
8391
|
-
const currentProof = proof();
|
|
8894
|
+
const currentProof = proof(void 0, request);
|
|
8392
8895
|
if (!binding || binding.session.id !== request.sessionId || !busy.has(binding.session) || currentProof === void 0 || currentRequests.get(binding.session) !== request.signal) return void 0;
|
|
8393
8896
|
const transform = store.prepare(binding.session, currentProof, request.model, binding.turn);
|
|
8394
|
-
const current = () => active && !request.signal?.aborted && proof() === currentProof && currentRequests.get(binding.session) === request.signal && busy.has(binding.session);
|
|
8897
|
+
const current = () => active && !request.signal?.aborted && proof(void 0, request) === currentProof && currentRequests.get(binding.session) === request.signal && busy.has(binding.session);
|
|
8395
8898
|
return {
|
|
8396
8899
|
transform(payload) {
|
|
8397
8900
|
if (!current()) throw new Error("COPILOT_REPLAY_RECOVERY_REVOKED");
|
|
@@ -9751,6 +10254,14 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
9751
10254
|
if (inherited !== void 0) return autoModelPreference(inherited.model) !== void 0 ? inherited.model : void 0;
|
|
9752
10255
|
return pendingAuto(agent);
|
|
9753
10256
|
};
|
|
10257
|
+
const admitAccount = (agent, turn, signal) => {
|
|
10258
|
+
const owner = ctx.get("githubCopilotSessionAccounts");
|
|
10259
|
+
if (!owner) return;
|
|
10260
|
+
const projections = ctx.get("sessionProjections");
|
|
10261
|
+
const state = record(projections) && typeof projections.stateOf === "function" ? projections.stateOf(agent.session, "modelSelection") : void 0;
|
|
10262
|
+
const pending = record(state) ? state.pending : void 0;
|
|
10263
|
+
if ((followIntent(agent)?.provider ?? (record(pending) ? pending.provider : agent.session.requestHeader()?.config.provider ?? (record(state) && pending === null ? ctx.get("agentDefaultModel")?.currentSelection()?.provider : void 0))) === "github-copilot-preview") owner.admit(agent, turn, signal);
|
|
10264
|
+
};
|
|
9754
10265
|
const installAgent = (agent) => {
|
|
9755
10266
|
if (agentDisposers.has(agent)) return;
|
|
9756
10267
|
const removeAssembly = agent.ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
@@ -9776,6 +10287,7 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
9776
10287
|
};
|
|
9777
10288
|
}, { prepend: true });
|
|
9778
10289
|
const removePreStep = agent.ctx.on("agent/pre-step", async ({ messages, turn, signal }, next) => {
|
|
10290
|
+
admitAccount(agent, turn, signal);
|
|
9779
10291
|
const result = await next();
|
|
9780
10292
|
const entered = result.kind === "enter" ? result.messages : messages;
|
|
9781
10293
|
captured.set(agent, {
|
|
@@ -9839,6 +10351,7 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
9839
10351
|
});
|
|
9840
10352
|
const removeRequest = ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
|
|
9841
10353
|
installAgent(agent);
|
|
10354
|
+
admitAccount(agent, turn, signal);
|
|
9842
10355
|
const native = await next();
|
|
9843
10356
|
const admitted = routed.get(agent);
|
|
9844
10357
|
if (admitted?.turn === turn && admitted.admitted !== void 0) {
|
|
@@ -10279,7 +10792,8 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10279
10792
|
accountModelSettings;
|
|
10280
10793
|
replayRecovery;
|
|
10281
10794
|
requestCheckpoint;
|
|
10282
|
-
|
|
10795
|
+
captureRequest;
|
|
10796
|
+
constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery, requestCheckpoint, captureRequest = () => void 0) {
|
|
10283
10797
|
super(optionsFor());
|
|
10284
10798
|
this.lifetime = lifetime;
|
|
10285
10799
|
this.optionsFor = optionsFor;
|
|
@@ -10289,6 +10803,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10289
10803
|
this.accountModelSettings = accountModelSettings;
|
|
10290
10804
|
this.replayRecovery = replayRecovery;
|
|
10291
10805
|
this.requestCheckpoint = requestCheckpoint;
|
|
10806
|
+
this.captureRequest = captureRequest;
|
|
10292
10807
|
}
|
|
10293
10808
|
async listModels(provider) {
|
|
10294
10809
|
owned(provider);
|
|
@@ -10505,6 +11020,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10505
11020
|
signal,
|
|
10506
11021
|
...effort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(effort) }
|
|
10507
11022
|
};
|
|
11023
|
+
let capturedRequest = false;
|
|
10508
11024
|
for await (const chunk of native.stream(request)) {
|
|
10509
11025
|
owner.requestCheckpoint?.();
|
|
10510
11026
|
let delivered = chunk;
|
|
@@ -10531,6 +11047,10 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10531
11047
|
};
|
|
10532
11048
|
}
|
|
10533
11049
|
liveness?.pause();
|
|
11050
|
+
if (!capturedRequest && options.purpose === void 0) {
|
|
11051
|
+
capturedRequest = true;
|
|
11052
|
+
owner.captureRequest(options.signal);
|
|
11053
|
+
}
|
|
10534
11054
|
try {
|
|
10535
11055
|
yield delivered;
|
|
10536
11056
|
} finally {
|
|
@@ -10549,8 +11069,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10549
11069
|
return excludedModelSet(this.accountModelSettings().excludedModelIds);
|
|
10550
11070
|
}
|
|
10551
11071
|
};
|
|
10552
|
-
|
|
10553
|
-
function apply$1(ctx, config = {}) {
|
|
11072
|
+
function createAccountRuntime(ctx, config, binding, exclusionTurns, replayRecovery, publish) {
|
|
10554
11073
|
const { accountModelTtlMs, accountModelFailureCooldownMs, accountModelSettings, requestBudget, requestBudgetSettings, streamLiveness, chatRequestSettings, ...requestConfig } = config;
|
|
10555
11074
|
const cacheSettings = accountModelSettings ?? (() => ({
|
|
10556
11075
|
accountModelTtlMs,
|
|
@@ -10560,11 +11079,11 @@ function apply$1(ctx, config = {}) {
|
|
|
10560
11079
|
const budgetSettings = requestBudgetSettings ?? (() => requestBudget ?? {});
|
|
10561
11080
|
const excludedModels = () => excludedModelSet(cacheSettings().excludedModelIds);
|
|
10562
11081
|
resolveRequestBudgetPolicy(budgetSettings());
|
|
10563
|
-
const store = () => createGitHubCopilotCredentialStore(ctx, GITHUB_COPILOT_PREVIEW_PROVIDER_ID,
|
|
10564
|
-
const acquire = (signal) => ctx.get("githubCopilotAccounts")?.host.acquire(signal);
|
|
11082
|
+
const store = () => createGitHubCopilotCredentialStore(ctx, GITHUB_COPILOT_PREVIEW_PROVIDER_ID, binding);
|
|
11083
|
+
const acquire = (signal) => ctx.get("githubCopilotAccounts")?.host.acquire(signal, true, binding?.accountId);
|
|
10565
11084
|
let rejectedAuth;
|
|
10566
11085
|
let authRecovery;
|
|
10567
|
-
const nativeAuth = createAccountModelAuth(() => createGitHubCopilotCredentialStore(ctx, "github-copilot",
|
|
11086
|
+
const nativeAuth = createAccountModelAuth(() => createGitHubCopilotCredentialStore(ctx, "github-copilot", binding), (grant) => {
|
|
10568
11087
|
const accountKey = copilotAccountKey(grant);
|
|
10569
11088
|
if (rejectedAuth?.accountKey !== accountKey || rejectedAuth.tokenFingerprint !== tokenFingerprint(grant.access)) return false;
|
|
10570
11089
|
const now = Date.now();
|
|
@@ -10620,20 +11139,10 @@ function apply$1(ctx, config = {}) {
|
|
|
10620
11139
|
});
|
|
10621
11140
|
const displayProofFor = (snapshot) => source.readDisplaySnapshot() === snapshot && provenSnapshot === snapshot && snapshotProof?.accountKey === snapshot.accountKey ? snapshotProof : void 0;
|
|
10622
11141
|
const proofFor = (snapshot) => source.readSnapshot() === snapshot && snapshotProof !== void 0 && snapshotProof.expires > Date.now() ? displayProofFor(snapshot) : void 0;
|
|
10623
|
-
const exclusionTurns = new ModelExclusionTurns();
|
|
10624
11142
|
const lifetime = new PreviewLifetime(store, source, proofFor, displayProofFor, (modelId) => excludedModels().has(modelId), exclusionTurns, acquire);
|
|
10625
|
-
const replayRecovery = installReplayRecovery(ctx, () => {
|
|
10626
|
-
if (snapshotProof === void 0 || snapshotProof.expires <= Date.now()) return void 0;
|
|
10627
|
-
return `${lifetime.revision}:${snapshotProof.accountKey}:${snapshotProof.tokenFingerprint}`;
|
|
10628
|
-
});
|
|
10629
|
-
const removeStepListener = ctx.on("session/event", (session, event) => {
|
|
10630
|
-
if (event.type === "step/start" || event.type === "turn/end") lifetime.clearSessionRetries(session.id);
|
|
10631
|
-
if (event.type === "turn/end") exclusionTurns.end(session);
|
|
10632
|
-
});
|
|
10633
11143
|
const template = resolvedProfile(createAccountProvider([], lifetime.guard(), "https://api.individual.githubcopilot.com").provider, requestConfig);
|
|
10634
11144
|
let configured = false;
|
|
10635
11145
|
let readError;
|
|
10636
|
-
let publishedDirectory = "";
|
|
10637
11146
|
const getView = () => {
|
|
10638
11147
|
const status = source.getView();
|
|
10639
11148
|
const cachedSnapshot = source.readDisplaySnapshot();
|
|
@@ -10680,7 +11189,7 @@ function apply$1(ctx, config = {}) {
|
|
|
10680
11189
|
...readError === void 0 && status.error === void 0 ? {} : { error: readError ?? status.error }
|
|
10681
11190
|
});
|
|
10682
11191
|
};
|
|
10683
|
-
|
|
11192
|
+
const notify = publish;
|
|
10684
11193
|
const refresh = async () => {
|
|
10685
11194
|
lifetime.assertActive();
|
|
10686
11195
|
const ticket = { revision: lifetime.revision };
|
|
@@ -10817,7 +11326,7 @@ function apply$1(ctx, config = {}) {
|
|
|
10817
11326
|
lifetime.assertActive();
|
|
10818
11327
|
},
|
|
10819
11328
|
auth: {
|
|
10820
|
-
credentials: lease?.credentials ??
|
|
11329
|
+
credentials: lease?.credentials ?? store(),
|
|
10821
11330
|
authContext: {
|
|
10822
11331
|
env: async () => void 0,
|
|
10823
11332
|
fileExists: async () => false
|
|
@@ -10827,65 +11336,192 @@ function apply$1(ctx, config = {}) {
|
|
|
10827
11336
|
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, (hostPath) => ctx.get("fs")?.processPathFromHostPath(hostPath), ref)
|
|
10828
11337
|
};
|
|
10829
11338
|
};
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
11339
|
+
return {
|
|
11340
|
+
adapter: new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, replayRecovery, void 0, (signal) => ctx.get("githubCopilotSessionAccounts")?.recordRequest(signal)),
|
|
11341
|
+
preview: {
|
|
11342
|
+
getView,
|
|
11343
|
+
refresh,
|
|
11344
|
+
recoveryLimits(modelId) {
|
|
11345
|
+
const snapshot = source.readSnapshot();
|
|
11346
|
+
if (snapshot === void 0 || proofFor(snapshot) === void 0 || !getView().available || excludedModels().has(modelId)) return void 0;
|
|
11347
|
+
const descriptor = snapshot.models.find((model) => model.id === modelId);
|
|
11348
|
+
if (descriptor === void 0) return void 0;
|
|
11349
|
+
const revision = lifetime.revision;
|
|
11350
|
+
const proof = snapshotProof;
|
|
11351
|
+
return Object.freeze({
|
|
11352
|
+
limits: Object.freeze({
|
|
11353
|
+
contextWindow: descriptor.contextWindow,
|
|
11354
|
+
maxTokens: descriptor.maxTokens,
|
|
11355
|
+
...descriptor.maxInputTokens === void 0 ? {} : { maxInputTokens: descriptor.maxInputTokens }
|
|
11356
|
+
}),
|
|
11357
|
+
policy: Object.freeze({ ...budgetSettings() }),
|
|
11358
|
+
assertCurrent: () => {
|
|
11359
|
+
if (!lifetime.isCurrent(revision) || snapshotProof !== proof || proofFor(snapshot) === void 0 || source.readSnapshot() !== snapshot || excludedModels().has(modelId)) throw new Error("COPILOT_MANUAL_RECOVERY_ACCOUNT_PROOF_CHANGED");
|
|
11360
|
+
}
|
|
11361
|
+
});
|
|
11362
|
+
},
|
|
11363
|
+
captureSearchProof() {
|
|
11364
|
+
const revision = lifetime.revision;
|
|
11365
|
+
const captured = snapshotProof;
|
|
11366
|
+
const expires = captured !== void 0 && captured.expires > Date.now() ? captured.expires : void 0;
|
|
11367
|
+
return () => lifetime.isCurrent(revision) && (expires === void 0 || expires > Date.now()) && (snapshotProof === captured || snapshotProof === void 0 || snapshotProof.expires > Date.now());
|
|
11368
|
+
},
|
|
11369
|
+
routeFacts(modelId) {
|
|
11370
|
+
if (excludedModels().has(modelId)) return void 0;
|
|
11371
|
+
const snapshot = source.readSnapshot();
|
|
11372
|
+
const proof = snapshot === void 0 ? void 0 : proofFor(snapshot);
|
|
11373
|
+
const descriptor = snapshot?.models.find((model) => model.id === modelId);
|
|
11374
|
+
return !getView().available || proof === void 0 || descriptor === void 0 ? void 0 : Object.freeze({
|
|
11375
|
+
api: descriptor.api,
|
|
11376
|
+
baseURL: proof.baseURL
|
|
11377
|
+
});
|
|
11378
|
+
},
|
|
11379
|
+
async resolveRequestAuth(modelId, signal) {
|
|
11380
|
+
const snapshot = await discoverSnapshot({ signal });
|
|
11381
|
+
const lease = await lifetime.lease(snapshot, modelId, signal);
|
|
11382
|
+
const auth = await nativeAuth.resolveAuth(lease.signal);
|
|
11383
|
+
const grant = await lifetime.read(lease.signal);
|
|
11384
|
+
if (grant === void 0) throw failure("COPILOT_PREVIEW_OAUTH_REQUIRED");
|
|
11385
|
+
lifetime.guard(lease).assertEntitled(grant, modelId);
|
|
11386
|
+
if (auth.accountKey !== lease.proof.accountKey || tokenFingerprint(auth.apiKey) !== lease.proof.tokenFingerprint || auth.baseURL !== lease.proof.baseURL) throw failure("COPILOT_PREVIEW_METADATA_STALE");
|
|
11387
|
+
await nativeAuth.assertAuthCurrent(auth, lease.signal);
|
|
11388
|
+
lifetime.guard(lease).assertEntitled(grant, modelId);
|
|
11389
|
+
return Object.freeze({
|
|
11390
|
+
apiKey: auth.apiKey,
|
|
11391
|
+
baseURL: auth.baseURL,
|
|
11392
|
+
headers: Object.freeze({ ...copilotPublicHeaders() })
|
|
11393
|
+
});
|
|
11394
|
+
},
|
|
11395
|
+
async discover(options) {
|
|
11396
|
+
try {
|
|
11397
|
+
await discoverSnapshot(options);
|
|
11398
|
+
} catch {
|
|
11399
|
+
lifetime.assertActive();
|
|
11400
|
+
}
|
|
11401
|
+
return getView();
|
|
11402
|
+
}
|
|
10834
11403
|
},
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
stage: "model-selected",
|
|
10848
|
-
modelId: model.id
|
|
10849
|
-
});
|
|
10850
|
-
const revision = lifetime.revision;
|
|
10851
|
-
const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, void 0, checkpoint);
|
|
10852
|
-
try {
|
|
10853
|
-
const prepared = await adapter.prepareCall(GITHUB_COPILOT_PREVIEW_PROVIDER_ID, model.id, signal);
|
|
11404
|
+
auto: {
|
|
11405
|
+
async loadModels(signal) {
|
|
11406
|
+
const excluded = excludedModels();
|
|
11407
|
+
return (await discoverSnapshot({ signal })).models.filter((model) => !excluded.has(model.id));
|
|
11408
|
+
},
|
|
11409
|
+
budgetPolicy: () => budgetSettings(),
|
|
11410
|
+
parentModelBindings: () => cacheSettings().parentModelFollow ?? [],
|
|
11411
|
+
followParentModel: () => cacheSettings().followParentModel === true,
|
|
11412
|
+
semanticAssessment: () => cacheSettings().autoSemanticAssessment ?? true,
|
|
11413
|
+
assessmentDiagnostic: (code) => ctx.logger.warn(code),
|
|
11414
|
+
async classifyTask(...args) {
|
|
11415
|
+
const [input, signal, observe, checkpoint] = args;
|
|
10854
11416
|
checkpoint?.();
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
if (
|
|
11417
|
+
const snapshot = await discoverSnapshot({ signal });
|
|
11418
|
+
checkpoint?.();
|
|
11419
|
+
const model = taskClassifierModel(snapshot.models.filter((model) => !excludedModels().has(model.id)));
|
|
11420
|
+
if (model === void 0) throw failure("COPILOT_AUTO_CLASSIFIER_UNAVAILABLE");
|
|
11421
|
+
observe?.({
|
|
11422
|
+
stage: "model-selected",
|
|
11423
|
+
modelId: model.id
|
|
11424
|
+
});
|
|
11425
|
+
const revision = lifetime.revision;
|
|
11426
|
+
const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, void 0, checkpoint);
|
|
11427
|
+
try {
|
|
11428
|
+
const prepared = await adapter.prepareCall(GITHUB_COPILOT_PREVIEW_PROVIDER_ID, model.id, signal);
|
|
11429
|
+
checkpoint?.();
|
|
11430
|
+
if (signal.aborted) throw signal.reason;
|
|
11431
|
+
return await classifyTaskWithAdapter(model, input, signal, (request) => prepared.stream(request), observe, prepared.model.reasoning?.efforts.some((effort) => effort.id === "off") === true, checkpoint);
|
|
11432
|
+
} finally {
|
|
11433
|
+
if (!lifetime.isCurrent(revision) || source.readSnapshot() !== snapshot || proofFor(snapshot) === void 0) throw new TaskAssessmentRevokedError(failure("COPILOT_PREVIEW_METADATA_STALE", "ABORTED"));
|
|
11434
|
+
}
|
|
11435
|
+
},
|
|
11436
|
+
admitModel(agent, turn, model, signal) {
|
|
11437
|
+
if (!exclusionTurns.admit(agent.session, turn, model, signal, excludedModels())) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
|
|
10859
11438
|
}
|
|
10860
11439
|
},
|
|
10861
|
-
|
|
10862
|
-
|
|
11440
|
+
pressureCallbacks: { resolve(request) {
|
|
11441
|
+
const snapshot = source.readSnapshot();
|
|
11442
|
+
if (snapshot === void 0 || proofFor(snapshot) === void 0) return void 0;
|
|
11443
|
+
if (excludedModels().has(request.model)) return void 0;
|
|
11444
|
+
const descriptor = snapshot.models.find((model) => model.id === request.model);
|
|
11445
|
+
if (descriptor === void 0) return void 0;
|
|
11446
|
+
const result = calculateRequestBudget(descriptor, request.maxTokens, resolveRequestBudgetPolicy(budgetSettings()));
|
|
11447
|
+
return result.ok ? { inputBudgetTokens: result.budget.pressureInputLimit } : void 0;
|
|
11448
|
+
} },
|
|
11449
|
+
optionsFor,
|
|
11450
|
+
lifetime,
|
|
11451
|
+
proof() {
|
|
11452
|
+
if (snapshotProof === void 0 || snapshotProof.expires <= Date.now()) return void 0;
|
|
11453
|
+
return `${binding?.accountId ?? "canonical"}:${lifetime.revision}:${snapshotProof.accountKey}:${snapshotProof.tokenFingerprint}`;
|
|
11454
|
+
},
|
|
11455
|
+
invalidate() {
|
|
11456
|
+
lifetime.change();
|
|
11457
|
+
provenSnapshot = void 0;
|
|
11458
|
+
snapshotProof = void 0;
|
|
11459
|
+
lastValidatedProof = void 0;
|
|
11460
|
+
refresh().catch(() => void 0);
|
|
10863
11461
|
}
|
|
11462
|
+
};
|
|
11463
|
+
}
|
|
11464
|
+
/** One registry owner delegates to immutable account-local native adapter state. */
|
|
11465
|
+
var AccountRoutingAdapter = class extends PiAiAdapter {
|
|
11466
|
+
requestRuntime;
|
|
11467
|
+
constructor(options, requestRuntime) {
|
|
11468
|
+
super(options);
|
|
11469
|
+
this.requestRuntime = requestRuntime;
|
|
11470
|
+
}
|
|
11471
|
+
listModels(provider) {
|
|
11472
|
+
return this.requestRuntime().adapter.listModels(provider);
|
|
11473
|
+
}
|
|
11474
|
+
resolveModel(provider, model, signal) {
|
|
11475
|
+
return this.requestRuntime(signal).adapter.resolveModel(provider, model, signal);
|
|
11476
|
+
}
|
|
11477
|
+
prepareCall(provider, model, signal) {
|
|
11478
|
+
return this.requestRuntime(signal).adapter.prepareCall(provider, model, signal);
|
|
11479
|
+
}
|
|
11480
|
+
stream(options) {
|
|
11481
|
+
return this.requestRuntime(options.signal).adapter.stream(options);
|
|
11482
|
+
}
|
|
11483
|
+
};
|
|
11484
|
+
/** Register services once; account switches affect the directory, not admitted turns. */
|
|
11485
|
+
function apply$1(ctx, config = {}) {
|
|
11486
|
+
const runtimes = /* @__PURE__ */ new Map();
|
|
11487
|
+
const exclusionTurns = new ModelExclusionTurns();
|
|
11488
|
+
const freezeBinding = (binding) => binding === void 0 ? void 0 : ctx.get("githubCopilotAccounts")?.host.captureAccount(binding.accountId) ?? binding;
|
|
11489
|
+
const globalBinding = () => freezeBinding(activeCopilotBinding(ctx));
|
|
11490
|
+
const requestBinding = (signal) => ctx.get("githubCopilotSessionAccounts")?.requestBinding(signal) ?? globalBinding();
|
|
11491
|
+
let disposed = false;
|
|
11492
|
+
let publishedDirectory = "";
|
|
11493
|
+
let publish = () => void 0;
|
|
11494
|
+
const runtimeFor = (binding) => {
|
|
11495
|
+
if (disposed) throw failure("COPILOT_PREVIEW_DISPOSED", "ABORTED");
|
|
11496
|
+
binding?.assertCurrent();
|
|
11497
|
+
const accountId = binding?.accountId ?? "canonical";
|
|
11498
|
+
const current = runtimes.get(accountId);
|
|
11499
|
+
if (current !== void 0) return current;
|
|
11500
|
+
if (runtimes.size >= 32) throw failure("COPILOT_ACCOUNTS_RUNTIME_LIMIT", "INVALID_REQUEST");
|
|
11501
|
+
const runtime = createAccountRuntime(ctx, config, binding, exclusionTurns, replayRecovery, () => {
|
|
11502
|
+
if (disposed) return;
|
|
11503
|
+
try {
|
|
11504
|
+
if ((globalBinding()?.accountId ?? "canonical") === accountId) publish();
|
|
11505
|
+
} catch {
|
|
11506
|
+
ctx.logger.warn("COPILOT_PREVIEW_DIRECTORY_ACCOUNT_UNAVAILABLE");
|
|
11507
|
+
}
|
|
11508
|
+
});
|
|
11509
|
+
runtimes.set(accountId, runtime);
|
|
11510
|
+
return runtime;
|
|
11511
|
+
};
|
|
11512
|
+
const currentRuntime = (signal) => runtimeFor(requestBinding(signal));
|
|
11513
|
+
const directoryRuntime = () => runtimeFor(globalBinding());
|
|
11514
|
+
const replayRecovery = installReplayRecovery(ctx, (agent, request) => {
|
|
11515
|
+
const accounts = ctx.get("githubCopilotSessionAccounts");
|
|
11516
|
+
const binding = agent !== void 0 && accounts !== void 0 ? accounts.bindingForAccount((accounts.turns.current(agent.session) ?? accounts.selected(agent)).accountId) : requestBinding(request?.signal);
|
|
11517
|
+
return runtimeFor(binding).proof();
|
|
10864
11518
|
});
|
|
10865
|
-
const
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
const next = JSON.stringify([...excludedModels()]);
|
|
10870
|
-
if (next === exclusionSignature) return;
|
|
10871
|
-
exclusionSignature = next;
|
|
10872
|
-
publishedDirectory = "";
|
|
10873
|
-
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
10874
|
-
});
|
|
10875
|
-
const pressureCallbacks = { resolve(request) {
|
|
10876
|
-
const snapshot = source.readSnapshot();
|
|
10877
|
-
if (snapshot === void 0 || proofFor(snapshot) === void 0) return void 0;
|
|
10878
|
-
if (excludedModels().has(request.model)) return void 0;
|
|
10879
|
-
const descriptor = snapshot.models.find((model) => model.id === request.model);
|
|
10880
|
-
if (descriptor === void 0) return void 0;
|
|
10881
|
-
const result = calculateRequestBudget(descriptor, request.maxTokens, resolveRequestBudgetPolicy(budgetSettings()));
|
|
10882
|
-
return result.ok ? { inputBudgetTokens: result.budget.pressureInputLimit } : void 0;
|
|
10883
|
-
} };
|
|
10884
|
-
installCopilotPreStepPressure(ctx, pressureCallbacks);
|
|
10885
|
-
installCopilotCompactionPressure(ctx, pressureCallbacks);
|
|
10886
|
-
notify = () => {
|
|
10887
|
-
const view = getView();
|
|
11519
|
+
const initial = directoryRuntime();
|
|
11520
|
+
const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new AccountRoutingAdapter(initial.optionsFor(), currentRuntime));
|
|
11521
|
+
publish = () => {
|
|
11522
|
+
const view = directoryRuntime().preview.getView();
|
|
10888
11523
|
const directory = JSON.stringify({
|
|
11524
|
+
account: globalBinding()?.accountId ?? "canonical",
|
|
10889
11525
|
models: view.models,
|
|
10890
11526
|
available: view.available,
|
|
10891
11527
|
configured: view.configured
|
|
@@ -10894,87 +11530,58 @@ function apply$1(ctx, config = {}) {
|
|
|
10894
11530
|
publishedDirectory = directory;
|
|
10895
11531
|
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
10896
11532
|
};
|
|
11533
|
+
const removeAutoRoute = installAutoModelRouting(ctx, {
|
|
11534
|
+
loadModels: (signal) => currentRuntime(signal).auto.loadModels(signal),
|
|
11535
|
+
classifyTask: (...args) => currentRuntime(args[1]).auto.classifyTask(...args),
|
|
11536
|
+
budgetPolicy: () => currentRuntime().auto.budgetPolicy(),
|
|
11537
|
+
parentModelBindings: () => currentRuntime().auto.parentModelBindings(),
|
|
11538
|
+
followParentModel: () => currentRuntime().auto.followParentModel(),
|
|
11539
|
+
semanticAssessment: () => currentRuntime().auto.semanticAssessment(),
|
|
11540
|
+
assessmentDiagnostic: (code) => ctx.logger.warn(code),
|
|
11541
|
+
admitModel: (agent, turn, model, signal) => currentRuntime(signal).auto.admitModel(agent, turn, model, signal)
|
|
11542
|
+
});
|
|
11543
|
+
const pressureCallbacks = { resolve: (request) => currentRuntime(request.signal).pressureCallbacks.resolve(request) };
|
|
11544
|
+
installCopilotPreStepPressure(ctx, pressureCallbacks);
|
|
11545
|
+
installCopilotCompactionPressure(ctx, pressureCallbacks);
|
|
10897
11546
|
ctx.provide("githubCopilotPreview", {
|
|
10898
|
-
getView,
|
|
10899
|
-
refresh,
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
contextWindow: descriptor.contextWindow,
|
|
10910
|
-
maxTokens: descriptor.maxTokens,
|
|
10911
|
-
...descriptor.maxInputTokens === void 0 ? {} : { maxInputTokens: descriptor.maxInputTokens }
|
|
10912
|
-
}),
|
|
10913
|
-
policy: Object.freeze({ ...budgetSettings() }),
|
|
10914
|
-
assertCurrent: () => {
|
|
10915
|
-
if (!lifetime.isCurrent(revision) || snapshotProof !== proof || proofFor(snapshot) === void 0 || source.readSnapshot() !== snapshot || excludedModels().has(modelId)) throw new Error("COPILOT_MANUAL_RECOVERY_ACCOUNT_PROOF_CHANGED");
|
|
10916
|
-
}
|
|
10917
|
-
});
|
|
10918
|
-
},
|
|
10919
|
-
captureSearchProof() {
|
|
10920
|
-
const revision = lifetime.revision;
|
|
10921
|
-
const captured = snapshotProof;
|
|
10922
|
-
const expires = captured !== void 0 && captured.expires > Date.now() ? captured.expires : void 0;
|
|
10923
|
-
return () => lifetime.isCurrent(revision) && (expires === void 0 || expires > Date.now()) && (snapshotProof === captured || snapshotProof === void 0 || snapshotProof.expires > Date.now());
|
|
10924
|
-
},
|
|
10925
|
-
routeFacts(modelId) {
|
|
10926
|
-
if (excludedModels().has(modelId)) return void 0;
|
|
10927
|
-
const snapshot = source.readSnapshot();
|
|
10928
|
-
const proof = snapshot === void 0 ? void 0 : proofFor(snapshot);
|
|
10929
|
-
const descriptor = snapshot?.models.find((model) => model.id === modelId);
|
|
10930
|
-
return !getView().available || proof === void 0 || descriptor === void 0 ? void 0 : Object.freeze({
|
|
10931
|
-
api: descriptor.api,
|
|
10932
|
-
baseURL: proof.baseURL
|
|
10933
|
-
});
|
|
10934
|
-
},
|
|
10935
|
-
async resolveRequestAuth(modelId, signal) {
|
|
10936
|
-
const snapshot = await discoverSnapshot({ signal });
|
|
10937
|
-
const lease = await lifetime.lease(snapshot, modelId, signal);
|
|
10938
|
-
const auth = await nativeAuth.resolveAuth(lease.signal);
|
|
10939
|
-
const grant = await lifetime.read(lease.signal);
|
|
10940
|
-
if (grant === void 0) throw failure("COPILOT_PREVIEW_OAUTH_REQUIRED");
|
|
10941
|
-
lifetime.guard(lease).assertEntitled(grant, modelId);
|
|
10942
|
-
if (auth.accountKey !== lease.proof.accountKey || tokenFingerprint(auth.apiKey) !== lease.proof.tokenFingerprint || auth.baseURL !== lease.proof.baseURL) throw failure("COPILOT_PREVIEW_METADATA_STALE");
|
|
10943
|
-
await nativeAuth.assertAuthCurrent(auth, lease.signal);
|
|
10944
|
-
lifetime.guard(lease).assertEntitled(grant, modelId);
|
|
10945
|
-
return Object.freeze({
|
|
10946
|
-
apiKey: auth.apiKey,
|
|
10947
|
-
baseURL: auth.baseURL,
|
|
10948
|
-
headers: Object.freeze({ ...copilotPublicHeaders() })
|
|
10949
|
-
});
|
|
10950
|
-
},
|
|
10951
|
-
async discover(options) {
|
|
10952
|
-
try {
|
|
10953
|
-
await discoverSnapshot(options);
|
|
10954
|
-
} catch {
|
|
10955
|
-
lifetime.assertActive();
|
|
10956
|
-
}
|
|
10957
|
-
return getView();
|
|
10958
|
-
}
|
|
11547
|
+
getView: () => disposed ? initial.preview.getView() : currentRuntime().preview.getView(),
|
|
11548
|
+
refresh: async () => currentRuntime().preview.refresh(),
|
|
11549
|
+
discover: (options) => currentRuntime(options?.signal).preview.discover(options),
|
|
11550
|
+
recoveryLimits: (model) => currentRuntime().preview.recoveryLimits(model),
|
|
11551
|
+
routeFacts: (model) => currentRuntime().preview.routeFacts(model),
|
|
11552
|
+
captureSearchProof: () => currentRuntime().preview.captureSearchProof(),
|
|
11553
|
+
resolveRequestAuth: (model, signal) => currentRuntime(signal).preview.resolveRequestAuth(model, signal)
|
|
11554
|
+
});
|
|
11555
|
+
const removeStepListener = ctx.on("session/event", (session, event) => {
|
|
11556
|
+
if (event.type === "step/start" || event.type === "turn/end") for (const runtime of runtimes.values()) runtime.lifetime.clearSessionRetries(session.id);
|
|
11557
|
+
if (event.type === "turn/end") exclusionTurns.end(session);
|
|
10959
11558
|
});
|
|
10960
11559
|
const removeListener = ctx.on("credentials/record-updated", (key) => {
|
|
10961
|
-
if (
|
|
10962
|
-
lifetime.change();
|
|
10963
|
-
provenSnapshot = void 0;
|
|
10964
|
-
snapshotProof = void 0;
|
|
10965
|
-
lastValidatedProof = void 0;
|
|
10966
|
-
refresh().catch(() => void 0);
|
|
11560
|
+
for (const [accountId, runtime] of runtimes) if ((accountId === "canonical" ? "llm-pi-ai/github-copilot" : `github-copilot/account-${accountId}`) === key) runtime.invalidate();
|
|
10967
11561
|
});
|
|
10968
11562
|
const removeAccountListener = ctx.get("githubCopilotAccounts")?.host.onChanged(() => {
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
11563
|
+
publishedDirectory = "";
|
|
11564
|
+
try {
|
|
11565
|
+
publish();
|
|
11566
|
+
directoryRuntime().preview.refresh().catch(() => void 0);
|
|
11567
|
+
} catch {
|
|
11568
|
+
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
11569
|
+
ctx.logger.warn("COPILOT_PREVIEW_DIRECTORY_ACCOUNT_UNAVAILABLE");
|
|
11570
|
+
}
|
|
11571
|
+
});
|
|
11572
|
+
let exclusionSignature = JSON.stringify([...excludedModelSet(config.accountModelSettings?.().excludedModelIds)]);
|
|
11573
|
+
const removeSettings = onSettingsNamespaceUpdated(ctx, (namespace) => {
|
|
11574
|
+
if (namespace !== "github-copilot") return;
|
|
11575
|
+
const next = JSON.stringify([...excludedModelSet(config.accountModelSettings?.().excludedModelIds)]);
|
|
11576
|
+
if (next === exclusionSignature) return;
|
|
11577
|
+
exclusionSignature = next;
|
|
11578
|
+
publishedDirectory = "";
|
|
11579
|
+
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
10975
11580
|
});
|
|
10976
11581
|
ctx.effect(() => () => {
|
|
10977
|
-
|
|
11582
|
+
disposed = true;
|
|
11583
|
+
for (const runtime of runtimes.values()) runtime.lifetime.dispose();
|
|
11584
|
+
runtimes.clear();
|
|
10978
11585
|
removeStepListener();
|
|
10979
11586
|
replayRecovery.dispose();
|
|
10980
11587
|
removeListener();
|
|
@@ -10983,7 +11590,7 @@ function apply$1(ctx, config = {}) {
|
|
|
10983
11590
|
removeAutoRoute();
|
|
10984
11591
|
registration();
|
|
10985
11592
|
});
|
|
10986
|
-
refresh().catch(() => void 0);
|
|
11593
|
+
initial.preview.refresh().catch(() => void 0);
|
|
10987
11594
|
}
|
|
10988
11595
|
var preview_route_default = {
|
|
10989
11596
|
name: "github-copilot-preview",
|
|
@@ -11099,23 +11706,35 @@ function activate(ctx, config) {
|
|
|
11099
11706
|
if (legacy && (legacy.searchProvider !== void 0 || legacy.defaultSearchProvider !== void 0 || legacy.searchMode !== void 0)) return legacy;
|
|
11100
11707
|
return current().searchRouting ?? {};
|
|
11101
11708
|
};
|
|
11709
|
+
const sessionAccounts = new SessionAccountsHost(ctx);
|
|
11710
|
+
ctx.provide("githubCopilotSessionAccounts", sessionAccounts);
|
|
11711
|
+
ctx.plugin({ apply(scope) {
|
|
11712
|
+
new SessionAccountController(scope, sessionAccounts);
|
|
11713
|
+
} });
|
|
11102
11714
|
const accountTurns = /* @__PURE__ */ new Map();
|
|
11103
11715
|
ctx.on("session/event", (session, event) => {
|
|
11104
11716
|
if (event.type !== "turn/end") return;
|
|
11105
11717
|
accountTurns.get(session.id)?.release();
|
|
11106
11718
|
accountTurns.delete(session.id);
|
|
11719
|
+
sessionAccounts.end(session, event.data.turn);
|
|
11107
11720
|
});
|
|
11108
11721
|
ctx.on("agent/disposed", ({ agent }) => {
|
|
11109
11722
|
accountTurns.get(agent.session.id)?.release();
|
|
11110
11723
|
accountTurns.delete(agent.session.id);
|
|
11724
|
+
sessionAccounts.remove(agent.session);
|
|
11111
11725
|
});
|
|
11112
|
-
|
|
11726
|
+
const acquireAccount = (signal, provider) => {
|
|
11727
|
+
if (provider === "github-copilot") return ctx.get("githubCopilotAccounts")?.host.acquire(signal);
|
|
11728
|
+
const binding = sessionAccounts.requestBinding(signal);
|
|
11729
|
+
return ctx.get("githubCopilotAccounts")?.host.acquire(signal, true, binding.accountId);
|
|
11730
|
+
};
|
|
11731
|
+
ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
|
|
11113
11732
|
const projections = ctx.get("sessionProjections");
|
|
11114
11733
|
const state = typeof projections === "object" && projections !== null && "stateOf" in projections && typeof projections.stateOf === "function" ? Reflect.apply(projections.stateOf, projections, [agent.session, "modelSelection"]) : void 0;
|
|
11115
11734
|
const pending = typeof state === "object" && state !== null && "pending" in state ? state.pending : void 0;
|
|
11116
|
-
|
|
11117
|
-
|
|
11118
|
-
const lease =
|
|
11735
|
+
if (((typeof pending === "object" && pending !== null && "provider" in pending ? pending.provider : void 0) ?? agent.session.requestHeader()?.config.provider) !== "github-copilot-preview" && !sessionAccounts.turns.current(agent.session)) return next();
|
|
11736
|
+
sessionAccounts.admit(agent, turn, signal);
|
|
11737
|
+
const lease = acquireAccount(signal);
|
|
11119
11738
|
let retained = false;
|
|
11120
11739
|
try {
|
|
11121
11740
|
const result = await next();
|
|
@@ -11133,6 +11752,7 @@ function activate(ctx, config) {
|
|
|
11133
11752
|
ctx.effect(() => () => {
|
|
11134
11753
|
for (const lease of accountTurns.values()) lease.release();
|
|
11135
11754
|
accountTurns.clear();
|
|
11755
|
+
sessionAccounts.dispose();
|
|
11136
11756
|
});
|
|
11137
11757
|
ctx.plugin(preview_route_default, {
|
|
11138
11758
|
accountModelSettings: () => current(),
|
|
@@ -11158,6 +11778,25 @@ function activate(ctx, config) {
|
|
|
11158
11778
|
let proofCancellation = new AbortController();
|
|
11159
11779
|
const candidateGenerations = /* @__PURE__ */ new WeakMap();
|
|
11160
11780
|
const candidateProviders = /* @__PURE__ */ new WeakMap();
|
|
11781
|
+
const accountProofs = /* @__PURE__ */ new Map();
|
|
11782
|
+
const candidateAccounts = /* @__PURE__ */ new WeakMap();
|
|
11783
|
+
function accountProof(signal, provider) {
|
|
11784
|
+
const key = provider === "github-copilot" ? GITHUB_COPILOT_CREDENTIAL_KEY$1 : sessionAccounts.requestBinding(signal).key;
|
|
11785
|
+
let proof = accountProofs.get(key);
|
|
11786
|
+
if (!proof) {
|
|
11787
|
+
if (accountProofs.size >= 64) throw new Error("COPILOT_SEARCH_ACCOUNT_PROOF_LIMIT");
|
|
11788
|
+
proof = {
|
|
11789
|
+
key,
|
|
11790
|
+
cancellation: new AbortController()
|
|
11791
|
+
};
|
|
11792
|
+
accountProofs.set(key, proof);
|
|
11793
|
+
}
|
|
11794
|
+
return proof;
|
|
11795
|
+
}
|
|
11796
|
+
function invalidateAccount(key) {
|
|
11797
|
+
accountProofs.get(key)?.cancellation.abort();
|
|
11798
|
+
accountProofs.delete(key);
|
|
11799
|
+
}
|
|
11161
11800
|
const ownerPlans = /* @__PURE__ */ new WeakMap();
|
|
11162
11801
|
const disposedOwners = /* @__PURE__ */ new WeakSet();
|
|
11163
11802
|
const candidateSignals = /* @__PURE__ */ new WeakMap();
|
|
@@ -11180,17 +11819,20 @@ function activate(ctx, config) {
|
|
|
11180
11819
|
proofCancellation = new AbortController();
|
|
11181
11820
|
}
|
|
11182
11821
|
ctx.on("credentials/record-updated", (key) => {
|
|
11183
|
-
if (
|
|
11822
|
+
if (isCopilotAccountRecord(key)) invalidateAccount(key);
|
|
11184
11823
|
});
|
|
11185
|
-
ctx.get("githubCopilotAccounts")?.host.onChanged(invalidatePlans);
|
|
11186
11824
|
ctx.effect(() => () => {
|
|
11187
11825
|
active = false;
|
|
11188
11826
|
invalidatePlans();
|
|
11827
|
+
for (const proof of accountProofs.values()) proof.cancellation.abort();
|
|
11828
|
+
accountProofs.clear();
|
|
11189
11829
|
});
|
|
11190
11830
|
function assertCurrentCandidate(candidate) {
|
|
11191
11831
|
if (!active) throw new Error("github-copilot: hosted search integration was disposed");
|
|
11192
11832
|
if (candidateSignals.get(candidate)?.aborted === true) throw new Error("github-copilot: search owner or proof was disposed");
|
|
11193
11833
|
if (candidateGenerations.get(candidate) !== generation) throw new Error("github-copilot: search proof invalidated; retry with current credentials");
|
|
11834
|
+
const account = candidateAccounts.get(candidate);
|
|
11835
|
+
if (!account || account.cancellation.signal.aborted || accountProof(candidateSignals.get(candidate), candidateProviders.get(candidate)).key !== account.key) throw new Error("COPILOT_SEARCH_ACCOUNT_PROOF_INVALIDATED");
|
|
11194
11836
|
}
|
|
11195
11837
|
const hooks = {
|
|
11196
11838
|
resolveResponsesReasoning: (request, candidate) => resolveCopilotResponsesReasoning(ctx, request, candidate),
|
|
@@ -11207,7 +11849,10 @@ function activate(ctx, config) {
|
|
|
11207
11849
|
assertCurrentCandidate(candidate);
|
|
11208
11850
|
return auth;
|
|
11209
11851
|
} catch (error) {
|
|
11210
|
-
if (active && candidateGenerations.get(candidate) === generation && candidateSignals.get(candidate)?.aborted !== true)
|
|
11852
|
+
if (active && candidateGenerations.get(candidate) === generation && candidateSignals.get(candidate)?.aborted !== true) {
|
|
11853
|
+
const account = candidateAccounts.get(candidate);
|
|
11854
|
+
if (account) invalidateAccount(account.key);
|
|
11855
|
+
}
|
|
11211
11856
|
throw error;
|
|
11212
11857
|
}
|
|
11213
11858
|
}
|
|
@@ -11221,15 +11866,21 @@ function activate(ctx, config) {
|
|
|
11221
11866
|
}
|
|
11222
11867
|
function createPlan(candidates, cfg, provider, plans, operation) {
|
|
11223
11868
|
const startedAt = generation;
|
|
11224
|
-
const
|
|
11869
|
+
const account = accountProof(operation?.signal, provider);
|
|
11870
|
+
const signal = AbortSignal.any([
|
|
11871
|
+
proofCancellation.signal,
|
|
11872
|
+
account.cancellation.signal,
|
|
11873
|
+
...plans === void 0 ? [] : [plans.cancellation.signal]
|
|
11874
|
+
]);
|
|
11225
11875
|
const probeSignal = operation?.signal === void 0 ? signal : AbortSignal.any([signal, operation.signal]);
|
|
11226
11876
|
function bind(candidate, lifetime) {
|
|
11227
11877
|
candidateGenerations.set(candidate, startedAt);
|
|
11878
|
+
candidateAccounts.set(candidate, account);
|
|
11228
11879
|
candidateSignals.set(candidate, lifetime);
|
|
11229
11880
|
if (provider !== void 0) candidateProviders.set(candidate, provider);
|
|
11230
11881
|
}
|
|
11231
11882
|
for (const candidate of candidates) bind(candidate, cfg.probe ? probeSignal : signal);
|
|
11232
|
-
const admission =
|
|
11883
|
+
const admission = acquireAccount(probeSignal, provider);
|
|
11233
11884
|
let nextPlan;
|
|
11234
11885
|
try {
|
|
11235
11886
|
nextPlan = new SearchPlan(candidates, (candidate) => probeCandidate(candidate, async (selected) => {
|
|
@@ -11249,28 +11900,31 @@ function activate(ctx, config) {
|
|
|
11249
11900
|
});
|
|
11250
11901
|
return nextPlan;
|
|
11251
11902
|
}
|
|
11252
|
-
function matches(cached, route, candidates, cfg) {
|
|
11903
|
+
function matches(cached, route, candidates, cfg, provider) {
|
|
11253
11904
|
try {
|
|
11254
11905
|
cached?.assertProof?.();
|
|
11255
11906
|
} catch {
|
|
11256
11907
|
return false;
|
|
11257
11908
|
}
|
|
11258
11909
|
if (cached?.assertProof !== void 0 && cached.plan.chosenCandidate() === void 0 && (cached.plan.available() || cached.probeSignal?.aborted === true)) return false;
|
|
11259
|
-
return cached !== void 0 && cached.generation === generation && cached.plan.signal?.aborted !== true && sameRoute(route, cached.route) && cached.probe.enabled === cfg.probe && cached.probe.timeoutMs === cfg.probeTimeoutMs && sameCandidates(candidates, cached.plan.candidates);
|
|
11910
|
+
return cached !== void 0 && cached.generation === generation && cached.account === accountProof(void 0, provider) && !cached.account.cancellation.signal.aborted && cached.plan.signal?.aborted !== true && sameRoute(route, cached.route) && cached.probe.enabled === cfg.probe && cached.probe.timeoutMs === cfg.probeTimeoutMs && sameCandidates(candidates, cached.plan.candidates);
|
|
11260
11911
|
}
|
|
11261
11912
|
function plan(route, cfg, owner, surface, operation) {
|
|
11262
11913
|
const plans = owner === void 0 ? void 0 : plansFor(owner);
|
|
11263
11914
|
const candidates = surface === "inline" ? candidatesForRoute(route) : surface === "configured" ? configuredCandidates(cfg) : traditionalCandidates(route, cfg);
|
|
11264
11915
|
const cached = plans?.[surface];
|
|
11265
|
-
|
|
11916
|
+
const provider = surface === "configured" ? GITHUB_COPILOT_PREVIEW_PROVIDER_ID : route?.provider;
|
|
11917
|
+
if (matches(cached, route, candidates, cfg, provider)) return cached.plan;
|
|
11266
11918
|
const startedAt = generation;
|
|
11267
|
-
const
|
|
11919
|
+
const account = accountProof(operation?.signal, provider);
|
|
11920
|
+
const nextPlan = createPlan(candidates, cfg, provider, plans, operation);
|
|
11268
11921
|
if (generation === startedAt && active && plans?.cancellation.signal.aborted !== true) {
|
|
11269
11922
|
if (plans !== void 0) plans[surface] = {
|
|
11270
11923
|
plan: nextPlan,
|
|
11271
11924
|
route,
|
|
11272
11925
|
probe: probeSettings(cfg),
|
|
11273
11926
|
generation: startedAt,
|
|
11927
|
+
account,
|
|
11274
11928
|
...operation === void 0 ? {} : {
|
|
11275
11929
|
assertProof: operation.assertProof,
|
|
11276
11930
|
...operation.signal === void 0 ? {} : { probeSignal: operation.signal }
|
|
@@ -11291,15 +11945,20 @@ function activate(ctx, config) {
|
|
|
11291
11945
|
const startedAt = generation;
|
|
11292
11946
|
if (owner === void 0 || disposedOwners.has(owner) || selection === void 0) throw new Error("github-copilot: hosted search requires agents.currentInitiator() and Session.requestHeader().config");
|
|
11293
11947
|
const plans = plansFor(owner);
|
|
11948
|
+
const account = accountProof(signal, selection.provider);
|
|
11294
11949
|
if (selection?.provider === "github-copilot-preview") {
|
|
11295
|
-
const signals = [
|
|
11950
|
+
const signals = [
|
|
11951
|
+
proofCancellation.signal,
|
|
11952
|
+
account.cancellation.signal,
|
|
11953
|
+
plans.cancellation.signal
|
|
11954
|
+
];
|
|
11296
11955
|
if (signal !== void 0) signals.push(signal);
|
|
11297
11956
|
await ctx.get("githubCopilotPreview")?.discover({
|
|
11298
11957
|
force: false,
|
|
11299
11958
|
signal: AbortSignal.any(signals)
|
|
11300
11959
|
});
|
|
11301
11960
|
}
|
|
11302
|
-
if (!active || startedAt !== generation || plans.cancellation.signal.aborted || signal?.aborted === true) throw new Error("github-copilot: search proof invalidated during route resolution");
|
|
11961
|
+
if (!active || startedAt !== generation || account.cancellation.signal.aborted || plans.cancellation.signal.aborted || signal?.aborted === true) throw new Error("github-copilot: search proof invalidated during route resolution");
|
|
11303
11962
|
return plan(currentChatRoute(ctx, selection), cfg, owner, "traditional");
|
|
11304
11963
|
}
|
|
11305
11964
|
function configuredSearchSelection(cfg) {
|
|
@@ -11318,14 +11977,19 @@ function activate(ctx, config) {
|
|
|
11318
11977
|
const startedAt = generation;
|
|
11319
11978
|
if (owner === void 0 || disposedOwners.has(owner) || !configuredAllowed(cfg)) throw new Error("github-copilot: independent hosted search requires an initiating Agent and an allowed Copilot provider");
|
|
11320
11979
|
const plans = plansFor(owner);
|
|
11321
|
-
const
|
|
11980
|
+
const account = accountProof(signal);
|
|
11981
|
+
const signals = [
|
|
11982
|
+
proofCancellation.signal,
|
|
11983
|
+
account.cancellation.signal,
|
|
11984
|
+
plans.cancellation.signal
|
|
11985
|
+
];
|
|
11322
11986
|
if (signal !== void 0) signals.push(signal);
|
|
11323
11987
|
await ctx.get("githubCopilotPreview")?.discover({
|
|
11324
11988
|
force: false,
|
|
11325
11989
|
signal: AbortSignal.any(signals)
|
|
11326
11990
|
});
|
|
11327
11991
|
assertCurrent();
|
|
11328
|
-
if (!active || startedAt !== generation || plans.cancellation.signal.aborted || signal?.aborted === true) throw new Error("github-copilot: configured search proof invalidated during route resolution");
|
|
11992
|
+
if (!active || startedAt !== generation || account.cancellation.signal.aborted || plans.cancellation.signal.aborted || signal?.aborted === true) throw new Error("github-copilot: configured search proof invalidated during route resolution");
|
|
11329
11993
|
return plan(selection === void 0 ? void 0 : currentChatRoute(ctx, selection), cfg, owner, "configured", {
|
|
11330
11994
|
assertCurrent,
|
|
11331
11995
|
assertProof,
|
|
@@ -11370,7 +12034,7 @@ function activate(ctx, config) {
|
|
|
11370
12034
|
const candidates = traditionalCandidates(route, cfg);
|
|
11371
12035
|
if (candidates.length === 0) return cfg.enabled && route?.provider === "github-copilot-preview" && route.api === void 0 && (cfg.providers.length === 0 || cfg.providers.includes(route.provider)) && ctx.get("githubCopilotPreview")?.getView().configured === true;
|
|
11372
12036
|
const cached = ownerPlans.get(owner)?.traditional;
|
|
11373
|
-
return !matches(cached, route, candidates, cfg) || cached.plan.available();
|
|
12037
|
+
return !matches(cached, route, candidates, cfg, route?.provider) || cached.plan.available();
|
|
11374
12038
|
}
|
|
11375
12039
|
/** Local readiness for the provider-owned Copilot search model. */
|
|
11376
12040
|
function configuredAvailable() {
|
|
@@ -11387,13 +12051,13 @@ function activate(ctx, config) {
|
|
|
11387
12051
|
return view?.configured === true && (selection === void 0 ? view.state !== "ready" : route?.provider === "github-copilot-preview" && route.api === void 0);
|
|
11388
12052
|
}
|
|
11389
12053
|
const cached = ownerPlans.get(owner)?.configured;
|
|
11390
|
-
return !matches(cached, route, candidates, cfg) || cached.plan.available();
|
|
12054
|
+
return !matches(cached, route, candidates, cfg, "github-copilot-preview") || cached.plan.available();
|
|
11391
12055
|
}
|
|
11392
12056
|
const nativeTraditionalProvider = createTraditionalSearchProvider(traditionalAvailable, webPlan, hooks, current);
|
|
11393
12057
|
const traditionalProvider = {
|
|
11394
12058
|
...nativeTraditionalProvider,
|
|
11395
12059
|
async search(request, signal) {
|
|
11396
|
-
const lease = ctx
|
|
12060
|
+
const lease = acquireAccount(signal, currentSearchSelection(currentSearchInitiator(ctx))?.provider);
|
|
11397
12061
|
try {
|
|
11398
12062
|
return await nativeTraditionalProvider.search(request, signal);
|
|
11399
12063
|
} finally {
|
|
@@ -11402,7 +12066,7 @@ function activate(ctx, config) {
|
|
|
11402
12066
|
}
|
|
11403
12067
|
};
|
|
11404
12068
|
async function configuredSearch(request, signal) {
|
|
11405
|
-
const lease =
|
|
12069
|
+
const lease = acquireAccount(signal);
|
|
11406
12070
|
try {
|
|
11407
12071
|
return await configuredAccountSearch(request, signal);
|
|
11408
12072
|
} finally {
|
|
@@ -11412,11 +12076,12 @@ function activate(ctx, config) {
|
|
|
11412
12076
|
async function configuredAccountSearch(request, signal) {
|
|
11413
12077
|
const owner = currentSearchInitiator(ctx);
|
|
11414
12078
|
const startedGeneration = generation;
|
|
12079
|
+
const account = accountProof(signal);
|
|
11415
12080
|
const cfg = current();
|
|
11416
12081
|
const preview = ctx.get("githubCopilotPreview");
|
|
11417
12082
|
const proof = preview?.captureSearchProof();
|
|
11418
12083
|
const assertProof = () => {
|
|
11419
|
-
if (!active || generation !== startedGeneration || owner === void 0 || disposedOwners.has(owner) || preview === void 0 || ctx.get("githubCopilotPreview") !== preview || proof?.() !== true) throw new ConfiguredSearchProofInvalidated();
|
|
12084
|
+
if (!active || generation !== startedGeneration || account.cancellation.signal.aborted || owner === void 0 || disposedOwners.has(owner) || preview === void 0 || ctx.get("githubCopilotPreview") !== preview || proof?.() !== true) throw new ConfiguredSearchProofInvalidated();
|
|
11420
12085
|
};
|
|
11421
12086
|
const assertCurrent = () => {
|
|
11422
12087
|
if (signal?.aborted) throw new WebError("web search aborted", "WEB_ABORTED");
|
|
@@ -11463,6 +12128,7 @@ function activate(ctx, config) {
|
|
|
11463
12128
|
if (captureSearchProvider !== void 0) {
|
|
11464
12129
|
if (policy.primaryProvider === "none") throw new WebError("web search is disabled by the primary search provider setting", "WEB_PROVIDER_UNAVAILABLE");
|
|
11465
12130
|
const startedGeneration = generation;
|
|
12131
|
+
const account = accountProof(signal, policy.primaryProvider === "auto" ? selection?.provider : void 0);
|
|
11466
12132
|
const registrations = [];
|
|
11467
12133
|
let usingManagedPrimary = false;
|
|
11468
12134
|
let configuredProofInvalid = false;
|
|
@@ -11509,10 +12175,11 @@ function activate(ctx, config) {
|
|
|
11509
12175
|
const boundSignal = AbortSignal.any([
|
|
11510
12176
|
...signal === void 0 ? [] : [signal],
|
|
11511
12177
|
proofCancellation.signal,
|
|
12178
|
+
account.cancellation.signal,
|
|
11512
12179
|
plansFor(owner).cancellation.signal,
|
|
11513
12180
|
...registrations.map((provider) => provider.signal)
|
|
11514
12181
|
]);
|
|
11515
|
-
const canContinue = () => active && generation === startedGeneration && !disposedOwners.has(owner) && !configuredProofInvalid && registrations.every((provider) => provider.current()) && (!usingManagedPrimary || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
12182
|
+
const canContinue = () => active && generation === startedGeneration && !account.cancellation.signal.aborted && !disposedOwners.has(owner) && !configuredProofInvalid && registrations.every((provider) => provider.current()) && (!usingManagedPrimary || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
11516
12183
|
return routeSearchTools(request, boundSignal, {
|
|
11517
12184
|
primary,
|
|
11518
12185
|
fallback,
|
|
@@ -11526,15 +12193,17 @@ function activate(ctx, config) {
|
|
|
11526
12193
|
if (!useNative && defaultProviderId === "none") throw new WebError("web search is disabled by github-copilot-search-routing.defaultSearchProvider", "WEB_PROVIDER_UNAVAILABLE");
|
|
11527
12194
|
if (!useNative && defaultProviderId !== "github-copilot-hosted" && selectProvider === void 0) return delegate(request, signal);
|
|
11528
12195
|
const startedGeneration = generation;
|
|
12196
|
+
const account = accountProof(signal, useNative ? selection?.provider : void 0);
|
|
11529
12197
|
const managedPreview = useNative && managedOwned ? ctx.get("githubCopilotPreview") : void 0;
|
|
11530
12198
|
const managedProof = managedPreview?.captureSearchProof();
|
|
11531
12199
|
const ownerSignal = plansFor(owner).cancellation.signal;
|
|
11532
12200
|
const boundSignal = AbortSignal.any([
|
|
11533
12201
|
...signal === void 0 ? [] : [signal],
|
|
11534
12202
|
proofCancellation.signal,
|
|
12203
|
+
account.cancellation.signal,
|
|
11535
12204
|
ownerSignal
|
|
11536
12205
|
]);
|
|
11537
|
-
const canContinue = () => active && generation === startedGeneration && !disposedOwners.has(owner) && (!useNative || !managedOwned || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
12206
|
+
const canContinue = () => active && generation === startedGeneration && !account.cancellation.signal.aborted && !disposedOwners.has(owner) && (!useNative || !managedOwned || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
11538
12207
|
if (!useNative) {
|
|
11539
12208
|
if (defaultProviderId === "github-copilot-hosted") return configuredSearch(request, boundSignal);
|
|
11540
12209
|
return selectProvider(defaultProviderId, request, boundSignal);
|
|
@@ -11549,11 +12218,26 @@ function activate(ctx, config) {
|
|
|
11549
12218
|
canContinue
|
|
11550
12219
|
})).result;
|
|
11551
12220
|
} });
|
|
12221
|
+
function searchSettingsSignature() {
|
|
12222
|
+
const { activeAccountId: _global, sessionAccounts: _sessions, ...settings } = current();
|
|
12223
|
+
return JSON.stringify({
|
|
12224
|
+
settings,
|
|
12225
|
+
routing: readRouting()
|
|
12226
|
+
});
|
|
12227
|
+
}
|
|
12228
|
+
let settingsSignature = searchSettingsSignature();
|
|
11552
12229
|
observeSettingsNamespace(ctx, GITHUB_COPILOT_SETTINGS_NAMESPACE, config, {
|
|
11553
12230
|
setSource: (source) => {
|
|
11554
12231
|
current = source;
|
|
12232
|
+
settingsSignature = searchSettingsSignature();
|
|
11555
12233
|
},
|
|
11556
|
-
onChange:
|
|
12234
|
+
onChange: () => {
|
|
12235
|
+
const next = searchSettingsSignature();
|
|
12236
|
+
if (next !== settingsSignature) {
|
|
12237
|
+
settingsSignature = next;
|
|
12238
|
+
invalidatePlans();
|
|
12239
|
+
}
|
|
12240
|
+
}
|
|
11557
12241
|
});
|
|
11558
12242
|
ensureGitHubCopilotProviderProfile(ctx).catch((error) => {
|
|
11559
12243
|
ctx.logger.error("github-copilot: failed to repair the GitHub Copilot provider route during startup");
|
|
@@ -11574,7 +12258,11 @@ function activate(ctx, config) {
|
|
|
11574
12258
|
signal: AbortSignal.any(signals)
|
|
11575
12259
|
};
|
|
11576
12260
|
return (async function* () {
|
|
11577
|
-
|
|
12261
|
+
if (operation.signal.aborted) {
|
|
12262
|
+
yield* inlineWireStream(operation, p, hooks, cfg);
|
|
12263
|
+
return;
|
|
12264
|
+
}
|
|
12265
|
+
const lease = acquireAccount(operation.signal, operation.provider);
|
|
11578
12266
|
try {
|
|
11579
12267
|
yield* inlineWireStream(operation, p, hooks, cfg);
|
|
11580
12268
|
} finally {
|
|
@@ -11594,7 +12282,7 @@ function activate(ctx, config) {
|
|
|
11594
12282
|
const cfg = current();
|
|
11595
12283
|
if (route === void 0 || cfg.providers.length > 0 && !cfg.providers.includes(route.provider)) return "";
|
|
11596
12284
|
const cached = ownerPlans.get(owner)?.inline;
|
|
11597
|
-
const nativeGuidance = servingPrompt(current, matches(cached, route, candidatesForRoute(route), cfg) ? cached.plan : void 0);
|
|
12285
|
+
const nativeGuidance = servingPrompt(current, matches(cached, route, candidatesForRoute(route), cfg, route.provider) ? cached.plan : void 0);
|
|
11598
12286
|
const owned = route.provider === "github-copilot-preview" && isPluginPreviewProvider(ctx, route.provider);
|
|
11599
12287
|
if (!cfg.enabled || cfg.routeWebSearch === false || ctx.get("githubCopilotOriginalWeb") === void 0 || !isCopilotSearchSelection(route, owned)) return nativeGuidance;
|
|
11600
12288
|
return [nativeGuidance, policy.defaultProvider === "none" || policy.legacy && cfg.searchFallback === "none" ? "Copilot search fallback is disabled. Do not silently substitute another paid search backend after a search failure." : "When web_search reports a fallback, explicitly tell the user the actual search backend (and custom endpoint/model when provided) and possible API charges in your answer. Never describe fallback results as Copilot search. Automatic fallback does not need per-search confirmation."].filter(Boolean).join("\n\n");
|