dsh-github-copilot 0.4.0-alpha.77 → 0.4.0-alpha.79

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
@@ -21,12 +21,12 @@ import { estimateContextTokens, estimateMessageTokens } from "@earendil-works/pi
21
21
  import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "@earendil-works/pi-ai/api/github-copilot-headers";
22
22
  //#region lib/types/dual-model-host.js
23
23
  /** Retired planner/executor entry points; retained policies stay enforceable without migration. */
24
- var __runInitializers$3 = function(thisArg, initializers, value) {
24
+ var __runInitializers$4 = function(thisArg, initializers, value) {
25
25
  var useValue = arguments.length > 2;
26
26
  for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
27
27
  return useValue ? value : void 0;
28
28
  };
29
- var __esDecorate$3 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
29
+ var __esDecorate$4 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
30
30
  function accept(f) {
31
31
  if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
32
32
  return f;
@@ -272,7 +272,7 @@ let GitHubCopilotDualModel = (() => {
272
272
  _view_decorators = [Remote];
273
273
  _save_decorators = [Remote];
274
274
  _create_decorators = [Remote];
275
- __esDecorate$3(this, null, _view_decorators, {
275
+ __esDecorate$4(this, null, _view_decorators, {
276
276
  kind: "method",
277
277
  name: "view",
278
278
  static: false,
@@ -283,7 +283,7 @@ let GitHubCopilotDualModel = (() => {
283
283
  },
284
284
  metadata: _metadata
285
285
  }, null, _instanceExtraInitializers);
286
- __esDecorate$3(this, null, _save_decorators, {
286
+ __esDecorate$4(this, null, _save_decorators, {
287
287
  kind: "method",
288
288
  name: "save",
289
289
  static: false,
@@ -294,7 +294,7 @@ let GitHubCopilotDualModel = (() => {
294
294
  },
295
295
  metadata: _metadata
296
296
  }, null, _instanceExtraInitializers);
297
- __esDecorate$3(this, null, _create_decorators, {
297
+ __esDecorate$4(this, null, _create_decorators, {
298
298
  kind: "method",
299
299
  name: "create",
300
300
  static: false,
@@ -312,7 +312,7 @@ let GitHubCopilotDualModel = (() => {
312
312
  value: _metadata
313
313
  });
314
314
  }
315
- owner = __runInitializers$3(this, _instanceExtraInitializers);
315
+ owner = __runInitializers$4(this, _instanceExtraInitializers);
316
316
  lifetime = new AbortController();
317
317
  creates = /* @__PURE__ */ new Map();
318
318
  overlays = /* @__PURE__ */ new Map();
@@ -740,12 +740,12 @@ const SearchProviderCatalogSchema = z$1.object({
740
740
  }).strict();
741
741
  //#endregion
742
742
  //#region lib/types/search-routing-host.js
743
- var __runInitializers$2 = function(thisArg, initializers, value) {
743
+ var __runInitializers$3 = function(thisArg, initializers, value) {
744
744
  var useValue = arguments.length > 2;
745
745
  for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
746
746
  return useValue ? value : void 0;
747
747
  };
748
- var __esDecorate$2 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
748
+ var __esDecorate$3 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
749
749
  function accept(f) {
750
750
  if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
751
751
  return f;
@@ -788,7 +788,7 @@ let SearchRoutingController = (() => {
788
788
  static {
789
789
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
790
790
  _providers_decorators = [Remote];
791
- __esDecorate$2(this, null, _providers_decorators, {
791
+ __esDecorate$3(this, null, _providers_decorators, {
792
792
  kind: "method",
793
793
  name: "providers",
794
794
  static: false,
@@ -808,7 +808,7 @@ let SearchRoutingController = (() => {
808
808
  }
809
809
  constructor(ctx) {
810
810
  super(ctx, "githubCopilotSearchRouting");
811
- __runInitializers$2(this, _instanceExtraInitializers);
811
+ __runInitializers$3(this, _instanceExtraInitializers);
812
812
  }
813
813
  providers() {
814
814
  const unavailable = {
@@ -1250,12 +1250,12 @@ function normalizeCopilotUsage(input, observedAt) {
1250
1250
  }
1251
1251
  //#endregion
1252
1252
  //#region lib/types/copilot-usage-host.js
1253
- var __runInitializers$1 = function(thisArg, initializers, value) {
1253
+ var __runInitializers$2 = function(thisArg, initializers, value) {
1254
1254
  var useValue = arguments.length > 2;
1255
1255
  for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
1256
1256
  return useValue ? value : void 0;
1257
1257
  };
1258
- var __esDecorate$1 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
1258
+ var __esDecorate$2 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
1259
1259
  function accept(f) {
1260
1260
  if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
1261
1261
  return f;
@@ -1595,7 +1595,7 @@ let GitHubCopilotUsageController = (() => {
1595
1595
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
1596
1596
  _get_decorators = [Remote];
1597
1597
  _refresh_decorators = [Remote];
1598
- __esDecorate$1(this, null, _get_decorators, {
1598
+ __esDecorate$2(this, null, _get_decorators, {
1599
1599
  kind: "method",
1600
1600
  name: "get",
1601
1601
  static: false,
@@ -1606,7 +1606,7 @@ let GitHubCopilotUsageController = (() => {
1606
1606
  },
1607
1607
  metadata: _metadata
1608
1608
  }, null, _instanceExtraInitializers);
1609
- __esDecorate$1(this, null, _refresh_decorators, {
1609
+ __esDecorate$2(this, null, _refresh_decorators, {
1610
1610
  kind: "method",
1611
1611
  name: "refresh",
1612
1612
  static: false,
@@ -1624,7 +1624,7 @@ let GitHubCopilotUsageController = (() => {
1624
1624
  value: _metadata
1625
1625
  });
1626
1626
  }
1627
- source = __runInitializers$1(this, _instanceExtraInitializers);
1627
+ source = __runInitializers$2(this, _instanceExtraInitializers);
1628
1628
  constructor(ctx) {
1629
1629
  super(ctx, "githubCopilotUsage");
1630
1630
  const credentials = createGitHubCopilotCredentialStore(ctx);
@@ -1847,7 +1847,7 @@ function installContextEvidence(ctx) {
1847
1847
  //#endregion
1848
1848
  //#region package.json
1849
1849
  var name$1 = "dsh-github-copilot";
1850
- var version = "0.4.0-alpha.77";
1850
+ var version = "0.4.0-alpha.79";
1851
1851
  //#endregion
1852
1852
  //#region lib/types/probe.js
1853
1853
  /**
@@ -4365,6 +4365,38 @@ function migrationStatus(ctx) {
4365
4365
  return result;
4366
4366
  }
4367
4367
  const MAX_MODEL_ID_LENGTH = 512;
4368
+ /** Admission is bound to the native turn and its request signal, not the global picker. */
4369
+ var ModelExclusionTurns = class {
4370
+ turns = /* @__PURE__ */ new WeakMap();
4371
+ signals = /* @__PURE__ */ new WeakMap();
4372
+ admit(owner, turn, model, signal, excluded) {
4373
+ const previous = this.turns.get(owner);
4374
+ if (signal.aborted || excluded.has(model) && (previous?.turn !== turn || previous.model !== model)) {
4375
+ if (previous?.turn !== turn) this.turns.delete(owner);
4376
+ return false;
4377
+ }
4378
+ this.turns.set(owner, {
4379
+ turn,
4380
+ model
4381
+ });
4382
+ this.signals.set(signal, {
4383
+ owner,
4384
+ turn,
4385
+ model
4386
+ });
4387
+ return true;
4388
+ }
4389
+ permits(signal, model) {
4390
+ if (signal === void 0 || signal.aborted) return false;
4391
+ const admitted = this.signals.get(signal);
4392
+ if (admitted?.model !== model) return false;
4393
+ const current = this.turns.get(admitted.owner);
4394
+ return current?.turn === admitted.turn && current.model === model;
4395
+ }
4396
+ end(owner) {
4397
+ this.turns.delete(owner);
4398
+ }
4399
+ };
4368
4400
  function normalizeExcludedModelIds(value) {
4369
4401
  if (value === void 0) return [];
4370
4402
  if (!Array.isArray(value) || value.length > 512) throw new Error("COPILOT_MODEL_EXCLUSIONS_INVALID");
@@ -4384,12 +4416,12 @@ function excludedModelSet(value) {
4384
4416
  * Host-side bridge between the Models-page companion UI and DSH's neutral
4385
4417
  * authorization, credential-record, and settings seams.
4386
4418
  */
4387
- var __runInitializers = function(thisArg, initializers, value) {
4419
+ var __runInitializers$1 = function(thisArg, initializers, value) {
4388
4420
  var useValue = arguments.length > 2;
4389
4421
  for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
4390
4422
  return useValue ? value : void 0;
4391
4423
  };
4392
- var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
4424
+ var __esDecorate$1 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
4393
4425
  function accept(f) {
4394
4426
  if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
4395
4427
  return f;
@@ -4503,56 +4535,6 @@ function accountModelsView(ctx) {
4503
4535
  return empty;
4504
4536
  }
4505
4537
  }
4506
- function modelSelection(value) {
4507
- const selection = object$4(value);
4508
- const provider = selection?.provider;
4509
- const model = selection?.model;
4510
- return typeof provider === "string" && provider.length > 0 && typeof model === "string" && model.length > 0 ? {
4511
- provider,
4512
- model
4513
- } : void 0;
4514
- }
4515
- function fixedPreviewModel(value) {
4516
- const selection = modelSelection(value);
4517
- return selection?.provider === "github-copilot-preview" && autoModelPreference(selection.model) === void 0 ? selection.model : void 0;
4518
- }
4519
- function selectedFixedModelIds(ctx) {
4520
- try {
4521
- const defaults = service(ctx, "agentDefaultModel", ["currentSelection"]);
4522
- const agents = service(ctx, "agents", ["list"]);
4523
- const projections = service(ctx, "sessionProjections", ["stateOf"]);
4524
- const locked = /* @__PURE__ */ new Set();
4525
- const currentSelection = Reflect.get(defaults, "currentSelection");
4526
- const defaultValue = typeof currentSelection === "function" ? Reflect.apply(currentSelection, defaults, []) : void 0;
4527
- if (defaultValue !== null && defaultValue !== void 0 && modelSelection(defaultValue) === void 0) return void 0;
4528
- const defaultSelection = fixedPreviewModel(defaultValue);
4529
- if (defaultSelection !== void 0) locked.add(defaultSelection);
4530
- const list = Reflect.get(agents, "list");
4531
- const rows = typeof list === "function" ? Reflect.apply(list, agents, []) : void 0;
4532
- if (!Array.isArray(rows) || rows.length > 1024) return void 0;
4533
- const stateOf = Reflect.get(projections, "stateOf");
4534
- if (typeof stateOf !== "function") return void 0;
4535
- for (const candidate of rows) {
4536
- const session = object$4(object$4(candidate)?.session);
4537
- if (session === void 0) return void 0;
4538
- const state = object$4(Reflect.apply(stateOf, projections, [session, "modelSelection"]));
4539
- if (state === void 0 || !("pending" in state)) return void 0;
4540
- const pending = state.pending;
4541
- if (pending !== null && modelSelection(pending) === void 0) return void 0;
4542
- let selected = pending === null ? void 0 : fixedPreviewModel(pending);
4543
- if (pending === null) {
4544
- const requestHeader = session.requestHeader;
4545
- const header = typeof requestHeader === "function" ? object$4(Reflect.apply(requestHeader, session, [])) : void 0;
4546
- if (header?.config !== void 0 && modelSelection(header.config) === void 0) return void 0;
4547
- selected = fixedPreviewModel(header?.config);
4548
- }
4549
- if (selected !== void 0) locked.add(selected);
4550
- }
4551
- return [...locked].toSorted();
4552
- } catch {
4553
- return;
4554
- }
4555
- }
4556
4538
  function modelPreferencesView(ctx, accountModels, error) {
4557
4539
  const unavailable = (diagnostic) => ({
4558
4540
  state: "error",
@@ -4580,15 +4562,14 @@ function modelPreferencesView(ctx, accountModels, error) {
4580
4562
  } catch {
4581
4563
  return unavailable("COPILOT_MODEL_SETTINGS_INVALID");
4582
4564
  }
4583
- const lockedModelIds = selectedFixedModelIds(ctx);
4584
- const diagnostic = lockedModelIds === void 0 ? "COPILOT_MODEL_SELECTION_UNAVAILABLE" : error;
4565
+ const diagnostic = error;
4585
4566
  const available = new Set(accountModels?.models.map((model) => model.id) ?? []);
4586
4567
  return {
4587
4568
  state: diagnostic === void 0 ? "ready" : "error",
4588
- writable: lockedModelIds !== void 0,
4569
+ writable: true,
4589
4570
  revision: descriptor.revision,
4590
4571
  excludedModelIds,
4591
- lockedModelIds: lockedModelIds ?? [],
4572
+ lockedModelIds: [],
4592
4573
  unavailableExcludedModelIds: excludedModelIds.filter((id) => !available.has(id)),
4593
4574
  ...diagnostic === void 0 ? {} : { error: diagnostic }
4594
4575
  };
@@ -4749,6 +4730,7 @@ let GitHubCopilotAuthorizationController = (() => {
4749
4730
  let _status_decorators;
4750
4731
  let _excludeModel_decorators;
4751
4732
  let _restoreModel_decorators;
4733
+ let _setModelExcluded_decorators;
4752
4734
  let _discoverModels_decorators;
4753
4735
  let _ensureModels_decorators;
4754
4736
  let _reconcile_decorators;
@@ -4762,13 +4744,14 @@ let GitHubCopilotAuthorizationController = (() => {
4762
4744
  _status_decorators = [Remote];
4763
4745
  _excludeModel_decorators = [Remote];
4764
4746
  _restoreModel_decorators = [Remote];
4747
+ _setModelExcluded_decorators = [Remote];
4765
4748
  _discoverModels_decorators = [Remote];
4766
4749
  _ensureModels_decorators = [Remote];
4767
4750
  _reconcile_decorators = [Remote];
4768
4751
  _start_decorators = [Remote];
4769
4752
  _cancel_decorators = [Remote];
4770
4753
  _signOut_decorators = [Remote];
4771
- __esDecorate(this, null, _migrationStatus_decorators, {
4754
+ __esDecorate$1(this, null, _migrationStatus_decorators, {
4772
4755
  kind: "method",
4773
4756
  name: "migrationStatus",
4774
4757
  static: false,
@@ -4779,7 +4762,7 @@ let GitHubCopilotAuthorizationController = (() => {
4779
4762
  },
4780
4763
  metadata: _metadata
4781
4764
  }, null, _instanceExtraInitializers);
4782
- __esDecorate(this, null, _status_decorators, {
4765
+ __esDecorate$1(this, null, _status_decorators, {
4783
4766
  kind: "method",
4784
4767
  name: "status",
4785
4768
  static: false,
@@ -4790,7 +4773,7 @@ let GitHubCopilotAuthorizationController = (() => {
4790
4773
  },
4791
4774
  metadata: _metadata
4792
4775
  }, null, _instanceExtraInitializers);
4793
- __esDecorate(this, null, _excludeModel_decorators, {
4776
+ __esDecorate$1(this, null, _excludeModel_decorators, {
4794
4777
  kind: "method",
4795
4778
  name: "excludeModel",
4796
4779
  static: false,
@@ -4801,7 +4784,7 @@ let GitHubCopilotAuthorizationController = (() => {
4801
4784
  },
4802
4785
  metadata: _metadata
4803
4786
  }, null, _instanceExtraInitializers);
4804
- __esDecorate(this, null, _restoreModel_decorators, {
4787
+ __esDecorate$1(this, null, _restoreModel_decorators, {
4805
4788
  kind: "method",
4806
4789
  name: "restoreModel",
4807
4790
  static: false,
@@ -4812,7 +4795,18 @@ let GitHubCopilotAuthorizationController = (() => {
4812
4795
  },
4813
4796
  metadata: _metadata
4814
4797
  }, null, _instanceExtraInitializers);
4815
- __esDecorate(this, null, _discoverModels_decorators, {
4798
+ __esDecorate$1(this, null, _setModelExcluded_decorators, {
4799
+ kind: "method",
4800
+ name: "setModelExcluded",
4801
+ static: false,
4802
+ private: false,
4803
+ access: {
4804
+ has: (obj) => "setModelExcluded" in obj,
4805
+ get: (obj) => obj.setModelExcluded
4806
+ },
4807
+ metadata: _metadata
4808
+ }, null, _instanceExtraInitializers);
4809
+ __esDecorate$1(this, null, _discoverModels_decorators, {
4816
4810
  kind: "method",
4817
4811
  name: "discoverModels",
4818
4812
  static: false,
@@ -4823,7 +4817,7 @@ let GitHubCopilotAuthorizationController = (() => {
4823
4817
  },
4824
4818
  metadata: _metadata
4825
4819
  }, null, _instanceExtraInitializers);
4826
- __esDecorate(this, null, _ensureModels_decorators, {
4820
+ __esDecorate$1(this, null, _ensureModels_decorators, {
4827
4821
  kind: "method",
4828
4822
  name: "ensureModels",
4829
4823
  static: false,
@@ -4834,7 +4828,7 @@ let GitHubCopilotAuthorizationController = (() => {
4834
4828
  },
4835
4829
  metadata: _metadata
4836
4830
  }, null, _instanceExtraInitializers);
4837
- __esDecorate(this, null, _reconcile_decorators, {
4831
+ __esDecorate$1(this, null, _reconcile_decorators, {
4838
4832
  kind: "method",
4839
4833
  name: "reconcile",
4840
4834
  static: false,
@@ -4845,7 +4839,7 @@ let GitHubCopilotAuthorizationController = (() => {
4845
4839
  },
4846
4840
  metadata: _metadata
4847
4841
  }, null, _instanceExtraInitializers);
4848
- __esDecorate(this, null, _start_decorators, {
4842
+ __esDecorate$1(this, null, _start_decorators, {
4849
4843
  kind: "method",
4850
4844
  name: "start",
4851
4845
  static: false,
@@ -4856,7 +4850,7 @@ let GitHubCopilotAuthorizationController = (() => {
4856
4850
  },
4857
4851
  metadata: _metadata
4858
4852
  }, null, _instanceExtraInitializers);
4859
- __esDecorate(this, null, _cancel_decorators, {
4853
+ __esDecorate$1(this, null, _cancel_decorators, {
4860
4854
  kind: "method",
4861
4855
  name: "cancel",
4862
4856
  static: false,
@@ -4867,7 +4861,7 @@ let GitHubCopilotAuthorizationController = (() => {
4867
4861
  },
4868
4862
  metadata: _metadata
4869
4863
  }, null, _instanceExtraInitializers);
4870
- __esDecorate(this, null, _signOut_decorators, {
4864
+ __esDecorate$1(this, null, _signOut_decorators, {
4871
4865
  kind: "method",
4872
4866
  name: "signOut",
4873
4867
  static: false,
@@ -4885,7 +4879,7 @@ let GitHubCopilotAuthorizationController = (() => {
4885
4879
  value: _metadata
4886
4880
  });
4887
4881
  }
4888
- notices = (__runInitializers(this, _instanceExtraInitializers), []);
4882
+ notices = (__runInitializers$1(this, _instanceExtraInitializers), []);
4889
4883
  failure;
4890
4884
  reconciliationFailed = false;
4891
4885
  attempt;
@@ -4940,10 +4934,15 @@ let GitHubCopilotAuthorizationController = (() => {
4940
4934
  };
4941
4935
  }
4942
4936
  async excludeModel(modelId) {
4943
- return this.updateModelExclusion(modelId, true);
4937
+ await this.updateModelExclusion(modelId, true);
4938
+ return this.status();
4944
4939
  }
4945
4940
  async restoreModel(modelId) {
4946
- return this.updateModelExclusion(modelId, false);
4941
+ await this.updateModelExclusion(modelId, false);
4942
+ return this.status();
4943
+ }
4944
+ async setModelExcluded(modelId, excluded) {
4945
+ return this.updateModelExclusion(modelId, excluded);
4947
4946
  }
4948
4947
  /** Explicit model discovery: may refresh OAuth and GET the account catalog, never changes selection. */
4949
4948
  async discoverModels() {
@@ -5071,21 +5070,18 @@ let GitHubCopilotAuthorizationController = (() => {
5071
5070
  return this.status();
5072
5071
  }
5073
5072
  async updateModelExclusion(modelId, exclude) {
5073
+ const view = () => modelPreferencesView(this.ctx, accountModelsView(this.ctx), this.modelPreferenceFailure);
5074
5074
  let normalized;
5075
5075
  try {
5076
5076
  [normalized] = normalizeExcludedModelIds([modelId]);
5077
5077
  } catch {
5078
5078
  this.modelPreferenceFailure = "COPILOT_MODEL_EXCLUSION_SAVE_FAILED";
5079
- return this.status();
5079
+ return view();
5080
5080
  }
5081
5081
  const current = modelPreferencesView(this.ctx, accountModelsView(this.ctx));
5082
5082
  if (!current.writable || current.revision === void 0) {
5083
5083
  this.modelPreferenceFailure = "COPILOT_MODEL_PREFERENCES_UNAVAILABLE";
5084
- return this.status();
5085
- }
5086
- if (exclude && current.lockedModelIds.includes(normalized)) {
5087
- this.modelPreferenceFailure = "COPILOT_MODEL_EXCLUSION_SELECTED";
5088
- return this.status();
5084
+ return view();
5089
5085
  }
5090
5086
  const ids = new Set(current.excludedModelIds);
5091
5087
  if (exclude) ids.add(normalized);
@@ -5093,7 +5089,7 @@ let GitHubCopilotAuthorizationController = (() => {
5093
5089
  const next = normalizeExcludedModelIds([...ids]);
5094
5090
  if (next.length === current.excludedModelIds.length && next.every((id, index) => id === current.excludedModelIds[index])) {
5095
5091
  this.modelPreferenceFailure = void 0;
5096
- return this.status();
5092
+ return current;
5097
5093
  }
5098
5094
  try {
5099
5095
  await service(this.ctx, "settings", ["describe", "mutate"]).mutate(GITHUB_COPILOT_SETTINGS_NAMESPACE$1, [{
@@ -5106,7 +5102,7 @@ let GitHubCopilotAuthorizationController = (() => {
5106
5102
  const record = object$4(cause);
5107
5103
  this.modelPreferenceFailure = record?.code === "SETTINGS_CONFLICT" || cause instanceof Error && /conflict/i.test(cause.message) ? "COPILOT_MODEL_EXCLUSION_CONFLICT" : "COPILOT_MODEL_EXCLUSION_SAVE_FAILED";
5108
5104
  }
5109
- return this.status();
5105
+ return view();
5110
5106
  }
5111
5107
  async ensureProviderProfile() {
5112
5108
  try {
@@ -6897,6 +6893,85 @@ var TurnSelectionStore = class {
6897
6893
  }
6898
6894
  };
6899
6895
  //#endregion
6896
+ //#region lib/types/turn-selection-host.js
6897
+ var __runInitializers = function(thisArg, initializers, value) {
6898
+ var useValue = arguments.length > 2;
6899
+ for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6900
+ return useValue ? value : void 0;
6901
+ };
6902
+ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
6903
+ function accept(f) {
6904
+ if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
6905
+ return f;
6906
+ }
6907
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
6908
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6909
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6910
+ var _, done = false;
6911
+ for (var i = decorators.length - 1; i >= 0; i--) {
6912
+ var context = {};
6913
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
6914
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
6915
+ context.addInitializer = function(f) {
6916
+ if (done) throw new TypeError("Cannot add initializers after decoration has completed");
6917
+ extraInitializers.push(accept(f || null));
6918
+ };
6919
+ var result = (0, decorators[i])(kind === "accessor" ? {
6920
+ get: descriptor.get,
6921
+ set: descriptor.set
6922
+ } : descriptor[key], context);
6923
+ if (kind === "accessor") {
6924
+ if (result === void 0) continue;
6925
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
6926
+ if (_ = accept(result.get)) descriptor.get = _;
6927
+ if (_ = accept(result.set)) descriptor.set = _;
6928
+ if (_ = accept(result.init)) initializers.unshift(_);
6929
+ } else if (_ = accept(result)) {
6930
+ if (kind === "field") initializers.unshift(_);
6931
+ else descriptor[key] = _;
6932
+ }
6933
+ }
6934
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
6935
+ done = true;
6936
+ };
6937
+ /** Public Host binding for the existing bounded, runtime-only decision store. */
6938
+ let TurnSelectionController = (() => {
6939
+ let _classSuper = TypertRemoteService;
6940
+ let _instanceExtraInitializers = [];
6941
+ let _get_decorators;
6942
+ return class TurnSelectionController extends _classSuper {
6943
+ static {
6944
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
6945
+ _get_decorators = [Remote];
6946
+ __esDecorate(this, null, _get_decorators, {
6947
+ kind: "method",
6948
+ name: "get",
6949
+ static: false,
6950
+ private: false,
6951
+ access: {
6952
+ has: (obj) => "get" in obj,
6953
+ get: (obj) => obj.get
6954
+ },
6955
+ metadata: _metadata
6956
+ }, null, _instanceExtraInitializers);
6957
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, {
6958
+ enumerable: true,
6959
+ configurable: true,
6960
+ writable: true,
6961
+ value: _metadata
6962
+ });
6963
+ }
6964
+ selections = __runInitializers(this, _instanceExtraInitializers);
6965
+ constructor(ctx, selections) {
6966
+ super(ctx, "githubCopilotTurnSelection");
6967
+ this.selections = selections;
6968
+ }
6969
+ get(agent, turn) {
6970
+ return this.selections.get(agent, turn);
6971
+ }
6972
+ };
6973
+ })();
6974
+ //#endregion
6900
6975
  //#region lib/types/parent-model-follow.js
6901
6976
  const PARENT_MODEL_FOLLOW_PROJECTION = "githubCopilotParentModelFollow";
6902
6977
  function object(value) {
@@ -7091,7 +7166,7 @@ function actualNotice(agent, model) {
7091
7166
  /** Resolve virtual Auto once per Core turn before request/header persistence. */
7092
7167
  function installAutoModelRouting(ctx, dependencies) {
7093
7168
  const selections = new TurnSelectionStore();
7094
- ctx.provide("githubCopilotTurnSelection", { get: (agent, turn) => selections.get(agent, turn) });
7169
+ new TurnSelectionController(ctx, selections);
7095
7170
  const captured = /* @__PURE__ */ new WeakMap();
7096
7171
  const routed = /* @__PURE__ */ new WeakMap();
7097
7172
  const agentDisposers = /* @__PURE__ */ new WeakMap();
@@ -7286,7 +7361,10 @@ function installAutoModelRouting(ctx, dependencies) {
7286
7361
  const projections = ctx.get("sessionProjections");
7287
7362
  const selection = record(projections) && typeof projections.stateOf === "function" ? projections.stateOf(agent.session, "modelSelection") : void 0;
7288
7363
  const fixed = record(selection) && record(selection.pending) && selection.pending.provider === resolved.provider && selection.pending.model === resolved.model;
7289
- if (!signal.aborted && (resolved.provider === "github-copilot-preview" || resolved.provider === "github-copilot")) selections.record(agent, turn, { mode: fixed ? "manual" : "unknown" });
7364
+ if (!signal.aborted && (resolved.provider === "github-copilot-preview" || resolved.provider === "github-copilot")) {
7365
+ if (resolved.provider === "github-copilot-preview") dependencies.admitModel?.(agent, turn, resolved.model, signal);
7366
+ selections.record(agent, turn, { mode: fixed ? "manual" : "unknown" });
7367
+ }
7290
7368
  return resolved;
7291
7369
  }
7292
7370
  if (resolved.provider !== "github-copilot-preview") {
@@ -7318,13 +7396,16 @@ function installAutoModelRouting(ctx, dependencies) {
7318
7396
  }
7319
7397
  state.recorded = true;
7320
7398
  }
7321
- if (!signal.aborted) selections.record(agent, turn, {
7322
- mode: "auto",
7323
- preference: state.decision.preference,
7324
- reason: state.decision.reason,
7325
- candidateCount: state.decision.candidateCount,
7326
- fittingCandidateCount: state.decision.fittingCandidateCount
7327
- });
7399
+ if (!signal.aborted) {
7400
+ dependencies.admitModel?.(agent, turn, state.decision.model.id, signal);
7401
+ selections.record(agent, turn, {
7402
+ mode: "auto",
7403
+ preference: state.decision.preference,
7404
+ reason: state.decision.reason,
7405
+ candidateCount: state.decision.candidateCount,
7406
+ fittingCandidateCount: state.decision.fittingCandidateCount
7407
+ });
7408
+ }
7328
7409
  return {
7329
7410
  ...resolved,
7330
7411
  model: state.decision.model.id
@@ -7387,17 +7468,19 @@ var PreviewLifetime = class {
7387
7468
  proofFor;
7388
7469
  displayProofFor;
7389
7470
  excluded;
7471
+ turns;
7390
7472
  controller = new AbortController();
7391
7473
  wires = /* @__PURE__ */ new Set();
7392
7474
  retryEntries = /* @__PURE__ */ new Map();
7393
7475
  revision = 0;
7394
7476
  active = true;
7395
- constructor(credentials, source, proofFor, displayProofFor, excluded) {
7477
+ constructor(credentials, source, proofFor, displayProofFor, excluded, turns) {
7396
7478
  this.credentials = credentials;
7397
7479
  this.source = source;
7398
7480
  this.proofFor = proofFor;
7399
7481
  this.displayProofFor = displayProofFor;
7400
7482
  this.excluded = excluded;
7483
+ this.turns = turns;
7401
7484
  }
7402
7485
  assertActive() {
7403
7486
  if (!this.active) throw failure("COPILOT_PREVIEW_DISPOSED", "ABORTED");
@@ -7499,7 +7582,7 @@ var PreviewLifetime = class {
7499
7582
  const combined = signal === void 0 ? this.controller.signal : AbortSignal.any([signal, this.controller.signal]);
7500
7583
  const grant = await this.read(combined);
7501
7584
  if (grant === void 0) throw failure("COPILOT_PREVIEW_OAUTH_REQUIRED");
7502
- if (this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7585
+ if (!this.turns.permits(signal, model) && this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7503
7586
  const descriptor = snapshot.models.find((item) => item.id === model);
7504
7587
  if (descriptor === void 0) throw failure("COPILOT_PREVIEW_MODEL_NOT_ENTITLED", "UNKNOWN_MODEL");
7505
7588
  const proof = this.proofFor(snapshot);
@@ -7510,6 +7593,7 @@ var PreviewLifetime = class {
7510
7593
  proof,
7511
7594
  revision: this.revision,
7512
7595
  signal: combined,
7596
+ retrySignal: signal,
7513
7597
  started: false
7514
7598
  };
7515
7599
  this.entitled(lease, grant, model);
@@ -7526,7 +7610,7 @@ var PreviewLifetime = class {
7526
7610
  }
7527
7611
  entitled(lease, grant, model) {
7528
7612
  this.account(lease, grant);
7529
- if (this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7613
+ if (!this.turns.permits(lease.retrySignal, model) && !lease.started && this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7530
7614
  if (lease.descriptor.id !== model) throw failure("COPILOT_PREVIEW_MODEL_MISMATCH", "UNKNOWN_MODEL");
7531
7615
  if (this.source.readSnapshot() !== lease.snapshot || this.proofFor(lease.snapshot) !== lease.proof) throw failure("COPILOT_PREVIEW_METADATA_STALE");
7532
7616
  if (tokenFingerprint(grant.access) !== lease.proof.tokenFingerprint || copilotEntitlementKey(grant) !== lease.proof.entitlementKey || grant.expires <= Date.now()) {
@@ -7538,6 +7622,7 @@ var PreviewLifetime = class {
7538
7622
  start(lease) {
7539
7623
  this.assertActive();
7540
7624
  if (!lease.started && lease.revision !== this.revision) throw failure("COPILOT_PREVIEW_PREPARED_CALL_INVALIDATED", "ABORTED");
7625
+ if (!this.turns.permits(lease.retrySignal, lease.descriptor.id) && this.excluded(lease.descriptor.id)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7541
7626
  lease.started = true;
7542
7627
  }
7543
7628
  guard(lease) {
@@ -7900,9 +7985,11 @@ function apply$1(ctx, config = {}) {
7900
7985
  });
7901
7986
  const displayProofFor = (snapshot) => source.readDisplaySnapshot() === snapshot && provenSnapshot === snapshot && snapshotProof?.accountKey === snapshot.accountKey ? snapshotProof : void 0;
7902
7987
  const proofFor = (snapshot) => source.readSnapshot() === snapshot && snapshotProof !== void 0 && snapshotProof.expires > Date.now() ? displayProofFor(snapshot) : void 0;
7903
- const lifetime = new PreviewLifetime(store, source, proofFor, displayProofFor, (modelId) => excludedModels().has(modelId));
7988
+ const exclusionTurns = new ModelExclusionTurns();
7989
+ const lifetime = new PreviewLifetime(store, source, proofFor, displayProofFor, (modelId) => excludedModels().has(modelId), exclusionTurns);
7904
7990
  const removeStepListener = ctx.on("session/event", (session, event) => {
7905
7991
  if (event.type === "step/start" || event.type === "turn/end") lifetime.clearSessionRetries(session.id);
7992
+ if (event.type === "turn/end") exclusionTurns.end(session);
7906
7993
  });
7907
7994
  const template = resolvedProfile(createAccountProvider([], lifetime.guard(), "https://api.individual.githubcopilot.com").provider, requestConfig);
7908
7995
  let configured = false;
@@ -8094,7 +8181,10 @@ function apply$1(ctx, config = {}) {
8094
8181
  },
8095
8182
  budgetPolicy: () => budgetSettings(),
8096
8183
  parentModelBindings: () => cacheSettings().parentModelFollow ?? [],
8097
- followParentModel: () => cacheSettings().followParentModel === true
8184
+ followParentModel: () => cacheSettings().followParentModel === true,
8185
+ admitModel(agent, turn, model, signal) {
8186
+ if (!exclusionTurns.admit(agent.session, turn, model, signal, excludedModels())) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
8187
+ }
8098
8188
  });
8099
8189
  const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings));
8100
8190
  let exclusionSignature = JSON.stringify([...excludedModels()]);