dsh-github-copilot 0.4.0-alpha.103 → 0.4.0-alpha.105
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 +5 -1
- package/CHANGELOG.md +14 -0
- package/README.md +23 -11
- package/README.zh.md +21 -10
- package/deployment-baseline.json +25 -1
- package/docs/copilot-accounts.md +66 -26
- package/docs/copilot-usage.md +5 -3
- package/lib/client.js +372 -37
- package/lib/client.js.map +1 -1
- package/lib/index.js +1039 -237
- package/lib/remote.js +75 -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-card.d.ts +1 -0
- package/lib/types/copilot-accounts-host.d.ts +18 -2
- package/lib/types/copilot-accounts-remote.d.ts +7 -0
- package/lib/types/copilot-accounts-types.d.ts +1 -1
- package/lib/types/copilot-usage-card.d.ts +18 -1
- 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 +20 -0
- package/lib/types/session-accounts-host.d.ts +32 -0
- package/lib/types/session-accounts-remote.d.ts +113 -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.105",
|
|
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;
|
|
@@ -3414,6 +3414,7 @@ var __esDecorate$4 = function(ctor, descriptorIn, decorators, contextIn, initial
|
|
|
3414
3414
|
done = true;
|
|
3415
3415
|
};
|
|
3416
3416
|
const IDENTITY_TTL = 6e5;
|
|
3417
|
+
const IDENTITY_FAILURE_COOLDOWN = 3e4;
|
|
3417
3418
|
const TIMEOUT = 1e4;
|
|
3418
3419
|
const MAX_BODY = 65536;
|
|
3419
3420
|
var AccountsFailure = class extends Error {
|
|
@@ -3454,8 +3455,11 @@ var CopilotAccountsHost = class {
|
|
|
3454
3455
|
selectionSignature;
|
|
3455
3456
|
disposed = false;
|
|
3456
3457
|
leases = /* @__PURE__ */ new Set();
|
|
3458
|
+
accountLeases = /* @__PURE__ */ new Map();
|
|
3457
3459
|
identities = /* @__PURE__ */ new Map();
|
|
3458
3460
|
unavailableIdentities = /* @__PURE__ */ new Set();
|
|
3461
|
+
identityFlights = /* @__PURE__ */ new Map();
|
|
3462
|
+
identityFailures = /* @__PURE__ */ new Map();
|
|
3459
3463
|
listeners = /* @__PURE__ */ new Set();
|
|
3460
3464
|
abort = new AbortController();
|
|
3461
3465
|
operation;
|
|
@@ -3487,16 +3491,19 @@ var CopilotAccountsHost = class {
|
|
|
3487
3491
|
const signature = accountId;
|
|
3488
3492
|
const changed = this.selectionSignature !== void 0 && this.selectionSignature !== signature;
|
|
3489
3493
|
this.selectionSignature = signature;
|
|
3490
|
-
if (changed) this.revoke();
|
|
3494
|
+
if (changed) this.revoke(false);
|
|
3491
3495
|
return {
|
|
3492
3496
|
accountId,
|
|
3493
3497
|
revision: descriptor.revision
|
|
3494
3498
|
};
|
|
3495
3499
|
}
|
|
3496
|
-
revoke() {
|
|
3500
|
+
revoke(clearIdentity = true) {
|
|
3497
3501
|
this.generation++;
|
|
3498
|
-
this.
|
|
3499
|
-
|
|
3502
|
+
for (const accountId of this.identityFlights.keys()) this.invalidateIdentity(accountId);
|
|
3503
|
+
if (clearIdentity) {
|
|
3504
|
+
this.identities.clear();
|
|
3505
|
+
this.unavailableIdentities.clear();
|
|
3506
|
+
}
|
|
3500
3507
|
for (const listener of this.listeners) listener();
|
|
3501
3508
|
}
|
|
3502
3509
|
selectionChanged() {
|
|
@@ -3513,15 +3520,25 @@ var CopilotAccountsHost = class {
|
|
|
3513
3520
|
credentialChanged(key) {
|
|
3514
3521
|
if (!isCopilotAccountRecord(key)) return;
|
|
3515
3522
|
const accountId = key === "llm-pi-ai/github-copilot" ? "canonical" : key.slice(23);
|
|
3523
|
+
this.invalidateIdentity(accountId);
|
|
3516
3524
|
this.identities.delete(accountId);
|
|
3517
3525
|
this.unavailableIdentities.delete(accountId);
|
|
3518
3526
|
}
|
|
3527
|
+
invalidateIdentity(accountId) {
|
|
3528
|
+
this.identityFlights.get(accountId)?.abort.abort(new AccountsFailure("COPILOT_ACCOUNTS_CHANGED"));
|
|
3529
|
+
this.identityFlights.delete(accountId);
|
|
3530
|
+
this.identityFailures.delete(accountId);
|
|
3531
|
+
}
|
|
3519
3532
|
onChanged(listener) {
|
|
3520
3533
|
this.listeners.add(listener);
|
|
3521
3534
|
return () => {
|
|
3522
3535
|
this.listeners.delete(listener);
|
|
3523
3536
|
};
|
|
3524
3537
|
}
|
|
3538
|
+
cachedIdentity(accountId) {
|
|
3539
|
+
const cached = this.identities.get(accountId);
|
|
3540
|
+
return cached && Date.now() - cached.at < IDENTITY_TTL ? cached.identity : void 0;
|
|
3541
|
+
}
|
|
3525
3542
|
capture(accountId) {
|
|
3526
3543
|
const selected = this.selection();
|
|
3527
3544
|
const target = accountId === void 0 ? selected.accountId : id(accountId);
|
|
@@ -3536,19 +3553,48 @@ var CopilotAccountsHost = class {
|
|
|
3536
3553
|
}
|
|
3537
3554
|
});
|
|
3538
3555
|
}
|
|
3539
|
-
|
|
3556
|
+
/** A frozen turn owns a record, not the mutable profile default. */
|
|
3557
|
+
captureAccount(accountId) {
|
|
3558
|
+
const target = id(accountId);
|
|
3559
|
+
if (this.disposed) fail("COPILOT_ACCOUNTS_DISPOSED");
|
|
3560
|
+
return Object.freeze({
|
|
3561
|
+
accountId: target,
|
|
3562
|
+
key: recordKey(target),
|
|
3563
|
+
generation: 0,
|
|
3564
|
+
assertCurrent: () => {
|
|
3565
|
+
if (this.disposed) fail("COPILOT_ACCOUNTS_DISPOSED");
|
|
3566
|
+
}
|
|
3567
|
+
});
|
|
3568
|
+
}
|
|
3569
|
+
async validateAccount(binding) {
|
|
3570
|
+
const blocked = this.routeDiagnostic(false);
|
|
3571
|
+
if (blocked) fail(blocked);
|
|
3572
|
+
if (!(await this.membership()).some((row) => row.id === binding.accountId && row.configured)) fail("COPILOT_ACCOUNTS_SELECTED_MISSING");
|
|
3573
|
+
binding.assertCurrent();
|
|
3574
|
+
}
|
|
3575
|
+
acquire(signal, requireManaged = true, accountId) {
|
|
3540
3576
|
if (this.operation !== void 0 || this.ctx.get("authorization")?.describe(recordKey("canonical"))?.inFlight === true) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3541
3577
|
if (signal?.aborted) fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3542
|
-
const binding = this.capture();
|
|
3578
|
+
const binding = accountId === void 0 ? this.capture() : this.captureAccount(accountId);
|
|
3543
3579
|
if (requireManaged && binding.accountId !== "canonical") {
|
|
3544
3580
|
const blocked = this.routeDiagnostic(false);
|
|
3545
3581
|
if (blocked) fail(blocked);
|
|
3546
3582
|
}
|
|
3583
|
+
let leases = this.leases;
|
|
3584
|
+
if (accountId !== void 0) {
|
|
3585
|
+
let pinned = this.accountLeases.get(accountId);
|
|
3586
|
+
if (!pinned) {
|
|
3587
|
+
pinned = /* @__PURE__ */ new Set();
|
|
3588
|
+
this.accountLeases.set(accountId, pinned);
|
|
3589
|
+
}
|
|
3590
|
+
leases = pinned;
|
|
3591
|
+
}
|
|
3547
3592
|
const release = () => {
|
|
3548
|
-
|
|
3593
|
+
leases.delete(release);
|
|
3594
|
+
if (accountId !== void 0 && leases.size === 0) this.accountLeases.delete(accountId);
|
|
3549
3595
|
signal?.removeEventListener("abort", release);
|
|
3550
3596
|
};
|
|
3551
|
-
|
|
3597
|
+
leases.add(release);
|
|
3552
3598
|
signal?.addEventListener("abort", release, { once: true });
|
|
3553
3599
|
return {
|
|
3554
3600
|
binding,
|
|
@@ -3556,7 +3602,7 @@ var CopilotAccountsHost = class {
|
|
|
3556
3602
|
};
|
|
3557
3603
|
}
|
|
3558
3604
|
acquireCanonicalAuthorization() {
|
|
3559
|
-
if (this.busy()) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3605
|
+
if (this.busy() || this.accountLeases.get("canonical")?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3560
3606
|
const binding = this.capture();
|
|
3561
3607
|
if (binding.accountId !== "canonical") fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3562
3608
|
this.operation = "authorizing";
|
|
@@ -3578,7 +3624,7 @@ var CopilotAccountsHost = class {
|
|
|
3578
3624
|
const evidence = migrationStatus(this.ctx);
|
|
3579
3625
|
if (!evidence.complete.routes || includeActivity && (!evidence.complete.sessions || !evidence.complete.defaultSelection) || !evidence.capabilities.settingsCas) return "COPILOT_ACCOUNTS_EVIDENCE_INCOMPLETE";
|
|
3580
3626
|
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";
|
|
3627
|
+
if (!this.ctx.get("githubCopilotSessionAccounts") && includeActivity && evidence.sessions.some((row) => row.status === "running" && row.effectiveSelection?.provider === "github-copilot-preview")) return "COPILOT_ACCOUNTS_BUSY";
|
|
3582
3628
|
}
|
|
3583
3629
|
busy() {
|
|
3584
3630
|
return this.leases.size > 0 || this.operation !== void 0 || this.ctx.get("authorization")?.describe(recordKey("canonical"))?.inFlight === true;
|
|
@@ -3616,23 +3662,26 @@ var CopilotAccountsHost = class {
|
|
|
3616
3662
|
return rows;
|
|
3617
3663
|
}
|
|
3618
3664
|
async get() {
|
|
3665
|
+
return this.accountView();
|
|
3666
|
+
}
|
|
3667
|
+
async accountView(accountId) {
|
|
3619
3668
|
let activeAccountId = "canonical", revision;
|
|
3620
3669
|
let accounts = [], writable = false;
|
|
3621
3670
|
let problem;
|
|
3622
3671
|
try {
|
|
3623
3672
|
const selection = this.selection();
|
|
3624
|
-
activeAccountId = selection.accountId;
|
|
3673
|
+
activeAccountId = accountId === void 0 ? selection.accountId : id(accountId);
|
|
3625
3674
|
revision = selection.revision;
|
|
3626
3675
|
writable = true;
|
|
3627
3676
|
accounts = await this.membership();
|
|
3628
3677
|
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);
|
|
3678
|
+
if (current.accountId !== selection.accountId || current.revision !== revision) fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3679
|
+
if ((accountId !== void 0 || activeAccountId !== "canonical") && !accounts.some((row) => row.id === activeAccountId && row.configured)) fail("COPILOT_ACCOUNTS_SELECTED_MISSING");
|
|
3680
|
+
problem = (accountId !== void 0 || this.lastFailure === "COPILOT_ACCOUNTS_BUSY" ? void 0 : this.lastFailure) ?? this.routeDiagnostic() ?? (this.busy() ? "COPILOT_ACCOUNTS_BUSY" : void 0);
|
|
3632
3681
|
} catch (error) {
|
|
3633
3682
|
problem = diagnostic(error, "COPILOT_ACCOUNTS_CREDENTIALS_UNAVAILABLE");
|
|
3634
3683
|
}
|
|
3635
|
-
if (this.lastFailure === "COPILOT_ACCOUNTS_COMMIT_UNCERTAIN") problem = this.lastFailure;
|
|
3684
|
+
if (accountId === void 0 && this.lastFailure === "COPILOT_ACCOUNTS_COMMIT_UNCERTAIN") problem = this.lastFailure;
|
|
3636
3685
|
const recovery = problem === "COPILOT_ACCOUNTS_SELECTED_MISSING" && writable && this.routeDiagnostic() === void 0;
|
|
3637
3686
|
return {
|
|
3638
3687
|
state: problem ? "error" : "ready",
|
|
@@ -3657,6 +3706,7 @@ var CopilotAccountsHost = class {
|
|
|
3657
3706
|
const latest = await store.read(GITHUB_COPILOT_PROVIDER_ID);
|
|
3658
3707
|
if (!latest || copilotAccountKey(normalizeGitHubCopilotOAuthCredential(latest)) !== before) fail("COPILOT_ACCOUNTS_CHANGED");
|
|
3659
3708
|
binding.assertCurrent();
|
|
3709
|
+
signal.throwIfAborted();
|
|
3660
3710
|
const previous = this.identities.get(binding.accountId);
|
|
3661
3711
|
if (previous && previous.identity.userId !== identity.userId) fail("COPILOT_ACCOUNTS_IDENTITY_CHANGED");
|
|
3662
3712
|
if (!this.identities.has(binding.accountId) && this.identities.size >= 32) this.identities.delete(this.identities.keys().next().value);
|
|
@@ -3669,6 +3719,23 @@ var CopilotAccountsHost = class {
|
|
|
3669
3719
|
return identity;
|
|
3670
3720
|
}
|
|
3671
3721
|
async fetchIdentity(grant, signal) {
|
|
3722
|
+
try {
|
|
3723
|
+
return await this.fetchIdentityResponse(grant, signal);
|
|
3724
|
+
} catch (error) {
|
|
3725
|
+
if (error instanceof AccountsFailure) throw error;
|
|
3726
|
+
if (signal.aborted) fail(signal.reason instanceof DOMException && signal.reason.name === "TimeoutError" ? "COPILOT_ACCOUNTS_IDENTITY_TIMEOUT" : "COPILOT_ACCOUNTS_CHANGED");
|
|
3727
|
+
const cause = object$4(error) ? error.cause : void 0;
|
|
3728
|
+
fail(object$4(cause) && typeof cause.code === "string" && [
|
|
3729
|
+
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
3730
|
+
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
3731
|
+
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
3732
|
+
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
3733
|
+
"CERT_HAS_EXPIRED",
|
|
3734
|
+
"ERR_TLS_CERT_ALTNAME_INVALID"
|
|
3735
|
+
].includes(cause.code) ? "COPILOT_ACCOUNTS_IDENTITY_TLS" : "COPILOT_ACCOUNTS_IDENTITY_NETWORK");
|
|
3736
|
+
}
|
|
3737
|
+
}
|
|
3738
|
+
async fetchIdentityResponse(grant, signal) {
|
|
3672
3739
|
if (grant.enterpriseUrl !== void 0) fail("COPILOT_ACCOUNTS_ENTERPRISE_UNSUPPORTED");
|
|
3673
3740
|
signal.throwIfAborted();
|
|
3674
3741
|
const response = await abortable$1((this.dependencies.fetch ?? globalThis.fetch)("https://api.github.com/user", {
|
|
@@ -3684,7 +3751,7 @@ var CopilotAccountsHost = class {
|
|
|
3684
3751
|
}), signal);
|
|
3685
3752
|
if (!response.ok || response.redirected || !response.body) {
|
|
3686
3753
|
response.body?.cancel().catch(() => void 0);
|
|
3687
|
-
fail("
|
|
3754
|
+
fail(response.status === 429 || response.status === 403 && (response.headers.get("x-ratelimit-remaining") === "0" || response.headers.has("retry-after")) ? "COPILOT_ACCOUNTS_IDENTITY_RATE_LIMITED" : response.status === 401 || response.status === 403 ? "COPILOT_ACCOUNTS_IDENTITY_AUTH_REJECTED" : "COPILOT_ACCOUNTS_IDENTITY_HTTP_ERROR");
|
|
3688
3755
|
}
|
|
3689
3756
|
const reader = response.body.getReader();
|
|
3690
3757
|
const chunks = [];
|
|
@@ -3695,7 +3762,7 @@ var CopilotAccountsHost = class {
|
|
|
3695
3762
|
signal.addEventListener("abort", cancel, { once: true });
|
|
3696
3763
|
try {
|
|
3697
3764
|
while (true) {
|
|
3698
|
-
|
|
3765
|
+
signal.throwIfAborted();
|
|
3699
3766
|
const chunk = await abortable$1(reader.read(), signal);
|
|
3700
3767
|
if (chunk.done) break;
|
|
3701
3768
|
bytes += chunk.value.byteLength;
|
|
@@ -3709,7 +3776,7 @@ var CopilotAccountsHost = class {
|
|
|
3709
3776
|
signal.removeEventListener("abort", cancel);
|
|
3710
3777
|
reader.releaseLock();
|
|
3711
3778
|
}
|
|
3712
|
-
|
|
3779
|
+
signal.throwIfAborted();
|
|
3713
3780
|
const buffer = new Uint8Array(bytes);
|
|
3714
3781
|
let offset = 0;
|
|
3715
3782
|
for (const chunk of chunks) {
|
|
@@ -3729,22 +3796,93 @@ var CopilotAccountsHost = class {
|
|
|
3729
3796
|
});
|
|
3730
3797
|
}
|
|
3731
3798
|
async refreshIdentity() {
|
|
3732
|
-
let lease;
|
|
3733
3799
|
try {
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3800
|
+
const view = await this.refreshIdentityFor(this.selection().accountId);
|
|
3801
|
+
if (view.state === "ready") this.lastFailure = void 0;
|
|
3802
|
+
return view;
|
|
3737
3803
|
} catch (error) {
|
|
3738
|
-
if (lease) {
|
|
3739
|
-
this.identities.delete(lease.binding.accountId);
|
|
3740
|
-
this.unavailableIdentities.add(lease.binding.accountId);
|
|
3741
|
-
}
|
|
3742
3804
|
this.lastFailure = diagnostic(error, "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE");
|
|
3743
|
-
} finally {
|
|
3744
|
-
lease?.release();
|
|
3745
3805
|
}
|
|
3746
3806
|
return this.get();
|
|
3747
3807
|
}
|
|
3808
|
+
async ensureIdentity() {
|
|
3809
|
+
try {
|
|
3810
|
+
return await this.ensureIdentityFor(this.selection().accountId);
|
|
3811
|
+
} catch (error) {
|
|
3812
|
+
return {
|
|
3813
|
+
...await this.get(),
|
|
3814
|
+
state: "error",
|
|
3815
|
+
switchable: false,
|
|
3816
|
+
diagnostic: diagnostic(error, "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE")
|
|
3817
|
+
};
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
async viewForAccount(accountId) {
|
|
3821
|
+
return this.accountView(accountId);
|
|
3822
|
+
}
|
|
3823
|
+
async refreshIdentityFor(accountId) {
|
|
3824
|
+
return this.readIdentity(accountId, true);
|
|
3825
|
+
}
|
|
3826
|
+
async ensureIdentityFor(accountId) {
|
|
3827
|
+
return this.readIdentity(accountId, false);
|
|
3828
|
+
}
|
|
3829
|
+
async readIdentity(accountId, force) {
|
|
3830
|
+
id(accountId);
|
|
3831
|
+
if (this.disposed) fail("COPILOT_ACCOUNTS_DISPOSED");
|
|
3832
|
+
let flight = this.identityFlights.get(accountId);
|
|
3833
|
+
let problem;
|
|
3834
|
+
const failed = this.identityFailures.get(accountId);
|
|
3835
|
+
if (flight === void 0 && !force && this.cachedIdentity(accountId)) return this.viewForAccount(accountId);
|
|
3836
|
+
if (flight === void 0 && !force && failed && Date.now() - failed.at < IDENTITY_FAILURE_COOLDOWN) problem = failed.diagnostic;
|
|
3837
|
+
else {
|
|
3838
|
+
if (flight === void 0) {
|
|
3839
|
+
if (this.identityFlights.size >= 32) fail("COPILOT_ACCOUNTS_LIMIT");
|
|
3840
|
+
const abort = new AbortController();
|
|
3841
|
+
const signal = AbortSignal.any([
|
|
3842
|
+
abort.signal,
|
|
3843
|
+
this.abort.signal,
|
|
3844
|
+
AbortSignal.timeout(TIMEOUT)
|
|
3845
|
+
]);
|
|
3846
|
+
flight = {
|
|
3847
|
+
abort,
|
|
3848
|
+
promise: Promise.resolve().then(async () => {
|
|
3849
|
+
let lease;
|
|
3850
|
+
try {
|
|
3851
|
+
signal.throwIfAborted();
|
|
3852
|
+
lease = this.acquire(void 0, false, accountId);
|
|
3853
|
+
await abortable$1(this.identity(lease.binding, signal), signal);
|
|
3854
|
+
this.identityFailures.delete(accountId);
|
|
3855
|
+
return;
|
|
3856
|
+
} catch (error) {
|
|
3857
|
+
const problem = signal.aborted ? signal.reason instanceof DOMException && signal.reason.name === "TimeoutError" ? "COPILOT_ACCOUNTS_IDENTITY_TIMEOUT" : "COPILOT_ACCOUNTS_CHANGED" : diagnostic(error, "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE");
|
|
3858
|
+
if (!abort.signal.aborted && !this.disposed) {
|
|
3859
|
+
this.identities.delete(accountId);
|
|
3860
|
+
this.unavailableIdentities.add(accountId);
|
|
3861
|
+
if (!this.identityFailures.has(accountId) && this.identityFailures.size >= 32) this.identityFailures.delete(this.identityFailures.keys().next().value);
|
|
3862
|
+
this.identityFailures.set(accountId, {
|
|
3863
|
+
at: Date.now(),
|
|
3864
|
+
diagnostic: problem
|
|
3865
|
+
});
|
|
3866
|
+
}
|
|
3867
|
+
return problem;
|
|
3868
|
+
} finally {
|
|
3869
|
+
lease?.release();
|
|
3870
|
+
if (this.identityFlights.get(accountId)?.abort === abort) this.identityFlights.delete(accountId);
|
|
3871
|
+
}
|
|
3872
|
+
})
|
|
3873
|
+
};
|
|
3874
|
+
this.identityFlights.set(accountId, flight);
|
|
3875
|
+
}
|
|
3876
|
+
problem = await flight.promise;
|
|
3877
|
+
}
|
|
3878
|
+
const view = await this.viewForAccount(accountId);
|
|
3879
|
+
return problem === void 0 ? view : {
|
|
3880
|
+
...view,
|
|
3881
|
+
state: "error",
|
|
3882
|
+
switchable: false,
|
|
3883
|
+
diagnostic: problem
|
|
3884
|
+
};
|
|
3885
|
+
}
|
|
3748
3886
|
async validateModels(binding, signal) {
|
|
3749
3887
|
try {
|
|
3750
3888
|
if (this.dependencies.validateModels) return await this.dependencies.validateModels(binding, signal);
|
|
@@ -3830,9 +3968,10 @@ var CopilotAccountsHost = class {
|
|
|
3830
3968
|
}
|
|
3831
3969
|
async authorize(accountId, expectedRevision) {
|
|
3832
3970
|
let removeFlow;
|
|
3833
|
-
let fenced = false;
|
|
3971
|
+
let fenced = false, rejectedBusy = false;
|
|
3834
3972
|
try {
|
|
3835
3973
|
id(accountId);
|
|
3974
|
+
if (this.accountLeases.get(accountId)?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3836
3975
|
if (accountId === "canonical") fail("COPILOT_ACCOUNTS_AUTH_UNAVAILABLE");
|
|
3837
3976
|
const assertRevision = () => {
|
|
3838
3977
|
if (expectedRevision !== void 0 && this.selection().revision !== expectedRevision) fail("COPILOT_ACCOUNTS_CONFLICT");
|
|
@@ -3969,13 +4108,20 @@ var CopilotAccountsHost = class {
|
|
|
3969
4108
|
} catch (error) {
|
|
3970
4109
|
removeFlow?.();
|
|
3971
4110
|
this.lastFailure = diagnostic(error, "COPILOT_ACCOUNTS_AUTH_FAILED");
|
|
4111
|
+
rejectedBusy = this.lastFailure === "COPILOT_ACCOUNTS_BUSY";
|
|
3972
4112
|
if (fenced) {
|
|
3973
4113
|
this.operation = void 0;
|
|
3974
4114
|
this.attemptKey = void 0;
|
|
3975
4115
|
this.authorizationAbort = void 0;
|
|
3976
4116
|
}
|
|
3977
4117
|
}
|
|
3978
|
-
|
|
4118
|
+
const view = await this.get();
|
|
4119
|
+
return rejectedBusy ? {
|
|
4120
|
+
...view,
|
|
4121
|
+
state: "error",
|
|
4122
|
+
switchable: false,
|
|
4123
|
+
diagnostic: "COPILOT_ACCOUNTS_BUSY"
|
|
4124
|
+
} : view;
|
|
3979
4125
|
}
|
|
3980
4126
|
async cancel() {
|
|
3981
4127
|
this.authorizationAbort?.abort();
|
|
@@ -3983,12 +4129,13 @@ var CopilotAccountsHost = class {
|
|
|
3983
4129
|
return this.get();
|
|
3984
4130
|
}
|
|
3985
4131
|
async remove(accountId, expectedRevision) {
|
|
3986
|
-
let fenced = false;
|
|
4132
|
+
let fenced = false, rejectedBusy = false;
|
|
3987
4133
|
try {
|
|
3988
4134
|
id(accountId);
|
|
3989
4135
|
const before = this.selection();
|
|
3990
4136
|
if (!Number.isSafeInteger(expectedRevision) || expectedRevision !== before.revision) fail("COPILOT_ACCOUNTS_CONFLICT");
|
|
3991
4137
|
if (accountId === "canonical" || accountId === before.accountId) fail("COPILOT_ACCOUNTS_ACTIVE_REMOVE_BLOCKED");
|
|
4138
|
+
if (this.accountLeases.get(accountId)?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3992
4139
|
if (this.busy()) fail("COPILOT_ACCOUNTS_BUSY");
|
|
3993
4140
|
this.operation = "switching";
|
|
3994
4141
|
fenced = true;
|
|
@@ -4003,14 +4150,22 @@ var CopilotAccountsHost = class {
|
|
|
4003
4150
|
this.lastFailure = void 0;
|
|
4004
4151
|
} catch (error) {
|
|
4005
4152
|
this.lastFailure = diagnostic(error, "COPILOT_ACCOUNTS_REMOVE_FAILED");
|
|
4153
|
+
rejectedBusy = this.lastFailure === "COPILOT_ACCOUNTS_BUSY";
|
|
4006
4154
|
} finally {
|
|
4007
4155
|
if (fenced) this.operation = void 0;
|
|
4008
4156
|
}
|
|
4009
|
-
|
|
4157
|
+
const view = await this.get();
|
|
4158
|
+
return rejectedBusy ? {
|
|
4159
|
+
...view,
|
|
4160
|
+
state: "error",
|
|
4161
|
+
switchable: false,
|
|
4162
|
+
diagnostic: "COPILOT_ACCOUNTS_BUSY"
|
|
4163
|
+
} : view;
|
|
4010
4164
|
}
|
|
4011
4165
|
async signOutActive() {
|
|
4012
4166
|
if (this.busy()) fail("COPILOT_ACCOUNTS_BUSY");
|
|
4013
4167
|
const binding = this.capture();
|
|
4168
|
+
if (this.accountLeases.get(binding.accountId)?.size) fail("COPILOT_ACCOUNTS_BUSY");
|
|
4014
4169
|
if (binding.accountId === "canonical") fail("COPILOT_ACCOUNTS_ACTIVE_REMOVE_BLOCKED");
|
|
4015
4170
|
this.operation = "switching";
|
|
4016
4171
|
try {
|
|
@@ -4028,7 +4183,9 @@ var CopilotAccountsHost = class {
|
|
|
4028
4183
|
this.authorizationAbort?.abort();
|
|
4029
4184
|
this.abort.abort();
|
|
4030
4185
|
this.revoke();
|
|
4186
|
+
this.identityFailures.clear();
|
|
4031
4187
|
for (const release of this.leases) release();
|
|
4188
|
+
for (const leases of this.accountLeases.values()) for (const release of leases) release();
|
|
4032
4189
|
this.listeners.clear();
|
|
4033
4190
|
}
|
|
4034
4191
|
};
|
|
@@ -4045,6 +4202,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4045
4202
|
let _instanceExtraInitializers = [];
|
|
4046
4203
|
let _get_decorators;
|
|
4047
4204
|
let _refreshIdentity_decorators;
|
|
4205
|
+
let _ensureIdentity_decorators;
|
|
4048
4206
|
let _add_decorators;
|
|
4049
4207
|
let _cancel_decorators;
|
|
4050
4208
|
let _reauthorize_decorators;
|
|
@@ -4055,12 +4213,13 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4055
4213
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
4056
4214
|
_get_decorators = [Remote];
|
|
4057
4215
|
_refreshIdentity_decorators = [Remote];
|
|
4216
|
+
_ensureIdentity_decorators = [Remote];
|
|
4058
4217
|
_add_decorators = [Remote];
|
|
4059
4218
|
_cancel_decorators = [Remote];
|
|
4060
4219
|
_reauthorize_decorators = [Remote];
|
|
4061
4220
|
_switchAccount_decorators = [Remote];
|
|
4062
4221
|
_removeAccount_decorators = [Remote];
|
|
4063
|
-
__esDecorate$
|
|
4222
|
+
__esDecorate$5(this, null, _get_decorators, {
|
|
4064
4223
|
kind: "method",
|
|
4065
4224
|
name: "get",
|
|
4066
4225
|
static: false,
|
|
@@ -4071,7 +4230,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4071
4230
|
},
|
|
4072
4231
|
metadata: _metadata
|
|
4073
4232
|
}, null, _instanceExtraInitializers);
|
|
4074
|
-
__esDecorate$
|
|
4233
|
+
__esDecorate$5(this, null, _refreshIdentity_decorators, {
|
|
4075
4234
|
kind: "method",
|
|
4076
4235
|
name: "refreshIdentity",
|
|
4077
4236
|
static: false,
|
|
@@ -4082,7 +4241,18 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4082
4241
|
},
|
|
4083
4242
|
metadata: _metadata
|
|
4084
4243
|
}, null, _instanceExtraInitializers);
|
|
4085
|
-
__esDecorate$
|
|
4244
|
+
__esDecorate$5(this, null, _ensureIdentity_decorators, {
|
|
4245
|
+
kind: "method",
|
|
4246
|
+
name: "ensureIdentity",
|
|
4247
|
+
static: false,
|
|
4248
|
+
private: false,
|
|
4249
|
+
access: {
|
|
4250
|
+
has: (obj) => "ensureIdentity" in obj,
|
|
4251
|
+
get: (obj) => obj.ensureIdentity
|
|
4252
|
+
},
|
|
4253
|
+
metadata: _metadata
|
|
4254
|
+
}, null, _instanceExtraInitializers);
|
|
4255
|
+
__esDecorate$5(this, null, _add_decorators, {
|
|
4086
4256
|
kind: "method",
|
|
4087
4257
|
name: "add",
|
|
4088
4258
|
static: false,
|
|
@@ -4093,7 +4263,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4093
4263
|
},
|
|
4094
4264
|
metadata: _metadata
|
|
4095
4265
|
}, null, _instanceExtraInitializers);
|
|
4096
|
-
__esDecorate$
|
|
4266
|
+
__esDecorate$5(this, null, _cancel_decorators, {
|
|
4097
4267
|
kind: "method",
|
|
4098
4268
|
name: "cancel",
|
|
4099
4269
|
static: false,
|
|
@@ -4104,7 +4274,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4104
4274
|
},
|
|
4105
4275
|
metadata: _metadata
|
|
4106
4276
|
}, null, _instanceExtraInitializers);
|
|
4107
|
-
__esDecorate$
|
|
4277
|
+
__esDecorate$5(this, null, _reauthorize_decorators, {
|
|
4108
4278
|
kind: "method",
|
|
4109
4279
|
name: "reauthorize",
|
|
4110
4280
|
static: false,
|
|
@@ -4115,7 +4285,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4115
4285
|
},
|
|
4116
4286
|
metadata: _metadata
|
|
4117
4287
|
}, null, _instanceExtraInitializers);
|
|
4118
|
-
__esDecorate$
|
|
4288
|
+
__esDecorate$5(this, null, _switchAccount_decorators, {
|
|
4119
4289
|
kind: "method",
|
|
4120
4290
|
name: "switchAccount",
|
|
4121
4291
|
static: false,
|
|
@@ -4126,7 +4296,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4126
4296
|
},
|
|
4127
4297
|
metadata: _metadata
|
|
4128
4298
|
}, null, _instanceExtraInitializers);
|
|
4129
|
-
__esDecorate$
|
|
4299
|
+
__esDecorate$5(this, null, _removeAccount_decorators, {
|
|
4130
4300
|
kind: "method",
|
|
4131
4301
|
name: "removeAccount",
|
|
4132
4302
|
static: false,
|
|
@@ -4144,7 +4314,7 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4144
4314
|
value: _metadata
|
|
4145
4315
|
});
|
|
4146
4316
|
}
|
|
4147
|
-
host = __runInitializers$
|
|
4317
|
+
host = __runInitializers$5(this, _instanceExtraInitializers);
|
|
4148
4318
|
constructor(ctx) {
|
|
4149
4319
|
super(ctx, "githubCopilotAccounts");
|
|
4150
4320
|
this.host = new CopilotAccountsHost(ctx);
|
|
@@ -4160,6 +4330,9 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4160
4330
|
refreshIdentity() {
|
|
4161
4331
|
return this.host.refreshIdentity();
|
|
4162
4332
|
}
|
|
4333
|
+
ensureIdentity() {
|
|
4334
|
+
return this.host.ensureIdentity();
|
|
4335
|
+
}
|
|
4163
4336
|
add() {
|
|
4164
4337
|
return this.host.add();
|
|
4165
4338
|
}
|
|
@@ -4179,12 +4352,12 @@ let GitHubCopilotAccountsController = (() => {
|
|
|
4179
4352
|
})();
|
|
4180
4353
|
//#endregion
|
|
4181
4354
|
//#region lib/types/copilot-usage-host.js
|
|
4182
|
-
var __runInitializers$
|
|
4355
|
+
var __runInitializers$4 = function(thisArg, initializers, value) {
|
|
4183
4356
|
var useValue = arguments.length > 2;
|
|
4184
4357
|
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
4185
4358
|
return useValue ? value : void 0;
|
|
4186
4359
|
};
|
|
4187
|
-
var __esDecorate$
|
|
4360
|
+
var __esDecorate$4 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
4188
4361
|
function accept(f) {
|
|
4189
4362
|
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
4190
4363
|
return f;
|
|
@@ -4528,7 +4701,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4528
4701
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
4529
4702
|
_get_decorators = [Remote];
|
|
4530
4703
|
_refresh_decorators = [Remote];
|
|
4531
|
-
__esDecorate$
|
|
4704
|
+
__esDecorate$4(this, null, _get_decorators, {
|
|
4532
4705
|
kind: "method",
|
|
4533
4706
|
name: "get",
|
|
4534
4707
|
static: false,
|
|
@@ -4539,7 +4712,7 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4539
4712
|
},
|
|
4540
4713
|
metadata: _metadata
|
|
4541
4714
|
}, null, _instanceExtraInitializers);
|
|
4542
|
-
__esDecorate$
|
|
4715
|
+
__esDecorate$4(this, null, _refresh_decorators, {
|
|
4543
4716
|
kind: "method",
|
|
4544
4717
|
name: "refresh",
|
|
4545
4718
|
static: false,
|
|
@@ -4557,7 +4730,8 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4557
4730
|
value: _metadata
|
|
4558
4731
|
});
|
|
4559
4732
|
}
|
|
4560
|
-
|
|
4733
|
+
accountSources = (__runInitializers$4(this, _instanceExtraInitializers), /* @__PURE__ */ new Map());
|
|
4734
|
+
source;
|
|
4561
4735
|
accountSignature;
|
|
4562
4736
|
sourceInitialized = false;
|
|
4563
4737
|
constructor(ctx) {
|
|
@@ -4567,11 +4741,30 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4567
4741
|
} });
|
|
4568
4742
|
ctx.on("credentials/record-updated", (key) => {
|
|
4569
4743
|
if (isActiveCopilotRecord(ctx, key)) this.source.invalidate();
|
|
4744
|
+
this.accountSources.get(key)?.invalidate();
|
|
4570
4745
|
});
|
|
4571
4746
|
onSettingsNamespaceUpdated(ctx, (namespace) => {
|
|
4572
4747
|
if (namespace === "github-copilot" || namespace === "llm-pi-ai") this.source.invalidate();
|
|
4573
4748
|
});
|
|
4574
|
-
ctx.effect(() => () =>
|
|
4749
|
+
ctx.effect(() => async () => {
|
|
4750
|
+
await this.source.dispose();
|
|
4751
|
+
await Promise.all([...this.accountSources.values()].map((source) => source.dispose()));
|
|
4752
|
+
this.accountSources.clear();
|
|
4753
|
+
});
|
|
4754
|
+
}
|
|
4755
|
+
forAccount(binding, force = false) {
|
|
4756
|
+
binding.assertCurrent();
|
|
4757
|
+
let source = this.accountSources.get(binding.key);
|
|
4758
|
+
if (!source) {
|
|
4759
|
+
if (this.accountSources.size >= 32) throw new Error("COPILOT_SESSION_ACCOUNTS_LIMIT");
|
|
4760
|
+
const credentials = createGitHubCopilotCredentialStore(this.ctx, GITHUB_COPILOT_PROVIDER_ID, binding);
|
|
4761
|
+
source = new CopilotUsageSource({
|
|
4762
|
+
accountId: binding.accountId,
|
|
4763
|
+
readCredential: () => credentials.read(GITHUB_COPILOT_PROVIDER_ID)
|
|
4764
|
+
});
|
|
4765
|
+
this.accountSources.set(binding.key, source);
|
|
4766
|
+
}
|
|
4767
|
+
return force ? source.refresh() : source.get();
|
|
4575
4768
|
}
|
|
4576
4769
|
createSource() {
|
|
4577
4770
|
const binding = activeCopilotBinding(this.ctx);
|
|
@@ -4608,6 +4801,421 @@ let GitHubCopilotUsageController = (() => {
|
|
|
4608
4801
|
}
|
|
4609
4802
|
};
|
|
4610
4803
|
})();
|
|
4804
|
+
function invalid() {
|
|
4805
|
+
throw new Error("COPILOT_SESSION_ACCOUNTS_INVALID");
|
|
4806
|
+
}
|
|
4807
|
+
function parseSessionAccounts(value) {
|
|
4808
|
+
if (value === void 0) return [];
|
|
4809
|
+
if (!Array.isArray(value) || value.length > 2048) invalid();
|
|
4810
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4811
|
+
return value.map((row) => {
|
|
4812
|
+
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();
|
|
4813
|
+
seen.add(row.sessionId);
|
|
4814
|
+
return Object.freeze({
|
|
4815
|
+
sessionId: row.sessionId,
|
|
4816
|
+
accountId: row.accountId
|
|
4817
|
+
});
|
|
4818
|
+
});
|
|
4819
|
+
}
|
|
4820
|
+
function resolveSessionAccount(sessionId, preferences, globalAccountId) {
|
|
4821
|
+
if (!COPILOT_ACCOUNT_ID_PATTERN.test(globalAccountId)) invalid();
|
|
4822
|
+
const explicit = preferences.find((row) => row.sessionId === sessionId);
|
|
4823
|
+
return Object.freeze({
|
|
4824
|
+
accountId: explicit?.accountId ?? globalAccountId,
|
|
4825
|
+
source: explicit ? "session" : "global"
|
|
4826
|
+
});
|
|
4827
|
+
}
|
|
4828
|
+
/** Active turns are never evicted; bounded historical evidence may become unknown. */
|
|
4829
|
+
var SessionAccountTurns = class {
|
|
4830
|
+
active = /* @__PURE__ */ new Map();
|
|
4831
|
+
signals = /* @__PURE__ */ new WeakMap();
|
|
4832
|
+
history = /* @__PURE__ */ new Map();
|
|
4833
|
+
admit(agent, turn, signal, selection) {
|
|
4834
|
+
if (!Number.isSafeInteger(turn) || turn < 0 || signal.aborted) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_INVALID");
|
|
4835
|
+
const previous = this.active.get(agent);
|
|
4836
|
+
if (previous) {
|
|
4837
|
+
if (previous.turn !== turn) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_UNSETTLED");
|
|
4838
|
+
if (previous.signal !== signal) throw new Error("COPILOT_SESSION_ACCOUNT_SIGNAL_CHANGED");
|
|
4839
|
+
return previous;
|
|
4840
|
+
}
|
|
4841
|
+
const bound = this.signals.get(signal);
|
|
4842
|
+
if (bound && bound.agent !== agent) throw new Error("COPILOT_SESSION_ACCOUNT_SIGNAL_CHANGED");
|
|
4843
|
+
const admission = Object.freeze({
|
|
4844
|
+
...selection,
|
|
4845
|
+
turn,
|
|
4846
|
+
signal
|
|
4847
|
+
});
|
|
4848
|
+
this.active.set(agent, admission);
|
|
4849
|
+
this.signals.set(signal, {
|
|
4850
|
+
agent,
|
|
4851
|
+
admission
|
|
4852
|
+
});
|
|
4853
|
+
return admission;
|
|
4854
|
+
}
|
|
4855
|
+
record(agent, turn, identity) {
|
|
4856
|
+
const admission = this.active.get(agent);
|
|
4857
|
+
if (!admission || admission.turn !== turn) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_INVALID");
|
|
4858
|
+
let turns = this.history.get(agent);
|
|
4859
|
+
if (!turns) {
|
|
4860
|
+
turns = /* @__PURE__ */ new Map();
|
|
4861
|
+
this.history.set(agent, turns);
|
|
4862
|
+
if (this.history.size > 64) this.history.delete(this.history.keys().next().value);
|
|
4863
|
+
}
|
|
4864
|
+
if (!turns.has(turn)) turns.set(turn, Object.freeze({
|
|
4865
|
+
accountId: admission.accountId,
|
|
4866
|
+
source: admission.source,
|
|
4867
|
+
...identity ? { identity: Object.freeze({ ...identity }) } : {}
|
|
4868
|
+
}));
|
|
4869
|
+
if (turns.size > 128) turns.delete(turns.keys().next().value);
|
|
4870
|
+
}
|
|
4871
|
+
current(agent) {
|
|
4872
|
+
return this.active.get(agent);
|
|
4873
|
+
}
|
|
4874
|
+
forSignal(signal) {
|
|
4875
|
+
const entry = this.signals.get(signal);
|
|
4876
|
+
return entry && this.active.get(entry.agent) === entry.admission ? entry.admission : void 0;
|
|
4877
|
+
}
|
|
4878
|
+
evidence(agent, turn) {
|
|
4879
|
+
return this.history.get(agent)?.get(turn);
|
|
4880
|
+
}
|
|
4881
|
+
end(agent, turn) {
|
|
4882
|
+
const admission = this.active.get(agent);
|
|
4883
|
+
if (admission?.turn !== turn) return;
|
|
4884
|
+
this.signals.delete(admission.signal);
|
|
4885
|
+
this.active.delete(agent);
|
|
4886
|
+
}
|
|
4887
|
+
remove(agent) {
|
|
4888
|
+
const admission = this.active.get(agent);
|
|
4889
|
+
if (admission) this.signals.delete(admission.signal);
|
|
4890
|
+
this.active.delete(agent);
|
|
4891
|
+
this.history.delete(agent);
|
|
4892
|
+
}
|
|
4893
|
+
clear() {
|
|
4894
|
+
for (const admission of this.active.values()) this.signals.delete(admission.signal);
|
|
4895
|
+
this.active.clear();
|
|
4896
|
+
this.history.clear();
|
|
4897
|
+
}
|
|
4898
|
+
recordSignal(signal, identity) {
|
|
4899
|
+
const entry = this.signals.get(signal);
|
|
4900
|
+
if (entry && this.active.get(entry.agent) === entry.admission) this.record(entry.agent, entry.admission.turn, identity);
|
|
4901
|
+
}
|
|
4902
|
+
};
|
|
4903
|
+
//#endregion
|
|
4904
|
+
//#region lib/types/session-accounts-host.js
|
|
4905
|
+
/** Host-only routing owner; credentials remain in the existing account service. */
|
|
4906
|
+
var SessionAccountsHost = class {
|
|
4907
|
+
ctx;
|
|
4908
|
+
turns = new SessionAccountTurns();
|
|
4909
|
+
leases = /* @__PURE__ */ new Map();
|
|
4910
|
+
constructor(ctx) {
|
|
4911
|
+
this.ctx = ctx;
|
|
4912
|
+
}
|
|
4913
|
+
selected(agent) {
|
|
4914
|
+
const settings = readSettingsNamespace(this.ctx, "github-copilot");
|
|
4915
|
+
if (typeof settings !== "object" || settings === null) throw new Error("COPILOT_SESSION_ACCOUNTS_SETTINGS_UNAVAILABLE");
|
|
4916
|
+
const preferences = parseSessionAccounts("sessionAccounts" in settings ? settings.sessionAccounts : void 0);
|
|
4917
|
+
const global = this.ctx.get("githubCopilotAccounts")?.host.capture().accountId;
|
|
4918
|
+
if (!global) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4919
|
+
return resolveSessionAccount(agent.session.id, preferences, global);
|
|
4920
|
+
}
|
|
4921
|
+
admit(agent, turn, signal) {
|
|
4922
|
+
const existing = this.turns.current(agent.session);
|
|
4923
|
+
const selected = existing ?? this.selected(agent);
|
|
4924
|
+
if (existing) {
|
|
4925
|
+
const admission = this.turns.admit(agent.session, turn, signal, selected);
|
|
4926
|
+
return this.bindingForAccount(admission.accountId);
|
|
4927
|
+
}
|
|
4928
|
+
if (this.leases.size >= 2048) throw new Error("COPILOT_SESSION_ACCOUNTS_LIMIT");
|
|
4929
|
+
const lease = this.ctx.get("githubCopilotAccounts")?.host.acquire(void 0, true, selected.accountId);
|
|
4930
|
+
if (!lease) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4931
|
+
try {
|
|
4932
|
+
this.turns.admit(agent.session, turn, signal, selected);
|
|
4933
|
+
this.leases.set(agent.session, lease);
|
|
4934
|
+
return lease.binding;
|
|
4935
|
+
} catch (error) {
|
|
4936
|
+
lease.release();
|
|
4937
|
+
throw error;
|
|
4938
|
+
}
|
|
4939
|
+
}
|
|
4940
|
+
end(session, turn) {
|
|
4941
|
+
if (this.turns.current(session)?.turn !== turn) return;
|
|
4942
|
+
this.leases.get(session)?.release();
|
|
4943
|
+
this.leases.delete(session);
|
|
4944
|
+
this.turns.end(session, turn);
|
|
4945
|
+
}
|
|
4946
|
+
remove(session) {
|
|
4947
|
+
this.leases.get(session)?.release();
|
|
4948
|
+
this.leases.delete(session);
|
|
4949
|
+
this.turns.remove(session);
|
|
4950
|
+
}
|
|
4951
|
+
dispose() {
|
|
4952
|
+
for (const lease of this.leases.values()) lease.release();
|
|
4953
|
+
this.leases.clear();
|
|
4954
|
+
this.turns.clear();
|
|
4955
|
+
}
|
|
4956
|
+
bindingForAccount(accountId) {
|
|
4957
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
4958
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4959
|
+
return accounts.host.captureAccount(accountId);
|
|
4960
|
+
}
|
|
4961
|
+
recordRequest(signal) {
|
|
4962
|
+
const admission = signal === void 0 ? void 0 : this.turns.forSignal(signal);
|
|
4963
|
+
if (admission && signal) this.turns.recordSignal(signal, this.ctx.get("githubCopilotAccounts")?.host.cachedIdentity(admission.accountId));
|
|
4964
|
+
}
|
|
4965
|
+
requestBinding(signal) {
|
|
4966
|
+
const exact = signal === void 0 ? void 0 : this.turns.forSignal(signal);
|
|
4967
|
+
if (exact) return this.bindingForAccount(exact.accountId);
|
|
4968
|
+
const agents = this.ctx.get("agents");
|
|
4969
|
+
const agent = typeof agents?.currentInitiator === "function" ? agents.currentInitiator() : void 0;
|
|
4970
|
+
if (agent) {
|
|
4971
|
+
const admitted = this.turns.current(agent.session);
|
|
4972
|
+
if (admitted) return this.bindingForAccount(admitted.accountId);
|
|
4973
|
+
return this.bindingForAccount(this.selected(agent).accountId);
|
|
4974
|
+
}
|
|
4975
|
+
const binding = this.ctx.get("githubCopilotAccounts")?.host.capture();
|
|
4976
|
+
if (!binding) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4977
|
+
return this.bindingForAccount(binding.accountId);
|
|
4978
|
+
}
|
|
4979
|
+
async set(agent, accountId, revision) {
|
|
4980
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
4981
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
4982
|
+
if (accountId !== null) {
|
|
4983
|
+
const binding = this.bindingForAccount(accountId);
|
|
4984
|
+
await accounts.host.validateAccount(binding);
|
|
4985
|
+
}
|
|
4986
|
+
const settings = this.ctx.get("settings");
|
|
4987
|
+
if (!settings) throw new Error("COPILOT_SESSION_ACCOUNTS_SETTINGS_UNAVAILABLE");
|
|
4988
|
+
const descriptor = settings.describe({ redactSecrets: true }).find((row) => row.ns === "github-copilot");
|
|
4989
|
+
if (!descriptor || descriptor.revision !== revision) throw new Error("COPILOT_ACCOUNTS_CONFLICT");
|
|
4990
|
+
const value = descriptor.value;
|
|
4991
|
+
const next = parseSessionAccounts(typeof value === "object" && value !== null && "sessionAccounts" in value ? value.sessionAccounts : void 0).filter((row) => row.sessionId !== agent.session.id);
|
|
4992
|
+
if (accountId !== null) next.push({
|
|
4993
|
+
sessionId: agent.session.id,
|
|
4994
|
+
accountId
|
|
4995
|
+
});
|
|
4996
|
+
if (next.length > 2048) throw new Error("COPILOT_SESSION_ACCOUNTS_LIMIT");
|
|
4997
|
+
await settings.mutate("github-copilot", [{
|
|
4998
|
+
op: "set",
|
|
4999
|
+
path: ["sessionAccounts"],
|
|
5000
|
+
value: next
|
|
5001
|
+
}], revision);
|
|
5002
|
+
const actual = this.selected(agent);
|
|
5003
|
+
if (actual.source !== (accountId === null ? "global" : "session") || accountId !== null && actual.accountId !== accountId) throw new Error("COPILOT_SESSION_ACCOUNTS_COMMIT_UNCERTAIN");
|
|
5004
|
+
}
|
|
5005
|
+
};
|
|
5006
|
+
//#endregion
|
|
5007
|
+
//#region lib/types/session-accounts-controller.js
|
|
5008
|
+
var __runInitializers$3 = function(thisArg, initializers, value) {
|
|
5009
|
+
var useValue = arguments.length > 2;
|
|
5010
|
+
for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5011
|
+
return useValue ? value : void 0;
|
|
5012
|
+
};
|
|
5013
|
+
var __esDecorate$3 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
5014
|
+
function accept(f) {
|
|
5015
|
+
if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
|
|
5016
|
+
return f;
|
|
5017
|
+
}
|
|
5018
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5019
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5020
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
5021
|
+
var _, done = false;
|
|
5022
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
5023
|
+
var context = {};
|
|
5024
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
5025
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
5026
|
+
context.addInitializer = function(f) {
|
|
5027
|
+
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
5028
|
+
extraInitializers.push(accept(f || null));
|
|
5029
|
+
};
|
|
5030
|
+
var result = (0, decorators[i])(kind === "accessor" ? {
|
|
5031
|
+
get: descriptor.get,
|
|
5032
|
+
set: descriptor.set
|
|
5033
|
+
} : descriptor[key], context);
|
|
5034
|
+
if (kind === "accessor") {
|
|
5035
|
+
if (result === void 0) continue;
|
|
5036
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
5037
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
5038
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
5039
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
5040
|
+
} else if (_ = accept(result)) {
|
|
5041
|
+
if (kind === "field") initializers.unshift(_);
|
|
5042
|
+
else descriptor[key] = _;
|
|
5043
|
+
}
|
|
5044
|
+
}
|
|
5045
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
5046
|
+
done = true;
|
|
5047
|
+
};
|
|
5048
|
+
let SessionAccountController = (() => {
|
|
5049
|
+
let _classSuper = TypertRemoteService;
|
|
5050
|
+
let _instanceExtraInitializers = [];
|
|
5051
|
+
let _get_decorators;
|
|
5052
|
+
let _set_decorators;
|
|
5053
|
+
let _refreshIdentity_decorators;
|
|
5054
|
+
let _ensureIdentity_decorators;
|
|
5055
|
+
let _usage_decorators;
|
|
5056
|
+
let _refreshUsage_decorators;
|
|
5057
|
+
let _turn_decorators;
|
|
5058
|
+
return class SessionAccountController extends _classSuper {
|
|
5059
|
+
static {
|
|
5060
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
5061
|
+
_get_decorators = [Remote];
|
|
5062
|
+
_set_decorators = [Remote];
|
|
5063
|
+
_refreshIdentity_decorators = [Remote];
|
|
5064
|
+
_ensureIdentity_decorators = [Remote];
|
|
5065
|
+
_usage_decorators = [Remote];
|
|
5066
|
+
_refreshUsage_decorators = [Remote];
|
|
5067
|
+
_turn_decorators = [Remote];
|
|
5068
|
+
__esDecorate$3(this, null, _get_decorators, {
|
|
5069
|
+
kind: "method",
|
|
5070
|
+
name: "get",
|
|
5071
|
+
static: false,
|
|
5072
|
+
private: false,
|
|
5073
|
+
access: {
|
|
5074
|
+
has: (obj) => "get" in obj,
|
|
5075
|
+
get: (obj) => obj.get
|
|
5076
|
+
},
|
|
5077
|
+
metadata: _metadata
|
|
5078
|
+
}, null, _instanceExtraInitializers);
|
|
5079
|
+
__esDecorate$3(this, null, _set_decorators, {
|
|
5080
|
+
kind: "method",
|
|
5081
|
+
name: "set",
|
|
5082
|
+
static: false,
|
|
5083
|
+
private: false,
|
|
5084
|
+
access: {
|
|
5085
|
+
has: (obj) => "set" in obj,
|
|
5086
|
+
get: (obj) => obj.set
|
|
5087
|
+
},
|
|
5088
|
+
metadata: _metadata
|
|
5089
|
+
}, null, _instanceExtraInitializers);
|
|
5090
|
+
__esDecorate$3(this, null, _refreshIdentity_decorators, {
|
|
5091
|
+
kind: "method",
|
|
5092
|
+
name: "refreshIdentity",
|
|
5093
|
+
static: false,
|
|
5094
|
+
private: false,
|
|
5095
|
+
access: {
|
|
5096
|
+
has: (obj) => "refreshIdentity" in obj,
|
|
5097
|
+
get: (obj) => obj.refreshIdentity
|
|
5098
|
+
},
|
|
5099
|
+
metadata: _metadata
|
|
5100
|
+
}, null, _instanceExtraInitializers);
|
|
5101
|
+
__esDecorate$3(this, null, _ensureIdentity_decorators, {
|
|
5102
|
+
kind: "method",
|
|
5103
|
+
name: "ensureIdentity",
|
|
5104
|
+
static: false,
|
|
5105
|
+
private: false,
|
|
5106
|
+
access: {
|
|
5107
|
+
has: (obj) => "ensureIdentity" in obj,
|
|
5108
|
+
get: (obj) => obj.ensureIdentity
|
|
5109
|
+
},
|
|
5110
|
+
metadata: _metadata
|
|
5111
|
+
}, null, _instanceExtraInitializers);
|
|
5112
|
+
__esDecorate$3(this, null, _usage_decorators, {
|
|
5113
|
+
kind: "method",
|
|
5114
|
+
name: "usage",
|
|
5115
|
+
static: false,
|
|
5116
|
+
private: false,
|
|
5117
|
+
access: {
|
|
5118
|
+
has: (obj) => "usage" in obj,
|
|
5119
|
+
get: (obj) => obj.usage
|
|
5120
|
+
},
|
|
5121
|
+
metadata: _metadata
|
|
5122
|
+
}, null, _instanceExtraInitializers);
|
|
5123
|
+
__esDecorate$3(this, null, _refreshUsage_decorators, {
|
|
5124
|
+
kind: "method",
|
|
5125
|
+
name: "refreshUsage",
|
|
5126
|
+
static: false,
|
|
5127
|
+
private: false,
|
|
5128
|
+
access: {
|
|
5129
|
+
has: (obj) => "refreshUsage" in obj,
|
|
5130
|
+
get: (obj) => obj.refreshUsage
|
|
5131
|
+
},
|
|
5132
|
+
metadata: _metadata
|
|
5133
|
+
}, null, _instanceExtraInitializers);
|
|
5134
|
+
__esDecorate$3(this, null, _turn_decorators, {
|
|
5135
|
+
kind: "method",
|
|
5136
|
+
name: "turn",
|
|
5137
|
+
static: false,
|
|
5138
|
+
private: false,
|
|
5139
|
+
access: {
|
|
5140
|
+
has: (obj) => "turn" in obj,
|
|
5141
|
+
get: (obj) => obj.turn
|
|
5142
|
+
},
|
|
5143
|
+
metadata: _metadata
|
|
5144
|
+
}, null, _instanceExtraInitializers);
|
|
5145
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
5146
|
+
enumerable: true,
|
|
5147
|
+
configurable: true,
|
|
5148
|
+
writable: true,
|
|
5149
|
+
value: _metadata
|
|
5150
|
+
});
|
|
5151
|
+
}
|
|
5152
|
+
owner = __runInitializers$3(this, _instanceExtraInitializers);
|
|
5153
|
+
constructor(ctx, owner) {
|
|
5154
|
+
super(ctx, "githubCopilotSessionAccount");
|
|
5155
|
+
this.owner = owner;
|
|
5156
|
+
}
|
|
5157
|
+
async get(agent) {
|
|
5158
|
+
const selected = this.owner.selected(agent);
|
|
5159
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
5160
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
5161
|
+
const view = await accounts.host.viewForAccount(selected.accountId);
|
|
5162
|
+
const latest = this.owner.selected(agent);
|
|
5163
|
+
if (latest.accountId !== selected.accountId || latest.source !== selected.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
|
|
5164
|
+
const running = this.owner.turns.current(agent.session);
|
|
5165
|
+
return {
|
|
5166
|
+
...selected,
|
|
5167
|
+
globalAccountId: accounts.host.capture().accountId,
|
|
5168
|
+
accounts: view,
|
|
5169
|
+
...running ? { runningAccountId: running.accountId } : {}
|
|
5170
|
+
};
|
|
5171
|
+
}
|
|
5172
|
+
async set(agent, accountId, revision) {
|
|
5173
|
+
await this.owner.set(agent, accountId, revision);
|
|
5174
|
+
return this.get(agent);
|
|
5175
|
+
}
|
|
5176
|
+
async refreshIdentity(agent) {
|
|
5177
|
+
return this.readIdentity(agent, true);
|
|
5178
|
+
}
|
|
5179
|
+
async ensureIdentity(agent) {
|
|
5180
|
+
return this.readIdentity(agent, false);
|
|
5181
|
+
}
|
|
5182
|
+
async readIdentity(agent, force) {
|
|
5183
|
+
const selected = this.owner.selected(agent);
|
|
5184
|
+
const accounts = this.ctx.get("githubCopilotAccounts");
|
|
5185
|
+
if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
|
|
5186
|
+
const identity = await (force ? accounts.host.refreshIdentityFor(selected.accountId) : accounts.host.ensureIdentityFor(selected.accountId));
|
|
5187
|
+
const latest = await this.get(agent);
|
|
5188
|
+
if (latest.accountId !== selected.accountId || latest.source !== selected.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
|
|
5189
|
+
return {
|
|
5190
|
+
...latest,
|
|
5191
|
+
accounts: identity
|
|
5192
|
+
};
|
|
5193
|
+
}
|
|
5194
|
+
async readUsage(agent, force) {
|
|
5195
|
+
const selection = this.owner.selected(agent);
|
|
5196
|
+
const service = this.ctx.get("githubCopilotUsage");
|
|
5197
|
+
if (!service) throw new Error("COPILOT_USAGE_REMOTE_UNAVAILABLE");
|
|
5198
|
+
const result = await service.forAccount(this.owner.bindingForAccount(selection.accountId), force);
|
|
5199
|
+
const current = this.owner.selected(agent);
|
|
5200
|
+
if (current.accountId !== selection.accountId || current.source !== selection.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
|
|
5201
|
+
return result;
|
|
5202
|
+
}
|
|
5203
|
+
usage(agent) {
|
|
5204
|
+
return this.readUsage(agent, false);
|
|
5205
|
+
}
|
|
5206
|
+
refreshUsage(agent) {
|
|
5207
|
+
return this.readUsage(agent, true);
|
|
5208
|
+
}
|
|
5209
|
+
turn(agent, turn) {
|
|
5210
|
+
if (!Number.isSafeInteger(turn) || turn < 0) throw new Error("COPILOT_SESSION_ACCOUNT_TURN_INVALID");
|
|
5211
|
+
const evidence = this.owner.turns.evidence(agent.session, turn);
|
|
5212
|
+
return evidence ? {
|
|
5213
|
+
state: "recorded",
|
|
5214
|
+
...evidence
|
|
5215
|
+
} : { state: "unknown" };
|
|
5216
|
+
}
|
|
5217
|
+
};
|
|
5218
|
+
})();
|
|
4611
5219
|
//#endregion
|
|
4612
5220
|
//#region lib/types/context-usage.js
|
|
4613
5221
|
/** All observed counters are zero, not proof that an attempted prompt was empty. */
|
|
@@ -5126,9 +5734,14 @@ const WebSearchRoutingConfigSchema = z.object({
|
|
|
5126
5734
|
function readInlineConfig(config) {
|
|
5127
5735
|
const exclusions = readConfigValue(config.excludedModelIds);
|
|
5128
5736
|
const bindings = readConfigValue(config.parentModelFollow);
|
|
5737
|
+
const accounts = readConfigValue(config.sessionAccounts);
|
|
5129
5738
|
return {
|
|
5130
5739
|
...config,
|
|
5131
5740
|
activeAccountId: readConfigValue(config.activeAccountId),
|
|
5741
|
+
sessionAccounts: accounts === void 0 ? void 0 : Array.from(accounts, (account) => ({
|
|
5742
|
+
sessionId: account.sessionId,
|
|
5743
|
+
accountId: account.accountId
|
|
5744
|
+
})),
|
|
5132
5745
|
excludedModelIds: exclusions === void 0 ? void 0 : Array.from(exclusions),
|
|
5133
5746
|
parentModelFollow: bindings === void 0 ? void 0 : Array.from(bindings, (binding) => ({
|
|
5134
5747
|
childSessionId: binding.childSessionId,
|
|
@@ -5158,6 +5771,10 @@ const Config = z.object({
|
|
|
5158
5771
|
accountModelFailureCooldownMs: z.number().step(1).min(0).max(MAX_TIMEOUT_MS).default(3e5),
|
|
5159
5772
|
excludedModelIds: z.array(z.string()).default([]).hidden().volatile(),
|
|
5160
5773
|
activeAccountId: z.string().hidden().volatile(),
|
|
5774
|
+
sessionAccounts: z.array(z.object({
|
|
5775
|
+
sessionId: z.string().min(1).max(256),
|
|
5776
|
+
accountId: z.string().min(1).max(36)
|
|
5777
|
+
})).default([]).hidden().volatile(),
|
|
5161
5778
|
followParentModel: z.boolean().default(false).volatile(),
|
|
5162
5779
|
autoSemanticAssessment: z.boolean().default(true),
|
|
5163
5780
|
parentModelFollow: z.array(z.object({
|
|
@@ -8341,15 +8958,15 @@ let ReplayRecoveryController = (() => {
|
|
|
8341
8958
|
this.busy = busy;
|
|
8342
8959
|
}
|
|
8343
8960
|
get(agent) {
|
|
8344
|
-
return this.store.view(agent.session, this.proof());
|
|
8961
|
+
return this.store.view(agent.session, this.proof(agent));
|
|
8345
8962
|
}
|
|
8346
8963
|
setEnabled(agent, revision, enabled) {
|
|
8347
8964
|
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);
|
|
8965
|
+
return this.store.setEnabled(agent.session, this.proof(agent), revision, enabled);
|
|
8349
8966
|
}
|
|
8350
8967
|
authorize(agent, revision, duration) {
|
|
8351
8968
|
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);
|
|
8969
|
+
return this.store.authorize(agent.session, this.proof(agent), revision, duration);
|
|
8353
8970
|
}
|
|
8354
8971
|
};
|
|
8355
8972
|
})();
|
|
@@ -8388,10 +9005,10 @@ function installReplayRecovery(ctx, proof) {
|
|
|
8388
9005
|
prepare(request) {
|
|
8389
9006
|
if (!active || request.signal === void 0 || request.signal.aborted || request.purpose !== void 0 || request.provider !== "github-copilot-preview") return void 0;
|
|
8390
9007
|
const binding = requests.get(request.signal);
|
|
8391
|
-
const currentProof = proof();
|
|
9008
|
+
const currentProof = proof(void 0, request);
|
|
8392
9009
|
if (!binding || binding.session.id !== request.sessionId || !busy.has(binding.session) || currentProof === void 0 || currentRequests.get(binding.session) !== request.signal) return void 0;
|
|
8393
9010
|
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);
|
|
9011
|
+
const current = () => active && !request.signal?.aborted && proof(void 0, request) === currentProof && currentRequests.get(binding.session) === request.signal && busy.has(binding.session);
|
|
8395
9012
|
return {
|
|
8396
9013
|
transform(payload) {
|
|
8397
9014
|
if (!current()) throw new Error("COPILOT_REPLAY_RECOVERY_REVOKED");
|
|
@@ -9751,6 +10368,14 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
9751
10368
|
if (inherited !== void 0) return autoModelPreference(inherited.model) !== void 0 ? inherited.model : void 0;
|
|
9752
10369
|
return pendingAuto(agent);
|
|
9753
10370
|
};
|
|
10371
|
+
const admitAccount = (agent, turn, signal) => {
|
|
10372
|
+
const owner = ctx.get("githubCopilotSessionAccounts");
|
|
10373
|
+
if (!owner) return;
|
|
10374
|
+
const projections = ctx.get("sessionProjections");
|
|
10375
|
+
const state = record(projections) && typeof projections.stateOf === "function" ? projections.stateOf(agent.session, "modelSelection") : void 0;
|
|
10376
|
+
const pending = record(state) ? state.pending : void 0;
|
|
10377
|
+
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);
|
|
10378
|
+
};
|
|
9754
10379
|
const installAgent = (agent) => {
|
|
9755
10380
|
if (agentDisposers.has(agent)) return;
|
|
9756
10381
|
const removeAssembly = agent.ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
@@ -9776,6 +10401,7 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
9776
10401
|
};
|
|
9777
10402
|
}, { prepend: true });
|
|
9778
10403
|
const removePreStep = agent.ctx.on("agent/pre-step", async ({ messages, turn, signal }, next) => {
|
|
10404
|
+
admitAccount(agent, turn, signal);
|
|
9779
10405
|
const result = await next();
|
|
9780
10406
|
const entered = result.kind === "enter" ? result.messages : messages;
|
|
9781
10407
|
captured.set(agent, {
|
|
@@ -9839,6 +10465,7 @@ function installAutoModelRouting(ctx, dependencies) {
|
|
|
9839
10465
|
});
|
|
9840
10466
|
const removeRequest = ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
|
|
9841
10467
|
installAgent(agent);
|
|
10468
|
+
admitAccount(agent, turn, signal);
|
|
9842
10469
|
const native = await next();
|
|
9843
10470
|
const admitted = routed.get(agent);
|
|
9844
10471
|
if (admitted?.turn === turn && admitted.admitted !== void 0) {
|
|
@@ -10279,7 +10906,8 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10279
10906
|
accountModelSettings;
|
|
10280
10907
|
replayRecovery;
|
|
10281
10908
|
requestCheckpoint;
|
|
10282
|
-
|
|
10909
|
+
captureRequest;
|
|
10910
|
+
constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery, requestCheckpoint, captureRequest = () => void 0) {
|
|
10283
10911
|
super(optionsFor());
|
|
10284
10912
|
this.lifetime = lifetime;
|
|
10285
10913
|
this.optionsFor = optionsFor;
|
|
@@ -10289,6 +10917,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10289
10917
|
this.accountModelSettings = accountModelSettings;
|
|
10290
10918
|
this.replayRecovery = replayRecovery;
|
|
10291
10919
|
this.requestCheckpoint = requestCheckpoint;
|
|
10920
|
+
this.captureRequest = captureRequest;
|
|
10292
10921
|
}
|
|
10293
10922
|
async listModels(provider) {
|
|
10294
10923
|
owned(provider);
|
|
@@ -10505,6 +11134,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10505
11134
|
signal,
|
|
10506
11135
|
...effort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(effort) }
|
|
10507
11136
|
};
|
|
11137
|
+
let capturedRequest = false;
|
|
10508
11138
|
for await (const chunk of native.stream(request)) {
|
|
10509
11139
|
owner.requestCheckpoint?.();
|
|
10510
11140
|
let delivered = chunk;
|
|
@@ -10531,6 +11161,10 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10531
11161
|
};
|
|
10532
11162
|
}
|
|
10533
11163
|
liveness?.pause();
|
|
11164
|
+
if (!capturedRequest && options.purpose === void 0) {
|
|
11165
|
+
capturedRequest = true;
|
|
11166
|
+
owner.captureRequest(options.signal);
|
|
11167
|
+
}
|
|
10534
11168
|
try {
|
|
10535
11169
|
yield delivered;
|
|
10536
11170
|
} finally {
|
|
@@ -10549,8 +11183,7 @@ var PreviewAdapter = class extends PiAiAdapter {
|
|
|
10549
11183
|
return excludedModelSet(this.accountModelSettings().excludedModelIds);
|
|
10550
11184
|
}
|
|
10551
11185
|
};
|
|
10552
|
-
|
|
10553
|
-
function apply$1(ctx, config = {}) {
|
|
11186
|
+
function createAccountRuntime(ctx, config, binding, exclusionTurns, replayRecovery, publish) {
|
|
10554
11187
|
const { accountModelTtlMs, accountModelFailureCooldownMs, accountModelSettings, requestBudget, requestBudgetSettings, streamLiveness, chatRequestSettings, ...requestConfig } = config;
|
|
10555
11188
|
const cacheSettings = accountModelSettings ?? (() => ({
|
|
10556
11189
|
accountModelTtlMs,
|
|
@@ -10560,11 +11193,11 @@ function apply$1(ctx, config = {}) {
|
|
|
10560
11193
|
const budgetSettings = requestBudgetSettings ?? (() => requestBudget ?? {});
|
|
10561
11194
|
const excludedModels = () => excludedModelSet(cacheSettings().excludedModelIds);
|
|
10562
11195
|
resolveRequestBudgetPolicy(budgetSettings());
|
|
10563
|
-
const store = () => createGitHubCopilotCredentialStore(ctx, GITHUB_COPILOT_PREVIEW_PROVIDER_ID,
|
|
10564
|
-
const acquire = (signal) => ctx.get("githubCopilotAccounts")?.host.acquire(signal);
|
|
11196
|
+
const store = () => createGitHubCopilotCredentialStore(ctx, GITHUB_COPILOT_PREVIEW_PROVIDER_ID, binding);
|
|
11197
|
+
const acquire = (signal) => ctx.get("githubCopilotAccounts")?.host.acquire(signal, true, binding?.accountId);
|
|
10565
11198
|
let rejectedAuth;
|
|
10566
11199
|
let authRecovery;
|
|
10567
|
-
const nativeAuth = createAccountModelAuth(() => createGitHubCopilotCredentialStore(ctx, "github-copilot",
|
|
11200
|
+
const nativeAuth = createAccountModelAuth(() => createGitHubCopilotCredentialStore(ctx, "github-copilot", binding), (grant) => {
|
|
10568
11201
|
const accountKey = copilotAccountKey(grant);
|
|
10569
11202
|
if (rejectedAuth?.accountKey !== accountKey || rejectedAuth.tokenFingerprint !== tokenFingerprint(grant.access)) return false;
|
|
10570
11203
|
const now = Date.now();
|
|
@@ -10620,20 +11253,10 @@ function apply$1(ctx, config = {}) {
|
|
|
10620
11253
|
});
|
|
10621
11254
|
const displayProofFor = (snapshot) => source.readDisplaySnapshot() === snapshot && provenSnapshot === snapshot && snapshotProof?.accountKey === snapshot.accountKey ? snapshotProof : void 0;
|
|
10622
11255
|
const proofFor = (snapshot) => source.readSnapshot() === snapshot && snapshotProof !== void 0 && snapshotProof.expires > Date.now() ? displayProofFor(snapshot) : void 0;
|
|
10623
|
-
const exclusionTurns = new ModelExclusionTurns();
|
|
10624
11256
|
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
11257
|
const template = resolvedProfile(createAccountProvider([], lifetime.guard(), "https://api.individual.githubcopilot.com").provider, requestConfig);
|
|
10634
11258
|
let configured = false;
|
|
10635
11259
|
let readError;
|
|
10636
|
-
let publishedDirectory = "";
|
|
10637
11260
|
const getView = () => {
|
|
10638
11261
|
const status = source.getView();
|
|
10639
11262
|
const cachedSnapshot = source.readDisplaySnapshot();
|
|
@@ -10680,7 +11303,7 @@ function apply$1(ctx, config = {}) {
|
|
|
10680
11303
|
...readError === void 0 && status.error === void 0 ? {} : { error: readError ?? status.error }
|
|
10681
11304
|
});
|
|
10682
11305
|
};
|
|
10683
|
-
|
|
11306
|
+
const notify = publish;
|
|
10684
11307
|
const refresh = async () => {
|
|
10685
11308
|
lifetime.assertActive();
|
|
10686
11309
|
const ticket = { revision: lifetime.revision };
|
|
@@ -10817,7 +11440,7 @@ function apply$1(ctx, config = {}) {
|
|
|
10817
11440
|
lifetime.assertActive();
|
|
10818
11441
|
},
|
|
10819
11442
|
auth: {
|
|
10820
|
-
credentials: lease?.credentials ??
|
|
11443
|
+
credentials: lease?.credentials ?? store(),
|
|
10821
11444
|
authContext: {
|
|
10822
11445
|
env: async () => void 0,
|
|
10823
11446
|
fileExists: async () => false
|
|
@@ -10827,65 +11450,192 @@ function apply$1(ctx, config = {}) {
|
|
|
10827
11450
|
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, (hostPath) => ctx.get("fs")?.processPathFromHostPath(hostPath), ref)
|
|
10828
11451
|
};
|
|
10829
11452
|
};
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
11453
|
+
return {
|
|
11454
|
+
adapter: new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, replayRecovery, void 0, (signal) => ctx.get("githubCopilotSessionAccounts")?.recordRequest(signal)),
|
|
11455
|
+
preview: {
|
|
11456
|
+
getView,
|
|
11457
|
+
refresh,
|
|
11458
|
+
recoveryLimits(modelId) {
|
|
11459
|
+
const snapshot = source.readSnapshot();
|
|
11460
|
+
if (snapshot === void 0 || proofFor(snapshot) === void 0 || !getView().available || excludedModels().has(modelId)) return void 0;
|
|
11461
|
+
const descriptor = snapshot.models.find((model) => model.id === modelId);
|
|
11462
|
+
if (descriptor === void 0) return void 0;
|
|
11463
|
+
const revision = lifetime.revision;
|
|
11464
|
+
const proof = snapshotProof;
|
|
11465
|
+
return Object.freeze({
|
|
11466
|
+
limits: Object.freeze({
|
|
11467
|
+
contextWindow: descriptor.contextWindow,
|
|
11468
|
+
maxTokens: descriptor.maxTokens,
|
|
11469
|
+
...descriptor.maxInputTokens === void 0 ? {} : { maxInputTokens: descriptor.maxInputTokens }
|
|
11470
|
+
}),
|
|
11471
|
+
policy: Object.freeze({ ...budgetSettings() }),
|
|
11472
|
+
assertCurrent: () => {
|
|
11473
|
+
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");
|
|
11474
|
+
}
|
|
11475
|
+
});
|
|
11476
|
+
},
|
|
11477
|
+
captureSearchProof() {
|
|
11478
|
+
const revision = lifetime.revision;
|
|
11479
|
+
const captured = snapshotProof;
|
|
11480
|
+
const expires = captured !== void 0 && captured.expires > Date.now() ? captured.expires : void 0;
|
|
11481
|
+
return () => lifetime.isCurrent(revision) && (expires === void 0 || expires > Date.now()) && (snapshotProof === captured || snapshotProof === void 0 || snapshotProof.expires > Date.now());
|
|
11482
|
+
},
|
|
11483
|
+
routeFacts(modelId) {
|
|
11484
|
+
if (excludedModels().has(modelId)) return void 0;
|
|
11485
|
+
const snapshot = source.readSnapshot();
|
|
11486
|
+
const proof = snapshot === void 0 ? void 0 : proofFor(snapshot);
|
|
11487
|
+
const descriptor = snapshot?.models.find((model) => model.id === modelId);
|
|
11488
|
+
return !getView().available || proof === void 0 || descriptor === void 0 ? void 0 : Object.freeze({
|
|
11489
|
+
api: descriptor.api,
|
|
11490
|
+
baseURL: proof.baseURL
|
|
11491
|
+
});
|
|
11492
|
+
},
|
|
11493
|
+
async resolveRequestAuth(modelId, signal) {
|
|
11494
|
+
const snapshot = await discoverSnapshot({ signal });
|
|
11495
|
+
const lease = await lifetime.lease(snapshot, modelId, signal);
|
|
11496
|
+
const auth = await nativeAuth.resolveAuth(lease.signal);
|
|
11497
|
+
const grant = await lifetime.read(lease.signal);
|
|
11498
|
+
if (grant === void 0) throw failure("COPILOT_PREVIEW_OAUTH_REQUIRED");
|
|
11499
|
+
lifetime.guard(lease).assertEntitled(grant, modelId);
|
|
11500
|
+
if (auth.accountKey !== lease.proof.accountKey || tokenFingerprint(auth.apiKey) !== lease.proof.tokenFingerprint || auth.baseURL !== lease.proof.baseURL) throw failure("COPILOT_PREVIEW_METADATA_STALE");
|
|
11501
|
+
await nativeAuth.assertAuthCurrent(auth, lease.signal);
|
|
11502
|
+
lifetime.guard(lease).assertEntitled(grant, modelId);
|
|
11503
|
+
return Object.freeze({
|
|
11504
|
+
apiKey: auth.apiKey,
|
|
11505
|
+
baseURL: auth.baseURL,
|
|
11506
|
+
headers: Object.freeze({ ...copilotPublicHeaders() })
|
|
11507
|
+
});
|
|
11508
|
+
},
|
|
11509
|
+
async discover(options) {
|
|
11510
|
+
try {
|
|
11511
|
+
await discoverSnapshot(options);
|
|
11512
|
+
} catch {
|
|
11513
|
+
lifetime.assertActive();
|
|
11514
|
+
}
|
|
11515
|
+
return getView();
|
|
11516
|
+
}
|
|
10834
11517
|
},
|
|
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);
|
|
11518
|
+
auto: {
|
|
11519
|
+
async loadModels(signal) {
|
|
11520
|
+
const excluded = excludedModels();
|
|
11521
|
+
return (await discoverSnapshot({ signal })).models.filter((model) => !excluded.has(model.id));
|
|
11522
|
+
},
|
|
11523
|
+
budgetPolicy: () => budgetSettings(),
|
|
11524
|
+
parentModelBindings: () => cacheSettings().parentModelFollow ?? [],
|
|
11525
|
+
followParentModel: () => cacheSettings().followParentModel === true,
|
|
11526
|
+
semanticAssessment: () => cacheSettings().autoSemanticAssessment ?? true,
|
|
11527
|
+
assessmentDiagnostic: (code) => ctx.logger.warn(code),
|
|
11528
|
+
async classifyTask(...args) {
|
|
11529
|
+
const [input, signal, observe, checkpoint] = args;
|
|
10854
11530
|
checkpoint?.();
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
|
|
10858
|
-
if (
|
|
11531
|
+
const snapshot = await discoverSnapshot({ signal });
|
|
11532
|
+
checkpoint?.();
|
|
11533
|
+
const model = taskClassifierModel(snapshot.models.filter((model) => !excludedModels().has(model.id)));
|
|
11534
|
+
if (model === void 0) throw failure("COPILOT_AUTO_CLASSIFIER_UNAVAILABLE");
|
|
11535
|
+
observe?.({
|
|
11536
|
+
stage: "model-selected",
|
|
11537
|
+
modelId: model.id
|
|
11538
|
+
});
|
|
11539
|
+
const revision = lifetime.revision;
|
|
11540
|
+
const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, void 0, checkpoint);
|
|
11541
|
+
try {
|
|
11542
|
+
const prepared = await adapter.prepareCall(GITHUB_COPILOT_PREVIEW_PROVIDER_ID, model.id, signal);
|
|
11543
|
+
checkpoint?.();
|
|
11544
|
+
if (signal.aborted) throw signal.reason;
|
|
11545
|
+
return await classifyTaskWithAdapter(model, input, signal, (request) => prepared.stream(request), observe, prepared.model.reasoning?.efforts.some((effort) => effort.id === "off") === true, checkpoint);
|
|
11546
|
+
} finally {
|
|
11547
|
+
if (!lifetime.isCurrent(revision) || source.readSnapshot() !== snapshot || proofFor(snapshot) === void 0) throw new TaskAssessmentRevokedError(failure("COPILOT_PREVIEW_METADATA_STALE", "ABORTED"));
|
|
11548
|
+
}
|
|
11549
|
+
},
|
|
11550
|
+
admitModel(agent, turn, model, signal) {
|
|
11551
|
+
if (!exclusionTurns.admit(agent.session, turn, model, signal, excludedModels())) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
|
|
10859
11552
|
}
|
|
10860
11553
|
},
|
|
10861
|
-
|
|
10862
|
-
|
|
11554
|
+
pressureCallbacks: { resolve(request) {
|
|
11555
|
+
const snapshot = source.readSnapshot();
|
|
11556
|
+
if (snapshot === void 0 || proofFor(snapshot) === void 0) return void 0;
|
|
11557
|
+
if (excludedModels().has(request.model)) return void 0;
|
|
11558
|
+
const descriptor = snapshot.models.find((model) => model.id === request.model);
|
|
11559
|
+
if (descriptor === void 0) return void 0;
|
|
11560
|
+
const result = calculateRequestBudget(descriptor, request.maxTokens, resolveRequestBudgetPolicy(budgetSettings()));
|
|
11561
|
+
return result.ok ? { inputBudgetTokens: result.budget.pressureInputLimit } : void 0;
|
|
11562
|
+
} },
|
|
11563
|
+
optionsFor,
|
|
11564
|
+
lifetime,
|
|
11565
|
+
proof() {
|
|
11566
|
+
if (snapshotProof === void 0 || snapshotProof.expires <= Date.now()) return void 0;
|
|
11567
|
+
return `${binding?.accountId ?? "canonical"}:${lifetime.revision}:${snapshotProof.accountKey}:${snapshotProof.tokenFingerprint}`;
|
|
11568
|
+
},
|
|
11569
|
+
invalidate() {
|
|
11570
|
+
lifetime.change();
|
|
11571
|
+
provenSnapshot = void 0;
|
|
11572
|
+
snapshotProof = void 0;
|
|
11573
|
+
lastValidatedProof = void 0;
|
|
11574
|
+
refresh().catch(() => void 0);
|
|
10863
11575
|
}
|
|
11576
|
+
};
|
|
11577
|
+
}
|
|
11578
|
+
/** One registry owner delegates to immutable account-local native adapter state. */
|
|
11579
|
+
var AccountRoutingAdapter = class extends PiAiAdapter {
|
|
11580
|
+
requestRuntime;
|
|
11581
|
+
constructor(options, requestRuntime) {
|
|
11582
|
+
super(options);
|
|
11583
|
+
this.requestRuntime = requestRuntime;
|
|
11584
|
+
}
|
|
11585
|
+
listModels(provider) {
|
|
11586
|
+
return this.requestRuntime().adapter.listModels(provider);
|
|
11587
|
+
}
|
|
11588
|
+
resolveModel(provider, model, signal) {
|
|
11589
|
+
return this.requestRuntime(signal).adapter.resolveModel(provider, model, signal);
|
|
11590
|
+
}
|
|
11591
|
+
prepareCall(provider, model, signal) {
|
|
11592
|
+
return this.requestRuntime(signal).adapter.prepareCall(provider, model, signal);
|
|
11593
|
+
}
|
|
11594
|
+
stream(options) {
|
|
11595
|
+
return this.requestRuntime(options.signal).adapter.stream(options);
|
|
11596
|
+
}
|
|
11597
|
+
};
|
|
11598
|
+
/** Register services once; account switches affect the directory, not admitted turns. */
|
|
11599
|
+
function apply$1(ctx, config = {}) {
|
|
11600
|
+
const runtimes = /* @__PURE__ */ new Map();
|
|
11601
|
+
const exclusionTurns = new ModelExclusionTurns();
|
|
11602
|
+
const freezeBinding = (binding) => binding === void 0 ? void 0 : ctx.get("githubCopilotAccounts")?.host.captureAccount(binding.accountId) ?? binding;
|
|
11603
|
+
const globalBinding = () => freezeBinding(activeCopilotBinding(ctx));
|
|
11604
|
+
const requestBinding = (signal) => ctx.get("githubCopilotSessionAccounts")?.requestBinding(signal) ?? globalBinding();
|
|
11605
|
+
let disposed = false;
|
|
11606
|
+
let publishedDirectory = "";
|
|
11607
|
+
let publish = () => void 0;
|
|
11608
|
+
const runtimeFor = (binding) => {
|
|
11609
|
+
if (disposed) throw failure("COPILOT_PREVIEW_DISPOSED", "ABORTED");
|
|
11610
|
+
binding?.assertCurrent();
|
|
11611
|
+
const accountId = binding?.accountId ?? "canonical";
|
|
11612
|
+
const current = runtimes.get(accountId);
|
|
11613
|
+
if (current !== void 0) return current;
|
|
11614
|
+
if (runtimes.size >= 32) throw failure("COPILOT_ACCOUNTS_RUNTIME_LIMIT", "INVALID_REQUEST");
|
|
11615
|
+
const runtime = createAccountRuntime(ctx, config, binding, exclusionTurns, replayRecovery, () => {
|
|
11616
|
+
if (disposed) return;
|
|
11617
|
+
try {
|
|
11618
|
+
if ((globalBinding()?.accountId ?? "canonical") === accountId) publish();
|
|
11619
|
+
} catch {
|
|
11620
|
+
ctx.logger.warn("COPILOT_PREVIEW_DIRECTORY_ACCOUNT_UNAVAILABLE");
|
|
11621
|
+
}
|
|
11622
|
+
});
|
|
11623
|
+
runtimes.set(accountId, runtime);
|
|
11624
|
+
return runtime;
|
|
11625
|
+
};
|
|
11626
|
+
const currentRuntime = (signal) => runtimeFor(requestBinding(signal));
|
|
11627
|
+
const directoryRuntime = () => runtimeFor(globalBinding());
|
|
11628
|
+
const replayRecovery = installReplayRecovery(ctx, (agent, request) => {
|
|
11629
|
+
const accounts = ctx.get("githubCopilotSessionAccounts");
|
|
11630
|
+
const binding = agent !== void 0 && accounts !== void 0 ? accounts.bindingForAccount((accounts.turns.current(agent.session) ?? accounts.selected(agent)).accountId) : requestBinding(request?.signal);
|
|
11631
|
+
return runtimeFor(binding).proof();
|
|
10864
11632
|
});
|
|
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();
|
|
11633
|
+
const initial = directoryRuntime();
|
|
11634
|
+
const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new AccountRoutingAdapter(initial.optionsFor(), currentRuntime));
|
|
11635
|
+
publish = () => {
|
|
11636
|
+
const view = directoryRuntime().preview.getView();
|
|
10888
11637
|
const directory = JSON.stringify({
|
|
11638
|
+
account: globalBinding()?.accountId ?? "canonical",
|
|
10889
11639
|
models: view.models,
|
|
10890
11640
|
available: view.available,
|
|
10891
11641
|
configured: view.configured
|
|
@@ -10894,87 +11644,58 @@ function apply$1(ctx, config = {}) {
|
|
|
10894
11644
|
publishedDirectory = directory;
|
|
10895
11645
|
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
10896
11646
|
};
|
|
11647
|
+
const removeAutoRoute = installAutoModelRouting(ctx, {
|
|
11648
|
+
loadModels: (signal) => currentRuntime(signal).auto.loadModels(signal),
|
|
11649
|
+
classifyTask: (...args) => currentRuntime(args[1]).auto.classifyTask(...args),
|
|
11650
|
+
budgetPolicy: () => currentRuntime().auto.budgetPolicy(),
|
|
11651
|
+
parentModelBindings: () => currentRuntime().auto.parentModelBindings(),
|
|
11652
|
+
followParentModel: () => currentRuntime().auto.followParentModel(),
|
|
11653
|
+
semanticAssessment: () => currentRuntime().auto.semanticAssessment(),
|
|
11654
|
+
assessmentDiagnostic: (code) => ctx.logger.warn(code),
|
|
11655
|
+
admitModel: (agent, turn, model, signal) => currentRuntime(signal).auto.admitModel(agent, turn, model, signal)
|
|
11656
|
+
});
|
|
11657
|
+
const pressureCallbacks = { resolve: (request) => currentRuntime(request.signal).pressureCallbacks.resolve(request) };
|
|
11658
|
+
installCopilotPreStepPressure(ctx, pressureCallbacks);
|
|
11659
|
+
installCopilotCompactionPressure(ctx, pressureCallbacks);
|
|
10897
11660
|
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
|
-
}
|
|
11661
|
+
getView: () => disposed ? initial.preview.getView() : currentRuntime().preview.getView(),
|
|
11662
|
+
refresh: async () => currentRuntime().preview.refresh(),
|
|
11663
|
+
discover: (options) => currentRuntime(options?.signal).preview.discover(options),
|
|
11664
|
+
recoveryLimits: (model) => currentRuntime().preview.recoveryLimits(model),
|
|
11665
|
+
routeFacts: (model) => currentRuntime().preview.routeFacts(model),
|
|
11666
|
+
captureSearchProof: () => currentRuntime().preview.captureSearchProof(),
|
|
11667
|
+
resolveRequestAuth: (model, signal) => currentRuntime(signal).preview.resolveRequestAuth(model, signal)
|
|
11668
|
+
});
|
|
11669
|
+
const removeStepListener = ctx.on("session/event", (session, event) => {
|
|
11670
|
+
if (event.type === "step/start" || event.type === "turn/end") for (const runtime of runtimes.values()) runtime.lifetime.clearSessionRetries(session.id);
|
|
11671
|
+
if (event.type === "turn/end") exclusionTurns.end(session);
|
|
10959
11672
|
});
|
|
10960
11673
|
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);
|
|
11674
|
+
for (const [accountId, runtime] of runtimes) if ((accountId === "canonical" ? "llm-pi-ai/github-copilot" : `github-copilot/account-${accountId}`) === key) runtime.invalidate();
|
|
10967
11675
|
});
|
|
10968
11676
|
const removeAccountListener = ctx.get("githubCopilotAccounts")?.host.onChanged(() => {
|
|
10969
|
-
|
|
10970
|
-
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
|
|
11677
|
+
publishedDirectory = "";
|
|
11678
|
+
try {
|
|
11679
|
+
publish();
|
|
11680
|
+
directoryRuntime().preview.refresh().catch(() => void 0);
|
|
11681
|
+
} catch {
|
|
11682
|
+
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
11683
|
+
ctx.logger.warn("COPILOT_PREVIEW_DIRECTORY_ACCOUNT_UNAVAILABLE");
|
|
11684
|
+
}
|
|
11685
|
+
});
|
|
11686
|
+
let exclusionSignature = JSON.stringify([...excludedModelSet(config.accountModelSettings?.().excludedModelIds)]);
|
|
11687
|
+
const removeSettings = onSettingsNamespaceUpdated(ctx, (namespace) => {
|
|
11688
|
+
if (namespace !== "github-copilot") return;
|
|
11689
|
+
const next = JSON.stringify([...excludedModelSet(config.accountModelSettings?.().excludedModelIds)]);
|
|
11690
|
+
if (next === exclusionSignature) return;
|
|
11691
|
+
exclusionSignature = next;
|
|
11692
|
+
publishedDirectory = "";
|
|
11693
|
+
registration.replace([GITHUB_COPILOT_PREVIEW_PROVIDER_ID]);
|
|
10975
11694
|
});
|
|
10976
11695
|
ctx.effect(() => () => {
|
|
10977
|
-
|
|
11696
|
+
disposed = true;
|
|
11697
|
+
for (const runtime of runtimes.values()) runtime.lifetime.dispose();
|
|
11698
|
+
runtimes.clear();
|
|
10978
11699
|
removeStepListener();
|
|
10979
11700
|
replayRecovery.dispose();
|
|
10980
11701
|
removeListener();
|
|
@@ -10983,7 +11704,7 @@ function apply$1(ctx, config = {}) {
|
|
|
10983
11704
|
removeAutoRoute();
|
|
10984
11705
|
registration();
|
|
10985
11706
|
});
|
|
10986
|
-
refresh().catch(() => void 0);
|
|
11707
|
+
initial.preview.refresh().catch(() => void 0);
|
|
10987
11708
|
}
|
|
10988
11709
|
var preview_route_default = {
|
|
10989
11710
|
name: "github-copilot-preview",
|
|
@@ -11099,23 +11820,35 @@ function activate(ctx, config) {
|
|
|
11099
11820
|
if (legacy && (legacy.searchProvider !== void 0 || legacy.defaultSearchProvider !== void 0 || legacy.searchMode !== void 0)) return legacy;
|
|
11100
11821
|
return current().searchRouting ?? {};
|
|
11101
11822
|
};
|
|
11823
|
+
const sessionAccounts = new SessionAccountsHost(ctx);
|
|
11824
|
+
ctx.provide("githubCopilotSessionAccounts", sessionAccounts);
|
|
11825
|
+
ctx.plugin({ apply(scope) {
|
|
11826
|
+
new SessionAccountController(scope, sessionAccounts);
|
|
11827
|
+
} });
|
|
11102
11828
|
const accountTurns = /* @__PURE__ */ new Map();
|
|
11103
11829
|
ctx.on("session/event", (session, event) => {
|
|
11104
11830
|
if (event.type !== "turn/end") return;
|
|
11105
11831
|
accountTurns.get(session.id)?.release();
|
|
11106
11832
|
accountTurns.delete(session.id);
|
|
11833
|
+
sessionAccounts.end(session, event.data.turn);
|
|
11107
11834
|
});
|
|
11108
11835
|
ctx.on("agent/disposed", ({ agent }) => {
|
|
11109
11836
|
accountTurns.get(agent.session.id)?.release();
|
|
11110
11837
|
accountTurns.delete(agent.session.id);
|
|
11838
|
+
sessionAccounts.remove(agent.session);
|
|
11111
11839
|
});
|
|
11112
|
-
|
|
11840
|
+
const acquireAccount = (signal, provider) => {
|
|
11841
|
+
if (provider === "github-copilot") return ctx.get("githubCopilotAccounts")?.host.acquire(signal);
|
|
11842
|
+
const binding = sessionAccounts.requestBinding(signal);
|
|
11843
|
+
return ctx.get("githubCopilotAccounts")?.host.acquire(signal, true, binding.accountId);
|
|
11844
|
+
};
|
|
11845
|
+
ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
|
|
11113
11846
|
const projections = ctx.get("sessionProjections");
|
|
11114
11847
|
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
11848
|
const pending = typeof state === "object" && state !== null && "pending" in state ? state.pending : void 0;
|
|
11116
|
-
|
|
11117
|
-
|
|
11118
|
-
const lease =
|
|
11849
|
+
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();
|
|
11850
|
+
sessionAccounts.admit(agent, turn, signal);
|
|
11851
|
+
const lease = acquireAccount(signal);
|
|
11119
11852
|
let retained = false;
|
|
11120
11853
|
try {
|
|
11121
11854
|
const result = await next();
|
|
@@ -11133,6 +11866,7 @@ function activate(ctx, config) {
|
|
|
11133
11866
|
ctx.effect(() => () => {
|
|
11134
11867
|
for (const lease of accountTurns.values()) lease.release();
|
|
11135
11868
|
accountTurns.clear();
|
|
11869
|
+
sessionAccounts.dispose();
|
|
11136
11870
|
});
|
|
11137
11871
|
ctx.plugin(preview_route_default, {
|
|
11138
11872
|
accountModelSettings: () => current(),
|
|
@@ -11158,6 +11892,25 @@ function activate(ctx, config) {
|
|
|
11158
11892
|
let proofCancellation = new AbortController();
|
|
11159
11893
|
const candidateGenerations = /* @__PURE__ */ new WeakMap();
|
|
11160
11894
|
const candidateProviders = /* @__PURE__ */ new WeakMap();
|
|
11895
|
+
const accountProofs = /* @__PURE__ */ new Map();
|
|
11896
|
+
const candidateAccounts = /* @__PURE__ */ new WeakMap();
|
|
11897
|
+
function accountProof(signal, provider) {
|
|
11898
|
+
const key = provider === "github-copilot" ? GITHUB_COPILOT_CREDENTIAL_KEY$1 : sessionAccounts.requestBinding(signal).key;
|
|
11899
|
+
let proof = accountProofs.get(key);
|
|
11900
|
+
if (!proof) {
|
|
11901
|
+
if (accountProofs.size >= 64) throw new Error("COPILOT_SEARCH_ACCOUNT_PROOF_LIMIT");
|
|
11902
|
+
proof = {
|
|
11903
|
+
key,
|
|
11904
|
+
cancellation: new AbortController()
|
|
11905
|
+
};
|
|
11906
|
+
accountProofs.set(key, proof);
|
|
11907
|
+
}
|
|
11908
|
+
return proof;
|
|
11909
|
+
}
|
|
11910
|
+
function invalidateAccount(key) {
|
|
11911
|
+
accountProofs.get(key)?.cancellation.abort();
|
|
11912
|
+
accountProofs.delete(key);
|
|
11913
|
+
}
|
|
11161
11914
|
const ownerPlans = /* @__PURE__ */ new WeakMap();
|
|
11162
11915
|
const disposedOwners = /* @__PURE__ */ new WeakSet();
|
|
11163
11916
|
const candidateSignals = /* @__PURE__ */ new WeakMap();
|
|
@@ -11180,17 +11933,20 @@ function activate(ctx, config) {
|
|
|
11180
11933
|
proofCancellation = new AbortController();
|
|
11181
11934
|
}
|
|
11182
11935
|
ctx.on("credentials/record-updated", (key) => {
|
|
11183
|
-
if (
|
|
11936
|
+
if (isCopilotAccountRecord(key)) invalidateAccount(key);
|
|
11184
11937
|
});
|
|
11185
|
-
ctx.get("githubCopilotAccounts")?.host.onChanged(invalidatePlans);
|
|
11186
11938
|
ctx.effect(() => () => {
|
|
11187
11939
|
active = false;
|
|
11188
11940
|
invalidatePlans();
|
|
11941
|
+
for (const proof of accountProofs.values()) proof.cancellation.abort();
|
|
11942
|
+
accountProofs.clear();
|
|
11189
11943
|
});
|
|
11190
11944
|
function assertCurrentCandidate(candidate) {
|
|
11191
11945
|
if (!active) throw new Error("github-copilot: hosted search integration was disposed");
|
|
11192
11946
|
if (candidateSignals.get(candidate)?.aborted === true) throw new Error("github-copilot: search owner or proof was disposed");
|
|
11193
11947
|
if (candidateGenerations.get(candidate) !== generation) throw new Error("github-copilot: search proof invalidated; retry with current credentials");
|
|
11948
|
+
const account = candidateAccounts.get(candidate);
|
|
11949
|
+
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
11950
|
}
|
|
11195
11951
|
const hooks = {
|
|
11196
11952
|
resolveResponsesReasoning: (request, candidate) => resolveCopilotResponsesReasoning(ctx, request, candidate),
|
|
@@ -11207,7 +11963,10 @@ function activate(ctx, config) {
|
|
|
11207
11963
|
assertCurrentCandidate(candidate);
|
|
11208
11964
|
return auth;
|
|
11209
11965
|
} catch (error) {
|
|
11210
|
-
if (active && candidateGenerations.get(candidate) === generation && candidateSignals.get(candidate)?.aborted !== true)
|
|
11966
|
+
if (active && candidateGenerations.get(candidate) === generation && candidateSignals.get(candidate)?.aborted !== true) {
|
|
11967
|
+
const account = candidateAccounts.get(candidate);
|
|
11968
|
+
if (account) invalidateAccount(account.key);
|
|
11969
|
+
}
|
|
11211
11970
|
throw error;
|
|
11212
11971
|
}
|
|
11213
11972
|
}
|
|
@@ -11221,15 +11980,21 @@ function activate(ctx, config) {
|
|
|
11221
11980
|
}
|
|
11222
11981
|
function createPlan(candidates, cfg, provider, plans, operation) {
|
|
11223
11982
|
const startedAt = generation;
|
|
11224
|
-
const
|
|
11983
|
+
const account = accountProof(operation?.signal, provider);
|
|
11984
|
+
const signal = AbortSignal.any([
|
|
11985
|
+
proofCancellation.signal,
|
|
11986
|
+
account.cancellation.signal,
|
|
11987
|
+
...plans === void 0 ? [] : [plans.cancellation.signal]
|
|
11988
|
+
]);
|
|
11225
11989
|
const probeSignal = operation?.signal === void 0 ? signal : AbortSignal.any([signal, operation.signal]);
|
|
11226
11990
|
function bind(candidate, lifetime) {
|
|
11227
11991
|
candidateGenerations.set(candidate, startedAt);
|
|
11992
|
+
candidateAccounts.set(candidate, account);
|
|
11228
11993
|
candidateSignals.set(candidate, lifetime);
|
|
11229
11994
|
if (provider !== void 0) candidateProviders.set(candidate, provider);
|
|
11230
11995
|
}
|
|
11231
11996
|
for (const candidate of candidates) bind(candidate, cfg.probe ? probeSignal : signal);
|
|
11232
|
-
const admission =
|
|
11997
|
+
const admission = acquireAccount(probeSignal, provider);
|
|
11233
11998
|
let nextPlan;
|
|
11234
11999
|
try {
|
|
11235
12000
|
nextPlan = new SearchPlan(candidates, (candidate) => probeCandidate(candidate, async (selected) => {
|
|
@@ -11249,28 +12014,31 @@ function activate(ctx, config) {
|
|
|
11249
12014
|
});
|
|
11250
12015
|
return nextPlan;
|
|
11251
12016
|
}
|
|
11252
|
-
function matches(cached, route, candidates, cfg) {
|
|
12017
|
+
function matches(cached, route, candidates, cfg, provider) {
|
|
11253
12018
|
try {
|
|
11254
12019
|
cached?.assertProof?.();
|
|
11255
12020
|
} catch {
|
|
11256
12021
|
return false;
|
|
11257
12022
|
}
|
|
11258
12023
|
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);
|
|
12024
|
+
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
12025
|
}
|
|
11261
12026
|
function plan(route, cfg, owner, surface, operation) {
|
|
11262
12027
|
const plans = owner === void 0 ? void 0 : plansFor(owner);
|
|
11263
12028
|
const candidates = surface === "inline" ? candidatesForRoute(route) : surface === "configured" ? configuredCandidates(cfg) : traditionalCandidates(route, cfg);
|
|
11264
12029
|
const cached = plans?.[surface];
|
|
11265
|
-
|
|
12030
|
+
const provider = surface === "configured" ? GITHUB_COPILOT_PREVIEW_PROVIDER_ID : route?.provider;
|
|
12031
|
+
if (matches(cached, route, candidates, cfg, provider)) return cached.plan;
|
|
11266
12032
|
const startedAt = generation;
|
|
11267
|
-
const
|
|
12033
|
+
const account = accountProof(operation?.signal, provider);
|
|
12034
|
+
const nextPlan = createPlan(candidates, cfg, provider, plans, operation);
|
|
11268
12035
|
if (generation === startedAt && active && plans?.cancellation.signal.aborted !== true) {
|
|
11269
12036
|
if (plans !== void 0) plans[surface] = {
|
|
11270
12037
|
plan: nextPlan,
|
|
11271
12038
|
route,
|
|
11272
12039
|
probe: probeSettings(cfg),
|
|
11273
12040
|
generation: startedAt,
|
|
12041
|
+
account,
|
|
11274
12042
|
...operation === void 0 ? {} : {
|
|
11275
12043
|
assertProof: operation.assertProof,
|
|
11276
12044
|
...operation.signal === void 0 ? {} : { probeSignal: operation.signal }
|
|
@@ -11291,15 +12059,20 @@ function activate(ctx, config) {
|
|
|
11291
12059
|
const startedAt = generation;
|
|
11292
12060
|
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
12061
|
const plans = plansFor(owner);
|
|
12062
|
+
const account = accountProof(signal, selection.provider);
|
|
11294
12063
|
if (selection?.provider === "github-copilot-preview") {
|
|
11295
|
-
const signals = [
|
|
12064
|
+
const signals = [
|
|
12065
|
+
proofCancellation.signal,
|
|
12066
|
+
account.cancellation.signal,
|
|
12067
|
+
plans.cancellation.signal
|
|
12068
|
+
];
|
|
11296
12069
|
if (signal !== void 0) signals.push(signal);
|
|
11297
12070
|
await ctx.get("githubCopilotPreview")?.discover({
|
|
11298
12071
|
force: false,
|
|
11299
12072
|
signal: AbortSignal.any(signals)
|
|
11300
12073
|
});
|
|
11301
12074
|
}
|
|
11302
|
-
if (!active || startedAt !== generation || plans.cancellation.signal.aborted || signal?.aborted === true) throw new Error("github-copilot: search proof invalidated during route resolution");
|
|
12075
|
+
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
12076
|
return plan(currentChatRoute(ctx, selection), cfg, owner, "traditional");
|
|
11304
12077
|
}
|
|
11305
12078
|
function configuredSearchSelection(cfg) {
|
|
@@ -11318,14 +12091,19 @@ function activate(ctx, config) {
|
|
|
11318
12091
|
const startedAt = generation;
|
|
11319
12092
|
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
12093
|
const plans = plansFor(owner);
|
|
11321
|
-
const
|
|
12094
|
+
const account = accountProof(signal);
|
|
12095
|
+
const signals = [
|
|
12096
|
+
proofCancellation.signal,
|
|
12097
|
+
account.cancellation.signal,
|
|
12098
|
+
plans.cancellation.signal
|
|
12099
|
+
];
|
|
11322
12100
|
if (signal !== void 0) signals.push(signal);
|
|
11323
12101
|
await ctx.get("githubCopilotPreview")?.discover({
|
|
11324
12102
|
force: false,
|
|
11325
12103
|
signal: AbortSignal.any(signals)
|
|
11326
12104
|
});
|
|
11327
12105
|
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");
|
|
12106
|
+
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
12107
|
return plan(selection === void 0 ? void 0 : currentChatRoute(ctx, selection), cfg, owner, "configured", {
|
|
11330
12108
|
assertCurrent,
|
|
11331
12109
|
assertProof,
|
|
@@ -11370,7 +12148,7 @@ function activate(ctx, config) {
|
|
|
11370
12148
|
const candidates = traditionalCandidates(route, cfg);
|
|
11371
12149
|
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
12150
|
const cached = ownerPlans.get(owner)?.traditional;
|
|
11373
|
-
return !matches(cached, route, candidates, cfg) || cached.plan.available();
|
|
12151
|
+
return !matches(cached, route, candidates, cfg, route?.provider) || cached.plan.available();
|
|
11374
12152
|
}
|
|
11375
12153
|
/** Local readiness for the provider-owned Copilot search model. */
|
|
11376
12154
|
function configuredAvailable() {
|
|
@@ -11387,13 +12165,13 @@ function activate(ctx, config) {
|
|
|
11387
12165
|
return view?.configured === true && (selection === void 0 ? view.state !== "ready" : route?.provider === "github-copilot-preview" && route.api === void 0);
|
|
11388
12166
|
}
|
|
11389
12167
|
const cached = ownerPlans.get(owner)?.configured;
|
|
11390
|
-
return !matches(cached, route, candidates, cfg) || cached.plan.available();
|
|
12168
|
+
return !matches(cached, route, candidates, cfg, "github-copilot-preview") || cached.plan.available();
|
|
11391
12169
|
}
|
|
11392
12170
|
const nativeTraditionalProvider = createTraditionalSearchProvider(traditionalAvailable, webPlan, hooks, current);
|
|
11393
12171
|
const traditionalProvider = {
|
|
11394
12172
|
...nativeTraditionalProvider,
|
|
11395
12173
|
async search(request, signal) {
|
|
11396
|
-
const lease = ctx
|
|
12174
|
+
const lease = acquireAccount(signal, currentSearchSelection(currentSearchInitiator(ctx))?.provider);
|
|
11397
12175
|
try {
|
|
11398
12176
|
return await nativeTraditionalProvider.search(request, signal);
|
|
11399
12177
|
} finally {
|
|
@@ -11402,7 +12180,7 @@ function activate(ctx, config) {
|
|
|
11402
12180
|
}
|
|
11403
12181
|
};
|
|
11404
12182
|
async function configuredSearch(request, signal) {
|
|
11405
|
-
const lease =
|
|
12183
|
+
const lease = acquireAccount(signal);
|
|
11406
12184
|
try {
|
|
11407
12185
|
return await configuredAccountSearch(request, signal);
|
|
11408
12186
|
} finally {
|
|
@@ -11412,11 +12190,12 @@ function activate(ctx, config) {
|
|
|
11412
12190
|
async function configuredAccountSearch(request, signal) {
|
|
11413
12191
|
const owner = currentSearchInitiator(ctx);
|
|
11414
12192
|
const startedGeneration = generation;
|
|
12193
|
+
const account = accountProof(signal);
|
|
11415
12194
|
const cfg = current();
|
|
11416
12195
|
const preview = ctx.get("githubCopilotPreview");
|
|
11417
12196
|
const proof = preview?.captureSearchProof();
|
|
11418
12197
|
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();
|
|
12198
|
+
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
12199
|
};
|
|
11421
12200
|
const assertCurrent = () => {
|
|
11422
12201
|
if (signal?.aborted) throw new WebError("web search aborted", "WEB_ABORTED");
|
|
@@ -11463,6 +12242,7 @@ function activate(ctx, config) {
|
|
|
11463
12242
|
if (captureSearchProvider !== void 0) {
|
|
11464
12243
|
if (policy.primaryProvider === "none") throw new WebError("web search is disabled by the primary search provider setting", "WEB_PROVIDER_UNAVAILABLE");
|
|
11465
12244
|
const startedGeneration = generation;
|
|
12245
|
+
const account = accountProof(signal, policy.primaryProvider === "auto" ? selection?.provider : void 0);
|
|
11466
12246
|
const registrations = [];
|
|
11467
12247
|
let usingManagedPrimary = false;
|
|
11468
12248
|
let configuredProofInvalid = false;
|
|
@@ -11509,10 +12289,11 @@ function activate(ctx, config) {
|
|
|
11509
12289
|
const boundSignal = AbortSignal.any([
|
|
11510
12290
|
...signal === void 0 ? [] : [signal],
|
|
11511
12291
|
proofCancellation.signal,
|
|
12292
|
+
account.cancellation.signal,
|
|
11512
12293
|
plansFor(owner).cancellation.signal,
|
|
11513
12294
|
...registrations.map((provider) => provider.signal)
|
|
11514
12295
|
]);
|
|
11515
|
-
const canContinue = () => active && generation === startedGeneration && !disposedOwners.has(owner) && !configuredProofInvalid && registrations.every((provider) => provider.current()) && (!usingManagedPrimary || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
12296
|
+
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
12297
|
return routeSearchTools(request, boundSignal, {
|
|
11517
12298
|
primary,
|
|
11518
12299
|
fallback,
|
|
@@ -11526,15 +12307,17 @@ function activate(ctx, config) {
|
|
|
11526
12307
|
if (!useNative && defaultProviderId === "none") throw new WebError("web search is disabled by github-copilot-search-routing.defaultSearchProvider", "WEB_PROVIDER_UNAVAILABLE");
|
|
11527
12308
|
if (!useNative && defaultProviderId !== "github-copilot-hosted" && selectProvider === void 0) return delegate(request, signal);
|
|
11528
12309
|
const startedGeneration = generation;
|
|
12310
|
+
const account = accountProof(signal, useNative ? selection?.provider : void 0);
|
|
11529
12311
|
const managedPreview = useNative && managedOwned ? ctx.get("githubCopilotPreview") : void 0;
|
|
11530
12312
|
const managedProof = managedPreview?.captureSearchProof();
|
|
11531
12313
|
const ownerSignal = plansFor(owner).cancellation.signal;
|
|
11532
12314
|
const boundSignal = AbortSignal.any([
|
|
11533
12315
|
...signal === void 0 ? [] : [signal],
|
|
11534
12316
|
proofCancellation.signal,
|
|
12317
|
+
account.cancellation.signal,
|
|
11535
12318
|
ownerSignal
|
|
11536
12319
|
]);
|
|
11537
|
-
const canContinue = () => active && generation === startedGeneration && !disposedOwners.has(owner) && (!useNative || !managedOwned || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
12320
|
+
const canContinue = () => active && generation === startedGeneration && !account.cancellation.signal.aborted && !disposedOwners.has(owner) && (!useNative || !managedOwned || ctx.get("githubCopilotPreview") === managedPreview && managedProof?.() === true);
|
|
11538
12321
|
if (!useNative) {
|
|
11539
12322
|
if (defaultProviderId === "github-copilot-hosted") return configuredSearch(request, boundSignal);
|
|
11540
12323
|
return selectProvider(defaultProviderId, request, boundSignal);
|
|
@@ -11549,11 +12332,26 @@ function activate(ctx, config) {
|
|
|
11549
12332
|
canContinue
|
|
11550
12333
|
})).result;
|
|
11551
12334
|
} });
|
|
12335
|
+
function searchSettingsSignature() {
|
|
12336
|
+
const { activeAccountId: _global, sessionAccounts: _sessions, ...settings } = current();
|
|
12337
|
+
return JSON.stringify({
|
|
12338
|
+
settings,
|
|
12339
|
+
routing: readRouting()
|
|
12340
|
+
});
|
|
12341
|
+
}
|
|
12342
|
+
let settingsSignature = searchSettingsSignature();
|
|
11552
12343
|
observeSettingsNamespace(ctx, GITHUB_COPILOT_SETTINGS_NAMESPACE, config, {
|
|
11553
12344
|
setSource: (source) => {
|
|
11554
12345
|
current = source;
|
|
12346
|
+
settingsSignature = searchSettingsSignature();
|
|
11555
12347
|
},
|
|
11556
|
-
onChange:
|
|
12348
|
+
onChange: () => {
|
|
12349
|
+
const next = searchSettingsSignature();
|
|
12350
|
+
if (next !== settingsSignature) {
|
|
12351
|
+
settingsSignature = next;
|
|
12352
|
+
invalidatePlans();
|
|
12353
|
+
}
|
|
12354
|
+
}
|
|
11557
12355
|
});
|
|
11558
12356
|
ensureGitHubCopilotProviderProfile(ctx).catch((error) => {
|
|
11559
12357
|
ctx.logger.error("github-copilot: failed to repair the GitHub Copilot provider route during startup");
|
|
@@ -11574,7 +12372,11 @@ function activate(ctx, config) {
|
|
|
11574
12372
|
signal: AbortSignal.any(signals)
|
|
11575
12373
|
};
|
|
11576
12374
|
return (async function* () {
|
|
11577
|
-
|
|
12375
|
+
if (operation.signal.aborted) {
|
|
12376
|
+
yield* inlineWireStream(operation, p, hooks, cfg);
|
|
12377
|
+
return;
|
|
12378
|
+
}
|
|
12379
|
+
const lease = acquireAccount(operation.signal, operation.provider);
|
|
11578
12380
|
try {
|
|
11579
12381
|
yield* inlineWireStream(operation, p, hooks, cfg);
|
|
11580
12382
|
} finally {
|
|
@@ -11594,7 +12396,7 @@ function activate(ctx, config) {
|
|
|
11594
12396
|
const cfg = current();
|
|
11595
12397
|
if (route === void 0 || cfg.providers.length > 0 && !cfg.providers.includes(route.provider)) return "";
|
|
11596
12398
|
const cached = ownerPlans.get(owner)?.inline;
|
|
11597
|
-
const nativeGuidance = servingPrompt(current, matches(cached, route, candidatesForRoute(route), cfg) ? cached.plan : void 0);
|
|
12399
|
+
const nativeGuidance = servingPrompt(current, matches(cached, route, candidatesForRoute(route), cfg, route.provider) ? cached.plan : void 0);
|
|
11598
12400
|
const owned = route.provider === "github-copilot-preview" && isPluginPreviewProvider(ctx, route.provider);
|
|
11599
12401
|
if (!cfg.enabled || cfg.routeWebSearch === false || ctx.get("githubCopilotOriginalWeb") === void 0 || !isCopilotSearchSelection(route, owned)) return nativeGuidance;
|
|
11600
12402
|
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");
|