dsh-github-copilot 0.4.0-alpha.76 → 0.4.0-alpha.78

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
@@ -1700,7 +1700,7 @@ const usageSchema = z$1.object({
1700
1700
  totalTokens: count.optional(),
1701
1701
  reasoningTokens: count.optional()
1702
1702
  });
1703
- function record$5(value) {
1703
+ function record$6(value) {
1704
1704
  return typeof value === "object" && value !== null && !Array.isArray(value);
1705
1705
  }
1706
1706
  function sameRoute$1(left, right) {
@@ -1719,10 +1719,10 @@ function initialContextEvidence() {
1719
1719
  }
1720
1720
  /** Read only counts and routing leaves; never message content or opaque replay. */
1721
1721
  function foldContextEvidence(state, event) {
1722
- if (!record$5(event) || typeof event.type !== "string" || !record$5(event.data)) return state;
1722
+ if (!record$6(event) || typeof event.type !== "string" || !record$6(event.data)) return state;
1723
1723
  if (event.type === "request/header" || event.type === "model/selection") {
1724
- const raw = event.type === "request/header" ? record$5(event.data.header) ? event.data.header.config : void 0 : event.data;
1725
- if (!record$5(raw)) return {
1724
+ const raw = event.type === "request/header" ? record$6(event.data.header) ? event.data.header.config : void 0 : event.data;
1725
+ if (!record$6(raw)) return {
1726
1726
  ...state,
1727
1727
  route: null,
1728
1728
  sample: null,
@@ -1761,7 +1761,7 @@ function foldContextEvidence(state, event) {
1761
1761
  if (!copilot(state.route)) return state;
1762
1762
  if (event.type === "assistant/message" && event.data.source !== void 0) {
1763
1763
  const source = event.data.source;
1764
- const parsed = routeSchema.safeParse(record$5(source) ? {
1764
+ const parsed = routeSchema.safeParse(record$6(source) ? {
1765
1765
  provider: source.provider,
1766
1766
  model: source.model
1767
1767
  } : source);
@@ -1777,7 +1777,7 @@ function foldContextEvidence(state, event) {
1777
1777
  const settledUsage = usage !== void 0;
1778
1778
  let terminal;
1779
1779
  for (const entry of stream) {
1780
- if (!record$5(entry) || entry.type !== "chunk" || !record$5(entry.chunk)) continue;
1780
+ if (!record$6(entry) || entry.type !== "chunk" || !record$6(entry.chunk)) continue;
1781
1781
  if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
1782
1782
  if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
1783
1783
  }
@@ -1791,7 +1791,7 @@ function foldContextEvidence(state, event) {
1791
1791
  };
1792
1792
  const value = parsed.data;
1793
1793
  const zero = isZeroContextUsage(value);
1794
- const successful = record$5(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
1794
+ const successful = record$6(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
1795
1795
  if (zero && !successful) {
1796
1796
  const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
1797
1797
  return {
@@ -1833,7 +1833,7 @@ const contextEvidenceDefinition = {
1833
1833
  function installContextEvidence(ctx) {
1834
1834
  ctx.inject(["sessionProjections"], (scope) => {
1835
1835
  const registry = scope.get("sessionProjections");
1836
- if (!record$5(registry) || typeof registry.register !== "function") {
1836
+ if (!record$6(registry) || typeof registry.register !== "function") {
1837
1837
  scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
1838
1838
  return;
1839
1839
  }
@@ -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.76";
1850
+ var version = "0.4.0-alpha.78";
1851
1851
  //#endregion
1852
1852
  //#region lib/types/probe.js
1853
1853
  /**
@@ -2856,7 +2856,7 @@ function buildAnthropicWireBody(request, cfg, model) {
2856
2856
  }
2857
2857
  //#endregion
2858
2858
  //#region lib/types/responses-reasoning-text.js
2859
- function record$4(value) {
2859
+ function record$5(value) {
2860
2860
  return typeof value === "object" && value !== null;
2861
2861
  }
2862
2862
  function responseIndex(value) {
@@ -2914,13 +2914,13 @@ var ResponsesReasoningText = class {
2914
2914
  }
2915
2915
  /** Only recognized public text fields are examined; no copying of the item. */
2916
2916
  snapshot(item) {
2917
- if (!record$4(item) || item.type !== "reasoning") return "";
2917
+ if (!record$5(item) || item.type !== "reasoning") return "";
2918
2918
  let delta = "";
2919
2919
  for (const family of ["summary", "raw"]) {
2920
2920
  const value = family === "summary" ? item.summary : item.content;
2921
2921
  if (!Array.isArray(value)) continue;
2922
2922
  for (const [index, part] of value.entries()) {
2923
- if (!record$4(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
2923
+ if (!record$5(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
2924
2924
  delta += this.update(family, index, part.text, true);
2925
2925
  }
2926
2926
  }
@@ -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");
@@ -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,6 +4744,7 @@ 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];
@@ -4812,6 +4795,17 @@ let GitHubCopilotAuthorizationController = (() => {
4812
4795
  },
4813
4796
  metadata: _metadata
4814
4797
  }, null, _instanceExtraInitializers);
4798
+ __esDecorate(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);
4815
4809
  __esDecorate(this, null, _discoverModels_decorators, {
4816
4810
  kind: "method",
4817
4811
  name: "discoverModels",
@@ -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 {
@@ -5542,16 +5538,16 @@ async function isCopilotInputItemScopeError(response, signal) {
5542
5538
  //#endregion
5543
5539
  //#region lib/types/request-body-timeout.js
5544
5540
  const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
5545
- function record$3(value) {
5541
+ function record$4(value) {
5546
5542
  return typeof value === "object" && value !== null && !Array.isArray(value);
5547
5543
  }
5548
5544
  /** Verified provider evidence, not guessed capabilities, token limits or network cause. */
5549
5545
  async function requestBodyTimeoutDiagnostic(response, body, signal) {
5550
5546
  if (response.status !== 408 || signal?.aborted) return void 0;
5551
5547
  const value = await readResponseErrorJson(response, signal);
5552
- if (!record$3(value)) return void 0;
5548
+ if (!record$4(value)) return void 0;
5553
5549
  const error = Object.hasOwn(value, "error") ? value.error : value;
5554
- if (!record$3(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;
5550
+ if (!record$4(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;
5555
5551
  return `COPILOT_REQUEST_BODY_TIMEOUT: Copilot returned HTTP 408 / user_request_timeout while reading the request body; this is not context-window overflow. ${body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`} Native retry policy is unchanged. If retries exhaust, explicitly compact the conversation or reduce attachments/tool output before retrying; also check network/proxy health and GitHub service status. A larger client timeout does not change this server timeout. No history was trimmed or model switched.`;
5556
5552
  }
5557
5553
  //#endregion
@@ -5888,7 +5884,7 @@ var Budget = class {
5888
5884
  if (this.consumed > ACCOUNT_MODEL_CATALOG_LIMITS.maxBytes) fail("CATALOG_TOO_LARGE", true);
5889
5885
  }
5890
5886
  };
5891
- function record$2(value, code) {
5887
+ function record$3(value, code) {
5892
5888
  if (typeof value !== "object" || value === null || Array.isArray(value)) fail(code);
5893
5889
  return value;
5894
5890
  }
@@ -5938,11 +5934,11 @@ function normalizeModel(raw, id, options, budget) {
5938
5934
  if (options.availableModelIds?.has(id) !== true) fail("MISSING_POLICY");
5939
5935
  policySource = "account-available-id";
5940
5936
  } else {
5941
- if (text(field(record$2(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail("POLICY_NOT_ENABLED");
5937
+ if (text(field(record$3(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail("POLICY_NOT_ENABLED");
5942
5938
  policySource = "server-enabled";
5943
5939
  }
5944
- const capabilities = record$2(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
5945
- const supports = record$2(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
5940
+ const capabilities = record$3(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
5941
+ const supports = record$3(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
5946
5942
  const streaming = field(supports, "streaming", budget);
5947
5943
  if (streaming === false) fail("STREAMING_UNSUPPORTED");
5948
5944
  if (streaming !== true) fail("INVALID_SUPPORTS");
@@ -5963,7 +5959,7 @@ function normalizeModel(raw, id, options, budget) {
5963
5959
  if (selected === void 0) fail(unsupportedEndpointCount === 0 && endpoints.includes("ws:/responses") ? "WEBSOCKET_ONLY" : "UNSUPPORTED_ENDPOINTS");
5964
5960
  const rawLimits = field(capabilities, "limits", budget);
5965
5961
  if (rawLimits === void 0) fail("MISSING_LIMITS");
5966
- const limits = record$2(rawLimits, "INVALID_LIMITS");
5962
+ const limits = record$3(rawLimits, "INVALID_LIMITS");
5967
5963
  const maxContext = optionalPositive(limits, "max_context_window_tokens", "INVALID_LIMITS", budget);
5968
5964
  const maxInputTokens = optionalPositive(limits, "max_prompt_tokens", "INVALID_LIMITS", budget);
5969
5965
  if (maxContext === void 0 && maxInputTokens === void 0) fail("MISSING_CONTEXT_LIMIT");
@@ -5981,7 +5977,7 @@ function normalizeModel(raw, id, options, budget) {
5981
5977
  if (vision === true) {
5982
5978
  const rawVisionLimits = field(limits, "vision", budget);
5983
5979
  if (rawVisionLimits !== void 0) {
5984
- const rawMediaTypes = field(record$2(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
5980
+ const rawMediaTypes = field(record$3(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
5985
5981
  if (rawMediaTypes !== void 0) {
5986
5982
  const mediaTypes = stringList(rawMediaTypes, ACCOUNT_MODEL_CATALOG_LIMITS.maxMediaTypes, 128, "INVALID_VISION_LIMITS", budget);
5987
5983
  const mime = /^[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*\/[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*$/iu;
@@ -6041,7 +6037,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
6041
6037
  fail("INVALID_JSON", true);
6042
6038
  }
6043
6039
  }
6044
- const data = field(record$2(raw, "INVALID_CATALOG"), "data", budget);
6040
+ const data = field(record$3(raw, "INVALID_CATALOG"), "data", budget);
6045
6041
  if (!Array.isArray(data)) fail("INVALID_CATALOG");
6046
6042
  const count = field(data, "length", budget);
6047
6043
  if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) fail("INVALID_CATALOG");
@@ -6064,7 +6060,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
6064
6060
  for (let index = 0; index < count; index++) {
6065
6061
  let id;
6066
6062
  try {
6067
- const candidate = record$2(field(data, String(index), budget), "INVALID_MODEL");
6063
+ const candidate = record$3(field(data, String(index), budget), "INVALID_MODEL");
6068
6064
  const candidateId = text(field(candidate, "id", budget), ACCOUNT_MODEL_CATALOG_LIMITS.maxIdLength, "INVALID_ID", budget);
6069
6065
  if (!identifier.test(candidateId)) fail("INVALID_ID");
6070
6066
  id = candidateId;
@@ -6495,6 +6491,25 @@ function createAccountModelSource(dependencies) {
6495
6491
  return new AccountModelSource(dependencies);
6496
6492
  }
6497
6493
  //#endregion
6494
+ //#region lib/types/agent-compaction.js
6495
+ function record$2(value) {
6496
+ return typeof value === "object" && value !== null;
6497
+ }
6498
+ /** Resolve the owning preset's service without reaching into Core's service registry. */
6499
+ function agentCompaction(agent) {
6500
+ if (typeof agent.ctx?.get !== "function") throw new LlmError("COPILOT_COMPACTION_AGENT_CONTEXT_UNAVAILABLE", "INVALID_REQUEST");
6501
+ const presets = agent.ctx.get("agentPresets");
6502
+ if (presets !== void 0) {
6503
+ if (!record$2(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
6504
+ const preset = presets.composedPreset(agent.ctx);
6505
+ if (preset !== void 0) {
6506
+ if (typeof preset !== "string" || preset.trim().length === 0) throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
6507
+ return presets.serviceFor(agent, "compaction");
6508
+ }
6509
+ }
6510
+ return agent.ctx.get("compaction");
6511
+ }
6512
+ //#endregion
6498
6513
  //#region lib/types/compaction-pressure.js
6499
6514
  function object$1(value) {
6500
6515
  return typeof value === "object" && value !== null ? value : void 0;
@@ -6541,7 +6556,7 @@ function installCopilotCompactionPressure(ctx, callbacks) {
6541
6556
  if (header === void 0 || !callConfigEquals(header.config, request)) return void 0;
6542
6557
  const budget = callbacks.resolve(request);
6543
6558
  if (budget === void 0 || !positiveInteger(budget.inputBudgetTokens)) return void 0;
6544
- const compaction = object$1(optionalService(ctx, "compaction"));
6559
+ const compaction = object$1(agentCompaction(owner));
6545
6560
  const config = object$1(compaction?.config);
6546
6561
  if (config?.auto === false) return void 0;
6547
6562
  if (config?.auto !== true || typeof compaction?.compactIfNeeded !== "function") {
@@ -7022,7 +7037,7 @@ function buildRoutingContext(ctx, agent, turn, messages, budgetPolicyConfig) {
7022
7037
  return value;
7023
7038
  };
7024
7039
  const sessionId = typeof agent.session?.id === "string" ? agent.session.id : void 0;
7025
- const compaction = ctx.get("compaction");
7040
+ const compaction = agentCompaction(agent);
7026
7041
  const compactionConfig = record(compaction) && record(compaction.config) ? compaction.config : void 0;
7027
7042
  const compactionAvailable = compaction !== void 0 && compactionConfig?.auto !== false && (typeof compactionConfig?.maxOverflowRetries !== "number" || compactionConfig.maxOverflowRetries > 0);
7028
7043
  const hasCompactionSummary = messages.some((m) => record(m) && (record(m.source) && (m.source.kind === "compaction" || m.source.kind === "compact-checkpoint") || typeof m.surfaceOp === "object"));
@@ -7267,7 +7282,10 @@ function installAutoModelRouting(ctx, dependencies) {
7267
7282
  const projections = ctx.get("sessionProjections");
7268
7283
  const selection = record(projections) && typeof projections.stateOf === "function" ? projections.stateOf(agent.session, "modelSelection") : void 0;
7269
7284
  const fixed = record(selection) && record(selection.pending) && selection.pending.provider === resolved.provider && selection.pending.model === resolved.model;
7270
- if (!signal.aborted && (resolved.provider === "github-copilot-preview" || resolved.provider === "github-copilot")) selections.record(agent, turn, { mode: fixed ? "manual" : "unknown" });
7285
+ if (!signal.aborted && (resolved.provider === "github-copilot-preview" || resolved.provider === "github-copilot")) {
7286
+ if (resolved.provider === "github-copilot-preview") dependencies.admitModel?.(agent, turn, resolved.model, signal);
7287
+ selections.record(agent, turn, { mode: fixed ? "manual" : "unknown" });
7288
+ }
7271
7289
  return resolved;
7272
7290
  }
7273
7291
  if (resolved.provider !== "github-copilot-preview") {
@@ -7299,13 +7317,16 @@ function installAutoModelRouting(ctx, dependencies) {
7299
7317
  }
7300
7318
  state.recorded = true;
7301
7319
  }
7302
- if (!signal.aborted) selections.record(agent, turn, {
7303
- mode: "auto",
7304
- preference: state.decision.preference,
7305
- reason: state.decision.reason,
7306
- candidateCount: state.decision.candidateCount,
7307
- fittingCandidateCount: state.decision.fittingCandidateCount
7308
- });
7320
+ if (!signal.aborted) {
7321
+ dependencies.admitModel?.(agent, turn, state.decision.model.id, signal);
7322
+ selections.record(agent, turn, {
7323
+ mode: "auto",
7324
+ preference: state.decision.preference,
7325
+ reason: state.decision.reason,
7326
+ candidateCount: state.decision.candidateCount,
7327
+ fittingCandidateCount: state.decision.fittingCandidateCount
7328
+ });
7329
+ }
7309
7330
  return {
7310
7331
  ...resolved,
7311
7332
  model: state.decision.model.id
@@ -7368,17 +7389,19 @@ var PreviewLifetime = class {
7368
7389
  proofFor;
7369
7390
  displayProofFor;
7370
7391
  excluded;
7392
+ turns;
7371
7393
  controller = new AbortController();
7372
7394
  wires = /* @__PURE__ */ new Set();
7373
7395
  retryEntries = /* @__PURE__ */ new Map();
7374
7396
  revision = 0;
7375
7397
  active = true;
7376
- constructor(credentials, source, proofFor, displayProofFor, excluded) {
7398
+ constructor(credentials, source, proofFor, displayProofFor, excluded, turns) {
7377
7399
  this.credentials = credentials;
7378
7400
  this.source = source;
7379
7401
  this.proofFor = proofFor;
7380
7402
  this.displayProofFor = displayProofFor;
7381
7403
  this.excluded = excluded;
7404
+ this.turns = turns;
7382
7405
  }
7383
7406
  assertActive() {
7384
7407
  if (!this.active) throw failure("COPILOT_PREVIEW_DISPOSED", "ABORTED");
@@ -7480,7 +7503,7 @@ var PreviewLifetime = class {
7480
7503
  const combined = signal === void 0 ? this.controller.signal : AbortSignal.any([signal, this.controller.signal]);
7481
7504
  const grant = await this.read(combined);
7482
7505
  if (grant === void 0) throw failure("COPILOT_PREVIEW_OAUTH_REQUIRED");
7483
- if (this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7506
+ if (!this.turns.permits(signal, model) && this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7484
7507
  const descriptor = snapshot.models.find((item) => item.id === model);
7485
7508
  if (descriptor === void 0) throw failure("COPILOT_PREVIEW_MODEL_NOT_ENTITLED", "UNKNOWN_MODEL");
7486
7509
  const proof = this.proofFor(snapshot);
@@ -7491,6 +7514,7 @@ var PreviewLifetime = class {
7491
7514
  proof,
7492
7515
  revision: this.revision,
7493
7516
  signal: combined,
7517
+ retrySignal: signal,
7494
7518
  started: false
7495
7519
  };
7496
7520
  this.entitled(lease, grant, model);
@@ -7507,7 +7531,7 @@ var PreviewLifetime = class {
7507
7531
  }
7508
7532
  entitled(lease, grant, model) {
7509
7533
  this.account(lease, grant);
7510
- if (this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7534
+ if (!this.turns.permits(lease.retrySignal, model) && !lease.started && this.excluded(model)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7511
7535
  if (lease.descriptor.id !== model) throw failure("COPILOT_PREVIEW_MODEL_MISMATCH", "UNKNOWN_MODEL");
7512
7536
  if (this.source.readSnapshot() !== lease.snapshot || this.proofFor(lease.snapshot) !== lease.proof) throw failure("COPILOT_PREVIEW_METADATA_STALE");
7513
7537
  if (tokenFingerprint(grant.access) !== lease.proof.tokenFingerprint || copilotEntitlementKey(grant) !== lease.proof.entitlementKey || grant.expires <= Date.now()) {
@@ -7519,6 +7543,7 @@ var PreviewLifetime = class {
7519
7543
  start(lease) {
7520
7544
  this.assertActive();
7521
7545
  if (!lease.started && lease.revision !== this.revision) throw failure("COPILOT_PREVIEW_PREPARED_CALL_INVALIDATED", "ABORTED");
7546
+ if (!this.turns.permits(lease.retrySignal, lease.descriptor.id) && this.excluded(lease.descriptor.id)) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
7522
7547
  lease.started = true;
7523
7548
  }
7524
7549
  guard(lease) {
@@ -7881,9 +7906,11 @@ function apply$1(ctx, config = {}) {
7881
7906
  });
7882
7907
  const displayProofFor = (snapshot) => source.readDisplaySnapshot() === snapshot && provenSnapshot === snapshot && snapshotProof?.accountKey === snapshot.accountKey ? snapshotProof : void 0;
7883
7908
  const proofFor = (snapshot) => source.readSnapshot() === snapshot && snapshotProof !== void 0 && snapshotProof.expires > Date.now() ? displayProofFor(snapshot) : void 0;
7884
- const lifetime = new PreviewLifetime(store, source, proofFor, displayProofFor, (modelId) => excludedModels().has(modelId));
7909
+ const exclusionTurns = new ModelExclusionTurns();
7910
+ const lifetime = new PreviewLifetime(store, source, proofFor, displayProofFor, (modelId) => excludedModels().has(modelId), exclusionTurns);
7885
7911
  const removeStepListener = ctx.on("session/event", (session, event) => {
7886
7912
  if (event.type === "step/start" || event.type === "turn/end") lifetime.clearSessionRetries(session.id);
7913
+ if (event.type === "turn/end") exclusionTurns.end(session);
7887
7914
  });
7888
7915
  const template = resolvedProfile(createAccountProvider([], lifetime.guard(), "https://api.individual.githubcopilot.com").provider, requestConfig);
7889
7916
  let configured = false;
@@ -8075,7 +8102,10 @@ function apply$1(ctx, config = {}) {
8075
8102
  },
8076
8103
  budgetPolicy: () => budgetSettings(),
8077
8104
  parentModelBindings: () => cacheSettings().parentModelFollow ?? [],
8078
- followParentModel: () => cacheSettings().followParentModel === true
8105
+ followParentModel: () => cacheSettings().followParentModel === true,
8106
+ admitModel(agent, turn, model, signal) {
8107
+ if (!exclusionTurns.admit(agent.session, turn, model, signal, excludedModels())) throw failure("COPILOT_PREVIEW_MODEL_EXCLUDED", "INVALID_REQUEST");
8108
+ }
8079
8109
  });
8080
8110
  const registration = ctx.llm.registerAdapter([GITHUB_COPILOT_PREVIEW_PROVIDER_ID], new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings));
8081
8111
  let exclusionSignature = JSON.stringify([...excludedModels()]);
package/lib/remote.js CHANGED
@@ -340,6 +340,7 @@ const GitHubCopilotAuthorizationViewSchema = z.object({
340
340
  ]).optional()
341
341
  }).strict();
342
342
  const result = strictRemoteCodec(GITHUB_COPILOT_AUTHORIZATION_VIEW_TYPE_SYMBOL, GitHubCopilotAuthorizationViewSchema);
343
+ const GitHubCopilotModelPreferencesViewSchema = GitHubCopilotAuthorizationViewSchema.shape.modelPreferences.unwrap();
343
344
  const GITHUB_COPILOT_MIGRATION_STATUS_TYPE_SYMBOL = "dsh-github-copilot#GitHubCopilotMigrationStatus";
344
345
  const selectionSchema = z.object({
345
346
  provider: z.string().min(1).max(512),
@@ -420,6 +421,25 @@ const contribution = {
420
421
  }],
421
422
  result
422
423
  })),
424
+ {
425
+ id: "dsh-github-copilot:githubCopilot.setModelExcluded",
426
+ service: "githubCopilotAuthorization",
427
+ namespace: "githubCopilot",
428
+ method: "setModelExcluded",
429
+ invocation: direct,
430
+ parameters: [{
431
+ name: "modelId",
432
+ wire: "modelId",
433
+ source: "json",
434
+ codec: strictRemoteCodec("dsh-github-copilot#GitHubCopilotModelId", z.string().min(1).max(512))
435
+ }, {
436
+ name: "excluded",
437
+ wire: "excluded",
438
+ source: "json",
439
+ codec: strictRemoteCodec("dsh-github-copilot#GitHubCopilotModelExcluded", z.boolean())
440
+ }],
441
+ result: strictRemoteCodec("dsh-github-copilot#GitHubCopilotModelPreferencesView", GitHubCopilotModelPreferencesViewSchema)
442
+ },
423
443
  {
424
444
  id: "dsh-github-copilot:githubCopilot.migrationStatus",
425
445
  service: "githubCopilotAuthorization",
@@ -436,4 +456,4 @@ const contribution = {
436
456
  ]
437
457
  };
438
458
  //#endregion
439
- export { GITHUB_COPILOT_AUTHORIZATION_VIEW_TYPE_SYMBOL, GITHUB_COPILOT_MIGRATION_STATUS_TYPE_SYMBOL, GitHubCopilotAuthorizationViewSchema, GitHubCopilotMigrationStatusSchema, contribution as default };
459
+ export { GITHUB_COPILOT_AUTHORIZATION_VIEW_TYPE_SYMBOL, GITHUB_COPILOT_MIGRATION_STATUS_TYPE_SYMBOL, GitHubCopilotAuthorizationViewSchema, GitHubCopilotMigrationStatusSchema, GitHubCopilotModelPreferencesViewSchema, contribution as default };
@@ -0,0 +1,4 @@
1
+ import type { Agent } from '@deepseek-ai/dsh-agent';
2
+ /** Resolve the owning preset's service without reaching into Core's service registry. */
3
+ export declare function agentCompaction(agent: Agent): unknown;
4
+ //# sourceMappingURL=agent-compaction.d.ts.map
@@ -101,6 +101,7 @@ export declare class GitHubCopilotAuthorizationController extends TypertRemoteSe
101
101
  status(): Promise<GitHubCopilotAuthorizationView>;
102
102
  excludeModel(modelId: string): Promise<GitHubCopilotAuthorizationView>;
103
103
  restoreModel(modelId: string): Promise<GitHubCopilotAuthorizationView>;
104
+ setModelExcluded(modelId: string, excluded: boolean): Promise<GitHubCopilotModelPreferencesView>;
104
105
  /** Explicit model discovery: may refresh OAuth and GET the account catalog, never changes selection. */
105
106
  discoverModels(): Promise<GitHubCopilotAuthorizationView>;
106
107
  /** Ensure metadata for a visible account view, honoring shared cache and failure cooldown. */
@@ -16,6 +16,7 @@ export interface AutoModelHostDependencies {
16
16
  budgetPolicy?: () => Partial<RequestBudgetPolicy>;
17
17
  parentModelBindings?: () => readonly ParentModelBinding[];
18
18
  followParentModel?: () => boolean;
19
+ admitModel?: (agent: Agent, turn: number, model: string, signal: AbortSignal) => void;
19
20
  }
20
21
  /** Resolve virtual Auto once per Core turn before request/header persistence. */
21
22
  export declare function installAutoModelRouting(ctx: Context, dependencies: AutoModelHostDependencies): () => void;
@@ -1,4 +1,12 @@
1
1
  export declare const MAX_EXCLUDED_MODEL_IDS = 512;
2
+ /** Admission is bound to the native turn and its request signal, not the global picker. */
3
+ export declare class ModelExclusionTurns {
4
+ private readonly turns;
5
+ private readonly signals;
6
+ admit(owner: object, turn: number, model: string, signal: AbortSignal, excluded: ReadonlySet<string>): boolean;
7
+ permits(signal: AbortSignal | undefined, model: string): boolean;
8
+ end(owner: object): void;
9
+ }
2
10
  export declare function normalizeExcludedModelIds(value: unknown): readonly string[];
3
11
  export declare function excludedModelSet(value: unknown): ReadonlySet<string>;
4
12
  export declare function filterExcludedModels<T extends {
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import type { RemoteResult, TypertRemoteContribution } from '@deepseek-ai/dsh-typert-protocol';
5
5
  import { z } from 'zod';
6
- import type { GitHubCopilotAuthorizationView } from './authorization-controller.ts';
6
+ import type { GitHubCopilotAuthorizationView, GitHubCopilotModelPreferencesView } from './authorization-controller.ts';
7
7
  import type { GitHubCopilotMigrationStatus } from './migration-status.ts';
8
8
  declare module '@deepseek-ai/dsh-typert-protocol' {
9
9
  interface TypertRemoteNamespaceMap {
@@ -15,6 +15,7 @@ declare module '@deepseek-ai/dsh-typert-protocol' {
15
15
  ensureModels(): Promise<RemoteResult<GitHubCopilotAuthorizationView>>;
16
16
  excludeModel(modelId: string): Promise<RemoteResult<GitHubCopilotAuthorizationView>>;
17
17
  restoreModel(modelId: string): Promise<RemoteResult<GitHubCopilotAuthorizationView>>;
18
+ setModelExcluded(modelId: string, excluded: boolean): Promise<RemoteResult<GitHubCopilotModelPreferencesView>>;
18
19
  start(): Promise<RemoteResult<GitHubCopilotAuthorizationView>>;
19
20
  cancel(): Promise<RemoteResult<GitHubCopilotAuthorizationView>>;
20
21
  signOut(): Promise<RemoteResult<GitHubCopilotAuthorizationView>>;
@@ -117,6 +118,26 @@ export declare const GitHubCopilotAuthorizationViewSchema: z.ZodObject<{
117
118
  INTERACTION_NOTICE_OBSERVED: "INTERACTION_NOTICE_OBSERVED";
118
119
  }>>;
119
120
  }, z.core.$strict>;
121
+ export declare const GitHubCopilotModelPreferencesViewSchema: z.ZodObject<{
122
+ state: z.ZodEnum<{
123
+ error: "error";
124
+ ready: "ready";
125
+ }>;
126
+ writable: z.ZodBoolean;
127
+ revision: z.ZodOptional<z.ZodNumber>;
128
+ excludedModelIds: z.ZodArray<z.ZodString>;
129
+ lockedModelIds: z.ZodArray<z.ZodString>;
130
+ unavailableExcludedModelIds: z.ZodArray<z.ZodString>;
131
+ error: z.ZodOptional<z.ZodEnum<{
132
+ COPILOT_MODEL_PREFERENCES_UNAVAILABLE: "COPILOT_MODEL_PREFERENCES_UNAVAILABLE";
133
+ COPILOT_MODEL_EXCLUSION_SELECTED: "COPILOT_MODEL_EXCLUSION_SELECTED";
134
+ COPILOT_MODEL_EXCLUSION_CONFLICT: "COPILOT_MODEL_EXCLUSION_CONFLICT";
135
+ COPILOT_MODEL_EXCLUSION_SAVE_FAILED: "COPILOT_MODEL_EXCLUSION_SAVE_FAILED";
136
+ COPILOT_MODEL_SETTINGS_UNAVAILABLE: "COPILOT_MODEL_SETTINGS_UNAVAILABLE";
137
+ COPILOT_MODEL_SETTINGS_INVALID: "COPILOT_MODEL_SETTINGS_INVALID";
138
+ COPILOT_MODEL_SELECTION_UNAVAILABLE: "COPILOT_MODEL_SELECTION_UNAVAILABLE";
139
+ }>>;
140
+ }, z.core.$strict>;
120
141
  export declare const GITHUB_COPILOT_MIGRATION_STATUS_TYPE_SYMBOL = "dsh-github-copilot#GitHubCopilotMigrationStatus";
121
142
  /** Independent Ops result: strict at every object level; no account or private Session data. */
122
143
  export declare const GitHubCopilotMigrationStatusSchema: z.ZodObject<{