@armadra/agent 0.4.0 → 0.5.1
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 +184 -1
- package/README.md +202 -83
- 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/session-cache.d.ts +5 -0
- package/dist/agent/session-cache.js +17 -1
- package/dist/agent/session-classifier.d.ts +1 -1
- package/dist/agent/session-classifier.js +3 -1
- package/dist/agent/session-compaction.d.ts +35 -6
- package/dist/agent/session-compaction.js +157 -31
- package/dist/agent/session-core.d.ts +27 -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 +40 -1
- package/dist/agent/session.d.ts +30 -29
- package/dist/agent/session.js +79 -123
- 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 +57 -4
- package/dist/agent/types-w5.d.ts +192 -0
- package/dist/agent/types-w5.js +10 -0
- package/dist/agent/types.d.ts +47 -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-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/openai-compat.d.ts +4 -1
- package/dist/ai/apis/openai-compat.js +8 -1
- 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 +20 -10
- package/dist/ai/providers/registry.js +82 -43
- package/dist/ai/types.d.ts +28 -2
- package/dist/ai/types.js +5 -0
- package/dist/bundle/ama.cjs +37605 -21619
- 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 +8 -4
- package/dist/cli/args.js +17 -97
- package/dist/cli/bootstrap.js +13 -1
- package/dist/cli/choice-prompt.d.ts +58 -0
- package/dist/cli/choice-prompt.js +140 -0
- package/dist/cli/codemode-notice.d.ts +3 -2
- package/dist/cli/codemode-notice.js +3 -2
- 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 +3 -0
- package/dist/cli/compose-session.js +47 -4
- package/dist/cli/compose.d.ts +3 -0
- package/dist/cli/compose.js +33 -6
- package/dist/cli/deps.d.ts +6 -0
- package/dist/cli/exit-codes.d.ts +10 -0
- package/dist/cli/exit-codes.js +12 -0
- package/dist/cli/help-text.d.ts +4 -0
- package/dist/cli/help-text.js +102 -0
- package/dist/cli/startup-screen.js +5 -3
- package/dist/cli/startup-steps.js +7 -1
- package/dist/cli/subcommands/config.d.ts +4 -1
- package/dist/cli/subcommands/config.js +17 -6
- package/dist/cli/subcommands/doctor.js +21 -0
- package/dist/cli/subcommands/models-cache-probe.d.ts +1 -1
- package/dist/cli/subcommands/models-cache-probe.js +3 -12
- package/dist/cli/subcommands/models-discover.js +5 -6
- package/dist/cli/subcommands/models.d.ts +2 -0
- package/dist/cli/subcommands/models.js +33 -14
- package/dist/cli/subcommands/providers.d.ts +1 -1
- package/dist/cli/subcommands/providers.js +8 -15
- package/dist/cli/subcommands/sessions.d.ts +3 -1
- package/dist/cli/subcommands/sessions.js +36 -2
- 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/tool.d.ts +1 -1
- package/dist/codemode/tool.js +6 -4
- 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/json-schema.js +63 -2
- package/dist/config/key-docs.js +72 -3
- package/dist/config/merge.d.ts +5 -3
- package/dist/config/merge.js +81 -7
- 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 +68 -114
- package/dist/config/types-w5.d.ts +118 -0
- package/dist/config/types-w5.js +20 -0
- package/dist/config/types.d.ts +50 -1
- package/dist/config/types.js +12 -0
- 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 +13 -1
- package/dist/modes/commands-core.js +64 -0
- 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 +21 -4
- package/dist/modes/interactive/approval-dialog.js +98 -20
- 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 +12 -1
- package/dist/modes/interactive/commands.js +31 -1
- package/dist/modes/interactive/confirm-dialog.d.ts +49 -0
- package/dist/modes/interactive/confirm-dialog.js +121 -0
- 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 +14 -1
- package/dist/modes/interactive/interactive-mode.js +140 -136
- package/dist/modes/interactive/key-dispatch.d.ts +22 -2
- package/dist/modes/interactive/key-dispatch.js +66 -7
- package/dist/modes/interactive/line/line-mode.d.ts +4 -1
- package/dist/modes/interactive/line/line-mode.js +31 -5
- package/dist/modes/interactive/line/line-render.d.ts +2 -1
- package/dist/modes/interactive/line/line-render.js +40 -4
- package/dist/modes/interactive/message-view.d.ts +1 -1
- package/dist/modes/interactive/message-view.js +24 -2
- package/dist/modes/interactive/panels.d.ts +18 -1
- package/dist/modes/interactive/panels.js +19 -5
- 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/session-events.d.ts +24 -0
- package/dist/modes/interactive/session-events.js +96 -0
- package/dist/modes/interactive/startup-ui.js +5 -1
- 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 +99 -11
- package/dist/modes/interactive/status-bar.js +273 -90
- 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-view.d.ts +12 -2
- package/dist/modes/interactive/tool-view.js +34 -4
- package/dist/modes/print/print-mode.d.ts +13 -4
- package/dist/modes/print/print-mode.js +56 -12
- package/dist/modes/rpc/commands.d.ts +9 -0
- package/dist/modes/rpc/commands.js +44 -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 +5 -0
- package/dist/permissions/auto-safe.js +18 -0
- package/dist/permissions/bypass.d.ts +32 -0
- package/dist/permissions/bypass.js +36 -0
- package/dist/permissions/classifier.d.ts +4 -0
- package/dist/permissions/classifier.js +2 -0
- package/dist/permissions/modes.js +1 -1
- package/dist/permissions/pipeline.d.ts +43 -4
- package/dist/permissions/pipeline.js +114 -9
- package/dist/permissions/readonly-bash.d.ts +30 -0
- package/dist/permissions/readonly-bash.js +118 -0
- package/dist/permissions/types.d.ts +42 -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 +33 -2
- package/dist/sdk.js +24 -2
- 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 +7 -2
- package/dist/tools/presets.js +11 -4
- 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/glyphs.d.ts +4 -0
- package/dist/tui/glyphs.js +4 -0
- package/dist/tui/keybindings.d.ts +6 -1
- package/dist/tui/keybindings.js +6 -1
- package/docs/acp.md +78 -0
- package/docs/agents.md +250 -0
- package/docs/codemode.md +12 -8
- package/docs/hooks.md +26 -22
- package/docs/permissions.md +78 -13
- package/docs/plan.md +107 -0
- package/docs/providers.md +228 -52
- package/docs/rewind-plan.md +181 -0
- package/docs/rpc.md +92 -5
- package/docs/sandbox.md +215 -0
- package/docs/session-format.md +41 -21
- package/docs/sessions.md +41 -1
- package/docs/tui-design.md +751 -0
- package/docs/tui.md +179 -21
- package/package.json +13 -2
|
@@ -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
|
};
|
|
@@ -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
|
];
|
|
@@ -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>`(非字母数字转下划线、大写)。 */
|
|
@@ -1,14 +1,26 @@
|
|
|
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
|
*/
|
|
16
|
+
function ch(name, api, baseUrl, extra = {}) {
|
|
17
|
+
return { name, api, baseUrl, ...extra };
|
|
18
|
+
}
|
|
19
|
+
const CHAT = "openai-completions";
|
|
20
|
+
const MESSAGES = "anthropic-messages";
|
|
21
|
+
const RESPONSES = "openai-responses";
|
|
22
|
+
/** 文档写 `Authorization: Bearer` 的 Anthropic 兼容端点(Kimi、MiniMax、阶跃)。 */
|
|
23
|
+
const BEARER = { authHeader: "authorization-bearer" };
|
|
12
24
|
export const BUILTIN_PROVIDERS = [
|
|
13
25
|
{
|
|
14
26
|
id: "anthropic",
|
|
@@ -24,7 +36,14 @@ export const BUILTIN_PROVIDERS = [
|
|
|
24
36
|
id: "openai",
|
|
25
37
|
name: "OpenAI",
|
|
26
38
|
api: "openai-completions",
|
|
39
|
+
catalogApi: RESPONSES,
|
|
27
40
|
baseUrl: "https://api.openai.com/v1",
|
|
41
|
+
// 全部模型缺省 Responses(R1 §2.3);Chat 作渠道
|
|
42
|
+
channels: [
|
|
43
|
+
ch("responses", RESPONSES, "https://api.openai.com/v1"),
|
|
44
|
+
ch("chat", CHAT, "https://api.openai.com/v1"),
|
|
45
|
+
],
|
|
46
|
+
defaultChannel: "responses",
|
|
28
47
|
baseUrlEnv: "OPENAI_BASE_URL",
|
|
29
48
|
envKeys: ["OPENAI_API_KEY", "AMA_API_KEY_OPENAI"],
|
|
30
49
|
requiresApiKey: true,
|
|
@@ -43,6 +62,12 @@ export const BUILTIN_PROVIDERS = [
|
|
|
43
62
|
name: "DeepSeek",
|
|
44
63
|
api: "openai-completions",
|
|
45
64
|
baseUrl: "https://api.deepseek.com",
|
|
65
|
+
// 实测门(wave5-plan §3.2)未过前缺省 chat;messages 上 cache_control 被忽略
|
|
66
|
+
channels: [
|
|
67
|
+
ch("chat", CHAT, "https://api.deepseek.com"),
|
|
68
|
+
ch("messages", MESSAGES, "https://api.deepseek.com/anthropic"),
|
|
69
|
+
],
|
|
70
|
+
defaultChannel: "chat",
|
|
46
71
|
envKeys: ["DEEPSEEK_API_KEY", "AMA_API_KEY_DEEPSEEK"],
|
|
47
72
|
requiresApiKey: true,
|
|
48
73
|
},
|
|
@@ -51,6 +76,15 @@ export const BUILTIN_PROVIDERS = [
|
|
|
51
76
|
name: "Moonshot (Kimi)",
|
|
52
77
|
api: "openai-completions",
|
|
53
78
|
baseUrl: "https://api.moonshot.cn/v1",
|
|
79
|
+
// 实测门未过前缺省 chat(K3 在 Messages 端点有 tool_use.id 复用的第三方报告)
|
|
80
|
+
channels: [
|
|
81
|
+
ch("chat", CHAT, "https://api.moonshot.cn/v1"),
|
|
82
|
+
ch("messages", MESSAGES, "https://api.moonshot.cn/anthropic", BEARER),
|
|
83
|
+
ch("responses", RESPONSES, "https://api.moonshot.cn/v1"),
|
|
84
|
+
ch("chat-intl", CHAT, "https://api.moonshot.ai/v1"),
|
|
85
|
+
ch("messages-intl", MESSAGES, "https://api.moonshot.ai/anthropic", BEARER),
|
|
86
|
+
],
|
|
87
|
+
defaultChannel: "chat",
|
|
54
88
|
envKeys: ["MOONSHOT_API_KEY", "KIMI_API_KEY", "AMA_API_KEY_MOONSHOT"],
|
|
55
89
|
requiresApiKey: true,
|
|
56
90
|
},
|
|
@@ -59,6 +93,14 @@ export const BUILTIN_PROVIDERS = [
|
|
|
59
93
|
name: "Zhipu GLM",
|
|
60
94
|
api: "openai-completions",
|
|
61
95
|
baseUrl: "https://open.bigmodel.cn/api/paas/v4",
|
|
96
|
+
// 实测门未过前缺省 chat;只有隐式缓存
|
|
97
|
+
channels: [
|
|
98
|
+
ch("chat", CHAT, "https://open.bigmodel.cn/api/paas/v4"),
|
|
99
|
+
ch("messages", MESSAGES, "https://open.bigmodel.cn/api/anthropic"),
|
|
100
|
+
ch("chat-intl", CHAT, "https://api.z.ai/api/paas/v4"),
|
|
101
|
+
ch("messages-intl", MESSAGES, "https://api.z.ai/api/anthropic"),
|
|
102
|
+
],
|
|
103
|
+
defaultChannel: "chat",
|
|
62
104
|
envKeys: ["ZHIPU_API_KEY", "ZAI_API_KEY", "AMA_API_KEY_ZHIPU"],
|
|
63
105
|
requiresApiKey: true,
|
|
64
106
|
},
|
|
@@ -67,6 +109,15 @@ export const BUILTIN_PROVIDERS = [
|
|
|
67
109
|
name: "Alibaba DashScope (Qwen)",
|
|
68
110
|
api: "openai-completions",
|
|
69
111
|
baseUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
112
|
+
// Messages 端点执行 cache_control(5m),直接切
|
|
113
|
+
channels: [
|
|
114
|
+
ch("messages", MESSAGES, "https://dashscope.aliyuncs.com/apps/anthropic"),
|
|
115
|
+
ch("responses", RESPONSES, "https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
|
116
|
+
ch("chat", CHAT, "https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
|
117
|
+
ch("messages-intl", MESSAGES, "https://dashscope-intl.aliyuncs.com/apps/anthropic"),
|
|
118
|
+
ch("chat-intl", CHAT, "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"),
|
|
119
|
+
],
|
|
120
|
+
defaultChannel: "messages",
|
|
70
121
|
envKeys: ["DASHSCOPE_API_KEY", "QWEN_API_KEY", "AMA_API_KEY_DASHSCOPE"],
|
|
71
122
|
requiresApiKey: true,
|
|
72
123
|
},
|
|
@@ -94,7 +145,14 @@ export const BUILTIN_PROVIDERS = [
|
|
|
94
145
|
id: "xai",
|
|
95
146
|
name: "xAI",
|
|
96
147
|
api: "openai-completions",
|
|
148
|
+
catalogApi: RESPONSES,
|
|
97
149
|
baseUrl: "https://api.x.ai/v1",
|
|
150
|
+
// 官方已把 Anthropic 兼容标为 deprecated,不做 messages 渠道
|
|
151
|
+
channels: [
|
|
152
|
+
ch("responses", RESPONSES, "https://api.x.ai/v1"),
|
|
153
|
+
ch("chat", CHAT, "https://api.x.ai/v1"),
|
|
154
|
+
],
|
|
155
|
+
defaultChannel: "responses",
|
|
98
156
|
envKeys: ["XAI_API_KEY", "AMA_API_KEY_XAI"],
|
|
99
157
|
requiresApiKey: true,
|
|
100
158
|
},
|
|
@@ -106,6 +164,69 @@ export const BUILTIN_PROVIDERS = [
|
|
|
106
164
|
envKeys: ["MISTRAL_API_KEY", "AMA_API_KEY_MISTRAL"],
|
|
107
165
|
requiresApiKey: true,
|
|
108
166
|
},
|
|
167
|
+
{
|
|
168
|
+
id: "minimax",
|
|
169
|
+
name: "MiniMax",
|
|
170
|
+
api: "openai-completions",
|
|
171
|
+
baseUrl: "https://api.minimax.cn/v1",
|
|
172
|
+
// 官方推荐 Anthropic 兼容端点;M2.x 执行 cache_control(5m),M3 的缓存行为列入实测;Responses 只有 M3
|
|
173
|
+
channels: [
|
|
174
|
+
ch("messages", MESSAGES, "https://api.minimax.cn/anthropic", BEARER),
|
|
175
|
+
ch("responses", RESPONSES, "https://api.minimax.cn/v1"),
|
|
176
|
+
ch("chat", CHAT, "https://api.minimax.cn/v1"),
|
|
177
|
+
ch("messages-intl", MESSAGES, "https://api.minimax.io/anthropic", BEARER),
|
|
178
|
+
ch("chat-intl", CHAT, "https://api.minimax.io/v1"),
|
|
179
|
+
],
|
|
180
|
+
defaultChannel: "messages",
|
|
181
|
+
envKeys: ["MINIMAX_API_KEY", "AMA_API_KEY_MINIMAX"],
|
|
182
|
+
requiresApiKey: true,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: "stepfun",
|
|
186
|
+
name: "StepFun",
|
|
187
|
+
api: "openai-completions",
|
|
188
|
+
baseUrl: "https://api.stepfun.com/v1",
|
|
189
|
+
// 自动前缀缓存;Responses 按模型开放(目录标注)
|
|
190
|
+
channels: [
|
|
191
|
+
ch("messages", MESSAGES, "https://api.stepfun.com", BEARER),
|
|
192
|
+
ch("chat", CHAT, "https://api.stepfun.com/v1"),
|
|
193
|
+
ch("responses", RESPONSES, "https://api.stepfun.com/v1"),
|
|
194
|
+
ch("messages-intl", MESSAGES, "https://api.stepfun.ai", BEARER),
|
|
195
|
+
ch("chat-intl", CHAT, "https://api.stepfun.ai/v1"),
|
|
196
|
+
],
|
|
197
|
+
defaultChannel: "messages",
|
|
198
|
+
envKeys: ["STEPFUN_API_KEY", "STEP_API_KEY", "AMA_API_KEY_STEPFUN"],
|
|
199
|
+
requiresApiKey: true,
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: "volcengine",
|
|
203
|
+
name: "Volcengine Ark (Doubao)",
|
|
204
|
+
api: "openai-completions",
|
|
205
|
+
catalogApi: RESPONSES,
|
|
206
|
+
baseUrl: "https://ark.cn-beijing.volces.com/api/v3",
|
|
207
|
+
// 官方推荐 Responses(显式缓存只在 Responses 上);Anthropic 兼容只在 Coding Plan,不做渠道(D9)
|
|
208
|
+
channels: [
|
|
209
|
+
ch("responses", RESPONSES, "https://ark.cn-beijing.volces.com/api/v3"),
|
|
210
|
+
ch("chat", CHAT, "https://ark.cn-beijing.volces.com/api/v3"),
|
|
211
|
+
],
|
|
212
|
+
defaultChannel: "responses",
|
|
213
|
+
envKeys: ["ARK_API_KEY", "VOLCENGINE_API_KEY", "AMA_API_KEY_VOLCENGINE"],
|
|
214
|
+
requiresApiKey: true,
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
id: "tencent",
|
|
218
|
+
name: "Tencent TokenHub (Hunyuan)",
|
|
219
|
+
api: "openai-completions",
|
|
220
|
+
baseUrl: "https://tokenhub.tencentmaas.com/v1",
|
|
221
|
+
// Anthropic 线执行 cache_control(含 1h),直接切
|
|
222
|
+
channels: [
|
|
223
|
+
ch("messages", MESSAGES, "https://tokenhub.tencentmaas.com"),
|
|
224
|
+
ch("chat", CHAT, "https://tokenhub.tencentmaas.com/v1"),
|
|
225
|
+
],
|
|
226
|
+
defaultChannel: "messages",
|
|
227
|
+
envKeys: ["TOKENHUB_API_KEY", "HUNYUAN_API_KEY", "AMA_API_KEY_TENCENT"],
|
|
228
|
+
requiresApiKey: true,
|
|
229
|
+
},
|
|
109
230
|
{
|
|
110
231
|
id: "ollama",
|
|
111
232
|
name: "Ollama (local)",
|
|
@@ -132,15 +253,23 @@ function hostOf(url) {
|
|
|
132
253
|
return undefined;
|
|
133
254
|
}
|
|
134
255
|
}
|
|
256
|
+
/** 内置供应商的官方主机(单渠道回落 + 全部内置渠道)。 */
|
|
257
|
+
export function builtinHosts(providerId) {
|
|
258
|
+
const builtin = BUILTIN_PROVIDERS.find((p) => p.id === providerId);
|
|
259
|
+
const urls = [builtin?.baseUrl, ...(builtin?.channels ?? []).map((c) => c.baseUrl)];
|
|
260
|
+
return new Set(urls.map((url) => (url ? hostOf(url) : undefined)).filter((h) => h !== undefined));
|
|
261
|
+
}
|
|
135
262
|
/**
|
|
136
263
|
* 内置供应商的 baseUrl 是否被改到了非官方主机(中转站):此时目录外的 model id 也接受,
|
|
137
|
-
* compat
|
|
264
|
+
* compat 走保守缺省。按渠道比较主机:落在任一内置渠道的主机上(如国际站)不算中转。
|
|
265
|
+
* 非内置供应商与本地服务返回 false。
|
|
138
266
|
*/
|
|
139
267
|
export function isRelayedBaseUrl(providerId, baseUrl) {
|
|
140
268
|
const builtin = BUILTIN_PROVIDERS.find((p) => p.id === providerId);
|
|
141
269
|
if (builtin === undefined || builtin.requiresApiKey === false)
|
|
142
270
|
return false;
|
|
143
|
-
|
|
271
|
+
const host = hostOf(baseUrl);
|
|
272
|
+
return host === undefined || !builtinHosts(providerId).has(host);
|
|
144
273
|
}
|
|
145
274
|
/** 自定义供应商的兜底环境变量名:`AMA_API_KEY_<ID>`(非字母数字转下划线、大写)。 */
|
|
146
275
|
export function fallbackEnvKey(providerId) {
|