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,264 @@
|
|
|
1
|
+
import { load as loadYaml } from "js-yaml";
|
|
2
|
+
import nunjucks from "nunjucks";
|
|
3
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join } from "pathe";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { Agent, defineAgent } from "./agent.js";
|
|
8
|
+
import { formatSystemPromptDate } from "./instruction-context.js";
|
|
9
|
+
export { prepareSystemPromptContext } from "./instruction-context.js";
|
|
10
|
+
// Prompts aren't HTML, so don't escape; a missing template var is a loud error, never a silent
|
|
11
|
+
// `{{ placeholder }}` leaked to the model.
|
|
12
|
+
const njk = new nunjucks.Environment(null, { autoescape: false, throwOnUndefined: true });
|
|
13
|
+
// ── profile schema (YAML on disk; `extends` inheritance) ─────────────────────────────────────
|
|
14
|
+
const SubagentRefSchema = z.object({ description: z.string().optional() });
|
|
15
|
+
/** A raw agent profile as authored in YAML (before `extends` is merged). */
|
|
16
|
+
export const RawAgentProfileSchema = z.object({
|
|
17
|
+
extends: z.string().optional(),
|
|
18
|
+
name: z.string().min(1),
|
|
19
|
+
description: z.string().optional(),
|
|
20
|
+
/** Path to a system-prompt template file, relative to the profile (resolved by the loader). */
|
|
21
|
+
systemPromptPath: z.string().optional(),
|
|
22
|
+
/** The system-prompt template inline (set by the loader from `systemPromptPath`, or directly). */
|
|
23
|
+
systemPromptTemplate: z.string().optional(),
|
|
24
|
+
promptVars: z.record(z.string(), z.string()).optional(),
|
|
25
|
+
/** Exact tool names; entries containing `*` are MCP access globs (informational here — AF adds
|
|
26
|
+
* MCP tools via the MCP capability, and does not gate the active set). */
|
|
27
|
+
tools: z.array(z.string()).optional(),
|
|
28
|
+
/** Optional model ref the host resolves; absent → inherit the session model. */
|
|
29
|
+
model: z.string().optional(),
|
|
30
|
+
whenToUse: z.string().optional(),
|
|
31
|
+
subagents: z.record(z.string(), SubagentRefSchema).optional(),
|
|
32
|
+
});
|
|
33
|
+
function buildTemplateVars(context, promptVars) {
|
|
34
|
+
const now = context.now instanceof Date ? formatSystemPromptDate(context.now) : (context.now ?? "");
|
|
35
|
+
return {
|
|
36
|
+
...promptVars,
|
|
37
|
+
os: context.osKind,
|
|
38
|
+
osArch: context.osArch ?? "",
|
|
39
|
+
osVersion: context.osVersion ?? "",
|
|
40
|
+
shell: context.shell,
|
|
41
|
+
now,
|
|
42
|
+
workDir: context.cwd,
|
|
43
|
+
agentsMd: context.agentsMd ?? "",
|
|
44
|
+
roleAdditional: context.roleAdditional ?? promptVars["roleAdditional"] ?? "",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Resolve raw profiles with `extends` inheritance into renderers + a linked subagent graph. */
|
|
48
|
+
export function resolveAgentProfiles(raw) {
|
|
49
|
+
const byName = new Map();
|
|
50
|
+
for (const profile of raw) {
|
|
51
|
+
if (byName.has(profile.name))
|
|
52
|
+
throw new Error(`duplicate agent profile name: "${profile.name}"`);
|
|
53
|
+
byName.set(profile.name, profile);
|
|
54
|
+
}
|
|
55
|
+
const mergedCache = new Map();
|
|
56
|
+
const resolved = new Map();
|
|
57
|
+
for (const profile of raw) {
|
|
58
|
+
const merged = mergeProfile(profile.name, byName, mergedCache, []);
|
|
59
|
+
resolved.set(profile.name, {
|
|
60
|
+
name: merged.name,
|
|
61
|
+
description: merged.description,
|
|
62
|
+
model: merged.model,
|
|
63
|
+
systemPrompt: (context) => {
|
|
64
|
+
try {
|
|
65
|
+
return njk.renderString(merged.systemPromptTemplate, buildTemplateVars(context, merged.promptVars));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new Error(`render system prompt for profile "${merged.name}" failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
tools: [...merged.tools],
|
|
72
|
+
whenToUse: merged.whenToUse,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
// Link declared subagents after all profiles exist. Pass 1 links every graph to the
|
|
76
|
+
// SHARED resolved targets, so each target's own `subagents` is fully linked before pass 2
|
|
77
|
+
// snapshots any per-edge view of it.
|
|
78
|
+
for (const profile of raw) {
|
|
79
|
+
const merged = mergedCache.get(profile.name);
|
|
80
|
+
if (merged.subagents === undefined)
|
|
81
|
+
continue;
|
|
82
|
+
const graph = {};
|
|
83
|
+
for (const subName of Object.keys(merged.subagents)) {
|
|
84
|
+
const target = resolved.get(subName);
|
|
85
|
+
if (target === undefined)
|
|
86
|
+
throw new Error(`profile "${profile.name}" declares subagent "${subName}" but it was not found`);
|
|
87
|
+
graph[subName] = target;
|
|
88
|
+
}
|
|
89
|
+
resolved.get(profile.name).subagents = graph;
|
|
90
|
+
}
|
|
91
|
+
// Pass 2: a ref's description belongs to THIS parent's edge, not to the shared target —
|
|
92
|
+
// two parents may describe the same subagent differently. Materialize it as a per-edge
|
|
93
|
+
// copy (winning over the target's own description on that edge) instead of mutating the
|
|
94
|
+
// shared profile, which made the outcome depend on profile processing order.
|
|
95
|
+
for (const profile of raw) {
|
|
96
|
+
const merged = mergedCache.get(profile.name);
|
|
97
|
+
if (merged.subagents === undefined)
|
|
98
|
+
continue;
|
|
99
|
+
const graph = resolved.get(profile.name).subagents;
|
|
100
|
+
for (const [subName, ref] of Object.entries(merged.subagents)) {
|
|
101
|
+
const target = graph[subName];
|
|
102
|
+
if (ref.description === undefined || ref.description === target.description)
|
|
103
|
+
continue;
|
|
104
|
+
graph[subName] = { ...target, description: ref.description };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return Object.fromEntries(resolved);
|
|
108
|
+
}
|
|
109
|
+
function mergeProfile(name, byName, cache, stack) {
|
|
110
|
+
const cached = cache.get(name);
|
|
111
|
+
if (cached !== undefined)
|
|
112
|
+
return cached;
|
|
113
|
+
if (stack.includes(name))
|
|
114
|
+
throw new Error(`agent profile extends cycle: ${[...stack.slice(stack.indexOf(name)), name].join(" -> ")}`);
|
|
115
|
+
const profile = byName.get(name);
|
|
116
|
+
if (profile === undefined)
|
|
117
|
+
throw new Error(`agent profile "${name}" not found`);
|
|
118
|
+
let parent;
|
|
119
|
+
if (profile.extends !== undefined) {
|
|
120
|
+
if (!byName.has(profile.extends))
|
|
121
|
+
throw new Error(`profile "${profile.name}" extends "${profile.extends}" but the parent was not found`);
|
|
122
|
+
parent = mergeProfile(profile.extends, byName, cache, [...stack, name]);
|
|
123
|
+
}
|
|
124
|
+
const merged = {
|
|
125
|
+
name: profile.name,
|
|
126
|
+
description: profile.description ?? parent?.description,
|
|
127
|
+
model: profile.model ?? parent?.model,
|
|
128
|
+
systemPromptTemplate: profile.systemPromptTemplate ?? parent?.systemPromptTemplate ?? "",
|
|
129
|
+
promptVars: { ...parent?.promptVars, ...profile.promptVars },
|
|
130
|
+
tools: profile.tools !== undefined ? [...profile.tools] : [...(parent?.tools ?? [])],
|
|
131
|
+
whenToUse: profile.whenToUse ?? parent?.whenToUse,
|
|
132
|
+
subagents: profile.subagents !== undefined ? { ...profile.subagents } : undefined,
|
|
133
|
+
};
|
|
134
|
+
cache.set(profile.name, merged);
|
|
135
|
+
return merged;
|
|
136
|
+
}
|
|
137
|
+
/** Turn a resolved profile into a runnable Agent whose system prompt renders from live context. */
|
|
138
|
+
export async function buildAgentFromProfile(profile, options = {}) {
|
|
139
|
+
const toolset = [];
|
|
140
|
+
for (const name of profile.tools) {
|
|
141
|
+
if (name.includes("*"))
|
|
142
|
+
continue; // MCP access glob — added by the MCP capability, not here
|
|
143
|
+
const tool = options.tools?.[name];
|
|
144
|
+
if (tool !== undefined)
|
|
145
|
+
toolset.push(tool);
|
|
146
|
+
// Unresolved names are capability tools joining at runtime — or typos. Not distinguishable
|
|
147
|
+
// here, so never throw; surface them through the optional diagnostic callback instead.
|
|
148
|
+
else if (options.tools !== undefined)
|
|
149
|
+
options.onUnknownTool?.(name);
|
|
150
|
+
}
|
|
151
|
+
const model = options.model ??
|
|
152
|
+
(profile.model !== undefined && options.resolveModel !== undefined ? await options.resolveModel(profile.model) : undefined);
|
|
153
|
+
const roleAdditional = options.roleAdditional;
|
|
154
|
+
return defineAgent({
|
|
155
|
+
name: profile.name,
|
|
156
|
+
instructions: async (runContext) => {
|
|
157
|
+
if (runContext.resolveSystemPromptContext === undefined) {
|
|
158
|
+
throw new Error(`profile agent "${profile.name}" requires a runtime Session to render its system prompt`);
|
|
159
|
+
}
|
|
160
|
+
const context = await runContext.resolveSystemPromptContext();
|
|
161
|
+
return profile.systemPrompt({
|
|
162
|
+
...context,
|
|
163
|
+
...(roleAdditional !== undefined ? { roleAdditional } : {}),
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
model,
|
|
167
|
+
tools: toolset,
|
|
168
|
+
...(options.maxStepsPerTurn !== undefined ? { maxStepsPerTurn: options.maxStepsPerTurn } : {}),
|
|
169
|
+
handoffDescription: profile.whenToUse ?? profile.description,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** Profile dirs, low → high precedence: user (`~/.<app>/agents`) < project (`<cwd>/.<app>/agents`). */
|
|
173
|
+
export function resolveProfileDirs(options = {}) {
|
|
174
|
+
const appName = options.appName ?? "agents";
|
|
175
|
+
const home = options.homeDir ?? join(homedir(), `.${appName}`);
|
|
176
|
+
const cwd = options.cwd ?? process.cwd();
|
|
177
|
+
return [join(home, "agents"), join(cwd, `.${appName}`, "agents")];
|
|
178
|
+
}
|
|
179
|
+
function parseProfile(content, path) {
|
|
180
|
+
let raw;
|
|
181
|
+
try {
|
|
182
|
+
raw = loadYaml(content);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw new Error(`agent profile YAML parse failed for ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
186
|
+
}
|
|
187
|
+
const parsed = RawAgentProfileSchema.safeParse(raw);
|
|
188
|
+
if (!parsed.success) {
|
|
189
|
+
throw new Error(`invalid agent profile ${path}: ${parsed.error.issues.map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`).join("; ")}`);
|
|
190
|
+
}
|
|
191
|
+
return parsed.data;
|
|
192
|
+
}
|
|
193
|
+
/** Discover + parse `*.yaml`/`*.yml` profiles across tiers (project name overrides user), resolving
|
|
194
|
+
* each `systemPromptPath` relative to its file. Returns resolved profiles (extends merged). */
|
|
195
|
+
export async function loadAgentProfiles(options = {}) {
|
|
196
|
+
const byName = new Map();
|
|
197
|
+
for (const dir of resolveProfileDirs(options)) {
|
|
198
|
+
let files;
|
|
199
|
+
try {
|
|
200
|
+
files = (await readdir(dir)).filter((f) => f.endsWith(".yaml") || f.endsWith(".yml"));
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
for (const file of files.sort()) {
|
|
206
|
+
const path = join(dir, file);
|
|
207
|
+
const profile = parseProfile(await readFile(path, "utf-8"), path);
|
|
208
|
+
const withTemplate = await inlineSystemPromptFromDisk(profile, path);
|
|
209
|
+
byName.set(withTemplate.name, withTemplate);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return resolveAgentProfiles([...byName.values()]);
|
|
213
|
+
}
|
|
214
|
+
async function inlineSystemPromptFromDisk(profile, profilePath) {
|
|
215
|
+
if (profile.systemPromptPath === undefined)
|
|
216
|
+
return profile;
|
|
217
|
+
const templatePath = join(dirname(profilePath), profile.systemPromptPath);
|
|
218
|
+
return { ...profile, systemPromptTemplate: await readFile(templatePath, "utf-8") };
|
|
219
|
+
}
|
|
220
|
+
/** Build profiles from in-memory sources (YAML strings keyed by path); `systemPromptPath` resolves
|
|
221
|
+
* against the same map. Used for builtin profiles, which ship inline (no bundler/fs needed). */
|
|
222
|
+
export function loadAgentProfilesFromSources(profilePaths, sources) {
|
|
223
|
+
const raw = [];
|
|
224
|
+
for (const path of profilePaths) {
|
|
225
|
+
const content = sources[path];
|
|
226
|
+
if (content === undefined)
|
|
227
|
+
throw new Error(`builtin profile source missing: ${path}`);
|
|
228
|
+
const profile = parseProfile(content, path);
|
|
229
|
+
if (profile.systemPromptPath !== undefined) {
|
|
230
|
+
const templateKey = join(dirname(path), profile.systemPromptPath);
|
|
231
|
+
const template = sources[templateKey];
|
|
232
|
+
if (template === undefined)
|
|
233
|
+
throw new Error(`builtin profile "${profile.name}" references missing template: ${templateKey}`);
|
|
234
|
+
raw.push({ ...profile, systemPromptTemplate: template });
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
raw.push(profile);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return resolveAgentProfiles(raw);
|
|
241
|
+
}
|
|
242
|
+
/** A `SubagentProvider` over resolved profiles (built lazily + cached per type). Pass `only` to
|
|
243
|
+
* expose a subset (e.g. a main profile's declared subagents); omit to expose all. */
|
|
244
|
+
export function profileSubagentProvider(profiles, options = {}) {
|
|
245
|
+
const names = options.only ?? Object.keys(profiles);
|
|
246
|
+
const built = new Map();
|
|
247
|
+
return {
|
|
248
|
+
list: () => names.filter((n) => profiles[n] !== undefined).map((n) => ({ name: n, description: profiles[n].whenToUse ?? profiles[n].description })),
|
|
249
|
+
get: async (type) => {
|
|
250
|
+
if (!names.includes(type))
|
|
251
|
+
return undefined;
|
|
252
|
+
const cached = built.get(type);
|
|
253
|
+
if (cached !== undefined)
|
|
254
|
+
return cached;
|
|
255
|
+
const profile = profiles[type];
|
|
256
|
+
if (profile === undefined)
|
|
257
|
+
return undefined;
|
|
258
|
+
const agent = await buildAgentFromProfile(profile, options);
|
|
259
|
+
built.set(type, agent);
|
|
260
|
+
return agent;
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LlmRequest } from "../llm/model.ts";
|
|
2
|
+
import type { RunState } from "./runner.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Add request-only recovery context for the final assistant batch when some tool calls have no
|
|
5
|
+
* durable result. Pi still owns protocol repair (one synthetic error tool result per missing
|
|
6
|
+
* call); this hook only tells the model which real execution identities survived the crash.
|
|
7
|
+
* Nothing here is appended to ConversationContext or SessionStore.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withToolCallRecoveryContext<TContext>(state: RunState<TContext>, request: LlmRequest): Promise<LlmRequest>;
|
|
10
|
+
//# sourceMappingURL=recovery.d.ts.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const SUBAGENT_META = "subagent_meta";
|
|
2
|
+
const WORKFLOW_JOURNAL = "wf_journal";
|
|
3
|
+
/**
|
|
4
|
+
* Add request-only recovery context for the final assistant batch when some tool calls have no
|
|
5
|
+
* durable result. Pi still owns protocol repair (one synthetic error tool result per missing
|
|
6
|
+
* call); this hook only tells the model which real execution identities survived the crash.
|
|
7
|
+
* Nothing here is appended to ConversationContext or SessionStore.
|
|
8
|
+
*/
|
|
9
|
+
export async function withToolCallRecoveryContext(state, request) {
|
|
10
|
+
const unresolved = unresolvedTailCalls(request.messages);
|
|
11
|
+
if (unresolved.length === 0)
|
|
12
|
+
return request;
|
|
13
|
+
const background = new Map();
|
|
14
|
+
for (const call of unresolved) {
|
|
15
|
+
const task = findBackgroundByOrigin(state.background, state.address, call.id);
|
|
16
|
+
if (task !== undefined)
|
|
17
|
+
background.set(call.id, task);
|
|
18
|
+
}
|
|
19
|
+
const unresolvedWithoutTask = unresolved.filter((call) => !background.has(call.id));
|
|
20
|
+
const durable = state.store === undefined
|
|
21
|
+
? { agents: new Map(), workflows: new Map() }
|
|
22
|
+
: await findDurableExecutions(state.store, state.address, new Set(unresolvedWithoutTask.map((call) => call.id)));
|
|
23
|
+
const lines = [
|
|
24
|
+
"Recovery context: the previous process ended with an unresolved assistant tool-call batch.",
|
|
25
|
+
"Pi will supply a synthetic error tool result for each missing result so the conversation can continue. Those synthetic results do not prove that execution never started; treat every call below independently.",
|
|
26
|
+
];
|
|
27
|
+
for (const call of unresolved) {
|
|
28
|
+
lines.push("", `- tool_call_id: ${call.id}`, ` tool: ${call.name}`);
|
|
29
|
+
const task = background.get(call.id);
|
|
30
|
+
if (task !== undefined) {
|
|
31
|
+
lines.push(` recovered_task_id: ${task.taskId}`, ` task_kind: ${task.kind}`, ` persisted_status: ${task.status}`, ` action: Inspect it with BackgroundOutput(task_id=\"${task.taskId}\", block=false) before retrying or resuming anything.`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const agent = durable.agents.get(call.id);
|
|
35
|
+
if (agent !== undefined) {
|
|
36
|
+
lines.push(` recovered_agent_id: ${agent.agentId}`, ` subagent_type: ${agent.type}`, ` action: Continue the same durable subagent with Agent(resume=\"${agent.agentId}\", prompt=...). Do not spawn a replacement unless continuation fails.`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const workflow = durable.workflows.get(call.id);
|
|
40
|
+
if (workflow !== undefined) {
|
|
41
|
+
lines.push(` recovered_run_id: ${workflow.runId}`, ...(workflow.status !== undefined ? [` journal_status: ${workflow.status}`] : []), ` action: Continue the same journaled run with Workflow(resumeFromRunId=\"${workflow.runId}\").`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
lines.push(" recovered_execution: none", " action: Execution status is unknown. Inspect likely side effects before deciding whether retrying is safe.");
|
|
45
|
+
}
|
|
46
|
+
const reminder = lines.join("\n");
|
|
47
|
+
return {
|
|
48
|
+
...request,
|
|
49
|
+
system: request.system === undefined || request.system.length === 0
|
|
50
|
+
? reminder
|
|
51
|
+
: `${request.system}\n\n${reminder}`,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function findBackgroundByOrigin(value, parentAddress, toolCallId) {
|
|
55
|
+
if (typeof value !== "object" || value === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
const lookup = value.findByOrigin;
|
|
58
|
+
if (typeof lookup !== "function")
|
|
59
|
+
return undefined;
|
|
60
|
+
return lookup.call(value, parentAddress, toolCallId);
|
|
61
|
+
}
|
|
62
|
+
/** Calls in the last assistant message minus every real tool result recorded after it. */
|
|
63
|
+
function unresolvedTailCalls(messages) {
|
|
64
|
+
let assistantIndex = -1;
|
|
65
|
+
let assistant;
|
|
66
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
67
|
+
const message = messages[i];
|
|
68
|
+
if (message.role !== "assistant")
|
|
69
|
+
continue;
|
|
70
|
+
assistantIndex = i;
|
|
71
|
+
assistant = message;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (assistant === undefined)
|
|
75
|
+
return [];
|
|
76
|
+
const calls = assistant.content.filter((part) => part.type === "toolCall");
|
|
77
|
+
if (calls.length === 0)
|
|
78
|
+
return [];
|
|
79
|
+
const completed = new Set();
|
|
80
|
+
for (let i = assistantIndex + 1; i < messages.length; i++) {
|
|
81
|
+
const message = messages[i];
|
|
82
|
+
if (message.role === "assistant")
|
|
83
|
+
break;
|
|
84
|
+
if (message.role === "toolResult")
|
|
85
|
+
completed.add(message.toolCallId);
|
|
86
|
+
}
|
|
87
|
+
return calls.filter((call) => !completed.has(call.id));
|
|
88
|
+
}
|
|
89
|
+
async function findDurableExecutions(store, parentAddress, wanted) {
|
|
90
|
+
const agents = new Map();
|
|
91
|
+
const workflows = new Map();
|
|
92
|
+
const workflowOutcomes = new Map();
|
|
93
|
+
if (wanted.size === 0)
|
|
94
|
+
return { agents, workflows };
|
|
95
|
+
for await (const record of store.readRecords()) {
|
|
96
|
+
if (record.type !== "custom")
|
|
97
|
+
continue;
|
|
98
|
+
if (record.name === SUBAGENT_META) {
|
|
99
|
+
const data = objectData(record);
|
|
100
|
+
const callId = stringField(data, "parentToolCallId");
|
|
101
|
+
if (callId !== undefined &&
|
|
102
|
+
wanted.has(callId) &&
|
|
103
|
+
stringField(data, "parentAddress") === parentAddress) {
|
|
104
|
+
const agentId = stringField(data, "agentId");
|
|
105
|
+
const type = stringField(data, "type");
|
|
106
|
+
if (agentId !== undefined && type !== undefined) {
|
|
107
|
+
agents.set(callId, { agentId, type, address: record.address ?? "main" });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (record.name !== WORKFLOW_JOURNAL)
|
|
113
|
+
continue;
|
|
114
|
+
const data = objectData(record);
|
|
115
|
+
const type = stringField(data, "type");
|
|
116
|
+
if (type === "outcome") {
|
|
117
|
+
const status = stringField(data, "status");
|
|
118
|
+
if (status !== undefined)
|
|
119
|
+
workflowOutcomes.set(record.address ?? "", status);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (type !== "run")
|
|
123
|
+
continue;
|
|
124
|
+
const callId = stringField(data, "parentToolCallId");
|
|
125
|
+
if (callId === undefined ||
|
|
126
|
+
!wanted.has(callId) ||
|
|
127
|
+
stringField(data, "parentAddress") !== parentAddress)
|
|
128
|
+
continue;
|
|
129
|
+
const runId = stringField(data, "runId");
|
|
130
|
+
if (runId !== undefined)
|
|
131
|
+
workflows.set(callId, { runId, address: record.address ?? "" });
|
|
132
|
+
}
|
|
133
|
+
// Outcome records follow their run record in the same workflow shard. Apply them after the
|
|
134
|
+
// full scan so ordering across store backends does not matter.
|
|
135
|
+
for (const [callId, workflow] of workflows) {
|
|
136
|
+
const status = workflowOutcomes.get(workflow.address);
|
|
137
|
+
if (status !== undefined)
|
|
138
|
+
workflows.set(callId, { ...workflow, status });
|
|
139
|
+
}
|
|
140
|
+
return { agents, workflows };
|
|
141
|
+
}
|
|
142
|
+
function objectData(record) {
|
|
143
|
+
return typeof record.data === "object" && record.data !== null
|
|
144
|
+
? record.data
|
|
145
|
+
: {};
|
|
146
|
+
}
|
|
147
|
+
function stringField(record, key) {
|
|
148
|
+
const value = record[key];
|
|
149
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=recovery.js.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-frame support: the free functions every engine collaborator (the turn loop,
|
|
3
|
+
* the handoff executor, the durable pause, the toolset, the hook builder) shares. They
|
|
4
|
+
* take the frame (`RunState`) or plain messages as input and hold no state of their own,
|
|
5
|
+
* so collaborators import THESE instead of reaching back into the Engine. Only TYPES are
|
|
6
|
+
* imported from `runner.ts`, so there is no value-level import cycle.
|
|
7
|
+
*/
|
|
8
|
+
import type { AssistantMessage, Message } from "../protocol/index.ts";
|
|
9
|
+
import type { ModelSettings, ThinkingLevel } from "../llm/model.ts";
|
|
10
|
+
import type { AgentEventBody, EventSink } from "../events/index.ts";
|
|
11
|
+
import type { ConversationContext, HistoryChangeListener } from "../loop/context.ts";
|
|
12
|
+
import type { AgentRunContext } from "./agent.ts";
|
|
13
|
+
import type { DeriveOptions, RunState, RunStatus } from "./runner.ts";
|
|
14
|
+
import type { TurnStopReason } from "../loop/types.ts";
|
|
15
|
+
/**
|
|
16
|
+
* This frame's flat directory id — what peers address it by.
|
|
17
|
+
*
|
|
18
|
+
* A child frame always carries `parentFrameId` (set unconditionally by `deriveChild`), so its
|
|
19
|
+
* absence identifies the root frame. The root IS the session for addressing purposes; every
|
|
20
|
+
* child is its own agent instance. Deliberately derived rather than stored: one less field to
|
|
21
|
+
* keep in sync across derive/resume, and no magic `"root"` string comparison.
|
|
22
|
+
*/
|
|
23
|
+
export declare function selfAgentId<TContext>(state: RunState<TContext>): string;
|
|
24
|
+
/** Stamp the frame envelope (address/sessionId) onto an event body and emit it. */
|
|
25
|
+
export declare function emitRunEvent<TContext>(state: RunState<TContext>, body: AgentEventBody): void | Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* The single translation from a journaled history record to its event. Hand this to a
|
|
28
|
+
* `ConversationContext` as `onHistoryChange` and every history mutation broadcasts itself —
|
|
29
|
+
* no call site has to remember to emit next to its mutation, which is the mistake that
|
|
30
|
+
* silently dropped `replaceHistory` from the stream entirely.
|
|
31
|
+
*
|
|
32
|
+
* The address comes from the RECORD, not from the frame: it names the shard the message
|
|
33
|
+
* actually landed in, which is what a consumer routing by address needs. (These coincide for
|
|
34
|
+
* every frame today; a handoff opening a fresh shard is where they would not.)
|
|
35
|
+
*
|
|
36
|
+
* Exhaustive over history-bearing record types, so adding a fourth one fails compilation here
|
|
37
|
+
* rather than silently skipping the stream.
|
|
38
|
+
*/
|
|
39
|
+
export declare function historyChangeEmitter(events: EventSink, sessionId: string): HistoryChangeListener;
|
|
40
|
+
/**
|
|
41
|
+
* Fold the agent profile's static `modelSettings` and the session's runtime overrides into the
|
|
42
|
+
* params one request carries.
|
|
43
|
+
*
|
|
44
|
+
* Precedence, lowest to highest: `ModelSpec.requestOptions` (model instance defaults, applied
|
|
45
|
+
* down in `toOptions`) < `agent.modelSettings` < session runtime (`setThinkingLevel()`) <
|
|
46
|
+
* `LlmRequest.providerOptions` (the extension escape hatch). The session tier outranks the
|
|
47
|
+
* profile because it is a live user decision: a level picked mid-session must not be overruled
|
|
48
|
+
* by static config.
|
|
49
|
+
*
|
|
50
|
+
* Returns `undefined` when nothing is set, so requests from agents with no `modelSettings`
|
|
51
|
+
* stay exactly as they were.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveModelParams(settings: ModelSettings | undefined, sessionThinking: ThinkingLevel | undefined): ModelSettings | undefined;
|
|
54
|
+
/** The run context handed to agent-facing callbacks (instructions/guardrails/onHandoff). */
|
|
55
|
+
export declare function runCtxFor<TContext>(state: RunState<TContext>): AgentRunContext<TContext>;
|
|
56
|
+
/**
|
|
57
|
+
* Fork a child runtime for a spawned sub-agent: fresh usage/turns ledger and a new
|
|
58
|
+
* `address` shard, inheriting the parent's shared machine (session/store/permission/…)
|
|
59
|
+
* unless an override is given. This is the single place child frames are minted — the
|
|
60
|
+
* subagent, Agent, and Workflow tools all go through it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function deriveChild<TContext>(parent: RunState<TContext>, opts: DeriveOptions): RunState<TContext>;
|
|
63
|
+
/** Runs the turn-boundary injectors, appending their reminders to `context`, and returns each
|
|
64
|
+
* injector's token estimate so the context breakdown can break the framing out of `messages`. */
|
|
65
|
+
export declare function injectAtTurnBoundary<TContext>(state: RunState<TContext>, context: ConversationContext): Map<string, number>;
|
|
66
|
+
export declare function lastAssistant(messages: readonly Message[]): AssistantMessage | undefined;
|
|
67
|
+
export declare function finalText(messages: readonly Message[]): string;
|
|
68
|
+
export declare function mapTerminalStatus(stop: TurnStopReason): RunStatus;
|
|
69
|
+
export interface ParsedOutput {
|
|
70
|
+
/** The parsed value; absent when the schema rejected the text (see `error`). */
|
|
71
|
+
readonly value?: unknown;
|
|
72
|
+
/** Set when an outputType schema was present and rejected the final text. Distinguishes
|
|
73
|
+
* "parse failed" from "no schema configured" — both used to surface as a bare
|
|
74
|
+
* `outputParsed: undefined`, with the schema's rejection reason swallowed. */
|
|
75
|
+
readonly error?: string;
|
|
76
|
+
}
|
|
77
|
+
export declare function tryParseOutput(schema: unknown, text: string): ParsedOutput;
|
|
78
|
+
export declare function addressTail(address: string): string;
|
|
79
|
+
//# sourceMappingURL=run-support.d.ts.map
|