mixdog 1.4.4 → 1.4.5

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.
Files changed (218) hide show
  1. package/package.json +1 -2
  2. package/src/cli.mjs +5 -1
  3. package/src/defaults/shipped-history.json +26 -2
  4. package/src/defaults/skills/browser-use/SKILL.md +148 -273
  5. package/src/defaults/skills/browser-use/references/devtools.md +14 -0
  6. package/src/defaults/skills/browser-use/references/page-flows.md +66 -0
  7. package/src/defaults/skills/browser-use/references/sign-in.md +70 -0
  8. package/src/defaults/skills/code-tidy/SKILL.md +60 -84
  9. package/src/defaults/skills/code-tidy/references/agent-cleanup.md +27 -2
  10. package/src/defaults/skills/computer-use/SKILL.md +145 -240
  11. package/src/defaults/skills/computer-use/references/flows.md +35 -0
  12. package/src/defaults/skills/computer-use/references/operations.md +22 -0
  13. package/src/defaults/skills/computer-use/references/platforms.md +12 -0
  14. package/src/defaults/skills/docx/SKILL.md +23 -31
  15. package/src/defaults/skills/docx/references/native-authoring.md +26 -3
  16. package/src/defaults/skills/docx/references/redlining.md +15 -0
  17. package/src/defaults/skills/image/SKILL.md +37 -77
  18. package/src/defaults/skills/image/references/prompt-forms.md +51 -0
  19. package/src/defaults/skills/image/references/text.md +6 -0
  20. package/src/defaults/skills/local-provider/SKILL.md +75 -105
  21. package/src/defaults/skills/local-provider/references/lifecycle.md +14 -0
  22. package/src/defaults/skills/local-provider/references/maintenance.md +19 -0
  23. package/src/defaults/skills/local-provider/references/recovery.md +30 -0
  24. package/src/defaults/skills/memory-management/SKILL.md +16 -20
  25. package/src/defaults/skills/pdf/SKILL.md +21 -23
  26. package/src/defaults/skills/pdf/references/blocks.md +20 -0
  27. package/src/defaults/skills/pdf/references/forms.md +12 -0
  28. package/src/defaults/skills/pdf/references/html.md +2 -2
  29. package/src/defaults/skills/pdf/references/ocr.md +7 -0
  30. package/src/defaults/skills/pdf/references/security.md +8 -0
  31. package/src/defaults/skills/pptx/SKILL.md +30 -109
  32. package/src/defaults/skills/pptx/references/audit.md +45 -0
  33. package/src/defaults/skills/pptx/references/brief-critique.md +47 -0
  34. package/src/defaults/skills/pptx/references/editing.md +24 -0
  35. package/src/defaults/skills/pptx/references/html.md +1 -1
  36. package/src/defaults/skills/pptx/references/script.md +33 -0
  37. package/src/defaults/skills/setup/SKILL.md +34 -102
  38. package/src/defaults/skills/setup/references/actions.md +72 -13
  39. package/src/defaults/skills/setup/references/surfaces.md +23 -8
  40. package/src/defaults/skills/setup-guide/SKILL.md +28 -115
  41. package/src/defaults/skills/setup-guide/references/features.md +36 -0
  42. package/src/defaults/skills/setup-guide/references/glossary.md +38 -0
  43. package/src/defaults/skills/setup-guide/references/workflow-models.md +62 -0
  44. package/src/defaults/skills/test-suite/SKILL.md +15 -127
  45. package/src/defaults/skills/test-suite/references/case-management.md +17 -9
  46. package/src/defaults/skills/test-suite/references/diagnose.md +23 -0
  47. package/src/defaults/skills/test-suite/references/prune.md +27 -0
  48. package/src/defaults/skills/test-suite/references/write.md +44 -0
  49. package/src/defaults/skills/video/SKILL.md +28 -42
  50. package/src/defaults/skills/video/references/prompting.md +31 -0
  51. package/src/defaults/skills/visualize/SKILL.md +73 -107
  52. package/src/defaults/skills/visualize/references/craft.md +1 -2
  53. package/src/defaults/skills/visualize/references/feedback.md +36 -0
  54. package/src/defaults/skills/visualize/references/showing.md +13 -0
  55. package/src/defaults/skills/xlsx/SKILL.md +23 -50
  56. package/src/defaults/skills/xlsx/references/editing.md +15 -0
  57. package/src/defaults/skills/xlsx/references/model-conventions.md +1 -1
  58. package/src/defaults/skills/xlsx/references/recalculation.md +37 -0
  59. package/src/defaults/skills/xlsx/references/report-design.md +18 -2
  60. package/src/lib/keychain-cjs.cjs +22 -1
  61. package/src/lib/rules-builder.cjs +1 -1
  62. package/src/rules/agent/AGENT.md +3 -0
  63. package/src/rules/lead/LEAD.md +3 -1
  64. package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +8 -30
  65. package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +5 -0
  66. package/src/runtime/agent/orchestrator/mcp/oauth-request.mjs +21 -2
  67. package/src/runtime/agent/orchestrator/providers/account-pool.mjs +3 -0
  68. package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -2
  69. package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +2 -0
  70. package/src/runtime/agent/orchestrator/providers/anthropic-message-threads.mjs +583 -0
  71. package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +1 -1
  72. package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +81 -19
  73. package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
  74. package/src/runtime/agent/orchestrator/providers/anthropic.mjs +56 -6
  75. package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
  76. package/src/runtime/agent/orchestrator/providers/gemini-error-contract.mjs +6 -6
  77. package/src/runtime/agent/orchestrator/providers/gemini-model-redirect.mjs +44 -0
  78. package/src/runtime/agent/orchestrator/providers/gemini-reasoning-relay.mjs +5 -0
  79. package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +34 -5
  80. package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +10 -0
  81. package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +11 -6
  82. package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +4 -100
  83. package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +3 -227
  84. package/src/runtime/agent/orchestrator/providers/gemini.mjs +226 -118
  85. package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +11 -1
  86. package/src/runtime/agent/orchestrator/providers/lib/claude-bridge-schema.mjs +15 -3
  87. package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +2 -1
  88. package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
  89. package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
  90. package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +14 -10
  91. package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +1 -3
  92. package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +8 -3
  93. package/src/runtime/agent/orchestrator/providers/vertex-ai-maas.mjs +2 -2
  94. package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +4 -5
  95. package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +2 -2
  96. package/src/runtime/agent/orchestrator/runtime-core/provider-request-tools.mjs +15 -8
  97. package/src/runtime/agent/orchestrator/runtime-core/session-title.mjs +1 -0
  98. package/src/runtime/agent/orchestrator/runtime-core/todo-list.mjs +9 -32
  99. package/src/runtime/agent/orchestrator/runtime-core/todo-tool-defs.mjs +4 -5
  100. package/src/runtime/agent/orchestrator/session/compact/summary-route.mjs +1 -3
  101. package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +5 -2
  102. package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/todo-check.mjs +2 -17
  103. package/src/runtime/agent/orchestrator/session/loop/usage.mjs +7 -3
  104. package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +9 -2
  105. package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +26 -13
  106. package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +4 -5
  107. package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +16 -5
  108. package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +22 -1
  109. package/src/runtime/agent/orchestrator/session/store/live-state.mjs +4 -0
  110. package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +11 -9
  111. package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +2 -8
  112. package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +1 -9
  113. package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +2 -2
  114. package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +1 -1
  115. package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +12 -3
  116. package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +9 -2
  117. package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +137 -7
  118. package/src/runtime/agent/orchestrator/tools/code-graph/calls-cache.mjs +43 -14
  119. package/src/runtime/agent/orchestrator/tools/code-graph/calls-sidecar-worker.mjs +33 -0
  120. package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +146 -11
  121. package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +31 -24
  122. package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +172 -25
  123. package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +100 -2
  124. package/src/runtime/agent/orchestrator/tools/code-graph/main-thread-slice.mjs +18 -0
  125. package/src/runtime/agent/orchestrator/tools/code-graph/mask-pool.mjs +219 -0
  126. package/src/runtime/agent/orchestrator/tools/code-graph/mask-worker.mjs +12 -0
  127. package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +6 -1
  128. package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +9 -2
  129. package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +5 -1
  130. package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +8 -2
  131. package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +14 -11
  132. package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +41 -18
  133. package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +391 -83
  134. package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +109 -9
  135. package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +73 -29
  136. package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +6 -5
  137. package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +7 -3
  138. package/src/runtime/channels/lib/crash-log.mjs +21 -1
  139. package/src/runtime/channels/lib/worker-main.mjs +8 -25
  140. package/src/runtime/media/jobs.mjs +5 -0
  141. package/src/runtime/media/store.mjs +146 -3
  142. package/src/runtime/office/core/office-write-ledger.mjs +2 -2
  143. package/src/runtime/shared/agent-reap-state.mjs +19 -0
  144. package/src/runtime/shared/desktop-notice-host.d.mts +13 -0
  145. package/src/runtime/shared/desktop-notice-host.mjs +87 -0
  146. package/src/runtime/shared/file-lock.mjs +2 -2
  147. package/src/runtime/shared/heap-cap.mjs +9 -11
  148. package/src/runtime/shared/llm/http-agent.mjs +11 -1
  149. package/src/runtime/shared/llm/system-proxy.mjs +100 -25
  150. package/src/runtime/shared/llm/usage-accounting.mjs +18 -7
  151. package/src/runtime/shared/llm/usage-context.mjs +2 -2
  152. package/src/runtime/shared/llm/usage-ledger-requests.mjs +10 -3
  153. package/src/runtime/shared/llm/usage-ledger.mjs +13 -1
  154. package/src/runtime/shared/provider-accounts.mjs +22 -0
  155. package/src/runtime/shared/provider-auth-binding.mjs +2 -2
  156. package/src/runtime/shared/resource-admission.mjs +2 -2
  157. package/src/runtime/shared/root-async-context.mjs +51 -0
  158. package/src/runtime/shared/run-child.mjs +18 -1
  159. package/src/runtime/shared/slow-span.mjs +2 -2
  160. package/src/runtime/shared/tool-execution-owner.mjs +2 -2
  161. package/src/runtime/shared/tool-work-units.mjs +2 -0
  162. package/src/runtime/shared/turn-snapshot-store.mjs +75 -18
  163. package/src/runtime/shared/turn-worktree-snapshot.mjs +38 -8
  164. package/src/runtime/shared/user-cwd.mjs +2 -2
  165. package/src/runtime/shared/worker-requests.mjs +3 -1
  166. package/src/runtime/shared/worktrees/lock.mjs +2 -2
  167. package/src/runtime/visualize-bridge/client.mjs +26 -4
  168. package/src/runtime/visualize-bridge/tool-defs.mjs +46 -5
  169. package/src/session-runtime/boot/apis.mjs +1 -0
  170. package/src/session-runtime/boot/begin.mjs +2 -0
  171. package/src/session-runtime/media-api.mjs +15 -0
  172. package/src/session-runtime/provider-readiness.mjs +10 -2
  173. package/src/session-runtime/runtime-core.mjs +35 -8
  174. package/src/session-runtime/runtime-review-api.mjs +3 -1
  175. package/src/session-runtime/services/agent-tool/close-flow.mjs +6 -1
  176. package/src/session-runtime/services/agent-tool/execute-resume.mjs +94 -0
  177. package/src/session-runtime/services/agent-tool/execute-send.mjs +77 -27
  178. package/src/session-runtime/services/agent-tool/execute-spawn.mjs +28 -7
  179. package/src/session-runtime/services/agent-tool/execute.mjs +6 -1
  180. package/src/session-runtime/services/agent-tool/helpers.mjs +11 -0
  181. package/src/session-runtime/services/agent-tool/job-views/job-render.mjs +13 -10
  182. package/src/session-runtime/services/agent-tool/render.mjs +2 -0
  183. package/src/session-runtime/services/agent-tool/send-flow.mjs +1 -0
  184. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-prep.mjs +6 -0
  185. package/src/session-runtime/services/agent-tool/spawn-flow/spawn-run.mjs +2 -1
  186. package/src/session-runtime/services/agent-tool/tag-registry/reaped-sessions.mjs +82 -0
  187. package/src/session-runtime/services/agent-tool/tag-registry/record-facts-worker.mjs +36 -0
  188. package/src/session-runtime/services/agent-tool/tag-registry.mjs +4 -0
  189. package/src/session-runtime/services/agent-tool/terminal-reaper/row-helpers.mjs +29 -0
  190. package/src/session-runtime/services/agent-tool/terminal-reaper/scan-admission.mjs +11 -3
  191. package/src/session-runtime/services/agent-tool/terminal-reaper/stale-rows.mjs +19 -8
  192. package/src/session-runtime/services/agent-tool/terminal-reaper.mjs +5 -2
  193. package/src/session-runtime/services/agent-tool/worker-index.mjs +1 -0
  194. package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
  195. package/src/session-runtime/session-create.mjs +5 -0
  196. package/src/session-runtime/setup-tool/settings-contract.mjs +2 -0
  197. package/src/session-runtime/usage-stats-api.mjs +3 -0
  198. package/src/session-runtime/workspace/admission-gate.mjs +25 -7
  199. package/src/session-runtime/workspace/transitions.mjs +4 -0
  200. package/src/standalone/daemon-log.mjs +28 -4
  201. package/src/standalone/daemon-owner.mjs +41 -7
  202. package/src/standalone/daemon-work-gate.mjs +139 -0
  203. package/src/standalone/daemon.mjs +80 -11
  204. package/src/standalone/desktop-service-registry.mjs +11 -4
  205. package/src/standalone/session-client.mjs +57 -5
  206. package/src/standalone/session-protocol.mjs +5 -0
  207. package/src/standalone/session-service/agent-tree/agent-cancel.mjs +17 -1
  208. package/src/standalone/session-service/agent-tree.mjs +7 -0
  209. package/src/standalone/session-service/session-calls/session-turns.mjs +12 -5
  210. package/src/standalone/session-transport/call-route.mjs +10 -4
  211. package/src/standalone/session-transport/routes.mjs +21 -0
  212. package/src/standalone/session-transport/stack.mjs +3 -1
  213. package/src/standalone/session-transport.mjs +5 -0
  214. package/src/tui/dist/index.mjs +495 -477
  215. package/src/tui/session/session-api/media.mjs +5 -0
  216. package/src/tui/session/turn.mjs +13 -0
  217. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +0 -71
  218. package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/reader.mjs +0 -108
@@ -56,6 +56,7 @@ import { applyAnthropicErrorContract } from './anthropic-error-contract.mjs';
56
56
  import { adjustMaxTokensForContextOverflow } from './anthropic-max-tokens-recovery.mjs';
57
57
  import { createAnthropicOverloadTracker, takeAnthropicModelFallback } from './anthropic-overload-fallback.mjs';
58
58
  import { createAnthropicOAuthRecovery } from './anthropic-oauth-recovery.mjs';
59
+ import { THREAD_MESSAGE_STOP_WAIT_MS, planAnthropicThread, threadAccountKey } from './anthropic-message-threads.mjs';
59
60
  import { createMidState, createMidstreamRecovery } from './anthropic-oauth-midstream.mjs';
60
61
  import { assertAnthropicStreamNotEmpty } from './anthropic-midstream-recovery.mjs';
61
62
  import { applyAnthropicEffortToBody, shouldIncludeEffortBeta } from './anthropic-effort.mjs';
@@ -553,18 +554,39 @@ export class AnthropicOAuthProvider {
553
554
  // Default when the caller doesn't pin a model: newest high-tier chat
554
555
  // model from the live catalog (one warmup round-trip if cache is cold).
555
556
  const useModel = model || (await ensureLatestAnthropicModel(this));
556
- const body = buildRequestBody(messages, useModel, tools, sendOpts);
557
- body.messages = await prepareAnthropicImages(body.messages, { signal: externalSignal });
557
+ const fullBody = buildRequestBody(messages, useModel, tools, sendOpts);
558
+ fullBody.messages = await prepareAnthropicImages(fullBody.messages, { signal: externalSignal });
558
559
  // Diagnostic: per-block prefix hashes of exactly what is sent.
559
- recordAnthropicPrefix(anthropicPrefixSessionId(opts), anthropicPrefixFingerprint(body));
560
- if (body.speed === 'fast') {
560
+ recordAnthropicPrefix(anthropicPrefixSessionId(opts), anthropicPrefixFingerprint(fullBody));
561
+ if (fullBody.speed === 'fast') {
561
562
  this.fastModeBetaHeaderLatched = true;
562
563
  }
563
564
  // advanced-tool-use-2025-11-20 beta is only needed when this request
564
565
  // actually carries deferred (defer_loading) tools — gate the header on
565
566
  // that instead of sending it unconditionally on every request.
566
- const hasDeferredTools = Array.isArray(body.tools) && body.tools.some((t) => t && t.defer_loading === true);
567
- const knownToolNames = requestToolNames(body);
567
+ const hasDeferredTools = Array.isArray(fullBody.tools) && fullBody.tools.some((t) => t && t.defer_loading === true);
568
+ const knownToolNames = requestToolNames(fullBody);
569
+ // Message thread (anthropic-message-threads.mjs): the same request as a
570
+ // create, a delta continue, or unchanged. Its beta set is the full body's,
571
+ // so a continue keeps the create's fixed header.
572
+ const thread = planAnthropicThread({
573
+ provider: 'anthropic-oauth',
574
+ config: this.config,
575
+ opts,
576
+ body: fullBody,
577
+ betas: buildOAuthBetaHeaders(fullBody, {
578
+ fastMode: this.fastModeBetaHeaderLatched,
579
+ toolSearch: hasDeferredTools,
580
+ model: useModel,
581
+ opts,
582
+ }).split(','),
583
+ account: threadAccountKey(
584
+ 'anthropic-oauth',
585
+ auth.creds?.identity?.id || auth.creds?.path || boundProviderAuthPath('anthropic-oauth') || ''
586
+ ),
587
+ requestMessages: messages,
588
+ });
589
+ const body = thread.body;
568
590
  const sessionId = opts.sessionId || null;
569
591
  const iteration = Number.isFinite(Number(opts.iteration)) ? Number(opts.iteration) : null;
570
592
  // Option A: no absolute wall-clock cap on streaming generation. A stream
@@ -589,6 +611,7 @@ export class AnthropicOAuthProvider {
589
611
  auth,
590
612
  totalSignal,
591
613
  hasDeferredTools,
614
+ thread,
592
615
  onStageChange,
593
616
  onTextReset,
594
617
  });
@@ -596,6 +619,8 @@ export class AnthropicOAuthProvider {
596
619
  let maxTokensAdjusted = false;
597
620
  try {
598
621
  for (let attemptIndex = 0; attemptIndex <= ANTHROPIC_MAX_MIDSTREAM_RETRIES; attemptIndex++) {
622
+ // A dropped continue is resent once as-is; after that it replays.
623
+ if (attemptIndex >= 2) thread.toCreate();
599
624
  const opened = await this._openResponse({
600
625
  requestWithRetry,
601
626
  cleanupCancelHandler,
@@ -607,6 +632,8 @@ export class AnthropicOAuthProvider {
607
632
  maxTokensAdjusted = opened.maxTokensAdjusted;
608
633
  if (!response.ok) {
609
634
  cleanupCancelHandler(cancelHandler);
635
+ // This request is over; any resend plans the thread afresh.
636
+ thread.settle();
610
637
  return await this._resendAfterRejection({
611
638
  response,
612
639
  rejectedAuthBody,
@@ -616,6 +643,7 @@ export class AnthropicOAuthProvider {
616
643
  tools,
617
644
  opts,
618
645
  onStageChange,
646
+ thread,
619
647
  });
620
648
  }
621
649
 
@@ -638,13 +666,26 @@ export class AnthropicOAuthProvider {
638
666
  midState,
639
667
  onTextDelta,
640
668
  knownToolNames,
641
- { relayProgressUpdates: body.thinking?.display === 'updates', onStreamItemStart }
669
+ {
670
+ relayProgressUpdates: body.thinking?.display === 'updates',
671
+ onStreamItemStart,
672
+ awaitMessageStopMs: thread.mode === 'none' ? 0 : THREAD_MESSAGE_STOP_WAIT_MS,
673
+ releaseSignal: externalSignal,
674
+ }
642
675
  );
643
- try {
644
- controller?.abort?.('Anthropic SSE complete');
645
- } catch {
646
- // the stream is complete; the controller may already be aborted
647
- }
676
+ thread.commit(result);
677
+ const finishStream = () => {
678
+ try {
679
+ controller?.abort?.('Anthropic SSE complete');
680
+ } catch {
681
+ // the stream is complete; the controller may already be aborted
682
+ }
683
+ };
684
+ // A thread's message_stop may still be read in the background: the
685
+ // body stays open until that read settles.
686
+ const receiptTail = result?.threadReceipt?.pending;
687
+ if (receiptTail) void receiptTail.then(finishStream);
688
+ else finishStream();
648
689
  this._settleStreamedTurn({
649
690
  result,
650
691
  midState,
@@ -667,6 +708,7 @@ export class AnthropicOAuthProvider {
667
708
  }
668
709
  throw midstream.exhaustedError();
669
710
  } catch (err) {
711
+ thread.settle();
670
712
  const fallbackOpts = takeAnthropicModelFallback(err, {
671
713
  tag: 'anthropic-oauth',
672
714
  model: useModel,
@@ -676,6 +718,7 @@ export class AnthropicOAuthProvider {
676
718
  });
677
719
  return await this.send(messages, err.fallbackModel, tools, fallbackOpts);
678
720
  } finally {
721
+ thread.settle();
679
722
  totalTimeout.cleanup();
680
723
  }
681
724
  }
@@ -691,6 +734,7 @@ export class AnthropicOAuthProvider {
691
734
  auth,
692
735
  totalSignal,
693
736
  hasDeferredTools,
737
+ thread = null,
694
738
  onStageChange,
695
739
  onTextReset,
696
740
  }) {
@@ -709,12 +753,14 @@ export class AnthropicOAuthProvider {
709
753
  totalSignal,
710
754
  overload,
711
755
  betaHeadersFor: (requestBody) =>
712
- buildOAuthBetaHeaders(requestBody, {
713
- fastMode: this.fastModeBetaHeaderLatched,
714
- toolSearch: hasDeferredTools,
715
- model: useModel,
716
- opts,
717
- }),
756
+ thread && thread.mode !== 'none'
757
+ ? thread.betas.join(',')
758
+ : buildOAuthBetaHeaders(requestBody, {
759
+ fastMode: this.fastModeBetaHeaderLatched,
760
+ toolSearch: hasDeferredTools,
761
+ model: useModel,
762
+ opts,
763
+ }),
718
764
  onStageChange,
719
765
  });
720
766
  const recovery = createAnthropicOAuthRecovery({
@@ -793,8 +839,24 @@ export class AnthropicOAuthProvider {
793
839
 
794
840
  // A non-OK initial response: quota errors surface as-is; a CLI-version
795
841
  // floor or an unknown/retired model replays the turn ONCE through send().
796
- async _resendAfterRejection({ response, rejectedAuthBody, messages, model, useModel, tools, opts, onStageChange }) {
842
+ async _resendAfterRejection({
843
+ response,
844
+ rejectedAuthBody,
845
+ messages,
846
+ model,
847
+ useModel,
848
+ tools,
849
+ opts,
850
+ onStageChange,
851
+ thread = null,
852
+ }) {
797
853
  const text = rejectedAuthBody ?? (await response.text().catch(() => ''));
854
+ // A refused thread request (nothing ran): replay as a create or send
855
+ // unthreaded, per the thread error.
856
+ const threadDirective = thread?.classify(response.status, text);
857
+ if (threadDirective) {
858
+ return this._sendOnce(messages, useModel, tools, { ...opts, _anthropicThread: threadDirective });
859
+ }
798
860
  const scrubbedText = this.scrubTokens(text);
799
861
  const safeText = scrubbedText.slice(0, 200);
800
862
  process.stderr.write(`[anthropic-oauth] API error ${response.status}: ${safeText}\n`);
@@ -131,8 +131,9 @@ export function _anthropicSseError(event, labels) {
131
131
  // must stop reading (a terminal frame). A malformed record is skipped exactly
132
132
  // like the former per-event JSON.parse throw — and, unlike a whole-batch
133
133
  // rejection, the well-formed records beside it still run.
134
- function applyAnthropicSseEvent(framedEvent, { turn, watchdogs, state, progress, labels }) {
134
+ function applyAnthropicSseEvent(framedEvent, { turn, watchdogs, state, progress, labels, receipt }) {
135
135
  const event = framedEvent.value;
136
+ noteThreadReceipt(receipt, event);
136
137
  try {
137
138
  if (framedEvent.name === 'error' || event?.type === 'error' || event?.error) {
138
139
  throw _anthropicSseError(event, labels);
@@ -192,7 +193,21 @@ export async function parseSSEStream(
192
193
  state,
193
194
  onTextDelta,
194
195
  knownToolNames,
195
- { relayProgressUpdates = false, labels = OAUTH_STREAM_LABELS, onStreamItemStart = null } = {}
196
+ {
197
+ relayProgressUpdates = false,
198
+ labels = OAUTH_STREAM_LABELS,
199
+ onStreamItemStart = null,
200
+ // A message-thread request: after an early terminal frame (tool_use
201
+ // message_delta) the stream is read on in the background, up to this
202
+ // long, for the message_stop that confirms the API stored the response
203
+ // (`threadReceipt.pending`). The caller must not abort the response body
204
+ // before that settles.
205
+ awaitMessageStopMs = 0,
206
+ // The send's own request/session signal: aborting it (turn abort, session
207
+ // close) ends that background read at once, as does
208
+ // `threadReceipt.cancel()`.
209
+ releaseSignal = null,
210
+ } = {}
196
211
  ) {
197
212
  // Anthropic/Claude parity: every received SSE byte proves transport
198
213
  // activity, including comment and named ping keepalives. Content kinds
@@ -233,6 +248,11 @@ export async function parseSSEStream(
233
248
  const onAbort = () => cancelReaderOnAbort(reader);
234
249
  let buffer = '';
235
250
  let currentEvent = '';
251
+ // What a message thread needs from the stream: the response id, whether
252
+ // message_stop arrived (and when), and every content block exactly as the
253
+ // API stored it, before any leak-guard rewriting.
254
+ const receipt = createThreadReceipt();
255
+ let handedOff = false;
236
256
  retainProviderSseStream(streamKey);
237
257
  try {
238
258
  // Reader ownership begins at getReader() above, so even a signal that
@@ -268,11 +288,29 @@ export async function parseSSEStream(
268
288
  const framed = frameProviderSseChunk(region, { currentEvent, streamKey });
269
289
  const framedChunk = typeof framed?.then === 'function' ? await framed : framed;
270
290
  currentEvent = framedChunk.currentEvent;
271
- if (applyAnthropicSseChunk(framedChunk.events, { turn, watchdogs, state, progress, labels })) break;
291
+ if (applyAnthropicSseChunk(framedChunk.events, { turn, watchdogs, state, progress, labels, receipt })) break;
272
292
  }
273
293
  turn.flushLeak();
274
294
  if (state?.sawMessageStart && !state?.sawCompleted) throw turn.truncatedError();
275
- return turn.result();
295
+ const result = turn.result();
296
+ // An early terminal frame (tool_use message_delta) ends the turn now; the
297
+ // message_stop that confirms storage is awaited on the side, never by
298
+ // the turn.
299
+ if (awaitMessageStopMs > 0 && !receipt.stoppedAt) {
300
+ receipt.terminalAt = Date.now();
301
+ receipt.pending = drainForMessageStop({
302
+ reader,
303
+ decoder,
304
+ rest: buffer,
305
+ receipt,
306
+ waitMs: awaitMessageStopMs,
307
+ labels,
308
+ signals: [signal, releaseSignal],
309
+ });
310
+ handedOff = true;
311
+ }
312
+ Object.defineProperty(result, 'threadReceipt', { value: receipt, enumerable: false });
313
+ return result;
276
314
  } finally {
277
315
  watchdogs.dispose();
278
316
  try {
@@ -283,13 +321,16 @@ export async function parseSSEStream(
283
321
  if (signal) signal.removeEventListener('abort', onAbort);
284
322
  // message_stop deliberately exits before EOF because Anthropic may keep
285
323
  // sending pings. Cancel the reader so the successful response body and
286
- // underlying keep-alive connection are not stranded.
287
- try {
288
- await reader.cancel('Anthropic SSE complete');
289
- } catch {
290
- // the reader may already be closed after the stream ended
324
+ // underlying keep-alive connection are not stranded. A reader handed to
325
+ // the message_stop drain is cancelled there.
326
+ if (!handedOff) {
327
+ try {
328
+ await reader.cancel('Anthropic SSE complete');
329
+ } catch {
330
+ // the reader may already be closed after the stream ended
331
+ }
332
+ releaseReaderLock(reader, labels);
291
333
  }
292
- releaseReaderLock(reader, labels);
293
334
  }
294
335
  }
295
336
 
@@ -324,14 +365,140 @@ function readFailureError(err, { watchdogs, signal, state, turn, abortedError })
324
365
 
325
366
  // Fold one network chunk's framed records into the turn, in order. Returns true
326
367
  // once a terminal record ends the stream; a framing error skips its record.
368
+ // Records after the terminal one are only scanned for message_stop.
327
369
  function applyAnthropicSseChunk(events, context) {
328
- for (const framedEvent of events) {
329
- if (framedEvent.error) continue;
330
- if (applyAnthropicSseEvent(framedEvent, context)) return true;
370
+ for (let i = 0; i < events.length; i++) {
371
+ if (events[i].error) continue;
372
+ if (applyAnthropicSseEvent(events[i], context)) {
373
+ for (const rest of events.slice(i + 1)) if (!rest.error) noteThreadReceipt(context.receipt, rest.value);
374
+ return true;
375
+ }
331
376
  }
332
377
  return false;
333
378
  }
334
379
 
380
+ // The response as the API stores it, block by block. `opaque` marks anything
381
+ // the recording cannot reproduce exactly (an unknown delta, an unparsable
382
+ // tool input, a block never closed); such a response is never continued.
383
+ function createThreadReceipt() {
384
+ const open = new Map();
385
+ const receipt = { id: '', stoppedAt: 0, terminalAt: 0, blocks: [], opaque: false, pending: null };
386
+ Object.defineProperty(receipt, 'open', { value: open, enumerable: false });
387
+ return receipt;
388
+ }
389
+
390
+ const APPEND_DELTA_FIELD = {
391
+ text_delta: ['text', 'text'],
392
+ thinking_delta: ['thinking', 'thinking'],
393
+ signature_delta: ['signature', 'signature'],
394
+ };
395
+
396
+ function noteThreadReceipt(receipt, event) {
397
+ if (!receipt || !event || typeof event !== 'object') return;
398
+ switch (event.type) {
399
+ case 'message_start':
400
+ if (typeof event.message?.id === 'string') receipt.id = event.message.id;
401
+ return;
402
+ case 'message_stop':
403
+ receipt.stoppedAt ||= Date.now();
404
+ if (receipt.open.size) receipt.opaque = true;
405
+ return;
406
+ case 'content_block_start': {
407
+ const block = event.content_block;
408
+ if (!block || typeof block !== 'object') receipt.opaque = true;
409
+ else receipt.open.set(event.index, { block: structuredClone(block), json: '' });
410
+ return;
411
+ }
412
+ case 'content_block_delta': {
413
+ const entry = receipt.open.get(event.index);
414
+ const delta = event.delta || {};
415
+ const append = APPEND_DELTA_FIELD[delta.type];
416
+ if (!entry) receipt.opaque = true;
417
+ else if (append) entry.block[append[0]] = `${entry.block[append[0]] ?? ''}${delta[append[1]] ?? ''}`;
418
+ else if (delta.type === 'input_json_delta') entry.json += String(delta.partial_json ?? '');
419
+ else if (delta.type === 'citations_delta') (entry.block.citations ||= []).push(delta.citation);
420
+ else receipt.opaque = true;
421
+ return;
422
+ }
423
+ case 'content_block_stop': {
424
+ const entry = receipt.open.get(event.index);
425
+ if (!entry) {
426
+ receipt.opaque = true;
427
+ return;
428
+ }
429
+ receipt.open.delete(event.index);
430
+ if (entry.json) {
431
+ try {
432
+ entry.block.input = JSON.parse(entry.json);
433
+ } catch {
434
+ receipt.opaque = true;
435
+ }
436
+ }
437
+ receipt.blocks[event.index] = entry.block;
438
+ return;
439
+ }
440
+ default:
441
+ }
442
+ }
443
+
444
+ const MESSAGE_STOP_FRAME = /(?:^|\n)event:\s*message_stop\b|"type"\s*:\s*"message_stop"/;
445
+
446
+ // Read a handed-over stream for at most `waitMs` until its message_stop frame,
447
+ // then cancel it. Only the storage confirmation depends on it: a late or
448
+ // missing frame leaves the response unconfirmed. An abort of any of
449
+ // `signals`, or `receipt.cancel()`, ends it at once. Never rejects.
450
+ async function drainForMessageStop({ reader, decoder, rest, receipt, waitMs, labels, signals = [] }) {
451
+ const deadline = Date.now() + waitMs;
452
+ let tail = rest || '';
453
+ let timer = null;
454
+ let cancelled = false;
455
+ let wake = null;
456
+ const cancel = () => {
457
+ cancelled = true;
458
+ wake?.(null);
459
+ };
460
+ Object.defineProperty(receipt, 'cancel', { value: cancel, enumerable: false, configurable: true });
461
+ const watched = signals.filter(Boolean);
462
+ for (const s of watched) {
463
+ if (s.aborted) cancelled = true;
464
+ else s.addEventListener('abort', cancel, { once: true });
465
+ }
466
+ try {
467
+ while (!receipt.stoppedAt && !cancelled) {
468
+ if (MESSAGE_STOP_FRAME.test(tail)) {
469
+ receipt.stoppedAt = Date.now();
470
+ break;
471
+ }
472
+ const remaining = deadline - Date.now();
473
+ if (remaining <= 0) break;
474
+ const read = reader.read();
475
+ read.catch(() => {});
476
+ const chunk = await Promise.race([
477
+ read,
478
+ new Promise((resolve) => {
479
+ wake = resolve;
480
+ timer = setTimeout(() => resolve(null), remaining);
481
+ }),
482
+ ]);
483
+ clearTimeout(timer);
484
+ wake = null;
485
+ if (!chunk || chunk.done || cancelled) break;
486
+ tail = `${tail}${decoder.decode(chunk.value, { stream: true })}`.slice(-4096);
487
+ }
488
+ } catch {
489
+ // the turn already completed; only the storage confirmation is lost
490
+ } finally {
491
+ clearTimeout(timer);
492
+ for (const s of watched) s.removeEventListener('abort', cancel);
493
+ try {
494
+ await reader.cancel('Anthropic SSE complete');
495
+ } catch {
496
+ // the reader may already be closed
497
+ }
498
+ releaseReaderLock(reader, labels);
499
+ }
500
+ }
501
+
335
502
  function releaseReaderLock(reader, labels) {
336
503
  try {
337
504
  reader.releaseLock();
@@ -28,6 +28,7 @@ import {
28
28
  import { enrichModels } from './model-catalog.mjs';
29
29
  import { sanitizeModelList } from './model-list-sanitize.mjs';
30
30
  import { getLlmDispatcher } from '../../../shared/llm/http-agent.mjs';
31
+ import { THREAD_MESSAGE_STOP_WAIT_MS, planAnthropicThread, threadAccountKey } from './anthropic-message-threads.mjs';
31
32
 
32
33
  import {
33
34
  loadAnthropic,
@@ -40,6 +41,13 @@ import { streamCallbacks } from './lib/send-callbacks.mjs';
40
41
  import { preparePdfTextForProvider } from './media-normalization.mjs';
41
42
  export { _test, _toAnthropicMessagesForTest } from './anthropic-messages.mjs';
42
43
 
44
+ // The beta names a request actually sends: its anthropic-beta header (which a
45
+ // caller's requestHeaders may have replaced), else the selected names.
46
+ function sentBetas(requestHeaders, betas) {
47
+ const header = requestHeaders?.['anthropic-beta'];
48
+ return typeof header === 'string' ? header.split(',').filter(Boolean) : betas || [];
49
+ }
50
+
43
51
  // One stream attempt's controller, aborted with the caller's reason when the
44
52
  // send's signal aborts. An already-aborted send fails before the attempt.
45
53
  function linkAttemptAbort(totalSignal) {
@@ -219,7 +227,7 @@ export class AnthropicProvider {
219
227
  // Wire request (system/cache layout, tools, effort, fast mode, images)
220
228
  // and the per-request beta headers derived from that final body —
221
229
  // anthropic-api-request.mjs. Fast mode latches on the provider instance.
222
- const { params, requestHeaders, knownToolNames, fastModeLatched } = await buildAnthropicApiRequest({
230
+ const built = await buildAnthropicApiRequest({
223
231
  name: this.name,
224
232
  config: this.config,
225
233
  messages,
@@ -232,7 +240,25 @@ export class AnthropicProvider {
232
240
  capabilityModel: this._capabilityModel(useModel),
233
241
  customConfig: this.customConfig ?? null,
234
242
  });
243
+ const { knownToolNames, fastModeLatched } = built;
235
244
  this.fastModeBetaHeaderLatched = fastModeLatched;
245
+ // Message thread (anthropic-message-threads.mjs): the same request as a
246
+ // create, a delta continue, or unchanged. The thread belongs to this key.
247
+ this._currentClient();
248
+ const thread = planAnthropicThread({
249
+ provider: this.name,
250
+ config: this.config,
251
+ opts,
252
+ body: built.params,
253
+ betas: sentBetas(built.requestHeaders, built.betas),
254
+ account: threadAccountKey(this.name, this.config?.baseURL || '', this.apiKey),
255
+ requestMessages: messages,
256
+ });
257
+ const params = thread.body;
258
+ const requestHeaders =
259
+ thread.mode === 'none'
260
+ ? built.requestHeaders
261
+ : { ...(built.requestHeaders || {}), 'anthropic-beta': thread.betas.join(',') };
236
262
 
237
263
  const { onStageChange, onStreamDelta, onToolCall, onTextDelta, onTextReset, onStreamItemStart } =
238
264
  streamCallbacks(opts);
@@ -260,6 +286,8 @@ export class AnthropicProvider {
260
286
  let streamingFallbackTried = false;
261
287
  try {
262
288
  for (let attemptIndex = 0; attemptIndex <= ANTHROPIC_MAX_MIDSTREAM_RETRIES; attemptIndex++) {
289
+ // A dropped continue is resent once as-is; after that it replays.
290
+ if (attemptIndex >= 2) thread.toCreate();
263
291
  const { streamController, cancelHandler } = linkAttemptAbort(totalSignal);
264
292
 
265
293
  const midState = createAnthropicMidState(attemptIndex);
@@ -297,13 +325,23 @@ export class AnthropicProvider {
297
325
  relayProgressUpdates: params.thinking?.display === 'updates',
298
326
  labels: { display: 'Anthropic', tag: this.name },
299
327
  onStreamItemStart,
328
+ awaitMessageStopMs: thread.mode === 'none' ? 0 : THREAD_MESSAGE_STOP_WAIT_MS,
329
+ releaseSignal: externalSignal,
300
330
  }
301
331
  );
302
- try {
303
- streamController.abort?.('Anthropic SSE complete');
304
- } catch {
305
- // the stream is complete; the controller may already be aborted
306
- }
332
+ thread.commit(parseResult);
333
+ const finishStream = () => {
334
+ try {
335
+ streamController.abort?.('Anthropic SSE complete');
336
+ } catch {
337
+ // the stream is complete; the controller may already be aborted
338
+ }
339
+ };
340
+ // A thread's message_stop may still be read in the background: the
341
+ // body stays open until that read settles.
342
+ const receiptTail = parseResult.threadReceipt?.pending;
343
+ if (receiptTail) void receiptTail.then(finishStream);
344
+ else finishStream();
307
345
 
308
346
  firstByte.cleanup();
309
347
  assertAnthropicStreamNotEmpty(midState, parseResult, 'Anthropic');
@@ -312,6 +350,16 @@ export class AnthropicProvider {
312
350
  } catch (err) {
313
351
  // The fallback trigger is handled around the whole send below.
314
352
  if (err instanceof AnthropicFallbackTriggeredError) throw err;
353
+ // A refused thread request (nothing ran): replay as a create or
354
+ // send unthreaded, per the thread error.
355
+ const threadDirective =
356
+ err?.initialResponseError === true
357
+ ? thread.classify(err.status, err.responseBody ?? err.error ?? err.message)
358
+ : null;
359
+ if (threadDirective) {
360
+ thread.settle();
361
+ return await this._sendOnce(messages, model, tools, { ...opts, _anthropicThread: threadDirective });
362
+ }
315
363
  // Gateways that 404 the streaming endpoint but serve non-streaming:
316
364
  // one non-streaming replay (nothing was streamed yet).
317
365
  if (err?.initialResponseError === true && Number(err.status) === 404 && !streamingFallbackTried) {
@@ -337,9 +385,11 @@ export class AnthropicProvider {
337
385
  }
338
386
  throw midstream.exhaustedError();
339
387
  } catch (err) {
388
+ thread.settle();
340
389
  const fallbackOpts = takeAnthropicModelFallback(err, { tag: this.name, model: useModel, opts, onStageChange });
341
390
  return await this._doSend(messages, err.fallbackModel, tools, fallbackOpts);
342
391
  } finally {
392
+ thread.settle();
343
393
  totalTimeout.cleanup();
344
394
  }
345
395
  }
@@ -121,9 +121,11 @@ function drainCursorRuns(reason = 'shutdown') {
121
121
  // so chain the previously registered handler instead of overwriting it: whoever
122
122
  // loads first stays reachable, in either import order.
123
123
  const _priorCursorSessionCloseHook = globalThis.__mixdogCloseProviderConnectionsForSession;
124
- globalThis.__mixdogCloseProviderConnectionsForSession = (sessionId, reason) => {
124
+ // An active Cursor run is the turn in flight, so a turn abort
125
+ // (`options.inFlightOnly`) closes it as well; the options pass down the chain.
126
+ globalThis.__mixdogCloseProviderConnectionsForSession = (sessionId, reason, options) => {
125
127
  try {
126
- _priorCursorSessionCloseHook?.(sessionId, reason);
128
+ _priorCursorSessionCloseHook?.(sessionId, reason, options);
127
129
  } finally {
128
130
  closeCursorRunsForSession(sessionId, reason);
129
131
  // A disposed transport scope never sends again: drop its conversation.
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * gemini-error-contract.mjs — Google RPC error details → the provider error
3
- * contract shared by Gemini (REST + SDK) and Antigravity:
3
+ * contract shared by Gemini and Antigravity:
4
4
  * status, code (lowercased), retryAfterMs (uncapped), resetAt (epoch ms),
5
5
  * quotaScope ('minute' | 'day' | undefined).
6
6
  *
7
- * Details come from `error.details` (REST body) or `errorDetails` (SDK
8
- * GoogleGenerativeAIFetchError). Entries are google.rpc.RetryInfo,
7
+ * Details come from `error.details` or `errorDetails` of the error body.
8
+ * Entries are google.rpc.RetryInfo,
9
9
  * QuotaFailure and ErrorInfo.
10
10
  */
11
11
 
@@ -267,9 +267,9 @@ export function geminiFinishErrorFields(response) {
267
267
  }
268
268
 
269
269
  /**
270
- * Typed result for a CONTINUATION finish, which this client cannot resume
271
- * (Gemini direct only). Keeps the original error's partial turn and the
272
- * token so a caller can continue it out of band.
270
+ * Typed result for a CONTINUATION finish that cannot be resumed here: a
271
+ * gateway route, or a CONTINUATION without a token (the direct Gemini API
272
+ * resumes tokened hops itself). Keeps the partial turn and any token.
273
273
  */
274
274
  export function geminiContinuationUnsupportedError(incomplete, response) {
275
275
  return Object.assign(incomplete, geminiFinishErrorFields(response), {
@@ -0,0 +1,44 @@
1
+ /**
2
+ * gemini-model-redirect.mjs — model ids the Gemini API serves as another
3
+ * model, and the models that ignore the deprecated sampling parameters.
4
+ *
5
+ * Redirects (https://aistudio.google.com/docs/changelog.md, 2026-11-02, and
6
+ * docs/deprecations.md): effective December 1, 2026 every API request to
7
+ * `gemini-2.5-pro` routes to `gemini-3.8-flash` and every request to
8
+ * `gemini-2.5-flash` routes to `gemini-3.5-flash-lite`, billed at the target's
9
+ * rates; `gemini-2.5-flash-lite` is not affected. No time zone is documented,
10
+ * so the date is taken as UTC midnight.
11
+ */
12
+ const REDIRECT_FROM_MS = Date.parse('2026-12-01T00:00:00Z');
13
+ const REDIRECTS = new Map([
14
+ ['gemini-2.5-pro', 'gemini-3.8-flash'],
15
+ ['gemini-2.5-flash', 'gemini-3.5-flash-lite'],
16
+ ]);
17
+
18
+ const bareId = (model) =>
19
+ String(model || '')
20
+ .replace(/^models\//i, '')
21
+ .toLowerCase();
22
+
23
+ /** The id the API serves `model` as at `nowMs`, or null when it is served as itself. */
24
+ export function geminiRedirectTarget(model, nowMs = Date.now()) {
25
+ if (nowMs < REDIRECT_FROM_MS) return null;
26
+ return REDIRECTS.get(bareId(model)) ?? null;
27
+ }
28
+
29
+ /**
30
+ * True for models that ignore `temperature`/`top_p`/`top_k`: "Starting with
31
+ * Gemini 3.6 Flash and Gemini 3.5 Flash-Lite ... these models and all future
32
+ * Gemini model releases" (docs/whats-new-gemini-3.6.md#api-changes-and-parameter-updates;
33
+ * changelog 2026-07-21). `gemini-3.5-flash` is routed to `gemini-3.6-flash`
34
+ * (deprecations.md), so it is served by a model that ignores them too.
35
+ */
36
+ export function geminiIgnoresSamplingParams(model) {
37
+ const bare = bareId(model);
38
+ if (/^gemini-3\.5-flash(?:-lite)?$/.test(bare)) return true;
39
+ const version = /^gemini-(\d+)(?:\.(\d+))?(?:-|$)/.exec(bare);
40
+ if (!version) return false;
41
+ const major = Number(version[1]);
42
+ const minor = Number(version[2] || 0);
43
+ return major >= 4 || (major === 3 && minor >= 6);
44
+ }
@@ -18,6 +18,11 @@ export function createGeminiReasoningRelay(opts) {
18
18
  opts.onReasoningDelta(text);
19
19
  }
20
20
  : null,
21
+ // A finished long-decode hop is part of the answer: a later hop's retry
22
+ // must not retract the thinking it showed.
23
+ commit() {
24
+ relayed = false;
25
+ },
21
26
  retract() {
22
27
  if (!relayed) return;
23
28
  relayed = false;