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,217 @@
|
|
|
1
|
+
import type { ChatModel } from "../llm/define-model.ts";
|
|
2
|
+
import type { LlmRequest } from "../llm/model.ts";
|
|
3
|
+
import type { AssistantMessage, Message, ToolCall, Usage } from "../protocol/index.ts";
|
|
4
|
+
import type { ConversationContext } from "./context.ts";
|
|
5
|
+
import type { Tool, ToolInputRequest, ToolPlan, ToolResult } from "../tool/types.ts";
|
|
6
|
+
import type { ToolCallSuspension } from "./interruption.ts";
|
|
7
|
+
export type StepStopReason = "tool_use" | "end_turn" | "handoff" | "interrupt" | "max_tokens" | "error" | "aborted";
|
|
8
|
+
export type TerminalStepStopReason = Exclude<StepStopReason, "tool_use">;
|
|
9
|
+
export type TurnStopReason = TerminalStepStopReason;
|
|
10
|
+
/** Per-model-step output guardrail adapter. The agent layer creates this monitor; the loop
|
|
11
|
+
* only feeds it optimistic text deltas and waits for it before sealing the assistant message. */
|
|
12
|
+
export interface OutputGuardrailMonitor {
|
|
13
|
+
/** Child signal aborted when an optimistic streaming check trips. */
|
|
14
|
+
readonly signal: AbortSignal;
|
|
15
|
+
/** Observe a text delta after it has been surfaced to live event consumers. */
|
|
16
|
+
observeTextDelta(delta: string): void;
|
|
17
|
+
/** Discard provisional text when the model retry layer resets the current attempt. */
|
|
18
|
+
reset(): void;
|
|
19
|
+
/** Finish outstanding checks. `runFinal` preserves the old final-output-only semantics. */
|
|
20
|
+
finish(output: string, runFinal: boolean, usage: Usage): Promise<void>;
|
|
21
|
+
/** Settle a check that may have aborted the underlying model stream, surfacing its error. */
|
|
22
|
+
settle(): Promise<void>;
|
|
23
|
+
dispose(): void;
|
|
24
|
+
}
|
|
25
|
+
export interface OutputGuardrailMonitorOptions {
|
|
26
|
+
readonly turnId: string;
|
|
27
|
+
readonly step: number;
|
|
28
|
+
readonly stepId: string;
|
|
29
|
+
readonly signal: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
export type OutputGuardrailMonitorFactory = (options: OutputGuardrailMonitorOptions) => OutputGuardrailMonitor;
|
|
32
|
+
/** A tool call waiting for a permission decision (produced at authorization time —
|
|
33
|
+
* the whole batch suspends before anything runs). */
|
|
34
|
+
export interface PendingApprovalInterrupt {
|
|
35
|
+
readonly kind: "approval";
|
|
36
|
+
readonly toolCallId: string;
|
|
37
|
+
readonly toolName: string;
|
|
38
|
+
readonly approvalRule: string;
|
|
39
|
+
readonly policyName?: string;
|
|
40
|
+
readonly display?: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** A tool call that suspended itself mid-execution via `ctx.suspend` (sibling calls
|
|
43
|
+
* have already completed and are journaled). */
|
|
44
|
+
export interface PendingInputInterrupt {
|
|
45
|
+
readonly kind: "input";
|
|
46
|
+
readonly toolCallId: string;
|
|
47
|
+
readonly toolName: string;
|
|
48
|
+
readonly request: ToolInputRequest;
|
|
49
|
+
/** Continuation state saved by the tool. Internal — stripped from public projections. */
|
|
50
|
+
readonly state?: unknown;
|
|
51
|
+
}
|
|
52
|
+
/** Anything a paused run is waiting on the caller for. */
|
|
53
|
+
export type PendingInterrupt = PendingApprovalInterrupt | PendingInputInterrupt;
|
|
54
|
+
/**
|
|
55
|
+
* Resume payload for re-running an interrupted tool batch: the paused frame's pending
|
|
56
|
+
* entries plus the caller's input answers. Approval answers travel separately (through
|
|
57
|
+
* the authorize hook); this only carries what the tool-call layer itself consumes —
|
|
58
|
+
* which suspended calls may run (`inputAnswers` has their key) and which re-park.
|
|
59
|
+
*/
|
|
60
|
+
export interface BatchResume {
|
|
61
|
+
readonly pending: readonly PendingInterrupt[];
|
|
62
|
+
readonly inputAnswers: Readonly<Record<string, unknown>>;
|
|
63
|
+
}
|
|
64
|
+
export interface HandoffSignal {
|
|
65
|
+
readonly toolName: string;
|
|
66
|
+
readonly toolCallId: string;
|
|
67
|
+
readonly targetAgentName: string;
|
|
68
|
+
readonly args: unknown;
|
|
69
|
+
}
|
|
70
|
+
export interface TurnResult {
|
|
71
|
+
readonly stopReason: TurnStopReason;
|
|
72
|
+
readonly steps: number;
|
|
73
|
+
readonly usage: Usage;
|
|
74
|
+
readonly handoff?: HandoffSignal;
|
|
75
|
+
readonly pending?: readonly PendingInterrupt[];
|
|
76
|
+
readonly suspensions?: readonly ToolCallSuspension[];
|
|
77
|
+
}
|
|
78
|
+
export interface StepHookContext {
|
|
79
|
+
readonly turnId: string;
|
|
80
|
+
readonly stepNumber: number;
|
|
81
|
+
/** Conversation shard for the active root/subagent/workflow frame. */
|
|
82
|
+
readonly address?: string;
|
|
83
|
+
readonly signal: AbortSignal;
|
|
84
|
+
readonly model: ChatModel;
|
|
85
|
+
}
|
|
86
|
+
export interface ContextStepHookContext extends StepHookContext {
|
|
87
|
+
/** Live model-visible history — READONLY. To change history, go through the journaled
|
|
88
|
+
* mutators on `context` (`appendMessage`/`replaceHistory`); mutating this array directly
|
|
89
|
+
* would bypass the journal and silently diverge live state from replay. */
|
|
90
|
+
readonly messages: readonly Message[];
|
|
91
|
+
readonly context: ConversationContext;
|
|
92
|
+
readonly system?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface ToolExecutionHookContext extends StepHookContext {
|
|
95
|
+
readonly toolCall: ToolCall;
|
|
96
|
+
readonly tool?: Tool;
|
|
97
|
+
readonly args: unknown;
|
|
98
|
+
}
|
|
99
|
+
export interface ResolvedToolExecutionHookContext extends ToolExecutionHookContext {
|
|
100
|
+
readonly plan: ToolPlan;
|
|
101
|
+
}
|
|
102
|
+
export interface AuthorizeToolExecutionResult {
|
|
103
|
+
readonly block?: boolean;
|
|
104
|
+
readonly reason?: string;
|
|
105
|
+
readonly syntheticResult?: ToolResult;
|
|
106
|
+
readonly executionMetadata?: unknown;
|
|
107
|
+
readonly interrupt?: PendingApprovalInterrupt;
|
|
108
|
+
}
|
|
109
|
+
export interface PrepareToolExecutionResult extends AuthorizeToolExecutionResult {
|
|
110
|
+
readonly updatedArgs?: unknown;
|
|
111
|
+
/** With `block`: end the turn after this batch instead of feeding the denial back to the
|
|
112
|
+
* model. Ignored unless the call is blocked — a `syntheticResult` carries its own `stopTurn`. */
|
|
113
|
+
readonly terminate?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export interface FinalizeToolResultContext extends ToolExecutionHookContext {
|
|
116
|
+
readonly result: ToolResult;
|
|
117
|
+
}
|
|
118
|
+
export interface AfterStepContext extends ContextStepHookContext {
|
|
119
|
+
readonly usage: Usage;
|
|
120
|
+
readonly stopReason: StepStopReason;
|
|
121
|
+
}
|
|
122
|
+
export interface StoppedStepContext extends StepHookContext {
|
|
123
|
+
readonly usage: Usage;
|
|
124
|
+
readonly stopReason: TerminalStepStopReason;
|
|
125
|
+
}
|
|
126
|
+
export interface BeforeStepResult {
|
|
127
|
+
readonly block?: boolean;
|
|
128
|
+
readonly reason?: string;
|
|
129
|
+
/** Replace the system prompt for THIS step only. Chained across hooks in registration order;
|
|
130
|
+
* the step's own `deps.system` is untouched, so the next step re-resolves from the agent. */
|
|
131
|
+
readonly system?: string;
|
|
132
|
+
}
|
|
133
|
+
/** Context for the once-per-run hook that sees the caller's input before it enters history. */
|
|
134
|
+
export interface BeforeRunContext {
|
|
135
|
+
readonly sessionId: string;
|
|
136
|
+
readonly address: string;
|
|
137
|
+
/** Name of the agent about to run (the conversation head's agent, post-handoff resolution). */
|
|
138
|
+
readonly agent: string;
|
|
139
|
+
readonly signal: AbortSignal;
|
|
140
|
+
readonly input: readonly Message[];
|
|
141
|
+
}
|
|
142
|
+
export interface BeforeRunResult {
|
|
143
|
+
/** Replace the input messages before they are appended + journaled. */
|
|
144
|
+
readonly input?: readonly Message[];
|
|
145
|
+
/**
|
|
146
|
+
* Answer the prompt without running the agent at all: no turn, no model call, nothing
|
|
147
|
+
* journaled. The run settles as `status: "skipped"` carrying `output`. The FIRST hook to
|
|
148
|
+
* claim it wins — later hooks are not consulted, since the run is already decided.
|
|
149
|
+
*/
|
|
150
|
+
readonly handled?: {
|
|
151
|
+
readonly output?: string;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export interface AfterStepResult {
|
|
155
|
+
readonly stopTurn?: boolean;
|
|
156
|
+
}
|
|
157
|
+
export interface BeforeModelRequestContext extends StepHookContext {
|
|
158
|
+
readonly request: LlmRequest;
|
|
159
|
+
readonly context: ConversationContext;
|
|
160
|
+
}
|
|
161
|
+
export interface BeforeModelRequestResult {
|
|
162
|
+
readonly request?: LlmRequest;
|
|
163
|
+
readonly block?: boolean;
|
|
164
|
+
readonly reason?: string;
|
|
165
|
+
}
|
|
166
|
+
export interface AfterModelResponseContext extends StepHookContext {
|
|
167
|
+
readonly request: LlmRequest;
|
|
168
|
+
readonly response: AssistantMessage;
|
|
169
|
+
readonly context: ConversationContext;
|
|
170
|
+
}
|
|
171
|
+
export interface ShouldContinueAfterStopResult {
|
|
172
|
+
readonly continue: boolean;
|
|
173
|
+
}
|
|
174
|
+
/** Context for the step-failure recovery hook. Extends the step-context shape so a claimant
|
|
175
|
+
* (compaction) can act on live history the same way `beforeStep` does. */
|
|
176
|
+
export interface RecoverStepErrorContext extends ContextStepHookContext {
|
|
177
|
+
/** The error the failed step threw (e.g. `APIContextOverflowError`). */
|
|
178
|
+
readonly error: unknown;
|
|
179
|
+
/** 1-based count of recovery attempts within this turn, including this one. */
|
|
180
|
+
readonly attempt: number;
|
|
181
|
+
}
|
|
182
|
+
export interface RecoverStepErrorResult {
|
|
183
|
+
/** `true` claims the error: the loop re-runs the failed step (without consuming its step
|
|
184
|
+
* budget). The claimant must already have changed what made the step fail — a claim that
|
|
185
|
+
* fixed nothing just burns a recovery attempt. */
|
|
186
|
+
readonly recovered: boolean;
|
|
187
|
+
}
|
|
188
|
+
export type BeforeStepHook = (ctx: ContextStepHookContext) => Promise<BeforeStepResult | undefined>;
|
|
189
|
+
export type AfterStepHook = (ctx: AfterStepContext) => Promise<AfterStepResult | void>;
|
|
190
|
+
export type BeforeModelRequestHook = (ctx: BeforeModelRequestContext) => Promise<BeforeModelRequestResult | undefined>;
|
|
191
|
+
export type AfterModelResponseHook = (ctx: AfterModelResponseContext) => Promise<AssistantMessage | undefined>;
|
|
192
|
+
export type PrepareToolExecutionHook = (ctx: ToolExecutionHookContext) => Promise<PrepareToolExecutionResult | undefined>;
|
|
193
|
+
export type AuthorizeToolExecutionHook = (ctx: ResolvedToolExecutionHookContext) => Promise<AuthorizeToolExecutionResult | undefined>;
|
|
194
|
+
export type FinalizeToolResultHook = (ctx: FinalizeToolResultContext) => Promise<ToolResult | undefined>;
|
|
195
|
+
export type ShouldContinueAfterStopHook = (ctx: StoppedStepContext) => Promise<ShouldContinueAfterStopResult | undefined>;
|
|
196
|
+
export type BeforeRunHook = (ctx: BeforeRunContext) => Promise<BeforeRunResult | undefined>;
|
|
197
|
+
/** Consulted when a step THROWS (not when it stops with an error message). First claim wins. */
|
|
198
|
+
export type RecoverStepErrorHook = (ctx: RecoverStepErrorContext) => Promise<RecoverStepErrorResult | undefined>;
|
|
199
|
+
/**
|
|
200
|
+
* `beforeRun` and `shouldContinueAfterStop` are RUN-tier, not step-tier: the capability
|
|
201
|
+
* assembler pulls them out of this bag and the Runner drives them directly (see
|
|
202
|
+
* `AssembledCapabilities`). They live here so a capability declares all of its interception
|
|
203
|
+
* points in one place.
|
|
204
|
+
*/
|
|
205
|
+
export interface LoopHooks {
|
|
206
|
+
beforeRun?: BeforeRunHook;
|
|
207
|
+
beforeStep?: BeforeStepHook;
|
|
208
|
+
afterStep?: AfterStepHook;
|
|
209
|
+
beforeModelRequest?: BeforeModelRequestHook;
|
|
210
|
+
afterModelResponse?: AfterModelResponseHook;
|
|
211
|
+
prepareToolExecution?: PrepareToolExecutionHook;
|
|
212
|
+
authorizeToolExecution?: AuthorizeToolExecutionHook;
|
|
213
|
+
finalizeToolResult?: FinalizeToolResultHook;
|
|
214
|
+
shouldContinueAfterStop?: ShouldContinueAfterStopHook;
|
|
215
|
+
recoverStepError?: RecoverStepErrorHook;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Usage } from "../protocol/index.ts";
|
|
2
|
+
export declare function emptyUsage(): Usage;
|
|
3
|
+
export declare function addUsage(a: Usage, b: Usage): Usage;
|
|
4
|
+
/** Delta between two cumulative usage snapshots, used when a paused child frame resumes. */
|
|
5
|
+
export declare function subtractUsage(total: Usage, previous: Usage): Usage;
|
|
6
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function emptyUsage() {
|
|
2
|
+
return {
|
|
3
|
+
input: 0,
|
|
4
|
+
output: 0,
|
|
5
|
+
cacheRead: 0,
|
|
6
|
+
cacheWrite: 0,
|
|
7
|
+
totalTokens: 0,
|
|
8
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function addUsage(a, b) {
|
|
12
|
+
return {
|
|
13
|
+
input: a.input + b.input,
|
|
14
|
+
output: a.output + b.output,
|
|
15
|
+
cacheRead: a.cacheRead + b.cacheRead,
|
|
16
|
+
cacheWrite: a.cacheWrite + b.cacheWrite,
|
|
17
|
+
totalTokens: a.totalTokens + b.totalTokens,
|
|
18
|
+
cost: {
|
|
19
|
+
input: a.cost.input + b.cost.input,
|
|
20
|
+
output: a.cost.output + b.cost.output,
|
|
21
|
+
cacheRead: a.cost.cacheRead + b.cost.cacheRead,
|
|
22
|
+
cacheWrite: a.cost.cacheWrite + b.cost.cacheWrite,
|
|
23
|
+
total: a.cost.total + b.cost.total,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** Delta between two cumulative usage snapshots, used when a paused child frame resumes. */
|
|
28
|
+
export function subtractUsage(total, previous) {
|
|
29
|
+
return {
|
|
30
|
+
input: Math.max(0, total.input - previous.input),
|
|
31
|
+
output: Math.max(0, total.output - previous.output),
|
|
32
|
+
cacheRead: Math.max(0, total.cacheRead - previous.cacheRead),
|
|
33
|
+
cacheWrite: Math.max(0, total.cacheWrite - previous.cacheWrite),
|
|
34
|
+
totalTokens: Math.max(0, total.totalTokens - previous.totalTokens),
|
|
35
|
+
cost: {
|
|
36
|
+
input: Math.max(0, total.cost.input - previous.cost.input),
|
|
37
|
+
output: Math.max(0, total.cost.output - previous.cost.output),
|
|
38
|
+
cacheRead: Math.max(0, total.cost.cacheRead - previous.cost.cacheRead),
|
|
39
|
+
cacheWrite: Math.max(0, total.cost.cacheWrite - previous.cost.cacheWrite),
|
|
40
|
+
total: Math.max(0, total.cost.total - previous.cost.total),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Tool } from "../index.ts";
|
|
2
|
+
import { type McpOAuthService } from "./oauth/index.ts";
|
|
3
|
+
export declare const MCP_OAUTH_AUTHORIZATION_URL_UPDATE = "mcp_oauth_authorization_url";
|
|
4
|
+
export interface CreateMcpAuthToolOptions {
|
|
5
|
+
readonly serverName: string;
|
|
6
|
+
readonly serverUrl: string;
|
|
7
|
+
readonly oauthService: McpOAuthService;
|
|
8
|
+
readonly reconnect: (signal?: AbortSignal) => Promise<void>;
|
|
9
|
+
readonly timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function createMcpAuthTool(options: CreateMcpAuthToolOptions): Tool;
|
|
12
|
+
//# sourceMappingURL=auth-tool.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ToolAccesses } from "../index.js";
|
|
2
|
+
import { qualifyMcpToolName } from "./tool-naming.js";
|
|
3
|
+
import { AlreadyAuthorizedError } from "./oauth/index.js";
|
|
4
|
+
const DEFAULT_AUTH_TIMEOUT_MS = 15 * 60 * 1000; // 15 minutes
|
|
5
|
+
export const MCP_OAUTH_AUTHORIZATION_URL_UPDATE = "mcp_oauth_authorization_url";
|
|
6
|
+
const description = (serverName) => `Authenticate with MCP server "${serverName}" via OAuth.
|
|
7
|
+
|
|
8
|
+
This server requires an OAuth login that has not yet been completed. Calling this tool starts the authorization flow:
|
|
9
|
+
|
|
10
|
+
1. The tool prints an authorization URL.
|
|
11
|
+
2. **You must show that URL to the user verbatim** and ask them to open it in a browser, sign in, and approve the client.
|
|
12
|
+
3. The tool blocks (up to 15 minutes) until the browser redirects back to the local callback listener.
|
|
13
|
+
4. On success, the MCP server reconnects and the real tools replace this synthetic tool.
|
|
14
|
+
|
|
15
|
+
Takes no arguments. Treat the URL as sensitive — do not modify it or strip query parameters.`;
|
|
16
|
+
export function createMcpAuthTool(options) {
|
|
17
|
+
const { serverName, serverUrl, oauthService, reconnect, timeoutMs } = options;
|
|
18
|
+
const name = qualifyMcpToolName(serverName, "authenticate");
|
|
19
|
+
return {
|
|
20
|
+
schema: {
|
|
21
|
+
name,
|
|
22
|
+
description: description(serverName),
|
|
23
|
+
parameters: { type: "object", properties: {} },
|
|
24
|
+
},
|
|
25
|
+
resolve: () => ({
|
|
26
|
+
approvalRule: name,
|
|
27
|
+
accesses: ToolAccesses.all(),
|
|
28
|
+
display: { kind: "mcp_oauth", title: name, detail: `Authenticate ${serverName}` },
|
|
29
|
+
run: async (ctx) => {
|
|
30
|
+
const { signal, onUpdate } = ctx;
|
|
31
|
+
signal.throwIfAborted();
|
|
32
|
+
onUpdate?.({ kind: "status", text: `Discovering OAuth metadata for ${serverName}…` });
|
|
33
|
+
let flow;
|
|
34
|
+
try {
|
|
35
|
+
flow = await oauthService.beginAuthorization(serverName, serverUrl);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof AlreadyAuthorizedError) {
|
|
39
|
+
onUpdate?.({ kind: "status", text: `Already authorized; reconnecting ${serverName}…` });
|
|
40
|
+
try {
|
|
41
|
+
await reconnect(signal);
|
|
42
|
+
}
|
|
43
|
+
catch (reconnectError) {
|
|
44
|
+
return errorResult(serverName, reconnectError);
|
|
45
|
+
}
|
|
46
|
+
return textResult(`MCP server "${serverName}" already had valid OAuth credentials. Reconnected; real tools are available now.`);
|
|
47
|
+
}
|
|
48
|
+
return errorResult(serverName, error);
|
|
49
|
+
}
|
|
50
|
+
const urlText = flow.authorizationUrl.toString();
|
|
51
|
+
onUpdate?.({
|
|
52
|
+
kind: "custom",
|
|
53
|
+
customKind: MCP_OAUTH_AUTHORIZATION_URL_UPDATE,
|
|
54
|
+
customData: { serverName, authorizationUrl: urlText },
|
|
55
|
+
});
|
|
56
|
+
onUpdate?.({
|
|
57
|
+
kind: "status",
|
|
58
|
+
text: `Open this URL in your browser to authorize "${serverName}":\n\n${urlText}\n\n` +
|
|
59
|
+
`Waiting for the OAuth callback (timeout 15 min). If you cancel, call this tool again to restart.`,
|
|
60
|
+
});
|
|
61
|
+
try {
|
|
62
|
+
await flow.complete({ signal, timeoutMs: timeoutMs ?? DEFAULT_AUTH_TIMEOUT_MS });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return errorResult(serverName, error, urlText);
|
|
66
|
+
}
|
|
67
|
+
onUpdate?.({ kind: "status", text: `Authorized — reconnecting ${serverName}…` });
|
|
68
|
+
try {
|
|
69
|
+
await reconnect(signal);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return errorResult(serverName, error);
|
|
73
|
+
}
|
|
74
|
+
return textResult(`MCP server "${serverName}" authenticated successfully. The real MCP tools have replaced this synthetic authenticate tool.`);
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function textResult(text) {
|
|
80
|
+
return { content: [{ type: "text", text }] };
|
|
81
|
+
}
|
|
82
|
+
function errorResult(serverName, error, authorizationUrl) {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
const suffix = authorizationUrl !== undefined
|
|
85
|
+
? `\n\nAuthorization URL (still valid if the listener has not timed out): ${authorizationUrl}`
|
|
86
|
+
: "";
|
|
87
|
+
return {
|
|
88
|
+
isError: true,
|
|
89
|
+
content: [{ type: "text", text: `OAuth flow for MCP server "${serverName}" did not complete: ${message}${suffix}` }],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=auth-tool.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Capability } from "../index.ts";
|
|
2
|
+
import type { MCPServer } from "./server.ts";
|
|
3
|
+
export interface MCPCapabilityOptions {
|
|
4
|
+
readonly injectResources?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function mcpCapability(servers: readonly MCPServer[], options?: MCPCapabilityOptions): Capability;
|
|
7
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BoundaryInjector } from "../index.js";
|
|
2
|
+
import { hasResources } from "./server.js";
|
|
3
|
+
import { mcpToolProvider } from "./provider.js";
|
|
4
|
+
class McpResourcesInjector extends BoundaryInjector {
|
|
5
|
+
id = "mcp_resources";
|
|
6
|
+
getResources;
|
|
7
|
+
constructor(getResources) {
|
|
8
|
+
super();
|
|
9
|
+
this.getResources = getResources;
|
|
10
|
+
}
|
|
11
|
+
getInjection(ctx) {
|
|
12
|
+
if (this.restoreInjectedAt(ctx, ["mcp_resources"]))
|
|
13
|
+
return null;
|
|
14
|
+
const resources = this.getResources();
|
|
15
|
+
if (resources.length === 0)
|
|
16
|
+
return null;
|
|
17
|
+
const lines = ["Available MCP resources (read via the server's resource tools):"];
|
|
18
|
+
for (const r of resources) {
|
|
19
|
+
lines.push(`- ${r.uri}${r.name ? ` (${r.name})` : ""}${r.mimeType ? ` [${r.mimeType}]` : ""} — server "${r.server}"`);
|
|
20
|
+
}
|
|
21
|
+
return { text: lines.join("\n"), variant: "mcp_resources" };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function mcpCapability(servers, options = {}) {
|
|
25
|
+
let resources = [];
|
|
26
|
+
const capability = {
|
|
27
|
+
name: "mcp",
|
|
28
|
+
toolProviders: servers.map((server) => mcpToolProvider(server)),
|
|
29
|
+
service: servers,
|
|
30
|
+
...(options.injectResources ? { injectors: [new McpResourcesInjector(() => resources)] } : {}),
|
|
31
|
+
// Connect every server in parallel, fault-isolated — session open would otherwise cost
|
|
32
|
+
// the SUM of each server's startup (matching `mcpServersCapability`, which already does).
|
|
33
|
+
openSession: async (ctx) => {
|
|
34
|
+
const perServer = await Promise.all(servers.map(async (server) => {
|
|
35
|
+
try {
|
|
36
|
+
await server.connect();
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const tail = server.stderrSnapshot?.().trimEnd();
|
|
40
|
+
const base = error instanceof Error ? error.message : String(error);
|
|
41
|
+
ctx.events?.emit({
|
|
42
|
+
type: "warning",
|
|
43
|
+
address: "main",
|
|
44
|
+
sessionId: ctx.sessionId,
|
|
45
|
+
message: `MCP server "${server.name}" failed to connect: ${base}${tail ? `\nstderr: ${tail}` : ""}`,
|
|
46
|
+
});
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
// Watch for a self-initiated drop after a clean connect (subprocess crash / HTTP
|
|
50
|
+
// give-up): warn so the user knows the server's tools have gone absent mid-session.
|
|
51
|
+
server.onUnexpectedClose?.((reason) => {
|
|
52
|
+
const parts = [`MCP server "${server.name}" closed unexpectedly`];
|
|
53
|
+
if (reason.error !== undefined)
|
|
54
|
+
parts.push(reason.error.message);
|
|
55
|
+
if (reason.stderr !== undefined && reason.stderr.length > 0)
|
|
56
|
+
parts.push(`stderr: ${reason.stderr.trimEnd()}`);
|
|
57
|
+
ctx.events?.emit({ type: "warning", address: "main", sessionId: ctx.sessionId, message: parts.join("\n") });
|
|
58
|
+
});
|
|
59
|
+
if (!options.injectResources || !hasResources(server))
|
|
60
|
+
return [];
|
|
61
|
+
try {
|
|
62
|
+
const list = await server.listResources();
|
|
63
|
+
return list.resources.map((r) => ({
|
|
64
|
+
server: server.name,
|
|
65
|
+
uri: r.uri,
|
|
66
|
+
...(r.name !== undefined ? { name: r.name } : {}),
|
|
67
|
+
...(r.mimeType !== undefined ? { mimeType: r.mimeType } : {}),
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// resources are optional context; a failure here never blocks tools.
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
// Flattened in `servers` order, so the injected listing doesn't reshuffle per run.
|
|
76
|
+
resources = perServer.flat();
|
|
77
|
+
},
|
|
78
|
+
closeSession: async () => {
|
|
79
|
+
for (const server of [...servers].reverse()) {
|
|
80
|
+
try {
|
|
81
|
+
await server.close();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// best-effort teardown; the assembler already guards + times out stop().
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
return capability;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=capability.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Machine } from "../index.ts";
|
|
2
|
+
import { type McpServerConfig } from "../config/schema.ts";
|
|
3
|
+
export declare function loadProjectMcpServers(machine: Machine, cwd: string): Promise<Record<string, McpServerConfig>>;
|
|
4
|
+
export type McpConfigTier = "user" | "project" | "local";
|
|
5
|
+
export interface McpConfigLayerOptions {
|
|
6
|
+
/** Working directory the project root is discovered from. Defaults to the machine cwd. */
|
|
7
|
+
readonly cwd?: string;
|
|
8
|
+
/** User-tier directory. Defaults to `<machine home>/.<appName>`. */
|
|
9
|
+
readonly homeDir?: string;
|
|
10
|
+
readonly appName?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface McpConfigLayer {
|
|
13
|
+
readonly tier: McpConfigTier;
|
|
14
|
+
readonly files: readonly string[];
|
|
15
|
+
readonly loaded: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LoadedMcpServers {
|
|
18
|
+
readonly servers: Record<string, McpServerConfig>;
|
|
19
|
+
readonly layers: readonly McpConfigLayer[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Load MCP servers across three tiers, low → high precedence (a later tier overrides a
|
|
23
|
+
* same-named server): user (`~/.<app>/mcp.json`) < project (`<root>/mcp.json` + `.mcp.json`)
|
|
24
|
+
* < local (`<root>/mcp.local.json` + `.mcp.local.json`). Stdio `cwd` is resolved against the
|
|
25
|
+
* project root. The interop `mcp.json` stays JSON (own config is TOML — see ConfigStore).
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadMcpServers(machine: Machine, options?: McpConfigLayerOptions): Promise<LoadedMcpServers>;
|
|
28
|
+
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { McpServerConfigSchema } from "../config/schema.js";
|
|
4
|
+
import { readTextFile } from "../tool/support/machine-ops.js";
|
|
5
|
+
const PROJECT_MCP_FILENAMES = ["mcp.json", ".mcp.json"];
|
|
6
|
+
const McpJsonFileSchema = z.object({
|
|
7
|
+
mcpServers: z.record(z.string(), McpServerConfigSchema).default({}),
|
|
8
|
+
});
|
|
9
|
+
async function findProjectRoot(machine, cwd) {
|
|
10
|
+
let current = machine.normpath(cwd);
|
|
11
|
+
// Bounded by reaching the filesystem root (dirname fixpoint).
|
|
12
|
+
for (;;) {
|
|
13
|
+
if (await pathExists(machine, path.join(current, ".git")))
|
|
14
|
+
return current;
|
|
15
|
+
const parent = path.dirname(current);
|
|
16
|
+
if (parent === current)
|
|
17
|
+
return machine.normpath(cwd);
|
|
18
|
+
current = parent;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function pathExists(machine, p) {
|
|
22
|
+
try {
|
|
23
|
+
await machine.fileInfo(p);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function loadProjectMcpServers(machine, cwd) {
|
|
31
|
+
const root = await findProjectRoot(machine, cwd);
|
|
32
|
+
const merged = {};
|
|
33
|
+
for (const filename of PROJECT_MCP_FILENAMES) {
|
|
34
|
+
const file = path.join(root, filename);
|
|
35
|
+
const parsed = await readMcpJsonFile(machine, file);
|
|
36
|
+
if (parsed === undefined)
|
|
37
|
+
continue;
|
|
38
|
+
Object.assign(merged, parsed.mcpServers);
|
|
39
|
+
}
|
|
40
|
+
return normalizeStdioCwd(merged, root);
|
|
41
|
+
}
|
|
42
|
+
const LOCAL_MCP_FILENAMES = ["mcp.local.json", ".mcp.local.json"];
|
|
43
|
+
/**
|
|
44
|
+
* Load MCP servers across three tiers, low → high precedence (a later tier overrides a
|
|
45
|
+
* same-named server): user (`~/.<app>/mcp.json`) < project (`<root>/mcp.json` + `.mcp.json`)
|
|
46
|
+
* < local (`<root>/mcp.local.json` + `.mcp.local.json`). Stdio `cwd` is resolved against the
|
|
47
|
+
* project root. The interop `mcp.json` stays JSON (own config is TOML — see ConfigStore).
|
|
48
|
+
*/
|
|
49
|
+
export async function loadMcpServers(machine, options = {}) {
|
|
50
|
+
const appName = options.appName ?? "agents";
|
|
51
|
+
const cwd = options.cwd ?? machine.getcwd();
|
|
52
|
+
const root = await findProjectRoot(machine, cwd);
|
|
53
|
+
const homeDir = options.homeDir ?? path.join(machine.gethome(), `.${appName}`);
|
|
54
|
+
const tiers = [
|
|
55
|
+
{ tier: "user", files: [path.join(homeDir, "mcp.json"), path.join(homeDir, ".mcp.json")] },
|
|
56
|
+
// Project tier reads the cross-tool `<root>/mcp.json` + `<root>/.mcp.json`, plus the
|
|
57
|
+
// app-namespaced `<root>/.<appName>/mcp.json` (highest precedence within the tier).
|
|
58
|
+
{
|
|
59
|
+
tier: "project",
|
|
60
|
+
files: [...PROJECT_MCP_FILENAMES.map((f) => path.join(root, f)), path.join(root, `.${appName}`, "mcp.json")],
|
|
61
|
+
},
|
|
62
|
+
{ tier: "local", files: LOCAL_MCP_FILENAMES.map((f) => path.join(root, f)) },
|
|
63
|
+
];
|
|
64
|
+
const merged = {};
|
|
65
|
+
const layers = [];
|
|
66
|
+
for (const { tier, files } of tiers) {
|
|
67
|
+
let loaded = false;
|
|
68
|
+
for (const file of files) {
|
|
69
|
+
const parsed = await readMcpJsonFile(machine, file);
|
|
70
|
+
if (parsed === undefined)
|
|
71
|
+
continue;
|
|
72
|
+
Object.assign(merged, parsed.mcpServers);
|
|
73
|
+
loaded = true;
|
|
74
|
+
}
|
|
75
|
+
layers.push({ tier, files, loaded });
|
|
76
|
+
}
|
|
77
|
+
return { servers: normalizeStdioCwd(merged, root), layers };
|
|
78
|
+
}
|
|
79
|
+
async function readMcpJsonFile(machine, file) {
|
|
80
|
+
let text;
|
|
81
|
+
try {
|
|
82
|
+
text = await readTextFile(machine, file);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
if (text.trim().length === 0)
|
|
88
|
+
return undefined;
|
|
89
|
+
let data;
|
|
90
|
+
try {
|
|
91
|
+
data = JSON.parse(text);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`Invalid JSON in ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
95
|
+
}
|
|
96
|
+
return McpJsonFileSchema.parse(data);
|
|
97
|
+
}
|
|
98
|
+
function normalizeStdioCwd(servers, root) {
|
|
99
|
+
const out = {};
|
|
100
|
+
for (const [name, config] of Object.entries(servers)) {
|
|
101
|
+
if (config.transport === "stdio") {
|
|
102
|
+
const cwd = config.cwd === undefined
|
|
103
|
+
? root
|
|
104
|
+
: path.isAbsolute(config.cwd)
|
|
105
|
+
? config.cwd
|
|
106
|
+
: path.resolve(root, config.cwd);
|
|
107
|
+
out[name] = { ...config, cwd };
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
out[name] = config;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=config-loader.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CapabilityContext } from "../index.ts";
|
|
2
|
+
import type { MCPTool } from "./types.ts";
|
|
3
|
+
export interface MCPToolFilterStatic {
|
|
4
|
+
readonly allowedToolNames?: readonly string[];
|
|
5
|
+
readonly blockedToolNames?: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
export interface MCPToolFilterContext {
|
|
8
|
+
readonly serverName: string;
|
|
9
|
+
readonly ctx: CapabilityContext;
|
|
10
|
+
}
|
|
11
|
+
export type MCPToolFilterCallable = (context: MCPToolFilterContext, tool: MCPTool) => boolean | Promise<boolean>;
|
|
12
|
+
export type MCPToolFilter = MCPToolFilterStatic | MCPToolFilterCallable;
|
|
13
|
+
export declare function createMCPToolStaticFilter(options?: {
|
|
14
|
+
allowed?: readonly string[];
|
|
15
|
+
blocked?: readonly string[];
|
|
16
|
+
}): MCPToolFilterStatic | undefined;
|
|
17
|
+
export declare function applyMcpToolFilter(filter: MCPToolFilter | undefined, tools: readonly MCPTool[], context: MCPToolFilterContext): Promise<MCPTool[]>;
|
|
18
|
+
//# sourceMappingURL=filter.d.ts.map
|