@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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview @Traced 装饰器实现
|
|
3
|
+
*
|
|
4
|
+
* 提供函数包装和装饰器来自动创建 Span
|
|
5
|
+
* 支持注解到 async 函数和非 async 函数上
|
|
6
|
+
* 使用 OpenTelemetry 标准方式
|
|
7
|
+
*/
|
|
8
|
+
export interface TracedOptions {
|
|
9
|
+
name?: string;
|
|
10
|
+
recordParams?: boolean;
|
|
11
|
+
recordResult?: boolean;
|
|
12
|
+
recordError?: boolean;
|
|
13
|
+
log?: boolean;
|
|
14
|
+
maxLogSize?: number;
|
|
15
|
+
paramFilter?: (args: any[], argNames?: string[]) => Record<string, any>;
|
|
16
|
+
/**
|
|
17
|
+
* NEW: result filter - returns object whose keys are spread as top-level
|
|
18
|
+
* span attributes. Used to expose named result fields (e.g. diagnostics.length,
|
|
19
|
+
* cache.hit) for cli-e2e-test field-shape verification.
|
|
20
|
+
*/
|
|
21
|
+
resultFilter?: (result: any) => Record<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* NEW: when true (default false), spread paramFilter output keys to top-level
|
|
24
|
+
* attributes in addition to attributes['params']. Used to expose named
|
|
25
|
+
* parameter fields (e.g. serverIds, workspaceRoot) for cli-e2e-test.
|
|
26
|
+
*/
|
|
27
|
+
flattenParamFilter?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* NEW: 返回值驱动的 ERROR 状态。
|
|
30
|
+
*
|
|
31
|
+
* 返回 Error(或任意 truthy)→ 即使函数**正常返回**,也把 span 标成 ERROR;
|
|
32
|
+
* 返回 undefined / null / false → 保持 OK。
|
|
33
|
+
*
|
|
34
|
+
* 解决什么:有些 API 用返回值而不是抛异常来表达失败,例如工具执行返回
|
|
35
|
+
* `{ success: false, error: "Tool not found: bash" }`。旧行为下 span.status
|
|
36
|
+
* 仍是 `ok`(错误只落在 result 属性里),`roy-agent debug trace --list`
|
|
37
|
+
* 聚合出来的 status 全是 ok —— 2026-10-16 的空 checkpoint 事故就是这样
|
|
38
|
+
* 静默了几周,直到人工翻 25GB trace DB 才发现。
|
|
39
|
+
*
|
|
40
|
+
* 为什么不用抛异常:ReAct 循环需要把失败作为 tool result 回灌给模型
|
|
41
|
+
* (AI SDK v6 要求 tool-call / tool-result 1:1 配对)。抛异常会破坏配对,
|
|
42
|
+
* 所以只能在「返回值已是失败」的前提下补一个 span 状态。
|
|
43
|
+
*/
|
|
44
|
+
errorIf?: (result: any) => Error | string | undefined | null | false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @Traced 装饰器工厂
|
|
48
|
+
*
|
|
49
|
+
* 同时支持两种调用约定,避免 toolchain 差异导致崩溃:
|
|
50
|
+
* 1. Legacy(TS experimentalDecorators): (target, propertyKey, descriptor)
|
|
51
|
+
* — 改写 descriptor.value,返回 descriptor。
|
|
52
|
+
* 2. Standard(TC39 / Bun __decorateElement): (value, context)
|
|
53
|
+
* — 返回包装后的函数;context.name 作为默认 span 名。
|
|
54
|
+
*
|
|
55
|
+
* 背景:同一 tsconfig(experimentalDecorators: true)下,Bun 对个别文件
|
|
56
|
+
* (如 event-store.ts)会走 standard 装饰器路径,只传 2 个参数,导致旧实现
|
|
57
|
+
* `descriptor.value` 读到 undefined 崩溃。
|
|
58
|
+
*/
|
|
59
|
+
export declare function Traced(options?: TracedOptions): (target: any, propertyKey?: any, descriptor?: any) => any;
|
|
60
|
+
/**
|
|
61
|
+
* @TracedAs 装饰器工厂 - 使用自定义名称
|
|
62
|
+
*/
|
|
63
|
+
export declare function TracedAs(name: string, options?: Omit<TracedOptions, "name">): (target: any, propertyKey?: any, descriptor?: any) => any;
|
|
64
|
+
/**
|
|
65
|
+
* @TracedLightweight 装饰器工厂 - 轻量级追踪
|
|
66
|
+
*/
|
|
67
|
+
export declare function TracedLightweight(options?: {
|
|
68
|
+
log?: boolean;
|
|
69
|
+
maxLogSize?: number;
|
|
70
|
+
}): (target: any, propertyKey?: any, descriptor?: any) => any;
|
|
71
|
+
/**
|
|
72
|
+
* 包装函数以自动创建 Span
|
|
73
|
+
*
|
|
74
|
+
* 同时支持 async 函数和非 async 函数:
|
|
75
|
+
* - async 函数:自动检测 Promise 并正确处理
|
|
76
|
+
* - 非 async 函数:同步执行,直接返回结果
|
|
77
|
+
*/
|
|
78
|
+
export declare function wrapFunction<T extends (...args: any[]) => any>(fn: T, name: string, options?: {
|
|
79
|
+
recordParams?: boolean;
|
|
80
|
+
recordResult?: boolean;
|
|
81
|
+
recordError?: boolean;
|
|
82
|
+
log?: boolean;
|
|
83
|
+
maxLogSize?: number;
|
|
84
|
+
paramFilter?: (args: any[], argNames?: string[]) => Record<string, any>;
|
|
85
|
+
resultFilter?: (result: any) => Record<string, any>;
|
|
86
|
+
flattenParamFilter?: boolean;
|
|
87
|
+
errorIf?: (result: any) => Error | string | undefined | null | false;
|
|
88
|
+
}): T;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Log & Trace 模块导出
|
|
3
|
+
*
|
|
4
|
+
* OpenTelemetry 标准接口
|
|
5
|
+
*/
|
|
6
|
+
export { type Span, type SpanContext, type SpanAttributes, type TraceInfo, type SpanStorage, type ITraceContext, type LogLevel, type LoggerConfig, type ILogger, type TraceContextOptions, } from "./types";
|
|
7
|
+
export { SpanKind, SpanStatus } from "./types";
|
|
8
|
+
export { SQLiteSpanStorage } from "./span-storage";
|
|
9
|
+
export { LogTraceComponent, type LogTraceConfig, type LogTraceComponentOptions, LogTraceConfigSchema, getDefaultLogDir, getDefaultSpanDbPath, } from "./log-trace-component";
|
|
10
|
+
export { OTelTracerProvider, getTracerProvider, resetTracerProvider, type OTelTracer, type OTelSpan, type SpanOptions, } from "./opentelemetry/tracer-provider";
|
|
11
|
+
export { propagation, serialize, parse, type ExtractedContext, } from "./opentelemetry/propagation";
|
|
12
|
+
export { injectToEnv, injectToEnvWithContext, injectToEnvFromCarrier, getTraceparentHeader, type EnvCarrier, } from "./opentelemetry/propagation-env";
|
|
13
|
+
export { createLogger, setQuietMode, isQuietMode, setConfigComponent as setLoggerConfigComponent, getLogLevel, getLogLevels, getLogDir, getLogFile, setLogDirOverride, getLogDirOverride, simplifyFilePath, getMaxOutput, } from "./logger";
|
|
14
|
+
export { TracedAs, Traced, TracedLightweight, wrapFunction, type TracedOptions } from "./decorator";
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Log & Trace Component
|
|
3
|
+
*
|
|
4
|
+
* 提供日志和追踪的统一组件封装
|
|
5
|
+
*
|
|
6
|
+
* 配置通过 ConfigComponent 实时获取,支持配置热更新
|
|
7
|
+
*/
|
|
8
|
+
import { BaseComponent, type ComponentConfig, type ComponentSchema } from "../component";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { createLogger, type LogLevel } from "./logger";
|
|
11
|
+
import { type OTelTracer } from "./opentelemetry/tracer-provider";
|
|
12
|
+
import { type ITraceContext } from "./trace-context";
|
|
13
|
+
import type { ConfigComponent } from "../../config/config-component";
|
|
14
|
+
/**
|
|
15
|
+
* 获取默认日志目录(基于 XDG 标准)
|
|
16
|
+
* 存储在 XDG_DATA_HOME/roy-agent/logs/
|
|
17
|
+
*/
|
|
18
|
+
export declare function getDefaultLogDir(): string;
|
|
19
|
+
/**
|
|
20
|
+
* 获取默认的 span 数据库路径(基于 XDG 标准)
|
|
21
|
+
* 存储在 XDG_DATA_HOME/roy-agent/traces.db
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDefaultSpanDbPath(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Log & Trace Component 配置 Schema
|
|
26
|
+
*/
|
|
27
|
+
export declare const LogTraceConfigSchema: z.ZodObject<{
|
|
28
|
+
/** 是否启用日志 */
|
|
29
|
+
logging: z.ZodDefault<z.ZodObject<{
|
|
30
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
31
|
+
level: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error"]>>;
|
|
32
|
+
quiet: z.ZodDefault<z.ZodBoolean>;
|
|
33
|
+
file: z.ZodDefault<z.ZodString>;
|
|
34
|
+
dir: z.ZodDefault<z.ZodString>;
|
|
35
|
+
/** 日志输出最大长度(0 表示不限制) */
|
|
36
|
+
maxOutput: z.ZodDefault<z.ZodNumber>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
file: string;
|
|
40
|
+
level: "error" | "debug" | "info" | "warn";
|
|
41
|
+
quiet: boolean;
|
|
42
|
+
dir: string;
|
|
43
|
+
maxOutput: number;
|
|
44
|
+
}, {
|
|
45
|
+
enabled?: boolean | undefined;
|
|
46
|
+
file?: string | undefined;
|
|
47
|
+
level?: "error" | "debug" | "info" | "warn" | undefined;
|
|
48
|
+
quiet?: boolean | undefined;
|
|
49
|
+
dir?: string | undefined;
|
|
50
|
+
maxOutput?: number | undefined;
|
|
51
|
+
}>>;
|
|
52
|
+
/** 是否启用追踪 */
|
|
53
|
+
tracing: z.ZodDefault<z.ZodObject<{
|
|
54
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
55
|
+
dbPath: z.ZodOptional<z.ZodString>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
dbPath?: string | undefined;
|
|
59
|
+
}, {
|
|
60
|
+
enabled?: boolean | undefined;
|
|
61
|
+
dbPath?: string | undefined;
|
|
62
|
+
}>>;
|
|
63
|
+
/** 初始化请求上下文 */
|
|
64
|
+
initContext: z.ZodOptional<z.ZodObject<{
|
|
65
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
66
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
requestId?: string | undefined;
|
|
69
|
+
sessionId?: string | undefined;
|
|
70
|
+
}, {
|
|
71
|
+
requestId?: string | undefined;
|
|
72
|
+
sessionId?: string | undefined;
|
|
73
|
+
}>>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
logging: {
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
file: string;
|
|
78
|
+
level: "error" | "debug" | "info" | "warn";
|
|
79
|
+
quiet: boolean;
|
|
80
|
+
dir: string;
|
|
81
|
+
maxOutput: number;
|
|
82
|
+
};
|
|
83
|
+
tracing: {
|
|
84
|
+
enabled: boolean;
|
|
85
|
+
dbPath?: string | undefined;
|
|
86
|
+
};
|
|
87
|
+
initContext?: {
|
|
88
|
+
requestId?: string | undefined;
|
|
89
|
+
sessionId?: string | undefined;
|
|
90
|
+
} | undefined;
|
|
91
|
+
}, {
|
|
92
|
+
logging?: {
|
|
93
|
+
enabled?: boolean | undefined;
|
|
94
|
+
file?: string | undefined;
|
|
95
|
+
level?: "error" | "debug" | "info" | "warn" | undefined;
|
|
96
|
+
quiet?: boolean | undefined;
|
|
97
|
+
dir?: string | undefined;
|
|
98
|
+
maxOutput?: number | undefined;
|
|
99
|
+
} | undefined;
|
|
100
|
+
tracing?: {
|
|
101
|
+
enabled?: boolean | undefined;
|
|
102
|
+
dbPath?: string | undefined;
|
|
103
|
+
} | undefined;
|
|
104
|
+
initContext?: {
|
|
105
|
+
requestId?: string | undefined;
|
|
106
|
+
sessionId?: string | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
export type LogTraceConfig = z.infer<typeof LogTraceConfigSchema>;
|
|
110
|
+
/**
|
|
111
|
+
* LogTraceComponent 配置选项(通过 options 传递)
|
|
112
|
+
*
|
|
113
|
+
* 配置加载顺序(优先级从低到高):
|
|
114
|
+
* 1. File - 配置文件(通过 configPath 指定)
|
|
115
|
+
* 2. Env - 环境变量(通过 envPrefix 配置前缀)
|
|
116
|
+
* 3. Object - 直接传入的 config 对象(最高优先级)
|
|
117
|
+
*/
|
|
118
|
+
export interface LogTraceComponentOptions {
|
|
119
|
+
/** ConfigComponent 实例(必填) */
|
|
120
|
+
configComponent: ConfigComponent;
|
|
121
|
+
/** 配置文件相对路径(可选,基于 XDG_DATA_HOME) */
|
|
122
|
+
configPath?: string;
|
|
123
|
+
/** 环境变量前缀(可选,默认 "LOG") */
|
|
124
|
+
envPrefix?: string;
|
|
125
|
+
/**
|
|
126
|
+
* 项目根目录(可选,默认 process.cwd())
|
|
127
|
+
* 用于加载 ${cwd}/.roy/config.jsonc 项目级配置
|
|
128
|
+
*/
|
|
129
|
+
cwd?: string;
|
|
130
|
+
/** 回调函数 */
|
|
131
|
+
callbacks?: {
|
|
132
|
+
onLogLevelChange?: (level: LogLevel) => void;
|
|
133
|
+
};
|
|
134
|
+
/** 直接传入的配置对象(可选,优先级最高) */
|
|
135
|
+
config?: Partial<LogTraceConfig>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Log & Trace Component
|
|
139
|
+
*
|
|
140
|
+
* 提供统一的日志和追踪能力
|
|
141
|
+
* 配置通过 ConfigComponent 实时获取,支持配置热更新
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // 通过 ConfigComponent 初始化
|
|
145
|
+
* const configComponent = new ConfigComponent();
|
|
146
|
+
* const component = new LogTraceComponent();
|
|
147
|
+
* await component.init({
|
|
148
|
+
* env, // Environment 实例(必填)
|
|
149
|
+
* options: { configComponent }
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* // 配置更新后,日志级别会自动热更新
|
|
153
|
+
* configComponent.set("log-trace.logging.level", "debug");
|
|
154
|
+
*
|
|
155
|
+
* // 初始化追踪上下文
|
|
156
|
+
* component.initContext("request-123", "session-456");
|
|
157
|
+
*
|
|
158
|
+
* // 使用日志
|
|
159
|
+
* component.getLogger().info("Hello, world!");
|
|
160
|
+
*
|
|
161
|
+
* // 使用追踪
|
|
162
|
+
* const span = component.getTracer().startSpan("my-span");
|
|
163
|
+
* component.getTracer().endSpan(span);
|
|
164
|
+
*/
|
|
165
|
+
export declare class LogTraceComponent extends BaseComponent {
|
|
166
|
+
readonly name = "log-trace";
|
|
167
|
+
readonly version = "1.0.0";
|
|
168
|
+
private config?;
|
|
169
|
+
private configComponent?;
|
|
170
|
+
private tracer?;
|
|
171
|
+
private traceContext?;
|
|
172
|
+
/** 配置变更 watcher 清理函数 */
|
|
173
|
+
private configWatcher?;
|
|
174
|
+
constructor();
|
|
175
|
+
/**
|
|
176
|
+
* 初始化组件
|
|
177
|
+
*
|
|
178
|
+
* 配置加载优先级(从高到低):
|
|
179
|
+
* 1. Object - 直接传入的 config 对象
|
|
180
|
+
* 2. Env - 环境变量(通过 envPrefix 配置前缀)
|
|
181
|
+
* 3. File - 配置文件(通过 configPath 指定)
|
|
182
|
+
*/
|
|
183
|
+
init(config: ComponentConfig): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* 注册配置到 ConfigComponent
|
|
186
|
+
*
|
|
187
|
+
* 遵循 SessionComponent 模式:
|
|
188
|
+
* 1. 使用 registerComponent 注册配置结构
|
|
189
|
+
* 2. 使用 load 加载配置
|
|
190
|
+
* 3. 设置默认值
|
|
191
|
+
* 4. 处理环境变量后备方案
|
|
192
|
+
* 5. 处理 config 对象
|
|
193
|
+
*
|
|
194
|
+
* 配置加载顺序(优先级从低到高):
|
|
195
|
+
* 1. FileSource - 从配置文件加载(最低)
|
|
196
|
+
* 2. EnvSource - 从环境变量加载(中等)
|
|
197
|
+
* 3. MemorySource - 直接配置对象(最高)
|
|
198
|
+
*/
|
|
199
|
+
private registerConfig;
|
|
200
|
+
/**
|
|
201
|
+
* 将配置对象展平为点号路径
|
|
202
|
+
*/
|
|
203
|
+
private flattenConfig;
|
|
204
|
+
/**
|
|
205
|
+
* 注册配置热更新监听
|
|
206
|
+
*/
|
|
207
|
+
private registerConfigWatcher;
|
|
208
|
+
/**
|
|
209
|
+
* 处理配置变更
|
|
210
|
+
*/
|
|
211
|
+
protected onConfigChange(event: {
|
|
212
|
+
key: string;
|
|
213
|
+
oldValue?: unknown;
|
|
214
|
+
newValue?: unknown;
|
|
215
|
+
}): void;
|
|
216
|
+
/**
|
|
217
|
+
* 创建存储实例
|
|
218
|
+
*
|
|
219
|
+
* @throws Error 如果未配置 dbPath
|
|
220
|
+
*/
|
|
221
|
+
private createStorage;
|
|
222
|
+
/**
|
|
223
|
+
* 配置日志系统
|
|
224
|
+
*
|
|
225
|
+
* 默认 quiet 模式开启,除非显式设置为 false
|
|
226
|
+
*/
|
|
227
|
+
private configureLogging;
|
|
228
|
+
/**
|
|
229
|
+
* 初始化追踪上下文
|
|
230
|
+
*
|
|
231
|
+
* @param requestId 请求 ID
|
|
232
|
+
* @param sessionId 会话 ID(可选)
|
|
233
|
+
*/
|
|
234
|
+
initContext(requestId: string, sessionId?: string): void;
|
|
235
|
+
/**
|
|
236
|
+
* 创建新的追踪上下文(返回清理函数)
|
|
237
|
+
*
|
|
238
|
+
* @param requestId 请求 ID
|
|
239
|
+
* @param sessionId 会话 ID(可选)
|
|
240
|
+
*/
|
|
241
|
+
startContext(requestId: string, sessionId?: string): () => void;
|
|
242
|
+
/**
|
|
243
|
+
* 获取 Logger
|
|
244
|
+
*
|
|
245
|
+
* @param prefix 日志前缀
|
|
246
|
+
*/
|
|
247
|
+
getLogger(prefix?: string): ReturnType<typeof createLogger>;
|
|
248
|
+
/**
|
|
249
|
+
* 获取 Tracer
|
|
250
|
+
*/
|
|
251
|
+
getTracer(): OTelTracer;
|
|
252
|
+
/**
|
|
253
|
+
* 获取 Trace Context
|
|
254
|
+
*/
|
|
255
|
+
getTraceContext(): ITraceContext | undefined;
|
|
256
|
+
/**
|
|
257
|
+
* 获取当前 requestId
|
|
258
|
+
*/
|
|
259
|
+
getRequestId(): string | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* 停止组件
|
|
262
|
+
*/
|
|
263
|
+
onStop(): Promise<void>;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Log & Trace Component Schema
|
|
267
|
+
*/
|
|
268
|
+
export declare const logTraceComponentSchema: ComponentSchema;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview LogTrace Component 配置注册
|
|
3
|
+
*
|
|
4
|
+
* 使用 ConfigComponent.registerComponent() 机制统一管理配置
|
|
5
|
+
*/
|
|
6
|
+
import type { ComponentRegistration } from "../../config/config-component";
|
|
7
|
+
/**
|
|
8
|
+
* LogTrace Component 默认配置值
|
|
9
|
+
*
|
|
10
|
+
* 注意:键使用完整格式(带 "log-trace." 前缀),在 registerConfig 中手动设置
|
|
11
|
+
* 注意:动态默认值(logging.dir, logging.file, logging.maxOutput)在 registerConfig 中单独处理
|
|
12
|
+
*/
|
|
13
|
+
export declare const LOG_TRACE_DEFAULTS: Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* LogTrace Component 配置注册常量
|
|
16
|
+
*
|
|
17
|
+
* 定义了所有 LogTrace 相关的配置项和来源
|
|
18
|
+
*
|
|
19
|
+
* Source 优先级(数值越大越高):
|
|
20
|
+
* - project: 25(${cwd}/.roy/config.jsonc,最高优先级)— 由 LogTraceComponent.registerConfig() 手动注册
|
|
21
|
+
* - env: 20(环境变量)
|
|
22
|
+
* - file: 10(全局 XDG 配置,默认)
|
|
23
|
+
* - memory: 0(默认值,代码设置)
|
|
24
|
+
*/
|
|
25
|
+
export declare const LOG_TRACE_CONFIG_REGISTRATION: ComponentRegistration;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Logger - 统一日志系统
|
|
3
|
+
*
|
|
4
|
+
* 遵循 XDG Base Directory Specification:
|
|
5
|
+
* - 日志存储在 XDG_DATA_HOME/roy-agent/logs/ (默认 ~/.local/share/roy-agent/logs/)
|
|
6
|
+
* 无需配置,自动创建目录
|
|
7
|
+
*
|
|
8
|
+
* 支持 traceId 追踪:通过 trace-context 模块自动注入
|
|
9
|
+
*
|
|
10
|
+
* 配置优先级(从高到低):
|
|
11
|
+
* 1. ConfigComponent (log-trace.logging.level, log-trace.logging.dir)
|
|
12
|
+
* 2. 环境变量 (LOG_LEVEL, LOG_DIR)
|
|
13
|
+
* 3. setLogDirOverride() 手动设置
|
|
14
|
+
* 4. XDG 默认路径
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* 简化 Bun file: 协议的编码路径
|
|
18
|
+
* 例如: packages+core/node_modules/.bun/@roy-agent+core@file+packages+core/node_modules/@roy-agent/core/src/env/agent/agent-component.ts
|
|
19
|
+
* 转换为: packages/core/src/env/agent/agent-component.ts
|
|
20
|
+
*/
|
|
21
|
+
export declare function simplifyFilePath(fullPath: string): string;
|
|
22
|
+
import type { LogLevel, ILogger } from "./types";
|
|
23
|
+
export declare function isQuietMode(): boolean;
|
|
24
|
+
export declare function setQuietMode(enabled: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* 设置 ConfigComponent 实例(用于实时配置读取)
|
|
27
|
+
*/
|
|
28
|
+
export declare function setConfigComponent(component: any): void;
|
|
29
|
+
/**
|
|
30
|
+
* 获取日志级别(支持热更新)
|
|
31
|
+
*/
|
|
32
|
+
export declare function getLogLevel(): LogLevel;
|
|
33
|
+
/**
|
|
34
|
+
* 获取指定类别的日志级别
|
|
35
|
+
*
|
|
36
|
+
* 支持按类别配置日志级别,配置路径:log-trace.logging.levels.<category>
|
|
37
|
+
*
|
|
38
|
+
* @param category 日志类别(如 "llm", "agent", "tool")
|
|
39
|
+
* @returns 该类别的日志级别,如果未配置则返回全局级别
|
|
40
|
+
*/
|
|
41
|
+
export declare function getCategoryLogLevel(category: string): LogLevel;
|
|
42
|
+
/**
|
|
43
|
+
* 获取日志文件名
|
|
44
|
+
* 实时从 ConfigComponent 读取(支持 env/file/memory 多 source)
|
|
45
|
+
*/
|
|
46
|
+
export declare function getLogFile(): string;
|
|
47
|
+
export declare function getLogDir(): string;
|
|
48
|
+
/**
|
|
49
|
+
* 获取日志输出最大长度配置
|
|
50
|
+
* 实时从 ConfigComponent 读取
|
|
51
|
+
*
|
|
52
|
+
* @returns 配置的值(0 表示不限制),如果未配置则返回 undefined
|
|
53
|
+
*/
|
|
54
|
+
export declare function getMaxOutput(): number | undefined;
|
|
55
|
+
export declare function setLogDirOverride(dir: string): void;
|
|
56
|
+
export declare function getLogDirOverride(): string | undefined;
|
|
57
|
+
declare class Logger implements ILogger {
|
|
58
|
+
private prefix;
|
|
59
|
+
constructor(prefix: string);
|
|
60
|
+
private shouldLog;
|
|
61
|
+
private ensureLogDirectory;
|
|
62
|
+
private getCallerLocation;
|
|
63
|
+
private getRelativePath;
|
|
64
|
+
private formatMessage;
|
|
65
|
+
private writeToFile;
|
|
66
|
+
private log;
|
|
67
|
+
debug(message: string, data?: unknown): void;
|
|
68
|
+
info(message: string, data?: unknown): void;
|
|
69
|
+
warn(message: string, data?: unknown): void;
|
|
70
|
+
error(message: string, data?: unknown): void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 创建或获取 Logger 实例
|
|
74
|
+
* @param prefix Logger 前缀
|
|
75
|
+
*
|
|
76
|
+
* 日志文件名通过 ConfigComponent 实时读取(log-trace.logging.file)
|
|
77
|
+
*/
|
|
78
|
+
export declare function createLogger(prefix: string): Logger;
|
|
79
|
+
/**
|
|
80
|
+
* 获取所有日志级别
|
|
81
|
+
*/
|
|
82
|
+
export declare function getLogLevels(): LogLevel[];
|
|
83
|
+
export type { LogLevel, ILogger } from "./types";
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview CLI Propagation 模块
|
|
3
|
+
*
|
|
4
|
+
* 提供 CLI 启动时从环境变量提取 trace context 的功能:
|
|
5
|
+
* - 从 TRACEPARENT 环境变量提取父 span context
|
|
6
|
+
* - 支持 W3C TraceContext 格式
|
|
7
|
+
*
|
|
8
|
+
* 使用场景:
|
|
9
|
+
* - Workflow CLI 启动时从父进程传递 trace context
|
|
10
|
+
* - 子进程能够关联到主进程的 trace
|
|
11
|
+
*/
|
|
12
|
+
import type { SpanContext } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* CLI 传播选项
|
|
15
|
+
*/
|
|
16
|
+
export interface CliPropagationOptions {
|
|
17
|
+
/** 是否静默模式(不输出日志) */
|
|
18
|
+
silent?: boolean;
|
|
19
|
+
/** 自定义 carrier(默认从 process.env 读取) */
|
|
20
|
+
carrier?: Record<string, string | undefined>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 提取结果
|
|
24
|
+
*/
|
|
25
|
+
export interface ExtractResult {
|
|
26
|
+
/** 提取的 traceId */
|
|
27
|
+
traceId: string;
|
|
28
|
+
/** 父 spanId(新 span 的 parentSpanId) */
|
|
29
|
+
parentSpanId: string;
|
|
30
|
+
/** 原始的 traceparent 字符串 */
|
|
31
|
+
rawTraceparent: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 从环境变量提取 trace context
|
|
35
|
+
*
|
|
36
|
+
* @param options 传播选项
|
|
37
|
+
* @returns 提取结果,如果不存在则返回 undefined
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractFromEnv(options?: CliPropagationOptions): ExtractResult | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* 从提取结果构建 SpanContext
|
|
42
|
+
*
|
|
43
|
+
* 用于初始化 OTelTracerProvider 时构建传入的上下文
|
|
44
|
+
*
|
|
45
|
+
* @param extracted 提取结果
|
|
46
|
+
* @returns 适用于初始化 provider 的 SpanContext
|
|
47
|
+
*/
|
|
48
|
+
export declare function buildSpanContextFromExtracted(extracted: ExtractResult): SpanContext;
|
|
49
|
+
/**
|
|
50
|
+
* 从提取结果构建完整 SpanContext(包含占位 spanId)
|
|
51
|
+
*
|
|
52
|
+
* 用于初始化 OTelTracerProvider 的 tracer.currentContext
|
|
53
|
+
*
|
|
54
|
+
* @param extracted 提取结果
|
|
55
|
+
* @returns SpanContext,其中 spanId 待 provider 生成新值
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildInitialSpanContext(extracted: ExtractResult): SpanContext;
|
|
58
|
+
/**
|
|
59
|
+
* CLI 初始化追踪器
|
|
60
|
+
*
|
|
61
|
+
* 从环境变量提取 trace context 并初始化 OTelTracerProvider
|
|
62
|
+
*
|
|
63
|
+
* 使用场景:
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // 在 CLI 启动时调用
|
|
66
|
+
* import { initTracerFromEnv } from './opentelemetry/cli-propagation';
|
|
67
|
+
* import { getTracerProvider } from './opentelemetry/tracer-provider';
|
|
68
|
+
*
|
|
69
|
+
* async function main() {
|
|
70
|
+
* const provider = getTracerProvider();
|
|
71
|
+
* await provider.initialize();
|
|
72
|
+
*
|
|
73
|
+
* // 尝试从环境变量恢复上下文
|
|
74
|
+
* initTracerFromEnv(provider);
|
|
75
|
+
*
|
|
76
|
+
* // 继续正常执行...
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param provider OTelTracerProvider 实例
|
|
81
|
+
* @param options 传播选项
|
|
82
|
+
*/
|
|
83
|
+
export declare function initTracerFromEnv(provider: {
|
|
84
|
+
getTracer: (name: string) => {
|
|
85
|
+
setCurrentContext: (ctx: SpanContext | undefined) => void;
|
|
86
|
+
};
|
|
87
|
+
}, options?: CliPropagationOptions): void;
|
|
88
|
+
/**
|
|
89
|
+
* 检查是否存在 trace context
|
|
90
|
+
*
|
|
91
|
+
* @returns 是否存在有效的 trace context
|
|
92
|
+
*/
|
|
93
|
+
export declare function hasTraceContext(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* 获取当前 traceId(如果存在)
|
|
96
|
+
*
|
|
97
|
+
* @returns traceId 或 undefined
|
|
98
|
+
*/
|
|
99
|
+
export declare function getTraceId(): string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* 获取当前 parentSpanId(如果存在)
|
|
102
|
+
*
|
|
103
|
+
* @returns parentSpanId 或 undefined
|
|
104
|
+
*/
|
|
105
|
+
export declare function getParentSpanId(): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OpenTelemetry 模块统一导出
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* import { getTracerProvider, propagation } from './opentelemetry/mod';
|
|
6
|
+
*
|
|
7
|
+
* // 初始化
|
|
8
|
+
* const provider = getTracerProvider();
|
|
9
|
+
* await provider.initialize();
|
|
10
|
+
*
|
|
11
|
+
* // 获取 Tracer
|
|
12
|
+
* const tracer = provider.getTracer('my-service');
|
|
13
|
+
*
|
|
14
|
+
* // 启动 Span
|
|
15
|
+
* const span = tracer.startSpan('my-operation');
|
|
16
|
+
*
|
|
17
|
+
* // 注入到环境变量
|
|
18
|
+
* const env: Record<string, string | undefined> = {};
|
|
19
|
+
* tracer.injectToEnv(env);
|
|
20
|
+
* process.env = { ...process.env, ...env };
|
|
21
|
+
*/
|
|
22
|
+
export { OTelTracerProvider, getTracerProvider, resetTracerProvider, type OTelTracer, type OTelSpan, type SpanOptions } from './tracer-provider';
|
|
23
|
+
export { propagation, serialize, parse, type ExtractedContext } from './propagation';
|
|
24
|
+
export { injectToEnv, injectToEnvWithContext, injectToEnvFromCarrier, getTraceparentHeader, type EnvCarrier } from './propagation-env';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Propagation Env Module
|
|
3
|
+
*
|
|
4
|
+
* 提供便捷的环境变量注入功能,用于在子进程执行时传递 trace context。
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { injectToEnv, injectToEnvWithContext } from './propagation-env';
|
|
9
|
+
*
|
|
10
|
+
* // 在 Bash 工具中执行子进程前:
|
|
11
|
+
* const traceEnv = injectToEnv(); // 从当前 OTelTracerProvider 获取并注入
|
|
12
|
+
* const options = {
|
|
13
|
+
* env: { ...process.env, ...traceEnv, ...env },
|
|
14
|
+
* };
|
|
15
|
+
* spawn(command, args, options);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { SpanContext } from "../types";
|
|
19
|
+
/**
|
|
20
|
+
* 环境变量对象类型
|
|
21
|
+
*/
|
|
22
|
+
export type EnvCarrier = Record<string, string | undefined>;
|
|
23
|
+
/**
|
|
24
|
+
* 从当前 OTelTracerProvider 获取上下文并注入到环境变量
|
|
25
|
+
*
|
|
26
|
+
* 这是一个便捷函数,封装了常见的注入模式:
|
|
27
|
+
* 1. 从全局 TracerProvider 获取当前 Tracer
|
|
28
|
+
* 2. 获取当前 span context
|
|
29
|
+
* 3. 注入到目标环境变量
|
|
30
|
+
*
|
|
31
|
+
* @param env 目标环境变量对象(默认:{})
|
|
32
|
+
* @returns 注入了 TRACEPARENT 的环境变量对象
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const env = injectToEnv({ PATH: '/usr/bin' });
|
|
37
|
+
* // env.TRACEPARENT = '00-{traceId}-{spanId}-01'
|
|
38
|
+
* // env.PATH = '/usr/bin'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function injectToEnv(env?: EnvCarrier): EnvCarrier;
|
|
42
|
+
/**
|
|
43
|
+
* 将指定的 SpanContext 直接注入到环境变量
|
|
44
|
+
*
|
|
45
|
+
* 与 injectToEnv 不同,这个函数不需要访问全局 TracerProvider,
|
|
46
|
+
* 直接使用传入的 SpanContext 进行注入。
|
|
47
|
+
*
|
|
48
|
+
* @param env 目标环境变量对象
|
|
49
|
+
* @param context 要注入的 SpanContext
|
|
50
|
+
* @returns 注入了 TRACEPARENT 的环境变量对象
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const span = tracer.startSpan('my-span');
|
|
55
|
+
* const env = injectToEnvWithContext({}, span.spanContext);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function injectToEnvWithContext(env: EnvCarrier, context: SpanContext): EnvCarrier;
|
|
59
|
+
/**
|
|
60
|
+
* 从源环境变量 carrier 复制 TRACEPARENT 到目标 carrier
|
|
61
|
+
*
|
|
62
|
+
* 用于将一个环境变量对象中的 trace context 传递到另一个:
|
|
63
|
+
* - 从 process.env 复制到子进程的环境变量
|
|
64
|
+
* - 从父进程环境变量复制到子进程环境变量
|
|
65
|
+
*
|
|
66
|
+
* @param target 目标 carrier(将被修改)
|
|
67
|
+
* @param source 源 carrier
|
|
68
|
+
* @returns 目标 carrier
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // 在 fork 子进程时继承父进程的 trace context
|
|
73
|
+
* const childEnv = injectToEnvFromCarrier({}, process.env);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function injectToEnvFromCarrier(target: EnvCarrier, source: EnvCarrier): EnvCarrier;
|
|
77
|
+
/**
|
|
78
|
+
* 获取 TRACEPARENT 字段名
|
|
79
|
+
*/
|
|
80
|
+
export declare function getTraceparentHeader(): string;
|
|
81
|
+
export type { SpanContext } from "../types";
|