@armadra/agent 0.3.0 → 0.5.0
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/CHANGELOG.md +257 -0
- package/README.md +263 -95
- package/THIRD_PARTY_NOTICES.md +34 -0
- package/dist/acp.d.ts +18 -0
- package/dist/acp.js +19 -0
- package/dist/agent/limits.d.ts +38 -0
- package/dist/agent/limits.js +127 -0
- package/dist/agent/loop-guard.d.ts +38 -0
- package/dist/agent/loop-guard.js +95 -0
- package/dist/agent/loop.d.ts +4 -0
- package/dist/agent/loop.js +7 -0
- package/dist/agent/prompt-rules.d.ts +12 -0
- package/dist/agent/prompt-rules.js +18 -0
- package/dist/agent/reminders.d.ts +59 -0
- package/dist/agent/reminders.js +327 -0
- package/dist/agent/retry.d.ts +1 -1
- package/dist/agent/retry.js +2 -1
- package/dist/agent/session-cache.d.ts +5 -0
- package/dist/agent/session-cache.js +18 -2
- package/dist/agent/session-classifier.d.ts +18 -0
- package/dist/agent/session-classifier.js +105 -0
- package/dist/agent/session-compaction.d.ts +35 -6
- package/dist/agent/session-compaction.js +157 -31
- package/dist/agent/session-core.d.ts +40 -1
- package/dist/agent/session-extensions.d.ts +61 -0
- package/dist/agent/session-extensions.js +129 -0
- package/dist/agent/session-images.d.ts +23 -0
- package/dist/agent/session-images.js +97 -0
- package/dist/agent/session-plan.d.ts +21 -0
- package/dist/agent/session-plan.js +524 -0
- package/dist/agent/session-rewind.d.ts +81 -0
- package/dist/agent/session-rewind.js +354 -0
- package/dist/agent/session-run.d.ts +28 -1
- package/dist/agent/session-run.js +157 -6
- package/dist/agent/session-settings.d.ts +49 -0
- package/dist/agent/session-settings.js +95 -0
- package/dist/agent/session-subagent.d.ts +36 -24
- package/dist/agent/session-subagent.js +259 -129
- package/dist/agent/session-sync.d.ts +10 -3
- package/dist/agent/session-sync.js +37 -8
- package/dist/agent/session-telemetry.d.ts +39 -0
- package/dist/agent/session-telemetry.js +231 -0
- package/dist/agent/session-tools.js +63 -3
- package/dist/agent/session.d.ts +33 -29
- package/dist/agent/session.js +91 -126
- package/dist/agent/subagent-registry.d.ts +91 -0
- package/dist/agent/subagent-registry.js +494 -0
- package/dist/agent/system-prompt.d.ts +6 -3
- package/dist/agent/system-prompt.js +7 -2
- package/dist/agent/tool-runner.d.ts +8 -1
- package/dist/agent/tool-runner.js +72 -6
- package/dist/agent/types-w5.d.ts +192 -0
- package/dist/agent/types-w5.js +10 -0
- package/dist/agent/types.d.ts +55 -4
- package/dist/agent/types.js +2 -0
- package/dist/agent/worktree.d.ts +36 -0
- package/dist/agent/worktree.js +86 -0
- package/dist/agents/builtin.d.ts +14 -0
- package/dist/agents/builtin.js +39 -0
- package/dist/agents/catalog.d.ts +43 -0
- package/dist/agents/catalog.js +82 -0
- package/dist/agents/discover.d.ts +35 -0
- package/dist/agents/discover.js +83 -0
- package/dist/agents/external.d.ts +82 -0
- package/dist/agents/external.js +326 -0
- package/dist/agents/parse.d.ts +18 -0
- package/dist/agents/parse.js +116 -0
- package/dist/agents/result.d.ts +32 -0
- package/dist/agents/result.js +67 -0
- package/dist/agents/task-control.d.ts +17 -0
- package/dist/agents/task-control.js +17 -0
- package/dist/agents/task-record.d.ts +78 -0
- package/dist/agents/task-record.js +141 -0
- package/dist/agents/types.d.ts +46 -0
- package/dist/agents/types.js +8 -0
- package/dist/ai/apis/anthropic-compat.d.ts +36 -0
- package/dist/ai/apis/anthropic-compat.js +92 -0
- package/dist/ai/apis/anthropic-messages.js +3 -2
- package/dist/ai/apis/anthropic-request.d.ts +7 -6
- package/dist/ai/apis/anthropic-request.js +10 -28
- package/dist/ai/apis/cache-params.d.ts +11 -2
- package/dist/ai/apis/cache-params.js +25 -6
- package/dist/ai/apis/google-generative-ai.js +3 -2
- package/dist/ai/apis/openai-compat.d.ts +4 -1
- package/dist/ai/apis/openai-compat.js +8 -1
- package/dist/ai/apis/openai-completions.js +3 -2
- package/dist/ai/apis/openai-responses.js +3 -2
- package/dist/ai/http.d.ts +28 -6
- package/dist/ai/http.js +41 -8
- package/dist/ai/image-limits.d.ts +45 -0
- package/dist/ai/image-limits.js +68 -0
- package/dist/ai/providers/builtin.d.ts +18 -6
- package/dist/ai/providers/builtin.js +135 -6
- package/dist/ai/providers/catalog-data.js +17 -13
- package/dist/ai/providers/catalog.d.ts +60 -7
- package/dist/ai/providers/catalog.js +197 -38
- package/dist/ai/providers/channels.d.ts +33 -3
- package/dist/ai/providers/channels.js +108 -7
- package/dist/ai/providers/enrich.d.ts +6 -3
- package/dist/ai/providers/enrich.js +19 -4
- package/dist/ai/providers/models-dev-cache.d.ts +28 -24
- package/dist/ai/providers/models-dev-cache.js +92 -78
- package/dist/ai/providers/models-dev-data.d.ts +7 -0
- package/dist/ai/providers/models-dev-data.js +32 -0
- package/dist/ai/providers/models-dev-snapshot.d.ts +50 -0
- package/dist/ai/providers/models-dev-snapshot.js +137 -0
- package/dist/ai/providers/models-dev.d.ts +51 -10
- package/dist/ai/providers/models-dev.js +132 -39
- package/dist/ai/providers/registry.d.ts +28 -11
- package/dist/ai/providers/registry.js +112 -65
- package/dist/ai/providers/suggest.d.ts +18 -0
- package/dist/ai/providers/suggest.js +72 -0
- package/dist/ai/sse.d.ts +6 -2
- package/dist/ai/sse.js +22 -2
- package/dist/ai/types.d.ts +37 -4
- package/dist/ai/types.js +5 -0
- package/dist/bundle/ama.cjs +41979 -21147
- package/dist/checkpoints/backend.d.ts +61 -0
- package/dist/checkpoints/backend.js +135 -0
- package/dist/checkpoints/blobs.d.ts +60 -0
- package/dist/checkpoints/blobs.js +203 -0
- package/dist/checkpoints/gc.d.ts +47 -0
- package/dist/checkpoints/gc.js +144 -0
- package/dist/checkpoints/git-head.d.ts +15 -0
- package/dist/checkpoints/git-head.js +89 -0
- package/dist/checkpoints/index.d.ts +17 -0
- package/dist/checkpoints/index.js +17 -0
- package/dist/checkpoints/replay.d.ts +48 -0
- package/dist/checkpoints/replay.js +154 -0
- package/dist/checkpoints/restore.d.ts +86 -0
- package/dist/checkpoints/restore.js +263 -0
- package/dist/checkpoints/settings.d.ts +14 -0
- package/dist/checkpoints/settings.js +23 -0
- package/dist/checkpoints/shadow-git.d.ts +108 -0
- package/dist/checkpoints/shadow-git.js +491 -0
- package/dist/checkpoints/shadow-restore.d.ts +25 -0
- package/dist/checkpoints/shadow-restore.js +128 -0
- package/dist/checkpoints/tracker.d.ts +64 -0
- package/dist/checkpoints/tracker.js +192 -0
- package/dist/checkpoints/types.d.ts +99 -0
- package/dist/checkpoints/types.js +12 -0
- package/dist/cli/args.d.ts +26 -7
- package/dist/cli/args.js +75 -82
- package/dist/cli/bootstrap.js +40 -4
- package/dist/cli/codemode-notice.d.ts +21 -0
- package/dist/cli/codemode-notice.js +56 -0
- package/dist/cli/compose-agents.d.ts +27 -0
- package/dist/cli/compose-agents.js +111 -0
- package/dist/cli/compose-extensions.d.ts +29 -0
- package/dist/cli/compose-extensions.js +44 -0
- package/dist/cli/compose-session.d.ts +8 -0
- package/dist/cli/compose-session.js +76 -2
- package/dist/cli/compose-store.d.ts +1 -1
- package/dist/cli/compose-store.js +3 -1
- package/dist/cli/compose.d.ts +17 -4
- package/dist/cli/compose.js +60 -14
- package/dist/cli/default-model.d.ts +38 -1
- package/dist/cli/default-model.js +96 -9
- package/dist/cli/deps.d.ts +42 -0
- package/dist/cli/exit-codes.d.ts +12 -0
- package/dist/cli/exit-codes.js +15 -0
- package/dist/cli/fake-visibility.d.ts +13 -0
- package/dist/cli/fake-visibility.js +26 -0
- package/dist/cli/from-prompt.d.ts +18 -0
- package/dist/cli/from-prompt.js +49 -0
- package/dist/cli/help-text.d.ts +4 -0
- package/dist/cli/help-text.js +102 -0
- package/dist/cli/main.d.ts +9 -2
- package/dist/cli/main.js +77 -3
- package/dist/cli/proxy.d.ts +51 -0
- package/dist/cli/proxy.js +135 -0
- package/dist/cli/startup-screen.d.ts +29 -0
- package/dist/cli/startup-screen.js +51 -2
- package/dist/cli/startup-steps.d.ts +1 -1
- package/dist/cli/startup-steps.js +21 -13
- package/dist/cli/subcommands/config.d.ts +22 -3
- package/dist/cli/subcommands/config.js +119 -21
- package/dist/cli/subcommands/context.js +4 -1
- package/dist/cli/subcommands/doctor.js +33 -1
- package/dist/cli/subcommands/init.js +2 -1
- package/dist/cli/subcommands/models-discover.d.ts +15 -9
- package/dist/cli/subcommands/models-discover.js +58 -52
- package/dist/cli/subcommands/models.d.ts +2 -0
- package/dist/cli/subcommands/models.js +33 -14
- package/dist/cli/subcommands/probe-runner.d.ts +96 -0
- package/dist/cli/subcommands/probe-runner.js +264 -0
- package/dist/cli/subcommands/providers-probe.d.ts +34 -0
- package/dist/cli/subcommands/providers-probe.js +87 -0
- package/dist/cli/subcommands/providers.d.ts +3 -2
- package/dist/cli/subcommands/providers.js +53 -51
- package/dist/cli/subcommands/sessions-export.d.ts +10 -0
- package/dist/cli/subcommands/sessions-export.js +59 -0
- package/dist/cli/subcommands/sessions-search.d.ts +13 -0
- package/dist/cli/subcommands/sessions-search.js +103 -0
- package/dist/cli/subcommands/sessions.d.ts +6 -3
- package/dist/cli/subcommands/sessions.js +58 -3
- package/dist/cli/subcommands/stats.d.ts +17 -0
- package/dist/cli/subcommands/stats.js +198 -0
- package/dist/cli/system-prompt-arg.d.ts +11 -0
- package/dist/cli/system-prompt-arg.js +34 -0
- package/dist/codemode/capability.d.ts +24 -7
- package/dist/codemode/capability.js +38 -10
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +24 -1
- package/dist/codemode/modes.d.ts +4 -11
- package/dist/codemode/modes.js +5 -27
- package/dist/codemode/tool.d.ts +18 -14
- package/dist/codemode/tool.js +76 -31
- package/dist/compaction/breaker.d.ts +25 -9
- package/dist/compaction/breaker.js +47 -17
- package/dist/compaction/estimate.d.ts +11 -3
- package/dist/compaction/estimate.js +64 -22
- package/dist/compaction/image-budget.d.ts +45 -0
- package/dist/compaction/image-budget.js +115 -0
- package/dist/compaction/post-compact.d.ts +38 -0
- package/dist/compaction/post-compact.js +152 -0
- package/dist/compaction/protect.d.ts +27 -0
- package/dist/compaction/protect.js +56 -0
- package/dist/compaction/prune-tier.d.ts +58 -12
- package/dist/compaction/prune-tier.js +120 -54
- package/dist/compaction/summarize-tier.d.ts +23 -4
- package/dist/compaction/summarize-tier.js +100 -29
- package/dist/config/checker.d.ts +28 -0
- package/dist/config/checker.js +97 -0
- package/dist/config/init.d.ts +6 -2
- package/dist/config/init.js +12 -5
- package/dist/config/json-schema.d.ts +1 -0
- package/dist/config/json-schema.js +98 -4
- package/dist/config/key-docs.d.ts +22 -0
- package/dist/config/key-docs.js +174 -0
- package/dist/config/merge.d.ts +12 -9
- package/dist/config/merge.js +102 -13
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +2 -0
- package/dist/config/schema-w5.d.ts +18 -0
- package/dist/config/schema-w5.js +109 -0
- package/dist/config/schema.d.ts +5 -9
- package/dist/config/schema.js +91 -118
- package/dist/config/types-w5.d.ts +118 -0
- package/dist/config/types-w5.js +20 -0
- package/dist/config/types.d.ts +84 -7
- package/dist/config/types.js +29 -1
- package/dist/drivers/acp/client.d.ts +57 -0
- package/dist/drivers/acp/client.js +160 -0
- package/dist/drivers/acp/driver.d.ts +31 -0
- package/dist/drivers/acp/driver.js +274 -0
- package/dist/drivers/acp/testing/fake-agent-main.d.ts +5 -0
- package/dist/drivers/acp/testing/fake-agent-main.js +7 -0
- package/dist/drivers/acp/testing/fake-agent.d.ts +27 -0
- package/dist/drivers/acp/testing/fake-agent.js +211 -0
- package/dist/drivers/acp/types.d.ts +285 -0
- package/dist/drivers/acp/types.js +36 -0
- package/dist/drivers/agents.d.ts +58 -0
- package/dist/drivers/agents.js +142 -0
- package/dist/drivers/base.d.ts +35 -0
- package/dist/drivers/base.js +59 -0
- package/dist/drivers/catalog.d.ts +46 -0
- package/dist/drivers/catalog.js +167 -0
- package/dist/drivers/env.d.ts +20 -0
- package/dist/drivers/env.js +46 -0
- package/dist/drivers/host-runners.d.ts +18 -0
- package/dist/drivers/host-runners.js +45 -0
- package/dist/drivers/jsonrpc.d.ts +58 -0
- package/dist/drivers/jsonrpc.js +180 -0
- package/dist/drivers/native/claude-normalize.d.ts +46 -0
- package/dist/drivers/native/claude-normalize.js +106 -0
- package/dist/drivers/native/claude-stream.d.ts +29 -0
- package/dist/drivers/native/claude-stream.js +456 -0
- package/dist/drivers/native/codex-app-server.d.ts +26 -0
- package/dist/drivers/native/codex-app-server.js +407 -0
- package/dist/drivers/native/codex-normalize.d.ts +38 -0
- package/dist/drivers/native/codex-normalize.js +124 -0
- package/dist/drivers/native/oneshot.d.ts +28 -0
- package/dist/drivers/native/oneshot.js +312 -0
- package/dist/drivers/permissions.d.ts +40 -0
- package/dist/drivers/permissions.js +92 -0
- package/dist/drivers/pids.d.ts +32 -0
- package/dist/drivers/pids.js +93 -0
- package/dist/drivers/pool.d.ts +28 -0
- package/dist/drivers/pool.js +96 -0
- package/dist/drivers/probe.d.ts +47 -0
- package/dist/drivers/probe.js +172 -0
- package/dist/drivers/process.d.ts +48 -0
- package/dist/drivers/process.js +100 -0
- package/dist/drivers/runner.d.ts +61 -0
- package/dist/drivers/runner.js +388 -0
- package/dist/drivers/store.d.ts +49 -0
- package/dist/drivers/store.js +91 -0
- package/dist/drivers/turn.d.ts +41 -0
- package/dist/drivers/turn.js +99 -0
- package/dist/drivers/types.d.ts +122 -0
- package/dist/drivers/types.js +11 -0
- package/dist/git/info.d.ts +75 -0
- package/dist/git/info.js +191 -0
- package/dist/hooks/protocol.js +6 -1
- package/dist/hooks/types.d.ts +10 -1
- package/dist/hooks/types.js +2 -0
- package/dist/host/api-impl.d.ts +7 -0
- package/dist/host/api-impl.js +15 -0
- package/dist/host/types.d.ts +24 -2
- package/dist/host/types.js +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/modes/acp/acp-events.d.ts +46 -0
- package/dist/modes/acp/acp-events.js +233 -0
- package/dist/modes/acp/acp-mode.d.ts +17 -0
- package/dist/modes/acp/acp-mode.js +47 -0
- package/dist/modes/acp/acp-server.d.ts +79 -0
- package/dist/modes/acp/acp-server.js +315 -0
- package/dist/modes/commands-core.d.ts +7 -1
- package/dist/modes/commands-core.js +61 -5
- package/dist/modes/image-input.d.ts +12 -4
- package/dist/modes/image-input.js +22 -5
- package/dist/modes/interactive/agent-panels.d.ts +14 -0
- package/dist/modes/interactive/agent-panels.js +103 -0
- package/dist/modes/interactive/agent-ui.d.ts +73 -0
- package/dist/modes/interactive/agent-ui.js +234 -0
- package/dist/modes/interactive/approval-dialog.d.ts +40 -7
- package/dist/modes/interactive/approval-dialog.js +192 -35
- package/dist/modes/interactive/approval-merge.d.ts +41 -0
- package/dist/modes/interactive/approval-merge.js +89 -0
- package/dist/modes/interactive/clipboard-paste.d.ts +18 -0
- package/dist/modes/interactive/clipboard-paste.js +28 -0
- package/dist/modes/interactive/commands.d.ts +20 -3
- package/dist/modes/interactive/commands.js +75 -16
- package/dist/modes/interactive/double-esc.d.ts +20 -0
- package/dist/modes/interactive/double-esc.js +34 -0
- package/dist/modes/interactive/event-notices.d.ts +32 -0
- package/dist/modes/interactive/event-notices.js +79 -0
- package/dist/modes/interactive/external-editor.d.ts +16 -0
- package/dist/modes/interactive/external-editor.js +39 -0
- package/dist/modes/interactive/interactive-mode.d.ts +16 -2
- package/dist/modes/interactive/interactive-mode.js +184 -202
- package/dist/modes/interactive/key-dispatch.d.ts +18 -2
- package/dist/modes/interactive/key-dispatch.js +53 -6
- package/dist/modes/interactive/line/line-mode.d.ts +3 -1
- package/dist/modes/interactive/line/line-mode.js +28 -9
- package/dist/modes/interactive/line/line-render.d.ts +6 -1
- package/dist/modes/interactive/line/line-render.js +66 -8
- package/dist/modes/interactive/message-view.d.ts +49 -10
- package/dist/modes/interactive/message-view.js +262 -46
- package/dist/modes/interactive/panels.d.ts +35 -0
- package/dist/modes/interactive/panels.js +157 -0
- package/dist/modes/interactive/pickers.d.ts +23 -2
- package/dist/modes/interactive/pickers.js +48 -15
- package/dist/modes/interactive/plan-command.d.ts +40 -0
- package/dist/modes/interactive/plan-command.js +129 -0
- package/dist/modes/interactive/plan-dialog.d.ts +98 -0
- package/dist/modes/interactive/plan-dialog.js +290 -0
- package/dist/modes/interactive/plan-flow.d.ts +34 -0
- package/dist/modes/interactive/plan-flow.js +98 -0
- package/dist/modes/interactive/rewind-command.d.ts +31 -0
- package/dist/modes/interactive/rewind-command.js +106 -0
- package/dist/modes/interactive/rewind-flow.d.ts +37 -0
- package/dist/modes/interactive/rewind-flow.js +151 -0
- package/dist/modes/interactive/rewind-list.d.ts +36 -0
- package/dist/modes/interactive/rewind-list.js +123 -0
- package/dist/modes/interactive/rewind-panel.d.ts +77 -0
- package/dist/modes/interactive/rewind-panel.js +309 -0
- package/dist/modes/interactive/rewind-text.d.ts +40 -0
- package/dist/modes/interactive/rewind-text.js +139 -0
- package/dist/modes/interactive/run-indicator.d.ts +51 -0
- package/dist/modes/interactive/run-indicator.js +189 -0
- package/dist/modes/interactive/session-events.d.ts +24 -0
- package/dist/modes/interactive/session-events.js +96 -0
- package/dist/modes/interactive/startup-header.d.ts +40 -0
- package/dist/modes/interactive/startup-header.js +169 -0
- package/dist/modes/interactive/status-area.d.ts +73 -0
- package/dist/modes/interactive/status-area.js +190 -0
- package/dist/modes/interactive/status-bar.d.ts +107 -16
- package/dist/modes/interactive/status-bar.js +306 -81
- package/dist/modes/interactive/status-line.d.ts +33 -0
- package/dist/modes/interactive/status-line.js +113 -0
- package/dist/modes/interactive/subagent-view.d.ts +56 -0
- package/dist/modes/interactive/subagent-view.js +154 -0
- package/dist/modes/interactive/tasks-report.d.ts +27 -0
- package/dist/modes/interactive/tasks-report.js +114 -0
- package/dist/modes/interactive/tool-summary.d.ts +46 -0
- package/dist/modes/interactive/tool-summary.js +218 -0
- package/dist/modes/interactive/tool-view.d.ts +58 -15
- package/dist/modes/interactive/tool-view.js +233 -145
- package/dist/modes/print/print-mode.d.ts +40 -4
- package/dist/modes/print/print-mode.js +161 -8
- package/dist/modes/rpc/commands.d.ts +9 -0
- package/dist/modes/rpc/commands.js +49 -0
- package/dist/modes/rpc/rpc-mode.js +7 -1
- package/dist/modes/session-report.d.ts +11 -0
- package/dist/modes/session-report.js +48 -1
- package/dist/permissions/auto-safe.d.ts +65 -0
- package/dist/permissions/auto-safe.js +547 -0
- package/dist/permissions/classifier.d.ts +68 -0
- package/dist/permissions/classifier.js +186 -0
- package/dist/permissions/dangerous.d.ts +5 -0
- package/dist/permissions/dangerous.js +1 -1
- package/dist/permissions/modes.d.ts +30 -0
- package/dist/permissions/modes.js +78 -0
- package/dist/permissions/pipeline.d.ts +72 -6
- package/dist/permissions/pipeline.js +306 -11
- package/dist/permissions/protected.d.ts +19 -0
- package/dist/permissions/protected.js +74 -0
- package/dist/permissions/readonly-bash.d.ts +30 -0
- package/dist/permissions/readonly-bash.js +118 -0
- package/dist/permissions/rules.js +3 -0
- package/dist/permissions/types.d.ts +92 -3
- package/dist/permissions/types.js +3 -0
- package/dist/plan/compose.d.ts +9 -0
- package/dist/plan/compose.js +19 -0
- package/dist/plan/controller.d.ts +71 -0
- package/dist/plan/controller.js +27 -0
- package/dist/plan/done-markers.d.ts +17 -0
- package/dist/plan/done-markers.js +51 -0
- package/dist/plan/extract.d.ts +29 -0
- package/dist/plan/extract.js +160 -0
- package/dist/plan/prompts.d.ts +36 -0
- package/dist/plan/prompts.js +89 -0
- package/dist/plan/store.d.ts +37 -0
- package/dist/plan/store.js +90 -0
- package/dist/rpc.d.ts +58 -2
- package/dist/rpc.js +7 -0
- package/dist/sandbox/bash.d.ts +74 -0
- package/dist/sandbox/bash.js +126 -0
- package/dist/sandbox/detect.d.ts +48 -0
- package/dist/sandbox/detect.js +149 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/profile.d.ts +33 -0
- package/dist/sandbox/profile.js +76 -0
- package/dist/sandbox/wrap.d.ts +29 -0
- package/dist/sandbox/wrap.js +117 -0
- package/dist/sdk.d.ts +42 -5
- package/dist/sdk.js +34 -4
- package/dist/session/export.d.ts +32 -0
- package/dist/session/export.js +187 -0
- package/dist/session/redact.d.ts +15 -0
- package/dist/session/redact.js +55 -0
- package/dist/session/reuse.d.ts +33 -0
- package/dist/session/reuse.js +86 -0
- package/dist/session/scan.d.ts +34 -0
- package/dist/session/scan.js +140 -0
- package/dist/session/search.d.ts +52 -0
- package/dist/session/search.js +211 -0
- package/dist/session/stats-aggregate.d.ts +63 -0
- package/dist/session/stats-aggregate.js +163 -0
- package/dist/session/stats-index.d.ts +26 -0
- package/dist/session/stats-index.js +91 -0
- package/dist/session/stats-scan.d.ts +54 -0
- package/dist/session/stats-scan.js +236 -0
- package/dist/session/types.d.ts +3 -1
- package/dist/session/types.js +1 -0
- package/dist/skills/builtin.d.ts +31 -0
- package/dist/skills/builtin.js +109 -0
- package/dist/skills/discover.d.ts +2 -1
- package/dist/skills/index-prompt.js +5 -8
- package/dist/tools/background-jobs.d.ts +71 -0
- package/dist/tools/background-jobs.js +198 -0
- package/dist/tools/bash.d.ts +53 -1
- package/dist/tools/bash.js +158 -7
- package/dist/tools/clipboard-image.d.ts +44 -0
- package/dist/tools/clipboard-image.js +148 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.js +18 -3
- package/dist/tools/image-file.d.ts +38 -3
- package/dist/tools/image-file.js +81 -10
- package/dist/tools/image-resize.d.ts +58 -0
- package/dist/tools/image-resize.js +97 -0
- package/dist/tools/presets.d.ts +40 -8
- package/dist/tools/presets.js +65 -19
- package/dist/tools/read.d.ts +5 -2
- package/dist/tools/read.js +13 -10
- package/dist/tools/registry.d.ts +7 -1
- package/dist/tools/registry.js +27 -4
- package/dist/tools/task-ctl.d.ts +22 -0
- package/dist/tools/task-ctl.js +116 -0
- package/dist/tools/task.d.ts +22 -10
- package/dist/tools/task.js +66 -26
- package/dist/tools/todo.d.ts +22 -2
- package/dist/tools/todo.js +58 -14
- package/dist/tools/truncate.d.ts +15 -0
- package/dist/tools/truncate.js +25 -0
- package/dist/tools/types.d.ts +113 -0
- package/dist/tools/types.js +5 -0
- package/dist/tools/write.js +3 -0
- package/dist/tui/component.d.ts +8 -2
- package/dist/tui/component.js +3 -1
- package/dist/tui/components/box.d.ts +6 -1
- package/dist/tui/components/box.js +16 -6
- package/dist/tui/components/card.d.ts +23 -0
- package/dist/tui/components/card.js +37 -0
- package/dist/tui/components/editor-history.d.ts +6 -0
- package/dist/tui/components/editor-history.js +45 -0
- package/dist/tui/components/editor-paste.d.ts +1 -1
- package/dist/tui/components/editor-paste.js +4 -4
- package/dist/tui/components/editor.d.ts +11 -5
- package/dist/tui/components/editor.js +52 -58
- package/dist/tui/components/key-value.d.ts +3 -0
- package/dist/tui/components/key-value.js +16 -6
- package/dist/tui/components/loader.d.ts +37 -7
- package/dist/tui/components/loader.js +84 -21
- package/dist/tui/components/markdown.d.ts +5 -1
- package/dist/tui/components/markdown.js +45 -21
- package/dist/tui/components/meter.d.ts +3 -3
- package/dist/tui/components/meter.js +13 -11
- package/dist/tui/components/select-list.d.ts +23 -1
- package/dist/tui/components/select-list.js +76 -13
- package/dist/tui/glyphs.d.ts +72 -0
- package/dist/tui/glyphs.js +118 -0
- package/dist/tui/keybindings.d.ts +5 -0
- package/dist/tui/keybindings.js +5 -0
- package/dist/tui/theme.d.ts +30 -6
- package/dist/tui/theme.js +103 -17
- package/dist/tui.d.ts +4 -2
- package/dist/tui.js +3 -1
- package/docs/acp.md +78 -0
- package/docs/agents.md +250 -0
- package/docs/codemode.md +28 -10
- package/docs/hooks.md +36 -32
- package/docs/permissions.md +212 -0
- package/docs/plan.md +107 -0
- package/docs/providers.md +261 -62
- package/docs/rewind-plan.md +181 -0
- package/docs/rpc.md +127 -40
- package/docs/sandbox.md +215 -0
- package/docs/session-format.md +43 -22
- package/docs/sessions.md +174 -0
- package/docs/tui-design.md +751 -0
- package/docs/tui.md +260 -64
- package/package.json +15 -2
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 任一出现过(含 0)即 `cacheReported: true`,之后的事件不会把它改回 false。
|
|
13
13
|
*/
|
|
14
14
|
import { AssistantEventStreamImpl } from "../event-stream.js";
|
|
15
|
-
import {
|
|
15
|
+
import { authHeaders, describeErrorJson, idleTimeoutOf, mergeHeaders, USER_AGENT, } from "../http.js";
|
|
16
16
|
import { readSseEvents } from "../sse.js";
|
|
17
17
|
import { postWithCacheFallback } from "./cache-params.js";
|
|
18
18
|
import { ANTHROPIC_VERSION, anthropicMessagesUrl, buildAnthropicRequest, detectAnthropicCompat, } from "./anthropic-request.js";
|
|
@@ -168,11 +168,12 @@ async function run(stream, model, context, options) {
|
|
|
168
168
|
body,
|
|
169
169
|
signal: options.signal,
|
|
170
170
|
timeoutMs: options.timeoutMs,
|
|
171
|
+
idleTimeoutMs: idleTimeoutOf(options),
|
|
171
172
|
onResponse: options.onResponse,
|
|
172
173
|
});
|
|
173
174
|
stream.push({ type: "start", partial: tracker.output });
|
|
174
175
|
const state = { blocks: new Map(), stop: undefined, sawMessageStop: false };
|
|
175
|
-
for await (const sse of readSseEvents(response.body, options.signal)) {
|
|
176
|
+
for await (const sse of readSseEvents(response.body, options.signal, idleTimeoutOf(options))) {
|
|
176
177
|
if (sse.event === "ping" || sse.data === "")
|
|
177
178
|
continue;
|
|
178
179
|
let data;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* anthropic-messages 请求体(设计 §3.1、§3.3、§3.6):消息转换、三断点缓存、thinking、工具。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* compat 按主机推断见 anthropic-compat.ts([W5-M2])。
|
|
5
|
+
*
|
|
6
|
+
* 缓存断点(`sendCacheControl` 关时不打;cacheRetention 缺省 short,未指定时读 `AMA_CACHE_RETENTION`;none 不打;long 加
|
|
5
7
|
* `ttl: "1h"`,仅 `supportsLongCacheRetention`——官方端点缺省开,中转缺省关、降为 short;最后做 TTL
|
|
6
8
|
* 顺序校验,5m 之后出现 1h 则全部降为 5m)按优先级取前
|
|
7
9
|
* `maxCacheBreakpoints` 个:① 最后一条 user 消息(含工具结果)的最后一个块 ② system 末块
|
|
8
10
|
* ③ 最后一个工具定义(`supportsCacheControlOnTools`)。
|
|
9
11
|
*
|
|
10
12
|
* thinking:`adaptiveThinking` 模型发 `{type:"adaptive"}` + `output_config.effort`;
|
|
11
|
-
* 其余推理模型按预算发 `{type:"enabled", budget_tokens}`,预算计入 max_tokens
|
|
13
|
+
* 其余推理模型按预算发 `{type:"enabled", budget_tokens}`,预算计入 max_tokens(有工具时带交错思考 beta 头,
|
|
14
|
+
* `sendInterleavedThinkingBeta` 关时不带);off 发
|
|
12
15
|
* `{type:"disabled"}`(映射表 off 为 null 的模型不发)。思考开启时不发 temperature,
|
|
13
16
|
* 除非 `supportsTemperatureWithThinking`。`toolChoice: "none"`(有工具时)→ `tool_choice:{type:"none"}`。
|
|
14
17
|
*/
|
|
15
|
-
import type {
|
|
18
|
+
import type { AssistantMessage, Model, ModelThinkingLevel, StreamOptions, ToolResultMessage, TranscriptContext, UserMessage } from "../types.js";
|
|
16
19
|
export declare const ANTHROPIC_VERSION = "2023-06-01";
|
|
17
20
|
export declare const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
18
|
-
export
|
|
19
|
-
export declare function detectAnthropicCompat(model: Model, provider?: ProviderData): AnthropicMessagesCompat;
|
|
21
|
+
export { DEFAULT_ANTHROPIC_COMPAT, detectAnthropicCompat } from "./anthropic-compat.js";
|
|
20
22
|
type Json = Record<string, unknown>;
|
|
21
23
|
export interface AnthropicRequest {
|
|
22
24
|
body: Json;
|
|
@@ -39,4 +41,3 @@ export declare function anthropicMessagesUrl(baseUrl: string): string;
|
|
|
39
41
|
export declare function normalizeToolId(id: string): string;
|
|
40
42
|
export declare function convertMessages(messages: readonly (UserMessage | AssistantMessage | ToolResultMessage)[]): Json[];
|
|
41
43
|
export declare function buildAnthropicRequest(model: Model, context: TranscriptContext, options: StreamOptions): AnthropicRequest;
|
|
42
|
-
export {};
|
|
@@ -1,46 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* anthropic-messages 请求体(设计 §3.1、§3.3、§3.6):消息转换、三断点缓存、thinking、工具。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* compat 按主机推断见 anthropic-compat.ts([W5-M2])。
|
|
5
|
+
*
|
|
6
|
+
* 缓存断点(`sendCacheControl` 关时不打;cacheRetention 缺省 short,未指定时读 `AMA_CACHE_RETENTION`;none 不打;long 加
|
|
5
7
|
* `ttl: "1h"`,仅 `supportsLongCacheRetention`——官方端点缺省开,中转缺省关、降为 short;最后做 TTL
|
|
6
8
|
* 顺序校验,5m 之后出现 1h 则全部降为 5m)按优先级取前
|
|
7
9
|
* `maxCacheBreakpoints` 个:① 最后一条 user 消息(含工具结果)的最后一个块 ② system 末块
|
|
8
10
|
* ③ 最后一个工具定义(`supportsCacheControlOnTools`)。
|
|
9
11
|
*
|
|
10
12
|
* thinking:`adaptiveThinking` 模型发 `{type:"adaptive"}` + `output_config.effort`;
|
|
11
|
-
* 其余推理模型按预算发 `{type:"enabled", budget_tokens}`,预算计入 max_tokens
|
|
13
|
+
* 其余推理模型按预算发 `{type:"enabled", budget_tokens}`,预算计入 max_tokens(有工具时带交错思考 beta 头,
|
|
14
|
+
* `sendInterleavedThinkingBeta` 关时不带);off 发
|
|
12
15
|
* `{type:"disabled"}`(映射表 off 为 null 的模型不发)。思考开启时不发 temperature,
|
|
13
16
|
* 除非 `supportsTemperatureWithThinking`。`toolChoice: "none"`(有工具时)→ `tool_choice:{type:"none"}`。
|
|
14
17
|
*/
|
|
15
18
|
import { contentText, normalizeContext, sanitizeText } from "../context.js";
|
|
16
19
|
import { budgetedMaxTokens, clampThinkingLevel, mappedThinkingValue, thinkingBudget, } from "../thinking.js";
|
|
20
|
+
import { detectAnthropicCompat } from "./anthropic-compat.js";
|
|
17
21
|
import { effectiveRetention, resolveCacheRetention, resolvePromptCacheCompat, } from "./cache-params.js";
|
|
18
22
|
export const ANTHROPIC_VERSION = "2023-06-01";
|
|
19
23
|
export const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
20
|
-
|
|
21
|
-
"supportsCacheControlOnTools",
|
|
22
|
-
"supportsTemperatureWithThinking",
|
|
23
|
-
"adaptiveThinking",
|
|
24
|
-
"maxCacheBreakpoints",
|
|
25
|
-
];
|
|
26
|
-
export const DEFAULT_ANTHROPIC_COMPAT = {
|
|
27
|
-
supportsCacheControlOnTools: true,
|
|
28
|
-
supportsTemperatureWithThinking: false,
|
|
29
|
-
adaptiveThinking: false,
|
|
30
|
-
maxCacheBreakpoints: 4,
|
|
31
|
-
};
|
|
32
|
-
function pick(compat) {
|
|
33
|
-
const out = {};
|
|
34
|
-
for (const key of ANTHROPIC_COMPAT_KEYS) {
|
|
35
|
-
const value = compat?.[key];
|
|
36
|
-
if (value !== undefined)
|
|
37
|
-
out[key] = value;
|
|
38
|
-
}
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
export function detectAnthropicCompat(model, provider) {
|
|
42
|
-
return { ...DEFAULT_ANTHROPIC_COMPAT, ...pick(provider?.compat), ...pick(model.compat) };
|
|
43
|
-
}
|
|
24
|
+
export { DEFAULT_ANTHROPIC_COMPAT, detectAnthropicCompat } from "./anthropic-compat.js";
|
|
44
25
|
export function cacheControlFor(retention) {
|
|
45
26
|
if (retention === "none")
|
|
46
27
|
return undefined;
|
|
@@ -227,7 +208,7 @@ function applyThinking(body, model, compat, level, requestedMax, hasTools, betas
|
|
|
227
208
|
if (plan.budget < 1024)
|
|
228
209
|
return undefined; // 回答上限太小,放弃思考
|
|
229
210
|
body["thinking"] = { type: "enabled", budget_tokens: plan.budget, display: "summarized" };
|
|
230
|
-
if (hasTools)
|
|
211
|
+
if (hasTools && compat.sendInterleavedThinkingBeta !== false)
|
|
231
212
|
betas.push(INTERLEAVED_THINKING_BETA);
|
|
232
213
|
return String(plan.budget);
|
|
233
214
|
}
|
|
@@ -236,7 +217,8 @@ export function buildAnthropicRequest(model, context, options) {
|
|
|
236
217
|
const normalized = normalizeContext(context, { model });
|
|
237
218
|
const cacheCompat = resolvePromptCacheCompat(model, "anthropic-messages");
|
|
238
219
|
const retention = effectiveRetention(resolveCacheRetention(options.cacheRetention), cacheCompat);
|
|
239
|
-
|
|
220
|
+
// sendCacheControl:false(端点忽略 cache_control,如 DeepSeek):不打断点
|
|
221
|
+
const cacheControl = compat.sendCacheControl === false ? undefined : cacheControlFor(retention);
|
|
240
222
|
const messages = convertMessages(normalized.messages);
|
|
241
223
|
const level = clampThinkingLevel(model, options.thinkingLevel ?? "off");
|
|
242
224
|
const betas = [];
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* 协议层缓存参数(第三波 §1.3):缓存兼容开关的端点推断、保留层级解析、亲和头。
|
|
3
3
|
*
|
|
4
4
|
* 推断只看最终请求的主机名(不看 provider id:`OPENAI_BASE_URL` 把 openai 指到中转时按中转处理):
|
|
5
|
-
* - `sendPromptCacheKey`、`supportsLongCacheRetention
|
|
6
|
-
*
|
|
5
|
+
* - `sendPromptCacheKey`、`supportsLongCacheRetention`:按 `HOST_CACHE_CAPABILITIES`([W5-M2],官方
|
|
6
|
+
* 文档写明支持的主机才开;其余主机——含全部中转——缺省关)。`sendPromptCacheKey` 只对 OpenAI 两条线有意义;
|
|
7
7
|
* - `sendSessionAffinityHeaders`、`supportsExplicitPromptCacheMode`:缺省一律关(实测中转都接受
|
|
8
8
|
* 但未见命中提升,OpenRouter 未实测,见 docs/providers.md「缓存」);
|
|
9
9
|
* - `cacheReporting`:`auto`。
|
|
@@ -15,6 +15,15 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { type PostOptions } from "../http.js";
|
|
17
17
|
import type { Api, CacheRetention, Model, PromptCacheCompat } from "../types.js";
|
|
18
|
+
/**
|
|
19
|
+
* 按主机的缓存能力(精确主机名;docs/research/R1-models-protocols.md §2.1 的官方文档为据):
|
|
20
|
+
* - OpenAI:`prompt_cache_key` 路由 + `prompt_cache_retention: "24h"`;
|
|
21
|
+
* - Anthropic:`ttl: "1h"`;
|
|
22
|
+
* - xAI、Mistral、Kimi:官方推荐 `prompt_cache_key`(Kimi 的 `prompt_cache_options.ttl` 形状不同,不开);
|
|
23
|
+
* - 腾讯 TokenHub:Anthropic 线 `cache_control` 支持 `ttl: "1h"`,OpenAI 线自动缓存 + `prompt_cache_key`。
|
|
24
|
+
* 通义 Messages 只有 5m(不开长保留);Groq 的 Responses 不认 `prompt_cache_key`(不开)。
|
|
25
|
+
*/
|
|
26
|
+
export declare const HOST_CACHE_CAPABILITIES: Readonly<Record<string, Partial<Pick<PromptCacheCompat, "sendPromptCacheKey" | "supportsLongCacheRetention">>>>;
|
|
18
27
|
/** 请求实际发往的主机名(小写);baseUrl 不可解析时返回空串。 */
|
|
19
28
|
export declare function endpointHost(model: Pick<Model, "baseUrl">, api: Api): string;
|
|
20
29
|
/** 解析后的缓存兼容开关:端点推断 ← `model.compat`。 */
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* 协议层缓存参数(第三波 §1.3):缓存兼容开关的端点推断、保留层级解析、亲和头。
|
|
3
3
|
*
|
|
4
4
|
* 推断只看最终请求的主机名(不看 provider id:`OPENAI_BASE_URL` 把 openai 指到中转时按中转处理):
|
|
5
|
-
* - `sendPromptCacheKey`、`supportsLongCacheRetention
|
|
6
|
-
*
|
|
5
|
+
* - `sendPromptCacheKey`、`supportsLongCacheRetention`:按 `HOST_CACHE_CAPABILITIES`([W5-M2],官方
|
|
6
|
+
* 文档写明支持的主机才开;其余主机——含全部中转——缺省关)。`sendPromptCacheKey` 只对 OpenAI 两条线有意义;
|
|
7
7
|
* - `sendSessionAffinityHeaders`、`supportsExplicitPromptCacheMode`:缺省一律关(实测中转都接受
|
|
8
8
|
* 但未见命中提升,OpenRouter 未实测,见 docs/providers.md「缓存」);
|
|
9
9
|
* - `cacheReporting`:`auto`。
|
|
@@ -19,7 +19,23 @@ const DEFAULT_BASE_URLS = {
|
|
|
19
19
|
"openai-completions": "https://api.openai.com/v1",
|
|
20
20
|
"openai-responses": "https://api.openai.com/v1",
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* 按主机的缓存能力(精确主机名;docs/research/R1-models-protocols.md §2.1 的官方文档为据):
|
|
24
|
+
* - OpenAI:`prompt_cache_key` 路由 + `prompt_cache_retention: "24h"`;
|
|
25
|
+
* - Anthropic:`ttl: "1h"`;
|
|
26
|
+
* - xAI、Mistral、Kimi:官方推荐 `prompt_cache_key`(Kimi 的 `prompt_cache_options.ttl` 形状不同,不开);
|
|
27
|
+
* - 腾讯 TokenHub:Anthropic 线 `cache_control` 支持 `ttl: "1h"`,OpenAI 线自动缓存 + `prompt_cache_key`。
|
|
28
|
+
* 通义 Messages 只有 5m(不开长保留);Groq 的 Responses 不认 `prompt_cache_key`(不开)。
|
|
29
|
+
*/
|
|
30
|
+
export const HOST_CACHE_CAPABILITIES = {
|
|
31
|
+
"api.openai.com": { sendPromptCacheKey: true, supportsLongCacheRetention: true },
|
|
32
|
+
"api.anthropic.com": { supportsLongCacheRetention: true },
|
|
33
|
+
"api.x.ai": { sendPromptCacheKey: true },
|
|
34
|
+
"api.mistral.ai": { sendPromptCacheKey: true },
|
|
35
|
+
"api.moonshot.cn": { sendPromptCacheKey: true },
|
|
36
|
+
"api.moonshot.ai": { sendPromptCacheKey: true },
|
|
37
|
+
"tokenhub.tencentmaas.com": { sendPromptCacheKey: true, supportsLongCacheRetention: true },
|
|
38
|
+
};
|
|
23
39
|
const PROMPT_CACHE_KEYS = [
|
|
24
40
|
"sendPromptCacheKey",
|
|
25
41
|
"sendSessionAffinityHeaders",
|
|
@@ -39,11 +55,14 @@ export function endpointHost(model, api) {
|
|
|
39
55
|
}
|
|
40
56
|
/** 解析后的缓存兼容开关:端点推断 ← `model.compat`。 */
|
|
41
57
|
export function resolvePromptCacheCompat(model, api) {
|
|
42
|
-
const
|
|
58
|
+
const name = endpointHost(model, api);
|
|
59
|
+
const host = Object.hasOwn(HOST_CACHE_CAPABILITIES, name)
|
|
60
|
+
? HOST_CACHE_CAPABILITIES[name]
|
|
61
|
+
: undefined;
|
|
43
62
|
const out = {
|
|
44
|
-
sendPromptCacheKey:
|
|
63
|
+
sendPromptCacheKey: host?.sendPromptCacheKey === true && api !== "anthropic-messages",
|
|
45
64
|
sendSessionAffinityHeaders: false,
|
|
46
|
-
supportsLongCacheRetention:
|
|
65
|
+
supportsLongCacheRetention: host?.supportsLongCacheRetention === true,
|
|
47
66
|
supportsExplicitPromptCacheMode: false,
|
|
48
67
|
cacheReporting: "auto",
|
|
49
68
|
};
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* - 错误体 `{error:{code,status,message}}` 重排为 `429 RESOURCE_EXHAUSTED: …`。
|
|
17
17
|
*/
|
|
18
18
|
import { AssistantEventStreamImpl } from "../event-stream.js";
|
|
19
|
-
import {
|
|
19
|
+
import { authHeaders, HttpError, idleTimeoutOf, joinUrl, mergeHeaders, postJson, USER_AGENT, } from "../http.js";
|
|
20
20
|
import { readSseEvents } from "../sse.js";
|
|
21
21
|
import { GOOGLE_BASE_URL, buildGoogleRequest, detectGoogleCompat } from "./google-request.js";
|
|
22
22
|
import { BlockTracker, ProviderStopError, STREAM_ENDED_MESSAGE, createOutput, finishDone, finishError, requireApiKey, } from "./shared.js";
|
|
@@ -196,6 +196,7 @@ async function run(stream, model, context, options) {
|
|
|
196
196
|
body: replaced === undefined ? request.body : replaced,
|
|
197
197
|
signal: options.signal,
|
|
198
198
|
timeoutMs: options.timeoutMs,
|
|
199
|
+
idleTimeoutMs: idleTimeoutOf(options),
|
|
199
200
|
onResponse: options.onResponse,
|
|
200
201
|
});
|
|
201
202
|
}
|
|
@@ -209,7 +210,7 @@ async function run(stream, model, context, options) {
|
|
|
209
210
|
idSeed: Date.now().toString(36),
|
|
210
211
|
};
|
|
211
212
|
const body = response.body;
|
|
212
|
-
for await (const sse of readSseEvents(body, options.signal)) {
|
|
213
|
+
for await (const sse of readSseEvents(body, options.signal, idleTimeoutOf(options))) {
|
|
213
214
|
const data = sse.data.trim();
|
|
214
215
|
if (data === "" || data === "[DONE]")
|
|
215
216
|
continue;
|
|
@@ -19,7 +19,10 @@ interface InferenceRule {
|
|
|
19
19
|
baseUrl: string;
|
|
20
20
|
patch: (modelId: string) => Patch;
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* 推断表:内置里有 OpenAI 兼容线(Chat 渠道或单渠道回落)的各家(anthropic / google 不走本协议)。
|
|
24
|
+
* [W5-M2] 新增四家暂无已验证的差异,按保守缺省(空补丁)登记。
|
|
25
|
+
*/
|
|
23
26
|
export declare const INFERENCE_RULES: readonly InferenceRule[];
|
|
24
27
|
/** 命中的推断规则(先 provider id,后 baseUrl 子串)。 */
|
|
25
28
|
export declare function findInferenceRule(providerId: string, baseUrl: string): InferenceRule | undefined;
|
|
@@ -39,7 +39,10 @@ export const CONSERVATIVE_COMPAT = {
|
|
|
39
39
|
supportsStrictTools: false,
|
|
40
40
|
supportsStore: false,
|
|
41
41
|
};
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* 推断表:内置里有 OpenAI 兼容线(Chat 渠道或单渠道回落)的各家(anthropic / google 不走本协议)。
|
|
44
|
+
* [W5-M2] 新增四家暂无已验证的差异,按保守缺省(空补丁)登记。
|
|
45
|
+
*/
|
|
43
46
|
export const INFERENCE_RULES = [
|
|
44
47
|
{
|
|
45
48
|
provider: "openai",
|
|
@@ -102,6 +105,10 @@ export const INFERENCE_RULES = [
|
|
|
102
105
|
baseUrl: "mistral.ai",
|
|
103
106
|
patch: () => ({ thinkingFormat: "none", requiresToolResultName: true }),
|
|
104
107
|
},
|
|
108
|
+
{ provider: "minimax", baseUrl: "minimax", patch: () => ({}) },
|
|
109
|
+
{ provider: "stepfun", baseUrl: "stepfun", patch: () => ({}) },
|
|
110
|
+
{ provider: "volcengine", baseUrl: "volces.com", patch: () => ({}) },
|
|
111
|
+
{ provider: "tencent", baseUrl: "tencentmaas.com", patch: () => ({}) },
|
|
105
112
|
{ provider: "ollama", baseUrl: ":11434", patch: () => ({}) },
|
|
106
113
|
{ provider: "lmstudio", baseUrl: ":1234", patch: () => ({}) },
|
|
107
114
|
];
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* 内容推断。
|
|
15
15
|
*/
|
|
16
16
|
import { AssistantEventStreamImpl } from "../event-stream.js";
|
|
17
|
-
import {
|
|
17
|
+
import { authHeaders, describeErrorJson, idleTimeoutOf, joinUrl, mergeHeaders, USER_AGENT, } from "../http.js";
|
|
18
18
|
import { readSseEvents } from "../sse.js";
|
|
19
19
|
import { affinityHeaders, postWithCacheFallback, resolveCacheRetention } from "./cache-params.js";
|
|
20
20
|
import { detectCompat } from "./openai-compat.js";
|
|
@@ -190,6 +190,7 @@ async function run(stream, model, context, options) {
|
|
|
190
190
|
body: replaced === undefined ? request.body : replaced,
|
|
191
191
|
signal: options.signal,
|
|
192
192
|
timeoutMs: options.timeoutMs,
|
|
193
|
+
idleTimeoutMs: idleTimeoutOf(options),
|
|
193
194
|
onResponse: options.onResponse,
|
|
194
195
|
});
|
|
195
196
|
stream.push({ type: "start", partial: tracker.output });
|
|
@@ -203,7 +204,7 @@ async function run(stream, model, context, options) {
|
|
|
203
204
|
sawDone: false,
|
|
204
205
|
};
|
|
205
206
|
const body = response.body;
|
|
206
|
-
for await (const sse of readSseEvents(body, options.signal)) {
|
|
207
|
+
for await (const sse of readSseEvents(body, options.signal, idleTimeoutOf(options))) {
|
|
207
208
|
const data = sse.data.trim();
|
|
208
209
|
if (data === "")
|
|
209
210
|
continue;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* `cacheReported: true`。
|
|
16
16
|
*/
|
|
17
17
|
import { AssistantEventStreamImpl } from "../event-stream.js";
|
|
18
|
-
import {
|
|
18
|
+
import { authHeaders, describeErrorJson, idleTimeoutOf, joinUrl, mergeHeaders, USER_AGENT, } from "../http.js";
|
|
19
19
|
import { readSseEvents } from "../sse.js";
|
|
20
20
|
import { affinityHeaders, postWithCacheFallback, resolveCacheRetention } from "./cache-params.js";
|
|
21
21
|
import { buildResponsesRequest, detectResponsesCompat, encodeMessageSignature, } from "./openai-responses-request.js";
|
|
@@ -249,6 +249,7 @@ async function run(stream, model, context, options) {
|
|
|
249
249
|
body: replaced === undefined ? request.body : replaced,
|
|
250
250
|
signal: options.signal,
|
|
251
251
|
timeoutMs: options.timeoutMs,
|
|
252
|
+
idleTimeoutMs: idleTimeoutOf(options),
|
|
252
253
|
onResponse: options.onResponse,
|
|
253
254
|
});
|
|
254
255
|
stream.push({ type: "start", partial: tracker.output });
|
|
@@ -260,7 +261,7 @@ async function run(stream, model, context, options) {
|
|
|
260
261
|
};
|
|
261
262
|
let finished = false;
|
|
262
263
|
const body = response.body;
|
|
263
|
-
for await (const sse of readSseEvents(body, options.signal)) {
|
|
264
|
+
for await (const sse of readSseEvents(body, options.signal, idleTimeoutOf(options))) {
|
|
264
265
|
const raw = sse.data.trim();
|
|
265
266
|
if (raw === "" || raw === "[DONE]")
|
|
266
267
|
continue;
|
package/dist/ai/http.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* fetch 包装(设计 §1.2 ai/http.ts):超时、头合并(值为 null 删除)、错误体读取。
|
|
3
3
|
*
|
|
4
|
-
* 代理:Node 的全局 fetch 缺省不读 HTTP(S)_PROXY。
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 代理:Node 的全局 fetch 缺省不读 HTTP(S)_PROXY。CLI 启动时由 cli/proxy.ts 调 Node 内置的
|
|
5
|
+
* `http.setGlobalProxyFromEnv()`(等价于 `NODE_USE_ENV_PROXY=1`);SDK 嵌入方自行决定。
|
|
6
|
+
* 本模块不自行实现代理。
|
|
7
|
+
*
|
|
8
|
+
* 超时:`timeoutMs` 只管到拿到响应头为止;`idleTimeoutMs`(缺省 300 s,0 关闭)既管等响应头,
|
|
9
|
+
* 也管流式读取期间两次收到数据之间的间隔(每收到一块字节即重新计时,见 sse.ts)。空闲超时抛
|
|
10
|
+
* `IdleTimeoutError`,文案含 `idle timeout`,会话层按可重试错误处理。
|
|
7
11
|
*
|
|
8
12
|
* 协议层自身**不重试**(重试在会话层,§3.6)。
|
|
9
13
|
*/
|
|
@@ -29,6 +33,21 @@ export declare class HttpError extends Error {
|
|
|
29
33
|
export declare class RequestTimeoutError extends Error {
|
|
30
34
|
constructor(timeoutMs: number);
|
|
31
35
|
}
|
|
36
|
+
/** 流空闲超时缺省值:与 `request.idleTimeoutMs` / `AMA_IDLE_TIMEOUT_MS` 的缺省一致。 */
|
|
37
|
+
export declare const DEFAULT_IDLE_TIMEOUT_MS = 300000;
|
|
38
|
+
/** 请求选项里的空闲超时;未给出用缺省值,0 或负数表示关闭(返回 undefined)。 */
|
|
39
|
+
export declare function idleTimeoutOf(options: {
|
|
40
|
+
idleTimeoutMs?: number | undefined;
|
|
41
|
+
}): number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* 服务端在 `idleTimeoutMs` 内没有任何字节:`response` = 发出请求后迟迟没有响应头,
|
|
44
|
+
* `stream` = 流读到一半停住。文案含 `idle timeout`(重试分类据此判为可重试)。
|
|
45
|
+
*/
|
|
46
|
+
export declare class IdleTimeoutError extends Error {
|
|
47
|
+
readonly idleTimeoutMs: number;
|
|
48
|
+
readonly phase: "response" | "stream";
|
|
49
|
+
constructor(idleTimeoutMs: number, phase: "response" | "stream");
|
|
50
|
+
}
|
|
32
51
|
/**
|
|
33
52
|
* 从错误体提取文本:识别 `{error:{type,message,code}}`、`{error:"..."}`、`{message}`、
|
|
34
53
|
* `{detail}` 等常见形状;不是 JSON 则截断原文。结果形如 `429 rate_limit_error: ...`。
|
|
@@ -41,12 +60,15 @@ export interface PostOptions {
|
|
|
41
60
|
body: unknown;
|
|
42
61
|
signal: AbortSignal;
|
|
43
62
|
timeoutMs?: number | undefined;
|
|
63
|
+
/** 等响应头的空闲上限(`timeoutMs` 未给时生效);undefined 不限。 */
|
|
64
|
+
idleTimeoutMs?: number | undefined;
|
|
44
65
|
onResponse?: ((status: number, headers: Headers) => void) | undefined;
|
|
45
66
|
}
|
|
46
67
|
/**
|
|
47
|
-
* POST JSON 并返回 2xx 响应(body 是 SSE 字节流)。非 2xx → HttpError;超时 → RequestTimeoutError
|
|
48
|
-
*
|
|
49
|
-
*
|
|
68
|
+
* POST JSON 并返回 2xx 响应(body 是 SSE 字节流)。非 2xx → HttpError;超时 → RequestTimeoutError
|
|
69
|
+
* (`timeoutMs`)或 IdleTimeoutError(`idleTimeoutMs`);调用方的 signal 中止 → 原样抛 AbortError
|
|
70
|
+
* (调用方据 signal.aborted 判 aborted)。超时只覆盖到拿到响应头为止,流式读取期间的空闲由
|
|
71
|
+
* `readSseEvents` 的 `idleTimeoutMs` 控制。
|
|
50
72
|
*/
|
|
51
73
|
export declare function postJson(url: string, options: PostOptions): Promise<Response>;
|
|
52
74
|
/** undici 的 `fetch failed` 把真正原因藏在 cause 里;拼出来便于重试分类与排错。 */
|
package/dist/ai/http.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* fetch 包装(设计 §1.2 ai/http.ts):超时、头合并(值为 null 删除)、错误体读取。
|
|
3
3
|
*
|
|
4
|
-
* 代理:Node 的全局 fetch 缺省不读 HTTP(S)_PROXY。
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 代理:Node 的全局 fetch 缺省不读 HTTP(S)_PROXY。CLI 启动时由 cli/proxy.ts 调 Node 内置的
|
|
5
|
+
* `http.setGlobalProxyFromEnv()`(等价于 `NODE_USE_ENV_PROXY=1`);SDK 嵌入方自行决定。
|
|
6
|
+
* 本模块不自行实现代理。
|
|
7
|
+
*
|
|
8
|
+
* 超时:`timeoutMs` 只管到拿到响应头为止;`idleTimeoutMs`(缺省 300 s,0 关闭)既管等响应头,
|
|
9
|
+
* 也管流式读取期间两次收到数据之间的间隔(每收到一块字节即重新计时,见 sse.ts)。空闲超时抛
|
|
10
|
+
* `IdleTimeoutError`,文案含 `idle timeout`,会话层按可重试错误处理。
|
|
7
11
|
*
|
|
8
12
|
* 协议层自身**不重试**(重试在会话层,§3.6)。
|
|
9
13
|
*/
|
|
@@ -76,6 +80,33 @@ export class RequestTimeoutError extends Error {
|
|
|
76
80
|
this.name = "RequestTimeoutError";
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
/** 流空闲超时缺省值:与 `request.idleTimeoutMs` / `AMA_IDLE_TIMEOUT_MS` 的缺省一致。 */
|
|
84
|
+
export const DEFAULT_IDLE_TIMEOUT_MS = 300_000;
|
|
85
|
+
/** 请求选项里的空闲超时;未给出用缺省值,0 或负数表示关闭(返回 undefined)。 */
|
|
86
|
+
export function idleTimeoutOf(options) {
|
|
87
|
+
const value = options.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS;
|
|
88
|
+
return Number.isFinite(value) && value > 0 ? value : undefined;
|
|
89
|
+
}
|
|
90
|
+
function formatDuration(ms) {
|
|
91
|
+
return ms >= 1000 && ms % 1000 === 0 ? `${ms / 1000} s` : `${ms} ms`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 服务端在 `idleTimeoutMs` 内没有任何字节:`response` = 发出请求后迟迟没有响应头,
|
|
95
|
+
* `stream` = 流读到一半停住。文案含 `idle timeout`(重试分类据此判为可重试)。
|
|
96
|
+
*/
|
|
97
|
+
export class IdleTimeoutError extends Error {
|
|
98
|
+
idleTimeoutMs;
|
|
99
|
+
phase;
|
|
100
|
+
constructor(idleTimeoutMs, phase) {
|
|
101
|
+
const what = phase === "response"
|
|
102
|
+
? `No response from the server within ${formatDuration(idleTimeoutMs)}`
|
|
103
|
+
: `Stream stalled: no data from the server for ${formatDuration(idleTimeoutMs)}`;
|
|
104
|
+
super(`${what} (idle timeout; adjust with request.idleTimeoutMs or AMA_IDLE_TIMEOUT_MS)`);
|
|
105
|
+
this.name = "IdleTimeoutError";
|
|
106
|
+
this.idleTimeoutMs = idleTimeoutMs;
|
|
107
|
+
this.phase = phase;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
79
110
|
const MAX_ERROR_BODY = 4000;
|
|
80
111
|
/**
|
|
81
112
|
* 从错误体提取文本:识别 `{error:{type,message,code}}`、`{error:"..."}`、`{message}`、
|
|
@@ -141,12 +172,14 @@ function parseRetryAfter(headers) {
|
|
|
141
172
|
return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
|
|
142
173
|
}
|
|
143
174
|
/**
|
|
144
|
-
* POST JSON 并返回 2xx 响应(body 是 SSE 字节流)。非 2xx → HttpError;超时 → RequestTimeoutError
|
|
145
|
-
*
|
|
146
|
-
*
|
|
175
|
+
* POST JSON 并返回 2xx 响应(body 是 SSE 字节流)。非 2xx → HttpError;超时 → RequestTimeoutError
|
|
176
|
+
* (`timeoutMs`)或 IdleTimeoutError(`idleTimeoutMs`);调用方的 signal 中止 → 原样抛 AbortError
|
|
177
|
+
* (调用方据 signal.aborted 判 aborted)。超时只覆盖到拿到响应头为止,流式读取期间的空闲由
|
|
178
|
+
* `readSseEvents` 的 `idleTimeoutMs` 控制。
|
|
147
179
|
*/
|
|
148
180
|
export async function postJson(url, options) {
|
|
149
|
-
const
|
|
181
|
+
const explicit = options.timeoutMs !== undefined && options.timeoutMs > 0;
|
|
182
|
+
const timeout = explicit ? options.timeoutMs : options.idleTimeoutMs;
|
|
150
183
|
const timer = new AbortController();
|
|
151
184
|
const handle = timeout !== undefined && timeout > 0 ? setTimeout(() => timer.abort(), timeout) : undefined;
|
|
152
185
|
const signal = AbortSignal.any([options.signal, timer.signal]);
|
|
@@ -161,7 +194,7 @@ export async function postJson(url, options) {
|
|
|
161
194
|
}
|
|
162
195
|
catch (error) {
|
|
163
196
|
if (timer.signal.aborted && !options.signal.aborted && timeout !== undefined) {
|
|
164
|
-
throw new RequestTimeoutError(timeout);
|
|
197
|
+
throw explicit ? new RequestTimeoutError(timeout) : new IdleTimeoutError(timeout, "response");
|
|
165
198
|
}
|
|
166
199
|
throw normalizeNetworkError(error);
|
|
167
200
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片大小上限(docs/wave5-plan.md §4、D11;R1 §3.2)。[W5-I]
|
|
3
|
+
*
|
|
4
|
+
* 各家的上限都按 **base64 后**的字节数计算:`base64Bytes = ceil(bytes / 3) * 4`。
|
|
5
|
+
*
|
|
6
|
+
* | 端点 | 单图 | 单请求总量(按协议) |
|
|
7
|
+
* | -------------------------------------- | -------- | ------------------------------- |
|
|
8
|
+
* | 官方 Anthropic(api.anthropic.com) | 10 MB | anthropic-messages 32 MB |
|
|
9
|
+
* | 官方 Gemini(generativelanguage…) | 20 MB | google-generative-ai 20 MB |
|
|
10
|
+
* | 官方 OpenAI(api.openai.com) | 20 MB | 其它协议 20 MB |
|
|
11
|
+
* | 中转(内置供应商改了 baseUrl)/ 未知 | 5 MB | 同上,按协议 |
|
|
12
|
+
*
|
|
13
|
+
* 中转背后常是 Bedrock / Vertex(单图 5 MB),所以只认官方主机,其余一律按 5 MB。
|
|
14
|
+
* 尺寸:任一边 > 8000 px 拒绝;单请求超过 20 张图时每边 ≤ 2000 px(Anthropic)。
|
|
15
|
+
*/
|
|
16
|
+
import type { Api } from "./types.js";
|
|
17
|
+
export declare const MB: number;
|
|
18
|
+
/** 单图任一边上限(像素)。 */
|
|
19
|
+
export declare const MAX_IMAGE_EDGE = 8000;
|
|
20
|
+
/** 单请求图片数超过这个数时,每张图的边长上限收紧为 `MANY_IMAGES_EDGE`。 */
|
|
21
|
+
export declare const MANY_IMAGES_COUNT = 20;
|
|
22
|
+
export declare const MANY_IMAGES_EDGE = 2000;
|
|
23
|
+
/** 未知端点 / 中转的单图上限(base64 后)。 */
|
|
24
|
+
export declare const DEFAULT_IMAGE_BASE64_LIMIT: number;
|
|
25
|
+
export interface ImageLimits {
|
|
26
|
+
/** 单张图片 base64 后的上限(字节)。 */
|
|
27
|
+
perImageBase64: number;
|
|
28
|
+
/** 单次请求全部图片 base64 后的总量预算(字节)。 */
|
|
29
|
+
perRequestBase64: number;
|
|
30
|
+
}
|
|
31
|
+
export type ImageEndpoint = "anthropic" | "gemini" | "openai" | "other";
|
|
32
|
+
/** 判断端点只需要地址与协议。 */
|
|
33
|
+
export interface ImageModelInfo {
|
|
34
|
+
baseUrl?: string | undefined;
|
|
35
|
+
api: Api;
|
|
36
|
+
}
|
|
37
|
+
/** 原始字节数 → base64 后的字节数。 */
|
|
38
|
+
export declare function base64Size(bytes: number): number;
|
|
39
|
+
/** 按 baseUrl 的主机判断是不是官方端点;中转与未知主机都是 `other`。 */
|
|
40
|
+
export declare function imageEndpoint(model: Pick<ImageModelInfo, "baseUrl">): ImageEndpoint;
|
|
41
|
+
/** 单请求图片总量预算按协议:Anthropic 32 MB,其余(含 Gemini)20 MB。 */
|
|
42
|
+
export declare function requestImageBudget(api: Api): number;
|
|
43
|
+
export declare function imageLimits(model: ImageModelInfo, api?: Api): ImageLimits;
|
|
44
|
+
/** 文案用:`10 MB`、`3.8 MB`。 */
|
|
45
|
+
export declare function formatMb(bytes: number): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片大小上限(docs/wave5-plan.md §4、D11;R1 §3.2)。[W5-I]
|
|
3
|
+
*
|
|
4
|
+
* 各家的上限都按 **base64 后**的字节数计算:`base64Bytes = ceil(bytes / 3) * 4`。
|
|
5
|
+
*
|
|
6
|
+
* | 端点 | 单图 | 单请求总量(按协议) |
|
|
7
|
+
* | -------------------------------------- | -------- | ------------------------------- |
|
|
8
|
+
* | 官方 Anthropic(api.anthropic.com) | 10 MB | anthropic-messages 32 MB |
|
|
9
|
+
* | 官方 Gemini(generativelanguage…) | 20 MB | google-generative-ai 20 MB |
|
|
10
|
+
* | 官方 OpenAI(api.openai.com) | 20 MB | 其它协议 20 MB |
|
|
11
|
+
* | 中转(内置供应商改了 baseUrl)/ 未知 | 5 MB | 同上,按协议 |
|
|
12
|
+
*
|
|
13
|
+
* 中转背后常是 Bedrock / Vertex(单图 5 MB),所以只认官方主机,其余一律按 5 MB。
|
|
14
|
+
* 尺寸:任一边 > 8000 px 拒绝;单请求超过 20 张图时每边 ≤ 2000 px(Anthropic)。
|
|
15
|
+
*/
|
|
16
|
+
export const MB = 1024 * 1024;
|
|
17
|
+
/** 单图任一边上限(像素)。 */
|
|
18
|
+
export const MAX_IMAGE_EDGE = 8000;
|
|
19
|
+
/** 单请求图片数超过这个数时,每张图的边长上限收紧为 `MANY_IMAGES_EDGE`。 */
|
|
20
|
+
export const MANY_IMAGES_COUNT = 20;
|
|
21
|
+
export const MANY_IMAGES_EDGE = 2000;
|
|
22
|
+
/** 未知端点 / 中转的单图上限(base64 后)。 */
|
|
23
|
+
export const DEFAULT_IMAGE_BASE64_LIMIT = 5 * MB;
|
|
24
|
+
/** 原始字节数 → base64 后的字节数。 */
|
|
25
|
+
export function base64Size(bytes) {
|
|
26
|
+
return Math.ceil(bytes / 3) * 4;
|
|
27
|
+
}
|
|
28
|
+
const OFFICIAL_HOSTS = {
|
|
29
|
+
"api.anthropic.com": "anthropic",
|
|
30
|
+
"generativelanguage.googleapis.com": "gemini",
|
|
31
|
+
"api.openai.com": "openai",
|
|
32
|
+
};
|
|
33
|
+
const PER_IMAGE = {
|
|
34
|
+
anthropic: 10 * MB,
|
|
35
|
+
gemini: 20 * MB,
|
|
36
|
+
openai: 20 * MB,
|
|
37
|
+
other: DEFAULT_IMAGE_BASE64_LIMIT,
|
|
38
|
+
};
|
|
39
|
+
function hostOf(url) {
|
|
40
|
+
if (url === undefined)
|
|
41
|
+
return undefined;
|
|
42
|
+
try {
|
|
43
|
+
return new URL(url).hostname.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** 按 baseUrl 的主机判断是不是官方端点;中转与未知主机都是 `other`。 */
|
|
50
|
+
export function imageEndpoint(model) {
|
|
51
|
+
const host = hostOf(model.baseUrl);
|
|
52
|
+
return (host !== undefined ? OFFICIAL_HOSTS[host] : undefined) ?? "other";
|
|
53
|
+
}
|
|
54
|
+
/** 单请求图片总量预算按协议:Anthropic 32 MB,其余(含 Gemini)20 MB。 */
|
|
55
|
+
export function requestImageBudget(api) {
|
|
56
|
+
return api === "anthropic-messages" ? 32 * MB : 20 * MB;
|
|
57
|
+
}
|
|
58
|
+
export function imageLimits(model, api = model.api) {
|
|
59
|
+
return {
|
|
60
|
+
perImageBase64: PER_IMAGE[imageEndpoint(model)],
|
|
61
|
+
perRequestBase64: requestImageBudget(api),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** 文案用:`10 MB`、`3.8 MB`。 */
|
|
65
|
+
export function formatMb(bytes) {
|
|
66
|
+
const mb = bytes / MB;
|
|
67
|
+
return `${Number.isInteger(mb) ? mb : mb.toFixed(1)} MB`;
|
|
68
|
+
}
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 内置供应商(设计 §3.3、docs/wave5-plan.md §3.2)。这里只放供应商级数据;模型来自 catalog/*.json,
|
|
3
|
+
* compat 由各协议的 detectCompat 推断(openai-compat.ts、anthropic-compat.ts 的主机表),这里只写推断
|
|
4
|
+
* 不出来的东西。
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* 内置渠道([W5-M2]):一家同时开放多种协议时写 `channels`(首个不一定是缺省,看 `defaultChannel`)。
|
|
7
|
+
* registry 物化时与用户 config 的 `channels` 合并(同名字段级覆盖、新名追加),用户的 `defaultChannel`
|
|
8
|
+
* 优先。供应商级 `api` + `baseUrl` 是**单渠道回落**:用户(config / auth.json / `*_BASE_URL`)把
|
|
9
|
+
* baseUrl 改到别处时内置渠道整体作废,按这一对单渠道处理(与引入内置渠道之前的行为一致)。
|
|
10
|
+
* 只做按量计费端点;Coding Plan 类订阅端点不做内置渠道(D9),见 docs/providers.md。
|
|
7
11
|
*
|
|
8
12
|
* `baseUrlEnv`(第三波 §2.3):通行约定的 baseUrl 环境变量(OpenAI SDK 的 `OPENAI_BASE_URL`、
|
|
9
13
|
* Claude Code 的 `ANTHROPIC_BASE_URL`),设了就把内置供应商指向中转站,零配置可用;优先级低于
|
|
10
14
|
* config.json 与 auth.json 的 baseUrl。
|
|
11
15
|
*/
|
|
12
|
-
import type { ProviderData } from "../types.js";
|
|
16
|
+
import type { Api, ProviderData } from "../types.js";
|
|
13
17
|
export type BuiltinProvider = Omit<ProviderData, "models" | "builtin"> & {
|
|
14
18
|
baseUrlEnv?: string;
|
|
19
|
+
/**
|
|
20
|
+
* 单渠道回落时目录模型的协议(缺省同 `api`):OpenAI / xAI 的目录模型在中转上仍走 Responses,
|
|
21
|
+
* 目录外的 id(本地服务、中转自有模型)走 `api`(Chat)。
|
|
22
|
+
*/
|
|
23
|
+
catalogApi?: Api;
|
|
15
24
|
};
|
|
16
25
|
export declare const BUILTIN_PROVIDERS: readonly BuiltinProvider[];
|
|
26
|
+
/** 内置供应商的官方主机(单渠道回落 + 全部内置渠道)。 */
|
|
27
|
+
export declare function builtinHosts(providerId: string): Set<string>;
|
|
17
28
|
/**
|
|
18
29
|
* 内置供应商的 baseUrl 是否被改到了非官方主机(中转站):此时目录外的 model id 也接受,
|
|
19
|
-
* compat
|
|
30
|
+
* compat 走保守缺省。按渠道比较主机:落在任一内置渠道的主机上(如国际站)不算中转。
|
|
31
|
+
* 非内置供应商与本地服务返回 false。
|
|
20
32
|
*/
|
|
21
33
|
export declare function isRelayedBaseUrl(providerId: string, baseUrl: string): boolean;
|
|
22
34
|
/** 自定义供应商的兜底环境变量名:`AMA_API_KEY_<ID>`(非字母数字转下划线、大写)。 */
|