@synergenius/flow-weaver 0.33.2 → 0.44.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 +201 -226
- package/NOTICE +13 -0
- package/README.md +152 -245
- package/dist/agent/agent-loop.d.ts +4 -2
- package/dist/agent/cli-session.d.ts +3 -3
- package/dist/agent/cli-session.js +511 -438
- package/dist/agent/cli-spawn-config.d.ts +4 -4
- package/dist/agent/gate.d.ts +164 -0
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.js +174 -28
- package/dist/agent/mcp-bridge.d.ts +1 -1
- package/dist/agent/mcp-bridge.js +114 -128
- package/dist/agent/mcp-tool-server.d.ts +2 -2
- package/dist/agent/mcp-tool-server.js +147 -189
- package/dist/agent/profiles.d.ts +69 -0
- package/dist/agent/providers/anthropic.d.ts +2 -4
- package/dist/agent/providers/claude-cli.d.ts +4 -5
- package/dist/agent/providers/openai-compat.d.ts +8 -1
- package/dist/agent/streaming.d.ts +2 -2
- package/dist/agent/types.d.ts +16 -10
- package/dist/api/builder.d.ts +3 -3
- package/dist/api/compile.d.ts +9 -4
- package/dist/api/durable-validation.d.ts +15 -0
- package/dist/api/generate-in-place.d.ts +21 -19
- package/dist/api/generate.d.ts +21 -16
- package/dist/api/generated-module/local-node-functions.d.ts +24 -0
- package/dist/api/generated-module/module-format.d.ts +23 -0
- package/dist/api/generated-module/module-writer.d.ts +34 -0
- package/dist/api/generated-module/node-type-imports.d.ts +39 -0
- package/dist/api/generated-module/preamble.d.ts +16 -0
- package/dist/api/generated-module/workflow-functions.d.ts +29 -0
- package/dist/api/graph-identity.d.ts +39 -0
- package/dist/api/helpers.d.ts +4 -60
- package/dist/api/in-place/built-in-nodes.d.ts +18 -0
- package/dist/api/in-place/function-body.d.ts +21 -0
- package/dist/api/in-place/fw-imports.d.ts +30 -0
- package/dist/api/in-place/macro-coverage.d.ts +14 -0
- package/dist/api/in-place/node-type-functions.d.ts +18 -0
- package/dist/api/in-place/node-type-jsdoc.d.ts +20 -0
- package/dist/api/in-place/orphaned-node-types.d.ts +16 -0
- package/dist/api/in-place/runtime-section.d.ts +16 -0
- package/dist/api/in-place/signature.d.ts +47 -0
- package/dist/api/in-place/source-file.d.ts +19 -0
- package/dist/api/in-place/workflow-jsdoc.d.ts +19 -0
- package/dist/api/index.d.ts +18 -21
- package/dist/api/index.js +259 -53
- package/dist/api/inline-engine.generated.d.ts +3 -0
- package/dist/api/inline-runtime.d.ts +10 -2
- package/dist/api/manipulation/connections.d.ts +1 -1
- package/dist/api/manipulation/index.d.ts +8 -8
- package/dist/api/manipulation/node-types.d.ts +1 -1
- package/dist/api/manipulation/nodes.d.ts +3 -13
- package/dist/api/manipulation/ports.d.ts +1 -1
- package/dist/api/manipulation/scopes.d.ts +1 -1
- package/dist/api/manipulation/workflow.d.ts +1 -1
- package/dist/api/modify-operation.d.ts +0 -2
- package/dist/api/parse.d.ts +22 -1
- package/dist/api/port-references.d.ts +66 -0
- package/dist/api/query.d.ts +18 -2
- package/dist/api/templates.d.ts +1 -1
- package/dist/api/transform.d.ts +1 -1
- package/dist/api/validate.d.ts +1 -1
- package/dist/api/validation-registry.d.ts +2 -2
- package/dist/artifacts/brief.d.ts +43 -0
- package/dist/artifacts/index.d.ts +31 -0
- package/dist/artifacts/pdf.d.ts +19 -0
- package/dist/ast/builder.d.ts +3 -3
- package/dist/ast/index.d.ts +4 -4
- package/dist/ast/index.js +60 -5
- package/dist/ast/serialization-node.d.ts +1 -1
- package/dist/ast/serialization.d.ts +1 -1
- package/dist/ast/types.d.ts +82 -291
- package/dist/ast/workflow-utils.d.ts +4 -4
- package/dist/built-in-nodes/coercion-types.d.ts +1 -1
- package/dist/built-in-nodes/delay.d.ts +3 -1
- package/dist/built-in-nodes/generated-registry.d.ts +1 -1
- package/dist/built-in-nodes/index.d.ts +6 -5
- package/dist/built-in-nodes/index.js +79 -5
- package/dist/built-in-nodes/invoke-workflow.d.ts +2 -1
- package/dist/built-in-nodes/mock-types.d.ts +45 -14
- package/dist/built-in-nodes/sleep.d.ts +12 -0
- package/dist/built-in-nodes/wait-for-agent.d.ts +2 -1
- package/dist/built-in-nodes/wait-for-event.d.ts +2 -1
- package/dist/chevrotain-parser/coerce-parser.d.ts +1 -1
- package/dist/chevrotain-parser/connect-parser.d.ts +1 -1
- package/dist/chevrotain-parser/grammar-diagrams.d.ts +1 -1
- package/dist/chevrotain-parser/index.d.ts +20 -23
- package/dist/chevrotain-parser/node-parser.d.ts +7 -8
- package/dist/chevrotain-parser/parse-line.d.ts +54 -0
- package/dist/chevrotain-parser/tokens.d.ts +0 -17
- package/dist/chevrotain-parser/trigger-cancel-parser.d.ts +6 -1
- package/dist/chunks/chunk-4EUSHAY6.js +298 -0
- package/dist/chunks/chunk-4KDUEOFD.js +197 -0
- package/dist/chunks/chunk-5Y3AIUWY.js +911 -0
- package/dist/chunks/chunk-6KMVP6AU.js +20 -0
- package/dist/chunks/chunk-6PNJORFL.js +128 -0
- package/dist/chunks/chunk-7AAQNGRH.js +2001 -0
- package/dist/chunks/chunk-7YYKTPJ5.js +22705 -0
- package/dist/chunks/chunk-A5MBOFVY.js +33 -0
- package/dist/chunks/chunk-AXNQRVJB.js +18 -0
- package/dist/chunks/chunk-B6HQ6YS5.js +572 -0
- package/dist/chunks/chunk-CY3RNVML.js +296 -0
- package/dist/chunks/chunk-CYHYDLV4.js +653 -0
- package/dist/chunks/chunk-CZBCCK4Y.js +82 -0
- package/dist/chunks/chunk-DCMGQP5V.js +505 -0
- package/dist/chunks/chunk-DIAA66GL.js +72 -0
- package/dist/chunks/chunk-DUO6H5PR.js +20 -0
- package/dist/chunks/chunk-E5WN7IGO.js +125 -0
- package/dist/chunks/chunk-EFGFXXQF.js +184 -0
- package/dist/chunks/chunk-F3RTZV2A.js +2811 -0
- package/dist/chunks/chunk-FMTLP5ZX.js +1397 -0
- package/dist/chunks/chunk-HKZLQJDV.js +79 -0
- package/dist/chunks/chunk-INDEVYEC.js +146 -0
- package/dist/chunks/chunk-JQTF4R5L.js +390 -0
- package/dist/chunks/chunk-KMCAYNUM.js +331 -0
- package/dist/chunks/chunk-KMWCCOUJ.js +1444 -0
- package/dist/chunks/chunk-KU3CLJI2.js +338 -0
- package/dist/chunks/chunk-NDSTGMKR.js +3300 -0
- package/dist/chunks/chunk-NQNLUAPO.js +505 -0
- package/dist/chunks/chunk-O2U2LO57.js +466 -0
- package/dist/chunks/chunk-OOQG7UPP.js +457 -0
- package/dist/chunks/chunk-OZQAW5ZG.js +112 -0
- package/dist/chunks/chunk-P2CVDGHR.js +487 -0
- package/dist/chunks/chunk-P44RIZ7C.js +592 -0
- package/dist/chunks/chunk-PEZCT37T.js +1475 -0
- package/dist/chunks/chunk-PKWSAW6O.js +152 -0
- package/dist/chunks/chunk-Q6MDDZMT.js +4373 -0
- package/dist/chunks/chunk-QDE4Z7KW.js +6 -0
- package/dist/chunks/chunk-QJDAVSNY.js +8 -0
- package/dist/chunks/chunk-QYPORSLO.js +7552 -0
- package/dist/chunks/chunk-R4QGNK34.js +183 -0
- package/dist/chunks/chunk-REEYC73I.js +3002 -0
- package/dist/chunks/chunk-SEWDMQ6Q.js +46 -0
- package/dist/chunks/chunk-TAIUWKZB.js +3057 -0
- package/dist/chunks/chunk-TN4YZ3O7.js +196 -0
- package/dist/chunks/chunk-TRMFB43C.js +143 -0
- package/dist/chunks/chunk-VO4QXG2X.js +1016 -0
- package/dist/chunks/chunk-VP2P3BPA.js +1002 -0
- package/dist/chunks/chunk-VQ7H33J4.js +2176 -0
- package/dist/chunks/chunk-VWA7MCV2.js +105 -0
- package/dist/chunks/chunk-XAV22WD7.js +253 -0
- package/dist/chunks/chunk-YSPBPZDV.js +148 -0
- package/dist/chunks/chunk-ZKEGXO73.js +282 -0
- package/dist/chunks/chunk-ZMGN6F3S.js +4256 -0
- package/dist/chunks/grammar-diagrams-AI7VDXOM.js +14 -0
- package/dist/chunks/index.min-ECJD6GZC.js +37 -0
- package/dist/chunks/manifest-EPTR5MYH.js +21 -0
- package/dist/chunks/openapi-document-6TCGVDUW.js +69 -0
- package/dist/chunks/registry-K2U5KUTY.js +23 -0
- package/dist/chunks/serialization-node-UGY6CFH6.js +38 -0
- package/dist/chunks/validate-GEKSZPIN.js +24 -0
- package/dist/chunks/validation-registry-IQZX3UE3.js +7 -0
- package/dist/chunks/validator-VXFHLPDW.js +26 -0
- package/dist/chunks/workflow-executor-KBGFKHNR.js +36 -0
- package/dist/cli/commands/agents.d.ts +16 -0
- package/dist/cli/commands/artifact.d.ts +10 -0
- package/dist/cli/commands/compile.d.ts +0 -30
- package/dist/cli/commands/console.d.ts +32 -0
- package/dist/cli/commands/context.d.ts +0 -3
- package/dist/cli/commands/describe.js +386 -352
- package/dist/cli/commands/dev.d.ts +9 -4
- package/dist/cli/commands/diagram.d.ts +3 -5
- package/dist/cli/commands/doctor.d.ts +27 -4
- package/dist/cli/commands/doctor.js +3307 -633
- package/dist/cli/commands/export.d.ts +6 -4
- package/dist/cli/commands/grammar.d.ts +0 -3
- package/dist/cli/commands/implement.d.ts +1 -1
- package/dist/cli/commands/init/agent-handoff.d.ts +28 -0
- package/dist/cli/commands/init/config.d.ts +3 -0
- package/dist/cli/commands/init/files.d.ts +12 -0
- package/dist/cli/commands/init/naming.d.ts +13 -0
- package/dist/cli/commands/init/output.d.ts +12 -0
- package/dist/cli/commands/init/setup.d.ts +21 -0
- package/dist/cli/commands/init/types.d.ts +53 -0
- package/dist/cli/commands/init-personas.d.ts +9 -1
- package/dist/cli/commands/init.d.ts +24 -88
- package/dist/cli/commands/market.d.ts +1 -1
- package/dist/cli/commands/mcp-setup.d.ts +1 -4
- package/dist/cli/commands/modify.d.ts +0 -5
- package/dist/cli/commands/openapi.d.ts +9 -11
- package/dist/cli/commands/run.d.ts +0 -4
- package/dist/cli/commands/serve.d.ts +24 -26
- package/dist/cli/commands/status.d.ts +1 -1
- package/dist/cli/exports.d.ts +3 -4
- package/dist/cli/exports.js +124 -23
- package/dist/cli/flow-weaver-agents-H653446S.mjs +81 -0
- package/dist/cli/flow-weaver-artifact-WBFYTW76.mjs +58 -0
- package/dist/cli/flow-weaver-chunk-265CEK74.mjs +2 -0
- package/dist/cli/flow-weaver-chunk-2C7PZCV5.mjs +186 -0
- package/dist/cli/flow-weaver-chunk-3BSYCWPL.mjs +3109 -0
- package/dist/cli/flow-weaver-chunk-3MKUQP3D.mjs +547 -0
- package/dist/cli/flow-weaver-chunk-3ZLMPQTH.mjs +27 -0
- package/dist/cli/flow-weaver-chunk-4DVY73ML.mjs +280 -0
- package/dist/cli/flow-weaver-chunk-54M4KNEL.mjs +200 -0
- package/dist/cli/flow-weaver-chunk-55QMUZIA.mjs +256 -0
- package/dist/cli/flow-weaver-chunk-6ZUJ7LMX.mjs +2003 -0
- package/dist/cli/flow-weaver-chunk-7ET6N32V.mjs +419 -0
- package/dist/cli/flow-weaver-chunk-7G63RR4K.mjs +8880 -0
- package/dist/cli/flow-weaver-chunk-A6M5K3W7.mjs +4418 -0
- package/dist/cli/flow-weaver-chunk-AA3NATMX.mjs +154 -0
- package/dist/cli/flow-weaver-chunk-APX6MQ5A.mjs +5652 -0
- package/dist/cli/flow-weaver-chunk-BHCC5FE5.mjs +17 -0
- package/dist/cli/flow-weaver-chunk-DM4BBRRU.mjs +35 -0
- package/dist/cli/flow-weaver-chunk-DRN7KPWY.mjs +168 -0
- package/dist/cli/flow-weaver-chunk-EKWF27G6.mjs +23 -0
- package/dist/cli/flow-weaver-chunk-EM5HWQ4R.mjs +338 -0
- package/dist/cli/flow-weaver-chunk-FPPPU2DG.mjs +226 -0
- package/dist/cli/flow-weaver-chunk-GAQXZHNO.mjs +3005 -0
- package/dist/cli/flow-weaver-chunk-GBUNNP33.mjs +1329 -0
- package/dist/cli/flow-weaver-chunk-HMAKDE55.mjs +636 -0
- package/dist/cli/flow-weaver-chunk-HQ3ZAN44.mjs +367 -0
- package/dist/cli/flow-weaver-chunk-I4APCXYN.mjs +21442 -0
- package/dist/cli/flow-weaver-chunk-IJJ4JXTL.mjs +2297 -0
- package/dist/cli/flow-weaver-chunk-J7EPZW2I.mjs +33 -0
- package/dist/cli/flow-weaver-chunk-KOEMJHLG.mjs +83 -0
- package/dist/cli/flow-weaver-chunk-M6CBWQKJ.mjs +271 -0
- package/dist/cli/flow-weaver-chunk-MHJ4N652.mjs +1580 -0
- package/dist/cli/flow-weaver-chunk-MKAFQWLP.mjs +202 -0
- package/dist/cli/flow-weaver-chunk-MMV2XGD3.mjs +3291 -0
- package/dist/cli/flow-weaver-chunk-MSI2UJES.mjs +125 -0
- package/dist/cli/flow-weaver-chunk-N767YRAI.mjs +48 -0
- package/dist/cli/flow-weaver-chunk-NQKKWDGF.mjs +56 -0
- package/dist/cli/flow-weaver-chunk-NYZDQYFU.mjs +45 -0
- package/dist/cli/flow-weaver-chunk-OMVWSNHJ.mjs +14 -0
- package/dist/cli/flow-weaver-chunk-PUWZ47H5.mjs +2188 -0
- package/dist/cli/flow-weaver-chunk-QOPRVDES.mjs +46 -0
- package/dist/cli/flow-weaver-chunk-RIWE7YTR.mjs +216 -0
- package/dist/cli/flow-weaver-chunk-S63Q3JIU.mjs +789 -0
- package/dist/cli/flow-weaver-chunk-T7X5A23H.mjs +558 -0
- package/dist/cli/flow-weaver-chunk-TLV3VZUN.mjs +2 -0
- package/dist/cli/flow-weaver-chunk-TS5P3PIN.mjs +194 -0
- package/dist/cli/flow-weaver-chunk-U3EO3X4B.mjs +649 -0
- package/dist/cli/flow-weaver-chunk-UNFS3NQP.mjs +34 -0
- package/dist/cli/flow-weaver-chunk-V6DHWFQG.mjs +2811 -0
- package/dist/cli/flow-weaver-chunk-VXWNLYQU.mjs +9 -0
- package/dist/cli/flow-weaver-chunk-W3YNK26P.mjs +149 -0
- package/dist/cli/flow-weaver-chunk-XG2WKXYZ.mjs +324 -0
- package/dist/cli/flow-weaver-chunk-YLSRZWFK.mjs +2219 -0
- package/dist/cli/flow-weaver-chunk-YVPURWS6.mjs +40 -0
- package/dist/cli/flow-weaver-chunk-Z44JK332.mjs +582 -0
- package/dist/cli/flow-weaver-chunk-Z5ZJPNSY.mjs +517 -0
- package/dist/cli/flow-weaver-chunk-ZQALO25T.mjs +594 -0
- package/dist/cli/flow-weaver-compile-A2CABDSB.mjs +37 -0
- package/dist/cli/flow-weaver-console-6EBHDBTN.mjs +71 -0
- package/dist/cli/flow-weaver-context-ECLYANFF.mjs +17 -0
- package/dist/cli/flow-weaver-context-ZRUMW2KE.mjs +69 -0
- package/dist/cli/flow-weaver-create-WIP4EFNP.mjs +124 -0
- package/dist/cli/flow-weaver-deployment-WJJRK7NO.mjs +14 -0
- package/dist/cli/flow-weaver-describe-XDIFF5LI.mjs +41 -0
- package/dist/cli/flow-weaver-dev-LG2NSQAU.mjs +196 -0
- package/dist/cli/flow-weaver-diagram-3EVQARQE.mjs +52 -0
- package/dist/cli/flow-weaver-diagram-7LR7O4M2.mjs +44 -0
- package/dist/cli/flow-weaver-diff-USF7DJLU.mjs +85 -0
- package/dist/cli/flow-weaver-docs-QU2ZOXKH.mjs +96 -0
- package/dist/cli/flow-weaver-doctor-K447YWHR.mjs +43 -0
- package/dist/cli/flow-weaver-export-LAS6N56Y.mjs +140 -0
- package/dist/cli/flow-weaver-grammar-RIRUS3Q6.mjs +49 -0
- package/dist/cli/flow-weaver-grammar-diagrams-WXRTW5SK.mjs +15 -0
- package/dist/cli/flow-weaver-implement-5JG6BCFZ.mjs +114 -0
- package/dist/cli/flow-weaver-index.min-OR5SIHXD.mjs +39 -0
- package/dist/cli/flow-weaver-init-34YZNPQX.mjs +972 -0
- package/dist/cli/flow-weaver-init-personas-NOGZTQQ2.mjs +48 -0
- package/dist/cli/flow-weaver-manifest-4JNUSEB3.mjs +18 -0
- package/dist/cli/flow-weaver-market-WA4CKHKV.mjs +444 -0
- package/dist/cli/flow-weaver-mcp-setup-O26MGXSD.mjs +22 -0
- package/dist/cli/flow-weaver-migrate-VFVEUTPH.mjs +119 -0
- package/dist/cli/flow-weaver-modify-VM3JP5K6.mjs +97 -0
- package/dist/cli/flow-weaver-openapi-IRBWI3HM.mjs +71 -0
- package/dist/cli/flow-weaver-openapi-document-7N6YMPG3.mjs +30 -0
- package/dist/cli/flow-weaver-pack-commands-OS2QRXAK.mjs +146 -0
- package/dist/cli/flow-weaver-registry-5MLFRPPT.mjs +25 -0
- package/dist/cli/flow-weaver-run-DSTLSTHR.mjs +555 -0
- package/dist/cli/flow-weaver-serialization-node-LE6PCG4M.mjs +50 -0
- package/dist/cli/flow-weaver-serve-NVLCLSOW.mjs +192 -0
- package/dist/cli/flow-weaver-server-7IERLVXE.mjs +2925 -0
- package/dist/cli/flow-weaver-server-KWF4PXYC.mjs +19112 -0
- package/dist/cli/flow-weaver-status-75W2S3YB.mjs +138 -0
- package/dist/cli/flow-weaver-strip-AZPXUYVA.mjs +79 -0
- package/dist/cli/flow-weaver-templates-DSNMB6K7.mjs +72 -0
- package/dist/cli/flow-weaver-validate-A4UWDQN6.mjs +19 -0
- package/dist/cli/flow-weaver-validate-GRBZ5W4C.mjs +296 -0
- package/dist/cli/flow-weaver-validation-registry-BINGUNXX.mjs +9 -0
- package/dist/cli/flow-weaver-validator-TY56CI42.mjs +21 -0
- package/dist/cli/flow-weaver-watch-OPPERXL6.mjs +114 -0
- package/dist/cli/flow-weaver-workflow-executor-6AHYPXAN.mjs +26 -0
- package/dist/cli/flow-weaver.mjs +3557 -89384
- package/dist/cli/index.d.ts +5 -2
- package/dist/cli/pack-commands-needed.d.ts +12 -0
- package/dist/cli/program.d.ts +14 -0
- package/dist/cli/templates/ai/mock-provider.d.ts +1 -1
- package/dist/cli/templates/index.d.ts +1 -8
- package/dist/cli/templates/nodes/agent-router.d.ts +1 -1
- package/dist/cli/templates/nodes/aggregator.d.ts +1 -1
- package/dist/cli/templates/nodes/conversation-memory.d.ts +1 -1
- package/dist/cli/templates/nodes/http.d.ts +1 -1
- package/dist/cli/templates/nodes/human-approval.d.ts +1 -1
- package/dist/cli/templates/nodes/json-extractor.d.ts +1 -1
- package/dist/cli/templates/nodes/llm-call.d.ts +1 -1
- package/dist/cli/templates/nodes/prompt-template.d.ts +1 -1
- package/dist/cli/templates/nodes/rag-retriever.d.ts +1 -1
- package/dist/cli/templates/nodes/tool-executor.d.ts +1 -1
- package/dist/cli/templates/nodes/transformer.d.ts +1 -1
- package/dist/cli/templates/nodes/validator.d.ts +1 -1
- package/dist/cli/templates/shared/approval-types.d.ts +1 -1
- package/dist/cli/templates/shared/case.d.ts +14 -0
- package/dist/cli/templates/shared/llm-types.d.ts +4 -4
- package/dist/cli/templates/workflows/aggregator.d.ts +1 -1
- package/dist/cli/templates/workflows/ai-agent.d.ts +1 -1
- package/dist/cli/templates/workflows/ai-chat.d.ts +1 -1
- package/dist/cli/templates/workflows/ai-rag.d.ts +1 -1
- package/dist/cli/templates/workflows/ai-react.d.ts +1 -1
- package/dist/cli/templates/workflows/approval.d.ts +10 -0
- package/dist/cli/templates/workflows/conditional.d.ts +2 -2
- package/dist/cli/templates/workflows/error-handler.d.ts +2 -2
- package/dist/cli/templates/workflows/foreach.d.ts +1 -1
- package/dist/cli/templates/workflows/sequential.d.ts +1 -1
- package/dist/cli/templates/workflows/webhook.d.ts +1 -1
- package/dist/cli/utils/interactive.d.ts +6 -0
- package/dist/cli/utils/json-option.d.ts +8 -0
- package/dist/cli/utils/logger.d.ts +2 -0
- package/dist/compiler/durable-source-proof.d.ts +23 -0
- package/dist/compiler/executable-artifact.d.ts +29 -0
- package/dist/compiler/index.d.ts +4 -0
- package/dist/compiler/index.js +36 -0
- package/dist/console/app.js +106 -0
- package/dist/console/assets/synergenius.svg +18 -0
- package/dist/console/author.d.ts +32 -0
- package/dist/console/cli-catalog.d.ts +21 -0
- package/dist/console/cli-run.d.ts +35 -0
- package/dist/console/cli-run.js +46 -0
- package/dist/console/debug.d.ts +67 -0
- package/dist/console/diff-view.d.ts +96 -0
- package/dist/console/export.d.ts +36 -0
- package/dist/console/git.d.ts +27 -0
- package/dist/console/index.d.ts +4 -0
- package/dist/console/index.html +16 -0
- package/dist/console/index.js +203 -0
- package/dist/console/packs.d.ts +100 -0
- package/dist/console/request-guard.d.ts +10 -0
- package/dist/console/respond.d.ts +16 -0
- package/dist/console/router.d.ts +64 -0
- package/dist/console/routes-agents.d.ts +14 -0
- package/dist/console/routes-project.d.ts +3 -0
- package/dist/console/routes-runs.d.ts +3 -0
- package/dist/console/routes-services.d.ts +7 -0
- package/dist/console/routes-tools.d.ts +3 -0
- package/dist/console/runs.d.ts +69 -0
- package/dist/console/scan.d.ts +49 -0
- package/dist/console/schema.d.ts +74 -0
- package/dist/console/server.d.ts +34 -0
- package/dist/console/server.js +43264 -0
- package/dist/console/services.d.ts +119 -0
- package/dist/console/source.d.ts +23 -0
- package/dist/console/status.d.ts +68 -0
- package/dist/console/styles.css +1023 -0
- package/dist/console/terminals.d.ts +22 -0
- package/dist/console/workflow-view.d.ts +153 -0
- package/dist/constants.d.ts +5 -1
- package/dist/constants.js +56 -167
- package/dist/context/index.d.ts +10 -0
- package/dist/context/index.js +14 -191
- package/dist/coordinator/agent-gate.d.ts +107 -0
- package/dist/coordinator/bundle-digest.d.ts +20 -0
- package/dist/coordinator/clock-tick.d.ts +4 -0
- package/dist/coordinator/effect-receipts.d.ts +10 -0
- package/dist/coordinator/errors.d.ts +31 -0
- package/dist/coordinator/file-store.d.ts +3 -0
- package/dist/coordinator/gate-labeling.d.ts +33 -0
- package/dist/coordinator/gate-resolution.d.ts +28 -0
- package/dist/coordinator/index.d.ts +12 -0
- package/dist/coordinator/index.js +107 -0
- package/dist/coordinator/memory-store.d.ts +3 -0
- package/dist/coordinator/params.d.ts +18 -0
- package/dist/coordinator/run-annotations.d.ts +6 -0
- package/dist/coordinator/run-context.d.ts +11 -0
- package/dist/coordinator/run-ending.d.ts +5 -0
- package/dist/coordinator/run-outcome.d.ts +31 -0
- package/dist/coordinator/run-resume.d.ts +6 -0
- package/dist/coordinator/run-start.d.ts +4 -0
- package/dist/coordinator/run-store.d.ts +275 -0
- package/dist/coordinator/run-trace.d.ts +41 -0
- package/dist/coordinator/run-views.d.ts +12 -0
- package/dist/coordinator/runs-dir.d.ts +26 -0
- package/dist/coordinator/store.d.ts +67 -0
- package/dist/coordinator/time.d.ts +39 -0
- package/dist/coordinator/workflow-selection.d.ts +6 -0
- package/dist/deployment/index.d.ts +11 -16
- package/dist/deployment/index.js +541 -50
- package/dist/deployment/targets/base.d.ts +11 -13
- package/dist/deployment/targets/openapi-parts.d.ts +92 -0
- package/dist/diagram/arms.d.ts +70 -0
- package/dist/diagram/ascii-renderer.d.ts +1 -1
- package/dist/diagram/geometry.d.ts +20 -32
- package/dist/diagram/graph/bounds.d.ts +30 -0
- package/dist/diagram/graph/metrics.d.ts +21 -0
- package/dist/diagram/graph/nodes.d.ts +33 -0
- package/dist/diagram/graph/placement.d.ts +22 -0
- package/dist/diagram/graph/ports.d.ts +23 -0
- package/dist/diagram/graph/routing.d.ts +40 -0
- package/dist/diagram/graph/scopes.d.ts +30 -0
- package/dist/diagram/index.d.ts +15 -23
- package/dist/diagram/index.js +632 -111
- package/dist/diagram/labels.d.ts +12 -0
- package/dist/diagram/lanes.d.ts +93 -0
- package/dist/diagram/layout.d.ts +1 -1
- package/dist/diagram/material-symbols.d.ts +7 -0
- package/dist/diagram/orthogonal-router.d.ts +2 -3
- package/dist/diagram/process-view.d.ts +79 -0
- package/dist/diagram/spine.d.ts +25 -0
- package/dist/diagram/theme.d.ts +1 -5
- package/dist/diagram/types.d.ts +6 -20
- package/dist/diff/index.js +53 -9
- package/dist/diff/types.d.ts +1 -5
- package/dist/doc-metadata/extractors/annotations.d.ts +0 -4
- package/dist/doc-metadata/extractors/cli-commands.d.ts +2 -1
- package/dist/doc-metadata/extractors/core-metadata.d.ts +19 -4
- package/dist/doc-metadata/extractors/error-codes.d.ts +1 -1
- package/dist/doc-metadata/extractors/mcp-tools.d.ts +7 -3
- package/dist/doc-metadata/index.d.ts +1 -2
- package/dist/doc-metadata/index.js +2368 -9
- package/dist/doc-metadata/types.d.ts +7 -24
- package/dist/docs/guide.d.ts +33 -0
- package/dist/docs/index.d.ts +7 -4
- package/dist/docs/index.js +298 -298
- package/dist/docs/pack-topics.d.ts +18 -0
- package/dist/editor-completions/annotationValues.d.ts +1 -1
- package/dist/editor-completions/contextParser.d.ts +3 -2
- package/dist/editor-completions/dataTypes.d.ts +1 -1
- package/dist/editor-completions/goToDefinition.d.ts +1 -1
- package/dist/editor-completions/index.d.ts +8 -8
- package/dist/editor-completions/index.js +1244 -175
- package/dist/editor-completions/jsDocAnnotations.d.ts +1 -1
- package/dist/editor-completions/modifierCompletions.d.ts +1 -1
- package/dist/export/index.d.ts +7 -1
- package/dist/generated-branding.js +8 -21
- package/dist/generated-version.d.ts +1 -1
- package/dist/generated-version.js +7 -3
- package/dist/generator/annotation-generator.d.ts +84 -0
- package/dist/generator/async-detection.d.ts +1 -1
- package/dist/{body-generator.d.ts → generator/body-generator.d.ts} +7 -3
- package/dist/generator/code-utils.d.ts +15 -60
- package/dist/generator/connection-reads.d.ts +94 -0
- package/dist/generator/control-flow-plan.d.ts +74 -0
- package/dist/generator/control-flow.d.ts +1 -1
- package/dist/generator/exit-assembly.d.ts +11 -0
- package/dist/generator/index.d.ts +4 -5
- package/dist/generator/index.js +34 -11
- package/dist/generator/input-port-values.d.ts +22 -0
- package/dist/generator/{scope-function-generator.d.ts → node-arguments.d.ts} +76 -1
- package/dist/generator/node-invocation.d.ts +74 -0
- package/dist/{node-types-generator.d.ts → generator/node-types-generator.d.ts} +3 -2
- package/dist/generator/scope-closure.d.ts +23 -0
- package/dist/generator/scoped-child.d.ts +49 -0
- package/dist/{sugar-optimizer.d.ts → generator/sugar-optimizer.d.ts} +1 -1
- package/dist/generator/unified.d.ts +14 -2
- package/dist/generator/workflow-generator.d.ts +37 -0
- package/dist/index.d.ts +29 -26
- package/dist/index.js +1322 -92
- package/dist/jsdoc-port-sync/apply-diff.d.ts +15 -0
- package/dist/jsdoc-port-sync/callback-signature.d.ts +17 -0
- package/dist/jsdoc-port-sync/diff.d.ts +5 -7
- package/dist/jsdoc-port-sync/incomplete-lines.d.ts +41 -0
- package/dist/jsdoc-port-sync/index.d.ts +11 -11
- package/dist/jsdoc-port-sync/index.js +88 -45
- package/dist/jsdoc-port-sync/jsdoc-to-signature.d.ts +66 -0
- package/dist/jsdoc-port-sync/port-parser.d.ts +6 -24
- package/dist/jsdoc-port-sync/port-tag-placement.d.ts +55 -0
- package/dist/jsdoc-port-sync/scoped-ports.d.ts +21 -0
- package/dist/jsdoc-port-sync/signature-parser.d.ts +8 -1
- package/dist/jsdoc-port-sync/signature-to-jsdoc.d.ts +77 -0
- package/dist/jsdoc-port-sync/sync.d.ts +4 -1
- package/dist/marketplace/index.d.ts +5 -3
- package/dist/marketplace/index.js +62 -10
- package/dist/marketplace/install.d.ts +24 -0
- package/dist/marketplace/manifest.d.ts +1 -1
- package/dist/marketplace/npmrc.d.ts +24 -0
- package/dist/marketplace/registry.d.ts +46 -11
- package/dist/marketplace/types.d.ts +41 -24
- package/dist/marketplace/validator.d.ts +1 -1
- package/dist/mcp/debug-session.d.ts +2 -4
- package/dist/mcp/dist-imports.d.ts +12 -0
- package/dist/mcp/response-utils.d.ts +11 -9
- package/dist/mcp/server.d.ts +0 -1
- package/dist/mcp/tools-context.d.ts +11 -0
- package/dist/mcp/tools-diagram.d.ts +1 -2
- package/dist/mcp/tools-export.d.ts +2 -2
- package/dist/mcp/tools-marketplace.d.ts +1 -1
- package/dist/mcp/tools-run.d.ts +17 -0
- package/dist/mcp/tools-workflow.d.ts +3 -0
- package/dist/mcp/types.d.ts +4 -14
- package/dist/mcp/workflow-executor.d.ts +57 -19
- package/dist/npm-packages.d.ts +1 -1
- package/dist/npm-packages.js +10 -473
- package/dist/parser/annotation-parser.d.ts +88 -0
- package/dist/parser/annotation-suggestion.d.ts +23 -0
- package/dist/parser/durable-effect-contract.d.ts +10 -0
- package/dist/parser/expression-references.d.ts +101 -0
- package/dist/parser/external-node-types.d.ts +69 -0
- package/dist/{function-like.d.ts → parser/function-like.d.ts} +10 -3
- package/dist/parser/generated-sections.d.ts +25 -0
- package/dist/parser/import-resolution.d.ts +67 -0
- package/dist/parser/import-stub.d.ts +29 -0
- package/dist/parser/jsdoc/config-types.d.ts +209 -0
- package/dist/parser/jsdoc/graph-tags.d.ts +54 -0
- package/dist/parser/jsdoc/node-type-block.d.ts +23 -0
- package/dist/parser/jsdoc/parse-line-once.d.ts +11 -0
- package/dist/parser/jsdoc/port-tags.d.ts +42 -0
- package/dist/parser/jsdoc/runtime-tags.d.ts +65 -0
- package/dist/parser/jsdoc/signature-types.d.ts +52 -0
- package/dist/parser/jsdoc/workflow-block.d.ts +22 -0
- package/dist/parser/jsdoc-parser.d.ts +23 -0
- package/dist/parser/macro-expansion.d.ts +80 -0
- package/dist/parser/module-resolution.d.ts +38 -0
- package/dist/parser/node-inference.d.ts +39 -0
- package/dist/parser/npm-node-types.d.ts +24 -0
- package/dist/parser/pack-handlers.d.ts +12 -0
- package/dist/parser/path-data-resolution.d.ts +75 -0
- package/dist/parser/port-inference.d.ts +15 -0
- package/dist/{resolve-package-types.d.ts → parser/resolve-package-types.d.ts} +4 -0
- package/dist/parser/serialize-deploy-annotations.d.ts +19 -0
- package/dist/parser/tag-registry.d.ts +22 -0
- package/dist/parser/workflow-extraction.d.ts +39 -0
- package/dist/runtime/ExecutionContext.d.ts +87 -99
- package/dist/runtime/continuation-core.d.ts +147 -0
- package/dist/runtime/continuation.d.ts +48 -0
- package/dist/runtime/debug-controller.d.ts +7 -22
- package/dist/runtime/durable-execution.d.ts +176 -0
- package/dist/runtime/events.d.ts +16 -1
- package/dist/runtime/executable-module-contract.d.ts +16 -0
- package/dist/runtime/index.d.ts +13 -10
- package/dist/runtime/index.js +947 -9
- package/dist/runtime/strict-json.d.ts +15 -0
- package/dist/server/access.d.ts +12 -0
- package/dist/server/api.d.ts +126 -0
- package/dist/server/callback-delivery.d.ts +62 -0
- package/dist/server/callback-url.d.ts +44 -0
- package/dist/server/context.d.ts +35 -0
- package/dist/server/http-error.d.ts +10 -0
- package/dist/server/index.d.ts +7 -1
- package/dist/server/index.js +125 -6
- package/dist/server/openapi-document.d.ts +33 -0
- package/dist/server/openapi.d.ts +32 -0
- package/dist/server/respond.d.ts +35 -0
- package/dist/server/route-params.d.ts +17 -0
- package/dist/server/route-plan.d.ts +41 -0
- package/dist/server/routes-catalog.d.ts +5 -0
- package/dist/server/routes-declared.d.ts +12 -0
- package/dist/server/routes-runs.d.ts +8 -0
- package/dist/server/run-driver.d.ts +58 -0
- package/dist/server/run-view.d.ts +26 -0
- package/dist/server/transport.d.ts +35 -0
- package/dist/server/types.d.ts +143 -52
- package/dist/server/webhook-server.d.ts +12 -38
- package/dist/server/workflow-registry.d.ts +7 -4
- package/dist/service-registry.d.ts +49 -0
- package/dist/service-registry.js +123 -0
- package/dist/testing/assertions.d.ts +2 -2
- package/dist/testing/index.d.ts +14 -13
- package/dist/testing/index.js +582 -24
- package/dist/testing/mock-approval.d.ts +3 -5
- package/dist/testing/mock-llm.d.ts +2 -3
- package/dist/testing/recorder.d.ts +5 -6
- package/dist/testing/replayer.d.ts +6 -7
- package/dist/testing/run-store-check.d.ts +3 -0
- package/dist/testing/token-tracker.d.ts +2 -2
- package/dist/{type-mappings.d.ts → types/type-mappings.d.ts} +13 -1
- package/dist/utils/error-utils.d.ts +4 -2
- package/dist/utils/port-ordering.d.ts +2 -2
- package/dist/utils/port-tag-utils.d.ts +1 -1
- package/dist/validation/agent-detection.d.ts +17 -5
- package/dist/validation/agent-rules.d.ts +6 -7
- package/dist/validation/core-rules.d.ts +49 -0
- package/dist/validation/design-rules.d.ts +9 -3
- package/dist/validation/rule-registry.d.ts +3 -3
- package/dist/validation/rules/connections.d.ts +27 -0
- package/dist/validation/rules/context.d.ts +11 -0
- package/dist/validation/rules/cycles.d.ts +17 -0
- package/dist/validation/rules/data-flow.d.ts +19 -0
- package/dist/validation/rules/scope-topology.d.ts +35 -0
- package/dist/validation/rules/type-compatibility.d.ts +30 -0
- package/dist/validation/type-checker.d.ts +39 -0
- package/dist/validation/validator-helpers.d.ts +31 -0
- package/dist/validation/validator.d.ts +30 -0
- package/docs/reference/advanced-annotations.md +277 -60
- package/docs/reference/built-in-nodes.md +164 -94
- package/docs/reference/cancellation.md +44 -0
- package/docs/reference/cli-reference.md +252 -234
- package/docs/reference/compilation.md +36 -109
- package/docs/reference/concepts.md +80 -63
- package/docs/reference/console.md +169 -0
- package/docs/reference/debugging.md +26 -57
- package/docs/reference/deployment.md +217 -143
- package/docs/reference/durable-gates.md +445 -0
- package/docs/reference/error-codes.md +90 -43
- package/docs/reference/export-interface.md +91 -26
- package/docs/reference/iterative-development.md +50 -28
- package/docs/reference/jsdoc-grammar.md +66 -311
- package/docs/reference/library.md +250 -0
- package/docs/reference/marketplace.md +301 -152
- package/docs/reference/mcp-tools.md +102 -0
- package/docs/reference/node-conversion.md +84 -59
- package/docs/reference/orientation.md +68 -0
- package/docs/reference/scaffold.md +5 -4
- package/docs/reference/tutorial.md +106 -166
- package/docs/reference/visual-reference.md +1 -1
- package/package.json +85 -50
- package/dist/agent/agent-loop.js +0 -156
- package/dist/agent/cli-spawn-config.js +0 -65
- package/dist/agent/device-connection.d.ts +0 -79
- package/dist/agent/device-connection.js +0 -184
- package/dist/agent/env-allowlist.js +0 -60
- package/dist/agent/providers/anthropic.js +0 -198
- package/dist/agent/providers/claude-cli.js +0 -161
- package/dist/agent/providers/openai-compat.js +0 -205
- package/dist/agent/providers/platform.d.ts +0 -23
- package/dist/agent/providers/platform.js +0 -132
- package/dist/agent/streaming.js +0 -186
- package/dist/agent/types.js +0 -20
- package/dist/annotation-generator.d.ts +0 -50
- package/dist/annotation-generator.js +0 -743
- package/dist/api/builder.js +0 -345
- package/dist/api/command-runner.js +0 -787
- package/dist/api/compile.js +0 -148
- package/dist/api/extract-types.js +0 -57
- package/dist/api/generate-in-place.js +0 -1477
- package/dist/api/generate.js +0 -514
- package/dist/api/helpers.js +0 -285
- package/dist/api/inline-runtime.js +0 -526
- package/dist/api/manipulation/connections.js +0 -151
- package/dist/api/manipulation/index.js +0 -41
- package/dist/api/manipulation/node-types.js +0 -200
- package/dist/api/manipulation/nodes.js +0 -355
- package/dist/api/manipulation/ports.js +0 -228
- package/dist/api/manipulation/scopes.js +0 -156
- package/dist/api/manipulation/workflow.js +0 -116
- package/dist/api/modify-operation.js +0 -177
- package/dist/api/parse.js +0 -115
- package/dist/api/patterns.d.ts +0 -112
- package/dist/api/patterns.js +0 -303
- package/dist/api/query.js +0 -840
- package/dist/api/templates.js +0 -117
- package/dist/api/transform.js +0 -40
- package/dist/api/validate.js +0 -64
- package/dist/api/validation-registry.js +0 -10
- package/dist/api/workflow-file-operations.js +0 -180
- package/dist/ast/builder.js +0 -395
- package/dist/ast/serialization-node.js +0 -30
- package/dist/ast/serialization.js +0 -134
- package/dist/ast/types.js +0 -2
- package/dist/ast/workflow-utils.js +0 -114
- package/dist/body-generator.js +0 -35
- package/dist/built-in-nodes/coercion-types.js +0 -61
- package/dist/built-in-nodes/delay.js +0 -29
- package/dist/built-in-nodes/generated-registry.js +0 -299
- package/dist/built-in-nodes/invoke-workflow.js +0 -36
- package/dist/built-in-nodes/mock-types.js +0 -42
- package/dist/built-in-nodes/wait-for-agent.js +0 -31
- package/dist/built-in-nodes/wait-for-event.js +0 -25
- package/dist/chevrotain-parser/coerce-parser.js +0 -103
- package/dist/chevrotain-parser/connect-parser.js +0 -136
- package/dist/chevrotain-parser/fan-parser.js +0 -149
- package/dist/chevrotain-parser/grammar-diagrams.js +0 -273
- package/dist/chevrotain-parser/index.js +0 -31
- package/dist/chevrotain-parser/map-parser.js +0 -130
- package/dist/chevrotain-parser/node-parser.js +0 -558
- package/dist/chevrotain-parser/path-parser.js +0 -140
- package/dist/chevrotain-parser/port-parser.js +0 -519
- package/dist/chevrotain-parser/position-parser.d.ts +0 -20
- package/dist/chevrotain-parser/position-parser.js +0 -83
- package/dist/chevrotain-parser/scope-parser.js +0 -104
- package/dist/chevrotain-parser/tokens.js +0 -429
- package/dist/chevrotain-parser/trigger-cancel-parser.js +0 -291
- package/dist/cli/commands/account.d.ts +0 -4
- package/dist/cli/commands/account.js +0 -50
- package/dist/cli/commands/ai-credentials.d.ts +0 -12
- package/dist/cli/commands/ai-credentials.js +0 -95
- package/dist/cli/commands/apikey.d.ts +0 -4
- package/dist/cli/commands/apikey.js +0 -64
- package/dist/cli/commands/auth.d.ts +0 -9
- package/dist/cli/commands/auth.js +0 -255
- package/dist/cli/commands/compile.js +0 -331
- package/dist/cli/commands/connect.d.ts +0 -4
- package/dist/cli/commands/connect.js +0 -163
- package/dist/cli/commands/context.js +0 -51
- package/dist/cli/commands/create.js +0 -139
- package/dist/cli/commands/deploy.d.ts +0 -6
- package/dist/cli/commands/deploy.js +0 -74
- package/dist/cli/commands/dev.js +0 -227
- package/dist/cli/commands/diagram.js +0 -39
- package/dist/cli/commands/diff.js +0 -57
- package/dist/cli/commands/docs.js +0 -74
- package/dist/cli/commands/export.js +0 -153
- package/dist/cli/commands/grammar.js +0 -40
- package/dist/cli/commands/implement.js +0 -91
- package/dist/cli/commands/init-personas.js +0 -541
- package/dist/cli/commands/init.js +0 -797
- package/dist/cli/commands/market.js +0 -440
- package/dist/cli/commands/mcp-setup.js +0 -433
- package/dist/cli/commands/migrate.js +0 -91
- package/dist/cli/commands/modify.js +0 -58
- package/dist/cli/commands/openapi.js +0 -71
- package/dist/cli/commands/org.d.ts +0 -8
- package/dist/cli/commands/org.js +0 -136
- package/dist/cli/commands/pattern.d.ts +0 -34
- package/dist/cli/commands/pattern.js +0 -186
- package/dist/cli/commands/plugin.d.ts +0 -16
- package/dist/cli/commands/plugin.js +0 -176
- package/dist/cli/commands/run.js +0 -742
- package/dist/cli/commands/serve.js +0 -93
- package/dist/cli/commands/status.js +0 -123
- package/dist/cli/commands/strip.js +0 -61
- package/dist/cli/commands/templates.js +0 -58
- package/dist/cli/commands/validate.js +0 -267
- package/dist/cli/commands/watch.js +0 -71
- package/dist/cli/config/credentials.d.ts +0 -15
- package/dist/cli/config/credentials.js +0 -43
- package/dist/cli/config/platform-client.d.ts +0 -123
- package/dist/cli/config/platform-client.js +0 -248
- package/dist/cli/env-setup.js +0 -12
- package/dist/cli/index.js +0 -850
- package/dist/cli/pack-commands.js +0 -122
- package/dist/cli/postinstall.d.ts +0 -16
- package/dist/cli/postinstall.js +0 -119
- package/dist/cli/templates/ai/mock-provider.js +0 -64
- package/dist/cli/templates/ai/types.js +0 -5
- package/dist/cli/templates/approvals/index.d.ts +0 -15
- package/dist/cli/templates/approvals/index.js +0 -241
- package/dist/cli/templates/index.js +0 -123
- package/dist/cli/templates/nodes/agent-router.js +0 -114
- package/dist/cli/templates/nodes/aggregator.js +0 -63
- package/dist/cli/templates/nodes/conversation-memory.js +0 -85
- package/dist/cli/templates/nodes/http.js +0 -80
- package/dist/cli/templates/nodes/human-approval.js +0 -109
- package/dist/cli/templates/nodes/json-extractor.js +0 -119
- package/dist/cli/templates/nodes/llm-call.js +0 -106
- package/dist/cli/templates/nodes/prompt-template.js +0 -52
- package/dist/cli/templates/nodes/rag-retriever.js +0 -128
- package/dist/cli/templates/nodes/tool-executor.js +0 -108
- package/dist/cli/templates/nodes/transformer.js +0 -68
- package/dist/cli/templates/nodes/validator.js +0 -62
- package/dist/cli/templates/pack-loader.js +0 -58
- package/dist/cli/templates/providers/index.js +0 -239
- package/dist/cli/templates/shared/approval-types.js +0 -31
- package/dist/cli/templates/shared/llm-types.js +0 -109
- package/dist/cli/templates/workflows/aggregator.js +0 -101
- package/dist/cli/templates/workflows/ai-agent.js +0 -326
- package/dist/cli/templates/workflows/ai-chat.js +0 -167
- package/dist/cli/templates/workflows/ai-rag.js +0 -184
- package/dist/cli/templates/workflows/ai-react.js +0 -293
- package/dist/cli/templates/workflows/conditional.js +0 -139
- package/dist/cli/templates/workflows/error-handler.js +0 -145
- package/dist/cli/templates/workflows/foreach.js +0 -140
- package/dist/cli/templates/workflows/sequential.js +0 -200
- package/dist/cli/templates/workflows/webhook.js +0 -158
- package/dist/cli/utils/cli-helpers.d.ts +0 -44
- package/dist/cli/utils/cli-helpers.js +0 -99
- package/dist/cli/utils/logger.js +0 -126
- package/dist/cli/utils/parse-int-strict.js +0 -17
- package/dist/cli/utils/safe-write.js +0 -54
- package/dist/deployment/config/defaults.d.ts +0 -29
- package/dist/deployment/config/defaults.js +0 -98
- package/dist/deployment/config/loader.d.ts +0 -24
- package/dist/deployment/config/loader.js +0 -237
- package/dist/deployment/config/types.d.ts +0 -117
- package/dist/deployment/config/types.js +0 -5
- package/dist/deployment/core/adapters.d.ts +0 -66
- package/dist/deployment/core/adapters.js +0 -156
- package/dist/deployment/core/executor.d.ts +0 -62
- package/dist/deployment/core/executor.js +0 -197
- package/dist/deployment/core/formatters.d.ts +0 -42
- package/dist/deployment/core/formatters.js +0 -146
- package/dist/deployment/openapi/generator.d.ts +0 -146
- package/dist/deployment/openapi/generator.js +0 -347
- package/dist/deployment/openapi/schema-converter.d.ts +0 -49
- package/dist/deployment/openapi/schema-converter.js +0 -192
- package/dist/deployment/targets/base.js +0 -855
- package/dist/deployment/types.d.ts +0 -140
- package/dist/deployment/types.js +0 -8
- package/dist/diagram/ascii-renderer.js +0 -528
- package/dist/diagram/geometry.js +0 -1226
- package/dist/diagram/html-viewer.d.ts +0 -21
- package/dist/diagram/html-viewer.js +0 -1745
- package/dist/diagram/layout.js +0 -143
- package/dist/diagram/orthogonal-router.js +0 -458
- package/dist/diagram/renderer.d.ts +0 -3
- package/dist/diagram/renderer.js +0 -280
- package/dist/diagram/theme.js +0 -282
- package/dist/diagram/types.js +0 -2
- package/dist/diff/WorkflowDiffer.js +0 -429
- package/dist/diff/formatDiff.js +0 -239
- package/dist/diff/impact.js +0 -119
- package/dist/diff/types.js +0 -35
- package/dist/doc-metadata/extractors/annotations.js +0 -638
- package/dist/doc-metadata/extractors/cli-commands.js +0 -326
- package/dist/doc-metadata/extractors/core-metadata.js +0 -61
- package/dist/doc-metadata/extractors/error-codes.js +0 -372
- package/dist/doc-metadata/extractors/grammar-rules.js +0 -51
- package/dist/doc-metadata/extractors/mcp-tools.js +0 -705
- package/dist/doc-metadata/extractors/plugin-api.d.ts +0 -19
- package/dist/doc-metadata/extractors/plugin-api.js +0 -279
- package/dist/doc-metadata/types.js +0 -5
- package/dist/editor-completions/annotationValues.js +0 -146
- package/dist/editor-completions/contextParser.js +0 -410
- package/dist/editor-completions/dataTypes.js +0 -95
- package/dist/editor-completions/goToDefinition.js +0 -112
- package/dist/editor-completions/jsDocAnnotations.js +0 -359
- package/dist/editor-completions/modifierCompletions.js +0 -197
- package/dist/editor-completions/types.js +0 -8
- package/dist/export/index.js +0 -212
- package/dist/extensions/index.d.ts +0 -16
- package/dist/extensions/index.js +0 -17
- package/dist/friendly-errors.js +0 -761
- package/dist/function-like.js +0 -84
- package/dist/generator/async-detection.js +0 -56
- package/dist/generator/code-utils.js +0 -551
- package/dist/generator/compile-target-registry.d.ts +0 -20
- package/dist/generator/compile-target-registry.js +0 -20
- package/dist/generator/control-flow.js +0 -358
- package/dist/generator/dev-mode-registry.d.ts +0 -27
- package/dist/generator/dev-mode-registry.js +0 -20
- package/dist/generator/scope-function-generator.js +0 -397
- package/dist/generator/unified.js +0 -1831
- package/dist/generator.d.ts +0 -54
- package/dist/generator.js +0 -101
- package/dist/jsdoc-parser.d.ts +0 -377
- package/dist/jsdoc-parser.js +0 -1189
- package/dist/jsdoc-port-sync/constants.js +0 -103
- package/dist/jsdoc-port-sync/diff.js +0 -319
- package/dist/jsdoc-port-sync/port-parser.js +0 -579
- package/dist/jsdoc-port-sync/rename.js +0 -256
- package/dist/jsdoc-port-sync/signature-parser.js +0 -559
- package/dist/jsdoc-port-sync/sync.js +0 -653
- package/dist/marketplace/manifest.js +0 -194
- package/dist/marketplace/registry.js +0 -198
- package/dist/marketplace/types.js +0 -9
- package/dist/marketplace/validator.js +0 -150
- package/dist/mcp/agent-channel.d.ts +0 -35
- package/dist/mcp/agent-channel.js +0 -61
- package/dist/mcp/auto-registration.d.ts +0 -3
- package/dist/mcp/auto-registration.js +0 -62
- package/dist/mcp/debug-session.js +0 -25
- package/dist/mcp/index.d.ts +0 -11
- package/dist/mcp/index.js +0 -10
- package/dist/mcp/pack-tools.js +0 -59
- package/dist/mcp/prompts.js +0 -68
- package/dist/mcp/response-utils.js +0 -97
- package/dist/mcp/run-registry.d.ts +0 -29
- package/dist/mcp/run-registry.js +0 -24
- package/dist/mcp/server.js +0 -63
- package/dist/mcp/tools-context.js +0 -51
- package/dist/mcp/tools-debug.js +0 -451
- package/dist/mcp/tools-diagram.js +0 -97
- package/dist/mcp/tools-docs.js +0 -62
- package/dist/mcp/tools-export.js +0 -222
- package/dist/mcp/tools-marketplace.js +0 -132
- package/dist/mcp/tools-model.d.ts +0 -3
- package/dist/mcp/tools-model.js +0 -279
- package/dist/mcp/tools-pattern.d.ts +0 -3
- package/dist/mcp/tools-pattern.js +0 -604
- package/dist/mcp/tools-query.js +0 -377
- package/dist/mcp/tools-resources.js +0 -41
- package/dist/mcp/tools-template.js +0 -119
- package/dist/mcp/tools-workflow-run.d.ts +0 -40
- package/dist/mcp/tools-workflow-run.js +0 -150
- package/dist/mcp/types.js +0 -2
- package/dist/mcp/workflow-executor.js +0 -242
- package/dist/migration/registry.js +0 -29
- package/dist/node-types-generator.js +0 -139
- package/dist/parser/tag-registry.js +0 -57
- package/dist/parser.d.ts +0 -232
- package/dist/parser.js +0 -2500
- package/dist/plugin/PluginPanel.d.ts +0 -12
- package/dist/plugin/PluginPanel.js +0 -5
- package/dist/plugin/index.d.ts +0 -13
- package/dist/plugin/index.js +0 -14
- package/dist/plugin/types.d.ts +0 -75
- package/dist/plugin/types.js +0 -8
- package/dist/resolve-package-types.js +0 -123
- package/dist/runtime/CancellationError.js +0 -20
- package/dist/runtime/ExecutionContext.js +0 -280
- package/dist/runtime/builtin-functions.js +0 -549
- package/dist/runtime/checkpoint.d.ts +0 -84
- package/dist/runtime/checkpoint.js +0 -225
- package/dist/runtime/debug-controller.js +0 -247
- package/dist/runtime/events.js +0 -2
- package/dist/runtime/function-registry.js +0 -66
- package/dist/runtime/parameter-resolver.js +0 -113
- package/dist/server/types.js +0 -5
- package/dist/server/webhook-server.js +0 -269
- package/dist/server/workflow-registry.js +0 -202
- package/dist/shared-project.js +0 -28
- package/dist/sugar-optimizer.js +0 -498
- package/dist/testing/assertions.js +0 -127
- package/dist/testing/mock-approval.js +0 -98
- package/dist/testing/mock-llm.js +0 -119
- package/dist/testing/recorder.js +0 -70
- package/dist/testing/replayer.js +0 -143
- package/dist/testing/token-tracker.js +0 -94
- package/dist/type-checker.d.ts +0 -42
- package/dist/type-checker.js +0 -190
- package/dist/type-mappings.js +0 -131
- package/dist/types/branded-ports.d.ts +0 -151
- package/dist/types/branded-ports.js +0 -121
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -5
- package/dist/types.d.ts +0 -139
- package/dist/types.js +0 -15
- package/dist/utils/error-utils.js +0 -27
- package/dist/utils/lru-cache.js +0 -40
- package/dist/utils/port-ordering.js +0 -81
- package/dist/utils/port-tag-utils.js +0 -41
- package/dist/utils/string-distance.js +0 -56
- package/dist/validation/agent-detection.js +0 -115
- package/dist/validation/agent-rules.js +0 -262
- package/dist/validation/design-rules.js +0 -377
- package/dist/validation/rule-registry.js +0 -37
- package/dist/validator.d.ts +0 -113
- package/dist/validator.js +0 -1631
- package/docs/reference/patterns.md +0 -159
- package/scripts/postinstall.cjs +0 -86
- /package/dist/{shared-project.d.ts → parser/shared-project.d.ts} +0 -0
- /package/dist/{friendly-errors.d.ts → validation/friendly-errors.d.ts} +0 -0
|
@@ -0,0 +1,2001 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NODE_DEFAULT_COLOR,
|
|
3
|
+
NODE_VARIANT_COLORS,
|
|
4
|
+
TYPE_ABBREVIATIONS,
|
|
5
|
+
getPortColor
|
|
6
|
+
} from "./chunk-XAV22WD7.js";
|
|
7
|
+
import {
|
|
8
|
+
assignImplicitPortOrders
|
|
9
|
+
} from "./chunk-VP2P3BPA.js";
|
|
10
|
+
import {
|
|
11
|
+
SCOPED_PORT_NAMES,
|
|
12
|
+
isExecutePort,
|
|
13
|
+
isExitNode,
|
|
14
|
+
isFailurePort,
|
|
15
|
+
isScopedFailurePort,
|
|
16
|
+
isScopedStartPort,
|
|
17
|
+
isScopedSuccessPort,
|
|
18
|
+
isSuccessPort
|
|
19
|
+
} from "./chunk-R4QGNK34.js";
|
|
20
|
+
|
|
21
|
+
// src/diagram/layout.ts
|
|
22
|
+
function layoutWorkflow(ast) {
|
|
23
|
+
const nodeIds = /* @__PURE__ */ new Set();
|
|
24
|
+
nodeIds.add("Start");
|
|
25
|
+
nodeIds.add("Exit");
|
|
26
|
+
const scopedChildren = /* @__PURE__ */ new Set();
|
|
27
|
+
if (ast.scopes) {
|
|
28
|
+
for (const children of Object.values(ast.scopes)) {
|
|
29
|
+
for (const child of children) {
|
|
30
|
+
scopedChildren.add(child);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const inst of ast.instances) {
|
|
35
|
+
if (!scopedChildren.has(inst.id)) {
|
|
36
|
+
nodeIds.add(inst.id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const forward = /* @__PURE__ */ new Map();
|
|
40
|
+
const backward = /* @__PURE__ */ new Map();
|
|
41
|
+
for (const id of nodeIds) {
|
|
42
|
+
forward.set(id, /* @__PURE__ */ new Set());
|
|
43
|
+
backward.set(id, /* @__PURE__ */ new Set());
|
|
44
|
+
}
|
|
45
|
+
for (const conn of ast.connections) {
|
|
46
|
+
if (conn.from.scope || conn.to.scope) continue;
|
|
47
|
+
const from = conn.from.node;
|
|
48
|
+
const to = conn.to.node;
|
|
49
|
+
if (!nodeIds.has(from) || !nodeIds.has(to)) continue;
|
|
50
|
+
forward.get(from).add(to);
|
|
51
|
+
backward.get(to).add(from);
|
|
52
|
+
}
|
|
53
|
+
const nodeLayer = /* @__PURE__ */ new Map();
|
|
54
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
55
|
+
for (const id of nodeIds) {
|
|
56
|
+
inDegree.set(id, backward.get(id).size);
|
|
57
|
+
}
|
|
58
|
+
const queue = [];
|
|
59
|
+
for (const id of nodeIds) {
|
|
60
|
+
if (inDegree.get(id) === 0) {
|
|
61
|
+
queue.push(id);
|
|
62
|
+
nodeLayer.set(id, 0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!nodeLayer.has("Start")) {
|
|
66
|
+
nodeLayer.set("Start", 0);
|
|
67
|
+
queue.push("Start");
|
|
68
|
+
}
|
|
69
|
+
let head = 0;
|
|
70
|
+
while (head < queue.length) {
|
|
71
|
+
const node = queue[head++];
|
|
72
|
+
const layer = nodeLayer.get(node);
|
|
73
|
+
for (const next of forward.get(node)) {
|
|
74
|
+
const candidate = layer + 1;
|
|
75
|
+
if (!nodeLayer.has(next) || nodeLayer.get(next) < candidate) {
|
|
76
|
+
nodeLayer.set(next, candidate);
|
|
77
|
+
}
|
|
78
|
+
inDegree.set(next, inDegree.get(next) - 1);
|
|
79
|
+
if (inDegree.get(next) === 0) {
|
|
80
|
+
queue.push(next);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const id of nodeIds) {
|
|
85
|
+
if (!nodeLayer.has(id)) {
|
|
86
|
+
nodeLayer.set(id, 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
let maxLayer = 0;
|
|
90
|
+
for (const [id, layer] of nodeLayer) {
|
|
91
|
+
if (!isExitNode(id) && layer > maxLayer) {
|
|
92
|
+
maxLayer = layer;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
nodeLayer.set("Exit", maxLayer + 1);
|
|
96
|
+
const layerCount = nodeLayer.get("Exit") + 1;
|
|
97
|
+
const layers = Array.from({ length: layerCount }, () => []);
|
|
98
|
+
for (const [id, layer] of nodeLayer) {
|
|
99
|
+
layers[layer].push(id);
|
|
100
|
+
}
|
|
101
|
+
for (let sweep = 0; sweep < 4; sweep++) {
|
|
102
|
+
if (sweep % 2 === 0) {
|
|
103
|
+
for (let l = 1; l < layerCount; l++) {
|
|
104
|
+
sortLayerByBarycenter(layers[l], layers[l - 1], backward, forward);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
for (let l = layerCount - 2; l >= 0; l--) {
|
|
108
|
+
sortLayerByBarycenter(layers[l], layers[l + 1], forward, backward);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { layers, nodeLayer };
|
|
113
|
+
}
|
|
114
|
+
function sortLayerByBarycenter(layer, referenceLayer, _adjacencyToRef, _adjacencyFromRef) {
|
|
115
|
+
const refPositions = /* @__PURE__ */ new Map();
|
|
116
|
+
referenceLayer.forEach((id, i) => refPositions.set(id, i));
|
|
117
|
+
const barycenters = /* @__PURE__ */ new Map();
|
|
118
|
+
for (const nodeId of layer) {
|
|
119
|
+
const neighbors = [];
|
|
120
|
+
const fwd = _adjacencyToRef.get(nodeId);
|
|
121
|
+
const bwd = _adjacencyFromRef.get(nodeId);
|
|
122
|
+
if (fwd) {
|
|
123
|
+
for (const n of fwd) {
|
|
124
|
+
if (refPositions.has(n)) neighbors.push(refPositions.get(n));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (bwd) {
|
|
128
|
+
for (const n of bwd) {
|
|
129
|
+
if (refPositions.has(n)) neighbors.push(refPositions.get(n));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (neighbors.length > 0) {
|
|
133
|
+
barycenters.set(nodeId, neighbors.reduce((a, b) => a + b, 0) / neighbors.length);
|
|
134
|
+
} else {
|
|
135
|
+
barycenters.set(nodeId, Infinity);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
layer.sort((a, b) => barycenters.get(a) - barycenters.get(b));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/diagram/graph/metrics.ts
|
|
142
|
+
var PORT_RADIUS = 7;
|
|
143
|
+
var PORT_SIZE = PORT_RADIUS * 2;
|
|
144
|
+
var PORT_GAP = 8;
|
|
145
|
+
var PORT_PADDING_Y = 18;
|
|
146
|
+
var NODE_MIN_WIDTH = 90;
|
|
147
|
+
var NODE_MIN_HEIGHT = 90;
|
|
148
|
+
var LABEL_CLEARANCE = 42;
|
|
149
|
+
var LABEL_HEIGHT = 24;
|
|
150
|
+
var LABEL_GAP = 12;
|
|
151
|
+
var CHAR_WIDTHS = {
|
|
152
|
+
" ": 2.78,
|
|
153
|
+
"!": 3.34,
|
|
154
|
+
'"': 4.74,
|
|
155
|
+
"#": 5.56,
|
|
156
|
+
"$": 5.56,
|
|
157
|
+
"%": 8.9,
|
|
158
|
+
"&": 7.23,
|
|
159
|
+
"'": 2.38,
|
|
160
|
+
"(": 3.34,
|
|
161
|
+
")": 3.34,
|
|
162
|
+
"*": 3.9,
|
|
163
|
+
"+": 5.84,
|
|
164
|
+
",": 2.78,
|
|
165
|
+
"-": 3.34,
|
|
166
|
+
".": 2.78,
|
|
167
|
+
"/": 3.95,
|
|
168
|
+
"0": 5.56,
|
|
169
|
+
"1": 5.56,
|
|
170
|
+
"2": 5.56,
|
|
171
|
+
"3": 5.56,
|
|
172
|
+
"4": 5.56,
|
|
173
|
+
"5": 5.56,
|
|
174
|
+
"6": 5.56,
|
|
175
|
+
"7": 5.56,
|
|
176
|
+
"8": 5.56,
|
|
177
|
+
"9": 5.56,
|
|
178
|
+
":": 3.34,
|
|
179
|
+
";": 3.34,
|
|
180
|
+
"<": 5.86,
|
|
181
|
+
"=": 5.84,
|
|
182
|
+
">": 5.86,
|
|
183
|
+
"?": 6.11,
|
|
184
|
+
"@": 9.76,
|
|
185
|
+
A: 7.23,
|
|
186
|
+
B: 7.23,
|
|
187
|
+
C: 7.23,
|
|
188
|
+
D: 7.23,
|
|
189
|
+
E: 6.67,
|
|
190
|
+
F: 6.11,
|
|
191
|
+
G: 7.78,
|
|
192
|
+
H: 7.23,
|
|
193
|
+
I: 2.78,
|
|
194
|
+
J: 5.56,
|
|
195
|
+
K: 7.23,
|
|
196
|
+
L: 6.11,
|
|
197
|
+
M: 8.34,
|
|
198
|
+
N: 7.23,
|
|
199
|
+
O: 7.78,
|
|
200
|
+
P: 6.67,
|
|
201
|
+
Q: 7.78,
|
|
202
|
+
R: 7.23,
|
|
203
|
+
S: 6.67,
|
|
204
|
+
T: 6.11,
|
|
205
|
+
U: 7.23,
|
|
206
|
+
V: 6.67,
|
|
207
|
+
W: 9.45,
|
|
208
|
+
X: 6.67,
|
|
209
|
+
Y: 6.67,
|
|
210
|
+
Z: 6.11,
|
|
211
|
+
"[": 3.34,
|
|
212
|
+
"\\": 3.95,
|
|
213
|
+
"]": 3.34,
|
|
214
|
+
"^": 5.84,
|
|
215
|
+
"_": 5.56,
|
|
216
|
+
"`": 3.58,
|
|
217
|
+
a: 5.56,
|
|
218
|
+
b: 6.11,
|
|
219
|
+
c: 5.56,
|
|
220
|
+
d: 6.11,
|
|
221
|
+
e: 5.56,
|
|
222
|
+
f: 3.34,
|
|
223
|
+
g: 6.11,
|
|
224
|
+
h: 6.11,
|
|
225
|
+
i: 2.78,
|
|
226
|
+
j: 2.78,
|
|
227
|
+
k: 5.56,
|
|
228
|
+
l: 2.78,
|
|
229
|
+
m: 8.9,
|
|
230
|
+
n: 6.11,
|
|
231
|
+
o: 6.11,
|
|
232
|
+
p: 6.11,
|
|
233
|
+
q: 6.11,
|
|
234
|
+
r: 3.9,
|
|
235
|
+
s: 5.56,
|
|
236
|
+
t: 3.34,
|
|
237
|
+
u: 6.11,
|
|
238
|
+
v: 5.56,
|
|
239
|
+
w: 7.78,
|
|
240
|
+
x: 5.56,
|
|
241
|
+
y: 5.56,
|
|
242
|
+
z: 5,
|
|
243
|
+
"{": 3.9,
|
|
244
|
+
"|": 2.8,
|
|
245
|
+
"}": 3.9,
|
|
246
|
+
"~": 5.96
|
|
247
|
+
};
|
|
248
|
+
var DEFAULT_CHAR_WIDTH = 5.56;
|
|
249
|
+
function measureText(text) {
|
|
250
|
+
let width = 0;
|
|
251
|
+
for (let i = 0; i < text.length; i++) {
|
|
252
|
+
width += CHAR_WIDTHS[text[i]] ?? DEFAULT_CHAR_WIDTH;
|
|
253
|
+
}
|
|
254
|
+
return width;
|
|
255
|
+
}
|
|
256
|
+
function portBadgeWidth(port) {
|
|
257
|
+
const abbrev = TYPE_ABBREVIATIONS[port.dataType] ?? port.dataType;
|
|
258
|
+
const typeWidth = measureText(abbrev);
|
|
259
|
+
const labelWidth = measureText(port.label);
|
|
260
|
+
const pad = 7;
|
|
261
|
+
const divGap = 4;
|
|
262
|
+
return pad + typeWidth + divGap + 1 + divGap + labelWidth + pad;
|
|
263
|
+
}
|
|
264
|
+
function portLabelExtent(port) {
|
|
265
|
+
const badgeGap = 5;
|
|
266
|
+
return PORT_RADIUS + badgeGap + portBadgeWidth(port);
|
|
267
|
+
}
|
|
268
|
+
function maxPortLabelExtent(ports) {
|
|
269
|
+
if (ports.length === 0) return 0;
|
|
270
|
+
let max = 0;
|
|
271
|
+
for (const port of ports) {
|
|
272
|
+
const abbrev = TYPE_ABBREVIATIONS[port.dataType] ?? port.dataType;
|
|
273
|
+
const badgeTextWidth = measureText(abbrev) + measureText(port.label);
|
|
274
|
+
const badgeWidth = badgeTextWidth + 23;
|
|
275
|
+
max = Math.max(max, PORT_RADIUS + 5 + badgeWidth);
|
|
276
|
+
}
|
|
277
|
+
return max;
|
|
278
|
+
}
|
|
279
|
+
function portsColumnHeight(count) {
|
|
280
|
+
if (count === 0) return 0;
|
|
281
|
+
return PORT_PADDING_Y + count * PORT_SIZE + (count - 1) * PORT_GAP + PORT_PADDING_Y;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/diagram/graph/bounds.ts
|
|
285
|
+
var PADDING = 40;
|
|
286
|
+
function normalizeNodes(nodes) {
|
|
287
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
288
|
+
for (const node of nodes) {
|
|
289
|
+
const labelTop = node.y - LABEL_HEIGHT - LABEL_GAP;
|
|
290
|
+
const inputLabelExtent = maxPortLabelExtent(node.inputs);
|
|
291
|
+
const outputLabelExtent = maxPortLabelExtent(node.outputs);
|
|
292
|
+
minX = Math.min(minX, node.x - inputLabelExtent);
|
|
293
|
+
minY = Math.min(minY, labelTop);
|
|
294
|
+
maxX = Math.max(maxX, node.x + node.width + outputLabelExtent);
|
|
295
|
+
maxY = Math.max(maxY, node.y + node.height);
|
|
296
|
+
}
|
|
297
|
+
const offsetX = -minX + PADDING;
|
|
298
|
+
const offsetY = -minY + PADDING;
|
|
299
|
+
const shiftPorts = (ports) => {
|
|
300
|
+
for (const p of ports) {
|
|
301
|
+
p.cx += offsetX;
|
|
302
|
+
p.cy += offsetY;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
for (const node of nodes) {
|
|
306
|
+
node.x += offsetX;
|
|
307
|
+
node.y += offsetY;
|
|
308
|
+
shiftPorts(node.inputs);
|
|
309
|
+
shiftPorts(node.outputs);
|
|
310
|
+
if (node.scopeChildren) {
|
|
311
|
+
for (const child of node.scopeChildren) {
|
|
312
|
+
child.x += offsetX;
|
|
313
|
+
child.y += offsetY;
|
|
314
|
+
shiftPorts(child.inputs);
|
|
315
|
+
shiftPorts(child.outputs);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (node.scopePorts) {
|
|
319
|
+
shiftPorts(node.scopePorts.inputs);
|
|
320
|
+
shiftPorts(node.scopePorts.outputs);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return { minX, minY, maxX, maxY };
|
|
324
|
+
}
|
|
325
|
+
function graphBounds(extent, connections, nodes) {
|
|
326
|
+
const { minX, minY, maxX, maxY } = extent;
|
|
327
|
+
let originX = 0;
|
|
328
|
+
let originY = 0;
|
|
329
|
+
let normalizedMaxY = maxY - minY + PADDING * 2;
|
|
330
|
+
let normalizedMaxX = maxX - minX + PADDING * 2;
|
|
331
|
+
const allConns = [...connections];
|
|
332
|
+
for (const node of nodes) {
|
|
333
|
+
if (node.scopeConnections) allConns.push(...node.scopeConnections);
|
|
334
|
+
}
|
|
335
|
+
for (const conn of allConns) {
|
|
336
|
+
const pe = pathExtent(conn.path);
|
|
337
|
+
if (pe.maxY + PADDING > normalizedMaxY) normalizedMaxY = pe.maxY + PADDING;
|
|
338
|
+
if (pe.maxX + PADDING > normalizedMaxX) normalizedMaxX = pe.maxX + PADDING;
|
|
339
|
+
if (pe.minY - PADDING < originY) originY = pe.minY - PADDING;
|
|
340
|
+
if (pe.minX - PADDING < originX) originX = pe.minX - PADDING;
|
|
341
|
+
}
|
|
342
|
+
normalizedMaxX -= originX;
|
|
343
|
+
normalizedMaxY -= originY;
|
|
344
|
+
return { width: normalizedMaxX, height: normalizedMaxY, originX, originY };
|
|
345
|
+
}
|
|
346
|
+
function pathExtent(path) {
|
|
347
|
+
let minX = Infinity, minY = Infinity;
|
|
348
|
+
let maxX = -Infinity, maxY = -Infinity;
|
|
349
|
+
const pattern = /(-?[\d.]+),(-?[\d.]+)/g;
|
|
350
|
+
let m;
|
|
351
|
+
while ((m = pattern.exec(path)) !== null) {
|
|
352
|
+
const x = parseFloat(m[1]);
|
|
353
|
+
const y = parseFloat(m[2]);
|
|
354
|
+
minX = Math.min(minX, x);
|
|
355
|
+
minY = Math.min(minY, y);
|
|
356
|
+
maxX = Math.max(maxX, x);
|
|
357
|
+
maxY = Math.max(maxY, y);
|
|
358
|
+
}
|
|
359
|
+
return { minX, minY, maxX, maxY };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// src/diagram/graph/ports.ts
|
|
363
|
+
function orderedPorts(ports, direction) {
|
|
364
|
+
const cloned = {};
|
|
365
|
+
for (const [name, def] of Object.entries(ports)) {
|
|
366
|
+
cloned[name] = { ...def, metadata: def.metadata ? { ...def.metadata } : void 0 };
|
|
367
|
+
}
|
|
368
|
+
assignImplicitPortOrders(cloned);
|
|
369
|
+
return Object.entries(cloned).sort(([, a], [, b]) => {
|
|
370
|
+
const orderA = a.metadata?.order ?? Infinity;
|
|
371
|
+
const orderB = b.metadata?.order ?? Infinity;
|
|
372
|
+
return orderA - orderB;
|
|
373
|
+
}).map(([name, def]) => ({
|
|
374
|
+
name,
|
|
375
|
+
label: def.label ?? name,
|
|
376
|
+
dataType: def.dataType,
|
|
377
|
+
direction,
|
|
378
|
+
isControlFlow: def.dataType === "STEP",
|
|
379
|
+
isFailure: !!def.failure,
|
|
380
|
+
cx: 0,
|
|
381
|
+
cy: 0
|
|
382
|
+
}));
|
|
383
|
+
}
|
|
384
|
+
function filterHiddenPorts(ports) {
|
|
385
|
+
const result = {};
|
|
386
|
+
for (const [name, def] of Object.entries(ports)) {
|
|
387
|
+
if (!def.hidden) result[name] = def;
|
|
388
|
+
}
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
function filterNonScopedPorts(ports) {
|
|
392
|
+
const result = {};
|
|
393
|
+
for (const [name, def] of Object.entries(ports)) {
|
|
394
|
+
if (!def.scope) result[name] = def;
|
|
395
|
+
}
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
function computePortPositions(node) {
|
|
399
|
+
positionPortList(node.inputs, node.x, node.y);
|
|
400
|
+
positionPortList(node.outputs, node.x + node.width, node.y);
|
|
401
|
+
}
|
|
402
|
+
function positionPortList(ports, cx, nodeY) {
|
|
403
|
+
if (ports.length === 0) return;
|
|
404
|
+
for (let i = 0; i < ports.length; i++) {
|
|
405
|
+
ports[i].cx = cx;
|
|
406
|
+
ports[i].cy = nodeY + PORT_PADDING_Y + i * (PORT_SIZE + PORT_GAP) + PORT_SIZE / 2;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/diagram/graph/nodes.ts
|
|
411
|
+
function buildNodeTypeMap(ast) {
|
|
412
|
+
const nodeTypeMap = /* @__PURE__ */ new Map();
|
|
413
|
+
for (const nt of ast.nodeTypes) {
|
|
414
|
+
nodeTypeMap.set(nt.name, nt);
|
|
415
|
+
if (nt.functionName && nt.functionName !== nt.name) {
|
|
416
|
+
nodeTypeMap.set(nt.functionName, nt);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return nodeTypeMap;
|
|
420
|
+
}
|
|
421
|
+
function computeNodeDimensions(node) {
|
|
422
|
+
const maxPorts = Math.max(node.inputs.length, node.outputs.length);
|
|
423
|
+
const portsHeight = maxPorts > 0 ? PORT_PADDING_Y + maxPorts * PORT_SIZE + (maxPorts - 1) * PORT_GAP + PORT_PADDING_Y : 0;
|
|
424
|
+
node.width = NODE_MIN_WIDTH;
|
|
425
|
+
node.height = Math.max(NODE_MIN_HEIGHT, portsHeight);
|
|
426
|
+
}
|
|
427
|
+
function buildStartNode(ast) {
|
|
428
|
+
const allStartPorts = filterHiddenPorts({ ...ast.startPorts });
|
|
429
|
+
if (!allStartPorts.execute && !ast.startPorts.execute?.hidden) {
|
|
430
|
+
allStartPorts.execute = { dataType: "STEP" };
|
|
431
|
+
}
|
|
432
|
+
const startOutputs = orderedPorts(allStartPorts, "OUTPUT");
|
|
433
|
+
return {
|
|
434
|
+
id: "Start",
|
|
435
|
+
label: "Start",
|
|
436
|
+
color: NODE_DEFAULT_COLOR,
|
|
437
|
+
icon: "startNode",
|
|
438
|
+
isVirtual: true,
|
|
439
|
+
inputs: [],
|
|
440
|
+
outputs: startOutputs,
|
|
441
|
+
x: 0,
|
|
442
|
+
y: 0,
|
|
443
|
+
width: NODE_MIN_WIDTH,
|
|
444
|
+
height: NODE_MIN_HEIGHT
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function buildExitNode(ast) {
|
|
448
|
+
const allExitPorts = filterHiddenPorts({ ...ast.exitPorts });
|
|
449
|
+
if (!allExitPorts.onSuccess && !ast.exitPorts.onSuccess?.hidden) {
|
|
450
|
+
allExitPorts.onSuccess = { dataType: "STEP", isControlFlow: true };
|
|
451
|
+
}
|
|
452
|
+
if (!allExitPorts.onFailure && !ast.exitPorts.onFailure?.hidden) {
|
|
453
|
+
allExitPorts.onFailure = { dataType: "STEP", isControlFlow: true, failure: true };
|
|
454
|
+
} else if (allExitPorts.onFailure) {
|
|
455
|
+
allExitPorts.onFailure = { ...allExitPorts.onFailure, failure: true };
|
|
456
|
+
}
|
|
457
|
+
const exitInputs = orderedPorts(allExitPorts, "INPUT");
|
|
458
|
+
return {
|
|
459
|
+
id: "Exit",
|
|
460
|
+
label: "Exit",
|
|
461
|
+
color: NODE_DEFAULT_COLOR,
|
|
462
|
+
icon: "exitNode",
|
|
463
|
+
isVirtual: true,
|
|
464
|
+
inputs: exitInputs,
|
|
465
|
+
outputs: [],
|
|
466
|
+
x: 0,
|
|
467
|
+
y: 0,
|
|
468
|
+
width: NODE_MIN_WIDTH,
|
|
469
|
+
height: NODE_MIN_HEIGHT
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function collectWiredStepPorts(ast) {
|
|
473
|
+
const stepPortsUsed = /* @__PURE__ */ new Map();
|
|
474
|
+
const noteStep = (nodeId, port) => {
|
|
475
|
+
if (!isExecutePort(port) && !isSuccessPort(port) && !isFailurePort(port)) return;
|
|
476
|
+
let s = stepPortsUsed.get(nodeId);
|
|
477
|
+
if (!s) stepPortsUsed.set(nodeId, s = /* @__PURE__ */ new Set());
|
|
478
|
+
s.add(port);
|
|
479
|
+
};
|
|
480
|
+
for (const conn of ast.connections) {
|
|
481
|
+
noteStep(conn.from.node, conn.from.port);
|
|
482
|
+
noteStep(conn.to.node, conn.to.port);
|
|
483
|
+
}
|
|
484
|
+
return stepPortsUsed;
|
|
485
|
+
}
|
|
486
|
+
function buildInstanceNode(instId, instNodeType, instConfig, nodeTypeMap, theme = "dark", connectedStepPorts) {
|
|
487
|
+
const nt = nodeTypeMap.get(instNodeType);
|
|
488
|
+
const allInputs = nt ? filterHiddenPorts(filterNonScopedPorts(nt.inputs)) : {};
|
|
489
|
+
const allOutputs = nt ? filterHiddenPorts(filterNonScopedPorts(nt.outputs)) : {};
|
|
490
|
+
const pullStyle = !!nt?.expression && connectedStepPorts !== void 0 && connectedStepPorts.size === 0;
|
|
491
|
+
if (pullStyle) {
|
|
492
|
+
delete allInputs.execute;
|
|
493
|
+
delete allOutputs.onSuccess;
|
|
494
|
+
delete allOutputs.onFailure;
|
|
495
|
+
}
|
|
496
|
+
if (nt && !nt.expression) {
|
|
497
|
+
if (!allInputs.execute && !nt.inputs.execute?.hidden) allInputs.execute = { dataType: "STEP" };
|
|
498
|
+
}
|
|
499
|
+
if (!pullStyle && nt && nt.hasSuccessPort && !allOutputs.onSuccess && !nt.outputs.onSuccess?.hidden) {
|
|
500
|
+
allOutputs.onSuccess = { dataType: "STEP", isControlFlow: true };
|
|
501
|
+
}
|
|
502
|
+
if (!pullStyle && nt && nt.hasFailurePort && !allOutputs.onFailure && !nt.outputs.onFailure?.hidden) {
|
|
503
|
+
allOutputs.onFailure = { dataType: "STEP", isControlFlow: true, failure: true };
|
|
504
|
+
}
|
|
505
|
+
const resolvedIcon = instConfig?.icon ?? nt?.visuals?.icon ?? resolveDefaultIcon(nt);
|
|
506
|
+
return {
|
|
507
|
+
id: instId,
|
|
508
|
+
label: instConfig?.label ?? nt?.label ?? instId,
|
|
509
|
+
color: resolveNodeColor(instConfig?.color ?? nt?.visuals?.color, theme),
|
|
510
|
+
icon: resolvedIcon,
|
|
511
|
+
isVirtual: false,
|
|
512
|
+
inputs: orderedPorts(allInputs, "INPUT"),
|
|
513
|
+
outputs: orderedPorts(allOutputs, "OUTPUT"),
|
|
514
|
+
x: 0,
|
|
515
|
+
y: 0,
|
|
516
|
+
width: NODE_MIN_WIDTH,
|
|
517
|
+
height: NODE_MIN_HEIGHT
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function applySizeOverrides(ast, diagramNodes, scopedChildren) {
|
|
521
|
+
for (const inst of ast.instances) {
|
|
522
|
+
if (scopedChildren.has(inst.id)) continue;
|
|
523
|
+
const node = diagramNodes.get(inst.id);
|
|
524
|
+
if (!node) continue;
|
|
525
|
+
if (inst.config?.width != null) node.width = inst.config.width;
|
|
526
|
+
if (inst.config?.height != null) node.height = inst.config.height;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function resolveNodeColor(color, theme = "dark") {
|
|
530
|
+
if (!color) return NODE_DEFAULT_COLOR;
|
|
531
|
+
const variant = NODE_VARIANT_COLORS[color];
|
|
532
|
+
if (variant) return theme === "dark" ? variant.darkBorder : variant.border;
|
|
533
|
+
return color;
|
|
534
|
+
}
|
|
535
|
+
function resolveDefaultIcon(nt) {
|
|
536
|
+
if (!nt) return "code";
|
|
537
|
+
if (nt.variant === "WORKFLOW" || nt.variant === "IMPORTED_WORKFLOW") return "flow";
|
|
538
|
+
return "code";
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/diagram/graph/placement.ts
|
|
542
|
+
var LAYER_GAP_X = 300;
|
|
543
|
+
var MIN_EDGE_GAP = 112;
|
|
544
|
+
var NODE_GAP_Y = 60;
|
|
545
|
+
function layerOutputExtent(layerNodes, diagramNodes) {
|
|
546
|
+
let max = 0;
|
|
547
|
+
for (const id of layerNodes) {
|
|
548
|
+
const node = diagramNodes.get(id);
|
|
549
|
+
max = Math.max(max, maxPortLabelExtent(node.outputs));
|
|
550
|
+
}
|
|
551
|
+
return max;
|
|
552
|
+
}
|
|
553
|
+
function layerInputExtent(layerNodes, diagramNodes) {
|
|
554
|
+
let max = 0;
|
|
555
|
+
for (const id of layerNodes) {
|
|
556
|
+
const node = diagramNodes.get(id);
|
|
557
|
+
max = Math.max(max, maxPortLabelExtent(node.inputs));
|
|
558
|
+
}
|
|
559
|
+
return max;
|
|
560
|
+
}
|
|
561
|
+
function adaptiveGapY(layerSize) {
|
|
562
|
+
if (layerSize <= 2) return NODE_GAP_Y;
|
|
563
|
+
return Math.max(24, Math.round(NODE_GAP_Y * 2 / layerSize));
|
|
564
|
+
}
|
|
565
|
+
function assignLayerCoordinates(layers, diagramNodes) {
|
|
566
|
+
const filtered = layers.map((l) => l.filter((id) => diagramNodes.has(id)));
|
|
567
|
+
let currentX = 0;
|
|
568
|
+
for (let i = 0; i < filtered.length; i++) {
|
|
569
|
+
const layerNodes = filtered[i];
|
|
570
|
+
if (layerNodes.length === 0) {
|
|
571
|
+
currentX += LAYER_GAP_X;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const maxWidth = Math.max(...layerNodes.map((id) => diagramNodes.get(id).width));
|
|
575
|
+
const gapY = adaptiveGapY(layerNodes.length);
|
|
576
|
+
const totalHeight = layerNodes.reduce((sum, id) => {
|
|
577
|
+
const n = diagramNodes.get(id);
|
|
578
|
+
return sum + n.height + LABEL_HEIGHT + LABEL_GAP;
|
|
579
|
+
}, 0) + (layerNodes.length - 1) * gapY;
|
|
580
|
+
let currentY = -totalHeight / 2;
|
|
581
|
+
for (const id of layerNodes) {
|
|
582
|
+
const node = diagramNodes.get(id);
|
|
583
|
+
currentY += LABEL_HEIGHT + LABEL_GAP;
|
|
584
|
+
node.x = currentX + (maxWidth - node.width) / 2;
|
|
585
|
+
node.y = currentY;
|
|
586
|
+
currentY += node.height + gapY;
|
|
587
|
+
}
|
|
588
|
+
const nextLayerNodes = filtered[i + 1];
|
|
589
|
+
if (nextLayerNodes && nextLayerNodes.length > 0) {
|
|
590
|
+
const outputOverhang = layerOutputExtent(layerNodes, diagramNodes);
|
|
591
|
+
const inputOverhang = layerInputExtent(nextLayerNodes, diagramNodes);
|
|
592
|
+
const labelMinGap = outputOverhang + LABEL_CLEARANCE + inputOverhang;
|
|
593
|
+
const edgeGap = Math.max(labelMinGap, LAYER_GAP_X - maxWidth, MIN_EDGE_GAP);
|
|
594
|
+
currentX += maxWidth + edgeGap;
|
|
595
|
+
} else {
|
|
596
|
+
currentX += maxWidth + LAYER_GAP_X;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function resolvePostLayoutOverlaps(diagramNodes) {
|
|
601
|
+
const hasScopeParent = [...diagramNodes.values()].some((n) => n.scopeChildren && n.scopeChildren.length > 0);
|
|
602
|
+
if (!hasScopeParent) return;
|
|
603
|
+
const nodes = [...diagramNodes.values()].sort((a, b) => a.x - b.x);
|
|
604
|
+
for (let i = 1; i < nodes.length; i++) {
|
|
605
|
+
const prev = nodes[i - 1];
|
|
606
|
+
const curr = nodes[i];
|
|
607
|
+
if (!prev.scopeChildren || prev.scopeChildren.length === 0) continue;
|
|
608
|
+
const actualGap = curr.x - (prev.x + prev.width);
|
|
609
|
+
if (actualGap < MIN_EDGE_GAP) {
|
|
610
|
+
const shift = MIN_EDGE_GAP - actualGap;
|
|
611
|
+
for (let j = i; j < nodes.length; j++) {
|
|
612
|
+
nodes[j].x += shift;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/diagram/orthogonal-router.ts
|
|
619
|
+
var TRACK_SPACING = 15;
|
|
620
|
+
var EDGE_OFFSET = 5;
|
|
621
|
+
var BELOW_BIAS = 40;
|
|
622
|
+
var TrackAllocator = class {
|
|
623
|
+
claims = /* @__PURE__ */ new Map();
|
|
624
|
+
claim(xMin, xMax, candidateY) {
|
|
625
|
+
const snap = (y) => Math.round(y / TRACK_SPACING) * TRACK_SPACING;
|
|
626
|
+
const overlaps = (slot) => {
|
|
627
|
+
const intervals = this.claims.get(slot);
|
|
628
|
+
if (!intervals) return false;
|
|
629
|
+
return intervals.some(([a, b]) => xMin < b && xMax > a);
|
|
630
|
+
};
|
|
631
|
+
const take = (slot) => {
|
|
632
|
+
if (!this.claims.has(slot)) this.claims.set(slot, []);
|
|
633
|
+
const slotClaims = this.claims.get(slot);
|
|
634
|
+
if (slotClaims) slotClaims.push([xMin, xMax]);
|
|
635
|
+
return slot;
|
|
636
|
+
};
|
|
637
|
+
const base = snap(candidateY);
|
|
638
|
+
for (let i = 0; i < 60; i++) {
|
|
639
|
+
const below = base + i * TRACK_SPACING;
|
|
640
|
+
if (!overlaps(below)) return take(below);
|
|
641
|
+
if (i > 0) {
|
|
642
|
+
const above = base - i * TRACK_SPACING;
|
|
643
|
+
if (!overlaps(above)) return take(above);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return candidateY;
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
function inflateBox(box, padding) {
|
|
650
|
+
return {
|
|
651
|
+
left: box.x - padding,
|
|
652
|
+
right: box.x + box.width + padding,
|
|
653
|
+
top: box.y - padding,
|
|
654
|
+
bottom: box.y + box.height + padding
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
function segmentOverlapsBox(xMin, xMax, y, box) {
|
|
658
|
+
return xMin < box.right && xMax > box.left && y >= box.top && y <= box.bottom;
|
|
659
|
+
}
|
|
660
|
+
function verticalSegmentClear(x, yMin, yMax, boxes) {
|
|
661
|
+
return !boxes.some(
|
|
662
|
+
(box) => x >= box.left && x <= box.right && yMin < box.bottom && yMax > box.top
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
function findClearY(xMin, xMax, candidateY, boxes) {
|
|
666
|
+
const isBlocked = (y) => boxes.some((box) => segmentOverlapsBox(xMin, xMax, y, box));
|
|
667
|
+
if (!isBlocked(candidateY)) return candidateY;
|
|
668
|
+
const edges = [];
|
|
669
|
+
for (const box of boxes) {
|
|
670
|
+
if (xMin < box.right && xMax > box.left) {
|
|
671
|
+
edges.push(box.top);
|
|
672
|
+
edges.push(box.bottom);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (edges.length === 0) return candidateY;
|
|
676
|
+
edges.sort((a, b) => a - b);
|
|
677
|
+
let bestY = candidateY;
|
|
678
|
+
let bestDist = Infinity;
|
|
679
|
+
for (const edge of edges) {
|
|
680
|
+
for (const y of [edge - EDGE_OFFSET, edge + EDGE_OFFSET]) {
|
|
681
|
+
if (!isBlocked(y)) {
|
|
682
|
+
const dist = Math.abs(y - candidateY);
|
|
683
|
+
if (dist < bestDist) {
|
|
684
|
+
bestDist = dist;
|
|
685
|
+
bestY = y;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
if (bestDist === Infinity) {
|
|
691
|
+
const allMin = Math.min(...edges) - EDGE_OFFSET * 2;
|
|
692
|
+
const allMax = Math.max(...edges) + EDGE_OFFSET * 2;
|
|
693
|
+
bestY = Math.abs(allMin - candidateY) < Math.abs(allMax - candidateY) ? allMin : allMax;
|
|
694
|
+
if (isBlocked(bestY)) {
|
|
695
|
+
for (let offset = TRACK_SPACING; offset < 800; offset += TRACK_SPACING) {
|
|
696
|
+
if (!isBlocked(bestY - offset)) {
|
|
697
|
+
bestY -= offset;
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
if (!isBlocked(bestY + offset)) {
|
|
701
|
+
bestY += offset;
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return bestY;
|
|
708
|
+
}
|
|
709
|
+
function findClearX(yMin, yMax, candidateX, boxes) {
|
|
710
|
+
const isBlocked = (x) => boxes.some((box) => x >= box.left && x <= box.right && yMin < box.bottom && yMax > box.top);
|
|
711
|
+
if (!isBlocked(candidateX)) return candidateX;
|
|
712
|
+
const edges = [];
|
|
713
|
+
for (const box of boxes) {
|
|
714
|
+
if (yMin < box.bottom && yMax > box.top) {
|
|
715
|
+
edges.push(box.left);
|
|
716
|
+
edges.push(box.right);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
if (edges.length === 0) return candidateX;
|
|
720
|
+
edges.sort((a, b) => a - b);
|
|
721
|
+
let bestX = candidateX;
|
|
722
|
+
let bestDist = Infinity;
|
|
723
|
+
for (const edge of edges) {
|
|
724
|
+
for (const x of [edge - EDGE_OFFSET, edge + EDGE_OFFSET]) {
|
|
725
|
+
if (!isBlocked(x)) {
|
|
726
|
+
const dist = Math.abs(x - candidateX);
|
|
727
|
+
if (dist < bestDist) {
|
|
728
|
+
bestDist = dist;
|
|
729
|
+
bestX = x;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
if (bestDist === Infinity) {
|
|
735
|
+
const allMin = Math.min(...edges) - EDGE_OFFSET * 2;
|
|
736
|
+
const allMax = Math.max(...edges) + EDGE_OFFSET * 2;
|
|
737
|
+
bestX = Math.abs(allMin - candidateX) <= Math.abs(allMax - candidateX) ? allMin : allMax;
|
|
738
|
+
if (isBlocked(bestX)) {
|
|
739
|
+
for (let offset = TRACK_SPACING; offset < 800; offset += TRACK_SPACING) {
|
|
740
|
+
if (!isBlocked(bestX - offset)) {
|
|
741
|
+
bestX -= offset;
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
744
|
+
if (!isBlocked(bestX + offset)) {
|
|
745
|
+
bestX += offset;
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
return bestX;
|
|
752
|
+
}
|
|
753
|
+
var MIN_SEGMENT_LENGTH = 3;
|
|
754
|
+
var JOG_THRESHOLD = 10;
|
|
755
|
+
function simplifyWaypoints(waypoints) {
|
|
756
|
+
if (waypoints.length <= 2) return waypoints;
|
|
757
|
+
let pts = waypoints;
|
|
758
|
+
let jogFound = true;
|
|
759
|
+
while (jogFound) {
|
|
760
|
+
jogFound = false;
|
|
761
|
+
for (let i = 0; i < pts.length - 3; i++) {
|
|
762
|
+
const a = pts[i], b = pts[i + 1], c = pts[i + 2], d = pts[i + 3];
|
|
763
|
+
const jogH = Math.abs(b[1] - c[1]);
|
|
764
|
+
if (Math.abs(a[1] - b[1]) < 0.5 && Math.abs(b[0] - c[0]) < 0.5 && Math.abs(c[1] - d[1]) < 0.5 && jogH > 0.5 && jogH < JOG_THRESHOLD) {
|
|
765
|
+
if (Math.abs(a[1] - d[1]) < 0.5) {
|
|
766
|
+
const snapY = a[1];
|
|
767
|
+
const newPts = pts.slice();
|
|
768
|
+
newPts[i + 1] = [b[0], snapY];
|
|
769
|
+
newPts[i + 2] = [c[0], snapY];
|
|
770
|
+
pts = newPts;
|
|
771
|
+
jogFound = true;
|
|
772
|
+
break;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const jogW = Math.abs(b[0] - c[0]);
|
|
776
|
+
if (Math.abs(a[0] - b[0]) < 0.5 && Math.abs(b[1] - c[1]) < 0.5 && Math.abs(c[0] - d[0]) < 0.5 && jogW > 0.5 && jogW < JOG_THRESHOLD) {
|
|
777
|
+
if (Math.abs(a[0] - d[0]) < 0.5) {
|
|
778
|
+
const snapX = a[0];
|
|
779
|
+
const newPts = pts.slice();
|
|
780
|
+
newPts[i + 1] = [snapX, b[1]];
|
|
781
|
+
newPts[i + 2] = [snapX, c[1]];
|
|
782
|
+
pts = newPts;
|
|
783
|
+
jogFound = true;
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
const result = [pts[0]];
|
|
790
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
791
|
+
const prev = result[result.length - 1];
|
|
792
|
+
const curr = pts[i];
|
|
793
|
+
const next = pts[i + 1];
|
|
794
|
+
const distToPrev = Math.abs(prev[0] - curr[0]) + Math.abs(prev[1] - curr[1]);
|
|
795
|
+
if (distToPrev < MIN_SEGMENT_LENGTH) {
|
|
796
|
+
const wouldDiag = Math.abs(prev[0] - next[0]) > 0.5 && Math.abs(prev[1] - next[1]) > 0.5;
|
|
797
|
+
if (!wouldDiag) continue;
|
|
798
|
+
}
|
|
799
|
+
const sameX = Math.abs(prev[0] - curr[0]) < 0.01 && Math.abs(curr[0] - next[0]) < 0.01;
|
|
800
|
+
const sameY = Math.abs(prev[1] - curr[1]) < 0.01 && Math.abs(curr[1] - next[1]) < 0.01;
|
|
801
|
+
if (!sameX && !sameY) {
|
|
802
|
+
result.push(curr);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
result.push(pts[pts.length - 1]);
|
|
806
|
+
return result;
|
|
807
|
+
}
|
|
808
|
+
function waypointsToSvgPath(waypoints, cornerRadius) {
|
|
809
|
+
if (waypoints.length < 2) return "";
|
|
810
|
+
if (waypoints.length === 2) {
|
|
811
|
+
return `M ${waypoints[0][0]},${waypoints[0][1]} L ${waypoints[1][0]},${waypoints[1][1]}`;
|
|
812
|
+
}
|
|
813
|
+
const radii = new Array(waypoints.length).fill(0);
|
|
814
|
+
for (let i = 1; i < waypoints.length - 1; i++) {
|
|
815
|
+
const prev = waypoints[i - 1];
|
|
816
|
+
const curr = waypoints[i];
|
|
817
|
+
const next = waypoints[i + 1];
|
|
818
|
+
const lenPrev = Math.sqrt((prev[0] - curr[0]) ** 2 + (prev[1] - curr[1]) ** 2);
|
|
819
|
+
const lenNext = Math.sqrt((next[0] - curr[0]) ** 2 + (next[1] - curr[1]) ** 2);
|
|
820
|
+
radii[i] = lenPrev < 0.01 || lenNext < 0.01 ? 0 : Math.min(cornerRadius, lenPrev / 2, lenNext / 2);
|
|
821
|
+
}
|
|
822
|
+
for (let i = 1; i < waypoints.length - 2; i++) {
|
|
823
|
+
const curr = waypoints[i];
|
|
824
|
+
const next = waypoints[i + 1];
|
|
825
|
+
const segLen = Math.sqrt((next[0] - curr[0]) ** 2 + (next[1] - curr[1]) ** 2);
|
|
826
|
+
const total = radii[i] + radii[i + 1];
|
|
827
|
+
if (total > segLen && total > 0) {
|
|
828
|
+
const scale = segLen / total;
|
|
829
|
+
radii[i] *= scale;
|
|
830
|
+
radii[i + 1] *= scale;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
let path = `M ${waypoints[0][0]},${waypoints[0][1]}`;
|
|
834
|
+
for (let i = 1; i < waypoints.length - 1; i++) {
|
|
835
|
+
const prev = waypoints[i - 1];
|
|
836
|
+
const curr = waypoints[i];
|
|
837
|
+
const next = waypoints[i + 1];
|
|
838
|
+
const r = radii[i];
|
|
839
|
+
if (r < 0.01) {
|
|
840
|
+
path += ` L ${curr[0]},${curr[1]}`;
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
const dPrev = [prev[0] - curr[0], prev[1] - curr[1]];
|
|
844
|
+
const dNext = [next[0] - curr[0], next[1] - curr[1]];
|
|
845
|
+
const lenPrev = Math.sqrt(dPrev[0] * dPrev[0] + dPrev[1] * dPrev[1]);
|
|
846
|
+
const lenNext = Math.sqrt(dNext[0] * dNext[0] + dNext[1] * dNext[1]);
|
|
847
|
+
const uPrev = [dPrev[0] / lenPrev, dPrev[1] / lenPrev];
|
|
848
|
+
const uNext = [dNext[0] / lenNext, dNext[1] / lenNext];
|
|
849
|
+
const cross = uPrev[0] * uNext[1] - uPrev[1] * uNext[0];
|
|
850
|
+
const deflection = Math.abs(cross);
|
|
851
|
+
const scaledR = r * deflection;
|
|
852
|
+
if (scaledR < 0.5) {
|
|
853
|
+
path += ` L ${curr[0]},${curr[1]}`;
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
const arcStart = [curr[0] + uPrev[0] * scaledR, curr[1] + uPrev[1] * scaledR];
|
|
857
|
+
const arcEnd = [curr[0] + uNext[0] * scaledR, curr[1] + uNext[1] * scaledR];
|
|
858
|
+
const sweep = cross > 0 ? 0 : 1;
|
|
859
|
+
path += ` L ${arcStart[0]},${arcStart[1]}`;
|
|
860
|
+
path += ` A ${scaledR} ${scaledR} 0 0 ${sweep} ${arcEnd[0]},${arcEnd[1]}`;
|
|
861
|
+
}
|
|
862
|
+
const last = waypoints[waypoints.length - 1];
|
|
863
|
+
path += ` L ${last[0]},${last[1]}`;
|
|
864
|
+
return path;
|
|
865
|
+
}
|
|
866
|
+
function computeWaypoints(from, to, nodeBoxes, sourceNodeId, targetNodeId, padding, exitStub, entryStub, scopedInternal, allocator) {
|
|
867
|
+
const isSelfConnection = sourceNodeId === targetNodeId && !scopedInternal;
|
|
868
|
+
const inflatedBoxes = nodeBoxes.map((box) => inflateBox(box, padding));
|
|
869
|
+
const stubExit = [from[0] + exitStub, from[1]];
|
|
870
|
+
const stubEntry = [to[0] - entryStub, to[1]];
|
|
871
|
+
const xMin = Math.min(stubExit[0], stubEntry[0]);
|
|
872
|
+
const xMax = Math.max(stubExit[0], stubEntry[0]);
|
|
873
|
+
if (!isSelfConnection && to[0] >= from[0] - exitStub) {
|
|
874
|
+
let candidateY = (from[1] + to[1]) / 2 + BELOW_BIAS;
|
|
875
|
+
const intermediateBoxes = inflatedBoxes.filter((box) => box.left < xMax && box.right > xMin);
|
|
876
|
+
if (intermediateBoxes.length >= 2) {
|
|
877
|
+
const clusterTop = Math.min(...intermediateBoxes.map((b) => b.top));
|
|
878
|
+
const clusterBottom = Math.max(...intermediateBoxes.map((b) => b.bottom));
|
|
879
|
+
if (candidateY > clusterTop && candidateY < clusterBottom) {
|
|
880
|
+
const distToTop = candidateY - clusterTop;
|
|
881
|
+
const distToBottom = clusterBottom - candidateY;
|
|
882
|
+
candidateY = distToTop < distToBottom ? clusterTop - padding : clusterBottom + padding;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
const clearY = allocator ? allocator.claim(xMin, xMax, findClearY(xMin, xMax, candidateY, inflatedBoxes)) : findClearY(xMin, xMax, candidateY, inflatedBoxes);
|
|
886
|
+
const yMin = Math.min(from[1], to[1]);
|
|
887
|
+
const yMax = Math.max(from[1], to[1]);
|
|
888
|
+
const stubsCross = stubExit[0] >= stubEntry[0];
|
|
889
|
+
const midX = stubsCross ? (from[0] + to[0]) / 2 : stubExit[0] + (stubEntry[0] - stubExit[0]) * 0.75;
|
|
890
|
+
const freeMidX = findClearX(yMin, yMax || yMin + 1, midX, inflatedBoxes);
|
|
891
|
+
const lShapeXValid = stubsCross ? freeMidX >= Math.min(from[0], to[0]) && freeMidX <= Math.max(from[0], to[0]) : freeMidX > stubExit[0] && freeMidX < stubEntry[0];
|
|
892
|
+
if (lShapeXValid && verticalSegmentClear(freeMidX, yMin, yMax, inflatedBoxes) && !inflatedBoxes.some((box) => segmentOverlapsBox(stubExit[0], freeMidX, from[1], box)) && !inflatedBoxes.some((box) => segmentOverlapsBox(freeMidX, stubEntry[0], to[1], box))) {
|
|
893
|
+
return simplifyWaypoints([from, [freeMidX, from[1]], [freeMidX, to[1]], to]);
|
|
894
|
+
}
|
|
895
|
+
if (Math.abs(clearY - from[1]) < JOG_THRESHOLD && !inflatedBoxes.some((box) => segmentOverlapsBox(xMin, xMax, from[1], box))) {
|
|
896
|
+
candidateY = from[1];
|
|
897
|
+
} else if (Math.abs(clearY - to[1]) < JOG_THRESHOLD && !inflatedBoxes.some((box) => segmentOverlapsBox(xMin, xMax, to[1], box))) {
|
|
898
|
+
candidateY = to[1];
|
|
899
|
+
} else {
|
|
900
|
+
candidateY = clearY;
|
|
901
|
+
}
|
|
902
|
+
const exitYMin = Math.min(from[1], candidateY);
|
|
903
|
+
const exitYMax = Math.max(from[1], candidateY);
|
|
904
|
+
let exitX = findClearX(exitYMin, exitYMax, stubExit[0], inflatedBoxes);
|
|
905
|
+
if (exitX < from[0]) {
|
|
906
|
+
exitX = stubExit[0];
|
|
907
|
+
if (!verticalSegmentClear(exitX, exitYMin, exitYMax, inflatedBoxes)) {
|
|
908
|
+
exitX = findClearX(exitYMin, exitYMax, stubExit[0] + TRACK_SPACING, inflatedBoxes);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
const entryYMin = Math.min(to[1], candidateY);
|
|
912
|
+
const entryYMax = Math.max(to[1], candidateY);
|
|
913
|
+
let entryX = findClearX(entryYMin, entryYMax, stubEntry[0], inflatedBoxes);
|
|
914
|
+
if (entryX > to[0]) {
|
|
915
|
+
entryX = stubEntry[0];
|
|
916
|
+
if (!verticalSegmentClear(entryX, entryYMin, entryYMax, inflatedBoxes)) {
|
|
917
|
+
entryX = findClearX(entryYMin, entryYMax, stubEntry[0] - TRACK_SPACING, inflatedBoxes);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
return simplifyWaypoints([
|
|
921
|
+
from,
|
|
922
|
+
[exitX, from[1]],
|
|
923
|
+
[exitX, candidateY],
|
|
924
|
+
[entryX, candidateY],
|
|
925
|
+
[entryX, to[1]],
|
|
926
|
+
to
|
|
927
|
+
]);
|
|
928
|
+
} else {
|
|
929
|
+
const sourceBox = nodeBoxes.find((b) => b.id === sourceNodeId);
|
|
930
|
+
const targetBox = nodeBoxes.find((b) => b.id === targetNodeId);
|
|
931
|
+
const corridorBoxes = inflatedBoxes.filter((box) => box.left < xMax && box.right > xMin);
|
|
932
|
+
const bottoms = corridorBoxes.map((b) => b.bottom);
|
|
933
|
+
const tops = corridorBoxes.map((b) => b.top);
|
|
934
|
+
if (sourceBox) {
|
|
935
|
+
bottoms.push(sourceBox.y + sourceBox.height + padding);
|
|
936
|
+
tops.push(sourceBox.y - padding);
|
|
937
|
+
}
|
|
938
|
+
if (targetBox) {
|
|
939
|
+
bottoms.push(targetBox.y + targetBox.height + padding);
|
|
940
|
+
tops.push(targetBox.y - padding);
|
|
941
|
+
}
|
|
942
|
+
const maxBottom = Math.max(...bottoms, from[1] + 50, to[1] + 50);
|
|
943
|
+
const minTop = Math.min(...tops, from[1] - 50, to[1] - 50);
|
|
944
|
+
const avgY = (from[1] + to[1]) / 2 + BELOW_BIAS;
|
|
945
|
+
const escapeBelow = maxBottom + padding;
|
|
946
|
+
const escapeAbove = minTop - padding;
|
|
947
|
+
let escapeY = Math.abs(escapeAbove - avgY) < Math.abs(escapeBelow - avgY) ? escapeAbove : escapeBelow;
|
|
948
|
+
escapeY = allocator ? allocator.claim(xMin, xMax, findClearY(xMin, xMax, escapeY, inflatedBoxes)) : findClearY(xMin, xMax, escapeY, inflatedBoxes);
|
|
949
|
+
const bwExitYMin = Math.min(from[1], escapeY);
|
|
950
|
+
const bwExitYMax = Math.max(from[1], escapeY);
|
|
951
|
+
const bwExitX = findClearX(bwExitYMin, bwExitYMax, stubExit[0], inflatedBoxes);
|
|
952
|
+
const bwEntryYMin = Math.min(to[1], escapeY);
|
|
953
|
+
const bwEntryYMax = Math.max(to[1], escapeY);
|
|
954
|
+
const bwEntryX = findClearX(bwEntryYMin, bwEntryYMax, stubEntry[0], inflatedBoxes);
|
|
955
|
+
return simplifyWaypoints([
|
|
956
|
+
from,
|
|
957
|
+
[bwExitX, from[1]],
|
|
958
|
+
[bwExitX, escapeY],
|
|
959
|
+
[bwEntryX, escapeY],
|
|
960
|
+
[bwEntryX, to[1]],
|
|
961
|
+
to
|
|
962
|
+
]);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
function calculateOrthogonalPath(from, to, nodeBoxes, sourceNodeId, targetNodeId, options) {
|
|
966
|
+
const cornerRadius = options?.cornerRadius ?? 10;
|
|
967
|
+
const padding = options?.padding ?? 15;
|
|
968
|
+
const stubLength = options?.stubLength ?? 20;
|
|
969
|
+
const stubSpacing = options?.stubSpacing ?? 12;
|
|
970
|
+
const maxStubLength = options?.maxStubLength ?? 80;
|
|
971
|
+
const fromPortIndex = options?.fromPortIndex ?? 0;
|
|
972
|
+
const toPortIndex = options?.toPortIndex ?? 0;
|
|
973
|
+
const exitStub = Math.min(stubLength + fromPortIndex * stubSpacing, maxStubLength);
|
|
974
|
+
const entryStub = Math.min(stubLength + toPortIndex * stubSpacing, maxStubLength);
|
|
975
|
+
const waypoints = computeWaypoints(
|
|
976
|
+
from,
|
|
977
|
+
to,
|
|
978
|
+
nodeBoxes,
|
|
979
|
+
sourceNodeId,
|
|
980
|
+
targetNodeId,
|
|
981
|
+
padding,
|
|
982
|
+
exitStub,
|
|
983
|
+
entryStub,
|
|
984
|
+
options?.scopedInternal,
|
|
985
|
+
options?.allocator
|
|
986
|
+
);
|
|
987
|
+
if (!waypoints) return null;
|
|
988
|
+
return waypointsToSvgPath(waypoints, cornerRadius);
|
|
989
|
+
}
|
|
990
|
+
function calculateOrthogonalPathSafe(from, to, nodeBoxes, sourceNodeId, targetNodeId, options) {
|
|
991
|
+
try {
|
|
992
|
+
const path = calculateOrthogonalPath(from, to, nodeBoxes, sourceNodeId, targetNodeId, options);
|
|
993
|
+
if (!path || path.length < 5) return null;
|
|
994
|
+
return path;
|
|
995
|
+
} catch {
|
|
996
|
+
return null;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
// src/diagram/graph/routing.ts
|
|
1001
|
+
var STUB_DISTANCE_THRESHOLD = 500;
|
|
1002
|
+
var STUB_LENGTH = 30;
|
|
1003
|
+
function computeConnectionPath(sx, sy, tx, ty) {
|
|
1004
|
+
return `M ${sx},${sy} L ${tx},${ty}`;
|
|
1005
|
+
}
|
|
1006
|
+
function collectExternalConnections(ast, diagramNodes, scopedChildren) {
|
|
1007
|
+
const pendingConnections = [];
|
|
1008
|
+
for (const conn of ast.connections) {
|
|
1009
|
+
if (conn.from.scope || conn.to.scope) continue;
|
|
1010
|
+
let fromNode = diagramNodes.get(conn.from.node);
|
|
1011
|
+
let toNode = diagramNodes.get(conn.to.node);
|
|
1012
|
+
if (!fromNode) {
|
|
1013
|
+
for (const node of diagramNodes.values()) {
|
|
1014
|
+
const child = node.scopeChildren?.find((c) => c.id === conn.from.node);
|
|
1015
|
+
if (child) {
|
|
1016
|
+
fromNode = child;
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
if (!toNode) {
|
|
1022
|
+
for (const node of diagramNodes.values()) {
|
|
1023
|
+
const child = node.scopeChildren?.find((c) => c.id === conn.to.node);
|
|
1024
|
+
if (child) {
|
|
1025
|
+
toNode = child;
|
|
1026
|
+
break;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (!fromNode || !toNode) continue;
|
|
1031
|
+
const fromIsScoped = scopedChildren.has(conn.from.node);
|
|
1032
|
+
const toIsScoped = scopedChildren.has(conn.to.node);
|
|
1033
|
+
if (fromIsScoped && toIsScoped) continue;
|
|
1034
|
+
if (fromIsScoped && diagramNodes.has(conn.to.node) && findScopeParent(conn.from.node, diagramNodes) === conn.to.node) continue;
|
|
1035
|
+
if (toIsScoped && diagramNodes.has(conn.from.node) && findScopeParent(conn.to.node, diagramNodes) === conn.from.node) continue;
|
|
1036
|
+
const sourcePort = fromNode.outputs.find((p) => p.name === conn.from.port);
|
|
1037
|
+
const targetPort = toNode.inputs.find((p) => p.name === conn.to.port);
|
|
1038
|
+
if (!sourcePort || !targetPort) continue;
|
|
1039
|
+
const fromPortIndex = fromNode.outputs.indexOf(sourcePort);
|
|
1040
|
+
const toPortIndex = toNode.inputs.indexOf(targetPort);
|
|
1041
|
+
pendingConnections.push({
|
|
1042
|
+
fromNodeId: conn.from.node,
|
|
1043
|
+
fromPortName: conn.from.port,
|
|
1044
|
+
toNodeId: conn.to.node,
|
|
1045
|
+
toPortName: conn.to.port,
|
|
1046
|
+
sourcePort,
|
|
1047
|
+
targetPort,
|
|
1048
|
+
fromPortIndex,
|
|
1049
|
+
toPortIndex
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
return pendingConnections;
|
|
1053
|
+
}
|
|
1054
|
+
function routeConnections(pendingConnections, nodes, theme) {
|
|
1055
|
+
const nodeBoxes = buildNodeBoxes(nodes);
|
|
1056
|
+
const allocator = new TrackAllocator();
|
|
1057
|
+
const connections = routeExternalConnections(pendingConnections, nodeBoxes, allocator, theme);
|
|
1058
|
+
routeScopeConnections(nodes, nodeBoxes, allocator);
|
|
1059
|
+
return connections;
|
|
1060
|
+
}
|
|
1061
|
+
function buildNodeBoxes(nodes) {
|
|
1062
|
+
const nodeBoxes = nodes.map((node) => ({
|
|
1063
|
+
id: node.id,
|
|
1064
|
+
x: node.x,
|
|
1065
|
+
y: node.y,
|
|
1066
|
+
width: node.width,
|
|
1067
|
+
height: node.height
|
|
1068
|
+
}));
|
|
1069
|
+
for (const node of nodes) {
|
|
1070
|
+
if (node.scopeChildren) {
|
|
1071
|
+
for (const child of node.scopeChildren) {
|
|
1072
|
+
nodeBoxes.push({ id: child.id, x: child.x, y: child.y, width: child.width, height: child.height });
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return nodeBoxes;
|
|
1077
|
+
}
|
|
1078
|
+
function compareRoutingOrder(a, b) {
|
|
1079
|
+
const aSpan = Math.abs(a.targetPort.cx - a.sourcePort.cx);
|
|
1080
|
+
const bSpan = Math.abs(b.targetPort.cx - b.sourcePort.cx);
|
|
1081
|
+
if (Math.abs(aSpan - bSpan) > 1) return aSpan - bSpan;
|
|
1082
|
+
if (Math.abs(a.sourcePort.cx - b.sourcePort.cx) > 1) return a.sourcePort.cx - b.sourcePort.cx;
|
|
1083
|
+
return a.sourcePort.cy - b.sourcePort.cy;
|
|
1084
|
+
}
|
|
1085
|
+
function routeExternalConnections(pendingConnections, nodeBoxes, allocator, theme) {
|
|
1086
|
+
pendingConnections.sort(compareRoutingOrder);
|
|
1087
|
+
const connections = [];
|
|
1088
|
+
for (const pc of pendingConnections) {
|
|
1089
|
+
const sx = pc.sourcePort.cx;
|
|
1090
|
+
const sy = pc.sourcePort.cy;
|
|
1091
|
+
const tx = pc.targetPort.cx;
|
|
1092
|
+
const ty = pc.targetPort.cy;
|
|
1093
|
+
const sourceColor = getPortColor(pc.sourcePort.dataType, pc.sourcePort.isFailure, theme);
|
|
1094
|
+
const targetColor = getPortColor(pc.targetPort.dataType, pc.targetPort.isFailure, theme);
|
|
1095
|
+
const xDistance = Math.abs(tx - sx);
|
|
1096
|
+
const dashed = pc.sourcePort.dataType !== "STEP";
|
|
1097
|
+
const srcLabelEnd = portLabelExtent(pc.sourcePort);
|
|
1098
|
+
const tgtLabelEnd = portLabelExtent(pc.targetPort);
|
|
1099
|
+
const sourceStub = {
|
|
1100
|
+
x: sx + srcLabelEnd,
|
|
1101
|
+
y: sy,
|
|
1102
|
+
endX: sx + srcLabelEnd + STUB_LENGTH,
|
|
1103
|
+
labelOffset: srcLabelEnd,
|
|
1104
|
+
color: sourceColor,
|
|
1105
|
+
dashed
|
|
1106
|
+
};
|
|
1107
|
+
const targetStub = {
|
|
1108
|
+
x: tx - tgtLabelEnd,
|
|
1109
|
+
y: ty,
|
|
1110
|
+
endX: tx - tgtLabelEnd - STUB_LENGTH,
|
|
1111
|
+
labelOffset: tgtLabelEnd,
|
|
1112
|
+
color: targetColor,
|
|
1113
|
+
dashed
|
|
1114
|
+
};
|
|
1115
|
+
const pathSx = sx + srcLabelEnd;
|
|
1116
|
+
const pathTx = tx - tgtLabelEnd;
|
|
1117
|
+
let path;
|
|
1118
|
+
if (xDistance > STUB_DISTANCE_THRESHOLD) {
|
|
1119
|
+
path = "";
|
|
1120
|
+
} else {
|
|
1121
|
+
const orthoPath = calculateOrthogonalPathSafe(
|
|
1122
|
+
[pathSx, sy],
|
|
1123
|
+
[pathTx, ty],
|
|
1124
|
+
nodeBoxes,
|
|
1125
|
+
pc.fromNodeId,
|
|
1126
|
+
pc.toNodeId,
|
|
1127
|
+
{ fromPortIndex: pc.fromPortIndex, toPortIndex: pc.toPortIndex, allocator }
|
|
1128
|
+
);
|
|
1129
|
+
path = orthoPath ?? computeConnectionPath(pathSx, sy, pathTx, ty);
|
|
1130
|
+
}
|
|
1131
|
+
connections.push({
|
|
1132
|
+
fromNode: pc.fromNodeId,
|
|
1133
|
+
fromPort: pc.fromPortName,
|
|
1134
|
+
toNode: pc.toNodeId,
|
|
1135
|
+
toPort: pc.toPortName,
|
|
1136
|
+
sourceColor,
|
|
1137
|
+
targetColor,
|
|
1138
|
+
isStepConnection: pc.sourcePort.dataType === "STEP",
|
|
1139
|
+
path,
|
|
1140
|
+
sourceStub,
|
|
1141
|
+
targetStub
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
return connections;
|
|
1145
|
+
}
|
|
1146
|
+
function routeScopeConnections(nodes, nodeBoxes, allocator) {
|
|
1147
|
+
for (const node of nodes) {
|
|
1148
|
+
if (!node.scopeConnections || !node.scopePorts || !node.scopeChildren) continue;
|
|
1149
|
+
const childMap = /* @__PURE__ */ new Map();
|
|
1150
|
+
for (const c of node.scopeChildren) childMap.set(c.id, c);
|
|
1151
|
+
const scopePending = [];
|
|
1152
|
+
for (const conn of node.scopeConnections) {
|
|
1153
|
+
const sPort = findScopePort(conn.fromNode, conn.fromPort, node, childMap, "output");
|
|
1154
|
+
const tPort = findScopePort(conn.toNode, conn.toPort, node, childMap, "input");
|
|
1155
|
+
if (!sPort || !tPort) continue;
|
|
1156
|
+
let fromPortIndex = 0;
|
|
1157
|
+
let toPortIndex = 0;
|
|
1158
|
+
if (conn.fromNode === node.id) {
|
|
1159
|
+
fromPortIndex = node.scopePorts.outputs.indexOf(sPort);
|
|
1160
|
+
} else {
|
|
1161
|
+
const fromChild = childMap.get(conn.fromNode);
|
|
1162
|
+
if (fromChild) fromPortIndex = fromChild.outputs.indexOf(sPort);
|
|
1163
|
+
}
|
|
1164
|
+
if (conn.toNode === node.id) {
|
|
1165
|
+
toPortIndex = node.scopePorts.inputs.indexOf(tPort);
|
|
1166
|
+
} else {
|
|
1167
|
+
const toChild = childMap.get(conn.toNode);
|
|
1168
|
+
if (toChild) toPortIndex = toChild.inputs.indexOf(tPort);
|
|
1169
|
+
}
|
|
1170
|
+
scopePending.push({
|
|
1171
|
+
conn,
|
|
1172
|
+
sourcePort: sPort,
|
|
1173
|
+
targetPort: tPort,
|
|
1174
|
+
fromNodeId: conn.fromNode,
|
|
1175
|
+
toNodeId: conn.toNode,
|
|
1176
|
+
fromPortIndex: Math.max(0, fromPortIndex),
|
|
1177
|
+
toPortIndex: Math.max(0, toPortIndex)
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
scopePending.sort(compareRoutingOrder);
|
|
1181
|
+
for (const sp of scopePending) {
|
|
1182
|
+
const sx = sp.sourcePort.cx;
|
|
1183
|
+
const sy = sp.sourcePort.cy;
|
|
1184
|
+
const tx = sp.targetPort.cx;
|
|
1185
|
+
const ty = sp.targetPort.cy;
|
|
1186
|
+
const orthoPath = calculateOrthogonalPathSafe(
|
|
1187
|
+
[sx, sy],
|
|
1188
|
+
[tx, ty],
|
|
1189
|
+
nodeBoxes,
|
|
1190
|
+
sp.fromNodeId,
|
|
1191
|
+
sp.toNodeId,
|
|
1192
|
+
{ fromPortIndex: sp.fromPortIndex, toPortIndex: sp.toPortIndex, allocator }
|
|
1193
|
+
);
|
|
1194
|
+
sp.conn.path = orthoPath ?? computeConnectionPath(sx, sy, tx, ty);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
function findScopePort(nodeId, portName, parentNode, childMap, side) {
|
|
1199
|
+
if (nodeId === parentNode.id) {
|
|
1200
|
+
const ports = side === "output" ? parentNode.scopePorts?.outputs : parentNode.scopePorts?.inputs;
|
|
1201
|
+
return ports?.find((p) => p.name === portName);
|
|
1202
|
+
}
|
|
1203
|
+
const child = childMap.get(nodeId);
|
|
1204
|
+
if (!child) return void 0;
|
|
1205
|
+
return side === "output" ? child.outputs.find((p) => p.name === portName) : child.inputs.find((p) => p.name === portName);
|
|
1206
|
+
}
|
|
1207
|
+
function findScopeParent(childId, diagramNodes) {
|
|
1208
|
+
for (const node of diagramNodes.values()) {
|
|
1209
|
+
if (node.scopeChildren?.some((c) => c.id === childId)) return node.id;
|
|
1210
|
+
}
|
|
1211
|
+
return void 0;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// src/diagram/graph/scopes.ts
|
|
1215
|
+
var SCOPE_PADDING_X = 140;
|
|
1216
|
+
var SCOPE_PADDING_Y = 40;
|
|
1217
|
+
var SCOPE_PORT_COLUMN = 45;
|
|
1218
|
+
var SCOPE_INNER_GAP_X = 240;
|
|
1219
|
+
function collectScopes(ast) {
|
|
1220
|
+
const scopedChildren = /* @__PURE__ */ new Set();
|
|
1221
|
+
const allScopes = { ...ast.scopes ?? {} };
|
|
1222
|
+
if (ast.scopes) {
|
|
1223
|
+
for (const children of Object.values(ast.scopes)) {
|
|
1224
|
+
for (const child of children) scopedChildren.add(child);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
const inferredScopes = /* @__PURE__ */ new Map();
|
|
1228
|
+
for (const conn of ast.connections) {
|
|
1229
|
+
if (conn.from.scope) {
|
|
1230
|
+
const key = `${conn.from.node}.${conn.from.scope}`;
|
|
1231
|
+
if (!inferredScopes.has(key)) inferredScopes.set(key, /* @__PURE__ */ new Set());
|
|
1232
|
+
inferredScopes.get(key).add(conn.to.node);
|
|
1233
|
+
}
|
|
1234
|
+
if (conn.to.scope) {
|
|
1235
|
+
const key = `${conn.to.node}.${conn.to.scope}`;
|
|
1236
|
+
if (!inferredScopes.has(key)) inferredScopes.set(key, /* @__PURE__ */ new Set());
|
|
1237
|
+
inferredScopes.get(key).add(conn.from.node);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
for (const [key, childSet] of inferredScopes) {
|
|
1241
|
+
if (!allScopes[key]) {
|
|
1242
|
+
allScopes[key] = [...childSet];
|
|
1243
|
+
for (const child of childSet) scopedChildren.add(child);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return { allScopes, scopedChildren };
|
|
1247
|
+
}
|
|
1248
|
+
function buildScopeSubGraphs(ast, diagramNodes, allScopes, nodeTypeMap, theme) {
|
|
1249
|
+
for (const [scopeKey, childIds] of Object.entries(allScopes)) {
|
|
1250
|
+
const dotIndex = scopeKey.indexOf(".");
|
|
1251
|
+
const parentId = scopeKey.substring(0, dotIndex);
|
|
1252
|
+
const scopeName = scopeKey.substring(dotIndex + 1);
|
|
1253
|
+
const parentNode = diagramNodes.get(parentId);
|
|
1254
|
+
if (!parentNode) continue;
|
|
1255
|
+
const parentInst = ast.instances.find((i) => i.id === parentId);
|
|
1256
|
+
if (!parentInst) continue;
|
|
1257
|
+
const parentNt = nodeTypeMap.get(parentInst.nodeType);
|
|
1258
|
+
if (!parentNt) continue;
|
|
1259
|
+
buildScopeSubGraph(parentNode, parentNt, scopeName, childIds, ast, nodeTypeMap, theme);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
function buildScopeSubGraph(parentNode, parentNt, scopeName, childIds, ast, nodeTypeMap, theme = "dark") {
|
|
1263
|
+
const childIdSet = new Set(childIds);
|
|
1264
|
+
const scopedOutputDefs = {};
|
|
1265
|
+
const scopedInputDefs = {};
|
|
1266
|
+
for (const [name, def] of Object.entries(parentNt.outputs)) {
|
|
1267
|
+
if (def.scope === scopeName) scopedOutputDefs[name] = def;
|
|
1268
|
+
}
|
|
1269
|
+
for (const [name, def] of Object.entries(parentNt.inputs)) {
|
|
1270
|
+
if (def.scope === scopeName) scopedInputDefs[name] = def;
|
|
1271
|
+
}
|
|
1272
|
+
for (const conn of ast.connections) {
|
|
1273
|
+
if (conn.from.node === parentNode.id && childIdSet.has(conn.to.node)) {
|
|
1274
|
+
const portName = conn.from.port;
|
|
1275
|
+
if (!scopedOutputDefs[portName]) {
|
|
1276
|
+
const parentDef = parentNt.outputs[portName];
|
|
1277
|
+
if (parentDef) {
|
|
1278
|
+
scopedOutputDefs[portName] = { ...parentDef, scope: scopeName };
|
|
1279
|
+
} else {
|
|
1280
|
+
const childInst = ast.instances.find((i) => i.id === conn.to.node);
|
|
1281
|
+
const childNt = childInst ? nodeTypeMap.get(childInst.nodeType) : void 0;
|
|
1282
|
+
const childInputDef = childNt?.inputs[conn.to.port];
|
|
1283
|
+
scopedOutputDefs[portName] = {
|
|
1284
|
+
dataType: childInputDef?.dataType ?? "ANY",
|
|
1285
|
+
scope: scopeName,
|
|
1286
|
+
label: childInputDef?.label ?? portName
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
if (conn.to.node === parentNode.id && childIdSet.has(conn.from.node)) {
|
|
1292
|
+
const portName = conn.to.port;
|
|
1293
|
+
if (!scopedInputDefs[portName]) {
|
|
1294
|
+
const parentDef = parentNt.inputs[portName];
|
|
1295
|
+
if (parentDef) {
|
|
1296
|
+
scopedInputDefs[portName] = { ...parentDef, scope: scopeName };
|
|
1297
|
+
} else {
|
|
1298
|
+
const childInst = ast.instances.find((i) => i.id === conn.from.node);
|
|
1299
|
+
const childNt = childInst ? nodeTypeMap.get(childInst.nodeType) : void 0;
|
|
1300
|
+
const childOutputDef = childNt?.outputs[conn.from.port];
|
|
1301
|
+
scopedInputDefs[portName] = {
|
|
1302
|
+
dataType: childOutputDef?.dataType ?? "ANY",
|
|
1303
|
+
scope: scopeName,
|
|
1304
|
+
label: childOutputDef?.label ?? portName
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
if (!parentNt.expression) {
|
|
1311
|
+
if (!scopedOutputDefs[SCOPED_PORT_NAMES.START]) {
|
|
1312
|
+
scopedOutputDefs[SCOPED_PORT_NAMES.START] = { dataType: "STEP", scope: scopeName, label: "Execute" };
|
|
1313
|
+
}
|
|
1314
|
+
if (!scopedInputDefs[SCOPED_PORT_NAMES.SUCCESS]) {
|
|
1315
|
+
scopedInputDefs[SCOPED_PORT_NAMES.SUCCESS] = { dataType: "STEP", isControlFlow: true, scope: scopeName, label: "On Success" };
|
|
1316
|
+
}
|
|
1317
|
+
if (!scopedInputDefs[SCOPED_PORT_NAMES.FAILURE]) {
|
|
1318
|
+
scopedInputDefs[SCOPED_PORT_NAMES.FAILURE] = { dataType: "STEP", isControlFlow: true, scope: scopeName, failure: true, label: "On Failure" };
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
parentNode.outputs = parentNode.outputs.filter((p) => !scopedOutputDefs[p.name]);
|
|
1322
|
+
parentNode.inputs = parentNode.inputs.filter((p) => !scopedInputDefs[p.name]);
|
|
1323
|
+
const scopeOutputPorts = orderedPorts(scopedOutputDefs, "OUTPUT");
|
|
1324
|
+
const scopeInputPorts = orderedPorts(scopedInputDefs, "INPUT");
|
|
1325
|
+
const children = [];
|
|
1326
|
+
for (const childId of childIds) {
|
|
1327
|
+
const childInst = ast.instances.find((i) => i.id === childId);
|
|
1328
|
+
if (!childInst) continue;
|
|
1329
|
+
const childNode = buildInstanceNode(childId, childInst.nodeType, childInst.config, nodeTypeMap, theme);
|
|
1330
|
+
computeNodeDimensions(childNode);
|
|
1331
|
+
if (childInst.config?.width != null) childNode.width = childInst.config.width;
|
|
1332
|
+
if (childInst.config?.height != null) childNode.height = childInst.config.height;
|
|
1333
|
+
children.push(childNode);
|
|
1334
|
+
}
|
|
1335
|
+
if (children.length === 0) return;
|
|
1336
|
+
let childX = 0;
|
|
1337
|
+
const maxChildHeight = Math.max(...children.map((c) => c.height + LABEL_HEIGHT + LABEL_GAP));
|
|
1338
|
+
for (const child of children) {
|
|
1339
|
+
child.x = childX;
|
|
1340
|
+
child.y = LABEL_HEIGHT + LABEL_GAP + (maxChildHeight - LABEL_HEIGHT - LABEL_GAP - child.height) / 2;
|
|
1341
|
+
childX += child.width + SCOPE_INNER_GAP_X;
|
|
1342
|
+
}
|
|
1343
|
+
const childrenWidth = childX > 0 ? childX - SCOPE_INNER_GAP_X : 0;
|
|
1344
|
+
const childrenHeight = maxChildHeight;
|
|
1345
|
+
const scopeOutPortsHeight = portsColumnHeight(scopeOutputPorts.length);
|
|
1346
|
+
const scopeInPortsHeight = portsColumnHeight(scopeInputPorts.length);
|
|
1347
|
+
const parentUI = ast.ui?.instances?.find((u) => u.name === parentNode.id);
|
|
1348
|
+
const uiWidth = parentUI?.expandedWidth ?? parentUI?.width;
|
|
1349
|
+
const uiHeight = parentUI?.expandedHeight ?? parentUI?.height;
|
|
1350
|
+
const maxLeftLabelExtent = scopeOutputPorts.length > 0 ? Math.max(...scopeOutputPorts.map(portLabelExtent)) : 0;
|
|
1351
|
+
const maxRightLabelExtent = scopeInputPorts.length > 0 ? Math.max(...scopeInputPorts.map(portLabelExtent)) : 0;
|
|
1352
|
+
const minInnerWidth = maxLeftLabelExtent + LABEL_CLEARANCE + maxRightLabelExtent;
|
|
1353
|
+
const contentWidth = Math.max(childrenWidth, minInnerWidth);
|
|
1354
|
+
const computedWidth = SCOPE_PORT_COLUMN + SCOPE_PADDING_X + contentWidth + SCOPE_PADDING_X + SCOPE_PORT_COLUMN;
|
|
1355
|
+
const computedHeight = SCOPE_PADDING_Y * 2 + Math.max(childrenHeight, scopeOutPortsHeight, scopeInPortsHeight);
|
|
1356
|
+
parentNode.width = Math.max(parentNode.width, uiWidth ?? computedWidth);
|
|
1357
|
+
parentNode.height = Math.max(parentNode.height, uiHeight ?? computedHeight);
|
|
1358
|
+
parentNode.scopeChildren = children;
|
|
1359
|
+
parentNode.scopePorts = { inputs: scopeInputPorts, outputs: scopeOutputPorts };
|
|
1360
|
+
parentNode.scopeConnections = [];
|
|
1361
|
+
}
|
|
1362
|
+
function finalizeScopePositions(parentNode, ast, theme = "dark") {
|
|
1363
|
+
const children = parentNode.scopeChildren;
|
|
1364
|
+
const scopePorts = parentNode.scopePorts;
|
|
1365
|
+
if (!children || children.length === 0 || !scopePorts) return;
|
|
1366
|
+
const innerLeft = parentNode.x + SCOPE_PORT_COLUMN + SCOPE_PADDING_X;
|
|
1367
|
+
const innerRight = parentNode.x + parentNode.width - SCOPE_PORT_COLUMN - SCOPE_PADDING_X;
|
|
1368
|
+
const innerWidth = innerRight - innerLeft;
|
|
1369
|
+
const lastChild = children[children.length - 1];
|
|
1370
|
+
const childrenBlockWidth = lastChild.x + lastChild.width;
|
|
1371
|
+
const centerOffsetX = innerLeft + (innerWidth - childrenBlockWidth) / 2;
|
|
1372
|
+
const scopeOriginY = parentNode.y + SCOPE_PADDING_Y;
|
|
1373
|
+
for (const child of children) {
|
|
1374
|
+
child.x += centerOffsetX;
|
|
1375
|
+
child.y += scopeOriginY;
|
|
1376
|
+
computePortPositions(child);
|
|
1377
|
+
}
|
|
1378
|
+
const leftEdgeX = parentNode.x + SCOPE_PORT_COLUMN;
|
|
1379
|
+
positionPortList(scopePorts.outputs, leftEdgeX, parentNode.y);
|
|
1380
|
+
const rightEdgeX = parentNode.x + parentNode.width - SCOPE_PORT_COLUMN;
|
|
1381
|
+
positionPortList(scopePorts.inputs, rightEdgeX, parentNode.y);
|
|
1382
|
+
const childNodeMap = /* @__PURE__ */ new Map();
|
|
1383
|
+
for (const child of children) childNodeMap.set(child.id, child);
|
|
1384
|
+
const childIdSet = new Set(children.map((c) => c.id));
|
|
1385
|
+
parentNode.scopeConnections = [];
|
|
1386
|
+
for (const conn of ast.connections) {
|
|
1387
|
+
const fromIsChild = childIdSet.has(conn.from.node);
|
|
1388
|
+
const toIsChild = childIdSet.has(conn.to.node);
|
|
1389
|
+
const fromIsParent = conn.from.node === parentNode.id;
|
|
1390
|
+
const toIsParent = conn.to.node === parentNode.id;
|
|
1391
|
+
if (!fromIsChild && !toIsChild) continue;
|
|
1392
|
+
if (fromIsParent && toIsChild) {
|
|
1393
|
+
const sourcePort = scopePorts.outputs.find((p) => p.name === conn.from.port);
|
|
1394
|
+
const targetChild = childNodeMap.get(conn.to.node);
|
|
1395
|
+
const targetPort = targetChild?.inputs.find((p) => p.name === conn.to.port);
|
|
1396
|
+
if (sourcePort && targetPort) {
|
|
1397
|
+
parentNode.scopeConnections.push(buildConnection(
|
|
1398
|
+
parentNode.id,
|
|
1399
|
+
conn.from.port,
|
|
1400
|
+
conn.to.node,
|
|
1401
|
+
conn.to.port,
|
|
1402
|
+
sourcePort,
|
|
1403
|
+
targetPort,
|
|
1404
|
+
theme
|
|
1405
|
+
));
|
|
1406
|
+
}
|
|
1407
|
+
continue;
|
|
1408
|
+
}
|
|
1409
|
+
if (fromIsChild && toIsParent) {
|
|
1410
|
+
const sourceChild = childNodeMap.get(conn.from.node);
|
|
1411
|
+
const sourcePort = sourceChild?.outputs.find((p) => p.name === conn.from.port);
|
|
1412
|
+
const targetPort = scopePorts.inputs.find((p) => p.name === conn.to.port);
|
|
1413
|
+
if (sourcePort && targetPort) {
|
|
1414
|
+
parentNode.scopeConnections.push(buildConnection(
|
|
1415
|
+
conn.from.node,
|
|
1416
|
+
conn.from.port,
|
|
1417
|
+
parentNode.id,
|
|
1418
|
+
conn.to.port,
|
|
1419
|
+
sourcePort,
|
|
1420
|
+
targetPort,
|
|
1421
|
+
theme
|
|
1422
|
+
));
|
|
1423
|
+
}
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
if (fromIsChild && toIsChild) {
|
|
1427
|
+
const sourceChild = childNodeMap.get(conn.from.node);
|
|
1428
|
+
const targetChild = childNodeMap.get(conn.to.node);
|
|
1429
|
+
if (sourceChild && targetChild) {
|
|
1430
|
+
const sourcePort = sourceChild.outputs.find((p) => p.name === conn.from.port);
|
|
1431
|
+
const targetPort = targetChild.inputs.find((p) => p.name === conn.to.port);
|
|
1432
|
+
if (sourcePort && targetPort) {
|
|
1433
|
+
parentNode.scopeConnections.push(buildConnection(
|
|
1434
|
+
conn.from.node,
|
|
1435
|
+
conn.from.port,
|
|
1436
|
+
conn.to.node,
|
|
1437
|
+
conn.to.port,
|
|
1438
|
+
sourcePort,
|
|
1439
|
+
targetPort,
|
|
1440
|
+
theme
|
|
1441
|
+
));
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
continue;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (children.length > 0) {
|
|
1448
|
+
const connectedScopePorts = new Set(
|
|
1449
|
+
parentNode.scopeConnections.map(
|
|
1450
|
+
(c) => c.fromNode === parentNode.id ? `out:${c.fromPort}` : `in:${c.toPort}`
|
|
1451
|
+
).filter((k) => k.startsWith("out:") || k.startsWith("in:"))
|
|
1452
|
+
);
|
|
1453
|
+
const firstChild = children[0];
|
|
1454
|
+
const lastChild2 = children[children.length - 1];
|
|
1455
|
+
const execScopePort = scopePorts.outputs.find((p) => isScopedStartPort(p.name));
|
|
1456
|
+
const execChildPort = firstChild.inputs.find((p) => isExecutePort(p.name));
|
|
1457
|
+
if (execScopePort && execChildPort && !connectedScopePorts.has(`out:${execScopePort.name}`)) {
|
|
1458
|
+
parentNode.scopeConnections.push(buildConnection(
|
|
1459
|
+
parentNode.id,
|
|
1460
|
+
execScopePort.name,
|
|
1461
|
+
firstChild.id,
|
|
1462
|
+
execChildPort.name,
|
|
1463
|
+
execScopePort,
|
|
1464
|
+
execChildPort,
|
|
1465
|
+
theme
|
|
1466
|
+
));
|
|
1467
|
+
}
|
|
1468
|
+
const successScopePort = scopePorts.inputs.find((p) => isScopedSuccessPort(p.name));
|
|
1469
|
+
const successChildPort = lastChild2.outputs.find((p) => isSuccessPort(p.name));
|
|
1470
|
+
if (successScopePort && successChildPort && !connectedScopePorts.has(`in:${successScopePort.name}`)) {
|
|
1471
|
+
parentNode.scopeConnections.push(buildConnection(
|
|
1472
|
+
lastChild2.id,
|
|
1473
|
+
successChildPort.name,
|
|
1474
|
+
parentNode.id,
|
|
1475
|
+
successScopePort.name,
|
|
1476
|
+
successChildPort,
|
|
1477
|
+
successScopePort,
|
|
1478
|
+
theme
|
|
1479
|
+
));
|
|
1480
|
+
}
|
|
1481
|
+
const failureScopePort = scopePorts.inputs.find((p) => isScopedFailurePort(p.name));
|
|
1482
|
+
const failureChildPort = lastChild2.outputs.find((p) => isFailurePort(p.name));
|
|
1483
|
+
if (failureScopePort && failureChildPort && !connectedScopePorts.has(`in:${failureScopePort.name}`)) {
|
|
1484
|
+
parentNode.scopeConnections.push(buildConnection(
|
|
1485
|
+
lastChild2.id,
|
|
1486
|
+
failureChildPort.name,
|
|
1487
|
+
parentNode.id,
|
|
1488
|
+
failureScopePort.name,
|
|
1489
|
+
failureChildPort,
|
|
1490
|
+
failureScopePort,
|
|
1491
|
+
theme
|
|
1492
|
+
));
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
function buildConnection(fromNode, fromPort, toNode, toPort, sourcePort, targetPort, theme = "dark") {
|
|
1497
|
+
const sourceColor = getPortColor(sourcePort.dataType, sourcePort.isFailure, theme);
|
|
1498
|
+
const targetColor = getPortColor(targetPort.dataType, targetPort.isFailure, theme);
|
|
1499
|
+
const path = computeConnectionPath(sourcePort.cx, sourcePort.cy, targetPort.cx, targetPort.cy);
|
|
1500
|
+
return {
|
|
1501
|
+
fromNode,
|
|
1502
|
+
fromPort,
|
|
1503
|
+
toNode,
|
|
1504
|
+
toPort,
|
|
1505
|
+
sourceColor,
|
|
1506
|
+
targetColor,
|
|
1507
|
+
isStepConnection: sourcePort.dataType === "STEP",
|
|
1508
|
+
path
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
// src/diagram/geometry.ts
|
|
1513
|
+
function buildDiagramGraph(ast, options = {}) {
|
|
1514
|
+
const themeName = options.theme ?? "dark";
|
|
1515
|
+
const nodeTypeMap = buildNodeTypeMap(ast);
|
|
1516
|
+
const { allScopes, scopedChildren } = collectScopes(ast);
|
|
1517
|
+
const diagramNodes = /* @__PURE__ */ new Map();
|
|
1518
|
+
diagramNodes.set("Start", buildStartNode(ast));
|
|
1519
|
+
diagramNodes.set("Exit", buildExitNode(ast));
|
|
1520
|
+
const stepPortsUsed = collectWiredStepPorts(ast);
|
|
1521
|
+
for (const inst of ast.instances) {
|
|
1522
|
+
if (scopedChildren.has(inst.id)) continue;
|
|
1523
|
+
const node = buildInstanceNode(
|
|
1524
|
+
inst.id,
|
|
1525
|
+
inst.nodeType,
|
|
1526
|
+
inst.config,
|
|
1527
|
+
nodeTypeMap,
|
|
1528
|
+
themeName,
|
|
1529
|
+
stepPortsUsed.get(inst.id) ?? /* @__PURE__ */ new Set()
|
|
1530
|
+
);
|
|
1531
|
+
diagramNodes.set(inst.id, node);
|
|
1532
|
+
}
|
|
1533
|
+
for (const node of diagramNodes.values()) {
|
|
1534
|
+
computeNodeDimensions(node);
|
|
1535
|
+
}
|
|
1536
|
+
buildScopeSubGraphs(ast, diagramNodes, allScopes, nodeTypeMap, themeName);
|
|
1537
|
+
applySizeOverrides(ast, diagramNodes, scopedChildren);
|
|
1538
|
+
const { layers } = layoutWorkflow(ast);
|
|
1539
|
+
assignLayerCoordinates(layers, diagramNodes);
|
|
1540
|
+
resolvePostLayoutOverlaps(diagramNodes);
|
|
1541
|
+
for (const node of diagramNodes.values()) {
|
|
1542
|
+
computePortPositions(node);
|
|
1543
|
+
}
|
|
1544
|
+
for (const node of diagramNodes.values()) {
|
|
1545
|
+
if (node.scopeChildren) {
|
|
1546
|
+
finalizeScopePositions(node, ast, themeName);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
const pendingConnections = collectExternalConnections(ast, diagramNodes, scopedChildren);
|
|
1550
|
+
const nodes = Array.from(diagramNodes.values());
|
|
1551
|
+
const extent = normalizeNodes(nodes);
|
|
1552
|
+
const connections = routeConnections(pendingConnections, nodes, themeName);
|
|
1553
|
+
return {
|
|
1554
|
+
nodes,
|
|
1555
|
+
connections,
|
|
1556
|
+
bounds: graphBounds(extent, connections, nodes),
|
|
1557
|
+
workflowName: ast.name
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
// src/diagram/ascii-renderer.ts
|
|
1562
|
+
function groupByLayer(nodes) {
|
|
1563
|
+
if (nodes.length === 0) return [];
|
|
1564
|
+
const sorted = [...nodes].sort((a, b) => a.x - b.x);
|
|
1565
|
+
const layers = [];
|
|
1566
|
+
let currentX = sorted[0].x;
|
|
1567
|
+
let currentLayer = [];
|
|
1568
|
+
for (const node of sorted) {
|
|
1569
|
+
if (Math.abs(node.x - currentX) > 10) {
|
|
1570
|
+
layers.push(currentLayer);
|
|
1571
|
+
currentLayer = [];
|
|
1572
|
+
currentX = node.x;
|
|
1573
|
+
}
|
|
1574
|
+
currentLayer.push(node);
|
|
1575
|
+
}
|
|
1576
|
+
if (currentLayer.length > 0) layers.push(currentLayer);
|
|
1577
|
+
return layers;
|
|
1578
|
+
}
|
|
1579
|
+
function buildConnectedPorts(connections) {
|
|
1580
|
+
const s = /* @__PURE__ */ new Set();
|
|
1581
|
+
for (const c of connections) {
|
|
1582
|
+
s.add(`${c.fromNode}.${c.fromPort}`);
|
|
1583
|
+
s.add(`${c.toNode}.${c.toPort}`);
|
|
1584
|
+
}
|
|
1585
|
+
return s;
|
|
1586
|
+
}
|
|
1587
|
+
function portSymbol(nodeId, port, connected) {
|
|
1588
|
+
return connected.has(`${nodeId}.${port.name}`) ? "\u25CF" : "\u25CB";
|
|
1589
|
+
}
|
|
1590
|
+
function cornerChar(isStep, hDir, vDir) {
|
|
1591
|
+
if (hDir === "right" && vDir === "down") return isStep ? "\u2554" : "\u250C";
|
|
1592
|
+
if (hDir === "left" && vDir === "down") return isStep ? "\u2557" : "\u2510";
|
|
1593
|
+
if (hDir === "right" && vDir === "up") return isStep ? "\u255A" : "\u2514";
|
|
1594
|
+
if (hDir === "left" && vDir === "up") return isStep ? "\u255D" : "\u2518";
|
|
1595
|
+
return "\u253C";
|
|
1596
|
+
}
|
|
1597
|
+
var H_CHARS = new Set("\u2500\u2550");
|
|
1598
|
+
var V_CHARS = new Set("\u2502\u2551");
|
|
1599
|
+
var CharGrid = class {
|
|
1600
|
+
cells;
|
|
1601
|
+
width;
|
|
1602
|
+
height;
|
|
1603
|
+
constructor(w, h) {
|
|
1604
|
+
this.width = w;
|
|
1605
|
+
this.height = h;
|
|
1606
|
+
this.cells = new Array(w * h).fill(" ");
|
|
1607
|
+
}
|
|
1608
|
+
set(x, y, ch) {
|
|
1609
|
+
if (x < 0 || x >= this.width || y < 0 || y >= this.height) return;
|
|
1610
|
+
const existing = this.cells[y * this.width + x];
|
|
1611
|
+
if (existing !== " ") {
|
|
1612
|
+
if (H_CHARS.has(ch) && V_CHARS.has(existing) || V_CHARS.has(ch) && H_CHARS.has(existing)) {
|
|
1613
|
+
this.cells[y * this.width + x] = "\u253C";
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
if (H_CHARS.has(ch) && H_CHARS.has(existing) || V_CHARS.has(ch) && V_CHARS.has(existing)) {
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
this.cells[y * this.width + x] = ch;
|
|
1621
|
+
}
|
|
1622
|
+
get(x, y) {
|
|
1623
|
+
if (x >= 0 && x < this.width && y >= 0 && y < this.height) {
|
|
1624
|
+
return this.cells[y * this.width + x];
|
|
1625
|
+
}
|
|
1626
|
+
return " ";
|
|
1627
|
+
}
|
|
1628
|
+
/** Force-write, ignoring collision logic (for boxes and text). */
|
|
1629
|
+
forceSet(x, y, ch) {
|
|
1630
|
+
if (x >= 0 && x < this.width && y >= 0 && y < this.height) {
|
|
1631
|
+
this.cells[y * this.width + x] = ch;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
writeStr(x, y, s) {
|
|
1635
|
+
for (let i = 0; i < s.length; i++) {
|
|
1636
|
+
this.forceSet(x + i, y, s[i]);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
toLines() {
|
|
1640
|
+
const lines = [];
|
|
1641
|
+
for (let y = 0; y < this.height; y++) {
|
|
1642
|
+
let line = "";
|
|
1643
|
+
for (let x = 0; x < this.width; x++) {
|
|
1644
|
+
line += this.cells[y * this.width + x];
|
|
1645
|
+
}
|
|
1646
|
+
lines.push(line.trimEnd());
|
|
1647
|
+
}
|
|
1648
|
+
while (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
1649
|
+
return lines;
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
function mergePortRows(inputs, outputs) {
|
|
1653
|
+
const rows = [];
|
|
1654
|
+
const maxLen = Math.max(inputs.length, outputs.length);
|
|
1655
|
+
for (let i = 0; i < maxLen; i++) {
|
|
1656
|
+
rows.push({
|
|
1657
|
+
input: i < inputs.length ? inputs[i] : null,
|
|
1658
|
+
output: i < outputs.length ? outputs[i] : null
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
return rows;
|
|
1662
|
+
}
|
|
1663
|
+
function measureBox(node) {
|
|
1664
|
+
const portRows = mergePortRows(node.inputs, node.outputs);
|
|
1665
|
+
const maxInputPortLen = node.inputs.length > 0 ? Math.max(...node.inputs.map((p) => p.name.length)) : 0;
|
|
1666
|
+
const maxOutputPortLen = node.outputs.length > 0 ? Math.max(...node.outputs.map((p) => p.name.length)) : 0;
|
|
1667
|
+
const portsContentWidth = (maxInputPortLen > 0 ? maxInputPortLen + 2 : 0) + 2 + (maxOutputPortLen > 0 ? maxOutputPortLen + 2 : 0);
|
|
1668
|
+
const innerWidth = Math.max(node.label.length + 2, portsContentWidth, 10);
|
|
1669
|
+
const boxWidth = innerWidth + 2;
|
|
1670
|
+
const headerRows = 3;
|
|
1671
|
+
const portRowCount = Math.max(portRows.length, 1);
|
|
1672
|
+
const boxHeight = headerRows + portRowCount + 1;
|
|
1673
|
+
const portRowOffsets = /* @__PURE__ */ new Map();
|
|
1674
|
+
for (let i = 0; i < portRows.length; i++) {
|
|
1675
|
+
if (portRows[i].input) portRowOffsets.set(portRows[i].input.name, headerRows + i);
|
|
1676
|
+
if (portRows[i].output) portRowOffsets.set(portRows[i].output.name, headerRows + i);
|
|
1677
|
+
}
|
|
1678
|
+
return { node, innerWidth, boxWidth, portRows, boxHeight, portRowOffsets };
|
|
1679
|
+
}
|
|
1680
|
+
function drawBox(grid, box, bx, by, connected) {
|
|
1681
|
+
const { innerWidth, portRows, node } = box;
|
|
1682
|
+
grid.forceSet(bx, by, "\u250C");
|
|
1683
|
+
for (let i = 0; i < innerWidth; i++) grid.forceSet(bx + 1 + i, by, "\u2500");
|
|
1684
|
+
grid.forceSet(bx + innerWidth + 1, by, "\u2510");
|
|
1685
|
+
const labelPad = innerWidth - node.label.length;
|
|
1686
|
+
const padL = Math.floor(labelPad / 2);
|
|
1687
|
+
grid.forceSet(bx, by + 1, "\u2502");
|
|
1688
|
+
grid.writeStr(bx + 1 + padL, by + 1, node.label);
|
|
1689
|
+
grid.forceSet(bx + innerWidth + 1, by + 1, "\u2502");
|
|
1690
|
+
grid.forceSet(bx, by + 2, "\u251C");
|
|
1691
|
+
for (let i = 0; i < innerWidth; i++) grid.forceSet(bx + 1 + i, by + 2, "\u2500");
|
|
1692
|
+
grid.forceSet(bx + innerWidth + 1, by + 2, "\u2524");
|
|
1693
|
+
for (let i = 0; i < Math.max(portRows.length, 1); i++) {
|
|
1694
|
+
const ry = by + 3 + i;
|
|
1695
|
+
grid.forceSet(bx, ry, "\u2502");
|
|
1696
|
+
grid.forceSet(bx + innerWidth + 1, ry, "\u2502");
|
|
1697
|
+
if (i < portRows.length) {
|
|
1698
|
+
const row = portRows[i];
|
|
1699
|
+
if (row.input) {
|
|
1700
|
+
grid.writeStr(bx + 1, ry, `${portSymbol(node.id, row.input, connected)} ${row.input.name}`);
|
|
1701
|
+
}
|
|
1702
|
+
if (row.output) {
|
|
1703
|
+
const txt = `${row.output.name} ${portSymbol(node.id, row.output, connected)}`;
|
|
1704
|
+
grid.writeStr(bx + innerWidth + 1 - txt.length, ry, txt);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
const bottomY = by + box.boxHeight - 1;
|
|
1709
|
+
grid.forceSet(bx, bottomY, "\u2514");
|
|
1710
|
+
for (let i = 0; i < innerWidth; i++) grid.forceSet(bx + 1 + i, bottomY, "\u2500");
|
|
1711
|
+
grid.forceSet(bx + innerWidth + 1, bottomY, "\u2518");
|
|
1712
|
+
}
|
|
1713
|
+
function renderASCII(graph) {
|
|
1714
|
+
const layers = groupByLayer(graph.nodes);
|
|
1715
|
+
if (layers.length === 0) return `${graph.workflowName}
|
|
1716
|
+
(empty workflow)`;
|
|
1717
|
+
const layerBoxes = layers.map((layer) => layer.map(measureBox));
|
|
1718
|
+
const colWidths = layerBoxes.map((boxes) => Math.max(...boxes.map((b) => b.boxWidth)));
|
|
1719
|
+
const wireGap = 14;
|
|
1720
|
+
const colX = [];
|
|
1721
|
+
let cx = 1;
|
|
1722
|
+
for (let c = 0; c < layerBoxes.length; c++) {
|
|
1723
|
+
colX.push(cx);
|
|
1724
|
+
cx += colWidths[c] + wireGap;
|
|
1725
|
+
}
|
|
1726
|
+
const gridWidth = cx + 1;
|
|
1727
|
+
const nodeColMap = /* @__PURE__ */ new Map();
|
|
1728
|
+
for (let c = 0; c < layerBoxes.length; c++) {
|
|
1729
|
+
for (const box of layerBoxes[c]) nodeColMap.set(box.node.id, c);
|
|
1730
|
+
}
|
|
1731
|
+
let spanCount = 0;
|
|
1732
|
+
for (const conn of graph.connections) {
|
|
1733
|
+
const fc = nodeColMap.get(conn.fromNode);
|
|
1734
|
+
const tc = nodeColMap.get(conn.toNode);
|
|
1735
|
+
if (fc !== void 0 && tc !== void 0 && Math.abs(tc - fc) > 1) spanCount++;
|
|
1736
|
+
}
|
|
1737
|
+
const highwayMargin = spanCount > 0 ? spanCount + 1 : 0;
|
|
1738
|
+
const nodeGapY = 2;
|
|
1739
|
+
const boxPositions = /* @__PURE__ */ new Map();
|
|
1740
|
+
const boxStartY = 3 + highwayMargin;
|
|
1741
|
+
let maxGridHeight = 0;
|
|
1742
|
+
for (let c = 0; c < layerBoxes.length; c++) {
|
|
1743
|
+
let y = boxStartY;
|
|
1744
|
+
for (const box of layerBoxes[c]) {
|
|
1745
|
+
boxPositions.set(box.node.id, { col: c, bx: colX[c], by: y, box });
|
|
1746
|
+
y += box.boxHeight + nodeGapY;
|
|
1747
|
+
}
|
|
1748
|
+
if (y > maxGridHeight) maxGridHeight = y;
|
|
1749
|
+
}
|
|
1750
|
+
maxGridHeight += highwayMargin + 3;
|
|
1751
|
+
const connected = buildConnectedPorts(graph.connections);
|
|
1752
|
+
const grid = new CharGrid(gridWidth, maxGridHeight);
|
|
1753
|
+
const titleX = Math.max(0, Math.floor((gridWidth - graph.workflowName.length) / 2));
|
|
1754
|
+
grid.writeStr(titleX, 1, graph.workflowName);
|
|
1755
|
+
for (const pos of boxPositions.values()) {
|
|
1756
|
+
drawBox(grid, pos.box, pos.bx, pos.by, connected);
|
|
1757
|
+
}
|
|
1758
|
+
drawConnections(grid, graph.connections, boxPositions, boxStartY, maxGridHeight);
|
|
1759
|
+
const scopeLines = [];
|
|
1760
|
+
for (const node of graph.nodes) {
|
|
1761
|
+
if (node.scopeChildren && node.scopeChildren.length > 0) {
|
|
1762
|
+
scopeLines.push("");
|
|
1763
|
+
scopeLines.push(` Scope [${node.label}]:`);
|
|
1764
|
+
if (node.scopeConnections) {
|
|
1765
|
+
for (const sc of node.scopeConnections) {
|
|
1766
|
+
const arrow = sc.isStepConnection ? "\u2550\u2550\u25B6" : "\u2500\u2500\u25B6";
|
|
1767
|
+
scopeLines.push(` ${sc.fromNode}.${sc.fromPort} ${arrow} ${sc.toNode}.${sc.toPort}${sc.isStepConnection ? " STEP" : ""}`);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
const lines = grid.toLines();
|
|
1773
|
+
lines.push(...scopeLines);
|
|
1774
|
+
lines.push("");
|
|
1775
|
+
lines.push(" \u25CF connected \u25CB not connected \u2550\u2550\u25B6 STEP \u2500\u2500\u25B6 DATA");
|
|
1776
|
+
return lines.join("\n");
|
|
1777
|
+
}
|
|
1778
|
+
function drawConnections(grid, connections, positions, _boxAreaTop, _gridHeight) {
|
|
1779
|
+
let globalMinY = Infinity;
|
|
1780
|
+
let globalMaxY = 0;
|
|
1781
|
+
for (const pos of positions.values()) {
|
|
1782
|
+
globalMinY = Math.min(globalMinY, pos.by);
|
|
1783
|
+
globalMaxY = Math.max(globalMaxY, pos.by + pos.box.boxHeight);
|
|
1784
|
+
}
|
|
1785
|
+
const sorted = [...connections].sort((a, b) => {
|
|
1786
|
+
const fa = positions.get(a.fromNode);
|
|
1787
|
+
const ta = positions.get(a.toNode);
|
|
1788
|
+
const fb = positions.get(b.fromNode);
|
|
1789
|
+
const tb = positions.get(b.toNode);
|
|
1790
|
+
if (!fa || !ta || !fb || !tb) return 0;
|
|
1791
|
+
const spanA = Math.abs(ta.col - fa.col);
|
|
1792
|
+
const spanB = Math.abs(tb.col - fb.col);
|
|
1793
|
+
if (spanA !== spanB) return spanA - spanB;
|
|
1794
|
+
const ya = fa.by + (fa.box.portRowOffsets.get(a.fromPort) ?? 0);
|
|
1795
|
+
const yb = fb.by + (fb.box.portRowOffsets.get(b.fromPort) ?? 0);
|
|
1796
|
+
return ya - yb;
|
|
1797
|
+
});
|
|
1798
|
+
const usedTracks = /* @__PURE__ */ new Map();
|
|
1799
|
+
let nextAboveHighway = globalMinY - 2;
|
|
1800
|
+
let nextBelowHighway = globalMaxY + 1;
|
|
1801
|
+
for (const conn of sorted) {
|
|
1802
|
+
const fromPos = positions.get(conn.fromNode);
|
|
1803
|
+
const toPos = positions.get(conn.toNode);
|
|
1804
|
+
if (!fromPos || !toPos) continue;
|
|
1805
|
+
const fromRowOff = fromPos.box.portRowOffsets.get(conn.fromPort);
|
|
1806
|
+
const toRowOff = toPos.box.portRowOffsets.get(conn.toPort);
|
|
1807
|
+
if (fromRowOff === void 0 || toRowOff === void 0) continue;
|
|
1808
|
+
const y1 = fromPos.by + fromRowOff;
|
|
1809
|
+
const y2 = toPos.by + toRowOff;
|
|
1810
|
+
const x1 = fromPos.bx + fromPos.box.boxWidth;
|
|
1811
|
+
const x2 = toPos.bx - 1;
|
|
1812
|
+
const isStep = conn.isStepConnection;
|
|
1813
|
+
const hCh = isStep ? "\u2550" : "\u2500";
|
|
1814
|
+
const vCh = isStep ? "\u2551" : "\u2502";
|
|
1815
|
+
const isAdjacent = toPos.col === fromPos.col + 1;
|
|
1816
|
+
if (isAdjacent) {
|
|
1817
|
+
drawAdjacentRoute(grid, x1, y1, x2, y2, hCh, vCh, isStep, usedTracks, fromPos, toPos);
|
|
1818
|
+
} else {
|
|
1819
|
+
const avgY = (y1 + y2) / 2;
|
|
1820
|
+
const midBoxY = (globalMinY + globalMaxY) / 2;
|
|
1821
|
+
let highwayY;
|
|
1822
|
+
if (avgY <= midBoxY) {
|
|
1823
|
+
highwayY = nextAboveHighway;
|
|
1824
|
+
nextAboveHighway--;
|
|
1825
|
+
} else {
|
|
1826
|
+
highwayY = nextBelowHighway;
|
|
1827
|
+
nextBelowHighway++;
|
|
1828
|
+
}
|
|
1829
|
+
drawSpanningRoute(grid, x1, y1, x2, y2, highwayY, hCh, vCh, isStep, usedTracks, fromPos, toPos);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
function drawAdjacentRoute(grid, x1, y1, x2, y2, hCh, vCh, isStep, usedTracks, fromPos, toPos) {
|
|
1834
|
+
if (y1 === y2) {
|
|
1835
|
+
for (let x = x1; x < x2; x++) grid.set(x, y1, hCh);
|
|
1836
|
+
grid.set(x2, y1, "\u25B6");
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
const gapStart = fromPos.bx + fromPos.box.boxWidth + 1;
|
|
1840
|
+
const gapEnd = toPos.bx - 2;
|
|
1841
|
+
const midX = findTrack(usedTracks, gapStart, gapEnd, y1, y2);
|
|
1842
|
+
markTrack(usedTracks, midX, y1, y2);
|
|
1843
|
+
for (let x = x1; x < midX; x++) grid.set(x, y1, hCh);
|
|
1844
|
+
grid.set(midX, y1, cornerChar(isStep, "left", y2 > y1 ? "down" : "up"));
|
|
1845
|
+
drawVerticalSegment(grid, midX, y1, y2, vCh);
|
|
1846
|
+
grid.set(midX, y2, cornerChar(isStep, "right", y2 > y1 ? "up" : "down"));
|
|
1847
|
+
for (let x = midX + 1; x < x2; x++) grid.set(x, y2, hCh);
|
|
1848
|
+
grid.set(x2, y2, "\u25B6");
|
|
1849
|
+
}
|
|
1850
|
+
function drawSpanningRoute(grid, x1, y1, x2, y2, highwayY, hCh, vCh, isStep, usedTracks, fromPos, toPos) {
|
|
1851
|
+
const srcGapStart = fromPos.bx + fromPos.box.boxWidth + 1;
|
|
1852
|
+
const srcGapEnd = srcGapStart + 10;
|
|
1853
|
+
const srcMidX = findTrack(usedTracks, srcGapStart, srcGapEnd, y1, highwayY);
|
|
1854
|
+
markTrack(usedTracks, srcMidX, y1, highwayY);
|
|
1855
|
+
const tgtGapEnd = toPos.bx - 2;
|
|
1856
|
+
const tgtGapStart = tgtGapEnd - 10;
|
|
1857
|
+
const tgtMidX = findTrack(usedTracks, tgtGapStart, tgtGapEnd, highwayY, y2);
|
|
1858
|
+
markTrack(usedTracks, tgtMidX, highwayY, y2);
|
|
1859
|
+
const goingDown = highwayY > y1;
|
|
1860
|
+
const goingUp = y2 < highwayY;
|
|
1861
|
+
for (let x = x1; x < srcMidX; x++) grid.set(x, y1, hCh);
|
|
1862
|
+
grid.set(srcMidX, y1, cornerChar(isStep, "left", goingDown ? "down" : "up"));
|
|
1863
|
+
drawVerticalSegment(grid, srcMidX, y1, highwayY, vCh);
|
|
1864
|
+
grid.set(srcMidX, highwayY, cornerChar(isStep, "right", goingDown ? "up" : "down"));
|
|
1865
|
+
for (let x = srcMidX + 1; x < tgtMidX; x++) grid.set(x, highwayY, hCh);
|
|
1866
|
+
grid.set(tgtMidX, highwayY, cornerChar(isStep, "left", goingUp ? "up" : "down"));
|
|
1867
|
+
drawVerticalSegment(grid, tgtMidX, highwayY, y2, vCh);
|
|
1868
|
+
grid.set(tgtMidX, y2, cornerChar(isStep, "right", goingUp ? "down" : "up"));
|
|
1869
|
+
for (let x = tgtMidX + 1; x < x2; x++) grid.set(x, y2, hCh);
|
|
1870
|
+
grid.set(x2, y2, "\u25B6");
|
|
1871
|
+
}
|
|
1872
|
+
function drawVerticalSegment(grid, x, y1, y2, vCh) {
|
|
1873
|
+
const minY = Math.min(y1, y2);
|
|
1874
|
+
const maxY = Math.max(y1, y2);
|
|
1875
|
+
for (let y = minY + 1; y < maxY; y++) {
|
|
1876
|
+
grid.set(x, y, vCh);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
function findTrack(usedTracks, gapStart, gapEnd, y1, y2) {
|
|
1880
|
+
const minY = Math.min(y1, y2);
|
|
1881
|
+
const maxY = Math.max(y1, y2);
|
|
1882
|
+
const actualStart = Math.min(gapStart, gapEnd);
|
|
1883
|
+
const actualEnd = Math.max(gapStart, gapEnd);
|
|
1884
|
+
const mid = Math.floor((actualStart + actualEnd) / 2);
|
|
1885
|
+
for (let offset = 0; offset <= actualEnd - actualStart; offset++) {
|
|
1886
|
+
for (const candidate of [mid + offset, mid - offset]) {
|
|
1887
|
+
if (candidate < actualStart || candidate > actualEnd) continue;
|
|
1888
|
+
const existing = usedTracks.get(candidate);
|
|
1889
|
+
if (!existing) return candidate;
|
|
1890
|
+
let conflict = false;
|
|
1891
|
+
for (let y = minY; y <= maxY; y++) {
|
|
1892
|
+
if (existing.has(y)) {
|
|
1893
|
+
conflict = true;
|
|
1894
|
+
break;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
if (!conflict) return candidate;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
return mid;
|
|
1901
|
+
}
|
|
1902
|
+
function markTrack(usedTracks, x, y1, y2) {
|
|
1903
|
+
if (!usedTracks.has(x)) usedTracks.set(x, /* @__PURE__ */ new Set());
|
|
1904
|
+
const s = usedTracks.get(x);
|
|
1905
|
+
const minY = Math.min(y1, y2);
|
|
1906
|
+
const maxY = Math.max(y1, y2);
|
|
1907
|
+
for (let y = minY; y <= maxY; y++) s.add(y);
|
|
1908
|
+
}
|
|
1909
|
+
function renderASCIICompact(graph) {
|
|
1910
|
+
const layers = groupByLayer(graph.nodes);
|
|
1911
|
+
if (layers.length === 0) return `${graph.workflowName}
|
|
1912
|
+
(empty workflow)`;
|
|
1913
|
+
const outputLines = [];
|
|
1914
|
+
outputLines.push(graph.workflowName);
|
|
1915
|
+
outputLines.push("");
|
|
1916
|
+
const mainChain = [];
|
|
1917
|
+
const parallelNodes = [];
|
|
1918
|
+
for (const layer of layers) {
|
|
1919
|
+
mainChain.push(layer[0]);
|
|
1920
|
+
for (let i = 1; i < layer.length; i++) parallelNodes.push(layer[i]);
|
|
1921
|
+
}
|
|
1922
|
+
const topParts = [];
|
|
1923
|
+
const midParts = [];
|
|
1924
|
+
const botParts = [];
|
|
1925
|
+
for (let i = 0; i < mainChain.length; i++) {
|
|
1926
|
+
const node = mainChain[i];
|
|
1927
|
+
const innerWidth = Math.max(node.label.length + 2, 5);
|
|
1928
|
+
const padLeft = Math.floor((innerWidth - node.label.length) / 2);
|
|
1929
|
+
const padRight = innerWidth - node.label.length - padLeft;
|
|
1930
|
+
topParts.push("\u250C" + "\u2500".repeat(innerWidth) + "\u2510");
|
|
1931
|
+
midParts.push("\u2502" + " ".repeat(padLeft) + node.label + " ".repeat(padRight) + "\u2502");
|
|
1932
|
+
botParts.push("\u2514" + "\u2500".repeat(innerWidth) + "\u2518");
|
|
1933
|
+
if (i < mainChain.length - 1) {
|
|
1934
|
+
topParts.push(" ");
|
|
1935
|
+
midParts.push("\u2501\u2501\u2501\u25B6");
|
|
1936
|
+
botParts.push(" ");
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
outputLines.push(" " + topParts.join(""));
|
|
1940
|
+
outputLines.push(" " + midParts.join(""));
|
|
1941
|
+
outputLines.push(" " + botParts.join(""));
|
|
1942
|
+
if (parallelNodes.length > 0) {
|
|
1943
|
+
outputLines.push("");
|
|
1944
|
+
outputLines.push(" Parallel: " + parallelNodes.map((n) => n.label).join(", "));
|
|
1945
|
+
}
|
|
1946
|
+
for (const node of graph.nodes) {
|
|
1947
|
+
if (node.scopeChildren && node.scopeChildren.length > 0) {
|
|
1948
|
+
outputLines.push("");
|
|
1949
|
+
outputLines.push(` Scope [${node.label}]: ` + node.scopeChildren.map((c) => c.label).join(" \u2501\u25B6 "));
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
return outputLines.join("\n");
|
|
1953
|
+
}
|
|
1954
|
+
function renderText(graph) {
|
|
1955
|
+
const lines = [];
|
|
1956
|
+
const connected = buildConnectedPorts(graph.connections);
|
|
1957
|
+
lines.push(graph.workflowName);
|
|
1958
|
+
lines.push("\u2550".repeat(graph.workflowName.length));
|
|
1959
|
+
lines.push("");
|
|
1960
|
+
lines.push("Nodes:");
|
|
1961
|
+
const maxLabelLen = Math.max(...graph.nodes.map((n) => n.label.length), 5);
|
|
1962
|
+
for (const node of graph.nodes) {
|
|
1963
|
+
const label = node.label.padEnd(maxLabelLen);
|
|
1964
|
+
const inputPorts = node.inputs.map((p) => `${p.name}${portSymbol(node.id, p, connected)}`);
|
|
1965
|
+
const outputPorts = node.outputs.map((p) => `${p.name}${portSymbol(node.id, p, connected)}`);
|
|
1966
|
+
const inputStr = inputPorts.length > 0 ? `[${inputPorts.join(", ")}]` : "";
|
|
1967
|
+
const outputStr = outputPorts.length > 0 ? `[${outputPorts.join(", ")}]` : "";
|
|
1968
|
+
if (inputStr && outputStr) {
|
|
1969
|
+
lines.push(` ${label} ${inputStr} \u2192 ${outputStr}`);
|
|
1970
|
+
} else if (outputStr) {
|
|
1971
|
+
lines.push(` ${label} ${outputStr}`);
|
|
1972
|
+
} else if (inputStr) {
|
|
1973
|
+
lines.push(` ${label} ${inputStr}`);
|
|
1974
|
+
} else {
|
|
1975
|
+
lines.push(` ${label}`);
|
|
1976
|
+
}
|
|
1977
|
+
if (node.scopeChildren && node.scopeChildren.length > 0) {
|
|
1978
|
+
lines.push(` ${" ".repeat(maxLabelLen)} scope: ${node.scopeChildren.map((c) => c.label).join(", ")}`);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
if (graph.connections.length > 0) {
|
|
1982
|
+
lines.push("");
|
|
1983
|
+
lines.push("Connections:");
|
|
1984
|
+
const maxFromLen = Math.max(...graph.connections.map((c) => `${c.fromNode}.${c.fromPort}`.length));
|
|
1985
|
+
for (const conn of graph.connections) {
|
|
1986
|
+
const from = `${conn.fromNode}.${conn.fromPort}`.padEnd(maxFromLen);
|
|
1987
|
+
const arrow = conn.isStepConnection ? "\u2501\u2501\u25B6" : "\u2500\u2500\u25B6";
|
|
1988
|
+
const to = `${conn.toNode}.${conn.toPort}`;
|
|
1989
|
+
const type = conn.isStepConnection ? "STEP" : "";
|
|
1990
|
+
lines.push(` ${from} ${arrow} ${to}${type ? " " + type : ""}`);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
return lines.join("\n");
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
export {
|
|
1997
|
+
buildDiagramGraph,
|
|
1998
|
+
renderASCII,
|
|
1999
|
+
renderASCIICompact,
|
|
2000
|
+
renderText
|
|
2001
|
+
};
|