@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,83 @@
|
|
|
1
|
+
import type { TGenerateOptions as ASTGenerateOptions, TWorkflowAST, TModuleFormat } from '../ast/types.js';
|
|
2
|
+
export interface GenerateOptions extends Partial<ASTGenerateOptions> {
|
|
3
|
+
/**
|
|
4
|
+
* Whether to generate production-optimized code (no debug events)
|
|
5
|
+
*/
|
|
6
|
+
production?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to generate source maps
|
|
9
|
+
*/
|
|
10
|
+
sourceMap?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* All workflows in the source file (needed for local workflow dependencies)
|
|
13
|
+
*/
|
|
14
|
+
allWorkflows?: TWorkflowAST[];
|
|
15
|
+
/**
|
|
16
|
+
* Module format for generated code ('esm' or 'cjs')
|
|
17
|
+
* @default 'esm'
|
|
18
|
+
*/
|
|
19
|
+
moduleFormat?: TModuleFormat;
|
|
20
|
+
/**
|
|
21
|
+
* Path to external runtime module (relative from the generated file).
|
|
22
|
+
* When set, generates import from this path instead of inlining runtime types.
|
|
23
|
+
* Use this for multi-workflow bundles to avoid duplicate type declarations.
|
|
24
|
+
* @example '../runtime/types.js'
|
|
25
|
+
*/
|
|
26
|
+
externalRuntimePath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Constants from source file(s) to include at the top of the generated file.
|
|
29
|
+
* Used in bundle mode when local node functions are inlined and need their
|
|
30
|
+
* referenced constants available.
|
|
31
|
+
*/
|
|
32
|
+
constants?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Map of node type names to their import paths.
|
|
35
|
+
* When set, generates imports instead of inlining the function text.
|
|
36
|
+
* Used in bundle mode where node types are in separate files.
|
|
37
|
+
* @example { 'add': '../node-types/add.js', 'greet': '../node-types/greet.js' }
|
|
38
|
+
*/
|
|
39
|
+
externalNodeTypes?: Record<string, string>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Generate an import statement in the appropriate module format
|
|
43
|
+
*/
|
|
44
|
+
export declare function generateImportStatement(names: string[], source: string, moduleFormat: TModuleFormat): string;
|
|
45
|
+
/**
|
|
46
|
+
* Generate an export statement for a function in the appropriate module format
|
|
47
|
+
* For ESM: export async function name() { }
|
|
48
|
+
* For CJS: async function name() { } (module.exports added at end)
|
|
49
|
+
*/
|
|
50
|
+
export declare function generateFunctionExportKeyword(moduleFormat: TModuleFormat): string;
|
|
51
|
+
/**
|
|
52
|
+
* Generate module.exports statement for CJS format
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateModuleExports(functionNames: string[]): string;
|
|
55
|
+
export interface GenerateResult {
|
|
56
|
+
code: string;
|
|
57
|
+
sourceMap?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generate executable TypeScript code from a workflow AST
|
|
61
|
+
*
|
|
62
|
+
* @param ast - The workflow AST to generate code from
|
|
63
|
+
* @param options - Generation options (production mode, source maps, etc.)
|
|
64
|
+
* @returns Generated code as a string, or GenerateResult with source map
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const result = generateCode(ast, {
|
|
69
|
+
* production: false,
|
|
70
|
+
* sourceMap: true
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* fs.writeFileSync('workflow.generated.ts', result.code);
|
|
74
|
+
* if (result.sourceMap) {
|
|
75
|
+
* fs.writeFileSync('workflow.generated.ts.map', result.sourceMap);
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function generateCode(ast: TWorkflowAST, options?: GenerateOptions & {
|
|
80
|
+
sourceMap: true;
|
|
81
|
+
}): GenerateResult;
|
|
82
|
+
export declare function generateCode(ast: TWorkflowAST, options?: GenerateOptions): string;
|
|
83
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
import { bodyGenerator } from '../body-generator.js';
|
|
2
|
+
import { extractExitPorts, extractStartPorts, hasBranching } from '../ast/workflow-utils.js';
|
|
3
|
+
import { isExecutePort } from '../constants.js';
|
|
4
|
+
import { mapToTypeScript } from '../type-mappings.js';
|
|
5
|
+
import { SourceMapGenerator } from 'source-map';
|
|
6
|
+
import { generateInlineRuntime, generateInlineDebugClient } from './inline-runtime.js';
|
|
7
|
+
import { validateWorkflowAsync } from '../generator/async-detection.js';
|
|
8
|
+
import { extractTypeDeclarationsFromFile } from './extract-types.js';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Module Format Helpers
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Generate an import statement in the appropriate module format
|
|
16
|
+
*/
|
|
17
|
+
export function generateImportStatement(names, source, moduleFormat) {
|
|
18
|
+
if (moduleFormat === 'cjs') {
|
|
19
|
+
return `const { ${names.join(', ')} } = require('${source}');`;
|
|
20
|
+
}
|
|
21
|
+
return `import { ${names.join(', ')} } from '${source}';`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate an export statement for a function in the appropriate module format
|
|
25
|
+
* For ESM: export async function name() { }
|
|
26
|
+
* For CJS: async function name() { } (module.exports added at end)
|
|
27
|
+
*/
|
|
28
|
+
export function generateFunctionExportKeyword(moduleFormat) {
|
|
29
|
+
return moduleFormat === 'cjs' ? '' : 'export ';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generate module.exports statement for CJS format
|
|
33
|
+
*/
|
|
34
|
+
export function generateModuleExports(functionNames) {
|
|
35
|
+
if (functionNames.length === 1) {
|
|
36
|
+
return `module.exports = { ${functionNames[0]} };`;
|
|
37
|
+
}
|
|
38
|
+
return `module.exports = { ${functionNames.join(', ')} };`;
|
|
39
|
+
}
|
|
40
|
+
export function generateCode(ast, options) {
|
|
41
|
+
const { production = false, sourceMap = false, allWorkflows = [], moduleFormat = 'esm', externalRuntimePath, constants = [], externalNodeTypes = {}, } = options || {};
|
|
42
|
+
// Determine if workflow should be async based on node composition
|
|
43
|
+
const { shouldBeAsync, warning } = validateWorkflowAsync(ast, ast.nodeTypes);
|
|
44
|
+
if (warning && !production) {
|
|
45
|
+
console.warn(warning);
|
|
46
|
+
}
|
|
47
|
+
// Initialize source map generator if requested
|
|
48
|
+
let sourceMapGenerator;
|
|
49
|
+
let currentLine = 1;
|
|
50
|
+
if (sourceMap) {
|
|
51
|
+
sourceMapGenerator = new SourceMapGenerator({
|
|
52
|
+
file: `${ast.functionName}.generated.ts`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const addLine = () => {
|
|
56
|
+
currentLine++;
|
|
57
|
+
};
|
|
58
|
+
const addMapping = (sourceLine, sourceColumn = 0) => {
|
|
59
|
+
if (sourceMapGenerator && ast.sourceFile) {
|
|
60
|
+
sourceMapGenerator.addMapping({
|
|
61
|
+
generated: {
|
|
62
|
+
line: currentLine,
|
|
63
|
+
column: 0,
|
|
64
|
+
},
|
|
65
|
+
source: ast.sourceFile,
|
|
66
|
+
original: {
|
|
67
|
+
line: sourceLine,
|
|
68
|
+
column: sourceColumn,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// Generate function body using existing body generator
|
|
74
|
+
// Bundle mode uses params object pattern for node wrapper calls
|
|
75
|
+
const bundleMode = !!externalRuntimePath;
|
|
76
|
+
const functionBody = bodyGenerator.generateWithExecutionContext(ast, ast.nodeTypes, shouldBeAsync, production, bundleMode);
|
|
77
|
+
// Build the complete module
|
|
78
|
+
const lines = [];
|
|
79
|
+
lines.push('');
|
|
80
|
+
addLine();
|
|
81
|
+
lines.push('');
|
|
82
|
+
addLine();
|
|
83
|
+
// Include runtime (either inline or external import)
|
|
84
|
+
if (externalRuntimePath) {
|
|
85
|
+
// Import from external runtime module to avoid duplicate declarations in multi-file bundles
|
|
86
|
+
lines.push(`// Runtime imported from shared module`);
|
|
87
|
+
addLine();
|
|
88
|
+
lines.push(generateImportStatement(['GeneratedExecutionContext', 'CancellationError'], externalRuntimePath, moduleFormat));
|
|
89
|
+
addLine();
|
|
90
|
+
if (!production) {
|
|
91
|
+
lines.push(generateImportStatement(['TDebugger', 'createFlowWeaverDebugClient'], externalRuntimePath, moduleFormat));
|
|
92
|
+
addLine();
|
|
93
|
+
}
|
|
94
|
+
lines.push('');
|
|
95
|
+
addLine();
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Include inline runtime (types + GeneratedExecutionContext)
|
|
99
|
+
const inlineRuntime = generateInlineRuntime(production);
|
|
100
|
+
const runtimeLines = inlineRuntime.split('\n');
|
|
101
|
+
runtimeLines.forEach((line) => {
|
|
102
|
+
lines.push(line);
|
|
103
|
+
addLine();
|
|
104
|
+
});
|
|
105
|
+
lines.push('');
|
|
106
|
+
addLine();
|
|
107
|
+
// Include inline debug client (dev mode only)
|
|
108
|
+
if (!production) {
|
|
109
|
+
const inlineDebugClient = generateInlineDebugClient(moduleFormat);
|
|
110
|
+
const debugClientLines = inlineDebugClient.split('\n');
|
|
111
|
+
debugClientLines.forEach((line) => {
|
|
112
|
+
lines.push(line);
|
|
113
|
+
addLine();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Extract and include type declarations from source file (interfaces, type aliases)
|
|
118
|
+
if (ast.sourceFile) {
|
|
119
|
+
const extractedTypes = extractTypeDeclarationsFromFile(ast.sourceFile);
|
|
120
|
+
if (extractedTypes.all.length > 0) {
|
|
121
|
+
lines.push('');
|
|
122
|
+
addLine();
|
|
123
|
+
lines.push('// ============================================================================');
|
|
124
|
+
addLine();
|
|
125
|
+
lines.push('// Type Declarations (preserved from source)');
|
|
126
|
+
addLine();
|
|
127
|
+
lines.push('// ============================================================================');
|
|
128
|
+
addLine();
|
|
129
|
+
lines.push('');
|
|
130
|
+
addLine();
|
|
131
|
+
extractedTypes.all.forEach((typeDecl) => {
|
|
132
|
+
const typeDeclLines = typeDecl.split('\n');
|
|
133
|
+
typeDeclLines.forEach((line) => {
|
|
134
|
+
lines.push(line);
|
|
135
|
+
addLine();
|
|
136
|
+
});
|
|
137
|
+
lines.push('');
|
|
138
|
+
addLine();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Handle imported nodes — three categories:
|
|
143
|
+
// 1. npm package nodes (have importSource)
|
|
144
|
+
// 2. relative file imports (sourceLocation file differs from workflow source)
|
|
145
|
+
// 3. local nodes (same source file)
|
|
146
|
+
const npmPackageNodes = ast.nodeTypes.filter((n) => n.importSource);
|
|
147
|
+
const localNodes = ast.nodeTypes.filter((n) => !n.importSource && n.sourceLocation?.file === ast.sourceFile);
|
|
148
|
+
const importedNodes = ast.nodeTypes.filter((n) => !n.importSource && n.sourceLocation?.file !== ast.sourceFile);
|
|
149
|
+
if (importedNodes.length > 0 || npmPackageNodes.length > 0) {
|
|
150
|
+
// Separate FUNCTION imports (from source) vs IMPORTED_WORKFLOW imports (from generated)
|
|
151
|
+
// Store full node info to access expression property later
|
|
152
|
+
const functionImportsByFile = new Map();
|
|
153
|
+
const workflowImportsByFile = new Map();
|
|
154
|
+
importedNodes.forEach((node) => {
|
|
155
|
+
const sourceFile = node.sourceLocation?.file;
|
|
156
|
+
if (!sourceFile)
|
|
157
|
+
return;
|
|
158
|
+
if (node.variant === 'IMPORTED_WORKFLOW') {
|
|
159
|
+
if (!workflowImportsByFile.has(sourceFile)) {
|
|
160
|
+
workflowImportsByFile.set(sourceFile, []);
|
|
161
|
+
}
|
|
162
|
+
workflowImportsByFile.get(sourceFile)?.push(node.functionName);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
if (!functionImportsByFile.has(sourceFile)) {
|
|
166
|
+
functionImportsByFile.set(sourceFile, []);
|
|
167
|
+
}
|
|
168
|
+
functionImportsByFile.get(sourceFile)?.push(node);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
lines.push('');
|
|
172
|
+
addLine();
|
|
173
|
+
// Import regular node functions from source files
|
|
174
|
+
// In bundle mode (externalRuntimePath is set), import from node-types directory
|
|
175
|
+
// Otherwise import from .generated files in the same directory
|
|
176
|
+
functionImportsByFile.forEach((nodes, sourceFile) => {
|
|
177
|
+
if (externalRuntimePath) {
|
|
178
|
+
// Bundle mode: import from node-types directory
|
|
179
|
+
// Bundle mode: import _impl (positional data args for expression nodes, execute + data args for regular)
|
|
180
|
+
// The wrapper is only for HTTP entry points, not internal workflow calls
|
|
181
|
+
nodes.forEach((node) => {
|
|
182
|
+
const lowerName = node.functionName.toLowerCase();
|
|
183
|
+
const relativePath = `../node-types/${lowerName}.js`;
|
|
184
|
+
const importName = `${lowerName}_impl as ${node.functionName}`;
|
|
185
|
+
lines.push(generateImportStatement([importName], relativePath, moduleFormat));
|
|
186
|
+
addLine();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const sourceFileName = path.basename(sourceFile, '.ts');
|
|
191
|
+
const generatedFileName = sourceFileName + '.generated';
|
|
192
|
+
const relativePath = `./${generatedFileName}`;
|
|
193
|
+
const names = nodes.map((n) => n.functionName);
|
|
194
|
+
lines.push(generateImportStatement(names, relativePath, moduleFormat));
|
|
195
|
+
addLine();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
// Import workflows from their generated files
|
|
199
|
+
// In bundle mode, import from sibling workflow files
|
|
200
|
+
workflowImportsByFile.forEach((names, sourceFile) => {
|
|
201
|
+
if (externalRuntimePath) {
|
|
202
|
+
// Bundle mode: import each workflow from the workflows directory
|
|
203
|
+
names.forEach((name) => {
|
|
204
|
+
const relativePath = `./${name}.js`;
|
|
205
|
+
lines.push(generateImportStatement([name], relativePath, moduleFormat));
|
|
206
|
+
addLine();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const sourceFileName = path.basename(sourceFile, '.ts');
|
|
211
|
+
// For workflows, always import from generated file
|
|
212
|
+
// Add .generated suffix if not already present
|
|
213
|
+
const generatedFileName = sourceFileName.includes('.generated')
|
|
214
|
+
? sourceFileName
|
|
215
|
+
: sourceFileName + '.generated';
|
|
216
|
+
const relativePath = `./${generatedFileName}`;
|
|
217
|
+
lines.push(generateImportStatement(names, relativePath, moduleFormat));
|
|
218
|
+
addLine();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
// Import npm package functions directly from their package specifiers
|
|
222
|
+
if (npmPackageNodes.length > 0) {
|
|
223
|
+
const npmImportsByPackage = new Map();
|
|
224
|
+
npmPackageNodes.forEach((node) => {
|
|
225
|
+
const pkg = node.importSource;
|
|
226
|
+
if (!npmImportsByPackage.has(pkg))
|
|
227
|
+
npmImportsByPackage.set(pkg, []);
|
|
228
|
+
npmImportsByPackage.get(pkg).push(node.functionName);
|
|
229
|
+
});
|
|
230
|
+
npmImportsByPackage.forEach((names, pkg) => {
|
|
231
|
+
lines.push(generateImportStatement(names, pkg, moduleFormat));
|
|
232
|
+
addLine();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
lines.push('');
|
|
236
|
+
addLine();
|
|
237
|
+
}
|
|
238
|
+
// Separate local nodes into functions and workflows
|
|
239
|
+
const localFunctions = localNodes.filter((n) => n.variant !== 'IMPORTED_WORKFLOW');
|
|
240
|
+
// Only include workflows that are actually used as node instances in this workflow
|
|
241
|
+
// (not all sibling workflows in the same file)
|
|
242
|
+
const usedNodeTypeNames = new Set(ast.instances.map((i) => i.nodeType));
|
|
243
|
+
const localWorkflowNodes = localNodes.filter((n) => n.variant === 'IMPORTED_WORKFLOW' && usedNodeTypeNames.has(n.name));
|
|
244
|
+
// In bundle mode, local node functions are inlined directly
|
|
245
|
+
// They're not imported from node-types directory because:
|
|
246
|
+
// 1. They may not be in the bundled node types list
|
|
247
|
+
// 2. Scoped nodes need the scope function closure generated inline
|
|
248
|
+
// Constants that were extracted from source files are included before the functions
|
|
249
|
+
// Include constants from source files (needed for inlined local functions)
|
|
250
|
+
if (constants.length > 0 && localFunctions.length > 0) {
|
|
251
|
+
lines.push('');
|
|
252
|
+
addLine();
|
|
253
|
+
lines.push('// Constants from source file');
|
|
254
|
+
addLine();
|
|
255
|
+
constants.forEach((constant) => {
|
|
256
|
+
lines.push(constant);
|
|
257
|
+
const constLines = constant.split('\n');
|
|
258
|
+
constLines.forEach(() => addLine());
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
// Include local node functions (regular functions, not workflows)
|
|
262
|
+
// If externalNodeTypes is provided, generate imports instead of inlining
|
|
263
|
+
if (localFunctions.length > 0) {
|
|
264
|
+
// Separate into external (import) and inline
|
|
265
|
+
const externalFunctions = localFunctions.filter((n) => externalNodeTypes[n.name]);
|
|
266
|
+
const inlineFunctions = localFunctions.filter((n) => !externalNodeTypes[n.name]);
|
|
267
|
+
// Generate imports for external node types
|
|
268
|
+
if (externalFunctions.length > 0) {
|
|
269
|
+
lines.push('');
|
|
270
|
+
addLine();
|
|
271
|
+
externalFunctions.forEach((node) => {
|
|
272
|
+
const importPath = externalNodeTypes[node.name];
|
|
273
|
+
const lowerFunctionName = node.functionName.toLowerCase();
|
|
274
|
+
// Bundle mode: import _impl (positional data args for expression nodes, execute + data args for regular)
|
|
275
|
+
// The wrapper is only for HTTP entry points, not internal workflow calls
|
|
276
|
+
const importName = `${lowerFunctionName}_impl as ${node.functionName}`;
|
|
277
|
+
const importStatement = generateImportStatement([importName], importPath, moduleFormat);
|
|
278
|
+
lines.push(importStatement);
|
|
279
|
+
addLine();
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// Inline functions not in externalNodeTypes
|
|
283
|
+
if (inlineFunctions.length > 0) {
|
|
284
|
+
lines.push('');
|
|
285
|
+
addLine();
|
|
286
|
+
inlineFunctions.forEach((node) => {
|
|
287
|
+
if (node.importSource)
|
|
288
|
+
return; // Never inline npm package functions
|
|
289
|
+
const functionText = node.functionText;
|
|
290
|
+
if (functionText) {
|
|
291
|
+
const functionWithoutDecorators = removeDecorators(functionText);
|
|
292
|
+
// Add source mapping for the node function
|
|
293
|
+
if (node.sourceLocation) {
|
|
294
|
+
addMapping(node.sourceLocation.line, node.sourceLocation.column);
|
|
295
|
+
}
|
|
296
|
+
lines.push(functionWithoutDecorators);
|
|
297
|
+
const functionLines = functionWithoutDecorators.split('\n');
|
|
298
|
+
functionLines.forEach(() => addLine());
|
|
299
|
+
lines.push('');
|
|
300
|
+
addLine();
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Generate local workflow dependencies (workflows used as nodes in the same file)
|
|
306
|
+
const generatedWorkflows = new Set();
|
|
307
|
+
generatedWorkflows.add(ast.functionName); // Don't regenerate the main workflow
|
|
308
|
+
if (localWorkflowNodes.length > 0 && allWorkflows.length > 0) {
|
|
309
|
+
lines.push('');
|
|
310
|
+
addLine();
|
|
311
|
+
lines.push('// ============================================================================');
|
|
312
|
+
addLine();
|
|
313
|
+
lines.push('// Local Workflow Dependencies');
|
|
314
|
+
addLine();
|
|
315
|
+
lines.push('// ============================================================================');
|
|
316
|
+
addLine();
|
|
317
|
+
for (const node of localWorkflowNodes) {
|
|
318
|
+
if (generatedWorkflows.has(node.functionName)) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
// Find the workflow AST for this node
|
|
322
|
+
const depWorkflow = allWorkflows.find((w) => w.functionName === node.functionName);
|
|
323
|
+
if (!depWorkflow) {
|
|
324
|
+
lines.push(`// WARNING: Could not find workflow AST for ${node.functionName}`);
|
|
325
|
+
addLine();
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
// Generate the workflow function (without module wrapper)
|
|
329
|
+
const depFunctionCode = generateWorkflowFunction(depWorkflow, production, allWorkflows, generatedWorkflows);
|
|
330
|
+
const depLines = depFunctionCode.split('\n');
|
|
331
|
+
depLines.forEach((line) => {
|
|
332
|
+
lines.push(line);
|
|
333
|
+
addLine();
|
|
334
|
+
});
|
|
335
|
+
lines.push('');
|
|
336
|
+
addLine();
|
|
337
|
+
generatedWorkflows.add(node.functionName);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// Generate workflow function signature
|
|
341
|
+
const startPorts = extractStartPorts(ast);
|
|
342
|
+
const exitPorts = extractExitPorts(ast);
|
|
343
|
+
lines.push('');
|
|
344
|
+
addLine();
|
|
345
|
+
// Add source mapping for the workflow export function
|
|
346
|
+
if (sourceMapGenerator && ast.sourceFile) {
|
|
347
|
+
try {
|
|
348
|
+
const sourceContent = fs.readFileSync(ast.sourceFile, 'utf-8');
|
|
349
|
+
const sourceLines = sourceContent.split('\n');
|
|
350
|
+
const exportLineIndex = sourceLines.findIndex((line) => line.includes(`export`) && line.includes(`function ${ast.functionName}`));
|
|
351
|
+
if (exportLineIndex >= 0) {
|
|
352
|
+
addMapping(exportLineIndex + 1, 0); // Line numbers are 1-indexed
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
// If we can't find the source line, skip the mapping
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
// Generate conditional async keyword and export keyword based on module format
|
|
360
|
+
const asyncKeyword = shouldBeAsync ? 'async ' : '';
|
|
361
|
+
const exportKeyword = generateFunctionExportKeyword(moduleFormat);
|
|
362
|
+
lines.push(`${exportKeyword}${asyncKeyword}function ${ast.functionName}(`);
|
|
363
|
+
addLine();
|
|
364
|
+
// STEP Port Architecture: execute is first parameter
|
|
365
|
+
lines.push(` execute: boolean = true,`);
|
|
366
|
+
addLine();
|
|
367
|
+
// Collect param names and types for destructuring
|
|
368
|
+
const paramEntries = [];
|
|
369
|
+
Object.entries(startPorts).forEach(([portName, portDef]) => {
|
|
370
|
+
if (isExecutePort(portName))
|
|
371
|
+
return;
|
|
372
|
+
paramEntries.push({
|
|
373
|
+
name: portName,
|
|
374
|
+
type: mapToTypeScript(portDef.dataType, portDef.tsType),
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
// Use Record<string, unknown> for params to support HTTP handler compatibility
|
|
378
|
+
lines.push(` params: Record<string, unknown> = {},`);
|
|
379
|
+
addLine();
|
|
380
|
+
// In development mode, accept optional debugger parameter for local debugging
|
|
381
|
+
// (environment variable is used as fallback)
|
|
382
|
+
if (!production) {
|
|
383
|
+
lines.push(` __flowWeaverDebugger__?: TDebugger,`);
|
|
384
|
+
addLine();
|
|
385
|
+
}
|
|
386
|
+
// Accept optional AbortSignal for cancellation support
|
|
387
|
+
lines.push(` __abortSignal__?: AbortSignal`);
|
|
388
|
+
addLine();
|
|
389
|
+
addLine();
|
|
390
|
+
const workflowHasBranching = hasBranching(ast);
|
|
391
|
+
const returnTypes = [];
|
|
392
|
+
Object.entries(exitPorts).forEach(([portName, portDef]) => {
|
|
393
|
+
const optional = workflowHasBranching ? '?' : '';
|
|
394
|
+
const tsType = mapToTypeScript(portDef.dataType, portDef.tsType);
|
|
395
|
+
returnTypes.push(`${portName}${optional}: ${tsType}`);
|
|
396
|
+
});
|
|
397
|
+
// Generate conditional return type (Promise vs direct)
|
|
398
|
+
const returnTypeInner = `{ ${returnTypes.join('; ')} }`;
|
|
399
|
+
const returnType = shouldBeAsync ? `Promise<${returnTypeInner}>` : returnTypeInner;
|
|
400
|
+
lines.push(`): ${returnType} {`);
|
|
401
|
+
addLine();
|
|
402
|
+
// NOTE: We intentionally don't destructure params here.
|
|
403
|
+
// The body generator uses ctx.getVariable to access Start ports, and
|
|
404
|
+
// destructuring would shadow local node functions with the same name
|
|
405
|
+
// (e.g., a 'delay' param would shadow a 'delay' node function).
|
|
406
|
+
// Add function body
|
|
407
|
+
const bodyLines = functionBody.split('\n');
|
|
408
|
+
bodyLines.forEach((line) => {
|
|
409
|
+
lines.push(line);
|
|
410
|
+
addLine();
|
|
411
|
+
});
|
|
412
|
+
lines.push('}');
|
|
413
|
+
addLine();
|
|
414
|
+
// For CJS format, add module.exports at the end
|
|
415
|
+
if (moduleFormat === 'cjs') {
|
|
416
|
+
lines.push('');
|
|
417
|
+
addLine();
|
|
418
|
+
lines.push(generateModuleExports([ast.functionName]));
|
|
419
|
+
addLine();
|
|
420
|
+
}
|
|
421
|
+
const code = lines.join('\n');
|
|
422
|
+
// Set source content for the source map
|
|
423
|
+
if (sourceMapGenerator && ast.sourceFile) {
|
|
424
|
+
const sourceContent = fs.readFileSync(ast.sourceFile, 'utf8');
|
|
425
|
+
sourceMapGenerator.setSourceContent(ast.sourceFile, sourceContent);
|
|
426
|
+
}
|
|
427
|
+
// Return result with source map if requested
|
|
428
|
+
if (sourceMap && sourceMapGenerator) {
|
|
429
|
+
return {
|
|
430
|
+
code,
|
|
431
|
+
sourceMap: sourceMapGenerator.toString(),
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
return code;
|
|
435
|
+
}
|
|
436
|
+
function removeDecorators(functionText) {
|
|
437
|
+
return functionText.replace(/@\w+\({[\s\S]*?}\)\s*/g, '');
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Generate just the workflow function (no module wrapper)
|
|
441
|
+
* Used for local workflow dependencies
|
|
442
|
+
*/
|
|
443
|
+
function generateWorkflowFunction(workflow, production, allWorkflows, generatedWorkflows) {
|
|
444
|
+
const lines = [];
|
|
445
|
+
// Mark this workflow as generated FIRST to prevent infinite recursion
|
|
446
|
+
// (a workflow may reference itself in nodeTypes)
|
|
447
|
+
generatedWorkflows.add(workflow.functionName);
|
|
448
|
+
// Find local workflow dependencies (other workflows in same file actually used as nodes)
|
|
449
|
+
const usedNodeTypeNames = new Set(workflow.instances.map((i) => i.nodeType));
|
|
450
|
+
const localWorkflowDeps = workflow.nodeTypes.filter((n) => n.variant === 'IMPORTED_WORKFLOW' &&
|
|
451
|
+
n.sourceLocation?.file === workflow.sourceFile &&
|
|
452
|
+
usedNodeTypeNames.has(n.name) &&
|
|
453
|
+
!generatedWorkflows.has(n.functionName));
|
|
454
|
+
for (const dep of localWorkflowDeps) {
|
|
455
|
+
const depWorkflow = allWorkflows.find((w) => w.functionName === dep.functionName);
|
|
456
|
+
if (depWorkflow) {
|
|
457
|
+
const depCode = generateWorkflowFunction(depWorkflow, production, allWorkflows, generatedWorkflows);
|
|
458
|
+
lines.push(depCode);
|
|
459
|
+
lines.push('');
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
// Determine if workflow should be async
|
|
463
|
+
const { shouldBeAsync } = validateWorkflowAsync(workflow, workflow.nodeTypes);
|
|
464
|
+
// Generate function body (local dependencies always use non-bundle mode)
|
|
465
|
+
const functionBody = bodyGenerator.generateWithExecutionContext(workflow, workflow.nodeTypes, shouldBeAsync, production, false // bundleMode - local deps use positional args
|
|
466
|
+
);
|
|
467
|
+
// Generate function signature
|
|
468
|
+
const startPorts = extractStartPorts(workflow);
|
|
469
|
+
const exitPorts = extractExitPorts(workflow);
|
|
470
|
+
const asyncKeyword = shouldBeAsync ? 'async ' : '';
|
|
471
|
+
lines.push(`${asyncKeyword}function ${workflow.functionName}(`);
|
|
472
|
+
// STEP Port Architecture: execute is first parameter
|
|
473
|
+
lines.push(` execute: boolean = true,`);
|
|
474
|
+
// Collect param names and types for destructuring
|
|
475
|
+
const paramEntries = [];
|
|
476
|
+
Object.entries(startPorts).forEach(([portName, portDef]) => {
|
|
477
|
+
if (isExecutePort(portName))
|
|
478
|
+
return;
|
|
479
|
+
paramEntries.push({
|
|
480
|
+
name: portName,
|
|
481
|
+
type: mapToTypeScript(portDef.dataType, portDef.tsType),
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
// Use Record<string, unknown> for params to support HTTP handler compatibility
|
|
485
|
+
lines.push(` params: Record<string, unknown> = {},`);
|
|
486
|
+
// In development mode, accept optional debugger parameter
|
|
487
|
+
if (!production) {
|
|
488
|
+
lines.push(` __flowWeaverDebugger__?: TDebugger,`);
|
|
489
|
+
}
|
|
490
|
+
// Accept optional AbortSignal for cancellation support
|
|
491
|
+
lines.push(` __abortSignal__?: AbortSignal`);
|
|
492
|
+
const workflowHasBranching = hasBranching(workflow);
|
|
493
|
+
const returnTypes = [];
|
|
494
|
+
Object.entries(exitPorts).forEach(([portName, portDef]) => {
|
|
495
|
+
const optional = workflowHasBranching ? '?' : '';
|
|
496
|
+
const tsType = mapToTypeScript(portDef.dataType, portDef.tsType);
|
|
497
|
+
returnTypes.push(`${portName}${optional}: ${tsType}`);
|
|
498
|
+
});
|
|
499
|
+
const returnTypeInner = `{ ${returnTypes.join('; ')} }`;
|
|
500
|
+
const returnType = shouldBeAsync ? `Promise<${returnTypeInner}>` : returnTypeInner;
|
|
501
|
+
lines.push(`): ${returnType} {`);
|
|
502
|
+
// NOTE: We intentionally don't destructure params here.
|
|
503
|
+
// The body generator uses ctx.getVariable to access Start ports, and
|
|
504
|
+
// destructuring would shadow local node functions with the same name.
|
|
505
|
+
// Add function body
|
|
506
|
+
lines.push(functionBody);
|
|
507
|
+
lines.push('}');
|
|
508
|
+
return lines.join('\n');
|
|
509
|
+
}
|
|
510
|
+
//# sourceMappingURL=generate.js.map
|