@roj-ai/sdk 0.0.2
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/dist/bootstrap.d.ts +453 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/builtin-events.d.ts +16 -0
- package/dist/builtin-events.d.ts.map +1 -0
- package/dist/bun-platform/fs.d.ts +9 -0
- package/dist/bun-platform/fs.d.ts.map +1 -0
- package/dist/bun-platform/index.d.ts +12 -0
- package/dist/bun-platform/index.d.ts.map +1 -0
- package/dist/bun-platform/process.d.ts +6 -0
- package/dist/bun-platform/process.d.ts.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.test.d.ts +2 -0
- package/dist/config.test.d.ts.map +1 -0
- package/dist/core/agent-loop.integration.test.d.ts +2 -0
- package/dist/core/agent-loop.integration.test.d.ts.map +1 -0
- package/dist/core/agents/agent-config.test.d.ts +2 -0
- package/dist/core/agents/agent-config.test.d.ts.map +1 -0
- package/dist/core/agents/agent-roles.d.ts +33 -0
- package/dist/core/agents/agent-roles.d.ts.map +1 -0
- package/dist/core/agents/agent-shutdown.test.d.ts +6 -0
- package/dist/core/agents/agent-shutdown.test.d.ts.map +1 -0
- package/dist/core/agents/agent.d.ts +234 -0
- package/dist/core/agents/agent.d.ts.map +1 -0
- package/dist/core/agents/agent.test.d.ts +2 -0
- package/dist/core/agents/agent.test.d.ts.map +1 -0
- package/dist/core/agents/communicator.d.ts +3 -0
- package/dist/core/agents/communicator.d.ts.map +1 -0
- package/dist/core/agents/config.d.ts +84 -0
- package/dist/core/agents/config.d.ts.map +1 -0
- package/dist/core/agents/context.d.ts +16 -0
- package/dist/core/agents/context.d.ts.map +1 -0
- package/dist/core/agents/debounce.d.ts +52 -0
- package/dist/core/agents/debounce.d.ts.map +1 -0
- package/dist/core/agents/handler-events.test.d.ts +5 -0
- package/dist/core/agents/handler-events.test.d.ts.map +1 -0
- package/dist/core/agents/index.d.ts +2 -0
- package/dist/core/agents/index.d.ts.map +1 -0
- package/dist/core/agents/response-sanitizer.d.ts +25 -0
- package/dist/core/agents/response-sanitizer.d.ts.map +1 -0
- package/dist/core/agents/response-sanitizer.test.d.ts +2 -0
- package/dist/core/agents/response-sanitizer.test.d.ts.map +1 -0
- package/dist/core/agents/retry.d.ts +40 -0
- package/dist/core/agents/retry.d.ts.map +1 -0
- package/dist/core/agents/schema.d.ts +57 -0
- package/dist/core/agents/schema.d.ts.map +1 -0
- package/dist/core/agents/state.d.ts +255 -0
- package/dist/core/agents/state.d.ts.map +1 -0
- package/dist/core/context/state.d.ts +28 -0
- package/dist/core/context/state.d.ts.map +1 -0
- package/dist/core/errors.d.ts +29 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/event-sourcing.integration.test.d.ts +2 -0
- package/dist/core/event-sourcing.integration.test.d.ts.map +1 -0
- package/dist/core/events/base-event-store.d.ts +55 -0
- package/dist/core/events/base-event-store.d.ts.map +1 -0
- package/dist/core/events/event-store.d.ts +108 -0
- package/dist/core/events/event-store.d.ts.map +1 -0
- package/dist/core/events/file.d.ts +50 -0
- package/dist/core/events/file.d.ts.map +1 -0
- package/dist/core/events/file.test.d.ts +2 -0
- package/dist/core/events/file.test.d.ts.map +1 -0
- package/dist/core/events/index.d.ts +4 -0
- package/dist/core/events/index.d.ts.map +1 -0
- package/dist/core/events/memory.d.ts +43 -0
- package/dist/core/events/memory.d.ts.map +1 -0
- package/dist/core/events/memory.test.d.ts +2 -0
- package/dist/core/events/memory.test.d.ts.map +1 -0
- package/dist/core/events/metadata-utils.d.ts +27 -0
- package/dist/core/events/metadata-utils.d.ts.map +1 -0
- package/dist/core/events/test-helpers.d.ts +28 -0
- package/dist/core/events/test-helpers.d.ts.map +1 -0
- package/dist/core/events/types.d.ts +46 -0
- package/dist/core/events/types.d.ts.map +1 -0
- package/dist/core/file-store/file-store.d.ts +56 -0
- package/dist/core/file-store/file-store.d.ts.map +1 -0
- package/dist/core/file-store/types.d.ts +50 -0
- package/dist/core/file-store/types.d.ts.map +1 -0
- package/dist/core/image/image-processor.d.ts +15 -0
- package/dist/core/image/image-processor.d.ts.map +1 -0
- package/dist/core/image/image-processor.test.d.ts +2 -0
- package/dist/core/image/image-processor.test.d.ts.map +1 -0
- package/dist/core/image/index.d.ts +5 -0
- package/dist/core/image/index.d.ts.map +1 -0
- package/dist/core/image/noop-resizer.d.ts +5 -0
- package/dist/core/image/noop-resizer.d.ts.map +1 -0
- package/dist/core/image/types.d.ts +20 -0
- package/dist/core/image/types.d.ts.map +1 -0
- package/dist/core/image/vips-resizer.d.ts +21 -0
- package/dist/core/image/vips-resizer.d.ts.map +1 -0
- package/dist/core/image/vips-resizer.test.d.ts +2 -0
- package/dist/core/image/vips-resizer.test.d.ts.map +1 -0
- package/dist/core/llm/anthropic.d.ts +51 -0
- package/dist/core/llm/anthropic.d.ts.map +1 -0
- package/dist/core/llm/anthropic.test.d.ts +2 -0
- package/dist/core/llm/anthropic.test.d.ts.map +1 -0
- package/dist/core/llm/cache-breakpoints.d.ts +17 -0
- package/dist/core/llm/cache-breakpoints.d.ts.map +1 -0
- package/dist/core/llm/cache-live.test.d.ts +16 -0
- package/dist/core/llm/cache-live.test.d.ts.map +1 -0
- package/dist/core/llm/index.d.ts +16 -0
- package/dist/core/llm/index.d.ts.map +1 -0
- package/dist/core/llm/llm-log-types.d.ts +148 -0
- package/dist/core/llm/llm-log-types.d.ts.map +1 -0
- package/dist/core/llm/logger.d.ts +74 -0
- package/dist/core/llm/logger.d.ts.map +1 -0
- package/dist/core/llm/logger.test.d.ts +7 -0
- package/dist/core/llm/logger.test.d.ts.map +1 -0
- package/dist/core/llm/logging-provider.d.ts +20 -0
- package/dist/core/llm/logging-provider.d.ts.map +1 -0
- package/dist/core/llm/middleware.d.ts +79 -0
- package/dist/core/llm/middleware.d.ts.map +1 -0
- package/dist/core/llm/mock.d.ts +79 -0
- package/dist/core/llm/mock.d.ts.map +1 -0
- package/dist/core/llm/mock.test.d.ts +2 -0
- package/dist/core/llm/mock.test.d.ts.map +1 -0
- package/dist/core/llm/openrouter-mapping.test.d.ts +2 -0
- package/dist/core/llm/openrouter-mapping.test.d.ts.map +1 -0
- package/dist/core/llm/openrouter.d.ts +37 -0
- package/dist/core/llm/openrouter.d.ts.map +1 -0
- package/dist/core/llm/openrouter.test.d.ts +2 -0
- package/dist/core/llm/openrouter.test.d.ts.map +1 -0
- package/dist/core/llm/provider-integration.test.d.ts +12 -0
- package/dist/core/llm/provider-integration.test.d.ts.map +1 -0
- package/dist/core/llm/provider.d.ts +175 -0
- package/dist/core/llm/provider.d.ts.map +1 -0
- package/dist/core/llm/routing-provider.d.ts +31 -0
- package/dist/core/llm/routing-provider.d.ts.map +1 -0
- package/dist/core/llm/routing-provider.test.d.ts +2 -0
- package/dist/core/llm/routing-provider.test.d.ts.map +1 -0
- package/dist/core/llm/schema.d.ts +24 -0
- package/dist/core/llm/schema.d.ts.map +1 -0
- package/dist/core/llm/snapshot-fetch.d.ts +21 -0
- package/dist/core/llm/snapshot-fetch.d.ts.map +1 -0
- package/dist/core/llm/snapshot-middleware.d.ts +71 -0
- package/dist/core/llm/snapshot-middleware.d.ts.map +1 -0
- package/dist/core/llm/snapshot-middleware.test.d.ts +2 -0
- package/dist/core/llm/snapshot-middleware.test.d.ts.map +1 -0
- package/dist/core/llm/state.d.ts +73 -0
- package/dist/core/llm/state.d.ts.map +1 -0
- package/dist/core/llm/tokens.d.ts +36 -0
- package/dist/core/llm/tokens.d.ts.map +1 -0
- package/dist/core/multi-agent.integration.test.d.ts +2 -0
- package/dist/core/multi-agent.integration.test.d.ts.map +1 -0
- package/dist/core/plugin-hooks.integration.test.d.ts +2 -0
- package/dist/core/plugin-hooks.integration.test.d.ts.map +1 -0
- package/dist/core/plugins/hook-types.d.ts +55 -0
- package/dist/core/plugins/hook-types.d.ts.map +1 -0
- package/dist/core/plugins/index.d.ts +23 -0
- package/dist/core/plugins/index.d.ts.map +1 -0
- package/dist/core/plugins/plugin-builder.d.ts +474 -0
- package/dist/core/plugins/plugin-builder.d.ts.map +1 -0
- package/dist/core/preset/config.d.ts +55 -0
- package/dist/core/preset/config.d.ts.map +1 -0
- package/dist/core/preset/index.d.ts +8 -0
- package/dist/core/preset/index.d.ts.map +1 -0
- package/dist/core/preset/preset-builder.d.ts +44 -0
- package/dist/core/preset/preset-builder.d.ts.map +1 -0
- package/dist/core/session-lifecycle.integration.test.d.ts +2 -0
- package/dist/core/session-lifecycle.integration.test.d.ts.map +1 -0
- package/dist/core/sessions/apply-event.d.ts +19 -0
- package/dist/core/sessions/apply-event.d.ts.map +1 -0
- package/dist/core/sessions/context.d.ts +34 -0
- package/dist/core/sessions/context.d.ts.map +1 -0
- package/dist/core/sessions/fork-utils.d.ts +20 -0
- package/dist/core/sessions/fork-utils.d.ts.map +1 -0
- package/dist/core/sessions/fork-utils.test.d.ts +2 -0
- package/dist/core/sessions/fork-utils.test.d.ts.map +1 -0
- package/dist/core/sessions/reducer.d.ts +50 -0
- package/dist/core/sessions/reducer.d.ts.map +1 -0
- package/dist/core/sessions/schema.d.ts +82 -0
- package/dist/core/sessions/schema.d.ts.map +1 -0
- package/dist/core/sessions/session-environment.d.ts +13 -0
- package/dist/core/sessions/session-environment.d.ts.map +1 -0
- package/dist/core/sessions/session-manager.d.ts +183 -0
- package/dist/core/sessions/session-manager.d.ts.map +1 -0
- package/dist/core/sessions/session-store.d.ts +69 -0
- package/dist/core/sessions/session-store.d.ts.map +1 -0
- package/dist/core/sessions/session.d.ts +212 -0
- package/dist/core/sessions/session.d.ts.map +1 -0
- package/dist/core/sessions/session.test.d.ts +2 -0
- package/dist/core/sessions/session.test.d.ts.map +1 -0
- package/dist/core/sessions/state.d.ts +110 -0
- package/dist/core/sessions/state.d.ts.map +1 -0
- package/dist/core/system.d.ts +97 -0
- package/dist/core/system.d.ts.map +1 -0
- package/dist/core/tools/context.d.ts +3 -0
- package/dist/core/tools/context.d.ts.map +1 -0
- package/dist/core/tools/definition.d.ts +10 -0
- package/dist/core/tools/definition.d.ts.map +1 -0
- package/dist/core/tools/executor.d.ts +28 -0
- package/dist/core/tools/executor.d.ts.map +1 -0
- package/dist/core/tools/executor.test.d.ts +2 -0
- package/dist/core/tools/executor.test.d.ts.map +1 -0
- package/dist/core/tools/index.d.ts +4 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/schema.d.ts +61 -0
- package/dist/core/tools/schema.d.ts.map +1 -0
- package/dist/core/tools/state.d.ts +28 -0
- package/dist/core/tools/state.d.ts.map +1 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/json/index.d.ts +17 -0
- package/dist/lib/json/index.d.ts.map +1 -0
- package/dist/lib/logger/console.d.ts +35 -0
- package/dist/lib/logger/console.d.ts.map +1 -0
- package/dist/lib/logger/console.test.d.ts +2 -0
- package/dist/lib/logger/console.test.d.ts.map +1 -0
- package/dist/lib/logger/file.d.ts +20 -0
- package/dist/lib/logger/file.d.ts.map +1 -0
- package/dist/lib/logger/index.d.ts +5 -0
- package/dist/lib/logger/index.d.ts.map +1 -0
- package/dist/lib/logger/logger.d.ts +87 -0
- package/dist/lib/logger/logger.d.ts.map +1 -0
- package/dist/lib/logger/ring-buffer.d.ts +33 -0
- package/dist/lib/logger/ring-buffer.d.ts.map +1 -0
- package/dist/lib/logger/tee.d.ts +15 -0
- package/dist/lib/logger/tee.d.ts.map +1 -0
- package/dist/lib/mime.d.ts +9 -0
- package/dist/lib/mime.d.ts.map +1 -0
- package/dist/lib/never.d.ts +2 -0
- package/dist/lib/never.d.ts.map +1 -0
- package/dist/lib/utils/hash.d.ts +19 -0
- package/dist/lib/utils/hash.d.ts.map +1 -0
- package/dist/lib/utils/result.d.ts +26 -0
- package/dist/lib/utils/result.d.ts.map +1 -0
- package/dist/platform/fs.d.ts +39 -0
- package/dist/platform/fs.d.ts.map +1 -0
- package/dist/platform/index.d.ts +21 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/process.d.ts +24 -0
- package/dist/platform/process.d.ts.map +1 -0
- package/dist/plugins/agent-status/plugin.d.ts +8 -0
- package/dist/plugins/agent-status/plugin.d.ts.map +1 -0
- package/dist/plugins/agents/agents.integration.test.d.ts +2 -0
- package/dist/plugins/agents/agents.integration.test.d.ts.map +1 -0
- package/dist/plugins/agents/index.d.ts +3 -0
- package/dist/plugins/agents/index.d.ts.map +1 -0
- package/dist/plugins/agents/plugin.d.ts +57 -0
- package/dist/plugins/agents/plugin.d.ts.map +1 -0
- package/dist/plugins/context-compact/context-compact.integration.test.d.ts +2 -0
- package/dist/plugins/context-compact/context-compact.integration.test.d.ts.map +1 -0
- package/dist/plugins/context-compact/context-compactor.d.ts +88 -0
- package/dist/plugins/context-compact/context-compactor.d.ts.map +1 -0
- package/dist/plugins/context-compact/context-compactor.test.d.ts +2 -0
- package/dist/plugins/context-compact/context-compactor.test.d.ts.map +1 -0
- package/dist/plugins/context-compact/history-offloader.d.ts +17 -0
- package/dist/plugins/context-compact/history-offloader.d.ts.map +1 -0
- package/dist/plugins/context-compact/history-offloader.test.d.ts +2 -0
- package/dist/plugins/context-compact/history-offloader.test.d.ts.map +1 -0
- package/dist/plugins/context-compact/index.d.ts +4 -0
- package/dist/plugins/context-compact/index.d.ts.map +1 -0
- package/dist/plugins/context-compact/plugin.d.ts +15 -0
- package/dist/plugins/context-compact/plugin.d.ts.map +1 -0
- package/dist/plugins/filesystem/filesystem.integration.test.d.ts +2 -0
- package/dist/plugins/filesystem/filesystem.integration.test.d.ts.map +1 -0
- package/dist/plugins/filesystem/helpers.d.ts +34 -0
- package/dist/plugins/filesystem/helpers.d.ts.map +1 -0
- package/dist/plugins/filesystem/index.d.ts +5 -0
- package/dist/plugins/filesystem/index.d.ts.map +1 -0
- package/dist/plugins/filesystem/listing.d.ts +38 -0
- package/dist/plugins/filesystem/listing.d.ts.map +1 -0
- package/dist/plugins/filesystem/plugin.d.ts +53 -0
- package/dist/plugins/filesystem/plugin.d.ts.map +1 -0
- package/dist/plugins/filesystem/schema.d.ts +7 -0
- package/dist/plugins/filesystem/schema.d.ts.map +1 -0
- package/dist/plugins/git-status/index.d.ts +2 -0
- package/dist/plugins/git-status/index.d.ts.map +1 -0
- package/dist/plugins/git-status/plugin.d.ts +12 -0
- package/dist/plugins/git-status/plugin.d.ts.map +1 -0
- package/dist/plugins/limits-guard/config.d.ts +23 -0
- package/dist/plugins/limits-guard/config.d.ts.map +1 -0
- package/dist/plugins/limits-guard/index.d.ts +5 -0
- package/dist/plugins/limits-guard/index.d.ts.map +1 -0
- package/dist/plugins/limits-guard/limit-guard.d.ts +40 -0
- package/dist/plugins/limits-guard/limit-guard.d.ts.map +1 -0
- package/dist/plugins/limits-guard/limit-guard.test.d.ts +2 -0
- package/dist/plugins/limits-guard/limit-guard.test.d.ts.map +1 -0
- package/dist/plugins/limits-guard/limits-guard.integration.test.d.ts +2 -0
- package/dist/plugins/limits-guard/limits-guard.integration.test.d.ts.map +1 -0
- package/dist/plugins/limits-guard/plugin.d.ts +39 -0
- package/dist/plugins/limits-guard/plugin.d.ts.map +1 -0
- package/dist/plugins/llm-debug/index.d.ts +2 -0
- package/dist/plugins/llm-debug/index.d.ts.map +1 -0
- package/dist/plugins/llm-debug/llm-debug.integration.test.d.ts +2 -0
- package/dist/plugins/llm-debug/llm-debug.integration.test.d.ts.map +1 -0
- package/dist/plugins/llm-debug/plugin.d.ts +31 -0
- package/dist/plugins/llm-debug/plugin.d.ts.map +1 -0
- package/dist/plugins/logs/index.d.ts +2 -0
- package/dist/plugins/logs/index.d.ts.map +1 -0
- package/dist/plugins/logs/plugin.d.ts +10 -0
- package/dist/plugins/logs/plugin.d.ts.map +1 -0
- package/dist/plugins/mailbox/helpers.d.ts +20 -0
- package/dist/plugins/mailbox/helpers.d.ts.map +1 -0
- package/dist/plugins/mailbox/index.d.ts +9 -0
- package/dist/plugins/mailbox/index.d.ts.map +1 -0
- package/dist/plugins/mailbox/mailbox.integration.test.d.ts +2 -0
- package/dist/plugins/mailbox/mailbox.integration.test.d.ts.map +1 -0
- package/dist/plugins/mailbox/plugin.d.ts +31 -0
- package/dist/plugins/mailbox/plugin.d.ts.map +1 -0
- package/dist/plugins/mailbox/prompts.d.ts +21 -0
- package/dist/plugins/mailbox/prompts.d.ts.map +1 -0
- package/dist/plugins/mailbox/query.d.ts +33 -0
- package/dist/plugins/mailbox/query.d.ts.map +1 -0
- package/dist/plugins/mailbox/schema.d.ts +54 -0
- package/dist/plugins/mailbox/schema.d.ts.map +1 -0
- package/dist/plugins/mailbox/state.d.ts +40 -0
- package/dist/plugins/mailbox/state.d.ts.map +1 -0
- package/dist/plugins/resources/index.d.ts +7 -0
- package/dist/plugins/resources/index.d.ts.map +1 -0
- package/dist/plugins/resources/manifest.d.ts +23 -0
- package/dist/plugins/resources/manifest.d.ts.map +1 -0
- package/dist/plugins/resources/plugin.d.ts +28 -0
- package/dist/plugins/resources/plugin.d.ts.map +1 -0
- package/dist/plugins/resources/post-inject.d.ts +39 -0
- package/dist/plugins/resources/post-inject.d.ts.map +1 -0
- package/dist/plugins/resources/state.d.ts +25 -0
- package/dist/plugins/resources/state.d.ts.map +1 -0
- package/dist/plugins/result-eviction/index.d.ts +3 -0
- package/dist/plugins/result-eviction/index.d.ts.map +1 -0
- package/dist/plugins/result-eviction/plugin.d.ts +19 -0
- package/dist/plugins/result-eviction/plugin.d.ts.map +1 -0
- package/dist/plugins/result-eviction/result-eviction.integration.test.d.ts +2 -0
- package/dist/plugins/result-eviction/result-eviction.integration.test.d.ts.map +1 -0
- package/dist/plugins/services/plugin.d.ts +85 -0
- package/dist/plugins/services/plugin.d.ts.map +1 -0
- package/dist/plugins/services/port-pool.d.ts +32 -0
- package/dist/plugins/services/port-pool.d.ts.map +1 -0
- package/dist/plugins/services/prompt.d.ts +13 -0
- package/dist/plugins/services/prompt.d.ts.map +1 -0
- package/dist/plugins/services/schema.d.ts +70 -0
- package/dist/plugins/services/schema.d.ts.map +1 -0
- package/dist/plugins/services/service.d.ts +86 -0
- package/dist/plugins/services/service.d.ts.map +1 -0
- package/dist/plugins/services/services.integration.test.d.ts +2 -0
- package/dist/plugins/services/services.integration.test.d.ts.map +1 -0
- package/dist/plugins/session-lifecycle/index.d.ts +2 -0
- package/dist/plugins/session-lifecycle/index.d.ts.map +1 -0
- package/dist/plugins/session-lifecycle/plugin.d.ts +97 -0
- package/dist/plugins/session-lifecycle/plugin.d.ts.map +1 -0
- package/dist/plugins/session-lifecycle/session-lifecycle.integration.test.d.ts +2 -0
- package/dist/plugins/session-lifecycle/session-lifecycle.integration.test.d.ts.map +1 -0
- package/dist/plugins/session-state/plugin.d.ts +48 -0
- package/dist/plugins/session-state/plugin.d.ts.map +1 -0
- package/dist/plugins/session-stats/index.d.ts +4 -0
- package/dist/plugins/session-stats/index.d.ts.map +1 -0
- package/dist/plugins/session-stats/plugin.d.ts +29 -0
- package/dist/plugins/session-stats/plugin.d.ts.map +1 -0
- package/dist/plugins/shell/executor.d.ts +78 -0
- package/dist/plugins/shell/executor.d.ts.map +1 -0
- package/dist/plugins/shell/index.d.ts +6 -0
- package/dist/plugins/shell/index.d.ts.map +1 -0
- package/dist/plugins/shell/plugin.d.ts +51 -0
- package/dist/plugins/shell/plugin.d.ts.map +1 -0
- package/dist/plugins/shell/shell.integration.test.d.ts +2 -0
- package/dist/plugins/shell/shell.integration.test.d.ts.map +1 -0
- package/dist/plugins/shell/shell.test.d.ts +2 -0
- package/dist/plugins/shell/shell.test.d.ts.map +1 -0
- package/dist/plugins/skills/discovery.d.ts +69 -0
- package/dist/plugins/skills/discovery.d.ts.map +1 -0
- package/dist/plugins/skills/discovery.test.d.ts +2 -0
- package/dist/plugins/skills/discovery.test.d.ts.map +1 -0
- package/dist/plugins/skills/index.d.ts +11 -0
- package/dist/plugins/skills/index.d.ts.map +1 -0
- package/dist/plugins/skills/plugin.d.ts +94 -0
- package/dist/plugins/skills/plugin.d.ts.map +1 -0
- package/dist/plugins/skills/prompts.d.ts +29 -0
- package/dist/plugins/skills/prompts.d.ts.map +1 -0
- package/dist/plugins/skills/schema.d.ts +64 -0
- package/dist/plugins/skills/schema.d.ts.map +1 -0
- package/dist/plugins/skills/skills.integration.test.d.ts +2 -0
- package/dist/plugins/skills/skills.integration.test.d.ts.map +1 -0
- package/dist/plugins/snapshotting/index.d.ts +4 -0
- package/dist/plugins/snapshotting/index.d.ts.map +1 -0
- package/dist/plugins/snapshotting/jj-snapshotter.d.ts +27 -0
- package/dist/plugins/snapshotting/jj-snapshotter.d.ts.map +1 -0
- package/dist/plugins/snapshotting/plugin.d.ts +15 -0
- package/dist/plugins/snapshotting/plugin.d.ts.map +1 -0
- package/dist/plugins/snapshotting/snapshotter.d.ts +19 -0
- package/dist/plugins/snapshotting/snapshotter.d.ts.map +1 -0
- package/dist/plugins/todo/index.d.ts +7 -0
- package/dist/plugins/todo/index.d.ts.map +1 -0
- package/dist/plugins/todo/plugin.d.ts +95 -0
- package/dist/plugins/todo/plugin.d.ts.map +1 -0
- package/dist/plugins/todo/prompts.d.ts +13 -0
- package/dist/plugins/todo/prompts.d.ts.map +1 -0
- package/dist/plugins/todo/schema.d.ts +44 -0
- package/dist/plugins/todo/schema.d.ts.map +1 -0
- package/dist/plugins/todo/todo.integration.test.d.ts +2 -0
- package/dist/plugins/todo/todo.integration.test.d.ts.map +1 -0
- package/dist/plugins/uploads/index.d.ts +9 -0
- package/dist/plugins/uploads/index.d.ts.map +1 -0
- package/dist/plugins/uploads/plugin.d.ts +56 -0
- package/dist/plugins/uploads/plugin.d.ts.map +1 -0
- package/dist/plugins/uploads/preprocessor.d.ts +70 -0
- package/dist/plugins/uploads/preprocessor.d.ts.map +1 -0
- package/dist/plugins/uploads/preprocessors/image-classifier.d.ts +49 -0
- package/dist/plugins/uploads/preprocessors/image-classifier.d.ts.map +1 -0
- package/dist/plugins/uploads/preprocessors/index.d.ts +7 -0
- package/dist/plugins/uploads/preprocessors/index.d.ts.map +1 -0
- package/dist/plugins/uploads/preprocessors/markitdown-preprocessor.d.ts +43 -0
- package/dist/plugins/uploads/preprocessors/markitdown-preprocessor.d.ts.map +1 -0
- package/dist/plugins/uploads/preprocessors/zip-preprocessor.d.ts +30 -0
- package/dist/plugins/uploads/preprocessors/zip-preprocessor.d.ts.map +1 -0
- package/dist/plugins/uploads/schema.d.ts +72 -0
- package/dist/plugins/uploads/schema.d.ts.map +1 -0
- package/dist/plugins/uploads/state.d.ts +38 -0
- package/dist/plugins/uploads/state.d.ts.map +1 -0
- package/dist/plugins/uploads/uploads.integration.test.d.ts +2 -0
- package/dist/plugins/uploads/uploads.integration.test.d.ts.map +1 -0
- package/dist/plugins/user-chat/index.d.ts +7 -0
- package/dist/plugins/user-chat/index.d.ts.map +1 -0
- package/dist/plugins/user-chat/plugin.d.ts +221 -0
- package/dist/plugins/user-chat/plugin.d.ts.map +1 -0
- package/dist/plugins/user-chat/prompts.d.ts +13 -0
- package/dist/plugins/user-chat/prompts.d.ts.map +1 -0
- package/dist/plugins/user-chat/schema.d.ts +82 -0
- package/dist/plugins/user-chat/schema.d.ts.map +1 -0
- package/dist/plugins/user-chat/user-chat.integration.test.d.ts +2 -0
- package/dist/plugins/user-chat/user-chat.integration.test.d.ts.map +1 -0
- package/dist/plugins/workers/context.d.ts +159 -0
- package/dist/plugins/workers/context.d.ts.map +1 -0
- package/dist/plugins/workers/definition.d.ts +118 -0
- package/dist/plugins/workers/definition.d.ts.map +1 -0
- package/dist/plugins/workers/index.d.ts +11 -0
- package/dist/plugins/workers/index.d.ts.map +1 -0
- package/dist/plugins/workers/plugin.d.ts +125 -0
- package/dist/plugins/workers/plugin.d.ts.map +1 -0
- package/dist/plugins/workers/worker.d.ts +76 -0
- package/dist/plugins/workers/worker.d.ts.map +1 -0
- package/dist/plugins/workers/workers.integration.test.d.ts +2 -0
- package/dist/plugins/workers/workers.integration.test.d.ts.map +1 -0
- package/dist/prompts/base.d.ts +75 -0
- package/dist/prompts/base.d.ts.map +1 -0
- package/dist/prompts/builder.d.ts +73 -0
- package/dist/prompts/builder.d.ts.map +1 -0
- package/dist/prompts/index.d.ts +10 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/macros.d.ts +15 -0
- package/dist/prompts/macros.d.ts.map +1 -0
- package/dist/prompts/macros.test.d.ts +2 -0
- package/dist/prompts/macros.test.d.ts.map +1 -0
- package/dist/testing/bootstrap-for-testing.d.ts +12 -0
- package/dist/testing/bootstrap-for-testing.d.ts.map +1 -0
- package/dist/testing/index.d.ts +8 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/node-platform.d.ts +12 -0
- package/dist/testing/node-platform.d.ts.map +1 -0
- package/dist/testing/notification-collector.d.ts +46 -0
- package/dist/testing/notification-collector.d.ts.map +1 -0
- package/dist/testing/preset-helpers.d.ts +28 -0
- package/dist/testing/preset-helpers.d.ts.map +1 -0
- package/dist/testing/test-harness.d.ts +117 -0
- package/dist/testing/test-harness.d.ts.map +1 -0
- package/dist/testing/test-harness.test.d.ts +2 -0
- package/dist/testing/test-harness.test.d.ts.map +1 -0
- package/dist/testing/wait-helpers.d.ts +17 -0
- package/dist/testing/wait-helpers.d.ts.map +1 -0
- package/dist/transport/adapter/client-adapter.d.ts +32 -0
- package/dist/transport/adapter/client-adapter.d.ts.map +1 -0
- package/dist/transport/adapter/index.d.ts +23 -0
- package/dist/transport/adapter/index.d.ts.map +1 -0
- package/dist/transport/adapter/server-adapter.d.ts +29 -0
- package/dist/transport/adapter/server-adapter.d.ts.map +1 -0
- package/dist/transport/adapter/types.d.ts +14 -0
- package/dist/transport/adapter/types.d.ts.map +1 -0
- package/dist/transport/http/app.d.ts +41 -0
- package/dist/transport/http/app.d.ts.map +1 -0
- package/dist/transport/http/index.d.ts +7 -0
- package/dist/transport/http/index.d.ts.map +1 -0
- package/dist/transport/http/middleware/bearer-auth.d.ts +16 -0
- package/dist/transport/http/middleware/bearer-auth.d.ts.map +1 -0
- package/dist/transport/http/middleware/error-handler.d.ts +21 -0
- package/dist/transport/http/middleware/error-handler.d.ts.map +1 -0
- package/dist/transport/http/routes/files.d.ts +16 -0
- package/dist/transport/http/routes/files.d.ts.map +1 -0
- package/dist/transport/http/routes/resources.d.ts +12 -0
- package/dist/transport/http/routes/resources.d.ts.map +1 -0
- package/dist/transport/http/routes/rpc.d.ts +22 -0
- package/dist/transport/http/routes/rpc.d.ts.map +1 -0
- package/dist/transport/http/routes/rpc.integration.test.d.ts +2 -0
- package/dist/transport/http/routes/rpc.integration.test.d.ts.map +1 -0
- package/dist/transport/http/routes/rpc.test.d.ts +2 -0
- package/dist/transport/http/routes/rpc.test.d.ts.map +1 -0
- package/dist/transport/http/routes/upload.d.ts +14 -0
- package/dist/transport/http/routes/upload.d.ts.map +1 -0
- package/dist/transport/rpc/index.d.ts +8 -0
- package/dist/transport/rpc/index.d.ts.map +1 -0
- package/dist/transport/rpc/methods.d.ts +25 -0
- package/dist/transport/rpc/methods.d.ts.map +1 -0
- package/dist/user-config.d.ts +29 -0
- package/dist/user-config.d.ts.map +1 -0
- package/package.json +154 -0
- package/src/bootstrap.ts +268 -0
- package/src/builtin-events.ts +25 -0
- package/src/bun-platform/fs.ts +50 -0
- package/src/bun-platform/index.ts +21 -0
- package/src/bun-platform/process.ts +25 -0
- package/src/config.test.ts +174 -0
- package/src/config.ts +103 -0
- package/src/core/agent-loop.integration.test.ts +503 -0
- package/src/core/agents/agent-config.test.ts +240 -0
- package/src/core/agents/agent-roles.ts +41 -0
- package/src/core/agents/agent-shutdown.test.ts +236 -0
- package/src/core/agents/agent.test.ts +387 -0
- package/src/core/agents/agent.ts +1472 -0
- package/src/core/agents/communicator.ts +16 -0
- package/src/core/agents/config.ts +98 -0
- package/src/core/agents/context.ts +19 -0
- package/src/core/agents/debounce.ts +116 -0
- package/src/core/agents/handler-events.test.ts +167 -0
- package/src/core/agents/index.ts +1 -0
- package/src/core/agents/response-sanitizer.test.ts +137 -0
- package/src/core/agents/response-sanitizer.ts +67 -0
- package/src/core/agents/retry.ts +164 -0
- package/src/core/agents/schema.ts +75 -0
- package/src/core/agents/state.ts +272 -0
- package/src/core/context/state.ts +38 -0
- package/src/core/errors.ts +55 -0
- package/src/core/event-sourcing.integration.test.ts +191 -0
- package/src/core/events/base-event-store.ts +264 -0
- package/src/core/events/event-store.ts +143 -0
- package/src/core/events/file.test.ts +436 -0
- package/src/core/events/file.ts +372 -0
- package/src/core/events/index.ts +3 -0
- package/src/core/events/memory.test.ts +741 -0
- package/src/core/events/memory.ts +131 -0
- package/src/core/events/metadata-utils.ts +133 -0
- package/src/core/events/test-helpers.ts +31 -0
- package/src/core/events/types.ts +64 -0
- package/src/core/file-store/file-store.ts +275 -0
- package/src/core/file-store/types.ts +52 -0
- package/src/core/image/image-processor.test.ts +218 -0
- package/src/core/image/image-processor.ts +127 -0
- package/src/core/image/index.ts +4 -0
- package/src/core/image/noop-resizer.ts +7 -0
- package/src/core/image/types.ts +24 -0
- package/src/core/image/vips-resizer.test.ts +377 -0
- package/src/core/image/vips-resizer.ts +124 -0
- package/src/core/llm/__snapshots__/anthropic-assistant-text-with-tool-calls.json +156 -0
- package/src/core/llm/__snapshots__/anthropic-consecutive-tool-results.json +152 -0
- package/src/core/llm/__snapshots__/anthropic-image-data-url.json +105 -0
- package/src/core/llm/__snapshots__/anthropic-image-http-url.json +104 -0
- package/src/core/llm/__snapshots__/anthropic-multiple-images.json +113 -0
- package/src/core/llm/__snapshots__/anthropic-multiple-tool-calls-requested.json +151 -0
- package/src/core/llm/__snapshots__/anthropic-simple-user-message.json +97 -0
- package/src/core/llm/__snapshots__/anthropic-system-message-in-conversation.json +119 -0
- package/src/core/llm/__snapshots__/anthropic-tool-call.json +123 -0
- package/src/core/llm/__snapshots__/anthropic-tool-error-result.json +139 -0
- package/src/core/llm/__snapshots__/anthropic-tool-result-with-image.json +152 -0
- package/src/core/llm/__snapshots__/anthropic-tool-roundtrip.json +139 -0
- package/src/core/llm/__snapshots__/openrouter-assistant-text-with-tool-calls.json +150 -0
- package/src/core/llm/__snapshots__/openrouter-consecutive-tool-results.json +150 -0
- package/src/core/llm/__snapshots__/openrouter-image-data-url.json +107 -0
- package/src/core/llm/__snapshots__/openrouter-image-http-url.json +107 -0
- package/src/core/llm/__snapshots__/openrouter-multiple-images.json +113 -0
- package/src/core/llm/__snapshots__/openrouter-multiple-tool-calls-requested.json +158 -0
- package/src/core/llm/__snapshots__/openrouter-simple-user-message.json +96 -0
- package/src/core/llm/__snapshots__/openrouter-system-message-in-conversation.json +108 -0
- package/src/core/llm/__snapshots__/openrouter-tool-call.json +129 -0
- package/src/core/llm/__snapshots__/openrouter-tool-error-result.json +137 -0
- package/src/core/llm/__snapshots__/openrouter-tool-result-with-image.json +148 -0
- package/src/core/llm/__snapshots__/openrouter-tool-roundtrip.json +137 -0
- package/src/core/llm/anthropic.test.ts +509 -0
- package/src/core/llm/anthropic.ts +578 -0
- package/src/core/llm/cache-breakpoints.ts +38 -0
- package/src/core/llm/cache-live.test.ts +155 -0
- package/src/core/llm/index.ts +30 -0
- package/src/core/llm/llm-log-types.ts +167 -0
- package/src/core/llm/logger.test.ts +270 -0
- package/src/core/llm/logger.ts +306 -0
- package/src/core/llm/logging-provider.ts +73 -0
- package/src/core/llm/middleware.ts +172 -0
- package/src/core/llm/mock.test.ts +402 -0
- package/src/core/llm/mock.ts +234 -0
- package/src/core/llm/openrouter-mapping.test.ts +153 -0
- package/src/core/llm/openrouter.test.ts +499 -0
- package/src/core/llm/openrouter.ts +458 -0
- package/src/core/llm/provider-integration.test.ts +408 -0
- package/src/core/llm/provider.ts +238 -0
- package/src/core/llm/routing-provider.test.ts +113 -0
- package/src/core/llm/routing-provider.ts +86 -0
- package/src/core/llm/schema.ts +47 -0
- package/src/core/llm/snapshot-fetch.ts +158 -0
- package/src/core/llm/snapshot-middleware.test.ts +168 -0
- package/src/core/llm/snapshot-middleware.ts +185 -0
- package/src/core/llm/state.ts +92 -0
- package/src/core/llm/tokens.ts +61 -0
- package/src/core/multi-agent.integration.test.ts +340 -0
- package/src/core/plugin-hooks.integration.test.ts +428 -0
- package/src/core/plugins/hook-types.ts +49 -0
- package/src/core/plugins/index.ts +52 -0
- package/src/core/plugins/plugin-builder.ts +967 -0
- package/src/core/preset/config.ts +110 -0
- package/src/core/preset/index.ts +11 -0
- package/src/core/preset/preset-builder.ts +111 -0
- package/src/core/session-lifecycle.integration.test.ts +202 -0
- package/src/core/sessions/apply-event.ts +46 -0
- package/src/core/sessions/context.ts +36 -0
- package/src/core/sessions/fork-utils.test.ts +158 -0
- package/src/core/sessions/fork-utils.ts +71 -0
- package/src/core/sessions/reducer.ts +95 -0
- package/src/core/sessions/schema.ts +91 -0
- package/src/core/sessions/session-environment.ts +12 -0
- package/src/core/sessions/session-manager.ts +883 -0
- package/src/core/sessions/session-store.ts +141 -0
- package/src/core/sessions/session.test.ts +1730 -0
- package/src/core/sessions/session.ts +833 -0
- package/src/core/sessions/state.ts +520 -0
- package/src/core/system.ts +206 -0
- package/src/core/tools/context.ts +3 -0
- package/src/core/tools/definition.ts +15 -0
- package/src/core/tools/executor.test.ts +160 -0
- package/src/core/tools/executor.ts +117 -0
- package/src/core/tools/index.ts +3 -0
- package/src/core/tools/schema.ts +80 -0
- package/src/core/tools/state.ts +34 -0
- package/src/index.ts +165 -0
- package/src/lib/json/index.ts +20 -0
- package/src/lib/logger/console.test.ts +348 -0
- package/src/lib/logger/console.ts +185 -0
- package/src/lib/logger/file.ts +65 -0
- package/src/lib/logger/index.ts +4 -0
- package/src/lib/logger/logger.ts +114 -0
- package/src/lib/logger/ring-buffer.ts +65 -0
- package/src/lib/logger/tee.ts +51 -0
- package/src/lib/mime.ts +23 -0
- package/src/lib/never.ts +3 -0
- package/src/lib/utils/hash.ts +38 -0
- package/src/lib/utils/result.ts +35 -0
- package/src/platform/fs.ts +38 -0
- package/src/platform/index.ts +23 -0
- package/src/platform/process.ts +28 -0
- package/src/plugins/agent-status/plugin.ts +77 -0
- package/src/plugins/agents/agents.integration.test.ts +808 -0
- package/src/plugins/agents/index.ts +2 -0
- package/src/plugins/agents/plugin.ts +242 -0
- package/src/plugins/context-compact/context-compact.integration.test.ts +207 -0
- package/src/plugins/context-compact/context-compactor.test.ts +923 -0
- package/src/plugins/context-compact/context-compactor.ts +343 -0
- package/src/plugins/context-compact/history-offloader.test.ts +100 -0
- package/src/plugins/context-compact/history-offloader.ts +47 -0
- package/src/plugins/context-compact/index.ts +3 -0
- package/src/plugins/context-compact/plugin.ts +62 -0
- package/src/plugins/filesystem/filesystem.integration.test.ts +485 -0
- package/src/plugins/filesystem/helpers.ts +216 -0
- package/src/plugins/filesystem/index.ts +4 -0
- package/src/plugins/filesystem/listing.ts +276 -0
- package/src/plugins/filesystem/plugin.ts +468 -0
- package/src/plugins/filesystem/schema.ts +6 -0
- package/src/plugins/git-status/index.ts +1 -0
- package/src/plugins/git-status/plugin.ts +166 -0
- package/src/plugins/limits-guard/config.ts +26 -0
- package/src/plugins/limits-guard/index.ts +4 -0
- package/src/plugins/limits-guard/limit-guard.test.ts +161 -0
- package/src/plugins/limits-guard/limit-guard.ts +164 -0
- package/src/plugins/limits-guard/limits-guard.integration.test.ts +437 -0
- package/src/plugins/limits-guard/plugin.ts +306 -0
- package/src/plugins/llm-debug/index.ts +1 -0
- package/src/plugins/llm-debug/llm-debug.integration.test.ts +192 -0
- package/src/plugins/llm-debug/plugin.ts +172 -0
- package/src/plugins/logs/index.ts +1 -0
- package/src/plugins/logs/plugin.ts +39 -0
- package/src/plugins/mailbox/helpers.ts +83 -0
- package/src/plugins/mailbox/index.ts +13 -0
- package/src/plugins/mailbox/mailbox.integration.test.ts +705 -0
- package/src/plugins/mailbox/plugin.ts +270 -0
- package/src/plugins/mailbox/prompts.ts +104 -0
- package/src/plugins/mailbox/query.ts +53 -0
- package/src/plugins/mailbox/schema.ts +81 -0
- package/src/plugins/mailbox/state.ts +52 -0
- package/src/plugins/resources/index.ts +11 -0
- package/src/plugins/resources/manifest.ts +25 -0
- package/src/plugins/resources/plugin.ts +201 -0
- package/src/plugins/resources/post-inject.ts +74 -0
- package/src/plugins/resources/state.ts +30 -0
- package/src/plugins/result-eviction/index.ts +2 -0
- package/src/plugins/result-eviction/plugin.ts +65 -0
- package/src/plugins/result-eviction/result-eviction.integration.test.ts +244 -0
- package/src/plugins/services/plugin.ts +485 -0
- package/src/plugins/services/port-pool.ts +73 -0
- package/src/plugins/services/prompt.ts +53 -0
- package/src/plugins/services/schema.ts +83 -0
- package/src/plugins/services/service.ts +578 -0
- package/src/plugins/services/services.integration.test.ts +595 -0
- package/src/plugins/session-lifecycle/index.ts +1 -0
- package/src/plugins/session-lifecycle/plugin.ts +302 -0
- package/src/plugins/session-lifecycle/session-lifecycle.integration.test.ts +639 -0
- package/src/plugins/session-state/plugin.ts +179 -0
- package/src/plugins/session-stats/index.ts +3 -0
- package/src/plugins/session-stats/plugin.ts +120 -0
- package/src/plugins/shell/executor.ts +462 -0
- package/src/plugins/shell/index.ts +23 -0
- package/src/plugins/shell/plugin.ts +118 -0
- package/src/plugins/shell/shell.integration.test.ts +273 -0
- package/src/plugins/shell/shell.test.ts +314 -0
- package/src/plugins/skills/discovery.test.ts +395 -0
- package/src/plugins/skills/discovery.ts +276 -0
- package/src/plugins/skills/index.ts +32 -0
- package/src/plugins/skills/plugin.ts +381 -0
- package/src/plugins/skills/prompts.ts +84 -0
- package/src/plugins/skills/schema.ts +88 -0
- package/src/plugins/skills/skills.integration.test.ts +580 -0
- package/src/plugins/snapshotting/index.ts +3 -0
- package/src/plugins/snapshotting/jj-snapshotter.ts +122 -0
- package/src/plugins/snapshotting/plugin.ts +36 -0
- package/src/plugins/snapshotting/snapshotter.ts +20 -0
- package/src/plugins/todo/index.ts +11 -0
- package/src/plugins/todo/plugin.ts +363 -0
- package/src/plugins/todo/prompts.ts +63 -0
- package/src/plugins/todo/schema.ts +71 -0
- package/src/plugins/todo/todo.integration.test.ts +687 -0
- package/src/plugins/uploads/index.ts +13 -0
- package/src/plugins/uploads/plugin.ts +406 -0
- package/src/plugins/uploads/preprocessor.ts +111 -0
- package/src/plugins/uploads/preprocessors/image-classifier.ts +176 -0
- package/src/plugins/uploads/preprocessors/index.ts +7 -0
- package/src/plugins/uploads/preprocessors/markitdown-preprocessor.ts +262 -0
- package/src/plugins/uploads/preprocessors/zip-preprocessor.ts +210 -0
- package/src/plugins/uploads/schema.ts +92 -0
- package/src/plugins/uploads/state.ts +42 -0
- package/src/plugins/uploads/uploads.integration.test.ts +654 -0
- package/src/plugins/user-chat/index.ts +17 -0
- package/src/plugins/user-chat/plugin.ts +728 -0
- package/src/plugins/user-chat/prompts.ts +30 -0
- package/src/plugins/user-chat/schema.ts +80 -0
- package/src/plugins/user-chat/user-chat.integration.test.ts +794 -0
- package/src/plugins/workers/context.ts +251 -0
- package/src/plugins/workers/definition.ts +169 -0
- package/src/plugins/workers/index.ts +21 -0
- package/src/plugins/workers/plugin.ts +722 -0
- package/src/plugins/workers/worker.ts +115 -0
- package/src/plugins/workers/workers.integration.test.ts +778 -0
- package/src/prompts/base.ts +266 -0
- package/src/prompts/builder.ts +194 -0
- package/src/prompts/index.ts +36 -0
- package/src/prompts/macros.test.ts +107 -0
- package/src/prompts/macros.ts +27 -0
- package/src/testing/bootstrap-for-testing.ts +39 -0
- package/src/testing/index.ts +7 -0
- package/src/testing/node-platform.ts +80 -0
- package/src/testing/notification-collector.ts +100 -0
- package/src/testing/preset-helpers.ts +57 -0
- package/src/testing/test-harness.test.ts +63 -0
- package/src/testing/test-harness.ts +279 -0
- package/src/testing/wait-helpers.ts +84 -0
- package/src/transport/adapter/client-adapter.ts +81 -0
- package/src/transport/adapter/index.ts +42 -0
- package/src/transport/adapter/server-adapter.ts +93 -0
- package/src/transport/adapter/types.ts +20 -0
- package/src/transport/http/app.ts +129 -0
- package/src/transport/http/index.ts +7 -0
- package/src/transport/http/middleware/bearer-auth.ts +40 -0
- package/src/transport/http/middleware/error-handler.ts +76 -0
- package/src/transport/http/routes/files.ts +274 -0
- package/src/transport/http/routes/resources.ts +115 -0
- package/src/transport/http/routes/rpc.integration.test.ts +243 -0
- package/src/transport/http/routes/rpc.test.ts +372 -0
- package/src/transport/http/routes/rpc.ts +156 -0
- package/src/transport/http/routes/upload.ts +286 -0
- package/src/transport/rpc/index.ts +11 -0
- package/src/transport/rpc/methods.ts +38 -0
- package/src/user-config.ts +33 -0
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import type { ToolCall } from '~/core/agents/state.js'
|
|
2
|
+
import type { ImageProcessor } from '~/core/image/types.js'
|
|
3
|
+
import type { ChatMessageContentItem } from '~/core/llm/llm-log-types.js'
|
|
4
|
+
import { ToolCallId } from '~/core/tools/schema.js'
|
|
5
|
+
import type { Logger } from '~/lib/logger/logger.js'
|
|
6
|
+
import type { Result } from '~/lib/utils/result.js'
|
|
7
|
+
import { Err, Ok } from '~/lib/utils/result.js'
|
|
8
|
+
import type {
|
|
9
|
+
InferenceContext,
|
|
10
|
+
InferenceRequest,
|
|
11
|
+
InferenceResponse,
|
|
12
|
+
LLMError,
|
|
13
|
+
LLMMessage,
|
|
14
|
+
LLMMetrics,
|
|
15
|
+
LLMProvider,
|
|
16
|
+
ProviderHttpRequest,
|
|
17
|
+
RawInferenceRequest,
|
|
18
|
+
RawToolSpec,
|
|
19
|
+
} from './provider.js'
|
|
20
|
+
import type { RoutableLLMProvider } from './routing-provider.js'
|
|
21
|
+
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Configuration
|
|
24
|
+
// ============================================================================
|
|
25
|
+
|
|
26
|
+
export interface AnthropicConfig {
|
|
27
|
+
apiKey: string
|
|
28
|
+
defaultModel?: string
|
|
29
|
+
timeout?: number
|
|
30
|
+
logger?: Logger
|
|
31
|
+
imageProcessor: ImageProcessor
|
|
32
|
+
/** When set, enables extended thinking with this token budget. Min 1024. */
|
|
33
|
+
thinkingBudget?: number
|
|
34
|
+
/** Custom fetch function (for testing/caching). Defaults to globalThis.fetch. */
|
|
35
|
+
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ============================================================================
|
|
39
|
+
// Anthropic API types
|
|
40
|
+
// ============================================================================
|
|
41
|
+
|
|
42
|
+
interface AnthropicTextBlock {
|
|
43
|
+
type: 'text'
|
|
44
|
+
text: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface AnthropicThinkingBlock {
|
|
48
|
+
type: 'thinking'
|
|
49
|
+
thinking: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface AnthropicToolUseBlock {
|
|
53
|
+
type: 'tool_use'
|
|
54
|
+
id: string
|
|
55
|
+
name: string
|
|
56
|
+
input: unknown
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type AnthropicContentBlock = AnthropicTextBlock | AnthropicThinkingBlock | AnthropicToolUseBlock
|
|
60
|
+
|
|
61
|
+
interface AnthropicMessageResponse {
|
|
62
|
+
id: string
|
|
63
|
+
type: 'message'
|
|
64
|
+
role: 'assistant'
|
|
65
|
+
content: AnthropicContentBlock[]
|
|
66
|
+
model: string
|
|
67
|
+
stop_reason: string | null
|
|
68
|
+
usage: {
|
|
69
|
+
input_tokens: number
|
|
70
|
+
output_tokens: number
|
|
71
|
+
cache_creation_input_tokens?: number
|
|
72
|
+
cache_read_input_tokens?: number
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface AnthropicErrorResponse {
|
|
77
|
+
type: 'error'
|
|
78
|
+
error: {
|
|
79
|
+
type: string
|
|
80
|
+
message: string
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Request body types
|
|
86
|
+
// ============================================================================
|
|
87
|
+
|
|
88
|
+
interface AnthropicTextBlockParam {
|
|
89
|
+
type: 'text'
|
|
90
|
+
text: string
|
|
91
|
+
cache_control?: { type: 'ephemeral' }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface AnthropicImageBlockParam {
|
|
95
|
+
type: 'image'
|
|
96
|
+
source:
|
|
97
|
+
| { type: 'base64'; media_type: string; data: string }
|
|
98
|
+
| { type: 'url'; url: string }
|
|
99
|
+
cache_control?: { type: 'ephemeral' }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface AnthropicToolUseBlockParam {
|
|
103
|
+
type: 'tool_use'
|
|
104
|
+
id: string
|
|
105
|
+
name: string
|
|
106
|
+
input: unknown
|
|
107
|
+
cache_control?: { type: 'ephemeral' }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface AnthropicToolResultBlockParam {
|
|
111
|
+
type: 'tool_result'
|
|
112
|
+
tool_use_id: string
|
|
113
|
+
content: string | Array<AnthropicTextBlockParam | AnthropicImageBlockParam>
|
|
114
|
+
is_error?: boolean
|
|
115
|
+
cache_control?: { type: 'ephemeral' }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type AnthropicContentBlockParam =
|
|
119
|
+
| AnthropicTextBlockParam
|
|
120
|
+
| AnthropicImageBlockParam
|
|
121
|
+
| AnthropicToolUseBlockParam
|
|
122
|
+
| AnthropicToolResultBlockParam
|
|
123
|
+
|
|
124
|
+
interface AnthropicMessageParam {
|
|
125
|
+
role: 'user' | 'assistant'
|
|
126
|
+
content: string | AnthropicContentBlockParam[]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Add `cache_control: { type: 'ephemeral' }` to the LAST content block of an
|
|
131
|
+
* AnthropicMessageParam, regardless of block type. Converts string content to
|
|
132
|
+
* a single text block first so the mark has a place to live. Mutates in place
|
|
133
|
+
* so the cache breakpoint survives subsequent `mergeConsecutiveMessages`.
|
|
134
|
+
*/
|
|
135
|
+
function applyCacheControlToLastBlock(msg: AnthropicMessageParam): void {
|
|
136
|
+
if (typeof msg.content === 'string') {
|
|
137
|
+
msg.content = [{ type: 'text', text: msg.content, cache_control: { type: 'ephemeral' } }]
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
if (msg.content.length === 0) return
|
|
141
|
+
const lastIdx = msg.content.length - 1
|
|
142
|
+
msg.content[lastIdx] = { ...msg.content[lastIdx], cache_control: { type: 'ephemeral' } }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface AnthropicToolParam {
|
|
146
|
+
name: string
|
|
147
|
+
description: string
|
|
148
|
+
input_schema: Record<string, unknown>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
interface AnthropicRequestBody {
|
|
152
|
+
model: string
|
|
153
|
+
max_tokens: number
|
|
154
|
+
system: AnthropicTextBlockParam[]
|
|
155
|
+
messages: AnthropicMessageParam[]
|
|
156
|
+
stream: false
|
|
157
|
+
tools?: AnthropicToolParam[]
|
|
158
|
+
temperature?: number
|
|
159
|
+
stop_sequences?: string[]
|
|
160
|
+
thinking?: { type: 'enabled'; budget_tokens: number }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ============================================================================
|
|
164
|
+
// AnthropicProvider
|
|
165
|
+
// ============================================================================
|
|
166
|
+
|
|
167
|
+
const ANTHROPIC_API_URL = 'https://api.anthropic.com/v1/messages'
|
|
168
|
+
const ANTHROPIC_VERSION = '2023-06-01'
|
|
169
|
+
|
|
170
|
+
/** Anthropic model prefix used by OpenRouter */
|
|
171
|
+
const ANTHROPIC_PREFIX = 'anthropic/'
|
|
172
|
+
|
|
173
|
+
/** Known Anthropic model prefixes (without vendor prefix) */
|
|
174
|
+
const ANTHROPIC_MODEL_PREFIXES = ['claude-']
|
|
175
|
+
|
|
176
|
+
/** Per-million-token pricing: [input, output] */
|
|
177
|
+
const ANTHROPIC_PRICING: Record<string, [input: number, output: number]> = {
|
|
178
|
+
'haiku': [1.00, 5.00],
|
|
179
|
+
'sonnet': [3.00, 15.00],
|
|
180
|
+
'opus': [5.00, 25.00],
|
|
181
|
+
}
|
|
182
|
+
/** Cache read = 10% of input price, cache write (5min ephemeral) = 125% of input price */
|
|
183
|
+
const CACHE_READ_MULTIPLIER = 0.1
|
|
184
|
+
const CACHE_WRITE_MULTIPLIER = 1.25
|
|
185
|
+
|
|
186
|
+
export class AnthropicProvider implements RoutableLLMProvider {
|
|
187
|
+
readonly name = 'anthropic'
|
|
188
|
+
private apiKey: string
|
|
189
|
+
private defaultModel: string
|
|
190
|
+
private logger?: Logger
|
|
191
|
+
private imageProcessor: ImageProcessor
|
|
192
|
+
private thinkingBudget?: number
|
|
193
|
+
private timeout: number
|
|
194
|
+
private fetchFn: (input: string | URL | Request, init?: RequestInit) => Promise<Response>
|
|
195
|
+
|
|
196
|
+
constructor(config: AnthropicConfig) {
|
|
197
|
+
this.apiKey = config.apiKey
|
|
198
|
+
this.defaultModel = config.defaultModel ?? 'claude-sonnet-4-5-20250514'
|
|
199
|
+
this.logger = config.logger
|
|
200
|
+
this.imageProcessor = config.imageProcessor
|
|
201
|
+
this.thinkingBudget = config.thinkingBudget
|
|
202
|
+
this.timeout = config.timeout ?? 120000
|
|
203
|
+
this.fetchFn = config.fetch ?? globalThis.fetch
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Returns true for models with `anthropic/` prefix or starting with `claude-`.
|
|
208
|
+
*/
|
|
209
|
+
canHandle(model: string): boolean {
|
|
210
|
+
if (model.startsWith(ANTHROPIC_PREFIX)) return true
|
|
211
|
+
return ANTHROPIC_MODEL_PREFIXES.some((prefix) => model.startsWith(prefix))
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Normalizes model ID for the Anthropic API:
|
|
216
|
+
* 1. Strips `anthropic/` prefix if present
|
|
217
|
+
* 2. Converts version dots to dashes (OpenRouter `claude-opus-4.6` → Anthropic `claude-opus-4-6`)
|
|
218
|
+
*/
|
|
219
|
+
normalizeModel(model: string): string {
|
|
220
|
+
let normalized = model.startsWith(ANTHROPIC_PREFIX)
|
|
221
|
+
? model.slice(ANTHROPIC_PREFIX.length)
|
|
222
|
+
: model
|
|
223
|
+
// OpenRouter uses dots in version (claude-opus-4.6), Anthropic API uses dashes (claude-opus-4-6)
|
|
224
|
+
normalized = normalized.replace(/(\d+)\.(\d+)/g, '$1-$2')
|
|
225
|
+
return normalized
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async inference(request: InferenceRequest, context?: InferenceContext): Promise<Result<InferenceResponse, LLMError>> {
|
|
229
|
+
const startTime = Date.now()
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
const rawRequest: RawInferenceRequest = {
|
|
233
|
+
...request,
|
|
234
|
+
tools: request.tools?.map((t) => ({
|
|
235
|
+
name: t.name,
|
|
236
|
+
description: t.description,
|
|
237
|
+
parameters: t.input.toJSONSchema(),
|
|
238
|
+
})),
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const httpRequest = await this.buildHttpRequest(rawRequest, context)
|
|
242
|
+
|
|
243
|
+
const controller = new AbortController()
|
|
244
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout)
|
|
245
|
+
|
|
246
|
+
// Combine with external signal if provided
|
|
247
|
+
if (context?.signal) {
|
|
248
|
+
context.signal.addEventListener('abort', () => controller.abort(), { once: true })
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let response: Response
|
|
252
|
+
try {
|
|
253
|
+
response = await this.fetchFn(httpRequest.url, {
|
|
254
|
+
method: httpRequest.method,
|
|
255
|
+
headers: {
|
|
256
|
+
...httpRequest.headers,
|
|
257
|
+
'x-api-key': this.apiKey,
|
|
258
|
+
'anthropic-dangerous-direct-browser-access': 'true',
|
|
259
|
+
},
|
|
260
|
+
body: JSON.stringify(httpRequest.body),
|
|
261
|
+
signal: controller.signal,
|
|
262
|
+
})
|
|
263
|
+
} finally {
|
|
264
|
+
clearTimeout(timeoutId)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (!response.ok) {
|
|
268
|
+
const body = await response.text()
|
|
269
|
+
return Err(this.mapHttpError(response.status, body))
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const data = await response.json() as AnthropicMessageResponse
|
|
273
|
+
const latencyMs = Date.now() - startTime
|
|
274
|
+
|
|
275
|
+
const textContent = data.content
|
|
276
|
+
.filter((block): block is AnthropicTextBlock => block.type === 'text')
|
|
277
|
+
.map((block) => block.text)
|
|
278
|
+
.join('')
|
|
279
|
+
|
|
280
|
+
const reasoning = data.content
|
|
281
|
+
.filter((block): block is AnthropicThinkingBlock => block.type === 'thinking')
|
|
282
|
+
.map((block) => block.thinking)
|
|
283
|
+
.join('')
|
|
284
|
+
|
|
285
|
+
const toolCalls: ToolCall[] = data.content
|
|
286
|
+
.filter((block): block is AnthropicToolUseBlock => block.type === 'tool_use')
|
|
287
|
+
.map((block) => ({
|
|
288
|
+
id: ToolCallId(block.id),
|
|
289
|
+
name: block.name,
|
|
290
|
+
input: block.input,
|
|
291
|
+
}))
|
|
292
|
+
|
|
293
|
+
const metrics: LLMMetrics = {
|
|
294
|
+
promptTokens: data.usage.input_tokens,
|
|
295
|
+
completionTokens: data.usage.output_tokens,
|
|
296
|
+
totalTokens: data.usage.input_tokens + data.usage.output_tokens,
|
|
297
|
+
latencyMs,
|
|
298
|
+
model: data.model,
|
|
299
|
+
provider: this.name,
|
|
300
|
+
cost: this.calculateCost(data.model, data.usage),
|
|
301
|
+
cachedTokens: data.usage.cache_read_input_tokens || undefined,
|
|
302
|
+
cacheWriteTokens: data.usage.cache_creation_input_tokens || undefined,
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return Ok({
|
|
306
|
+
content: textContent || null,
|
|
307
|
+
toolCalls,
|
|
308
|
+
finishReason: this.mapStopReason(data.stop_reason),
|
|
309
|
+
metrics,
|
|
310
|
+
providerRequestId: data.id,
|
|
311
|
+
reasoning: reasoning || undefined,
|
|
312
|
+
})
|
|
313
|
+
} catch (error) {
|
|
314
|
+
return Err(this.mapError(error))
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async buildHttpRequest(request: RawInferenceRequest, context?: InferenceContext): Promise<ProviderHttpRequest> {
|
|
319
|
+
const mappedMessages = await Promise.all(request.messages.map((m) => this.mapMessage(m, context)))
|
|
320
|
+
const mergedMessages = this.mergeConsecutiveMessages(mappedMessages)
|
|
321
|
+
|
|
322
|
+
const body: AnthropicRequestBody = {
|
|
323
|
+
model: request.model ?? this.defaultModel,
|
|
324
|
+
max_tokens: request.maxTokens ?? 100_000,
|
|
325
|
+
system: [{ type: 'text', text: request.systemPrompt, cache_control: { type: 'ephemeral' } }],
|
|
326
|
+
messages: mergedMessages,
|
|
327
|
+
stream: false,
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (request.tools?.length) {
|
|
331
|
+
body.tools = request.tools.map((t): AnthropicToolParam => ({
|
|
332
|
+
name: t.name,
|
|
333
|
+
description: t.description,
|
|
334
|
+
input_schema: t.parameters as AnthropicToolParam['input_schema'],
|
|
335
|
+
}))
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (request.temperature !== undefined) {
|
|
339
|
+
body.temperature = request.temperature
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (request.stopSequences?.length) {
|
|
343
|
+
body.stop_sequences = request.stopSequences
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const thinkingBudget = request.anthropic?.thinkingBudget ?? this.thinkingBudget
|
|
347
|
+
if (thinkingBudget) {
|
|
348
|
+
body.thinking = { type: 'enabled', budget_tokens: thinkingBudget }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
url: ANTHROPIC_API_URL,
|
|
353
|
+
method: 'POST',
|
|
354
|
+
headers: {
|
|
355
|
+
'content-type': 'application/json',
|
|
356
|
+
'anthropic-version': ANTHROPIC_VERSION,
|
|
357
|
+
},
|
|
358
|
+
body,
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ============================================================================
|
|
363
|
+
// Message mapping
|
|
364
|
+
// ============================================================================
|
|
365
|
+
|
|
366
|
+
private async mapMessage(msg: LLMMessage, context?: InferenceContext): Promise<AnthropicMessageParam> {
|
|
367
|
+
const mapped = await this.mapMessageContent(msg, context)
|
|
368
|
+
if (msg.cacheControl) {
|
|
369
|
+
applyCacheControlToLastBlock(mapped)
|
|
370
|
+
}
|
|
371
|
+
return mapped
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
private async mapMessageContent(msg: LLMMessage, context?: InferenceContext): Promise<AnthropicMessageParam> {
|
|
375
|
+
switch (msg.role) {
|
|
376
|
+
case 'tool': {
|
|
377
|
+
const resolvedContent = await this.imageProcessor.resolveContent(msg.content, context?.fileStore)
|
|
378
|
+
const toolResult = this.mapToolResultContent(resolvedContent, msg.isError)
|
|
379
|
+
toolResult.tool_use_id = msg.toolCallId
|
|
380
|
+
return {
|
|
381
|
+
role: 'user',
|
|
382
|
+
content: [toolResult],
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
case 'assistant': {
|
|
386
|
+
const contentBlocks: AnthropicContentBlockParam[] = []
|
|
387
|
+
if (msg.content) {
|
|
388
|
+
contentBlocks.push({ type: 'text', text: msg.content })
|
|
389
|
+
}
|
|
390
|
+
if (msg.toolCalls?.length) {
|
|
391
|
+
for (const tc of msg.toolCalls) {
|
|
392
|
+
contentBlocks.push({
|
|
393
|
+
type: 'tool_use',
|
|
394
|
+
id: tc.id,
|
|
395
|
+
name: tc.name,
|
|
396
|
+
input: tc.input as Record<string, unknown>,
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
role: 'assistant',
|
|
402
|
+
content: contentBlocks.length > 0 ? contentBlocks : [{ type: 'text', text: '' }],
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
case 'system':
|
|
406
|
+
return {
|
|
407
|
+
role: 'user',
|
|
408
|
+
content: [{ type: 'text', text: `[System] ${msg.content}` }],
|
|
409
|
+
}
|
|
410
|
+
case 'user': {
|
|
411
|
+
if (Array.isArray(msg.content)) {
|
|
412
|
+
const resolved = await this.imageProcessor.resolveContent(msg.content, context?.fileStore)
|
|
413
|
+
const blocks = this.mapUserContentItems(Array.isArray(resolved) ? resolved : [{ type: 'text', text: String(resolved) }])
|
|
414
|
+
return { role: 'user', content: blocks }
|
|
415
|
+
}
|
|
416
|
+
return { role: 'user', content: msg.content }
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
private mapToolResultContent(content: string | ChatMessageContentItem[], isError?: boolean): AnthropicToolResultBlockParam {
|
|
422
|
+
if (typeof content === 'string') {
|
|
423
|
+
const text = isError ? `[ERROR] ${content}` : content
|
|
424
|
+
return {
|
|
425
|
+
type: 'tool_result',
|
|
426
|
+
tool_use_id: '', // will be set by caller context — but we set it in mapMessage
|
|
427
|
+
content: text,
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const blocks = this.mapUserContentItems(content)
|
|
432
|
+
return {
|
|
433
|
+
type: 'tool_result',
|
|
434
|
+
tool_use_id: '',
|
|
435
|
+
content: blocks,
|
|
436
|
+
is_error: isError,
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private mapUserContentItems(items: ChatMessageContentItem[]): Array<AnthropicTextBlockParam | AnthropicImageBlockParam> {
|
|
441
|
+
return items.map((item) => {
|
|
442
|
+
if (item.type === 'text') {
|
|
443
|
+
return { type: 'text' as const, text: item.text }
|
|
444
|
+
}
|
|
445
|
+
if (item.type === 'image_url') {
|
|
446
|
+
return this.mapImageContent(item.imageUrl.url)
|
|
447
|
+
}
|
|
448
|
+
return { type: 'text' as const, text: JSON.stringify(item) }
|
|
449
|
+
})
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private mapImageContent(url: string): AnthropicImageBlockParam {
|
|
453
|
+
const dataUrlMatch = url.match(/^data:(image\/[^;]+);base64,(.+)$/)
|
|
454
|
+
if (dataUrlMatch) {
|
|
455
|
+
return {
|
|
456
|
+
type: 'image',
|
|
457
|
+
source: {
|
|
458
|
+
type: 'base64',
|
|
459
|
+
media_type: dataUrlMatch[1],
|
|
460
|
+
data: dataUrlMatch[2],
|
|
461
|
+
},
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
type: 'image',
|
|
466
|
+
source: {
|
|
467
|
+
type: 'url',
|
|
468
|
+
url,
|
|
469
|
+
},
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// ============================================================================
|
|
474
|
+
// Message alternation
|
|
475
|
+
// ============================================================================
|
|
476
|
+
|
|
477
|
+
private mergeConsecutiveMessages(messages: AnthropicMessageParam[]): AnthropicMessageParam[] {
|
|
478
|
+
if (messages.length === 0) return []
|
|
479
|
+
|
|
480
|
+
const result: AnthropicMessageParam[] = []
|
|
481
|
+
for (const msg of messages) {
|
|
482
|
+
const last = result[result.length - 1]
|
|
483
|
+
if (last && last.role === msg.role) {
|
|
484
|
+
// Merge content arrays
|
|
485
|
+
const lastContent = this.normalizeContent(last.content)
|
|
486
|
+
const msgContent = this.normalizeContent(msg.content)
|
|
487
|
+
last.content = [...lastContent, ...msgContent]
|
|
488
|
+
} else {
|
|
489
|
+
result.push({ ...msg, content: this.normalizeContent(msg.content) })
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return result
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
private normalizeContent(content: AnthropicMessageParam['content']): AnthropicContentBlockParam[] {
|
|
496
|
+
if (typeof content === 'string') {
|
|
497
|
+
return [{ type: 'text', text: content }]
|
|
498
|
+
}
|
|
499
|
+
return [...content]
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// ============================================================================
|
|
503
|
+
// Response mapping
|
|
504
|
+
// ============================================================================
|
|
505
|
+
|
|
506
|
+
private mapStopReason(reason: string | null): InferenceResponse['finishReason'] {
|
|
507
|
+
switch (reason) {
|
|
508
|
+
case 'end_turn':
|
|
509
|
+
return 'stop'
|
|
510
|
+
case 'tool_use':
|
|
511
|
+
return 'tool_calls'
|
|
512
|
+
case 'max_tokens':
|
|
513
|
+
return 'length'
|
|
514
|
+
default:
|
|
515
|
+
return 'stop'
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// ============================================================================
|
|
520
|
+
// Cost calculation
|
|
521
|
+
// ============================================================================
|
|
522
|
+
|
|
523
|
+
private calculateCost(model: string, usage: AnthropicMessageResponse['usage']): number | undefined {
|
|
524
|
+
const family = Object.keys(ANTHROPIC_PRICING).find((key) => model.includes(key))
|
|
525
|
+
if (!family) return undefined
|
|
526
|
+
const [inputPrice, outputPrice] = ANTHROPIC_PRICING[family]
|
|
527
|
+
const perM = 1_000_000
|
|
528
|
+
const inputCost = usage.input_tokens * inputPrice / perM
|
|
529
|
+
const outputCost = usage.output_tokens * outputPrice / perM
|
|
530
|
+
const cacheReadCost = (usage.cache_read_input_tokens ?? 0) * inputPrice * CACHE_READ_MULTIPLIER / perM
|
|
531
|
+
const cacheWriteCost = (usage.cache_creation_input_tokens ?? 0) * inputPrice * CACHE_WRITE_MULTIPLIER / perM
|
|
532
|
+
return inputCost + outputCost + cacheReadCost + cacheWriteCost
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// ============================================================================
|
|
536
|
+
// Error mapping
|
|
537
|
+
// ============================================================================
|
|
538
|
+
|
|
539
|
+
private mapHttpError(status: number, body: string): LLMError {
|
|
540
|
+
let message = `HTTP ${status}`
|
|
541
|
+
try {
|
|
542
|
+
const parsed = JSON.parse(body) as AnthropicErrorResponse
|
|
543
|
+
if (parsed.error?.message) {
|
|
544
|
+
message = parsed.error.message
|
|
545
|
+
}
|
|
546
|
+
} catch {
|
|
547
|
+
// use raw body as message if not parseable
|
|
548
|
+
if (body) message = body
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (status === 429) {
|
|
552
|
+
return { type: 'rate_limit', message, retryAfterMs: 60000, statusCode: status }
|
|
553
|
+
}
|
|
554
|
+
if (status === 400) {
|
|
555
|
+
if (message.includes('max_tokens') || message.includes('too long') || message.includes('context') || message.includes('token')) {
|
|
556
|
+
return { type: 'context_length', message, statusCode: status }
|
|
557
|
+
}
|
|
558
|
+
return { type: 'invalid_request', message, statusCode: status }
|
|
559
|
+
}
|
|
560
|
+
if (status === 401) {
|
|
561
|
+
return { type: 'invalid_request', message, statusCode: status }
|
|
562
|
+
}
|
|
563
|
+
if (status === 529 || status >= 500) {
|
|
564
|
+
return { type: 'server_error', message, statusCode: status }
|
|
565
|
+
}
|
|
566
|
+
return { type: 'server_error', message, statusCode: status, responseBody: body }
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
private mapError(err: unknown): LLMError {
|
|
570
|
+
if (err instanceof Error && err.name === 'AbortError') {
|
|
571
|
+
return { type: 'aborted', message: 'Request was aborted' }
|
|
572
|
+
}
|
|
573
|
+
if (err instanceof TypeError && (err.message.includes('fetch') || err.message.includes('network'))) {
|
|
574
|
+
return { type: 'network_error', message: err.message, cause: err }
|
|
575
|
+
}
|
|
576
|
+
return { type: 'network_error', message: err instanceof Error ? err.message : String(err), cause: err }
|
|
577
|
+
}
|
|
578
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { LLMMessage } from '~/core/agents/state.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mark the prompt cache breakpoint on a message list.
|
|
5
|
+
*
|
|
6
|
+
* Flag-based: the target message gets a `cacheControl` marker. Providers that
|
|
7
|
+
* support ephemeral prompt caching (anthropic, openrouter) react to the flag
|
|
8
|
+
* during `buildHttpRequest` and place `cache_control: { type: 'ephemeral' }`
|
|
9
|
+
* on the LAST content block of the mapped message — regardless of block type
|
|
10
|
+
* (text / tool_use / tool_result / image). This matches the API semantics
|
|
11
|
+
* "cache the prefix up to and including this block".
|
|
12
|
+
*
|
|
13
|
+
* Target index is `messages.length - 1 - uncachedSuffixCount`. The suffix is
|
|
14
|
+
* the tail of messages that must remain fresh (e.g. ephemeral session context
|
|
15
|
+
* rebuilt each inference).
|
|
16
|
+
*/
|
|
17
|
+
export function applyCacheBreakpoint(messages: LLMMessage[], uncachedSuffixCount: number): LLMMessage[] {
|
|
18
|
+
const idx = messages.length - 1 - uncachedSuffixCount
|
|
19
|
+
if (idx < 0) return messages
|
|
20
|
+
|
|
21
|
+
const target = messages[idx]
|
|
22
|
+
const result = [...messages]
|
|
23
|
+
switch (target.role) {
|
|
24
|
+
case 'user':
|
|
25
|
+
result[idx] = { ...target, cacheControl: { type: 'ephemeral' } }
|
|
26
|
+
break
|
|
27
|
+
case 'assistant':
|
|
28
|
+
result[idx] = { ...target, cacheControl: { type: 'ephemeral' } }
|
|
29
|
+
break
|
|
30
|
+
case 'system':
|
|
31
|
+
result[idx] = { ...target, cacheControl: { type: 'ephemeral' } }
|
|
32
|
+
break
|
|
33
|
+
case 'tool':
|
|
34
|
+
result[idx] = { ...target, cacheControl: { type: 'ephemeral' } }
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
return result
|
|
38
|
+
}
|