dsh-github-copilot 0.4.0-alpha.97 → 0.4.0-alpha.99

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
@@ -1656,14 +1656,14 @@ function isZeroContextUsage(usage) {
1656
1656
  //#endregion
1657
1657
  //#region lib/types/context-evidence.js
1658
1658
  const COPILOT_CONTEXT_EVIDENCE = "githubCopilotContextEvidence";
1659
- const count$1 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
1659
+ const count$2 = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
1660
1660
  const routeSchema = z$1.object({
1661
1661
  provider: z$1.string().min(1),
1662
1662
  model: z$1.string().min(1)
1663
1663
  }).strict();
1664
1664
  const sampleSchema = z$1.object({
1665
- tokens: count$1,
1666
- seq: count$1,
1665
+ tokens: count$2,
1666
+ seq: count$2,
1667
1667
  route: routeSchema
1668
1668
  }).strict();
1669
1669
  const ContextEvidenceSchema = z$1.object({
@@ -1679,14 +1679,14 @@ const ContextEvidenceSchema = z$1.object({
1679
1679
  ])
1680
1680
  }).strict();
1681
1681
  const usageSchema = z$1.object({
1682
- inputTokens: count$1,
1683
- outputTokens: count$1,
1684
- cacheReadTokens: count$1.optional(),
1685
- cacheWriteTokens: count$1.optional(),
1686
- totalTokens: count$1.optional(),
1687
- reasoningTokens: count$1.optional()
1682
+ inputTokens: count$2,
1683
+ outputTokens: count$2,
1684
+ cacheReadTokens: count$2.optional(),
1685
+ cacheWriteTokens: count$2.optional(),
1686
+ totalTokens: count$2.optional(),
1687
+ reasoningTokens: count$2.optional()
1688
1688
  });
1689
- function record$9(value) {
1689
+ function record$10(value) {
1690
1690
  return typeof value === "object" && value !== null && !Array.isArray(value);
1691
1691
  }
1692
1692
  function sameRoute$1(left, right) {
@@ -1705,10 +1705,10 @@ function initialContextEvidence() {
1705
1705
  }
1706
1706
  /** Read only counts and routing leaves; never message content or opaque replay. */
1707
1707
  function foldContextEvidence(state, event) {
1708
- if (!record$9(event) || typeof event.type !== "string" || !record$9(event.data)) return state;
1708
+ if (!record$10(event) || typeof event.type !== "string" || !record$10(event.data)) return state;
1709
1709
  if (event.type === "request/header" || event.type === "model/selection") {
1710
- const raw = event.type === "request/header" ? record$9(event.data.header) ? event.data.header.config : void 0 : event.data;
1711
- if (!record$9(raw)) return {
1710
+ const raw = event.type === "request/header" ? record$10(event.data.header) ? event.data.header.config : void 0 : event.data;
1711
+ if (!record$10(raw)) return {
1712
1712
  ...state,
1713
1713
  route: null,
1714
1714
  sample: null,
@@ -1747,7 +1747,7 @@ function foldContextEvidence(state, event) {
1747
1747
  if (!copilot(state.route)) return state;
1748
1748
  if (event.type === "assistant/message" && event.data.source !== void 0) {
1749
1749
  const source = event.data.source;
1750
- const parsed = routeSchema.safeParse(record$9(source) ? {
1750
+ const parsed = routeSchema.safeParse(record$10(source) ? {
1751
1751
  provider: source.provider,
1752
1752
  model: source.model
1753
1753
  } : source);
@@ -1763,13 +1763,13 @@ function foldContextEvidence(state, event) {
1763
1763
  const settledUsage = usage !== void 0;
1764
1764
  let terminal;
1765
1765
  for (const entry of stream) {
1766
- if (!record$9(entry) || entry.type !== "chunk" || !record$9(entry.chunk)) continue;
1766
+ if (!record$10(entry) || entry.type !== "chunk" || !record$10(entry.chunk)) continue;
1767
1767
  if (!settledUsage && entry.chunk.type === "usage") usage = entry.chunk.usage;
1768
1768
  if (entry.chunk.type === "finish") terminal = entry.chunk.reason;
1769
1769
  }
1770
1770
  if (usage === void 0) return state;
1771
1771
  const parsed = usageSchema.safeParse(usage);
1772
- if (!parsed.success || !count$1.safeParse(event.seq).success) return {
1772
+ if (!parsed.success || !count$2.safeParse(event.seq).success) return {
1773
1773
  ...state,
1774
1774
  sample: null,
1775
1775
  invalid: true,
@@ -1777,7 +1777,7 @@ function foldContextEvidence(state, event) {
1777
1777
  };
1778
1778
  const value = parsed.data;
1779
1779
  const zero = isZeroContextUsage(value);
1780
- const successful = record$9(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
1780
+ const successful = record$10(terminal) && (terminal.kind === "stop" || terminal.kind === "max-tokens" || terminal.kind === "tool-calls");
1781
1781
  if (zero && !successful) {
1782
1782
  const reason = state.sample !== null || state.reason === "none" ? "failed-zero" : state.reason;
1783
1783
  return {
@@ -1797,7 +1797,7 @@ function foldContextEvidence(state, event) {
1797
1797
  ...state,
1798
1798
  sample: {
1799
1799
  tokens,
1800
- seq: count$1.parse(event.seq),
1800
+ seq: count$2.parse(event.seq),
1801
1801
  route: state.route
1802
1802
  },
1803
1803
  invalid: false,
@@ -1819,7 +1819,7 @@ const contextEvidenceDefinition = {
1819
1819
  function installContextEvidence(ctx) {
1820
1820
  ctx.inject(["sessionProjections"], (scope) => {
1821
1821
  const registry = scope.get("sessionProjections");
1822
- if (!record$9(registry) || typeof registry.register !== "function") {
1822
+ if (!record$10(registry) || typeof registry.register !== "function") {
1823
1823
  scope.logger.warn("[github-copilot] COPILOT_CONTEXT_PROJECTION_UNAVAILABLE");
1824
1824
  return;
1825
1825
  }
@@ -1833,7 +1833,7 @@ function installContextEvidence(ctx) {
1833
1833
  //#endregion
1834
1834
  //#region package.json
1835
1835
  var name$1 = "dsh-github-copilot";
1836
- var version = "0.4.0-alpha.97";
1836
+ var version = "0.4.0-alpha.99";
1837
1837
  //#endregion
1838
1838
  //#region lib/types/probe.js
1839
1839
  /**
@@ -2845,7 +2845,7 @@ function buildAnthropicWireBody(request, cfg, model) {
2845
2845
  }
2846
2846
  //#endregion
2847
2847
  //#region lib/types/responses-reasoning-text.js
2848
- function record$8(value) {
2848
+ function record$9(value) {
2849
2849
  return typeof value === "object" && value !== null;
2850
2850
  }
2851
2851
  function responseIndex(value) {
@@ -2903,13 +2903,13 @@ var ResponsesReasoningText = class {
2903
2903
  }
2904
2904
  /** Only recognized public text fields are examined; no copying of the item. */
2905
2905
  snapshot(item) {
2906
- if (!record$8(item) || item.type !== "reasoning") return "";
2906
+ if (!record$9(item) || item.type !== "reasoning") return "";
2907
2907
  let delta = "";
2908
2908
  for (const family of ["summary", "raw"]) {
2909
2909
  const value = family === "summary" ? item.summary : item.content;
2910
2910
  if (!Array.isArray(value)) continue;
2911
2911
  for (const [index, part] of value.entries()) {
2912
- if (!record$8(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
2912
+ if (!record$9(part) || part.type !== (family === "summary" ? "summary_text" : "reasoning_text")) continue;
2913
2913
  delta += this.update(family, index, part.text, true);
2914
2914
  }
2915
2915
  }
@@ -5456,13 +5456,13 @@ function requestBodyEvidence(body, protocol) {
5456
5456
  }
5457
5457
  //#endregion
5458
5458
  //#region lib/types/replay-recovery.js
5459
- function record$7(value) {
5459
+ function record$8(value) {
5460
5460
  return value !== null && typeof value === "object" && !Array.isArray(value);
5461
5461
  }
5462
5462
  function parsed(body) {
5463
5463
  if (requestBodyEvidence(body, "openai-responses").state !== "complete" || body === void 0) throw new Error("COPILOT_REPLAY_RECOVERY_EVIDENCE_UNAVAILABLE");
5464
5464
  const payload = JSON.parse(body);
5465
- if (!record$7(payload) || !Array.isArray(payload.input) || !payload.input.every(record$7)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
5465
+ if (!record$8(payload) || !Array.isArray(payload.input) || !payload.input.every(record$8)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
5466
5466
  return {
5467
5467
  input: payload.input,
5468
5468
  payload
@@ -5558,7 +5558,7 @@ var ReplayRecoveryStore = class {
5558
5558
  const value = hash(item);
5559
5559
  return value === void 0 || !admitted.has(value);
5560
5560
  }).length === decoded.input.length) return payload;
5561
- if (!record$7(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
5561
+ if (!record$8(payload) || !Array.isArray(payload.input)) throw new Error("COPILOT_REPLAY_RECOVERY_INVALID_PAYLOAD");
5562
5562
  const input = payload.input.filter((_, index) => {
5563
5563
  const item = decoded.input[index];
5564
5564
  const value = hash(item);
@@ -6056,7 +6056,7 @@ const REQUEST_BODY_TIMEOUT_MARKER = "COPILOT_REQUEST_BODY_TIMEOUT: Copilot retur
6056
6056
  function object$2(value) {
6057
6057
  return typeof value === "object" && value !== null;
6058
6058
  }
6059
- function count(value) {
6059
+ function count$1(value) {
6060
6060
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
6061
6061
  }
6062
6062
  /** Observe public native events only; never read request fields, mutate transport or imply remote receipt. */
@@ -6068,7 +6068,7 @@ function createRequestUploadObserver() {
6068
6068
  let socket;
6069
6069
  let connectionAmbiguous = false, socketBoundToRequest = false;
6070
6070
  let alpn = "unavailable", nodeWritableBufferBytes;
6071
- const elapsed = () => startedAt === void 0 ? void 0 : count(Math.round(performance.now() - startedAt));
6071
+ const elapsed = () => startedAt === void 0 ? void 0 : count$1(Math.round(performance.now() - startedAt));
6072
6072
  const request = (data) => !closed && object$2(data) && object$2(data.request) ? requests.get(data.request) : void 0;
6073
6073
  const connected = (data, boundToRequest = false) => {
6074
6074
  if (closed || !object$2(data) || !object$2(data.socket)) return;
@@ -6103,7 +6103,7 @@ function createRequestUploadObserver() {
6103
6103
  if (request(data) !== 1 || bodyWrite) return;
6104
6104
  bodyWrite = true;
6105
6105
  bodyWriteCompleteMs = elapsed();
6106
- nodeWritableBufferBytes = count(socket?.writableLength);
6106
+ nodeWritableBufferBytes = count$1(socket?.writableLength);
6107
6107
  },
6108
6108
  "undici:request:headers": (data) => {
6109
6109
  if (request(data) === 1 && nativeResponseHeadersMs === void 0) nativeResponseHeadersMs = elapsed();
@@ -6153,16 +6153,16 @@ function formatRequestUploadEvidence(evidence) {
6153
6153
  //#endregion
6154
6154
  //#region lib/types/request-body-timeout.js
6155
6155
  const observedMessage = "Timed out reading request body. Try again, or use a smaller request size.";
6156
- function record$6(value) {
6156
+ function record$7(value) {
6157
6157
  return typeof value === "object" && value !== null && !Array.isArray(value);
6158
6158
  }
6159
6159
  /** Verified provider evidence, not guessed capabilities, token limits or network cause. */
6160
6160
  async function requestBodyTimeoutDiagnostic(response, body, signal, dispatch) {
6161
6161
  if (response.status !== 408 || signal?.aborted) return void 0;
6162
6162
  const value = await readResponseErrorJson(response, signal);
6163
- if (signal?.aborted || !record$6(value)) return void 0;
6163
+ if (signal?.aborted || !record$7(value)) return void 0;
6164
6164
  const error = Object.hasOwn(value, "error") ? value.error : value;
6165
- if (!record$6(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;
6165
+ if (!record$7(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;
6166
6166
  const size = body === void 0 ? "Request body size unavailable." : `Request body: ${Buffer.byteLength(body, "utf8")} UTF-8 bytes (not context tokens).`;
6167
6167
  const composition = formatRequestBodyEvidence(dispatch === void 0 ? { state: "unavailable" } : requestBodyEvidence(body, dispatch.protocol), dispatch?.responseHeadersMs);
6168
6168
  const upload = formatRequestUploadEvidence(dispatch?.upload);
@@ -6510,6 +6510,7 @@ function createAccountProvider(descriptors, guard, baseURL) {
6510
6510
  } : options.onPayload;
6511
6511
  const fetch = options.fetch ?? globalThis.fetch;
6512
6512
  const observeResponse = async (input, init) => {
6513
+ guard.requestCheckpoint?.();
6513
6514
  guard.onRequestBodyTimeout?.(void 0);
6514
6515
  liveness?.beginRequest(typeof init?.body === "string" ? init.body : void 0);
6515
6516
  const replayHeaders = responses && init?.headers !== void 0 ? new Headers(init.headers) : void 0;
@@ -6650,7 +6651,7 @@ var Budget = class {
6650
6651
  if (this.consumed > ACCOUNT_MODEL_CATALOG_LIMITS.maxBytes) fail("CATALOG_TOO_LARGE", true);
6651
6652
  }
6652
6653
  };
6653
- function record$5(value, code) {
6654
+ function record$6(value, code) {
6654
6655
  if (typeof value !== "object" || value === null || Array.isArray(value)) fail(code);
6655
6656
  return value;
6656
6657
  }
@@ -6703,11 +6704,11 @@ function normalizeModel(raw, id, options, budget) {
6703
6704
  if (options.availableModelIds?.has(id) !== true) fail("MISSING_POLICY");
6704
6705
  policySource = "account-available-id";
6705
6706
  } else {
6706
- if (text$1(field(record$5(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail("POLICY_NOT_ENABLED");
6707
+ if (text$1(field(record$6(rawPolicy, "INVALID_POLICY"), "state", budget), 64, "INVALID_POLICY", budget) !== "enabled") fail("POLICY_NOT_ENABLED");
6707
6708
  policySource = "server-enabled";
6708
6709
  }
6709
- const capabilities = record$5(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
6710
- const supports = record$5(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
6710
+ const capabilities = record$6(field(raw, "capabilities", budget), "INVALID_CAPABILITIES");
6711
+ const supports = record$6(field(capabilities, "supports", budget), "INVALID_SUPPORTS");
6711
6712
  const streaming = field(supports, "streaming", budget);
6712
6713
  if (streaming === false) fail("STREAMING_UNSUPPORTED");
6713
6714
  if (streaming !== true) fail("INVALID_SUPPORTS");
@@ -6728,7 +6729,7 @@ function normalizeModel(raw, id, options, budget) {
6728
6729
  if (selected === void 0) fail(unsupportedEndpointCount === 0 && endpoints.includes("ws:/responses") ? "WEBSOCKET_ONLY" : "UNSUPPORTED_ENDPOINTS");
6729
6730
  const rawLimits = field(capabilities, "limits", budget);
6730
6731
  if (rawLimits === void 0) fail("MISSING_LIMITS");
6731
- const limits = record$5(rawLimits, "INVALID_LIMITS");
6732
+ const limits = record$6(rawLimits, "INVALID_LIMITS");
6732
6733
  const maxContext = optionalPositive(limits, "max_context_window_tokens", "INVALID_LIMITS", budget);
6733
6734
  const maxInputTokens = optionalPositive(limits, "max_prompt_tokens", "INVALID_LIMITS", budget);
6734
6735
  if (maxContext === void 0 && maxInputTokens === void 0) fail("MISSING_CONTEXT_LIMIT");
@@ -6746,7 +6747,7 @@ function normalizeModel(raw, id, options, budget) {
6746
6747
  if (vision === true) {
6747
6748
  const rawVisionLimits = field(limits, "vision", budget);
6748
6749
  if (rawVisionLimits !== void 0) {
6749
- const rawMediaTypes = field(record$5(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
6750
+ const rawMediaTypes = field(record$6(rawVisionLimits, "INVALID_VISION_LIMITS"), "supported_media_types", budget);
6750
6751
  if (rawMediaTypes !== void 0) {
6751
6752
  const mediaTypes = stringList(rawMediaTypes, ACCOUNT_MODEL_CATALOG_LIMITS.maxMediaTypes, 128, "INVALID_VISION_LIMITS", budget);
6752
6753
  const mime = /^[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*\/[a-z0-9][a-z0-9!#$%&'*+.^_`|~-]*$/iu;
@@ -6808,7 +6809,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
6808
6809
  fail("INVALID_JSON", true);
6809
6810
  }
6810
6811
  }
6811
- const data = field(record$5(raw, "INVALID_CATALOG"), "data", budget);
6812
+ const data = field(record$6(raw, "INVALID_CATALOG"), "data", budget);
6812
6813
  if (!Array.isArray(data)) fail("INVALID_CATALOG");
6813
6814
  const count = field(data, "length", budget);
6814
6815
  if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) fail("INVALID_CATALOG");
@@ -6831,7 +6832,7 @@ function normalizeAccountModelCatalog(raw, options = {}) {
6831
6832
  for (let index = 0; index < count; index++) {
6832
6833
  let id;
6833
6834
  try {
6834
- const candidate = record$5(field(data, String(index), budget), "INVALID_MODEL");
6835
+ const candidate = record$6(field(data, String(index), budget), "INVALID_MODEL");
6835
6836
  const candidateId = text$1(field(candidate, "id", budget), ACCOUNT_MODEL_CATALOG_LIMITS.maxIdLength, "INVALID_ID", budget);
6836
6837
  if (!identifier.test(candidateId)) fail("INVALID_ID");
6837
6838
  id = candidateId;
@@ -7263,7 +7264,7 @@ function createAccountModelSource(dependencies) {
7263
7264
  }
7264
7265
  //#endregion
7265
7266
  //#region lib/types/agent-compaction.js
7266
- function record$4(value) {
7267
+ function record$5(value) {
7267
7268
  return typeof value === "object" && value !== null;
7268
7269
  }
7269
7270
  /** Resolve the owning preset's service without reaching into Core's service registry. */
@@ -7271,7 +7272,7 @@ function agentCompaction(agent) {
7271
7272
  if (typeof agent.ctx?.get !== "function") throw new LlmError("COPILOT_COMPACTION_AGENT_CONTEXT_UNAVAILABLE", "INVALID_REQUEST");
7272
7273
  const presets = agent.ctx.get("agentPresets");
7273
7274
  if (presets !== void 0) {
7274
- if (!record$4(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
7275
+ if (!record$5(presets) || typeof presets.composedPreset !== "function" || typeof presets.serviceFor !== "function") throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
7275
7276
  const preset = presets.composedPreset(agent.ctx);
7276
7277
  if (preset !== void 0) {
7277
7278
  if (typeof preset !== "string" || preset.trim().length === 0) throw new LlmError("COPILOT_COMPACTION_PRESET_LOOKUP_UNAVAILABLE", "INVALID_REQUEST");
@@ -7394,14 +7395,14 @@ function installCopilotCompactionPressure(ctx, callbacks) {
7394
7395
  }
7395
7396
  //#endregion
7396
7397
  //#region lib/types/pre-step-pressure.js
7397
- function record$3(value) {
7398
+ function record$4(value) {
7398
7399
  return typeof value === "object" && value !== null && !Array.isArray(value);
7399
7400
  }
7400
7401
  function positive(value) {
7401
7402
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
7402
7403
  }
7403
7404
  function isEngine(value) {
7404
- return record$3(value) && record$3(value.config) && typeof value.compactIfNeeded === "function";
7405
+ return record$4(value) && record$4(value.config) && typeof value.compactIfNeeded === "function";
7405
7406
  }
7406
7407
  /**
7407
7408
  * Prevent a continuing, unchanged route's known pressure from becoming an
@@ -7422,12 +7423,12 @@ function installCopilotPreStepPressure(ctx, callbacks) {
7422
7423
  const header = agent.session.requestHeader();
7423
7424
  if (header?.config.provider !== "github-copilot-preview" || !isPluginPreviewProvider(ctx, header.config.provider)) return decision;
7424
7425
  const projections = ctx.get("sessionProjections");
7425
- if (!record$3(projections) || typeof projections.stateOf !== "function") {
7426
+ if (!record$4(projections) || typeof projections.stateOf !== "function") {
7426
7427
  unavailable();
7427
7428
  return decision;
7428
7429
  }
7429
7430
  const selection = projections.stateOf(agent.session, "modelSelection");
7430
- if (!record$3(selection) || !Object.hasOwn(selection, "pending")) {
7431
+ if (!record$4(selection) || !Object.hasOwn(selection, "pending")) {
7431
7432
  unavailable();
7432
7433
  return decision;
7433
7434
  }
@@ -7449,20 +7450,20 @@ function installCopilotPreStepPressure(ctx, callbacks) {
7449
7450
  unavailable();
7450
7451
  return decision;
7451
7452
  }
7452
- const policy = Array.isArray(config.modelPolicies) ? config.modelPolicies.find((value) => record$3(value) && value.provider === header.config.provider && value.model === header.config.model) : void 0;
7453
- const retries = record$3(policy) ? policy.maxOverflowRetries ?? config.maxOverflowRetries : config.maxOverflowRetries;
7453
+ 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;
7454
+ const retries = record$4(policy) ? policy.maxOverflowRetries ?? config.maxOverflowRetries : config.maxOverflowRetries;
7454
7455
  if (retries === 0) return decision;
7455
7456
  if (!positive(retries)) {
7456
7457
  unavailable();
7457
7458
  return decision;
7458
7459
  }
7459
7460
  const meter = ctx.get("tokenMeter");
7460
- if (!record$3(meter) || typeof meter.measure !== "function") {
7461
+ if (!record$4(meter) || typeof meter.measure !== "function") {
7461
7462
  unavailable();
7462
7463
  return decision;
7463
7464
  }
7464
7465
  const measured = meter.measure(agent.session);
7465
- if (!record$3(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) {
7466
+ if (!record$4(measured) || typeof measured.totalTokens !== "number" || !Number.isSafeInteger(measured.totalTokens) || measured.totalTokens < 0) {
7466
7467
  unavailable();
7467
7468
  return decision;
7468
7469
  }
@@ -7580,17 +7581,17 @@ const TaskAssessmentSchema = z$1.object({
7580
7581
  "insufficient-evidence"
7581
7582
  ])).max(7)
7582
7583
  }).strict();
7583
- function record$2(value) {
7584
+ function record$3(value) {
7584
7585
  return typeof value === "object" && value !== null && !Array.isArray(value);
7585
7586
  }
7586
7587
  function text(message) {
7587
- if (!record$2(message) || !Array.isArray(message.content)) return "";
7588
- return message.content.flatMap((block) => record$2(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
7588
+ if (!record$3(message) || !Array.isArray(message.content)) return "";
7589
+ return message.content.flatMap((block) => record$3(block) && block.type === "text" && typeof block.text === "string" ? [block.text] : []).join("\n");
7589
7590
  }
7590
7591
  function user(message) {
7591
- if (!record$2(message)) return false;
7592
- if (record$2(message.source) && message.source.kind === "model-selection") return false;
7593
- return message.role === "user" || record$2(message.source) && message.source.kind === "user";
7592
+ if (!record$3(message)) return false;
7593
+ if (record$3(message.source) && message.source.kind === "model-selection") return false;
7594
+ return message.role === "user" || record$3(message.source) && message.source.kind === "user";
7594
7595
  }
7595
7596
  function difficult(current) {
7596
7597
  return /\b(prove|proof|theorem|debug|investigate|diagnose)\b|证明|定理|调试|排查|根因|调查/iu.test(current);
@@ -7607,8 +7608,8 @@ function assessTaskLocally(messages) {
7607
7608
  const last = messages.findLast(user);
7608
7609
  const current = text(last).trim();
7609
7610
  const history = messages.slice(0, last === void 0 ? 0 : messages.lastIndexOf(last));
7610
- const hasWork = history.some((message) => record$2(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$2(message.source) && message.source.kind === "model"));
7611
- const nonText = record$2(last) && Array.isArray(last.content) && last.content.some((block) => !record$2(block) || block.type !== "text");
7611
+ const hasWork = history.some((message) => record$3(message) && (message.role === "assistant" || message.role === "tool" || user(message) || record$3(message.source) && message.source.kind === "model"));
7612
+ const nonText = record$3(last) && Array.isArray(last.content) && last.content.some((block) => !record$3(block) || block.type !== "text");
7612
7613
  if (!hasWork && !nonText && /^(hello|hi|hey|你好|您好|嗨)[!!。.\s]*$/iu.test(current)) return {
7613
7614
  demand: "simple",
7614
7615
  source: "local",
@@ -7650,7 +7651,7 @@ function assessTaskLocally(messages) {
7650
7651
  /** Separate text-only projection for assessment; never mutates the chat request. */
7651
7652
  function assessmentInput(messages) {
7652
7653
  let omitted = false;
7653
- const context = messages.filter((message) => !record$2(message) || message.role !== "system" && message.role !== "developer" && !(record$2(message.source) && message.source.kind === "model-selection"));
7654
+ const context = messages.filter((message) => !record$3(message) || message.role !== "system" && message.role !== "developer" && !(record$3(message.source) && message.source.kind === "model-selection"));
7654
7655
  const lastUser = context.findLastIndex(user);
7655
7656
  const priorUser = context.slice(0, lastUser < 0 ? 0 : lastUser).findLastIndex(user);
7656
7657
  const priority = [.../* @__PURE__ */ new Set([
@@ -7662,13 +7663,13 @@ function assessmentInput(messages) {
7662
7663
  let length = 0;
7663
7664
  for (const index of priority) {
7664
7665
  const message = context[index];
7665
- if (!record$2(message)) {
7666
+ if (!record$3(message)) {
7666
7667
  omitted = true;
7667
7668
  continue;
7668
7669
  }
7669
7670
  if (!Array.isArray(message.content)) omitted = true;
7670
7671
  const content = text(message);
7671
- if (Array.isArray(message.content) && message.content.some((block) => !record$2(block) || block.type !== "text")) omitted = true;
7672
+ if (Array.isArray(message.content) && message.content.some((block) => !record$3(block) || block.type !== "text")) omitted = true;
7672
7673
  if (content.length > 1600) omitted = true;
7673
7674
  const role = typeof message.role === "string" && [
7674
7675
  "user",
@@ -7725,13 +7726,24 @@ async function assessAutoTask(messages, dependencies) {
7725
7726
  diagnostic: "unavailable"
7726
7727
  };
7727
7728
  }
7729
+ const classify = dependencies.classify;
7728
7730
  const budgetMs = dependencies.timeoutMs ?? 8e3;
7731
+ const deadline = performance.now() + budgetMs;
7729
7732
  const evidence = assessmentEvidence(budgetMs);
7730
- const timeout = AbortSignal.timeout(budgetMs);
7731
- const signal = AbortSignal.any([dependencies.signal, timeout]);
7732
- const input = assessmentInput(messages);
7733
+ const timeout = new AbortController();
7734
+ const expire = () => timeout.abort(new DOMException("Auto assessment deadline exceeded", "TimeoutError"));
7735
+ const timer = setTimeout(expire, budgetMs);
7736
+ const signal = AbortSignal.any([dependencies.signal, timeout.signal]);
7737
+ const checkpoint = () => {
7738
+ if (dependencies.signal.aborted) throw dependencies.signal.reason;
7739
+ if (performance.now() >= deadline) expire();
7740
+ if (signal.aborted) throw signal.reason;
7741
+ };
7733
7742
  let remove = () => {};
7743
+ let settled = false;
7734
7744
  try {
7745
+ const input = assessmentInput(messages);
7746
+ checkpoint();
7735
7747
  const aborted = new Promise((_resolve, reject) => {
7736
7748
  const abort = () => reject(signal.reason);
7737
7749
  signal.addEventListener("abort", abort, { once: true });
@@ -7739,10 +7751,16 @@ async function assessAutoTask(messages, dependencies) {
7739
7751
  if (signal.aborted) abort();
7740
7752
  });
7741
7753
  const observe = (observation) => {
7742
- if (!signal.aborted) evidence.observe(observation);
7754
+ if (settled || signal.aborted) return;
7755
+ checkpoint();
7756
+ evidence.observe(observation);
7743
7757
  };
7744
- const output = await Promise.race([dependencies.classify(input, signal, observe), aborted]);
7745
- if (dependencies.signal.aborted) throw dependencies.signal.reason;
7758
+ const classification = Promise.resolve().then(() => {
7759
+ checkpoint();
7760
+ return classify(input, signal, observe, checkpoint);
7761
+ });
7762
+ const output = await Promise.race([classification, aborted]);
7763
+ checkpoint();
7746
7764
  if (output.length > 2048) throw new Error("INVALID_RESULT");
7747
7765
  let raw;
7748
7766
  try {
@@ -7751,6 +7769,7 @@ async function assessAutoTask(messages, dependencies) {
7751
7769
  throw new Error("INVALID_RESULT");
7752
7770
  }
7753
7771
  const parsed = TaskAssessmentSchema.safeParse(raw);
7772
+ checkpoint();
7754
7773
  if (!parsed.success) throw new Error("INVALID_RESULT");
7755
7774
  if (input.omitted && (parsed.data.demand === "simple" || parsed.data.demand === "routine")) {
7756
7775
  dependencies.diagnostic("COPILOT_AUTO_ASSESSMENT_CONTEXT_OMITTED");
@@ -7770,7 +7789,7 @@ async function assessAutoTask(messages, dependencies) {
7770
7789
  } catch (cause) {
7771
7790
  if (dependencies.signal.aborted) throw dependencies.signal.reason;
7772
7791
  if (cause instanceof TaskAssessmentRevokedError) throw cause.cause;
7773
- const code = timeout.aborted ? "timeout" : cause instanceof Error && cause.message === "INVALID_RESULT" ? "invalid-result" : cause instanceof Error && cause.message === "COPILOT_AUTO_CLASSIFIER_UNAVAILABLE" ? "unavailable" : "failed";
7792
+ const code = timeout.signal.aborted || performance.now() >= deadline ? "timeout" : cause instanceof Error && cause.message === "INVALID_RESULT" ? "invalid-result" : cause instanceof Error && cause.message === "COPILOT_AUTO_CLASSIFIER_UNAVAILABLE" ? "unavailable" : "failed";
7774
7793
  dependencies.diagnostic(`COPILOT_AUTO_ASSESSMENT_${code.toUpperCase().replace("-", "_")}`);
7775
7794
  return {
7776
7795
  ...local,
@@ -7778,6 +7797,8 @@ async function assessAutoTask(messages, dependencies) {
7778
7797
  semantic: evidence.finish(code === "invalid-result" ? "invalid" : "not-validated")
7779
7798
  };
7780
7799
  } finally {
7800
+ settled = true;
7801
+ clearTimeout(timer);
7781
7802
  remove();
7782
7803
  }
7783
7804
  }
@@ -7800,14 +7821,14 @@ var AutoModelRoutingError = class extends Error {
7800
7821
  this.name = "AutoModelRoutingError";
7801
7822
  }
7802
7823
  };
7803
- function record$1(value) {
7824
+ function record$2(value) {
7804
7825
  return typeof value === "object" && value !== null;
7805
7826
  }
7806
7827
  function userMessage(value) {
7807
- if (!record$1(value)) return false;
7808
- if (record$1(value.source) && value.source.kind === "model-selection") return false;
7828
+ if (!record$2(value)) return false;
7829
+ if (record$2(value.source) && value.source.kind === "model-selection") return false;
7809
7830
  if (value.role === "user") return true;
7810
- return record$1(value.source) && value.source.kind === "user";
7831
+ return record$2(value.source) && value.source.kind === "user";
7811
7832
  }
7812
7833
  function latestUserContent(messages) {
7813
7834
  for (let index = messages.length - 1; index >= 0; index--) {
@@ -7818,9 +7839,9 @@ function latestUserContent(messages) {
7818
7839
  }
7819
7840
  function classifyAutoModelTurn(messages) {
7820
7841
  let text = "";
7821
- const requiresImage = messages.some((message) => record$1(message) && Array.isArray(message.content) && message.content.some((block) => record$1(block) && block.type === "image" && block.offloaded !== true));
7842
+ 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));
7822
7843
  for (const block of latestUserContent(messages)) {
7823
- if (!record$1(block)) continue;
7844
+ if (!record$2(block)) continue;
7824
7845
  if (block.type === "text" && typeof block.text === "string") text += `${block.text}\n`;
7825
7846
  }
7826
7847
  const codeFenceCount = text.match(/```/gu)?.length ?? 0;
@@ -7870,7 +7891,7 @@ function resolveSeed(messages, context) {
7870
7891
  if (typeof context?.seed === "string" && context.seed.length > 0) return fnv1a(context.seed);
7871
7892
  if (context?.sessionId !== void 0) return fnv1a(`${context.sessionId}:${context.turn ?? 1}`);
7872
7893
  let text = "";
7873
- for (const block of latestUserContent(messages)) if (record$1(block) && typeof block.text === "string") text += block.text;
7894
+ for (const block of latestUserContent(messages)) if (record$2(block) && typeof block.text === "string") text += block.text;
7874
7895
  return fnv1a(text || "default-auto-seed");
7875
7896
  }
7876
7897
  function targetCategory(assessment, preference) {
@@ -8274,6 +8295,60 @@ function resolveParentModel(child, bindings, lookup, followAll = false) {
8274
8295
  }
8275
8296
  }
8276
8297
  //#endregion
8298
+ //#region lib/types/auto-model-intent.js
8299
+ const AUTO_MODEL_INTENT_PROJECTION = "githubCopilotAutoModelIntent";
8300
+ const count = z$1.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
8301
+ const selectionSchema = z$1.object({
8302
+ provider: z$1.string().min(1),
8303
+ model: z$1.string().min(1)
8304
+ }).strict();
8305
+ const AutoModelIntentSchema = z$1.object({
8306
+ inherited: count,
8307
+ selection: selectionSchema.nullable(),
8308
+ blocked: z$1.boolean()
8309
+ }).strict();
8310
+ function record$1(value) {
8311
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8312
+ }
8313
+ function initialAutoModelIntent(inherited = 0) {
8314
+ return {
8315
+ inherited,
8316
+ selection: null,
8317
+ blocked: false
8318
+ };
8319
+ }
8320
+ /** Request headers describe execution, not replacement of an explicit picker intent. */
8321
+ function foldAutoModelIntent(state, event) {
8322
+ if (!record$1(event) || event.type !== "model/selection") return state;
8323
+ if (!Number.isSafeInteger(event.seq) || Number(event.seq) < 0) return {
8324
+ ...state,
8325
+ selection: null,
8326
+ blocked: true
8327
+ };
8328
+ if (Number(event.seq) < state.inherited) return state;
8329
+ const data = event.data;
8330
+ const parsed = selectionSchema.safeParse(record$1(data) ? {
8331
+ provider: data.provider,
8332
+ model: data.model
8333
+ } : data);
8334
+ return parsed.success ? {
8335
+ ...state,
8336
+ selection: parsed.data,
8337
+ blocked: false
8338
+ } : {
8339
+ ...state,
8340
+ selection: null,
8341
+ blocked: true
8342
+ };
8343
+ }
8344
+ const autoModelIntentDefinition = {
8345
+ key: AUTO_MODEL_INTENT_PROJECTION,
8346
+ stateVersion: 1,
8347
+ stateSchema: AutoModelIntentSchema,
8348
+ init: (_header, inherited = 0) => initialAutoModelIntent(inherited),
8349
+ apply: foldAutoModelIntent
8350
+ };
8351
+ //#endregion
8277
8352
  //#region lib/types/auto-model-host.js
8278
8353
  function failure$1(code, kind = "INVALID_REQUEST") {
8279
8354
  return new LlmError(code, kind);
@@ -8332,13 +8407,6 @@ function buildRoutingContext(ctx, agent, turn, messages, budgetPolicyConfig) {
8332
8407
  previousModelId: requestHeader?.config.provider === "github-copilot-preview" ? requestHeader.config.model : void 0
8333
8408
  };
8334
8409
  }
8335
- function pendingAuto(ctx, agent) {
8336
- const candidate = ctx.get("sessionProjections");
8337
- if (!record(candidate) || typeof candidate.stateOf !== "function") return void 0;
8338
- const state = candidate.stateOf(agent.session, "modelSelection");
8339
- if (!record(state) || !record(state.pending) || state.pending.provider !== "github-copilot-preview") return void 0;
8340
- return typeof state.pending.model === "string" && autoModelPreference(state.pending.model) !== void 0 ? state.pending.model : void 0;
8341
- }
8342
8410
  function modelSelectionNotice(value) {
8343
8411
  return record(value) && record(value.source) && value.source.kind === "model-selection";
8344
8412
  }
@@ -8371,6 +8439,31 @@ function installAutoModelRouting(ctx, dependencies) {
8371
8439
  const pendingDecisions = /* @__PURE__ */ new WeakMap();
8372
8440
  const activeDecisions = /* @__PURE__ */ new Set();
8373
8441
  let active = true;
8442
+ let removeIntentProjection;
8443
+ const retainedAuto = (registry, session) => {
8444
+ if (typeof registry.register !== "function" || typeof registry.stateOf !== "function") throw failure$1("COPILOT_AUTO_INTENT_PROJECTIONS_UNAVAILABLE");
8445
+ if (!removeIntentProjection) {
8446
+ const remove = registry.register(autoModelIntentDefinition);
8447
+ if (typeof remove !== "function") throw failure$1("COPILOT_AUTO_INTENT_DISPOSER_UNAVAILABLE");
8448
+ removeIntentProjection = () => {
8449
+ remove();
8450
+ };
8451
+ }
8452
+ const intent = AutoModelIntentSchema.safeParse(registry.stateOf(session, AUTO_MODEL_INTENT_PROJECTION));
8453
+ if (!intent.success || intent.data.blocked) throw failure$1("COPILOT_AUTO_INTENT_UNAVAILABLE");
8454
+ const selection = intent.data.selection;
8455
+ return selection?.provider === "github-copilot-preview" && autoModelPreference(selection.model) !== void 0 ? selection.model : void 0;
8456
+ };
8457
+ const pendingAuto = (agent) => {
8458
+ const registry = ctx.get("sessionProjections");
8459
+ if (!record(registry) || typeof registry.stateOf !== "function") return void 0;
8460
+ const native = registry.stateOf(agent.session, "modelSelection");
8461
+ if (!record(native)) return void 0;
8462
+ const selection = native.pending;
8463
+ if (selection === null && agent.session.requestHeader()?.config.provider === "github-copilot-preview") return retainedAuto(registry, agent.session);
8464
+ if (!record(selection) || selection.provider !== "github-copilot-preview") return void 0;
8465
+ return typeof selection.model === "string" && autoModelPreference(selection.model) !== void 0 ? selection.model : void 0;
8466
+ };
8374
8467
  const decisionFor = (agent, turn, messages, preference, signal) => {
8375
8468
  if (!active || signal.aborted) return Promise.reject(signal.reason ?? failure$1("COPILOT_AUTO_DISPOSED", "ABORTED"));
8376
8469
  const completed = routed.get(agent);
@@ -8460,13 +8553,18 @@ function installAutoModelRouting(ctx, dependencies) {
8460
8553
  const pending = selection.pending === null ? null : followSelection(selection.pending);
8461
8554
  if (pending === void 0) throw failure$1("COPILOT_PARENT_MODEL_SELECTION_UNAVAILABLE");
8462
8555
  const header = session.requestHeader();
8556
+ const recorded = record(header) ? followSelection(header.config) : void 0;
8557
+ const retained = pending === null && recorded?.provider === "github-copilot-preview" ? retainedAuto(projections, session) : void 0;
8463
8558
  return {
8464
8559
  id: session.id,
8465
8560
  parentId: typeof session.header.parentSession === "string" ? session.header.parentSession : void 0,
8466
8561
  origin: typeof session.header.origin === "string" ? session.header.origin : void 0,
8467
8562
  state: parsed.data,
8468
8563
  pending,
8469
- recorded: record(header) ? followSelection(header.config) : void 0
8564
+ recorded: retained === void 0 ? recorded : {
8565
+ provider: GITHUB_COPILOT_PREVIEW_PROVIDER_ID,
8566
+ model: retained
8567
+ }
8470
8568
  };
8471
8569
  };
8472
8570
  const child = readSubject(agent);
@@ -8497,7 +8595,7 @@ function installAutoModelRouting(ctx, dependencies) {
8497
8595
  const effectiveAuto = (agent) => {
8498
8596
  const inherited = followIntent(agent);
8499
8597
  if (inherited !== void 0) return autoModelPreference(inherited.model) !== void 0 ? inherited.model : void 0;
8500
- return pendingAuto(ctx, agent);
8598
+ return pendingAuto(agent);
8501
8599
  };
8502
8600
  const installAgent = (agent) => {
8503
8601
  if (agentDisposers.has(agent)) return;
@@ -8512,7 +8610,7 @@ function installAutoModelRouting(ctx, dependencies) {
8512
8610
  model: inherited.model
8513
8611
  }
8514
8612
  };
8515
- const pending = pendingAuto(ctx, agent);
8613
+ const pending = pendingAuto(agent);
8516
8614
  if (pending === void 0) return assembled;
8517
8615
  return {
8518
8616
  ...assembled,
@@ -8530,6 +8628,15 @@ function installAutoModelRouting(ctx, dependencies) {
8530
8628
  turn,
8531
8629
  messages: entered
8532
8630
  });
8631
+ const admitted = routed.get(agent);
8632
+ if (result.kind === "enter" && !signal.aborted && admitted?.turn === turn && admitted.admitted !== void 0) {
8633
+ const filtered = result.messages.filter((message) => !modelSelectionNotice(message));
8634
+ const notice = actualNotice(agent, admitted.decision.model.id);
8635
+ return {
8636
+ ...result,
8637
+ messages: notice === void 0 ? filtered : [...filtered, notice]
8638
+ };
8639
+ }
8533
8640
  const pending = effectiveAuto(agent);
8534
8641
  const preference = pending === void 0 ? void 0 : autoModelPreference(pending);
8535
8642
  const inherited = followIntent(agent);
@@ -8579,6 +8686,15 @@ function installAutoModelRouting(ctx, dependencies) {
8579
8686
  const removeRequest = ctx.on("agent/request", async ({ agent, turn, signal }, next) => {
8580
8687
  installAgent(agent);
8581
8688
  const native = await next();
8689
+ const admitted = routed.get(agent);
8690
+ if (admitted?.turn === turn && admitted.admitted !== void 0) {
8691
+ if (!signal.aborted) dependencies.admitModel?.(agent, turn, admitted.decision.model.id, signal);
8692
+ const { reasoningEffort: _changedEffort, ...current } = native;
8693
+ return {
8694
+ ...current,
8695
+ ...admitted.admitted
8696
+ };
8697
+ }
8582
8698
  const inherited = followIntent(agent);
8583
8699
  const { reasoningEffort: _nativeEffort, ...withoutEffort } = native;
8584
8700
  const resolved = inherited === void 0 ? native : {
@@ -8624,6 +8740,11 @@ function installAutoModelRouting(ctx, dependencies) {
8624
8740
  }
8625
8741
  if (!signal.aborted) {
8626
8742
  dependencies.admitModel?.(agent, turn, state.decision.model.id, signal);
8743
+ state.admitted = {
8744
+ provider: resolved.provider,
8745
+ model: state.decision.model.id,
8746
+ ...resolved.reasoningEffort === void 0 ? {} : { reasoningEffort: resolved.reasoningEffort }
8747
+ };
8627
8748
  selections.record(agent, turn, {
8628
8749
  mode: "auto",
8629
8750
  preference: state.decision.preference,
@@ -8646,19 +8767,21 @@ function installAutoModelRouting(ctx, dependencies) {
8646
8767
  removeDisposed();
8647
8768
  removeRequest();
8648
8769
  removeFollowProjection?.();
8770
+ removeIntentProjection?.();
8649
8771
  for (const dispose of activeDisposers) dispose();
8650
8772
  activeDisposers.clear();
8651
8773
  selections.clear();
8652
8774
  };
8653
8775
  }
8654
8776
  function taskClassifierModel(models) {
8655
- return models.filter((model) => model.category === "lightweight" && model.input.includes("text")).toSorted((left, right) => left.id.localeCompare(right.id, "en")).find((model) => {
8777
+ return models.filter((model) => model.category === "lightweight" && model.input.includes("text")).toSorted((left, right) => Number(right.reasoning.advertisedEfforts.includes("off")) - Number(left.reasoning.advertisedEfforts.includes("off")) || left.id.localeCompare(right.id, "en")).find((model) => {
8656
8778
  const budget = calculateRequestBudget(model, 128);
8657
8779
  return budget.ok && budget.budget.hardInputLimit >= 12e3;
8658
8780
  });
8659
8781
  }
8660
8782
  /** One auxiliary concrete-model call; no Auto recursion, tools, history writes or retry loop. */
8661
- async function classifyTaskWithAdapter(model, input, signal, stream, observe, reasoningOffSupported = false) {
8783
+ async function classifyTaskWithAdapter(model, input, signal, stream, observe, reasoningOffSupported = false, checkpoint) {
8784
+ checkpoint?.();
8662
8785
  if (signal.aborted) throw signal.reason;
8663
8786
  let output = "";
8664
8787
  let finished = false;
@@ -8681,6 +8804,8 @@ async function classifyTaskWithAdapter(model, input, signal, stream, observe, re
8681
8804
  maxTokens: 128,
8682
8805
  ...reasoningOffSupported && model.reasoning.advertisedEfforts.includes("off") ? { reasoningEffort: ReasoningEffortId("off") } : {}
8683
8806
  })) {
8807
+ checkpoint?.();
8808
+ checkpoint?.();
8684
8809
  if (signal.aborted) throw signal.reason;
8685
8810
  if (chunk.type === "text-delta") {
8686
8811
  output += chunk.text;
@@ -8996,7 +9121,8 @@ var PreviewAdapter = class extends PiAiAdapter {
8996
9121
  requestBudgetSettings;
8997
9122
  accountModelSettings;
8998
9123
  replayRecovery;
8999
- constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery) {
9124
+ requestCheckpoint;
9125
+ constructor(lifetime, optionsFor, discoverSnapshot, refreshRejected, requestBudgetSettings, accountModelSettings, replayRecovery, requestCheckpoint) {
9000
9126
  super(optionsFor());
9001
9127
  this.lifetime = lifetime;
9002
9128
  this.optionsFor = optionsFor;
@@ -9005,6 +9131,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9005
9131
  this.requestBudgetSettings = requestBudgetSettings;
9006
9132
  this.accountModelSettings = accountModelSettings;
9007
9133
  this.replayRecovery = replayRecovery;
9134
+ this.requestCheckpoint = requestCheckpoint;
9008
9135
  }
9009
9136
  async listModels(provider) {
9010
9137
  owned(provider);
@@ -9066,13 +9193,18 @@ var PreviewAdapter = class extends PiAiAdapter {
9066
9193
  return this.withRecovery(snapshot, signal, () => new PiAiAdapter(this.optionsFor(lease)).resolveModel(provider, model, signal));
9067
9194
  }
9068
9195
  async prepareCall(provider, model, signal) {
9196
+ this.requestCheckpoint?.();
9069
9197
  owned(provider);
9070
9198
  if (autoModelPreference(model) !== void 0) throw failure("COPILOT_AUTO_ROUTE_UNRESOLVED", "INVALID_REQUEST");
9071
9199
  const cached = this.lifetime.source.readSnapshot();
9072
9200
  const snapshot = await this.discoverSnapshot({ signal });
9201
+ this.requestCheckpoint?.();
9073
9202
  const lease = await this.lease(snapshot, model, signal, cached === snapshot);
9203
+ this.requestCheckpoint?.();
9204
+ const prepared = await this.withRecovery(snapshot, signal, () => new PiAiAdapter(this.optionsFor(lease)).prepareCall(provider, model, signal));
9205
+ this.requestCheckpoint?.();
9074
9206
  return {
9075
- model: (await this.withRecovery(snapshot, signal, () => new PiAiAdapter(this.optionsFor(lease)).prepareCall(provider, model, signal))).model,
9207
+ model: prepared.model,
9076
9208
  stream: (options) => this.guardedStream(lease, options)
9077
9209
  };
9078
9210
  }
@@ -9106,6 +9238,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9106
9238
  guardedStream(lease, options) {
9107
9239
  const owner = this;
9108
9240
  return (async function* () {
9241
+ owner.requestCheckpoint?.();
9109
9242
  owner.lifetime.start(lease);
9110
9243
  owned(options.provider);
9111
9244
  if (options.model !== lease.descriptor.id) throw failure("COPILOT_PREVIEW_MODEL_MISMATCH");
@@ -9123,6 +9256,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9123
9256
  let bodyTimeout;
9124
9257
  let liveness;
9125
9258
  const inspectRequest = (_model, context, nativeOptions) => {
9259
+ owner.requestCheckpoint?.();
9126
9260
  if (signal.aborted) throw abortFailure(signal);
9127
9261
  const imageFailure = imageInputFailure(lease.descriptor, context.messages);
9128
9262
  if (imageFailure !== void 0) {
@@ -9141,10 +9275,12 @@ var PreviewAdapter = class extends PiAiAdapter {
9141
9275
  requestFailure = budgetFailure(admitted);
9142
9276
  throw requestFailure;
9143
9277
  }
9278
+ owner.requestCheckpoint?.();
9144
9279
  };
9145
9280
  try {
9146
9281
  const native = new PiAiAdapter(owner.optionsFor(lease, {
9147
9282
  inspectRequest,
9283
+ requestCheckpoint: owner.requestCheckpoint,
9148
9284
  ...recovery === void 0 ? {} : {
9149
9285
  recoverReplay: recovery.transform,
9150
9286
  onReplayScopeRejected: recovery.rejected
@@ -9166,6 +9302,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9166
9302
  }
9167
9303
  }));
9168
9304
  const prepared = await native.prepareCall(options.provider, options.model, signal);
9305
+ owner.requestCheckpoint?.();
9169
9306
  const suppliedEffort = options.reasoningEffort ?? prepared.model.reasoning?.defaultEffort;
9170
9307
  const effort = options.purpose === "compaction" ? selectCompactionReasoning(getSupportedThinkingLevels(model), suppliedEffort, policy.compactionReasoning) : suppliedEffort;
9171
9308
  const request = {
@@ -9174,6 +9311,7 @@ var PreviewAdapter = class extends PiAiAdapter {
9174
9311
  ...effort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(effort) }
9175
9312
  };
9176
9313
  for await (const chunk of native.stream(request)) {
9314
+ owner.requestCheckpoint?.();
9177
9315
  let delivered = chunk;
9178
9316
  if (requestFailure !== void 0 && chunk.type === "finish") {
9179
9317
  if (signal.aborted) throw abortFailure(signal);
@@ -9495,8 +9633,10 @@ function apply$1(ctx, config = {}) {
9495
9633
  followParentModel: () => cacheSettings().followParentModel === true,
9496
9634
  semanticAssessment: () => cacheSettings().autoSemanticAssessment ?? true,
9497
9635
  assessmentDiagnostic: (code) => ctx.logger.warn(code),
9498
- async classifyTask(input, signal, observe) {
9636
+ async classifyTask(input, signal, observe, checkpoint) {
9637
+ checkpoint?.();
9499
9638
  const snapshot = await discoverSnapshot({ signal });
9639
+ checkpoint?.();
9500
9640
  const model = taskClassifierModel(snapshot.models.filter((model) => !excludedModels().has(model.id)));
9501
9641
  if (model === void 0) throw failure("COPILOT_AUTO_CLASSIFIER_UNAVAILABLE");
9502
9642
  observe?.({
@@ -9504,11 +9644,12 @@ function apply$1(ctx, config = {}) {
9504
9644
  modelId: model.id
9505
9645
  });
9506
9646
  const revision = lifetime.revision;
9507
- const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings);
9647
+ const adapter = new PreviewAdapter(lifetime, optionsFor, discoverSnapshot, refreshRejected, budgetSettings, cacheSettings, void 0, checkpoint);
9508
9648
  try {
9509
9649
  const prepared = await adapter.prepareCall(GITHUB_COPILOT_PREVIEW_PROVIDER_ID, model.id, signal);
9650
+ checkpoint?.();
9510
9651
  if (signal.aborted) throw signal.reason;
9511
- return await classifyTaskWithAdapter(model, input, signal, (request) => prepared.stream(request), observe, prepared.model.reasoning?.efforts.some((effort) => effort.id === "off") === true);
9652
+ return await classifyTaskWithAdapter(model, input, signal, (request) => prepared.stream(request), observe, prepared.model.reasoning?.efforts.some((effort) => effort.id === "off") === true, checkpoint);
9512
9653
  } finally {
9513
9654
  if (!lifetime.isCurrent(revision) || source.readSnapshot() !== snapshot || proofFor(snapshot) === void 0) throw new TaskAssessmentRevokedError(failure("COPILOT_PREVIEW_METADATA_STALE", "ABORTED"));
9514
9655
  }