mixdog 1.4.3 → 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 +30 -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 -229
- 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 +22 -21
- 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 +73 -14
- 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/agent-mode/MIXY.md +5 -3
- 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 +4 -3
- package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +11 -1
- 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-turn/turn-events/content-block-start.mjs +4 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse-turn/turn-outcome.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +180 -13
- package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +58 -6
- package/src/runtime/agent/orchestrator/providers/cursor-wire.mjs +4 -2
- package/src/runtime/agent/orchestrator/providers/custom-provider-config.mjs +121 -9
- package/src/runtime/agent/orchestrator/providers/custom-provider.mjs +4 -1
- 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/lib/generation-window.mjs +9 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-send.mjs +9 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-result.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-chat-stream/stream-state.mjs +5 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-options.mjs +3 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-response-normalization.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +10 -1
- package/src/runtime/agent/orchestrator/providers/openai-direct-request.mjs +5 -28
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-events.mjs +3 -0
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +50 -28
- package/src/runtime/agent/orchestrator/providers/openai-ws-response-state.mjs +9 -2
- 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/openrouter-provider-routing.mjs +28 -0
- package/src/runtime/agent/orchestrator/providers/openrouter.mjs +4 -1
- package/src/runtime/agent/orchestrator/providers/registry.mjs +30 -25
- 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/ask-user-result.mjs +66 -0
- 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/runtime-liveness.mjs +8 -1
- 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/session/store.mjs +12 -6
- 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/lib/shell-output-silence.mjs +64 -0
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +20 -6
- 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/builtin/task-tool.mjs +12 -1
- 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/routines-db.mjs +35 -0
- package/src/runtime/channels/lib/schedules-db.mjs +4 -0
- package/src/runtime/channels/lib/webhooks-db.mjs +4 -0
- package/src/runtime/channels/lib/worker-main.mjs +8 -25
- package/src/runtime/computer-bridge/action-schema.mjs +2 -2
- package/src/runtime/computer-bridge/core-actions.mjs +16 -2
- package/src/runtime/computer-bridge/result-canonical.mjs +6 -0
- package/src/runtime/media/jobs.mjs +5 -0
- package/src/runtime/media/store.mjs +146 -3
- package/src/runtime/memory/tool-defs.mjs +1 -1
- 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 +121 -19
- package/src/runtime/shared/llm/usage-context.mjs +3 -3
- package/src/runtime/shared/llm/usage-ledger-quota.mjs +2 -0
- package/src/runtime/shared/llm/usage-ledger-requests.mjs +190 -0
- package/src/runtime/shared/llm/usage-ledger-rollup.mjs +7 -3
- package/src/runtime/shared/llm/usage-ledger-worker.mjs +2 -0
- package/src/runtime/shared/llm/usage-ledger.mjs +69 -1
- package/src/runtime/shared/llm/usage-request-status.mjs +48 -0
- 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-result-summary.mjs +1 -1
- 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/agent-home-delivery.mjs +76 -8
- package/src/session-runtime/agent-task-sessions.mjs +63 -22
- package/src/session-runtime/boot/apis.mjs +16 -0
- package/src/session-runtime/boot/begin.mjs +2 -0
- package/src/session-runtime/boot/tools.mjs +8 -2
- package/src/session-runtime/internal-tool-executor/ask-user-tool.mjs +3 -58
- package/src/session-runtime/media-api.mjs +15 -0
- package/src/session-runtime/model-route/route-persist.mjs +12 -4
- package/src/session-runtime/provider-models/row-hydration.mjs +2 -0
- package/src/session-runtime/provider-readiness.mjs +10 -2
- package/src/session-runtime/routine-owner.mjs +9 -3
- 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-task-status.mjs +29 -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/job-views/session-progress.mjs +3 -0
- package/src/session-runtime/services/agent-tool/render.mjs +8 -1
- 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/channel-admin.mjs +44 -3
- package/src/session-runtime/services/daemon-crash-capture/daemon-exit-record.mjs +2 -2
- package/src/session-runtime/services/plugin-admin.mjs +46 -7
- package/src/session-runtime/services/provider-admin.mjs +5 -0
- package/src/session-runtime/session-create.mjs +5 -0
- package/src/session-runtime/setup-tool/agent-settings-actions.mjs +1 -1
- package/src/session-runtime/setup-tool/executor.mjs +1 -1
- package/src/session-runtime/setup-tool/extended-actions.mjs +1 -1
- package/src/session-runtime/setup-tool/settings-contract.mjs +4 -2
- package/src/session-runtime/usage-stats-api.mjs +120 -1
- package/src/session-runtime/workflow-agents-api/agent-connectors.mjs +36 -29
- package/src/session-runtime/workflow-agents-api/agent-editor.mjs +183 -23
- 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 +6 -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/retention/busy.mjs +3 -2
- 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/app/model-picker/model-footer.mjs +1 -1
- package/src/tui/app/model-picker/provider-models-list.mjs +7 -3
- package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +23 -3
- package/src/tui/app/model-picker/route-selection.mjs +1 -0
- package/src/tui/dist/index.mjs +536 -484
- package/src/tui/session/session-api/integrations.mjs +3 -0
- package/src/tui/session/session-api/media.mjs +5 -0
- package/src/tui/session/tool-approval-settle.mjs +24 -4
- package/src/tui/session/tool-approval.mjs +35 -10
- 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
|
@@ -13,6 +13,35 @@ export const CUSTOM_REASONING_WIRE_FORMATS = Object.freeze(['standard', 'deepsee
|
|
|
13
13
|
export const CUSTOM_PROVIDER_AUTH_MODES = Object.freeze(['key', 'none']);
|
|
14
14
|
export const CUSTOM_MODEL_OVERRIDE_LIMIT = 500;
|
|
15
15
|
export const CUSTOM_HEADER_LIMIT = 64;
|
|
16
|
+
// Serialized size cap of one extra-request JSON object (provider or model).
|
|
17
|
+
export const CUSTOM_REQUEST_BODY_MAX_CHARS = 16384;
|
|
18
|
+
// What the Chat, Responses and Messages wires build themselves (body fields
|
|
19
|
+
// the app sets, or whose override would break replay, tool use or streaming).
|
|
20
|
+
export const CUSTOM_RESERVED_BODY_KEYS = Object.freeze(
|
|
21
|
+
new Set([
|
|
22
|
+
'model',
|
|
23
|
+
'messages',
|
|
24
|
+
'input',
|
|
25
|
+
'system',
|
|
26
|
+
'instructions',
|
|
27
|
+
'tools',
|
|
28
|
+
'tool_choice',
|
|
29
|
+
'parallel_tool_calls',
|
|
30
|
+
'stream',
|
|
31
|
+
'stream_options',
|
|
32
|
+
'previous_response_id',
|
|
33
|
+
'store',
|
|
34
|
+
'include',
|
|
35
|
+
'prompt_cache_key',
|
|
36
|
+
'max_tokens',
|
|
37
|
+
'max_output_tokens',
|
|
38
|
+
'max_completion_tokens',
|
|
39
|
+
])
|
|
40
|
+
);
|
|
41
|
+
// Transport headers the HTTP client owns; model-level headers may not set them.
|
|
42
|
+
export const CUSTOM_MODEL_REFUSED_HEADERS = Object.freeze(
|
|
43
|
+
new Set(['content-type', 'content-length', 'host', 'connection', 'transfer-encoding', 'proxy-authorization'])
|
|
44
|
+
);
|
|
16
45
|
|
|
17
46
|
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
18
47
|
const MAX_MODEL_ID = 256;
|
|
@@ -74,6 +103,8 @@ const OVERRIDE_KEYS = new Set([
|
|
|
74
103
|
'maxOutputTokens',
|
|
75
104
|
'supportsVision',
|
|
76
105
|
'reasoning',
|
|
106
|
+
'requestBody',
|
|
107
|
+
'requestHeaders',
|
|
77
108
|
]);
|
|
78
109
|
const REASONING_KEYS = new Set(['levels', 'wireFormat', 'wireValues', 'replay']);
|
|
79
110
|
const DISCOVERY_KEYS = new Set(['newModelsHidden']);
|
|
@@ -93,6 +124,7 @@ const V2_TOP_LEVEL_KEYS = new Set([
|
|
|
93
124
|
'wires',
|
|
94
125
|
'modelWires',
|
|
95
126
|
'headers',
|
|
127
|
+
'requestBody',
|
|
96
128
|
'id',
|
|
97
129
|
'apiKey',
|
|
98
130
|
'apiKeyEnv',
|
|
@@ -244,6 +276,10 @@ function normalizeOverride(id, raw, protocol, legacy) {
|
|
|
244
276
|
const reasoning = normalizeReasoning(raw.reasoning, `${label}.reasoning`, protocol);
|
|
245
277
|
if (Object.keys(reasoning).length) out.reasoning = reasoning;
|
|
246
278
|
}
|
|
279
|
+
const requestBody = normalizeRequestBody(raw.requestBody, `${label}.requestBody`);
|
|
280
|
+
if (Object.keys(requestBody).length) out.requestBody = requestBody;
|
|
281
|
+
const requestHeaders = normalizeHeaders(raw.requestHeaders, `${label}.requestHeaders`, CUSTOM_MODEL_REFUSED_HEADERS);
|
|
282
|
+
if (Object.keys(requestHeaders).length) out.requestHeaders = requestHeaders;
|
|
247
283
|
return out;
|
|
248
284
|
}
|
|
249
285
|
|
|
@@ -307,31 +343,98 @@ function normalizeModelWires(raw, protocol, wires) {
|
|
|
307
343
|
// `headers`: extra HTTP headers sent with every request to the endpoint
|
|
308
344
|
// (inference, model discovery, connection test). Names are case-insensitive
|
|
309
345
|
// tokens; the credential headers belong to the API key field.
|
|
310
|
-
function normalizeHeaders(raw) {
|
|
346
|
+
function normalizeHeaders(raw, label = 'headers', refused = AUTH_HEADERS) {
|
|
311
347
|
if (raw === undefined) return {};
|
|
312
|
-
if (!isPlainObject(raw)) fail(
|
|
348
|
+
if (!isPlainObject(raw)) fail(`${label} must be an object of header names to string values`);
|
|
313
349
|
const names = Object.keys(raw);
|
|
314
|
-
if (names.length > CUSTOM_HEADER_LIMIT) fail(`at most ${CUSTOM_HEADER_LIMIT}
|
|
350
|
+
if (names.length > CUSTOM_HEADER_LIMIT) fail(`at most ${CUSTOM_HEADER_LIMIT} ${label} are allowed`);
|
|
315
351
|
const seen = new Set();
|
|
316
352
|
const entries = [];
|
|
317
353
|
for (const name of names) {
|
|
318
354
|
if (name.length > MAX_HEADER_TEXT || !HEADER_NAME.test(name))
|
|
319
|
-
fail(
|
|
355
|
+
fail(`${label} has an invalid header name: ${JSON.stringify(name.slice(0, 64))}`);
|
|
320
356
|
const lower = name.toLowerCase();
|
|
321
|
-
if (AUTH_HEADERS.has(lower)) fail(
|
|
322
|
-
if (
|
|
357
|
+
if (AUTH_HEADERS.has(lower)) fail(`${label} must not set ${name}: authentication belongs to the API key field`);
|
|
358
|
+
if (refused.has(lower)) fail(`${label} must not set ${name}: the app owns this header`);
|
|
359
|
+
if (seen.has(lower)) fail(`${label} has duplicate header: ${name}`);
|
|
323
360
|
seen.add(lower);
|
|
324
|
-
if (typeof raw[name] !== 'string') fail(
|
|
361
|
+
if (typeof raw[name] !== 'string') fail(`${label}.${name} must be a string`);
|
|
325
362
|
// Validate before trimming, and trim only HTTP whitespace (space, tab), so
|
|
326
363
|
// CR/LF is refused rather than stripped and other characters are kept.
|
|
327
|
-
if (!HEADER_VALUE.test(raw[name])) fail(
|
|
364
|
+
if (!HEADER_VALUE.test(raw[name])) fail(`${label}.${name} has an invalid value`);
|
|
328
365
|
const value = raw[name].replace(/^[ \t]+|[ \t]+$/g, '');
|
|
329
|
-
if (value.length > MAX_HEADER_TEXT) fail(
|
|
366
|
+
if (value.length > MAX_HEADER_TEXT) fail(`${label}.${name} has an invalid value`);
|
|
330
367
|
entries.push([name, value]);
|
|
331
368
|
}
|
|
332
369
|
return Object.fromEntries(entries);
|
|
333
370
|
}
|
|
334
371
|
|
|
372
|
+
// `requestBody` (provider and model): extra JSON request fields. A shallow
|
|
373
|
+
// object, size-capped; the keys the app builds the request from can never be set here.
|
|
374
|
+
function normalizeRequestBody(raw, label) {
|
|
375
|
+
if (raw === undefined) return {};
|
|
376
|
+
if (!isPlainObject(raw)) fail(`${label} must be a JSON object`);
|
|
377
|
+
let size;
|
|
378
|
+
try {
|
|
379
|
+
size = JSON.stringify(raw)?.length;
|
|
380
|
+
} catch {
|
|
381
|
+
fail(`${label} must be JSON-serializable`);
|
|
382
|
+
}
|
|
383
|
+
if (!Number.isInteger(size)) fail(`${label} must be JSON-serializable`);
|
|
384
|
+
if (size > CUSTOM_REQUEST_BODY_MAX_CHARS)
|
|
385
|
+
fail(`${label} must be at most ${CUSTOM_REQUEST_BODY_MAX_CHARS} characters`);
|
|
386
|
+
const out = {};
|
|
387
|
+
for (const key of Object.keys(raw)) {
|
|
388
|
+
if (UNSAFE_KEYS.has(key)) fail(`${label} has an unsafe key: ${key}`);
|
|
389
|
+
if (CUSTOM_RESERVED_BODY_KEYS.has(key)) fail(`${label} must not set ${key}: the app owns this field`);
|
|
390
|
+
out[key] = raw[key];
|
|
391
|
+
}
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The extra request fields and headers for one model of a normalized config:
|
|
397
|
+
* provider JSON, then model JSON over it (shallow); provider headers, then
|
|
398
|
+
* model headers over them. Reserved keys are stripped again here, so a stored
|
|
399
|
+
* config that somehow carries one still cannot override the app. Headers are
|
|
400
|
+
* the model layer only: the provider's ride the engine's default headers.
|
|
401
|
+
*/
|
|
402
|
+
export function resolveCustomRequestExtras(config, model) {
|
|
403
|
+
const override =
|
|
404
|
+
config?.modelOverrides && Object.hasOwn(config.modelOverrides, model) ? config.modelOverrides[model] : null;
|
|
405
|
+
const body = {};
|
|
406
|
+
for (const layer of [config?.requestBody, override?.requestBody]) {
|
|
407
|
+
for (const [key, value] of Object.entries(layer || {})) {
|
|
408
|
+
if (!CUSTOM_RESERVED_BODY_KEYS.has(key) && !UNSAFE_KEYS.has(key)) body[key] = structuredClone(value);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
const headers = {};
|
|
412
|
+
for (const [name, value] of Object.entries(override?.requestHeaders || {})) {
|
|
413
|
+
const lower = name.toLowerCase();
|
|
414
|
+
if (!AUTH_HEADERS.has(lower) && !CUSTOM_MODEL_REFUSED_HEADERS.has(lower)) headers[name] = value;
|
|
415
|
+
}
|
|
416
|
+
return { body, headers };
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/** `params` (the finished request body) with the extras layered over it; reserved keys keep the app's value. */
|
|
420
|
+
export function applyCustomRequestBody(params, config, model) {
|
|
421
|
+
const { body } = resolveCustomRequestExtras(config, model ?? params?.model);
|
|
422
|
+
for (const [key, value] of Object.entries(body)) params[key] = value;
|
|
423
|
+
return params;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Per-request headers: the model's extra headers under the caller's own. */
|
|
427
|
+
export function customRequestHeaders(config, model, requestHeaders) {
|
|
428
|
+
const { headers } = resolveCustomRequestExtras(config, model);
|
|
429
|
+
if (!Object.keys(headers).length) return requestHeaders;
|
|
430
|
+
if (requestHeaders instanceof Headers || Array.isArray(requestHeaders)) {
|
|
431
|
+
const merged = new Headers(headers);
|
|
432
|
+
for (const [name, value] of new Headers(requestHeaders)) merged.set(name, value);
|
|
433
|
+
return merged;
|
|
434
|
+
}
|
|
435
|
+
return { ...headers, ...(requestHeaders || {}) };
|
|
436
|
+
}
|
|
437
|
+
|
|
335
438
|
// Legacy (pre-v2) `models: [{ id, name?, contextWindow?, maxOutputTokens? }]`
|
|
336
439
|
// become manual, visible overrides; their presence hides newly discovered ids.
|
|
337
440
|
function migrateLegacy(input) {
|
|
@@ -374,6 +477,7 @@ export function normalizeCustomProviderConfig(input) {
|
|
|
374
477
|
if (input.wires !== undefined || input.modelWires !== undefined)
|
|
375
478
|
fail('wires and modelWires require schemaVersion 2');
|
|
376
479
|
if (input.headers !== undefined) fail('headers require schemaVersion 2');
|
|
480
|
+
if (input.requestBody !== undefined) fail('requestBody requires schemaVersion 2');
|
|
377
481
|
source = migrateLegacy(input);
|
|
378
482
|
} else if (Number.isInteger(version) && version > CUSTOM_PROVIDER_SCHEMA_VERSION)
|
|
379
483
|
fail(`unsupported schemaVersion ${version}; update mixdog to use this provider`);
|
|
@@ -407,6 +511,7 @@ export function normalizeCustomProviderConfig(input) {
|
|
|
407
511
|
const wires = normalizeWires(source.wires, protocol);
|
|
408
512
|
const modelWires = normalizeModelWires(source.modelWires, protocol, wires);
|
|
409
513
|
const headers = normalizeHeaders(source.headers);
|
|
514
|
+
const requestBody = normalizeRequestBody(source.requestBody, 'requestBody');
|
|
410
515
|
return {
|
|
411
516
|
type: 'custom',
|
|
412
517
|
schemaVersion: CUSTOM_PROVIDER_SCHEMA_VERSION,
|
|
@@ -417,6 +522,7 @@ export function normalizeCustomProviderConfig(input) {
|
|
|
417
522
|
auth,
|
|
418
523
|
...(apiKeyEnv && auth === 'key' ? { apiKeyEnv } : {}),
|
|
419
524
|
...(Object.keys(headers).length ? { headers } : {}),
|
|
525
|
+
...(Object.keys(requestBody).length ? { requestBody } : {}),
|
|
420
526
|
discovery: { newModelsHidden },
|
|
421
527
|
modelOverrides: normalizeOverrides(source.modelOverrides, protocol, legacy),
|
|
422
528
|
...(wires ? { wires } : {}),
|
|
@@ -471,6 +577,12 @@ function effectiveRow(base, override, { providerId, discovered, newModelsHidden
|
|
|
471
577
|
outputTokens: ov.maxOutputTokens ?? (Number(base.outputTokens) > 0 ? Number(base.outputTokens) : null),
|
|
472
578
|
hidden,
|
|
473
579
|
manual: ov.manual === true,
|
|
580
|
+
// What the model has without its own override (a reset restores these).
|
|
581
|
+
inherited: {
|
|
582
|
+
name: base.name || base.id,
|
|
583
|
+
contextWindow: Number(base.contextWindow) > 0 ? Number(base.contextWindow) : 0,
|
|
584
|
+
maxOutputTokens: Number(base.outputTokens) > 0 ? Number(base.outputTokens) : null,
|
|
585
|
+
},
|
|
474
586
|
// An explicit override (false included) beats the catalog; unset keeps the base.
|
|
475
587
|
...(typeof ov.supportsVision === 'boolean' ? { supportsVision: ov.supportsVision } : {}),
|
|
476
588
|
supportsReasoning: levels ? levels.some((level) => level !== 'none') : base.supportsReasoning === true,
|
|
@@ -217,8 +217,11 @@ export async function createCustomProvider(id, config) {
|
|
|
217
217
|
// The bound Messages engine reads the parent's model rows, so a routed
|
|
218
218
|
// Messages request carries the same row-driven thinking/effort as the
|
|
219
219
|
// Anthropic protocol.
|
|
220
|
-
if (provider.messagesEngine)
|
|
220
|
+
if (provider.messagesEngine) {
|
|
221
221
|
provider.messagesEngine.getCachedModelInfo = (model) => provider.getCachedModelInfo(model);
|
|
222
|
+
// …and the same extra request fields and headers.
|
|
223
|
+
provider.messagesEngine.customConfig = cfg;
|
|
224
|
+
}
|
|
222
225
|
provider.customConfig = cfg;
|
|
223
226
|
provider._customKeyless = keyless;
|
|
224
227
|
provider._applyCustomRows(provider._customRows());
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* gemini-error-contract.mjs — Google RPC error details → the provider error
|
|
3
|
-
* contract shared by Gemini
|
|
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`
|
|
8
|
-
*
|
|
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
|
|
271
|
-
*
|
|
272
|
-
*
|
|
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;
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
import { geminiThinkingConfig } from './gemini-thinking.mjs';
|
|
12
12
|
import { geminiMaxOutputTokens } from './gemini-output-limit.mjs';
|
|
13
13
|
import { toGeminiContents, toGeminiRequestTools, toGeminiToolConfig } from './gemini-schema.mjs';
|
|
14
|
+
import { geminiIgnoresSamplingParams } from './gemini-model-redirect.mjs';
|
|
14
15
|
|
|
15
|
-
// Request pieces shared by the cached
|
|
16
|
+
// Request pieces shared by the cached and uncached REST bodies.
|
|
16
17
|
// Caller-supplied generation controls the wire carries in generationConfig.
|
|
17
18
|
// maxOutputTokens counts thought tokens too (see the thinking docs). Anything
|
|
18
19
|
// invalid is rejected here instead of being dropped. (safetySettings is a
|
|
19
20
|
// request-level field, forwarded separately.)
|
|
20
|
-
function geminiGenerationControls(opts, useModel, outputLimit) {
|
|
21
|
+
function geminiGenerationControls(opts, useModel, outputLimit, omitIgnoredSampling) {
|
|
21
22
|
const controls = {};
|
|
22
23
|
const maxOutputTokens = geminiMaxOutputTokens(useModel, opts, outputLimit);
|
|
23
24
|
if (maxOutputTokens !== undefined) controls.maxOutputTokens = maxOutputTokens;
|
|
@@ -26,20 +27,29 @@ function geminiGenerationControls(opts, useModel, outputLimit) {
|
|
|
26
27
|
if (!Number.isFinite(temperature) || temperature < 0 || temperature > 2) {
|
|
27
28
|
throw new TypeError('temperature must be a number between 0 and 2.');
|
|
28
29
|
}
|
|
29
|
-
controls.temperature = temperature;
|
|
30
|
+
if (!(omitIgnoredSampling && geminiIgnoresSamplingParams(useModel))) controls.temperature = temperature;
|
|
30
31
|
}
|
|
31
32
|
return controls;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
// `outputLimit` is the provider roster's declared output limit for the model.
|
|
35
|
-
|
|
36
|
+
// `omitIgnoredSampling` drops temperature for models the Gemini API documents
|
|
37
|
+
// as ignoring it (the Gemini API-key route; other routes keep their wire).
|
|
38
|
+
export function buildGeminiRequest(
|
|
39
|
+
messages,
|
|
40
|
+
useModel,
|
|
41
|
+
tools,
|
|
42
|
+
opts,
|
|
43
|
+
outputLimit = null,
|
|
44
|
+
{ omitIgnoredSampling = false } = {}
|
|
45
|
+
) {
|
|
36
46
|
// Gemini returns thought summaries only when the request asks for them.
|
|
37
47
|
// Without this the reasoning channel stays empty for the whole turn and
|
|
38
48
|
// the model's only visible output is the plain pre-tool text, so every
|
|
39
49
|
// round reads as another preamble. On by default for every model; an
|
|
40
50
|
// explicit opts.includeThoughts still wins.
|
|
41
51
|
const thinkingConfig = geminiThinkingConfig(useModel, opts, { includeThoughts: true });
|
|
42
|
-
const controls = geminiGenerationControls(opts, useModel, outputLimit);
|
|
52
|
+
const controls = geminiGenerationControls(opts, useModel, outputLimit, omitIgnoredSampling);
|
|
43
53
|
let generationConfig;
|
|
44
54
|
if (thinkingConfig || Object.keys(controls).length) {
|
|
45
55
|
generationConfig = { ...(thinkingConfig ? { thinkingConfig } : {}), ...controls };
|
|
@@ -66,6 +76,25 @@ export function buildGeminiRequest(messages, useModel, tools, opts, outputLimit
|
|
|
66
76
|
return { generationConfig, systemInstruction, contents, geminiTools, toolConfig, safetySettings };
|
|
67
77
|
}
|
|
68
78
|
|
|
79
|
+
// The generateContent body without a cached prefix: the whole request.
|
|
80
|
+
export function geminiUncachedRestBody({
|
|
81
|
+
contents,
|
|
82
|
+
systemInstruction,
|
|
83
|
+
geminiTools,
|
|
84
|
+
toolConfig,
|
|
85
|
+
generationConfig,
|
|
86
|
+
safetySettings,
|
|
87
|
+
}) {
|
|
88
|
+
return {
|
|
89
|
+
contents,
|
|
90
|
+
...(systemInstruction ? { systemInstruction: { role: 'system', parts: [{ text: systemInstruction }] } } : {}),
|
|
91
|
+
...(geminiTools ? { tools: geminiTools } : {}),
|
|
92
|
+
...(toolConfig ? { toolConfig } : {}),
|
|
93
|
+
...(generationConfig ? { generationConfig } : {}),
|
|
94
|
+
...(safetySettings ? { safetySettings } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
69
98
|
// The generateContent body for a cached prefix. The cache carries the
|
|
70
99
|
// recorded prefix; every uncached tail turn is sent, not just the last
|
|
71
100
|
// message, so reused cachedContents preserve full conversation context
|
|
@@ -104,6 +104,16 @@ export function normalizeGeminiUsage(um, opts, cachedContent) {
|
|
|
104
104
|
// subset). Alias the resolver's normalized total directly.
|
|
105
105
|
promptTokens: inputTokens,
|
|
106
106
|
};
|
|
107
|
+
// A long-decode turn bills every hop's prompt, but the context only holds
|
|
108
|
+
// the first hop's prompt plus what was generated. The summed input stays the
|
|
109
|
+
// billing figure; this is the input the context gauge and compaction count.
|
|
110
|
+
const initialPromptTokens = Number(um.initialPromptTokenCount);
|
|
111
|
+
if (initialPromptTokens > 0 && initialPromptTokens < inputTokens) {
|
|
112
|
+
resolvedUsage.contextInputTokens = initialPromptTokens;
|
|
113
|
+
// The cached reads of the billed hops repeat the same way; the context
|
|
114
|
+
// holds only the first hop's.
|
|
115
|
+
resolvedUsage.contextCachedTokens = Math.min(Number(um.initialCachedContentTokenCount) || 0, initialPromptTokens);
|
|
116
|
+
}
|
|
107
117
|
return { resolvedUsage, cache };
|
|
108
118
|
}
|
|
109
119
|
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
* FunctionDeclarationSchema, tool/tool-config mapping, message → content
|
|
4
4
|
* mapping, tool-call parsing/emission, and grounding-source collection.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
// The Gemini Schema `type` values, as the v1beta wire spells them.
|
|
7
|
+
const SchemaType = Object.freeze({
|
|
8
|
+
STRING: 'string',
|
|
9
|
+
NUMBER: 'number',
|
|
10
|
+
INTEGER: 'integer',
|
|
11
|
+
BOOLEAN: 'boolean',
|
|
12
|
+
ARRAY: 'array',
|
|
13
|
+
OBJECT: 'object',
|
|
14
|
+
});
|
|
7
15
|
import { traceHash, stableTraceStringify } from './trace-utils.mjs';
|
|
8
16
|
import {
|
|
9
17
|
normalizeContentForGeminiParts,
|
|
@@ -89,7 +97,6 @@ function splitGeminiToolContent(content) {
|
|
|
89
97
|
|
|
90
98
|
/**
|
|
91
99
|
* Convert JSON Schema type string to Gemini SchemaType.
|
|
92
|
-
* Gemini SDK uses its own enum instead of plain strings.
|
|
93
100
|
*/
|
|
94
101
|
function toSchemaType(t) {
|
|
95
102
|
const map = {
|
|
@@ -1107,10 +1114,8 @@ export function parseGeminiTextPartMetadata(parts) {
|
|
|
1107
1114
|
export function parseToolCalls(parts) {
|
|
1108
1115
|
const calls = parts.filter((p) => 'functionCall' in p && !!p.functionCall);
|
|
1109
1116
|
if (!calls.length) return undefined;
|
|
1110
|
-
//
|
|
1111
|
-
//
|
|
1112
|
-
// however, retains whatever the wire response carried, which means the
|
|
1113
|
-
// signature may sit under any of:
|
|
1117
|
+
// A FunctionCall part retains whatever the wire response carried, which
|
|
1118
|
+
// means the signature may sit under any of:
|
|
1114
1119
|
// • part.functionCall.thoughtSignature (camelCase, expected)
|
|
1115
1120
|
// • part.functionCall.thought_signature (snake_case, raw protobuf)
|
|
1116
1121
|
// • part.thoughtSignature / part.thought_signature (sibling on Part)
|
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* arrive, and the text-leak guard both transports build from the same turn
|
|
6
|
-
* inputs. Frame consumption itself stays in gemini-stream.mjs.
|
|
2
|
+
* The text-leak guard every Gemini-shaped REST transport builds from the same
|
|
3
|
+
* turn inputs. (The module name predates the removal of the legacy SDK; the
|
|
4
|
+
* Vertex and OpenCode Go engines import the guard from here.)
|
|
7
5
|
*/
|
|
8
|
-
import {
|
|
9
|
-
GEMINI_FIRST_BYTE_TIMEOUT_MS,
|
|
10
|
-
geminiTimeoutError,
|
|
11
|
-
createGeminiTextLeakGuard,
|
|
12
|
-
consumeGeminiSdkStream,
|
|
13
|
-
normalizeGeminiSdkError,
|
|
14
|
-
} from './gemini-stream.mjs';
|
|
15
|
-
import { geminiFailureUsage } from './gemini-response.mjs';
|
|
6
|
+
import { createGeminiTextLeakGuard } from './gemini-stream.mjs';
|
|
16
7
|
|
|
17
8
|
export function geminiTextLeakGuardFor({ tools, callbacks }) {
|
|
18
9
|
return createGeminiTextLeakGuard({
|
|
@@ -23,90 +14,3 @@ export function geminiTextLeakGuardFor({ tools, callbacks }) {
|
|
|
23
14
|
deferToolCalls: true,
|
|
24
15
|
});
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
// Mirrors the REST branch's signal lifetime: the request controller stays
|
|
28
|
-
// linked to the parent (attemptSignal) for the FULL stream — connect AND
|
|
29
|
-
// body — so a parent / client / gateway abort after first byte still
|
|
30
|
-
// cancels the underlying SDK request (the SSE idle watchdog is off by
|
|
31
|
-
// default). The first-byte timer only bounds the connect phase and is
|
|
32
|
-
// cleared once the stream starts, so it can never kill a live,
|
|
33
|
-
// still-producing stream.
|
|
34
|
-
function linkSdkRequestController(attemptSignal) {
|
|
35
|
-
const controller = new AbortController();
|
|
36
|
-
let parentAbortListener = null;
|
|
37
|
-
let firstByteTimer = null;
|
|
38
|
-
const detachParent = () => {
|
|
39
|
-
if (parentAbortListener && attemptSignal) {
|
|
40
|
-
try {
|
|
41
|
-
attemptSignal.removeEventListener('abort', parentAbortListener);
|
|
42
|
-
} catch {}
|
|
43
|
-
parentAbortListener = null;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const clearConnectTimer = () => {
|
|
47
|
-
if (firstByteTimer) {
|
|
48
|
-
clearTimeout(firstByteTimer);
|
|
49
|
-
firstByteTimer = null;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
if (attemptSignal) {
|
|
53
|
-
if (attemptSignal.aborted) {
|
|
54
|
-
try {
|
|
55
|
-
controller.abort(attemptSignal.reason);
|
|
56
|
-
} catch {}
|
|
57
|
-
} else {
|
|
58
|
-
parentAbortListener = () => {
|
|
59
|
-
try {
|
|
60
|
-
controller.abort(attemptSignal.reason);
|
|
61
|
-
} catch {}
|
|
62
|
-
};
|
|
63
|
-
attemptSignal.addEventListener('abort', parentAbortListener, { once: true });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
firstByteTimer = setTimeout(() => {
|
|
67
|
-
try {
|
|
68
|
-
controller.abort(geminiTimeoutError('Gemini SDK first byte', GEMINI_FIRST_BYTE_TIMEOUT_MS));
|
|
69
|
-
} catch {}
|
|
70
|
-
}, GEMINI_FIRST_BYTE_TIMEOUT_MS);
|
|
71
|
-
if (firstByteTimer.unref) firstByteTimer.unref();
|
|
72
|
-
return { controller, detachParent, clearConnectTimer };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function streamGeminiSdkAttempt(genModel, stream, attemptSignal, onConnected = null) {
|
|
76
|
-
const { contents, callbacks } = stream;
|
|
77
|
-
const link = linkSdkRequestController(attemptSignal);
|
|
78
|
-
const { controller } = link;
|
|
79
|
-
try {
|
|
80
|
-
let streamResult;
|
|
81
|
-
try {
|
|
82
|
-
streamResult = await genModel.generateContentStream({ contents }, { signal: controller.signal });
|
|
83
|
-
} catch (err) {
|
|
84
|
-
if (controller.signal.aborted) {
|
|
85
|
-
throw controller.signal.reason instanceof Error ? controller.signal.reason : err;
|
|
86
|
-
}
|
|
87
|
-
throw normalizeGeminiSdkError(err, 'Gemini SDK streamGenerateContent');
|
|
88
|
-
}
|
|
89
|
-
// First byte / headers received: drop the connect-phase timer but KEEP
|
|
90
|
-
// the parent link attached so a later abort during streaming still
|
|
91
|
-
// reaches the request.
|
|
92
|
-
link.clearConnectTimer();
|
|
93
|
-
onConnected?.();
|
|
94
|
-
const textLeakGuard = geminiTextLeakGuardFor(stream);
|
|
95
|
-
const response = await consumeGeminiSdkStream(streamResult, {
|
|
96
|
-
signal: attemptSignal,
|
|
97
|
-
onStreamDelta: callbacks.onStreamDelta,
|
|
98
|
-
onTextDelta: callbacks.onTextDelta,
|
|
99
|
-
onReasoningDelta: callbacks.onReasoningDelta,
|
|
100
|
-
textLeakGuard,
|
|
101
|
-
label: 'Gemini SDK streamGenerateContent',
|
|
102
|
-
failureUsage: geminiFailureUsage(stream.opts, stream.cachedContent, stream.useModel),
|
|
103
|
-
cancelGeneration: (reason) => {
|
|
104
|
-
if (!controller.signal.aborted) controller.abort(reason);
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
return { response, textLeakGuard };
|
|
108
|
-
} finally {
|
|
109
|
-
link.clearConnectTimer();
|
|
110
|
-
link.detachParent();
|
|
111
|
-
}
|
|
112
|
-
}
|