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,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-graph resolution + validation helpers, shared by the Runner (run()/resume()
|
|
3
|
+
* boundary checks, conversation-head resolution) and the toolset's spawner
|
|
4
|
+
* (resolveInGraph). Pure functions over the `Agent` graph — no runtime state.
|
|
5
|
+
*/
|
|
6
|
+
import { Agent } from "./agent.js";
|
|
7
|
+
import { toFunctionToolName } from "./handoff.js";
|
|
8
|
+
/**
|
|
9
|
+
* Fail a malformed graph at the run()/resume() boundary — before any turn executes or records
|
|
10
|
+
* commit — rather than mid-conversation when the offending agent finally becomes active. Walks
|
|
11
|
+
* by object identity, not name: distinct same-named agents in different corners of the graph are
|
|
12
|
+
* legal, and each one still gets validated.
|
|
13
|
+
*/
|
|
14
|
+
export function assertGraphUnambiguous(root) {
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
const queue = [root];
|
|
17
|
+
while (queue.length > 0) {
|
|
18
|
+
const agent = queue.shift();
|
|
19
|
+
if (seen.has(agent))
|
|
20
|
+
continue;
|
|
21
|
+
seen.add(agent);
|
|
22
|
+
assertUnambiguousEdges(agent);
|
|
23
|
+
for (const h of agent.handoffs)
|
|
24
|
+
queue.push(h.target);
|
|
25
|
+
for (const s of agent.subagents)
|
|
26
|
+
queue.push(s);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An agent's edges are addressed by name at two seams — tool names the model calls
|
|
31
|
+
* (`transfer_to_<x>`, `agent_<slug>`) and durable handoff records resolved on resume — so within
|
|
32
|
+
* one agent each name must map to a single target. Not checked in the Agent constructor: cyclic
|
|
33
|
+
* graphs are built by pushing into `handoffs` after both agents exist, so the constructor never
|
|
34
|
+
* sees the final lists. Runs only at the run()/resume() boundary (via `assertGraphUnambiguous`);
|
|
35
|
+
* agents that enter the graph later — provider-loaded subagents, post-run() edge mutation — are
|
|
36
|
+
* the caller's responsibility (name clashes with static subagents already dedupe, static wins).
|
|
37
|
+
*/
|
|
38
|
+
export function assertUnambiguousEdges(agent) {
|
|
39
|
+
const toolNames = new Set();
|
|
40
|
+
const targetsByName = new Map();
|
|
41
|
+
for (const h of agent.handoffs) {
|
|
42
|
+
if (toolNames.has(h.toolName)) {
|
|
43
|
+
throw new Error(`Agent "${agent.name}" has multiple handoff tools named "${h.toolName}".`);
|
|
44
|
+
}
|
|
45
|
+
toolNames.add(h.toolName);
|
|
46
|
+
const prior = targetsByName.get(h.target.name);
|
|
47
|
+
if (prior !== undefined && prior !== h.target) {
|
|
48
|
+
throw new Error(`Agent "${agent.name}" has handoffs to two different agents both named "${h.target.name}"; handoff target names must be unique per agent.`);
|
|
49
|
+
}
|
|
50
|
+
targetsByName.set(h.target.name, h.target);
|
|
51
|
+
}
|
|
52
|
+
const subagentSlugs = new Map();
|
|
53
|
+
for (const sub of agent.subagents) {
|
|
54
|
+
const slug = toFunctionToolName(sub.name);
|
|
55
|
+
const prior = subagentSlugs.get(slug);
|
|
56
|
+
if (prior !== undefined) {
|
|
57
|
+
throw new Error(`Agent "${agent.name}" has subagents "${prior}" and "${sub.name}" that share the tool name "agent_${slug}"; subagent names must be unique per agent.`);
|
|
58
|
+
}
|
|
59
|
+
subagentSlugs.set(slug, sub.name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Durable state (conversation head, interruption frames) stores agent NAMES, so resume-time
|
|
63
|
+
* resolution is by name — and a graph with two distinct same-named agents (legal, see
|
|
64
|
+
* {@link assertGraphUnambiguous}) cannot be resolved safely that way. Thrown instead of
|
|
65
|
+
* guessing: binding whichever BFS found first would silently hand the conversation to the
|
|
66
|
+
* wrong agent. */
|
|
67
|
+
export class AmbiguousAgentNameError extends Error {
|
|
68
|
+
agentName;
|
|
69
|
+
constructor(name, count) {
|
|
70
|
+
super(`Agent name "${name}" is ambiguous: ${String(count)} distinct agents in the graph share it. ` +
|
|
71
|
+
`Durable state stores agents by name, so resume/head resolution cannot tell them apart — give agents unique names.`);
|
|
72
|
+
this.name = "AmbiguousAgentNameError";
|
|
73
|
+
this.agentName = name;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Names shared by ≥2 distinct agent objects in the graph. Such a graph builds and runs
|
|
77
|
+
* live fine (edges resolve by object), but durable name-keyed resolution (resume,
|
|
78
|
+
* interruption frames) fails closed on those names — surfaced as a run-boundary warning
|
|
79
|
+
* so users hear about it before an {@link AmbiguousAgentNameError} interrupts a resume. */
|
|
80
|
+
export function duplicateAgentNames(root) {
|
|
81
|
+
const seen = new Set();
|
|
82
|
+
const counts = new Map();
|
|
83
|
+
const queue = [root];
|
|
84
|
+
while (queue.length > 0) {
|
|
85
|
+
const agent = queue.shift();
|
|
86
|
+
if (seen.has(agent))
|
|
87
|
+
continue;
|
|
88
|
+
seen.add(agent);
|
|
89
|
+
counts.set(agent.name, (counts.get(agent.name) ?? 0) + 1);
|
|
90
|
+
for (const h of agent.handoffs)
|
|
91
|
+
queue.push(h.target);
|
|
92
|
+
for (const s of agent.subagents)
|
|
93
|
+
queue.push(s);
|
|
94
|
+
}
|
|
95
|
+
return [...counts.entries()].filter(([, count]) => count > 1).map(([name]) => name);
|
|
96
|
+
}
|
|
97
|
+
/** Every distinct agent OBJECT in the graph named `name`. Visits by object identity — a
|
|
98
|
+
* name-keyed visited set would prune the subtree behind a same-named duplicate, hiding
|
|
99
|
+
* agents reachable only through it. */
|
|
100
|
+
export function findAgentsByName(root, name) {
|
|
101
|
+
const seen = new Set();
|
|
102
|
+
const matches = [];
|
|
103
|
+
const queue = [root];
|
|
104
|
+
while (queue.length > 0) {
|
|
105
|
+
const agent = queue.shift();
|
|
106
|
+
if (seen.has(agent))
|
|
107
|
+
continue;
|
|
108
|
+
seen.add(agent);
|
|
109
|
+
if (agent.name === name)
|
|
110
|
+
matches.push(agent);
|
|
111
|
+
for (const h of agent.handoffs)
|
|
112
|
+
queue.push(h.target);
|
|
113
|
+
for (const s of agent.subagents)
|
|
114
|
+
queue.push(s);
|
|
115
|
+
}
|
|
116
|
+
return matches;
|
|
117
|
+
}
|
|
118
|
+
/** Resolve `name` to THE agent it denotes: `undefined` when absent, the agent when unique,
|
|
119
|
+
* and a thrown {@link AmbiguousAgentNameError} when several distinct agents share the name
|
|
120
|
+
* (fail-closed — see the error's doc). Callers that can resolve ambiguity another way
|
|
121
|
+
* (the Runner's cold head walk resolves along committed handoff edges) should catch it or
|
|
122
|
+
* use {@link findAgentsByName} directly. */
|
|
123
|
+
export function findAgentByName(root, name) {
|
|
124
|
+
const matches = findAgentsByName(root, name);
|
|
125
|
+
if (matches.length > 1)
|
|
126
|
+
throw new AmbiguousAgentNameError(name, matches.length);
|
|
127
|
+
return matches[0];
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ToolCall, Usage } from "../protocol/index.ts";
|
|
2
|
+
import type { FinalizeToolResultHook, OutputGuardrailMonitor, OutputGuardrailMonitorOptions, PrepareToolExecutionHook } from "../loop/types.ts";
|
|
3
|
+
import type { ToolResult } from "../tool/types.ts";
|
|
4
|
+
import type { Agent, AgentRunContext } from "./agent.ts";
|
|
5
|
+
export interface GuardrailFunctionOutput {
|
|
6
|
+
readonly tripwireTriggered: boolean;
|
|
7
|
+
readonly outputInfo?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface InputGuardrailArgs<TContext = unknown> {
|
|
10
|
+
readonly agent: Agent<TContext>;
|
|
11
|
+
readonly input: readonly import("../protocol/index.ts").Message[];
|
|
12
|
+
readonly context: AgentRunContext<TContext>;
|
|
13
|
+
}
|
|
14
|
+
export interface InputGuardrail<TContext = unknown> {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
execute(args: InputGuardrailArgs<TContext>): Promise<GuardrailFunctionOutput> | GuardrailFunctionOutput;
|
|
17
|
+
readonly runInParallel?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface OutputGuardrailArgs<TContext = unknown> {
|
|
20
|
+
readonly agent: Agent<TContext>;
|
|
21
|
+
/** Full text produced so far (stream) or the complete final output (final). */
|
|
22
|
+
readonly output: string;
|
|
23
|
+
/** Text not covered by this guardrail's previous successful check. */
|
|
24
|
+
readonly delta: string;
|
|
25
|
+
readonly phase: "stream" | "final";
|
|
26
|
+
readonly context: AgentRunContext<TContext>;
|
|
27
|
+
}
|
|
28
|
+
export interface OutputGuardrailStreamingOptions {
|
|
29
|
+
/** Start a background check after this many unchecked characters. Defaults to 300. */
|
|
30
|
+
readonly minChars?: number;
|
|
31
|
+
/** Check an undersized tail after this delay. Defaults to 500ms. */
|
|
32
|
+
readonly maxDelayMs?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface OutputGuardrail<TContext = unknown> {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
/** Opt in to optimistic delta checks. Final output is always checked. */
|
|
37
|
+
readonly streaming?: boolean | OutputGuardrailStreamingOptions;
|
|
38
|
+
execute(args: OutputGuardrailArgs<TContext>): Promise<GuardrailFunctionOutput> | GuardrailFunctionOutput;
|
|
39
|
+
}
|
|
40
|
+
export type GuardrailStage = "input" | "output" | "tool_input" | "tool_output";
|
|
41
|
+
/** Where the tripped run lived, so an upper layer can locate (and potentially resume) it. */
|
|
42
|
+
export interface GuardrailLocation {
|
|
43
|
+
readonly sessionId?: string;
|
|
44
|
+
readonly address?: string;
|
|
45
|
+
readonly agentName?: string;
|
|
46
|
+
readonly turnId?: string;
|
|
47
|
+
readonly step?: number;
|
|
48
|
+
readonly stepId?: string;
|
|
49
|
+
}
|
|
50
|
+
export declare class GuardrailTripwireError extends Error {
|
|
51
|
+
readonly stage: GuardrailStage;
|
|
52
|
+
readonly guardrailName: string;
|
|
53
|
+
readonly outputInfo?: unknown;
|
|
54
|
+
readonly sessionId?: string;
|
|
55
|
+
readonly address?: string;
|
|
56
|
+
readonly agentName?: string;
|
|
57
|
+
readonly turnId?: string;
|
|
58
|
+
readonly step?: number;
|
|
59
|
+
readonly stepId?: string;
|
|
60
|
+
/** Model usage already incurred before an output tripwire stopped the step. */
|
|
61
|
+
usage?: Usage;
|
|
62
|
+
constructor(stage: GuardrailStage, guardrailName: string, outputInfo?: unknown, location?: GuardrailLocation);
|
|
63
|
+
}
|
|
64
|
+
export declare function isGuardrailTripwireError(error: unknown): error is GuardrailTripwireError;
|
|
65
|
+
export declare function runInputGuardrails<TContext>(guardrails: readonly InputGuardrail<TContext>[], args: InputGuardrailArgs<TContext>): Promise<void>;
|
|
66
|
+
export declare function runOutputGuardrails<TContext>(guardrails: readonly OutputGuardrail<TContext>[], args: Omit<OutputGuardrailArgs<TContext>, "delta" | "phase"> & Partial<Pick<OutputGuardrailArgs<TContext>, "delta" | "phase">>): Promise<void>;
|
|
67
|
+
/** Build one per-step optimistic monitor. Deltas remain live-only and are surfaced before
|
|
68
|
+
* checks complete; a tripwire aborts the model and prevents the final message from journaling. */
|
|
69
|
+
export declare function createOutputGuardrailMonitor<TContext>(guardrails: readonly OutputGuardrail<TContext>[], agent: Agent<TContext>, context: AgentRunContext<TContext>, options: OutputGuardrailMonitorOptions): OutputGuardrailMonitor;
|
|
70
|
+
export type ToolGuardrailBehavior = {
|
|
71
|
+
readonly type: "allow";
|
|
72
|
+
} | {
|
|
73
|
+
readonly type: "rejectContent";
|
|
74
|
+
readonly message: string;
|
|
75
|
+
} | {
|
|
76
|
+
readonly type: "throwException";
|
|
77
|
+
};
|
|
78
|
+
export interface ToolGuardrailFunctionOutput {
|
|
79
|
+
readonly behavior: ToolGuardrailBehavior;
|
|
80
|
+
readonly outputInfo?: unknown;
|
|
81
|
+
}
|
|
82
|
+
export interface ToolInputGuardrailData<TContext = unknown> {
|
|
83
|
+
readonly agent: Agent<TContext>;
|
|
84
|
+
readonly toolCall: ToolCall;
|
|
85
|
+
readonly context: AgentRunContext<TContext>;
|
|
86
|
+
}
|
|
87
|
+
export interface ToolOutputGuardrailData<TContext = unknown> extends ToolInputGuardrailData<TContext> {
|
|
88
|
+
readonly output: ToolResult;
|
|
89
|
+
}
|
|
90
|
+
export interface ToolInputGuardrail<TContext = unknown> {
|
|
91
|
+
readonly name: string;
|
|
92
|
+
run(data: ToolInputGuardrailData<TContext>): Promise<ToolGuardrailFunctionOutput> | ToolGuardrailFunctionOutput;
|
|
93
|
+
}
|
|
94
|
+
export interface ToolOutputGuardrail<TContext = unknown> {
|
|
95
|
+
readonly name: string;
|
|
96
|
+
run(data: ToolOutputGuardrailData<TContext>): Promise<ToolGuardrailFunctionOutput> | ToolGuardrailFunctionOutput;
|
|
97
|
+
}
|
|
98
|
+
export declare const toolGuardrail: {
|
|
99
|
+
allow(outputInfo?: unknown): ToolGuardrailFunctionOutput;
|
|
100
|
+
rejectContent(message: string, outputInfo?: unknown): ToolGuardrailFunctionOutput;
|
|
101
|
+
throwException(outputInfo?: unknown): ToolGuardrailFunctionOutput;
|
|
102
|
+
};
|
|
103
|
+
export declare function toolInputGuardrailHook<TContext>(agent: Agent<TContext>, context: AgentRunContext<TContext>, guardrails: readonly ToolInputGuardrail<TContext>[]): PrepareToolExecutionHook;
|
|
104
|
+
export declare function toolOutputGuardrailHook<TContext>(agent: Agent<TContext>, context: AgentRunContext<TContext>, guardrails: readonly ToolOutputGuardrail<TContext>[]): FinalizeToolResultHook;
|
|
105
|
+
//# sourceMappingURL=guardrail.d.ts.map
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
export class GuardrailTripwireError extends Error {
|
|
2
|
+
stage;
|
|
3
|
+
guardrailName;
|
|
4
|
+
outputInfo;
|
|
5
|
+
sessionId;
|
|
6
|
+
address;
|
|
7
|
+
agentName;
|
|
8
|
+
turnId;
|
|
9
|
+
step;
|
|
10
|
+
stepId;
|
|
11
|
+
/** Model usage already incurred before an output tripwire stopped the step. */
|
|
12
|
+
usage;
|
|
13
|
+
constructor(stage, guardrailName, outputInfo, location) {
|
|
14
|
+
super(`Guardrail "${guardrailName}" tripwire triggered (${stage}).`);
|
|
15
|
+
this.name = "GuardrailTripwireError";
|
|
16
|
+
this.stage = stage;
|
|
17
|
+
this.guardrailName = guardrailName;
|
|
18
|
+
this.outputInfo = outputInfo;
|
|
19
|
+
this.sessionId = location?.sessionId;
|
|
20
|
+
this.address = location?.address;
|
|
21
|
+
this.agentName = location?.agentName;
|
|
22
|
+
this.turnId = location?.turnId;
|
|
23
|
+
this.step = location?.step;
|
|
24
|
+
this.stepId = location?.stepId;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function isGuardrailTripwireError(error) {
|
|
28
|
+
return error instanceof GuardrailTripwireError;
|
|
29
|
+
}
|
|
30
|
+
export async function runInputGuardrails(guardrails, args) {
|
|
31
|
+
for (const guardrail of guardrails) {
|
|
32
|
+
const output = await guardrail.execute(args);
|
|
33
|
+
if (output.tripwireTriggered)
|
|
34
|
+
throw new GuardrailTripwireError("input", guardrail.name, output.outputInfo, locationOf(args));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function runOutputGuardrails(guardrails, args) {
|
|
38
|
+
const normalized = {
|
|
39
|
+
...args,
|
|
40
|
+
delta: args.delta ?? args.output,
|
|
41
|
+
phase: args.phase ?? "final",
|
|
42
|
+
};
|
|
43
|
+
for (const guardrail of guardrails) {
|
|
44
|
+
const output = await guardrail.execute(normalized);
|
|
45
|
+
if (output.tripwireTriggered)
|
|
46
|
+
throw new GuardrailTripwireError("output", guardrail.name, output.outputInfo, locationOf(normalized));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const DEFAULT_STREAM_MIN_CHARS = 300;
|
|
50
|
+
const DEFAULT_STREAM_MAX_DELAY_MS = 500;
|
|
51
|
+
/** Build one per-step optimistic monitor. Deltas remain live-only and are surfaced before
|
|
52
|
+
* checks complete; a tripwire aborts the model and prevents the final message from journaling. */
|
|
53
|
+
export function createOutputGuardrailMonitor(guardrails, agent, context, options) {
|
|
54
|
+
return new OptimisticOutputGuardrailMonitor(guardrails, agent, context, options);
|
|
55
|
+
}
|
|
56
|
+
class OptimisticOutputGuardrailMonitor {
|
|
57
|
+
signal;
|
|
58
|
+
guardrails;
|
|
59
|
+
streaming;
|
|
60
|
+
agent;
|
|
61
|
+
context;
|
|
62
|
+
options;
|
|
63
|
+
controller;
|
|
64
|
+
onParentAbort;
|
|
65
|
+
output = "";
|
|
66
|
+
generation = 0;
|
|
67
|
+
failure;
|
|
68
|
+
finishing = false;
|
|
69
|
+
constructor(guardrails, agent, context, options) {
|
|
70
|
+
this.guardrails = guardrails;
|
|
71
|
+
this.agent = agent;
|
|
72
|
+
this.context = context;
|
|
73
|
+
this.options = options;
|
|
74
|
+
this.streaming = guardrails.flatMap((guardrail) => {
|
|
75
|
+
if (guardrail.streaming === undefined || guardrail.streaming === false)
|
|
76
|
+
return [];
|
|
77
|
+
const config = guardrail.streaming === true ? {} : guardrail.streaming;
|
|
78
|
+
return [{
|
|
79
|
+
guardrail,
|
|
80
|
+
minChars: positiveInt(config.minChars, DEFAULT_STREAM_MIN_CHARS),
|
|
81
|
+
maxDelayMs: nonNegativeInt(config.maxDelayMs, DEFAULT_STREAM_MAX_DELAY_MS),
|
|
82
|
+
checkedThrough: 0,
|
|
83
|
+
}];
|
|
84
|
+
});
|
|
85
|
+
if (this.streaming.length === 0) {
|
|
86
|
+
this.signal = options.signal;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.controller = new AbortController();
|
|
90
|
+
this.signal = this.controller.signal;
|
|
91
|
+
this.onParentAbort = () => this.controller?.abort(options.signal.reason);
|
|
92
|
+
if (options.signal.aborted)
|
|
93
|
+
this.onParentAbort();
|
|
94
|
+
else
|
|
95
|
+
options.signal.addEventListener("abort", this.onParentAbort, { once: true });
|
|
96
|
+
}
|
|
97
|
+
observeTextDelta(delta) {
|
|
98
|
+
if (this.finishing || this.failure !== undefined || delta.length === 0)
|
|
99
|
+
return;
|
|
100
|
+
this.output += delta;
|
|
101
|
+
for (const state of this.streaming) {
|
|
102
|
+
if (this.output.length - state.checkedThrough >= state.minChars)
|
|
103
|
+
this.start(state);
|
|
104
|
+
else
|
|
105
|
+
this.ensureTimer(state);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
reset() {
|
|
109
|
+
this.generation += 1;
|
|
110
|
+
this.output = "";
|
|
111
|
+
for (const state of this.streaming) {
|
|
112
|
+
state.checkedThrough = 0;
|
|
113
|
+
this.clearTimer(state);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async finish(output, runFinal, usage) {
|
|
117
|
+
this.finishing = true;
|
|
118
|
+
this.output = output;
|
|
119
|
+
try {
|
|
120
|
+
for (const state of this.streaming)
|
|
121
|
+
this.clearTimer(state);
|
|
122
|
+
await this.awaitRunning();
|
|
123
|
+
this.throwIfFailed();
|
|
124
|
+
if (runFinal) {
|
|
125
|
+
for (const guardrail of this.guardrails) {
|
|
126
|
+
const state = this.streaming.find((candidate) => candidate.guardrail === guardrail);
|
|
127
|
+
await this.invoke(guardrail, {
|
|
128
|
+
output: this.output,
|
|
129
|
+
delta: this.output.slice(state?.checkedThrough ?? 0),
|
|
130
|
+
phase: "final",
|
|
131
|
+
});
|
|
132
|
+
if (state)
|
|
133
|
+
state.checkedThrough = this.output.length;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
for (const state of this.streaming) {
|
|
138
|
+
if (state.checkedThrough < this.output.length)
|
|
139
|
+
this.start(state, true);
|
|
140
|
+
}
|
|
141
|
+
await this.awaitRunning();
|
|
142
|
+
}
|
|
143
|
+
this.throwIfFailed();
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error instanceof GuardrailTripwireError)
|
|
147
|
+
error.usage = usage;
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async settle() {
|
|
152
|
+
await this.awaitRunning();
|
|
153
|
+
this.throwIfFailed();
|
|
154
|
+
}
|
|
155
|
+
dispose() {
|
|
156
|
+
this.finishing = true;
|
|
157
|
+
for (const state of this.streaming)
|
|
158
|
+
this.clearTimer(state);
|
|
159
|
+
if (this.onParentAbort)
|
|
160
|
+
this.options.signal.removeEventListener("abort", this.onParentAbort);
|
|
161
|
+
}
|
|
162
|
+
start(state, force = false) {
|
|
163
|
+
this.clearTimer(state);
|
|
164
|
+
if (this.failure !== undefined || state.running || (this.finishing && !force))
|
|
165
|
+
return;
|
|
166
|
+
if (!force && this.output.length - state.checkedThrough < state.minChars) {
|
|
167
|
+
this.ensureTimer(state);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const snapshot = this.output;
|
|
171
|
+
if (snapshot.length <= state.checkedThrough)
|
|
172
|
+
return;
|
|
173
|
+
const checkedFrom = state.checkedThrough;
|
|
174
|
+
const generation = this.generation;
|
|
175
|
+
const token = {};
|
|
176
|
+
state.runningToken = token;
|
|
177
|
+
state.running = (async () => {
|
|
178
|
+
try {
|
|
179
|
+
await this.invoke(state.guardrail, {
|
|
180
|
+
output: snapshot,
|
|
181
|
+
delta: snapshot.slice(checkedFrom),
|
|
182
|
+
phase: "stream",
|
|
183
|
+
});
|
|
184
|
+
if (generation === this.generation)
|
|
185
|
+
state.checkedThrough = snapshot.length;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (generation === this.generation)
|
|
189
|
+
this.fail(error);
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
if (state.runningToken === token) {
|
|
193
|
+
state.running = undefined;
|
|
194
|
+
state.runningToken = undefined;
|
|
195
|
+
}
|
|
196
|
+
if (generation === this.generation && this.failure === undefined && !this.finishing) {
|
|
197
|
+
if (this.output.length - state.checkedThrough >= state.minChars)
|
|
198
|
+
this.start(state);
|
|
199
|
+
else if (state.checkedThrough < this.output.length)
|
|
200
|
+
this.ensureTimer(state);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
})();
|
|
204
|
+
}
|
|
205
|
+
async invoke(guardrail, input) {
|
|
206
|
+
const result = await guardrail.execute({
|
|
207
|
+
agent: this.agent,
|
|
208
|
+
context: this.context,
|
|
209
|
+
...input,
|
|
210
|
+
});
|
|
211
|
+
if (result.tripwireTriggered) {
|
|
212
|
+
throw new GuardrailTripwireError("output", guardrail.name, result.outputInfo, {
|
|
213
|
+
sessionId: this.context.sessionId,
|
|
214
|
+
address: this.context.address,
|
|
215
|
+
agentName: this.agent.name,
|
|
216
|
+
turnId: this.options.turnId,
|
|
217
|
+
step: this.options.step,
|
|
218
|
+
stepId: this.options.stepId,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
fail(error) {
|
|
223
|
+
if (this.failure !== undefined)
|
|
224
|
+
return;
|
|
225
|
+
this.failure = error;
|
|
226
|
+
this.controller?.abort(error);
|
|
227
|
+
for (const state of this.streaming)
|
|
228
|
+
this.clearTimer(state);
|
|
229
|
+
}
|
|
230
|
+
async awaitRunning() {
|
|
231
|
+
while (true) {
|
|
232
|
+
const running = this.streaming.flatMap((state) => state.running ? [state.running] : []);
|
|
233
|
+
if (running.length === 0)
|
|
234
|
+
return;
|
|
235
|
+
await Promise.all(running);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
throwIfFailed() {
|
|
239
|
+
if (this.failure !== undefined)
|
|
240
|
+
throw this.failure;
|
|
241
|
+
}
|
|
242
|
+
ensureTimer(state) {
|
|
243
|
+
if (state.timer || state.running || this.finishing || this.failure !== undefined)
|
|
244
|
+
return;
|
|
245
|
+
state.timer = setTimeout(() => {
|
|
246
|
+
state.timer = undefined;
|
|
247
|
+
this.start(state, true);
|
|
248
|
+
}, state.maxDelayMs);
|
|
249
|
+
}
|
|
250
|
+
clearTimer(state) {
|
|
251
|
+
if (state.timer === undefined)
|
|
252
|
+
return;
|
|
253
|
+
clearTimeout(state.timer);
|
|
254
|
+
state.timer = undefined;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function positiveInt(value, fallback) {
|
|
258
|
+
return value !== undefined && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
259
|
+
}
|
|
260
|
+
function nonNegativeInt(value, fallback) {
|
|
261
|
+
return value !== undefined && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
|
|
262
|
+
}
|
|
263
|
+
/** Extract run-locating fields from guardrail args (input/output share `agent` + `context`). */
|
|
264
|
+
function locationOf(args) {
|
|
265
|
+
return { sessionId: args.context.sessionId, address: args.context.address, agentName: args.agent.name };
|
|
266
|
+
}
|
|
267
|
+
export const toolGuardrail = {
|
|
268
|
+
allow(outputInfo) {
|
|
269
|
+
return { behavior: { type: "allow" }, outputInfo };
|
|
270
|
+
},
|
|
271
|
+
rejectContent(message, outputInfo) {
|
|
272
|
+
return { behavior: { type: "rejectContent", message }, outputInfo };
|
|
273
|
+
},
|
|
274
|
+
throwException(outputInfo) {
|
|
275
|
+
return { behavior: { type: "throwException" }, outputInfo };
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
function rejectedResult(message) {
|
|
279
|
+
return { content: [{ type: "text", text: message }], isError: true };
|
|
280
|
+
}
|
|
281
|
+
export function toolInputGuardrailHook(agent, context, guardrails) {
|
|
282
|
+
return async (ctx) => {
|
|
283
|
+
for (const guardrail of guardrails) {
|
|
284
|
+
const out = await guardrail.run({ agent, toolCall: ctx.toolCall, context });
|
|
285
|
+
if (out.behavior.type === "rejectContent")
|
|
286
|
+
return { syntheticResult: rejectedResult(out.behavior.message) };
|
|
287
|
+
if (out.behavior.type === "throwException")
|
|
288
|
+
throw new GuardrailTripwireError("tool_input", guardrail.name, out.outputInfo, {
|
|
289
|
+
sessionId: context.sessionId,
|
|
290
|
+
address: context.address,
|
|
291
|
+
agentName: agent.name,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return undefined;
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export function toolOutputGuardrailHook(agent, context, guardrails) {
|
|
298
|
+
return async (ctx) => {
|
|
299
|
+
let result = ctx.result;
|
|
300
|
+
for (const guardrail of guardrails) {
|
|
301
|
+
const out = await guardrail.run({ agent, toolCall: ctx.toolCall, output: result, context });
|
|
302
|
+
if (out.behavior.type === "rejectContent")
|
|
303
|
+
result = rejectedResult(out.behavior.message);
|
|
304
|
+
else if (out.behavior.type === "throwException")
|
|
305
|
+
throw new GuardrailTripwireError("tool_output", guardrail.name, out.outputInfo, {
|
|
306
|
+
sessionId: context.sessionId,
|
|
307
|
+
address: context.address,
|
|
308
|
+
agentName: agent.name,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return result;
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=guardrail.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff execution — extracted from the Engine's turn loop. Only TYPES are imported from
|
|
3
|
+
* `runner.ts`; the loop calls `performHandoff` and continues with the returned agent/context.
|
|
4
|
+
*/
|
|
5
|
+
import { ConversationContext } from "../loop/context.ts";
|
|
6
|
+
import type { HandoffSignal } from "../loop/types.ts";
|
|
7
|
+
import type { Agent } from "./agent.ts";
|
|
8
|
+
import type { RunState } from "./runner.ts";
|
|
9
|
+
/**
|
|
10
|
+
* Execute a handoff edge: seed a fresh root shard for the target agent, journal both
|
|
11
|
+
* sides (destination first — the source-side record is the commit point for cold
|
|
12
|
+
* replay), and repoint the run (`state.address`, session head) at the destination.
|
|
13
|
+
* Returns the target agent and its context for the loop to continue with, or
|
|
14
|
+
* `undefined` when the signal names an edge the current agent doesn't have — the
|
|
15
|
+
* caller finishes the run as an error.
|
|
16
|
+
*/
|
|
17
|
+
export declare function performHandoff<TContext>(current: Agent<TContext>, context: ConversationContext, handoff: HandoffSignal, state: RunState<TContext>): Promise<{
|
|
18
|
+
agent: Agent<TContext>;
|
|
19
|
+
context: ConversationContext;
|
|
20
|
+
} | undefined>;
|
|
21
|
+
//# sourceMappingURL=handoff-executor.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff execution — extracted from the Engine's turn loop. Only TYPES are imported from
|
|
3
|
+
* `runner.ts`; the loop calls `performHandoff` and continues with the returned agent/context.
|
|
4
|
+
*/
|
|
5
|
+
import { ConversationContext } from "../loop/context.js";
|
|
6
|
+
import { newInterruptionId } from "../loop/interruption.js";
|
|
7
|
+
import { toFunctionToolName } from "./handoff.js";
|
|
8
|
+
import { runInputGuardrails } from "./guardrail.js";
|
|
9
|
+
import { emitRunEvent, historyChangeEmitter, runCtxFor } from "./run-support.js";
|
|
10
|
+
/**
|
|
11
|
+
* Execute a handoff edge: seed a fresh root shard for the target agent, journal both
|
|
12
|
+
* sides (destination first — the source-side record is the commit point for cold
|
|
13
|
+
* replay), and repoint the run (`state.address`, session head) at the destination.
|
|
14
|
+
* Returns the target agent and its context for the loop to continue with, or
|
|
15
|
+
* `undefined` when the signal names an edge the current agent doesn't have — the
|
|
16
|
+
* caller finishes the run as an error.
|
|
17
|
+
*/
|
|
18
|
+
export async function performHandoff(current, context, handoff, state) {
|
|
19
|
+
const messages = context.messages;
|
|
20
|
+
const edge = current.handoffs.find((h) => h.toolName === handoff.toolName);
|
|
21
|
+
if (!edge) {
|
|
22
|
+
emitRunEvent(state, { type: "warning", message: `Unknown handoff target "${handoff.toolName}".` });
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
// The tool framework already validated these args against the handoff's schema
|
|
26
|
+
// (`inputType`, or the default `{ reason }`), so hand them to onHandoff as-is.
|
|
27
|
+
// runCtxFor is called before the address repoint below, so onHandoff sees the source address.
|
|
28
|
+
if (edge.onHandoff)
|
|
29
|
+
await edge.onHandoff(runCtxFor(state), handoff.args);
|
|
30
|
+
const filtered = edge.inputFilter ? edge.inputFilter({ history: messages }) : { history: messages };
|
|
31
|
+
const handoffId = newInterruptionId("handoff");
|
|
32
|
+
const fromAddress = state.address;
|
|
33
|
+
const toAddress = handoffRootAddress(edge.target.name, handoffId);
|
|
34
|
+
const seeded = structuredClone([...filtered.history]);
|
|
35
|
+
const targetContext = new ConversationContext({
|
|
36
|
+
store: state.store,
|
|
37
|
+
address: toAddress,
|
|
38
|
+
...(state.store === undefined
|
|
39
|
+
? { onHistoryChange: historyChangeEmitter(state.events, state.sessionId) }
|
|
40
|
+
: {}),
|
|
41
|
+
});
|
|
42
|
+
// Prepare and flush the destination first. The source-side handoff record below is the
|
|
43
|
+
// commit point: a crash before it leaves only an unreachable orphan shard; a crash after
|
|
44
|
+
// it always finds a fully initialized destination during cold replay.
|
|
45
|
+
targetContext.record({
|
|
46
|
+
type: "agent.handoff.accepted",
|
|
47
|
+
handoffId,
|
|
48
|
+
from: current.name,
|
|
49
|
+
to: edge.target.name,
|
|
50
|
+
fromAddress,
|
|
51
|
+
seedCount: seeded.length,
|
|
52
|
+
});
|
|
53
|
+
for (const message of seeded) {
|
|
54
|
+
targetContext.appendMessage(message, { kind: "handoff_seed", handoffId, fromAddress });
|
|
55
|
+
}
|
|
56
|
+
await targetContext.flush();
|
|
57
|
+
await state.store?.flush?.();
|
|
58
|
+
context.record({
|
|
59
|
+
type: "agent.handoff",
|
|
60
|
+
from: current.name,
|
|
61
|
+
to: edge.target.name,
|
|
62
|
+
handoffId,
|
|
63
|
+
toAddress,
|
|
64
|
+
seedCount: seeded.length,
|
|
65
|
+
});
|
|
66
|
+
await context.flush();
|
|
67
|
+
await state.store?.flush?.();
|
|
68
|
+
if (state.store === undefined) {
|
|
69
|
+
emitRunEvent(state, {
|
|
70
|
+
type: "agent.handoff",
|
|
71
|
+
from: current.name,
|
|
72
|
+
to: edge.target.name,
|
|
73
|
+
handoffId,
|
|
74
|
+
fromAddress,
|
|
75
|
+
toAddress,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
state.session.setLiveContext(toAddress, targetContext);
|
|
79
|
+
state.session.setConversationHead({ agentKey: edge.target.name, address: toAddress });
|
|
80
|
+
state.address = toAddress;
|
|
81
|
+
await runInputGuardrails(edge.target.guardrails.input ?? [], {
|
|
82
|
+
agent: edge.target,
|
|
83
|
+
input: targetContext.messages,
|
|
84
|
+
context: runCtxFor(state),
|
|
85
|
+
});
|
|
86
|
+
emitRunEvent(state, { type: "agent.started", agent: edge.target.name, ...(state.parentToolCallId ? { parentToolCallId: state.parentToolCallId } : {}) });
|
|
87
|
+
return { agent: edge.target, context: targetContext };
|
|
88
|
+
}
|
|
89
|
+
/** Handoff destinations are new top-level shards; `/` remains reserved for spawned children. */
|
|
90
|
+
function handoffRootAddress(agentName, handoffId) {
|
|
91
|
+
const suffix = handoffId.startsWith("handoff_") ? handoffId.slice("handoff_".length) : handoffId;
|
|
92
|
+
const slug = toFunctionToolName(agentName).slice(0, 64);
|
|
93
|
+
return `h_${slug}_${suffix}`;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=handoff-executor.js.map
|