@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,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置 EventSourceHandler 实现
|
|
3
|
+
*
|
|
4
|
+
* 提供 lark-cli 事件源类型的 Handler 实现
|
|
5
|
+
* 支持通过 handleRule.plugins 加载外部 Plugin
|
|
6
|
+
*/
|
|
7
|
+
import { ChildProcess } from "child_process";
|
|
8
|
+
import type { EventSourceConfig, EventSourceHandler, EventSourceInstance, EventSourceStatus, EventSourceEventHandler, EventMetadata, ReplyChannel, RecommendedAction } from "./types";
|
|
9
|
+
import { timerHandler } from "./timer-handler";
|
|
10
|
+
import { bountyIMHandler } from "./bounty-im-handler";
|
|
11
|
+
import { bountyCliHandler } from "./bounty-cli-handler";
|
|
12
|
+
/**
|
|
13
|
+
* 构建 Lark `im.message.receive_v1` 事件推荐动作 prompt (Task #2185 / #4137 / #4242)
|
|
14
|
+
*
|
|
15
|
+
* 现状:飞书回复统一走 **单条结构化 post content**(`--msg-type post --content`)。
|
|
16
|
+
* - @mention 用结构化 at 节点 `{"tag":"at","user_id":"ou_xxx"}`,飞书会回填 mentions
|
|
17
|
+
* (真实 @);正文用 `{"tag":"md","text":"..."}` 节点,仍支持标题/表格/加粗。
|
|
18
|
+
* - 历史上的 `--markdown` + 正文内联 `<at>` 已废弃:LLM 常写坏标签
|
|
19
|
+
* (自闭合 `<at/>` 会让整条 Markdown 解析失败、@ 退化成纯文本)。
|
|
20
|
+
* - 用 mktemp + trap + `jq --rawfile` 安全构造 content(jq 自动转义换行)。
|
|
21
|
+
*
|
|
22
|
+
* 设计要点:
|
|
23
|
+
* 1. 推荐路径:先写临时 .md 文件(正文),再用 jq 组装结构化 content,
|
|
24
|
+
* 最后 `lark-cli ... --msg-type post --content "$content"` 调用。
|
|
25
|
+
* 2. 显式禁止:--text / --msg-type text / --markdown / 正文内联 <at> 标签 /
|
|
26
|
+
* 字面反斜杠+n / ANSI-C 引号 —— 这些都会导致坏 Markdown 或 @ 失效。
|
|
27
|
+
* 3. 必须使用下方 recommendedAction.replyTo 给定的 profile / chatId / messageId
|
|
28
|
+
* / --as bot,禁止 LLM 凭印象自己填。
|
|
29
|
+
* 4. replyTo 既有结构(appId / profile / chatId / messageId)保持不变,老 consumer
|
|
30
|
+
* 仍能解析。
|
|
31
|
+
* 5. prompt 自身 JSON/日志转义干净:警示用 words 描述字面反斜杠+n,避免把 0x0A
|
|
32
|
+
* 控制字符混进示例字符串里。
|
|
33
|
+
* 6. **#4242 + #4243 合并修复**:禁止 sub-agent 把回复拆成多条循环 send
|
|
34
|
+
* (综合 #4137 webhook 重复通知 + #4171 msg 进 thread 折叠丢失 +
|
|
35
|
+
* #4241 review 暴露 sub-agent 自行拼 flag)。整次回复**只发一条**结构化 post
|
|
36
|
+
* (「发送类」命令只调一次),全部内容写进单个 md 节点;超长压缩正文或用附件区。
|
|
37
|
+
* 长度上限用**官方 30 KB 请求体**(飞书错误码 230025),不是早期误写的
|
|
38
|
+
* "4096 字符"——那个数字没有出处,还会被 agent 当成分段阈值。
|
|
39
|
+
* 7. **单一来源(去重)**:#4242 的「关键 0」与 #4243 的「关键 4」讲的是同一条规则,
|
|
40
|
+
* 两个并行 task 各自 merge 后重复了三遍、占 prompt 38% 字符,且给出的"照抄模板"
|
|
41
|
+
* 互相矛盾(send --chat-id vs reply --message-id)。现合并为「关键 0」单一章节,
|
|
42
|
+
* `--reply-in-thread` 全文只出现一次;由
|
|
43
|
+
* `single-message-reply-prompt.test.ts` 的 (A)/(D)/(G) 组守护,防止再次重复。
|
|
44
|
+
* 8. **指令优先级**:lark-im skill 建议 `--markdown` / ANSI-C 引号,与本 prompt 冲突;
|
|
45
|
+
* 故在「关键 0」顶部显式声明"以本 prompt 为准",避免 sub-agent 自行揉合两套指令
|
|
46
|
+
* (#4241 的偏移指令语义根因)。
|
|
47
|
+
*
|
|
48
|
+
* 注意:本 prompt 字符串会在 console.log / JSON 序列化链路里往返多次,
|
|
49
|
+
* 不要在示例里出现字面换行(0x0A 控制字符)与 bash ANSI-C 引号(dollar 符号紧跟单引号),
|
|
50
|
+
* 否则就是新的字面陷阱。
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildLarkRecommendedAction(opts: {
|
|
53
|
+
profile?: string;
|
|
54
|
+
chatType?: string;
|
|
55
|
+
appId?: string;
|
|
56
|
+
chatId?: string;
|
|
57
|
+
messageId?: string;
|
|
58
|
+
}): RecommendedAction;
|
|
59
|
+
/**
|
|
60
|
+
* 提取事件元信息
|
|
61
|
+
*
|
|
62
|
+
* 支持两种事件格式:
|
|
63
|
+
* 1. 简化格式(lark-cli 推送):顶层有 message_id, chat_id, content 等
|
|
64
|
+
* 2. 嵌套格式:event.message, header.event_type 等
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* 从 rawEvent 中提取 EventMetadata + ReplyChannel + RecommendedAction
|
|
68
|
+
*
|
|
69
|
+
* 【导出】原文件 default 为 internal,Task #2326 lark-messageid-context 集成测试需要直接调用。
|
|
70
|
+
* 处理两种事件格式:
|
|
71
|
+
* - 嵌套格式: { event: { message: { message_id, chat_id }, sender: {...} } }
|
|
72
|
+
* - 简化格式: { message_id, chat_id, sender_id }
|
|
73
|
+
*/
|
|
74
|
+
export declare function extractMetadata(rawEvent: unknown, eventType?: string): {
|
|
75
|
+
metadata: EventMetadata;
|
|
76
|
+
replyChannel?: ReplyChannel;
|
|
77
|
+
recommendedAction?: RecommendedAction;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* LarkCli EventSourceInstance 实现
|
|
81
|
+
* 支持通过 handleRule.plugins 加载外部 Plugin
|
|
82
|
+
*
|
|
83
|
+
* 进程启动逻辑参考 bash-effect.ts:
|
|
84
|
+
* - 使用 shell: true + stdio: ["pipe", "pipe", "pipe"]
|
|
85
|
+
* - stdin 保持打开直到进程结束
|
|
86
|
+
*/
|
|
87
|
+
export declare class LarkCliInstance implements EventSourceInstance {
|
|
88
|
+
private config;
|
|
89
|
+
private status;
|
|
90
|
+
/**
|
|
91
|
+
* ★ Task #4339:所有 consume 子进程(**一个 EventKey 一个进程**)。
|
|
92
|
+
*
|
|
93
|
+
* lark-cli 硬约束(1.0.98 实测):`event consume` 只接受**恰好一个** EventKey;
|
|
94
|
+
* 逗号多 key(`k1,k2`)和通配符(`im.*`)都会 `unknown EventKey` 直接 exit 2。
|
|
95
|
+
* 所以"同时监听 im.message.receive_v1 + card.action.trigger"必须拆成两个
|
|
96
|
+
* 子进程 —— 它们共享同一个 bus daemon(UDS),互不干扰。
|
|
97
|
+
*
|
|
98
|
+
* 详见 reports/2026-10-19-lark-cli-multi-event-consume-research.md
|
|
99
|
+
*/
|
|
100
|
+
private children;
|
|
101
|
+
/** 默认 stream 行缓冲(processStream 兼容入口用;每个子进程用自己的 buffer) */
|
|
102
|
+
private buffer;
|
|
103
|
+
/** ★ Task #4339:start() 并发保护 */
|
|
104
|
+
private starting;
|
|
105
|
+
private eventHandler?;
|
|
106
|
+
/**
|
|
107
|
+
* ★ Task #4230 follow-up:卡片路由端口(lookup/getTask 侧)
|
|
108
|
+
*
|
|
109
|
+
* 构建一次、多处复用(含 loadPlugins 收尾时补 ensureTaskGroupChat)。
|
|
110
|
+
*/
|
|
111
|
+
private cardRoutingPorts?;
|
|
112
|
+
/** ★ Task #4230 follow-up:群名缓存(判定"触发群是不是别 task 的专属群") */
|
|
113
|
+
private chatNameCache;
|
|
114
|
+
/** ★ Task #4230 follow-up:已加载插件实例(收尾 cross-wire 用) */
|
|
115
|
+
private pluginInstances;
|
|
116
|
+
/**
|
|
117
|
+
* ★ Task #4331:卡片按钮 callback 端口(注入 getTask/updateTaskContext/createGroupChat/deleteGroupChat/notifier)。
|
|
118
|
+
* 由外部(一般是 loadPlugins 末尾的 cross-wire 或 CLI 启动器)注入。
|
|
119
|
+
* 未注入时 handleCardActionEvent 会 warn 并 skip(不影响其他事件处理)。
|
|
120
|
+
*/
|
|
121
|
+
private cardActionPorts?;
|
|
122
|
+
/**
|
|
123
|
+
* ★ Task #4331:注入卡片按钮 callback 端口(由 caller/loadPlugins 调用)
|
|
124
|
+
*/
|
|
125
|
+
setCardActionPorts(ports: import("../task/plugins/lark-card-action-handler").CardActionPorts): void;
|
|
126
|
+
/** 诊断:端口是否注入 */
|
|
127
|
+
hasCardActionPorts(): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* ★ Task #3977/3978 修复:去重最近处理的 event_id
|
|
130
|
+
*
|
|
131
|
+
* 根因:lark-cli event consume 偶尔会把同一条 JSON 事件写到 stdout 和 stderr
|
|
132
|
+
* 两路(race condition),导致 processStream 被调用两次 → 同一个飞书事件被
|
|
133
|
+
* dispatch 两次 → 主 agent 和 sub-agent 都创建同名 task(bug 表现:一次
|
|
134
|
+
* 用户委托产生 2 个 task)。
|
|
135
|
+
*
|
|
136
|
+
* 防御性做法:在 handleEvent 内根据 event_id 做 LRU 去重,避免重复 dispatch。
|
|
137
|
+
* - 用 Map 记录最近 100 个 event_id + 处理时间
|
|
138
|
+
* - 同一 instance 内 60s 内相同 event_id 视为重复,跳过
|
|
139
|
+
*
|
|
140
|
+
* ★ Task #4137 升级为跨实例共享 SHARED_SEEN(module-level Map):
|
|
141
|
+
* - 多 LarkCliInstance 共享去重表,避免"实例 A 处理过、实例 B 又处理一次"
|
|
142
|
+
* - key = event_id(共享窗口)
|
|
143
|
+
*
|
|
144
|
+
* 注意:这里**不做** self-echo(自回灌)检测。回灌的根因是出站身份,
|
|
145
|
+
* 已在源头解决——所有出站一律 `--as bot`(见 buildLarkRecommendedAction),
|
|
146
|
+
* bot 自己发出的消息不会被本 app 的事件订阅回投。
|
|
147
|
+
* 不要再引入"记录已发送 message_id 再在入口拦截"的兜底:它依赖 parse lark-cli
|
|
148
|
+
* stdout(正文含裸引号会 PARSE FAIL,拿不到 id 就形同虚设),收益/复杂度不成正比。
|
|
149
|
+
*/
|
|
150
|
+
private static SHARED_SEEN;
|
|
151
|
+
private static SHARED_MSG_TTL_MS;
|
|
152
|
+
private static SHARED_MSG_MAX;
|
|
153
|
+
/**
|
|
154
|
+
* 测试钩子:重置 SHARED_SEEN 静态状态。
|
|
155
|
+
* 仅供单测在 beforeEach 里调用,生产路径禁止调用。
|
|
156
|
+
*/
|
|
157
|
+
static __resetDedupForTest(): void;
|
|
158
|
+
private recentEventIds;
|
|
159
|
+
private readonly DEDUP_WINDOW_MS;
|
|
160
|
+
private readonly DEDUP_MAX_SIZE;
|
|
161
|
+
/**
|
|
162
|
+
* Environment 引用(由 EventSourceComponent.startSource 调用 setEnvironment 注入)
|
|
163
|
+
*
|
|
164
|
+
* 用于在 registerPluginHooks 时通过 env.getComponent('task') 拿到 taskComponent,
|
|
165
|
+
* 给支持 setTaskUpdater 的 plugin(如 PerTaskGroupChatPlugin)注入 DB 持久化回调。
|
|
166
|
+
* 未注入时(如第三方 handler)所有 plugin 都不会拿到 taskUpdater,行为与之前一致。
|
|
167
|
+
*/
|
|
168
|
+
private environment?;
|
|
169
|
+
/** 已加载的 plugins */
|
|
170
|
+
private loadedPlugins;
|
|
171
|
+
constructor(config: EventSourceConfig);
|
|
172
|
+
/**
|
|
173
|
+
* 注入 Environment 引用(实现 EventSourceInstance.setEnvironment)
|
|
174
|
+
*
|
|
175
|
+
* 调用时机:EventSourceComponent.startSource 在 instance.start() 之前调用。
|
|
176
|
+
* 必须先于 loadPlugins(),否则 plugin 拿不到 taskComponent。
|
|
177
|
+
*/
|
|
178
|
+
setEnvironment(env: unknown): void;
|
|
179
|
+
start(): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* ★ Task #4339:配置自检 —— 两个"静默失效"陷阱,必须在启动时喊出来。
|
|
182
|
+
*
|
|
183
|
+
* ① `eventKeys` 里包含 card.action.trigger,但 `eventTypes` 过滤器不含它:
|
|
184
|
+
* `handleEvent` 会先过 eventTypes 再分流,卡片点击会被**静默丢弃**。
|
|
185
|
+
* ② `eventKeys` 里包含 card.action.trigger,但飞书后台没开"回调配置":
|
|
186
|
+
* consumer 能 ready,事件永远不来(lark-cli 无 preflight 检查,我们查不到,
|
|
187
|
+
* 只能提示)。
|
|
188
|
+
*/
|
|
189
|
+
private warnOnCardActionConfigTraps;
|
|
190
|
+
/**
|
|
191
|
+
* ★ Task #4339:spawn 一个 consume 子进程。
|
|
192
|
+
*
|
|
193
|
+
* 抽成 protected 方法是为了让单测注入"假子进程"(否则测试会真的去连
|
|
194
|
+
* lark-cli bus,污染真实事件订阅)。
|
|
195
|
+
*/
|
|
196
|
+
protected spawnConsumeChild(command: string): ChildProcess;
|
|
197
|
+
/**
|
|
198
|
+
* ★ Task #4339:解析要消费的 EventKey 列表。
|
|
199
|
+
*
|
|
200
|
+
* lark-cli 的硬约束(1.0.98 实测):
|
|
201
|
+
* - `event consume` 只接受**恰好一个** EventKey;
|
|
202
|
+
* - 逗号多 key / 通配符都会 `unknown EventKey` 直接 exit 2;
|
|
203
|
+
* - 所以"同时监听 receive + card action"必须是**多个子进程**,
|
|
204
|
+
* 它们共享同一个 bus daemon(UDS),互不干扰。
|
|
205
|
+
*
|
|
206
|
+
* 配置来源优先级:
|
|
207
|
+
* 1. `config.eventKeys`(推荐:显式多 key,例:["im.message.receive_v1","card.action.trigger"])
|
|
208
|
+
* 2. `config.command`(用户自定义单命令,原样保留 / 注入 --profile)
|
|
209
|
+
* 3. 默认 `["im.message.receive_v1"]`
|
|
210
|
+
*/
|
|
211
|
+
resolveConsumeEventKeys(): string[];
|
|
212
|
+
/**
|
|
213
|
+
* ★ Task #4339:构造本实例要 spawn 的完整命令列表(已注入 --profile)。
|
|
214
|
+
*/
|
|
215
|
+
buildConsumeCommands(): string[];
|
|
216
|
+
/**
|
|
217
|
+
* ★ Task #4339:启动前 best-effort 冲突检查。
|
|
218
|
+
*
|
|
219
|
+
* lark-cli 一个 EventKey 只允许一个 consumer;若已有 orphan consumer 占着,
|
|
220
|
+
* 我们新起的进程会立刻 `failed_precondition` exit 2,整个 event-source 变 error。
|
|
221
|
+
* 这里提前查一次 `lark-cli event status --json` 并打 warn,让排障有据可依。
|
|
222
|
+
*
|
|
223
|
+
* 完全 best-effort:lark-cli 不存在 / 输出不是 JSON / 超时 → 静默跳过。
|
|
224
|
+
*/
|
|
225
|
+
private warnOnConsumeConflict;
|
|
226
|
+
/**
|
|
227
|
+
* ★ Task #4339:查询当前 bus 上已被占用的 EventKey 集合。
|
|
228
|
+
*
|
|
229
|
+
* 完全 best-effort:lark-cli 不存在 / 输出不是 JSON / 超时 → 返回空集合。
|
|
230
|
+
* protected 是为了让单测覆盖成 no-op(避免真的 spawn lark-cli)。
|
|
231
|
+
*/
|
|
232
|
+
protected probeBusyEventKeys(): Promise<Set<string>>;
|
|
233
|
+
/**
|
|
234
|
+
* ★ Task #4339:挂接单个 consume 子进程的 stdio。
|
|
235
|
+
*
|
|
236
|
+
* 每个子进程持有**自己的行缓冲**(避免两个进程的 NDJSON 切片互相错拼)。
|
|
237
|
+
*
|
|
238
|
+
* @returns 收到 `[event] ready event_key=` 时 resolve;5s 内没收到 ready
|
|
239
|
+
* (或进程直接退出,例如配置错误 exit 2)也会 resolve —— 避免
|
|
240
|
+
* start() 永久卡住,但此时 status 已被置为 error。
|
|
241
|
+
*/
|
|
242
|
+
private wireChildStreams;
|
|
243
|
+
stop(): Promise<void>;
|
|
244
|
+
getStatus(): EventSourceStatus;
|
|
245
|
+
onEvent(handler: EventSourceEventHandler): void;
|
|
246
|
+
offEvent(): void;
|
|
247
|
+
/**
|
|
248
|
+
* 加载 handleRule.plugins 中指定的 plugins
|
|
249
|
+
*
|
|
250
|
+
* ★ 必须先调用 setEnvironment(),否则 plugin.setTaskUpdater 不会注入。
|
|
251
|
+
*/
|
|
252
|
+
private loadPlugins;
|
|
253
|
+
/**
|
|
254
|
+
* ★ Task #4339:把 `card.action.trigger` 的真实端口接到本实例上。
|
|
255
|
+
*
|
|
256
|
+
* 为什么必须有这一步:`card.action.trigger` 走的是「直接回调」而不是 Agent ——
|
|
257
|
+
* `handleEvent` 分流后调 `handleCardActionEvent`,而它**依赖
|
|
258
|
+
* `this.cardActionPorts` 已注入**;未注入时只打一条 warn 然后 return。
|
|
259
|
+
* Task #4331 实现了这套机制但**一直没接线**(生产链路是死代码,只有单测 +
|
|
260
|
+
* 手工 bridge 脚本在跑)。
|
|
261
|
+
*
|
|
262
|
+
* 依赖:
|
|
263
|
+
* - getTask / updateTaskContext ← env.getComponent("task")
|
|
264
|
+
* - createGroupChat / deleteGroupChat ← lark-card-action-handler 的 lark-cli 实现
|
|
265
|
+
* - notifier ← pluginInstances 里插件共享的 LarkCardPatchNotifier
|
|
266
|
+
* (共享实例才知道这张卡片已累积的里程碑/过程历史;找不到就新建一个,
|
|
267
|
+
* `updateMetaAndBuildCard` 会返回 undefined,handler 自动走 fallback)
|
|
268
|
+
*
|
|
269
|
+
* 任意一环缺失(如没配 task component)→ 不注入,行为与之前一致(warn + skip)。
|
|
270
|
+
*/
|
|
271
|
+
private wireCardActionPorts;
|
|
272
|
+
/**
|
|
273
|
+
* Task #4230 follow-up:把「按需建专属群」能力接到卡片路由端口上
|
|
274
|
+
*
|
|
275
|
+
* 顺序问题:两个插件是分别 import + registerPluginHooks 的,NotifyHook 在
|
|
276
|
+
* PerTaskGroupChatPlugin 之前加载,所以只能在 loadPlugins 收尾时补一次。
|
|
277
|
+
*/
|
|
278
|
+
private wireCardRoutingGroupProvider;
|
|
279
|
+
/**
|
|
280
|
+
* 获取插件的 hook 点列表
|
|
281
|
+
*/
|
|
282
|
+
private getPluginHookPoints;
|
|
283
|
+
/**
|
|
284
|
+
* 实例化内置 Plugin
|
|
285
|
+
*
|
|
286
|
+
* 早期版本是按字符串名走动态 import,会因为 bundler 把 workspace 内的 core
|
|
287
|
+
* 同时识别为「内联源码」+「外部包」而产生两份 module(导致 tracer 单例分裂、
|
|
288
|
+
* traceId 跨 plugin 边界丢失)。现在改成顶层静态 import + factory 注册表,
|
|
289
|
+
* 让 bundler 直接看到依赖关系并完成内联。
|
|
290
|
+
*/
|
|
291
|
+
private importPlugin;
|
|
292
|
+
/**
|
|
293
|
+
* 注册 Plugin hooks 到 globalHookManager
|
|
294
|
+
*
|
|
295
|
+
* 支持三种模式:
|
|
296
|
+
* 1. BasePlugin 模式:继承 BasePlugin,需要调用 init(env)
|
|
297
|
+
* 2. TaskPlugin 模式:plugin.hooks 是 [{ point, priority }]
|
|
298
|
+
* 3. Hook 模式:plugin.execute 是函数
|
|
299
|
+
*
|
|
300
|
+
* ★ Task #XXXX P0 修复:检测 plugin.setTaskUpdater 存在性,自动绑定 taskComponent.updateTask 包装。
|
|
301
|
+
* - PerTaskGroupChatPlugin 依赖 setTaskUpdater 把 larkPerTaskChatId 持久化到 DB
|
|
302
|
+
* - 未注入时:plugin 在 attachChatIdToTask 阶段只更新 in-memory,DB 没持久化 → 后续
|
|
303
|
+
* AFTER_UPDATE 从 DB 加载 task 时 getTaskChatId() 返回 undefined,所有通知 silently skip。
|
|
304
|
+
* - 修复链路:EventSourceComponent.startSource → instance.setEnvironment(env) →
|
|
305
|
+
* registerPluginHooks → env.getComponent('task').updateTask → plugin.setTaskUpdater
|
|
306
|
+
*/
|
|
307
|
+
private registerPluginHooks;
|
|
308
|
+
/**
|
|
309
|
+
* ★ P0 修复:如果 plugin 支持 setTaskUpdater,自动注入 taskComponent.updateTask 包装
|
|
310
|
+
*
|
|
311
|
+
* 链路:
|
|
312
|
+
* EventSourceComponent.startSource → instance.setEnvironment(env) →
|
|
313
|
+
* loadPlugins → registerPluginHooks → injectTaskUpdater(plugin) →
|
|
314
|
+
* env.getComponent('task') → taskComponent.updateTask → plugin.setTaskUpdater
|
|
315
|
+
*
|
|
316
|
+
* 行为:
|
|
317
|
+
* - plugin.setTaskUpdater 存在 && env 已注入 && taskComponent 存在 → 注入成功
|
|
318
|
+
* - 任意一环缺失 → 跳过注入,plugin 走 fallback(in-memory only)
|
|
319
|
+
* - 已注入(plugin.hasTaskUpdater() === true)→ 跳过,避免重复
|
|
320
|
+
*
|
|
321
|
+
* 日志:注入成功/失败都有 debug 日志,方便排查为什么 plugin 拿不到 DB 写权限
|
|
322
|
+
*/
|
|
323
|
+
private injectTaskUpdater;
|
|
324
|
+
/**
|
|
325
|
+
* ★ Task #4039 C 项:如果 plugin 支持 setTaskGetter,自动注入 taskComponent.getTask。
|
|
326
|
+
*
|
|
327
|
+
* 用途:PerTaskGroupChatPlugin 的更新/完成/操作通知在"任务自身无群"时沿
|
|
328
|
+
* `parent_task_id` 上溯祖先群,与 CLI notify 路径(resolveNotifyChatIds)统一。
|
|
329
|
+
* 未注入时退化为只读自身 context(向后兼容)。
|
|
330
|
+
*/
|
|
331
|
+
private injectTaskGetter;
|
|
332
|
+
/**
|
|
333
|
+
* ★ Task #4230 follow-up:给支持 setCardRoutingPorts 的 plugin 注入「卡片路由端口」
|
|
334
|
+
*
|
|
335
|
+
* 端口负责三件"需要 IO"的事(让 plugin 保持纯逻辑 + 可单测):
|
|
336
|
+
* 1. lookupChatOwnership(chatId):这个群是不是某个 task 的专属群(多重信号)
|
|
337
|
+
* 2. getTask(id):lineage 上溯
|
|
338
|
+
* 3. ensureTaskGroupChat(task):按需建专属群(由 PerTaskGroupChatPlugin 提供,
|
|
339
|
+
* 在 loadPlugins 收尾时 cross-wire)
|
|
340
|
+
*/
|
|
341
|
+
private injectCardRoutingPorts;
|
|
342
|
+
/**
|
|
343
|
+
* 取群名(带进程内缓存)
|
|
344
|
+
*
|
|
345
|
+
* 只在需要判定"触发群是不是别 task 的群"时调用(DB 信号为空才会走到)。
|
|
346
|
+
* lark-cli 失败 / 未安装 → 返回 undefined(判定退化为"不是专属群")。
|
|
347
|
+
*/
|
|
348
|
+
private lookupChatName;
|
|
349
|
+
/**
|
|
350
|
+
* ★ Task #4023:如果 plugin 支持 setSessionComponent,自动注入 SessionComponent 引用
|
|
351
|
+
*
|
|
352
|
+
* 链路:
|
|
353
|
+
* EventSourceComponent.startSource → instance.setEnvironment(env) →
|
|
354
|
+
* registerPluginHooks → env.getComponent('session') → plugin.setSessionComponent
|
|
355
|
+
*
|
|
356
|
+
* 未注入时:PerTaskGroupChatPlugin 不会写 chat↔task 绑定,群消息 handler 拿不到
|
|
357
|
+
* parentTaskId 注入。task.context.larkPerTaskChatId 仍正常工作。
|
|
358
|
+
*/
|
|
359
|
+
private injectSessionComponent;
|
|
360
|
+
/**
|
|
361
|
+
* ★ Task #4023 + #4025 OC track #3 改进:查询 chat_id → task_id 绑定
|
|
362
|
+
*
|
|
363
|
+
* 缓存策略:依赖 SessionComponent.getChatTaskBinding 内置 LRU+TTL 缓存,
|
|
364
|
+
* 这里不再重复缓存(避免失效传播问题)。
|
|
365
|
+
*
|
|
366
|
+
* 设计选择(采纳 OC track B 的设计哲学):
|
|
367
|
+
* - duck-typing 检查 sessionComponent.getChatTaskBinding(不依赖具体类)
|
|
368
|
+
* - 仅当 binding.status === "ready" 且 taskId 是正数时才返回
|
|
369
|
+
* (保留 A 的 0/负数 fail-fast 哲学;不让 caller 处理无效 taskId)
|
|
370
|
+
* - 错误 / 缺失一律 graceful 返回 null(event dispatch 不被阻塞)
|
|
371
|
+
*
|
|
372
|
+
* @returns taskId(如有 ready 绑定);null 表示无绑定、缺 sessionComponent 或抛错
|
|
373
|
+
*/
|
|
374
|
+
private resolveChatTaskBinding;
|
|
375
|
+
/**
|
|
376
|
+
* 卸载所有已加载的 plugins
|
|
377
|
+
*/
|
|
378
|
+
private unloadPlugins;
|
|
379
|
+
/**
|
|
380
|
+
* 把一段流文本按行切分并 dispatch(默认共享 buffer 版本,兼容旧调用/测试)
|
|
381
|
+
*/
|
|
382
|
+
private processStream;
|
|
383
|
+
/**
|
|
384
|
+
* ★ Task #4339:带**独立行缓冲**的流处理。
|
|
385
|
+
*
|
|
386
|
+
* 每个 consume 子进程持有自己的 buffer holder —— 两个进程的 NDJSON 切片
|
|
387
|
+
* 若共用一个 buffer,会在 chunk 边界上互相错拼出坏行。
|
|
388
|
+
*
|
|
389
|
+
* @param opts.jsonLinesOnly true 时只 dispatch `{` 开头的完整行(stderr 用,
|
|
390
|
+
* 该流里混着 `[event] ...` 状态信息)。注意判断是在**拼完整行之后**做的,
|
|
391
|
+
* 所以跨 chunk 的 JSON 也能正确还原。
|
|
392
|
+
*/
|
|
393
|
+
private processStreamWith;
|
|
394
|
+
/**
|
|
395
|
+
* 逐行 dispatch。handleEvent 是 async(Task #4023 注入 parentTaskId 需要
|
|
396
|
+
* await binding 查询),但这里不能阻塞 stream 读取 —— fire-and-forget,
|
|
397
|
+
* 错误由 handleEvent 自己的 try/catch + span.end() 兜底。
|
|
398
|
+
*/
|
|
399
|
+
private dispatchLines;
|
|
400
|
+
private handleEvent;
|
|
401
|
+
/**
|
|
402
|
+
* 处理 card.action.trigger 事件(Task #4331)
|
|
403
|
+
*
|
|
404
|
+
* 流程:
|
|
405
|
+
* 1. 解析 event.action_value(JSON 字符串)拿到 { action, taskId }
|
|
406
|
+
* 2. 调 handleCardAction(建群/解散群 + 写 task.context + 渲染新卡片)
|
|
407
|
+
* 3. 用 event.token 调 lark-cli api POST /open-apis/interactive/v1/card/update patch 原卡片
|
|
408
|
+
* (飞书要求用 token 即时 patch,30min 有效)
|
|
409
|
+
*
|
|
410
|
+
* ★★ 如何真正收到 card.action.trigger(Task #4339 修正)★★
|
|
411
|
+
*
|
|
412
|
+
* 旧注释写的是「把 command 改成
|
|
413
|
+
* `lark-cli event consume 'im.message.receive_v1,card.action.trigger' --as bot`」
|
|
414
|
+
* —— 这是**错的**:lark-cli `event consume` 只接受恰好一个 EventKey,
|
|
415
|
+
* 逗号形式会 `unknown EventKey` 并 **exit 2**,整个 event-source 变 error。
|
|
416
|
+
*
|
|
417
|
+
* 正确做法:在 EventSource config 里配置 `eventKeys` 数组
|
|
418
|
+
* (一个 key 一个子进程,共享同一个 bus daemon):
|
|
419
|
+
*
|
|
420
|
+
* {
|
|
421
|
+
* "type": "lark-cli",
|
|
422
|
+
* "profile": "tongzhuli",
|
|
423
|
+
* "eventKeys": ["im.message.receive_v1", "card.action.trigger"]
|
|
424
|
+
* }
|
|
425
|
+
*
|
|
426
|
+
* 且必须先在飞书开发者后台「事件与回调 → 回调配置」里开启 card.action.trigger,
|
|
427
|
+
* 否则 consumer 能 ready 但永远收不到事件。
|
|
428
|
+
* 详见 reports/2026-10-19-lark-cli-multi-event-consume-research.md
|
|
429
|
+
*/
|
|
430
|
+
private handleCardActionEvent;
|
|
431
|
+
/**
|
|
432
|
+
* 用飞书 token 直接 patch 卡片(30min 有效,最多 2 次)
|
|
433
|
+
*
|
|
434
|
+
* 飞书 API: POST /open-apis/interactive/v1/card/update
|
|
435
|
+
*
|
|
436
|
+
* ★ Task #4337 Bug B fix + refactor:
|
|
437
|
+
* - 抽出为 module-level exported function `patchCardByLarkCli`(可独立测试 cmd 字符串)
|
|
438
|
+
* - 删掉 `--yes`(lark-cli 1.0.96 `api` 子命令不支持 `unknown flag "--yes"`)
|
|
439
|
+
*/
|
|
440
|
+
private patchCardByToken;
|
|
441
|
+
/**
|
|
442
|
+
* 从 rawEvent 中提取 userId
|
|
443
|
+
*
|
|
444
|
+
* ★ Task #3987 后续修复:兼容 lark-cli `event consume` 的简化格式
|
|
445
|
+
* - 嵌套格式: event.event.sender.sender_id.open_id
|
|
446
|
+
* - 简化格式: event.sender_id(顶层字符串)
|
|
447
|
+
*/
|
|
448
|
+
private extractUserId;
|
|
449
|
+
/**
|
|
450
|
+
* 构建 EnvReplyChannel
|
|
451
|
+
*/
|
|
452
|
+
private buildReplyChannel;
|
|
453
|
+
/**
|
|
454
|
+
* 使用 lark-cli 发送消息
|
|
455
|
+
*/
|
|
456
|
+
private sendLarkMessage;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* LarkCli Handler
|
|
460
|
+
*/
|
|
461
|
+
export declare const larkCliHandler: EventSourceHandler;
|
|
462
|
+
/**
|
|
463
|
+
* 用飞书 token 直接 patch 卡片(30min 有效,最多 2 次)
|
|
464
|
+
*
|
|
465
|
+
* 飞书 API: POST /open-apis/interactive/v1/card/update
|
|
466
|
+
*
|
|
467
|
+
* ★ Task #4337 Bug B fix:
|
|
468
|
+
* - 删掉 `--yes`(lark-cli 1.0.96 `api` 子命令不支持,会报 `unknown flag "--yes"`)
|
|
469
|
+
* - 抽出为 module-level exported function 便于独立测试 cmd 字符串
|
|
470
|
+
*
|
|
471
|
+
* @param token 飞书提供的 30min 有效 token(事件里带的 ctoken_xxx)
|
|
472
|
+
* @param card 新的卡片 payload(来自 buildTaskCard 的输出)
|
|
473
|
+
* @param profile lark-cli profile(可选)
|
|
474
|
+
*/
|
|
475
|
+
export declare function patchCardByLarkCli(token: string, card: any, profile?: string): Promise<void>;
|
|
476
|
+
/**
|
|
477
|
+
* 所有内置 Handler
|
|
478
|
+
*/
|
|
479
|
+
export declare const builtInHandlers: EventSourceHandler[];
|
|
480
|
+
export { timerHandler };
|
|
481
|
+
export { bountyIMHandler };
|
|
482
|
+
export { bountyCliHandler };
|
|
483
|
+
/**
|
|
484
|
+
* 根据类型获取内置 Handler
|
|
485
|
+
*/
|
|
486
|
+
export declare function getBuiltInHandler(type: string): EventSourceHandler | undefined;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventStore — ESPlugin v2 Phase 1(Task #4042)
|
|
3
|
+
*
|
|
4
|
+
* 持久化 trigger event,让 ES plugin 能:
|
|
5
|
+
* 1. emitTriggerEvent(payload) → 返回 triggerEventId 并落库
|
|
6
|
+
* 2. getEventById(id) → 主 agent 处理 notify event 时反查 ES info(chatId / messageId / senderId)
|
|
7
|
+
* 3. getRecentEvents(esType, senderId, limit) → 多轮对话上下文
|
|
8
|
+
*
|
|
9
|
+
* 设计目标:
|
|
10
|
+
* - 同步 API(better-sqlite3 / bun:sqlite 都是同步的,wrap 成 async 给上层调用方便)
|
|
11
|
+
* - 单库 / 单表 / 1 索引(开销最小)
|
|
12
|
+
* - 跑 bun:test < 10ms p95(warm)
|
|
13
|
+
*
|
|
14
|
+
* 向后兼容:
|
|
15
|
+
* - 不引入运行时依赖(沿用 core 现有的 sqlite 兼容层,与 span-storage 同源)
|
|
16
|
+
* - 不修改现有任何 schema
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Trigger event 元数据(来自 ES 原始 event)。
|
|
20
|
+
*
|
|
21
|
+
* 故意写得比 EventMetadata 更宽:因为不同 ES(lark / bounty-im / timer / cron)
|
|
22
|
+
* 元数据形状不同,store 不做形状校验,仅做 round-trip。
|
|
23
|
+
*/
|
|
24
|
+
export interface TriggerEventMetadata {
|
|
25
|
+
/** 事件类型(im.message.receive_v1 / cron.tick / ...)*/
|
|
26
|
+
eventType?: string;
|
|
27
|
+
/** 发送方 app ID(lark 用)*/
|
|
28
|
+
appId?: string;
|
|
29
|
+
/** 渠道 chat ID(lark / bounty-im 用)*/
|
|
30
|
+
chatId?: string;
|
|
31
|
+
/** 渠道类型(p2p / group / channel)*/
|
|
32
|
+
chatType?: string;
|
|
33
|
+
/** 原始消息 ID(lark 用,im +messages-reply 关联回原 user query)*/
|
|
34
|
+
messageId?: string;
|
|
35
|
+
/** 消息类型(text / image / ...)*/
|
|
36
|
+
messageType?: string;
|
|
37
|
+
/** 发送方 user ID(lark open_id / bounty user_id)*/
|
|
38
|
+
senderId?: string;
|
|
39
|
+
/** 租户 key(多租户场景)*/
|
|
40
|
+
tenantKey?: string;
|
|
41
|
+
/** 其他 ES-specific 元数据 */
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Trigger event 输入(emitTriggerEvent 调用方传)
|
|
46
|
+
*/
|
|
47
|
+
export interface TriggerEventInput {
|
|
48
|
+
/** 发送方 ID(必填,用于 getRecentEvents 查询)*/
|
|
49
|
+
senderId: string;
|
|
50
|
+
/** 提取出的文本内容(用于上层 LLM prompt)*/
|
|
51
|
+
text?: string;
|
|
52
|
+
/** 元数据(chatId / messageId / ...)*/
|
|
53
|
+
metadata: TriggerEventMetadata;
|
|
54
|
+
/** ES 原始 event 对象(可选,留档用)*/
|
|
55
|
+
rawEvent?: unknown;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 持久化后的 event(getEventById / getRecentEvents 返回)
|
|
59
|
+
*/
|
|
60
|
+
export interface PersistedEvent {
|
|
61
|
+
eventId: string;
|
|
62
|
+
esType: string;
|
|
63
|
+
senderId: string;
|
|
64
|
+
text: string | null;
|
|
65
|
+
/** JSON 反序列化后的元数据 */
|
|
66
|
+
metadata: TriggerEventMetadata;
|
|
67
|
+
/** 原始 event 对象(JSON 反序列化)*/
|
|
68
|
+
rawEvent: unknown;
|
|
69
|
+
createdAt: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* EventStore 接口
|
|
73
|
+
*/
|
|
74
|
+
export interface EventStore {
|
|
75
|
+
insertTriggerEvent(input: TriggerEventInput, esType: string): Promise<string>;
|
|
76
|
+
getEventById(eventId: string): Promise<PersistedEvent | null>;
|
|
77
|
+
getRecentEvents(esType: string, senderId: string, limit: number): Promise<PersistedEvent[]>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* EventStore 配置
|
|
81
|
+
*/
|
|
82
|
+
export interface EventStoreOptions {
|
|
83
|
+
/** SQLite 数据库路径(必填)*/
|
|
84
|
+
dbPath: string;
|
|
85
|
+
}
|
|
86
|
+
declare const SCHEMA_SQL = "\nCREATE TABLE IF NOT EXISTS event_store (\n event_id TEXT PRIMARY KEY,\n es_type TEXT NOT NULL,\n sender_id TEXT NOT NULL,\n text TEXT,\n metadata TEXT NOT NULL,\n raw_event TEXT,\n created_at INTEGER NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS idx_es_sender_time\n ON event_store (es_type, sender_id, created_at DESC);\n";
|
|
87
|
+
/**
|
|
88
|
+
* 默认 EventStore 实现(SQLite)
|
|
89
|
+
*/
|
|
90
|
+
export declare class EventStoreImpl implements EventStore {
|
|
91
|
+
private readonly db;
|
|
92
|
+
private readonly insertStmt;
|
|
93
|
+
private readonly getByIdStmt;
|
|
94
|
+
private readonly recentStmt;
|
|
95
|
+
constructor(options: EventStoreOptions);
|
|
96
|
+
insertTriggerEvent(input: TriggerEventInput, esType: string): Promise<string>;
|
|
97
|
+
getEventById(eventId: string): Promise<PersistedEvent | null>;
|
|
98
|
+
getRecentEvents(esType: string, senderId: string, limit: number): Promise<PersistedEvent[]>;
|
|
99
|
+
/**
|
|
100
|
+
* 关闭数据库(测试 / graceful shutdown 用)
|
|
101
|
+
*/
|
|
102
|
+
close(): void;
|
|
103
|
+
}
|
|
104
|
+
export { SCHEMA_SQL as EVENT_STORE_SCHEMA_SQL };
|
|
105
|
+
/** 注册进程内共享 EventStore(cli wiring / 测试用) */
|
|
106
|
+
export declare function setSharedEventStore(store: EventStore | null): void;
|
|
107
|
+
/** 获取进程内共享 EventStore(未注册返回 null) */
|
|
108
|
+
export declare function getSharedEventStore(): EventStore | null;
|
|
109
|
+
/** 清空共享单例(仅测试用) */
|
|
110
|
+
export declare function resetSharedEventStore(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview 共享 idempotency-key 派生器(Task #4137 P1)
|
|
3
|
+
*
|
|
4
|
+
* 用途:把"出站消息 idempotency-key 派生"逻辑抽出来,让:
|
|
5
|
+
* - PerTaskGroupChatPlugin.buildSendToChatArgs
|
|
6
|
+
* - LarkCliTaskNotifyHook.buildReplyArgs
|
|
7
|
+
* 共用同一份派生规则(hash 来源 / 截断 / 兜底)。
|
|
8
|
+
*
|
|
9
|
+
* 设计:飞书 lark-cli `im +messages-send --idempotency-key <key>` 限制 ≤ 50 字符,
|
|
10
|
+
* 因此派生后必须截断。Bun.hash 默认无依赖,hash 命中率高。
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* 派生 ≤50 字符的 idempotency-key
|
|
14
|
+
*
|
|
15
|
+
* @param parts - 拼接来源(如 chatId / taskId / type / content 截断 / messageId)
|
|
16
|
+
* 任意 string | number | undefined 都会被 stringify 拼到 source 串
|
|
17
|
+
* @returns ≤ 50 字符的 idempotency-key("roy-" 前缀)
|
|
18
|
+
*/
|
|
19
|
+
export declare function deriveIdempotencyKey(parts: Array<string | number | undefined | null>): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventSource 模块入口
|
|
3
|
+
*
|
|
4
|
+
* 导出所有 EventSource 相关的类型、类和函数
|
|
5
|
+
*/
|
|
6
|
+
export type { EventSourceStatus, EventSourceType, EventSourceConfig, EventMetadata, RecommendedAction, ReplyChannel, EventSourceEventPayload, EventSourceEvent, EventSourceEventHandler, EventSourceStatusChangeEvent, EventSourcePersistenceConfig, EventSourceInstance, EventSourceHandler, EventSourceInitHook, EventSourceComponentInterface, EventSourceAgentHandlerConfig, } from "./types";
|
|
7
|
+
export { EventSourceInitHooks } from "./types";
|
|
8
|
+
export { BUILT_IN_EVENT_SOURCE_TYPES, BUILT_IN_EVENT_SOURCE_TYPE_LIST } from "./types";
|
|
9
|
+
export { isBuiltInEventSourceType, isValidEventSourceType, getDefaultConfigForType, validateEventSourceConfig, } from "./types";
|
|
10
|
+
export { EventSourceComponent } from "./event-source-component";
|
|
11
|
+
export { EventStoreImpl, setSharedEventStore, getSharedEventStore, resetSharedEventStore, } from "./event-store";
|
|
12
|
+
export type { EventStore, TriggerEventInput, TriggerEventMetadata, PersistedEvent, EventStoreOptions, } from "./event-store";
|
|
13
|
+
export { larkCliHandler, timerHandler, bountyIMHandler, builtInHandlers, getBuiltInHandler, extractMetadata, } from "./event-source-handlers";
|
|
14
|
+
export { TimerInstance } from "./timer-handler";
|
|
15
|
+
export { BountyIMInstance, buildDefaultBountyIMSystemPrompt, resolveBountyIMSystemPrompt } from "./bounty-im-handler";
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
larkCliHandler,
|
|
12
12
|
resolveBountyIMSystemPrompt,
|
|
13
13
|
timerHandler
|
|
14
|
-
} from "../../shared/@ai-setting/roy-agent-core-
|
|
14
|
+
} from "../../shared/@ai-setting/roy-agent-core-ph5qbqcx.js";
|
|
15
15
|
import {
|
|
16
16
|
BUILT_IN_EVENT_SOURCE_TYPES,
|
|
17
17
|
BUILT_IN_EVENT_SOURCE_TYPE_LIST,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
validateEventSourceConfig
|
|
23
23
|
} from "../../shared/@ai-setting/roy-agent-core-ck60j1q9.js";
|
|
24
24
|
import"../../shared/@ai-setting/roy-agent-core-rnwr39b0.js";
|
|
25
|
-
import"../../shared/@ai-setting/roy-agent-core-
|
|
25
|
+
import"../../shared/@ai-setting/roy-agent-core-hch2geta.js";
|
|
26
26
|
import {
|
|
27
27
|
EventStoreImpl,
|
|
28
28
|
getSharedEventStore,
|