@roj-ai/sdk 0.1.35 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap.d.ts +420 -26
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +55 -24
- package/dist/bootstrap.js.map +1 -1
- package/dist/bun-platform/fs.d.ts.map +1 -1
- package/dist/bun-platform/fs.js +1 -0
- package/dist/bun-platform/fs.js.map +1 -1
- package/dist/bun-platform/index.d.ts +4 -1
- package/dist/bun-platform/index.d.ts.map +1 -1
- package/dist/bun-platform/index.js +7 -1
- package/dist/bun-platform/index.js.map +1 -1
- package/dist/bun-platform/server-lifecycle.d.ts +30 -0
- package/dist/bun-platform/server-lifecycle.d.ts.map +1 -0
- package/dist/bun-platform/server-lifecycle.js +182 -0
- package/dist/bun-platform/server-lifecycle.js.map +1 -0
- package/dist/bun-platform/shell.d.ts +33 -0
- package/dist/bun-platform/shell.d.ts.map +1 -0
- package/dist/bun-platform/shell.js +322 -0
- package/dist/bun-platform/shell.js.map +1 -0
- package/dist/config.d.ts +34 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +97 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agents/agent.d.ts +42 -7
- package/dist/core/agents/agent.d.ts.map +1 -1
- package/dist/core/agents/agent.js +209 -90
- package/dist/core/agents/agent.js.map +1 -1
- package/dist/core/agents/config.d.ts +8 -1
- package/dist/core/agents/config.d.ts.map +1 -1
- package/dist/core/agents/config.js +5 -1
- package/dist/core/agents/config.js.map +1 -1
- package/dist/core/agents/retry.d.ts +1 -1
- package/dist/core/agents/retry.d.ts.map +1 -1
- package/dist/core/agents/retry.js +14 -16
- package/dist/core/agents/retry.js.map +1 -1
- package/dist/core/agents/state.d.ts +27 -1
- package/dist/core/agents/state.d.ts.map +1 -1
- package/dist/core/agents/state.js +1 -1
- package/dist/core/agents/state.js.map +1 -1
- package/dist/core/context/state.d.ts +3 -3
- package/dist/core/context/state.d.ts.map +1 -1
- package/dist/core/context/state.js +6 -2
- package/dist/core/context/state.js.map +1 -1
- package/dist/core/events/base-event-store.d.ts.map +1 -1
- package/dist/core/events/base-event-store.js +22 -14
- package/dist/core/events/base-event-store.js.map +1 -1
- package/dist/core/events/file.d.ts +39 -1
- package/dist/core/events/file.d.ts.map +1 -1
- package/dist/core/events/file.js +159 -20
- package/dist/core/events/file.js.map +1 -1
- package/dist/core/events/types.d.ts +1 -1
- package/dist/core/file-store/containment.d.ts +19 -0
- package/dist/core/file-store/containment.d.ts.map +1 -0
- package/dist/core/file-store/containment.js +62 -0
- package/dist/core/file-store/containment.js.map +1 -0
- package/dist/core/file-store/file-store.d.ts +22 -2
- package/dist/core/file-store/file-store.d.ts.map +1 -1
- package/dist/core/file-store/file-store.js +88 -20
- package/dist/core/file-store/file-store.js.map +1 -1
- package/dist/core/file-store/types.d.ts +13 -1
- package/dist/core/file-store/types.d.ts.map +1 -1
- package/dist/core/image/image-processor.d.ts.map +1 -1
- package/dist/core/image/image-processor.js +3 -1
- package/dist/core/image/image-processor.js.map +1 -1
- package/dist/core/image/types.d.ts +2 -0
- package/dist/core/image/types.d.ts.map +1 -1
- package/dist/core/image/vips-resizer.d.ts.map +1 -1
- package/dist/core/image/vips-resizer.js +81 -33
- package/dist/core/image/vips-resizer.js.map +1 -1
- package/dist/core/llm/anthropic.d.ts +0 -1
- package/dist/core/llm/anthropic.d.ts.map +1 -1
- package/dist/core/llm/anthropic.js +101 -74
- package/dist/core/llm/anthropic.js.map +1 -1
- package/dist/core/llm/logger.d.ts +14 -2
- package/dist/core/llm/logger.d.ts.map +1 -1
- package/dist/core/llm/logger.js +161 -36
- package/dist/core/llm/logger.js.map +1 -1
- package/dist/core/llm/openrouter.d.ts +0 -1
- package/dist/core/llm/openrouter.d.ts.map +1 -1
- package/dist/core/llm/openrouter.js +70 -74
- package/dist/core/llm/openrouter.js.map +1 -1
- package/dist/core/llm/provider-request.d.ts +10 -0
- package/dist/core/llm/provider-request.d.ts.map +1 -0
- package/dist/core/llm/provider-request.js +41 -0
- package/dist/core/llm/provider-request.js.map +1 -0
- package/dist/core/llm/provider.d.ts +45 -3
- package/dist/core/llm/provider.d.ts.map +1 -1
- package/dist/core/llm/provider.js +26 -0
- package/dist/core/llm/provider.js.map +1 -1
- package/dist/core/llm/state.d.ts +4 -2
- package/dist/core/llm/state.d.ts.map +1 -1
- package/dist/core/llm/state.js +15 -4
- package/dist/core/llm/state.js.map +1 -1
- package/dist/core/plugins/plugin-builder.d.ts +57 -3
- package/dist/core/plugins/plugin-builder.d.ts.map +1 -1
- package/dist/core/plugins/plugin-builder.js +68 -14
- package/dist/core/plugins/plugin-builder.js.map +1 -1
- package/dist/core/preset/preset-builder.d.ts +3 -2
- package/dist/core/preset/preset-builder.d.ts.map +1 -1
- package/dist/core/preset/preset-builder.js +7 -16
- package/dist/core/preset/preset-builder.js.map +1 -1
- package/dist/core/sessions/context.d.ts +23 -5
- package/dist/core/sessions/context.d.ts.map +1 -1
- package/dist/core/sessions/runtime-activity.d.ts +33 -0
- package/dist/core/sessions/runtime-activity.d.ts.map +1 -0
- package/dist/core/sessions/runtime-activity.js +55 -0
- package/dist/core/sessions/runtime-activity.js.map +1 -0
- package/dist/core/sessions/schema.d.ts +23 -2
- package/dist/core/sessions/schema.d.ts.map +1 -1
- package/dist/core/sessions/schema.js +24 -3
- package/dist/core/sessions/schema.js.map +1 -1
- package/dist/core/sessions/session-manager.d.ts +83 -6
- package/dist/core/sessions/session-manager.d.ts.map +1 -1
- package/dist/core/sessions/session-manager.js +517 -118
- package/dist/core/sessions/session-manager.js.map +1 -1
- package/dist/core/sessions/session-store.d.ts +18 -0
- package/dist/core/sessions/session-store.d.ts.map +1 -1
- package/dist/core/sessions/session-store.js +33 -0
- package/dist/core/sessions/session-store.js.map +1 -1
- package/dist/core/sessions/session.d.ts +42 -6
- package/dist/core/sessions/session.d.ts.map +1 -1
- package/dist/core/sessions/session.js +176 -44
- package/dist/core/sessions/session.js.map +1 -1
- package/dist/core/sessions/state.d.ts +10 -1
- package/dist/core/sessions/state.d.ts.map +1 -1
- package/dist/core/sessions/state.js +16 -1
- package/dist/core/sessions/state.js.map +1 -1
- package/dist/core/system.d.ts +9 -0
- package/dist/core/system.d.ts.map +1 -1
- package/dist/core/system.js +4 -1
- package/dist/core/system.js.map +1 -1
- package/dist/core/tools/executor.d.ts +1 -1
- package/dist/core/wake-key.d.ts +34 -0
- package/dist/core/wake-key.d.ts.map +1 -0
- package/dist/core/wake-key.js +51 -0
- package/dist/core/wake-key.js.map +1 -0
- package/dist/index.d.ts +24 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/dist/lib/archive/archive-inspection.d.ts +48 -0
- package/dist/lib/archive/archive-inspection.d.ts.map +1 -0
- package/dist/lib/archive/archive-inspection.fixtures.d.ts +7 -0
- package/dist/lib/archive/archive-inspection.fixtures.d.ts.map +1 -0
- package/dist/lib/archive/archive-inspection.fixtures.js +134 -0
- package/dist/lib/archive/archive-inspection.fixtures.js.map +1 -0
- package/dist/lib/archive/archive-inspection.js +253 -0
- package/dist/lib/archive/archive-inspection.js.map +1 -0
- package/dist/lib/archive/index.d.ts +3 -0
- package/dist/lib/archive/index.d.ts.map +1 -0
- package/dist/lib/archive/index.js +2 -0
- package/dist/lib/archive/index.js.map +1 -0
- package/dist/lib/logger/console.d.ts +5 -12
- package/dist/lib/logger/console.d.ts.map +1 -1
- package/dist/lib/logger/console.js +5 -47
- package/dist/lib/logger/console.js.map +1 -1
- package/dist/lib/logger/file.d.ts +8 -11
- package/dist/lib/logger/file.d.ts.map +1 -1
- package/dist/lib/logger/file.js +26 -37
- package/dist/lib/logger/file.js.map +1 -1
- package/dist/lib/logger/index.d.ts +3 -1
- package/dist/lib/logger/index.d.ts.map +1 -1
- package/dist/lib/logger/index.js +3 -1
- package/dist/lib/logger/index.js.map +1 -1
- package/dist/lib/logger/jsonl.d.ts +21 -0
- package/dist/lib/logger/jsonl.d.ts.map +1 -0
- package/dist/lib/logger/jsonl.js +29 -0
- package/dist/lib/logger/jsonl.js.map +1 -0
- package/dist/lib/logger/logger.d.ts +22 -0
- package/dist/lib/logger/logger.d.ts.map +1 -1
- package/dist/lib/logger/logger.js +37 -0
- package/dist/lib/logger/logger.js.map +1 -1
- package/dist/lib/logger/session-log.d.ts +21 -0
- package/dist/lib/logger/session-log.d.ts.map +1 -0
- package/dist/lib/logger/session-log.js +37 -0
- package/dist/lib/logger/session-log.js.map +1 -0
- package/dist/lib/utils/concurrency.d.ts +1 -1
- package/dist/lib/utils/concurrency.d.ts.map +1 -1
- package/dist/lib/utils/concurrency.js +30 -7
- package/dist/lib/utils/concurrency.js.map +1 -1
- package/dist/lib/utils/fs-batch.d.ts +17 -0
- package/dist/lib/utils/fs-batch.d.ts.map +1 -0
- package/dist/lib/utils/fs-batch.js +38 -0
- package/dist/lib/utils/fs-batch.js.map +1 -0
- package/dist/lib/utils/result.d.ts +7 -22
- package/dist/lib/utils/result.d.ts.map +1 -1
- package/dist/lib/utils/result.js +6 -17
- package/dist/lib/utils/result.js.map +1 -1
- package/dist/lib/utils/sleep.d.ts +10 -0
- package/dist/lib/utils/sleep.d.ts.map +1 -0
- package/dist/lib/utils/sleep.js +26 -0
- package/dist/lib/utils/sleep.js.map +1 -0
- package/dist/platform/fs-revision.d.ts +21 -0
- package/dist/platform/fs-revision.d.ts.map +1 -0
- package/dist/platform/fs-revision.js +9 -0
- package/dist/platform/fs-revision.js.map +1 -0
- package/dist/platform/fs.d.ts +104 -1
- package/dist/platform/fs.d.ts.map +1 -1
- package/dist/platform/git.d.ts +59 -0
- package/dist/platform/git.d.ts.map +1 -0
- package/dist/platform/git.js +8 -0
- package/dist/platform/git.js.map +1 -0
- package/dist/platform/index.d.ts +40 -1
- package/dist/platform/index.d.ts.map +1 -1
- package/dist/platform/index.js +1 -1
- package/dist/platform/index.js.map +1 -1
- package/dist/platform/llm-call-log.d.ts +80 -0
- package/dist/platform/llm-call-log.d.ts.map +1 -0
- package/dist/platform/llm-call-log.js +12 -0
- package/dist/platform/llm-call-log.js.map +1 -0
- package/dist/platform/scheduler.d.ts +32 -0
- package/dist/platform/scheduler.d.ts.map +1 -0
- package/dist/platform/scheduler.js +46 -0
- package/dist/platform/scheduler.js.map +1 -0
- package/dist/platform/session-log.d.ts +36 -0
- package/dist/platform/session-log.d.ts.map +1 -0
- package/dist/platform/session-log.js +12 -0
- package/dist/platform/session-log.js.map +1 -0
- package/dist/platform/shell.d.ts +83 -0
- package/dist/platform/shell.d.ts.map +1 -0
- package/dist/platform/shell.js +13 -0
- package/dist/platform/shell.js.map +1 -0
- package/dist/plugins/agent-status/plugin.d.ts.map +1 -1
- package/dist/plugins/agent-status/plugin.js +1 -0
- package/dist/plugins/agent-status/plugin.js.map +1 -1
- package/dist/plugins/agents/plugin.d.ts.map +1 -1
- package/dist/plugins/agents/plugin.js +129 -62
- package/dist/plugins/agents/plugin.js.map +1 -1
- package/dist/plugins/filesystem/listing.d.ts +3 -0
- package/dist/plugins/filesystem/listing.d.ts.map +1 -1
- package/dist/plugins/filesystem/listing.js +66 -10
- package/dist/plugins/filesystem/listing.js.map +1 -1
- package/dist/plugins/filesystem/plugin.d.ts.map +1 -1
- package/dist/plugins/filesystem/plugin.js +8 -6
- package/dist/plugins/filesystem/plugin.js.map +1 -1
- package/dist/plugins/git-status/plugin.d.ts +34 -7
- package/dist/plugins/git-status/plugin.d.ts.map +1 -1
- package/dist/plugins/git-status/plugin.js +168 -64
- package/dist/plugins/git-status/plugin.js.map +1 -1
- package/dist/plugins/llm-debug/plugin.d.ts.map +1 -1
- package/dist/plugins/llm-debug/plugin.js +1 -0
- package/dist/plugins/llm-debug/plugin.js.map +1 -1
- package/dist/plugins/logs/plugin.d.ts +1 -4
- package/dist/plugins/logs/plugin.d.ts.map +1 -1
- package/dist/plugins/logs/plugin.js +7 -0
- package/dist/plugins/logs/plugin.js.map +1 -1
- package/dist/plugins/mailbox/helpers.d.ts +2 -2
- package/dist/plugins/mailbox/helpers.js +1 -1
- package/dist/plugins/mailbox/plugin.d.ts.map +1 -1
- package/dist/plugins/mailbox/plugin.js +38 -43
- package/dist/plugins/mailbox/plugin.js.map +1 -1
- package/dist/plugins/mailbox/query.d.ts +7 -2
- package/dist/plugins/mailbox/query.d.ts.map +1 -1
- package/dist/plugins/mailbox/query.js +14 -7
- package/dist/plugins/mailbox/query.js.map +1 -1
- package/dist/plugins/mailbox/state.d.ts +5 -4
- package/dist/plugins/mailbox/state.d.ts.map +1 -1
- package/dist/plugins/mailbox/state.js +6 -5
- package/dist/plugins/mailbox/state.js.map +1 -1
- package/dist/plugins/resources/filename.d.ts +4 -0
- package/dist/plugins/resources/filename.d.ts.map +1 -0
- package/dist/plugins/resources/filename.js +18 -0
- package/dist/plugins/resources/filename.js.map +1 -0
- package/dist/plugins/resources/plugin.d.ts +3 -0
- package/dist/plugins/resources/plugin.d.ts.map +1 -1
- package/dist/plugins/resources/plugin.js +97 -60
- package/dist/plugins/resources/plugin.js.map +1 -1
- package/dist/plugins/resources/state.d.ts +1 -1
- package/dist/plugins/resources/state.js +1 -1
- package/dist/plugins/result-eviction/plugin.d.ts.map +1 -1
- package/dist/plugins/result-eviction/plugin.js +6 -1
- package/dist/plugins/result-eviction/plugin.js.map +1 -1
- package/dist/plugins/services/plugin.d.ts +4 -1
- package/dist/plugins/services/plugin.d.ts.map +1 -1
- package/dist/plugins/services/plugin.js +251 -100
- package/dist/plugins/services/plugin.js.map +1 -1
- package/dist/plugins/services/prompt.d.ts.map +1 -1
- package/dist/plugins/services/prompt.js +1 -4
- package/dist/plugins/services/prompt.js.map +1 -1
- package/dist/plugins/services/schema.d.ts +15 -5
- package/dist/plugins/services/schema.d.ts.map +1 -1
- package/dist/plugins/services/service.d.ts +100 -18
- package/dist/plugins/services/service.d.ts.map +1 -1
- package/dist/plugins/services/service.js +680 -230
- package/dist/plugins/services/service.js.map +1 -1
- package/dist/plugins/session-lifecycle/plugin.d.ts +21 -1
- package/dist/plugins/session-lifecycle/plugin.d.ts.map +1 -1
- package/dist/plugins/session-lifecycle/plugin.js +53 -40
- package/dist/plugins/session-lifecycle/plugin.js.map +1 -1
- package/dist/plugins/session-state/plugin.d.ts +21 -13
- package/dist/plugins/session-state/plugin.d.ts.map +1 -1
- package/dist/plugins/session-state/plugin.js +214 -79
- package/dist/plugins/session-state/plugin.js.map +1 -1
- package/dist/plugins/session-stats/plugin.d.ts.map +1 -1
- package/dist/plugins/session-stats/plugin.js +1 -0
- package/dist/plugins/session-stats/plugin.js.map +1 -1
- package/dist/plugins/shell/executor.d.ts +17 -15
- package/dist/plugins/shell/executor.d.ts.map +1 -1
- package/dist/plugins/shell/executor.js +130 -195
- package/dist/plugins/shell/executor.js.map +1 -1
- package/dist/plugins/shell/index.d.ts +2 -2
- package/dist/plugins/shell/index.d.ts.map +1 -1
- package/dist/plugins/shell/index.js +2 -2
- package/dist/plugins/shell/index.js.map +1 -1
- package/dist/plugins/shell/plugin.d.ts +5 -4
- package/dist/plugins/shell/plugin.d.ts.map +1 -1
- package/dist/plugins/shell/plugin.js +4 -8
- package/dist/plugins/shell/plugin.js.map +1 -1
- package/dist/plugins/skills/discovery.d.ts.map +1 -1
- package/dist/plugins/skills/discovery.js +10 -8
- package/dist/plugins/skills/discovery.js.map +1 -1
- package/dist/plugins/skills/index.d.ts +1 -1
- package/dist/plugins/skills/index.d.ts.map +1 -1
- package/dist/plugins/skills/plugin.d.ts +1 -1
- package/dist/plugins/skills/plugin.d.ts.map +1 -1
- package/dist/plugins/skills/plugin.js +23 -30
- package/dist/plugins/skills/plugin.js.map +1 -1
- package/dist/plugins/skills/prompts.d.ts +3 -3
- package/dist/plugins/skills/prompts.d.ts.map +1 -1
- package/dist/plugins/skills/prompts.js.map +1 -1
- package/dist/plugins/skills/schema.d.ts +4 -2
- package/dist/plugins/skills/schema.d.ts.map +1 -1
- package/dist/plugins/todo/schema.d.ts +1 -1
- package/dist/plugins/uploads/plugin.d.ts +11 -4
- package/dist/plugins/uploads/plugin.d.ts.map +1 -1
- package/dist/plugins/uploads/plugin.js +891 -225
- package/dist/plugins/uploads/plugin.js.map +1 -1
- package/dist/plugins/uploads/preprocessor.d.ts +14 -0
- package/dist/plugins/uploads/preprocessor.d.ts.map +1 -1
- package/dist/plugins/uploads/preprocessor.js +11 -0
- package/dist/plugins/uploads/preprocessor.js.map +1 -1
- package/dist/plugins/uploads/preprocessors/image-classifier.d.ts +1 -1
- package/dist/plugins/uploads/preprocessors/image-classifier.d.ts.map +1 -1
- package/dist/plugins/uploads/preprocessors/image-classifier.js +51 -26
- package/dist/plugins/uploads/preprocessors/image-classifier.js.map +1 -1
- package/dist/plugins/uploads/preprocessors/markitdown-preprocessor.d.ts +2 -2
- package/dist/plugins/uploads/preprocessors/markitdown-preprocessor.d.ts.map +1 -1
- package/dist/plugins/uploads/preprocessors/markitdown-preprocessor.js +41 -16
- package/dist/plugins/uploads/preprocessors/markitdown-preprocessor.js.map +1 -1
- package/dist/plugins/uploads/preprocessors/pdf-preprocessor.d.ts +1 -1
- package/dist/plugins/uploads/preprocessors/pdf-preprocessor.d.ts.map +1 -1
- package/dist/plugins/uploads/preprocessors/pdf-preprocessor.js +29 -14
- package/dist/plugins/uploads/preprocessors/pdf-preprocessor.js.map +1 -1
- package/dist/plugins/uploads/preprocessors/zip-preprocessor.d.ts +1 -1
- package/dist/plugins/uploads/preprocessors/zip-preprocessor.d.ts.map +1 -1
- package/dist/plugins/uploads/preprocessors/zip-preprocessor.js +62 -34
- package/dist/plugins/uploads/preprocessors/zip-preprocessor.js.map +1 -1
- package/dist/plugins/uploads/schema.d.ts +25 -2
- package/dist/plugins/uploads/schema.d.ts.map +1 -1
- package/dist/plugins/uploads/schema.js +24 -3
- package/dist/plugins/uploads/schema.js.map +1 -1
- package/dist/plugins/uploads/state.d.ts +13 -1
- package/dist/plugins/uploads/state.d.ts.map +1 -1
- package/dist/plugins/uploads/state.js +4 -1
- package/dist/plugins/uploads/state.js.map +1 -1
- package/dist/plugins/user-chat/plugin.d.ts +12 -5
- package/dist/plugins/user-chat/plugin.d.ts.map +1 -1
- package/dist/plugins/user-chat/plugin.js +141 -32
- package/dist/plugins/user-chat/plugin.js.map +1 -1
- package/dist/plugins/workers/context.d.ts +35 -13
- package/dist/plugins/workers/context.d.ts.map +1 -1
- package/dist/plugins/workers/context.js +82 -32
- package/dist/plugins/workers/context.js.map +1 -1
- package/dist/plugins/workers/definition.d.ts +7 -0
- package/dist/plugins/workers/definition.d.ts.map +1 -1
- package/dist/plugins/workers/definition.js.map +1 -1
- package/dist/plugins/workers/index.d.ts +4 -4
- package/dist/plugins/workers/index.d.ts.map +1 -1
- package/dist/plugins/workers/index.js +2 -2
- package/dist/plugins/workers/index.js.map +1 -1
- package/dist/plugins/workers/plugin.d.ts +10 -57
- package/dist/plugins/workers/plugin.d.ts.map +1 -1
- package/dist/plugins/workers/plugin.js +385 -123
- package/dist/plugins/workers/plugin.js.map +1 -1
- package/dist/plugins/workers/state.d.ts +69 -0
- package/dist/plugins/workers/state.d.ts.map +1 -0
- package/dist/plugins/workers/state.js +52 -0
- package/dist/plugins/workers/state.js.map +1 -0
- package/dist/plugins/workers/worker.d.ts +15 -4
- package/dist/plugins/workers/worker.d.ts.map +1 -1
- package/dist/testing/conformance.d.ts +106 -0
- package/dist/testing/conformance.d.ts.map +1 -0
- package/dist/testing/conformance.js +1463 -0
- package/dist/testing/conformance.js.map +1 -0
- package/dist/testing/node-platform.d.ts.map +1 -1
- package/dist/testing/node-platform.js +5 -0
- package/dist/testing/node-platform.js.map +1 -1
- package/dist/testing/test-harness.d.ts +11 -1
- package/dist/testing/test-harness.d.ts.map +1 -1
- package/dist/testing/test-harness.js +17 -37
- package/dist/testing/test-harness.js.map +1 -1
- package/dist/testing/wait-helpers.d.ts.map +1 -1
- package/dist/testing/wait-helpers.js +1 -3
- package/dist/testing/wait-helpers.js.map +1 -1
- package/dist/transport/adapter/client-adapter.d.ts +6 -0
- package/dist/transport/adapter/client-adapter.d.ts.map +1 -1
- package/dist/transport/adapter/client-adapter.js +50 -3
- package/dist/transport/adapter/client-adapter.js.map +1 -1
- package/dist/transport/adapter/heartbeat.d.ts +16 -0
- package/dist/transport/adapter/heartbeat.d.ts.map +1 -0
- package/dist/transport/adapter/heartbeat.js +41 -0
- package/dist/transport/adapter/heartbeat.js.map +1 -0
- package/dist/transport/adapter/server-adapter.d.ts.map +1 -1
- package/dist/transport/adapter/server-adapter.js +6 -0
- package/dist/transport/adapter/server-adapter.js.map +1 -1
- package/dist/transport/http/app.d.ts +3 -30
- package/dist/transport/http/app.d.ts.map +1 -1
- package/dist/transport/http/app.js +3 -7
- package/dist/transport/http/app.js.map +1 -1
- package/dist/transport/http/context.d.ts +40 -0
- package/dist/transport/http/context.d.ts.map +1 -0
- package/dist/transport/http/context.js +17 -0
- package/dist/transport/http/context.js.map +1 -0
- package/dist/transport/http/fetch-guard.d.ts +49 -0
- package/dist/transport/http/fetch-guard.d.ts.map +1 -0
- package/dist/transport/http/fetch-guard.js +312 -0
- package/dist/transport/http/fetch-guard.js.map +1 -0
- package/dist/transport/http/index.d.ts +1 -1
- package/dist/transport/http/index.d.ts.map +1 -1
- package/dist/transport/http/middleware/bearer-auth.d.ts +1 -1
- package/dist/transport/http/middleware/bearer-auth.d.ts.map +1 -1
- package/dist/transport/http/middleware/error-handler.d.ts +2 -2
- package/dist/transport/http/middleware/error-handler.d.ts.map +1 -1
- package/dist/transport/http/path-containment.d.ts +20 -0
- package/dist/transport/http/path-containment.d.ts.map +1 -0
- package/dist/transport/http/path-containment.js +31 -0
- package/dist/transport/http/path-containment.js.map +1 -0
- package/dist/transport/http/responses.d.ts +30 -0
- package/dist/transport/http/responses.d.ts.map +1 -0
- package/dist/transport/http/responses.js +5 -0
- package/dist/transport/http/responses.js.map +1 -0
- package/dist/transport/http/routes/files.d.ts +1 -1
- package/dist/transport/http/routes/files.d.ts.map +1 -1
- package/dist/transport/http/routes/files.js +54 -155
- package/dist/transport/http/routes/files.js.map +1 -1
- package/dist/transport/http/routes/resources.d.ts +1 -1
- package/dist/transport/http/routes/resources.d.ts.map +1 -1
- package/dist/transport/http/routes/resources.js +92 -57
- package/dist/transport/http/routes/resources.js.map +1 -1
- package/dist/transport/http/routes/rpc.d.ts +6 -1
- package/dist/transport/http/routes/rpc.d.ts.map +1 -1
- package/dist/transport/http/routes/rpc.js +51 -21
- package/dist/transport/http/routes/rpc.js.map +1 -1
- package/dist/transport/http/routes/upload.d.ts +1 -1
- package/dist/transport/http/routes/upload.d.ts.map +1 -1
- package/dist/transport/http/routes/upload.js +256 -169
- package/dist/transport/http/routes/upload.js.map +1 -1
- package/dist/user-config.d.ts +34 -7
- package/dist/user-config.d.ts.map +1 -1
- package/dist/user-config.js +71 -0
- package/dist/user-config.js.map +1 -1
- package/package.json +18 -8
- package/src/bootstrap.ts +119 -35
- package/src/bun-platform/fs.ts +1 -0
- package/src/bun-platform/index.ts +18 -1
- package/src/bun-platform/server-lifecycle.ts +218 -0
- package/src/bun-platform/shell.ts +362 -0
- package/src/config.ts +130 -0
- package/src/core/agents/agent.ts +219 -95
- package/src/core/agents/config.ts +8 -0
- package/src/core/agents/retry.ts +16 -17
- package/src/core/agents/state.ts +28 -0
- package/src/core/context/state.ts +4 -0
- package/src/core/events/base-event-store.ts +24 -16
- package/src/core/events/file.ts +198 -22
- package/src/core/file-store/containment.ts +75 -0
- package/src/core/file-store/file-store.ts +106 -25
- package/src/core/file-store/types.ts +14 -1
- package/src/core/image/image-processor.ts +3 -1
- package/src/core/image/types.ts +2 -0
- package/src/core/image/vips-resizer.ts +102 -37
- package/src/core/llm/anthropic.ts +127 -82
- package/src/core/llm/logger.ts +175 -37
- package/src/core/llm/openrouter.ts +82 -81
- package/src/core/llm/provider-request.ts +40 -0
- package/src/core/llm/provider.ts +72 -3
- package/src/core/llm/state.ts +12 -0
- package/src/core/plugins/plugin-builder.ts +106 -14
- package/src/core/preset/preset-builder.ts +12 -22
- package/src/core/sessions/context.ts +18 -0
- package/src/core/sessions/runtime-activity.ts +78 -0
- package/src/core/sessions/schema.ts +29 -3
- package/src/core/sessions/session-manager.ts +560 -140
- package/src/core/sessions/session-store.ts +38 -0
- package/src/core/sessions/session.ts +187 -47
- package/src/core/sessions/state.ts +16 -0
- package/src/core/system.ts +15 -0
- package/src/core/wake-key.ts +65 -0
- package/src/index.ts +31 -12
- package/src/lib/archive/archive-inspection.fixtures.ts +138 -0
- package/src/lib/archive/archive-inspection.ts +359 -0
- package/src/lib/archive/index.ts +17 -0
- package/src/lib/logger/console.ts +7 -57
- package/src/lib/logger/file.ts +28 -50
- package/src/lib/logger/index.ts +3 -1
- package/src/lib/logger/jsonl.ts +36 -0
- package/src/lib/logger/logger.ts +48 -0
- package/src/lib/logger/session-log.ts +42 -0
- package/src/lib/utils/concurrency.ts +37 -8
- package/src/lib/utils/fs-batch.ts +49 -0
- package/src/lib/utils/result.ts +7 -31
- package/src/lib/utils/sleep.ts +23 -0
- package/src/platform/fs-revision.ts +21 -0
- package/src/platform/fs.ts +109 -1
- package/src/platform/git.ts +67 -0
- package/src/platform/index.ts +51 -1
- package/src/platform/llm-call-log.ts +86 -0
- package/src/platform/scheduler.ts +71 -0
- package/src/platform/session-log.ts +39 -0
- package/src/platform/shell.ts +89 -0
- package/src/plugins/agent-status/plugin.ts +1 -0
- package/src/plugins/agents/plugin.ts +134 -81
- package/src/plugins/filesystem/listing.ts +70 -12
- package/src/plugins/filesystem/plugin.ts +8 -6
- package/src/plugins/git-status/plugin.ts +204 -77
- package/src/plugins/llm-debug/plugin.ts +1 -0
- package/src/plugins/logs/plugin.ts +9 -0
- package/src/plugins/mailbox/plugin.ts +46 -64
- package/src/plugins/mailbox/query.ts +15 -7
- package/src/plugins/mailbox/state.ts +1 -0
- package/src/plugins/resources/filename.ts +19 -0
- package/src/plugins/resources/plugin.ts +111 -59
- package/src/plugins/result-eviction/plugin.ts +6 -1
- package/src/plugins/services/plugin.ts +254 -98
- package/src/plugins/services/prompt.ts +1 -6
- package/src/plugins/services/schema.ts +17 -3
- package/src/plugins/services/service.ts +702 -252
- package/src/plugins/session-lifecycle/plugin.ts +56 -41
- package/src/plugins/session-state/plugin.ts +242 -88
- package/src/plugins/session-stats/plugin.ts +1 -0
- package/src/plugins/shell/executor.ts +144 -226
- package/src/plugins/shell/index.ts +1 -4
- package/src/plugins/shell/plugin.ts +7 -9
- package/src/plugins/skills/discovery.ts +10 -8
- package/src/plugins/skills/index.ts +1 -1
- package/src/plugins/skills/plugin.ts +19 -27
- package/src/plugins/skills/prompts.ts +3 -3
- package/src/plugins/skills/schema.ts +5 -2
- package/src/plugins/uploads/plugin.ts +991 -273
- package/src/plugins/uploads/preprocessor.ts +25 -0
- package/src/plugins/uploads/preprocessors/image-classifier.ts +56 -25
- package/src/plugins/uploads/preprocessors/markitdown-preprocessor.ts +41 -15
- package/src/plugins/uploads/preprocessors/pdf-preprocessor.ts +32 -16
- package/src/plugins/uploads/preprocessors/zip-preprocessor.ts +67 -38
- package/src/plugins/uploads/schema.ts +30 -3
- package/src/plugins/uploads/state.ts +12 -0
- package/src/plugins/user-chat/plugin.ts +196 -40
- package/src/plugins/workers/context.ts +102 -39
- package/src/plugins/workers/definition.ts +7 -0
- package/src/plugins/workers/index.ts +4 -4
- package/src/plugins/workers/plugin.ts +461 -151
- package/src/plugins/workers/state.ts +64 -0
- package/src/plugins/workers/worker.ts +15 -4
- package/src/testing/conformance.ts +1751 -0
- package/src/testing/node-platform.ts +5 -0
- package/src/testing/test-harness.ts +21 -38
- package/src/testing/wait-helpers.ts +1 -4
- package/src/transport/adapter/client-adapter.ts +60 -3
- package/src/transport/adapter/heartbeat.ts +50 -0
- package/src/transport/adapter/server-adapter.ts +6 -0
- package/src/transport/http/app.ts +7 -35
- package/src/transport/http/context.ts +46 -0
- package/src/transport/http/fetch-guard.ts +318 -0
- package/src/transport/http/index.ts +1 -1
- package/src/transport/http/middleware/bearer-auth.ts +1 -1
- package/src/transport/http/middleware/error-handler.ts +1 -1
- package/src/transport/http/path-containment.ts +44 -0
- package/src/transport/http/responses.ts +20 -0
- package/src/transport/http/routes/files.ts +69 -159
- package/src/transport/http/routes/resources.ts +124 -93
- package/src/transport/http/routes/rpc.ts +63 -26
- package/src/transport/http/routes/upload.ts +327 -258
- package/src/user-config.ts +93 -7
- package/dist/config.test.d.ts +0 -2
- package/dist/config.test.d.ts.map +0 -1
- package/dist/config.test.js +0 -155
- package/dist/config.test.js.map +0 -1
- package/dist/core/agent-loop.integration.test.d.ts +0 -2
- package/dist/core/agent-loop.integration.test.d.ts.map +0 -1
- package/dist/core/agent-loop.integration.test.js +0 -414
- package/dist/core/agent-loop.integration.test.js.map +0 -1
- package/dist/core/agents/agent-config.test.d.ts +0 -2
- package/dist/core/agents/agent-config.test.d.ts.map +0 -1
- package/dist/core/agents/agent-config.test.js +0 -194
- package/dist/core/agents/agent-config.test.js.map +0 -1
- package/dist/core/agents/agent-shutdown.test.d.ts +0 -6
- package/dist/core/agents/agent-shutdown.test.d.ts.map +0 -1
- package/dist/core/agents/agent-shutdown.test.js +0 -180
- package/dist/core/agents/agent-shutdown.test.js.map +0 -1
- package/dist/core/agents/agent.test.d.ts +0 -2
- package/dist/core/agents/agent.test.d.ts.map +0 -1
- package/dist/core/agents/agent.test.js +0 -313
- package/dist/core/agents/agent.test.js.map +0 -1
- package/dist/core/agents/communicator.d.ts +0 -3
- package/dist/core/agents/communicator.d.ts.map +0 -1
- package/dist/core/agents/communicator.js +0 -13
- package/dist/core/agents/communicator.js.map +0 -1
- package/dist/core/agents/handler-events.test.d.ts +0 -5
- package/dist/core/agents/handler-events.test.d.ts.map +0 -1
- package/dist/core/agents/handler-events.test.js +0 -115
- package/dist/core/agents/handler-events.test.js.map +0 -1
- package/dist/core/agents/response-sanitizer.test.d.ts +0 -2
- package/dist/core/agents/response-sanitizer.test.d.ts.map +0 -1
- package/dist/core/agents/response-sanitizer.test.js +0 -101
- package/dist/core/agents/response-sanitizer.test.js.map +0 -1
- package/dist/core/error-recovery.integration.test.d.ts +0 -2
- package/dist/core/error-recovery.integration.test.d.ts.map +0 -1
- package/dist/core/error-recovery.integration.test.js +0 -288
- package/dist/core/error-recovery.integration.test.js.map +0 -1
- package/dist/core/event-sourcing.integration.test.d.ts +0 -2
- package/dist/core/event-sourcing.integration.test.d.ts.map +0 -1
- package/dist/core/event-sourcing.integration.test.js +0 -154
- package/dist/core/event-sourcing.integration.test.js.map +0 -1
- package/dist/core/events/file.test.d.ts +0 -2
- package/dist/core/events/file.test.d.ts.map +0 -1
- package/dist/core/events/file.test.js +0 -284
- package/dist/core/events/file.test.js.map +0 -1
- package/dist/core/events/memory.test.d.ts +0 -2
- package/dist/core/events/memory.test.d.ts.map +0 -1
- package/dist/core/events/memory.test.js +0 -502
- package/dist/core/events/memory.test.js.map +0 -1
- package/dist/core/image/image-processor.test.d.ts +0 -2
- package/dist/core/image/image-processor.test.d.ts.map +0 -1
- package/dist/core/image/image-processor.test.js +0 -171
- package/dist/core/image/image-processor.test.js.map +0 -1
- package/dist/core/image/vips-resizer.test.d.ts +0 -2
- package/dist/core/image/vips-resizer.test.d.ts.map +0 -1
- package/dist/core/image/vips-resizer.test.js +0 -336
- package/dist/core/image/vips-resizer.test.js.map +0 -1
- package/dist/core/llm/anthropic.test.d.ts +0 -2
- package/dist/core/llm/anthropic.test.d.ts.map +0 -1
- package/dist/core/llm/anthropic.test.js +0 -464
- package/dist/core/llm/anthropic.test.js.map +0 -1
- package/dist/core/llm/cache-breakpoints.test.d.ts +0 -2
- package/dist/core/llm/cache-breakpoints.test.d.ts.map +0 -1
- package/dist/core/llm/cache-breakpoints.test.js +0 -69
- package/dist/core/llm/cache-breakpoints.test.js.map +0 -1
- package/dist/core/llm/cache-live.test.d.ts +0 -16
- package/dist/core/llm/cache-live.test.d.ts.map +0 -1
- package/dist/core/llm/cache-live.test.js +0 -137
- package/dist/core/llm/cache-live.test.js.map +0 -1
- package/dist/core/llm/logger.test.d.ts +0 -7
- package/dist/core/llm/logger.test.d.ts.map +0 -1
- package/dist/core/llm/logger.test.js +0 -228
- package/dist/core/llm/logger.test.js.map +0 -1
- package/dist/core/llm/message-sanitization.test.d.ts +0 -2
- package/dist/core/llm/message-sanitization.test.d.ts.map +0 -1
- package/dist/core/llm/message-sanitization.test.js +0 -181
- package/dist/core/llm/message-sanitization.test.js.map +0 -1
- package/dist/core/llm/mock.test.d.ts +0 -2
- package/dist/core/llm/mock.test.d.ts.map +0 -1
- package/dist/core/llm/mock.test.js +0 -318
- package/dist/core/llm/mock.test.js.map +0 -1
- package/dist/core/llm/openrouter-mapping.test.d.ts +0 -2
- package/dist/core/llm/openrouter-mapping.test.d.ts.map +0 -1
- package/dist/core/llm/openrouter-mapping.test.js +0 -172
- package/dist/core/llm/openrouter-mapping.test.js.map +0 -1
- package/dist/core/llm/openrouter.test.d.ts +0 -2
- package/dist/core/llm/openrouter.test.d.ts.map +0 -1
- package/dist/core/llm/openrouter.test.js +0 -377
- package/dist/core/llm/openrouter.test.js.map +0 -1
- package/dist/core/llm/provider-integration.test.d.ts +0 -12
- package/dist/core/llm/provider-integration.test.d.ts.map +0 -1
- package/dist/core/llm/provider-integration.test.js +0 -350
- package/dist/core/llm/provider-integration.test.js.map +0 -1
- package/dist/core/llm/routing-provider.test.d.ts +0 -2
- package/dist/core/llm/routing-provider.test.d.ts.map +0 -1
- package/dist/core/llm/routing-provider.test.js +0 -94
- package/dist/core/llm/routing-provider.test.js.map +0 -1
- package/dist/core/llm/snapshot-middleware.test.d.ts +0 -2
- package/dist/core/llm/snapshot-middleware.test.d.ts.map +0 -1
- package/dist/core/llm/snapshot-middleware.test.js +0 -144
- package/dist/core/llm/snapshot-middleware.test.js.map +0 -1
- package/dist/core/multi-agent.integration.test.d.ts +0 -2
- package/dist/core/multi-agent.integration.test.d.ts.map +0 -1
- package/dist/core/multi-agent.integration.test.js +0 -298
- package/dist/core/multi-agent.integration.test.js.map +0 -1
- package/dist/core/plugin-hooks.integration.test.d.ts +0 -2
- package/dist/core/plugin-hooks.integration.test.d.ts.map +0 -1
- package/dist/core/plugin-hooks.integration.test.js +0 -458
- package/dist/core/plugin-hooks.integration.test.js.map +0 -1
- package/dist/core/session-lifecycle.integration.test.d.ts +0 -2
- package/dist/core/session-lifecycle.integration.test.d.ts.map +0 -1
- package/dist/core/session-lifecycle.integration.test.js +0 -159
- package/dist/core/session-lifecycle.integration.test.js.map +0 -1
- package/dist/core/sessions/fork-utils.test.d.ts +0 -2
- package/dist/core/sessions/fork-utils.test.d.ts.map +0 -1
- package/dist/core/sessions/fork-utils.test.js +0 -129
- package/dist/core/sessions/fork-utils.test.js.map +0 -1
- package/dist/core/sessions/session-overrides.integration.test.d.ts +0 -2
- package/dist/core/sessions/session-overrides.integration.test.d.ts.map +0 -1
- package/dist/core/sessions/session-overrides.integration.test.js +0 -154
- package/dist/core/sessions/session-overrides.integration.test.js.map +0 -1
- package/dist/core/sessions/session.test.d.ts +0 -2
- package/dist/core/sessions/session.test.d.ts.map +0 -1
- package/dist/core/sessions/session.test.js +0 -1100
- package/dist/core/sessions/session.test.js.map +0 -1
- package/dist/core/tools/executor.test.d.ts +0 -2
- package/dist/core/tools/executor.test.d.ts.map +0 -1
- package/dist/core/tools/executor.test.js +0 -144
- package/dist/core/tools/executor.test.js.map +0 -1
- package/dist/lib/logger/console.test.d.ts +0 -2
- package/dist/lib/logger/console.test.d.ts.map +0 -1
- package/dist/lib/logger/console.test.js +0 -258
- package/dist/lib/logger/console.test.js.map +0 -1
- package/dist/lib/never.d.ts +0 -2
- package/dist/lib/never.d.ts.map +0 -1
- package/dist/lib/never.js +0 -4
- package/dist/lib/never.js.map +0 -1
- package/dist/lib/utils/concurrency.test.d.ts +0 -2
- package/dist/lib/utils/concurrency.test.d.ts.map +0 -1
- package/dist/lib/utils/concurrency.test.js +0 -135
- package/dist/lib/utils/concurrency.test.js.map +0 -1
- package/dist/plugins/agent-status/agent-status.test.d.ts +0 -2
- package/dist/plugins/agent-status/agent-status.test.d.ts.map +0 -1
- package/dist/plugins/agent-status/agent-status.test.js +0 -136
- package/dist/plugins/agent-status/agent-status.test.js.map +0 -1
- package/dist/plugins/agents/agents.integration.test.d.ts +0 -2
- package/dist/plugins/agents/agents.integration.test.d.ts.map +0 -1
- package/dist/plugins/agents/agents.integration.test.js +0 -830
- package/dist/plugins/agents/agents.integration.test.js.map +0 -1
- package/dist/plugins/agents/supervision.integration.test.d.ts +0 -2
- package/dist/plugins/agents/supervision.integration.test.d.ts.map +0 -1
- package/dist/plugins/agents/supervision.integration.test.js +0 -215
- package/dist/plugins/agents/supervision.integration.test.js.map +0 -1
- package/dist/plugins/context-compact/compaction-live.test.d.ts +0 -17
- package/dist/plugins/context-compact/compaction-live.test.d.ts.map +0 -1
- package/dist/plugins/context-compact/compaction-live.test.js +0 -177
- package/dist/plugins/context-compact/compaction-live.test.js.map +0 -1
- package/dist/plugins/context-compact/context-compact.integration.test.d.ts +0 -2
- package/dist/plugins/context-compact/context-compact.integration.test.d.ts.map +0 -1
- package/dist/plugins/context-compact/context-compact.integration.test.js +0 -364
- package/dist/plugins/context-compact/context-compact.integration.test.js.map +0 -1
- package/dist/plugins/context-compact/context-compactor.test.d.ts +0 -2
- package/dist/plugins/context-compact/context-compactor.test.d.ts.map +0 -1
- package/dist/plugins/context-compact/context-compactor.test.js +0 -858
- package/dist/plugins/context-compact/context-compactor.test.js.map +0 -1
- package/dist/plugins/context-compact/history-offloader.test.d.ts +0 -2
- package/dist/plugins/context-compact/history-offloader.test.d.ts.map +0 -1
- package/dist/plugins/context-compact/history-offloader.test.js +0 -77
- package/dist/plugins/context-compact/history-offloader.test.js.map +0 -1
- package/dist/plugins/filesystem/filesystem.integration.test.d.ts +0 -2
- package/dist/plugins/filesystem/filesystem.integration.test.d.ts.map +0 -1
- package/dist/plugins/filesystem/filesystem.integration.test.js +0 -447
- package/dist/plugins/filesystem/filesystem.integration.test.js.map +0 -1
- package/dist/plugins/filesystem/schema.d.ts +0 -7
- package/dist/plugins/filesystem/schema.d.ts.map +0 -1
- package/dist/plugins/filesystem/schema.js +0 -2
- package/dist/plugins/filesystem/schema.js.map +0 -1
- package/dist/plugins/limits-guard/limit-guard.test.d.ts +0 -2
- package/dist/plugins/limits-guard/limit-guard.test.d.ts.map +0 -1
- package/dist/plugins/limits-guard/limit-guard.test.js +0 -194
- package/dist/plugins/limits-guard/limit-guard.test.js.map +0 -1
- package/dist/plugins/limits-guard/limits-guard.integration.test.d.ts +0 -2
- package/dist/plugins/limits-guard/limits-guard.integration.test.d.ts.map +0 -1
- package/dist/plugins/limits-guard/limits-guard.integration.test.js +0 -887
- package/dist/plugins/limits-guard/limits-guard.integration.test.js.map +0 -1
- package/dist/plugins/llm-debug/llm-debug.integration.test.d.ts +0 -2
- package/dist/plugins/llm-debug/llm-debug.integration.test.d.ts.map +0 -1
- package/dist/plugins/llm-debug/llm-debug.integration.test.js +0 -157
- package/dist/plugins/llm-debug/llm-debug.integration.test.js.map +0 -1
- package/dist/plugins/mailbox/mailbox.integration.test.d.ts +0 -2
- package/dist/plugins/mailbox/mailbox.integration.test.d.ts.map +0 -1
- package/dist/plugins/mailbox/mailbox.integration.test.js +0 -678
- package/dist/plugins/mailbox/mailbox.integration.test.js.map +0 -1
- package/dist/plugins/resources/resources.integration.test.d.ts +0 -2
- package/dist/plugins/resources/resources.integration.test.d.ts.map +0 -1
- package/dist/plugins/resources/resources.integration.test.js +0 -62
- package/dist/plugins/resources/resources.integration.test.js.map +0 -1
- package/dist/plugins/result-eviction/result-eviction.integration.test.d.ts +0 -2
- package/dist/plugins/result-eviction/result-eviction.integration.test.d.ts.map +0 -1
- package/dist/plugins/result-eviction/result-eviction.integration.test.js +0 -294
- package/dist/plugins/result-eviction/result-eviction.integration.test.js.map +0 -1
- package/dist/plugins/services/pid-registry.test.d.ts +0 -2
- package/dist/plugins/services/pid-registry.test.d.ts.map +0 -1
- package/dist/plugins/services/pid-registry.test.js +0 -161
- package/dist/plugins/services/pid-registry.test.js.map +0 -1
- package/dist/plugins/services/services.integration.test.d.ts +0 -2
- package/dist/plugins/services/services.integration.test.d.ts.map +0 -1
- package/dist/plugins/services/services.integration.test.js +0 -1057
- package/dist/plugins/services/services.integration.test.js.map +0 -1
- package/dist/plugins/session-lifecycle/session-lifecycle.integration.test.d.ts +0 -2
- package/dist/plugins/session-lifecycle/session-lifecycle.integration.test.d.ts.map +0 -1
- package/dist/plugins/session-lifecycle/session-lifecycle.integration.test.js +0 -498
- package/dist/plugins/session-lifecycle/session-lifecycle.integration.test.js.map +0 -1
- package/dist/plugins/session-stats/plugin.test.d.ts +0 -2
- package/dist/plugins/session-stats/plugin.test.d.ts.map +0 -1
- package/dist/plugins/session-stats/plugin.test.js +0 -145
- package/dist/plugins/session-stats/plugin.test.js.map +0 -1
- package/dist/plugins/shell/shell.integration.test.d.ts +0 -2
- package/dist/plugins/shell/shell.integration.test.d.ts.map +0 -1
- package/dist/plugins/shell/shell.integration.test.js +0 -234
- package/dist/plugins/shell/shell.integration.test.js.map +0 -1
- package/dist/plugins/shell/shell.test.d.ts +0 -2
- package/dist/plugins/shell/shell.test.d.ts.map +0 -1
- package/dist/plugins/shell/shell.test.js +0 -236
- package/dist/plugins/shell/shell.test.js.map +0 -1
- package/dist/plugins/skills/discovery.test.d.ts +0 -2
- package/dist/plugins/skills/discovery.test.d.ts.map +0 -1
- package/dist/plugins/skills/discovery.test.js +0 -312
- package/dist/plugins/skills/discovery.test.js.map +0 -1
- package/dist/plugins/skills/skills.integration.test.d.ts +0 -2
- package/dist/plugins/skills/skills.integration.test.d.ts.map +0 -1
- package/dist/plugins/skills/skills.integration.test.js +0 -475
- package/dist/plugins/skills/skills.integration.test.js.map +0 -1
- package/dist/plugins/todo/todo.integration.test.d.ts +0 -2
- package/dist/plugins/todo/todo.integration.test.d.ts.map +0 -1
- package/dist/plugins/todo/todo.integration.test.js +0 -605
- package/dist/plugins/todo/todo.integration.test.js.map +0 -1
- package/dist/plugins/uploads/preprocessors/image-classifier.test.d.ts +0 -2
- package/dist/plugins/uploads/preprocessors/image-classifier.test.d.ts.map +0 -1
- package/dist/plugins/uploads/preprocessors/image-classifier.test.js +0 -113
- package/dist/plugins/uploads/preprocessors/image-classifier.test.js.map +0 -1
- package/dist/plugins/uploads/uploads.integration.test.d.ts +0 -2
- package/dist/plugins/uploads/uploads.integration.test.d.ts.map +0 -1
- package/dist/plugins/uploads/uploads.integration.test.js +0 -639
- package/dist/plugins/uploads/uploads.integration.test.js.map +0 -1
- package/dist/plugins/user-chat/user-chat.integration.test.d.ts +0 -2
- package/dist/plugins/user-chat/user-chat.integration.test.d.ts.map +0 -1
- package/dist/plugins/user-chat/user-chat.integration.test.js +0 -754
- package/dist/plugins/user-chat/user-chat.integration.test.js.map +0 -1
- package/dist/plugins/workers/workers.integration.test.d.ts +0 -2
- package/dist/plugins/workers/workers.integration.test.d.ts.map +0 -1
- package/dist/plugins/workers/workers.integration.test.js +0 -629
- package/dist/plugins/workers/workers.integration.test.js.map +0 -1
- package/dist/prompts/macros.test.d.ts +0 -2
- package/dist/prompts/macros.test.d.ts.map +0 -1
- package/dist/prompts/macros.test.js +0 -80
- package/dist/prompts/macros.test.js.map +0 -1
- package/dist/testing/test-harness.test.d.ts +0 -2
- package/dist/testing/test-harness.test.d.ts.map +0 -1
- package/dist/testing/test-harness.test.js +0 -92
- package/dist/testing/test-harness.test.js.map +0 -1
- package/dist/transport/http/routes/rpc.integration.test.d.ts +0 -2
- package/dist/transport/http/routes/rpc.integration.test.d.ts.map +0 -1
- package/dist/transport/http/routes/rpc.integration.test.js +0 -189
- package/dist/transport/http/routes/rpc.integration.test.js.map +0 -1
- package/dist/transport/http/routes/rpc.test.d.ts +0 -2
- package/dist/transport/http/routes/rpc.test.d.ts.map +0 -1
- package/dist/transport/http/routes/rpc.test.js +0 -316
- package/dist/transport/http/routes/rpc.test.js.map +0 -1
- package/src/config.test.ts +0 -174
- package/src/core/agent-loop.integration.test.ts +0 -503
- package/src/core/agents/agent-config.test.ts +0 -240
- package/src/core/agents/agent-shutdown.test.ts +0 -236
- package/src/core/agents/agent.test.ts +0 -387
- package/src/core/agents/communicator.ts +0 -16
- package/src/core/agents/handler-events.test.ts +0 -167
- package/src/core/agents/response-sanitizer.test.ts +0 -137
- package/src/core/error-recovery.integration.test.ts +0 -343
- package/src/core/event-sourcing.integration.test.ts +0 -191
- package/src/core/events/file.test.ts +0 -436
- package/src/core/events/memory.test.ts +0 -741
- package/src/core/image/image-processor.test.ts +0 -218
- package/src/core/image/vips-resizer.test.ts +0 -388
- package/src/core/llm/anthropic.test.ts +0 -546
- package/src/core/llm/cache-breakpoints.test.ts +0 -85
- package/src/core/llm/cache-live.test.ts +0 -155
- package/src/core/llm/logger.test.ts +0 -270
- package/src/core/llm/message-sanitization.test.ts +0 -217
- package/src/core/llm/mock.test.ts +0 -402
- package/src/core/llm/openrouter-mapping.test.ts +0 -210
- package/src/core/llm/openrouter.test.ts +0 -499
- package/src/core/llm/provider-integration.test.ts +0 -408
- package/src/core/llm/routing-provider.test.ts +0 -113
- package/src/core/llm/snapshot-middleware.test.ts +0 -168
- package/src/core/multi-agent.integration.test.ts +0 -340
- package/src/core/plugin-hooks.integration.test.ts +0 -568
- package/src/core/session-lifecycle.integration.test.ts +0 -202
- package/src/core/sessions/fork-utils.test.ts +0 -158
- package/src/core/sessions/session-overrides.integration.test.ts +0 -210
- package/src/core/sessions/session.test.ts +0 -1736
- package/src/core/tools/executor.test.ts +0 -161
- package/src/lib/logger/console.test.ts +0 -348
- package/src/lib/never.ts +0 -3
- package/src/lib/utils/concurrency.test.ts +0 -169
- package/src/plugins/agent-status/agent-status.test.ts +0 -164
- package/src/plugins/agents/agents.integration.test.ts +0 -976
- package/src/plugins/agents/supervision.integration.test.ts +0 -249
- package/src/plugins/context-compact/compaction-live.test.ts +0 -221
- package/src/plugins/context-compact/context-compact.integration.test.ts +0 -418
- package/src/plugins/context-compact/context-compactor.test.ts +0 -1036
- package/src/plugins/context-compact/history-offloader.test.ts +0 -100
- package/src/plugins/filesystem/filesystem.integration.test.ts +0 -529
- package/src/plugins/filesystem/schema.ts +0 -6
- package/src/plugins/limits-guard/limit-guard.test.ts +0 -253
- package/src/plugins/limits-guard/limits-guard.integration.test.ts +0 -1012
- package/src/plugins/llm-debug/llm-debug.integration.test.ts +0 -192
- package/src/plugins/mailbox/mailbox.integration.test.ts +0 -794
- package/src/plugins/resources/resources.integration.test.ts +0 -68
- package/src/plugins/result-eviction/result-eviction.integration.test.ts +0 -332
- package/src/plugins/services/pid-registry.test.ts +0 -180
- package/src/plugins/services/services.integration.test.ts +0 -1223
- package/src/plugins/session-lifecycle/session-lifecycle.integration.test.ts +0 -639
- package/src/plugins/session-stats/plugin.test.ts +0 -160
- package/src/plugins/shell/shell.integration.test.ts +0 -273
- package/src/plugins/shell/shell.test.ts +0 -314
- package/src/plugins/skills/discovery.test.ts +0 -395
- package/src/plugins/skills/skills.integration.test.ts +0 -580
- package/src/plugins/todo/todo.integration.test.ts +0 -687
- package/src/plugins/uploads/preprocessors/image-classifier.test.ts +0 -142
- package/src/plugins/uploads/uploads.integration.test.ts +0 -831
- package/src/plugins/user-chat/user-chat.integration.test.ts +0 -893
- package/src/plugins/workers/workers.integration.test.ts +0 -778
- package/src/prompts/macros.test.ts +0 -107
- package/src/testing/test-harness.test.ts +0 -114
- package/src/transport/http/routes/rpc.integration.test.ts +0 -243
- package/src/transport/http/routes/rpc.test.ts +0 -372
|
@@ -1,83 +1,186 @@
|
|
|
1
1
|
import z from 'zod/v4';
|
|
2
2
|
import { agentIdSchema } from '../../core/agents/schema.js';
|
|
3
3
|
import { ValidationErrors } from '../../core/errors.js';
|
|
4
|
-
import { createEventsFactory } from '../../core/events/types.js';
|
|
5
4
|
import { definePlugin } from '../../core/plugins/plugin-builder.js';
|
|
6
5
|
import { createTool } from '../../core/tools/definition.js';
|
|
7
6
|
import { Err, Ok } from '../../lib/utils/result.js';
|
|
8
7
|
import { WorkerContextImpl } from './context.js';
|
|
8
|
+
import { workerEvents } from './state.js';
|
|
9
9
|
import { generateWorkerId, WorkerId, workerIdSchema } from './worker.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
config: z.unknown(),
|
|
17
|
-
}),
|
|
18
|
-
worker_sub_event: z.object({
|
|
19
|
-
workerId: workerIdSchema,
|
|
20
|
-
workerType: z.string(),
|
|
21
|
-
subEvent: z.record(z.string(), z.unknown()).and(z.object({
|
|
22
|
-
type: z.string(),
|
|
23
|
-
})),
|
|
24
|
-
}),
|
|
25
|
-
worker_status_changed: z.object({
|
|
26
|
-
workerId: workerIdSchema,
|
|
27
|
-
fromStatus: z.enum(['running', 'paused', 'completed', 'failed', 'cancelled']),
|
|
28
|
-
toStatus: z.enum(['running', 'paused', 'completed', 'failed', 'cancelled']),
|
|
29
|
-
reason: z.string().optional(),
|
|
30
|
-
}),
|
|
31
|
-
worker_completed: z.object({
|
|
32
|
-
workerId: workerIdSchema,
|
|
33
|
-
result: z.object({
|
|
34
|
-
status: z.string(),
|
|
35
|
-
resultsPath: z.string().optional(),
|
|
36
|
-
summary: z.string(),
|
|
37
|
-
data: z.unknown().optional(),
|
|
38
|
-
}),
|
|
39
|
-
}),
|
|
40
|
-
worker_failed: z.object({
|
|
41
|
-
workerId: workerIdSchema,
|
|
42
|
-
error: z.string(),
|
|
43
|
-
resumable: z.boolean(),
|
|
44
|
-
}),
|
|
45
|
-
},
|
|
46
|
-
});
|
|
10
|
+
/** Most workers a single session runtime runs at once. */
|
|
11
|
+
export const MAX_CONCURRENT_WORKERS = 10;
|
|
12
|
+
/** Default bound on waiting for a stopped worker's `execute()` to return. */
|
|
13
|
+
export const WORKER_STOP_TIMEOUT_MS = 5000;
|
|
14
|
+
/** Default bound on draining the context effects a stopped worker left in flight. */
|
|
15
|
+
export const WORKER_EFFECT_DRAIN_TIMEOUT_MS = 5000;
|
|
47
16
|
// ============================================================================
|
|
48
17
|
// Worker execution helper
|
|
49
18
|
// ============================================================================
|
|
50
|
-
async function executeWorker(workerId, definition, config, context,
|
|
19
|
+
async function executeWorker(workerId, definition, config, context, runningWorkers, logger, releaseLease, executionControl, effectDrainTimeoutMs) {
|
|
51
20
|
try {
|
|
52
21
|
const result = await definition.execute(config, context);
|
|
22
|
+
if (executionControl.suppressTerminalEvent)
|
|
23
|
+
return;
|
|
53
24
|
if (result.ok) {
|
|
54
|
-
await
|
|
25
|
+
const persisted = await context.persistTerminal(workerEvents.create('worker_completed', {
|
|
55
26
|
workerId,
|
|
56
27
|
result: result.value,
|
|
57
28
|
}));
|
|
58
|
-
|
|
29
|
+
if (persisted)
|
|
30
|
+
logger.info('Worker completed', { workerId, result: result.value.summary });
|
|
59
31
|
}
|
|
60
32
|
else {
|
|
61
|
-
await
|
|
33
|
+
const persisted = await context.persistTerminal(workerEvents.create('worker_failed', {
|
|
62
34
|
workerId,
|
|
63
35
|
error: result.error.message,
|
|
64
36
|
resumable: result.error.resumable,
|
|
65
37
|
}));
|
|
66
|
-
|
|
38
|
+
if (persisted)
|
|
39
|
+
logger.warn('Worker failed', { workerId, error: result.error.message, resumable: result.error.resumable });
|
|
67
40
|
}
|
|
68
41
|
}
|
|
69
42
|
catch (error) {
|
|
43
|
+
if (executionControl.suppressTerminalEvent)
|
|
44
|
+
return;
|
|
70
45
|
const message = error instanceof Error ? error.message : String(error);
|
|
71
|
-
await
|
|
46
|
+
const persisted = await context.persistTerminal(workerEvents.create('worker_failed', {
|
|
72
47
|
workerId,
|
|
73
48
|
error: message,
|
|
74
49
|
resumable: false,
|
|
75
50
|
}));
|
|
76
|
-
|
|
51
|
+
if (persisted)
|
|
52
|
+
logger.error('Worker threw exception', error instanceof Error ? error : undefined, { workerId });
|
|
77
53
|
}
|
|
78
54
|
finally {
|
|
79
|
-
|
|
55
|
+
// Bounded like the stop path: a stalled append must not hold the runtime lease forever.
|
|
56
|
+
const drained = await awaitWithin(context.waitForEffects(), effectDrainTimeoutMs);
|
|
57
|
+
if (!drained)
|
|
58
|
+
context.releaseEffectLeases();
|
|
59
|
+
// A stop may already have replaced this entry with a relaunch; only drop our own.
|
|
60
|
+
if (runningWorkers.get(workerId)?.context === context)
|
|
61
|
+
runningWorkers.delete(workerId);
|
|
62
|
+
releaseLease();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function resolveStopTimeouts(pluginConfig) {
|
|
66
|
+
return {
|
|
67
|
+
stopTimeoutMs: pluginConfig.stopTimeoutMs ?? WORKER_STOP_TIMEOUT_MS,
|
|
68
|
+
effectDrainTimeoutMs: pluginConfig.effectDrainTimeoutMs ?? WORKER_EFFECT_DRAIN_TIMEOUT_MS,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Await `work`, giving up after `timeoutMs`. Returns false when the wait timed out. */
|
|
72
|
+
async function awaitWithin(work, timeoutMs) {
|
|
73
|
+
let timeoutId;
|
|
74
|
+
const timeout = new Promise((resolve) => {
|
|
75
|
+
timeoutId = setTimeout(() => resolve(false), timeoutMs);
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
return await Promise.race([work.then(() => true, () => true), timeout]);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
if (timeoutId)
|
|
82
|
+
clearTimeout(timeoutId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Stop workers and give back their runtime leases, on a deadline.
|
|
87
|
+
*
|
|
88
|
+
* Shared by cancel, pause and session close so the three cannot drift: a worker
|
|
89
|
+
* that ignores cancellation must never pin the runtime, so both the execution
|
|
90
|
+
* wait and the effect drain are bounded and the leases are force-released once
|
|
91
|
+
* either bound expires.
|
|
92
|
+
*
|
|
93
|
+
* Giving up on the body does not stop it. A worker whose `execute()` outlived
|
|
94
|
+
* `stopTimeoutMs` keeps running with a live FileStore after its map entry is
|
|
95
|
+
* gone, so it is recorded in `abandonedWorkers` and `resume` refuses to launch a
|
|
96
|
+
* second body beside it until the first one finally returns.
|
|
97
|
+
*/
|
|
98
|
+
async function stopWorkers(workers, runningWorkers, abandonedWorkers, timeouts) {
|
|
99
|
+
if (workers.length === 0)
|
|
100
|
+
return;
|
|
101
|
+
for (const worker of workers) {
|
|
102
|
+
worker.executionControl.suppressTerminalEvent = true;
|
|
103
|
+
worker.context.invalidate();
|
|
104
|
+
}
|
|
105
|
+
const exited = await awaitWithin(Promise.allSettled(workers.map((worker) => worker.promise)), timeouts.stopTimeoutMs);
|
|
106
|
+
const drained = await awaitWithin(Promise.allSettled(workers.map((worker) => worker.context.waitForEffects())), timeouts.effectDrainTimeoutMs);
|
|
107
|
+
if (!exited || !drained) {
|
|
108
|
+
for (const worker of workers)
|
|
109
|
+
worker.releaseLease();
|
|
110
|
+
}
|
|
111
|
+
// The `worker:<id>` lease is not the only one a stalled write holds.
|
|
112
|
+
if (!drained) {
|
|
113
|
+
for (const worker of workers)
|
|
114
|
+
worker.context.releaseEffectLeases();
|
|
115
|
+
}
|
|
116
|
+
if (!exited) {
|
|
117
|
+
for (const worker of workers) {
|
|
118
|
+
abandonedWorkers.add(worker.workerId);
|
|
119
|
+
void worker.promise.then(() => abandonedWorkers.delete(worker.workerId));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const worker of workers) {
|
|
123
|
+
if (runningWorkers.get(worker.workerId) === worker)
|
|
124
|
+
runningWorkers.delete(worker.workerId);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Explain why a worker is not available for an operation that needs it running. */
|
|
128
|
+
function describeUnavailableWorker(workerId, entry) {
|
|
129
|
+
if (!entry)
|
|
130
|
+
return `Worker not found: ${workerId}`;
|
|
131
|
+
if (entry.status === 'paused')
|
|
132
|
+
return `Worker is paused: ${workerId} — resume it first`;
|
|
133
|
+
if (entry.status !== 'running')
|
|
134
|
+
return `Worker is ${entry.status}: ${workerId}`;
|
|
135
|
+
// Projection says running but no body is resident — the relaunch has not landed yet.
|
|
136
|
+
return `Worker is stopped and pending relaunch: ${workerId}`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Start a worker in the current runtime.
|
|
140
|
+
*
|
|
141
|
+
* The concurrency cap lives here so the unattended relaunch at boot cannot
|
|
142
|
+
* exceed what `spawn` allows.
|
|
143
|
+
*/
|
|
144
|
+
function launchWorker({ sessionId, agentId, workerId, definition, config, initialState, resumed, files, emitEvent, getSessionState, reserveMailboxMessageSequence, scheduleAgent, runtimeActivity, runningWorkers, effectDrainTimeoutMs, logger, }) {
|
|
145
|
+
if (runningWorkers.size >= MAX_CONCURRENT_WORKERS) {
|
|
146
|
+
return Err(`Max concurrent workers reached (${MAX_CONCURRENT_WORKERS})`);
|
|
80
147
|
}
|
|
148
|
+
const releaseLease = runtimeActivity.tryAcquire(`worker:${workerId}`);
|
|
149
|
+
if (!releaseLease)
|
|
150
|
+
return Err('Session runtime is no longer accepting workers');
|
|
151
|
+
const workerLogger = logger.child({ workerId, workerType: definition.type });
|
|
152
|
+
const workerContext = new WorkerContextImpl({
|
|
153
|
+
sessionId,
|
|
154
|
+
workerId,
|
|
155
|
+
agentId,
|
|
156
|
+
workerType: definition.type,
|
|
157
|
+
files,
|
|
158
|
+
emitEvent,
|
|
159
|
+
getSessionState,
|
|
160
|
+
reserveMailboxMessageSequence,
|
|
161
|
+
acquireEffectLease: () => runtimeActivity.tryAcquire(`worker:${workerId}:effect`),
|
|
162
|
+
reducer: definition.reduce,
|
|
163
|
+
initialState,
|
|
164
|
+
resumed,
|
|
165
|
+
logger: workerLogger,
|
|
166
|
+
schedule: () => scheduleAgent(agentId),
|
|
167
|
+
});
|
|
168
|
+
const executionControl = { suppressTerminalEvent: false };
|
|
169
|
+
const promise = executeWorker(workerId, definition, config, workerContext, runningWorkers, logger, releaseLease, executionControl, effectDrainTimeoutMs).catch((error) => {
|
|
170
|
+
logger.error('Unhandled error in worker execution', error instanceof Error ? error : undefined, {
|
|
171
|
+
workerId,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
runningWorkers.set(workerId, {
|
|
175
|
+
workerId,
|
|
176
|
+
workerType: definition.type,
|
|
177
|
+
definition,
|
|
178
|
+
context: workerContext,
|
|
179
|
+
promise,
|
|
180
|
+
releaseLease,
|
|
181
|
+
executionControl,
|
|
182
|
+
});
|
|
183
|
+
return Ok(undefined);
|
|
81
184
|
}
|
|
82
185
|
// ============================================================================
|
|
83
186
|
// Worker Plugin
|
|
@@ -110,7 +213,7 @@ export const workerPlugin = definePlugin('workers')
|
|
|
110
213
|
}
|
|
111
214
|
case 'worker_sub_event': {
|
|
112
215
|
const worker = workers.get(event.workerId);
|
|
113
|
-
if (!worker)
|
|
216
|
+
if (!worker || !Object.hasOwn(worker, 'state'))
|
|
114
217
|
return workers;
|
|
115
218
|
const definition = workerDefs.find((w) => w.type === event.workerType);
|
|
116
219
|
const newState = definition ? definition.reduce(worker.state, event.subEvent) : worker.state;
|
|
@@ -127,11 +230,23 @@ export const workerPlugin = definePlugin('workers')
|
|
|
127
230
|
if (!worker)
|
|
128
231
|
return workers;
|
|
129
232
|
const newWorkers = new Map(workers);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
233
|
+
if (event.toStatus === 'running' || event.toStatus === 'paused') {
|
|
234
|
+
newWorkers.set(event.workerId, {
|
|
235
|
+
...worker,
|
|
236
|
+
status: event.toStatus,
|
|
237
|
+
updatedAt: event.timestamp,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
newWorkers.set(event.workerId, {
|
|
242
|
+
id: worker.id,
|
|
243
|
+
agentId: worker.agentId,
|
|
244
|
+
workerType: worker.workerType,
|
|
245
|
+
status: event.toStatus,
|
|
246
|
+
createdAt: worker.createdAt,
|
|
247
|
+
updatedAt: event.timestamp,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
135
250
|
return newWorkers;
|
|
136
251
|
}
|
|
137
252
|
case 'worker_completed': {
|
|
@@ -140,8 +255,16 @@ export const workerPlugin = definePlugin('workers')
|
|
|
140
255
|
return workers;
|
|
141
256
|
const newWorkers = new Map(workers);
|
|
142
257
|
newWorkers.set(event.workerId, {
|
|
143
|
-
|
|
258
|
+
id: worker.id,
|
|
259
|
+
agentId: worker.agentId,
|
|
260
|
+
workerType: worker.workerType,
|
|
144
261
|
status: 'completed',
|
|
262
|
+
result: {
|
|
263
|
+
status: event.result.status,
|
|
264
|
+
resultsPath: event.result.resultsPath,
|
|
265
|
+
summary: event.result.summary,
|
|
266
|
+
},
|
|
267
|
+
createdAt: worker.createdAt,
|
|
145
268
|
updatedAt: event.timestamp,
|
|
146
269
|
});
|
|
147
270
|
return newWorkers;
|
|
@@ -152,8 +275,12 @@ export const workerPlugin = definePlugin('workers')
|
|
|
152
275
|
return workers;
|
|
153
276
|
const newWorkers = new Map(workers);
|
|
154
277
|
newWorkers.set(event.workerId, {
|
|
155
|
-
|
|
278
|
+
id: worker.id,
|
|
279
|
+
agentId: worker.agentId,
|
|
280
|
+
workerType: worker.workerType,
|
|
156
281
|
status: 'failed',
|
|
282
|
+
error: { message: event.error, resumable: event.resumable },
|
|
283
|
+
createdAt: worker.createdAt,
|
|
157
284
|
updatedAt: event.timestamp,
|
|
158
285
|
});
|
|
159
286
|
return newWorkers;
|
|
@@ -165,7 +292,12 @@ export const workerPlugin = definePlugin('workers')
|
|
|
165
292
|
})
|
|
166
293
|
.context(async (ctx) => {
|
|
167
294
|
const runningWorkers = new Map();
|
|
168
|
-
|
|
295
|
+
// Claimed synchronously by `resume` so the emit it awaits cannot let a second
|
|
296
|
+
// resume through and overwrite the live entry, leaking its lease.
|
|
297
|
+
const pendingLaunches = new Set();
|
|
298
|
+
// Workers whose `execute()` outlived its stop deadline and may still be running.
|
|
299
|
+
const abandonedWorkers = new Set();
|
|
300
|
+
return { runningWorkers, pendingLaunches, abandonedWorkers, logger: ctx.logger };
|
|
169
301
|
})
|
|
170
302
|
.agentConfig()
|
|
171
303
|
.method('spawn', {
|
|
@@ -194,6 +326,10 @@ export const workerPlugin = definePlugin('workers')
|
|
|
194
326
|
const validConfig = validationResult.data;
|
|
195
327
|
const workerId = generateWorkerId();
|
|
196
328
|
const { runningWorkers, logger } = ctx.pluginContext;
|
|
329
|
+
// Refuse before persisting a start we already know we cannot honour.
|
|
330
|
+
if (runningWorkers.size >= MAX_CONCURRENT_WORKERS) {
|
|
331
|
+
return Err(ValidationErrors.invalid(`Max concurrent workers reached (${MAX_CONCURRENT_WORKERS})`));
|
|
332
|
+
}
|
|
197
333
|
// Emit worker started event
|
|
198
334
|
await ctx.emitEvent(workerEvents.create('worker_started', {
|
|
199
335
|
workerId,
|
|
@@ -201,45 +337,105 @@ export const workerPlugin = definePlugin('workers')
|
|
|
201
337
|
workerType: definition.type,
|
|
202
338
|
config: validConfig,
|
|
203
339
|
}));
|
|
204
|
-
|
|
205
|
-
const
|
|
340
|
+
const sessionId = ctx.sessionId;
|
|
341
|
+
const agentId = input.agentId;
|
|
342
|
+
const files = ctx.files.session;
|
|
343
|
+
const emitEvent = ctx.emitEvent;
|
|
344
|
+
const getSessionState = ctx.getSessionState;
|
|
345
|
+
const reserveMailboxMessageSequence = ctx.reserveMailboxMessageSequence;
|
|
346
|
+
const scheduleAgent = ctx.scheduleAgent;
|
|
347
|
+
const runtimeActivity = ctx.runtimeActivity;
|
|
348
|
+
const launched = launchWorker({
|
|
206
349
|
sessionId: ctx.sessionId,
|
|
207
350
|
workerId,
|
|
208
|
-
agentId
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
emitEvent: ctx.emitEvent,
|
|
212
|
-
getSessionState: () => ctx.sessionState,
|
|
213
|
-
reducer: definition.reduce,
|
|
351
|
+
agentId,
|
|
352
|
+
definition,
|
|
353
|
+
config: validConfig,
|
|
214
354
|
initialState: definition.initialState(validConfig),
|
|
215
|
-
|
|
216
|
-
|
|
355
|
+
resumed: false,
|
|
356
|
+
files,
|
|
357
|
+
emitEvent,
|
|
358
|
+
getSessionState,
|
|
359
|
+
reserveMailboxMessageSequence,
|
|
360
|
+
scheduleAgent,
|
|
361
|
+
runtimeActivity,
|
|
362
|
+
runningWorkers,
|
|
363
|
+
effectDrainTimeoutMs: resolveStopTimeouts(ctx.pluginConfig).effectDrainTimeoutMs,
|
|
364
|
+
logger,
|
|
217
365
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
366
|
+
if (!launched.ok) {
|
|
367
|
+
// The pre-check can go stale across the emit above; keep the projection truthful.
|
|
368
|
+
await ctx.emitEvent(workerEvents.create('worker_failed', {
|
|
369
|
+
workerId,
|
|
370
|
+
error: launched.error,
|
|
371
|
+
resumable: true,
|
|
372
|
+
}));
|
|
373
|
+
return Err(ValidationErrors.invalid(launched.error));
|
|
222
374
|
}
|
|
223
|
-
// Start worker execution with error boundary
|
|
224
|
-
const promise = executeWorker(workerId, definition, validConfig, workerContext, ctx.emitEvent, runningWorkers, logger).catch((err) => {
|
|
225
|
-
logger.error('Unhandled error in worker execution', err instanceof Error ? err : undefined, { workerId });
|
|
226
|
-
});
|
|
227
|
-
// Track running worker
|
|
228
|
-
runningWorkers.set(workerId, {
|
|
229
|
-
workerId,
|
|
230
|
-
workerType: definition.type,
|
|
231
|
-
definition,
|
|
232
|
-
context: workerContext,
|
|
233
|
-
promise,
|
|
234
|
-
});
|
|
235
375
|
logger.info('Worker started', {
|
|
236
|
-
sessionId
|
|
376
|
+
sessionId,
|
|
237
377
|
workerId,
|
|
238
378
|
workerType: definition.type,
|
|
239
379
|
agentId: input.agentId,
|
|
240
380
|
});
|
|
241
381
|
return Ok({ workerId });
|
|
242
382
|
},
|
|
383
|
+
})
|
|
384
|
+
.sessionHook('onSessionReady', async (ctx) => {
|
|
385
|
+
const { runningWorkers, logger } = ctx.pluginContext;
|
|
386
|
+
const files = ctx.files.session;
|
|
387
|
+
const emitEvent = ctx.emitEvent;
|
|
388
|
+
const getSessionState = ctx.getSessionState;
|
|
389
|
+
const reserveMailboxMessageSequence = ctx.reserveMailboxMessageSequence;
|
|
390
|
+
const scheduleAgent = ctx.scheduleAgent;
|
|
391
|
+
const runtimeActivity = ctx.runtimeActivity;
|
|
392
|
+
const { effectDrainTimeoutMs } = resolveStopTimeouts(ctx.pluginConfig);
|
|
393
|
+
// A relaunch that does not happen must not leave the projection claiming `running`
|
|
394
|
+
// — park the worker instead, which keeps its state and lets `resume` pick it up.
|
|
395
|
+
const parkStoppedWorker = async (workerId) => {
|
|
396
|
+
await ctx.emitEvent(workerEvents.create('worker_status_changed', {
|
|
397
|
+
workerId,
|
|
398
|
+
fromStatus: 'running',
|
|
399
|
+
toStatus: 'paused',
|
|
400
|
+
}));
|
|
401
|
+
};
|
|
402
|
+
for (const worker of ctx.pluginState.values()) {
|
|
403
|
+
// Paused workers stay stopped — `workers.resume` relaunches them on demand.
|
|
404
|
+
if (worker.status !== 'running')
|
|
405
|
+
continue;
|
|
406
|
+
if (!Object.hasOwn(worker, 'config') || !Object.hasOwn(worker, 'state'))
|
|
407
|
+
continue;
|
|
408
|
+
if (runningWorkers.has(worker.id))
|
|
409
|
+
continue;
|
|
410
|
+
const definition = ctx.pluginConfig.workers.find((candidate) => candidate.type === worker.workerType);
|
|
411
|
+
if (!definition) {
|
|
412
|
+
logger.warn('Cannot resume worker with missing definition', { workerId: worker.id, workerType: worker.workerType });
|
|
413
|
+
await parkStoppedWorker(worker.id);
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const launched = launchWorker({
|
|
417
|
+
sessionId: ctx.sessionId,
|
|
418
|
+
agentId: worker.agentId,
|
|
419
|
+
workerId: worker.id,
|
|
420
|
+
definition,
|
|
421
|
+
config: worker.config,
|
|
422
|
+
initialState: worker.state,
|
|
423
|
+
resumed: true,
|
|
424
|
+
files,
|
|
425
|
+
emitEvent,
|
|
426
|
+
getSessionState,
|
|
427
|
+
reserveMailboxMessageSequence,
|
|
428
|
+
scheduleAgent,
|
|
429
|
+
runtimeActivity,
|
|
430
|
+
runningWorkers,
|
|
431
|
+
effectDrainTimeoutMs,
|
|
432
|
+
logger,
|
|
433
|
+
});
|
|
434
|
+
if (!launched.ok) {
|
|
435
|
+
logger.warn('Cannot relaunch worker', { workerId: worker.id, workerType: worker.workerType, reason: launched.error });
|
|
436
|
+
await parkStoppedWorker(worker.id);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
243
439
|
})
|
|
244
440
|
.method('getStatus', {
|
|
245
441
|
input: z.object({
|
|
@@ -256,8 +452,14 @@ export const workerPlugin = definePlugin('workers')
|
|
|
256
452
|
if (!worker) {
|
|
257
453
|
return Err(ValidationErrors.invalid(`Worker not found: ${input.workerId}`));
|
|
258
454
|
}
|
|
259
|
-
|
|
260
|
-
|
|
455
|
+
let state;
|
|
456
|
+
if (worker.status === 'running' || worker.status === 'paused') {
|
|
457
|
+
const definition = ctx.pluginConfig.workers.find((w) => w.type === worker.workerType);
|
|
458
|
+
state = definition?.summarizeState ? definition.summarizeState(worker.state) : worker.state;
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
state = worker.result ?? worker.error;
|
|
462
|
+
}
|
|
261
463
|
return Ok({
|
|
262
464
|
status: worker.status,
|
|
263
465
|
state,
|
|
@@ -277,7 +479,9 @@ export const workerPlugin = definePlugin('workers')
|
|
|
277
479
|
const workerId = WorkerId(input.workerId);
|
|
278
480
|
const worker = ctx.pluginContext.runningWorkers.get(workerId);
|
|
279
481
|
if (!worker) {
|
|
280
|
-
|
|
482
|
+
// Commands run against a live context, and starting one here would silently
|
|
483
|
+
// undo an explicit pause — the caller resumes first.
|
|
484
|
+
return Err(ValidationErrors.invalid(describeUnavailableWorker(workerId, ctx.pluginState.get(workerId))));
|
|
281
485
|
}
|
|
282
486
|
if (!worker.definition.handleCommand) {
|
|
283
487
|
return Err(ValidationErrors.invalid(`Worker type ${worker.workerType} does not support commands`));
|
|
@@ -297,16 +501,20 @@ export const workerPlugin = definePlugin('workers')
|
|
|
297
501
|
output: z.object({}),
|
|
298
502
|
handler: async (ctx, input) => {
|
|
299
503
|
const workerId = WorkerId(input.workerId);
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
return Err(ValidationErrors.invalid(`Worker not running: ${input.workerId}`));
|
|
303
|
-
}
|
|
304
|
-
worker.context.cancel();
|
|
504
|
+
const { runningWorkers, abandonedWorkers } = ctx.pluginContext;
|
|
505
|
+
const worker = runningWorkers.get(workerId);
|
|
305
506
|
const workerEntry = ctx.pluginState.get(workerId);
|
|
306
|
-
|
|
507
|
+
// The projection decides, not the map: a completed worker lingers there for the
|
|
508
|
+
// whole of its effect drain, and cancelling it would overwrite its real result.
|
|
509
|
+
if (!workerEntry || (workerEntry.status !== 'running' && workerEntry.status !== 'paused')) {
|
|
510
|
+
return Err(ValidationErrors.invalid(describeUnavailableWorker(workerId, workerEntry)));
|
|
511
|
+
}
|
|
512
|
+
// Bounded, so a worker that ignores cancellation cannot hold the runtime open.
|
|
513
|
+
if (worker)
|
|
514
|
+
await stopWorkers([worker], runningWorkers, abandonedWorkers, resolveStopTimeouts(ctx.pluginConfig));
|
|
307
515
|
await ctx.emitEvent(workerEvents.create('worker_status_changed', {
|
|
308
516
|
workerId,
|
|
309
|
-
fromStatus,
|
|
517
|
+
fromStatus: workerEntry.status,
|
|
310
518
|
toStatus: 'cancelled',
|
|
311
519
|
}));
|
|
312
520
|
return Ok({});
|
|
@@ -321,16 +529,20 @@ export const workerPlugin = definePlugin('workers')
|
|
|
321
529
|
output: z.object({}),
|
|
322
530
|
handler: async (ctx, input) => {
|
|
323
531
|
const workerId = WorkerId(input.workerId);
|
|
324
|
-
const
|
|
532
|
+
const { runningWorkers, abandonedWorkers } = ctx.pluginContext;
|
|
533
|
+
const worker = runningWorkers.get(workerId);
|
|
325
534
|
if (!worker) {
|
|
326
|
-
return Err(ValidationErrors.invalid(
|
|
535
|
+
return Err(ValidationErrors.invalid(describeUnavailableWorker(workerId, ctx.pluginState.get(workerId))));
|
|
327
536
|
}
|
|
328
537
|
const workerEntry = ctx.pluginState.get(workerId);
|
|
329
538
|
const fromStatus = workerEntry?.status ?? 'running';
|
|
330
539
|
if (fromStatus !== 'running') {
|
|
331
540
|
return Err(ValidationErrors.invalid(`Worker not in running state: ${fromStatus}`));
|
|
332
541
|
}
|
|
542
|
+
// Pausing stops the run instead of spinning it: a parked worker must not keep
|
|
543
|
+
// the runtime resident. `resume` re-enters execute() with the replayed state.
|
|
333
544
|
worker.context.pause();
|
|
545
|
+
await stopWorkers([worker], runningWorkers, abandonedWorkers, resolveStopTimeouts(ctx.pluginConfig));
|
|
334
546
|
await ctx.emitEvent(workerEvents.create('worker_status_changed', {
|
|
335
547
|
workerId,
|
|
336
548
|
fromStatus,
|
|
@@ -348,39 +560,89 @@ export const workerPlugin = definePlugin('workers')
|
|
|
348
560
|
output: z.object({}),
|
|
349
561
|
handler: async (ctx, input) => {
|
|
350
562
|
const workerId = WorkerId(input.workerId);
|
|
351
|
-
const
|
|
352
|
-
if (!worker) {
|
|
353
|
-
return Err(ValidationErrors.invalid(`Worker not running: ${input.workerId}`));
|
|
354
|
-
}
|
|
563
|
+
const { runningWorkers, pendingLaunches, abandonedWorkers, logger } = ctx.pluginContext;
|
|
355
564
|
const workerEntry = ctx.pluginState.get(workerId);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
565
|
+
if (!workerEntry) {
|
|
566
|
+
return Err(ValidationErrors.invalid(`Worker not found: ${input.workerId}`));
|
|
567
|
+
}
|
|
568
|
+
if (workerEntry.status !== 'paused') {
|
|
569
|
+
return Err(ValidationErrors.invalid(`Worker not in paused state: ${workerEntry.status}`));
|
|
570
|
+
}
|
|
571
|
+
if (!Object.hasOwn(workerEntry, 'config') || !Object.hasOwn(workerEntry, 'state')) {
|
|
572
|
+
return Err(ValidationErrors.invalid(`Worker is no longer resumable: ${input.workerId}`));
|
|
573
|
+
}
|
|
574
|
+
const definition = ctx.pluginConfig.workers.find((candidate) => candidate.type === workerEntry.workerType);
|
|
575
|
+
if (!definition) {
|
|
576
|
+
return Err(ValidationErrors.invalid(`Unknown worker type: ${workerEntry.workerType}`));
|
|
577
|
+
}
|
|
578
|
+
// Nothing runs a paused worker any more, so resume relaunches it — and must
|
|
579
|
+
// never overwrite a live entry, whose lease would then leak. The claim below
|
|
580
|
+
// is therefore taken in the same synchronous block as the checks: everything
|
|
581
|
+
// from here to `pendingLaunches.add` must stay free of `await`.
|
|
582
|
+
if (runningWorkers.has(workerId)) {
|
|
583
|
+
return Err(ValidationErrors.invalid(`Worker is already running: ${input.workerId}`));
|
|
584
|
+
}
|
|
585
|
+
if (pendingLaunches.has(workerId)) {
|
|
586
|
+
return Err(ValidationErrors.invalid(`Worker is already resuming: ${input.workerId}`));
|
|
587
|
+
}
|
|
588
|
+
if (abandonedWorkers.has(workerId)) {
|
|
589
|
+
return Err(ValidationErrors.invalid(`Worker did not stop within its deadline and may still be running: ${input.workerId}`));
|
|
590
|
+
}
|
|
591
|
+
if (runningWorkers.size + pendingLaunches.size >= MAX_CONCURRENT_WORKERS) {
|
|
592
|
+
return Err(ValidationErrors.invalid(`Max concurrent workers reached (${MAX_CONCURRENT_WORKERS})`));
|
|
593
|
+
}
|
|
594
|
+
pendingLaunches.add(workerId);
|
|
595
|
+
try {
|
|
596
|
+
// The status event goes first: a worker that finishes instantly would otherwise
|
|
597
|
+
// have its terminal projection overwritten by this event.
|
|
598
|
+
await ctx.emitEvent(workerEvents.create('worker_status_changed', {
|
|
599
|
+
workerId,
|
|
600
|
+
fromStatus: 'paused',
|
|
601
|
+
toStatus: 'running',
|
|
602
|
+
}));
|
|
603
|
+
const launched = launchWorker({
|
|
604
|
+
sessionId: ctx.sessionId,
|
|
605
|
+
agentId: workerEntry.agentId,
|
|
606
|
+
workerId,
|
|
607
|
+
definition,
|
|
608
|
+
config: workerEntry.config,
|
|
609
|
+
initialState: workerEntry.state,
|
|
610
|
+
resumed: true,
|
|
611
|
+
files: ctx.files.session,
|
|
612
|
+
emitEvent: ctx.emitEvent,
|
|
613
|
+
getSessionState: ctx.getSessionState,
|
|
614
|
+
reserveMailboxMessageSequence: ctx.reserveMailboxMessageSequence,
|
|
615
|
+
scheduleAgent: ctx.scheduleAgent,
|
|
616
|
+
runtimeActivity: ctx.runtimeActivity,
|
|
617
|
+
runningWorkers,
|
|
618
|
+
effectDrainTimeoutMs: resolveStopTimeouts(ctx.pluginConfig).effectDrainTimeoutMs,
|
|
619
|
+
logger,
|
|
620
|
+
});
|
|
621
|
+
if (!launched.ok) {
|
|
622
|
+
// Park it again rather than fail it: both triggers are transient, and a
|
|
623
|
+
// `worker_failed` would drop the state and config that keep it resumable.
|
|
624
|
+
await ctx.emitEvent(workerEvents.create('worker_status_changed', {
|
|
625
|
+
workerId,
|
|
626
|
+
fromStatus: 'running',
|
|
627
|
+
toStatus: 'paused',
|
|
628
|
+
reason: launched.error,
|
|
629
|
+
}));
|
|
630
|
+
return Err(ValidationErrors.invalid(launched.error));
|
|
631
|
+
}
|
|
632
|
+
return Ok({});
|
|
633
|
+
}
|
|
634
|
+
finally {
|
|
635
|
+
pendingLaunches.delete(workerId);
|
|
359
636
|
}
|
|
360
|
-
worker.context.resume();
|
|
361
|
-
await ctx.emitEvent(workerEvents.create('worker_status_changed', {
|
|
362
|
-
workerId,
|
|
363
|
-
fromStatus,
|
|
364
|
-
toStatus: 'running',
|
|
365
|
-
}));
|
|
366
|
-
return Ok({});
|
|
367
637
|
},
|
|
368
638
|
})
|
|
369
639
|
.sessionHook('onSessionClose', async (ctx) => {
|
|
370
|
-
const { runningWorkers, logger } = ctx.pluginContext;
|
|
640
|
+
const { runningWorkers, abandonedWorkers, logger } = ctx.pluginContext;
|
|
371
641
|
if (runningWorkers.size === 0)
|
|
372
642
|
return;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
worker.context.cancel();
|
|
377
|
-
}
|
|
378
|
-
// Await all worker promises with a timeout (5s)
|
|
379
|
-
const timeout = new Promise((resolve) => setTimeout(resolve, 5000));
|
|
380
|
-
await Promise.race([
|
|
381
|
-
Promise.allSettled([...runningWorkers.values()].map((w) => w.promise)),
|
|
382
|
-
timeout,
|
|
383
|
-
]);
|
|
643
|
+
const closingWorkers = [...runningWorkers.values()];
|
|
644
|
+
logger.info('Cancelling running workers on session close', { count: closingWorkers.length });
|
|
645
|
+
await stopWorkers(closingWorkers, runningWorkers, abandonedWorkers, resolveStopTimeouts(ctx.pluginConfig));
|
|
384
646
|
runningWorkers.clear();
|
|
385
647
|
})
|
|
386
648
|
.tools((ctx) => {
|
|
@@ -479,7 +741,7 @@ export const workerPlugin = definePlugin('workers')
|
|
|
479
741
|
},
|
|
480
742
|
}), createTool({
|
|
481
743
|
name: 'worker_cancel',
|
|
482
|
-
description: 'Cancel a running worker.
|
|
744
|
+
description: 'Cancel a running or paused worker. It stops for good and cannot be resumed.',
|
|
483
745
|
input: z.object({
|
|
484
746
|
workerId: workerIdSchema,
|
|
485
747
|
}),
|
|
@@ -495,7 +757,7 @@ export const workerPlugin = definePlugin('workers')
|
|
|
495
757
|
},
|
|
496
758
|
}), createTool({
|
|
497
759
|
name: 'worker_pause',
|
|
498
|
-
description: 'Pause a running worker.
|
|
760
|
+
description: 'Pause a running worker. It stops where it is; worker_resume restarts it from the progress it had recorded.',
|
|
499
761
|
input: z.object({
|
|
500
762
|
workerId: workerIdSchema,
|
|
501
763
|
}),
|
|
@@ -511,7 +773,7 @@ export const workerPlugin = definePlugin('workers')
|
|
|
511
773
|
},
|
|
512
774
|
}), createTool({
|
|
513
775
|
name: 'worker_resume',
|
|
514
|
-
description: 'Resume a paused worker.',
|
|
776
|
+
description: 'Resume a paused worker. It restarts from the progress it had recorded.',
|
|
515
777
|
input: z.object({
|
|
516
778
|
workerId: workerIdSchema,
|
|
517
779
|
}),
|