dsh-github-copilot 0.4.0-alpha.104 → 0.4.0-alpha.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1348,7 +1348,7 @@ var Budget = class {
1348
1348
  if (this.consumed > ACCOUNT_MODEL_CATALOG_LIMITS.maxBytes) fail$1("CATALOG_TOO_LARGE", true);
1349
1349
  }
1350
1350
  };
1351
- function record$10(value, code) {
1351
+ function record$12(value, code) {
1352
1352
  if (typeof value !== "object" || value === null || Array.isArray(value)) fail$1(code);
1353
1353
  return value;
1354
1354
  }
@@ -1401,11 +1401,11 @@ function normalizeModel(raw, id, options, budget) {
1401
1401
  if (options.availableModelIds?.has(id) !== true) fail$1("MISSING_POLICY");
1402
1402
  policySource = "account-available-id";
1403
1403
  } else {
1404
- if (text$2(field(record$10(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail$1("POLICY_NOT_ENABLED");
1404
+ if (text$2(field(record$12(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail$1("POLICY_NOT_ENABLED");
1405
1405
  policySource = "server-enabled";
1406
1406
  }
1407
- const capabilities = record$10(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
1408
- const supports = record$10(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
1407
+ const capabilities = record$12(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
1408
+ const supports = record$12(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
1409
1409
  const streaming = field(supports, "streaming", budget);
1410
1410
  if (streaming === false) fail$1("STREAMING_UNSUPPORTED");
1411
1411
  if (streaming !== true) fail$1("INVALID_SUPPORTS");
@@ -1426,7 +1426,7 @@ function normalizeModel(raw, id, options, budget) {
1426
1426
  if (selected === void 0) fail$1(unsupportedEndpointCount === 0 && endpoints.includes("ws:/responses") ? "WEBSOCKET_ONLY" : "UNSUPPORTED_ENDPOINTS");
1427
1427
  const rawLimits = field(capabilities, "limits", budget);
1428
1428
  if (rawLimits === void 0) fail$1("MISSING_LIMITS");
1429
- const limits = record$10(rawLimits, "INVALID_LIMITS");
1429
+ const limits = record$12(rawLimits, "INVALID_LIMITS");
1430
1430
  const maxContext = optionalPositive(limits, "max_context_window_tokens", "INVALID_LIMITS", budget);
1431
1431
  const maxInputTokens = optionalPositive(limits, "max_prompt_tokens", "INVALID_LIMITS", budget);
1432
1432
  if (maxContext === void 0 && maxInputTokens === void 0) fail$1("MISSING_CONTEXT_LIMIT");
@@ -1444,7 +1444,7 @@ function normalizeModel(raw, id, options, budget) {
1444
1444
  if (vision === true) {
1445
1445
  const rawVisionLimits = field(limits, "vision", budget);
1446
1446
  if (rawVisionLimits !== void 0) {
1447
- const rawMediaTypes = field(record$10(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
1447
+ const rawMediaTypes = field(record$12(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
1448
1448
  if (rawMediaTypes !== void 0) {
1449
1449
  const mediaTypes = stringList(rawMediaTypes, ACCOUNT_MODEL_CATALOG_LIMITS.maxMediaTypes, 128, "INVALID_VISION_LIMITS", budget);
1450
1450
  const mime = /^[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*\/[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*$/iu;
@@ -1506,7 +1506,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
1506
1506
  fail$1("INVALID_JSON", true);
1507
1507
  }
1508
1508
  }
1509
- const data = field(record$10(raw, "INVALID_CATALOG"), "data", budget);
1509
+ const data = field(record$12(raw, "INVALID_CATALOG"), "data", budget);
1510
1510
  if (!Array.isArray(data)) fail$1("INVALID_CATALOG");
1511
1511
  const count = field(data, "length", budget);
1512
1512
  if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) fail$1("INVALID_CATALOG");
@@ -1529,7 +1529,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
1529
1529
  for (let index = 0; index < count; index++) {
1530
1530
  let id;
1531
1531
  try {
1532
- const candidate = record$10(field(data, String(index), budget), "INVALID_MODEL");
1532
+ const candidate = record$12(field(data, String(index), budget), "INVALID_MODEL");
1533
1533
  const candidateId = text$2(field(candidate, "id", budget), ACCOUNT_MODEL_CATALOG_LIMITS.maxIdLength, "INVALID_ID", budget);
1534
1534
  if (!identifier.test(candidateId)) fail$1("INVALID_ID");
1535
1535
  id = candidateId;
@@ -2448,7 +2448,7 @@ const REQUEST_BODY_TIMEOUT_MARKER = "COPILOT_REQUEST_BODY_TIMEOUT: Copilot retur
2448
2448
  function object$6(value) {
2449
2449
  return typeof value === "object" && value !== null;
2450
2450
  }
2451
- function count$2(value) {
2451
+ function count$3(value) {
2452
2452
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
2453
2453
  }
2454
2454
  /** Observe public native events only; never read request fields, mutate transport or imply remote receipt. */
@@ -2460,7 +2460,7 @@ function createRequestUploadObserver() {
2460
2460
  let socket;
2461
2461
  let connectionAmbiguous = false, socketBoundToRequest = false;
2462
2462
  let alpn = "unavailable", nodeWritableBufferBytes;
2463
- const elapsed = () => startedAt === void 0 ? void 0 : count$2(Math.round(performance.now() - startedAt));
2463
+ const elapsed = () => startedAt === void 0 ? void 0 : count$3(Math.round(performance.now() - startedAt));
2464
2464
  const request = (data) => !closed && object$6(data) && object$6(data.request) ? requests.get(data.request) : void 0;
2465
2465
  const connected = (data, boundToRequest = false) => {
2466
2466
  if (closed || !object$6(data) || !object$6(data.socket)) return;
@@ -2495,7 +2495,7 @@ function createRequestUploadObserver() {
2495
2495
  if (request(data) !== 1 || bodyWrite) return;
2496
2496
  bodyWrite = true;
2497
2497
  bodyWriteCompleteMs = elapsed();
2498
- nodeWritableBufferBytes = count$2(socket?.writableLength);
2498
+ nodeWritableBufferBytes = count$3(socket?.writableLength);
2499
2499
  },
2500
2500
  "undici:request:headers": (data) => {
2501
2501
  if (request(data) === 1 && nativeResponseHeadersMs === void 0) nativeResponseHeadersMs = elapsed();
@@ -2545,16 +2545,16 @@ function formatRequestUploadEvidence(evidence) {
2545
2545
  //#endregion
2546
2546
  //#region lib/types/request-body-timeout.js
2547
2547
  const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
2548
- function record$9(value) {
2548
+ function record$11(value) {
2549
2549
  return typeof value === "object" && value !== null && !Array.isArray(value);
2550
2550
  }
2551
2551
  /** Verified provider evidence, not guessed capabilities, token limits or network cause. */
2552
2552
  async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
2553
2553
  if (response.status !== 408 || signal?.aborted) return void 0;
2554
2554
  const value = await readResponseErrorJson(response, signal);
2555
- if (signal?.aborted || !record$9(value)) return void 0;
2555
+ if (signal?.aborted || !record$11(value)) return void 0;
2556
2556
  const error = Object.hasOwn(value, "error") ? value.error : value;
2557
- if (!record$9(error) || error.code !== "user_request_timeout" || error.message !== observedMessage || value.code !== void 0 && value.code !== error.code || value.message !== void 0 && value.message !== error.message) return void 0;
2557
+ if (!record$11(error) || error.code !== "user_request_timeout" || error.message !== observedMessage || value.code !== void 0 && value.code !== error.code || value.message !== void 0 && value.message !== error.message) return void 0;
2558
2558
  const size = body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`;
2559
2559
  const composition = formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs);
2560
2560
  const upload = formatRequestUploadEvidence(dispatch?.upload);
@@ -2989,7 +2989,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
2989
2989
  var package_default = {
2990
2990
  name: "dsh-github-copilot",
2991
2991
  description: "DSH companion for GitHub Copilot sign-in, account-aware model profiles, tool compatibility, and provider-hosted search.",
2992
- version: "0.4.0-alpha.104",
2992
+ version: "0.4.0-alpha.106",
2993
2993
  publishConfig: {
2994
2994
  "access": "public",
2995
2995
  "registry": "https://registry.npmjs.org/",
@@ -3414,6 +3414,7 @@ var __esDecorate$5 = 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 {
@@ -3457,6 +3458,8 @@ var CopilotAccountsHost = class {
3457
3458
  accountLeases = /* @__PURE__ */ new Map();
3458
3459
  identities = /* @__PURE__ */ new Map();
3459
3460
  unavailableIdentities = /* @__PURE__ */ new Set();
3461
+ identityFlights = /* @__PURE__ */ new Map();
3462
+ identityFailures = /* @__PURE__ */ new Map();
3460
3463
  listeners = /* @__PURE__ */ new Set();
3461
3464
  abort = new AbortController();
3462
3465
  operation;
@@ -3496,6 +3499,7 @@ var CopilotAccountsHost = class {
3496
3499
  }
3497
3500
  revoke(clearIdentity = true) {
3498
3501
  this.generation++;
3502
+ for (const accountId of this.identityFlights.keys()) this.invalidateIdentity(accountId);
3499
3503
  if (clearIdentity) {
3500
3504
  this.identities.clear();
3501
3505
  this.unavailableIdentities.clear();
@@ -3516,9 +3520,15 @@ var CopilotAccountsHost = class {
3516
3520
  credentialChanged(key) {
3517
3521
  if (!isCopilotAccountRecord(key)) return;
3518
3522
  const accountId = key === "llm-pi-ai/github-copilot" ? "canonical" : key.slice(23);
3523
+ this.invalidateIdentity(accountId);
3519
3524
  this.identities.delete(accountId);
3520
3525
  this.unavailableIdentities.delete(accountId);
3521
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
+ }
3522
3532
  onChanged(listener) {
3523
3533
  this.listeners.add(listener);
3524
3534
  return () => {
@@ -3696,6 +3706,7 @@ var CopilotAccountsHost = class {
3696
3706
  const latest = await store.read(GITHUB_COPILOT_PROVIDER_ID);
3697
3707
  if (!latest || copilotAccountKey(normalizeGitHubCopilotOAuthCredential(latest)) !== before) fail("COPILOT_ACCOUNTS_CHANGED");
3698
3708
  binding.assertCurrent();
3709
+ signal.throwIfAborted();
3699
3710
  const previous = this.identities.get(binding.accountId);
3700
3711
  if (previous && previous.identity.userId !== identity.userId) fail("COPILOT_ACCOUNTS_IDENTITY_CHANGED");
3701
3712
  if (!this.identities.has(binding.accountId) && this.identities.size >= 32) this.identities.delete(this.identities.keys().next().value);
@@ -3708,6 +3719,23 @@ var CopilotAccountsHost = class {
3708
3719
  return identity;
3709
3720
  }
3710
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) {
3711
3739
  if (grant.enterpriseUrl !== void 0) fail("COPILOT_ACCOUNTS_ENTERPRISE_UNSUPPORTED");
3712
3740
  signal.throwIfAborted();
3713
3741
  const response = await abortable$1((this.dependencies.fetch ?? globalThis.fetch)("https://api.github.com/user", {
@@ -3723,7 +3751,7 @@ var CopilotAccountsHost = class {
3723
3751
  }), signal);
3724
3752
  if (!response.ok || response.redirected || !response.body) {
3725
3753
  response.body?.cancel().catch(() => void 0);
3726
- fail("COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE");
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");
3727
3755
  }
3728
3756
  const reader = response.body.getReader();
3729
3757
  const chunks = [];
@@ -3734,7 +3762,7 @@ var CopilotAccountsHost = class {
3734
3762
  signal.addEventListener("abort", cancel, { once: true });
3735
3763
  try {
3736
3764
  while (true) {
3737
- if (signal.aborted) fail("COPILOT_ACCOUNTS_CHANGED");
3765
+ signal.throwIfAborted();
3738
3766
  const chunk = await abortable$1(reader.read(), signal);
3739
3767
  if (chunk.done) break;
3740
3768
  bytes += chunk.value.byteLength;
@@ -3748,7 +3776,7 @@ var CopilotAccountsHost = class {
3748
3776
  signal.removeEventListener("abort", cancel);
3749
3777
  reader.releaseLock();
3750
3778
  }
3751
- if (signal.aborted) fail("COPILOT_ACCOUNTS_CHANGED");
3779
+ signal.throwIfAborted();
3752
3780
  const buffer = new Uint8Array(bytes);
3753
3781
  let offset = 0;
3754
3782
  for (const chunk of chunks) {
@@ -3768,42 +3796,92 @@ var CopilotAccountsHost = class {
3768
3796
  });
3769
3797
  }
3770
3798
  async refreshIdentity() {
3771
- let lease;
3772
3799
  try {
3773
- lease = this.acquire(void 0, false);
3774
- await this.identity(lease.binding, AbortSignal.any([this.abort.signal, AbortSignal.timeout(TIMEOUT)]));
3775
- this.lastFailure = void 0;
3800
+ const view = await this.refreshIdentityFor(this.selection().accountId);
3801
+ if (view.state === "ready") this.lastFailure = void 0;
3802
+ return view;
3776
3803
  } catch (error) {
3777
- if (lease) {
3778
- this.identities.delete(lease.binding.accountId);
3779
- this.unavailableIdentities.add(lease.binding.accountId);
3780
- }
3781
3804
  this.lastFailure = diagnostic(error, "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE");
3782
- } finally {
3783
- lease?.release();
3784
3805
  }
3785
3806
  return this.get();
3786
3807
  }
3787
- async viewForAccount(accountId) {
3788
- return this.accountView(accountId);
3789
- }
3790
- async refreshIdentityFor(accountId) {
3791
- const lease = this.acquire(void 0, false, accountId);
3808
+ async ensureIdentity() {
3792
3809
  try {
3793
- await this.identity(lease.binding, AbortSignal.any([this.abort.signal, AbortSignal.timeout(TIMEOUT)]));
3810
+ return await this.ensureIdentityFor(this.selection().accountId);
3794
3811
  } catch (error) {
3795
- this.identities.delete(accountId);
3796
- this.unavailableIdentities.add(accountId);
3797
3812
  return {
3798
- ...await this.viewForAccount(accountId),
3813
+ ...await this.get(),
3799
3814
  state: "error",
3800
3815
  switchable: false,
3801
3816
  diagnostic: diagnostic(error, "COPILOT_ACCOUNTS_IDENTITY_UNAVAILABLE")
3802
3817
  };
3803
- } finally {
3804
- lease.release();
3805
3818
  }
3806
- return this.viewForAccount(accountId);
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
+ };
3807
3885
  }
3808
3886
  async validateModels(binding, signal) {
3809
3887
  try {
@@ -4105,6 +4183,7 @@ var CopilotAccountsHost = class {
4105
4183
  this.authorizationAbort?.abort();
4106
4184
  this.abort.abort();
4107
4185
  this.revoke();
4186
+ this.identityFailures.clear();
4108
4187
  for (const release of this.leases) release();
4109
4188
  for (const leases of this.accountLeases.values()) for (const release of leases) release();
4110
4189
  this.listeners.clear();
@@ -4123,6 +4202,7 @@ let GitHubCopilotAccountsController = (() => {
4123
4202
  let _instanceExtraInitializers = [];
4124
4203
  let _get_decorators;
4125
4204
  let _refreshIdentity_decorators;
4205
+ let _ensureIdentity_decorators;
4126
4206
  let _add_decorators;
4127
4207
  let _cancel_decorators;
4128
4208
  let _reauthorize_decorators;
@@ -4133,6 +4213,7 @@ let GitHubCopilotAccountsController = (() => {
4133
4213
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
4134
4214
  _get_decorators = [Remote];
4135
4215
  _refreshIdentity_decorators = [Remote];
4216
+ _ensureIdentity_decorators = [Remote];
4136
4217
  _add_decorators = [Remote];
4137
4218
  _cancel_decorators = [Remote];
4138
4219
  _reauthorize_decorators = [Remote];
@@ -4160,6 +4241,17 @@ let GitHubCopilotAccountsController = (() => {
4160
4241
  },
4161
4242
  metadata: _metadata
4162
4243
  }, null, _instanceExtraInitializers);
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);
4163
4255
  __esDecorate$5(this, null, _add_decorators, {
4164
4256
  kind: "method",
4165
4257
  name: "add",
@@ -4238,6 +4330,9 @@ let GitHubCopilotAccountsController = (() => {
4238
4330
  refreshIdentity() {
4239
4331
  return this.host.refreshIdentity();
4240
4332
  }
4333
+ ensureIdentity() {
4334
+ return this.host.ensureIdentity();
4335
+ }
4241
4336
  add() {
4242
4337
  return this.host.add();
4243
4338
  }
@@ -4956,6 +5051,7 @@ let SessionAccountController = (() => {
4956
5051
  let _get_decorators;
4957
5052
  let _set_decorators;
4958
5053
  let _refreshIdentity_decorators;
5054
+ let _ensureIdentity_decorators;
4959
5055
  let _usage_decorators;
4960
5056
  let _refreshUsage_decorators;
4961
5057
  let _turn_decorators;
@@ -4965,6 +5061,7 @@ let SessionAccountController = (() => {
4965
5061
  _get_decorators = [Remote];
4966
5062
  _set_decorators = [Remote];
4967
5063
  _refreshIdentity_decorators = [Remote];
5064
+ _ensureIdentity_decorators = [Remote];
4968
5065
  _usage_decorators = [Remote];
4969
5066
  _refreshUsage_decorators = [Remote];
4970
5067
  _turn_decorators = [Remote];
@@ -5001,6 +5098,17 @@ let SessionAccountController = (() => {
5001
5098
  },
5002
5099
  metadata: _metadata
5003
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);
5004
5112
  __esDecorate$3(this, null, _usage_decorators, {
5005
5113
  kind: "method",
5006
5114
  name: "usage",
@@ -5066,10 +5174,16 @@ let SessionAccountController = (() => {
5066
5174
  return this.get(agent);
5067
5175
  }
5068
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) {
5069
5183
  const selected = this.owner.selected(agent);
5070
5184
  const accounts = this.ctx.get("githubCopilotAccounts");
5071
5185
  if (!accounts) throw new Error("COPILOT_SESSION_ACCOUNTS_UNAVAILABLE");
5072
- const identity = await accounts.host.refreshIdentityFor(selected.accountId);
5186
+ const identity = await (force ? accounts.host.refreshIdentityFor(selected.accountId) : accounts.host.ensureIdentityFor(selected.accountId));
5073
5187
  const latest = await this.get(agent);
5074
5188
  if (latest.accountId !== selected.accountId || latest.source !== selected.source) throw new Error("COPILOT_ACCOUNTS_CHANGED");
5075
5189
  return {
@@ -5111,14 +5225,14 @@ function isZeroContextUsage(usage) {
5111
5225
  //#endregion
5112
5226
  //#region lib/types/context-evidence.js
5113
5227
  const COPILOT_CONTEXT_EVIDENCE = "githubCopilotContextEvidence";
5114
- const count$1 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
5228
+ const count$2 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
5115
5229
  const routeSchema = z$1.object({
5116
5230
  provider: z$1.string().min(1),
5117
5231
  model: z$1.string().min(1)
5118
5232
  }).strict();
5119
5233
  const sampleSchema = z$1.object({
5120
- tokens: count$1,
5121
- seq: count$1,
5234
+ tokens: count$2,
5235
+ seq: count$2,
5122
5236
  route: routeSchema
5123
5237
  }).strict();
5124
5238
  const ContextEvidenceSchema = z$1.object({
@@ -5134,14 +5248,14 @@ const ContextEvidenceSchema = z$1.object({
5134
5248
  ])
5135
5249
  }).strict();
5136
5250
  const usageSchema = z$1.object({
5137
- inputTokens: count$1,
5138
- outputTokens: count$1,
5139
- cacheReadTokens: count$1.optional(),
5140
- cacheWriteTokens: count$1.optional(),
5141
- totalTokens: count$1.optional(),
5142
- reasoningTokens: count$1.optional()
5251
+ inputTokens: count$2,
5252
+ outputTokens: count$2,
5253
+ cacheReadTokens: count$2.optional(),
5254
+ cacheWriteTokens: count$2.optional(),
5255
+ totalTokens: count$2.optional(),
5256
+ reasoningTokens: count$2.optional()
5143
5257
  });
5144
- function record$8(value) {
5258
+ function record$10(value) {
5145
5259
  return typeof value === "object" && value !== null && !Array.isArray(value);
5146
5260
  }
5147
5261
  function sameRoute$1(left, right) {
@@ -5160,10 +5274,10 @@ function initialContextEvidence() {
5160
5274
  }
5161
5275
  /** Read only counts and routing leaves; never message content or opaque replay. */
5162
5276
  function foldContextEvidence(state, event) {
5163
- if (!record$8(event) || typeof event.type !== "string" || !record$8(event.data)) return state;
5277
+ if (!record$10(event) || typeof event.type !== "string" || !record$10(event.data)) return state;
5164
5278
  if (event.type === "request/header" || event.type === "model/selection") {
5165
- const raw = event.type === "request/header" ? record$8(event.data.header) ? event.data.header.config : void 0 : event.data;
5166
- if (!record$8(raw)) return {
5279
+ const raw = event.type === "request/header" ? record$10(event.data.header) ? event.data.header.config : void 0 : event.data;
5280
+ if (!record$10(raw)) return {
5167
5281
  ...state,
5168
5282
  route: null,
5169
5283
  sample: null,
@@ -5202,7 +5316,7 @@ function foldContextEvidence(state, event) {
5202
5316
  if (!copilot(state.route)) return state;
5203
5317
  if (event.type === "assistant/message" && event.data.source !== void 0) {
5204
5318
  const source = event.data.source;
5205
- const parsed = routeSchema.safeParse(record$8(source) ? {
5319
+ const parsed = routeSchema.safeParse(record$10(source) ? {
5206
5320
  provider: source.provider,
5207
5321
  model: source.model
5208
5322
  } : source);
@@ -5218,13 +5332,13 @@ function foldContextEvidence(state, event) {
5218
5332
  const settledUsage = usage !== void 0;
5219
5333
  let terminal;
5220
5334
  for (const entry of stream) {
5221
- if (!record$8(entry) || entry.type !== "chunk" || !record$8(entry.chunk)) continue;
5335
+ if (!record$10(entry) || entry.type !== "chunk" || !record$10(entry.chunk)) continue;
5222
5336
  if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
5223
5337
  if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
5224
5338
  }
5225
5339
  if (usage === void 0) return state;
5226
5340
  const parsed = usageSchema.safeParse(usage);
5227
- if (!parsed.success || !count$1.safeParse(event.seq).success) return {
5341
+ if (!parsed.success || !count$2.safeParse(event.seq).success) return {
5228
5342
  ...state,
5229
5343
  sample: null,
5230
5344
  invalid: true,
@@ -5232,7 +5346,7 @@ function foldContextEvidence(state, event) {
5232
5346
  };
5233
5347
  const value = parsed.data;
5234
5348
  const zero = isZeroContextUsage(value);
5235
- const successful = record$8(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
5349
+ const successful = record$10(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
5236
5350
  if (zero && !successful) {
5237
5351
  const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
5238
5352
  return {
@@ -5252,7 +5366,7 @@ function foldContextEvidence(state, event) {
5252
5366
  ...state,
5253
5367
  sample: {
5254
5368
  tokens,
5255
- seq: count$1.parse(event.seq),
5369
+ seq: count$2.parse(event.seq),
5256
5370
  route: state.route
5257
5371
  },
5258
5372
  invalid: false,
@@ -5274,7 +5388,7 @@ const contextEvidenceDefinition = {
5274
5388
  function installContextEvidence(ctx) {
5275
5389
  ctx.inject(["sessionProjections"], (scope) => {
5276
5390
  const registry = scope.get("sessionProjections");
5277
- if (!record$8(registry) || typeof registry.register !== "function") {
5391
+ if (!record$10(registry) || typeof registry.register !== "function") {
5278
5392
  scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
5279
5393
  return;
5280
5394
  }
@@ -6307,7 +6421,7 @@ function buildAnthropicWireBody(request, cfg, model) {
6307
6421
  }
6308
6422
  //#endregion
6309
6423
  //#region lib/types/responses-reasoning-text.js
6310
- function record$7(value) {
6424
+ function record$9(value) {
6311
6425
  return typeof value === "object" && value !== null;
6312
6426
  }
6313
6427
  function responseIndex(value) {
@@ -6365,13 +6479,13 @@ var ResponsesReasoningText = class {
6365
6479
  }
6366
6480
  /** Only recognized public text fields are examined; no copying of the item. */
6367
6481
  snapshot(item) {
6368
- if (!record$7(item) || item.type !== "reasoning") return "";
6482
+ if (!record$9(item) || item.type !== "reasoning") return "";
6369
6483
  let delta = "";
6370
6484
  for (const family of ["summary", "raw"]) {
6371
6485
  const value = family === "summary" ? item.summary : item.content;
6372
6486
  if (!Array.isArray(value)) continue;
6373
6487
  for (const [index, part] of value.entries()) {
6374
- if (!record$7(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
6488
+ if (!record$9(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
6375
6489
  delta += this.update(family, index, part.text, true);
6376
6490
  }
6377
6491
  }
@@ -8619,13 +8733,13 @@ function resolveCopilotResponsesReasoning(ctx, request, candidate) {
8619
8733
  }
8620
8734
  //#endregion
8621
8735
  //#region lib/types/replay-recovery.js
8622
- function record$6(value) {
8736
+ function record$8(value) {
8623
8737
  return value !== null && typeof value === "object" && !Array.isArray(value);
8624
8738
  }
8625
8739
  function parsed(body) {
8626
8740
  if (requestBodyEvidence(body, "openai-responses").state !== "complete" || body === void 0) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
8627
8741
  const payload = JSON.parse(body);
8628
- if (!record$6(payload) || !Array.isArray(payload.input) || !payload.input.every(record$6)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
8742
+ if (!record$8(payload) || !Array.isArray(payload.input) || !payload.input.every(record$8)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
8629
8743
  return {
8630
8744
  input: payload.input,
8631
8745
  payload
@@ -8721,7 +8835,7 @@ var ReplayRecoveryStore = class {
8721
8835
  const value = hash(item);
8722
8836
  return value === void 0 || !admitted.has(value);
8723
8837
  }).length === decoded.input.length) return payload;
8724
- if (!record$6(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
8838
+ if (!record$8(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
8725
8839
  const input = payload.input.filter((_, index) => {
8726
8840
  const item = decoded.input[index];
8727
8841
  const value = hash(item);
@@ -8921,7 +9035,7 @@ function installReplayRecovery(ctx, proof) {
8921
9035
  }
8922
9036
  //#endregion
8923
9037
  //#region lib/types/agent-compaction.js
8924
- function record$5(value) {
9038
+ function record$7(value) {
8925
9039
  return typeof value === "object" && value !== null;
8926
9040
  }
8927
9041
  /** Resolve the owning preset's service without reaching into Core's service registry. */
@@ -8929,7 +9043,7 @@ function agentCompaction(agent) {
8929
9043
  if (typeof agent.ctx?.get !== "function") throw new LlmError("COPILOT_COMPACTION_AGENT_CONTEXT_UNAVAILABLE", "INVALID_REQUEST");
8930
9044
  const presets = agent.ctx.get("agentPresets");
8931
9045
  if (presets !== void 0) {
8932
- if (!record$5(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
9046
+ if (!record$7(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
8933
9047
  const preset = presets.composedPreset(agent.ctx);
8934
9048
  if (preset !== void 0) {
8935
9049
  if (typeof preset !== "string" || preset.trim().length === 0) throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
@@ -9052,14 +9166,14 @@ function installCopilotCompactionPressure(ctx, callbacks) {
9052
9166
  }
9053
9167
  //#endregion
9054
9168
  //#region lib/types/pre-step-pressure.js
9055
- function record$4(value) {
9169
+ function record$6(value) {
9056
9170
  return typeof value === "object" && value !== null && !Array.isArray(value);
9057
9171
  }
9058
9172
  function positive(value) {
9059
9173
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
9060
9174
  }
9061
9175
  function isEngine(value) {
9062
- return record$4(value) && record$4(value.config) && typeof value.compactIfNeeded === "function";
9176
+ return record$6(value) && record$6(value.config) && typeof value.compactIfNeeded === "function";
9063
9177
  }
9064
9178
  /**
9065
9179
  * Prevent a continuing, unchanged route's known pressure from becoming an
@@ -9080,12 +9194,12 @@ function installCopilotPreStepPressure(ctx, callbacks) {
9080
9194
  const header = agent.session.requestHeader();
9081
9195
  if (header?.config.provider !== "github-copilot-preview" || !isPluginPreviewProvider(ctx, header.config.provider)) return decision;
9082
9196
  const projections = ctx.get("sessionProjections");
9083
- if (!record$4(projections) || typeof projections.stateOf !== "function") {
9197
+ if (!record$6(projections) || typeof projections.stateOf !== "function") {
9084
9198
  unavailable();
9085
9199
  return decision;
9086
9200
  }
9087
9201
  const selection = projections.stateOf(agent.session, "modelSelection");
9088
- if (!record$4(selection) || !Object.hasOwn(selection, "pending")) {
9202
+ if (!record$6(selection) || !Object.hasOwn(selection, "pending")) {
9089
9203
  unavailable();
9090
9204
  return decision;
9091
9205
  }
@@ -9107,20 +9221,20 @@ function installCopilotPreStepPressure(ctx, callbacks) {
9107
9221
  unavailable();
9108
9222
  return decision;
9109
9223
  }
9110
- const policy = Array.isArray(config.modelPolicies) ? config.modelPolicies.find((value) => record$4(value) && value.provider === header.config.provider && value.model === header.config.model) : void 0;
9111
- const retries = record$4(policy) ? policy.maxOverflowRetries ?? config.maxOverflowRetries : config.maxOverflowRetries;
9224
+ const policy = Array.isArray(config.modelPolicies) ? config.modelPolicies.find((value) => record$6(value) && value.provider === header.config.provider && value.model === header.config.model) : void 0;
9225
+ const retries = record$6(policy) ? policy.maxOverflowRetries ?? config.maxOverflowRetries : config.maxOverflowRetries;
9112
9226
  if (retries === 0) return decision;
9113
9227
  if (!positive(retries)) {
9114
9228
  unavailable();
9115
9229
  return decision;
9116
9230
  }
9117
9231
  const meter = ctx.get("tokenMeter");
9118
- if (!record$4(meter) || typeof meter.measure !== "function") {
9232
+ if (!record$6(meter) || typeof meter.measure !== "function") {
9119
9233
  unavailable();
9120
9234
  return decision;
9121
9235
  }
9122
9236
  const measured = meter.measure(agent.session);
9123
- if (!record$4(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) {
9237
+ if (!record$6(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) {
9124
9238
  unavailable();
9125
9239
  return decision;
9126
9240
  }
@@ -9238,17 +9352,17 @@ const TaskAssessmentSchema = z$1.object({
9238
9352
  "insufficient-evidence"
9239
9353
  ])).max(7)
9240
9354
  }).strict();
9241
- function record$3(value) {
9355
+ function record$5(value) {
9242
9356
  return typeof value === "object" && value !== null && !Array.isArray(value);
9243
9357
  }
9244
9358
  function text(message) {
9245
- if (!record$3(message) || !Array.isArray(message.content)) return "";
9246
- return message.content.flatMap((block) => record$3(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
9359
+ if (!record$5(message) || !Array.isArray(message.content)) return "";
9360
+ return message.content.flatMap((block) => record$5(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
9247
9361
  }
9248
9362
  function user(message) {
9249
- if (!record$3(message)) return false;
9250
- if (record$3(message.source) && message.source.kind === "model-selection") return false;
9251
- return message.role === "user" || record$3(message.source) && message.source.kind === "user";
9363
+ if (!record$5(message)) return false;
9364
+ if (record$5(message.source) && message.source.kind === "model-selection") return false;
9365
+ return message.role === "user" || record$5(message.source) && message.source.kind === "user";
9252
9366
  }
9253
9367
  function difficult(current) {
9254
9368
  return /\b(prove|proof|theorem|debug|investigate|diagnose)\b|证明|定理|调试|排查|根因|调查/iu.test(current);
@@ -9265,8 +9379,8 @@ function assessTaskLocally(messages) {
9265
9379
  const last = messages.findLast(user);
9266
9380
  const current = text(last).trim();
9267
9381
  const history = messages.slice(0, last === void 0 ? 0 : messages.lastIndexOf(last));
9268
- const hasWork = history.some((message) => record$3(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$3(message.source) && message.source.kind === "model"));
9269
- const nonText = record$3(last) && Array.isArray(last.content) && last.content.some((block) => !record$3(block) || block.type !== "text");
9382
+ const hasWork = history.some((message) => record$5(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$5(message.source) && message.source.kind === "model"));
9383
+ const nonText = record$5(last) && Array.isArray(last.content) && last.content.some((block) => !record$5(block) || block.type !== "text");
9270
9384
  if (!hasWork && !nonText && /^(hello|hi|hey|你好|您好|嗨)[!!。.\s]*$/iu.test(current)) return {
9271
9385
  demand: "simple",
9272
9386
  source: "local",
@@ -9308,7 +9422,7 @@ function assessTaskLocally(messages) {
9308
9422
  /** Separate text-only projection for assessment; never mutates the chat request. */
9309
9423
  function assessmentInput(messages) {
9310
9424
  let omitted = false;
9311
- const context = messages.filter((message) => !record$3(message) || message.role !== "system" && message.role !== "developer" && !(record$3(message.source) && message.source.kind === "model-selection"));
9425
+ const context = messages.filter((message) => !record$5(message) || message.role !== "system" && message.role !== "developer" && !(record$5(message.source) && message.source.kind === "model-selection"));
9312
9426
  const lastUser = context.findLastIndex(user);
9313
9427
  const priorUser = context.slice(0, lastUser < 0 ? 0 : lastUser).findLastIndex(user);
9314
9428
  const priority = [.../* @__PURE__ */ new Set([
@@ -9320,13 +9434,13 @@ function assessmentInput(messages) {
9320
9434
  let length = 0;
9321
9435
  for (const index of priority) {
9322
9436
  const message = context[index];
9323
- if (!record$3(message)) {
9437
+ if (!record$5(message)) {
9324
9438
  omitted = true;
9325
9439
  continue;
9326
9440
  }
9327
9441
  if (!Array.isArray(message.content)) omitted = true;
9328
9442
  const content = text(message);
9329
- if (Array.isArray(message.content) && message.content.some((block) => !record$3(block) || block.type !== "text")) omitted = true;
9443
+ if (Array.isArray(message.content) && message.content.some((block) => !record$5(block) || block.type !== "text")) omitted = true;
9330
9444
  if (content.length > 1600) omitted = true;
9331
9445
  const role = typeof message.role === "string" && [
9332
9446
  "user",
@@ -9478,14 +9592,14 @@ var AutoModelRoutingError = class extends Error {
9478
9592
  this.name = "AutoModelRoutingError";
9479
9593
  }
9480
9594
  };
9481
- function record$2(value) {
9595
+ function record$4(value) {
9482
9596
  return typeof value === "object" && value !== null;
9483
9597
  }
9484
9598
  function userMessage(value) {
9485
- if (!record$2(value)) return false;
9486
- if (record$2(value.source) && value.source.kind === "model-selection") return false;
9599
+ if (!record$4(value)) return false;
9600
+ if (record$4(value.source) && value.source.kind === "model-selection") return false;
9487
9601
  if (value.role === "user") return true;
9488
- return record$2(value.source) && value.source.kind === "user";
9602
+ return record$4(value.source) && value.source.kind === "user";
9489
9603
  }
9490
9604
  function latestUserContent(messages) {
9491
9605
  for (let index = messages.length - 1; index >= 0; index--) {
@@ -9496,9 +9610,9 @@ function latestUserContent(messages) {
9496
9610
  }
9497
9611
  function classifyAutoModelTurn(messages) {
9498
9612
  let text = "";
9499
- const requiresImage = messages.some((message) => record$2(message) && Array.isArray(message.content) && message.content.some((block) => record$2(block) && block.type === "image" && block.offloaded !== true));
9613
+ const requiresImage = messages.some((message) => record$4(message) && Array.isArray(message.content) && message.content.some((block) => record$4(block) && block.type === "image" && block.offloaded !== true));
9500
9614
  for (const block of latestUserContent(messages)) {
9501
- if (!record$2(block)) continue;
9615
+ if (!record$4(block)) continue;
9502
9616
  if (block.type === "text" && typeof block.text === "string") text += `${block.text}\n`;
9503
9617
  }
9504
9618
  const codeFenceCount = text.match(/```/gu)?.length ?? 0;
@@ -9548,7 +9662,7 @@ function resolveSeed(messages, context) {
9548
9662
  if (typeof context?.seed === "string" && context.seed.length > 0) return fnv1a(context.seed);
9549
9663
  if (context?.sessionId !== void 0) return fnv1a(`${context.sessionId}:${context.turn ?? 1}`);
9550
9664
  let text = "";
9551
- for (const block of latestUserContent(messages)) if (record$2(block) && typeof block.text === "string") text += block.text;
9665
+ for (const block of latestUserContent(messages)) if (record$4(block) && typeof block.text === "string") text += block.text;
9552
9666
  return fnv1a(text || "default-auto-seed");
9553
9667
  }
9554
9668
  function targetCategory(assessment, preference) {
@@ -9756,6 +9870,138 @@ var TurnSelectionStore = class {
9756
9870
  }
9757
9871
  };
9758
9872
  //#endregion
9873
+ //#region lib/types/turn-request-models.js
9874
+ const TURN_REQUEST_MODELS = "githubCopilotTurnRequestModels";
9875
+ const count$1 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
9876
+ const route = z$1.object({
9877
+ provider: z$1.string().trim().min(1).max(1024),
9878
+ model: z$1.string().trim().min(1).max(1024)
9879
+ }).strict();
9880
+ const row = z$1.object({
9881
+ routes: z$1.array(route).max(32),
9882
+ incomplete: z$1.boolean()
9883
+ }).strict().extend({ turn: count$1 }).strict();
9884
+ const TurnRequestModelsStateSchema = z$1.object({
9885
+ active: z$1.object({
9886
+ turn: count$1,
9887
+ step: count$1.nullable()
9888
+ }).strict().nullable(),
9889
+ turns: z$1.array(row).max(128)
9890
+ }).strict();
9891
+ function record$3(value) {
9892
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9893
+ }
9894
+ const validCount = (value) => count$1.safeParse(value).success;
9895
+ function uncertain(state) {
9896
+ return {
9897
+ active: null,
9898
+ turns: state.turns.map((row) => row.turn === state.active?.turn ? {
9899
+ ...row,
9900
+ routes: [],
9901
+ incomplete: true
9902
+ } : row)
9903
+ };
9904
+ }
9905
+ function foldTurnRequestModels(state, event) {
9906
+ if (!record$3(event)) return state;
9907
+ const lifecycle = [
9908
+ "turn/start",
9909
+ "turn/end",
9910
+ "step/start",
9911
+ "step/end"
9912
+ ].includes(String(event.type));
9913
+ if (!record$3(event.data)) return lifecycle || event.type === "request/header" ? uncertain(state) : state;
9914
+ const data = event.data;
9915
+ if (lifecycle && (!validCount(data.turn) || event.type !== "turn/start" && state.active !== null && data.turn !== state.active.turn || String(event.type).startsWith("step/") && !validCount(data.step) || event.type === "step/start" && state.active?.step != null || event.type === "step/end" && state.active !== null && data.step !== state.active.step)) return uncertain(state);
9916
+ if (event.type === "turn/start" && validCount(data.turn)) return {
9917
+ active: {
9918
+ turn: data.turn,
9919
+ step: null
9920
+ },
9921
+ turns: [...state.turns.filter((row) => row.turn !== data.turn), {
9922
+ turn: data.turn,
9923
+ routes: [],
9924
+ incomplete: false
9925
+ }].slice(-128)
9926
+ };
9927
+ const active = state.active;
9928
+ if (!active) return state;
9929
+ if (event.type === "step/start" && data.turn === active.turn && validCount(data.step)) return {
9930
+ ...state,
9931
+ active: {
9932
+ ...active,
9933
+ step: data.step
9934
+ }
9935
+ };
9936
+ if (event.type === "step/end" && data.turn === active.turn && data.step === active.step) return {
9937
+ ...state,
9938
+ active: {
9939
+ ...active,
9940
+ step: null
9941
+ }
9942
+ };
9943
+ if (event.type === "turn/end" && data.turn === active.turn) return {
9944
+ ...state,
9945
+ active: null
9946
+ };
9947
+ if (event.type !== "request/header" || active.step === null) return state;
9948
+ const config = record$3(data.header) ? data.header.config : void 0;
9949
+ const parsed = route.safeParse(record$3(config) && [
9950
+ "initial",
9951
+ "resume",
9952
+ "change",
9953
+ "series"
9954
+ ].includes(String(data.reason)) ? {
9955
+ provider: config.provider,
9956
+ model: config.model
9957
+ } : void 0);
9958
+ return {
9959
+ ...state,
9960
+ turns: state.turns.map((row) => {
9961
+ if (row.turn !== active.turn) return row;
9962
+ if (!parsed.success) return {
9963
+ ...row,
9964
+ routes: [],
9965
+ incomplete: true
9966
+ };
9967
+ if (row.incomplete || row.routes.some((value) => value.provider === parsed.data.provider && value.model === parsed.data.model)) return row;
9968
+ if (row.routes.length >= 32) return {
9969
+ ...row,
9970
+ routes: [],
9971
+ incomplete: true
9972
+ };
9973
+ return {
9974
+ ...row,
9975
+ routes: [...row.routes, parsed.data]
9976
+ };
9977
+ })
9978
+ };
9979
+ }
9980
+ const turnRequestModelsDefinition = {
9981
+ key: TURN_REQUEST_MODELS,
9982
+ stateVersion: 1,
9983
+ stateSchema: TurnRequestModelsStateSchema,
9984
+ init: () => ({
9985
+ active: null,
9986
+ turns: []
9987
+ }),
9988
+ apply: foldTurnRequestModels
9989
+ };
9990
+ function installTurnRequestModels(ctx) {
9991
+ ctx.inject(["sessionProjections"], (scope) => {
9992
+ const registry = scope.get("sessionProjections");
9993
+ if (!record$3(registry) || typeof registry.register !== "function") {
9994
+ scope.logger.warn("[github-copilot] COPILOT_TURN_REQUEST_PROJECTION_UNAVAILABLE");
9995
+ return;
9996
+ }
9997
+ const remove = registry.register(turnRequestModelsDefinition);
9998
+ if (typeof remove !== "function") throw new Error("COPILOT_TURN_REQUEST_PROJECTION_DISPOSER_UNAVAILABLE");
9999
+ return () => {
10000
+ remove();
10001
+ };
10002
+ });
10003
+ }
10004
+ //#endregion
9759
10005
  //#region lib/types/turn-selection-host.js
9760
10006
  var __runInitializers = function(thisArg, initializers, value) {
9761
10007
  var useValue = arguments.length > 2;
@@ -9797,15 +10043,20 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
9797
10043
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
9798
10044
  done = true;
9799
10045
  };
10046
+ function record$2(value) {
10047
+ return typeof value === "object" && value !== null;
10048
+ }
9800
10049
  /** Public Host binding for the existing bounded, runtime-only decision store. */
9801
10050
  let TurnSelectionController = (() => {
9802
10051
  let _classSuper = TypertRemoteService;
9803
10052
  let _instanceExtraInitializers = [];
9804
10053
  let _get_decorators;
10054
+ let _requestedModels_decorators;
9805
10055
  return class TurnSelectionController extends _classSuper {
9806
10056
  static {
9807
10057
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
9808
10058
  _get_decorators = [Remote];
10059
+ _requestedModels_decorators = [Remote];
9809
10060
  __esDecorate(this, null, _get_decorators, {
9810
10061
  kind: "method",
9811
10062
  name: "get",
@@ -9817,6 +10068,17 @@ let TurnSelectionController = (() => {
9817
10068
  },
9818
10069
  metadata: _metadata
9819
10070
  }, null, _instanceExtraInitializers);
10071
+ __esDecorate(this, null, _requestedModels_decorators, {
10072
+ kind: "method",
10073
+ name: "requestedModels",
10074
+ static: false,
10075
+ private: false,
10076
+ access: {
10077
+ has: (obj) => "requestedModels" in obj,
10078
+ get: (obj) => obj.requestedModels
10079
+ },
10080
+ metadata: _metadata
10081
+ }, null, _instanceExtraInitializers);
9820
10082
  if (_metadata) Object.defineProperty(this, Symbol.metadata, {
9821
10083
  enumerable: true,
9822
10084
  configurable: true,
@@ -9828,10 +10090,24 @@ let TurnSelectionController = (() => {
9828
10090
  constructor(ctx, selections) {
9829
10091
  super(ctx, "githubCopilotTurnSelection");
9830
10092
  this.selections = selections;
10093
+ installTurnRequestModels(ctx);
9831
10094
  }
9832
10095
  get(agent, turn) {
9833
10096
  return this.selections.get(agent, turn);
9834
10097
  }
10098
+ requestedModels(agent, turn) {
10099
+ if (!Number.isSafeInteger(turn) || turn < 0) throw new Error("COPILOT_TURN_SELECTION_INVALID_TURN");
10100
+ const registry = this.ctx.get("sessionProjections");
10101
+ if (!record$2(registry) || typeof registry.stateOf !== "function") throw new Error("COPILOT_TURN_REQUEST_PROJECTION_UNAVAILABLE");
10102
+ const row = TurnRequestModelsStateSchema.parse(registry.stateOf(agent.session, TURN_REQUEST_MODELS)).turns.find((value) => value.turn === turn);
10103
+ return row ? {
10104
+ routes: row.routes,
10105
+ incomplete: row.incomplete
10106
+ } : {
10107
+ routes: [],
10108
+ incomplete: true
10109
+ };
10110
+ }
9835
10111
  };
9836
10112
  })();
9837
10113
  //#endregion