@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,294 @@
|
|
|
1
|
+
import { LLM_SIMPLE_TYPES } from '../shared/llm-types.js';
|
|
2
|
+
export const aiReactTemplate = {
|
|
3
|
+
id: 'ai-react',
|
|
4
|
+
name: 'ReAct Agent',
|
|
5
|
+
description: 'Reasoning + Acting agent with explicit thought process',
|
|
6
|
+
category: 'ai',
|
|
7
|
+
generate: (opts) => {
|
|
8
|
+
const { workflowName } = opts;
|
|
9
|
+
return `
|
|
10
|
+
// ============================================================
|
|
11
|
+
// ReAct Agent — Thought → Action → Observation loop
|
|
12
|
+
// ============================================================
|
|
13
|
+
//
|
|
14
|
+
// The agent follows the ReAct pattern (Yao et al., 2022):
|
|
15
|
+
// 1. Think — reason about the current state
|
|
16
|
+
// 2. Act — call a tool or FINISH
|
|
17
|
+
// 3. Observe — receive tool output, feed back into next thought
|
|
18
|
+
//
|
|
19
|
+
// The reactLoop node manages iteration and message accumulation.
|
|
20
|
+
// think + act run inside the loop's scoped iteration.
|
|
21
|
+
|
|
22
|
+
// ============================================================
|
|
23
|
+
// LLM TYPES
|
|
24
|
+
// ============================================================
|
|
25
|
+
|
|
26
|
+
${LLM_SIMPLE_TYPES}
|
|
27
|
+
|
|
28
|
+
// Mock provider — replace with real provider
|
|
29
|
+
const createMockReactProvider = (): LLMProvider => ({
|
|
30
|
+
async chat(messages) {
|
|
31
|
+
const lastMessage = messages[messages.length - 1];
|
|
32
|
+
return {
|
|
33
|
+
content: \`Thought: Processing the request\\nAction: FINISH\\nAction Input: [Mock answer to: \${lastMessage.content.slice(0, 30)}...]\`,
|
|
34
|
+
toolCalls: [],
|
|
35
|
+
finishReason: 'stop',
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const llmProvider: LLMProvider = (globalThis as unknown as { __fw_llm_provider__?: LLMProvider }).__fw_llm_provider__ ?? createMockReactProvider();
|
|
41
|
+
const MAX_STEPS = 10;
|
|
42
|
+
|
|
43
|
+
const REACT_PROMPT = \`You are a ReAct (Reasoning + Acting) agent.
|
|
44
|
+
|
|
45
|
+
For each step, you MUST respond in this exact format:
|
|
46
|
+
Thought: [Your reasoning about what to do next]
|
|
47
|
+
Action: [tool_name] or [FINISH]
|
|
48
|
+
Action Input: [input for the tool, or final answer if FINISH]
|
|
49
|
+
|
|
50
|
+
Available tools: search, calculate
|
|
51
|
+
|
|
52
|
+
When you have the final answer:
|
|
53
|
+
Thought: I now have enough information to answer
|
|
54
|
+
Action: FINISH
|
|
55
|
+
Action Input: [Your final answer here]\`;
|
|
56
|
+
|
|
57
|
+
// Parse ReAct response format
|
|
58
|
+
function parseReactResponse(content: string): {
|
|
59
|
+
thought: string;
|
|
60
|
+
action: string;
|
|
61
|
+
actionInput: string;
|
|
62
|
+
} {
|
|
63
|
+
const thoughtMatch = content.match(/Thought:\\s*(.+?)(?=\\nAction:|$)/s);
|
|
64
|
+
const actionMatch = content.match(/Action:\\s*(.+?)(?=\\nAction Input:|$)/s);
|
|
65
|
+
const inputMatch = content.match(/Action Input:\\s*(.+?)$/s);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
thought: thoughtMatch?.[1]?.trim() ?? '',
|
|
69
|
+
action: actionMatch?.[1]?.trim() ?? 'FINISH',
|
|
70
|
+
actionInput: inputMatch?.[1]?.trim() ?? '',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============================================================
|
|
75
|
+
// TOOL IMPLEMENTATIONS
|
|
76
|
+
// ============================================================
|
|
77
|
+
|
|
78
|
+
// Replace with real tools
|
|
79
|
+
const TOOL_IMPLEMENTATIONS: Record<string, (input: string) => Promise<string>> = {
|
|
80
|
+
async search(input: string): Promise<string> {
|
|
81
|
+
return '[Search results for: ' + input + ']';
|
|
82
|
+
},
|
|
83
|
+
async calculate(input: string): Promise<string> {
|
|
84
|
+
return '[Calculation result for: ' + input + ']';
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// ============================================================
|
|
89
|
+
// NODES
|
|
90
|
+
// ============================================================
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* ReAct loop — manages Think→Act→Observe iterations.
|
|
94
|
+
* Accumulates messages and terminates when action is FINISH or max steps.
|
|
95
|
+
*
|
|
96
|
+
* @flowWeaver nodeType
|
|
97
|
+
* @label ReAct Loop
|
|
98
|
+
* @input execute [order:0] - Execute
|
|
99
|
+
* @input task [order:1] - Task for the agent
|
|
100
|
+
* @input success scope:step [order:0] - Iteration succeeded
|
|
101
|
+
* @input failure scope:step [order:1] - Iteration failed
|
|
102
|
+
* @input thought scope:step [order:2] - Agent's reasoning
|
|
103
|
+
* @input action scope:step [order:3] - Action name
|
|
104
|
+
* @input actionInput scope:step [order:4] - Action input / final answer
|
|
105
|
+
* @input observation scope:step [order:5] - Tool observation
|
|
106
|
+
* @output onSuccess [order:0] - On Success (finished)
|
|
107
|
+
* @output onFailure [order:1] - On Failure
|
|
108
|
+
* @output start scope:step [order:0] - Triggers iteration
|
|
109
|
+
* @output messages scope:step [order:1] - Current messages for LLM
|
|
110
|
+
* @output answer [order:2] - Final answer
|
|
111
|
+
*/
|
|
112
|
+
async function reactLoop(
|
|
113
|
+
execute: boolean,
|
|
114
|
+
task: string,
|
|
115
|
+
step: (start: boolean, messages: LLMMessage[]) => Promise<{
|
|
116
|
+
success: boolean;
|
|
117
|
+
failure: boolean;
|
|
118
|
+
thought: string;
|
|
119
|
+
action: string;
|
|
120
|
+
actionInput: string;
|
|
121
|
+
observation: string;
|
|
122
|
+
}>
|
|
123
|
+
): Promise<{ onSuccess: boolean; onFailure: boolean; answer: string }> {
|
|
124
|
+
if (!execute) {
|
|
125
|
+
return { onSuccess: false, onFailure: false, answer: '' };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const messages: LLMMessage[] = [{ role: 'user', content: task }];
|
|
129
|
+
|
|
130
|
+
for (let i = 0; i < MAX_STEPS; i++) {
|
|
131
|
+
const result = await step(true, messages);
|
|
132
|
+
|
|
133
|
+
if (result.failure) {
|
|
134
|
+
return { onSuccess: false, onFailure: true, answer: '' };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Append thought + action as assistant message
|
|
138
|
+
messages.push({
|
|
139
|
+
role: 'assistant',
|
|
140
|
+
content: \`Thought: \${result.thought}\\nAction: \${result.action}\\nAction Input: \${result.actionInput}\`,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Check termination
|
|
144
|
+
if (result.action.toUpperCase() === 'FINISH') {
|
|
145
|
+
return { onSuccess: true, onFailure: false, answer: result.actionInput };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Append observation
|
|
149
|
+
if (result.observation) {
|
|
150
|
+
messages.push({ role: 'user', content: \`Observation: \${result.observation}\` });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return { onSuccess: true, onFailure: false, answer: 'Max steps reached' };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* ReAct reasoning step — calls LLM and parses Thought/Action/ActionInput
|
|
159
|
+
*
|
|
160
|
+
* @flowWeaver nodeType
|
|
161
|
+
* @label Think
|
|
162
|
+
* @input execute [order:0] - Execute
|
|
163
|
+
* @input messages [order:1] - Conversation history
|
|
164
|
+
* @output onSuccess [order:0] - On Success
|
|
165
|
+
* @output onFailure [order:1] - On Failure
|
|
166
|
+
* @output thought [order:2] - Agent's reasoning
|
|
167
|
+
* @output action [order:3] - Action to take (tool name or FINISH)
|
|
168
|
+
* @output actionInput [order:4] - Input for action or final answer
|
|
169
|
+
*/
|
|
170
|
+
async function think(
|
|
171
|
+
execute: boolean,
|
|
172
|
+
messages: LLMMessage[]
|
|
173
|
+
): Promise<{
|
|
174
|
+
onSuccess: boolean;
|
|
175
|
+
onFailure: boolean;
|
|
176
|
+
thought: string;
|
|
177
|
+
action: string;
|
|
178
|
+
actionInput: string;
|
|
179
|
+
}> {
|
|
180
|
+
if (!execute) {
|
|
181
|
+
return { onSuccess: false, onFailure: false, thought: '', action: '', actionInput: '' };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const response = await llmProvider.chat(messages, { systemPrompt: REACT_PROMPT });
|
|
186
|
+
const parsed = parseReactResponse(response.content ?? '');
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
onSuccess: true,
|
|
190
|
+
onFailure: false,
|
|
191
|
+
thought: parsed.thought,
|
|
192
|
+
action: parsed.action,
|
|
193
|
+
actionInput: parsed.actionInput,
|
|
194
|
+
};
|
|
195
|
+
} catch {
|
|
196
|
+
return { onSuccess: false, onFailure: true, thought: '', action: '', actionInput: '' };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Execute action and return observation
|
|
202
|
+
*
|
|
203
|
+
* @flowWeaver nodeType
|
|
204
|
+
* @label Act
|
|
205
|
+
* @input execute [order:0] - Execute
|
|
206
|
+
* @input action [order:1] - Tool name to execute
|
|
207
|
+
* @input actionInput [order:2] - Input for tool
|
|
208
|
+
* @output onSuccess [order:0] - On Success
|
|
209
|
+
* @output onFailure [order:1] - On Failure
|
|
210
|
+
* @output observation [order:2] - Tool observation result
|
|
211
|
+
*/
|
|
212
|
+
async function act(
|
|
213
|
+
execute: boolean,
|
|
214
|
+
action: string,
|
|
215
|
+
actionInput: string
|
|
216
|
+
): Promise<{
|
|
217
|
+
onSuccess: boolean;
|
|
218
|
+
onFailure: boolean;
|
|
219
|
+
observation: string;
|
|
220
|
+
}> {
|
|
221
|
+
if (!execute) {
|
|
222
|
+
return { onSuccess: false, onFailure: false, observation: '' };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const tool = TOOL_IMPLEMENTATIONS[action.toLowerCase()];
|
|
226
|
+
if (!tool) {
|
|
227
|
+
return {
|
|
228
|
+
onSuccess: true,
|
|
229
|
+
onFailure: false,
|
|
230
|
+
observation: 'Unknown tool: ' + action,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const observation = await tool(actionInput);
|
|
236
|
+
return { onSuccess: true, onFailure: false, observation };
|
|
237
|
+
} catch (error) {
|
|
238
|
+
return { onSuccess: false, onFailure: true, observation: '' };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ============================================================
|
|
243
|
+
// WORKFLOW
|
|
244
|
+
// ============================================================
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* ReAct Agent — iterative Thought→Action→Observation loop
|
|
248
|
+
*
|
|
249
|
+
* @flowWeaver workflow
|
|
250
|
+
* @node loop reactLoop [size: 450 250]
|
|
251
|
+
* @node thinking think loop.step
|
|
252
|
+
* @node acting act loop.step
|
|
253
|
+
* @position Start -400 0
|
|
254
|
+
* @position loop -150 0
|
|
255
|
+
* @position thinking -80 30
|
|
256
|
+
* @position acting 130 30
|
|
257
|
+
* @position Exit 350 0
|
|
258
|
+
* @connect Start.execute -> loop.execute
|
|
259
|
+
* @connect Start.task -> loop.task
|
|
260
|
+
* @connect loop.start -> thinking.execute
|
|
261
|
+
* @connect loop.messages -> thinking.messages
|
|
262
|
+
* @connect thinking.onSuccess -> acting.execute
|
|
263
|
+
* @connect thinking.action -> acting.action
|
|
264
|
+
* @connect thinking.actionInput -> acting.actionInput
|
|
265
|
+
* @connect thinking.thought -> loop.thought
|
|
266
|
+
* @connect thinking.action -> loop.action
|
|
267
|
+
* @connect thinking.actionInput -> loop.actionInput
|
|
268
|
+
* @connect thinking.onFailure -> loop.failure
|
|
269
|
+
* @connect acting.observation -> loop.observation
|
|
270
|
+
* @connect acting.onSuccess -> loop.success
|
|
271
|
+
* @connect acting.onFailure -> loop.failure
|
|
272
|
+
* @connect loop.onSuccess -> Exit.onSuccess
|
|
273
|
+
* @connect loop.onFailure -> Exit.onFailure
|
|
274
|
+
* @connect loop.answer -> Exit.answer
|
|
275
|
+
* @param execute [order:0] - Execute
|
|
276
|
+
* @param task [order:1] - Task for the agent
|
|
277
|
+
* @returns onSuccess [order:0] - On Success
|
|
278
|
+
* @returns onFailure [order:1] - On Failure
|
|
279
|
+
* @returns answer [order:2] - Final answer
|
|
280
|
+
*/
|
|
281
|
+
export async function ${workflowName}(
|
|
282
|
+
execute: boolean,
|
|
283
|
+
params: { task: string }
|
|
284
|
+
): Promise<{
|
|
285
|
+
onSuccess: boolean;
|
|
286
|
+
onFailure: boolean;
|
|
287
|
+
answer: string;
|
|
288
|
+
}> {
|
|
289
|
+
throw new Error('Compile with: flow-weaver compile <file>');
|
|
290
|
+
}
|
|
291
|
+
`.trim();
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
//# sourceMappingURL=ai-react.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional Router Template
|
|
3
|
+
* Decision branching with success/failure paths
|
|
4
|
+
*
|
|
5
|
+
* Design: evaluateCondition uses onSuccess for "condition met" and
|
|
6
|
+
* onFailure for "condition not met". Error handling is done inside
|
|
7
|
+
* the function body via try/catch — errors route to Exit.onFailure
|
|
8
|
+
* via the handler chain.
|
|
9
|
+
*/
|
|
10
|
+
import type { WorkflowTemplate } from '../index.js';
|
|
11
|
+
export declare const conditionalTemplate: WorkflowTemplate;
|
|
12
|
+
//# sourceMappingURL=conditional.d.ts.map
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditional Router Template
|
|
3
|
+
* Decision branching with success/failure paths
|
|
4
|
+
*
|
|
5
|
+
* Design: evaluateCondition uses onSuccess for "condition met" and
|
|
6
|
+
* onFailure for "condition not met". Error handling is done inside
|
|
7
|
+
* the function body via try/catch — errors route to Exit.onFailure
|
|
8
|
+
* via the handler chain.
|
|
9
|
+
*/
|
|
10
|
+
export const conditionalTemplate = {
|
|
11
|
+
id: 'conditional',
|
|
12
|
+
name: 'Conditional Router',
|
|
13
|
+
description: 'Route data based on conditions with branching paths',
|
|
14
|
+
category: 'automation',
|
|
15
|
+
generate: (opts) => {
|
|
16
|
+
const { workflowName, async: isAsync } = opts;
|
|
17
|
+
const asyncKeyword = isAsync ? 'async ' : '';
|
|
18
|
+
const returnType = isAsync
|
|
19
|
+
? 'Promise<{ onSuccess: boolean; onFailure: boolean; successResult?: any; failureResult?: any }>'
|
|
20
|
+
: '{ onSuccess: boolean; onFailure: boolean; successResult?: any; failureResult?: any }';
|
|
21
|
+
return `
|
|
22
|
+
/**
|
|
23
|
+
* Evaluates condition and routes data.
|
|
24
|
+
* onSuccess = condition met (true path), onFailure = condition not met (false path).
|
|
25
|
+
* Errors are caught internally and returned via the onFailure path.
|
|
26
|
+
*
|
|
27
|
+
* @flowWeaver nodeType
|
|
28
|
+
* @label Evaluate Condition
|
|
29
|
+
* @input data [order:1] - Data to evaluate
|
|
30
|
+
* @input execute [order:0] - Execute
|
|
31
|
+
* @output conditionTrue [order:2] - Data if condition passed
|
|
32
|
+
* @output conditionFalse [order:3] - Data if condition failed
|
|
33
|
+
* @output conditionMet [order:4] - Whether condition was met
|
|
34
|
+
* @output onSuccess [order:0] - Condition passed (routes to success handler)
|
|
35
|
+
* @output onFailure [order:1] - Condition not met (routes to failure handler)
|
|
36
|
+
*/
|
|
37
|
+
function evaluateCondition(
|
|
38
|
+
execute: boolean,
|
|
39
|
+
data: any
|
|
40
|
+
): { onSuccess: boolean; onFailure: boolean; conditionTrue: any; conditionFalse: any; conditionMet: boolean } {
|
|
41
|
+
if (!execute) {
|
|
42
|
+
return { onSuccess: false, onFailure: false, conditionTrue: null, conditionFalse: null, conditionMet: false };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
// TODO: Define your condition logic
|
|
47
|
+
const conditionMet = Boolean(data && data.isValid);
|
|
48
|
+
|
|
49
|
+
if (conditionMet) {
|
|
50
|
+
return { onSuccess: true, onFailure: false, conditionTrue: data, conditionFalse: null, conditionMet: true };
|
|
51
|
+
} else {
|
|
52
|
+
return { onSuccess: false, onFailure: true, conditionTrue: null, conditionFalse: data, conditionMet: false };
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// On error, route to failure path with the original data
|
|
56
|
+
return { onSuccess: false, onFailure: true, conditionTrue: null, conditionFalse: data, conditionMet: false };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Handles success path
|
|
62
|
+
*
|
|
63
|
+
* @flowWeaver nodeType
|
|
64
|
+
* @label Handle Success
|
|
65
|
+
* @input data [order:1] - Data from success path
|
|
66
|
+
* @input execute [order:0] - Execute
|
|
67
|
+
* @output result [order:2] - Success result
|
|
68
|
+
* @output onSuccess [order:0] - On Success
|
|
69
|
+
* @output onFailure [order:1] - On Failure
|
|
70
|
+
*/
|
|
71
|
+
function handleSuccess(
|
|
72
|
+
execute: boolean,
|
|
73
|
+
data: any
|
|
74
|
+
): { onSuccess: boolean; onFailure: boolean; result: any } {
|
|
75
|
+
if (!execute) {
|
|
76
|
+
return { onSuccess: false, onFailure: false, result: null };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// TODO: Handle success case
|
|
80
|
+
return { onSuccess: true, onFailure: false, result: { status: "success", data } };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Handles failure path
|
|
85
|
+
*
|
|
86
|
+
* @flowWeaver nodeType
|
|
87
|
+
* @label Handle Failure
|
|
88
|
+
* @input data [order:1] - Data from failure path
|
|
89
|
+
* @input execute [order:0] - Execute
|
|
90
|
+
* @output result [order:2] - Failure result
|
|
91
|
+
* @output onSuccess [order:0] - On Success
|
|
92
|
+
* @output onFailure [order:1] - On Failure
|
|
93
|
+
*/
|
|
94
|
+
function handleFailure(
|
|
95
|
+
execute: boolean,
|
|
96
|
+
data: any
|
|
97
|
+
): { onSuccess: boolean; onFailure: boolean; result: any } {
|
|
98
|
+
if (!execute) {
|
|
99
|
+
return { onSuccess: false, onFailure: false, result: null };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// TODO: Handle failure case
|
|
103
|
+
return { onSuccess: true, onFailure: false, result: { status: "failure", data } };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @flowWeaver workflow
|
|
108
|
+
* @node router evaluateCondition
|
|
109
|
+
* @node successHandler handleSuccess
|
|
110
|
+
* @node failureHandler handleFailure
|
|
111
|
+
* @position Start -450 0
|
|
112
|
+
* @position router -180 0
|
|
113
|
+
* @position successHandler 90 -90
|
|
114
|
+
* @position failureHandler 90 90
|
|
115
|
+
* @position Exit 360 0
|
|
116
|
+
* @connect Start.execute -> router.execute
|
|
117
|
+
* @connect Start.data -> router.data
|
|
118
|
+
* @connect router.onSuccess -> successHandler.execute
|
|
119
|
+
* @connect router.conditionTrue -> successHandler.data
|
|
120
|
+
* @connect router.onFailure -> failureHandler.execute
|
|
121
|
+
* @connect router.conditionFalse -> failureHandler.data
|
|
122
|
+
* @connect successHandler.result -> Exit.successResult
|
|
123
|
+
* @connect successHandler.onSuccess -> Exit.onSuccess
|
|
124
|
+
* @connect failureHandler.result -> Exit.failureResult
|
|
125
|
+
* @connect failureHandler.onSuccess -> Exit.onFailure
|
|
126
|
+
* @param execute [order:0] - Execute
|
|
127
|
+
* @param data [order:1] - Input data to route
|
|
128
|
+
* @returns onSuccess [order:0] - Success path completed
|
|
129
|
+
* @returns onFailure [order:1] - Failure path completed
|
|
130
|
+
* @returns successResult [order:2] - Result from success path
|
|
131
|
+
* @returns failureResult [order:3] - Result from failure path
|
|
132
|
+
*/
|
|
133
|
+
export ${asyncKeyword}function ${workflowName}(
|
|
134
|
+
execute: boolean,
|
|
135
|
+
params: { data: any }
|
|
136
|
+
): ${returnType} {
|
|
137
|
+
throw new Error("Compile with: flow-weaver compile <file>");
|
|
138
|
+
}
|
|
139
|
+
`.trim();
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=conditional.js.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handler Template
|
|
3
|
+
* Try/catch/retry pattern for robust error handling
|
|
4
|
+
*/
|
|
5
|
+
export const errorHandlerTemplate = {
|
|
6
|
+
id: 'error-handler',
|
|
7
|
+
name: 'Error Handler',
|
|
8
|
+
description: 'Try/catch/retry pattern with error recovery',
|
|
9
|
+
category: 'utility',
|
|
10
|
+
generate: (opts) => {
|
|
11
|
+
const { workflowName, async: isAsync } = opts;
|
|
12
|
+
const asyncKeyword = isAsync ? 'async ' : '';
|
|
13
|
+
const returnType = isAsync
|
|
14
|
+
? 'Promise<{ onSuccess: boolean; onFailure: boolean; result: any; attempts: number; lastError?: string }>'
|
|
15
|
+
: '{ onSuccess: boolean; onFailure: boolean; result: any; attempts: number; lastError?: string }';
|
|
16
|
+
return `
|
|
17
|
+
/**
|
|
18
|
+
* Retry loop that orchestrates operation attempts
|
|
19
|
+
* Uses scoped ports to handle retry iteration internally
|
|
20
|
+
*
|
|
21
|
+
* @flowWeaver nodeType
|
|
22
|
+
* @label Retry Loop
|
|
23
|
+
* @input data [order:1] - Input data to process
|
|
24
|
+
* @input maxRetries [order:2] - Maximum retry attempts
|
|
25
|
+
* @input success scope:attempt [order:0] - From operation onSuccess
|
|
26
|
+
* @input failure scope:attempt [order:1] - From operation onFailure
|
|
27
|
+
* @input result scope:attempt [order:2] - Operation result
|
|
28
|
+
* @input error scope:attempt [order:3] - Error from operation
|
|
29
|
+
* @input execute [order:0] - Execute
|
|
30
|
+
* @output start scope:attempt [order:0] - Triggers attempt
|
|
31
|
+
* @output attemptData scope:attempt [order:1] - Data for this attempt
|
|
32
|
+
* @output attemptNum scope:attempt [order:2] - Current attempt number
|
|
33
|
+
* @output finalResult [order:2] - Final result
|
|
34
|
+
* @output attempts [order:3] - Total attempts made
|
|
35
|
+
* @output lastError [order:4] - Last error if failed
|
|
36
|
+
* @output onSuccess [order:0] - On Success
|
|
37
|
+
* @output onFailure [order:1] - On Failure
|
|
38
|
+
*/
|
|
39
|
+
function retryLoop(
|
|
40
|
+
execute: boolean,
|
|
41
|
+
data: any,
|
|
42
|
+
maxRetries: number,
|
|
43
|
+
attempt: (start: boolean, attemptData: any, attemptNum: number) => {
|
|
44
|
+
success: boolean;
|
|
45
|
+
failure: boolean;
|
|
46
|
+
result: any;
|
|
47
|
+
error: string;
|
|
48
|
+
}
|
|
49
|
+
): { onSuccess: boolean; onFailure: boolean; finalResult: any; attempts: number; lastError: string } {
|
|
50
|
+
if (!execute) {
|
|
51
|
+
return { onSuccess: false, onFailure: false, finalResult: null, attempts: 0, lastError: '' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let lastError = '';
|
|
55
|
+
for (let attemptNum = 1; attemptNum <= maxRetries; attemptNum++) {
|
|
56
|
+
const result = attempt(true, data, attemptNum);
|
|
57
|
+
|
|
58
|
+
if (result.success) {
|
|
59
|
+
return { onSuccess: true, onFailure: false, finalResult: result.result, attempts: attemptNum, lastError: '' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
lastError = result.error;
|
|
63
|
+
console.log(\`[Retry] Attempt \${attemptNum} failed: \${lastError}. \${attemptNum < maxRetries ? 'Retrying...' : 'Max retries reached.'}\`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return { onSuccess: false, onFailure: true, finalResult: null, attempts: maxRetries, lastError };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Attempts an operation that might fail
|
|
71
|
+
*
|
|
72
|
+
* @flowWeaver nodeType
|
|
73
|
+
* @label Try Operation
|
|
74
|
+
* @input data [order:1] - Input data
|
|
75
|
+
* @input attempt [order:2] - Current attempt number
|
|
76
|
+
* @input execute [order:0] - Execute
|
|
77
|
+
* @output result [order:2] - Operation result
|
|
78
|
+
* @output error [order:3] - Error message if failed
|
|
79
|
+
* @output onSuccess [order:0] - On Success
|
|
80
|
+
* @output onFailure [order:1] - On Failure
|
|
81
|
+
*/
|
|
82
|
+
function tryOperation(
|
|
83
|
+
execute: boolean,
|
|
84
|
+
data: any,
|
|
85
|
+
attempt: number
|
|
86
|
+
): { onSuccess: boolean; onFailure: boolean; result: any; error: string } {
|
|
87
|
+
if (!execute) {
|
|
88
|
+
return { onSuccess: false, onFailure: false, result: null, error: '' };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// TODO: Replace with your operation that might fail
|
|
93
|
+
// This is a placeholder that randomly fails for demonstration
|
|
94
|
+
if (Math.random() < 0.3) {
|
|
95
|
+
throw new Error('Simulated failure');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const result = { processed: data, attempt };
|
|
99
|
+
return { onSuccess: true, onFailure: false, result, error: '' };
|
|
100
|
+
} catch (err) {
|
|
101
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
102
|
+
return { onSuccess: false, onFailure: true, result: null, error };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @flowWeaver workflow
|
|
108
|
+
* @node loop retryLoop [size: 300 200]
|
|
109
|
+
* @node tryOp tryOperation loop.attempt
|
|
110
|
+
* @position Start -450 0
|
|
111
|
+
* @position loop -90 0
|
|
112
|
+
* @position tryOp 90 0
|
|
113
|
+
* @position Exit 360 0
|
|
114
|
+
* @connect Start.execute -> loop.execute
|
|
115
|
+
* @connect Start.data -> loop.data
|
|
116
|
+
* @connect Start.maxRetries -> loop.maxRetries
|
|
117
|
+
* @connect loop.start:attempt -> tryOp.execute
|
|
118
|
+
* @connect loop.attemptData:attempt -> tryOp.data
|
|
119
|
+
* @connect loop.attemptNum:attempt -> tryOp.attempt
|
|
120
|
+
* @connect tryOp.result -> loop.result:attempt
|
|
121
|
+
* @connect tryOp.error -> loop.error:attempt
|
|
122
|
+
* @connect tryOp.onSuccess -> loop.success:attempt
|
|
123
|
+
* @connect tryOp.onFailure -> loop.failure:attempt
|
|
124
|
+
* @connect loop.finalResult -> Exit.result
|
|
125
|
+
* @connect loop.attempts -> Exit.attempts
|
|
126
|
+
* @connect loop.lastError -> Exit.lastError
|
|
127
|
+
* @connect loop.onSuccess -> Exit.onSuccess
|
|
128
|
+
* @connect loop.onFailure -> Exit.onFailure
|
|
129
|
+
* @param execute [order:0] - Execute
|
|
130
|
+
* @param data [order:1] - Input data to process
|
|
131
|
+
* @param [maxRetries=3] [order:2] - Maximum retry attempts
|
|
132
|
+
* @returns onSuccess [order:0] - Operation succeeded
|
|
133
|
+
* @returns onFailure [order:1] - All retries exhausted
|
|
134
|
+
* @returns result [order:2] - Operation result
|
|
135
|
+
* @returns attempts [order:3] - Number of attempts made
|
|
136
|
+
* @returns lastError [order:4] - Last error message if failed
|
|
137
|
+
*/
|
|
138
|
+
export ${asyncKeyword}function ${workflowName}(
|
|
139
|
+
execute: boolean,
|
|
140
|
+
params: { data: any; maxRetries?: number }
|
|
141
|
+
): ${returnType} {
|
|
142
|
+
throw new Error("Compile with: flow-weaver compile <file>");
|
|
143
|
+
}
|
|
144
|
+
`.trim();
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=error-handler.js.map
|