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
@@ -127,6 +127,11 @@ export function createSessionMediaApi(bag) {
127
127
  setMediaPin: (input) => runtime.setMediaPin?.(input),
128
128
  listMediaAssets: (options) => runtime.listMediaAssets?.(options),
129
129
  readMediaAsset: (id, options) => runtime.readMediaAsset?.(id, options),
130
+ listMediaBoards: () => runtime.listMediaBoards?.(),
131
+ createMediaBoard: (name) => runtime.createMediaBoard?.(name),
132
+ renameMediaBoard: (id, name) => runtime.renameMediaBoard?.(id, name),
133
+ deleteMediaBoard: (id) => runtime.deleteMediaBoard?.(id),
134
+ setMediaAssetBoard: (ids, boardId) => runtime.setMediaAssetBoard?.(ids, boardId),
130
135
  cacheMediaThumbnail: (id, input) => runtime.cacheMediaThumbnail?.(id, input),
131
136
  resolveMediaFile: (id, options) => runtime.resolveMediaFile?.(id, options),
132
137
  getMediaJob: (id) => runtime.getMediaJob?.(id),
@@ -22,6 +22,8 @@ export { transcriptToolCallDisplayMode } from './turn-tool-cards.mjs';
22
22
  import { isRejected429 } from '../../runtime/shared/error-presentation.mjs';
23
23
  import { QUOTA_KINDS, providerErrorKind } from '../../runtime/agent/orchestrator/providers/provider-error-kind.mjs';
24
24
  import { turnFailureRecord } from '../../runtime/agent/orchestrator/session/turn-failure.mjs';
25
+ import { providerDisplayName } from '../../runtime/shared/provider-display-name.mjs';
26
+ import { clearDesktopNotice, raiseDesktopNotice } from '../../runtime/shared/desktop-notice-host.mjs';
25
27
  import { registerTaskWaitSteeringCheck } from '../../runtime/agent/orchestrator/session/task-wait-control.mjs';
26
28
  import {
27
29
  isReactionSuccess,
@@ -529,8 +531,11 @@ function completeTurn(ctx, result, session) {
529
531
  set({ stats: { ...getState().stats } });
530
532
  settleFinalText(stream, result?.content != null ? String(result.content) : '');
531
533
  turn.finishedNormally = true;
534
+ if (turn.routeMeta?.provider) clearDesktopNotice(providerSignInNoticeKey(turn.routeMeta.provider));
532
535
  }
533
536
 
537
+ const providerSignInNoticeKey = (provider) => `provider-sign-in:${provider}`;
538
+
534
539
  export function failTurn(ctx, error) {
535
540
  const { turn, stream, cards, pushNotice } = ctx;
536
541
  flushStreamBatch(stream); // ensure any batched text lands before the error notice
@@ -549,6 +554,14 @@ export function failTurn(ctx, error) {
549
554
  if (record.quota) turn.quota = record.quota;
550
555
  turn.failureDetail = record.detail;
551
556
  turn.failureDiagnostic = record.errorDetails;
557
+ // The provider refused the sign-in (expired, revoked, refresh failed): the
558
+ // desktop says so once per provider until a turn on it succeeds again.
559
+ const provider = turn.routeMeta?.provider;
560
+ if (provider && record.providerKind.kind === 'auth') {
561
+ raiseDesktopNotice(providerSignInNoticeKey(provider), 'provider-sign-in-expired', {
562
+ name: providerDisplayName(provider),
563
+ });
564
+ }
552
565
  // Answers the turn went on past before it failed (turn-report.mjs).
553
566
  if (typeof error?.carriedReport === 'string') turn.carriedReport = error.carriedReport;
554
567
  pushNotice(turn.failureDetail, 'error', { owner: 'transcript' });
@@ -1,71 +0,0 @@
1
- // Cancellation of an in-flight Gemini SDK iterator.
2
- //
3
- // A timeout or external abort must stop the generation and retire the SDK
4
- // iterator without deadlocking on it. The first forced failure wins; a read
5
- // that settles later reports that failure once cleanup finished.
6
- export function createSdkStreamCancellation({ signal, label, cancelGeneration, cancellationGraceMs }) {
7
- let iterator = null;
8
- let cancellation = null;
9
- let forcedFailure = null;
10
-
11
- const abortError = () => (signal?.reason instanceof Error ? signal.reason : new Error(`${label} aborted`));
12
-
13
- const cancelInFlight = (err) => {
14
- if (cancellation) return cancellation;
15
- forcedFailure = err;
16
- cancellation = (async () => {
17
- try {
18
- cancelGeneration?.(err);
19
- } catch {}
20
- let returnPromise;
21
- try {
22
- returnPromise = Promise.resolve(iterator?.return?.());
23
- } catch {
24
- return;
25
- }
26
- // iterator.return() is best-effort cleanup. A broken SDK iterator
27
- // must not deadlock the timeout path and prevent withRetry from
28
- // beginning the next attempt after the generation was aborted.
29
- let graceTimer = null;
30
- try {
31
- await Promise.race([
32
- returnPromise.catch(() => {}),
33
- new Promise((resolve) => {
34
- graceTimer = setTimeout(resolve, Math.max(0, cancellationGraceMs));
35
- }),
36
- ]);
37
- } finally {
38
- if (graceTimer) clearTimeout(graceTimer);
39
- // Keep observing a late rejection after the grace race expires.
40
- returnPromise.catch(() => {});
41
- }
42
- })();
43
- return cancellation;
44
- };
45
-
46
- return {
47
- abortError,
48
- cancelInFlight,
49
- // The iterator to retire; bound once the SDK stream is opened.
50
- bindIterator(next) {
51
- iterator = next;
52
- },
53
- // Fail a pending read only after the generation was cancelled.
54
- rejectAfterCancellation(reject, err) {
55
- cancelInFlight(err).then(
56
- () => reject(err),
57
- () => reject(err)
58
- );
59
- },
60
- // A read settling after a forced cancellation reports that failure once
61
- // cleanup finished. Returns false when no cancellation was forced.
62
- settleForced(reject) {
63
- if (!forcedFailure) return false;
64
- cancellation.then(
65
- () => reject(forcedFailure),
66
- () => reject(forcedFailure)
67
- );
68
- return true;
69
- },
70
- };
71
- }
@@ -1,108 +0,0 @@
1
- // Pending-read registry and watchdogs for the Gemini SDK iterator.
2
- //
3
- // One read is in flight at a time. Its reject handle is registered so the
4
- // first-byte timer, the idle watchdog and an external abort can fail the read
5
- // immediately instead of waiting for the SDK to notice.
6
- import { PROVIDER_SSE_IDLE_TIMEOUT_MS, PROVIDER_SSE_IDLE_WATCHDOG_ENABLED } from '../../stall-policy.mjs';
7
-
8
- export function createSdkStreamReader({ iterator, label, firstByteTimeoutMs, timeoutError, cancellation }) {
9
- let sawStreamChunk = false;
10
- let idleTimedOut = false;
11
- let idleTimer = null;
12
- let firstByteTimer = null;
13
- let firstByteReject = null;
14
- let inFlightReject = null;
15
-
16
- const idleError = () => timeoutError(`${label} SSE idle`, PROVIDER_SSE_IDLE_TIMEOUT_MS);
17
- const clearPending = () => {
18
- inFlightReject = null;
19
- firstByteReject = null;
20
- };
21
-
22
- const armFirstByteTimer = () => {
23
- if (firstByteTimer) clearTimeout(firstByteTimer);
24
- firstByteTimer = setTimeout(() => {
25
- if (firstByteReject) {
26
- const e = timeoutError(`${label} first byte`, firstByteTimeoutMs);
27
- const r = firstByteReject;
28
- firstByteReject = null;
29
- cancellation.rejectAfterCancellation(r, e);
30
- }
31
- }, firstByteTimeoutMs);
32
- };
33
- const clearFirstByteTimer = () => {
34
- if (firstByteTimer) {
35
- clearTimeout(firstByteTimer);
36
- firstByteTimer = null;
37
- }
38
- firstByteReject = null;
39
- };
40
- const resetIdleTimer = () => {
41
- if (!PROVIDER_SSE_IDLE_WATCHDOG_ENABLED) return;
42
- if (idleTimer) clearTimeout(idleTimer);
43
- idleTimer = setTimeout(() => {
44
- idleTimedOut = true;
45
- if (inFlightReject) {
46
- const r = inFlightReject;
47
- inFlightReject = null;
48
- cancellation.rejectAfterCancellation(r, idleError());
49
- }
50
- }, PROVIDER_SSE_IDLE_TIMEOUT_MS);
51
- };
52
-
53
- return {
54
- get sawStreamChunk() {
55
- return sawStreamChunk;
56
- },
57
- get idleTimedOut() {
58
- return idleTimedOut;
59
- },
60
- idleError,
61
- // Arm both watchdogs once the abort listener is in place.
62
- arm() {
63
- armFirstByteTimer();
64
- resetIdleTimer();
65
- },
66
- clearFirstByte: clearFirstByteTimer,
67
- // Stop every watchdog (completion or the finally path).
68
- stop() {
69
- clearFirstByteTimer();
70
- if (idleTimer) clearTimeout(idleTimer);
71
- },
72
- // External abort: fail the pending read now; the SDK iterator may
73
- // propagate the transport abort only after its own asynchronous cleanup.
74
- rejectPending(err) {
75
- if (!inFlightReject) return;
76
- const r = inFlightReject;
77
- clearPending();
78
- r(err);
79
- },
80
- // Resolve the next SDK step with its reject handle registered for the
81
- // watchdogs; a settlement after a forced cancellation reports that failure.
82
- next() {
83
- return new Promise((resolve, reject) => {
84
- inFlightReject = reject;
85
- if (!sawStreamChunk) firstByteReject = reject;
86
- iterator.next().then(
87
- (value) => {
88
- clearPending();
89
- if (!cancellation.settleForced(reject)) resolve(value);
90
- },
91
- (err) => {
92
- clearPending();
93
- if (!cancellation.settleForced(reject)) reject(err);
94
- }
95
- );
96
- });
97
- },
98
- // A delivered chunk retires the first-byte timer and restarts the idle
99
- // watchdog.
100
- noteChunk() {
101
- if (!sawStreamChunk) {
102
- sawStreamChunk = true;
103
- clearFirstByteTimer();
104
- }
105
- resetIdleTimer();
106
- },
107
- };
108
- }