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,35 @@
|
|
|
1
|
+
export function createMCPToolStaticFilter(options) {
|
|
2
|
+
if (!options?.allowed && !options?.blocked)
|
|
3
|
+
return undefined;
|
|
4
|
+
const filter = {};
|
|
5
|
+
if (options.allowed)
|
|
6
|
+
filter.allowedToolNames = options.allowed;
|
|
7
|
+
if (options.blocked)
|
|
8
|
+
filter.blockedToolNames = options.blocked;
|
|
9
|
+
return filter;
|
|
10
|
+
}
|
|
11
|
+
function isCallable(filter) {
|
|
12
|
+
return typeof filter === "function";
|
|
13
|
+
}
|
|
14
|
+
export async function applyMcpToolFilter(filter, tools, context) {
|
|
15
|
+
if (filter === undefined)
|
|
16
|
+
return [...tools];
|
|
17
|
+
if (isCallable(filter)) {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const tool of tools) {
|
|
20
|
+
if (await filter(context, tool))
|
|
21
|
+
out.push(tool);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
const allowed = filter.allowedToolNames;
|
|
26
|
+
const blocked = filter.blockedToolNames;
|
|
27
|
+
return tools.filter((tool) => {
|
|
28
|
+
if (allowed && !allowed.includes(tool.name))
|
|
29
|
+
return false;
|
|
30
|
+
if (blocked && blocked.includes(tool.name))
|
|
31
|
+
return false;
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type { MCPServer, MCPServerWithResources, MCPServerOptions, MCPToolErrorFunction } from "./server.ts";
|
|
2
|
+
export { TransportMCPServer, hasResources, withTimeout, DEFAULT_MCP_STARTUP_TIMEOUT_MS } from "./server.ts";
|
|
3
|
+
export type { MCPTool, MCPToolResult, MCPContentBlock, MCPResource, MCPResourceContent, MCPListResourcesResult, MCPReadResourceResult, MCPCallToolOptions, MCPPingOptions, MCPTransport, UnexpectedCloseReason, UnexpectedCloseListener, } from "./types.ts";
|
|
4
|
+
export type { MCPToolFilter, MCPToolFilterStatic, MCPToolFilterCallable, MCPToolFilterContext } from "./filter.ts";
|
|
5
|
+
export { applyMcpToolFilter, createMCPToolStaticFilter } from "./filter.ts";
|
|
6
|
+
export { qualifyMcpToolName, sanitizeMcpNamePart, isMcpToolName } from "./tool-naming.ts";
|
|
7
|
+
export { convertMcpContentBlock, mcpResultToContent, MCP_MAX_OUTPUT_CHARS, MCP_MAX_IMAGE_PART_BYTES } from "./output.ts";
|
|
8
|
+
export { mcpToolProvider, wrapMcpTool } from "./provider.ts";
|
|
9
|
+
export { mcpCapability } from "./capability.ts";
|
|
10
|
+
export type { MCPCapabilityOptions } from "./capability.ts";
|
|
11
|
+
export { serverFromConfig, mcpServersCapability, DEFAULT_RECONNECT_POLICY } from "./manager.ts";
|
|
12
|
+
export type { McpServerStatus, McpServerView, McpServersHandle, McpServersCapabilityOptions, ServerFromConfigOptions, McpTransportFactory, McpStatusListener, ReconnectPolicy, KeepAlivePolicy, McpTimer, } from "./manager.ts";
|
|
13
|
+
export { createMcpAuthTool, MCP_OAUTH_AUTHORIZATION_URL_UPDATE } from "./auth-tool.ts";
|
|
14
|
+
export type { CreateMcpAuthToolOptions } from "./auth-tool.ts";
|
|
15
|
+
export { MockMCPTransport } from "./mock-transport.ts";
|
|
16
|
+
export type { MockMCPFixture, MockMCPResource } from "./mock-transport.ts";
|
|
17
|
+
export { mcpStdioTransport, mcpStreamableHttpTransport, mergeStdioEnv, isTerminalTransportError, buildMcpHttpHeaders, } from "./sdk-transport.ts";
|
|
18
|
+
export type { MCPStdioConfig, MCPHttpConfig } from "./sdk-transport.ts";
|
|
19
|
+
export { loadProjectMcpServers, loadMcpServers } from "./config-loader.ts";
|
|
20
|
+
export type { McpConfigTier, McpConfigLayerOptions, McpConfigLayer, LoadedMcpServers } from "./config-loader.ts";
|
|
21
|
+
export { McpOAuthService, McpOAuthClientProvider, AlreadyAuthorizedError, JsonFileStore, MemoryMcpCredentialStore, startCallbackServer, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, mcpOAuthStoreKey, } from "./oauth/index.ts";
|
|
22
|
+
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, McpOAuthProviderOptions, McpCredentialStore, CallbackServer, CallbackResult, } from "./oauth/index.ts";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { TransportMCPServer, hasResources, withTimeout, DEFAULT_MCP_STARTUP_TIMEOUT_MS } from "./server.js";
|
|
2
|
+
export { applyMcpToolFilter, createMCPToolStaticFilter } from "./filter.js";
|
|
3
|
+
export { qualifyMcpToolName, sanitizeMcpNamePart, isMcpToolName } from "./tool-naming.js";
|
|
4
|
+
export { convertMcpContentBlock, mcpResultToContent, MCP_MAX_OUTPUT_CHARS, MCP_MAX_IMAGE_PART_BYTES } from "./output.js";
|
|
5
|
+
export { mcpToolProvider, wrapMcpTool } from "./provider.js";
|
|
6
|
+
export { mcpCapability } from "./capability.js";
|
|
7
|
+
export { serverFromConfig, mcpServersCapability, DEFAULT_RECONNECT_POLICY } from "./manager.js";
|
|
8
|
+
export { createMcpAuthTool, MCP_OAUTH_AUTHORIZATION_URL_UPDATE } from "./auth-tool.js";
|
|
9
|
+
export { MockMCPTransport } from "./mock-transport.js";
|
|
10
|
+
export { mcpStdioTransport, mcpStreamableHttpTransport, mergeStdioEnv, isTerminalTransportError, buildMcpHttpHeaders, } from "./sdk-transport.js";
|
|
11
|
+
export { loadProjectMcpServers, loadMcpServers } from "./config-loader.js";
|
|
12
|
+
export { McpOAuthService, McpOAuthClientProvider, AlreadyAuthorizedError, JsonFileStore, MemoryMcpCredentialStore, startCallbackServer, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, mcpOAuthStoreKey, } from "./oauth/index.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TransportMCPServer } from "./server.ts";
|
|
2
|
+
import type { MCPTransport } from "./types.ts";
|
|
3
|
+
import type { McpOAuthService } from "./oauth/index.ts";
|
|
4
|
+
import type { Capability } from "../index.ts";
|
|
5
|
+
import type { McpServerConfig } from "../config/schema.ts";
|
|
6
|
+
export type McpServerStatus = "pending" | "connected" | "failed" | "disabled" | "needs-auth";
|
|
7
|
+
export interface McpServerView {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly transport: "stdio" | "http";
|
|
10
|
+
readonly status: McpServerStatus;
|
|
11
|
+
readonly error?: string;
|
|
12
|
+
}
|
|
13
|
+
export type McpStatusListener = (view: McpServerView) => void;
|
|
14
|
+
export interface ReconnectPolicy {
|
|
15
|
+
readonly maxRetries: number;
|
|
16
|
+
readonly initialDelayMs: number;
|
|
17
|
+
readonly maxDelayMs: number;
|
|
18
|
+
readonly factor: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_RECONNECT_POLICY: ReconnectPolicy;
|
|
21
|
+
export interface KeepAlivePolicy {
|
|
22
|
+
readonly intervalMs: number;
|
|
23
|
+
readonly timeoutMs?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface McpTimer {
|
|
26
|
+
setTimeout(fn: () => void, ms: number): unknown;
|
|
27
|
+
clearTimeout(handle: unknown): void;
|
|
28
|
+
}
|
|
29
|
+
export type McpTransportFactory = (name: string, config: McpServerConfig) => MCPTransport;
|
|
30
|
+
export interface ServerFromConfigOptions {
|
|
31
|
+
readonly oauthService?: McpOAuthService;
|
|
32
|
+
readonly cacheToolsList?: boolean;
|
|
33
|
+
readonly transport?: MCPTransport;
|
|
34
|
+
}
|
|
35
|
+
export declare function serverFromConfig(name: string, config: McpServerConfig, opts?: ServerFromConfigOptions): TransportMCPServer;
|
|
36
|
+
export interface McpServersCapabilityOptions {
|
|
37
|
+
readonly oauthService?: McpOAuthService;
|
|
38
|
+
readonly cacheToolsList?: boolean;
|
|
39
|
+
readonly transportFactory?: McpTransportFactory;
|
|
40
|
+
readonly reconnectPolicy?: ReconnectPolicy;
|
|
41
|
+
readonly keepAlive?: KeepAlivePolicy;
|
|
42
|
+
readonly timer?: McpTimer;
|
|
43
|
+
}
|
|
44
|
+
export interface McpServersHandle {
|
|
45
|
+
list(): readonly McpServerView[];
|
|
46
|
+
reconnect(name: string): Promise<void>;
|
|
47
|
+
onStatusChange(listener: McpStatusListener): () => void;
|
|
48
|
+
shutdown(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare function mcpServersCapability(configs: Record<string, McpServerConfig>, options?: McpServersCapabilityOptions): Capability;
|
|
51
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { TransportMCPServer } from "./server.js";
|
|
2
|
+
import { mcpStdioTransport, mcpStreamableHttpTransport } from "./sdk-transport.js";
|
|
3
|
+
import { mcpToolProvider } from "./provider.js";
|
|
4
|
+
import { qualifyMcpToolName } from "./tool-naming.js";
|
|
5
|
+
import { createMcpAuthTool } from "./auth-tool.js";
|
|
6
|
+
export const DEFAULT_RECONNECT_POLICY = {
|
|
7
|
+
maxRetries: 5,
|
|
8
|
+
initialDelayMs: 1000,
|
|
9
|
+
maxDelayMs: 30_000,
|
|
10
|
+
factor: 2,
|
|
11
|
+
};
|
|
12
|
+
const REAL_TIMER = {
|
|
13
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
|
14
|
+
clearTimeout: (handle) => clearTimeout(handle),
|
|
15
|
+
};
|
|
16
|
+
const DEFAULT_CACHE_TOOLS = true;
|
|
17
|
+
export function serverFromConfig(name, config, opts = {}) {
|
|
18
|
+
const transport = opts.transport ?? transportFromConfig(name, config, opts.oauthService);
|
|
19
|
+
const filter = staticFilterFromConfig(config);
|
|
20
|
+
return new TransportMCPServer({
|
|
21
|
+
name,
|
|
22
|
+
transport,
|
|
23
|
+
cacheToolsList: opts.cacheToolsList ?? DEFAULT_CACHE_TOOLS,
|
|
24
|
+
...(filter !== undefined ? { toolFilter: filter } : {}),
|
|
25
|
+
...(config.startupTimeoutMs !== undefined ? { startupTimeoutMs: config.startupTimeoutMs } : {}),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function staticFilterFromConfig(config) {
|
|
29
|
+
const allowed = config.allowedTools;
|
|
30
|
+
const blocked = config.blockedTools;
|
|
31
|
+
if (allowed === undefined && blocked === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
return {
|
|
34
|
+
...(allowed !== undefined ? { allowedToolNames: allowed } : {}),
|
|
35
|
+
...(blocked !== undefined ? { blockedToolNames: blocked } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function transportFromConfig(name, config, oauthService) {
|
|
39
|
+
if (config.transport === "stdio") {
|
|
40
|
+
if (config.command === undefined)
|
|
41
|
+
throw new Error(`MCP server "${name}": stdio transport requires "command".`);
|
|
42
|
+
return mcpStdioTransport({
|
|
43
|
+
name,
|
|
44
|
+
command: config.command,
|
|
45
|
+
...(config.args !== undefined ? { args: config.args } : {}),
|
|
46
|
+
...(config.env !== undefined ? { env: config.env } : {}),
|
|
47
|
+
...(config.cwd !== undefined ? { cwd: config.cwd } : {}),
|
|
48
|
+
...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (config.url === undefined)
|
|
52
|
+
throw new Error(`MCP server "${name}": http transport requires "url".`);
|
|
53
|
+
const oauthProvider = resolveOAuthProvider(name, config, oauthService);
|
|
54
|
+
return mcpStreamableHttpTransport({
|
|
55
|
+
name,
|
|
56
|
+
url: config.url,
|
|
57
|
+
...(config.headers !== undefined ? { headers: config.headers } : {}),
|
|
58
|
+
...(config.bearerTokenEnvVar !== undefined ? { bearerTokenEnvVar: config.bearerTokenEnvVar } : {}),
|
|
59
|
+
...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
|
|
60
|
+
...(oauthProvider !== undefined ? { oauthProvider } : {}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function resolveOAuthProvider(name, config, oauthService) {
|
|
64
|
+
if (oauthService === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
if (config.transport !== "http")
|
|
67
|
+
return undefined;
|
|
68
|
+
if (config.bearerTokenEnvVar !== undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
if (config.headers !== undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
if (config.url === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
if (!oauthService.hasTokens(name, config.url))
|
|
75
|
+
return undefined;
|
|
76
|
+
return oauthService.getProvider(name, config.url);
|
|
77
|
+
}
|
|
78
|
+
function isUnauthorizedLikeError(error) {
|
|
79
|
+
if (!(error instanceof Error))
|
|
80
|
+
return false;
|
|
81
|
+
if (error.name === "UnauthorizedError")
|
|
82
|
+
return true;
|
|
83
|
+
const code = error.code;
|
|
84
|
+
if (typeof code === "number" && code === 401)
|
|
85
|
+
return true;
|
|
86
|
+
if (typeof code === "string" && code === "401")
|
|
87
|
+
return true;
|
|
88
|
+
return /\b401\b/.test(error.message) || /unauthorized/i.test(error.message);
|
|
89
|
+
}
|
|
90
|
+
class McpServerController {
|
|
91
|
+
name;
|
|
92
|
+
config;
|
|
93
|
+
oauthService;
|
|
94
|
+
cacheToolsList;
|
|
95
|
+
transportFactory;
|
|
96
|
+
onStatusChange;
|
|
97
|
+
reconnectPolicy;
|
|
98
|
+
keepAlivePolicy;
|
|
99
|
+
timer;
|
|
100
|
+
server;
|
|
101
|
+
authTool;
|
|
102
|
+
ctx;
|
|
103
|
+
_status = "pending";
|
|
104
|
+
_error;
|
|
105
|
+
reconnectAttempts = 0;
|
|
106
|
+
reconnectHandle;
|
|
107
|
+
keepAliveHandle;
|
|
108
|
+
disposed = false;
|
|
109
|
+
constructor(opts) {
|
|
110
|
+
this.name = opts.name;
|
|
111
|
+
this.config = opts.config;
|
|
112
|
+
this.oauthService = opts.oauthService;
|
|
113
|
+
this.cacheToolsList = opts.cacheToolsList;
|
|
114
|
+
this.transportFactory = opts.transportFactory;
|
|
115
|
+
this.onStatusChange = opts.onStatusChange;
|
|
116
|
+
this.reconnectPolicy = opts.reconnectPolicy;
|
|
117
|
+
this.keepAlivePolicy = opts.keepAlivePolicy;
|
|
118
|
+
this.timer = opts.timer;
|
|
119
|
+
}
|
|
120
|
+
view() {
|
|
121
|
+
return {
|
|
122
|
+
name: this.name,
|
|
123
|
+
transport: this.config.transport,
|
|
124
|
+
status: this._status,
|
|
125
|
+
...(this._error !== undefined ? { error: this._error } : {}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
setStatus(status, error) {
|
|
129
|
+
if (status === this._status && error === this._error)
|
|
130
|
+
return;
|
|
131
|
+
this._status = status;
|
|
132
|
+
this._error = error;
|
|
133
|
+
this.onStatusChange?.(this.view());
|
|
134
|
+
}
|
|
135
|
+
async connect(ctx) {
|
|
136
|
+
if (this.disposed)
|
|
137
|
+
return;
|
|
138
|
+
this.ctx = ctx;
|
|
139
|
+
if (this.config.enabled === false) {
|
|
140
|
+
this.setStatus("disabled");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
await this.attempt();
|
|
144
|
+
}
|
|
145
|
+
async attempt() {
|
|
146
|
+
// Attempts can overlap: a manual reconnect() can fire while an in-flight attempt is still
|
|
147
|
+
// awaiting connect(). Every mutation of the shared `this.server` slot is therefore guarded
|
|
148
|
+
// by identity — an attempt only ever publishes/retracts the server IT created, never a
|
|
149
|
+
// sibling's. Without this, a losing attempt's cleanup would tear down the winner's live
|
|
150
|
+
// connection (and a stale connect() success would leak an orphaned server/child process).
|
|
151
|
+
let server;
|
|
152
|
+
try {
|
|
153
|
+
server = serverFromConfig(this.name, this.config, {
|
|
154
|
+
...(this.oauthService !== undefined ? { oauthService: this.oauthService } : {}),
|
|
155
|
+
cacheToolsList: this.cacheToolsList,
|
|
156
|
+
...(this.transportFactory !== undefined ? { transport: this.transportFactory(this.name, this.config) } : {}),
|
|
157
|
+
});
|
|
158
|
+
const mine = server;
|
|
159
|
+
this.server = mine;
|
|
160
|
+
// Guard the drop callback by identity (mirrors runKeepAlivePing): a stale close from
|
|
161
|
+
// THIS server must not null out a newer server that has since replaced it.
|
|
162
|
+
mine.onUnexpectedClose?.((reason) => {
|
|
163
|
+
if (this.server === mine)
|
|
164
|
+
this.onDrop(reason);
|
|
165
|
+
});
|
|
166
|
+
await mine.connect();
|
|
167
|
+
if (this.server !== mine) {
|
|
168
|
+
// A newer attempt superseded us mid-connect — don't leak this now-orphaned connection.
|
|
169
|
+
await mine.close().catch(() => undefined);
|
|
170
|
+
return this._status;
|
|
171
|
+
}
|
|
172
|
+
this.reconnectAttempts = 0;
|
|
173
|
+
this.setStatus("connected");
|
|
174
|
+
this.scheduleKeepAlive();
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
// React only if we're still the current attempt; a superseding attempt owns the state.
|
|
178
|
+
const current = this.server === server || this.server === undefined;
|
|
179
|
+
if (current) {
|
|
180
|
+
this.cancelKeepAlive();
|
|
181
|
+
if (this.shouldMarkNeedsAuth(error)) {
|
|
182
|
+
this.setStatus("needs-auth", `${this.name} requires OAuth — call the "${qualifyMcpToolName(this.name, "authenticate")}" tool`);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
const tail = server?.stderrSnapshot?.().trimEnd();
|
|
186
|
+
const base = error instanceof Error ? error.message : String(error);
|
|
187
|
+
this.setStatus("failed", tail ? `${base}\nstderr: ${tail}` : base);
|
|
188
|
+
this.emitWarning(`MCP server "${this.name}" failed to connect: ${this._error}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Close the server WE created (not this.server, which may be a newer winner), and only
|
|
192
|
+
// release the shared slot when it still points at ours.
|
|
193
|
+
await server?.close().catch(() => undefined);
|
|
194
|
+
if (this.server === server)
|
|
195
|
+
this.server = undefined;
|
|
196
|
+
}
|
|
197
|
+
return this._status;
|
|
198
|
+
}
|
|
199
|
+
async reconnect() {
|
|
200
|
+
if (this.disposed)
|
|
201
|
+
throw new Error(`MCP server "${this.name}" has been shut down.`);
|
|
202
|
+
this.cancelScheduledReconnect();
|
|
203
|
+
this.cancelKeepAlive();
|
|
204
|
+
this.reconnectAttempts = 0;
|
|
205
|
+
await this.server?.close().catch(() => undefined);
|
|
206
|
+
this.server = undefined;
|
|
207
|
+
this.setStatus("pending");
|
|
208
|
+
const status = await this.attempt();
|
|
209
|
+
if (status !== "connected") {
|
|
210
|
+
throw new Error(this._error ?? `MCP server "${this.name}" failed to reconnect.`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async close() {
|
|
214
|
+
this.cancelScheduledReconnect();
|
|
215
|
+
this.cancelKeepAlive();
|
|
216
|
+
await this.server?.close().catch(() => undefined);
|
|
217
|
+
this.server = undefined;
|
|
218
|
+
}
|
|
219
|
+
async dispose() {
|
|
220
|
+
this.disposed = true;
|
|
221
|
+
await this.close();
|
|
222
|
+
}
|
|
223
|
+
toolProvider() {
|
|
224
|
+
return {
|
|
225
|
+
id: `mcp:${this.name}`,
|
|
226
|
+
listTools: async (ctx) => {
|
|
227
|
+
if (this._status === "needs-auth")
|
|
228
|
+
return [this.authToolInstance()];
|
|
229
|
+
if (this._status !== "connected" || this.server === undefined)
|
|
230
|
+
return [];
|
|
231
|
+
return mcpToolProvider(this.server).listTools(ctx);
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
shouldMarkNeedsAuth(error) {
|
|
236
|
+
if (this.oauthService === undefined)
|
|
237
|
+
return false;
|
|
238
|
+
if (this.config.transport !== "http")
|
|
239
|
+
return false;
|
|
240
|
+
if (this.config.bearerTokenEnvVar !== undefined)
|
|
241
|
+
return false;
|
|
242
|
+
if (this.config.headers !== undefined)
|
|
243
|
+
return false;
|
|
244
|
+
return isUnauthorizedLikeError(error);
|
|
245
|
+
}
|
|
246
|
+
authToolInstance() {
|
|
247
|
+
if (this.authTool === undefined) {
|
|
248
|
+
if (this.oauthService === undefined || this.config.url === undefined) {
|
|
249
|
+
throw new Error(`MCP server "${this.name}" is in needs-auth without an OAuth service / url.`);
|
|
250
|
+
}
|
|
251
|
+
this.authTool = createMcpAuthTool({
|
|
252
|
+
serverName: this.name,
|
|
253
|
+
serverUrl: this.config.url,
|
|
254
|
+
oauthService: this.oauthService,
|
|
255
|
+
reconnect: () => this.reconnect(),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return this.authTool;
|
|
259
|
+
}
|
|
260
|
+
onDrop(reason) {
|
|
261
|
+
this.cancelKeepAlive();
|
|
262
|
+
const parts = [`MCP server "${this.name}" closed unexpectedly`];
|
|
263
|
+
if (reason.error !== undefined)
|
|
264
|
+
parts.push(reason.error.message);
|
|
265
|
+
if (reason.stderr !== undefined && reason.stderr.length > 0)
|
|
266
|
+
parts.push(`stderr: ${reason.stderr.trimEnd()}`);
|
|
267
|
+
this.setStatus("failed", parts.join("\n"));
|
|
268
|
+
this.emitWarning(this._error);
|
|
269
|
+
this.server = undefined;
|
|
270
|
+
this.scheduleReconnect();
|
|
271
|
+
}
|
|
272
|
+
scheduleKeepAlive() {
|
|
273
|
+
this.cancelKeepAlive();
|
|
274
|
+
const policy = this.keepAlivePolicy;
|
|
275
|
+
if (policy === undefined || this.disposed)
|
|
276
|
+
return;
|
|
277
|
+
if (this.server === undefined || this._status !== "connected")
|
|
278
|
+
return;
|
|
279
|
+
this.keepAliveHandle = this.timer.setTimeout(() => {
|
|
280
|
+
this.keepAliveHandle = undefined;
|
|
281
|
+
void this.runKeepAlivePing();
|
|
282
|
+
}, policy.intervalMs);
|
|
283
|
+
}
|
|
284
|
+
async runKeepAlivePing() {
|
|
285
|
+
const server = this.server;
|
|
286
|
+
const policy = this.keepAlivePolicy;
|
|
287
|
+
if (this.disposed || policy === undefined || server === undefined || this._status !== "connected")
|
|
288
|
+
return;
|
|
289
|
+
try {
|
|
290
|
+
await server.ping({ timeoutMs: policy.timeoutMs });
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
if (this.disposed || this.server !== server)
|
|
294
|
+
return;
|
|
295
|
+
const base = error instanceof Error ? error.message : String(error);
|
|
296
|
+
const message = `MCP server "${this.name}" keep-alive ping failed: ${base}`;
|
|
297
|
+
this.setStatus("failed", message);
|
|
298
|
+
this.emitWarning(message);
|
|
299
|
+
await server.close().catch(() => undefined);
|
|
300
|
+
if (this.server === server)
|
|
301
|
+
this.server = undefined;
|
|
302
|
+
this.scheduleReconnect();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (!this.disposed && this.server === server && this._status === "connected")
|
|
306
|
+
this.scheduleKeepAlive();
|
|
307
|
+
}
|
|
308
|
+
cancelKeepAlive() {
|
|
309
|
+
if (this.keepAliveHandle !== undefined) {
|
|
310
|
+
this.timer.clearTimeout(this.keepAliveHandle);
|
|
311
|
+
this.keepAliveHandle = undefined;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
scheduleReconnect() {
|
|
315
|
+
const policy = this.reconnectPolicy;
|
|
316
|
+
if (policy === undefined || this.disposed)
|
|
317
|
+
return;
|
|
318
|
+
if (this.reconnectAttempts >= policy.maxRetries) {
|
|
319
|
+
this.emitWarning(`MCP server "${this.name}" gave up reconnecting after ${policy.maxRetries} attempts.`);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const delay = Math.min(policy.maxDelayMs, policy.initialDelayMs * policy.factor ** this.reconnectAttempts);
|
|
323
|
+
this.reconnectAttempts += 1;
|
|
324
|
+
this.cancelScheduledReconnect();
|
|
325
|
+
this.reconnectHandle = this.timer.setTimeout(() => {
|
|
326
|
+
this.reconnectHandle = undefined;
|
|
327
|
+
void this.runScheduledReconnect();
|
|
328
|
+
}, delay);
|
|
329
|
+
}
|
|
330
|
+
async runScheduledReconnect() {
|
|
331
|
+
if (this.disposed)
|
|
332
|
+
return;
|
|
333
|
+
this.setStatus("pending");
|
|
334
|
+
const status = await this.attempt();
|
|
335
|
+
// attempt() resets the counter + clears reconnect on success; on failure, back off again.
|
|
336
|
+
if (status !== "connected" && !this.disposed)
|
|
337
|
+
this.scheduleReconnect();
|
|
338
|
+
}
|
|
339
|
+
cancelScheduledReconnect() {
|
|
340
|
+
if (this.reconnectHandle !== undefined) {
|
|
341
|
+
this.timer.clearTimeout(this.reconnectHandle);
|
|
342
|
+
this.reconnectHandle = undefined;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
emitWarning(message) {
|
|
346
|
+
if (message === undefined)
|
|
347
|
+
return;
|
|
348
|
+
this.ctx?.events.emit({ type: "warning", address: "main", sessionId: this.ctx.sessionId, message });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function keepAliveOptions(config, defaults) {
|
|
352
|
+
const intervalMs = config.keepAliveIntervalMs ?? defaults?.intervalMs;
|
|
353
|
+
if (intervalMs === undefined)
|
|
354
|
+
return {};
|
|
355
|
+
const timeoutMs = config.keepAliveTimeoutMs ?? defaults?.timeoutMs;
|
|
356
|
+
return { keepAlivePolicy: timeoutMs === undefined ? { intervalMs } : { intervalMs, timeoutMs } };
|
|
357
|
+
}
|
|
358
|
+
export function mcpServersCapability(configs, options = {}) {
|
|
359
|
+
const listeners = new Set();
|
|
360
|
+
const notify = (view) => {
|
|
361
|
+
for (const listener of listeners)
|
|
362
|
+
listener(view);
|
|
363
|
+
};
|
|
364
|
+
const controllers = Object.entries(configs).map(([name, config]) => new McpServerController({
|
|
365
|
+
name,
|
|
366
|
+
config,
|
|
367
|
+
...(options.oauthService !== undefined ? { oauthService: options.oauthService } : {}),
|
|
368
|
+
cacheToolsList: options.cacheToolsList ?? DEFAULT_CACHE_TOOLS,
|
|
369
|
+
...(options.transportFactory !== undefined ? { transportFactory: options.transportFactory } : {}),
|
|
370
|
+
...(options.reconnectPolicy !== undefined ? { reconnectPolicy: options.reconnectPolicy } : {}),
|
|
371
|
+
...keepAliveOptions(config, options.keepAlive),
|
|
372
|
+
onStatusChange: notify,
|
|
373
|
+
timer: options.timer ?? REAL_TIMER,
|
|
374
|
+
}));
|
|
375
|
+
const byName = new Map(controllers.map((c) => [c.name, c]));
|
|
376
|
+
let shuttingDown;
|
|
377
|
+
const shutdown = async () => {
|
|
378
|
+
if (shuttingDown !== undefined)
|
|
379
|
+
return shuttingDown;
|
|
380
|
+
shuttingDown = (async () => {
|
|
381
|
+
for (const c of [...controllers].reverse())
|
|
382
|
+
await c.dispose();
|
|
383
|
+
listeners.clear();
|
|
384
|
+
})();
|
|
385
|
+
return shuttingDown;
|
|
386
|
+
};
|
|
387
|
+
const handle = {
|
|
388
|
+
list: () => controllers.map((c) => c.view()),
|
|
389
|
+
reconnect: async (name) => {
|
|
390
|
+
const controller = byName.get(name);
|
|
391
|
+
if (controller === undefined)
|
|
392
|
+
throw new Error(`Unknown MCP server: ${name}`);
|
|
393
|
+
await controller.reconnect();
|
|
394
|
+
},
|
|
395
|
+
onStatusChange: (listener) => {
|
|
396
|
+
listeners.add(listener);
|
|
397
|
+
return () => listeners.delete(listener);
|
|
398
|
+
},
|
|
399
|
+
shutdown,
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
name: "mcp",
|
|
403
|
+
toolProviders: controllers.map((c) => c.toolProvider()),
|
|
404
|
+
service: handle,
|
|
405
|
+
// Session-tier: connect all servers in parallel, fault-isolated (attempt() never throws).
|
|
406
|
+
openSession: async (ctx) => {
|
|
407
|
+
await Promise.all(controllers.map((c) => c.connect(ctx)));
|
|
408
|
+
},
|
|
409
|
+
closeSession: shutdown,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MCPListResourcesResult, MCPReadResourceResult, MCPTool, MCPToolResult, MCPTransport, MCPCallToolOptions, UnexpectedCloseListener } from "./types.ts";
|
|
2
|
+
export interface MockMCPResource {
|
|
3
|
+
readonly uri: string;
|
|
4
|
+
readonly name?: string;
|
|
5
|
+
readonly mimeType?: string;
|
|
6
|
+
readonly text?: string;
|
|
7
|
+
readonly blob?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface MockMCPFixture {
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
readonly tools: readonly MCPTool[];
|
|
12
|
+
readonly call: (toolName: string, args: Record<string, unknown> | null, options?: MCPCallToolOptions) => MCPToolResult | Promise<MCPToolResult>;
|
|
13
|
+
readonly ping?: () => void | Promise<void>;
|
|
14
|
+
readonly resources?: readonly MockMCPResource[];
|
|
15
|
+
}
|
|
16
|
+
export declare class MockMCPTransport implements MCPTransport {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
listToolsCalls: number;
|
|
19
|
+
connectCalls: number;
|
|
20
|
+
closeCalls: number;
|
|
21
|
+
pingCalls: number;
|
|
22
|
+
private readonly fixture;
|
|
23
|
+
private open;
|
|
24
|
+
private unexpectedCloseListener;
|
|
25
|
+
constructor(fixture: MockMCPFixture);
|
|
26
|
+
connect(): Promise<void>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
onUnexpectedClose(listener: UnexpectedCloseListener): void;
|
|
29
|
+
triggerUnexpectedClose(reason?: {
|
|
30
|
+
error?: Error;
|
|
31
|
+
stderr?: string;
|
|
32
|
+
}): void;
|
|
33
|
+
ping(): Promise<void>;
|
|
34
|
+
listTools(): Promise<readonly MCPTool[]>;
|
|
35
|
+
callTool(toolName: string, args: Record<string, unknown> | null, options?: MCPCallToolOptions): Promise<MCPToolResult>;
|
|
36
|
+
listResources(): Promise<MCPListResourcesResult>;
|
|
37
|
+
readResource(uri: string): Promise<MCPReadResourceResult>;
|
|
38
|
+
private assertOpen;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=mock-transport.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export class MockMCPTransport {
|
|
2
|
+
name;
|
|
3
|
+
listToolsCalls = 0;
|
|
4
|
+
connectCalls = 0;
|
|
5
|
+
closeCalls = 0;
|
|
6
|
+
pingCalls = 0;
|
|
7
|
+
fixture;
|
|
8
|
+
open = false;
|
|
9
|
+
unexpectedCloseListener;
|
|
10
|
+
constructor(fixture) {
|
|
11
|
+
this.fixture = fixture;
|
|
12
|
+
this.name = fixture.name ?? "mock";
|
|
13
|
+
}
|
|
14
|
+
async connect() {
|
|
15
|
+
this.connectCalls += 1;
|
|
16
|
+
this.open = true;
|
|
17
|
+
}
|
|
18
|
+
async close() {
|
|
19
|
+
this.closeCalls += 1;
|
|
20
|
+
this.open = false;
|
|
21
|
+
}
|
|
22
|
+
onUnexpectedClose(listener) {
|
|
23
|
+
this.unexpectedCloseListener = listener;
|
|
24
|
+
}
|
|
25
|
+
triggerUnexpectedClose(reason = {}) {
|
|
26
|
+
this.open = false;
|
|
27
|
+
this.unexpectedCloseListener?.(reason);
|
|
28
|
+
}
|
|
29
|
+
async ping() {
|
|
30
|
+
this.assertOpen();
|
|
31
|
+
this.pingCalls += 1;
|
|
32
|
+
await this.fixture.ping?.();
|
|
33
|
+
}
|
|
34
|
+
async listTools() {
|
|
35
|
+
this.assertOpen();
|
|
36
|
+
this.listToolsCalls += 1;
|
|
37
|
+
return this.fixture.tools;
|
|
38
|
+
}
|
|
39
|
+
async callTool(toolName, args, options) {
|
|
40
|
+
this.assertOpen();
|
|
41
|
+
options?.signal?.throwIfAborted();
|
|
42
|
+
return this.fixture.call(toolName, args, options);
|
|
43
|
+
}
|
|
44
|
+
async listResources() {
|
|
45
|
+
this.assertOpen();
|
|
46
|
+
const resources = (this.fixture.resources ?? []).map((r) => ({ uri: r.uri, name: r.name, mimeType: r.mimeType }));
|
|
47
|
+
return { resources };
|
|
48
|
+
}
|
|
49
|
+
async readResource(uri) {
|
|
50
|
+
this.assertOpen();
|
|
51
|
+
const found = (this.fixture.resources ?? []).find((r) => r.uri === uri);
|
|
52
|
+
if (!found)
|
|
53
|
+
throw new Error(`Mock MCP: resource not found: ${uri}`);
|
|
54
|
+
const content = { uri: found.uri };
|
|
55
|
+
if (found.mimeType !== undefined)
|
|
56
|
+
content.mimeType = found.mimeType;
|
|
57
|
+
if (found.text !== undefined)
|
|
58
|
+
content.text = found.text;
|
|
59
|
+
if (found.blob !== undefined)
|
|
60
|
+
content.blob = found.blob;
|
|
61
|
+
return { contents: [content] };
|
|
62
|
+
}
|
|
63
|
+
assertOpen() {
|
|
64
|
+
if (!this.open)
|
|
65
|
+
throw new Error(`Mock MCP transport "${this.name}" is not connected.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=mock-transport.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CallbackResult {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly state: string | undefined;
|
|
4
|
+
}
|
|
5
|
+
export interface CallbackServer {
|
|
6
|
+
readonly redirectUri: string;
|
|
7
|
+
waitForCode(opts: {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}): Promise<CallbackResult>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function startCallbackServer(): Promise<CallbackServer>;
|
|
14
|
+
//# sourceMappingURL=callback-server.d.ts.map
|