@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,113 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import type { Result } from '~/lib/utils/result.js'
|
|
3
|
+
import { Ok } from '~/lib/utils/result.js'
|
|
4
|
+
import type { InferenceContext, InferenceRequest, InferenceResponse, LLMError, LLMProvider } from './provider.js'
|
|
5
|
+
import type { RoutableLLMProvider } from './routing-provider.js'
|
|
6
|
+
import { RoutingLLMProvider } from './routing-provider.js'
|
|
7
|
+
import { ModelId } from './schema.js'
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Helpers
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
const createRequest = (model: string): InferenceRequest => ({
|
|
14
|
+
model: ModelId(model),
|
|
15
|
+
systemPrompt: 'test',
|
|
16
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const createMockProvider = (name: string, prefix: string): RoutableLLMProvider & { lastModel?: string } => {
|
|
20
|
+
const provider: RoutableLLMProvider & { lastModel?: string } = {
|
|
21
|
+
name,
|
|
22
|
+
canHandle: (model: string) => model.startsWith(prefix),
|
|
23
|
+
normalizeModel: (model: string) => model.startsWith(`${prefix}/`) ? model.slice(prefix.length + 1) : model,
|
|
24
|
+
async inference(request: InferenceRequest): Promise<Result<InferenceResponse, LLMError>> {
|
|
25
|
+
provider.lastModel = request.model
|
|
26
|
+
return Ok({
|
|
27
|
+
content: `Response from ${name}`,
|
|
28
|
+
toolCalls: [],
|
|
29
|
+
finishReason: 'stop',
|
|
30
|
+
metrics: { promptTokens: 10, completionTokens: 5, totalTokens: 15, latencyMs: 100, model: request.model },
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
return provider
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const createMockFallback = (name: string): LLMProvider & { lastModel?: string } => {
|
|
38
|
+
const provider: LLMProvider & { lastModel?: string } = {
|
|
39
|
+
name,
|
|
40
|
+
async inference(request: InferenceRequest): Promise<Result<InferenceResponse, LLMError>> {
|
|
41
|
+
provider.lastModel = request.model
|
|
42
|
+
return Ok({
|
|
43
|
+
content: `Response from ${name}`,
|
|
44
|
+
toolCalls: [],
|
|
45
|
+
finishReason: 'stop',
|
|
46
|
+
metrics: { promptTokens: 10, completionTokens: 5, totalTokens: 15, latencyMs: 100, model: request.model },
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
return provider
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ============================================================================
|
|
54
|
+
// Tests
|
|
55
|
+
// ============================================================================
|
|
56
|
+
|
|
57
|
+
describe('RoutingLLMProvider', () => {
|
|
58
|
+
test('routes to matching provider', async () => {
|
|
59
|
+
const anthropic = createMockProvider('anthropic', 'anthropic')
|
|
60
|
+
const fallback = createMockFallback('openrouter')
|
|
61
|
+
|
|
62
|
+
const router = new RoutingLLMProvider([anthropic], fallback)
|
|
63
|
+
const result = await router.inference(createRequest('anthropic/claude-sonnet-4.5'))
|
|
64
|
+
|
|
65
|
+
expect(result.ok).toBe(true)
|
|
66
|
+
if (result.ok) {
|
|
67
|
+
expect(result.value.content).toBe('Response from anthropic')
|
|
68
|
+
}
|
|
69
|
+
// Model should be normalized (prefix stripped)
|
|
70
|
+
expect(anthropic.lastModel).toBe('claude-sonnet-4.5')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('falls back to fallback provider when no match', async () => {
|
|
74
|
+
const anthropic = createMockProvider('anthropic', 'anthropic')
|
|
75
|
+
const fallback = createMockFallback('openrouter')
|
|
76
|
+
|
|
77
|
+
const router = new RoutingLLMProvider([anthropic], fallback)
|
|
78
|
+
const result = await router.inference(createRequest('openai/gpt-4o'))
|
|
79
|
+
|
|
80
|
+
expect(result.ok).toBe(true)
|
|
81
|
+
if (result.ok) {
|
|
82
|
+
expect(result.value.content).toBe('Response from openrouter')
|
|
83
|
+
}
|
|
84
|
+
// Model should be passed through unchanged to fallback
|
|
85
|
+
expect(fallback.lastModel).toBe('openai/gpt-4o')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('returns error when no provider matches and no fallback', async () => {
|
|
89
|
+
const anthropic = createMockProvider('anthropic', 'anthropic')
|
|
90
|
+
|
|
91
|
+
const router = new RoutingLLMProvider([anthropic])
|
|
92
|
+
const result = await router.inference(createRequest('openai/gpt-4o'))
|
|
93
|
+
|
|
94
|
+
expect(result.ok).toBe(false)
|
|
95
|
+
if (!result.ok) {
|
|
96
|
+
expect(result.error.type).toBe('invalid_request')
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('first matching provider wins', async () => {
|
|
101
|
+
const provider1 = createMockProvider('provider1', 'claude')
|
|
102
|
+
const provider2 = createMockProvider('provider2', 'claude')
|
|
103
|
+
const fallback = createMockFallback('fallback')
|
|
104
|
+
|
|
105
|
+
const router = new RoutingLLMProvider([provider1, provider2], fallback)
|
|
106
|
+
const result = await router.inference(createRequest('claude-sonnet-4.5'))
|
|
107
|
+
|
|
108
|
+
expect(result.ok).toBe(true)
|
|
109
|
+
if (result.ok) {
|
|
110
|
+
expect(result.value.content).toBe('Response from provider1')
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RoutingLLMProvider - Routes requests to the appropriate provider based on model ID.
|
|
3
|
+
*
|
|
4
|
+
* Each registered provider declares which models it can handle via `canHandle()`.
|
|
5
|
+
* The last registered provider acts as the fallback (typically OpenRouter).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Result } from '~/lib/utils/result.js'
|
|
9
|
+
import { Err } from '~/lib/utils/result.js'
|
|
10
|
+
import type {
|
|
11
|
+
InferenceContext,
|
|
12
|
+
InferenceRequest,
|
|
13
|
+
InferenceResponse,
|
|
14
|
+
LLMError,
|
|
15
|
+
LLMProvider,
|
|
16
|
+
ProviderHttpRequest,
|
|
17
|
+
RawInferenceRequest,
|
|
18
|
+
} from './provider.js'
|
|
19
|
+
import { ModelId } from './schema.js'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A provider that can declare which models it supports.
|
|
23
|
+
*/
|
|
24
|
+
export interface RoutableLLMProvider extends LLMProvider {
|
|
25
|
+
/** Returns true if this provider can handle the given model ID. */
|
|
26
|
+
canHandle(model: string): boolean
|
|
27
|
+
/** Normalizes the model ID for this provider (e.g. strips vendor prefix). */
|
|
28
|
+
normalizeModel(model: string): string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Routes inference requests to the appropriate provider based on model ID.
|
|
33
|
+
* Providers are checked in order; first match wins.
|
|
34
|
+
* If no provider matches, the fallback provider is used.
|
|
35
|
+
*/
|
|
36
|
+
export class RoutingLLMProvider implements LLMProvider {
|
|
37
|
+
readonly name = 'routing'
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
private readonly providers: RoutableLLMProvider[],
|
|
41
|
+
private readonly fallback?: LLMProvider,
|
|
42
|
+
) {}
|
|
43
|
+
|
|
44
|
+
async inference(
|
|
45
|
+
request: InferenceRequest,
|
|
46
|
+
context?: InferenceContext,
|
|
47
|
+
): Promise<Result<InferenceResponse, LLMError>> {
|
|
48
|
+
const model = request.model
|
|
49
|
+
|
|
50
|
+
for (const provider of this.providers) {
|
|
51
|
+
if (provider.canHandle(model)) {
|
|
52
|
+
const normalizedModel = ModelId(provider.normalizeModel(model))
|
|
53
|
+
return provider.inference({ ...request, model: normalizedModel }, context)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this.fallback) {
|
|
58
|
+
return this.fallback.inference(request, context)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return Err({
|
|
62
|
+
type: 'invalid_request',
|
|
63
|
+
message: `No provider available for model: ${model}`,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async buildHttpRequest(
|
|
68
|
+
request: RawInferenceRequest,
|
|
69
|
+
context?: InferenceContext,
|
|
70
|
+
): Promise<ProviderHttpRequest> {
|
|
71
|
+
const model = request.model
|
|
72
|
+
|
|
73
|
+
for (const provider of this.providers) {
|
|
74
|
+
if (provider.canHandle(model) && provider.buildHttpRequest) {
|
|
75
|
+
const normalizedModel = ModelId(provider.normalizeModel(model))
|
|
76
|
+
return provider.buildHttpRequest({ ...request, model: normalizedModel }, context)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (this.fallback?.buildHttpRequest) {
|
|
81
|
+
return this.fallback.buildHttpRequest(request, context)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
throw new Error(`No provider with buildHttpRequest available for model: ${model}`)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM domain types and schemas
|
|
3
|
+
*
|
|
4
|
+
* Contains all types related to LLM:
|
|
5
|
+
* - Branded ID types and constructors (LLMCallId, ModelId)
|
|
6
|
+
* - LLM response types
|
|
7
|
+
* - Zod schemas for validation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { uuidv7 } from 'uuidv7'
|
|
11
|
+
import z from 'zod/v4'
|
|
12
|
+
import type { LLMToolCall } from './state'
|
|
13
|
+
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// LLMCallId - Branded type
|
|
16
|
+
// ============================================================================
|
|
17
|
+
|
|
18
|
+
/** LLMCallId schema - validates any string and brands as LLMCallId. */
|
|
19
|
+
export const llmCallIdSchema = z.string().brand('LLMCallId')
|
|
20
|
+
|
|
21
|
+
/** Branded LLMCallId type */
|
|
22
|
+
export type LLMCallId = z.infer<typeof llmCallIdSchema>
|
|
23
|
+
|
|
24
|
+
/** Constructor for LLMCallId */
|
|
25
|
+
export const LLMCallId = (id: string): LLMCallId => id as LLMCallId
|
|
26
|
+
|
|
27
|
+
/** Generate a new LLMCallId (UUIDv7) */
|
|
28
|
+
export const generateLLMCallId = (): LLMCallId => LLMCallId(uuidv7())
|
|
29
|
+
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// LLMCallId - Zod schemas
|
|
32
|
+
// ============================================================================
|
|
33
|
+
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// ModelId - Branded type
|
|
36
|
+
// ============================================================================
|
|
37
|
+
|
|
38
|
+
/** ModelId schema - validates any string and brands as ModelId. */
|
|
39
|
+
export const modelIdSchema = z.string().brand('ModelId')
|
|
40
|
+
|
|
41
|
+
/** Branded ModelId type */
|
|
42
|
+
export type ModelId = z.infer<typeof modelIdSchema>
|
|
43
|
+
|
|
44
|
+
/** Constructor for ModelId */
|
|
45
|
+
export const ModelId = (id: string): ModelId => id as ModelId
|
|
46
|
+
|
|
47
|
+
// LLMResponse, LLMMetrics, and LLMToolCall are now defined in ./state.ts
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot-caching fetch wrapper for integration tests.
|
|
3
|
+
*
|
|
4
|
+
* On first run (or when request changes), makes a real HTTP call and saves
|
|
5
|
+
* the request+response pair to a JSON snapshot file. On subsequent runs
|
|
6
|
+
* with the same request, returns the cached response without making a call.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const fetch = createSnapshotFetch(snapshotsDir)
|
|
10
|
+
* const provider = new AnthropicProvider({ ..., fetch })
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createHash } from 'node:crypto'
|
|
14
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
15
|
+
import { join } from 'node:path'
|
|
16
|
+
|
|
17
|
+
interface SnapshotEntry {
|
|
18
|
+
requestHash: string
|
|
19
|
+
request: {
|
|
20
|
+
url: string
|
|
21
|
+
method: string
|
|
22
|
+
headers: Record<string, string>
|
|
23
|
+
body: unknown
|
|
24
|
+
}
|
|
25
|
+
response: {
|
|
26
|
+
status: number
|
|
27
|
+
headers: Record<string, string>
|
|
28
|
+
body: unknown
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Deterministic hash of a request (URL + method + body).
|
|
34
|
+
* Headers are excluded because auth headers change between runs.
|
|
35
|
+
*/
|
|
36
|
+
function hashRequest(url: string, method: string, body: string): string {
|
|
37
|
+
const hash = createHash('sha256')
|
|
38
|
+
hash.update(method)
|
|
39
|
+
hash.update(url)
|
|
40
|
+
hash.update(stableStringify(JSON.parse(body)))
|
|
41
|
+
return hash.digest('hex').slice(0, 16)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* JSON.stringify with sorted keys for deterministic output.
|
|
46
|
+
*/
|
|
47
|
+
function stableStringify(value: unknown): string {
|
|
48
|
+
return JSON.stringify(value, (_key, val) => {
|
|
49
|
+
if (val && typeof val === 'object' && !Array.isArray(val)) {
|
|
50
|
+
return Object.fromEntries(Object.entries(val).sort(([a], [b]) => a.localeCompare(b)))
|
|
51
|
+
}
|
|
52
|
+
return val
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Strip sensitive headers (auth) from a headers object for snapshot storage.
|
|
58
|
+
*/
|
|
59
|
+
function sanitizeHeaders(headers: Record<string, string>): Record<string, string> {
|
|
60
|
+
const result: Record<string, string> = {}
|
|
61
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
62
|
+
const lower = key.toLowerCase()
|
|
63
|
+
if (lower === 'authorization' || lower === 'x-api-key') continue
|
|
64
|
+
result[key] = value
|
|
65
|
+
}
|
|
66
|
+
return result
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create a fetch function that caches request/response pairs as JSON snapshots.
|
|
71
|
+
*
|
|
72
|
+
* @param snapshotsDir - Directory to store snapshot files
|
|
73
|
+
* @param testName - Test name used as the snapshot filename
|
|
74
|
+
*/
|
|
75
|
+
type FetchFn = (input: string | URL | Request, init?: RequestInit) => Promise<Response>
|
|
76
|
+
|
|
77
|
+
export function createSnapshotFetch(
|
|
78
|
+
snapshotsDir: string,
|
|
79
|
+
testName: string,
|
|
80
|
+
): FetchFn {
|
|
81
|
+
const snapshotPath = join(snapshotsDir, `${testName}.json`)
|
|
82
|
+
|
|
83
|
+
return async (input: string | URL | Request, init?: RequestInit): Promise<Response> => {
|
|
84
|
+
const url = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url
|
|
85
|
+
const method = init?.method ?? 'GET'
|
|
86
|
+
const body = typeof init?.body === 'string' ? init.body : ''
|
|
87
|
+
|
|
88
|
+
const currentHash = hashRequest(url, method, body)
|
|
89
|
+
|
|
90
|
+
// Try loading existing snapshot
|
|
91
|
+
let snapshot: SnapshotEntry | null = null
|
|
92
|
+
try {
|
|
93
|
+
const content = await readFile(snapshotPath, 'utf-8')
|
|
94
|
+
snapshot = JSON.parse(content) as SnapshotEntry
|
|
95
|
+
} catch {
|
|
96
|
+
// No snapshot yet
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// If snapshot exists and hash matches, return cached response
|
|
100
|
+
if (snapshot && snapshot.requestHash === currentHash) {
|
|
101
|
+
return new Response(JSON.stringify(snapshot.response.body), {
|
|
102
|
+
status: snapshot.response.status,
|
|
103
|
+
headers: snapshot.response.headers,
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Make real request
|
|
108
|
+
const response = await globalThis.fetch(input, init)
|
|
109
|
+
const responseBody = await response.json()
|
|
110
|
+
|
|
111
|
+
// Extract response headers
|
|
112
|
+
const responseHeaders: Record<string, string> = {}
|
|
113
|
+
response.headers.forEach((value, key) => {
|
|
114
|
+
responseHeaders[key] = value
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// Extract request headers
|
|
118
|
+
const requestHeaders: Record<string, string> = {}
|
|
119
|
+
if (init?.headers) {
|
|
120
|
+
if (init.headers instanceof Headers) {
|
|
121
|
+
init.headers.forEach((value, key) => {
|
|
122
|
+
requestHeaders[key] = value
|
|
123
|
+
})
|
|
124
|
+
} else if (Array.isArray(init.headers)) {
|
|
125
|
+
for (const [key, value] of init.headers) {
|
|
126
|
+
requestHeaders[key] = value
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
Object.assign(requestHeaders, init.headers)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Save snapshot
|
|
134
|
+
const entry: SnapshotEntry = {
|
|
135
|
+
requestHash: currentHash,
|
|
136
|
+
request: {
|
|
137
|
+
url,
|
|
138
|
+
method,
|
|
139
|
+
headers: sanitizeHeaders(requestHeaders),
|
|
140
|
+
body: body ? JSON.parse(body) : null,
|
|
141
|
+
},
|
|
142
|
+
response: {
|
|
143
|
+
status: response.status,
|
|
144
|
+
headers: sanitizeHeaders(responseHeaders),
|
|
145
|
+
body: responseBody,
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
await mkdir(snapshotsDir, { recursive: true })
|
|
150
|
+
await writeFile(snapshotPath, JSON.stringify(entry, null, '\t'))
|
|
151
|
+
|
|
152
|
+
// Return a new Response from the parsed body (original was consumed)
|
|
153
|
+
return new Response(JSON.stringify(responseBody), {
|
|
154
|
+
status: response.status,
|
|
155
|
+
headers: responseHeaders,
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { Err, Ok, isErr, isOk } from '~/lib/utils/result.js'
|
|
6
|
+
import { applyMiddleware } from './middleware.js'
|
|
7
|
+
import { MockLLMProvider } from './mock.js'
|
|
8
|
+
import type { InferenceRequest, InferenceResponse } from './provider.js'
|
|
9
|
+
import { ModelId } from './schema.js'
|
|
10
|
+
import { createSnapshotLLMMiddleware } from './snapshot-middleware.js'
|
|
11
|
+
|
|
12
|
+
describe('SnapshotLLMMiddleware', () => {
|
|
13
|
+
let dir: string
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
dir = mkdtempSync(join(tmpdir(), 'roj-snap-'))
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
rmSync(dir, { recursive: true, force: true })
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const request = (overrides: Partial<InferenceRequest> = {}): InferenceRequest => ({
|
|
24
|
+
model: ModelId('test-model'),
|
|
25
|
+
systemPrompt: 'You are a test assistant.',
|
|
26
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
27
|
+
...overrides,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const fixedResponse: InferenceResponse = {
|
|
31
|
+
content: 'Recorded response',
|
|
32
|
+
toolCalls: [],
|
|
33
|
+
finishReason: 'stop',
|
|
34
|
+
metrics: MockLLMProvider.defaultMetrics(),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
test('records on miss and replays on hit without calling next', async () => {
|
|
38
|
+
const downstream = new MockLLMProvider(() => fixedResponse)
|
|
39
|
+
const wrapped = applyMiddleware(downstream, [createSnapshotLLMMiddleware({ snapshotsDir: dir })])
|
|
40
|
+
|
|
41
|
+
const first = await wrapped.inference(request())
|
|
42
|
+
expect(isOk(first)).toBe(true)
|
|
43
|
+
expect(downstream.getCallCount()).toBe(1)
|
|
44
|
+
|
|
45
|
+
// Snapshot file created
|
|
46
|
+
const files = readdirSync(dir)
|
|
47
|
+
expect(files.length).toBe(1)
|
|
48
|
+
expect(files[0]).toMatch(/^[0-9a-f]{16}\.json$/)
|
|
49
|
+
|
|
50
|
+
// Replay — downstream NOT called again
|
|
51
|
+
const second = await wrapped.inference(request())
|
|
52
|
+
expect(isOk(second)).toBe(true)
|
|
53
|
+
if (isOk(second)) {
|
|
54
|
+
expect(second.value.content).toBe('Recorded response')
|
|
55
|
+
}
|
|
56
|
+
expect(downstream.getCallCount()).toBe(1)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('distinct requests produce distinct snapshot files', async () => {
|
|
60
|
+
const downstream = new MockLLMProvider(() => fixedResponse)
|
|
61
|
+
const wrapped = applyMiddleware(downstream, [createSnapshotLLMMiddleware({ snapshotsDir: dir })])
|
|
62
|
+
|
|
63
|
+
await wrapped.inference(request({ messages: [{ role: 'user', content: 'A' }] }))
|
|
64
|
+
await wrapped.inference(request({ messages: [{ role: 'user', content: 'B' }] }))
|
|
65
|
+
|
|
66
|
+
expect(readdirSync(dir).length).toBe(2)
|
|
67
|
+
expect(downstream.getCallCount()).toBe(2)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('hash is stable across key-order differences', async () => {
|
|
71
|
+
const downstream = new MockLLMProvider(() => fixedResponse)
|
|
72
|
+
const wrapped = applyMiddleware(downstream, [createSnapshotLLMMiddleware({ snapshotsDir: dir })])
|
|
73
|
+
|
|
74
|
+
// Two requests identical in content but constructed with different key order
|
|
75
|
+
await wrapped.inference({
|
|
76
|
+
model: ModelId('m'),
|
|
77
|
+
systemPrompt: 's',
|
|
78
|
+
messages: [{ role: 'user', content: 'x' }],
|
|
79
|
+
temperature: 0.5,
|
|
80
|
+
maxTokens: 100,
|
|
81
|
+
})
|
|
82
|
+
await wrapped.inference({
|
|
83
|
+
maxTokens: 100,
|
|
84
|
+
temperature: 0.5,
|
|
85
|
+
messages: [{ role: 'user', content: 'x' }],
|
|
86
|
+
systemPrompt: 's',
|
|
87
|
+
model: ModelId('m'),
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Same hash → single snapshot file → downstream called once
|
|
91
|
+
expect(readdirSync(dir).length).toBe(1)
|
|
92
|
+
expect(downstream.getCallCount()).toBe(1)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('replay mode errors on miss', async () => {
|
|
96
|
+
const downstream = new MockLLMProvider(() => fixedResponse)
|
|
97
|
+
const wrapped = applyMiddleware(downstream, [
|
|
98
|
+
createSnapshotLLMMiddleware({ snapshotsDir: dir, mode: 'replay' }),
|
|
99
|
+
])
|
|
100
|
+
|
|
101
|
+
const result = await wrapped.inference(request())
|
|
102
|
+
expect(isErr(result)).toBe(true)
|
|
103
|
+
if (isErr(result)) {
|
|
104
|
+
expect(result.error.type).toBe('invalid_request')
|
|
105
|
+
expect(result.error.message).toContain('Snapshot not found')
|
|
106
|
+
}
|
|
107
|
+
expect(downstream.getCallCount()).toBe(0)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('replay mode serves existing snapshot', async () => {
|
|
111
|
+
// Pre-seed a snapshot by running once in auto mode
|
|
112
|
+
const downstream1 = new MockLLMProvider(() => fixedResponse)
|
|
113
|
+
const recording = applyMiddleware(downstream1, [createSnapshotLLMMiddleware({ snapshotsDir: dir })])
|
|
114
|
+
await recording.inference(request())
|
|
115
|
+
|
|
116
|
+
// Now a replay-only chain must hit it
|
|
117
|
+
const downstream2 = new MockLLMProvider(() => {
|
|
118
|
+
throw new Error('should not be called')
|
|
119
|
+
})
|
|
120
|
+
const replaying = applyMiddleware(downstream2, [
|
|
121
|
+
createSnapshotLLMMiddleware({ snapshotsDir: dir, mode: 'replay' }),
|
|
122
|
+
])
|
|
123
|
+
const result = await replaying.inference(request())
|
|
124
|
+
expect(isOk(result)).toBe(true)
|
|
125
|
+
if (isOk(result)) {
|
|
126
|
+
expect(result.value.content).toBe('Recorded response')
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('record mode overwrites existing snapshot', async () => {
|
|
131
|
+
// Seed with response A
|
|
132
|
+
const downstream1 = new MockLLMProvider(() => ({ ...fixedResponse, content: 'A' }))
|
|
133
|
+
const first = applyMiddleware(downstream1, [createSnapshotLLMMiddleware({ snapshotsDir: dir })])
|
|
134
|
+
await first.inference(request())
|
|
135
|
+
|
|
136
|
+
// Force re-record with response B
|
|
137
|
+
const downstream2 = new MockLLMProvider(() => ({ ...fixedResponse, content: 'B' }))
|
|
138
|
+
const second = applyMiddleware(downstream2, [
|
|
139
|
+
createSnapshotLLMMiddleware({ snapshotsDir: dir, mode: 'record' }),
|
|
140
|
+
])
|
|
141
|
+
await second.inference(request())
|
|
142
|
+
|
|
143
|
+
// Read back
|
|
144
|
+
const downstream3 = new MockLLMProvider(() => {
|
|
145
|
+
throw new Error('should not be called')
|
|
146
|
+
})
|
|
147
|
+
const third = applyMiddleware(downstream3, [
|
|
148
|
+
createSnapshotLLMMiddleware({ snapshotsDir: dir, mode: 'replay' }),
|
|
149
|
+
])
|
|
150
|
+
const result = await third.inference(request())
|
|
151
|
+
expect(isOk(result)).toBe(true)
|
|
152
|
+
if (isOk(result)) {
|
|
153
|
+
expect(result.value.content).toBe('B')
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('does not persist error responses', async () => {
|
|
158
|
+
const downstream = new MockLLMProvider(() => {
|
|
159
|
+
const err = { type: 'rate_limit' as const, message: 'throttled' }
|
|
160
|
+
throw err
|
|
161
|
+
})
|
|
162
|
+
const wrapped = applyMiddleware(downstream, [createSnapshotLLMMiddleware({ snapshotsDir: dir })])
|
|
163
|
+
|
|
164
|
+
const result = await wrapped.inference(request())
|
|
165
|
+
expect(isErr(result)).toBe(true)
|
|
166
|
+
expect(readdirSync(dir).length).toBe(0)
|
|
167
|
+
})
|
|
168
|
+
})
|