praxis-agent 0.1.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/LICENSE +21 -0
- package/README.md +534 -0
- package/dist/application/background-agent-manager.d.ts +66 -0
- package/dist/application/background-agent-manager.d.ts.map +1 -0
- package/dist/application/background-agent-manager.js +362 -0
- package/dist/application/background-agent-manager.js.map +1 -0
- package/dist/application/background-bash-manager.d.ts +54 -0
- package/dist/application/background-bash-manager.d.ts.map +1 -0
- package/dist/application/background-bash-manager.js +354 -0
- package/dist/application/background-bash-manager.js.map +1 -0
- package/dist/application/background-task-id.d.ts +5 -0
- package/dist/application/background-task-id.d.ts.map +1 -0
- package/dist/application/background-task-id.js +25 -0
- package/dist/application/background-task-id.js.map +1 -0
- package/dist/application/claude-project-purge.d.ts +50 -0
- package/dist/application/claude-project-purge.d.ts.map +1 -0
- package/dist/application/claude-project-purge.js +459 -0
- package/dist/application/claude-project-purge.js.map +1 -0
- package/dist/application/managed-worktree.d.ts +15 -0
- package/dist/application/managed-worktree.d.ts.map +1 -0
- package/dist/application/managed-worktree.js +127 -0
- package/dist/application/managed-worktree.js.map +1 -0
- package/dist/application/model-compactor.d.ts +8 -0
- package/dist/application/model-compactor.d.ts.map +1 -0
- package/dist/application/model-compactor.js +70 -0
- package/dist/application/model-compactor.js.map +1 -0
- package/dist/application/scheduled-prompt-manager.d.ts +69 -0
- package/dist/application/scheduled-prompt-manager.d.ts.map +1 -0
- package/dist/application/scheduled-prompt-manager.js +387 -0
- package/dist/application/scheduled-prompt-manager.js.map +1 -0
- package/dist/application/session-service.d.ts +142 -0
- package/dist/application/session-service.d.ts.map +1 -0
- package/dist/application/session-service.js +1690 -0
- package/dist/application/session-service.js.map +1 -0
- package/dist/application/session-worktree.d.ts +55 -0
- package/dist/application/session-worktree.d.ts.map +1 -0
- package/dist/application/session-worktree.js +311 -0
- package/dist/application/session-worktree.js.map +1 -0
- package/dist/application/subagent-service.d.ts +98 -0
- package/dist/application/subagent-service.d.ts.map +1 -0
- package/dist/application/subagent-service.js +1305 -0
- package/dist/application/subagent-service.js.map +1 -0
- package/dist/application/tool-use-summary.d.ts +8 -0
- package/dist/application/tool-use-summary.d.ts.map +1 -0
- package/dist/application/tool-use-summary.js +53 -0
- package/dist/application/tool-use-summary.js.map +1 -0
- package/dist/application/top-level-agent-manager.d.ts +58 -0
- package/dist/application/top-level-agent-manager.d.ts.map +1 -0
- package/dist/application/top-level-agent-manager.js +907 -0
- package/dist/application/top-level-agent-manager.js.map +1 -0
- package/dist/application/workflow-manager.d.ts +61 -0
- package/dist/application/workflow-manager.d.ts.map +1 -0
- package/dist/application/workflow-manager.js +582 -0
- package/dist/application/workflow-manager.js.map +1 -0
- package/dist/application/workflow-meta.d.ts +18 -0
- package/dist/application/workflow-meta.d.ts.map +1 -0
- package/dist/application/workflow-meta.js +146 -0
- package/dist/application/workflow-meta.js.map +1 -0
- package/dist/application/workflow-runtime.d.ts +29 -0
- package/dist/application/workflow-runtime.d.ts.map +1 -0
- package/dist/application/workflow-runtime.js +176 -0
- package/dist/application/workflow-runtime.js.map +1 -0
- package/dist/application/workflow-worktree.d.ts +9 -0
- package/dist/application/workflow-worktree.d.ts.map +1 -0
- package/dist/application/workflow-worktree.js +11 -0
- package/dist/application/workflow-worktree.js.map +1 -0
- package/dist/cli/agents-dashboard.d.ts +37 -0
- package/dist/cli/agents-dashboard.d.ts.map +1 -0
- package/dist/cli/agents-dashboard.js +408 -0
- package/dist/cli/agents-dashboard.js.map +1 -0
- package/dist/cli/controls.d.ts +15 -0
- package/dist/cli/controls.d.ts.map +1 -0
- package/dist/cli/controls.js +219 -0
- package/dist/cli/controls.js.map +1 -0
- package/dist/cli/debug.d.ts +13 -0
- package/dist/cli/debug.d.ts.map +1 -0
- package/dist/cli/debug.js +37 -0
- package/dist/cli/debug.js.map +1 -0
- package/dist/cli/interactive.d.ts +63 -0
- package/dist/cli/interactive.d.ts.map +1 -0
- package/dist/cli/interactive.js +600 -0
- package/dist/cli/interactive.js.map +1 -0
- package/dist/cli/protocol.d.ts +251 -0
- package/dist/cli/protocol.d.ts.map +1 -0
- package/dist/cli/protocol.js +2146 -0
- package/dist/cli/protocol.js.map +1 -0
- package/dist/cli.d.ts +116 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3901 -0
- package/dist/cli.js.map +1 -0
- package/dist/compatibility/claude/compaction.d.ts +19 -0
- package/dist/compatibility/claude/compaction.d.ts.map +1 -0
- package/dist/compatibility/claude/compaction.js +82 -0
- package/dist/compatibility/claude/compaction.js.map +1 -0
- package/dist/compatibility/claude/context.d.ts +24 -0
- package/dist/compatibility/claude/context.d.ts.map +1 -0
- package/dist/compatibility/claude/context.js +92 -0
- package/dist/compatibility/claude/context.js.map +1 -0
- package/dist/compatibility/claude/dynamic-context.d.ts +20 -0
- package/dist/compatibility/claude/dynamic-context.d.ts.map +1 -0
- package/dist/compatibility/claude/dynamic-context.js +168 -0
- package/dist/compatibility/claude/dynamic-context.js.map +1 -0
- package/dist/compatibility/claude/file-history.d.ts +14 -0
- package/dist/compatibility/claude/file-history.d.ts.map +1 -0
- package/dist/compatibility/claude/file-history.js +340 -0
- package/dist/compatibility/claude/file-history.js.map +1 -0
- package/dist/compatibility/claude/file-resources.d.ts +28 -0
- package/dist/compatibility/claude/file-resources.d.ts.map +1 -0
- package/dist/compatibility/claude/file-resources.js +168 -0
- package/dist/compatibility/claude/file-resources.js.map +1 -0
- package/dist/compatibility/claude/fork.d.ts +9 -0
- package/dist/compatibility/claude/fork.d.ts.map +1 -0
- package/dist/compatibility/claude/fork.js +225 -0
- package/dist/compatibility/claude/fork.js.map +1 -0
- package/dist/compatibility/claude/history.d.ts +4 -0
- package/dist/compatibility/claude/history.d.ts.map +1 -0
- package/dist/compatibility/claude/history.js +86 -0
- package/dist/compatibility/claude/history.js.map +1 -0
- package/dist/compatibility/claude/ownership.d.ts +87 -0
- package/dist/compatibility/claude/ownership.d.ts.map +1 -0
- package/dist/compatibility/claude/ownership.js +100 -0
- package/dist/compatibility/claude/ownership.js.map +1 -0
- package/dist/compatibility/claude/paths.d.ts +17 -0
- package/dist/compatibility/claude/paths.d.ts.map +1 -0
- package/dist/compatibility/claude/paths.js +54 -0
- package/dist/compatibility/claude/paths.js.map +1 -0
- package/dist/compatibility/claude/pr-links.d.ts +25 -0
- package/dist/compatibility/claude/pr-links.d.ts.map +1 -0
- package/dist/compatibility/claude/pr-links.js +80 -0
- package/dist/compatibility/claude/pr-links.js.map +1 -0
- package/dist/compatibility/claude/projection.d.ts +11 -0
- package/dist/compatibility/claude/projection.d.ts.map +1 -0
- package/dist/compatibility/claude/projection.js +325 -0
- package/dist/compatibility/claude/projection.js.map +1 -0
- package/dist/compatibility/claude/schema.d.ts +18 -0
- package/dist/compatibility/claude/schema.d.ts.map +1 -0
- package/dist/compatibility/claude/schema.js +983 -0
- package/dist/compatibility/claude/schema.js.map +1 -0
- package/dist/compatibility/claude/shared-resources.d.ts +51 -0
- package/dist/compatibility/claude/shared-resources.d.ts.map +1 -0
- package/dist/compatibility/claude/shared-resources.js +382 -0
- package/dist/compatibility/claude/shared-resources.js.map +1 -0
- package/dist/compatibility/claude/sidechain.d.ts +50 -0
- package/dist/compatibility/claude/sidechain.d.ts.map +1 -0
- package/dist/compatibility/claude/sidechain.js +90 -0
- package/dist/compatibility/claude/sidechain.js.map +1 -0
- package/dist/compatibility/claude/tool-links.d.ts +13 -0
- package/dist/compatibility/claude/tool-links.d.ts.map +1 -0
- package/dist/compatibility/claude/tool-links.js +61 -0
- package/dist/compatibility/claude/tool-links.js.map +1 -0
- package/dist/compatibility/claude/translation.d.ts +71 -0
- package/dist/compatibility/claude/translation.d.ts.map +1 -0
- package/dist/compatibility/claude/translation.js +443 -0
- package/dist/compatibility/claude/translation.js.map +1 -0
- package/dist/compatibility/claude/workflow-replay.d.ts +10 -0
- package/dist/compatibility/claude/workflow-replay.d.ts.map +1 -0
- package/dist/compatibility/claude/workflow-replay.js +66 -0
- package/dist/compatibility/claude/workflow-replay.js.map +1 -0
- package/dist/compatibility/claude/workflow.d.ts +33 -0
- package/dist/compatibility/claude/workflow.d.ts.map +1 -0
- package/dist/compatibility/claude/workflow.js +76 -0
- package/dist/compatibility/claude/workflow.js.map +1 -0
- package/dist/core/compaction.d.ts +16 -0
- package/dist/core/compaction.d.ts.map +1 -0
- package/dist/core/compaction.js +2 -0
- package/dist/core/compaction.js.map +1 -0
- package/dist/core/context-budget.d.ts +28 -0
- package/dist/core/context-budget.d.ts.map +1 -0
- package/dist/core/context-budget.js +108 -0
- package/dist/core/context-budget.js.map +1 -0
- package/dist/core/context.d.ts +16 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +13 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/runtime.d.ts +394 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +507 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/usage.d.ts +26 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core/usage.js +133 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/extensions/claude-extension-tools.d.ts +16 -0
- package/dist/extensions/claude-extension-tools.d.ts.map +1 -0
- package/dist/extensions/claude-extension-tools.js +78 -0
- package/dist/extensions/claude-extension-tools.js.map +1 -0
- package/dist/extensions/claude-extensions.d.ts +41 -0
- package/dist/extensions/claude-extensions.d.ts.map +1 -0
- package/dist/extensions/claude-extensions.js +270 -0
- package/dist/extensions/claude-extensions.js.map +1 -0
- package/dist/hooks/claude-hook-tools.d.ts +26 -0
- package/dist/hooks/claude-hook-tools.d.ts.map +1 -0
- package/dist/hooks/claude-hook-tools.js +129 -0
- package/dist/hooks/claude-hook-tools.js.map +1 -0
- package/dist/hooks/claude-hooks.d.ts +87 -0
- package/dist/hooks/claude-hooks.d.ts.map +1 -0
- package/dist/hooks/claude-hooks.js +411 -0
- package/dist/hooks/claude-hooks.js.map +1 -0
- package/dist/maintenance/doctor.d.ts +33 -0
- package/dist/maintenance/doctor.d.ts.map +1 -0
- package/dist/maintenance/doctor.js +391 -0
- package/dist/maintenance/doctor.js.map +1 -0
- package/dist/maintenance/self-update.d.ts +31 -0
- package/dist/maintenance/self-update.d.ts.map +1 -0
- package/dist/maintenance/self-update.js +81 -0
- package/dist/maintenance/self-update.js.map +1 -0
- package/dist/mcp/claude-mcp-management.d.ts +28 -0
- package/dist/mcp/claude-mcp-management.d.ts.map +1 -0
- package/dist/mcp/claude-mcp-management.js +169 -0
- package/dist/mcp/claude-mcp-management.js.map +1 -0
- package/dist/mcp/claude-mcp-oauth.d.ts +113 -0
- package/dist/mcp/claude-mcp-oauth.d.ts.map +1 -0
- package/dist/mcp/claude-mcp-oauth.js +1053 -0
- package/dist/mcp/claude-mcp-oauth.js.map +1 -0
- package/dist/mcp/claude-mcp-tools.d.ts +98 -0
- package/dist/mcp/claude-mcp-tools.d.ts.map +1 -0
- package/dist/mcp/claude-mcp-tools.js +1246 -0
- package/dist/mcp/claude-mcp-tools.js.map +1 -0
- package/dist/mcp/praxis-mcp-server.d.ts +35 -0
- package/dist/mcp/praxis-mcp-server.d.ts.map +1 -0
- package/dist/mcp/praxis-mcp-server.js +520 -0
- package/dist/mcp/praxis-mcp-server.js.map +1 -0
- package/dist/permissions/claude-auto-classifier.d.ts +20 -0
- package/dist/permissions/claude-auto-classifier.d.ts.map +1 -0
- package/dist/permissions/claude-auto-classifier.js +140 -0
- package/dist/permissions/claude-auto-classifier.js.map +1 -0
- package/dist/permissions/claude-permission-resolver.d.ts +30 -0
- package/dist/permissions/claude-permission-resolver.d.ts.map +1 -0
- package/dist/permissions/claude-permission-resolver.js +334 -0
- package/dist/permissions/claude-permission-resolver.js.map +1 -0
- package/dist/persistence/claude-job-store.d.ts +68 -0
- package/dist/persistence/claude-job-store.d.ts.map +1 -0
- package/dist/persistence/claude-job-store.js +311 -0
- package/dist/persistence/claude-job-store.js.map +1 -0
- package/dist/persistence/claude-scheduled-task-store.d.ts +29 -0
- package/dist/persistence/claude-scheduled-task-store.d.ts.map +1 -0
- package/dist/persistence/claude-scheduled-task-store.js +163 -0
- package/dist/persistence/claude-scheduled-task-store.js.map +1 -0
- package/dist/persistence/claude-sidechain-store.d.ts +18 -0
- package/dist/persistence/claude-sidechain-store.d.ts.map +1 -0
- package/dist/persistence/claude-sidechain-store.js +107 -0
- package/dist/persistence/claude-sidechain-store.js.map +1 -0
- package/dist/persistence/claude-task-store.d.ts +72 -0
- package/dist/persistence/claude-task-store.d.ts.map +1 -0
- package/dist/persistence/claude-task-store.js +440 -0
- package/dist/persistence/claude-task-store.js.map +1 -0
- package/dist/persistence/claude-transcript-store.d.ts +85 -0
- package/dist/persistence/claude-transcript-store.d.ts.map +1 -0
- package/dist/persistence/claude-transcript-store.js +385 -0
- package/dist/persistence/claude-transcript-store.js.map +1 -0
- package/dist/persistence/claude-workflow-store.d.ts +41 -0
- package/dist/persistence/claude-workflow-store.d.ts.map +1 -0
- package/dist/persistence/claude-workflow-store.js +263 -0
- package/dist/persistence/claude-workflow-store.js.map +1 -0
- package/dist/persistence/in-memory-sidechain-store.d.ts +12 -0
- package/dist/persistence/in-memory-sidechain-store.d.ts.map +1 -0
- package/dist/persistence/in-memory-sidechain-store.js +30 -0
- package/dist/persistence/in-memory-sidechain-store.js.map +1 -0
- package/dist/persistence/in-memory-transcript-store.d.ts +15 -0
- package/dist/persistence/in-memory-transcript-store.d.ts.map +1 -0
- package/dist/persistence/in-memory-transcript-store.js +95 -0
- package/dist/persistence/in-memory-transcript-store.js.map +1 -0
- package/dist/platform/atomic-write.d.ts +5 -0
- package/dist/platform/atomic-write.d.ts.map +1 -0
- package/dist/platform/atomic-write.js +25 -0
- package/dist/platform/atomic-write.js.map +1 -0
- package/dist/platform/bounded-process-runner.d.ts +28 -0
- package/dist/platform/bounded-process-runner.d.ts.map +1 -0
- package/dist/platform/bounded-process-runner.js +209 -0
- package/dist/platform/bounded-process-runner.js.map +1 -0
- package/dist/platform/claude-version.d.ts +5 -0
- package/dist/platform/claude-version.d.ts.map +1 -0
- package/dist/platform/claude-version.js +17 -0
- package/dist/platform/claude-version.js.map +1 -0
- package/dist/platform/command-shell.d.ts +3 -0
- package/dist/platform/command-shell.d.ts.map +1 -0
- package/dist/platform/command-shell.js +15 -0
- package/dist/platform/command-shell.js.map +1 -0
- package/dist/platform/exclusive-file-lease.d.ts +15 -0
- package/dist/platform/exclusive-file-lease.d.ts.map +1 -0
- package/dist/platform/exclusive-file-lease.js +265 -0
- package/dist/platform/exclusive-file-lease.js.map +1 -0
- package/dist/platform/sensitive-data.d.ts +8 -0
- package/dist/platform/sensitive-data.d.ts.map +1 -0
- package/dist/platform/sensitive-data.js +138 -0
- package/dist/platform/sensitive-data.js.map +1 -0
- package/dist/platform/tmux-worktree.d.ts +30 -0
- package/dist/platform/tmux-worktree.d.ts.map +1 -0
- package/dist/platform/tmux-worktree.js +138 -0
- package/dist/platform/tmux-worktree.js.map +1 -0
- package/dist/plugins/claude-plugin-eval-discovery.d.ts +20 -0
- package/dist/plugins/claude-plugin-eval-discovery.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-eval-discovery.js +128 -0
- package/dist/plugins/claude-plugin-eval-discovery.js.map +1 -0
- package/dist/plugins/claude-plugin-eval-graders.d.ts +49 -0
- package/dist/plugins/claude-plugin-eval-graders.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-eval-graders.js +137 -0
- package/dist/plugins/claude-plugin-eval-graders.js.map +1 -0
- package/dist/plugins/claude-plugin-eval-runner.d.ts +50 -0
- package/dist/plugins/claude-plugin-eval-runner.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-eval-runner.js +189 -0
- package/dist/plugins/claude-plugin-eval-runner.js.map +1 -0
- package/dist/plugins/claude-plugin-eval-schema.d.ts +80 -0
- package/dist/plugins/claude-plugin-eval-schema.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-eval-schema.js +436 -0
- package/dist/plugins/claude-plugin-eval-schema.js.map +1 -0
- package/dist/plugins/claude-plugin-eval.d.ts +66 -0
- package/dist/plugins/claude-plugin-eval.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-eval.js +438 -0
- package/dist/plugins/claude-plugin-eval.js.map +1 -0
- package/dist/plugins/claude-plugin-maintenance.d.ts +39 -0
- package/dist/plugins/claude-plugin-maintenance.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-maintenance.js +336 -0
- package/dist/plugins/claude-plugin-maintenance.js.map +1 -0
- package/dist/plugins/claude-plugin-marketplace.d.ts +97 -0
- package/dist/plugins/claude-plugin-marketplace.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-marketplace.js +1433 -0
- package/dist/plugins/claude-plugin-marketplace.js.map +1 -0
- package/dist/plugins/claude-plugin-mcpb.d.ts +71 -0
- package/dist/plugins/claude-plugin-mcpb.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-mcpb.js +885 -0
- package/dist/plugins/claude-plugin-mcpb.js.map +1 -0
- package/dist/plugins/claude-plugin-runtime.d.ts +120 -0
- package/dist/plugins/claude-plugin-runtime.d.ts.map +1 -0
- package/dist/plugins/claude-plugin-runtime.js +1263 -0
- package/dist/plugins/claude-plugin-runtime.js.map +1 -0
- package/dist/providers/anthropic-compatible.d.ts +35 -0
- package/dist/providers/anthropic-compatible.d.ts.map +1 -0
- package/dist/providers/anthropic-compatible.js +733 -0
- package/dist/providers/anthropic-compatible.js.map +1 -0
- package/dist/providers/environment.d.ts +14 -0
- package/dist/providers/environment.d.ts.map +1 -0
- package/dist/providers/environment.js +67 -0
- package/dist/providers/environment.js.map +1 -0
- package/dist/providers/fallback-provider.d.ts +17 -0
- package/dist/providers/fallback-provider.d.ts.map +1 -0
- package/dist/providers/fallback-provider.js +70 -0
- package/dist/providers/fallback-provider.js.map +1 -0
- package/dist/providers/openai-compatible.d.ts +30 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai-compatible.js +409 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/tools/claude-interactive-tools.d.ts +58 -0
- package/dist/tools/claude-interactive-tools.d.ts.map +1 -0
- package/dist/tools/claude-interactive-tools.js +390 -0
- package/dist/tools/claude-interactive-tools.js.map +1 -0
- package/dist/tools/claude-lsp-formatters.d.ts +2 -0
- package/dist/tools/claude-lsp-formatters.d.ts.map +1 -0
- package/dist/tools/claude-lsp-formatters.js +291 -0
- package/dist/tools/claude-lsp-formatters.js.map +1 -0
- package/dist/tools/claude-lsp-tool.d.ts +22 -0
- package/dist/tools/claude-lsp-tool.d.ts.map +1 -0
- package/dist/tools/claude-lsp-tool.js +744 -0
- package/dist/tools/claude-lsp-tool.js.map +1 -0
- package/dist/tools/claude-scheduled-tools.d.ts +20 -0
- package/dist/tools/claude-scheduled-tools.d.ts.map +1 -0
- package/dist/tools/claude-scheduled-tools.js +344 -0
- package/dist/tools/claude-scheduled-tools.js.map +1 -0
- package/dist/tools/claude-task-tools.d.ts +30 -0
- package/dist/tools/claude-task-tools.d.ts.map +1 -0
- package/dist/tools/claude-task-tools.js +503 -0
- package/dist/tools/claude-task-tools.js.map +1 -0
- package/dist/tools/claude-user-message.d.ts +16 -0
- package/dist/tools/claude-user-message.d.ts.map +1 -0
- package/dist/tools/claude-user-message.js +98 -0
- package/dist/tools/claude-user-message.js.map +1 -0
- package/dist/tools/claude-workflow-tools.d.ts +27 -0
- package/dist/tools/claude-workflow-tools.d.ts.map +1 -0
- package/dist/tools/claude-workflow-tools.js +257 -0
- package/dist/tools/claude-workflow-tools.js.map +1 -0
- package/dist/tools/claude-worktree-tools.d.ts +17 -0
- package/dist/tools/claude-worktree-tools.d.ts.map +1 -0
- package/dist/tools/claude-worktree-tools.js +135 -0
- package/dist/tools/claude-worktree-tools.js.map +1 -0
- package/dist/tools/filtered-tool-registry.d.ts +16 -0
- package/dist/tools/filtered-tool-registry.d.ts.map +1 -0
- package/dist/tools/filtered-tool-registry.js +51 -0
- package/dist/tools/filtered-tool-registry.js.map +1 -0
- package/dist/tools/glob.d.ts +9 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +88 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/local-tools.d.ts +47 -0
- package/dist/tools/local-tools.d.ts.map +1 -0
- package/dist/tools/local-tools.js +1082 -0
- package/dist/tools/local-tools.js.map +1 -0
- package/dist/tools/notebook.d.ts +22 -0
- package/dist/tools/notebook.d.ts.map +1 -0
- package/dist/tools/notebook.js +154 -0
- package/dist/tools/notebook.js.map +1 -0
- package/dist/tools/web.d.ts +48 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +726 -0
- package/dist/tools/web.js.map +1 -0
- package/package.json +145 -0
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import { ModelProviderError, } from '../core/runtime.js';
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function webSearchLinks(value) {
|
|
6
|
+
if (!Array.isArray(value))
|
|
7
|
+
return [];
|
|
8
|
+
return value.flatMap((item) => isRecord(item) &&
|
|
9
|
+
item.type === 'web_search_result' &&
|
|
10
|
+
typeof item.title === 'string' &&
|
|
11
|
+
typeof item.url === 'string'
|
|
12
|
+
? [{ title: item.title, url: item.url }]
|
|
13
|
+
: []);
|
|
14
|
+
}
|
|
15
|
+
function positiveInteger(value, label) {
|
|
16
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
17
|
+
throw new Error(`${label} must be a positive integer`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function validateThinking(thinking) {
|
|
22
|
+
if (!thinking)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (!['enabled', 'adaptive', 'disabled'].includes(thinking.mode)) {
|
|
25
|
+
throw new Error(`Unsupported thinking mode: ${thinking.mode}`);
|
|
26
|
+
}
|
|
27
|
+
if (thinking.maxTokens !== undefined) {
|
|
28
|
+
positiveInteger(thinking.maxTokens, 'Max thinking tokens');
|
|
29
|
+
if (thinking.mode === 'disabled') {
|
|
30
|
+
throw new Error('Max thinking tokens cannot be used when thinking is disabled');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return thinking;
|
|
34
|
+
}
|
|
35
|
+
function isRetryableStatus(status) {
|
|
36
|
+
return status === 408 || status === 409 || status === 429 || status >= 500;
|
|
37
|
+
}
|
|
38
|
+
function readErrorMessage(value, status) {
|
|
39
|
+
if (isRecord(value) && isRecord(value.error)) {
|
|
40
|
+
const message = value.error.message;
|
|
41
|
+
if (typeof message === 'string' && message.length > 0)
|
|
42
|
+
return message;
|
|
43
|
+
}
|
|
44
|
+
return `Provider request failed with HTTP ${status}`;
|
|
45
|
+
}
|
|
46
|
+
function completedToolCall(state, index) {
|
|
47
|
+
const pending = state.tools.get(index);
|
|
48
|
+
if (!pending)
|
|
49
|
+
return null;
|
|
50
|
+
state.tools.delete(index);
|
|
51
|
+
let input = pending.initialInput;
|
|
52
|
+
if (pending.partialJson.length > 0) {
|
|
53
|
+
try {
|
|
54
|
+
input = JSON.parse(pending.partialJson);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw new ModelProviderError(`Provider returned malformed tool arguments for ${pending.name}`, { retryable: false, cause: error });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!pending.id || !pending.name || !isRecord(input)) {
|
|
61
|
+
throw new ModelProviderError('Provider returned an invalid tool call', {
|
|
62
|
+
retryable: false,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const call = {
|
|
66
|
+
id: pending.id,
|
|
67
|
+
name: pending.name,
|
|
68
|
+
input,
|
|
69
|
+
};
|
|
70
|
+
return { type: 'tool-call', call };
|
|
71
|
+
}
|
|
72
|
+
function parseSseEvent(data, state, maxToolArgumentsBytes, maxToolCallsPerResponse, maxToolMetadataBytes) {
|
|
73
|
+
let value;
|
|
74
|
+
try {
|
|
75
|
+
value = JSON.parse(data);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new ModelProviderError('Provider returned malformed SSE JSON', {
|
|
79
|
+
retryable: false,
|
|
80
|
+
cause: error,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!isRecord(value) || typeof value.type !== 'string')
|
|
84
|
+
return [];
|
|
85
|
+
if (value.type === 'error') {
|
|
86
|
+
const error = isRecord(value.error) ? value.error : {};
|
|
87
|
+
const message = typeof error.message === 'string'
|
|
88
|
+
? error.message
|
|
89
|
+
: 'Provider stream returned an error';
|
|
90
|
+
const retryable = [
|
|
91
|
+
'api_error',
|
|
92
|
+
'overloaded_error',
|
|
93
|
+
'rate_limit_error',
|
|
94
|
+
].includes(String(error.type));
|
|
95
|
+
throw new ModelProviderError(message, { retryable });
|
|
96
|
+
}
|
|
97
|
+
if (value.type === 'message_start') {
|
|
98
|
+
if (state.messageStarted || !isRecord(value.message)) {
|
|
99
|
+
throw new ModelProviderError('Provider returned an invalid message start', {
|
|
100
|
+
retryable: false,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
state.messageStarted = true;
|
|
104
|
+
const usage = value.message.usage;
|
|
105
|
+
if (isRecord(usage)) {
|
|
106
|
+
const inputTokens = [
|
|
107
|
+
usage.input_tokens,
|
|
108
|
+
usage.cache_creation_input_tokens,
|
|
109
|
+
usage.cache_read_input_tokens,
|
|
110
|
+
].reduce((total, count) => total + (typeof count === 'number' ? count : 0), 0);
|
|
111
|
+
state.inputTokens = inputTokens;
|
|
112
|
+
state.cacheCreationInputTokens =
|
|
113
|
+
typeof usage.cache_creation_input_tokens === 'number'
|
|
114
|
+
? usage.cache_creation_input_tokens
|
|
115
|
+
: 0;
|
|
116
|
+
state.cacheReadInputTokens =
|
|
117
|
+
typeof usage.cache_read_input_tokens === 'number'
|
|
118
|
+
? usage.cache_read_input_tokens
|
|
119
|
+
: 0;
|
|
120
|
+
state.usageSeen = true;
|
|
121
|
+
}
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
if ([
|
|
125
|
+
'content_block_start',
|
|
126
|
+
'content_block_delta',
|
|
127
|
+
'content_block_stop',
|
|
128
|
+
'message_delta',
|
|
129
|
+
'message_stop',
|
|
130
|
+
].includes(value.type) &&
|
|
131
|
+
!state.messageStarted) {
|
|
132
|
+
throw new ModelProviderError(`Provider sent ${value.type} before message_start`, { retryable: false });
|
|
133
|
+
}
|
|
134
|
+
if (state.messageDeltaSeen &&
|
|
135
|
+
[
|
|
136
|
+
'content_block_start',
|
|
137
|
+
'content_block_delta',
|
|
138
|
+
'content_block_stop',
|
|
139
|
+
].includes(value.type)) {
|
|
140
|
+
throw new ModelProviderError(`Provider sent ${value.type} after message_delta`, { retryable: false });
|
|
141
|
+
}
|
|
142
|
+
if (value.type === 'content_block_start') {
|
|
143
|
+
if (typeof value.index !== 'number' || !isRecord(value.content_block)) {
|
|
144
|
+
throw new ModelProviderError('Provider returned an invalid content block start', { retryable: false });
|
|
145
|
+
}
|
|
146
|
+
if (state.blocks.has(value.index)) {
|
|
147
|
+
throw new ModelProviderError(`Provider restarted active content block ${value.index}`, { retryable: false });
|
|
148
|
+
}
|
|
149
|
+
const block = value.content_block;
|
|
150
|
+
if (block.type === 'thinking') {
|
|
151
|
+
if (typeof block.thinking !== 'string') {
|
|
152
|
+
throw new ModelProviderError('Provider returned an invalid thinking block', { retryable: false });
|
|
153
|
+
}
|
|
154
|
+
const pending = {
|
|
155
|
+
type: 'thinking',
|
|
156
|
+
thinking: block.thinking,
|
|
157
|
+
signature: typeof block.signature === 'string' ? block.signature : '',
|
|
158
|
+
};
|
|
159
|
+
state.blocks.set(value.index, 'thinking');
|
|
160
|
+
state.thinking.set(value.index, pending);
|
|
161
|
+
return [
|
|
162
|
+
{
|
|
163
|
+
type: 'thinking-start',
|
|
164
|
+
block: { type: 'thinking', thinking: block.thinking },
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
if (block.type === 'redacted_thinking') {
|
|
169
|
+
if (typeof block.data !== 'string') {
|
|
170
|
+
throw new ModelProviderError('Provider returned an invalid redacted thinking block', { retryable: false });
|
|
171
|
+
}
|
|
172
|
+
const pending = {
|
|
173
|
+
type: 'redacted_thinking',
|
|
174
|
+
data: block.data,
|
|
175
|
+
};
|
|
176
|
+
state.blocks.set(value.index, 'redacted_thinking');
|
|
177
|
+
state.thinking.set(value.index, pending);
|
|
178
|
+
return [{ type: 'thinking-start', block: pending }];
|
|
179
|
+
}
|
|
180
|
+
if (block.type === 'text') {
|
|
181
|
+
state.blocks.set(value.index, 'text');
|
|
182
|
+
return typeof block.text === 'string' && block.text.length > 0
|
|
183
|
+
? [{ type: 'text-delta', delta: block.text }]
|
|
184
|
+
: [];
|
|
185
|
+
}
|
|
186
|
+
if (block.type === 'web_search_tool_result') {
|
|
187
|
+
state.blocks.set(value.index, 'ignored');
|
|
188
|
+
const links = webSearchLinks(block.content);
|
|
189
|
+
const serialized = links.length > 0 ? JSON.stringify(links) : '';
|
|
190
|
+
state.metadataBytes += Buffer.byteLength(serialized);
|
|
191
|
+
if (state.metadataBytes > maxToolMetadataBytes) {
|
|
192
|
+
throw new ModelProviderError(`Provider tool metadata exceeded ${maxToolMetadataBytes} bytes`, { retryable: false });
|
|
193
|
+
}
|
|
194
|
+
return serialized
|
|
195
|
+
? [{ type: 'text-delta', delta: `Links: ${serialized}\n\n` }]
|
|
196
|
+
: [];
|
|
197
|
+
}
|
|
198
|
+
if (block.type !== 'tool_use') {
|
|
199
|
+
state.blocks.set(value.index, 'ignored');
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
if (!state.tools.has(value.index)) {
|
|
203
|
+
if (state.toolCallsSeen >= maxToolCallsPerResponse) {
|
|
204
|
+
throw new ModelProviderError(`Provider exceeded ${maxToolCallsPerResponse} tool calls in one response`, { retryable: false });
|
|
205
|
+
}
|
|
206
|
+
const id = typeof block.id === 'string' ? block.id : '';
|
|
207
|
+
const name = typeof block.name === 'string' ? block.name : '';
|
|
208
|
+
if (!id || !name || !isRecord(block.input)) {
|
|
209
|
+
throw new ModelProviderError('Provider returned an invalid tool call', {
|
|
210
|
+
retryable: false,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const initialInput = block.input;
|
|
214
|
+
const initialInputBytes = Buffer.byteLength(JSON.stringify(initialInput));
|
|
215
|
+
if (initialInputBytes > maxToolArgumentsBytes) {
|
|
216
|
+
throw new ModelProviderError(`Provider tool arguments exceeded ${maxToolArgumentsBytes} bytes`, { retryable: false });
|
|
217
|
+
}
|
|
218
|
+
state.toolCallsSeen += 1;
|
|
219
|
+
state.metadataBytes +=
|
|
220
|
+
Buffer.byteLength(id) + Buffer.byteLength(name) + initialInputBytes;
|
|
221
|
+
state.tools.set(value.index, {
|
|
222
|
+
id,
|
|
223
|
+
name,
|
|
224
|
+
initialInput,
|
|
225
|
+
partialJson: '',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
state.blocks.set(value.index, 'tool_use');
|
|
229
|
+
}
|
|
230
|
+
if (value.type === 'content_block_delta') {
|
|
231
|
+
if (typeof value.index !== 'number' || !isRecord(value.delta)) {
|
|
232
|
+
throw new ModelProviderError('Provider returned an invalid content block delta', { retryable: false });
|
|
233
|
+
}
|
|
234
|
+
const blockType = state.blocks.get(value.index);
|
|
235
|
+
if (!blockType) {
|
|
236
|
+
throw new ModelProviderError(`Provider updated inactive content block ${value.index}`, { retryable: false });
|
|
237
|
+
}
|
|
238
|
+
if (blockType === 'ignored')
|
|
239
|
+
return [];
|
|
240
|
+
if (value.delta.type === 'thinking_delta') {
|
|
241
|
+
const pending = state.thinking.get(value.index);
|
|
242
|
+
if (blockType !== 'thinking' ||
|
|
243
|
+
pending?.type !== 'thinking' ||
|
|
244
|
+
typeof value.delta.thinking !== 'string') {
|
|
245
|
+
throw new ModelProviderError(`Provider sent thinking for non-thinking content block ${value.index}`, { retryable: false });
|
|
246
|
+
}
|
|
247
|
+
pending.thinking += value.delta.thinking;
|
|
248
|
+
return [{ type: 'thinking-delta', delta: value.delta.thinking }];
|
|
249
|
+
}
|
|
250
|
+
if (value.delta.type === 'signature_delta') {
|
|
251
|
+
const pending = state.thinking.get(value.index);
|
|
252
|
+
if (blockType !== 'thinking' ||
|
|
253
|
+
pending?.type !== 'thinking' ||
|
|
254
|
+
typeof value.delta.signature !== 'string') {
|
|
255
|
+
throw new ModelProviderError(`Provider sent a signature for non-thinking content block ${value.index}`, { retryable: false });
|
|
256
|
+
}
|
|
257
|
+
pending.signature += value.delta.signature;
|
|
258
|
+
return [
|
|
259
|
+
{ type: 'thinking-signature-delta', delta: value.delta.signature },
|
|
260
|
+
];
|
|
261
|
+
}
|
|
262
|
+
if (value.delta.type === 'text_delta') {
|
|
263
|
+
if (blockType !== 'text') {
|
|
264
|
+
throw new ModelProviderError(`Provider sent text for non-text content block ${value.index}`, { retryable: false });
|
|
265
|
+
}
|
|
266
|
+
return typeof value.delta.text === 'string' && value.delta.text.length > 0
|
|
267
|
+
? [{ type: 'text-delta', delta: value.delta.text }]
|
|
268
|
+
: [];
|
|
269
|
+
}
|
|
270
|
+
if (value.delta.type === 'input_json_delta') {
|
|
271
|
+
if (blockType !== 'tool_use') {
|
|
272
|
+
throw new ModelProviderError(`Provider sent tool input for non-tool content block ${value.index}`, { retryable: false });
|
|
273
|
+
}
|
|
274
|
+
const pending = state.tools.get(value.index);
|
|
275
|
+
if (!pending || typeof value.delta.partial_json !== 'string') {
|
|
276
|
+
throw new ModelProviderError(`Provider returned invalid tool input for content block ${value.index}`, { retryable: false });
|
|
277
|
+
}
|
|
278
|
+
pending.partialJson += value.delta.partial_json;
|
|
279
|
+
const inputBytes = Buffer.byteLength(pending.partialJson);
|
|
280
|
+
state.metadataBytes += Buffer.byteLength(value.delta.partial_json);
|
|
281
|
+
if (inputBytes > maxToolArgumentsBytes) {
|
|
282
|
+
throw new ModelProviderError(`Provider tool arguments exceeded ${maxToolArgumentsBytes} bytes`, { retryable: false });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (value.delta.type !== 'text_delta' &&
|
|
286
|
+
value.delta.type !== 'input_json_delta' &&
|
|
287
|
+
value.delta.type !== 'citations_delta' &&
|
|
288
|
+
value.delta.type !== 'thinking_delta' &&
|
|
289
|
+
value.delta.type !== 'signature_delta') {
|
|
290
|
+
throw new ModelProviderError(`Provider returned an unsupported delta for content block ${value.index}`, { retryable: false });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (state.metadataBytes > maxToolMetadataBytes) {
|
|
294
|
+
throw new ModelProviderError(`Provider tool metadata exceeded ${maxToolMetadataBytes} bytes`, { retryable: false });
|
|
295
|
+
}
|
|
296
|
+
if (value.type === 'content_block_stop') {
|
|
297
|
+
if (typeof value.index !== 'number') {
|
|
298
|
+
throw new ModelProviderError('Provider returned an invalid content block stop', { retryable: false });
|
|
299
|
+
}
|
|
300
|
+
const blockType = state.blocks.get(value.index);
|
|
301
|
+
if (!blockType) {
|
|
302
|
+
throw new ModelProviderError(`Provider stopped inactive content block ${value.index}`, { retryable: false });
|
|
303
|
+
}
|
|
304
|
+
state.blocks.delete(value.index);
|
|
305
|
+
if (blockType === 'thinking' || blockType === 'redacted_thinking') {
|
|
306
|
+
const block = state.thinking.get(value.index);
|
|
307
|
+
state.thinking.delete(value.index);
|
|
308
|
+
if (!block) {
|
|
309
|
+
throw new ModelProviderError(`Provider stopped missing thinking block ${value.index}`, { retryable: false });
|
|
310
|
+
}
|
|
311
|
+
if ((block.type === 'thinking' && block.signature.length === 0) ||
|
|
312
|
+
(block.type === 'redacted_thinking' && block.data.length === 0)) {
|
|
313
|
+
throw new ModelProviderError(`Provider returned incomplete ${block.type} block ${value.index}`, { retryable: false });
|
|
314
|
+
}
|
|
315
|
+
return [{ type: 'thinking-stop', block }];
|
|
316
|
+
}
|
|
317
|
+
const event = blockType === 'tool_use' ? completedToolCall(state, value.index) : null;
|
|
318
|
+
return event ? [event] : [];
|
|
319
|
+
}
|
|
320
|
+
if (value.type === 'message_delta') {
|
|
321
|
+
if (state.blocks.size > 0 ||
|
|
322
|
+
state.tools.size > 0 ||
|
|
323
|
+
state.thinking.size > 0 ||
|
|
324
|
+
!isRecord(value.usage)) {
|
|
325
|
+
throw new ModelProviderError('Provider returned an invalid message delta', { retryable: false });
|
|
326
|
+
}
|
|
327
|
+
state.messageDeltaSeen = true;
|
|
328
|
+
if (typeof value.usage.output_tokens === 'number') {
|
|
329
|
+
state.outputTokens = value.usage.output_tokens;
|
|
330
|
+
state.usageSeen = true;
|
|
331
|
+
}
|
|
332
|
+
return [];
|
|
333
|
+
}
|
|
334
|
+
if (value.type === 'message_stop') {
|
|
335
|
+
if (state.blocks.size > 0 ||
|
|
336
|
+
state.tools.size > 0 ||
|
|
337
|
+
state.thinking.size > 0) {
|
|
338
|
+
throw new ModelProviderError('Provider stopped with unfinished content blocks', { retryable: false });
|
|
339
|
+
}
|
|
340
|
+
if (!state.messageDeltaSeen) {
|
|
341
|
+
throw new ModelProviderError('Provider stopped before the terminal message delta', { retryable: false });
|
|
342
|
+
}
|
|
343
|
+
state.terminal = true;
|
|
344
|
+
const events = [];
|
|
345
|
+
if (state.usageSeen) {
|
|
346
|
+
events.push({
|
|
347
|
+
type: 'usage',
|
|
348
|
+
usage: {
|
|
349
|
+
inputTokens: state.inputTokens,
|
|
350
|
+
outputTokens: state.outputTokens,
|
|
351
|
+
...(state.cacheReadInputTokens === 0
|
|
352
|
+
? {}
|
|
353
|
+
: { cacheReadInputTokens: state.cacheReadInputTokens }),
|
|
354
|
+
...(state.cacheCreationInputTokens === 0
|
|
355
|
+
? {}
|
|
356
|
+
: { cacheCreationInputTokens: state.cacheCreationInputTokens }),
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
state.usageSeen = false;
|
|
360
|
+
}
|
|
361
|
+
return events;
|
|
362
|
+
}
|
|
363
|
+
return [];
|
|
364
|
+
}
|
|
365
|
+
function serializeMediaContent(message) {
|
|
366
|
+
const blocks = message.contentBlocks
|
|
367
|
+
? [...message.contentBlocks]
|
|
368
|
+
: message.content.length > 0
|
|
369
|
+
? [{ type: 'text', text: message.content }]
|
|
370
|
+
: [];
|
|
371
|
+
const mediaKeys = new Set(blocks
|
|
372
|
+
.filter((block) => block.type !== 'text')
|
|
373
|
+
.map((block) => `${block.type}\0${block.mediaType}\0${block.data}`));
|
|
374
|
+
for (const block of [
|
|
375
|
+
...(message.images ?? []),
|
|
376
|
+
...(message.documents ?? []),
|
|
377
|
+
]) {
|
|
378
|
+
const key = `${block.type}\0${block.mediaType}\0${block.data}`;
|
|
379
|
+
if (mediaKeys.has(key))
|
|
380
|
+
continue;
|
|
381
|
+
mediaKeys.add(key);
|
|
382
|
+
blocks.push(block);
|
|
383
|
+
}
|
|
384
|
+
return blocks.map((block) => block.type === 'text'
|
|
385
|
+
? { type: 'text', text: block.text }
|
|
386
|
+
: {
|
|
387
|
+
type: block.type,
|
|
388
|
+
source: {
|
|
389
|
+
type: 'base64',
|
|
390
|
+
media_type: block.mediaType,
|
|
391
|
+
data: block.data,
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function serializeMessages(messages) {
|
|
396
|
+
const system = [];
|
|
397
|
+
const serialized = [];
|
|
398
|
+
const append = (role, content) => {
|
|
399
|
+
if (content.length === 0)
|
|
400
|
+
return;
|
|
401
|
+
const previous = serialized.at(-1);
|
|
402
|
+
if (previous?.role === role)
|
|
403
|
+
previous.content.push(...content);
|
|
404
|
+
else
|
|
405
|
+
serialized.push({ role, content });
|
|
406
|
+
};
|
|
407
|
+
for (const message of messages) {
|
|
408
|
+
if (message.role === 'system') {
|
|
409
|
+
system.push(message.content);
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (message.role === 'user') {
|
|
413
|
+
append('user', serializeMediaContent(message));
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (message.role === 'tool') {
|
|
417
|
+
if (message.contentBlocks) {
|
|
418
|
+
const content = serializeMediaContent(message);
|
|
419
|
+
append('user', [
|
|
420
|
+
{
|
|
421
|
+
type: 'tool_result',
|
|
422
|
+
tool_use_id: message.toolCallId,
|
|
423
|
+
content: content.length === 1 && content[0]?.type === 'text'
|
|
424
|
+
? content[0].text
|
|
425
|
+
: content,
|
|
426
|
+
...(message.isError ? { is_error: true } : {}),
|
|
427
|
+
},
|
|
428
|
+
]);
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
const media = serializeMediaContent({ ...message, content: '' });
|
|
432
|
+
append('user', [
|
|
433
|
+
{
|
|
434
|
+
type: 'tool_result',
|
|
435
|
+
tool_use_id: message.toolCallId,
|
|
436
|
+
content: message.content,
|
|
437
|
+
is_error: message.isError,
|
|
438
|
+
},
|
|
439
|
+
...media,
|
|
440
|
+
]);
|
|
441
|
+
}
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (message.role !== 'assistant')
|
|
445
|
+
continue;
|
|
446
|
+
const content = [];
|
|
447
|
+
for (const block of message.thinkingBlocks ?? []) {
|
|
448
|
+
if ((block.type === 'thinking' && block.signature.length === 0) ||
|
|
449
|
+
(block.type === 'redacted_thinking' && block.data.length === 0)) {
|
|
450
|
+
throw new ModelProviderError(`Cannot replay incomplete ${block.type} block`, { retryable: false });
|
|
451
|
+
}
|
|
452
|
+
content.push(block);
|
|
453
|
+
}
|
|
454
|
+
if (message.content.length > 0) {
|
|
455
|
+
content.push({ type: 'text', text: message.content });
|
|
456
|
+
}
|
|
457
|
+
for (const call of message.toolCalls ?? []) {
|
|
458
|
+
content.push({
|
|
459
|
+
type: 'tool_use',
|
|
460
|
+
id: call.id,
|
|
461
|
+
name: call.name,
|
|
462
|
+
input: call.input,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
append('assistant', content);
|
|
466
|
+
}
|
|
467
|
+
return { system: system.join('\n\n'), messages: serialized };
|
|
468
|
+
}
|
|
469
|
+
export class AnthropicCompatibleProvider {
|
|
470
|
+
options;
|
|
471
|
+
capabilities;
|
|
472
|
+
model;
|
|
473
|
+
endpoint;
|
|
474
|
+
fetchImplementation;
|
|
475
|
+
maxOutputTokens;
|
|
476
|
+
anthropicVersion;
|
|
477
|
+
maxStreamBufferBytes;
|
|
478
|
+
maxToolArgumentsBytes;
|
|
479
|
+
maxToolCallsPerResponse;
|
|
480
|
+
maxToolMetadataBytes;
|
|
481
|
+
maxErrorBodyBytes;
|
|
482
|
+
thinking;
|
|
483
|
+
constructor(options) {
|
|
484
|
+
this.options = options;
|
|
485
|
+
if (options.contextWindowTokens !== undefined) {
|
|
486
|
+
positiveInteger(options.contextWindowTokens, 'Context window tokens');
|
|
487
|
+
}
|
|
488
|
+
this.capabilities = {
|
|
489
|
+
streaming: true,
|
|
490
|
+
usage: true,
|
|
491
|
+
tools: true,
|
|
492
|
+
images: true,
|
|
493
|
+
documents: true,
|
|
494
|
+
webSearch: options.webSearch === true,
|
|
495
|
+
thinking: {
|
|
496
|
+
modes: ['enabled', 'adaptive', 'disabled'],
|
|
497
|
+
maxTokens: true,
|
|
498
|
+
},
|
|
499
|
+
...(options.contextWindowTokens === undefined
|
|
500
|
+
? {}
|
|
501
|
+
: { contextWindowTokens: options.contextWindowTokens }),
|
|
502
|
+
};
|
|
503
|
+
this.endpoint = `${options.baseUrl.replace(/\/+$/, '')}/messages`;
|
|
504
|
+
this.model = options.model;
|
|
505
|
+
this.fetchImplementation = options.fetchImplementation ?? fetch;
|
|
506
|
+
this.maxOutputTokens = positiveInteger(options.maxOutputTokens ??
|
|
507
|
+
(options.model.includes('claude-opus-4-6')
|
|
508
|
+
? 64_000
|
|
509
|
+
: options.model.startsWith('claude-')
|
|
510
|
+
? 32_000
|
|
511
|
+
: 8192), 'Max output tokens');
|
|
512
|
+
this.thinking = validateThinking(options.thinking);
|
|
513
|
+
this.anthropicVersion = options.anthropicVersion ?? '2023-06-01';
|
|
514
|
+
this.maxStreamBufferBytes = options.maxStreamBufferBytes ?? 1024 * 1024;
|
|
515
|
+
this.maxToolArgumentsBytes = options.maxToolArgumentsBytes ?? 1024 * 1024;
|
|
516
|
+
this.maxToolCallsPerResponse = options.maxToolCallsPerResponse ?? 32;
|
|
517
|
+
this.maxToolMetadataBytes = options.maxToolMetadataBytes ?? 1024 * 1024;
|
|
518
|
+
this.maxErrorBodyBytes = options.maxErrorBodyBytes ?? 64 * 1024;
|
|
519
|
+
}
|
|
520
|
+
async *complete(request) {
|
|
521
|
+
if (request.webSearch && !this.capabilities.webSearch) {
|
|
522
|
+
throw new Error('Provider does not support web search');
|
|
523
|
+
}
|
|
524
|
+
if (request.webSearch && request.tools?.length) {
|
|
525
|
+
throw new Error('Web search cannot be combined with model tools');
|
|
526
|
+
}
|
|
527
|
+
const thinking = validateThinking(request.thinking ?? this.thinking);
|
|
528
|
+
const maxTokens = Math.max(this.maxOutputTokens, thinking?.maxTokens === undefined ? 0 : thinking.maxTokens + 1);
|
|
529
|
+
const thinkingPayload = thinking === undefined
|
|
530
|
+
? undefined
|
|
531
|
+
: thinking.mode === 'disabled'
|
|
532
|
+
? { type: 'disabled' }
|
|
533
|
+
: {
|
|
534
|
+
type: 'enabled',
|
|
535
|
+
budget_tokens: thinking.maxTokens ?? maxTokens - 1,
|
|
536
|
+
};
|
|
537
|
+
const betas = [
|
|
538
|
+
...(request.betas ?? []),
|
|
539
|
+
...(thinking && thinking.mode !== 'disabled'
|
|
540
|
+
? ['interleaved-thinking-2025-05-14']
|
|
541
|
+
: []),
|
|
542
|
+
].filter((beta, index, all) => all.indexOf(beta) === index);
|
|
543
|
+
const serialized = serializeMessages(request.messages);
|
|
544
|
+
const requestInit = {
|
|
545
|
+
method: 'POST',
|
|
546
|
+
headers: {
|
|
547
|
+
'anthropic-version': this.anthropicVersion,
|
|
548
|
+
'content-type': 'application/json',
|
|
549
|
+
'x-api-key': this.options.apiKey,
|
|
550
|
+
...(betas.length ? { 'anthropic-beta': betas.join(',') } : {}),
|
|
551
|
+
},
|
|
552
|
+
body: JSON.stringify({
|
|
553
|
+
model: this.options.model,
|
|
554
|
+
max_tokens: maxTokens,
|
|
555
|
+
messages: serialized.messages,
|
|
556
|
+
stream: true,
|
|
557
|
+
...(thinkingPayload ? { thinking: thinkingPayload } : {}),
|
|
558
|
+
...(request.effort
|
|
559
|
+
? { output_config: { effort: request.effort } }
|
|
560
|
+
: {}),
|
|
561
|
+
...(serialized.system ? { system: serialized.system } : {}),
|
|
562
|
+
...(request.webSearch
|
|
563
|
+
? {
|
|
564
|
+
tools: [
|
|
565
|
+
{
|
|
566
|
+
type: 'web_search_20250305',
|
|
567
|
+
name: 'web_search',
|
|
568
|
+
...(request.webSearch.allowedDomains
|
|
569
|
+
? { allowed_domains: request.webSearch.allowedDomains }
|
|
570
|
+
: {}),
|
|
571
|
+
...(request.webSearch.blockedDomains
|
|
572
|
+
? { blocked_domains: request.webSearch.blockedDomains }
|
|
573
|
+
: {}),
|
|
574
|
+
max_uses: positiveInteger(request.webSearch.maxUses, 'Web search max uses'),
|
|
575
|
+
},
|
|
576
|
+
],
|
|
577
|
+
tool_choice: { type: 'tool', name: 'web_search' },
|
|
578
|
+
}
|
|
579
|
+
: request.tools?.length
|
|
580
|
+
? {
|
|
581
|
+
tools: request.tools.map((tool) => ({
|
|
582
|
+
name: tool.name,
|
|
583
|
+
description: tool.description,
|
|
584
|
+
input_schema: tool.inputSchema,
|
|
585
|
+
})),
|
|
586
|
+
}
|
|
587
|
+
: {}),
|
|
588
|
+
}),
|
|
589
|
+
};
|
|
590
|
+
if (request.signal)
|
|
591
|
+
requestInit.signal = request.signal;
|
|
592
|
+
let response;
|
|
593
|
+
try {
|
|
594
|
+
response = await this.fetchImplementation(this.endpoint, requestInit);
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
if (request.signal?.aborted)
|
|
598
|
+
throw error;
|
|
599
|
+
throw new ModelProviderError('Provider transport failed', {
|
|
600
|
+
retryable: true,
|
|
601
|
+
cause: error,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
if (!response.ok) {
|
|
605
|
+
let payload;
|
|
606
|
+
try {
|
|
607
|
+
const reader = response.body?.getReader();
|
|
608
|
+
if (!reader)
|
|
609
|
+
payload = null;
|
|
610
|
+
else {
|
|
611
|
+
const chunks = [];
|
|
612
|
+
let size = 0;
|
|
613
|
+
let ended = false;
|
|
614
|
+
try {
|
|
615
|
+
while (true) {
|
|
616
|
+
const { done, value } = await reader.read();
|
|
617
|
+
if (done) {
|
|
618
|
+
ended = true;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
size += value.byteLength;
|
|
622
|
+
if (size > this.maxErrorBodyBytes) {
|
|
623
|
+
throw new ModelProviderError(`Provider error response exceeded ${this.maxErrorBodyBytes} bytes`, { retryable: false, status: response.status });
|
|
624
|
+
}
|
|
625
|
+
chunks.push(value);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
finally {
|
|
629
|
+
if (!ended) {
|
|
630
|
+
try {
|
|
631
|
+
await reader.cancel();
|
|
632
|
+
}
|
|
633
|
+
catch {
|
|
634
|
+
// Preserve the primary provider error.
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
reader.releaseLock();
|
|
638
|
+
}
|
|
639
|
+
payload = JSON.parse(Buffer.concat(chunks.map((chunk) => Buffer.from(chunk))).toString('utf8'));
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
if (error instanceof ModelProviderError)
|
|
644
|
+
throw error;
|
|
645
|
+
payload = null;
|
|
646
|
+
}
|
|
647
|
+
throw new ModelProviderError(readErrorMessage(payload, response.status), {
|
|
648
|
+
retryable: isRetryableStatus(response.status),
|
|
649
|
+
status: response.status,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
if (!response.body) {
|
|
653
|
+
throw new ModelProviderError('Provider response has no body', {
|
|
654
|
+
retryable: true,
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
const reader = response.body.getReader();
|
|
658
|
+
const decoder = new TextDecoder();
|
|
659
|
+
let buffer = '';
|
|
660
|
+
const state = {
|
|
661
|
+
blocks: new Map(),
|
|
662
|
+
thinking: new Map(),
|
|
663
|
+
tools: new Map(),
|
|
664
|
+
toolCallsSeen: 0,
|
|
665
|
+
metadataBytes: 0,
|
|
666
|
+
inputTokens: 0,
|
|
667
|
+
cacheReadInputTokens: 0,
|
|
668
|
+
cacheCreationInputTokens: 0,
|
|
669
|
+
outputTokens: 0,
|
|
670
|
+
usageSeen: false,
|
|
671
|
+
messageStarted: false,
|
|
672
|
+
messageDeltaSeen: false,
|
|
673
|
+
terminal: false,
|
|
674
|
+
};
|
|
675
|
+
let streamEnded = false;
|
|
676
|
+
try {
|
|
677
|
+
stream: while (true) {
|
|
678
|
+
const { done, value } = await reader.read();
|
|
679
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
680
|
+
buffer = buffer.replaceAll('\r\n', '\n');
|
|
681
|
+
if (Buffer.byteLength(buffer) > this.maxStreamBufferBytes) {
|
|
682
|
+
throw new ModelProviderError(`Provider stream buffer exceeded ${this.maxStreamBufferBytes} bytes`, { retryable: false });
|
|
683
|
+
}
|
|
684
|
+
let boundary = buffer.indexOf('\n\n');
|
|
685
|
+
while (boundary >= 0) {
|
|
686
|
+
const block = buffer.slice(0, boundary);
|
|
687
|
+
buffer = buffer.slice(boundary + 2);
|
|
688
|
+
const data = block
|
|
689
|
+
.split('\n')
|
|
690
|
+
.filter((line) => line.startsWith('data:'))
|
|
691
|
+
.map((line) => line.slice(5).trimStart())
|
|
692
|
+
.join('\n');
|
|
693
|
+
if (data.length > 0) {
|
|
694
|
+
for (const event of parseSseEvent(data, state, this.maxToolArgumentsBytes, this.maxToolCallsPerResponse, this.maxToolMetadataBytes)) {
|
|
695
|
+
yield event;
|
|
696
|
+
}
|
|
697
|
+
if (state.terminal)
|
|
698
|
+
break stream;
|
|
699
|
+
}
|
|
700
|
+
boundary = buffer.indexOf('\n\n');
|
|
701
|
+
}
|
|
702
|
+
if (done) {
|
|
703
|
+
streamEnded = true;
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (!state.terminal) {
|
|
708
|
+
throw new ModelProviderError('Provider stream ended before a terminal event', { retryable: true });
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
catch (error) {
|
|
712
|
+
if (error instanceof ModelProviderError || request.signal?.aborted) {
|
|
713
|
+
throw error;
|
|
714
|
+
}
|
|
715
|
+
throw new ModelProviderError('Provider stream failed', {
|
|
716
|
+
retryable: true,
|
|
717
|
+
cause: error,
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
finally {
|
|
721
|
+
if (!streamEnded) {
|
|
722
|
+
try {
|
|
723
|
+
await reader.cancel();
|
|
724
|
+
}
|
|
725
|
+
catch {
|
|
726
|
+
// Preserve the primary provider error or consumer return.
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
reader.releaseLock();
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
//# sourceMappingURL=anthropic-compatible.js.map
|