@ai-setting/roy-agent-core 1.7.52 → 1.7.53
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/dist/config/config-component.d.ts +346 -0
- package/dist/config/config-parser.d.ts +45 -0
- package/dist/config/env-key.d.ts +97 -0
- package/dist/config/env-source.d.ts +113 -0
- package/dist/config/file-source.d.ts +90 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/protocol-resolver.d.ts +94 -0
- package/dist/env/agent/agent-component.d.ts +646 -0
- package/dist/env/agent/agent-config-registration.d.ts +18 -0
- package/dist/env/agent/agent-registry.d.ts +500 -0
- package/dist/env/agent/index.d.ts +9 -0
- package/dist/env/agent/summary-agent.d.ts +44 -0
- package/dist/env/agent/types.d.ts +503 -0
- package/dist/env/commands/commands-component.d.ts +97 -0
- package/dist/env/commands/commands-config-registration.d.ts +19 -0
- package/dist/env/commands/index.d.ts +7 -0
- package/dist/env/commands/parser.d.ts +18 -0
- package/dist/env/commands/types.d.ts +133 -0
- package/dist/env/component.d.ts +186 -0
- package/dist/env/constants.d.ts +112 -0
- package/dist/env/context/env-context.d.ts +420 -0
- package/dist/env/context/env-event.d.ts +144 -0
- package/dist/env/context/index.d.ts +13 -0
- package/dist/env/debug/debug-component.d.ts +160 -0
- package/dist/env/debug/formatters/index.d.ts +8 -0
- package/dist/env/debug/formatters/repl-formatter.d.ts +80 -0
- package/dist/env/debug/formatters/trace-formatter.d.ts +43 -0
- package/dist/env/debug/formatters/tree-formatter.d.ts +72 -0
- package/dist/env/debug/index.d.ts +15 -0
- package/dist/env/debug/index.js +1 -1
- package/dist/env/debug/parser/regex-parser.d.ts +49 -0
- package/dist/env/debug/parser/span-builder.d.ts +79 -0
- package/dist/env/debug/reader/log-reader.d.ts +55 -0
- package/dist/env/debug/reader/span-db-reader.d.ts +70 -0
- package/dist/env/debug/types.d.ts +145 -0
- package/dist/env/environment.d.ts +185 -0
- package/dist/env/errors.d.ts +120 -0
- package/dist/env/event-source/bounty-cli-handler.d.ts +42 -0
- package/dist/env/event-source/bounty-im-handler.d.ts +232 -0
- package/dist/env/event-source/event-source-component.d.ts +177 -0
- package/dist/env/event-source/event-source-config-registration.d.ts +18 -0
- package/dist/env/event-source/event-source-handlers.d.ts +486 -0
- package/dist/env/event-source/event-store.d.ts +110 -0
- package/dist/env/event-source/idempotency-key.d.ts +19 -0
- package/dist/env/event-source/index.d.ts +15 -0
- package/dist/env/event-source/index.js +2 -2
- package/dist/env/event-source/timer-handler.d.ts +74 -0
- package/dist/env/event-source/types.d.ts +803 -0
- package/dist/env/hook/global-hook-manager.d.ts +73 -0
- package/dist/env/hook/hook-manager.d.ts +139 -0
- package/dist/env/hook/index.d.ts +9 -0
- package/dist/env/hook/types.d.ts +107 -0
- package/dist/env/index.d.ts +24 -0
- package/dist/env/index.js +4 -4
- package/dist/env/interface.d.ts +156 -0
- package/dist/env/lark-mention-utils.d.ts +59 -0
- package/dist/env/llm/adapter-ai-sdk.d.ts +10 -0
- package/dist/env/llm/adapter-pi-ai.d.ts +39 -0
- package/dist/env/llm/adapter.d.ts +80 -0
- package/dist/env/llm/factory.d.ts +13 -0
- package/dist/env/llm/hooks.d.ts +150 -0
- package/dist/env/llm/index.d.ts +16 -0
- package/dist/env/llm/invoke.d.ts +264 -0
- package/dist/env/llm/llm-cache.d.ts +38 -0
- package/dist/env/llm/llm.d.ts +238 -0
- package/dist/env/llm/opencode-session.d.ts +79 -0
- package/dist/env/llm/provider.d.ts +40 -0
- package/dist/env/llm/tool-args-parser.d.ts +77 -0
- package/dist/env/llm/tool-schema.d.ts +54 -0
- package/dist/env/llm/transform.d.ts +57 -0
- package/dist/env/llm/types.d.ts +818 -0
- package/dist/env/log-trace/decorator.d.ts +88 -0
- package/dist/env/log-trace/index.d.ts +14 -0
- package/dist/env/log-trace/log-trace-component.d.ts +268 -0
- package/dist/env/log-trace/log-trace-config-registration.d.ts +25 -0
- package/dist/env/log-trace/logger.d.ts +83 -0
- package/dist/env/log-trace/opentelemetry/cli-propagation.d.ts +105 -0
- package/dist/env/log-trace/opentelemetry/mod.d.ts +24 -0
- package/dist/env/log-trace/opentelemetry/propagation-env.d.ts +81 -0
- package/dist/env/log-trace/opentelemetry/propagation.d.ts +79 -0
- package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +157 -0
- package/dist/env/log-trace/span-storage.d.ts +37 -0
- package/dist/env/log-trace/trace-context.d.ts +28 -0
- package/dist/env/log-trace/types.d.ts +127 -0
- package/dist/env/mcp/command-resolver.d.ts +12 -0
- package/dist/env/mcp/config.d.ts +103 -0
- package/dist/env/mcp/index.d.ts +13 -0
- package/dist/env/mcp/loader.d.ts +78 -0
- package/dist/env/mcp/mcp-component.d.ts +54 -0
- package/dist/env/mcp/mcp-config-registration.d.ts +19 -0
- package/dist/env/mcp/npm-prefix/index.d.ts +17 -0
- package/dist/env/mcp/scanner.d.ts +38 -0
- package/dist/env/mcp/tool/adapter.d.ts +32 -0
- package/dist/env/mcp/tool/index.d.ts +4 -0
- package/dist/env/mcp/types.d.ts +131 -0
- package/dist/env/memory/built-in/index.d.ts +41 -0
- package/dist/env/memory/built-in/recall-memory.d.ts +29 -0
- package/dist/env/memory/built-in/record-memory.d.ts +44 -0
- package/dist/env/memory/index.d.ts +10 -0
- package/dist/env/memory/memory-component.d.ts +114 -0
- package/dist/env/memory/memory-config-registration.d.ts +18 -0
- package/dist/env/memory/memory-config.d.ts +18 -0
- package/dist/env/memory/plugin/index.d.ts +16 -0
- package/dist/env/memory/plugin/memory-agent.d.ts +126 -0
- package/dist/env/memory/plugin/memory-manager.d.ts +71 -0
- package/dist/env/memory/plugin/memory-plugin.d.ts +103 -0
- package/dist/env/memory/plugin/recall-memory.d.ts +16 -0
- package/dist/env/memory/plugin/types.d.ts +75 -0
- package/dist/env/memory/tools/memory-agent-tools.d.ts +109 -0
- package/dist/env/memory/types.d.ts +80 -0
- package/dist/env/paths.d.ts +46 -0
- package/dist/env/plugin/bounty-cli-notification-channel.d.ts +60 -0
- package/dist/env/plugin/event-bus-notification-channel.d.ts +50 -0
- package/dist/env/plugin/index.d.ts +13 -0
- package/dist/env/plugin/lark-cli-notification-channel.d.ts +61 -0
- package/dist/env/plugin/notification-channel.d.ts +143 -0
- package/dist/env/plugin/plugin-component.d.ts +232 -0
- package/dist/env/plugin/types.d.ts +146 -0
- package/dist/env/prompt/index.d.ts +7 -0
- package/dist/env/prompt/prompt-component.d.ts +194 -0
- package/dist/env/prompt/prompt-config-registration.d.ts +18 -0
- package/dist/env/prompt/prompt-store.d.ts +26 -0
- package/dist/env/prompt/prompts-index.d.ts +146 -0
- package/dist/env/prompt/renderer.d.ts +21 -0
- package/dist/env/prompt/types.d.ts +176 -0
- package/dist/env/session/hooks.d.ts +14 -0
- package/dist/env/session/index.d.ts +19 -0
- package/dist/env/session/search-query-parser.d.ts +41 -0
- package/dist/env/session/session-component.d.ts +464 -0
- package/dist/env/session/session-config-registration.d.ts +18 -0
- package/dist/env/session/session-id.d.ts +26 -0
- package/dist/env/session/session-message-converter.d.ts +142 -0
- package/dist/env/session/session-store.d.ts +188 -0
- package/dist/env/session/storage/index.d.ts +5 -0
- package/dist/env/session/storage/memory.d.ts +119 -0
- package/dist/env/session/storage/sqlite.d.ts +108 -0
- package/dist/env/session/types.d.ts +705 -0
- package/dist/env/session-tree-stopper.d.ts +79 -0
- package/dist/env/skill/config.d.ts +13 -0
- package/dist/env/skill/index.d.ts +6 -0
- package/dist/env/skill/parser.d.ts +9 -0
- package/dist/env/skill/scanner.d.ts +25 -0
- package/dist/env/skill/skill-component.d.ts +89 -0
- package/dist/env/skill/skill-config-registration.d.ts +18 -0
- package/dist/env/skill/tool/index.d.ts +1 -0
- package/dist/env/skill/tool/skill-tool.d.ts +15 -0
- package/dist/env/skill/types.d.ts +61 -0
- package/dist/env/task/backend/index.d.ts +24 -0
- package/dist/env/task/backend/index.js +704 -0
- package/dist/env/task/backend/roy-sidecar-task-port.d.ts +148 -0
- package/dist/env/task/backend/sqlite-task-port.d.ts +28 -0
- package/dist/env/task/backend/task-store-backend.d.ts +107 -0
- package/dist/env/task/backend/types.d.ts +293 -0
- package/dist/env/task/delegate/bg-task-id-storage.d.ts +9 -0
- package/dist/env/task/delegate/delegate-tool.d.ts +681 -0
- package/dist/env/task/delegate/index.d.ts +8 -0
- package/dist/env/task/delegate/process-registry.d.ts +58 -0
- package/dist/env/task/delegate/stop-tool.d.ts +12 -0
- package/dist/env/task/delegate/subagent-resolver.d.ts +25 -0
- package/dist/env/task/events/index.d.ts +7 -0
- package/dist/env/task/events/task-event-payloads.d.ts +101 -0
- package/dist/env/task/events/task-event-types.d.ts +23 -0
- package/dist/env/task/hooks/contexts.d.ts +191 -0
- package/dist/env/task/hooks/index.d.ts +7 -0
- package/dist/env/task/hooks/task-hook-points.d.ts +42 -0
- package/dist/env/task/index.d.ts +7 -0
- package/dist/env/task/plugins/auto-task-plugin.d.ts +38 -0
- package/dist/env/task/plugins/card-chat-routing.d.ts +135 -0
- package/dist/env/task/plugins/fake-user-message-helper.d.ts +90 -0
- package/dist/env/task/plugins/index.d.ts +8 -0
- package/dist/env/task/plugins/index.js +1 -1
- package/dist/env/task/plugins/lark-card-action-handler.d.ts +166 -0
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +651 -0
- package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +248 -0
- package/dist/env/task/plugins/max-iteration-reminder-plugin.d.ts +112 -0
- package/dist/env/task/plugins/per-task-group-chat-plugin.d.ts +561 -0
- package/dist/env/task/plugins/task-tag-plugin.d.ts +70 -0
- package/dist/env/task/plugins/workflow-extractor-agent.d.ts +43 -0
- package/dist/env/task/registry-hook-installer.d.ts +43 -0
- package/dist/env/task/storage/index.d.ts +5 -0
- package/dist/env/task/storage/migrations/001_add_project_path_context.d.ts +14 -0
- package/dist/env/task/storage/migrations/002_add_task_type.d.ts +14 -0
- package/dist/env/task/storage/migrations/003_add_process_description.d.ts +20 -0
- package/dist/env/task/storage/migrations/004_rename_action_to_milestone.d.ts +37 -0
- package/dist/env/task/storage/migrations/005_convert_blob_description_to_text.d.ts +51 -0
- package/dist/env/task/storage/sqlite-task-store.d.ts +241 -0
- package/dist/env/task/tag-service.d.ts +138 -0
- package/dist/env/task/task-child-context.d.ts +70 -0
- package/dist/env/task/task-component.d.ts +270 -0
- package/dist/env/task/task-config-registration.d.ts +19 -0
- package/dist/env/task/task-creation-registry.d.ts +181 -0
- package/dist/env/task/task-reuse-context.d.ts +52 -0
- package/dist/env/task/task-reuse-registry.d.ts +31 -0
- package/dist/env/task/tools/batch-archive-tool.d.ts +9 -0
- package/dist/env/task/tools/batch-delete-tool.d.ts +9 -0
- package/dist/env/task/tools/complete-tool.d.ts +12 -0
- package/dist/env/task/tools/create-tool.d.ts +6 -0
- package/dist/env/task/tools/delete-tool.d.ts +6 -0
- package/dist/env/task/tools/get-tool.d.ts +6 -0
- package/dist/env/task/tools/index.d.ts +13 -0
- package/dist/env/task/tools/list-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/create-tool.d.ts +12 -0
- package/dist/env/task/tools/operation/delete-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/get-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/index.d.ts +8 -0
- package/dist/env/task/tools/operation/list-tool.d.ts +6 -0
- package/dist/env/task/tools/operation/operation-types.d.ts +225 -0
- package/dist/env/task/tools/operation/update-tool.d.ts +6 -0
- package/dist/env/task/tools/search-tool.d.ts +9 -0
- package/dist/env/task/tools/task-tree-tool.d.ts +65 -0
- package/dist/env/task/tools/task-types.d.ts +255 -0
- package/dist/env/task/tools/update-tool.d.ts +6 -0
- package/dist/env/task/types.d.ts +290 -0
- package/dist/env/tool/built-in/bash-effect.d.ts +36 -0
- package/dist/env/tool/built-in/bash.d.ts +16 -0
- package/dist/env/tool/built-in/echo.d.ts +7 -0
- package/dist/env/tool/built-in/edit-file.d.ts +6 -0
- package/dist/env/tool/built-in/glob.d.ts +6 -0
- package/dist/env/tool/built-in/grep.d.ts +6 -0
- package/dist/env/tool/built-in/index.d.ts +39 -0
- package/dist/env/tool/built-in/query-background-process-tool.d.ts +113 -0
- package/dist/env/tool/built-in/read-file.d.ts +5 -0
- package/dist/env/tool/built-in/understand-image.d.ts +59 -0
- package/dist/env/tool/built-in/write-file.d.ts +5 -0
- package/dist/env/tool/index.d.ts +16 -0
- package/dist/env/tool/registry.d.ts +61 -0
- package/dist/env/tool/tool-component.d.ts +242 -0
- package/dist/env/tool/tool-config-registration.d.ts +18 -0
- package/dist/env/tool/types.d.ts +274 -0
- package/dist/env/tool/validator.d.ts +14 -0
- package/dist/env/types.d.ts +184 -0
- package/dist/env/workflow/decorators/decorator-node.d.ts +76 -0
- package/dist/env/workflow/decorators/edge.d.ts +42 -0
- package/dist/env/workflow/decorators/index.d.ts +13 -0
- package/dist/env/workflow/decorators/node-as.d.ts +40 -0
- package/dist/env/workflow/decorators/workflow.d.ts +30 -0
- package/dist/env/workflow/engine/dag-manager.d.ts +176 -0
- package/dist/env/workflow/engine/engine.d.ts +375 -0
- package/dist/env/workflow/engine/event-bus.d.ts +54 -0
- package/dist/env/workflow/engine/executor.d.ts +122 -0
- package/dist/env/workflow/engine/index.d.ts +15 -0
- package/dist/env/workflow/engine/node-registry.d.ts +159 -0
- package/dist/env/workflow/engine/scheduler.d.ts +164 -0
- package/dist/env/workflow/extractor/workflow-converter.d.ts +55 -0
- package/dist/env/workflow/fixtures.d.ts +401 -0
- package/dist/env/workflow/hooks/index.d.ts +4 -0
- package/dist/env/workflow/hooks/workflow-hook-points.d.ts +161 -0
- package/dist/env/workflow/index.d.ts +30 -0
- package/dist/env/workflow/index.js +1 -1
- package/dist/env/workflow/metadata/keys.d.ts +6 -0
- package/dist/env/workflow/nodes/agent-component-adapter.d.ts +175 -0
- package/dist/env/workflow/nodes/agent-node.d.ts +206 -0
- package/dist/env/workflow/nodes/ask-user-node.d.ts +66 -0
- package/dist/env/workflow/nodes/condition-node.d.ts +39 -0
- package/dist/env/workflow/nodes/index.d.ts +8 -0
- package/dist/env/workflow/nodes/merge-node.d.ts +40 -0
- package/dist/env/workflow/nodes/python-call-node.d.ts +95 -0
- package/dist/env/workflow/nodes/skill-node.d.ts +29 -0
- package/dist/env/workflow/nodes/tool-node.d.ts +58 -0
- package/dist/env/workflow/nodes/workflow-node.d.ts +118 -0
- package/dist/env/workflow/plugins/index.d.ts +6 -0
- package/dist/env/workflow/plugins/lark-cli-workflow-notify-plugin.d.ts +107 -0
- package/dist/env/workflow/plugins/workflow-json-output-plugin.d.ts +166 -0
- package/dist/env/workflow/runtime/runtime-cancellation-scope.d.ts +121 -0
- package/dist/env/workflow/service/index.d.ts +9 -0
- package/dist/env/workflow/service/registry.d.ts +37 -0
- package/dist/env/workflow/service/workflow-service.d.ts +422 -0
- package/dist/env/workflow/storage/index.d.ts +11 -0
- package/dist/env/workflow/storage/mock-repositories.d.ts +106 -0
- package/dist/env/workflow/storage/safe-json.d.ts +62 -0
- package/dist/env/workflow/storage/sqlite.d.ts +57 -0
- package/dist/env/workflow/storage/tag-repo.d.ts +65 -0
- package/dist/env/workflow/storage/workflow-repo.d.ts +161 -0
- package/dist/env/workflow/tools/ask-user-tool.d.ts +35 -0
- package/dist/env/workflow/tools/index.d.ts +16 -0
- package/dist/env/workflow/tools/run-workflow.d.ts +130 -0
- package/dist/env/workflow/tools/submit-json-output-tool.d.ts +38 -0
- package/dist/env/workflow/tools/workflow-add-tool.d.ts +47 -0
- package/dist/env/workflow/tools/workflow-get-tool.d.ts +29 -0
- package/dist/env/workflow/tools/workflow-list-tool.d.ts +55 -0
- package/dist/env/workflow/tools/workflow-run-status-tool.d.ts +26 -0
- package/dist/env/workflow/tools/workflow-run-stop-tool.d.ts +29 -0
- package/dist/env/workflow/tools/workflow-search-tool.d.ts +33 -0
- package/dist/env/workflow/tools/workflow-tag-list-tool.d.ts +59 -0
- package/dist/env/workflow/tools/workflow-validate-tool.d.ts +60 -0
- package/dist/env/workflow/types/context.d.ts +17 -0
- package/dist/env/workflow/types/decorators-types.d.ts +182 -0
- package/dist/env/workflow/types/edge.d.ts +33 -0
- package/dist/env/workflow/types/event.d.ts +869 -0
- package/dist/env/workflow/types/index.d.ts +16 -0
- package/dist/env/workflow/types/run.d.ts +235 -0
- package/dist/env/workflow/types/workflow-error.d.ts +79 -0
- package/dist/env/workflow/types/workflow-hil.d.ts +57 -0
- package/dist/env/workflow/types/workflow-message.d.ts +193 -0
- package/dist/env/workflow/types/workflow-session.d.ts +17 -0
- package/dist/env/workflow/types/workflow.d.ts +654 -0
- package/dist/env/workflow/types_compat.d.ts +10 -0
- package/dist/env/workflow/utils/agent-session-metadata.d.ts +35 -0
- package/dist/env/workflow/utils/build-agent-node-output.d.ts +11 -0
- package/dist/env/workflow/utils/create-workflow.d.ts +35 -0
- package/dist/env/workflow/utils/dependency-prescan.d.ts +67 -0
- package/dist/env/workflow/utils/execution-state.d.ts +46 -0
- package/dist/env/workflow/utils/extract-agent-json-output.d.ts +6 -0
- package/dist/env/workflow/utils/index.d.ts +14 -0
- package/dist/env/workflow/utils/json-schema-to-zod.d.ts +23 -0
- package/dist/env/workflow/utils/node-id-utils.d.ts +20 -0
- package/dist/env/workflow/utils/node-output-contracts.d.ts +137 -0
- package/dist/env/workflow/utils/node-registry-helper.d.ts +36 -0
- package/dist/env/workflow/utils/output-schema-hint.d.ts +7 -0
- package/dist/env/workflow/utils/parse-agent-output-config.d.ts +9 -0
- package/dist/env/workflow/utils/recovery-validator.d.ts +30 -0
- package/dist/env/workflow/utils/sensitive-redact.d.ts +37 -0
- package/dist/env/workflow/utils/session-parser.d.ts +23 -0
- package/dist/env/workflow/utils/session-recovery.d.ts +122 -0
- package/dist/env/workflow/utils/template-contract-validator.d.ts +87 -0
- package/dist/env/workflow/utils/template-resolver.d.ts +285 -0
- package/dist/env/workflow/utils/validate-workflow-definition.d.ts +57 -0
- package/dist/env/workflow/utils/validation-rules.d.ts +103 -0
- package/dist/env/workflow/utils/workflow-message-metadata.d.ts +20 -0
- package/dist/env/workflow/utils/workflow-sanitize.d.ts +51 -0
- package/dist/env/workflow/workflow-component.d.ts +138 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-rcfewbzr.js → roy-agent-core-4sx6sdb2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ezgsem94.js → roy-agent-core-ph5qbqcx.js} +1 -1
- package/dist/util/process/process-tree-killer.d.ts +67 -0
- package/dist/utils/id.d.ts +11 -0
- package/dist/utils/loose-json.d.ts +30 -0
- package/dist/utils/media.d.ts +70 -0
- package/dist/utils/temp-file-manager/index.d.ts +99 -0
- package/package.json +4 -2
- /package/dist/shared/@ai-setting/{roy-agent-core-s214vmmd.js → roy-agent-core-4vpk40ss.js} +0 -0
- /package/dist/shared/@ai-setting/{roy-agent-core-pkpkctvf.js → roy-agent-core-hch2geta.js} +0 -0
- /package/dist/shared/@ai-setting/{roy-agent-core-0cfaqnz9.js → roy-agent-core-k25gv86p.js} +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview W3C TraceContext Propagation
|
|
3
|
+
*
|
|
4
|
+
* 实现 W3C Trace Context 标准中的 traceparent 格式:
|
|
5
|
+
* https://www.w3.org/TR/trace-context/#traceparent-header
|
|
6
|
+
*
|
|
7
|
+
* 格式: 00-{traceId}-{parentSpanId}-{flags}
|
|
8
|
+
* - version: 2字符,固定 "00"
|
|
9
|
+
* - traceId: 32字符,128位追踪ID
|
|
10
|
+
* - parentSpanId: 16字符,64位父Span ID
|
|
11
|
+
* - flags: 2字符,采样标志(当前固定 "01")
|
|
12
|
+
*/
|
|
13
|
+
import type { SpanContext } from "../types";
|
|
14
|
+
/**
|
|
15
|
+
* 将 SpanContext 序列化为 traceparent 字符串
|
|
16
|
+
*
|
|
17
|
+
* W3C TraceContext 语义:
|
|
18
|
+
* - traceparent 中的 spanId 是"发送方 span"的 ID
|
|
19
|
+
* - 接收方会将其作为新 span 的 parentSpanId
|
|
20
|
+
* - 所以应该使用 context.spanId,而非 parentSpanId
|
|
21
|
+
*
|
|
22
|
+
* @param context SpanContext
|
|
23
|
+
* @returns traceparent 格式字符串
|
|
24
|
+
*/
|
|
25
|
+
export declare function serialize(context: SpanContext): string;
|
|
26
|
+
/**
|
|
27
|
+
* 提取的 Trace Context
|
|
28
|
+
*
|
|
29
|
+
* W3C TraceContext 格式: 00-{traceId}-{spanId}-{flags}
|
|
30
|
+
* - {spanId} 是发送方 span 的 ID
|
|
31
|
+
* - 接收方应将其作为新 span 的 parentSpanId
|
|
32
|
+
*/
|
|
33
|
+
export interface ExtractedContext {
|
|
34
|
+
traceId: string;
|
|
35
|
+
/** 发送方 span 的 ID,接收方应作为新 span 的 parentSpanId */
|
|
36
|
+
spanId: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 将 traceparent 字符串反序列化为 ExtractedContext
|
|
40
|
+
*
|
|
41
|
+
* W3C TraceContext 语义:
|
|
42
|
+
* - traceparent 中的 "span-id" 是发送方 span 的 ID
|
|
43
|
+
* - 接收方应该:
|
|
44
|
+
* - 使用提取的 traceId
|
|
45
|
+
* - 将提取的 spanId 作为 parentSpanId
|
|
46
|
+
* - 生成自己的新 spanId
|
|
47
|
+
*
|
|
48
|
+
* @param traceparent traceparent 格式字符串
|
|
49
|
+
* @returns 接收方 ExtractedContext 或 undefined(格式无效)
|
|
50
|
+
*/
|
|
51
|
+
export declare function parse(traceparent: string): ExtractedContext | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* W3C TraceContext Propagation 实现
|
|
54
|
+
*
|
|
55
|
+
* 用于在进程间传递 trace 上下文:
|
|
56
|
+
* - inject: 将 SpanContext 注入到 carrier(环境变量)
|
|
57
|
+
* - extract: 从 carrier(环境变量)提取 SpanContext
|
|
58
|
+
*/
|
|
59
|
+
export declare const propagation: {
|
|
60
|
+
/**
|
|
61
|
+
* 将 SpanContext 注入到 carrier
|
|
62
|
+
*
|
|
63
|
+
* @param carrier 载体对象(通常是环境变量对象)
|
|
64
|
+
* @param context Span 上下文
|
|
65
|
+
*/
|
|
66
|
+
inject(carrier: Record<string, string | undefined>, context: SpanContext): void;
|
|
67
|
+
/**
|
|
68
|
+
* 从 carrier 提取 SpanContext
|
|
69
|
+
*
|
|
70
|
+
* @param carrier 载体对象(通常是环境变量对象)
|
|
71
|
+
* @returns ExtractedContext 或 undefined
|
|
72
|
+
*/
|
|
73
|
+
extract(carrier: Record<string, string | undefined>): ExtractedContext | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* 获取 traceparent 字段名
|
|
76
|
+
*/
|
|
77
|
+
getTraceparentHeader(): string;
|
|
78
|
+
};
|
|
79
|
+
export type { SpanContext } from "../types";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenTelemetry TracerProvider 实现
|
|
3
|
+
*
|
|
4
|
+
* 提供 OpenTelemetry 风格的追踪能力:
|
|
5
|
+
* - TracerProvider: 全局 Tracer 管理器
|
|
6
|
+
* - OTelTracer: 具体 Tracer 实现
|
|
7
|
+
* - OTelSpan: Span 实现
|
|
8
|
+
*
|
|
9
|
+
* 支持 W3C TraceContext 格式的跨进程上下文传递
|
|
10
|
+
*/
|
|
11
|
+
import type { SpanContext, SpanAttributes } from "../types";
|
|
12
|
+
import { type SpanStorage } from "../span-storage";
|
|
13
|
+
/**
|
|
14
|
+
* Span 选项
|
|
15
|
+
*/
|
|
16
|
+
export interface SpanOptions {
|
|
17
|
+
/** 父 Span 上下文(可选) */
|
|
18
|
+
parent?: SpanContext;
|
|
19
|
+
/** Span 属性 */
|
|
20
|
+
attributes?: SpanAttributes;
|
|
21
|
+
/** Span 类型 */
|
|
22
|
+
kind?: string;
|
|
23
|
+
/** 指定 traceId(可选,如果不提供则自动生成) */
|
|
24
|
+
traceId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* 直接传入完整的 SpanContext(可选)
|
|
27
|
+
* 如果提供,将使用此 context 而忽略 parent 和 traceId 选项
|
|
28
|
+
* 用于从外部(如 ES 事件)注入已构建的 context
|
|
29
|
+
*/
|
|
30
|
+
context?: SpanContext;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* OTel Span 接口
|
|
34
|
+
*/
|
|
35
|
+
export interface OTelSpan {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly kind: string;
|
|
38
|
+
readonly spanContext: SpanContext;
|
|
39
|
+
readonly attributes: SpanAttributes;
|
|
40
|
+
startTime?: number;
|
|
41
|
+
endTime?: number;
|
|
42
|
+
error?: string;
|
|
43
|
+
setAttribute(key: string, value: unknown): void;
|
|
44
|
+
addEvent(name: string, attributes?: Record<string, unknown>): void;
|
|
45
|
+
end(result?: unknown, error?: Error): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 结束 span 并返回清理函数(用于恢复父上下文)
|
|
49
|
+
*/
|
|
50
|
+
export interface OTelSpanEndResult {
|
|
51
|
+
/** 结束后的父上下文 */
|
|
52
|
+
parentContext?: SpanContext;
|
|
53
|
+
/** traceId(用于显示) */
|
|
54
|
+
traceId: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* OTel Span 接口扩展 - 提供 endSpan 方法
|
|
58
|
+
*/
|
|
59
|
+
export interface OTelSpanWithEndSpan extends OTelSpan {
|
|
60
|
+
/**
|
|
61
|
+
* 结束 span 并返回父上下文
|
|
62
|
+
* 用于结束根 span 后恢复之前的上下文
|
|
63
|
+
*/
|
|
64
|
+
endSpan(): OTelSpanEndResult;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* OTel Tracer 接口
|
|
68
|
+
*/
|
|
69
|
+
export interface OTelTracer {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
readonly version?: string;
|
|
72
|
+
startSpan(name: string, options?: SpanOptions): OTelSpan;
|
|
73
|
+
/**
|
|
74
|
+
* 结束指定 span 并恢复父上下文
|
|
75
|
+
* @param span 要结束的 span
|
|
76
|
+
* @returns 结束后的父上下文(用于恢复之前的上下文)
|
|
77
|
+
*/
|
|
78
|
+
endSpan(span: OTelSpan): SpanContext | undefined;
|
|
79
|
+
injectToEnv(env: Record<string, string | undefined>): void;
|
|
80
|
+
getCurrentContext(): SpanContext | undefined;
|
|
81
|
+
setCurrentContext(context: SpanContext | undefined): void;
|
|
82
|
+
/**
|
|
83
|
+
* 生成符合 OTel 格式的 traceId(32 字符 16 进制)
|
|
84
|
+
*/
|
|
85
|
+
generateTraceId(): string;
|
|
86
|
+
/**
|
|
87
|
+
* 生成符合 OTel 格式的 spanId(16 字符 16 进制)
|
|
88
|
+
*/
|
|
89
|
+
generateSpanId(): string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* OpenTelemetry TracerProvider
|
|
93
|
+
*
|
|
94
|
+
* 全局 Tracer 管理器,负责:
|
|
95
|
+
* - 维护 Tracer 缓存
|
|
96
|
+
* - 管理存储
|
|
97
|
+
* - 处理上下文初始化
|
|
98
|
+
* - 提供全局 context 供所有 tracer 共享
|
|
99
|
+
*/
|
|
100
|
+
export declare class OTelTracerProvider {
|
|
101
|
+
private tracers;
|
|
102
|
+
private storage;
|
|
103
|
+
private initialized;
|
|
104
|
+
private globalContext;
|
|
105
|
+
readonly instanceId: string;
|
|
106
|
+
constructor(storage?: SpanStorage, dbPath?: string);
|
|
107
|
+
/**
|
|
108
|
+
* 初始化 Provider
|
|
109
|
+
*
|
|
110
|
+
* 从环境变量恢复上下文(如 TRACEPARENT)
|
|
111
|
+
*/
|
|
112
|
+
initialize(): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* 检查是否已初始化
|
|
115
|
+
*/
|
|
116
|
+
isInitialized(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* 获取全局 context(所有 tracer 共享)
|
|
119
|
+
*/
|
|
120
|
+
getGlobalContext(): SpanContext | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* 设置全局 context(所有 tracer 共享)
|
|
123
|
+
*/
|
|
124
|
+
setGlobalContext(context: SpanContext | undefined): void;
|
|
125
|
+
/**
|
|
126
|
+
* 获取 Tracer
|
|
127
|
+
*/
|
|
128
|
+
getTracer(name: string, version?: string): OTelTracer;
|
|
129
|
+
/**
|
|
130
|
+
* 从环境变量恢复上下文
|
|
131
|
+
*/
|
|
132
|
+
private restoreFromEnv;
|
|
133
|
+
/**
|
|
134
|
+
* 关闭 Provider
|
|
135
|
+
*/
|
|
136
|
+
shutdown(): void;
|
|
137
|
+
/**
|
|
138
|
+
* 获取存储
|
|
139
|
+
*/
|
|
140
|
+
getStorage(): SpanStorage;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 获取 TracerProvider 单例
|
|
144
|
+
*/
|
|
145
|
+
export declare function getTracerProvider(): OTelTracerProvider;
|
|
146
|
+
/**
|
|
147
|
+
* 重置 TracerProvider(用于测试)
|
|
148
|
+
*/
|
|
149
|
+
export declare function resetTracerProvider(): void;
|
|
150
|
+
/**
|
|
151
|
+
* 设置 TracerProvider 单例(用于测试中注入自定义 storage)
|
|
152
|
+
*
|
|
153
|
+
* Task #2580 (round 3) — 测试需要为 @TracedAs / wrapFunction 装饰的
|
|
154
|
+
* 函数提供一个带 SQLite 存储的 TracerProvider,以验证 span 名称
|
|
155
|
+
* 和 attributes。
|
|
156
|
+
*/
|
|
157
|
+
export declare function setTracerProvider(provider: OTelTracerProvider): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Span Storage 实现
|
|
3
|
+
*
|
|
4
|
+
* 提供 SQLiteSpanStorage 一种实现,用于持久化存储 span 数据
|
|
5
|
+
*/
|
|
6
|
+
import { type Span, type SpanStorage, type TraceInfo } from "./types";
|
|
7
|
+
export type { SpanStorage, TraceInfo } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* SQLite 存储实现
|
|
10
|
+
*
|
|
11
|
+
* 根据运行时环境使用 bun:sqlite 或 better-sqlite3
|
|
12
|
+
*
|
|
13
|
+
* 注意:此实现仅支持 SQLite 文件存储,不支持 :memory: 模式
|
|
14
|
+
* WAL 模式默认启用以支持跨进程并发访问
|
|
15
|
+
*/
|
|
16
|
+
export declare class SQLiteSpanStorage implements SpanStorage {
|
|
17
|
+
private db;
|
|
18
|
+
private dbPath;
|
|
19
|
+
private initialized;
|
|
20
|
+
/**
|
|
21
|
+
* 创建 SQLiteSpanStorage 实例
|
|
22
|
+
*
|
|
23
|
+
* @param dbPath SQLite 数据库文件路径(必填)
|
|
24
|
+
* @throws Error 如果 dbPath 为空或为 :memory:
|
|
25
|
+
*/
|
|
26
|
+
constructor(dbPath: string);
|
|
27
|
+
initialize(): Promise<void>;
|
|
28
|
+
save(span: Span): void;
|
|
29
|
+
saveBatch(spans: Span[]): void;
|
|
30
|
+
findByTraceId(traceId: string): Span[];
|
|
31
|
+
findBySpanId(spanId: string): Span | undefined;
|
|
32
|
+
listTraces(limit?: number): TraceInfo[];
|
|
33
|
+
deleteByTraceId(traceId: string): void;
|
|
34
|
+
close(): void;
|
|
35
|
+
private rowToSpan;
|
|
36
|
+
private buildTree;
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Trace Context 实现
|
|
3
|
+
*
|
|
4
|
+
* 基于 AsyncLocalStorage 的轻量级追踪上下文实现
|
|
5
|
+
*/
|
|
6
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
7
|
+
import { type SpanContext, type ITraceContext, type TraceContextOptions } from "./types";
|
|
8
|
+
interface RequestContextData {
|
|
9
|
+
requestId: string;
|
|
10
|
+
sessionId?: string;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
spanContext?: SpanContext;
|
|
13
|
+
}
|
|
14
|
+
declare const contextStore: AsyncLocalStorage<RequestContextData>;
|
|
15
|
+
export { contextStore };
|
|
16
|
+
/**
|
|
17
|
+
* 获取当前 TraceContext 实例
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTraceContext(): ITraceContext;
|
|
20
|
+
/**
|
|
21
|
+
* 设置 TraceContext 实现(用于测试或替换)
|
|
22
|
+
*/
|
|
23
|
+
export declare function setTraceContext(impl: ITraceContext): void;
|
|
24
|
+
/**
|
|
25
|
+
* 初始化 TraceContext
|
|
26
|
+
*/
|
|
27
|
+
export declare function initTraceContext(options?: TraceContextOptions): ITraceContext;
|
|
28
|
+
export type { ITraceContext, TraceContextOptions } from "./types";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Log & Trace Component 类型定义
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Span 上下文
|
|
6
|
+
*/
|
|
7
|
+
export interface SpanContext {
|
|
8
|
+
traceId: string;
|
|
9
|
+
spanId: string;
|
|
10
|
+
parentSpanId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Span 属性
|
|
14
|
+
*/
|
|
15
|
+
export interface SpanAttributes {
|
|
16
|
+
[key: string]: string | number | boolean | undefined | Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Span
|
|
20
|
+
*/
|
|
21
|
+
export interface Span {
|
|
22
|
+
traceId: string;
|
|
23
|
+
spanId: string;
|
|
24
|
+
parentSpanId?: string;
|
|
25
|
+
name: string;
|
|
26
|
+
kind: SpanKind;
|
|
27
|
+
status: SpanStatus;
|
|
28
|
+
startTime: number;
|
|
29
|
+
endTime?: number;
|
|
30
|
+
attributes: SpanAttributes;
|
|
31
|
+
result?: unknown;
|
|
32
|
+
error?: string;
|
|
33
|
+
children?: Span[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Span 类型
|
|
37
|
+
*/
|
|
38
|
+
export declare enum SpanKind {
|
|
39
|
+
CLIENT = "client",
|
|
40
|
+
SERVER = "server",
|
|
41
|
+
INTERNAL = "internal"
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Span 状态
|
|
45
|
+
*/
|
|
46
|
+
export declare enum SpanStatus {
|
|
47
|
+
OK = "ok",
|
|
48
|
+
ERROR = "error"
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Trace 信息
|
|
52
|
+
*/
|
|
53
|
+
export interface TraceInfo {
|
|
54
|
+
traceId: string;
|
|
55
|
+
rootSpanName: string;
|
|
56
|
+
startTime: number;
|
|
57
|
+
endTime?: number;
|
|
58
|
+
duration?: number;
|
|
59
|
+
spanCount: number;
|
|
60
|
+
status: "ok" | "error" | "mixed";
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* SpanStorage 接口
|
|
64
|
+
*/
|
|
65
|
+
export interface SpanStorage {
|
|
66
|
+
initialize(): Promise<void>;
|
|
67
|
+
save(span: Span): void;
|
|
68
|
+
saveBatch(spans: Span[]): void;
|
|
69
|
+
findByTraceId(traceId: string): Span[];
|
|
70
|
+
findBySpanId(spanId: string): Span | undefined;
|
|
71
|
+
listTraces(limit?: number): TraceInfo[];
|
|
72
|
+
deleteByTraceId(traceId: string): void;
|
|
73
|
+
close(): void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* TraceContext 选项
|
|
77
|
+
*/
|
|
78
|
+
export interface TraceContextOptions {
|
|
79
|
+
/** 追踪器实现类型 */
|
|
80
|
+
impl?: "lightweight" | "opentelemetry";
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* ITraceContext 接口
|
|
84
|
+
*/
|
|
85
|
+
export interface ITraceContext {
|
|
86
|
+
/** 获取当前请求的 requestId */
|
|
87
|
+
getRequestId(): string | undefined;
|
|
88
|
+
/** 获取当前 Span 上下文 */
|
|
89
|
+
getSpanContext(): SpanContext | undefined;
|
|
90
|
+
/** 更新当前 Span 上下文(用于设置子 span 的 parentSpanId) */
|
|
91
|
+
setSpanContext(spanContext: SpanContext): void;
|
|
92
|
+
/** 在已存在的追踪上下文中执行函数 */
|
|
93
|
+
runWithContext<T>(fn: () => T): T;
|
|
94
|
+
/** 在新追踪上下文中执行函数(同步) */
|
|
95
|
+
runWithNewContext<T>(requestId: string, sessionId: string | undefined, fn: () => T): T;
|
|
96
|
+
/** 在已存在的追踪上下文中执行异步函数 */
|
|
97
|
+
runWithContextAsync<T>(fn: () => Promise<T>): Promise<T>;
|
|
98
|
+
/** 在新追踪上下文中执行函数(异步) */
|
|
99
|
+
runWithNewContextAsync<T>(requestId: string, sessionId: string | undefined, fn: () => Promise<T>): Promise<T>;
|
|
100
|
+
/** 生成新的 requestId */
|
|
101
|
+
generateRequestId(): string;
|
|
102
|
+
/** 初始化追踪上下文(请求入口调用) */
|
|
103
|
+
initContext(requestId: string, sessionId?: string): void;
|
|
104
|
+
/** 创建并进入新的追踪上下文(请求入口使用,返回清理函数) */
|
|
105
|
+
startNewContext(requestId: string, sessionId?: string): () => void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 日志级别
|
|
109
|
+
*/
|
|
110
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
111
|
+
/**
|
|
112
|
+
* Logger 配置
|
|
113
|
+
*/
|
|
114
|
+
export interface LoggerConfig {
|
|
115
|
+
level?: LogLevel;
|
|
116
|
+
prefix?: string;
|
|
117
|
+
filename?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Logger 接口
|
|
121
|
+
*/
|
|
122
|
+
export interface ILogger {
|
|
123
|
+
debug(message: string, data?: unknown): void;
|
|
124
|
+
info(message: string, data?: unknown): void;
|
|
125
|
+
warn(message: string, data?: unknown): void;
|
|
126
|
+
error(message: string, data?: unknown): void;
|
|
127
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve MCP local commands and sanitize npm/npx runtime env.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Prefer a locally installed binary over npx/npm exec when available.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolvePackageRunnerCommand(command: string[], serverDir: string): string[];
|
|
8
|
+
/**
|
|
9
|
+
* When npm prefix is broken (common in Cursor remote), point npm/npx
|
|
10
|
+
* at a writable fallback prefix to avoid ENOENT stderr spam.
|
|
11
|
+
*/
|
|
12
|
+
export declare function augmentNpmEnvForPackageRunner(command: string[], env: Record<string, string>): Record<string, string>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MCP Component 配置
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { ConfigComponent } from "../../config/config-component";
|
|
6
|
+
/**
|
|
7
|
+
* MCP 路径配置
|
|
8
|
+
*/
|
|
9
|
+
export interface McpPath {
|
|
10
|
+
/** 来源类型 */
|
|
11
|
+
type: "user" | "project" | "custom";
|
|
12
|
+
/** 路径 */
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* McpPath Schema
|
|
17
|
+
*/
|
|
18
|
+
export declare const McpPathSchema: z.ZodObject<{
|
|
19
|
+
type: z.ZodEnum<["user", "project", "custom"]>;
|
|
20
|
+
path: z.ZodString;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
path: string;
|
|
23
|
+
type: "custom" | "project" | "user";
|
|
24
|
+
}, {
|
|
25
|
+
path: string;
|
|
26
|
+
type: "custom" | "project" | "user";
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* McpComponent 配置
|
|
30
|
+
*/
|
|
31
|
+
export interface McpComponentConfig {
|
|
32
|
+
/** 扫描路径列表 */
|
|
33
|
+
mcpPaths: McpPath[];
|
|
34
|
+
/** 显式配置的服务器 */
|
|
35
|
+
servers?: Record<string, z.infer<typeof import("./types.js").McpServerConfigSchema>>;
|
|
36
|
+
/** 默认超时(毫秒) */
|
|
37
|
+
timeout?: number;
|
|
38
|
+
/** 是否启用 */
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* McpComponent 配置 Schema
|
|
43
|
+
*/
|
|
44
|
+
export declare const McpComponentConfigSchema: z.ZodObject<{
|
|
45
|
+
mcpPaths: z.ZodArray<z.ZodObject<{
|
|
46
|
+
type: z.ZodEnum<["user", "project", "custom"]>;
|
|
47
|
+
path: z.ZodString;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
path: string;
|
|
50
|
+
type: "custom" | "project" | "user";
|
|
51
|
+
}, {
|
|
52
|
+
path: string;
|
|
53
|
+
type: "custom" | "project" | "user";
|
|
54
|
+
}>, "many">;
|
|
55
|
+
servers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
56
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
+
}, "strip", z.ZodTypeAny, {
|
|
59
|
+
mcpPaths: {
|
|
60
|
+
path: string;
|
|
61
|
+
type: "custom" | "project" | "user";
|
|
62
|
+
}[];
|
|
63
|
+
enabled?: boolean | undefined;
|
|
64
|
+
timeout?: number | undefined;
|
|
65
|
+
servers?: Record<string, any> | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
mcpPaths: {
|
|
68
|
+
path: string;
|
|
69
|
+
type: "custom" | "project" | "user";
|
|
70
|
+
}[];
|
|
71
|
+
enabled?: boolean | undefined;
|
|
72
|
+
timeout?: number | undefined;
|
|
73
|
+
servers?: Record<string, any> | undefined;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* McpComponentOptions(通过 options 传递)
|
|
77
|
+
*/
|
|
78
|
+
export interface McpComponentOptions {
|
|
79
|
+
/** ConfigComponent 实例(必填) */
|
|
80
|
+
configComponent: ConfigComponent;
|
|
81
|
+
/** 配置文件相对路径 */
|
|
82
|
+
configPath?: string;
|
|
83
|
+
/** 环境变量前缀 */
|
|
84
|
+
envPrefix?: string;
|
|
85
|
+
/** 直接传入的配置对象(最高优先级) */
|
|
86
|
+
config?: Partial<McpComponentConfig>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 默认 MCP 配置
|
|
90
|
+
*/
|
|
91
|
+
export declare const DEFAULT_MCP_CONFIG: McpComponentConfig;
|
|
92
|
+
/**
|
|
93
|
+
* 配置 Key 列表(用于 ConfigComponent 注册)
|
|
94
|
+
*/
|
|
95
|
+
export declare const MCP_CONFIG_KEYS: readonly ["mcp.enabled", "mcp.timeout", "mcp.mcpPaths", "mcp.servers"];
|
|
96
|
+
/**
|
|
97
|
+
* 路径类型优先级
|
|
98
|
+
*/
|
|
99
|
+
export declare const MCP_PATH_PRIORITY: Record<string, number>;
|
|
100
|
+
/**
|
|
101
|
+
* 获取路径优先级
|
|
102
|
+
*/
|
|
103
|
+
export declare function getMcpPathPriority(type: string): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MCP Component 导出
|
|
3
|
+
*/
|
|
4
|
+
export type { McpServerConfig, McpServerLocalConfig, McpServerRemoteConfig, DiscoveredMcpServer, McpServerStatus, } from "./types";
|
|
5
|
+
export { McpServerConfigSchema, McpServerLocalConfigSchema, McpServerRemoteConfigSchema, } from "./types";
|
|
6
|
+
export { DEFAULT_MCP_CONFIG, MCP_CONFIG_KEYS, getMcpPathPriority, } from "./config";
|
|
7
|
+
export type { McpComponentConfig, McpComponentOptions, McpPath, } from "./config";
|
|
8
|
+
export { McpComponent } from "./mcp-component";
|
|
9
|
+
export { McpScanner } from "./scanner";
|
|
10
|
+
export { McpLoader, type McpClientEntry } from "./loader";
|
|
11
|
+
export { resolveNpmPrefix, resolveGlobalNodeModulesPath, resolveGlobalBinPath, ensureFallbackNpmPrefix, isUsableNpmPrefix, } from "./npm-prefix";
|
|
12
|
+
export { resolvePackageRunnerCommand, augmentNpmEnvForPackageRunner, } from "./command-resolver";
|
|
13
|
+
export { adaptMcpTool, createMcpToolsDescription, convertInputSchemaToZod } from "./tool/adapter";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MCP 服务器加载器
|
|
3
|
+
*
|
|
4
|
+
* 负责连接和管理 MCP 客户端
|
|
5
|
+
*/
|
|
6
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
8
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
|
+
import type { McpServerConfig, DiscoveredMcpServer } from "./types";
|
|
10
|
+
/**
|
|
11
|
+
* MCP 客户端条目
|
|
12
|
+
*/
|
|
13
|
+
export interface McpClientEntry {
|
|
14
|
+
name: string;
|
|
15
|
+
client: Client;
|
|
16
|
+
transport: StdioClientTransport | StreamableHTTPClientTransport;
|
|
17
|
+
config: McpServerConfig;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* MCP 服务器加载器
|
|
21
|
+
*
|
|
22
|
+
* 负责:
|
|
23
|
+
* 1. 构建默认配置
|
|
24
|
+
* 2. 合并显式配置
|
|
25
|
+
* 3. 连接/断开 MCP 服务器
|
|
26
|
+
*/
|
|
27
|
+
export declare class McpLoader {
|
|
28
|
+
private clients;
|
|
29
|
+
private defaultTimeout;
|
|
30
|
+
constructor(defaultTimeout?: number);
|
|
31
|
+
/**
|
|
32
|
+
* 构建默认配置(从扫描结果)
|
|
33
|
+
*
|
|
34
|
+
* @param server - 扫描发现的 MCP 服务器信息
|
|
35
|
+
* @returns MCP 服务器配置
|
|
36
|
+
*/
|
|
37
|
+
buildDefaultConfig(server: DiscoveredMcpServer): McpServerConfig;
|
|
38
|
+
/**
|
|
39
|
+
* 合并配置(显式配置覆盖默认配置)
|
|
40
|
+
*/
|
|
41
|
+
mergeConfig(defaultConfig: McpServerConfig, explicitConfig?: Partial<McpServerConfig>): McpServerConfig;
|
|
42
|
+
/**
|
|
43
|
+
* 连接到 MCP 服务器
|
|
44
|
+
*/
|
|
45
|
+
connect(name: string, config: McpServerConfig): Promise<McpClientEntry>;
|
|
46
|
+
/**
|
|
47
|
+
* 断开连接
|
|
48
|
+
*/
|
|
49
|
+
disconnect(name: string): Promise<void>;
|
|
50
|
+
private attachStderrDrain;
|
|
51
|
+
private closeTransport;
|
|
52
|
+
/**
|
|
53
|
+
* 断开所有连接
|
|
54
|
+
*/
|
|
55
|
+
disconnectAll(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* 获取客户端
|
|
58
|
+
*/
|
|
59
|
+
getClient(name: string): McpClientEntry | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* 获取所有客户端
|
|
62
|
+
*/
|
|
63
|
+
getAllClients(): Map<string, McpClientEntry>;
|
|
64
|
+
/**
|
|
65
|
+
* 检查是否已连接
|
|
66
|
+
*/
|
|
67
|
+
isConnected(name: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 从 auth.json 加载 minimax API key
|
|
70
|
+
*/
|
|
71
|
+
loadMinimaxApiKey(): Promise<string | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* 注入 minimax 环境变量到 env 对象
|
|
74
|
+
*
|
|
75
|
+
* 如果已存在 MINIMAX_API_KEY,不会覆盖
|
|
76
|
+
*/
|
|
77
|
+
injectMinimaxEnv(env: Record<string, string>): Promise<void>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MCP Component 主组件
|
|
3
|
+
*
|
|
4
|
+
* MCP 客户端管理组件
|
|
5
|
+
*/
|
|
6
|
+
import { BaseComponent, type ComponentConfig } from "../component";
|
|
7
|
+
import type { McpServerStatus } from "./types";
|
|
8
|
+
import type { ToolInfo } from "../tool/types";
|
|
9
|
+
/**
|
|
10
|
+
* McpComponent
|
|
11
|
+
*
|
|
12
|
+
* MCP 客户端管理组件
|
|
13
|
+
*
|
|
14
|
+
* 功能:
|
|
15
|
+
* 1. 配置管理(支持 file/env/object 三层配置)
|
|
16
|
+
* 2. 扫描 MCP 服务器
|
|
17
|
+
* 3. 连接/断开 MCP 服务器
|
|
18
|
+
* 4. 注册 MCP tools 到 ToolComponent
|
|
19
|
+
*/
|
|
20
|
+
export declare class McpComponent extends BaseComponent {
|
|
21
|
+
readonly name = "mcp";
|
|
22
|
+
readonly version = "1.0.0";
|
|
23
|
+
private config;
|
|
24
|
+
private toolComponent?;
|
|
25
|
+
private configComponent?;
|
|
26
|
+
private scanner?;
|
|
27
|
+
private loader?;
|
|
28
|
+
private serverStatus;
|
|
29
|
+
private registeredTools;
|
|
30
|
+
constructor();
|
|
31
|
+
init(config?: ComponentConfig): Promise<void>;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
stop(): Promise<void>;
|
|
34
|
+
private registerConfig;
|
|
35
|
+
private flattenConfig;
|
|
36
|
+
private loadServers;
|
|
37
|
+
private registerServerTools;
|
|
38
|
+
/**
|
|
39
|
+
* 获取服务器状态
|
|
40
|
+
*/
|
|
41
|
+
getServerStatus(name: string): McpServerStatus | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* 列出所有服务器
|
|
44
|
+
*/
|
|
45
|
+
listServers(): McpServerStatus[];
|
|
46
|
+
/**
|
|
47
|
+
* 列出所有 MCP 工具
|
|
48
|
+
*/
|
|
49
|
+
listTools(): ToolInfo[];
|
|
50
|
+
/**
|
|
51
|
+
* 重新加载所有服务器
|
|
52
|
+
*/
|
|
53
|
+
reload(): Promise<void>;
|
|
54
|
+
}
|