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.
- package/package.json +1 -2
- package/src/cli.mjs +5 -1
- package/src/defaults/shipped-history.json +26 -2
- package/src/defaults/skills/browser-use/SKILL.md +148 -273
- package/src/defaults/skills/browser-use/references/devtools.md +14 -0
- package/src/defaults/skills/browser-use/references/page-flows.md +66 -0
- package/src/defaults/skills/browser-use/references/sign-in.md +70 -0
- package/src/defaults/skills/code-tidy/SKILL.md +60 -84
- package/src/defaults/skills/code-tidy/references/agent-cleanup.md +27 -2
- package/src/defaults/skills/computer-use/SKILL.md +145 -240
- package/src/defaults/skills/computer-use/references/flows.md +35 -0
- package/src/defaults/skills/computer-use/references/operations.md +22 -0
- package/src/defaults/skills/computer-use/references/platforms.md +12 -0
- package/src/defaults/skills/docx/SKILL.md +23 -31
- package/src/defaults/skills/docx/references/native-authoring.md +26 -3
- package/src/defaults/skills/docx/references/redlining.md +15 -0
- package/src/defaults/skills/image/SKILL.md +37 -77
- package/src/defaults/skills/image/references/prompt-forms.md +51 -0
- package/src/defaults/skills/image/references/text.md +6 -0
- package/src/defaults/skills/local-provider/SKILL.md +75 -105
- package/src/defaults/skills/local-provider/references/lifecycle.md +14 -0
- package/src/defaults/skills/local-provider/references/maintenance.md +19 -0
- package/src/defaults/skills/local-provider/references/recovery.md +30 -0
- package/src/defaults/skills/memory-management/SKILL.md +16 -20
- package/src/defaults/skills/pdf/SKILL.md +21 -23
- package/src/defaults/skills/pdf/references/blocks.md +20 -0
- package/src/defaults/skills/pdf/references/forms.md +12 -0
- package/src/defaults/skills/pdf/references/html.md +2 -2
- package/src/defaults/skills/pdf/references/ocr.md +7 -0
- package/src/defaults/skills/pdf/references/security.md +8 -0
- package/src/defaults/skills/pptx/SKILL.md +30 -109
- package/src/defaults/skills/pptx/references/audit.md +45 -0
- package/src/defaults/skills/pptx/references/brief-critique.md +47 -0
- package/src/defaults/skills/pptx/references/editing.md +24 -0
- package/src/defaults/skills/pptx/references/html.md +1 -1
- package/src/defaults/skills/pptx/references/script.md +33 -0
- package/src/defaults/skills/setup/SKILL.md +34 -102
- package/src/defaults/skills/setup/references/actions.md +72 -13
- package/src/defaults/skills/setup/references/surfaces.md +23 -8
- package/src/defaults/skills/setup-guide/SKILL.md +28 -115
- package/src/defaults/skills/setup-guide/references/features.md +36 -0
- package/src/defaults/skills/setup-guide/references/glossary.md +38 -0
- package/src/defaults/skills/setup-guide/references/workflow-models.md +62 -0
- package/src/defaults/skills/test-suite/SKILL.md +15 -127
- package/src/defaults/skills/test-suite/references/case-management.md +17 -9
- package/src/defaults/skills/test-suite/references/diagnose.md +23 -0
- package/src/defaults/skills/test-suite/references/prune.md +27 -0
- package/src/defaults/skills/test-suite/references/write.md +44 -0
- package/src/defaults/skills/video/SKILL.md +28 -42
- package/src/defaults/skills/video/references/prompting.md +31 -0
- package/src/defaults/skills/visualize/SKILL.md +73 -107
- package/src/defaults/skills/visualize/references/craft.md +1 -2
- package/src/defaults/skills/visualize/references/feedback.md +36 -0
- package/src/defaults/skills/visualize/references/showing.md +13 -0
- package/src/defaults/skills/xlsx/SKILL.md +23 -50
- package/src/defaults/skills/xlsx/references/editing.md +15 -0
- package/src/defaults/skills/xlsx/references/model-conventions.md +1 -1
- package/src/defaults/skills/xlsx/references/recalculation.md +37 -0
- package/src/defaults/skills/xlsx/references/report-design.md +18 -2
- package/src/lib/keychain-cjs.cjs +22 -1
- package/src/lib/rules-builder.cjs +1 -1
- package/src/rules/agent/AGENT.md +3 -0
- package/src/rules/lead/LEAD.md +3 -1
- package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +8 -30
- package/src/runtime/agent/orchestrator/agent-runtime/title-completion.mjs +5 -0
- package/src/runtime/agent/orchestrator/mcp/oauth-request.mjs +21 -2
- package/src/runtime/agent/orchestrator/providers/account-pool.mjs +3 -0
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +2 -2
- package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-message-threads.mjs +583 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-client-version.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +81 -19
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +56 -6
- package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
- package/src/runtime/agent/orchestrator/providers/gemini-error-contract.mjs +6 -6
- package/src/runtime/agent/orchestrator/providers/gemini-model-redirect.mjs +44 -0
- package/src/runtime/agent/orchestrator/providers/gemini-reasoning-relay.mjs +5 -0
- package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +34 -5
- package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +10 -0
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +11 -6
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +4 -100
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +3 -227
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +226 -118
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +11 -1
- package/src/runtime/agent/orchestrator/providers/lib/claude-bridge-schema.mjs +15 -3
- package/src/runtime/agent/orchestrator/providers/lib/gemini-model-catalog.mjs +2 -1
- package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream/socket-handlers.mjs +14 -10
- package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +1 -3
- package/src/runtime/agent/orchestrator/providers/stream-json-pool/worker-slots/slot-spawn.mjs +8 -3
- package/src/runtime/agent/orchestrator/providers/vertex-ai-maas.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/config-helpers.mjs +4 -5
- package/src/runtime/agent/orchestrator/runtime-core/goal-tool-defs.mjs +2 -2
- package/src/runtime/agent/orchestrator/runtime-core/provider-request-tools.mjs +15 -8
- package/src/runtime/agent/orchestrator/runtime-core/session-title.mjs +1 -0
- package/src/runtime/agent/orchestrator/runtime-core/todo-list.mjs +9 -32
- package/src/runtime/agent/orchestrator/runtime-core/todo-tool-defs.mjs +4 -5
- package/src/runtime/agent/orchestrator/session/compact/summary-route.mjs +1 -3
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +5 -2
- package/src/runtime/agent/orchestrator/session/loop/no-tool-turn/todo-check.mjs +2 -17
- package/src/runtime/agent/orchestrator/session/loop/usage.mjs +7 -3
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-settle.mjs +9 -2
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +26 -13
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +4 -5
- package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +16 -5
- package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +22 -1
- package/src/runtime/agent/orchestrator/session/store/live-state.mjs +4 -0
- package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +11 -9
- package/src/runtime/agent/orchestrator/tools/builtin/grep-formatting.mjs +2 -8
- package/src/runtime/agent/orchestrator/tools/builtin/lib/search-input-helpers.mjs +1 -9
- package/src/runtime/agent/orchestrator/tools/builtin/local-search-telemetry.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.mjs +12 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +9 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +137 -7
- package/src/runtime/agent/orchestrator/tools/code-graph/calls-cache.mjs +43 -14
- package/src/runtime/agent/orchestrator/tools/code-graph/calls-sidecar-worker.mjs +33 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +146 -11
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +31 -24
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary/spawn-jsonl.mjs +172 -25
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-model.mjs +100 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/main-thread-slice.mjs +18 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/mask-pool.mjs +219 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/mask-worker.mjs +12 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.mjs +6 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/calls.mjs +9 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/dependents.mjs +5 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/structure.mjs +8 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/modes/symbols.mjs +14 -11
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +41 -18
- package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +391 -83
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +109 -9
- package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +73 -29
- package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +6 -5
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.mjs +7 -3
- package/src/runtime/channels/lib/crash-log.mjs +21 -1
- package/src/runtime/channels/lib/worker-main.mjs +8 -25
- package/src/runtime/media/jobs.mjs +5 -0
- package/src/runtime/media/store.mjs +146 -3
- package/src/runtime/office/core/office-write-ledger.mjs +2 -2
- package/src/runtime/shared/agent-reap-state.mjs +19 -0
- package/src/runtime/shared/desktop-notice-host.d.mts +13 -0
- package/src/runtime/shared/desktop-notice-host.mjs +87 -0
- package/src/runtime/shared/file-lock.mjs +2 -2
- package/src/runtime/shared/heap-cap.mjs +9 -11
- package/src/runtime/shared/llm/http-agent.mjs +11 -1
- package/src/runtime/shared/llm/system-proxy.mjs +100 -25
- package/src/runtime/shared/llm/usage-accounting.mjs +18 -7
- package/src/runtime/shared/llm/usage-context.mjs +2 -2
- package/src/runtime/shared/llm/usage-ledger-requests.mjs +10 -3
- package/src/runtime/shared/llm/usage-ledger.mjs +13 -1
- package/src/runtime/shared/provider-accounts.mjs +22 -0
- package/src/runtime/shared/provider-auth-binding.mjs +2 -2
- package/src/runtime/shared/resource-admission.mjs +2 -2
- package/src/runtime/shared/root-async-context.mjs +51 -0
- package/src/runtime/shared/run-child.mjs +18 -1
- package/src/runtime/shared/slow-span.mjs +2 -2
- package/src/runtime/shared/tool-execution-owner.mjs +2 -2
- package/src/runtime/shared/tool-work-units.mjs +2 -0
- package/src/runtime/shared/turn-snapshot-store.mjs +75 -18
- package/src/runtime/shared/turn-worktree-snapshot.mjs +38 -8
- package/src/runtime/shared/user-cwd.mjs +2 -2
- package/src/runtime/shared/worker-requests.mjs +3 -1
- package/src/runtime/shared/worktrees/lock.mjs +2 -2
- package/src/runtime/visualize-bridge/client.mjs +26 -4
- package/src/runtime/visualize-bridge/tool-defs.mjs +46 -5
- package/src/session-runtime/boot/apis.mjs +1 -0
- package/src/session-runtime/boot/begin.mjs +2 -0
- package/src/session-runtime/media-api.mjs +15 -0
- package/src/session-runtime/provider-readiness.mjs +10 -2
- package/src/session-runtime/runtime-core.mjs +35 -8
- package/src/session-runtime/runtime-review-api.mjs +3 -1
- package/src/session-runtime/services/agent-tool/close-flow.mjs +6 -1
- package/src/session-runtime/services/agent-tool/execute-resume.mjs +94 -0
- package/src/session-runtime/services/agent-tool/execute-send.mjs +77 -27
- package/src/session-runtime/services/agent-tool/execute-spawn.mjs +28 -7
- package/src/session-runtime/services/agent-tool/execute.mjs +6 -1
- package/src/session-runtime/services/agent-tool/helpers.mjs +11 -0
- package/src/session-runtime/services/agent-tool/job-views/job-render.mjs +13 -10
- package/src/session-runtime/services/agent-tool/render.mjs +2 -0
- package/src/session-runtime/services/agent-tool/send-flow.mjs +1 -0
- package/src/session-runtime/services/agent-tool/spawn-flow/spawn-prep.mjs +6 -0
- package/src/session-runtime/services/agent-tool/spawn-flow/spawn-run.mjs +2 -1
- package/src/session-runtime/services/agent-tool/tag-registry/reaped-sessions.mjs +82 -0
- package/src/session-runtime/services/agent-tool/tag-registry/record-facts-worker.mjs +36 -0
- package/src/session-runtime/services/agent-tool/tag-registry.mjs +4 -0
- package/src/session-runtime/services/agent-tool/terminal-reaper/row-helpers.mjs +29 -0
- package/src/session-runtime/services/agent-tool/terminal-reaper/scan-admission.mjs +11 -3
- package/src/session-runtime/services/agent-tool/terminal-reaper/stale-rows.mjs +19 -8
- package/src/session-runtime/services/agent-tool/terminal-reaper.mjs +5 -2
- package/src/session-runtime/services/agent-tool/worker-index.mjs +1 -0
- package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
- package/src/session-runtime/session-create.mjs +5 -0
- package/src/session-runtime/setup-tool/settings-contract.mjs +2 -0
- package/src/session-runtime/usage-stats-api.mjs +3 -0
- package/src/session-runtime/workspace/admission-gate.mjs +25 -7
- package/src/session-runtime/workspace/transitions.mjs +4 -0
- package/src/standalone/daemon-log.mjs +28 -4
- package/src/standalone/daemon-owner.mjs +41 -7
- package/src/standalone/daemon-work-gate.mjs +139 -0
- package/src/standalone/daemon.mjs +80 -11
- package/src/standalone/desktop-service-registry.mjs +11 -4
- package/src/standalone/session-client.mjs +57 -5
- package/src/standalone/session-protocol.mjs +5 -0
- package/src/standalone/session-service/agent-tree/agent-cancel.mjs +17 -1
- package/src/standalone/session-service/agent-tree.mjs +7 -0
- package/src/standalone/session-service/session-calls/session-turns.mjs +12 -5
- package/src/standalone/session-transport/call-route.mjs +10 -4
- package/src/standalone/session-transport/routes.mjs +21 -0
- package/src/standalone/session-transport/stack.mjs +3 -1
- package/src/standalone/session-transport.mjs +5 -0
- package/src/tui/dist/index.mjs +495 -477
- package/src/tui/session/session-api/media.mjs +5 -0
- package/src/tui/session/turn.mjs +13 -0
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-stream/cancellation.mjs +0 -71
- 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),
|
package/src/tui/session/turn.mjs
CHANGED
|
@@ -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
|
-
}
|