operon-agents-core 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +55 -0
- package/README.md +7 -0
- package/dist/agent/agent.d.ts +65 -0
- package/dist/agent/agent.js +39 -0
- package/dist/agent/compose-hooks.d.ts +13 -0
- package/dist/agent/compose-hooks.js +197 -0
- package/dist/agent/concurrency.d.ts +22 -0
- package/dist/agent/concurrency.js +70 -0
- package/dist/agent/context-report.d.ts +60 -0
- package/dist/agent/context-report.js +45 -0
- package/dist/agent/graph.d.ts +48 -0
- package/dist/agent/graph.js +129 -0
- package/dist/agent/guardrail.d.ts +105 -0
- package/dist/agent/guardrail.js +314 -0
- package/dist/agent/handoff-executor.d.ts +21 -0
- package/dist/agent/handoff-executor.js +95 -0
- package/dist/agent/handoff.d.ts +42 -0
- package/dist/agent/handoff.js +70 -0
- package/dist/agent/index.d.ts +25 -0
- package/dist/agent/index.js +19 -0
- package/dist/agent/instruction-context.d.ts +33 -0
- package/dist/agent/instruction-context.js +100 -0
- package/dist/agent/pause.d.ts +12 -0
- package/dist/agent/pause.js +82 -0
- package/dist/agent/profile-builtins.d.ts +8 -0
- package/dist/agent/profile-builtins.js +130 -0
- package/dist/agent/profiles.d.ts +94 -0
- package/dist/agent/profiles.js +264 -0
- package/dist/agent/recovery.d.ts +10 -0
- package/dist/agent/recovery.js +151 -0
- package/dist/agent/run-support.d.ts +79 -0
- package/dist/agent/run-support.js +211 -0
- package/dist/agent/runner.d.ts +246 -0
- package/dist/agent/runner.js +786 -0
- package/dist/agent/session.d.ts +363 -0
- package/dist/agent/session.js +937 -0
- package/dist/agent/subagent-tools.d.ts +18 -0
- package/dist/agent/subagent-tools.js +650 -0
- package/dist/agent/subagent.d.ts +56 -0
- package/dist/agent/subagent.js +50 -0
- package/dist/agent/toolset.d.ts +24 -0
- package/dist/agent/toolset.js +112 -0
- package/dist/agent/workflow/index.d.ts +9 -0
- package/dist/agent/workflow/index.js +8 -0
- package/dist/agent/workflow/journal.d.ts +180 -0
- package/dist/agent/workflow/journal.js +224 -0
- package/dist/agent/workflow/manager.d.ts +27 -0
- package/dist/agent/workflow/manager.js +33 -0
- package/dist/agent/workflow/parse.d.ts +17 -0
- package/dist/agent/workflow/parse.js +174 -0
- package/dist/agent/workflow/prompt.d.ts +8 -0
- package/dist/agent/workflow/prompt.js +84 -0
- package/dist/agent/workflow/runtime.d.ts +64 -0
- package/dist/agent/workflow/runtime.js +380 -0
- package/dist/agent/workflow/sandbox.d.ts +35 -0
- package/dist/agent/workflow/sandbox.js +90 -0
- package/dist/agent/workflow/snapshot.d.ts +36 -0
- package/dist/agent/workflow/snapshot.js +9 -0
- package/dist/agent/workflow/structured.d.ts +35 -0
- package/dist/agent/workflow/structured.js +79 -0
- package/dist/agent/workflow/tool.d.ts +14 -0
- package/dist/agent/workflow/tool.js +569 -0
- package/dist/agent/workflow/types.d.ts +100 -0
- package/dist/agent/workflow/types.js +17 -0
- package/dist/agent/worktree.d.ts +38 -0
- package/dist/agent/worktree.js +56 -0
- package/dist/capabilities/assembler.d.ts +39 -0
- package/dist/capabilities/assembler.js +171 -0
- package/dist/capabilities/background/agent-task.d.ts +51 -0
- package/dist/capabilities/background/agent-task.js +101 -0
- package/dist/capabilities/background/command-task.d.ts +43 -0
- package/dist/capabilities/background/command-task.js +86 -0
- package/dist/capabilities/background/index.d.ts +20 -0
- package/dist/capabilities/background/index.js +57 -0
- package/dist/capabilities/background/manager.d.ts +194 -0
- package/dist/capabilities/background/manager.js +1131 -0
- package/dist/capabilities/background/persist-disk.d.ts +17 -0
- package/dist/capabilities/background/persist-disk.js +66 -0
- package/dist/capabilities/background/persist.d.ts +61 -0
- package/dist/capabilities/background/persist.js +117 -0
- package/dist/capabilities/background/question-task.d.ts +32 -0
- package/dist/capabilities/background/question-task.js +56 -0
- package/dist/capabilities/background/registrar.d.ts +12 -0
- package/dist/capabilities/background/registrar.js +9 -0
- package/dist/capabilities/background/swappable-sink.d.ts +20 -0
- package/dist/capabilities/background/swappable-sink.js +20 -0
- package/dist/capabilities/background/task.d.ts +114 -0
- package/dist/capabilities/background/task.js +20 -0
- package/dist/capabilities/background/tools.d.ts +6 -0
- package/dist/capabilities/background/tools.js +190 -0
- package/dist/capabilities/background/workflow-task.d.ts +48 -0
- package/dist/capabilities/background/workflow-task.js +91 -0
- package/dist/capabilities/capability-state.d.ts +13 -0
- package/dist/capabilities/capability-state.js +37 -0
- package/dist/capabilities/capability.d.ts +145 -0
- package/dist/capabilities/capability.js +2 -0
- package/dist/capabilities/compaction/full.d.ts +27 -0
- package/dist/capabilities/compaction/full.js +155 -0
- package/dist/capabilities/compaction/index.d.ts +17 -0
- package/dist/capabilities/compaction/index.js +145 -0
- package/dist/capabilities/compaction/instruction.d.ts +2 -0
- package/dist/capabilities/compaction/instruction.js +31 -0
- package/dist/capabilities/compaction/micro.d.ts +17 -0
- package/dist/capabilities/compaction/micro.js +57 -0
- package/dist/capabilities/compaction/service.d.ts +28 -0
- package/dist/capabilities/compaction/service.js +52 -0
- package/dist/capabilities/compaction/strategy.d.ts +43 -0
- package/dist/capabilities/compaction/strategy.js +116 -0
- package/dist/capabilities/compaction/tokens.d.ts +5 -0
- package/dist/capabilities/compaction/tokens.js +28 -0
- package/dist/capabilities/goal/goal-store.d.ts +69 -0
- package/dist/capabilities/goal/goal-store.js +172 -0
- package/dist/capabilities/goal/index.d.ts +6 -0
- package/dist/capabilities/goal/index.js +31 -0
- package/dist/capabilities/goal/injector.d.ts +9 -0
- package/dist/capabilities/goal/injector.js +79 -0
- package/dist/capabilities/goal/tools.d.ts +6 -0
- package/dist/capabilities/goal/tools.js +86 -0
- package/dist/capabilities/index.d.ts +25 -0
- package/dist/capabilities/index.js +22 -0
- package/dist/capabilities/injection.d.ts +44 -0
- package/dist/capabilities/injection.js +112 -0
- package/dist/capabilities/plan/index.d.ts +6 -0
- package/dist/capabilities/plan/index.js +25 -0
- package/dist/capabilities/plan/injector.d.ts +13 -0
- package/dist/capabilities/plan/injector.js +83 -0
- package/dist/capabilities/plan/plan-mode.d.ts +38 -0
- package/dist/capabilities/plan/plan-mode.js +113 -0
- package/dist/capabilities/plan/policies.d.ts +6 -0
- package/dist/capabilities/plan/policies.js +89 -0
- package/dist/capabilities/plan/tools.d.ts +15 -0
- package/dist/capabilities/plan/tools.js +87 -0
- package/dist/capabilities/skills/flow-provider.d.ts +6 -0
- package/dist/capabilities/skills/flow-provider.js +50 -0
- package/dist/capabilities/skills/index.d.ts +43 -0
- package/dist/capabilities/skills/index.js +48 -0
- package/dist/capabilities/skills/injector.d.ts +11 -0
- package/dist/capabilities/skills/injector.js +27 -0
- package/dist/capabilities/skills/parser.d.ts +36 -0
- package/dist/capabilities/skills/parser.js +334 -0
- package/dist/capabilities/skills/registry.d.ts +33 -0
- package/dist/capabilities/skills/registry.js +118 -0
- package/dist/capabilities/skills/scanner.d.ts +26 -0
- package/dist/capabilities/skills/scanner.js +154 -0
- package/dist/capabilities/skills/service.d.ts +39 -0
- package/dist/capabilities/skills/service.js +68 -0
- package/dist/capabilities/skills/skill-tool.d.ts +13 -0
- package/dist/capabilities/skills/skill-tool.js +72 -0
- package/dist/capabilities/skills/types.d.ts +62 -0
- package/dist/capabilities/skills/types.js +26 -0
- package/dist/capabilities/task/index.d.ts +23 -0
- package/dist/capabilities/task/index.js +38 -0
- package/dist/capabilities/task/injector.d.ts +9 -0
- package/dist/capabilities/task/injector.js +62 -0
- package/dist/capabilities/task/persist-disk.d.ts +19 -0
- package/dist/capabilities/task/persist-disk.js +84 -0
- package/dist/capabilities/task/persist.d.ts +52 -0
- package/dist/capabilities/task/persist.js +84 -0
- package/dist/capabilities/task/task-store.d.ts +44 -0
- package/dist/capabilities/task/task-store.js +106 -0
- package/dist/capabilities/task/tools.d.ts +12 -0
- package/dist/capabilities/task/tools.js +164 -0
- package/dist/capabilities/todo/index.d.ts +8 -0
- package/dist/capabilities/todo/index.js +21 -0
- package/dist/capabilities/todo/injector.d.ts +9 -0
- package/dist/capabilities/todo/injector.js +68 -0
- package/dist/capabilities/todo/todo-store.d.ts +19 -0
- package/dist/capabilities/todo/todo-store.js +36 -0
- package/dist/capabilities/todo/tools.d.ts +6 -0
- package/dist/capabilities/todo/tools.js +70 -0
- package/dist/capabilities/tool-provider.d.ts +12 -0
- package/dist/capabilities/tool-provider.js +20 -0
- package/dist/capabilities/user-hooks/engine.d.ts +22 -0
- package/dist/capabilities/user-hooks/engine.js +105 -0
- package/dist/capabilities/user-hooks/index.d.ts +13 -0
- package/dist/capabilities/user-hooks/index.js +126 -0
- package/dist/capabilities/user-hooks/types.d.ts +26 -0
- package/dist/capabilities/user-hooks/types.js +19 -0
- package/dist/capabilities/workflow/index.d.ts +16 -0
- package/dist/capabilities/workflow/index.js +15 -0
- package/dist/commands/index.d.ts +31 -0
- package/dist/commands/index.js +318 -0
- package/dist/config/config-store.d.ts +29 -0
- package/dist/config/config-store.js +103 -0
- package/dist/config/file-source.d.ts +40 -0
- package/dist/config/file-source.js +78 -0
- package/dist/config/flags.d.ts +13 -0
- package/dist/config/flags.js +25 -0
- package/dist/config/index.d.ts +17 -0
- package/dist/config/index.js +10 -0
- package/dist/config/merge.d.ts +5 -0
- package/dist/config/merge.js +57 -0
- package/dist/config/model-catalog.d.ts +17 -0
- package/dist/config/model-catalog.js +37 -0
- package/dist/config/paths.d.ts +31 -0
- package/dist/config/paths.js +28 -0
- package/dist/config/provider-manager.d.ts +57 -0
- package/dist/config/provider-manager.js +344 -0
- package/dist/config/resolver.d.ts +40 -0
- package/dist/config/resolver.js +52 -0
- package/dist/config/schema.d.ts +389 -0
- package/dist/config/schema.js +132 -0
- package/dist/events/events.d.ts +348 -0
- package/dist/events/events.js +146 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +5 -0
- package/dist/events/projection.d.ts +207 -0
- package/dist/events/projection.js +438 -0
- package/dist/events/publisher.d.ts +48 -0
- package/dist/events/publisher.js +404 -0
- package/dist/events/redacting-sink.d.ts +11 -0
- package/dist/events/redacting-sink.js +31 -0
- package/dist/home.d.ts +16 -0
- package/dist/home.js +20 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/internal.d.ts +33 -0
- package/dist/internal.js +29 -0
- package/dist/llm/auth.d.ts +22 -0
- package/dist/llm/auth.js +112 -0
- package/dist/llm/capability.d.ts +13 -0
- package/dist/llm/capability.js +45 -0
- package/dist/llm/define-model.d.ts +110 -0
- package/dist/llm/define-model.js +252 -0
- package/dist/llm/errors.d.ts +33 -0
- package/dist/llm/errors.js +154 -0
- package/dist/llm/index.d.ts +14 -0
- package/dist/llm/index.js +8 -0
- package/dist/llm/model.d.ts +43 -0
- package/dist/llm/model.js +9 -0
- package/dist/llm/retry.d.ts +35 -0
- package/dist/llm/retry.js +160 -0
- package/dist/llm/runtime.d.ts +25 -0
- package/dist/llm/runtime.js +38 -0
- package/dist/logging/diagnostics.d.ts +21 -0
- package/dist/logging/diagnostics.js +46 -0
- package/dist/logging/index.d.ts +11 -0
- package/dist/logging/index.js +7 -0
- package/dist/logging/logger.d.ts +25 -0
- package/dist/logging/logger.js +54 -0
- package/dist/logging/paths.d.ts +11 -0
- package/dist/logging/paths.js +20 -0
- package/dist/logging/policy.d.ts +5 -0
- package/dist/logging/policy.js +19 -0
- package/dist/logging/redact.d.ts +10 -0
- package/dist/logging/redact.js +95 -0
- package/dist/logging/sinks.d.ts +67 -0
- package/dist/logging/sinks.js +117 -0
- package/dist/loop/context.d.ts +69 -0
- package/dist/loop/context.js +129 -0
- package/dist/loop/errors.d.ts +8 -0
- package/dist/loop/errors.js +27 -0
- package/dist/loop/events.d.ts +14 -0
- package/dist/loop/events.js +2 -0
- package/dist/loop/index.d.ts +10 -0
- package/dist/loop/index.js +7 -0
- package/dist/loop/interruption.d.ts +118 -0
- package/dist/loop/interruption.js +191 -0
- package/dist/loop/run-turn.d.ts +54 -0
- package/dist/loop/run-turn.js +203 -0
- package/dist/loop/scheduler.d.ts +18 -0
- package/dist/loop/scheduler.js +71 -0
- package/dist/loop/steer.d.ts +122 -0
- package/dist/loop/steer.js +209 -0
- package/dist/loop/tool-call.d.ts +41 -0
- package/dist/loop/tool-call.js +326 -0
- package/dist/loop/turn-step.d.ts +57 -0
- package/dist/loop/turn-step.js +298 -0
- package/dist/loop/types.d.ts +217 -0
- package/dist/loop/types.js +2 -0
- package/dist/loop/usage.d.ts +6 -0
- package/dist/loop/usage.js +44 -0
- package/dist/mcp/auth-tool.d.ts +12 -0
- package/dist/mcp/auth-tool.js +92 -0
- package/dist/mcp/capability.d.ts +7 -0
- package/dist/mcp/capability.js +91 -0
- package/dist/mcp/config-loader.d.ts +28 -0
- package/dist/mcp/config-loader.js +115 -0
- package/dist/mcp/filter.d.ts +18 -0
- package/dist/mcp/filter.js +35 -0
- package/dist/mcp/index.d.ts +23 -0
- package/dist/mcp/index.js +13 -0
- package/dist/mcp/manager.d.ts +51 -0
- package/dist/mcp/manager.js +412 -0
- package/dist/mcp/mock-transport.d.ts +40 -0
- package/dist/mcp/mock-transport.js +68 -0
- package/dist/mcp/oauth/callback-server.d.ts +14 -0
- package/dist/mcp/oauth/callback-server.js +122 -0
- package/dist/mcp/oauth/index.d.ts +9 -0
- package/dist/mcp/oauth/index.js +5 -0
- package/dist/mcp/oauth/provider.d.ts +39 -0
- package/dist/mcp/oauth/provider.js +121 -0
- package/dist/mcp/oauth/service.d.ts +34 -0
- package/dist/mcp/oauth/service.js +130 -0
- package/dist/mcp/oauth/store.d.ts +40 -0
- package/dist/mcp/oauth/store.js +134 -0
- package/dist/mcp/output.d.ts +12 -0
- package/dist/mcp/output.js +110 -0
- package/dist/mcp/provider.d.ts +7 -0
- package/dist/mcp/provider.js +56 -0
- package/dist/mcp/sdk-transport.d.ts +25 -0
- package/dist/mcp/sdk-transport.js +228 -0
- package/dist/mcp/server.d.ts +77 -0
- package/dist/mcp/server.js +120 -0
- package/dist/mcp/tool-naming.d.ts +4 -0
- package/dist/mcp/tool-naming.js +26 -0
- package/dist/mcp/types.d.ts +75 -0
- package/dist/mcp/types.js +2 -0
- package/dist/net/index.d.ts +3 -0
- package/dist/net/index.js +2 -0
- package/dist/net/proxy.d.ts +16 -0
- package/dist/net/proxy.js +42 -0
- package/dist/permission/auto-approver/index.d.ts +3 -0
- package/dist/permission/auto-approver/index.js +3 -0
- package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
- package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
- package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
- package/dist/permission/auto-approver/prompts-data.js +155 -0
- package/dist/permission/auto-approver/prompts.d.ts +18 -0
- package/dist/permission/auto-approver/prompts.js +40 -0
- package/dist/permission/auto-approver/transcript.d.ts +22 -0
- package/dist/permission/auto-approver/transcript.js +75 -0
- package/dist/permission/auto-approver/xml.d.ts +5 -0
- package/dist/permission/auto-approver/xml.js +25 -0
- package/dist/permission/index.d.ts +7 -0
- package/dist/permission/index.js +5 -0
- package/dist/permission/manager.d.ts +74 -0
- package/dist/permission/manager.js +162 -0
- package/dist/permission/matches-rule.d.ts +27 -0
- package/dist/permission/matches-rule.js +54 -0
- package/dist/permission/policies.d.ts +14 -0
- package/dist/permission/policies.js +233 -0
- package/dist/permission/types.d.ts +84 -0
- package/dist/permission/types.js +2 -0
- package/dist/plugins/archive.d.ts +3 -0
- package/dist/plugins/archive.js +58 -0
- package/dist/plugins/github-resolver.d.ts +13 -0
- package/dist/plugins/github-resolver.js +20 -0
- package/dist/plugins/hooks.d.ts +28 -0
- package/dist/plugins/hooks.js +296 -0
- package/dist/plugins/index.d.ts +23 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/injector.d.ts +11 -0
- package/dist/plugins/injector.js +32 -0
- package/dist/plugins/manager.d.ts +37 -0
- package/dist/plugins/manager.js +330 -0
- package/dist/plugins/manifest.d.ts +9 -0
- package/dist/plugins/manifest.js +234 -0
- package/dist/plugins/marketplace.d.ts +85 -0
- package/dist/plugins/marketplace.js +205 -0
- package/dist/plugins/source.d.ts +23 -0
- package/dist/plugins/source.js +87 -0
- package/dist/plugins/store.d.ts +20 -0
- package/dist/plugins/store.js +30 -0
- package/dist/plugins/types.d.ts +118 -0
- package/dist/plugins/types.js +5 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +2 -0
- package/dist/protocol/tool-schema.d.ts +6 -0
- package/dist/protocol/tool-schema.js +2 -0
- package/dist/store/blob-store.d.ts +45 -0
- package/dist/store/blob-store.js +120 -0
- package/dist/store/catalog-store.d.ts +32 -0
- package/dist/store/catalog-store.js +73 -0
- package/dist/store/disk-store.d.ts +58 -0
- package/dist/store/disk-store.js +369 -0
- package/dist/store/index.d.ts +23 -0
- package/dist/store/index.js +15 -0
- package/dist/store/lock.d.ts +86 -0
- package/dist/store/lock.js +104 -0
- package/dist/store/log-store.d.ts +89 -0
- package/dist/store/log-store.js +296 -0
- package/dist/store/migrate.d.ts +26 -0
- package/dist/store/migrate.js +32 -0
- package/dist/store/origin.d.ts +89 -0
- package/dist/store/origin.js +16 -0
- package/dist/store/pg.d.ts +90 -0
- package/dist/store/pg.js +344 -0
- package/dist/store/redacting-store.d.ts +21 -0
- package/dist/store/redacting-store.js +46 -0
- package/dist/store/redis.d.ts +89 -0
- package/dist/store/redis.js +370 -0
- package/dist/store/repository.d.ts +150 -0
- package/dist/store/repository.js +508 -0
- package/dist/store/session-catalog.d.ts +32 -0
- package/dist/store/session-catalog.js +117 -0
- package/dist/store/storage.d.ts +27 -0
- package/dist/store/storage.js +54 -0
- package/dist/store/store.d.ts +262 -0
- package/dist/store/store.js +129 -0
- package/dist/store/workdir-key.d.ts +4 -0
- package/dist/store/workdir-key.js +28 -0
- package/dist/tool/access.d.ts +37 -0
- package/dist/tool/access.js +79 -0
- package/dist/tool/ask.d.ts +22 -0
- package/dist/tool/ask.js +38 -0
- package/dist/tool/background.d.ts +109 -0
- package/dist/tool/background.js +39 -0
- package/dist/tool/builtin/ask-user-question.d.ts +2 -0
- package/dist/tool/builtin/ask-user-question.js +175 -0
- package/dist/tool/builtin/bash.d.ts +2 -0
- package/dist/tool/builtin/bash.js +407 -0
- package/dist/tool/builtin/edit.d.ts +2 -0
- package/dist/tool/builtin/edit.js +202 -0
- package/dist/tool/builtin/glob.d.ts +3 -0
- package/dist/tool/builtin/glob.js +260 -0
- package/dist/tool/builtin/grep.d.ts +2 -0
- package/dist/tool/builtin/grep.js +574 -0
- package/dist/tool/builtin/line-endings.d.ts +10 -0
- package/dist/tool/builtin/line-endings.js +41 -0
- package/dist/tool/builtin/read.d.ts +28 -0
- package/dist/tool/builtin/read.js +498 -0
- package/dist/tool/builtin/write.d.ts +2 -0
- package/dist/tool/builtin/write.js +179 -0
- package/dist/tool/define.d.ts +46 -0
- package/dist/tool/define.js +45 -0
- package/dist/tool/file-freshness.d.ts +81 -0
- package/dist/tool/file-freshness.js +67 -0
- package/dist/tool/filesystem-tools.d.ts +16 -0
- package/dist/tool/filesystem-tools.js +19 -0
- package/dist/tool/git-context.d.ts +20 -0
- package/dist/tool/git-context.js +114 -0
- package/dist/tool/index.d.ts +37 -0
- package/dist/tool/index.js +34 -0
- package/dist/tool/machine-base.d.ts +138 -0
- package/dist/tool/machine-base.js +388 -0
- package/dist/tool/machine-local.d.ts +35 -0
- package/dist/tool/machine-local.js +316 -0
- package/dist/tool/machine-null.d.ts +36 -0
- package/dist/tool/machine-null.js +64 -0
- package/dist/tool/machine-ssh.d.ts +86 -0
- package/dist/tool/machine-ssh.js +576 -0
- package/dist/tool/machine.d.ts +333 -0
- package/dist/tool/machine.js +15 -0
- package/dist/tool/policies/path-access.d.ts +48 -0
- package/dist/tool/policies/path-access.js +186 -0
- package/dist/tool/policies/sensitive.d.ts +3 -0
- package/dist/tool/policies/sensitive.js +60 -0
- package/dist/tool/questions.d.ts +40 -0
- package/dist/tool/questions.js +8 -0
- package/dist/tool/search/activation.d.ts +13 -0
- package/dist/tool/search/activation.js +31 -0
- package/dist/tool/search/deferral.d.ts +37 -0
- package/dist/tool/search/deferral.js +128 -0
- package/dist/tool/search/search-tool.d.ts +9 -0
- package/dist/tool/search/search-tool.js +62 -0
- package/dist/tool/shell-env.d.ts +9 -0
- package/dist/tool/shell-env.js +34 -0
- package/dist/tool/support/bash-destructive.d.ts +24 -0
- package/dist/tool/support/bash-destructive.js +63 -0
- package/dist/tool/support/bash-paths.d.ts +7 -0
- package/dist/tool/support/bash-paths.js +247 -0
- package/dist/tool/support/bash-read-only.d.ts +8 -0
- package/dist/tool/support/bash-read-only.js +165 -0
- package/dist/tool/support/bash-rule-match.d.ts +20 -0
- package/dist/tool/support/bash-rule-match.js +191 -0
- package/dist/tool/support/file-type.d.ts +10 -0
- package/dist/tool/support/file-type.js +149 -0
- package/dist/tool/support/git-worktree.d.ts +10 -0
- package/dist/tool/support/git-worktree.js +63 -0
- package/dist/tool/support/image-compress.d.ts +69 -0
- package/dist/tool/support/image-compress.js +265 -0
- package/dist/tool/support/machine-ops.d.ts +34 -0
- package/dist/tool/support/machine-ops.js +34 -0
- package/dist/tool/support/path-glob-match.d.ts +12 -0
- package/dist/tool/support/path-glob-match.js +84 -0
- package/dist/tool/support/result-builder.d.ts +27 -0
- package/dist/tool/support/result-builder.js +108 -0
- package/dist/tool/support/rg-locator.d.ts +20 -0
- package/dist/tool/support/rg-locator.js +42 -0
- package/dist/tool/support/ripgrep-run.d.ts +65 -0
- package/dist/tool/support/ripgrep-run.js +40 -0
- package/dist/tool/support/rule-match.d.ts +6 -0
- package/dist/tool/support/rule-match.js +23 -0
- package/dist/tool/support/tool-path.d.ts +8 -0
- package/dist/tool/support/tool-path.js +28 -0
- package/dist/tool/support/workspace.d.ts +5 -0
- package/dist/tool/support/workspace.js +2 -0
- package/dist/tool/types.d.ts +131 -0
- package/dist/tool/types.js +2 -0
- package/dist/tool/web/fetch-url.d.ts +4 -0
- package/dist/tool/web/fetch-url.js +61 -0
- package/dist/tool/web/index.d.ts +11 -0
- package/dist/tool/web/index.js +7 -0
- package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
- package/dist/tool/web/providers/direct-fetch.js +198 -0
- package/dist/tool/web/providers/firecrawl.d.ts +16 -0
- package/dist/tool/web/providers/firecrawl.js +59 -0
- package/dist/tool/web/providers/tavily.d.ts +14 -0
- package/dist/tool/web/providers/tavily.js +43 -0
- package/dist/tool/web/types.d.ts +41 -0
- package/dist/tool/web/types.js +7 -0
- package/dist/tool/web/web-search.d.ts +4 -0
- package/dist/tool/web/web-search.js +68 -0
- package/dist/tool/workspace-spec.d.ts +74 -0
- package/dist/tool/workspace-spec.js +177 -0
- package/dist/tracing/bridge.d.ts +7 -0
- package/dist/tracing/bridge.js +171 -0
- package/dist/tracing/index.d.ts +9 -0
- package/dist/tracing/index.js +5 -0
- package/dist/tracing/otel.d.ts +38 -0
- package/dist/tracing/otel.js +221 -0
- package/dist/tracing/processor.d.ts +47 -0
- package/dist/tracing/processor.js +94 -0
- package/dist/tracing/spans.d.ts +94 -0
- package/dist/tracing/spans.js +56 -0
- package/dist/ui/ai-sdk.d.ts +114 -0
- package/dist/ui/ai-sdk.js +175 -0
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { Message, TextContent, ThinkingContent, Usage } from "../protocol/index.ts";
|
|
2
|
+
import type { PromptOrigin } from "../store/origin.ts";
|
|
3
|
+
import { type AgentRecord, type SessionStore } from "../store/store.ts";
|
|
4
|
+
import type { ToolInputRequest, ToolUpdate } from "../tool/types.ts";
|
|
5
|
+
import type { PendingRunInterrupt } from "../loop/interruption.ts";
|
|
6
|
+
import type { AgentEvent, EventSink, WorkflowAgentRecord } from "./events.ts";
|
|
7
|
+
/**
|
|
8
|
+
* SessionProjection — the session's event stream folded into per-address STATE, so a
|
|
9
|
+
* late-joining consumer (a UI opening a running agent, an SSE reconnect) gets an exact
|
|
10
|
+
* seam between history and live events.
|
|
11
|
+
*
|
|
12
|
+
* The whole design rests on the runtime being single-threaded:
|
|
13
|
+
* - `apply` mutates state and notifies subscribers in ONE synchronous block;
|
|
14
|
+
* - a consumer calls `observe()` to establish the snapshot/live boundary atomically.
|
|
15
|
+
* Any event is therefore either already folded into the snapshot or delivered to the
|
|
16
|
+
* subscriber — never both, never neither. `eventId` serves list/stream history overlap and
|
|
17
|
+
* diagnostics; this in-process snapshot boundary itself still needs no dedup.
|
|
18
|
+
* (Contrast with aligning an async `readRecords` against a live subscription, which
|
|
19
|
+
* inherently loses or duplicates the overlap.)
|
|
20
|
+
*
|
|
21
|
+
* Lifecycle contract: attach BEFORE the session's first run (events only flow during
|
|
22
|
+
* runs, so seeding from the store cannot race the subscription). The projection is the
|
|
23
|
+
* standard consumer for state-shaped needs; consumers that want events-as-events
|
|
24
|
+
* (tracing, telemetry, tests) keep subscribing to `session.events` directly.
|
|
25
|
+
*
|
|
26
|
+
* Memory discipline: messages are stored by REFERENCE — `message.appended` carries the
|
|
27
|
+
* same readonly `Message` object held by the live conversation context, so the
|
|
28
|
+
* projection adds pointers, not copies. Never deep-copy here.
|
|
29
|
+
*/
|
|
30
|
+
/** A tool call that has started and not yet produced its result. */
|
|
31
|
+
export interface ProjectedToolCall {
|
|
32
|
+
readonly toolCallId: string;
|
|
33
|
+
readonly toolName: string;
|
|
34
|
+
readonly args: unknown;
|
|
35
|
+
/** Latest `tool.progress` update, if any. */
|
|
36
|
+
readonly progress?: ToolUpdate;
|
|
37
|
+
/** The call entered its detachable window (UI may offer "move to background"). */
|
|
38
|
+
readonly detachable: boolean;
|
|
39
|
+
/** The call suspended awaiting caller input (`tool.suspended`); null when the
|
|
40
|
+
* suspension carried no input request. */
|
|
41
|
+
readonly suspended?: ToolInputRequest | null;
|
|
42
|
+
}
|
|
43
|
+
/** In-flight state of the turn currently running at an address. Everything here is
|
|
44
|
+
* bounded by one step's output and is absorbed into a message when it completes. */
|
|
45
|
+
export interface ProjectedTurn {
|
|
46
|
+
readonly turnId: string;
|
|
47
|
+
readonly origin?: PromptOrigin;
|
|
48
|
+
readonly step: number;
|
|
49
|
+
readonly stepId?: string;
|
|
50
|
+
/** Completed parts of the current step (absorbed by the step's assistant message). */
|
|
51
|
+
readonly parts: readonly (TextContent | ThinkingContent)[];
|
|
52
|
+
/** Streaming text accumulated since the last completed text part. */
|
|
53
|
+
readonly textTail: string;
|
|
54
|
+
/** Streaming thinking accumulated since the last completed thinking part. */
|
|
55
|
+
readonly thinkingTail: string;
|
|
56
|
+
readonly toolCalls: readonly ProjectedToolCall[];
|
|
57
|
+
/** Pending approvals / input requests when the run is paused (`turn.paused`). */
|
|
58
|
+
readonly paused?: readonly PendingRunInterrupt[];
|
|
59
|
+
}
|
|
60
|
+
/** A steer-bus message that has been queued but not yet consumed by the model. */
|
|
61
|
+
export interface ProjectedPendingSteer {
|
|
62
|
+
readonly steerId: string;
|
|
63
|
+
readonly channel: "steering" | "follow_up";
|
|
64
|
+
readonly origin: PromptOrigin;
|
|
65
|
+
readonly message: Message;
|
|
66
|
+
}
|
|
67
|
+
/** Full projected state of one address (one agent line). */
|
|
68
|
+
export interface AgentSnapshot {
|
|
69
|
+
readonly address: string;
|
|
70
|
+
/** Agent name from `agent.started`; undefined for a seeded-but-never-run shard. */
|
|
71
|
+
readonly agent?: string;
|
|
72
|
+
/** Tool call that spawned this agent (subagents); absent for the root. */
|
|
73
|
+
readonly parentToolCallId?: string;
|
|
74
|
+
/** Between `agent.started` and `agent.ended`. */
|
|
75
|
+
readonly live: boolean;
|
|
76
|
+
readonly messages: readonly Message[];
|
|
77
|
+
/**
|
|
78
|
+
* Provenance, parallel to `messages` (`origins[i]` describes `messages[i]`, `undefined`
|
|
79
|
+
* when unknown). This is how a UI tells apart a message the user sent, one a background
|
|
80
|
+
* task's settle injected, one a peer delivered, and the summary compaction left behind —
|
|
81
|
+
* a distinction that matters most for turns nobody asked for.
|
|
82
|
+
*/
|
|
83
|
+
readonly origins: readonly (PromptOrigin | undefined)[];
|
|
84
|
+
/** Total messages held (== messages.length unless the snapshot was tail-limited). */
|
|
85
|
+
readonly messageCount: number;
|
|
86
|
+
readonly turn?: ProjectedTurn;
|
|
87
|
+
readonly pendingSteers: readonly ProjectedPendingSteer[];
|
|
88
|
+
/** Run-total usage from the latest `usage.updated`. */
|
|
89
|
+
readonly usage?: Usage;
|
|
90
|
+
/** Wall-clock of the last event: durable record time on replay, apply time for live-only events. */
|
|
91
|
+
readonly lastEventAt?: number;
|
|
92
|
+
}
|
|
93
|
+
/** Lightweight per-address summary for "what agents exist and who is doing something". */
|
|
94
|
+
export interface DirectoryEntry {
|
|
95
|
+
readonly address: string;
|
|
96
|
+
readonly agent?: string;
|
|
97
|
+
readonly live: boolean;
|
|
98
|
+
readonly running: boolean;
|
|
99
|
+
readonly lastMessage?: Message;
|
|
100
|
+
readonly lastEventAt?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A workflow run's progress, folded from its steps.
|
|
104
|
+
*
|
|
105
|
+
* Separate from `agents` because a run is not a conversation: it has phases and a roster of
|
|
106
|
+
* agents rather than messages and a turn. The agents it spawns DO appear in `agents` under
|
|
107
|
+
* their own addresses — this is the orchestration layer above them.
|
|
108
|
+
*/
|
|
109
|
+
export interface WorkflowRunSnapshot {
|
|
110
|
+
readonly runId: string;
|
|
111
|
+
/** The Workflow tool call the run came from, if it had one. */
|
|
112
|
+
readonly toolCallId?: string;
|
|
113
|
+
/** False once the run settled; a run whose steps stopped arriving is still live until then. */
|
|
114
|
+
readonly live: boolean;
|
|
115
|
+
readonly phases: readonly {
|
|
116
|
+
readonly index: number;
|
|
117
|
+
readonly title: string;
|
|
118
|
+
readonly kind: "normal" | "child";
|
|
119
|
+
}[];
|
|
120
|
+
/** Latest state per agent index — running ones included, so this IS the live roster. */
|
|
121
|
+
readonly agents: readonly WorkflowAgentRecord[];
|
|
122
|
+
/** The script's own `log()` narration, in order. */
|
|
123
|
+
readonly logs: readonly string[];
|
|
124
|
+
readonly lastEventAt?: number;
|
|
125
|
+
}
|
|
126
|
+
export interface SessionSnapshot {
|
|
127
|
+
readonly sessionId: string;
|
|
128
|
+
/** Last event folded into this state. Useful only with a transport that preserves the same
|
|
129
|
+
* ordered event channel (the App Server does); managed HTTP deliberately does not expose
|
|
130
|
+
* this snapshot contract. */
|
|
131
|
+
readonly lastEventId?: string;
|
|
132
|
+
readonly directory: readonly DirectoryEntry[];
|
|
133
|
+
readonly agents: readonly AgentSnapshot[];
|
|
134
|
+
/** Workflow runs seen this session, newest activity last. */
|
|
135
|
+
readonly workflows: readonly WorkflowRunSnapshot[];
|
|
136
|
+
}
|
|
137
|
+
export interface SnapshotOptions {
|
|
138
|
+
/** Only include these addresses in `agents` (exact match). Default: all. The
|
|
139
|
+
* `directory` always covers every known address. */
|
|
140
|
+
readonly addresses?: readonly string[];
|
|
141
|
+
/** Cap `messages` to the last N (older pages come from the immutable log prefix,
|
|
142
|
+
* which is race-free by construction). Default: 200. */
|
|
143
|
+
readonly maxMessages?: number;
|
|
144
|
+
}
|
|
145
|
+
export type ProjectionListener = (event: AgentEvent) => void;
|
|
146
|
+
/** Atomically established state/live observation. `snapshot` contains every event folded
|
|
147
|
+
* before observation began; `listener` receives every event folded afterwards. */
|
|
148
|
+
export interface ProjectionObservation {
|
|
149
|
+
readonly snapshot: SessionSnapshot;
|
|
150
|
+
readonly unsubscribe: () => void;
|
|
151
|
+
}
|
|
152
|
+
/** Structural slice of `Session` the projection needs — kept structural so this file
|
|
153
|
+
* never imports the Session class (no cycle, and pure uses stay possible). */
|
|
154
|
+
export interface ProjectionSource {
|
|
155
|
+
readonly id: string;
|
|
156
|
+
readonly store?: SessionStore;
|
|
157
|
+
readonly events: EventSink;
|
|
158
|
+
}
|
|
159
|
+
export declare class SessionProjection {
|
|
160
|
+
readonly sessionId: string;
|
|
161
|
+
private readonly agents;
|
|
162
|
+
private readonly workflows;
|
|
163
|
+
private readonly listeners;
|
|
164
|
+
private detachFn?;
|
|
165
|
+
private lastEventId?;
|
|
166
|
+
constructor(sessionId: string);
|
|
167
|
+
/**
|
|
168
|
+
* Seed from the append log, then subscribe to the live event stream.
|
|
169
|
+
* MUST be called before the session's first run (see the class doc's lifecycle
|
|
170
|
+
* contract) — the seam guarantee comes from that ordering, not from alignment.
|
|
171
|
+
*
|
|
172
|
+
* Pass `preloadedLog` (the complete log, as `readRecords()` returns it) when the caller
|
|
173
|
+
* already read it — typically to share ONE open-time read with `Session.open`'s
|
|
174
|
+
* `preloadedLog`, which also makes the seeded prefix share `Message` objects with the
|
|
175
|
+
* session's live context instead of holding a second parsed copy.
|
|
176
|
+
*/
|
|
177
|
+
static attach(source: ProjectionSource, preloadedLog?: readonly AgentRecord[]): Promise<SessionProjection>;
|
|
178
|
+
/** Stop receiving live events (the projection keeps its last state). */
|
|
179
|
+
detach(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Fold one event into the projection, then notify subscribers — one synchronous
|
|
182
|
+
* block, which is what makes `snapshot()` + `subscribe()` an exact seam.
|
|
183
|
+
* `time` is supplied by durable replay so reopening preserves the record's wall clock;
|
|
184
|
+
* live callers omit it and use the apply time.
|
|
185
|
+
*/
|
|
186
|
+
apply(event: AgentEvent, time?: number): void;
|
|
187
|
+
/**
|
|
188
|
+
* Post-apply event feed. Listeners MUST be synchronous and non-blocking —
|
|
189
|
+
* backpressure belongs to the transport (drop the slow client), never here. Prefer
|
|
190
|
+
* `observe()` when the consumer also needs an initial snapshot.
|
|
191
|
+
*/
|
|
192
|
+
subscribe(listener: ProjectionListener): () => void;
|
|
193
|
+
/**
|
|
194
|
+
* Establish the exact snapshot/live seam as one operation, so callers cannot accidentally
|
|
195
|
+
* split `subscribe()` and `snapshot()` with asynchronous work. The subscription is installed
|
|
196
|
+
* first; because `apply()` folds and notifies synchronously, every event is represented by
|
|
197
|
+
* exactly one side of the returned boundary.
|
|
198
|
+
*/
|
|
199
|
+
observe(listener: ProjectionListener, options?: SnapshotOptions): ProjectionObservation;
|
|
200
|
+
directory(): DirectoryEntry[];
|
|
201
|
+
snapshot(options?: SnapshotOptions): SessionSnapshot;
|
|
202
|
+
private workflowFor;
|
|
203
|
+
private stateFor;
|
|
204
|
+
private foldWorkflow;
|
|
205
|
+
private fold;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { foldAppend, foldCompaction, foldReplace, } from "../store/store.js";
|
|
2
|
+
import { agentEventFromRecord } from "./publisher.js";
|
|
3
|
+
const DEFAULT_SNAPSHOT_MAX_MESSAGES = 200;
|
|
4
|
+
export class SessionProjection {
|
|
5
|
+
sessionId;
|
|
6
|
+
agents = new Map();
|
|
7
|
+
workflows = new Map();
|
|
8
|
+
listeners = new Set();
|
|
9
|
+
detachFn;
|
|
10
|
+
lastEventId;
|
|
11
|
+
constructor(sessionId) {
|
|
12
|
+
this.sessionId = sessionId;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Seed from the append log, then subscribe to the live event stream.
|
|
16
|
+
* MUST be called before the session's first run (see the class doc's lifecycle
|
|
17
|
+
* contract) — the seam guarantee comes from that ordering, not from alignment.
|
|
18
|
+
*
|
|
19
|
+
* Pass `preloadedLog` (the complete log, as `readRecords()` returns it) when the caller
|
|
20
|
+
* already read it — typically to share ONE open-time read with `Session.open`'s
|
|
21
|
+
* `preloadedLog`, which also makes the seeded prefix share `Message` objects with the
|
|
22
|
+
* session's live context instead of holding a second parsed copy.
|
|
23
|
+
*/
|
|
24
|
+
static async attach(source, preloadedLog) {
|
|
25
|
+
const projection = new SessionProjection(source.id);
|
|
26
|
+
const records = preloadedLog ?? (source.store !== undefined ? await collectRecords(source.store) : []);
|
|
27
|
+
for (const record of records) {
|
|
28
|
+
const event = agentEventFromRecord(record, source.id);
|
|
29
|
+
if (event !== undefined)
|
|
30
|
+
projection.apply(event, record.time);
|
|
31
|
+
}
|
|
32
|
+
projection.detachFn = source.events.subscribe((event) => {
|
|
33
|
+
projection.apply(event);
|
|
34
|
+
});
|
|
35
|
+
return projection;
|
|
36
|
+
}
|
|
37
|
+
/** Stop receiving live events (the projection keeps its last state). */
|
|
38
|
+
detach() {
|
|
39
|
+
this.detachFn?.();
|
|
40
|
+
this.detachFn = undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Fold one event into the projection, then notify subscribers — one synchronous
|
|
44
|
+
* block, which is what makes `snapshot()` + `subscribe()` an exact seam.
|
|
45
|
+
* `time` is supplied by durable replay so reopening preserves the record's wall clock;
|
|
46
|
+
* live callers omit it and use the apply time.
|
|
47
|
+
*/
|
|
48
|
+
apply(event, time = Date.now()) {
|
|
49
|
+
if (event.type === "workflow.progress") {
|
|
50
|
+
const run = this.workflowFor(event.runId);
|
|
51
|
+
if (event.toolCallId !== undefined)
|
|
52
|
+
run.toolCallId = event.toolCallId;
|
|
53
|
+
this.foldWorkflow(run, event.progress, time);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const state = this.stateFor(event.address);
|
|
57
|
+
state.lastEventAt = time;
|
|
58
|
+
this.fold(state, event);
|
|
59
|
+
}
|
|
60
|
+
this.lastEventId = event.eventId;
|
|
61
|
+
if (this.listeners.size > 0) {
|
|
62
|
+
// Copy so a listener subscribing/unsubscribing mid-notify can't skew delivery.
|
|
63
|
+
for (const listener of [...this.listeners])
|
|
64
|
+
listener(event);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Post-apply event feed. Listeners MUST be synchronous and non-blocking —
|
|
69
|
+
* backpressure belongs to the transport (drop the slow client), never here. Prefer
|
|
70
|
+
* `observe()` when the consumer also needs an initial snapshot.
|
|
71
|
+
*/
|
|
72
|
+
subscribe(listener) {
|
|
73
|
+
this.listeners.add(listener);
|
|
74
|
+
return () => this.listeners.delete(listener);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Establish the exact snapshot/live seam as one operation, so callers cannot accidentally
|
|
78
|
+
* split `subscribe()` and `snapshot()` with asynchronous work. The subscription is installed
|
|
79
|
+
* first; because `apply()` folds and notifies synchronously, every event is represented by
|
|
80
|
+
* exactly one side of the returned boundary.
|
|
81
|
+
*/
|
|
82
|
+
observe(listener, options) {
|
|
83
|
+
const unsubscribe = this.subscribe(listener);
|
|
84
|
+
try {
|
|
85
|
+
return { snapshot: this.snapshot(options), unsubscribe };
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
unsubscribe();
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
directory() {
|
|
93
|
+
return [...this.agents.values()].map((state) => ({
|
|
94
|
+
address: state.address,
|
|
95
|
+
...(state.agent !== undefined ? { agent: state.agent } : {}),
|
|
96
|
+
live: state.live,
|
|
97
|
+
running: state.turn !== undefined,
|
|
98
|
+
...(state.messages.length > 0 ? { lastMessage: state.messages[state.messages.length - 1] } : {}),
|
|
99
|
+
...(state.lastEventAt !== undefined ? { lastEventAt: state.lastEventAt } : {}),
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
snapshot(options = {}) {
|
|
103
|
+
const wanted = options.addresses === undefined ? undefined : new Set(options.addresses);
|
|
104
|
+
const agents = [];
|
|
105
|
+
for (const state of this.agents.values()) {
|
|
106
|
+
if (wanted !== undefined && !wanted.has(state.address))
|
|
107
|
+
continue;
|
|
108
|
+
agents.push(snapshotAgent(state, options.maxMessages ?? DEFAULT_SNAPSHOT_MAX_MESSAGES));
|
|
109
|
+
}
|
|
110
|
+
const workflows = [];
|
|
111
|
+
for (const run of this.workflows.values()) {
|
|
112
|
+
workflows.push({
|
|
113
|
+
runId: run.runId,
|
|
114
|
+
...(run.toolCallId !== undefined ? { toolCallId: run.toolCallId } : {}),
|
|
115
|
+
live: run.live,
|
|
116
|
+
phases: [...run.phases],
|
|
117
|
+
agents: [...run.agents.values()],
|
|
118
|
+
logs: [...run.logs],
|
|
119
|
+
...(run.lastEventAt !== undefined ? { lastEventAt: run.lastEventAt } : {}),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
sessionId: this.sessionId,
|
|
124
|
+
...(this.lastEventId !== undefined ? { lastEventId: this.lastEventId } : {}),
|
|
125
|
+
directory: this.directory(),
|
|
126
|
+
agents,
|
|
127
|
+
workflows,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
workflowFor(runId) {
|
|
131
|
+
const existing = this.workflows.get(runId);
|
|
132
|
+
if (existing !== undefined)
|
|
133
|
+
return existing;
|
|
134
|
+
const created = { runId, live: true, phases: [], agents: new Map(), logs: [] };
|
|
135
|
+
this.workflows.set(runId, created);
|
|
136
|
+
return created;
|
|
137
|
+
}
|
|
138
|
+
stateFor(address) {
|
|
139
|
+
const existing = this.agents.get(address);
|
|
140
|
+
if (existing !== undefined)
|
|
141
|
+
return existing;
|
|
142
|
+
const created = { address, live: false, messages: [], origins: [], pendingSteers: [] };
|
|
143
|
+
this.agents.set(address, created);
|
|
144
|
+
return created;
|
|
145
|
+
}
|
|
146
|
+
foldWorkflow(run, step, time) {
|
|
147
|
+
if (time !== undefined)
|
|
148
|
+
run.lastEventAt = time;
|
|
149
|
+
if (step.type === "started") {
|
|
150
|
+
// workflowFor() already established the run; name is currently presentation-only.
|
|
151
|
+
}
|
|
152
|
+
else if (step.type === "phase") {
|
|
153
|
+
if (!run.phases.some((phase) => phase.index === step.index)) {
|
|
154
|
+
run.phases.push({ index: step.index, title: step.title, kind: step.kind });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (step.type === "agent") {
|
|
158
|
+
run.agents.set(step.record.index, step.record);
|
|
159
|
+
}
|
|
160
|
+
else if (step.type === "log") {
|
|
161
|
+
run.logs.push(step.message);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
run.live = false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// ── the fold ──
|
|
168
|
+
// Every in-flight item has a birth event and a death event, so the state is
|
|
169
|
+
// self-cleaning: memory is bounded by one step's output plus the message list
|
|
170
|
+
// (which holds references, not copies). The switch is exhaustive over
|
|
171
|
+
// AgentEventBody so adding an event type fails compilation here, same
|
|
172
|
+
// discipline as reduceHistory.
|
|
173
|
+
fold(state, event) {
|
|
174
|
+
switch (event.type) {
|
|
175
|
+
case "agent.started":
|
|
176
|
+
state.live = true;
|
|
177
|
+
state.agent = event.agent;
|
|
178
|
+
if (event.parentToolCallId !== undefined)
|
|
179
|
+
state.parentToolCallId = event.parentToolCallId;
|
|
180
|
+
break;
|
|
181
|
+
case "agent.ended":
|
|
182
|
+
state.live = false;
|
|
183
|
+
state.turn = undefined;
|
|
184
|
+
break;
|
|
185
|
+
case "turn.started":
|
|
186
|
+
state.turn = {
|
|
187
|
+
turnId: event.turnId,
|
|
188
|
+
...(event.origin !== undefined ? { origin: event.origin } : {}),
|
|
189
|
+
step: 0,
|
|
190
|
+
parts: [],
|
|
191
|
+
textTail: "",
|
|
192
|
+
thinkingTail: "",
|
|
193
|
+
toolCalls: new Map(),
|
|
194
|
+
};
|
|
195
|
+
break;
|
|
196
|
+
case "turn.ended":
|
|
197
|
+
state.turn = undefined;
|
|
198
|
+
break;
|
|
199
|
+
case "turn.step.started": {
|
|
200
|
+
const turn = state.turn;
|
|
201
|
+
if (turn === undefined)
|
|
202
|
+
break;
|
|
203
|
+
turn.step = event.step;
|
|
204
|
+
turn.stepId = event.stepId;
|
|
205
|
+
// A new step implies the previous step's calls all settled (the loop contract);
|
|
206
|
+
// clearing here is defensive against a missed tool.result.
|
|
207
|
+
turn.parts = [];
|
|
208
|
+
turn.textTail = "";
|
|
209
|
+
turn.thinkingTail = "";
|
|
210
|
+
turn.toolCalls.clear();
|
|
211
|
+
turn.paused = undefined;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case "turn.step.completed":
|
|
215
|
+
// Parts stay until the step's assistant message is appended (message.appended
|
|
216
|
+
// clears them) — the durable form supersedes the in-flight one, not the
|
|
217
|
+
// step boundary.
|
|
218
|
+
break;
|
|
219
|
+
case "turn.step.retrying":
|
|
220
|
+
break;
|
|
221
|
+
case "turn.step.reset": {
|
|
222
|
+
const turn = state.turn;
|
|
223
|
+
if (turn === undefined)
|
|
224
|
+
break;
|
|
225
|
+
turn.parts = [];
|
|
226
|
+
turn.textTail = "";
|
|
227
|
+
turn.thinkingTail = "";
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case "turn.step.interrupted": {
|
|
231
|
+
const turn = state.turn;
|
|
232
|
+
if (turn === undefined)
|
|
233
|
+
break;
|
|
234
|
+
turn.textTail = "";
|
|
235
|
+
turn.thinkingTail = "";
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case "content.part": {
|
|
239
|
+
const turn = state.turn;
|
|
240
|
+
if (turn === undefined)
|
|
241
|
+
break;
|
|
242
|
+
turn.parts.push(event.part);
|
|
243
|
+
if (event.part.type === "text")
|
|
244
|
+
turn.textTail = "";
|
|
245
|
+
else
|
|
246
|
+
turn.thinkingTail = "";
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "assistant.delta": {
|
|
250
|
+
const turn = state.turn;
|
|
251
|
+
if (turn !== undefined)
|
|
252
|
+
turn.textTail += event.delta;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case "thinking.delta": {
|
|
256
|
+
const turn = state.turn;
|
|
257
|
+
if (turn !== undefined)
|
|
258
|
+
turn.thinkingTail += event.delta;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "message.appended": {
|
|
262
|
+
foldAppend(state, event.message, event.origin);
|
|
263
|
+
const turn = state.turn;
|
|
264
|
+
if (turn !== undefined && event.message.role === "assistant") {
|
|
265
|
+
// The step's parts are now durable inside this message.
|
|
266
|
+
turn.parts = [];
|
|
267
|
+
turn.textTail = "";
|
|
268
|
+
turn.thinkingTail = "";
|
|
269
|
+
for (const part of event.message.content) {
|
|
270
|
+
if (part.type !== "toolCall")
|
|
271
|
+
continue;
|
|
272
|
+
turn.toolCalls.set(part.id, {
|
|
273
|
+
toolCallId: part.id,
|
|
274
|
+
toolName: part.name,
|
|
275
|
+
args: part.arguments,
|
|
276
|
+
detachable: false,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (turn !== undefined && event.message.role === "toolResult") {
|
|
281
|
+
const toolCallId = event.message.toolCallId;
|
|
282
|
+
turn.toolCalls.delete(toolCallId);
|
|
283
|
+
if (turn.paused !== undefined) {
|
|
284
|
+
const remaining = turn.paused.filter((pending) => pending.toolCallId !== toolCallId);
|
|
285
|
+
turn.paused = remaining.length > 0 ? remaining : undefined;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const origin = event.origin;
|
|
289
|
+
const steerId = origin !== undefined && "steerId" in origin ? origin.steerId : undefined;
|
|
290
|
+
if (steerId !== undefined && state.pendingSteers.length > 0) {
|
|
291
|
+
state.pendingSteers = state.pendingSteers.filter((pending) => pending.steerId !== steerId);
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
// History is not append-only. Both of these run the SAME operation replay runs, so a
|
|
296
|
+
// transcript watched live and the same transcript after a reopen cannot diverge —
|
|
297
|
+
// which they silently did while these mutations were journaled but never broadcast.
|
|
298
|
+
case "history.replaced":
|
|
299
|
+
foldReplace(state, event.messages, event.origins);
|
|
300
|
+
break;
|
|
301
|
+
case "history.compacted":
|
|
302
|
+
foldCompaction(state, event.cutoff, event.summary, event.summaryTimestamp);
|
|
303
|
+
break;
|
|
304
|
+
case "steer.queued":
|
|
305
|
+
state.pendingSteers.push({
|
|
306
|
+
steerId: event.steerId,
|
|
307
|
+
channel: event.channel,
|
|
308
|
+
origin: event.origin,
|
|
309
|
+
message: event.message,
|
|
310
|
+
});
|
|
311
|
+
break;
|
|
312
|
+
case "delivery.accepted":
|
|
313
|
+
break;
|
|
314
|
+
case "tool.call.started": {
|
|
315
|
+
const turn = state.turn;
|
|
316
|
+
if (turn === undefined)
|
|
317
|
+
break;
|
|
318
|
+
turn.toolCalls.set(event.toolCallId, {
|
|
319
|
+
toolCallId: event.toolCallId,
|
|
320
|
+
toolName: event.toolName,
|
|
321
|
+
args: event.args,
|
|
322
|
+
detachable: false,
|
|
323
|
+
});
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case "tool.call.delta":
|
|
327
|
+
// Pre-execution argument streaming; the complete args arrive on
|
|
328
|
+
// tool.call.started. Not folded (mirrors VOLATILE_EVENT_TYPES intent).
|
|
329
|
+
break;
|
|
330
|
+
case "tool.progress": {
|
|
331
|
+
const call = state.turn?.toolCalls.get(event.toolCallId);
|
|
332
|
+
if (call !== undefined)
|
|
333
|
+
call.progress = event.update;
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
case "tool.detachable": {
|
|
337
|
+
const call = state.turn?.toolCalls.get(event.toolCallId);
|
|
338
|
+
if (call !== undefined)
|
|
339
|
+
call.detachable = true;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case "tool.suspended": {
|
|
343
|
+
const call = state.turn?.toolCalls.get(event.toolCallId);
|
|
344
|
+
if (call !== undefined)
|
|
345
|
+
call.suspended = event.request ?? null;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
case "tool.result": {
|
|
349
|
+
const turn = state.turn;
|
|
350
|
+
if (turn === undefined)
|
|
351
|
+
break;
|
|
352
|
+
turn.toolCalls.delete(event.toolCallId);
|
|
353
|
+
if (turn.paused !== undefined) {
|
|
354
|
+
const remaining = turn.paused.filter((pending) => pending.toolCallId !== event.toolCallId);
|
|
355
|
+
turn.paused = remaining.length > 0 ? remaining : undefined;
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
case "turn.paused": {
|
|
360
|
+
const turn = state.turn;
|
|
361
|
+
if (turn !== undefined)
|
|
362
|
+
turn.paused = event.pending;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
// Directory-level or audit-only signals: they bump lastEventAt (done in apply)
|
|
366
|
+
// but carry no per-agent state the projection tracks.
|
|
367
|
+
case "goal.updated":
|
|
368
|
+
case "plan.updated":
|
|
369
|
+
case "skill.activated":
|
|
370
|
+
case "background.task.started":
|
|
371
|
+
case "background.task.terminated":
|
|
372
|
+
case "extension":
|
|
373
|
+
case "agent.handoff":
|
|
374
|
+
case "compaction.started":
|
|
375
|
+
// compaction.completed is a process signal; history.compacted already performed the
|
|
376
|
+
// transcript fold from the same journal mutation.
|
|
377
|
+
case "compaction.completed":
|
|
378
|
+
case "guardrail.blocked":
|
|
379
|
+
case "error":
|
|
380
|
+
case "warning":
|
|
381
|
+
break;
|
|
382
|
+
case "usage.updated":
|
|
383
|
+
state.usage = event.usage;
|
|
384
|
+
break;
|
|
385
|
+
case "workflow.progress": {
|
|
386
|
+
// Routed before this per-agent fold in apply(). Keeping the case makes the
|
|
387
|
+
// AgentEventBody switch exhaustive without creating a workflow:* AgentState.
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
default: {
|
|
391
|
+
const exhaustive = event;
|
|
392
|
+
throw new Error(`SessionProjection: unhandled event type ${String(exhaustive.type)}`);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
async function collectRecords(store) {
|
|
398
|
+
const records = [];
|
|
399
|
+
for await (const record of store.readRecords())
|
|
400
|
+
records.push(record);
|
|
401
|
+
return records;
|
|
402
|
+
}
|
|
403
|
+
function snapshotAgent(state, maxMessages) {
|
|
404
|
+
// One slice point for both arrays: `origins[i]` describes `messages[i]`, and a tail limit
|
|
405
|
+
// that trimmed only one of them would silently misattribute every remaining message.
|
|
406
|
+
const from = maxMessages !== undefined && state.messages.length > maxMessages ? state.messages.length - maxMessages : 0;
|
|
407
|
+
const messages = state.messages.slice(from);
|
|
408
|
+
const origins = state.origins.slice(from, from + messages.length);
|
|
409
|
+
while (origins.length < messages.length)
|
|
410
|
+
origins.push(undefined);
|
|
411
|
+
return {
|
|
412
|
+
address: state.address,
|
|
413
|
+
...(state.agent !== undefined ? { agent: state.agent } : {}),
|
|
414
|
+
...(state.parentToolCallId !== undefined ? { parentToolCallId: state.parentToolCallId } : {}),
|
|
415
|
+
live: state.live,
|
|
416
|
+
messages,
|
|
417
|
+
origins,
|
|
418
|
+
messageCount: state.messages.length,
|
|
419
|
+
...(state.turn !== undefined ? { turn: snapshotTurn(state.turn) } : {}),
|
|
420
|
+
pendingSteers: [...state.pendingSteers],
|
|
421
|
+
...(state.usage !== undefined ? { usage: state.usage } : {}),
|
|
422
|
+
...(state.lastEventAt !== undefined ? { lastEventAt: state.lastEventAt } : {}),
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function snapshotTurn(turn) {
|
|
426
|
+
return {
|
|
427
|
+
turnId: turn.turnId,
|
|
428
|
+
...(turn.origin !== undefined ? { origin: turn.origin } : {}),
|
|
429
|
+
step: turn.step,
|
|
430
|
+
...(turn.stepId !== undefined ? { stepId: turn.stepId } : {}),
|
|
431
|
+
parts: [...turn.parts],
|
|
432
|
+
textTail: turn.textTail,
|
|
433
|
+
thinkingTail: turn.thinkingTail,
|
|
434
|
+
toolCalls: [...turn.toolCalls.values()].map((call) => ({ ...call })),
|
|
435
|
+
...(turn.paused !== undefined ? { paused: turn.paused } : {}),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
//# sourceMappingURL=projection.js.map
|