@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,967 @@
|
|
|
1
|
+
import z4 from 'zod/v4'
|
|
2
|
+
import type { DomainError } from '~/core/errors.js'
|
|
3
|
+
import type { Logger } from '~/lib/logger/logger.js'
|
|
4
|
+
import type { Result } from '~/lib/utils/result.js'
|
|
5
|
+
import type { MailboxMessage } from '../../plugins/mailbox/schema.js'
|
|
6
|
+
import type { AgentConfig } from '../agents/agent.js'
|
|
7
|
+
import type { AgentContext } from '../agents/context.js'
|
|
8
|
+
import type { AgentId } from '../agents/schema.js'
|
|
9
|
+
import type { EventStore } from '../events/event-store.js'
|
|
10
|
+
import type { BaseEvent, DomainEvent } from '../events/types.js'
|
|
11
|
+
import type { ToolResultContent } from '../llm/llm-log-types.js'
|
|
12
|
+
import type { LLMLogger } from '../llm/logger.js'
|
|
13
|
+
import type { LLMMessage } from '../llm/provider.js'
|
|
14
|
+
import type { LLMResponse } from '../llm/state.js'
|
|
15
|
+
import type { Preset } from '../preset/index.js'
|
|
16
|
+
import type { SessionContext } from '../sessions/context.js'
|
|
17
|
+
import type { StateSlice } from '../sessions/reducer.js'
|
|
18
|
+
import { createStateSlice } from '../sessions/reducer.js'
|
|
19
|
+
import type { SessionManager } from '../sessions/session-manager.js'
|
|
20
|
+
import type { SessionState } from '../sessions/state.js'
|
|
21
|
+
import type { ToolContext } from '../tools/context.js'
|
|
22
|
+
import type { ToolDefinition } from '../tools/definition.js'
|
|
23
|
+
import { createTool } from '../tools/definition.js'
|
|
24
|
+
import type { ToolResponse } from '../tools/schema.js'
|
|
25
|
+
import type { ToolCall } from '../tools/schema.js'
|
|
26
|
+
import type {
|
|
27
|
+
AfterInferenceResult,
|
|
28
|
+
AfterToolCallResult,
|
|
29
|
+
BeforeInferenceResult,
|
|
30
|
+
BeforeToolCallResult,
|
|
31
|
+
OnCompleteResult,
|
|
32
|
+
OnErrorResult,
|
|
33
|
+
OnStartResult,
|
|
34
|
+
} from './hook-types.js'
|
|
35
|
+
import type { PluginDequeueHook, PluginPendingMessages } from './index.js'
|
|
36
|
+
|
|
37
|
+
// ============================================================================
|
|
38
|
+
// Structural supertype for EventsFactory
|
|
39
|
+
// ============================================================================
|
|
40
|
+
|
|
41
|
+
type EventSourceRef = {
|
|
42
|
+
create(type: string, input: unknown): unknown
|
|
43
|
+
EventType: unknown
|
|
44
|
+
Events: unknown
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Method entry — what .method()/.managerMethod() accumulates as plain TS types
|
|
49
|
+
// ============================================================================
|
|
50
|
+
|
|
51
|
+
type MethodEntry = { input: unknown; output: unknown }
|
|
52
|
+
type ManagerMethodEntry = { input: unknown; output: unknown }
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Notification types
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Notification entry — registered via .notification() on PluginBuilder.
|
|
60
|
+
* Schema is stored for documentation/validation but not enforced at runtime.
|
|
61
|
+
*/
|
|
62
|
+
type NotificationEntry = { schema: z4.ZodType }
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A collected notification — emitted by ctx.notify() during handler/hook execution.
|
|
66
|
+
* Ephemeral (not persisted), broadcast to connected clients via transport.
|
|
67
|
+
*/
|
|
68
|
+
export interface PluginNotification {
|
|
69
|
+
pluginName: string
|
|
70
|
+
type: string
|
|
71
|
+
payload: unknown
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Plugin configuration types
|
|
76
|
+
// ============================================================================
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Session-level plugin configuration — binds a plugin name to its session config.
|
|
80
|
+
* Created via `pluginDefinition.configure(config)`.
|
|
81
|
+
*/
|
|
82
|
+
export interface SessionPluginConfig<TName extends string = string, TConfig = unknown> {
|
|
83
|
+
readonly pluginName: TName
|
|
84
|
+
readonly config: TConfig
|
|
85
|
+
readonly definition: PluginDefinition<TName, TConfig, any, any, any>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Agent-level plugin configuration — binds a plugin name to its per-agent config.
|
|
90
|
+
* Created via `pluginDefinition.configureAgent(config)`.
|
|
91
|
+
*/
|
|
92
|
+
export interface AgentPluginConfig<TName extends string = string, TAgentConfig = unknown> {
|
|
93
|
+
readonly pluginName: TName
|
|
94
|
+
readonly config: TAgentConfig
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ============================================================================
|
|
98
|
+
// Dependency type utilities
|
|
99
|
+
// ============================================================================
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Extract typed session-level method callers from a PluginDefinition.
|
|
103
|
+
* Uses indexed access on _methods brand (pre-resolved types) instead of
|
|
104
|
+
* conditional `infer` on 5-param generic + Zod type extraction.
|
|
105
|
+
*/
|
|
106
|
+
type PluginMethodCallers<TPlugin extends PluginDefinition<string, any, any, any, any>> = {
|
|
107
|
+
[K in keyof NonNullable<TPlugin['_methods']>]: (
|
|
108
|
+
input: NonNullable<TPlugin['_methods']>[K]['input'],
|
|
109
|
+
) => Promise<Result<NonNullable<TPlugin['_methods']>[K]['output'], DomainError>>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Build deps object type from an array of PluginDefinition instances.
|
|
114
|
+
* Maps each plugin's TName to its session-level method callers.
|
|
115
|
+
*/
|
|
116
|
+
export type DepsFromPlugins<TPlugins extends readonly PluginDefinition<string, any, any, any, any>[]> = {
|
|
117
|
+
[P in TPlugins[number] as P['name']]: PluginMethodCallers<P>
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Caller context
|
|
122
|
+
// ============================================================================
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Identifies who is calling a plugin method.
|
|
126
|
+
* - 'agent': called via agent tool (ctx.self)
|
|
127
|
+
* - 'client': called via SPA RPC (user-initiated)
|
|
128
|
+
* - 'system': called via backend/webhook (trusted)
|
|
129
|
+
*/
|
|
130
|
+
export type CallerContext = {
|
|
131
|
+
source: 'agent' | 'client' | 'system'
|
|
132
|
+
meta: Record<string, unknown>
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const DEFAULT_CALLER: CallerContext = { source: 'client', meta: {} }
|
|
136
|
+
export const AGENT_CALLER: CallerContext = { source: 'agent', meta: {} }
|
|
137
|
+
|
|
138
|
+
// ============================================================================
|
|
139
|
+
// Context types
|
|
140
|
+
// ============================================================================
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Context for method handlers — has pluginContext + pluginState + pluginConfig, no self.
|
|
144
|
+
*/
|
|
145
|
+
export type MethodHandlerContext<TConfig, TContext, TState, TNotifications extends Record<string, NotificationEntry> = {}, TDeps = {}> =
|
|
146
|
+
& SessionContext
|
|
147
|
+
& {
|
|
148
|
+
caller: CallerContext
|
|
149
|
+
pluginConfig: TConfig
|
|
150
|
+
pluginContext: TContext
|
|
151
|
+
pluginState: TState
|
|
152
|
+
scheduleAgent: (agentId: AgentId) => void
|
|
153
|
+
notify: <K extends string & keyof TNotifications>(type: K, payload: z4.infer<TNotifications[K]['schema']>) => void
|
|
154
|
+
deps: TDeps
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Context for hooks, tools callbacks, status — has self + pluginConfig.
|
|
159
|
+
*/
|
|
160
|
+
export type PluginHookContext<
|
|
161
|
+
TConfig,
|
|
162
|
+
TMethods extends Record<string, MethodEntry>,
|
|
163
|
+
TAgentConfig,
|
|
164
|
+
TContext,
|
|
165
|
+
TState,
|
|
166
|
+
TNotifications extends Record<string, NotificationEntry> = {},
|
|
167
|
+
TDeps = {},
|
|
168
|
+
> = AgentContext & {
|
|
169
|
+
pluginConfig: TConfig
|
|
170
|
+
pluginAgentConfig?: TAgentConfig
|
|
171
|
+
pluginContext: TContext
|
|
172
|
+
pluginState: TState
|
|
173
|
+
self: PluginSelf<TMethods>
|
|
174
|
+
schedule: () => void
|
|
175
|
+
notify: <K extends string & keyof TNotifications>(type: K, payload: z4.infer<TNotifications[K]['schema']>) => void
|
|
176
|
+
deps: TDeps
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Context for session-level hooks — has pluginConfig.
|
|
181
|
+
*/
|
|
182
|
+
export type PluginSessionHookContext<
|
|
183
|
+
TConfig,
|
|
184
|
+
TMethods extends Record<string, MethodEntry>,
|
|
185
|
+
TContext,
|
|
186
|
+
TState,
|
|
187
|
+
TNotifications extends Record<string, NotificationEntry> = {},
|
|
188
|
+
TDeps = {},
|
|
189
|
+
> = SessionContext & {
|
|
190
|
+
pluginConfig: TConfig
|
|
191
|
+
pluginContext: TContext
|
|
192
|
+
pluginState: TState
|
|
193
|
+
self: PluginSelf<TMethods>
|
|
194
|
+
scheduleAgent: (agentId: AgentId) => void
|
|
195
|
+
notify: <K extends string & keyof TNotifications>(type: K, payload: z4.infer<TNotifications[K]['schema']>) => void
|
|
196
|
+
deps: TDeps
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Context for manager-level method handlers — operates outside session context.
|
|
201
|
+
* Used for operations like session creation, listing, preset queries.
|
|
202
|
+
*/
|
|
203
|
+
export type ManagerMethodContext = {
|
|
204
|
+
sessionManager: SessionManager
|
|
205
|
+
eventStore: EventStore
|
|
206
|
+
presets: Map<string, Preset>
|
|
207
|
+
logger: Logger
|
|
208
|
+
/** Optional LLM logger for LLM call queries */
|
|
209
|
+
llmLogger?: LLMLogger
|
|
210
|
+
/** Host-environment adapters (filesystem, process). */
|
|
211
|
+
platform: import('~/platform/index.js').Platform
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Self accessor — typed method callers derived from accumulated types.
|
|
216
|
+
*/
|
|
217
|
+
type PluginSelf<TMethods extends Record<string, MethodEntry>> = {
|
|
218
|
+
[K in keyof TMethods]: (input: TMethods[K]['input']) => Promise<Result<TMethods[K]['output'], DomainError>>
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// ============================================================================
|
|
222
|
+
// Hook type map — maps hook name to its extra context fields
|
|
223
|
+
// ============================================================================
|
|
224
|
+
|
|
225
|
+
type HookMap<TCtx> = {
|
|
226
|
+
onStart: (ctx: TCtx) => Promise<OnStartResult>
|
|
227
|
+
beforeInference: (ctx: TCtx & { pendingMessages: MailboxMessage[]; turnNumber: number }) => Promise<BeforeInferenceResult>
|
|
228
|
+
afterInference: (ctx: TCtx & { response: LLMResponse; turnNumber: number }) => Promise<AfterInferenceResult>
|
|
229
|
+
beforeToolCall: (ctx: TCtx & { toolCall: ToolCall }) => Promise<BeforeToolCallResult>
|
|
230
|
+
afterToolCall: (ctx: TCtx & { toolCall: ToolCall; result: { isError: boolean; content: ToolResultContent } }) => Promise<AfterToolCallResult>
|
|
231
|
+
onComplete: (ctx: TCtx) => Promise<OnCompleteResult>
|
|
232
|
+
onError: (ctx: TCtx & { error: string }) => Promise<OnErrorResult>
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
type SessionHookMap<TCtx> = {
|
|
236
|
+
onSessionReady: (ctx: TCtx) => Promise<void>
|
|
237
|
+
onSessionClose: (ctx: TCtx) => Promise<void>
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ============================================================================
|
|
241
|
+
// Base (erased) context types — what Agent/Session provide at runtime
|
|
242
|
+
// ============================================================================
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Base plugin hook context — agent-level hooks, tools, status, dequeue.
|
|
246
|
+
* This is the type-erased form used by ConfiguredPlugin consumers.
|
|
247
|
+
*/
|
|
248
|
+
export type BasePluginHookContext = AgentContext & {
|
|
249
|
+
pluginConfig: unknown
|
|
250
|
+
pluginAgentConfig: unknown
|
|
251
|
+
pluginContext: unknown
|
|
252
|
+
pluginState: unknown
|
|
253
|
+
self: Record<string, (input: unknown) => Promise<unknown>>
|
|
254
|
+
schedule: () => void
|
|
255
|
+
notify: (type: string, payload: unknown) => void
|
|
256
|
+
deps: Record<string, Record<string, (input: unknown) => Promise<Result<unknown, DomainError>>>>
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Base session hook context — session-level hooks (onSessionReady, onSessionClose).
|
|
261
|
+
*/
|
|
262
|
+
export type BaseSessionHookContext = SessionContext & {
|
|
263
|
+
caller: CallerContext
|
|
264
|
+
pluginConfig: unknown
|
|
265
|
+
pluginContext: unknown
|
|
266
|
+
pluginState: unknown
|
|
267
|
+
self: Record<string, (input: unknown) => Promise<unknown>>
|
|
268
|
+
scheduleAgent: (agentId: AgentId) => void
|
|
269
|
+
notify: (type: string, payload: unknown) => void
|
|
270
|
+
deps: Record<string, Record<string, (input: unknown) => Promise<Result<unknown, DomainError>>>>
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Base method handler context — session-level method handlers.
|
|
275
|
+
*/
|
|
276
|
+
export type BaseMethodHandlerContext = SessionContext & {
|
|
277
|
+
caller: CallerContext
|
|
278
|
+
pluginConfig: unknown
|
|
279
|
+
pluginContext: unknown
|
|
280
|
+
pluginState: unknown
|
|
281
|
+
scheduleAgent: (agentId: AgentId) => void
|
|
282
|
+
notify: (type: string, payload: unknown) => void
|
|
283
|
+
deps: Record<string, Record<string, (input: unknown) => Promise<Result<unknown, DomainError>>>>
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ============================================================================
|
|
287
|
+
// Erased hook maps — typed return types, erased context
|
|
288
|
+
// ============================================================================
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Agent-level hook map with proper return types but erased context.
|
|
292
|
+
*/
|
|
293
|
+
type ErasedAgentHookMap = {
|
|
294
|
+
onStart: (ctx: BasePluginHookContext) => Promise<OnStartResult>
|
|
295
|
+
beforeInference: (ctx: BasePluginHookContext & { pendingMessages: MailboxMessage[]; turnNumber: number }) => Promise<BeforeInferenceResult>
|
|
296
|
+
afterInference: (ctx: BasePluginHookContext & { response: LLMResponse; turnNumber: number }) => Promise<AfterInferenceResult>
|
|
297
|
+
beforeToolCall: (ctx: BasePluginHookContext & { toolCall: ToolCall }) => Promise<BeforeToolCallResult>
|
|
298
|
+
afterToolCall: (
|
|
299
|
+
ctx: BasePluginHookContext & { toolCall: ToolCall; result: { isError: boolean; content: ToolResultContent } },
|
|
300
|
+
) => Promise<AfterToolCallResult>
|
|
301
|
+
onComplete: (ctx: BasePluginHookContext) => Promise<OnCompleteResult>
|
|
302
|
+
onError: (ctx: BasePluginHookContext & { error: string }) => Promise<OnErrorResult>
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Session-level hook map with proper return types but erased context.
|
|
307
|
+
*/
|
|
308
|
+
type ErasedSessionHookMap = {
|
|
309
|
+
onSessionReady: (ctx: BaseSessionHookContext) => Promise<void>
|
|
310
|
+
onSessionClose: (ctx: BaseSessionHookContext) => Promise<void>
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// ============================================================================
|
|
314
|
+
// Output types
|
|
315
|
+
// ============================================================================
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* ConfiguredPlugin — runtime-ready plugin instance with config bound.
|
|
319
|
+
* This is the shape that session/runtime code consumes.
|
|
320
|
+
*/
|
|
321
|
+
export interface ConfiguredPlugin {
|
|
322
|
+
name: string
|
|
323
|
+
methods: Record<string, {
|
|
324
|
+
input: z4.ZodType
|
|
325
|
+
output: z4.ZodType
|
|
326
|
+
handler: (ctx: BaseMethodHandlerContext, input: unknown) => Promise<Result<unknown, DomainError>>
|
|
327
|
+
}>
|
|
328
|
+
/** Registered notification types (for introspection/documentation) */
|
|
329
|
+
notifications: Record<string, { schema: z4.ZodType }>
|
|
330
|
+
/** Names of dependency plugins for runtime wiring */
|
|
331
|
+
dependencyNames: string[]
|
|
332
|
+
createContext?: (ctx: SessionContext) => Promise<unknown>
|
|
333
|
+
state?: {
|
|
334
|
+
key: string
|
|
335
|
+
events: readonly EventSourceRef[]
|
|
336
|
+
initialState: () => unknown
|
|
337
|
+
reduce: (state: unknown, event: DomainEvent, sessionState: SessionState) => unknown
|
|
338
|
+
}
|
|
339
|
+
agentHooks?: Partial<ErasedAgentHookMap>
|
|
340
|
+
sessionHooks?: Partial<ErasedSessionHookMap>
|
|
341
|
+
// ToolDefinition<any> required: ToolDefinition is contravariant in TInput,
|
|
342
|
+
// so ToolDefinition<SpecificInput> is not assignable to ToolDefinition<unknown>
|
|
343
|
+
getTools?: (ctx: BasePluginHookContext) => ToolDefinition<any>[]
|
|
344
|
+
getStatus?: (ctx: BasePluginHookContext) => string | null
|
|
345
|
+
getSystemPrompt?: (ctx: BasePluginHookContext) => string | null
|
|
346
|
+
dequeue?: {
|
|
347
|
+
hasPendingMessages: (ctx: BasePluginHookContext) => boolean
|
|
348
|
+
getPendingMessages: (ctx: BasePluginHookContext) => PluginPendingMessages | null
|
|
349
|
+
markConsumed: (ctx: BasePluginHookContext, token: unknown) => Promise<void>
|
|
350
|
+
}
|
|
351
|
+
slice?: StateSlice
|
|
352
|
+
isEnabled?: (ctx: { pluginConfig: unknown; pluginAgentConfig: unknown; agentConfig: AgentConfig }) => boolean
|
|
353
|
+
isSessionEnabled?: (ctx: { pluginConfig: unknown }) => boolean
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* PluginDefinition — static global constant. Call .create(config) to bind config.
|
|
358
|
+
* managerMethods are available without creating a session (manager-level operations).
|
|
359
|
+
*/
|
|
360
|
+
/** Erased runtime shape for manager methods — used for iteration in SessionManager */
|
|
361
|
+
type ManagerMethodRecord = Record<string, {
|
|
362
|
+
input: z4.ZodType
|
|
363
|
+
output: z4.ZodType
|
|
364
|
+
handler: (ctx: ManagerMethodContext, input: unknown) => Promise<Result<unknown, DomainError>>
|
|
365
|
+
}>
|
|
366
|
+
|
|
367
|
+
/** Erased runtime shape for session method schemas — no handler, just input/output */
|
|
368
|
+
type SessionMethodSchemaRecord = Record<string, {
|
|
369
|
+
input: z4.ZodType
|
|
370
|
+
output: z4.ZodType
|
|
371
|
+
}>
|
|
372
|
+
|
|
373
|
+
export interface PluginDefinition<
|
|
374
|
+
TName extends string = string,
|
|
375
|
+
TConfig = void,
|
|
376
|
+
TAgentConfig = void,
|
|
377
|
+
TManagerMethods extends Record<string, ManagerMethodEntry> = {},
|
|
378
|
+
TMethods extends Record<string, MethodEntry> = {},
|
|
379
|
+
> {
|
|
380
|
+
name: TName
|
|
381
|
+
create(...args: TConfig extends void ? [] : [config: TConfig]): ConfiguredPlugin
|
|
382
|
+
configure(...args: TConfig extends void ? [] : [config: TConfig]): SessionPluginConfig<TName, TConfig>
|
|
383
|
+
configureAgent(...args: TAgentConfig extends void ? [] : [config: TAgentConfig]): AgentPluginConfig<TName, TAgentConfig>
|
|
384
|
+
managerMethods: ManagerMethodRecord
|
|
385
|
+
/** Session-level method schemas — available statically without calling .create() */
|
|
386
|
+
sessionMethods: SessionMethodSchemaRecord
|
|
387
|
+
/** Type-only brand — carries session method types as plain TS types */
|
|
388
|
+
readonly _methods?: TMethods
|
|
389
|
+
/** Type-only brand — carries manager method types as plain TS types */
|
|
390
|
+
readonly _managerMethods?: TManagerMethods
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// ============================================================================
|
|
394
|
+
// Internal config accumulator
|
|
395
|
+
// ============================================================================
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Static tool spec — stored by .tool(), converted to ToolDefinition at runtime.
|
|
399
|
+
* Keeps the 3-arg execute signature so we can bind pluginCtx via closure.
|
|
400
|
+
*/
|
|
401
|
+
interface StaticToolSpec {
|
|
402
|
+
name: string
|
|
403
|
+
description: string
|
|
404
|
+
input: z4.ZodType
|
|
405
|
+
execute: (input: unknown, toolCtx: ToolContext, pluginCtx: BasePluginHookContext) => Promise<ToolResponse>
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
interface BuilderConfig {
|
|
409
|
+
name: string
|
|
410
|
+
events: readonly EventSourceRef[]
|
|
411
|
+
/** Names of dependency plugins — stored for runtime wiring */
|
|
412
|
+
dependencyNames: string[]
|
|
413
|
+
stateConfig: {
|
|
414
|
+
key: string
|
|
415
|
+
initial: () => unknown
|
|
416
|
+
reduce: (state: unknown, event: unknown, sessionState: SessionState, pluginConfig: unknown) => unknown
|
|
417
|
+
} | undefined
|
|
418
|
+
contextFactory: ((ctx: SessionContext, pluginConfig: unknown) => Promise<unknown>) | undefined
|
|
419
|
+
isSessionEnabledFn: ((ctx: { pluginConfig: unknown }) => boolean) | undefined
|
|
420
|
+
methods: Record<string, {
|
|
421
|
+
input: z4.ZodType
|
|
422
|
+
output: z4.ZodType
|
|
423
|
+
handler: (ctx: BaseMethodHandlerContext, input: unknown) => Promise<Result<unknown, DomainError>>
|
|
424
|
+
}>
|
|
425
|
+
managerMethods: Record<string, {
|
|
426
|
+
input: z4.ZodType
|
|
427
|
+
output: z4.ZodType
|
|
428
|
+
handler: (ctx: ManagerMethodContext, input: unknown) => Promise<Result<unknown, DomainError>>
|
|
429
|
+
}>
|
|
430
|
+
notifications: Record<string, { schema: z4.ZodType }>
|
|
431
|
+
staticTools: StaticToolSpec[]
|
|
432
|
+
dynamicTools: ((ctx: BasePluginHookContext) => ToolDefinition<any>[]) | undefined
|
|
433
|
+
statusFn: ((ctx: BasePluginHookContext) => string | null) | undefined
|
|
434
|
+
systemPromptFn: ((ctx: BasePluginHookContext) => string | null) | undefined
|
|
435
|
+
agentHooks: Partial<ErasedAgentHookMap>
|
|
436
|
+
sessionHooks: Partial<ErasedSessionHookMap>
|
|
437
|
+
isEnabledFn: ((ctx: { pluginConfig: unknown; pluginAgentConfig: unknown; agentConfig: AgentConfig }) => boolean) | undefined
|
|
438
|
+
dequeueHook: {
|
|
439
|
+
hasPendingMessages: (ctx: BasePluginHookContext) => boolean
|
|
440
|
+
getPendingMessages: (ctx: BasePluginHookContext) => PluginPendingMessages | null
|
|
441
|
+
markConsumed: (ctx: BasePluginHookContext, token: unknown) => Promise<void>
|
|
442
|
+
} | undefined
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// ============================================================================
|
|
446
|
+
// PluginBuilder
|
|
447
|
+
// ============================================================================
|
|
448
|
+
|
|
449
|
+
export class PluginBuilder<
|
|
450
|
+
TName extends string,
|
|
451
|
+
TConfig,
|
|
452
|
+
TContext,
|
|
453
|
+
TState,
|
|
454
|
+
TMethods extends Record<string, MethodEntry>,
|
|
455
|
+
TManagerMethods extends Record<string, ManagerMethodEntry>,
|
|
456
|
+
TAgentConfig,
|
|
457
|
+
TFactories extends readonly EventSourceRef[],
|
|
458
|
+
TNotifications extends Record<string, NotificationEntry> = {},
|
|
459
|
+
TDeps = {},
|
|
460
|
+
> {
|
|
461
|
+
/** @internal */
|
|
462
|
+
_cfg: BuilderConfig
|
|
463
|
+
/** @internal */
|
|
464
|
+
readonly _name: TName
|
|
465
|
+
|
|
466
|
+
constructor(name: TName, cfg?: BuilderConfig) {
|
|
467
|
+
this._name = name
|
|
468
|
+
this._cfg = cfg ?? {
|
|
469
|
+
name,
|
|
470
|
+
events: [],
|
|
471
|
+
dependencyNames: [],
|
|
472
|
+
stateConfig: undefined,
|
|
473
|
+
contextFactory: undefined,
|
|
474
|
+
isSessionEnabledFn: undefined,
|
|
475
|
+
methods: {},
|
|
476
|
+
managerMethods: {},
|
|
477
|
+
notifications: {},
|
|
478
|
+
staticTools: [],
|
|
479
|
+
dynamicTools: undefined,
|
|
480
|
+
statusFn: undefined,
|
|
481
|
+
systemPromptFn: undefined,
|
|
482
|
+
agentHooks: {},
|
|
483
|
+
sessionHooks: {},
|
|
484
|
+
isEnabledFn: undefined,
|
|
485
|
+
dequeueHook: undefined,
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// --- Setup ---
|
|
490
|
+
|
|
491
|
+
pluginConfig<T>(): PluginBuilder<TName, T, TContext, TState, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, TDeps> {
|
|
492
|
+
return this as unknown as PluginBuilder<TName, T, TContext, TState, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, TDeps>
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
events<const F extends readonly EventSourceRef[]>(
|
|
496
|
+
factories: F,
|
|
497
|
+
): PluginBuilder<TName, TConfig, TContext, TState, TMethods, TManagerMethods, TAgentConfig, F, TNotifications, TDeps> {
|
|
498
|
+
this._cfg.events = factories
|
|
499
|
+
return this as unknown as PluginBuilder<TName, TConfig, TContext, TState, TMethods, TManagerMethods, TAgentConfig, F, TNotifications, TDeps>
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
state<S>(config: {
|
|
503
|
+
key: string
|
|
504
|
+
initial: () => S
|
|
505
|
+
reduce: (state: S, event: TFactories[number]['EventType'] & BaseEvent<string>, sessionState: SessionState, pluginConfig: TConfig) => S
|
|
506
|
+
}): PluginBuilder<TName, TConfig, TContext, S, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, TDeps> {
|
|
507
|
+
this._cfg.stateConfig = config as BuilderConfig['stateConfig']
|
|
508
|
+
return this as unknown as PluginBuilder<TName, TConfig, TContext, S, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, TDeps>
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
context<C>(
|
|
512
|
+
factory: (ctx: SessionContext, pluginConfig: TConfig) => Promise<C>,
|
|
513
|
+
): PluginBuilder<TName, TConfig, C, TState, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, TDeps> {
|
|
514
|
+
this._cfg.contextFactory = factory as BuilderConfig['contextFactory']
|
|
515
|
+
return this as unknown as PluginBuilder<TName, TConfig, C, TState, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, TDeps>
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
agentConfig<A>(): PluginBuilder<TName, TConfig, TContext, TState, TMethods, TManagerMethods, A, TFactories, TNotifications, TDeps> {
|
|
519
|
+
return this as unknown as PluginBuilder<TName, TConfig, TContext, TState, TMethods, TManagerMethods, A, TFactories, TNotifications, TDeps>
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// --- Dependencies ---
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Declare dependencies on other plugins. The dependency plugins' session-level methods
|
|
526
|
+
* become available as `ctx.deps.pluginName.methodName(input)` in all handler contexts.
|
|
527
|
+
*/
|
|
528
|
+
dependencies<const TPlugins extends readonly PluginDefinition<string, any, any, any, any>[]>(
|
|
529
|
+
plugins: TPlugins,
|
|
530
|
+
): PluginBuilder<TName, TConfig, TContext, TState, TMethods, TManagerMethods, TAgentConfig, TFactories, TNotifications, DepsFromPlugins<TPlugins>> {
|
|
531
|
+
this._cfg.dependencyNames = plugins.map((p) => p.name)
|
|
532
|
+
return this as unknown as PluginBuilder<
|
|
533
|
+
TName,
|
|
534
|
+
TConfig,
|
|
535
|
+
TContext,
|
|
536
|
+
TState,
|
|
537
|
+
TMethods,
|
|
538
|
+
TManagerMethods,
|
|
539
|
+
TAgentConfig,
|
|
540
|
+
TFactories,
|
|
541
|
+
TNotifications,
|
|
542
|
+
DepsFromPlugins<TPlugins>
|
|
543
|
+
>
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// --- Methods ---
|
|
547
|
+
|
|
548
|
+
method<TMethodName extends string, TInput, TOutput>(
|
|
549
|
+
name: TMethodName,
|
|
550
|
+
def: {
|
|
551
|
+
input: z4.ZodSchema<TInput>
|
|
552
|
+
output: z4.ZodSchema<TOutput>
|
|
553
|
+
handler: (ctx: MethodHandlerContext<TConfig, TContext, TState, TNotifications, TDeps>, input: TInput) => Promise<Result<TOutput, DomainError>>
|
|
554
|
+
},
|
|
555
|
+
): PluginBuilder<
|
|
556
|
+
TName,
|
|
557
|
+
TConfig,
|
|
558
|
+
TContext,
|
|
559
|
+
TState,
|
|
560
|
+
TMethods & Record<TMethodName, { input: TInput; output: TOutput }>,
|
|
561
|
+
TManagerMethods,
|
|
562
|
+
TAgentConfig,
|
|
563
|
+
TFactories,
|
|
564
|
+
TNotifications,
|
|
565
|
+
TDeps
|
|
566
|
+
> {
|
|
567
|
+
this._cfg.methods[name] = def as BuilderConfig['methods'][string]
|
|
568
|
+
return this as unknown as PluginBuilder<
|
|
569
|
+
TName,
|
|
570
|
+
TConfig,
|
|
571
|
+
TContext,
|
|
572
|
+
TState,
|
|
573
|
+
TMethods & Record<TMethodName, { input: TInput; output: TOutput }>,
|
|
574
|
+
TManagerMethods,
|
|
575
|
+
TAgentConfig,
|
|
576
|
+
TFactories,
|
|
577
|
+
TNotifications,
|
|
578
|
+
TDeps
|
|
579
|
+
>
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// --- Manager Methods ---
|
|
583
|
+
|
|
584
|
+
managerMethod<TMethodName extends string, TInput, TOutput>(
|
|
585
|
+
name: TMethodName,
|
|
586
|
+
def: {
|
|
587
|
+
input: z4.ZodSchema<TInput>
|
|
588
|
+
output: z4.ZodSchema<TOutput>
|
|
589
|
+
handler: (ctx: ManagerMethodContext, input: TInput) => Promise<Result<TOutput, DomainError>>
|
|
590
|
+
},
|
|
591
|
+
): PluginBuilder<
|
|
592
|
+
TName,
|
|
593
|
+
TConfig,
|
|
594
|
+
TContext,
|
|
595
|
+
TState,
|
|
596
|
+
TMethods,
|
|
597
|
+
TManagerMethods & Record<TMethodName, { input: TInput; output: TOutput }>,
|
|
598
|
+
TAgentConfig,
|
|
599
|
+
TFactories,
|
|
600
|
+
TNotifications,
|
|
601
|
+
TDeps
|
|
602
|
+
> {
|
|
603
|
+
this._cfg.managerMethods[name] = def as BuilderConfig['managerMethods'][string]
|
|
604
|
+
return this as unknown as PluginBuilder<
|
|
605
|
+
TName,
|
|
606
|
+
TConfig,
|
|
607
|
+
TContext,
|
|
608
|
+
TState,
|
|
609
|
+
TMethods,
|
|
610
|
+
TManagerMethods & Record<TMethodName, { input: TInput; output: TOutput }>,
|
|
611
|
+
TAgentConfig,
|
|
612
|
+
TFactories,
|
|
613
|
+
TNotifications,
|
|
614
|
+
TDeps
|
|
615
|
+
>
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// --- Notifications ---
|
|
619
|
+
|
|
620
|
+
notification<TNotifName extends string, TPayload>(
|
|
621
|
+
name: TNotifName,
|
|
622
|
+
def: { schema: z4.ZodSchema<TPayload> },
|
|
623
|
+
): PluginBuilder<
|
|
624
|
+
TName,
|
|
625
|
+
TConfig,
|
|
626
|
+
TContext,
|
|
627
|
+
TState,
|
|
628
|
+
TMethods,
|
|
629
|
+
TManagerMethods,
|
|
630
|
+
TAgentConfig,
|
|
631
|
+
TFactories,
|
|
632
|
+
TNotifications & Record<TNotifName, { schema: typeof def.schema }>,
|
|
633
|
+
TDeps
|
|
634
|
+
> {
|
|
635
|
+
this._cfg.notifications[name] = def
|
|
636
|
+
return this as unknown as PluginBuilder<
|
|
637
|
+
TName,
|
|
638
|
+
TConfig,
|
|
639
|
+
TContext,
|
|
640
|
+
TState,
|
|
641
|
+
TMethods,
|
|
642
|
+
TManagerMethods,
|
|
643
|
+
TAgentConfig,
|
|
644
|
+
TFactories,
|
|
645
|
+
TNotifications & Record<TNotifName, { schema: typeof def.schema }>,
|
|
646
|
+
TDeps
|
|
647
|
+
>
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// --- Tools ---
|
|
651
|
+
|
|
652
|
+
tool<TInput>(name: string, def: {
|
|
653
|
+
description: string
|
|
654
|
+
input: z4.ZodSchema<TInput>
|
|
655
|
+
execute: (
|
|
656
|
+
input: TInput,
|
|
657
|
+
toolCtx: ToolContext,
|
|
658
|
+
pluginCtx: PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>,
|
|
659
|
+
) => Promise<ToolResponse>
|
|
660
|
+
}): this {
|
|
661
|
+
this._cfg.staticTools.push({
|
|
662
|
+
name,
|
|
663
|
+
description: def.description,
|
|
664
|
+
input: def.input,
|
|
665
|
+
// Erase TInput → unknown at the boundary (PluginBuilder → BuilderConfig)
|
|
666
|
+
execute: def.execute as StaticToolSpec['execute'],
|
|
667
|
+
})
|
|
668
|
+
return this
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ToolDefinition<TInput> is contravariant, need any for assignment
|
|
672
|
+
tools(fn: (ctx: PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>) => ToolDefinition<any>[]): this {
|
|
673
|
+
this._cfg.dynamicTools = fn as BuilderConfig['dynamicTools']
|
|
674
|
+
return this
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// --- Status ---
|
|
678
|
+
|
|
679
|
+
status(fn: (ctx: PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>) => string | null): this {
|
|
680
|
+
this._cfg.statusFn = fn as BuilderConfig['statusFn']
|
|
681
|
+
return this
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// --- System Prompt ---
|
|
685
|
+
|
|
686
|
+
systemPrompt(fn: (ctx: PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>) => string | null): this {
|
|
687
|
+
this._cfg.systemPromptFn = fn as BuilderConfig['systemPromptFn']
|
|
688
|
+
return this
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// --- Hooks ---
|
|
692
|
+
|
|
693
|
+
hook<TName extends keyof HookMap<PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>>>(
|
|
694
|
+
name: TName,
|
|
695
|
+
fn: HookMap<PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>>[TName],
|
|
696
|
+
): this {
|
|
697
|
+
;(this._cfg.agentHooks as Record<string, unknown>)[name] = fn
|
|
698
|
+
return this
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
sessionHook<TName extends keyof SessionHookMap<PluginSessionHookContext<TConfig, TMethods, TContext, TState, TNotifications, TDeps>>>(
|
|
702
|
+
name: TName,
|
|
703
|
+
fn: SessionHookMap<PluginSessionHookContext<TConfig, TMethods, TContext, TState, TNotifications, TDeps>>[TName],
|
|
704
|
+
): this {
|
|
705
|
+
;(this._cfg.sessionHooks as Record<string, unknown>)[name] = fn
|
|
706
|
+
return this
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// --- Conditional activation ---
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Define a function to determine if this plugin is enabled at session level.
|
|
713
|
+
* Called once when building plugins for a session.
|
|
714
|
+
*
|
|
715
|
+
* @param fn Function that receives plugin config and returns true if plugin should be active
|
|
716
|
+
*/
|
|
717
|
+
isSessionEnabled(
|
|
718
|
+
fn: (ctx: { pluginConfig: TConfig | undefined }) => boolean,
|
|
719
|
+
): this {
|
|
720
|
+
this._cfg.isSessionEnabledFn = fn as BuilderConfig['isSessionEnabledFn']
|
|
721
|
+
return this
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Define a function to determine if this plugin is enabled for a specific agent.
|
|
726
|
+
* Called once when creating agent plugins.
|
|
727
|
+
*
|
|
728
|
+
* @param fn Function that receives context and returns true if plugin should be active
|
|
729
|
+
*/
|
|
730
|
+
isEnabled(
|
|
731
|
+
fn: (ctx: {
|
|
732
|
+
pluginConfig: TConfig
|
|
733
|
+
pluginAgentConfig: TAgentConfig | undefined
|
|
734
|
+
agentConfig: AgentConfig
|
|
735
|
+
}) => boolean,
|
|
736
|
+
): this {
|
|
737
|
+
this._cfg.isEnabledFn = fn as BuilderConfig['isEnabledFn']
|
|
738
|
+
return this
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// --- Dequeue ---
|
|
742
|
+
|
|
743
|
+
dequeue<TToken>(hook: PluginDequeueHook<PluginHookContext<TConfig, TMethods, TAgentConfig, TContext, TState, TNotifications, TDeps>, TToken>): this {
|
|
744
|
+
this._cfg.dequeueHook = hook as BuilderConfig['dequeueHook']
|
|
745
|
+
return this
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// --- Build ---
|
|
749
|
+
|
|
750
|
+
build(): PluginDefinition<TName, TConfig, TAgentConfig, TManagerMethods, TMethods> {
|
|
751
|
+
const cfg = this._cfg
|
|
752
|
+
|
|
753
|
+
// Build session method schemas (input/output only, no handlers)
|
|
754
|
+
const sessionMethods: Record<string, { input: z4.ZodType; output: z4.ZodType }> = {}
|
|
755
|
+
for (const [name, method] of Object.entries(cfg.methods)) {
|
|
756
|
+
sessionMethods[name] = { input: method.input, output: method.output }
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const name = this._name
|
|
760
|
+
|
|
761
|
+
const def: PluginDefinition<TName, TConfig, TAgentConfig, TManagerMethods, TMethods> = {
|
|
762
|
+
name,
|
|
763
|
+
create: ((...args: unknown[]) => {
|
|
764
|
+
const pluginConfig = args[0]
|
|
765
|
+
return buildConfiguredPlugin(cfg, pluginConfig)
|
|
766
|
+
}) as PluginDefinition<TName, TConfig, TAgentConfig, TManagerMethods, TMethods>['create'],
|
|
767
|
+
configure: ((...args: unknown[]) => ({
|
|
768
|
+
pluginName: name,
|
|
769
|
+
config: args[0],
|
|
770
|
+
definition: def,
|
|
771
|
+
})) as PluginDefinition<TName, TConfig, TAgentConfig, TManagerMethods, TMethods>['configure'],
|
|
772
|
+
configureAgent: ((...args: unknown[]) => ({
|
|
773
|
+
pluginName: name,
|
|
774
|
+
config: args[0],
|
|
775
|
+
})) as PluginDefinition<TName, TConfig, TAgentConfig, TManagerMethods, TMethods>['configureAgent'],
|
|
776
|
+
managerMethods: cfg.managerMethods,
|
|
777
|
+
sessionMethods,
|
|
778
|
+
}
|
|
779
|
+
return def
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// ============================================================================
|
|
784
|
+
// Build configured plugin — binds config into all closures
|
|
785
|
+
// ============================================================================
|
|
786
|
+
|
|
787
|
+
function buildConfiguredPlugin(cfg: BuilderConfig, pluginConfig: unknown): ConfiguredPlugin {
|
|
788
|
+
let slice: StateSlice | undefined
|
|
789
|
+
if (cfg.stateConfig) {
|
|
790
|
+
const stateReduce = cfg.stateConfig.reduce
|
|
791
|
+
slice = createStateSlice({
|
|
792
|
+
key: cfg.stateConfig.key,
|
|
793
|
+
events: cfg.events,
|
|
794
|
+
initialState: cfg.stateConfig.initial,
|
|
795
|
+
apply: (state, event, sessionState) => stateReduce(state, event, sessionState, pluginConfig),
|
|
796
|
+
})
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
const agentHookEntries = Object.entries(cfg.agentHooks) as [string, (ctx: BasePluginHookContext) => Promise<unknown>][]
|
|
800
|
+
const agentHooks: Partial<ErasedAgentHookMap> | undefined = agentHookEntries.length > 0
|
|
801
|
+
? Object.fromEntries(
|
|
802
|
+
agentHookEntries.map(([name, fn]) => [
|
|
803
|
+
name,
|
|
804
|
+
// Agent.ts provides the full context with extra fields (pendingMessages, turnNumber, etc.)
|
|
805
|
+
// — this wrapper just injects pluginConfig at the boundary
|
|
806
|
+
(ctx: BasePluginHookContext) => fn({ ...ctx, pluginConfig }),
|
|
807
|
+
]),
|
|
808
|
+
) as Partial<ErasedAgentHookMap>
|
|
809
|
+
: undefined
|
|
810
|
+
|
|
811
|
+
const sessionHookEntries = Object.entries(cfg.sessionHooks)
|
|
812
|
+
const sessionHooks: Partial<ErasedSessionHookMap> | undefined = sessionHookEntries.length > 0
|
|
813
|
+
? Object.fromEntries(
|
|
814
|
+
sessionHookEntries.map(([name, fn]) => [
|
|
815
|
+
name,
|
|
816
|
+
(ctx: BaseSessionHookContext) => fn({ ...ctx, pluginConfig }),
|
|
817
|
+
]),
|
|
818
|
+
) as Partial<ErasedSessionHookMap>
|
|
819
|
+
: undefined
|
|
820
|
+
|
|
821
|
+
// Combine static + dynamic tools
|
|
822
|
+
const staticToolSpecs = cfg.staticTools
|
|
823
|
+
const dynamicToolsFn = cfg.dynamicTools
|
|
824
|
+
let getTools: ((ctx: BasePluginHookContext) => ToolDefinition<any>[]) | undefined
|
|
825
|
+
if (staticToolSpecs.length > 0 || dynamicToolsFn) {
|
|
826
|
+
getTools = (ctx: BasePluginHookContext) => {
|
|
827
|
+
const enrichedCtx: BasePluginHookContext = { ...ctx, pluginConfig }
|
|
828
|
+
const tools: ToolDefinition<any>[] = []
|
|
829
|
+
// Static tools — create ToolDefinition from StaticToolSpec using closure
|
|
830
|
+
for (const spec of staticToolSpecs) {
|
|
831
|
+
tools.push(createTool({
|
|
832
|
+
name: spec.name,
|
|
833
|
+
description: spec.description,
|
|
834
|
+
input: spec.input,
|
|
835
|
+
execute: (input, toolCtx) => spec.execute(input, toolCtx, enrichedCtx),
|
|
836
|
+
}))
|
|
837
|
+
}
|
|
838
|
+
// Dynamic tools
|
|
839
|
+
if (dynamicToolsFn) {
|
|
840
|
+
tools.push(...dynamicToolsFn(enrichedCtx))
|
|
841
|
+
}
|
|
842
|
+
return tools
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
// Wrap createContext to pass pluginConfig
|
|
847
|
+
const contextFactory = cfg.contextFactory
|
|
848
|
+
const wrappedContextFactory = contextFactory
|
|
849
|
+
? (ctx: SessionContext) => contextFactory(ctx, pluginConfig)
|
|
850
|
+
: undefined
|
|
851
|
+
|
|
852
|
+
// Wrap status/systemPrompt/dequeue to inject pluginConfig
|
|
853
|
+
const statusFn = cfg.statusFn
|
|
854
|
+
const wrappedStatus = statusFn
|
|
855
|
+
? (ctx: BasePluginHookContext) => statusFn({ ...ctx, pluginConfig })
|
|
856
|
+
: undefined
|
|
857
|
+
|
|
858
|
+
const systemPromptFn = cfg.systemPromptFn
|
|
859
|
+
const wrappedSystemPrompt = systemPromptFn
|
|
860
|
+
? (ctx: BasePluginHookContext) => systemPromptFn({ ...ctx, pluginConfig })
|
|
861
|
+
: undefined
|
|
862
|
+
|
|
863
|
+
const dequeueHook = cfg.dequeueHook
|
|
864
|
+
const wrappedDequeue = dequeueHook
|
|
865
|
+
? {
|
|
866
|
+
hasPendingMessages: (ctx: BasePluginHookContext) => dequeueHook.hasPendingMessages({ ...ctx, pluginConfig }),
|
|
867
|
+
getPendingMessages: (ctx: BasePluginHookContext) => dequeueHook.getPendingMessages({ ...ctx, pluginConfig }),
|
|
868
|
+
markConsumed: (ctx: BasePluginHookContext, token: unknown) => dequeueHook.markConsumed({ ...ctx, pluginConfig }, token),
|
|
869
|
+
}
|
|
870
|
+
: undefined
|
|
871
|
+
|
|
872
|
+
// Wrap isEnabled to pass pluginConfig
|
|
873
|
+
const wrappedIsEnabled = cfg.isEnabledFn
|
|
874
|
+
? (ctx: { pluginConfig: unknown; pluginAgentConfig: unknown; agentConfig: AgentConfig }) => {
|
|
875
|
+
return cfg.isEnabledFn!({ ...ctx, pluginConfig })
|
|
876
|
+
}
|
|
877
|
+
: undefined
|
|
878
|
+
|
|
879
|
+
// Wrap isSessionEnabled to pass pluginConfig
|
|
880
|
+
const wrappedIsSessionEnabled = cfg.isSessionEnabledFn
|
|
881
|
+
? (ctx: { pluginConfig: unknown }) => {
|
|
882
|
+
return cfg.isSessionEnabledFn!({ ...ctx, pluginConfig })
|
|
883
|
+
}
|
|
884
|
+
: undefined
|
|
885
|
+
|
|
886
|
+
// Wrap method handlers to inject pluginConfig
|
|
887
|
+
const wrappedMethods: ConfiguredPlugin['methods'] = {}
|
|
888
|
+
for (const [name, method] of Object.entries(cfg.methods)) {
|
|
889
|
+
wrappedMethods[name] = {
|
|
890
|
+
input: method.input,
|
|
891
|
+
output: method.output,
|
|
892
|
+
handler: (ctx, input) => method.handler({ ...ctx, pluginConfig }, input),
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
return {
|
|
897
|
+
name: cfg.name,
|
|
898
|
+
methods: wrappedMethods,
|
|
899
|
+
notifications: cfg.notifications,
|
|
900
|
+
dependencyNames: cfg.dependencyNames,
|
|
901
|
+
createContext: wrappedContextFactory,
|
|
902
|
+
state: cfg.stateConfig
|
|
903
|
+
? {
|
|
904
|
+
key: cfg.stateConfig.key,
|
|
905
|
+
events: cfg.events,
|
|
906
|
+
initialState: cfg.stateConfig.initial,
|
|
907
|
+
reduce: (state, event, sessionState) => cfg.stateConfig!.reduce(state, event, sessionState, pluginConfig),
|
|
908
|
+
}
|
|
909
|
+
: undefined,
|
|
910
|
+
agentHooks,
|
|
911
|
+
sessionHooks,
|
|
912
|
+
getTools,
|
|
913
|
+
getStatus: wrappedStatus,
|
|
914
|
+
getSystemPrompt: wrappedSystemPrompt,
|
|
915
|
+
dequeue: wrappedDequeue,
|
|
916
|
+
slice,
|
|
917
|
+
isEnabled: wrappedIsEnabled,
|
|
918
|
+
isSessionEnabled: wrappedIsSessionEnabled,
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// ============================================================================
|
|
923
|
+
// Runtime dependency wiring
|
|
924
|
+
// ============================================================================
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Callback type for resolving a plugin method call at runtime.
|
|
928
|
+
* Used by session.ts and agent.ts to delegate to the session's callPluginMethod.
|
|
929
|
+
*/
|
|
930
|
+
export type PluginMethodCaller = (pluginName: string, methodName: string, input: unknown) => Promise<Result<unknown, DomainError>>
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Build a `deps` object for a plugin at runtime.
|
|
934
|
+
* Creates proxy-like method callers for each dependency plugin.
|
|
935
|
+
*
|
|
936
|
+
* @param dependencyNames - Plugin names this plugin depends on
|
|
937
|
+
* @param allPlugins - All configured plugins in the session (to discover method names)
|
|
938
|
+
* @param callMethod - Callback that routes to the session's callPluginMethod
|
|
939
|
+
*/
|
|
940
|
+
export function buildPluginDeps(
|
|
941
|
+
dependencyNames: string[],
|
|
942
|
+
allPlugins: ConfiguredPlugin[],
|
|
943
|
+
callMethod: PluginMethodCaller,
|
|
944
|
+
): Record<string, Record<string, (input: unknown) => Promise<Result<unknown, DomainError>>>> {
|
|
945
|
+
const deps: Record<string, Record<string, (input: unknown) => Promise<Result<unknown, DomainError>>>> = {}
|
|
946
|
+
|
|
947
|
+
for (const depName of dependencyNames) {
|
|
948
|
+
const depPlugin = allPlugins.find((p) => p.name === depName)
|
|
949
|
+
if (!depPlugin) continue
|
|
950
|
+
|
|
951
|
+
const methods: Record<string, (input: unknown) => Promise<Result<unknown, DomainError>>> = {}
|
|
952
|
+
for (const methodName of Object.keys(depPlugin.methods)) {
|
|
953
|
+
methods[methodName] = (input: unknown) => callMethod(depName, methodName, input)
|
|
954
|
+
}
|
|
955
|
+
deps[depName] = methods
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
return deps
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// ============================================================================
|
|
962
|
+
// Entry point
|
|
963
|
+
// ============================================================================
|
|
964
|
+
|
|
965
|
+
export function definePlugin<TName extends string>(name: TName): PluginBuilder<TName, void, void, undefined, {}, {}, void, [], {}, {}> {
|
|
966
|
+
return new PluginBuilder(name)
|
|
967
|
+
}
|