@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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Global HookManager - 全局 Hook 单例
|
|
3
|
+
*
|
|
4
|
+
* 所有 Component 的 Hook 都注册到统一的全局实例
|
|
5
|
+
*/
|
|
6
|
+
import { HookManager } from "./hook-manager";
|
|
7
|
+
import type { HookResult } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* 全局 HookManager 实例
|
|
10
|
+
*
|
|
11
|
+
* 所有 Agent/LLM/Tool hooks 都注册到这个实例
|
|
12
|
+
*/
|
|
13
|
+
export declare const globalHookManager: HookManager<unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Agent Hook 点(新版统一命名)
|
|
16
|
+
*/
|
|
17
|
+
export declare const AgentHookPoints: {
|
|
18
|
+
readonly BEFORE_START: "agent:before.start";
|
|
19
|
+
readonly BEFORE_LLM: "agent:before.llm";
|
|
20
|
+
readonly AFTER_LLM: "agent:after.llm";
|
|
21
|
+
readonly BEFORE_TOOL: "agent:before.tool";
|
|
22
|
+
readonly AFTER_TOOL: "agent:after.tool";
|
|
23
|
+
readonly ON_ITERATION: "agent:on.iteration";
|
|
24
|
+
readonly ON_THRESHOLD: "agent:on.threshold";
|
|
25
|
+
readonly AFTER_COMPLETE: "agent:after.complete";
|
|
26
|
+
readonly ON_ERROR: "agent:on.error";
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* LLM Hook 点
|
|
30
|
+
*/
|
|
31
|
+
export declare const LLMHookPoints: {
|
|
32
|
+
readonly BEFORE_INVOKE: "llm:before.invoke";
|
|
33
|
+
readonly AFTER_INVOKE: "llm:after.invoke";
|
|
34
|
+
readonly ON_STREAM: "llm:on.stream";
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Tool Hook 点
|
|
38
|
+
*/
|
|
39
|
+
export declare const ToolHookPoints: {
|
|
40
|
+
readonly BEFORE_EXECUTE: "tool:before.execute";
|
|
41
|
+
readonly AFTER_EXECUTE: "tool:after.execute";
|
|
42
|
+
readonly BEFORE_REGISTER: "tool:before.register";
|
|
43
|
+
readonly AFTER_REGISTER: "tool:after.register";
|
|
44
|
+
readonly ON_ERROR: "tool:on.error";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 旧版 Tool Hook 点别名映射(向后兼容)
|
|
48
|
+
*/
|
|
49
|
+
export declare const LegacyToolHookPoints: {
|
|
50
|
+
readonly BEFORE_EXECUTE: "tool:before.execute";
|
|
51
|
+
readonly AFTER_EXECUTE: "tool:after.execute";
|
|
52
|
+
readonly BEFORE_REGISTER: "tool:before.register";
|
|
53
|
+
readonly AFTER_REGISTER: "tool:after.register";
|
|
54
|
+
readonly ON_ERROR: "tool:on.error";
|
|
55
|
+
readonly BEFORE_TOOL: "before.tool";
|
|
56
|
+
readonly AFTER_TOOL: "after.tool";
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 执行 Agent Hook(不带干预)
|
|
60
|
+
*/
|
|
61
|
+
export declare function executeAgentHook(hookPoint: string, data: unknown, metadata?: Record<string, unknown>): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* 执行 Agent Hook(带干预检查)
|
|
64
|
+
*/
|
|
65
|
+
export declare function executeAgentHookWithIntervention(hookPoint: string, data: unknown, metadata?: Record<string, unknown>): Promise<HookResult>;
|
|
66
|
+
/**
|
|
67
|
+
* 执行 LLM Hook(不带干预)
|
|
68
|
+
*/
|
|
69
|
+
export declare function executeLLMHook(hookPoint: string, data: unknown, metadata?: Record<string, unknown>): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* 执行 Tool Hook(不带干预)
|
|
72
|
+
*/
|
|
73
|
+
export declare function executeToolHook(hookPoint: string, data: unknown, metadata?: Record<string, unknown>): Promise<void>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hook Manager - 统一管理 Component 的 Hook
|
|
3
|
+
*
|
|
4
|
+
* 提供:
|
|
5
|
+
* - Hook 注册和管理
|
|
6
|
+
* - 按优先级排序执行
|
|
7
|
+
* - 错误隔离
|
|
8
|
+
* - 动态添加/移除
|
|
9
|
+
* - 干预机制(executeWithIntervention)
|
|
10
|
+
*/
|
|
11
|
+
import type { Hook, HookResult } from "./types";
|
|
12
|
+
/**
|
|
13
|
+
* HookManager 配置
|
|
14
|
+
*/
|
|
15
|
+
export interface HookManagerOptions {
|
|
16
|
+
/** 组件名称(用于上下文) */
|
|
17
|
+
componentName?: string;
|
|
18
|
+
/** 组件版本(用于上下文) */
|
|
19
|
+
componentVersion?: string;
|
|
20
|
+
/** 默认优先级 */
|
|
21
|
+
defaultPriority?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* HookManager
|
|
25
|
+
*
|
|
26
|
+
* 统一管理 Component 的 Hook
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const manager = new HookManager<MyContext>();
|
|
31
|
+
*
|
|
32
|
+
* // 注册 Hook
|
|
33
|
+
* manager.register("before-action", {
|
|
34
|
+
* name: "my-hook",
|
|
35
|
+
* priority: 10,
|
|
36
|
+
* execute: async (ctx) => { /* ... *\/ }
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // 执行 Hooks
|
|
40
|
+
* await manager.execute("before-action", data);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class HookManager<T = unknown> {
|
|
44
|
+
private _hooks;
|
|
45
|
+
private componentName;
|
|
46
|
+
private componentVersion;
|
|
47
|
+
private defaultPriority;
|
|
48
|
+
constructor(options?: HookManagerOptions);
|
|
49
|
+
/**
|
|
50
|
+
* 注册 Hook 到指定 hook 点
|
|
51
|
+
*/
|
|
52
|
+
register(hookPoint: string, hook: Hook<T>): void;
|
|
53
|
+
/**
|
|
54
|
+
* 注册多个 Hook
|
|
55
|
+
*/
|
|
56
|
+
registerMany(hookPoint: string, hooks: Hook<T>[]): void;
|
|
57
|
+
/**
|
|
58
|
+
* 按名称取消注册 Hook
|
|
59
|
+
* @returns 是否成功取消注册
|
|
60
|
+
*/
|
|
61
|
+
unregister(hookPoint: string, name: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 取消注册所有指定 hook 点的 Hook
|
|
64
|
+
*/
|
|
65
|
+
unregisterAll(hookPoint: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* 执行指定 hook 点的所有 Hook
|
|
68
|
+
*
|
|
69
|
+
* 支持 pluginEnabled 检查:
|
|
70
|
+
* - 如果 hook 有 pluginName 和 sourceId,则检查 metadata.pluginEnabled[key] 是否为 true
|
|
71
|
+
* - 如果未启用,则跳过该 hook
|
|
72
|
+
* - 如果 hook 没有 pluginName/sourceId,则总是执行
|
|
73
|
+
*
|
|
74
|
+
* 也会从线程变量 EnvContext 中获取信息补充到 metadata
|
|
75
|
+
*/
|
|
76
|
+
execute(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* 执行指定 hook 点的所有 Hook 并收集返回值
|
|
79
|
+
*/
|
|
80
|
+
executeAndCollect<R>(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<R[]>;
|
|
81
|
+
/**
|
|
82
|
+
* 获取指定 hook 点的 Hook 数量
|
|
83
|
+
*/
|
|
84
|
+
count(hookPoint: string): number;
|
|
85
|
+
/**
|
|
86
|
+
* 清空所有 Hook
|
|
87
|
+
*/
|
|
88
|
+
clear(): void;
|
|
89
|
+
/**
|
|
90
|
+
* 获取所有已注册的 hook 点
|
|
91
|
+
*/
|
|
92
|
+
getHookPoints(): string[];
|
|
93
|
+
/**
|
|
94
|
+
* 检查 hook 点是否有任何 Hook
|
|
95
|
+
*/
|
|
96
|
+
hasHooks(hookPoint: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* 设置组件信息
|
|
99
|
+
*/
|
|
100
|
+
setComponentInfo(name: string, version: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* 获取所有注册的 hooks(只读副本)
|
|
103
|
+
*/
|
|
104
|
+
get hooks(): ReadonlyMap<string, Hook<T>[]>;
|
|
105
|
+
/**
|
|
106
|
+
* 执行 Hook 并支持干预机制
|
|
107
|
+
*
|
|
108
|
+
* 如果任何一个 Hook 返回 { stop: true },执行会停止
|
|
109
|
+
* Hook 可以通过返回 HookResult 来执行干预动作
|
|
110
|
+
*
|
|
111
|
+
* @param hookPoint Hook 点
|
|
112
|
+
* @param data 数据
|
|
113
|
+
* @param metadata 元数据
|
|
114
|
+
* @returns 执行结果
|
|
115
|
+
*/
|
|
116
|
+
executeWithIntervention(hookPoint: string, data: T, metadata?: Record<string, unknown>): Promise<HookResult>;
|
|
117
|
+
/**
|
|
118
|
+
* 获取或创建 hook 列表
|
|
119
|
+
*/
|
|
120
|
+
private getOrCreateHooks;
|
|
121
|
+
/**
|
|
122
|
+
* 按优先级排序 Hook
|
|
123
|
+
*
|
|
124
|
+
* 优先级相同时保持原顺序(稳定排序)
|
|
125
|
+
*/
|
|
126
|
+
private sortHooks;
|
|
127
|
+
/**
|
|
128
|
+
* 创建 Hook 上下文
|
|
129
|
+
*/
|
|
130
|
+
private createContext;
|
|
131
|
+
/**
|
|
132
|
+
* 安全执行 Hook(错误隔离)
|
|
133
|
+
*/
|
|
134
|
+
private safeExecute;
|
|
135
|
+
/**
|
|
136
|
+
* 安全执行 Hook 并返回结果
|
|
137
|
+
*/
|
|
138
|
+
private safeExecuteAndReturn;
|
|
139
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hook 系统统一导出
|
|
3
|
+
*
|
|
4
|
+
* 注意:HookContext 泛型版本从 ./types 导出
|
|
5
|
+
* Agent 特有的 HookContext 包含 iteration, maxIterations 等字段,在 ./agent/types.ts 中
|
|
6
|
+
*/
|
|
7
|
+
export { type HookPhase, type HookMeta, type HookContext, type Hook, type HookFn, type HookActionType, type HookAction, type HookResult, type HookContext as BaseHookContext, type Hook as BaseHook, type HookFn as BaseHookFn, createHook, createPriorityHook, } from "./types";
|
|
8
|
+
export { HookManager, type HookManagerOptions } from "./hook-manager";
|
|
9
|
+
export { globalHookManager, AgentHookPoints, LLMHookPoints, ToolHookPoints, executeAgentHook, executeAgentHookWithIntervention, executeLLMHook, executeToolHook, } from "./global-hook-manager";
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hook 系统统一类型定义
|
|
3
|
+
*
|
|
4
|
+
* 提供所有 Component 使用的统一 Hook 接口
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Hook 执行阶段
|
|
8
|
+
*/
|
|
9
|
+
export type HookPhase = "before" | "after" | "error";
|
|
10
|
+
/**
|
|
11
|
+
* Hook 元信息
|
|
12
|
+
*/
|
|
13
|
+
export interface HookMeta {
|
|
14
|
+
/** Hook 唯一名称 */
|
|
15
|
+
name: string;
|
|
16
|
+
/** 执行优先级,默认 0,数值越小越先执行 */
|
|
17
|
+
priority?: number;
|
|
18
|
+
/** 描述 */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Plugin 名称(EventSource 加载的 plugin) */
|
|
21
|
+
pluginName?: string;
|
|
22
|
+
/** 事件源 ID(EventSource 加载的 plugin) */
|
|
23
|
+
sourceId?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 统一 Hook 上下文
|
|
27
|
+
*
|
|
28
|
+
* 泛型参数 T 表示该 Component 的上下文数据类型
|
|
29
|
+
*/
|
|
30
|
+
export interface HookContext<T = unknown> {
|
|
31
|
+
/** 当前组件信息 */
|
|
32
|
+
component: {
|
|
33
|
+
/** 组件名称 */
|
|
34
|
+
name: string;
|
|
35
|
+
/** 组件版本 */
|
|
36
|
+
version: string;
|
|
37
|
+
};
|
|
38
|
+
/** 上下文数据(Component 特定) */
|
|
39
|
+
data: T;
|
|
40
|
+
/** 元数据(可用于传递额外信息) */
|
|
41
|
+
metadata: Record<string, unknown>;
|
|
42
|
+
/** 执行阶段 */
|
|
43
|
+
phase: HookPhase;
|
|
44
|
+
/** 关联的 hook 点名称 */
|
|
45
|
+
hookPoint: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 统一 Hook 接口
|
|
49
|
+
*
|
|
50
|
+
* 所有 Component 的 Hook 都应实现此接口
|
|
51
|
+
*/
|
|
52
|
+
export interface Hook<T = unknown> extends HookMeta {
|
|
53
|
+
/** 执行 Hook
|
|
54
|
+
* @param ctx 上下文
|
|
55
|
+
*/
|
|
56
|
+
execute(ctx: HookContext<T>): void | Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Hook 函数类型(便捷别名)
|
|
60
|
+
*/
|
|
61
|
+
export type HookFn<T = unknown> = (ctx: HookContext<T>) => void | Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Hook 干预动作类型
|
|
64
|
+
*/
|
|
65
|
+
export type HookActionType = "stop" | "retry" | "compress" | "extract_memory" | "inject_message" | "skip_tool" | "custom";
|
|
66
|
+
/**
|
|
67
|
+
* Hook 干预动作
|
|
68
|
+
*/
|
|
69
|
+
export interface HookAction {
|
|
70
|
+
/** 动作类型 */
|
|
71
|
+
type: HookActionType;
|
|
72
|
+
/** 动作参数 */
|
|
73
|
+
params?: Record<string, unknown>;
|
|
74
|
+
/** 动作描述 */
|
|
75
|
+
description?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook 执行结果
|
|
79
|
+
*/
|
|
80
|
+
export interface HookResult {
|
|
81
|
+
/** 是否被停止 */
|
|
82
|
+
stopped?: boolean;
|
|
83
|
+
/** 干预动作(如果有) */
|
|
84
|
+
action?: HookAction;
|
|
85
|
+
/** 执行结果数据 */
|
|
86
|
+
results?: unknown[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 创建 Hook 的工厂函数
|
|
90
|
+
*
|
|
91
|
+
* @param meta Hook 元信息
|
|
92
|
+
* @param fn 执行函数
|
|
93
|
+
* @returns Hook 实例
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const hook = createHook(
|
|
98
|
+
* { name: "my-hook", priority: 10 },
|
|
99
|
+
* async (ctx) => { console.log(ctx.data); }
|
|
100
|
+
* );
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function createHook<T = unknown>(meta: HookMeta, fn: HookFn<T>): Hook<T>;
|
|
104
|
+
/**
|
|
105
|
+
* 创建带优先级的 Hook 的便捷函数
|
|
106
|
+
*/
|
|
107
|
+
export declare function createPriorityHook<T = unknown>(name: string, fn: HookFn<T>, priority: number): Hook<T>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Environment Module
|
|
3
|
+
*
|
|
4
|
+
* 导出 Environment 相关的类型和实现。
|
|
5
|
+
*/
|
|
6
|
+
export type { Environment } from "./interface";
|
|
7
|
+
export type { EnvironmentConfig, BaseEnvironmentConfig, EnvEvent, EnvEventMetadata, EnvEventHandler, Action, ToolResult, Context, } from "./types";
|
|
8
|
+
export { BaseEnvironment } from "./environment";
|
|
9
|
+
export { type Component, type ComponentConfig, type ComponentSchema, type ComponentPaths, type ComponentStatus, type ComponentConfigChangeEvent, type ComponentWatchCallback, BaseComponent, } from "./component";
|
|
10
|
+
export { type Hook, type HookContext, type HookPhase, type HookMeta, type HookFn, type HookManagerOptions, createHook, createPriorityHook, HookManager, } from "./hook";
|
|
11
|
+
export { type EnvContext, getEnvContext, getEnvContextOrEmpty, hasEnvContext, runWithEnvContext, runWithEnvContextAsync, createEnvContext, mergeEnvContext, } from "./context";
|
|
12
|
+
export { type XDGPaths, type XDGDirType, XDG_PATHS, getXDGPaths, getXDGPath, } from "./paths";
|
|
13
|
+
export { AgentComponent, type AgentComponentConfig, AgentComponentConfigSchema, type AgentInstance, type AgentInstanceConfig, type AgentRunResult, type AgentContext, type Plugin, type HookContext as AgentHookContext, type HookPoint, type HookResult, type HookActionType, type Tool, type ToolCall, type ToolResult as AgentToolResult, type ToolCallResult, type LLMOutput, } from "./agent";
|
|
14
|
+
export { TaskComponent, type TaskComponentOptions, } from "./task";
|
|
15
|
+
export type { Task, TaskOperation, TaskStatus, TaskPriority, ActionType, CreateTaskOptions, UpdateTaskOptions, ListTasksOptions, CreateOperationOptions, ListOperationsOptions, TaskConfig, } from "./task/types";
|
|
16
|
+
export { McpComponent, } from "./mcp";
|
|
17
|
+
export type { McpComponentConfig, McpComponentOptions, McpPath, McpServerConfig, McpServerStatus, DiscoveredMcpServer, } from "./mcp";
|
|
18
|
+
export { EventSourceComponent, larkCliHandler, builtInHandlers, } from "./event-source/event-source-component";
|
|
19
|
+
export type { EventSourceConfig, EventSourceStatus, EventSourceType, EventSourceEvent, EventSourceEventPayload, EventSourceEventHandler, EventSourceStatusChangeEvent, EventSourcePersistenceConfig, EventSourceComponentInterface, EventSourceHandler, EventSourceInstance, EventSourceAgentHandlerConfig, BUILT_IN_EVENT_SOURCE_TYPES, } from "./event-source/types";
|
|
20
|
+
export { EventSourceInitHooks, isValidEventSourceType, isBuiltInEventSourceType, getDefaultConfigForType, validateEventSourceConfig, } from "./event-source/types";
|
|
21
|
+
export { WorkflowComponent, } from "./workflow/workflow-component";
|
|
22
|
+
export type { WorkflowComponentConfig, } from "./workflow/workflow-component";
|
|
23
|
+
export { PluginComponent, } from "./plugin/plugin-component";
|
|
24
|
+
export type { PluginComponentOptions, } from "./plugin/plugin-component";
|
package/dist/env/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseEnvironment
|
|
3
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
3
|
+
} from "../shared/@ai-setting/roy-agent-core-4sx6sdb2.js";
|
|
4
4
|
import {
|
|
5
5
|
TaskComponent
|
|
6
6
|
} from "../shared/@ai-setting/roy-agent-core-39xejr39.js";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
EventSourceComponent,
|
|
16
16
|
builtInHandlers,
|
|
17
17
|
larkCliHandler
|
|
18
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
18
|
+
} from "../shared/@ai-setting/roy-agent-core-ph5qbqcx.js";
|
|
19
19
|
import {
|
|
20
20
|
EventSourceInitHooks,
|
|
21
21
|
getDefaultConfigForType,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
validateEventSourceConfig
|
|
25
25
|
} from "../shared/@ai-setting/roy-agent-core-ck60j1q9.js";
|
|
26
26
|
import"../shared/@ai-setting/roy-agent-core-rnwr39b0.js";
|
|
27
|
-
import"../shared/@ai-setting/roy-agent-core-
|
|
27
|
+
import"../shared/@ai-setting/roy-agent-core-hch2geta.js";
|
|
28
28
|
import"../shared/@ai-setting/roy-agent-core-yhsssn86.js";
|
|
29
29
|
import"../shared/@ai-setting/roy-agent-core-1pg0fepg.js";
|
|
30
30
|
import"../shared/@ai-setting/roy-agent-core-gdsqp6j8.js";
|
|
@@ -32,7 +32,7 @@ import"../shared/@ai-setting/roy-agent-core-brwzs8wf.js";
|
|
|
32
32
|
import"../shared/@ai-setting/roy-agent-core-j8e92gj8.js";
|
|
33
33
|
import {
|
|
34
34
|
WorkflowComponent
|
|
35
|
-
} from "../shared/@ai-setting/roy-agent-core-
|
|
35
|
+
} from "../shared/@ai-setting/roy-agent-core-4vpk40ss.js";
|
|
36
36
|
import"../shared/@ai-setting/roy-agent-core-vrsxhw9e.js";
|
|
37
37
|
import"../shared/@ai-setting/roy-agent-core-h0x19xgn.js";
|
|
38
38
|
import"../shared/@ai-setting/roy-agent-core-1ce3fqrk.js";
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Environment Interface
|
|
3
|
+
*
|
|
4
|
+
* Environment 是智能体运行时的核心抽象。
|
|
5
|
+
*
|
|
6
|
+
* 设计原则:
|
|
7
|
+
* 1. Environment 只做两件事:
|
|
8
|
+
* - 组件管理:持有、注册、获取组件
|
|
9
|
+
* - 核心调度:handle_query / handle_action / EnvEvent
|
|
10
|
+
* 2. 其他能力归属到对应 Component
|
|
11
|
+
*
|
|
12
|
+
* 服务配置能力:
|
|
13
|
+
* - loadServiceConfig(): 从配置文件加载服务配置
|
|
14
|
+
* - generateComponentOptions(): 生成组件初始化选项
|
|
15
|
+
* - registerComponentWithConfig(): 注册并用配置初始化组件
|
|
16
|
+
* - initFromConfig(): 从配置文件初始化整个环境
|
|
17
|
+
*/
|
|
18
|
+
import type { Component } from "./component";
|
|
19
|
+
import type { EnvEvent, EnvEventHandler, EnvEventInput, EnvironmentConfig, Action, ToolResult, Context } from "./types";
|
|
20
|
+
import type { AgentContext } from "./agent/types";
|
|
21
|
+
import type { ContentPart } from "./llm/types";
|
|
22
|
+
import type { ConfigComponent } from "../config/config-component";
|
|
23
|
+
export type { AgentContext };
|
|
24
|
+
/**
|
|
25
|
+
* 服务配置接口
|
|
26
|
+
*/
|
|
27
|
+
export interface ServiceConfig {
|
|
28
|
+
/** 环境配置 */
|
|
29
|
+
environment?: {
|
|
30
|
+
name?: string;
|
|
31
|
+
version?: string;
|
|
32
|
+
};
|
|
33
|
+
/** 组件配置映射 */
|
|
34
|
+
components?: Record<string, ComponentConfigEntry>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 组件配置项
|
|
38
|
+
*/
|
|
39
|
+
export interface ComponentConfigEntry {
|
|
40
|
+
/** 配置文件路径(可选) */
|
|
41
|
+
configPath?: string;
|
|
42
|
+
/** 环境变量前缀(可选) */
|
|
43
|
+
envPrefix?: string;
|
|
44
|
+
/** 直接配置对象(可选) */
|
|
45
|
+
config?: Record<string, unknown>;
|
|
46
|
+
/** 是否启用(可选,默认 true) */
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 组件初始化选项(由 generateComponentOptions 生成)
|
|
51
|
+
*/
|
|
52
|
+
export interface GeneratedComponentOptions {
|
|
53
|
+
/** ConfigComponent 实例 */
|
|
54
|
+
configComponent: ConfigComponent;
|
|
55
|
+
/** 配置文件路径 */
|
|
56
|
+
configPath?: string;
|
|
57
|
+
/** 环境变量前缀 */
|
|
58
|
+
envPrefix?: string;
|
|
59
|
+
/** 直接配置对象 */
|
|
60
|
+
config?: Record<string, unknown>;
|
|
61
|
+
/** 允许的其他属性 */
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Environment 接口
|
|
66
|
+
*
|
|
67
|
+
* 定义 Agent 运行时的核心能力接口。
|
|
68
|
+
*/
|
|
69
|
+
export interface Environment {
|
|
70
|
+
/** 环境名称 */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** 环境版本 */
|
|
73
|
+
readonly version: string;
|
|
74
|
+
/** 获取环境配置 */
|
|
75
|
+
getConfig(): EnvironmentConfig;
|
|
76
|
+
/**
|
|
77
|
+
* 注册组件
|
|
78
|
+
*/
|
|
79
|
+
registerComponent(component: Component): void;
|
|
80
|
+
/**
|
|
81
|
+
* 注销组件
|
|
82
|
+
*/
|
|
83
|
+
unregisterComponent(name: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* 获取组件
|
|
86
|
+
*/
|
|
87
|
+
getComponent<T extends Component>(name: string): T | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* 列出所有组件
|
|
90
|
+
*/
|
|
91
|
+
listComponents(): Component[];
|
|
92
|
+
/**
|
|
93
|
+
* 处理自然语言查询(核心入口)
|
|
94
|
+
*
|
|
95
|
+
* @param query 用户查询(文本 string 或多模态 ContentPart[])
|
|
96
|
+
* @param context 执行上下文(可选)
|
|
97
|
+
* @returns 完整的文本响应
|
|
98
|
+
*/
|
|
99
|
+
handle_query(query: string | ContentPart[], context?: AgentContext): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* 处理动作
|
|
102
|
+
*/
|
|
103
|
+
handle_action(action: Action, context: Context): Promise<ToolResult>;
|
|
104
|
+
/**
|
|
105
|
+
* 订阅 EnvEvent(返回取消订阅函数)
|
|
106
|
+
*/
|
|
107
|
+
subscribe(handler: EnvEventHandler): () => void;
|
|
108
|
+
/**
|
|
109
|
+
* 订阅指定类型事件
|
|
110
|
+
*/
|
|
111
|
+
subscribeTo(eventType: string | string[], handler: EnvEventHandler): () => void;
|
|
112
|
+
/**
|
|
113
|
+
* 订阅所有事件(通配符)
|
|
114
|
+
*/
|
|
115
|
+
subscribeAll(handler: EnvEventHandler): () => void;
|
|
116
|
+
/**
|
|
117
|
+
* 推送事件
|
|
118
|
+
*
|
|
119
|
+
* @param event EnvEvent 或 EnvEventInput(部分属性)
|
|
120
|
+
*/
|
|
121
|
+
pushEnvEvent(event: EnvEvent | EnvEventInput): void;
|
|
122
|
+
/**
|
|
123
|
+
* 从配置文件加载服务配置
|
|
124
|
+
*
|
|
125
|
+
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
126
|
+
* @returns 解析后的服务配置对象
|
|
127
|
+
*/
|
|
128
|
+
loadServiceConfig(configPath: string): Promise<ServiceConfig>;
|
|
129
|
+
/**
|
|
130
|
+
* 生成组件初始化选项
|
|
131
|
+
*
|
|
132
|
+
* 根据组件配置项生成可用于初始化的选项对象。
|
|
133
|
+
*
|
|
134
|
+
* @param componentName 组件名称
|
|
135
|
+
* @param configEntry 组件配置项
|
|
136
|
+
* @returns 生成的组件初始化选项
|
|
137
|
+
*/
|
|
138
|
+
generateComponentOptions(componentName: string, configEntry: ComponentConfigEntry): GeneratedComponentOptions;
|
|
139
|
+
/**
|
|
140
|
+
* 注册组件并用配置初始化
|
|
141
|
+
*
|
|
142
|
+
* 便捷方法:注册组件并通过 ConfigComponent 初始化。
|
|
143
|
+
*
|
|
144
|
+
* @param component 要注册的组件实例
|
|
145
|
+
* @param configEntry 组件配置项
|
|
146
|
+
*/
|
|
147
|
+
registerComponentWithConfig(component: Component, configEntry: ComponentConfigEntry): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* 从配置文件初始化整个环境
|
|
150
|
+
*
|
|
151
|
+
* 加载服务配置,注册并初始化所有配置的组件。
|
|
152
|
+
*
|
|
153
|
+
* @param configPath 配置文件路径(基于 XDG_DATA_HOME)
|
|
154
|
+
*/
|
|
155
|
+
initFromConfig(configPath: string): Promise<void>;
|
|
156
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 飞书消息 <at> 提及语法规范化工具
|
|
3
|
+
*
|
|
4
|
+
* ## 背景
|
|
5
|
+
*
|
|
6
|
+
* LLM 在生成消息时经常使用自闭合 XML 语法 `<at user_id="ou_xxx"/>` 来表达 @-mention,
|
|
7
|
+
* 但飞书 API 实际只识别 **带显式结束标签** 的形式:
|
|
8
|
+
* - `<at user_id="ou_xxx">name</at>` — 带显示名
|
|
9
|
+
* - `<at user_id="ou_xxx"></at>` — 空显示名(仍然会触发 @ 通知)
|
|
10
|
+
*
|
|
11
|
+
* 自闭合形式 `<at user_id="ou_xxx"/>` 会被飞书当作 **纯文本字面量** 展示,
|
|
12
|
+
* 收件人既看不到 mention,也不会收到通知。
|
|
13
|
+
*
|
|
14
|
+
* ## 解决方案
|
|
15
|
+
*
|
|
16
|
+
* 在发消息前调用 `normalizeLarkAtMentions(content)`,把所有自闭合 `<at>` 转为标准
|
|
17
|
+
* `<at user_id="..."></at>` 形式。如果调用方传入了 userId → name 的映射表,
|
|
18
|
+
* 还会把显示名填进去(更好的视觉提示)。
|
|
19
|
+
*
|
|
20
|
+
* ## 参考
|
|
21
|
+
*
|
|
22
|
+
* - lark-im skill: `lark-cli skills read lark-im/references/lark-im-messages-send.md`
|
|
23
|
+
* "## @Mention Format" 章节
|
|
24
|
+
* - `text`: `<at user_id="ou_xxx">name</at>` (inner optional, `<at user_id="ou_xxx"></at>` works)
|
|
25
|
+
* - `post` + `md`: 同 text 的 inline form
|
|
26
|
+
* - `post` + `at` element: `{"tag":"at","user_id":"ou_xxx"}`
|
|
27
|
+
* - @all: `<at user_id="all"></at>`
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* 规范化消息中的飞书 @-mention 语法
|
|
31
|
+
*
|
|
32
|
+
* 把 LLM 经常输出的自闭合形式 `<at user_id="ou_xxx"/>` 转换为飞书识别的
|
|
33
|
+
* 标准形式 `<at user_id="ou_xxx"></at>`,触发实际的 @ 通知。
|
|
34
|
+
*
|
|
35
|
+
* @param content 原始 markdown 消息文本
|
|
36
|
+
* @param nameMap 可选的 userId → displayName 映射;如果提供,会把名字填到
|
|
37
|
+
* `<at>` 内部,让收件人看到"@张三"而不是"@"
|
|
38
|
+
* @returns 规范化后的内容
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // 基础用法:自闭合 → 空闭合
|
|
42
|
+
* normalizeLarkAtMentions('<at user_id="ou_123"/>收到')
|
|
43
|
+
* // → '<at user_id="ou_123"></at>收到'
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // 带名字映射
|
|
47
|
+
* normalizeLarkAtMentions(
|
|
48
|
+
* '<at user_id="ou_123"/>收到',
|
|
49
|
+
* new Map([['ou_123', '张三']])
|
|
50
|
+
* )
|
|
51
|
+
* // → '<at user_id="ou_123">张三</at>收到'
|
|
52
|
+
*/
|
|
53
|
+
export declare function normalizeLarkAtMentions(content: string, nameMap?: ReadonlyMap<string, string>): string;
|
|
54
|
+
/**
|
|
55
|
+
* 检测消息内容是否包含飞书 mention 语法(任何形式)
|
|
56
|
+
*
|
|
57
|
+
* 用于调试/日志:在 send 之前打印"包含 N 个 mention",方便 trace。
|
|
58
|
+
*/
|
|
59
|
+
export declare function countLarkMentions(content: string): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LLMAdapter, ChatRequest, ChatResponse, StreamHandle, ResolvedProvider, EmbedRequest, EmbedResponse } from "./adapter";
|
|
2
|
+
export declare class AiSdkAdapter implements LLMAdapter {
|
|
3
|
+
readonly name: "ai-sdk";
|
|
4
|
+
chat(req: ChatRequest): Promise<ChatResponse>;
|
|
5
|
+
stream(req: ChatRequest): Promise<StreamHandle>;
|
|
6
|
+
embed(req: EmbedRequest): Promise<EmbedResponse>;
|
|
7
|
+
resolveProvider(provider: string, modelId: string): Promise<ResolvedProvider>;
|
|
8
|
+
private toInvokeConfig;
|
|
9
|
+
private toInvokeOptions;
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PiAiAdapter — 包装 @earendil-works/pi-ai。
|
|
3
|
+
*
|
|
4
|
+
* 这是 roy-agent 默认的 LLM 适配层(ROY_LLM_PROVIDER=pi-ai 时启用)。
|
|
5
|
+
* 把 ChatRequest / ChatResponse / StreamHandle 翻译成 pi-ai 的
|
|
6
|
+
* complete() / stream() / getModel() 三件套。
|
|
7
|
+
*
|
|
8
|
+
* 关键映射:
|
|
9
|
+
* - provider/modelId → getModel(provider, modelId)
|
|
10
|
+
* - LLMMessage[] → pi-ai Context.messages
|
|
11
|
+
* - AssistantMessage.stopReason → ChatResponse.finishReason
|
|
12
|
+
* - usage {input, output, totalTokens} → UsageInfo
|
|
13
|
+
*/
|
|
14
|
+
import { type Model, type Context } from "@earendil-works/pi-ai";
|
|
15
|
+
import type { LLMAdapter, ChatRequest, ChatResponse, StreamHandle, ResolvedProvider, EmbedRequest, EmbedResponse } from "./adapter";
|
|
16
|
+
import type { LLMMessage, ToolInfo } from "./types";
|
|
17
|
+
/**
|
|
18
|
+
* Resolve built-in models and models declared by roy-agent configuration.
|
|
19
|
+
* pi-ai's generated registry only contains its bundled provider/model pairs;
|
|
20
|
+
* custom provider ids (for example minimax-openai) need a complete Model
|
|
21
|
+
* descriptor before complete()/stream() can dispatch by API.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolvePiModel(provider: string, modelId: string, baseURL?: string): Model<any>;
|
|
24
|
+
/**
|
|
25
|
+
* 将 LLMMessage 转换为 pi-ai 的消息结构
|
|
26
|
+
*/
|
|
27
|
+
export declare function toPiMessages(messages: LLMMessage[]): Context["messages"];
|
|
28
|
+
export declare function extractSystemPrompt(messages: LLMMessage[]): string | undefined;
|
|
29
|
+
export declare function toPiTools(tools: ToolInfo[] | undefined): Context["tools"];
|
|
30
|
+
export declare class EmbeddingNotSupportedError extends Error {
|
|
31
|
+
constructor(adapter: string);
|
|
32
|
+
}
|
|
33
|
+
export declare class PiAiAdapter implements LLMAdapter {
|
|
34
|
+
readonly name: "pi-ai";
|
|
35
|
+
chat(req: ChatRequest): Promise<ChatResponse>;
|
|
36
|
+
stream(req: ChatRequest): Promise<StreamHandle>;
|
|
37
|
+
embed(_req: EmbedRequest): Promise<EmbedResponse>;
|
|
38
|
+
resolveProvider(provider: string, modelId: string): Promise<ResolvedProvider>;
|
|
39
|
+
}
|