@synergenius/flow-weaver 0.2.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/LICENSE +122 -0
- package/README.md +315 -0
- package/dist/annotation-generator.d.ts +45 -0
- package/dist/annotation-generator.js +557 -0
- package/dist/api/builder.d.ts +223 -0
- package/dist/api/builder.js +345 -0
- package/dist/api/compile.d.ts +92 -0
- package/dist/api/compile.js +149 -0
- package/dist/api/extract-types.d.ts +29 -0
- package/dist/api/extract-types.js +57 -0
- package/dist/api/generate-in-place.d.ts +73 -0
- package/dist/api/generate-in-place.js +1353 -0
- package/dist/api/generate.d.ts +83 -0
- package/dist/api/generate.js +510 -0
- package/dist/api/helpers.d.ts +248 -0
- package/dist/api/helpers.js +285 -0
- package/dist/api/index.d.ts +46 -0
- package/dist/api/index.js +45 -0
- package/dist/api/inline-runtime.d.ts +27 -0
- package/dist/api/inline-runtime.js +551 -0
- package/dist/api/manipulation/connections.d.ts +79 -0
- package/dist/api/manipulation/connections.js +151 -0
- package/dist/api/manipulation/index.d.ts +34 -0
- package/dist/api/manipulation/index.js +41 -0
- package/dist/api/manipulation/node-types.d.ts +123 -0
- package/dist/api/manipulation/node-types.js +200 -0
- package/dist/api/manipulation/nodes.d.ts +144 -0
- package/dist/api/manipulation/nodes.js +333 -0
- package/dist/api/manipulation/ports.d.ts +59 -0
- package/dist/api/manipulation/ports.js +228 -0
- package/dist/api/manipulation/scopes.d.ts +52 -0
- package/dist/api/manipulation/scopes.js +156 -0
- package/dist/api/manipulation/validation.d.ts +6 -0
- package/dist/api/manipulation/validation.js +6 -0
- package/dist/api/manipulation/workflow.d.ts +81 -0
- package/dist/api/manipulation/workflow.js +116 -0
- package/dist/api/manipulation.d.ts +8 -0
- package/dist/api/manipulation.js +8 -0
- package/dist/api/parse.d.ts +48 -0
- package/dist/api/parse.js +110 -0
- package/dist/api/patterns.d.ts +112 -0
- package/dist/api/patterns.js +306 -0
- package/dist/api/query.d.ts +429 -0
- package/dist/api/query.js +816 -0
- package/dist/api/templates.d.ts +98 -0
- package/dist/api/templates.js +117 -0
- package/dist/api/transform.d.ts +31 -0
- package/dist/api/transform.js +40 -0
- package/dist/api/validate.d.ts +25 -0
- package/dist/api/validate.js +39 -0
- package/dist/api/workflow-file-operations.d.ts +29 -0
- package/dist/api/workflow-file-operations.js +180 -0
- package/dist/ast/builder.d.ts +210 -0
- package/dist/ast/builder.js +395 -0
- package/dist/ast/index.d.ts +5 -0
- package/dist/ast/index.js +5 -0
- package/dist/ast/serialization-node.d.ts +6 -0
- package/dist/ast/serialization-node.js +30 -0
- package/dist/ast/serialization.d.ts +43 -0
- package/dist/ast/serialization.js +134 -0
- package/dist/ast/types.d.ts +852 -0
- package/dist/ast/types.js +2 -0
- package/dist/ast/workflow-utils.d.ts +54 -0
- package/dist/ast/workflow-utils.js +114 -0
- package/dist/body-generator.d.ts +31 -0
- package/dist/body-generator.js +35 -0
- package/dist/built-in-nodes/delay.d.ts +11 -0
- package/dist/built-in-nodes/delay.js +29 -0
- package/dist/built-in-nodes/index.d.ts +5 -0
- package/dist/built-in-nodes/index.js +4 -0
- package/dist/built-in-nodes/invoke-workflow.d.ts +13 -0
- package/dist/built-in-nodes/invoke-workflow.js +25 -0
- package/dist/built-in-nodes/mock-types.d.ts +18 -0
- package/dist/built-in-nodes/mock-types.js +12 -0
- package/dist/built-in-nodes/wait-for-event.d.ts +13 -0
- package/dist/built-in-nodes/wait-for-event.js +25 -0
- package/dist/chevrotain-parser/connect-parser.d.ts +24 -0
- package/dist/chevrotain-parser/connect-parser.js +98 -0
- package/dist/chevrotain-parser/grammar-diagrams.d.ts +29 -0
- package/dist/chevrotain-parser/grammar-diagrams.js +264 -0
- package/dist/chevrotain-parser/index.d.ts +25 -0
- package/dist/chevrotain-parser/index.js +27 -0
- package/dist/chevrotain-parser/map-parser.d.ts +33 -0
- package/dist/chevrotain-parser/map-parser.js +130 -0
- package/dist/chevrotain-parser/node-parser.d.ts +36 -0
- package/dist/chevrotain-parser/node-parser.js +466 -0
- package/dist/chevrotain-parser/path-parser.d.ts +28 -0
- package/dist/chevrotain-parser/path-parser.js +118 -0
- package/dist/chevrotain-parser/port-parser.d.ts +36 -0
- package/dist/chevrotain-parser/port-parser.js +442 -0
- package/dist/chevrotain-parser/position-parser.d.ts +20 -0
- package/dist/chevrotain-parser/position-parser.js +83 -0
- package/dist/chevrotain-parser/scope-parser.d.ts +19 -0
- package/dist/chevrotain-parser/scope-parser.js +104 -0
- package/dist/chevrotain-parser/tokens.d.ts +78 -0
- package/dist/chevrotain-parser/tokens.js +384 -0
- package/dist/chevrotain-parser/trigger-cancel-parser.d.ts +50 -0
- package/dist/chevrotain-parser/trigger-cancel-parser.js +282 -0
- package/dist/cli/commands/changelog.d.ts +13 -0
- package/dist/cli/commands/changelog.js +135 -0
- package/dist/cli/commands/compile.d.ts +64 -0
- package/dist/cli/commands/compile.js +278 -0
- package/dist/cli/commands/create.d.ts +33 -0
- package/dist/cli/commands/create.js +147 -0
- package/dist/cli/commands/describe.d.ts +68 -0
- package/dist/cli/commands/describe.js +377 -0
- package/dist/cli/commands/dev.d.ts +32 -0
- package/dist/cli/commands/dev.js +384 -0
- package/dist/cli/commands/diagram.d.ts +13 -0
- package/dist/cli/commands/diagram.js +33 -0
- package/dist/cli/commands/diff.d.ts +11 -0
- package/dist/cli/commands/diff.js +59 -0
- package/dist/cli/commands/doctor.d.ts +57 -0
- package/dist/cli/commands/doctor.js +719 -0
- package/dist/cli/commands/export.d.ts +57 -0
- package/dist/cli/commands/export.js +163 -0
- package/dist/cli/commands/grammar.d.ts +9 -0
- package/dist/cli/commands/grammar.js +39 -0
- package/dist/cli/commands/init.d.ts +59 -0
- package/dist/cli/commands/init.js +435 -0
- package/dist/cli/commands/listen.d.ts +16 -0
- package/dist/cli/commands/listen.js +39 -0
- package/dist/cli/commands/market.d.ts +52 -0
- package/dist/cli/commands/market.js +436 -0
- package/dist/cli/commands/migrate.d.ts +13 -0
- package/dist/cli/commands/migrate.js +89 -0
- package/dist/cli/commands/openapi.d.ts +37 -0
- package/dist/cli/commands/openapi.js +67 -0
- package/dist/cli/commands/pattern.d.ts +34 -0
- package/dist/cli/commands/pattern.js +185 -0
- package/dist/cli/commands/plugin.d.ts +16 -0
- package/dist/cli/commands/plugin.js +176 -0
- package/dist/cli/commands/run.d.ts +49 -0
- package/dist/cli/commands/run.js +191 -0
- package/dist/cli/commands/serve.d.ts +45 -0
- package/dist/cli/commands/serve.js +81 -0
- package/dist/cli/commands/templates.d.ts +8 -0
- package/dist/cli/commands/templates.js +54 -0
- package/dist/cli/commands/ui.d.ts +16 -0
- package/dist/cli/commands/ui.js +130 -0
- package/dist/cli/commands/validate.d.ts +12 -0
- package/dist/cli/commands/validate.js +247 -0
- package/dist/cli/commands/watch.d.ts +9 -0
- package/dist/cli/commands/watch.js +70 -0
- package/dist/cli/flow-weaver.mjs +92924 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +742 -0
- package/dist/cli/templates/ai/mock-provider.d.ts +7 -0
- package/dist/cli/templates/ai/mock-provider.js +64 -0
- package/dist/cli/templates/ai/types.d.ts +47 -0
- package/dist/cli/templates/ai/types.js +5 -0
- package/dist/cli/templates/approvals/index.d.ts +15 -0
- package/dist/cli/templates/approvals/index.js +241 -0
- package/dist/cli/templates/index.d.ts +102 -0
- package/dist/cli/templates/index.js +101 -0
- package/dist/cli/templates/nodes/agent-router.d.ts +3 -0
- package/dist/cli/templates/nodes/agent-router.js +114 -0
- package/dist/cli/templates/nodes/aggregator.d.ts +7 -0
- package/dist/cli/templates/nodes/aggregator.js +63 -0
- package/dist/cli/templates/nodes/conversation-memory.d.ts +3 -0
- package/dist/cli/templates/nodes/conversation-memory.js +85 -0
- package/dist/cli/templates/nodes/http.d.ts +7 -0
- package/dist/cli/templates/nodes/http.js +80 -0
- package/dist/cli/templates/nodes/human-approval.d.ts +3 -0
- package/dist/cli/templates/nodes/human-approval.js +110 -0
- package/dist/cli/templates/nodes/json-extractor.d.ts +3 -0
- package/dist/cli/templates/nodes/json-extractor.js +119 -0
- package/dist/cli/templates/nodes/llm-call.d.ts +3 -0
- package/dist/cli/templates/nodes/llm-call.js +106 -0
- package/dist/cli/templates/nodes/prompt-template.d.ts +3 -0
- package/dist/cli/templates/nodes/prompt-template.js +52 -0
- package/dist/cli/templates/nodes/rag-retriever.d.ts +3 -0
- package/dist/cli/templates/nodes/rag-retriever.js +128 -0
- package/dist/cli/templates/nodes/tool-executor.d.ts +3 -0
- package/dist/cli/templates/nodes/tool-executor.js +108 -0
- package/dist/cli/templates/nodes/transformer.d.ts +7 -0
- package/dist/cli/templates/nodes/transformer.js +68 -0
- package/dist/cli/templates/nodes/validator.d.ts +7 -0
- package/dist/cli/templates/nodes/validator.js +62 -0
- package/dist/cli/templates/providers/index.d.ts +14 -0
- package/dist/cli/templates/providers/index.js +239 -0
- package/dist/cli/templates/shared/approval-types.d.ts +9 -0
- package/dist/cli/templates/shared/approval-types.js +31 -0
- package/dist/cli/templates/shared/llm-types.d.ts +15 -0
- package/dist/cli/templates/shared/llm-types.js +104 -0
- package/dist/cli/templates/workflows/aggregator.d.ts +7 -0
- package/dist/cli/templates/workflows/aggregator.js +104 -0
- package/dist/cli/templates/workflows/ai-agent-durable.d.ts +8 -0
- package/dist/cli/templates/workflows/ai-agent-durable.js +338 -0
- package/dist/cli/templates/workflows/ai-agent.d.ts +31 -0
- package/dist/cli/templates/workflows/ai-agent.js +326 -0
- package/dist/cli/templates/workflows/ai-chat.d.ts +7 -0
- package/dist/cli/templates/workflows/ai-chat.js +169 -0
- package/dist/cli/templates/workflows/ai-pipeline-durable.d.ts +8 -0
- package/dist/cli/templates/workflows/ai-pipeline-durable.js +330 -0
- package/dist/cli/templates/workflows/ai-rag.d.ts +7 -0
- package/dist/cli/templates/workflows/ai-rag.js +186 -0
- package/dist/cli/templates/workflows/ai-react.d.ts +7 -0
- package/dist/cli/templates/workflows/ai-react.js +294 -0
- package/dist/cli/templates/workflows/conditional.d.ts +12 -0
- package/dist/cli/templates/workflows/conditional.js +142 -0
- package/dist/cli/templates/workflows/error-handler.d.ts +7 -0
- package/dist/cli/templates/workflows/error-handler.js +147 -0
- package/dist/cli/templates/workflows/foreach.d.ts +7 -0
- package/dist/cli/templates/workflows/foreach.js +143 -0
- package/dist/cli/templates/workflows/sequential.d.ts +7 -0
- package/dist/cli/templates/workflows/sequential.js +198 -0
- package/dist/cli/templates/workflows/webhook.d.ts +7 -0
- package/dist/cli/templates/workflows/webhook.js +161 -0
- package/dist/cli/utils/logger.d.ts +15 -0
- package/dist/cli/utils/logger.js +46 -0
- package/dist/constants.d.ts +100 -0
- package/dist/constants.js +125 -0
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.js +3 -0
- package/dist/deployment/config/defaults.d.ts +29 -0
- package/dist/deployment/config/defaults.js +98 -0
- package/dist/deployment/config/loader.d.ts +24 -0
- package/dist/deployment/config/loader.js +236 -0
- package/dist/deployment/config/types.d.ts +117 -0
- package/dist/deployment/config/types.js +5 -0
- package/dist/deployment/core/adapters.d.ts +90 -0
- package/dist/deployment/core/adapters.js +251 -0
- package/dist/deployment/core/executor.d.ts +62 -0
- package/dist/deployment/core/executor.js +197 -0
- package/dist/deployment/core/formatters.d.ts +57 -0
- package/dist/deployment/core/formatters.js +170 -0
- package/dist/deployment/index.d.ts +31 -0
- package/dist/deployment/index.js +48 -0
- package/dist/deployment/openapi/generator.d.ts +146 -0
- package/dist/deployment/openapi/generator.js +347 -0
- package/dist/deployment/openapi/schema-converter.d.ts +49 -0
- package/dist/deployment/openapi/schema-converter.js +192 -0
- package/dist/deployment/targets/base.d.ts +316 -0
- package/dist/deployment/targets/base.js +823 -0
- package/dist/deployment/targets/cloudflare.d.ts +23 -0
- package/dist/deployment/targets/cloudflare.js +1125 -0
- package/dist/deployment/targets/inngest.d.ts +38 -0
- package/dist/deployment/targets/inngest.js +926 -0
- package/dist/deployment/targets/lambda.d.ts +23 -0
- package/dist/deployment/targets/lambda.js +1289 -0
- package/dist/deployment/targets/vercel.d.ts +23 -0
- package/dist/deployment/targets/vercel.js +886 -0
- package/dist/deployment/types.d.ts +183 -0
- package/dist/deployment/types.js +8 -0
- package/dist/diagram/geometry.d.ts +26 -0
- package/dist/diagram/geometry.js +850 -0
- package/dist/diagram/index.d.ts +16 -0
- package/dist/diagram/index.js +42 -0
- package/dist/diagram/layout.d.ts +11 -0
- package/dist/diagram/layout.js +143 -0
- package/dist/diagram/orthogonal-router.d.ts +79 -0
- package/dist/diagram/orthogonal-router.js +568 -0
- package/dist/diagram/renderer.d.ts +3 -0
- package/dist/diagram/renderer.js +207 -0
- package/dist/diagram/theme.d.ts +20 -0
- package/dist/diagram/theme.js +189 -0
- package/dist/diagram/types.d.ts +70 -0
- package/dist/diagram/types.js +2 -0
- package/dist/diff/WorkflowDiffer.d.ts +13 -0
- package/dist/diff/WorkflowDiffer.js +429 -0
- package/dist/diff/formatDiff.d.ts +10 -0
- package/dist/diff/formatDiff.js +220 -0
- package/dist/diff/impact.d.ts +29 -0
- package/dist/diff/impact.js +119 -0
- package/dist/diff/index.d.ts +10 -0
- package/dist/diff/index.js +9 -0
- package/dist/diff/types.d.ts +138 -0
- package/dist/diff/types.js +35 -0
- package/dist/doc-metadata/extractors/annotations.d.ts +56 -0
- package/dist/doc-metadata/extractors/annotations.js +337 -0
- package/dist/doc-metadata/extractors/cli-commands.d.ts +17 -0
- package/dist/doc-metadata/extractors/cli-commands.js +355 -0
- package/dist/doc-metadata/extractors/mcp-tools.d.ts +16 -0
- package/dist/doc-metadata/extractors/mcp-tools.js +689 -0
- package/dist/doc-metadata/extractors/plugin-api.d.ts +19 -0
- package/dist/doc-metadata/extractors/plugin-api.js +279 -0
- package/dist/doc-metadata/index.d.ts +5 -0
- package/dist/doc-metadata/index.js +4 -0
- package/dist/doc-metadata/types.d.ts +120 -0
- package/dist/doc-metadata/types.js +5 -0
- package/dist/editor-completions/annotationValues.d.ts +12 -0
- package/dist/editor-completions/annotationValues.js +138 -0
- package/dist/editor-completions/contextParser.d.ts +40 -0
- package/dist/editor-completions/contextParser.js +410 -0
- package/dist/editor-completions/dataTypes.d.ts +16 -0
- package/dist/editor-completions/dataTypes.js +95 -0
- package/dist/editor-completions/goToDefinition.d.ts +27 -0
- package/dist/editor-completions/goToDefinition.js +112 -0
- package/dist/editor-completions/index.d.ts +39 -0
- package/dist/editor-completions/index.js +181 -0
- package/dist/editor-completions/jsDocAnnotations.d.ts +29 -0
- package/dist/editor-completions/jsDocAnnotations.js +357 -0
- package/dist/editor-completions/modifierCompletions.d.ts +17 -0
- package/dist/editor-completions/modifierCompletions.js +197 -0
- package/dist/editor-completions/types.d.ts +119 -0
- package/dist/editor-completions/types.js +8 -0
- package/dist/export/index.d.ts +68 -0
- package/dist/export/index.js +1074 -0
- package/dist/export/templates.d.ts +24 -0
- package/dist/export/templates.js +186 -0
- package/dist/friendly-errors.d.ts +35 -0
- package/dist/friendly-errors.js +375 -0
- package/dist/function-like.d.ts +38 -0
- package/dist/function-like.js +83 -0
- package/dist/generated-branding.d.ts +16 -0
- package/dist/generated-branding.js +22 -0
- package/dist/generator/async-detection.d.ts +27 -0
- package/dist/generator/async-detection.js +56 -0
- package/dist/generator/code-utils.d.ts +76 -0
- package/dist/generator/code-utils.js +410 -0
- package/dist/generator/control-flow.d.ts +54 -0
- package/dist/generator/control-flow.js +284 -0
- package/dist/generator/inngest.d.ts +53 -0
- package/dist/generator/inngest.js +1126 -0
- package/dist/generator/scope-function-generator.d.ts +78 -0
- package/dist/generator/scope-function-generator.js +360 -0
- package/dist/generator/unified.d.ts +42 -0
- package/dist/generator/unified.js +1504 -0
- package/dist/generator.d.ts +54 -0
- package/dist/generator.js +100 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +89 -0
- package/dist/jsdoc-parser.d.ts +308 -0
- package/dist/jsdoc-parser.js +923 -0
- package/dist/jsdoc-port-sync/constants.d.ts +41 -0
- package/dist/jsdoc-port-sync/constants.js +103 -0
- package/dist/jsdoc-port-sync/diff.d.ts +76 -0
- package/dist/jsdoc-port-sync/diff.js +319 -0
- package/dist/jsdoc-port-sync/index.d.ts +42 -0
- package/dist/jsdoc-port-sync/index.js +45 -0
- package/dist/jsdoc-port-sync/port-parser.d.ts +68 -0
- package/dist/jsdoc-port-sync/port-parser.js +579 -0
- package/dist/jsdoc-port-sync/rename.d.ts +21 -0
- package/dist/jsdoc-port-sync/rename.js +256 -0
- package/dist/jsdoc-port-sync/signature-parser.d.ts +104 -0
- package/dist/jsdoc-port-sync/signature-parser.js +559 -0
- package/dist/jsdoc-port-sync/sync.d.ts +36 -0
- package/dist/jsdoc-port-sync/sync.js +644 -0
- package/dist/jsdoc-port-sync.d.ts +10 -0
- package/dist/jsdoc-port-sync.js +10 -0
- package/dist/marketplace/index.d.ts +11 -0
- package/dist/marketplace/index.js +10 -0
- package/dist/marketplace/manifest.d.ts +32 -0
- package/dist/marketplace/manifest.js +176 -0
- package/dist/marketplace/registry.d.ts +30 -0
- package/dist/marketplace/registry.js +100 -0
- package/dist/marketplace/types.d.ts +154 -0
- package/dist/marketplace/types.js +9 -0
- package/dist/marketplace/validator.d.ts +13 -0
- package/dist/marketplace/validator.js +131 -0
- package/dist/mcp/auto-registration.d.ts +3 -0
- package/dist/mcp/auto-registration.js +62 -0
- package/dist/mcp/editor-connection.d.ts +50 -0
- package/dist/mcp/editor-connection.js +125 -0
- package/dist/mcp/event-buffer.d.ts +62 -0
- package/dist/mcp/event-buffer.js +150 -0
- package/dist/mcp/index.d.ts +12 -0
- package/dist/mcp/index.js +11 -0
- package/dist/mcp/resources.d.ts +14 -0
- package/dist/mcp/resources.js +55 -0
- package/dist/mcp/response-utils.d.ts +63 -0
- package/dist/mcp/response-utils.js +89 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.js +99 -0
- package/dist/mcp/tools-diagram.d.ts +8 -0
- package/dist/mcp/tools-diagram.js +53 -0
- package/dist/mcp/tools-editor.d.ts +5 -0
- package/dist/mcp/tools-editor.js +190 -0
- package/dist/mcp/tools-export.d.ts +9 -0
- package/dist/mcp/tools-export.js +180 -0
- package/dist/mcp/tools-marketplace.d.ts +9 -0
- package/dist/mcp/tools-marketplace.js +132 -0
- package/dist/mcp/tools-pattern.d.ts +3 -0
- package/dist/mcp/tools-pattern.js +783 -0
- package/dist/mcp/tools-query.d.ts +3 -0
- package/dist/mcp/tools-query.js +364 -0
- package/dist/mcp/tools-template.d.ts +10 -0
- package/dist/mcp/tools-template.js +119 -0
- package/dist/mcp/types.d.ts +70 -0
- package/dist/mcp/types.js +8 -0
- package/dist/mcp/workflow-executor.d.ts +47 -0
- package/dist/mcp/workflow-executor.js +133 -0
- package/dist/migration/registry.d.ts +30 -0
- package/dist/migration/registry.js +29 -0
- package/dist/node-types-generator.d.ts +49 -0
- package/dist/node-types-generator.js +139 -0
- package/dist/npm-packages.d.ts +56 -0
- package/dist/npm-packages.js +255 -0
- package/dist/parser.d.ts +204 -0
- package/dist/parser.js +2100 -0
- package/dist/plugin/PluginPanel.d.ts +12 -0
- package/dist/plugin/PluginPanel.js +5 -0
- package/dist/plugin/index.d.ts +13 -0
- package/dist/plugin/index.js +14 -0
- package/dist/plugin/types.d.ts +75 -0
- package/dist/plugin/types.js +8 -0
- package/dist/resolve-package-types.d.ts +17 -0
- package/dist/resolve-package-types.js +123 -0
- package/dist/runtime/CancellationError.d.ts +11 -0
- package/dist/runtime/CancellationError.js +20 -0
- package/dist/runtime/ExecutionContext.d.ts +146 -0
- package/dist/runtime/ExecutionContext.js +235 -0
- package/dist/runtime/builtin-functions.d.ts +8 -0
- package/dist/runtime/builtin-functions.js +549 -0
- package/dist/runtime/events.d.ts +50 -0
- package/dist/runtime/events.js +2 -0
- package/dist/runtime/function-registry.d.ts +59 -0
- package/dist/runtime/function-registry.js +66 -0
- package/dist/runtime/index.d.ts +7 -0
- package/dist/runtime/index.js +7 -0
- package/dist/runtime/parameter-resolver.d.ts +62 -0
- package/dist/runtime/parameter-resolver.js +113 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +6 -0
- package/dist/server/types.d.ts +93 -0
- package/dist/server/types.js +5 -0
- package/dist/server/webhook-server.d.ts +50 -0
- package/dist/server/webhook-server.js +269 -0
- package/dist/server/workflow-registry.d.ts +61 -0
- package/dist/server/workflow-registry.js +202 -0
- package/dist/shared-project.d.ts +9 -0
- package/dist/shared-project.js +28 -0
- package/dist/sugar-optimizer.d.ts +40 -0
- package/dist/sugar-optimizer.js +387 -0
- package/dist/testing/assertions.d.ts +51 -0
- package/dist/testing/assertions.js +127 -0
- package/dist/testing/index.d.ts +30 -0
- package/dist/testing/index.js +24 -0
- package/dist/testing/mock-approval.d.ts +81 -0
- package/dist/testing/mock-approval.js +98 -0
- package/dist/testing/mock-llm.d.ts +124 -0
- package/dist/testing/mock-llm.js +119 -0
- package/dist/testing/recorder.d.ts +72 -0
- package/dist/testing/recorder.js +70 -0
- package/dist/testing/replayer.d.ts +56 -0
- package/dist/testing/replayer.js +143 -0
- package/dist/testing/token-tracker.d.ts +71 -0
- package/dist/testing/token-tracker.js +94 -0
- package/dist/type-checker.d.ts +42 -0
- package/dist/type-checker.js +190 -0
- package/dist/type-mappings.d.ts +29 -0
- package/dist/type-mappings.js +125 -0
- package/dist/types/branded-ports.d.ts +151 -0
- package/dist/types/branded-ports.js +121 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +5 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.js +15 -0
- package/dist/utils/error-utils.d.ts +15 -0
- package/dist/utils/error-utils.js +27 -0
- package/dist/utils/lru-cache.d.ts +15 -0
- package/dist/utils/lru-cache.js +40 -0
- package/dist/utils/port-ordering.d.ts +26 -0
- package/dist/utils/port-ordering.js +88 -0
- package/dist/utils/port-tag-utils.d.ts +23 -0
- package/dist/utils/port-tag-utils.js +41 -0
- package/dist/utils/string-distance.d.ts +14 -0
- package/dist/utils/string-distance.js +56 -0
- package/dist/validation/agent-detection.d.ts +33 -0
- package/dist/validation/agent-detection.js +115 -0
- package/dist/validation/agent-rules.d.ts +48 -0
- package/dist/validation/agent-rules.js +262 -0
- package/dist/validator.d.ts +92 -0
- package/dist/validator.js +970 -0
- package/package.json +109 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { RESERVED_PORT_NAMES, isStartNode, isExitNode, isExecutePort, isSuccessPort, isFailurePort, } from '../constants.js';
|
|
2
|
+
import { generateScopeFunctionClosure } from './scope-function-generator.js';
|
|
3
|
+
import { mapToTypeScript } from '../type-mappings.js';
|
|
4
|
+
/**
|
|
5
|
+
* Sanitize a node ID to be a valid JavaScript identifier.
|
|
6
|
+
* Replaces non-alphanumeric characters (except _ and $) with underscores.
|
|
7
|
+
*
|
|
8
|
+
* @param nodeId - The node ID (may contain slashes, etc.)
|
|
9
|
+
* @returns A valid JavaScript identifier
|
|
10
|
+
*/
|
|
11
|
+
export function toValidIdentifier(nodeId) {
|
|
12
|
+
// Replace any character that's not alphanumeric, underscore, or dollar sign
|
|
13
|
+
let sanitized = nodeId.replace(/[^a-zA-Z0-9_$]/g, '_');
|
|
14
|
+
// Ensure it doesn't start with a digit
|
|
15
|
+
if (/^[0-9]/.test(sanitized)) {
|
|
16
|
+
sanitized = '_' + sanitized;
|
|
17
|
+
}
|
|
18
|
+
return sanitized;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a JavaScript expression that merges multiple source values based on strategy.
|
|
22
|
+
*
|
|
23
|
+
* @param sources - Array of source variable names
|
|
24
|
+
* @param strategy - Merge strategy to apply
|
|
25
|
+
* @returns JavaScript expression string
|
|
26
|
+
*/
|
|
27
|
+
export function buildMergeExpression(sources, strategy) {
|
|
28
|
+
switch (strategy) {
|
|
29
|
+
case 'FIRST':
|
|
30
|
+
return `(() => { const __s__ = [${sources.join(', ')}]; return __s__.find(v => v !== undefined); })()`;
|
|
31
|
+
case 'LAST':
|
|
32
|
+
return `(() => { const __s__ = [${sources.join(', ')}]; return __s__.filter(v => v !== undefined).pop(); })()`;
|
|
33
|
+
case 'COLLECT':
|
|
34
|
+
return `[${sources.join(', ')}]`;
|
|
35
|
+
case 'MERGE':
|
|
36
|
+
return `Object.assign({}, ${sources.join(', ')})`;
|
|
37
|
+
case 'CONCAT':
|
|
38
|
+
return `[${sources.join(', ')}].flat()`;
|
|
39
|
+
default:
|
|
40
|
+
return sources[0] ?? 'undefined';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds the argument list for a node function call by resolving input port values.
|
|
45
|
+
*
|
|
46
|
+
* This function is central to code generation - it determines where each input port
|
|
47
|
+
* gets its value from: connections, expressions, defaults, or execution strategies.
|
|
48
|
+
*
|
|
49
|
+
* ## Resolution Priority (per port):
|
|
50
|
+
* 1. **Skip Ports**: If port is in skipPorts set, use pre-declared variable
|
|
51
|
+
* 2. **Instance Expression**: Check instance.config.portConfigs for evaluateConstantAs
|
|
52
|
+
* 3. **Connection**: Get value from connected output port via ctx.getVariable()
|
|
53
|
+
* 4. **Node Type Expression**: Check nodeType.inputs[port].expression
|
|
54
|
+
* 5. **Default Value**: Use nodeType.inputs[port].default if available
|
|
55
|
+
* 6. **Undefined**: No value source found (may cause runtime error)
|
|
56
|
+
*
|
|
57
|
+
* ## Special Handling:
|
|
58
|
+
* - **execute port**: Always first, handles CONJUNCTION/DISJUNCTION strategies
|
|
59
|
+
* - **Scoped INPUT ports**: Skipped (they're return values from scope functions)
|
|
60
|
+
* - **STEP ports (onSuccess/onFailure)**: Use executionSignal config if present
|
|
61
|
+
* - **Scope functions**: Generated via generateScopeFunctionClosure() for FUNCTION ports
|
|
62
|
+
*
|
|
63
|
+
* ## STEP Port Execution Strategies:
|
|
64
|
+
* - **CONJUNCTION (AND)**: `execute = stepA && stepB && stepC`
|
|
65
|
+
* - **DISJUNCTION (OR)**: `execute = stepA || stepB || stepC`
|
|
66
|
+
* - **CUSTOM**: Uses evaluateExecutionSignalAs expression
|
|
67
|
+
*
|
|
68
|
+
* @param opts - Configuration object with node, workflow, and generation settings
|
|
69
|
+
* @param opts.node - The node type definition with input/output port specs
|
|
70
|
+
* @param opts.workflow - The workflow AST containing connections and instances
|
|
71
|
+
* @param opts.id - The node instance ID being generated
|
|
72
|
+
* @param opts.lines - Array to push generated code lines into
|
|
73
|
+
* @param opts.indent - Indentation prefix for generated lines (default: " ")
|
|
74
|
+
* @param opts.getCall - Method to get variables (default: "await ctx.getVariable")
|
|
75
|
+
* @param opts.isAsync - Whether generating async code
|
|
76
|
+
* @param opts.instanceParent - Parent node ID if this node is in a scope
|
|
77
|
+
* @param opts.skipPorts - Ports to skip (already pre-handled)
|
|
78
|
+
* @param opts.emitInputEvents - Whether to emit VARIABLE_SET events for inputs
|
|
79
|
+
* @param opts.setCall - Method to set variables (default: "await ctx.setVariable")
|
|
80
|
+
* @param opts.nodeTypeName - Override for node type name in events
|
|
81
|
+
* @returns Array of argument expressions to pass to the node function
|
|
82
|
+
*/
|
|
83
|
+
export function buildNodeArgumentsWithContext(opts) {
|
|
84
|
+
const { node, workflow, id, lines, indent = ' ', getCall = 'await ctx.getVariable', isAsync = true, instanceParent, skipPorts, emitInputEvents = false, setCall = 'await ctx.setVariable', nodeTypeName, bundleMode = false, } = opts;
|
|
85
|
+
const safeId = toValidIdentifier(id);
|
|
86
|
+
const inputConnections = workflow.connections.filter((conn) => conn.to.node === id);
|
|
87
|
+
const args = [];
|
|
88
|
+
// Find instance for checking instance-level constant expressions
|
|
89
|
+
const instance = workflow.instances.find((i) => i.id === id);
|
|
90
|
+
const getInstancePortConfig = (portName) => instance?.config?.portConfigs?.find((pc) => pc.portName === portName && (pc.direction == null || pc.direction === 'INPUT'));
|
|
91
|
+
// Handle execute port first
|
|
92
|
+
const executeConnections = inputConnections.filter((conn) => conn.to.port === 'execute');
|
|
93
|
+
const effectiveNodeTypeName = nodeTypeName || node.functionName;
|
|
94
|
+
if (node.expression) {
|
|
95
|
+
// Expression nodes don't take execute as a function argument.
|
|
96
|
+
// Their _impl has no execute parameter (data-only signature).
|
|
97
|
+
// The wrapper or workflow body handles execute guard and control flow.
|
|
98
|
+
// Still emit the event for the execute port so the UI shows it.
|
|
99
|
+
if (emitInputEvents) {
|
|
100
|
+
lines.push(`${indent}${setCall}({ id: '${id}', portName: 'execute', executionIndex: ${safeId}Idx, nodeTypeName: '${effectiveNodeTypeName}' }, true);`);
|
|
101
|
+
}
|
|
102
|
+
// Don't push execute to args - expression _impl doesn't receive it
|
|
103
|
+
}
|
|
104
|
+
else if (skipPorts?.has('execute')) {
|
|
105
|
+
// Execute was pre-handled (e.g., in scope functions)
|
|
106
|
+
args.push(`${safeId}_execute`);
|
|
107
|
+
}
|
|
108
|
+
else if (executeConnections.length > 0) {
|
|
109
|
+
// Execute port has a connection - use it
|
|
110
|
+
const conn = executeConnections[0];
|
|
111
|
+
const sourceNode = conn.from.node;
|
|
112
|
+
const sourcePort = conn.from.port;
|
|
113
|
+
const varName = `${safeId}_execute`;
|
|
114
|
+
// startIdx is const so no ! needed; parent scope node is also const; other node indices are let so need !
|
|
115
|
+
const sourceIdx = isStartNode(sourceNode) ? 'startIdx' : `${toValidIdentifier(sourceNode)}Idx`;
|
|
116
|
+
const isConstSource = isStartNode(sourceNode) || sourceNode === instanceParent;
|
|
117
|
+
const nonNullAssert = isConstSource ? '' : '!';
|
|
118
|
+
lines.push(`${indent}const ${varName} = ${getCall}({ id: '${sourceNode}', portName: '${sourcePort}', executionIndex: ${sourceIdx}${nonNullAssert} }) as boolean;`);
|
|
119
|
+
// Emit VARIABLE_SET for execute input port
|
|
120
|
+
if (emitInputEvents) {
|
|
121
|
+
lines.push(`${indent}${setCall}({ id: '${id}', portName: 'execute', executionIndex: ${safeId}Idx, nodeTypeName: '${effectiveNodeTypeName}' }, ${varName});`);
|
|
122
|
+
}
|
|
123
|
+
args.push(varName);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// Default execute to true - still emit event for the default value
|
|
127
|
+
if (emitInputEvents) {
|
|
128
|
+
lines.push(`${indent}${setCall}({ id: '${id}', portName: 'execute', executionIndex: ${safeId}Idx, nodeTypeName: '${effectiveNodeTypeName}' }, true);`);
|
|
129
|
+
}
|
|
130
|
+
args.push('true');
|
|
131
|
+
}
|
|
132
|
+
Object.keys(node.inputs).forEach((portName) => {
|
|
133
|
+
if (isExecutePort(portName))
|
|
134
|
+
return;
|
|
135
|
+
// Skip scoped INPUT ports - they're return values from scope, not function parameters
|
|
136
|
+
const portConfig = node.inputs[portName];
|
|
137
|
+
if (portConfig.scope)
|
|
138
|
+
return;
|
|
139
|
+
if (skipPorts?.has(portName)) {
|
|
140
|
+
// Port was pre-handled - skip variable declaration but include in args
|
|
141
|
+
const varName = `${safeId}_${portName}`;
|
|
142
|
+
args.push(varName);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const connections = inputConnections.filter((conn) => {
|
|
146
|
+
const targetPort = conn.to.port;
|
|
147
|
+
return targetPort === portName;
|
|
148
|
+
});
|
|
149
|
+
// Check for instance-level expression first
|
|
150
|
+
const instancePortConfig = getInstancePortConfig(portName);
|
|
151
|
+
const hasInstanceExpression = instancePortConfig?.expression !== undefined;
|
|
152
|
+
const varName = `${safeId}_${portName}`;
|
|
153
|
+
const effectiveNodeTypeName = nodeTypeName || node.functionName;
|
|
154
|
+
// Helper to emit VARIABLE_SET event for input port
|
|
155
|
+
const emitSetEvent = () => {
|
|
156
|
+
if (emitInputEvents) {
|
|
157
|
+
lines.push(`${indent}${setCall}({ id: '${id}', portName: '${portName}', executionIndex: ${safeId}Idx, nodeTypeName: '${effectiveNodeTypeName}' }, ${varName});`);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
if (hasInstanceExpression) {
|
|
161
|
+
// Instance-level expression takes priority
|
|
162
|
+
const expr = String(instancePortConfig.expression);
|
|
163
|
+
// Check if expression is a function (arrow or regular)
|
|
164
|
+
const isFunction = expr.includes('=>') || expr.trim().startsWith('function');
|
|
165
|
+
if (isFunction) {
|
|
166
|
+
lines.push(`${indent}const ${varName} = ${isAsync ? 'await ' : ''}(${expr})(ctx);`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// Simple expression - evaluate directly
|
|
170
|
+
lines.push(`${indent}const ${varName} = ${expr};`);
|
|
171
|
+
}
|
|
172
|
+
args.push(varName);
|
|
173
|
+
emitSetEvent();
|
|
174
|
+
}
|
|
175
|
+
else if (connections.length > 0) {
|
|
176
|
+
if (connections.length === 1) {
|
|
177
|
+
const connection = connections[0];
|
|
178
|
+
const sourceNode = connection.from.node;
|
|
179
|
+
const sourcePort = connection.from.port;
|
|
180
|
+
// Check if source node exists (Start node always exists)
|
|
181
|
+
const sourceExists = isStartNode(sourceNode) || workflow.instances.some((i) => i.id === sourceNode);
|
|
182
|
+
if (!sourceExists) {
|
|
183
|
+
lines.push(`${indent}const ${varName} = undefined; // Source node '${sourceNode}' not found`);
|
|
184
|
+
args.push(varName);
|
|
185
|
+
emitSetEvent();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const sourceIdx = isStartNode(sourceNode) ? 'startIdx' : `${toValidIdentifier(sourceNode)}Idx`;
|
|
189
|
+
const isConstSource = isStartNode(sourceNode) || sourceNode === instanceParent;
|
|
190
|
+
const nonNullAssert = isConstSource ? '' : '!';
|
|
191
|
+
const portType = mapToTypeScript(portConfig.dataType, portConfig.tsType);
|
|
192
|
+
// For FUNCTION type ports, add resolution step to handle registry IDs
|
|
193
|
+
if (portConfig.dataType === 'FUNCTION') {
|
|
194
|
+
const rawVarName = `${varName}_raw`;
|
|
195
|
+
lines.push(`${indent}const ${rawVarName} = ${getCall}({ id: '${sourceNode}', portName: '${sourcePort}', executionIndex: ${sourceIdx}${nonNullAssert} });`);
|
|
196
|
+
lines.push(`${indent}const ${varName}_resolved = resolveFunction(${rawVarName});`);
|
|
197
|
+
lines.push(`${indent}const ${varName} = ${varName}_resolved.fn as ${portType};`);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
lines.push(`${indent}const ${varName} = ${getCall}({ id: '${sourceNode}', portName: '${sourcePort}', executionIndex: ${sourceIdx}${nonNullAssert} }) as ${portType};`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// Filter to only connections with existing source nodes
|
|
205
|
+
const validConnections = connections.filter((conn) => {
|
|
206
|
+
const sourceNode = conn.from.node;
|
|
207
|
+
return isStartNode(sourceNode) || workflow.instances.some((i) => i.id === sourceNode);
|
|
208
|
+
});
|
|
209
|
+
if (validConnections.length === 0) {
|
|
210
|
+
// All source nodes are orphaned
|
|
211
|
+
lines.push(`${indent}const ${varName} = undefined; // All source nodes not found`);
|
|
212
|
+
args.push(varName);
|
|
213
|
+
emitSetEvent();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const attempts = [];
|
|
217
|
+
validConnections.forEach((conn, _idx) => {
|
|
218
|
+
const sourceNode = conn.from.node;
|
|
219
|
+
const sourcePort = conn.from.port;
|
|
220
|
+
const sourceIdx = isStartNode(sourceNode) ? 'startIdx' : `${toValidIdentifier(sourceNode)}Idx`;
|
|
221
|
+
attempts.push(`(${sourceIdx} !== undefined ? ${getCall}({ id: '${sourceNode}', portName: '${sourcePort}', executionIndex: ${sourceIdx} }) : undefined)`);
|
|
222
|
+
});
|
|
223
|
+
const ternary = attempts.join(' ?? ');
|
|
224
|
+
const portType = mapToTypeScript(portConfig.dataType, portConfig.tsType);
|
|
225
|
+
// For FUNCTION type ports, add resolution step to handle registry IDs
|
|
226
|
+
if (portConfig.dataType === 'FUNCTION') {
|
|
227
|
+
const rawVarName = `${varName}_raw`;
|
|
228
|
+
lines.push(`${indent}const ${rawVarName} = ${ternary};`);
|
|
229
|
+
lines.push(`${indent}const ${varName}_resolved = ${rawVarName} !== undefined ? resolveFunction(${rawVarName}) : undefined;`);
|
|
230
|
+
lines.push(`${indent}const ${varName} = ${varName}_resolved?.fn as ${portType};`);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
lines.push(`${indent}const ${varName} = ${ternary} as ${portType};`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
args.push(varName);
|
|
237
|
+
emitSetEvent();
|
|
238
|
+
}
|
|
239
|
+
else if (portConfig.expression) {
|
|
240
|
+
const expression = portConfig.expression;
|
|
241
|
+
const isFunction = expression.includes('=>') || expression.trim().startsWith('function');
|
|
242
|
+
const portType = mapToTypeScript(portConfig.dataType, portConfig.tsType);
|
|
243
|
+
if (isFunction) {
|
|
244
|
+
lines.push(`${indent}const ${varName} = ${isAsync ? 'await ' : ''}(${expression})(ctx) as ${portType};`);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
lines.push(`${indent}const ${varName} = ${expression} as ${portType};`);
|
|
248
|
+
}
|
|
249
|
+
args.push(varName);
|
|
250
|
+
emitSetEvent();
|
|
251
|
+
}
|
|
252
|
+
else if (portConfig.default !== undefined) {
|
|
253
|
+
const defaultVal = JSON.stringify(portConfig.default);
|
|
254
|
+
lines.push(`${indent}const ${varName} = ${defaultVal};`);
|
|
255
|
+
args.push(varName);
|
|
256
|
+
emitSetEvent();
|
|
257
|
+
}
|
|
258
|
+
else if (portConfig.optional) {
|
|
259
|
+
lines.push(`${indent}const ${varName} = undefined;`);
|
|
260
|
+
args.push(varName);
|
|
261
|
+
emitSetEvent();
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// Required port has no connection, expression, or default - use typed undefined fallback
|
|
265
|
+
const portType = mapToTypeScript(portConfig.dataType, portConfig.tsType);
|
|
266
|
+
lines.push(`${indent}let ${varName}!: ${portType}; // Required port '${portName}' has no connection`);
|
|
267
|
+
args.push(varName);
|
|
268
|
+
emitSetEvent();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
// Handle scoped ports: generate scope functions for each unique scope
|
|
272
|
+
// Collect all unique scope names from both inputs and outputs
|
|
273
|
+
const scopeNames = new Set();
|
|
274
|
+
Object.values(node.inputs).forEach((portDef) => {
|
|
275
|
+
if (portDef.scope)
|
|
276
|
+
scopeNames.add(portDef.scope);
|
|
277
|
+
});
|
|
278
|
+
Object.values(node.outputs).forEach((portDef) => {
|
|
279
|
+
if (portDef.scope)
|
|
280
|
+
scopeNames.add(portDef.scope);
|
|
281
|
+
});
|
|
282
|
+
// For each scope, generate a scope function closure
|
|
283
|
+
scopeNames.forEach((scopeName) => {
|
|
284
|
+
const scopeFunctionVar = `${safeId}_${scopeName}_scopeFn`;
|
|
285
|
+
// Find child instances in this scope
|
|
286
|
+
// Format: instance.parent = { id: parentId, scope: scopeName }
|
|
287
|
+
const childInstances = workflow.instances.filter((inst) => {
|
|
288
|
+
if (!inst.parent)
|
|
289
|
+
return false;
|
|
290
|
+
return inst.parent.id === id && inst.parent.scope === scopeName;
|
|
291
|
+
});
|
|
292
|
+
// Generate scope function closure
|
|
293
|
+
// The scope function's async/sync nature should match the workflow context (isAsync parameter).
|
|
294
|
+
// If the workflow is async, the scope function must be async to use await for context operations.
|
|
295
|
+
// We also consider node.isAsync for cases where the node type explicitly expects async callbacks.
|
|
296
|
+
// PHASE 9 FIX: Also check if any child node in the scope is async - if so, the scope
|
|
297
|
+
// function must be async to properly await those child node calls.
|
|
298
|
+
const hasAsyncChild = childInstances.some((child) => {
|
|
299
|
+
const childNodeType = workflow.nodeTypes?.find((nt) => nt.name === child.nodeType || nt.functionName === child.nodeType);
|
|
300
|
+
return childNodeType?.isAsync === true;
|
|
301
|
+
});
|
|
302
|
+
const scopeIsAsync = isAsync || node.isAsync || hasAsyncChild;
|
|
303
|
+
const scopeFunctionCode = generateScopeFunctionClosure(scopeName, id, node, workflow, childInstances, scopeIsAsync, false // production mode
|
|
304
|
+
);
|
|
305
|
+
lines.push(`${indent}const ${scopeFunctionVar} = ${scopeFunctionCode};`);
|
|
306
|
+
args.push(scopeFunctionVar);
|
|
307
|
+
});
|
|
308
|
+
return args;
|
|
309
|
+
}
|
|
310
|
+
export function generateNodeWithExecutionContext(node, workflow, lines, isAsync, indent = ' ') {
|
|
311
|
+
const nodeName = node.functionName;
|
|
312
|
+
const safeNodeName = toValidIdentifier(nodeName); // Sanitize for use as JS variable name
|
|
313
|
+
const awaitPrefix = isAsync ? 'await ' : '';
|
|
314
|
+
const getCall = isAsync ? 'await ctx.getVariable' : 'ctx.getVariable';
|
|
315
|
+
const setCall = isAsync ? 'await ctx.setVariable' : 'ctx.setVariable';
|
|
316
|
+
lines.push(`${indent}const ${safeNodeName}Idx = ctx.addExecution('${nodeName}');`);
|
|
317
|
+
lines.push(`${indent}ctx.sendStatusChangedEvent({`);
|
|
318
|
+
lines.push(`${indent} nodeTypeName: '${nodeName}',`);
|
|
319
|
+
lines.push(`${indent} id: '${nodeName}',`);
|
|
320
|
+
lines.push(`${indent} executionIndex: ${safeNodeName}Idx,`);
|
|
321
|
+
lines.push(`${indent} status: 'RUNNING',`);
|
|
322
|
+
lines.push(`${indent}});`);
|
|
323
|
+
lines.push(`${indent}try {`);
|
|
324
|
+
const args = buildNodeArgumentsWithContext({
|
|
325
|
+
node,
|
|
326
|
+
workflow,
|
|
327
|
+
id: nodeName,
|
|
328
|
+
lines,
|
|
329
|
+
indent: `${indent} `,
|
|
330
|
+
getCall,
|
|
331
|
+
isAsync,
|
|
332
|
+
});
|
|
333
|
+
const resultVar = `${safeNodeName}Result`;
|
|
334
|
+
lines.push(`${indent} const ${resultVar} = ${awaitPrefix}${node.functionName}(${args.join(', ')});`);
|
|
335
|
+
Object.keys(node.outputs).forEach((portName) => {
|
|
336
|
+
if (isSuccessPort(portName) || isFailurePort(portName))
|
|
337
|
+
return;
|
|
338
|
+
lines.push(`${indent} ${setCall}({ id: '${nodeName}', portName: '${portName}', executionIndex: ${safeNodeName}Idx, nodeTypeName: '${nodeName}' }, ${resultVar}.${portName});`);
|
|
339
|
+
});
|
|
340
|
+
lines.push(`${indent} ctx.sendStatusChangedEvent({`);
|
|
341
|
+
lines.push(`${indent} nodeTypeName: '${nodeName}',`);
|
|
342
|
+
lines.push(`${indent} id: '${nodeName}',`);
|
|
343
|
+
lines.push(`${indent} executionIndex: ${safeNodeName}Idx,`);
|
|
344
|
+
lines.push(`${indent} status: 'SUCCEEDED',`);
|
|
345
|
+
lines.push(`${indent} });`);
|
|
346
|
+
const hasOnSuccess = node.outputs.hasOwnProperty(RESERVED_PORT_NAMES.ON_SUCCESS);
|
|
347
|
+
const hasOnFailure = node.outputs.hasOwnProperty(RESERVED_PORT_NAMES.ON_FAILURE);
|
|
348
|
+
if (hasOnSuccess || hasOnFailure) {
|
|
349
|
+
if (hasOnSuccess) {
|
|
350
|
+
lines.push(`${indent} ${setCall}({ id: '${nodeName}', portName: '${RESERVED_PORT_NAMES.ON_SUCCESS}', executionIndex: ${safeNodeName}Idx, nodeTypeName: '${nodeName}' }, true);`);
|
|
351
|
+
}
|
|
352
|
+
if (hasOnFailure) {
|
|
353
|
+
lines.push(`${indent} ${setCall}({ id: '${nodeName}', portName: '${RESERVED_PORT_NAMES.ON_FAILURE}', executionIndex: ${safeNodeName}Idx, nodeTypeName: '${nodeName}' }, false);`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
lines.push(`${indent}} catch (error: unknown) {`);
|
|
357
|
+
lines.push(`${indent} ctx.sendStatusChangedEvent({`);
|
|
358
|
+
lines.push(`${indent} nodeTypeName: '${nodeName}',`);
|
|
359
|
+
lines.push(`${indent} id: '${nodeName}',`);
|
|
360
|
+
lines.push(`${indent} executionIndex: ${safeNodeName}Idx,`);
|
|
361
|
+
lines.push(`${indent} status: 'FAILED',`);
|
|
362
|
+
lines.push(`${indent} });`);
|
|
363
|
+
lines.push(`${indent} ctx.sendLogErrorEvent({`);
|
|
364
|
+
lines.push(`${indent} nodeTypeName: '${nodeName}',`);
|
|
365
|
+
lines.push(`${indent} id: '${nodeName}',`);
|
|
366
|
+
lines.push(`${indent} executionIndex: ${safeNodeName}Idx,`);
|
|
367
|
+
lines.push(`${indent} error: error instanceof Error ? error.message : String(error),`);
|
|
368
|
+
lines.push(`${indent} });`);
|
|
369
|
+
if (hasOnSuccess || hasOnFailure) {
|
|
370
|
+
if (hasOnSuccess) {
|
|
371
|
+
lines.push(`${indent} ${setCall}({ id: '${nodeName}', portName: '${RESERVED_PORT_NAMES.ON_SUCCESS}', executionIndex: ${safeNodeName}Idx, nodeTypeName: '${nodeName}' }, false);`);
|
|
372
|
+
}
|
|
373
|
+
if (hasOnFailure) {
|
|
374
|
+
lines.push(`${indent} ${setCall}({ id: '${nodeName}', portName: '${RESERVED_PORT_NAMES.ON_FAILURE}', executionIndex: ${safeNodeName}Idx, nodeTypeName: '${nodeName}' }, true);`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const hasOnFailureConnection = workflow.connections.some((conn) => conn.from.node === nodeName && isFailurePort(conn.from.port));
|
|
378
|
+
if (hasOnFailureConnection) {
|
|
379
|
+
lines.push(`${indent} `);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
lines.push(`${indent} throw error;`);
|
|
383
|
+
}
|
|
384
|
+
lines.push(`${indent}}`);
|
|
385
|
+
}
|
|
386
|
+
export function buildExecutionContextReturnForBranch(workflow, lines, isAsync, branchName, indent, executedNodes) {
|
|
387
|
+
const getCall = isAsync ? 'await ctx.getVariable' : 'ctx.getVariable';
|
|
388
|
+
const exitConnections = workflow.connections.filter((conn) => isExitNode(conn.to.node));
|
|
389
|
+
const returnProps = [];
|
|
390
|
+
exitConnections.forEach((conn) => {
|
|
391
|
+
const exitPort = conn.to.port;
|
|
392
|
+
const sourceNode = conn.from.node;
|
|
393
|
+
const sourcePort = conn.from.port;
|
|
394
|
+
const sourceIdx = isStartNode(sourceNode) ? 'startIdx' : `${toValidIdentifier(sourceNode)}Idx`;
|
|
395
|
+
// Get exit port type for type casting
|
|
396
|
+
const exitPortDef = workflow.exitPorts[exitPort];
|
|
397
|
+
const exitPortType = exitPortDef?.tsType || (exitPortDef ? mapToTypeScript(exitPortDef.dataType) : 'unknown');
|
|
398
|
+
if (!executedNodes.includes(sourceNode) && !isStartNode(sourceNode)) {
|
|
399
|
+
returnProps.push(`${exitPort}: undefined`);
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
const varName = `exit_${exitPort}_${branchName}`;
|
|
403
|
+
lines.push(`${indent}const ${varName} = ${sourceIdx} !== undefined ? ${getCall}({ id: '${sourceNode}', portName: '${sourcePort}', executionIndex: ${sourceIdx} }) : undefined;`);
|
|
404
|
+
// Cast to the exit port's declared type for type safety
|
|
405
|
+
returnProps.push(`${exitPort}: ${varName} as ${exitPortType}`);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
return `{ ${returnProps.join(', ')} }`;
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=code-utils.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { TNodeInstanceAST, TNodeTypeAST, TWorkflowAST } from '../ast/index.js';
|
|
2
|
+
import { RESERVED_PORT_NAMES } from '../constants.js';
|
|
3
|
+
export type ControlFlowGraph = {
|
|
4
|
+
graph: Map<string, string[]>;
|
|
5
|
+
inDegree: Map<string, number>;
|
|
6
|
+
};
|
|
7
|
+
export declare function buildControlFlowGraph(workflow: TWorkflowAST, nodeTypes: TNodeTypeAST[]): ControlFlowGraph;
|
|
8
|
+
/**
|
|
9
|
+
* Perform Kahn's topological sort algorithm on control flow graph
|
|
10
|
+
*
|
|
11
|
+
* Determines the execution order of nodes in the workflow, ensuring all
|
|
12
|
+
* dependencies execute before dependent nodes.
|
|
13
|
+
*
|
|
14
|
+
* Algorithm:
|
|
15
|
+
* 1. Start with nodes that have no dependencies (in-degree = 0)
|
|
16
|
+
* 2. Process each node, decreasing in-degree of successors
|
|
17
|
+
* 3. Add nodes with in-degree 0 to queue
|
|
18
|
+
* 4. Repeat until all nodes processed
|
|
19
|
+
*
|
|
20
|
+
* @param controlFlowGraph - Control flow graph with nodes and edges
|
|
21
|
+
* @returns Ordered array of node IDs in execution order
|
|
22
|
+
* @throws {Error} If circular dependency detected (cycle in graph)
|
|
23
|
+
*/
|
|
24
|
+
export declare function performKahnsTopologicalSort(controlFlowGraph: ControlFlowGraph): string[];
|
|
25
|
+
export declare function findAllBranchingNodes(workflow: TWorkflowAST, nodeTypes: TNodeTypeAST[]): Set<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Check if an instance is a per-port scoped child.
|
|
28
|
+
*
|
|
29
|
+
* Per-port scoped children:
|
|
30
|
+
* - Have a parent reference (instance.parent)
|
|
31
|
+
* - Parent has ports with matching scope name (scope declared via @scope tag or callback param)
|
|
32
|
+
* - Execute inside parent's scope function, NOT in main control flow
|
|
33
|
+
*
|
|
34
|
+
* Node-level scoped children:
|
|
35
|
+
* - Have a parent reference (instance.parent)
|
|
36
|
+
* - Parent does NOT have ports with matching scope
|
|
37
|
+
* - Execute in parent's scope block within main control flow
|
|
38
|
+
*/
|
|
39
|
+
export declare function isPerPortScopedChild(instance: TNodeInstanceAST, workflow: TWorkflowAST, nodeTypes: TNodeTypeAST[]): boolean;
|
|
40
|
+
export declare function findNodesInBranch(branchNode: string, branchPort: typeof RESERVED_PORT_NAMES.ON_SUCCESS | typeof RESERVED_PORT_NAMES.ON_FAILURE, workflow: TWorkflowAST, allNodes: Set<string>, stopAtBranchingNodes: Set<string>, _allParsedNodeTypes?: TNodeTypeAST[]): Set<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Detect sequential chains of branching nodes where flattening can reduce nesting.
|
|
43
|
+
*
|
|
44
|
+
* A chain link exists when a branching node has exactly one branching child in one
|
|
45
|
+
* direction (success or failure) and zero in the other. Chains must be >= 2 nodes.
|
|
46
|
+
*
|
|
47
|
+
* @returns Map from chain head ID to ordered array of chain node IDs
|
|
48
|
+
*/
|
|
49
|
+
export declare function detectBranchingChains(branchingNodes: Set<string>, branchRegions: Map<string, {
|
|
50
|
+
successNodes: Set<string>;
|
|
51
|
+
failureNodes: Set<string>;
|
|
52
|
+
}>): Map<string, string[]>;
|
|
53
|
+
export declare function determineExecutionOrder(workflow: TWorkflowAST, nodes: TNodeTypeAST[]): string[];
|
|
54
|
+
//# sourceMappingURL=control-flow.d.ts.map
|