@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,338 @@
|
|
|
1
|
+
import { getProviderCode } from '../providers/index.js';
|
|
2
|
+
import { aiConfigSchema } from './ai-agent.js';
|
|
3
|
+
import { LLM_CORE_TYPES, LLM_MOCK_PROVIDER_WITH_TOOLS } from '../shared/llm-types.js';
|
|
4
|
+
export const aiAgentDurableTemplate = {
|
|
5
|
+
id: 'ai-agent-durable',
|
|
6
|
+
name: 'Durable AI Agent',
|
|
7
|
+
description: 'Linear agent pipeline with durability — classify, tools, approval, respond',
|
|
8
|
+
category: 'ai',
|
|
9
|
+
configSchema: aiConfigSchema,
|
|
10
|
+
generate: ({ workflowName, config }) => {
|
|
11
|
+
const provider = config?.provider || 'mock';
|
|
12
|
+
const model = config?.model || '';
|
|
13
|
+
const providerCode = provider === 'mock'
|
|
14
|
+
? `
|
|
15
|
+
/* ============================================================
|
|
16
|
+
* MOCK PROVIDER (REPLACE IN REAL USE)
|
|
17
|
+
* ============================================================ */
|
|
18
|
+
|
|
19
|
+
${LLM_MOCK_PROVIDER_WITH_TOOLS}
|
|
20
|
+
`
|
|
21
|
+
: getProviderCode(provider, model);
|
|
22
|
+
return `
|
|
23
|
+
// ============================================================
|
|
24
|
+
// Durable AI Agent
|
|
25
|
+
// ============================================================
|
|
26
|
+
//
|
|
27
|
+
// Each node becomes a checkpointed step when compiled to Inngest.
|
|
28
|
+
// If a step fails, it retries from that step — not from scratch.
|
|
29
|
+
//
|
|
30
|
+
// Compile: flow-weaver compile <file>
|
|
31
|
+
// Export: fw export --target inngest
|
|
32
|
+
//
|
|
33
|
+
// Flow: classify → executeTool → requestApproval → respond
|
|
34
|
+
|
|
35
|
+
/* ============================================================
|
|
36
|
+
* CORE TYPES
|
|
37
|
+
* ============================================================ */
|
|
38
|
+
|
|
39
|
+
${LLM_CORE_TYPES}
|
|
40
|
+
|
|
41
|
+
/* ============================================================
|
|
42
|
+
* TOOL DEFINITIONS
|
|
43
|
+
* ============================================================ */
|
|
44
|
+
|
|
45
|
+
type ToolResult =
|
|
46
|
+
| { ok: true; value: string }
|
|
47
|
+
| { ok: false; error: string };
|
|
48
|
+
|
|
49
|
+
type ToolFn = (args: Record<string, unknown>) => Promise<ToolResult>;
|
|
50
|
+
|
|
51
|
+
const AVAILABLE_TOOLS: LLMTool[] = [
|
|
52
|
+
{
|
|
53
|
+
name: 'search',
|
|
54
|
+
description: 'Search for information',
|
|
55
|
+
parameters: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
query: { type: 'string' },
|
|
59
|
+
},
|
|
60
|
+
required: ['query'],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const TOOL_IMPLEMENTATIONS: Record<string, ToolFn> = {
|
|
66
|
+
async search(args) {
|
|
67
|
+
if (typeof args.query !== 'string') {
|
|
68
|
+
return { ok: false, error: 'Invalid query' };
|
|
69
|
+
}
|
|
70
|
+
return { ok: true, value: '[Search results for: ' + args.query + ']' };
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/* ============================================================
|
|
75
|
+
* APPROVAL BACKEND (mock — replace with real backend)
|
|
76
|
+
* ============================================================
|
|
77
|
+
*
|
|
78
|
+
* On Inngest targets, this node compiles to step.waitForEvent().
|
|
79
|
+
* The function pauses (zero compute cost) until an approval event arrives.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
interface ApprovalResult {
|
|
83
|
+
approved: boolean;
|
|
84
|
+
response: string;
|
|
85
|
+
reviewer: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function requestApproval(prompt: string, context?: Record<string, unknown>): Promise<ApprovalResult> {
|
|
89
|
+
console.log('[Mock Approval] Auto-approving:', prompt);
|
|
90
|
+
return { approved: true, response: 'Auto-approved (mock)', reviewer: 'system' };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
${providerCode}
|
|
94
|
+
|
|
95
|
+
const SYSTEM_PROMPT = \`You are a helpful AI assistant with access to tools.
|
|
96
|
+
Use tools when necessary. Respond directly when the task is complete.\`;
|
|
97
|
+
|
|
98
|
+
/* ============================================================
|
|
99
|
+
* NODES
|
|
100
|
+
* ============================================================ */
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Classify the user's request and determine if tools are needed
|
|
104
|
+
*
|
|
105
|
+
* @flowWeaver nodeType
|
|
106
|
+
* @label Classify
|
|
107
|
+
* @color purple
|
|
108
|
+
* @icon psychology
|
|
109
|
+
* @input execute [order:0] - Execute
|
|
110
|
+
* @input userMessage [order:1] - User's input message
|
|
111
|
+
* @output onSuccess [order:0] - On Success
|
|
112
|
+
* @output onFailure [order:1] - On Failure
|
|
113
|
+
* @output content [order:2] - LLM response text
|
|
114
|
+
* @output toolCalls [order:3] - Tool calls requested by LLM
|
|
115
|
+
* @output hasToolCalls [order:4] - Whether LLM wants to call tools
|
|
116
|
+
* @output messages [order:5] - Updated conversation messages
|
|
117
|
+
*/
|
|
118
|
+
async function classify(
|
|
119
|
+
execute: boolean,
|
|
120
|
+
userMessage: string
|
|
121
|
+
): Promise<{
|
|
122
|
+
onSuccess: boolean;
|
|
123
|
+
onFailure: boolean;
|
|
124
|
+
content: string | null;
|
|
125
|
+
toolCalls: LLMToolCall[];
|
|
126
|
+
hasToolCalls: boolean;
|
|
127
|
+
messages: LLMMessage[];
|
|
128
|
+
}> {
|
|
129
|
+
if (!execute) {
|
|
130
|
+
return { onSuccess: false, onFailure: false, content: null, toolCalls: [], hasToolCalls: false, messages: [] };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const messages: LLMMessage[] = [{ role: 'user', content: userMessage }];
|
|
135
|
+
const response = await llmProvider.chat(messages, {
|
|
136
|
+
tools: AVAILABLE_TOOLS,
|
|
137
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
onSuccess: true,
|
|
142
|
+
onFailure: false,
|
|
143
|
+
content: response.content,
|
|
144
|
+
toolCalls: response.toolCalls,
|
|
145
|
+
hasToolCalls: response.toolCalls.length > 0,
|
|
146
|
+
messages: [
|
|
147
|
+
...messages,
|
|
148
|
+
{ role: 'assistant', content: response.content || '' },
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
} catch {
|
|
152
|
+
return { onSuccess: false, onFailure: true, content: null, toolCalls: [], hasToolCalls: false, messages: [] };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Execute tool calls from the LLM response
|
|
158
|
+
*
|
|
159
|
+
* @flowWeaver nodeType
|
|
160
|
+
* @label Execute Tools
|
|
161
|
+
* @color cyan
|
|
162
|
+
* @icon build
|
|
163
|
+
* @input execute [order:0] - Execute
|
|
164
|
+
* @input toolCalls [order:1] - Tool calls to execute
|
|
165
|
+
* @output onSuccess [order:0] - On Success
|
|
166
|
+
* @output onFailure [order:1] - On Failure
|
|
167
|
+
* @output results [order:2] - Tool execution results as messages
|
|
168
|
+
*/
|
|
169
|
+
async function executeTool(
|
|
170
|
+
execute: boolean,
|
|
171
|
+
toolCalls: LLMToolCall[]
|
|
172
|
+
): Promise<{
|
|
173
|
+
onSuccess: boolean;
|
|
174
|
+
onFailure: boolean;
|
|
175
|
+
results: LLMMessage[];
|
|
176
|
+
}> {
|
|
177
|
+
if (!execute || !toolCalls || toolCalls.length === 0) {
|
|
178
|
+
return { onSuccess: true, onFailure: false, results: [] };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const results: LLMMessage[] = [];
|
|
182
|
+
|
|
183
|
+
for (const call of toolCalls) {
|
|
184
|
+
const impl = TOOL_IMPLEMENTATIONS[call.name];
|
|
185
|
+
if (!impl) {
|
|
186
|
+
results.push({ role: 'tool', content: 'Unknown tool: ' + call.name, toolCallId: call.id });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const result = await impl(call.arguments);
|
|
191
|
+
results.push({
|
|
192
|
+
role: 'tool',
|
|
193
|
+
content: result.ok ? result.value : 'Error: ' + result.error,
|
|
194
|
+
toolCallId: call.id,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return { onSuccess: true, onFailure: false, results };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Request human approval before proceeding
|
|
203
|
+
*
|
|
204
|
+
* @flowWeaver nodeType
|
|
205
|
+
* @label Request Approval
|
|
206
|
+
* @color orange
|
|
207
|
+
* @icon verified
|
|
208
|
+
* @input execute [order:0] - Execute
|
|
209
|
+
* @input toolResults [order:1] - Tool results to review
|
|
210
|
+
* @output onSuccess [order:0] - On Success
|
|
211
|
+
* @output onFailure [order:1] - On Failure (rejected or timeout)
|
|
212
|
+
* @output approved [order:2] - Whether the request was approved
|
|
213
|
+
*/
|
|
214
|
+
async function approvalGate(
|
|
215
|
+
execute: boolean,
|
|
216
|
+
toolResults: LLMMessage[]
|
|
217
|
+
): Promise<{
|
|
218
|
+
onSuccess: boolean;
|
|
219
|
+
onFailure: boolean;
|
|
220
|
+
approved: boolean;
|
|
221
|
+
}> {
|
|
222
|
+
if (!execute) {
|
|
223
|
+
return { onSuccess: false, onFailure: false, approved: false };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
const summary = toolResults.map((m) => m.content).join('; ');
|
|
228
|
+
const result = await requestApproval(
|
|
229
|
+
'Review tool execution results before responding to user',
|
|
230
|
+
{ toolResults: summary }
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
if (!result.approved) {
|
|
234
|
+
return { onSuccess: false, onFailure: true, approved: false };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return { onSuccess: true, onFailure: false, approved: true };
|
|
238
|
+
} catch {
|
|
239
|
+
return { onSuccess: false, onFailure: true, approved: false };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Generate the final response incorporating tool results
|
|
245
|
+
*
|
|
246
|
+
* @flowWeaver nodeType
|
|
247
|
+
* @label Respond
|
|
248
|
+
* @color purple
|
|
249
|
+
* @icon psychology
|
|
250
|
+
* @input execute [order:0] - Execute
|
|
251
|
+
* @input messages [order:1] - Conversation history including tool results
|
|
252
|
+
* @input toolResults [order:2] - Tool result messages to append
|
|
253
|
+
* @output onSuccess [order:0] - On Success
|
|
254
|
+
* @output onFailure [order:1] - On Failure
|
|
255
|
+
* @output response [order:2] - Final response text
|
|
256
|
+
*/
|
|
257
|
+
async function respond(
|
|
258
|
+
execute: boolean,
|
|
259
|
+
messages: LLMMessage[],
|
|
260
|
+
toolResults: LLMMessage[]
|
|
261
|
+
): Promise<{
|
|
262
|
+
onSuccess: boolean;
|
|
263
|
+
onFailure: boolean;
|
|
264
|
+
response: string;
|
|
265
|
+
}> {
|
|
266
|
+
if (!execute) {
|
|
267
|
+
return { onSuccess: false, onFailure: false, response: '' };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
const fullMessages = [...messages, ...toolResults];
|
|
272
|
+
const result = await llmProvider.chat(fullMessages, {
|
|
273
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
onSuccess: true,
|
|
278
|
+
onFailure: false,
|
|
279
|
+
response: result.content || 'No response generated',
|
|
280
|
+
};
|
|
281
|
+
} catch {
|
|
282
|
+
return { onSuccess: false, onFailure: true, response: '' };
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* ============================================================
|
|
287
|
+
* WORKFLOW
|
|
288
|
+
* ============================================================ */
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Durable AI Agent — linear pipeline with tool calling and human approval.
|
|
292
|
+
* Each node becomes a checkpointed step when compiled to Inngest.
|
|
293
|
+
*
|
|
294
|
+
* @flowWeaver workflow
|
|
295
|
+
* @trigger event="agent/request"
|
|
296
|
+
* @retries 3
|
|
297
|
+
* @node cls classify
|
|
298
|
+
* @node tools executeTool
|
|
299
|
+
* @node approval approvalGate
|
|
300
|
+
* @node resp respond
|
|
301
|
+
* @position Start -500 0
|
|
302
|
+
* @position cls -280 0
|
|
303
|
+
* @position tools -40 0
|
|
304
|
+
* @position approval 200 0
|
|
305
|
+
* @position resp 440 0
|
|
306
|
+
* @position Exit 680 0
|
|
307
|
+
* @connect Start.execute -> cls.execute
|
|
308
|
+
* @connect Start.userMessage -> cls.userMessage
|
|
309
|
+
* @connect cls.onSuccess -> tools.execute
|
|
310
|
+
* @connect cls.toolCalls -> tools.toolCalls
|
|
311
|
+
* @connect tools.onSuccess -> approval.execute
|
|
312
|
+
* @connect tools.results -> approval.toolResults
|
|
313
|
+
* @connect approval.onSuccess -> resp.execute
|
|
314
|
+
* @connect cls.messages -> resp.messages
|
|
315
|
+
* @connect tools.results -> resp.toolResults
|
|
316
|
+
* @connect cls.onFailure -> Exit.onFailure
|
|
317
|
+
* @connect resp.onSuccess -> Exit.onSuccess
|
|
318
|
+
* @connect resp.response -> Exit.response
|
|
319
|
+
* @param execute [order:0] - Execute
|
|
320
|
+
* @param userMessage [order:1] - User's message to the agent
|
|
321
|
+
* @returns onSuccess [order:0] - Agent completed successfully
|
|
322
|
+
* @returns onFailure [order:1] - Agent encountered an error
|
|
323
|
+
* @returns response [order:2] - Agent's final response
|
|
324
|
+
*/
|
|
325
|
+
export async function ${workflowName}(
|
|
326
|
+
execute: boolean,
|
|
327
|
+
params: { userMessage: string }
|
|
328
|
+
): Promise<{
|
|
329
|
+
onSuccess: boolean;
|
|
330
|
+
onFailure: boolean;
|
|
331
|
+
response: string;
|
|
332
|
+
}> {
|
|
333
|
+
throw new Error('Compile with: flow-weaver compile <file>');
|
|
334
|
+
}
|
|
335
|
+
`.trim();
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
//# sourceMappingURL=ai-agent-durable.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Agent Template
|
|
3
|
+
* Stateful, tool-calling agent with explicit loop and termination semantics
|
|
4
|
+
*/
|
|
5
|
+
import type { WorkflowTemplate } from '../index.js';
|
|
6
|
+
/** Shared configSchema for AI templates */
|
|
7
|
+
export declare const aiConfigSchema: {
|
|
8
|
+
provider: {
|
|
9
|
+
type: "select";
|
|
10
|
+
label: string;
|
|
11
|
+
description: string;
|
|
12
|
+
default: string;
|
|
13
|
+
options: {
|
|
14
|
+
value: string;
|
|
15
|
+
label: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
model: {
|
|
19
|
+
type: "string";
|
|
20
|
+
label: string;
|
|
21
|
+
description: string;
|
|
22
|
+
default: string;
|
|
23
|
+
placeholder: string;
|
|
24
|
+
dependsOn: {
|
|
25
|
+
field: string;
|
|
26
|
+
values: string[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const aiAgentTemplate: WorkflowTemplate;
|
|
31
|
+
//# sourceMappingURL=ai-agent.d.ts.map
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { getProviderCode } from '../providers/index.js';
|
|
2
|
+
import { LLM_CORE_TYPES, LLM_MOCK_PROVIDER_WITH_TOOLS } from '../shared/llm-types.js';
|
|
3
|
+
/** Shared configSchema for AI templates */
|
|
4
|
+
export const aiConfigSchema = {
|
|
5
|
+
provider: {
|
|
6
|
+
type: 'select',
|
|
7
|
+
label: 'LLM Provider',
|
|
8
|
+
description: 'Choose your LLM provider',
|
|
9
|
+
default: 'mock',
|
|
10
|
+
options: [
|
|
11
|
+
{ value: 'openai', label: 'OpenAI' },
|
|
12
|
+
{ value: 'anthropic', label: 'Anthropic' },
|
|
13
|
+
{ value: 'ollama', label: 'Ollama (Local)' },
|
|
14
|
+
{ value: 'mock', label: 'Mock (Testing)' },
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
model: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
label: 'Model',
|
|
20
|
+
description: 'Model identifier',
|
|
21
|
+
default: 'gpt-4o',
|
|
22
|
+
placeholder: 'e.g., gpt-4o, claude-3-5-sonnet-20241022, llama3.2',
|
|
23
|
+
dependsOn: {
|
|
24
|
+
field: 'provider',
|
|
25
|
+
values: ['openai', 'anthropic', 'ollama'],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export const aiAgentTemplate = {
|
|
30
|
+
id: 'ai-agent',
|
|
31
|
+
name: 'AI Agent (Tool Calling)',
|
|
32
|
+
description: 'Stateful LLM agent with explicit reasoning loop and tool execution',
|
|
33
|
+
category: 'ai',
|
|
34
|
+
configSchema: aiConfigSchema,
|
|
35
|
+
generate: ({ workflowName, config }) => {
|
|
36
|
+
const provider = config?.provider || 'mock';
|
|
37
|
+
const model = config?.model || '';
|
|
38
|
+
// Get provider-specific code or use mock
|
|
39
|
+
const providerCode = provider === 'mock'
|
|
40
|
+
? `
|
|
41
|
+
/* ============================================================
|
|
42
|
+
* MOCK PROVIDER (REPLACE IN REAL USE)
|
|
43
|
+
* ============================================================
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
${LLM_MOCK_PROVIDER_WITH_TOOLS}
|
|
47
|
+
`
|
|
48
|
+
: getProviderCode(provider, model);
|
|
49
|
+
return `
|
|
50
|
+
/* ============================================================
|
|
51
|
+
* CORE TYPES
|
|
52
|
+
* ============================================================
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
${LLM_CORE_TYPES}
|
|
56
|
+
|
|
57
|
+
type TerminationReason =
|
|
58
|
+
| 'completed'
|
|
59
|
+
| 'max_iterations'
|
|
60
|
+
| 'tool_error'
|
|
61
|
+
| 'llm_error'
|
|
62
|
+
| 'aborted';
|
|
63
|
+
|
|
64
|
+
/* ============================================================
|
|
65
|
+
* AGENT STATE
|
|
66
|
+
* ============================================================
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
interface AgentState {
|
|
70
|
+
messages: LLMMessage[];
|
|
71
|
+
iteration: number;
|
|
72
|
+
toolsUsed: string[];
|
|
73
|
+
terminated: boolean;
|
|
74
|
+
terminationReason?: TerminationReason;
|
|
75
|
+
finalResponse?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
${providerCode}
|
|
79
|
+
|
|
80
|
+
const SYSTEM_PROMPT = \`You are a helpful AI assistant with access to tools.
|
|
81
|
+
Use tools when necessary. Respond directly when the task is complete.\`;
|
|
82
|
+
|
|
83
|
+
const MAX_ITERATIONS = 10;
|
|
84
|
+
|
|
85
|
+
/* ============================================================
|
|
86
|
+
* TOOLS
|
|
87
|
+
* ============================================================
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
const AVAILABLE_TOOLS: LLMTool[] = [
|
|
91
|
+
{
|
|
92
|
+
name: 'search',
|
|
93
|
+
description: 'Search for information',
|
|
94
|
+
parameters: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
query: { type: 'string' },
|
|
98
|
+
},
|
|
99
|
+
required: ['query'],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
type ToolResult =
|
|
105
|
+
| { ok: true; value: string }
|
|
106
|
+
| { ok: false; error: string };
|
|
107
|
+
|
|
108
|
+
type ToolFn = (args: Record<string, unknown>) => Promise<ToolResult>;
|
|
109
|
+
|
|
110
|
+
const TOOL_IMPLEMENTATIONS: Record<string, ToolFn> = {
|
|
111
|
+
async search(args) {
|
|
112
|
+
if (typeof args.query !== 'string') {
|
|
113
|
+
return { ok: false, error: 'Invalid query' };
|
|
114
|
+
}
|
|
115
|
+
return { ok: true, value: '[Search results for: ' + args.query + ']' };
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/* ============================================================
|
|
120
|
+
* NODES
|
|
121
|
+
* ============================================================
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Agent loop that orchestrates LLM calls and tool execution
|
|
126
|
+
* Uses scoped ports to handle iteration internally
|
|
127
|
+
*
|
|
128
|
+
* @flowWeaver nodeType
|
|
129
|
+
* @label Agent Loop
|
|
130
|
+
* @input userMessage [order:1] - User's input message
|
|
131
|
+
* @input success scope:iteration [order:0] - From LLM onSuccess
|
|
132
|
+
* @input failure scope:iteration [order:1] - From LLM onFailure
|
|
133
|
+
* @input llmResponse scope:iteration [order:2] - LLM response
|
|
134
|
+
* @input toolMessages scope:iteration [order:3] - Tool results
|
|
135
|
+
* @input execute [order:0] - Execute
|
|
136
|
+
* @output start scope:iteration [order:0] - Triggers iteration
|
|
137
|
+
* @output state scope:iteration [order:1] - Current agent state
|
|
138
|
+
* @output response [order:2] - Final response when done
|
|
139
|
+
* @output onSuccess [order:0] - On Success
|
|
140
|
+
* @output onFailure [order:1] - On Failure
|
|
141
|
+
*/
|
|
142
|
+
async function agentLoop(
|
|
143
|
+
execute: boolean,
|
|
144
|
+
userMessage: string,
|
|
145
|
+
iteration: (start: boolean, state: AgentState) => Promise<{
|
|
146
|
+
success: boolean;
|
|
147
|
+
failure: boolean;
|
|
148
|
+
llmResponse: LLMResponse | null;
|
|
149
|
+
toolMessages: LLMMessage[];
|
|
150
|
+
}>
|
|
151
|
+
): Promise<{ onSuccess: boolean; onFailure: boolean; response: string }> {
|
|
152
|
+
if (!execute) {
|
|
153
|
+
return { onSuccess: false, onFailure: false, response: '' };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let state: AgentState = {
|
|
157
|
+
messages: [{ role: 'user', content: userMessage }],
|
|
158
|
+
iteration: 0,
|
|
159
|
+
toolsUsed: [],
|
|
160
|
+
terminated: false,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
while (state.iteration < MAX_ITERATIONS) {
|
|
164
|
+
const result = await iteration(true, state);
|
|
165
|
+
|
|
166
|
+
state.iteration++;
|
|
167
|
+
|
|
168
|
+
// Handle LLM failure
|
|
169
|
+
if (result.failure) {
|
|
170
|
+
return { onSuccess: false, onFailure: true, response: 'LLM error occurred' };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Add assistant message if present
|
|
174
|
+
if (result.llmResponse?.content) {
|
|
175
|
+
state.messages.push({ role: 'assistant', content: result.llmResponse.content });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Add tool messages
|
|
179
|
+
if (result.toolMessages && result.toolMessages.length > 0) {
|
|
180
|
+
state.messages.push(...result.toolMessages);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Check termination: no tool calls means we're done
|
|
184
|
+
if (result.llmResponse && result.llmResponse.toolCalls.length === 0 && result.llmResponse.content) {
|
|
185
|
+
return { onSuccess: true, onFailure: false, response: result.llmResponse.content };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return { onSuccess: true, onFailure: false, response: 'Max iterations reached' };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Calls the LLM with current state
|
|
194
|
+
*
|
|
195
|
+
* @flowWeaver nodeType
|
|
196
|
+
* @label Call LLM
|
|
197
|
+
* @input state [order:1] - Current agent state
|
|
198
|
+
* @input execute [order:0] - Execute
|
|
199
|
+
* @output response [order:2] - LLM response
|
|
200
|
+
* @output toolCalls [order:3] - Tool calls from LLM
|
|
201
|
+
* @output onSuccess [order:0] - On Success
|
|
202
|
+
* @output onFailure [order:1] - On Failure
|
|
203
|
+
*/
|
|
204
|
+
async function callLLM(
|
|
205
|
+
execute: boolean,
|
|
206
|
+
state: AgentState
|
|
207
|
+
): Promise<{
|
|
208
|
+
onSuccess: boolean;
|
|
209
|
+
onFailure: boolean;
|
|
210
|
+
response: LLMResponse | null;
|
|
211
|
+
toolCalls: LLMToolCall[];
|
|
212
|
+
}> {
|
|
213
|
+
if (!execute) {
|
|
214
|
+
return { onSuccess: false, onFailure: false, response: null, toolCalls: [] };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const response = await llmProvider.chat(state.messages, {
|
|
219
|
+
tools: AVAILABLE_TOOLS,
|
|
220
|
+
systemPrompt: SYSTEM_PROMPT,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return { onSuccess: true, onFailure: false, response, toolCalls: response.toolCalls };
|
|
224
|
+
} catch {
|
|
225
|
+
return { onSuccess: false, onFailure: true, response: null, toolCalls: [] };
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Executes tool calls
|
|
231
|
+
*
|
|
232
|
+
* @flowWeaver nodeType
|
|
233
|
+
* @label Execute Tools
|
|
234
|
+
* @input calls [order:1] - Tool calls to execute
|
|
235
|
+
* @input execute [order:0] - Execute
|
|
236
|
+
* @output messages [order:2] - Tool response messages
|
|
237
|
+
* @output onSuccess [order:0] - On Success
|
|
238
|
+
* @output onFailure [order:1] - On Failure
|
|
239
|
+
*/
|
|
240
|
+
async function executeTools(
|
|
241
|
+
execute: boolean,
|
|
242
|
+
calls: LLMToolCall[]
|
|
243
|
+
): Promise<{
|
|
244
|
+
onSuccess: boolean;
|
|
245
|
+
onFailure: boolean;
|
|
246
|
+
messages: LLMMessage[];
|
|
247
|
+
}> {
|
|
248
|
+
if (!execute || !calls || calls.length === 0) {
|
|
249
|
+
return { onSuccess: true, onFailure: false, messages: [] };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const messages: LLMMessage[] = [];
|
|
253
|
+
|
|
254
|
+
for (const call of calls) {
|
|
255
|
+
const impl = TOOL_IMPLEMENTATIONS[call.name];
|
|
256
|
+
if (!impl) {
|
|
257
|
+
messages.push({
|
|
258
|
+
role: 'tool',
|
|
259
|
+
content: 'Unknown tool: ' + call.name,
|
|
260
|
+
toolCallId: call.id,
|
|
261
|
+
});
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const result = await impl(call.arguments);
|
|
266
|
+
|
|
267
|
+
messages.push({
|
|
268
|
+
role: 'tool',
|
|
269
|
+
content: result.ok ? result.value : 'Error: ' + result.error,
|
|
270
|
+
toolCallId: call.id,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return { onSuccess: true, onFailure: false, messages };
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* ============================================================
|
|
278
|
+
* WORKFLOW
|
|
279
|
+
* ============================================================
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* AI Agent that uses tools to accomplish tasks
|
|
284
|
+
*
|
|
285
|
+
* @flowWeaver workflow
|
|
286
|
+
* @node loop agentLoop [size: 450 350]
|
|
287
|
+
* @node llm callLLM loop.iteration
|
|
288
|
+
* @node tools executeTools loop.iteration
|
|
289
|
+
* @position Start -450 0
|
|
290
|
+
* @position loop -180 0
|
|
291
|
+
* @position llm -40 100
|
|
292
|
+
* @position tools 120 200
|
|
293
|
+
* @position Exit 360 0
|
|
294
|
+
* @connect Start.execute -> loop.execute
|
|
295
|
+
* @connect Start.userMessage -> loop.userMessage
|
|
296
|
+
* @connect loop.start:iteration -> llm.execute
|
|
297
|
+
* @connect loop.state:iteration -> llm.state
|
|
298
|
+
* @connect llm.toolCalls -> tools.calls
|
|
299
|
+
* @connect llm.onSuccess -> tools.execute
|
|
300
|
+
* @connect llm.response -> loop.llmResponse:iteration
|
|
301
|
+
* @connect llm.onSuccess -> loop.success:iteration
|
|
302
|
+
* @connect llm.onFailure -> loop.failure:iteration
|
|
303
|
+
* @connect tools.messages -> loop.toolMessages:iteration
|
|
304
|
+
* @connect loop.response -> Exit.response
|
|
305
|
+
* @connect loop.onSuccess -> Exit.onSuccess
|
|
306
|
+
* @connect loop.onFailure -> Exit.onFailure
|
|
307
|
+
* @param execute [order:0] - Execute
|
|
308
|
+
* @param userMessage [order:1] - User's message to the agent
|
|
309
|
+
* @returns onSuccess [order:0] - Agent completed successfully
|
|
310
|
+
* @returns onFailure [order:1] - Agent encountered an error
|
|
311
|
+
* @returns response [order:2] - Agent's final response
|
|
312
|
+
*/
|
|
313
|
+
export async function ${workflowName}(
|
|
314
|
+
execute: boolean,
|
|
315
|
+
params: { userMessage: string }
|
|
316
|
+
): Promise<{
|
|
317
|
+
onSuccess: boolean;
|
|
318
|
+
onFailure: boolean;
|
|
319
|
+
response: string;
|
|
320
|
+
}> {
|
|
321
|
+
throw new Error('Compile with: flow-weaver compile <file>');
|
|
322
|
+
}
|
|
323
|
+
`.trim();
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
//# sourceMappingURL=ai-agent.js.map
|