@ai-setting/roy-agent-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +99145 -0
- package/package.json +114 -0
- package/src/config/config-component.test.ts +627 -0
- package/src/config/config-component.ts +906 -0
- package/src/config/config-parser.test.ts +319 -0
- package/src/config/config-parser.ts +203 -0
- package/src/config/decentralized-config.test.ts +740 -0
- package/src/config/env-key.ts +210 -0
- package/src/config/env-source.test.ts +252 -0
- package/src/config/env-source.ts +301 -0
- package/src/config/file-source.test.ts +357 -0
- package/src/config/file-source.ts +421 -0
- package/src/config/index.ts +24 -0
- package/src/config/protocol-resolver.test.ts +217 -0
- package/src/config/protocol-resolver.ts +228 -0
- package/src/env/agent/agent-component.abort.test.ts +511 -0
- package/src/env/agent/agent-component.record-session.test.ts +349 -0
- package/src/env/agent/agent-component.test.ts +1389 -0
- package/src/env/agent/agent-component.tool-error.test.ts +327 -0
- package/src/env/agent/agent-component.ts +1711 -0
- package/src/env/agent/agent-config-registration.test.ts +226 -0
- package/src/env/agent/agent-config-registration.ts +46 -0
- package/src/env/agent/agent-reminder-plugin.integration.test.ts +243 -0
- package/src/env/agent/index.ts +10 -0
- package/src/env/agent/summary-agent.parse-hint.test.ts +360 -0
- package/src/env/agent/summary-agent.ts +508 -0
- package/src/env/agent/types.ts +536 -0
- package/src/env/commands/commands-component.test.ts +364 -0
- package/src/env/commands/commands-component.ts +604 -0
- package/src/env/commands/commands-config-registration.test.ts +198 -0
- package/src/env/commands/commands-config-registration.ts +38 -0
- package/src/env/commands/index.ts +21 -0
- package/src/env/commands/parser.test.ts +203 -0
- package/src/env/commands/parser.ts +115 -0
- package/src/env/commands/types.ts +184 -0
- package/src/env/commands-prompt-integration.test.ts +243 -0
- package/src/env/component-env.test.ts +119 -0
- package/src/env/component.ts +335 -0
- package/src/env/constants.test.ts +72 -0
- package/src/env/constants.ts +123 -0
- package/src/env/debug/debug-component.test.ts +114 -0
- package/src/env/debug/debug-component.ts +547 -0
- package/src/env/debug/formatters/index.ts +9 -0
- package/src/env/debug/formatters/repl-formatter.test.ts +139 -0
- package/src/env/debug/formatters/repl-formatter.ts +358 -0
- package/src/env/debug/formatters/trace-formatter.test.ts +119 -0
- package/src/env/debug/formatters/trace-formatter.ts +191 -0
- package/src/env/debug/formatters/tree-formatter.test.ts +107 -0
- package/src/env/debug/formatters/tree-formatter.ts +325 -0
- package/src/env/debug/index.ts +38 -0
- package/src/env/debug/parser/regex-parser.test.ts +201 -0
- package/src/env/debug/parser/regex-parser.ts +196 -0
- package/src/env/debug/parser/span-builder.test.ts +241 -0
- package/src/env/debug/parser/span-builder.ts +386 -0
- package/src/env/debug/reader/log-reader.test.ts +170 -0
- package/src/env/debug/reader/log-reader.ts +186 -0
- package/src/env/debug/reader/span-db-reader.test.ts +118 -0
- package/src/env/debug/reader/span-db-reader.ts +201 -0
- package/src/env/debug/types.test.ts +187 -0
- package/src/env/debug/types.ts +171 -0
- package/src/env/environment-init.test.ts +183 -0
- package/src/env/environment-lifecycle.test.ts +516 -0
- package/src/env/environment-service.test.ts +332 -0
- package/src/env/environment.handle-query.test.ts +96 -0
- package/src/env/environment.test.ts +232 -0
- package/src/env/environment.ts +708 -0
- package/src/env/errors.test.ts +165 -0
- package/src/env/errors.ts +157 -0
- package/src/env/event-source/event-source-agent-handler.test.ts +193 -0
- package/src/env/event-source/event-source-agent-handler.ts +111 -0
- package/src/env/event-source/event-source-component.process-cleanup.test.ts +236 -0
- package/src/env/event-source/event-source-component.stop.test.ts +346 -0
- package/src/env/event-source/event-source-component.test.ts +1207 -0
- package/src/env/event-source/event-source-component.ts +1379 -0
- package/src/env/event-source/event-source-config-registration.test.ts +242 -0
- package/src/env/event-source/event-source-config-registration.ts +37 -0
- package/src/env/event-source/event-source-integration.test.ts +320 -0
- package/src/env/event-source/event-source-platform.test.ts +630 -0
- package/src/env/event-source/types.ts +298 -0
- package/src/env/hook/global-hook-manager.ts +162 -0
- package/src/env/hook/hook-manager.test.ts +374 -0
- package/src/env/hook/hook-manager.ts +309 -0
- package/src/env/hook/index.ts +38 -0
- package/src/env/hook/types.ts +138 -0
- package/src/env/index.ts +144 -0
- package/src/env/interface.ts +203 -0
- package/src/env/llm/hooks.test.ts +293 -0
- package/src/env/llm/hooks.ts +316 -0
- package/src/env/llm/index.ts +61 -0
- package/src/env/llm/invoke-threshold-check.test.ts +88 -0
- package/src/env/llm/invoke-timeout.test.ts +54 -0
- package/src/env/llm/invoke.test.ts +71 -0
- package/src/env/llm/invoke.ts +1039 -0
- package/src/env/llm/llm-config.test.ts +523 -0
- package/src/env/llm/llm.test.ts +233 -0
- package/src/env/llm/llm.ts +568 -0
- package/src/env/llm/provider.test.ts +182 -0
- package/src/env/llm/provider.ts +108 -0
- package/src/env/llm/transform.test.ts +251 -0
- package/src/env/llm/transform.ts +286 -0
- package/src/env/llm/types.test.ts +580 -0
- package/src/env/llm/types.ts +424 -0
- package/src/env/log-trace/decorator-otel.test.ts +182 -0
- package/src/env/log-trace/decorator.ts +230 -0
- package/src/env/log-trace/index.ts +79 -0
- package/src/env/log-trace/log-trace-component.test.ts +242 -0
- package/src/env/log-trace/log-trace-component.ts +497 -0
- package/src/env/log-trace/log-trace-config-registration.test.ts +348 -0
- package/src/env/log-trace/log-trace-config-registration.ts +45 -0
- package/src/env/log-trace/logger.test.ts +149 -0
- package/src/env/log-trace/logger.ts +522 -0
- package/src/env/log-trace/opentelemetry/cli-propagation.test.ts +147 -0
- package/src/env/log-trace/opentelemetry/cli-propagation.ts +194 -0
- package/src/env/log-trace/opentelemetry/integration.test.ts +668 -0
- package/src/env/log-trace/opentelemetry/mod.ts +25 -0
- package/src/env/log-trace/opentelemetry/propagation-env.test.ts +181 -0
- package/src/env/log-trace/opentelemetry/propagation-env.ts +136 -0
- package/src/env/log-trace/opentelemetry/propagation.test.ts +259 -0
- package/src/env/log-trace/opentelemetry/propagation.ts +215 -0
- package/src/env/log-trace/opentelemetry/tracer-provider-context.test.ts +166 -0
- package/src/env/log-trace/opentelemetry/tracer-provider.test.ts +379 -0
- package/src/env/log-trace/opentelemetry/tracer-provider.ts +612 -0
- package/src/env/log-trace/span-storage.test.ts +145 -0
- package/src/env/log-trace/span-storage.ts +230 -0
- package/src/env/log-trace/trace-context.test.ts +187 -0
- package/src/env/log-trace/trace-context.ts +162 -0
- package/src/env/log-trace/types.test.ts +63 -0
- package/src/env/log-trace/types.ts +172 -0
- package/src/env/mcp/README.md +244 -0
- package/src/env/mcp/__integration__/mcp-component.integration.test.ts +373 -0
- package/src/env/mcp/config.test.ts +74 -0
- package/src/env/mcp/config.ts +116 -0
- package/src/env/mcp/index.ts +41 -0
- package/src/env/mcp/loader.test.ts +161 -0
- package/src/env/mcp/loader.ts +209 -0
- package/src/env/mcp/mcp-component.test.ts +111 -0
- package/src/env/mcp/mcp-component.ts +358 -0
- package/src/env/mcp/mcp-config-registration.test.ts +304 -0
- package/src/env/mcp/mcp-config-registration.ts +50 -0
- package/src/env/mcp/scanner.test.ts +170 -0
- package/src/env/mcp/scanner.ts +246 -0
- package/src/env/mcp/tool/adapter.test.ts +520 -0
- package/src/env/mcp/tool/adapter.ts +521 -0
- package/src/env/mcp/tool/index.ts +5 -0
- package/src/env/mcp/types.test.ts +171 -0
- package/src/env/mcp/types.ts +79 -0
- package/src/env/memory/README.md +177 -0
- package/src/env/memory/built-in/index.ts +59 -0
- package/src/env/memory/built-in/recall-memory.ts +103 -0
- package/src/env/memory/built-in/record-memory.ts +148 -0
- package/src/env/memory/index.ts +20 -0
- package/src/env/memory/memory-component.test.ts +239 -0
- package/src/env/memory/memory-component.ts +503 -0
- package/src/env/memory/memory-config-registration.test.ts +67 -0
- package/src/env/memory/memory-config-registration.ts +48 -0
- package/src/env/memory/memory-config.ts +45 -0
- package/src/env/memory/memory-file.test.ts +268 -0
- package/src/env/memory/plugin/index.ts +48 -0
- package/src/env/memory/plugin/memory-agent.test.ts +249 -0
- package/src/env/memory/plugin/memory-agent.ts +365 -0
- package/src/env/memory/plugin/memory-manager.ts +198 -0
- package/src/env/memory/plugin/memory-plugin-agent.test.ts +145 -0
- package/src/env/memory/plugin/memory-plugin.ts +210 -0
- package/src/env/memory/plugin/plugin-simplified.test.ts +51 -0
- package/src/env/memory/plugin/recall-memory.test.ts +106 -0
- package/src/env/memory/plugin/recall-memory.ts +53 -0
- package/src/env/memory/plugin/types.ts +101 -0
- package/src/env/memory/tools/memory-agent-tools.ts +228 -0
- package/src/env/memory/types.ts +85 -0
- package/src/env/paths.ts +118 -0
- package/src/env/prompt/index.ts +18 -0
- package/src/env/prompt/memory-prompts.test.ts +91 -0
- package/src/env/prompt/prompt-component.test.ts +491 -0
- package/src/env/prompt/prompt-component.ts +619 -0
- package/src/env/prompt/prompt-config-registration.test.ts +213 -0
- package/src/env/prompt/prompt-config-registration.ts +39 -0
- package/src/env/prompt/prompts-index.ts +504 -0
- package/src/env/prompt/renderer.ts +67 -0
- package/src/env/prompt/types.ts +136 -0
- package/src/env/session/hooks.ts +18 -0
- package/src/env/session/index.ts +37 -0
- package/src/env/session/search-query-parser.test.ts +425 -0
- package/src/env/session/search-query-parser.ts +171 -0
- package/src/env/session/session-checkpoint.test.ts +523 -0
- package/src/env/session/session-component.extract-recent-messages.test.ts +209 -0
- package/src/env/session/session-component.test.ts +132 -0
- package/src/env/session/session-component.ts +1249 -0
- package/src/env/session/session-config-registration.test.ts +138 -0
- package/src/env/session/session-config-registration.ts +52 -0
- package/src/env/session/session-message-converter.test.ts +763 -0
- package/src/env/session/session-message-converter.ts +415 -0
- package/src/env/session/session-message-e2e.test.ts +448 -0
- package/src/env/session/session-search.test.ts +391 -0
- package/src/env/session/session-store.test.ts +362 -0
- package/src/env/session/session-store.ts +141 -0
- package/src/env/session/storage/index.ts +6 -0
- package/src/env/session/storage/memory.ts +502 -0
- package/src/env/session/storage/sqlite.ts +794 -0
- package/src/env/session/types.ts +742 -0
- package/src/env/skill/config.ts +39 -0
- package/src/env/skill/index.ts +6 -0
- package/src/env/skill/parser.test.ts +116 -0
- package/src/env/skill/parser.ts +77 -0
- package/src/env/skill/scanner.test.ts +211 -0
- package/src/env/skill/scanner.ts +119 -0
- package/src/env/skill/skill-component.test.ts +234 -0
- package/src/env/skill/skill-component.ts +352 -0
- package/src/env/skill/skill-config-registration.test.ts +60 -0
- package/src/env/skill/skill-config-registration.ts +43 -0
- package/src/env/skill/tool/index.ts +1 -0
- package/src/env/skill/tool/skill-tool.test.ts +100 -0
- package/src/env/skill/tool/skill-tool.ts +72 -0
- package/src/env/skill/types.ts +64 -0
- package/src/env/task/delegate/delegate-tool.test.ts +498 -0
- package/src/env/task/delegate/delegate-tool.ts +1014 -0
- package/src/env/task/delegate/index.ts +18 -0
- package/src/env/task/delegate/stop-tool.test.ts +140 -0
- package/src/env/task/delegate/stop-tool.ts +119 -0
- package/src/env/task/delegate/task-events.test.ts +178 -0
- package/src/env/task/delegate/task-events.ts +143 -0
- package/src/env/task/hooks/contexts.test.ts +92 -0
- package/src/env/task/hooks/contexts.ts +192 -0
- package/src/env/task/hooks/index.ts +23 -0
- package/src/env/task/hooks/task-hook-points.test.ts +32 -0
- package/src/env/task/hooks/task-hook-points.ts +54 -0
- package/src/env/task/index.ts +7 -0
- package/src/env/task/plugins/index.ts +13 -0
- package/src/env/task/plugins/task-plugin.test.ts +74 -0
- package/src/env/task/plugins/task-plugin.ts +89 -0
- package/src/env/task/plugins/task-tag-plugin.test.ts +377 -0
- package/src/env/task/plugins/task-tag-plugin.ts +319 -0
- package/src/env/task/plugins/task-workflow-extractor.integration.test.ts +226 -0
- package/src/env/task/plugins/workflow-extractor-agent.test.ts +107 -0
- package/src/env/task/plugins/workflow-extractor-agent.ts +225 -0
- package/src/env/task/storage/index.ts +6 -0
- package/src/env/task/storage/sqlite-task-store.test.ts +283 -0
- package/src/env/task/storage/sqlite-task-store.ts +903 -0
- package/src/env/task/storage/task-search.test.ts +291 -0
- package/src/env/task/tag-service.test.ts +198 -0
- package/src/env/task/tag-service.ts +264 -0
- package/src/env/task/task-component.test.ts +193 -0
- package/src/env/task/task-component.ts +658 -0
- package/src/env/task/task-config-registration.test.ts +57 -0
- package/src/env/task/task-config-registration.ts +37 -0
- package/src/env/task/task-types.test.ts +137 -0
- package/src/env/task/tools/complete-tool.ts +44 -0
- package/src/env/task/tools/create-tool.ts +49 -0
- package/src/env/task/tools/delete-tool.ts +43 -0
- package/src/env/task/tools/get-tool.ts +59 -0
- package/src/env/task/tools/index.ts +10 -0
- package/src/env/task/tools/list-tool.ts +40 -0
- package/src/env/task/tools/operation/create-tool.ts +48 -0
- package/src/env/task/tools/operation/delete-tool.ts +43 -0
- package/src/env/task/tools/operation/get-tool.ts +43 -0
- package/src/env/task/tools/operation/index.ts +9 -0
- package/src/env/task/tools/operation/list-tool.ts +40 -0
- package/src/env/task/tools/operation/operation-tools.test.ts +274 -0
- package/src/env/task/tools/operation/operation-types.ts +75 -0
- package/src/env/task/tools/operation/update-tool.ts +47 -0
- package/src/env/task/tools/task-tools.test.ts +203 -0
- package/src/env/task/tools/task-types.test.ts +75 -0
- package/src/env/task/tools/task-types.ts +68 -0
- package/src/env/task/tools/update-tool.ts +70 -0
- package/src/env/task/types.ts +160 -0
- package/src/env/tool/built-in/bash.ts +201 -0
- package/src/env/tool/built-in/echo.ts +29 -0
- package/src/env/tool/built-in/edit-file.test.ts +136 -0
- package/src/env/tool/built-in/edit-file.ts +92 -0
- package/src/env/tool/built-in/glob.test.ts +94 -0
- package/src/env/tool/built-in/glob.ts +65 -0
- package/src/env/tool/built-in/grep.test.ts +122 -0
- package/src/env/tool/built-in/grep.ts +108 -0
- package/src/env/tool/built-in/index.ts +44 -0
- package/src/env/tool/built-in/read-file.test.ts +84 -0
- package/src/env/tool/built-in/read-file.ts +75 -0
- package/src/env/tool/built-in/write-file.test.ts +119 -0
- package/src/env/tool/built-in/write-file.ts +68 -0
- package/src/env/tool/index.ts +24 -0
- package/src/env/tool/registry.test.ts +257 -0
- package/src/env/tool/registry.ts +167 -0
- package/src/env/tool/tool-component.test.ts +559 -0
- package/src/env/tool/tool-component.ts +563 -0
- package/src/env/tool/tool-config-registration.test.ts +249 -0
- package/src/env/tool/tool-config-registration.ts +46 -0
- package/src/env/tool/types.ts +267 -0
- package/src/env/tool/validator.test.ts +143 -0
- package/src/env/tool/validator.ts +44 -0
- package/src/env/types.ts +180 -0
- package/src/env/workflow/ask-user-tool-registration.test.ts +216 -0
- package/src/env/workflow/complex-workflow.integration.test.ts +1900 -0
- package/src/env/workflow/decorators/decorator-node.ts +229 -0
- package/src/env/workflow/decorators/decorator.test.ts +196 -0
- package/src/env/workflow/decorators/edge.ts +82 -0
- package/src/env/workflow/decorators/index.ts +31 -0
- package/src/env/workflow/decorators/node-as.ts +98 -0
- package/src/env/workflow/decorators/workflow.ts +54 -0
- package/src/env/workflow/engine/dag-manager.test.ts +570 -0
- package/src/env/workflow/engine/dag-manager.ts +594 -0
- package/src/env/workflow/engine/engine.ts +1422 -0
- package/src/env/workflow/engine/event-bus.test.ts +359 -0
- package/src/env/workflow/engine/event-bus.ts +156 -0
- package/src/env/workflow/engine/executor-agent-session.test.ts +84 -0
- package/src/env/workflow/engine/executor.test.ts +619 -0
- package/src/env/workflow/engine/executor.ts +593 -0
- package/src/env/workflow/engine/index.ts +24 -0
- package/src/env/workflow/engine/node-registry.test.ts +560 -0
- package/src/env/workflow/engine/node-registry.ts +289 -0
- package/src/env/workflow/engine/resume-removed.test.ts +22 -0
- package/src/env/workflow/engine/scheduler.test.ts +715 -0
- package/src/env/workflow/engine/scheduler.ts +318 -0
- package/src/env/workflow/engine/workflow-engine.test.ts +815 -0
- package/src/env/workflow/extractor/workflow-converter.ts +306 -0
- package/src/env/workflow/fixtures.ts +380 -0
- package/src/env/workflow/index.ts +38 -0
- package/src/env/workflow/integration/run-resume-unified.test.ts +186 -0
- package/src/env/workflow/integration/service-integration.test.ts +267 -0
- package/src/env/workflow/metadata/keys.ts +12 -0
- package/src/env/workflow/nodes/agent-component-adapter.test.ts +318 -0
- package/src/env/workflow/nodes/agent-component-adapter.ts +448 -0
- package/src/env/workflow/nodes/agent-node.test.ts +371 -0
- package/src/env/workflow/nodes/agent-node.ts +598 -0
- package/src/env/workflow/nodes/ask-user-node.ts +113 -0
- package/src/env/workflow/nodes/condition-node.ts +200 -0
- package/src/env/workflow/nodes/index.ts +9 -0
- package/src/env/workflow/nodes/merge-node.ts +141 -0
- package/src/env/workflow/nodes/skill-node.test.ts +253 -0
- package/src/env/workflow/nodes/skill-node.ts +393 -0
- package/src/env/workflow/nodes/tool-node.test.ts +251 -0
- package/src/env/workflow/nodes/tool-node.ts +493 -0
- package/src/env/workflow/nodes/workflow-llm-history.test.ts +455 -0
- package/src/env/workflow/nodes/workflow-node.test.ts +315 -0
- package/src/env/workflow/nodes/workflow-node.ts +311 -0
- package/src/env/workflow/service/index.ts +27 -0
- package/src/env/workflow/service/registry.test.ts +133 -0
- package/src/env/workflow/service/registry.ts +71 -0
- package/src/env/workflow/service/workflow-service.test.ts +310 -0
- package/src/env/workflow/service/workflow-service.ts +393 -0
- package/src/env/workflow/storage/index.ts +28 -0
- package/src/env/workflow/storage/mock-repositories.ts +385 -0
- package/src/env/workflow/storage/sqlite.test.ts +179 -0
- package/src/env/workflow/storage/sqlite.ts +163 -0
- package/src/env/workflow/storage/workflow-repo.test.ts +780 -0
- package/src/env/workflow/storage/workflow-repo.ts +342 -0
- package/src/env/workflow/tools/ask-user-tool.ts +82 -0
- package/src/env/workflow/tools/index.ts +26 -0
- package/src/env/workflow/tools/run-workflow.test.ts +352 -0
- package/src/env/workflow/tools/run-workflow.ts +214 -0
- package/src/env/workflow/types/context.ts +18 -0
- package/src/env/workflow/types/decorators-types.ts +198 -0
- package/src/env/workflow/types/event.test.ts +515 -0
- package/src/env/workflow/types/event.ts +193 -0
- package/src/env/workflow/types/index.ts +49 -0
- package/src/env/workflow/types/run.test.ts +437 -0
- package/src/env/workflow/types/run.ts +173 -0
- package/src/env/workflow/types/workflow-hil.ts +114 -0
- package/src/env/workflow/types/workflow-message.test.ts +138 -0
- package/src/env/workflow/types/workflow-message.ts +196 -0
- package/src/env/workflow/types/workflow-session.test.ts +95 -0
- package/src/env/workflow/types/workflow-session.ts +59 -0
- package/src/env/workflow/types/workflow.test.ts +495 -0
- package/src/env/workflow/types/workflow.ts +195 -0
- package/src/env/workflow/types_compat.ts +51 -0
- package/src/env/workflow/utils/create-workflow.ts +47 -0
- package/src/env/workflow/utils/execution-state.ts +245 -0
- package/src/env/workflow/utils/index.ts +18 -0
- package/src/env/workflow/utils/node-registry-helper.ts +58 -0
- package/src/env/workflow/utils/recovery-validator.test.ts +460 -0
- package/src/env/workflow/utils/recovery-validator.ts +377 -0
- package/src/env/workflow/utils/session-parser.test.ts +111 -0
- package/src/env/workflow/utils/session-parser.ts +94 -0
- package/src/env/workflow/utils/session-recovery.test.ts +334 -0
- package/src/env/workflow/utils/session-recovery.ts +188 -0
- package/src/env/workflow/utils/template-resolver.test.ts +258 -0
- package/src/env/workflow/utils/template-resolver.ts +436 -0
- package/src/env/workflow/utils/validation-rules.ts +149 -0
- package/src/env/workflow/workflow-component.ts +544 -0
- package/src/index.ts +422 -0
- package/src/utils/id.ts +21 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// ==================== 基础事件 ====================
|
|
4
|
+
|
|
5
|
+
export const BaseEventSchema = z.object({
|
|
6
|
+
type: z.string(),
|
|
7
|
+
run_id: z.string(),
|
|
8
|
+
timestamp: z.number(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export type BaseEvent = z.infer<typeof BaseEventSchema>;
|
|
12
|
+
|
|
13
|
+
// ==================== Workflow 生命周期事件 ====================
|
|
14
|
+
|
|
15
|
+
export const WorkflowStartedEventSchema = BaseEventSchema.extend({
|
|
16
|
+
type: z.literal('workflow.started'),
|
|
17
|
+
workflow_name: z.string(),
|
|
18
|
+
input: z.record(z.string(), z.unknown()).optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const WorkflowPausedEventSchema = BaseEventSchema.extend({
|
|
22
|
+
type: z.literal('workflow.paused'),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const WorkflowResumedEventSchema = BaseEventSchema.extend({
|
|
26
|
+
type: z.literal('workflow.resumed'),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const WorkflowStoppedEventSchema = BaseEventSchema.extend({
|
|
30
|
+
type: z.literal('workflow.stopped'),
|
|
31
|
+
reason: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const WorkflowCompletedEventSchema = BaseEventSchema.extend({
|
|
35
|
+
type: z.literal('workflow.completed'),
|
|
36
|
+
result: z.record(z.string(), z.unknown()).optional(),
|
|
37
|
+
duration_ms: z.number(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const WorkflowFailedEventSchema = BaseEventSchema.extend({
|
|
41
|
+
type: z.literal('workflow.failed'),
|
|
42
|
+
error: z.object({
|
|
43
|
+
message: z.string(),
|
|
44
|
+
stack: z.string().optional(),
|
|
45
|
+
}),
|
|
46
|
+
failed_at: z.string(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const WorkflowOutputEventSchema = BaseEventSchema.extend({
|
|
50
|
+
type: z.literal('workflow.output'),
|
|
51
|
+
output: z.record(z.string(), z.unknown()),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// ==================== Node 生命周期事件 ====================
|
|
55
|
+
|
|
56
|
+
export const NodeScheduledEventSchema = BaseEventSchema.extend({
|
|
57
|
+
type: z.literal('node.scheduled'),
|
|
58
|
+
node_id: z.string(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const NodeStartedEventSchema = BaseEventSchema.extend({
|
|
62
|
+
type: z.literal('node.started'),
|
|
63
|
+
node_id: z.string(),
|
|
64
|
+
input: z.any(),
|
|
65
|
+
agentSessionId: z.string().optional(),
|
|
66
|
+
userResponse: z.string().optional(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const NodeProgressEventSchema = BaseEventSchema.extend({
|
|
70
|
+
type: z.literal('node.progress'),
|
|
71
|
+
node_id: z.string(),
|
|
72
|
+
progress: z.number(),
|
|
73
|
+
message: z.string().optional(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const NodeCompletedEventSchema = BaseEventSchema.extend({
|
|
77
|
+
type: z.literal('node.completed'),
|
|
78
|
+
node_id: z.string(),
|
|
79
|
+
output: z.any(),
|
|
80
|
+
duration_ms: z.number(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export const NodeFailedEventSchema = BaseEventSchema.extend({
|
|
84
|
+
type: z.literal('node.failed'),
|
|
85
|
+
node_id: z.string(),
|
|
86
|
+
error: z.object({
|
|
87
|
+
message: z.string(),
|
|
88
|
+
stack: z.string().optional(),
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const NodeSkippedEventSchema = BaseEventSchema.extend({
|
|
93
|
+
type: z.literal('node.skipped'),
|
|
94
|
+
node_id: z.string(),
|
|
95
|
+
reason: z.string(),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// ==================== 节点间数据流事件 ====================
|
|
99
|
+
|
|
100
|
+
export const NodeDataEventSchema = BaseEventSchema.extend({
|
|
101
|
+
type: z.literal('node.data'),
|
|
102
|
+
from_node: z.string(),
|
|
103
|
+
to_node: z.string(),
|
|
104
|
+
data: z.any(),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// ==================== 动态节点事件 ====================
|
|
108
|
+
|
|
109
|
+
export const NodeAddedEventSchema = BaseEventSchema.extend({
|
|
110
|
+
type: z.literal('node.added'),
|
|
111
|
+
node_id: z.string(),
|
|
112
|
+
node: z.any(),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export const NodeRemovedEventSchema = BaseEventSchema.extend({
|
|
116
|
+
type: z.literal('node.removed'),
|
|
117
|
+
node_id: z.string(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// ==================== 控制事件 ====================
|
|
121
|
+
|
|
122
|
+
export const ControlPauseEventSchema = BaseEventSchema.extend({
|
|
123
|
+
type: z.literal('control.pause'),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
export const ControlResumeEventSchema = BaseEventSchema.extend({
|
|
127
|
+
type: z.literal('control.resume'),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const ControlStopEventSchema = BaseEventSchema.extend({
|
|
131
|
+
type: z.literal('control.stop'),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ==================== 人工交互事件 (Schemas only) ====================
|
|
135
|
+
|
|
136
|
+
export const NodeInterruptEventSchema = BaseEventSchema.extend({
|
|
137
|
+
type: z.literal('node.interrupt'),
|
|
138
|
+
node_id: z.string(),
|
|
139
|
+
node_type: z.string(),
|
|
140
|
+
query: z.string(),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export const WorkflowAskUserEventSchema = BaseEventSchema.extend({
|
|
144
|
+
type: z.literal('workflow.ask-user'),
|
|
145
|
+
session_id: z.string(),
|
|
146
|
+
node_id: z.string(),
|
|
147
|
+
node_type: z.string(),
|
|
148
|
+
query: z.string(),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ==================== 联合事件类型 ====================
|
|
152
|
+
|
|
153
|
+
export const WorkflowEventSchema = z.union([
|
|
154
|
+
WorkflowStartedEventSchema,
|
|
155
|
+
WorkflowPausedEventSchema,
|
|
156
|
+
WorkflowResumedEventSchema,
|
|
157
|
+
WorkflowStoppedEventSchema,
|
|
158
|
+
WorkflowCompletedEventSchema,
|
|
159
|
+
WorkflowFailedEventSchema,
|
|
160
|
+
WorkflowOutputEventSchema,
|
|
161
|
+
NodeScheduledEventSchema,
|
|
162
|
+
NodeStartedEventSchema,
|
|
163
|
+
NodeProgressEventSchema,
|
|
164
|
+
NodeCompletedEventSchema,
|
|
165
|
+
NodeFailedEventSchema,
|
|
166
|
+
NodeSkippedEventSchema,
|
|
167
|
+
NodeDataEventSchema,
|
|
168
|
+
NodeAddedEventSchema,
|
|
169
|
+
NodeRemovedEventSchema,
|
|
170
|
+
ControlPauseEventSchema,
|
|
171
|
+
ControlResumeEventSchema,
|
|
172
|
+
ControlStopEventSchema,
|
|
173
|
+
NodeInterruptEventSchema,
|
|
174
|
+
WorkflowAskUserEventSchema,
|
|
175
|
+
]);
|
|
176
|
+
|
|
177
|
+
export type WorkflowEvent = z.infer<typeof WorkflowEventSchema>;
|
|
178
|
+
|
|
179
|
+
// ==================== Event 工厂函数 ====================
|
|
180
|
+
|
|
181
|
+
export function createWorkflowEvent<T extends WorkflowEvent['type']>(
|
|
182
|
+
type: T,
|
|
183
|
+
runId: string,
|
|
184
|
+
data: Omit<Extract<WorkflowEvent, { type: T }>, 'type' | 'run_id' | 'timestamp'>
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
186
|
+
): any {
|
|
187
|
+
return {
|
|
188
|
+
type,
|
|
189
|
+
run_id: runId,
|
|
190
|
+
timestamp: Date.now(),
|
|
191
|
+
...data,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Re-export all types
|
|
2
|
+
export * from './workflow';
|
|
3
|
+
export * from './workflow-message';
|
|
4
|
+
export * from './workflow-session';
|
|
5
|
+
export * from './context';
|
|
6
|
+
export * from './workflow-hil';
|
|
7
|
+
export * from './event';
|
|
8
|
+
export * from './run';
|
|
9
|
+
|
|
10
|
+
// Export AgentSessionInfo
|
|
11
|
+
export type { AgentSessionInfo } from './workflow-message';
|
|
12
|
+
|
|
13
|
+
// Export AgentSessionRef from workflow-session (avoid duplicate with workflow-message)
|
|
14
|
+
export type { AgentSessionRef } from './workflow-session';
|
|
15
|
+
|
|
16
|
+
// Re-export from run.ts for convenience (includes NodeExecutionContext, NodeExecutionResult)
|
|
17
|
+
export type {
|
|
18
|
+
RunStatus,
|
|
19
|
+
NodeStatus,
|
|
20
|
+
WorkflowRun,
|
|
21
|
+
NodeRun,
|
|
22
|
+
RunOptions,
|
|
23
|
+
RunResult,
|
|
24
|
+
NodeExecutionContext,
|
|
25
|
+
NodeExecutionResult,
|
|
26
|
+
} from './run';
|
|
27
|
+
|
|
28
|
+
export { createNodeExecutionContext } from './run';
|
|
29
|
+
|
|
30
|
+
// Re-export from workflow.ts for convenience (includes Node, RetryConfig, TemplateResolver)
|
|
31
|
+
export type {
|
|
32
|
+
WorkflowDefinition,
|
|
33
|
+
WorkflowDefinitionExtended,
|
|
34
|
+
Workflow,
|
|
35
|
+
WorkflowConfig,
|
|
36
|
+
WorkflowMetadata,
|
|
37
|
+
RetryConfig,
|
|
38
|
+
Node,
|
|
39
|
+
NodeDefinition,
|
|
40
|
+
NodeDefinitionSchema,
|
|
41
|
+
DependsOn,
|
|
42
|
+
DependsOnSchema,
|
|
43
|
+
OutputDefinition,
|
|
44
|
+
OutputDefinitionSchema,
|
|
45
|
+
} from './workflow';
|
|
46
|
+
|
|
47
|
+
// Re-export Node and TemplateResolver from their actual locations
|
|
48
|
+
// Note: Node type should be imported from '../nodes' directly
|
|
49
|
+
export type { TemplateResolver } from '../utils/template-resolver';
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
describe('Run Types', () => {
|
|
5
|
+
describe('RunStatus', () => {
|
|
6
|
+
it('should accept all valid run statuses', () => {
|
|
7
|
+
const validStatuses = ['idle', 'running', 'paused', 'stopped', 'completed', 'failed'];
|
|
8
|
+
const schema = z.enum(['idle', 'running', 'paused', 'stopped', 'completed', 'failed']);
|
|
9
|
+
|
|
10
|
+
for (const status of validStatuses) {
|
|
11
|
+
expect(() => schema.parse(status)).not.toThrow();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should reject invalid run status', () => {
|
|
16
|
+
const schema = z.enum(['idle', 'running', 'paused', 'stopped', 'completed', 'failed']);
|
|
17
|
+
expect(() => schema.parse('invalid')).toThrow();
|
|
18
|
+
expect(() => schema.parse('pending')).toThrow();
|
|
19
|
+
expect(() => schema.parse('')).toThrow();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('NodeStatus', () => {
|
|
24
|
+
it('should accept all valid node statuses', () => {
|
|
25
|
+
const validStatuses = ['pending', 'scheduled', 'started', 'running', 'completed', 'failed', 'skipped'];
|
|
26
|
+
const schema = z.enum(['pending', 'scheduled', 'started', 'running', 'completed', 'failed', 'skipped']);
|
|
27
|
+
|
|
28
|
+
for (const status of validStatuses) {
|
|
29
|
+
expect(() => schema.parse(status)).not.toThrow();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should reject invalid node status', () => {
|
|
34
|
+
const schema = z.enum(['pending', 'scheduled', 'started', 'running', 'completed', 'failed', 'skipped']);
|
|
35
|
+
expect(() => schema.parse('invalid')).toThrow();
|
|
36
|
+
expect(() => schema.parse('idle')).toThrow();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('WorkflowRun', () => {
|
|
41
|
+
it('should accept minimal workflow run', () => {
|
|
42
|
+
const run = {
|
|
43
|
+
id: 'run_123',
|
|
44
|
+
workflowId: 'wf_456',
|
|
45
|
+
workflowName: 'test-workflow',
|
|
46
|
+
status: 'idle',
|
|
47
|
+
debugMode: false,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
expect(run.id).toBe('run_123');
|
|
51
|
+
expect(run.workflowId).toBe('wf_456');
|
|
52
|
+
expect(run.status).toBe('idle');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should accept full workflow run', () => {
|
|
56
|
+
const run = {
|
|
57
|
+
id: 'run_123',
|
|
58
|
+
workflowId: 'wf_456',
|
|
59
|
+
workflowName: 'test-workflow',
|
|
60
|
+
status: 'completed',
|
|
61
|
+
input: { param1: 'value1' },
|
|
62
|
+
output: { result: 'success' },
|
|
63
|
+
error: undefined,
|
|
64
|
+
startedAt: new Date('2024-01-01T10:00:00Z'),
|
|
65
|
+
completedAt: new Date('2024-01-01T10:05:00Z'),
|
|
66
|
+
durationMs: 300000,
|
|
67
|
+
debugMode: true,
|
|
68
|
+
parentRunId: 'run_000',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
expect(run.id).toBe('run_123');
|
|
72
|
+
expect(run.status).toBe('completed');
|
|
73
|
+
expect(run.input).toEqual({ param1: 'value1' });
|
|
74
|
+
expect(run.output).toEqual({ result: 'success' });
|
|
75
|
+
expect(run.startedAt).toBeInstanceOf(Date);
|
|
76
|
+
expect(run.durationMs).toBe(300000);
|
|
77
|
+
expect(run.debugMode).toBe(true);
|
|
78
|
+
expect(run.parentRunId).toBe('run_000');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should accept running state workflow run', () => {
|
|
82
|
+
const run = {
|
|
83
|
+
id: 'run_123',
|
|
84
|
+
workflowId: 'wf_456',
|
|
85
|
+
workflowName: 'test-workflow',
|
|
86
|
+
status: 'running',
|
|
87
|
+
startedAt: new Date(),
|
|
88
|
+
debugMode: false,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
expect(run.status).toBe('running');
|
|
92
|
+
expect(run.startedAt).toBeInstanceOf(Date);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should accept paused state workflow run', () => {
|
|
96
|
+
const run = {
|
|
97
|
+
id: 'run_123',
|
|
98
|
+
workflowId: 'wf_456',
|
|
99
|
+
workflowName: 'test-workflow',
|
|
100
|
+
status: 'paused',
|
|
101
|
+
startedAt: new Date(),
|
|
102
|
+
pausedAt: new Date(),
|
|
103
|
+
debugMode: false,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
expect(run.status).toBe('paused');
|
|
107
|
+
expect(run.pausedAt).toBeInstanceOf(Date);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should accept failed state workflow run', () => {
|
|
111
|
+
const run = {
|
|
112
|
+
id: 'run_123',
|
|
113
|
+
workflowId: 'wf_456',
|
|
114
|
+
workflowName: 'test-workflow',
|
|
115
|
+
status: 'failed',
|
|
116
|
+
error: 'Node execution failed: tool not found',
|
|
117
|
+
startedAt: new Date(),
|
|
118
|
+
completedAt: new Date(),
|
|
119
|
+
durationMs: 5000,
|
|
120
|
+
debugMode: false,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
expect(run.status).toBe('failed');
|
|
124
|
+
expect(run.error).toBe('Node execution failed: tool not found');
|
|
125
|
+
expect(run.durationMs).toBe(5000);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('NodeRun', () => {
|
|
130
|
+
it('should accept minimal node run', () => {
|
|
131
|
+
const nodeRun = {
|
|
132
|
+
id: 'nr_123',
|
|
133
|
+
runId: 'run_456',
|
|
134
|
+
nodeId: 'node1',
|
|
135
|
+
nodeType: 'tool',
|
|
136
|
+
status: 'pending',
|
|
137
|
+
retryCount: 0,
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
expect(nodeRun.id).toBe('nr_123');
|
|
141
|
+
expect(nodeRun.nodeId).toBe('node1');
|
|
142
|
+
expect(nodeRun.status).toBe('pending');
|
|
143
|
+
expect(nodeRun.retryCount).toBe(0);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should accept full node run', () => {
|
|
147
|
+
const nodeRun = {
|
|
148
|
+
id: 'nr_123',
|
|
149
|
+
runId: 'run_456',
|
|
150
|
+
nodeId: 'node1',
|
|
151
|
+
nodeType: 'tool',
|
|
152
|
+
status: 'completed',
|
|
153
|
+
input: { operation: 'add', a: 1, b: 2 },
|
|
154
|
+
output: { result: 3 },
|
|
155
|
+
error: undefined,
|
|
156
|
+
startedAt: new Date('2024-01-01T10:00:00Z'),
|
|
157
|
+
completedAt: new Date('2024-01-01T10:00:01Z'),
|
|
158
|
+
durationMs: 1000,
|
|
159
|
+
retryCount: 0,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
expect(nodeRun.status).toBe('completed');
|
|
163
|
+
expect(nodeRun.input).toEqual({ operation: 'add', a: 1, b: 2 });
|
|
164
|
+
expect(nodeRun.output).toEqual({ result: 3 });
|
|
165
|
+
expect(nodeRun.durationMs).toBe(1000);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should accept failed node run with error', () => {
|
|
169
|
+
const nodeRun = {
|
|
170
|
+
id: 'nr_123',
|
|
171
|
+
runId: 'run_456',
|
|
172
|
+
nodeId: 'node1',
|
|
173
|
+
nodeType: 'tool',
|
|
174
|
+
status: 'failed',
|
|
175
|
+
input: { tool: 'nonexistent' },
|
|
176
|
+
error: 'Tool not found: nonexistent',
|
|
177
|
+
startedAt: new Date(),
|
|
178
|
+
completedAt: new Date(),
|
|
179
|
+
durationMs: 100,
|
|
180
|
+
retryCount: 3,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
expect(nodeRun.status).toBe('failed');
|
|
184
|
+
expect(nodeRun.error).toBe('Tool not found: nonexistent');
|
|
185
|
+
expect(nodeRun.retryCount).toBe(3);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should accept running node run', () => {
|
|
189
|
+
const nodeRun = {
|
|
190
|
+
id: 'nr_123',
|
|
191
|
+
runId: 'run_456',
|
|
192
|
+
nodeId: 'node1',
|
|
193
|
+
nodeType: 'agent',
|
|
194
|
+
status: 'running',
|
|
195
|
+
input: { prompt: 'Do something' },
|
|
196
|
+
startedAt: new Date(),
|
|
197
|
+
retryCount: 0,
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
expect(nodeRun.status).toBe('running');
|
|
201
|
+
expect(nodeRun.startedAt).toBeInstanceOf(Date);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should accept skipped node run', () => {
|
|
205
|
+
const nodeRun = {
|
|
206
|
+
id: 'nr_123',
|
|
207
|
+
runId: 'run_456',
|
|
208
|
+
nodeId: 'node1',
|
|
209
|
+
nodeType: 'tool',
|
|
210
|
+
status: 'skipped',
|
|
211
|
+
reason: 'Previous dependency failed',
|
|
212
|
+
retryCount: 0,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
expect(nodeRun.status).toBe('skipped');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should accept scheduled node run', () => {
|
|
219
|
+
const nodeRun = {
|
|
220
|
+
id: 'nr_123',
|
|
221
|
+
runId: 'run_456',
|
|
222
|
+
nodeId: 'node1',
|
|
223
|
+
nodeType: 'tool',
|
|
224
|
+
status: 'scheduled',
|
|
225
|
+
retryCount: 0,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
expect(nodeRun.status).toBe('scheduled');
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('RunOptions', () => {
|
|
233
|
+
it('should accept minimal run options', () => {
|
|
234
|
+
const options = {};
|
|
235
|
+
expect(options).toEqual({});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should accept full run options', () => {
|
|
239
|
+
const options = {
|
|
240
|
+
input: { key: 'value' },
|
|
241
|
+
sync: true,
|
|
242
|
+
debug: true,
|
|
243
|
+
parallelLimit: 5,
|
|
244
|
+
timeout: 300000,
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
expect(options.input).toEqual({ key: 'value' });
|
|
248
|
+
expect(options.sync).toBe(true);
|
|
249
|
+
expect(options.debug).toBe(true);
|
|
250
|
+
expect(options.parallelLimit).toBe(5);
|
|
251
|
+
expect(options.timeout).toBe(300000);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it('should accept null parallelLimit for unlimited', () => {
|
|
255
|
+
const options = {
|
|
256
|
+
parallelLimit: null,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
expect(options.parallelLimit).toBeNull();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should accept null timeout for no timeout', () => {
|
|
263
|
+
const options = {
|
|
264
|
+
timeout: null,
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
expect(options.timeout).toBeNull();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should accept undefined input', () => {
|
|
271
|
+
const options = {
|
|
272
|
+
input: undefined,
|
|
273
|
+
sync: false,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
expect(options.input).toBeUndefined();
|
|
277
|
+
expect(options.sync).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('RunResult', () => {
|
|
282
|
+
it('should accept successful run result', () => {
|
|
283
|
+
const result = {
|
|
284
|
+
runId: 'run_123',
|
|
285
|
+
status: 'completed' as const,
|
|
286
|
+
output: { result: 'success' },
|
|
287
|
+
durationMs: 5000,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
expect(result.runId).toBe('run_123');
|
|
291
|
+
expect(result.status).toBe('completed');
|
|
292
|
+
expect(result.output).toEqual({ result: 'success' });
|
|
293
|
+
expect(result.durationMs).toBe(5000);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should accept failed run result', () => {
|
|
297
|
+
const result = {
|
|
298
|
+
runId: 'run_123',
|
|
299
|
+
status: 'failed' as const,
|
|
300
|
+
error: 'Workflow execution failed',
|
|
301
|
+
durationMs: 5000,
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
expect(result.status).toBe('failed');
|
|
305
|
+
expect(result.error).toBe('Workflow execution failed');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('should accept running run result', () => {
|
|
309
|
+
const result = {
|
|
310
|
+
runId: 'run_123',
|
|
311
|
+
status: 'running' as const,
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
expect(result.status).toBe('running');
|
|
315
|
+
expect(result.output).toBeUndefined();
|
|
316
|
+
expect(result.error).toBeUndefined();
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe('NodeExecutionContext', () => {
|
|
321
|
+
it('should accept valid execution context', () => {
|
|
322
|
+
const context = {
|
|
323
|
+
runId: 'run_123',
|
|
324
|
+
workflowName: 'test-workflow',
|
|
325
|
+
nodeId: 'node1',
|
|
326
|
+
input: { param: 'value' },
|
|
327
|
+
previousOutputs: new Map([['prev_node', { result: 42 }]]),
|
|
328
|
+
config: { tool: 'calculator' },
|
|
329
|
+
debug: false,
|
|
330
|
+
eventBus: {
|
|
331
|
+
publish: () => {},
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
expect(context.runId).toBe('run_123');
|
|
336
|
+
expect(context.nodeId).toBe('node1');
|
|
337
|
+
expect(context.previousOutputs).toBeInstanceOf(Map);
|
|
338
|
+
expect(context.config).toEqual({ tool: 'calculator' });
|
|
339
|
+
expect(context.debug).toBe(false);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('should accept empty previousOutputs', () => {
|
|
343
|
+
const context = {
|
|
344
|
+
runId: 'run_123',
|
|
345
|
+
workflowName: 'test-workflow',
|
|
346
|
+
nodeId: 'node1',
|
|
347
|
+
input: {},
|
|
348
|
+
previousOutputs: new Map(),
|
|
349
|
+
config: {},
|
|
350
|
+
debug: false,
|
|
351
|
+
eventBus: {},
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
expect(context.previousOutputs.size).toBe(0);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('should accept context with multiple previous outputs', () => {
|
|
358
|
+
const context = {
|
|
359
|
+
runId: 'run_123',
|
|
360
|
+
workflowName: 'test-workflow',
|
|
361
|
+
nodeId: 'node3',
|
|
362
|
+
input: {},
|
|
363
|
+
previousOutputs: new Map([
|
|
364
|
+
['node1', { result: 'step1' }],
|
|
365
|
+
['node2', { result: 'step2' }],
|
|
366
|
+
]),
|
|
367
|
+
config: {},
|
|
368
|
+
debug: false,
|
|
369
|
+
eventBus: {},
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
expect(context.previousOutputs.size).toBe(2);
|
|
373
|
+
expect(context.previousOutputs.get('node1')).toEqual({ result: 'step1' });
|
|
374
|
+
expect(context.previousOutputs.get('node2')).toEqual({ result: 'step2' });
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('should accept debug mode context', () => {
|
|
378
|
+
const context = {
|
|
379
|
+
runId: 'run_123',
|
|
380
|
+
workflowName: 'test-workflow',
|
|
381
|
+
nodeId: 'node1',
|
|
382
|
+
input: {},
|
|
383
|
+
previousOutputs: new Map(),
|
|
384
|
+
config: {},
|
|
385
|
+
debug: true,
|
|
386
|
+
eventBus: {},
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
expect(context.debug).toBe(true);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe('NodeExecutionResult', () => {
|
|
394
|
+
it('should accept successful execution result', () => {
|
|
395
|
+
const result = {
|
|
396
|
+
output: { result: 'success', data: [1, 2, 3] },
|
|
397
|
+
error: undefined,
|
|
398
|
+
durationMs: 1500,
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
expect(result.output).toEqual({ result: 'success', data: [1, 2, 3] });
|
|
402
|
+
expect(result.error).toBeUndefined();
|
|
403
|
+
expect(result.durationMs).toBe(1500);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('should accept failed execution result', () => {
|
|
407
|
+
const error = new Error('Execution failed');
|
|
408
|
+
const result = {
|
|
409
|
+
output: undefined,
|
|
410
|
+
error,
|
|
411
|
+
durationMs: 500,
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
expect(result.output).toBeUndefined();
|
|
415
|
+
expect(result.error).toBe(error);
|
|
416
|
+
expect(result.error.message).toBe('Execution failed');
|
|
417
|
+
expect(result.durationMs).toBe(500);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('should accept result with complex output', () => {
|
|
421
|
+
const result = {
|
|
422
|
+
output: {
|
|
423
|
+
files: [
|
|
424
|
+
{ name: 'file1.txt', size: 1024 },
|
|
425
|
+
{ name: 'file2.txt', size: 2048 },
|
|
426
|
+
],
|
|
427
|
+
summary: { total: 2, totalSize: 3072 },
|
|
428
|
+
},
|
|
429
|
+
error: undefined,
|
|
430
|
+
durationMs: 3000,
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
expect(result.output.files).toHaveLength(2);
|
|
434
|
+
expect(result.output.summary.total).toBe(2);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|