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,122 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
const SUCCESS_HTML = '<!doctype html><html><head><meta charset="utf-8"><title>Authorized</title></head>' +
|
|
3
|
+
'<body style="font-family:system-ui,sans-serif;padding:2rem;">' +
|
|
4
|
+
"<h1>Sign-in complete</h1>" +
|
|
5
|
+
"<p>You can close this tab and return to agent-framework.</p>" +
|
|
6
|
+
"</body></html>";
|
|
7
|
+
const ERROR_HTML = '<!doctype html><html><head><meta charset="utf-8"><title>OAuth error</title></head>' +
|
|
8
|
+
'<body style="font-family:system-ui,sans-serif;padding:2rem;">' +
|
|
9
|
+
"<h1>Sign-in failed</h1>" +
|
|
10
|
+
"<p>The authorization server reported an error. Return to agent-framework for details.</p>" +
|
|
11
|
+
"</body></html>";
|
|
12
|
+
export async function startCallbackServer() {
|
|
13
|
+
let resolveCode;
|
|
14
|
+
let rejectCode;
|
|
15
|
+
let settled = false;
|
|
16
|
+
const settle = (fn) => {
|
|
17
|
+
if (settled)
|
|
18
|
+
return;
|
|
19
|
+
settled = true;
|
|
20
|
+
fn();
|
|
21
|
+
};
|
|
22
|
+
const server = createServer((req, res) => {
|
|
23
|
+
handle(req, res);
|
|
24
|
+
});
|
|
25
|
+
function handle(req, res) {
|
|
26
|
+
if (req.method !== "GET" || req.url === undefined) {
|
|
27
|
+
res.writeHead(404).end();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let url;
|
|
31
|
+
try {
|
|
32
|
+
url = new URL(req.url, "http://localhost");
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
res.writeHead(404).end();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (url.pathname !== "/callback") {
|
|
39
|
+
res.writeHead(404).end();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const errorParam = url.searchParams.get("error");
|
|
43
|
+
if (errorParam !== null) {
|
|
44
|
+
const description = url.searchParams.get("error_description") ?? "";
|
|
45
|
+
res.writeHead(400, { "content-type": "text/html; charset=utf-8" }).end(ERROR_HTML);
|
|
46
|
+
settle(() => {
|
|
47
|
+
rejectCode?.(new Error(`OAuth error: ${errorParam}${description ? ` — ${description}` : ""}`));
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const code = url.searchParams.get("code");
|
|
52
|
+
if (code === null || code.length === 0) {
|
|
53
|
+
res.writeHead(400, { "content-type": "text/html; charset=utf-8" }).end(ERROR_HTML);
|
|
54
|
+
settle(() => {
|
|
55
|
+
rejectCode?.(new Error("OAuth callback missing authorization code"));
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const state = url.searchParams.get("state") ?? undefined;
|
|
60
|
+
res.writeHead(200, { "content-type": "text/html; charset=utf-8" }).end(SUCCESS_HTML);
|
|
61
|
+
settle(() => {
|
|
62
|
+
resolveCode?.({ code, state });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
await new Promise((resolve, reject) => {
|
|
66
|
+
server.once("error", reject);
|
|
67
|
+
server.listen(0, "127.0.0.1", () => {
|
|
68
|
+
server.off("error", reject);
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const port = server.address().port;
|
|
73
|
+
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
74
|
+
let closed = false;
|
|
75
|
+
const close = async () => {
|
|
76
|
+
if (closed)
|
|
77
|
+
return;
|
|
78
|
+
closed = true;
|
|
79
|
+
await new Promise((resolve) => {
|
|
80
|
+
server.close(() => {
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const waitForCode = ({ signal, timeoutMs } = {}) => {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
let timer;
|
|
88
|
+
const onAbort = () => {
|
|
89
|
+
settle(() => rejectCode?.(signal?.reason instanceof Error ? signal.reason : new Error("OAuth flow aborted")));
|
|
90
|
+
};
|
|
91
|
+
const cleanup = () => {
|
|
92
|
+
if (timer !== undefined)
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
signal?.removeEventListener("abort", onAbort);
|
|
95
|
+
};
|
|
96
|
+
resolveCode = (value) => {
|
|
97
|
+
cleanup();
|
|
98
|
+
void close();
|
|
99
|
+
resolve(value);
|
|
100
|
+
};
|
|
101
|
+
rejectCode = (reason) => {
|
|
102
|
+
cleanup();
|
|
103
|
+
void close();
|
|
104
|
+
reject(reason);
|
|
105
|
+
};
|
|
106
|
+
if (timeoutMs !== undefined) {
|
|
107
|
+
timer = setTimeout(() => {
|
|
108
|
+
settle(() => rejectCode?.(new Error("OAuth callback timed out")));
|
|
109
|
+
}, timeoutMs);
|
|
110
|
+
}
|
|
111
|
+
if (signal !== undefined) {
|
|
112
|
+
if (signal.aborted) {
|
|
113
|
+
onAbort();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
return { redirectUri, waitForCode, close };
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=callback-server.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { startCallbackServer } from "./callback-server.ts";
|
|
2
|
+
export type { CallbackServer, CallbackResult } from "./callback-server.ts";
|
|
3
|
+
export { McpOAuthClientProvider } from "./provider.ts";
|
|
4
|
+
export type { McpOAuthProviderOptions } from "./provider.ts";
|
|
5
|
+
export { McpOAuthService, AlreadyAuthorizedError, } from "./service.ts";
|
|
6
|
+
export type { McpOAuthServiceOptions, BeginAuthorizationOptions, BeginAuthorizationResult, } from "./service.ts";
|
|
7
|
+
export { JsonFileStore, MemoryMcpCredentialStore, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, sanitizeStoreKey, canonicalMcpOAuthResource, mcpOAuthStoreKey, } from "./store.ts";
|
|
8
|
+
export type { McpCredentialStore } from "./store.ts";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { startCallbackServer } from "./callback-server.js";
|
|
2
|
+
export { McpOAuthClientProvider } from "./provider.js";
|
|
3
|
+
export { McpOAuthService, AlreadyAuthorizedError, } from "./service.js";
|
|
4
|
+
export { JsonFileStore, MemoryMcpCredentialStore, frameworkHomeDir, mcpCredentialsDir, defaultMcpCredentialsDir, sanitizeStoreKey, canonicalMcpOAuthResource, mcpOAuthStoreKey, } from "./store.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OAuthClientProvider, OAuthDiscoveryState } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
|
+
import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
3
|
+
import { type McpCredentialStore } from "./store.ts";
|
|
4
|
+
export interface McpOAuthProviderOptions {
|
|
5
|
+
readonly serverName: string;
|
|
6
|
+
readonly serverUrl: string | URL;
|
|
7
|
+
readonly store: McpCredentialStore;
|
|
8
|
+
readonly clientLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class McpOAuthClientProvider implements OAuthClientProvider {
|
|
11
|
+
readonly storeKey: string;
|
|
12
|
+
readonly serverUrl: string;
|
|
13
|
+
private readonly store;
|
|
14
|
+
private readonly clientLabel;
|
|
15
|
+
private _redirectUrl;
|
|
16
|
+
private _codeVerifier;
|
|
17
|
+
private _state;
|
|
18
|
+
private _lastAuthorizationUrl;
|
|
19
|
+
constructor(options: McpOAuthProviderOptions);
|
|
20
|
+
setRedirectUrl(url: URL): void;
|
|
21
|
+
takeAuthorizationUrl(): URL | undefined;
|
|
22
|
+
expectedState(): string | undefined;
|
|
23
|
+
resetFlow(): void;
|
|
24
|
+
get redirectUrl(): string | URL;
|
|
25
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
26
|
+
state(): string;
|
|
27
|
+
clientInformation(): OAuthClientInformationMixed | undefined;
|
|
28
|
+
saveClientInformation(info: OAuthClientInformationMixed): void;
|
|
29
|
+
tokens(): OAuthTokens | undefined;
|
|
30
|
+
saveTokens(tokens: OAuthTokens): void;
|
|
31
|
+
redirectToAuthorization(url: URL): void;
|
|
32
|
+
saveCodeVerifier(codeVerifier: string): void;
|
|
33
|
+
codeVerifier(): string;
|
|
34
|
+
saveDiscoveryState(state: OAuthDiscoveryState): void;
|
|
35
|
+
discoveryState(): OAuthDiscoveryState | undefined;
|
|
36
|
+
invalidateCredentials(scope: "all" | "client" | "tokens" | "verifier" | "discovery"): void;
|
|
37
|
+
private effectiveRedirectUri;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { canonicalMcpOAuthResource, mcpOAuthStoreKey } from "./store.js";
|
|
3
|
+
const TOKENS_SUFFIX = "-tokens.json";
|
|
4
|
+
const CLIENT_SUFFIX = "-client.json";
|
|
5
|
+
const DISCOVERY_SUFFIX = "-discovery.json";
|
|
6
|
+
// Used only when the SDK probes auth during normal transport startup and no callback
|
|
7
|
+
// listener is active. Interactive login overrides it with a real URL.
|
|
8
|
+
const PASSIVE_REDIRECT_URI = "http://127.0.0.1:3118/callback";
|
|
9
|
+
export class McpOAuthClientProvider {
|
|
10
|
+
storeKey;
|
|
11
|
+
serverUrl;
|
|
12
|
+
store;
|
|
13
|
+
clientLabel;
|
|
14
|
+
_redirectUrl;
|
|
15
|
+
_codeVerifier;
|
|
16
|
+
_state;
|
|
17
|
+
_lastAuthorizationUrl;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.serverUrl = canonicalMcpOAuthResource(options.serverUrl);
|
|
20
|
+
this.storeKey = mcpOAuthStoreKey(options.serverName, this.serverUrl);
|
|
21
|
+
this.store = options.store;
|
|
22
|
+
this.clientLabel = options.clientLabel ?? `agent-framework (${options.serverName})`;
|
|
23
|
+
}
|
|
24
|
+
setRedirectUrl(url) {
|
|
25
|
+
this._redirectUrl = url;
|
|
26
|
+
}
|
|
27
|
+
takeAuthorizationUrl() {
|
|
28
|
+
const url = this._lastAuthorizationUrl;
|
|
29
|
+
this._lastAuthorizationUrl = undefined;
|
|
30
|
+
return url;
|
|
31
|
+
}
|
|
32
|
+
expectedState() {
|
|
33
|
+
return this._state;
|
|
34
|
+
}
|
|
35
|
+
resetFlow() {
|
|
36
|
+
this._redirectUrl = undefined;
|
|
37
|
+
this._codeVerifier = undefined;
|
|
38
|
+
this._state = undefined;
|
|
39
|
+
this._lastAuthorizationUrl = undefined;
|
|
40
|
+
}
|
|
41
|
+
get redirectUrl() {
|
|
42
|
+
return this.effectiveRedirectUri();
|
|
43
|
+
}
|
|
44
|
+
get clientMetadata() {
|
|
45
|
+
return {
|
|
46
|
+
redirect_uris: [this.effectiveRedirectUri()],
|
|
47
|
+
token_endpoint_auth_method: "none",
|
|
48
|
+
grant_types: ["authorization_code", "refresh_token"],
|
|
49
|
+
response_types: ["code"],
|
|
50
|
+
client_name: this.clientLabel,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
state() {
|
|
54
|
+
this._state ??= randomBytes(16).toString("hex");
|
|
55
|
+
return this._state;
|
|
56
|
+
}
|
|
57
|
+
clientInformation() {
|
|
58
|
+
return this.store.read(`${this.storeKey}${CLIENT_SUFFIX}`);
|
|
59
|
+
}
|
|
60
|
+
saveClientInformation(info) {
|
|
61
|
+
this.store.write(`${this.storeKey}${CLIENT_SUFFIX}`, info);
|
|
62
|
+
}
|
|
63
|
+
tokens() {
|
|
64
|
+
return this.store.read(`${this.storeKey}${TOKENS_SUFFIX}`);
|
|
65
|
+
}
|
|
66
|
+
saveTokens(tokens) {
|
|
67
|
+
this.store.write(`${this.storeKey}${TOKENS_SUFFIX}`, tokens);
|
|
68
|
+
}
|
|
69
|
+
redirectToAuthorization(url) {
|
|
70
|
+
// Capture the URL for the orchestrator instead of opening a browser. The synthetic
|
|
71
|
+
// authenticate tool surfaces it to the model so the user completes the flow themselves.
|
|
72
|
+
this._lastAuthorizationUrl = url;
|
|
73
|
+
}
|
|
74
|
+
saveCodeVerifier(codeVerifier) {
|
|
75
|
+
this._codeVerifier = codeVerifier;
|
|
76
|
+
}
|
|
77
|
+
codeVerifier() {
|
|
78
|
+
if (this._codeVerifier === undefined) {
|
|
79
|
+
throw new Error("McpOAuthClientProvider: PKCE code verifier not initialized");
|
|
80
|
+
}
|
|
81
|
+
return this._codeVerifier;
|
|
82
|
+
}
|
|
83
|
+
saveDiscoveryState(state) {
|
|
84
|
+
this.store.write(`${this.storeKey}${DISCOVERY_SUFFIX}`, state);
|
|
85
|
+
}
|
|
86
|
+
discoveryState() {
|
|
87
|
+
return this.store.read(`${this.storeKey}${DISCOVERY_SUFFIX}`);
|
|
88
|
+
}
|
|
89
|
+
invalidateCredentials(scope) {
|
|
90
|
+
if (scope === "verifier") {
|
|
91
|
+
this._codeVerifier = undefined;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (scope === "tokens" || scope === "all") {
|
|
95
|
+
this.store.remove(`${this.storeKey}${TOKENS_SUFFIX}`);
|
|
96
|
+
}
|
|
97
|
+
if (scope === "client" || scope === "all") {
|
|
98
|
+
this.store.remove(`${this.storeKey}${CLIENT_SUFFIX}`);
|
|
99
|
+
}
|
|
100
|
+
if (scope === "discovery" || scope === "all") {
|
|
101
|
+
this.store.remove(`${this.storeKey}${DISCOVERY_SUFFIX}`);
|
|
102
|
+
}
|
|
103
|
+
if (scope === "all") {
|
|
104
|
+
this._codeVerifier = undefined;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
effectiveRedirectUri() {
|
|
108
|
+
if (this._redirectUrl !== undefined) {
|
|
109
|
+
return this._redirectUrl.toString();
|
|
110
|
+
}
|
|
111
|
+
const registered = registeredRedirectUri(this.clientInformation());
|
|
112
|
+
return registered ?? PASSIVE_REDIRECT_URI;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function registeredRedirectUri(info) {
|
|
116
|
+
if (info === undefined || !("redirect_uris" in info))
|
|
117
|
+
return undefined;
|
|
118
|
+
const [redirectUri] = info.redirect_uris;
|
|
119
|
+
return redirectUri;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { McpOAuthClientProvider } from "./provider.ts";
|
|
2
|
+
import { type McpCredentialStore } from "./store.ts";
|
|
3
|
+
export interface McpOAuthServiceOptions {
|
|
4
|
+
/** Where credentials live. Defaults to a `JsonFileStore` (local disk); inject a
|
|
5
|
+
* `MemoryMcpCredentialStore` (or other backend) for deployments without local disk. */
|
|
6
|
+
readonly store?: McpCredentialStore;
|
|
7
|
+
readonly homeDir?: string;
|
|
8
|
+
readonly clientLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BeginAuthorizationOptions {
|
|
11
|
+
readonly clientLabel?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BeginAuthorizationResult {
|
|
14
|
+
readonly authorizationUrl: URL;
|
|
15
|
+
complete(opts?: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
cancel(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare class McpOAuthService {
|
|
22
|
+
private readonly store;
|
|
23
|
+
private readonly clientLabel;
|
|
24
|
+
private readonly providers;
|
|
25
|
+
constructor(options?: McpOAuthServiceOptions);
|
|
26
|
+
getProvider(serverName: string, serverUrl: string | URL): McpOAuthClientProvider;
|
|
27
|
+
hasTokens(serverName: string, serverUrl: string | URL): boolean;
|
|
28
|
+
beginAuthorization(serverName: string, serverUrl: string | URL, options?: BeginAuthorizationOptions): Promise<BeginAuthorizationResult>;
|
|
29
|
+
invalidate(serverName: string, serverUrl: string | URL, scope?: "all" | "client" | "tokens" | "discovery"): void;
|
|
30
|
+
}
|
|
31
|
+
export declare class AlreadyAuthorizedError extends Error {
|
|
32
|
+
constructor(serverName: string);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
|
+
import { startCallbackServer } from "./callback-server.js";
|
|
3
|
+
import { McpOAuthClientProvider } from "./provider.js";
|
|
4
|
+
import { JsonFileStore, mcpCredentialsDir, mcpOAuthStoreKey } from "./store.js";
|
|
5
|
+
export class McpOAuthService {
|
|
6
|
+
store;
|
|
7
|
+
clientLabel;
|
|
8
|
+
providers = new Map();
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.store =
|
|
11
|
+
options.store ??
|
|
12
|
+
new JsonFileStore(options.homeDir === undefined ? undefined : mcpCredentialsDir(options.homeDir));
|
|
13
|
+
this.clientLabel = options.clientLabel;
|
|
14
|
+
}
|
|
15
|
+
getProvider(serverName, serverUrl) {
|
|
16
|
+
const storeKey = mcpOAuthStoreKey(serverName, serverUrl);
|
|
17
|
+
let provider = this.providers.get(storeKey);
|
|
18
|
+
if (provider === undefined) {
|
|
19
|
+
provider = new McpOAuthClientProvider({
|
|
20
|
+
serverName,
|
|
21
|
+
serverUrl,
|
|
22
|
+
store: this.store,
|
|
23
|
+
...(this.clientLabel !== undefined ? { clientLabel: this.clientLabel } : {}),
|
|
24
|
+
});
|
|
25
|
+
this.providers.set(provider.storeKey, provider);
|
|
26
|
+
}
|
|
27
|
+
return provider;
|
|
28
|
+
}
|
|
29
|
+
hasTokens(serverName, serverUrl) {
|
|
30
|
+
return this.getProvider(serverName, serverUrl).tokens() !== undefined;
|
|
31
|
+
}
|
|
32
|
+
async beginAuthorization(serverName, serverUrl, options = {}) {
|
|
33
|
+
const provider = options.clientLabel === undefined
|
|
34
|
+
? this.getProvider(serverName, serverUrl)
|
|
35
|
+
: new McpOAuthClientProvider({
|
|
36
|
+
serverName,
|
|
37
|
+
serverUrl,
|
|
38
|
+
store: this.store,
|
|
39
|
+
clientLabel: options.clientLabel,
|
|
40
|
+
});
|
|
41
|
+
if (options.clientLabel !== undefined) {
|
|
42
|
+
this.providers.set(provider.storeKey, provider);
|
|
43
|
+
}
|
|
44
|
+
provider.resetFlow();
|
|
45
|
+
let callbackServer;
|
|
46
|
+
try {
|
|
47
|
+
callbackServer = await startCallbackServer();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw wrapAuthError("failed to start OAuth callback listener", error);
|
|
51
|
+
}
|
|
52
|
+
provider.setRedirectUrl(new URL(callbackServer.redirectUri));
|
|
53
|
+
let authorizationUrl;
|
|
54
|
+
try {
|
|
55
|
+
const result = await auth(provider, { serverUrl });
|
|
56
|
+
if (result !== "REDIRECT") {
|
|
57
|
+
// Tokens already valid (e.g. unexpired refresh). Nothing to do.
|
|
58
|
+
await callbackServer.close();
|
|
59
|
+
throw new AlreadyAuthorizedError(serverName);
|
|
60
|
+
}
|
|
61
|
+
authorizationUrl = provider.takeAuthorizationUrl();
|
|
62
|
+
if (authorizationUrl === undefined) {
|
|
63
|
+
throw new Error("OAuth provider did not capture an authorization URL");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
await callbackServer.close().catch(() => undefined);
|
|
68
|
+
provider.resetFlow();
|
|
69
|
+
if (error instanceof AlreadyAuthorizedError)
|
|
70
|
+
throw error;
|
|
71
|
+
throw wrapAuthError(`failed to start OAuth flow for "${serverName}"`, error);
|
|
72
|
+
}
|
|
73
|
+
let settled = false;
|
|
74
|
+
const cancel = async () => {
|
|
75
|
+
if (settled)
|
|
76
|
+
return;
|
|
77
|
+
settled = true;
|
|
78
|
+
await callbackServer.close().catch(() => undefined);
|
|
79
|
+
provider.resetFlow();
|
|
80
|
+
};
|
|
81
|
+
const complete = async (opts = {}) => {
|
|
82
|
+
if (settled) {
|
|
83
|
+
throw new Error("OAuth flow already completed or cancelled");
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const { code, state } = await callbackServer.waitForCode({
|
|
87
|
+
...(opts.signal !== undefined ? { signal: opts.signal } : {}),
|
|
88
|
+
...(opts.timeoutMs !== undefined ? { timeoutMs: opts.timeoutMs } : {}),
|
|
89
|
+
});
|
|
90
|
+
const expectedState = provider.expectedState();
|
|
91
|
+
if (expectedState !== undefined && state !== expectedState) {
|
|
92
|
+
throw new Error("OAuth state mismatch — possible CSRF; refusing token exchange");
|
|
93
|
+
}
|
|
94
|
+
const finalResult = await auth(provider, {
|
|
95
|
+
serverUrl,
|
|
96
|
+
authorizationCode: code,
|
|
97
|
+
});
|
|
98
|
+
if (finalResult !== "AUTHORIZED") {
|
|
99
|
+
throw new Error(`OAuth code exchange returned "${finalResult}" instead of AUTHORIZED`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
await cancel();
|
|
104
|
+
throw wrapAuthError(`OAuth flow for "${serverName}" failed`, error);
|
|
105
|
+
}
|
|
106
|
+
settled = true;
|
|
107
|
+
await callbackServer.close().catch(() => undefined);
|
|
108
|
+
provider.resetFlow();
|
|
109
|
+
};
|
|
110
|
+
return { authorizationUrl, complete, cancel };
|
|
111
|
+
}
|
|
112
|
+
invalidate(serverName, serverUrl, scope = "all") {
|
|
113
|
+
this.getProvider(serverName, serverUrl).invalidateCredentials(scope);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export class AlreadyAuthorizedError extends Error {
|
|
117
|
+
constructor(serverName) {
|
|
118
|
+
super(`"${serverName}" is already authorized; no browser flow needed`);
|
|
119
|
+
this.name = "AlreadyAuthorizedError";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function wrapAuthError(prefix, error) {
|
|
123
|
+
if (error instanceof Error) {
|
|
124
|
+
const wrapped = new Error(`${prefix}: ${error.message}`);
|
|
125
|
+
wrapped.cause = error;
|
|
126
|
+
return wrapped;
|
|
127
|
+
}
|
|
128
|
+
return new Error(`${prefix}: ${String(error)}`);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare function frameworkHomeDir(): string;
|
|
2
|
+
export declare function mcpCredentialsDir(homeDir: string): string;
|
|
3
|
+
export declare function defaultMcpCredentialsDir(): string;
|
|
4
|
+
export declare function sanitizeStoreKey(name: string): string;
|
|
5
|
+
export declare function canonicalMcpOAuthResource(serverUrl: string | URL): string;
|
|
6
|
+
export declare function mcpOAuthStoreKey(serverName: string, serverUrl: string | URL): string;
|
|
7
|
+
/**
|
|
8
|
+
* Where MCP OAuth credentials (client info / tokens / discovery) are persisted, keyed by a
|
|
9
|
+
* filename-shaped string. The MCP SDK calls `tokens()` synchronously, so this contract is sync
|
|
10
|
+
* — a network-backed backend must front an in-memory copy hydrated at session open (see
|
|
11
|
+
* `MemoryMcpCredentialStore`) rather than implement it directly. Mirrors `llm/auth`'s
|
|
12
|
+
* `CredentialStore` (that one is async because the model auth path is): same idea, credentials
|
|
13
|
+
* are a swappable backend, not hardwired to the local filesystem.
|
|
14
|
+
*/
|
|
15
|
+
export interface McpCredentialStore {
|
|
16
|
+
read<T>(file: string): T | undefined;
|
|
17
|
+
write(file: string, data: unknown): void;
|
|
18
|
+
remove(file: string): void;
|
|
19
|
+
}
|
|
20
|
+
/** In-memory `McpCredentialStore` — the injectable backend for deployments with no local disk
|
|
21
|
+
* (server hydrates it from external storage at session open, flushes on write). */
|
|
22
|
+
export declare class MemoryMcpCredentialStore implements McpCredentialStore {
|
|
23
|
+
private readonly entries;
|
|
24
|
+
read<T>(file: string): T | undefined;
|
|
25
|
+
write(file: string, data: unknown): void;
|
|
26
|
+
remove(file: string): void;
|
|
27
|
+
/** Snapshot for dehydration to external storage. */
|
|
28
|
+
toJSON(): Record<string, unknown>;
|
|
29
|
+
/** Rehydrate from a snapshot (server seeds this at session open). */
|
|
30
|
+
static from(snapshot: Record<string, unknown>): MemoryMcpCredentialStore;
|
|
31
|
+
}
|
|
32
|
+
/** Local default `McpCredentialStore`: one JSON file per key under `<home>/credentials/mcp`, 0600. */
|
|
33
|
+
export declare class JsonFileStore implements McpCredentialStore {
|
|
34
|
+
private readonly dir;
|
|
35
|
+
constructor(dir?: string);
|
|
36
|
+
read<T>(file: string): T | undefined;
|
|
37
|
+
write(file: string, data: unknown): void;
|
|
38
|
+
remove(file: string): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { chmodSync, closeSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeSync, } from "node:fs";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
4
|
+
import { operonHomeDir } from "../../home.js";
|
|
5
|
+
export function frameworkHomeDir() {
|
|
6
|
+
return operonHomeDir();
|
|
7
|
+
}
|
|
8
|
+
export function mcpCredentialsDir(homeDir) {
|
|
9
|
+
return join(homeDir, "credentials", "mcp");
|
|
10
|
+
}
|
|
11
|
+
export function defaultMcpCredentialsDir() {
|
|
12
|
+
return mcpCredentialsDir(frameworkHomeDir());
|
|
13
|
+
}
|
|
14
|
+
export function sanitizeStoreKey(name) {
|
|
15
|
+
// Strip path-traversal segments. Tokens land under `<key>-<suffix>.json`, so the sanitized
|
|
16
|
+
// value must also be a single filename component.
|
|
17
|
+
const safe = basename(name).replaceAll(/[^a-zA-Z0-9_-]/g, "_").replaceAll(/_+/g, "_");
|
|
18
|
+
if (safe.length === 0 || safe.startsWith(".")) {
|
|
19
|
+
throw new Error(`Invalid MCP OAuth store key: "${name}"`);
|
|
20
|
+
}
|
|
21
|
+
return safe;
|
|
22
|
+
}
|
|
23
|
+
export function canonicalMcpOAuthResource(serverUrl) {
|
|
24
|
+
const url = new URL(serverUrl);
|
|
25
|
+
url.hash = "";
|
|
26
|
+
return url.toString();
|
|
27
|
+
}
|
|
28
|
+
export function mcpOAuthStoreKey(serverName, serverUrl) {
|
|
29
|
+
const safeName = sanitizeStoreKey(serverName);
|
|
30
|
+
const resource = canonicalMcpOAuthResource(serverUrl);
|
|
31
|
+
const digest = createHash("sha256")
|
|
32
|
+
.update(serverName)
|
|
33
|
+
.update("\0")
|
|
34
|
+
.update(resource)
|
|
35
|
+
.digest("hex")
|
|
36
|
+
.slice(0, 24);
|
|
37
|
+
return `${safeName}-${digest}`;
|
|
38
|
+
}
|
|
39
|
+
/** In-memory `McpCredentialStore` — the injectable backend for deployments with no local disk
|
|
40
|
+
* (server hydrates it from external storage at session open, flushes on write). */
|
|
41
|
+
export class MemoryMcpCredentialStore {
|
|
42
|
+
entries = new Map();
|
|
43
|
+
read(file) {
|
|
44
|
+
const value = this.entries.get(file);
|
|
45
|
+
return value === undefined ? undefined : structuredClone(value);
|
|
46
|
+
}
|
|
47
|
+
write(file, data) {
|
|
48
|
+
this.entries.set(file, structuredClone(data));
|
|
49
|
+
}
|
|
50
|
+
remove(file) {
|
|
51
|
+
this.entries.delete(file);
|
|
52
|
+
}
|
|
53
|
+
/** Snapshot for dehydration to external storage. */
|
|
54
|
+
toJSON() {
|
|
55
|
+
return Object.fromEntries(this.entries);
|
|
56
|
+
}
|
|
57
|
+
/** Rehydrate from a snapshot (server seeds this at session open). */
|
|
58
|
+
static from(snapshot) {
|
|
59
|
+
const store = new MemoryMcpCredentialStore();
|
|
60
|
+
for (const [file, data] of Object.entries(snapshot))
|
|
61
|
+
store.entries.set(file, data);
|
|
62
|
+
return store;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Local default `McpCredentialStore`: one JSON file per key under `<home>/credentials/mcp`, 0600. */
|
|
66
|
+
export class JsonFileStore {
|
|
67
|
+
dir;
|
|
68
|
+
constructor(dir = defaultMcpCredentialsDir()) {
|
|
69
|
+
this.dir = dir;
|
|
70
|
+
}
|
|
71
|
+
read(file) {
|
|
72
|
+
const path = join(this.dir, file);
|
|
73
|
+
let raw;
|
|
74
|
+
try {
|
|
75
|
+
raw = readFileSync(path, "utf-8");
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return JSON.parse(raw);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
write(file, data) {
|
|
88
|
+
mkdirSync(this.dir, { recursive: true, mode: 0o700 });
|
|
89
|
+
try {
|
|
90
|
+
chmodSync(this.dir, 0o700);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// best-effort; Windows / read-only FS may refuse
|
|
94
|
+
}
|
|
95
|
+
const target = join(this.dir, file);
|
|
96
|
+
const tmp = `${target}.tmp.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
97
|
+
const buf = Buffer.from(`${JSON.stringify(data, null, 2)}\n`, "utf-8");
|
|
98
|
+
const fd = openSync(tmp, "w", 0o600);
|
|
99
|
+
try {
|
|
100
|
+
let written = 0;
|
|
101
|
+
while (written < buf.length) {
|
|
102
|
+
written += writeSync(fd, buf, written, buf.length - written);
|
|
103
|
+
}
|
|
104
|
+
fsyncSync(fd);
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
closeSync(fd);
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
chmodSync(tmp, 0o600);
|
|
111
|
+
renameSync(tmp, target);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
try {
|
|
115
|
+
unlinkSync(tmp);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* ignore */
|
|
119
|
+
}
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
remove(file) {
|
|
124
|
+
try {
|
|
125
|
+
unlinkSync(join(this.dir, file));
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (error.code !== "ENOENT") {
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ToolResultContent } from "../index.ts";
|
|
2
|
+
import type { MCPContentBlock, MCPToolResult } from "./types.ts";
|
|
3
|
+
export declare const MCP_MAX_OUTPUT_CHARS = 100000;
|
|
4
|
+
export declare const MCP_MAX_IMAGE_PART_BYTES: number;
|
|
5
|
+
type Part = ToolResultContent[number];
|
|
6
|
+
export declare function convertMcpContentBlock(block: MCPContentBlock): Part | null;
|
|
7
|
+
export declare function mcpResultToContent(result: MCPToolResult, qualifiedToolName: string): {
|
|
8
|
+
content: ToolResultContent;
|
|
9
|
+
isError: boolean;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=output.d.ts.map
|