@pikku/core 0.11.2 → 0.12.1
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/CHANGELOG.md +57 -2
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- package/dist/errors/errors.d.ts +14 -0
- package/dist/errors/errors.js +26 -0
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/function/function-runner.d.ts +10 -4
- package/dist/function/function-runner.js +126 -45
- package/dist/function/functions.types.d.ts +32 -87
- package/dist/function/functions.types.js +16 -46
- package/dist/function/index.d.ts +2 -2
- package/dist/function/index.js +1 -2
- package/dist/handle-error.d.ts +2 -2
- package/dist/handle-error.js +3 -12
- package/dist/index.d.ts +30 -26
- package/dist/index.js +19 -29
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +2 -2
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +3 -3
- package/dist/middleware/auth-bearer.js +4 -7
- package/dist/middleware/auth-cookie.d.ts +4 -4
- package/dist/middleware/auth-cookie.js +7 -9
- package/dist/middleware/cors.d.ts +46 -0
- package/dist/middleware/cors.js +81 -0
- package/dist/middleware/index.d.ts +5 -3
- package/dist/middleware/index.js +5 -3
- package/dist/middleware/remote-auth.d.ts +5 -0
- package/dist/middleware/remote-auth.js +55 -0
- package/dist/middleware/timeout.d.ts +2 -2
- package/dist/middleware-runner.d.ts +1 -1
- package/dist/middleware-runner.js +8 -10
- package/dist/permissions.d.ts +2 -2
- package/dist/permissions.js +11 -15
- package/dist/pikku-state.d.ts +10 -8
- package/dist/pikku-state.js +48 -25
- package/dist/schema.d.ts +4 -4
- package/dist/schema.js +20 -15
- package/dist/services/ai-agent-runner-service.d.ts +43 -0
- package/dist/services/ai-agent-runner-service.js +1 -0
- package/dist/services/ai-run-state-service.d.ts +13 -0
- package/dist/services/ai-run-state-service.js +1 -0
- package/dist/services/ai-storage-service.d.ts +18 -0
- package/dist/services/ai-storage-service.js +1 -0
- package/dist/services/content-service.d.ts +6 -0
- package/dist/services/deployment-service.d.ts +19 -0
- package/dist/services/deployment-service.js +1 -0
- package/dist/services/gopass-secrets.d.ts +47 -0
- package/dist/services/gopass-secrets.js +97 -0
- package/dist/services/in-memory-ai-run-state-service.d.ts +15 -0
- package/dist/services/in-memory-ai-run-state-service.js +44 -0
- package/dist/services/in-memory-trigger-service.d.ts +22 -0
- package/dist/services/in-memory-trigger-service.js +48 -0
- package/dist/services/in-memory-workflow-service.d.ts +59 -0
- package/dist/services/in-memory-workflow-service.js +287 -0
- package/dist/services/index.d.ts +26 -11
- package/dist/services/index.js +11 -13
- package/dist/services/local-content.d.ts +2 -1
- package/dist/services/local-content.js +6 -1
- package/dist/services/local-secrets.d.ts +25 -2
- package/dist/services/local-secrets.js +45 -0
- package/dist/services/local-variables.d.ts +6 -1
- package/dist/services/local-variables.js +18 -0
- package/dist/services/logger-console.d.ts +2 -1
- package/dist/services/scheduler-service.d.ts +9 -1
- package/dist/services/scheduler-service.js +8 -0
- package/dist/services/schema-service.d.ts +6 -0
- package/dist/services/scoped-secret-service.d.ts +16 -0
- package/dist/services/scoped-secret-service.js +35 -0
- package/dist/services/secret-service.d.ts +25 -4
- package/dist/services/trigger-service.d.ts +16 -0
- package/dist/services/trigger-service.js +1 -0
- package/dist/services/typed-secret-service.d.ts +30 -0
- package/dist/services/typed-secret-service.js +40 -0
- package/dist/services/typed-variables-service.d.ts +27 -0
- package/dist/services/typed-variables-service.js +46 -0
- package/dist/services/user-session-service.d.ts +15 -2
- package/dist/services/user-session-service.js +17 -0
- package/dist/services/variables-service.d.ts +5 -0
- package/dist/services/workflow-service.d.ts +9 -5
- package/dist/types/core.types.d.ts +67 -25
- package/dist/types/core.types.js +8 -1
- package/dist/types/state.types.d.ts +53 -59
- package/dist/utils.d.ts +7 -6
- package/dist/utils.js +27 -12
- package/dist/version.d.ts +6 -0
- package/dist/version.js +19 -0
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +5 -0
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +146 -0
- package/dist/wirings/ai-agent/ai-agent-helpers.d.ts +28 -0
- package/dist/wirings/ai-agent/ai-agent-helpers.js +40 -0
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +29 -0
- package/dist/wirings/ai-agent/ai-agent-memory.js +199 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +9 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.js +36 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +59 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.js +348 -0
- package/dist/wirings/ai-agent/ai-agent-registry.d.ts +15 -0
- package/dist/wirings/ai-agent/ai-agent-registry.js +47 -0
- package/dist/wirings/ai-agent/ai-agent-runner.d.ts +3 -0
- package/dist/wirings/ai-agent/ai-agent-runner.js +195 -0
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +12 -0
- package/dist/wirings/ai-agent/ai-agent-stream.js +662 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +313 -0
- package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
- package/dist/wirings/ai-agent/index.d.ts +7 -0
- package/dist/wirings/ai-agent/index.js +6 -0
- package/dist/wirings/channel/channel-common.d.ts +8 -5
- package/dist/wirings/channel/channel-common.js +15 -8
- package/dist/wirings/channel/channel-handler.d.ts +3 -3
- package/dist/wirings/channel/channel-handler.js +15 -6
- package/dist/wirings/channel/channel-middleware-runner.d.ts +9 -0
- package/dist/wirings/channel/channel-middleware-runner.js +73 -0
- package/dist/wirings/channel/channel-runner.d.ts +5 -5
- package/dist/wirings/channel/channel-runner.js +10 -9
- package/dist/wirings/channel/channel-store.d.ts +1 -1
- package/dist/wirings/channel/channel.types.d.ts +9 -7
- package/dist/wirings/channel/define-channel-routes.d.ts +21 -0
- package/dist/wirings/channel/define-channel-routes.js +23 -0
- package/dist/wirings/channel/index.d.ts +10 -8
- package/dist/wirings/channel/index.js +7 -8
- package/dist/wirings/channel/local/index.d.ts +3 -3
- package/dist/wirings/channel/local/index.js +3 -3
- package/dist/wirings/channel/local/local-channel-runner.d.ts +7 -2
- package/dist/wirings/channel/local/local-channel-runner.js +22 -9
- package/dist/wirings/channel/local/local-eventhub-service.d.ts +2 -2
- package/dist/wirings/channel/log-channels.d.ts +1 -1
- package/dist/wirings/channel/pikku-abstract-channel-handler.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +4 -4
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +40 -23
- package/dist/wirings/cli/channel/cli-channel-runner.d.ts +1 -1
- package/dist/wirings/cli/channel/index.d.ts +1 -1
- package/dist/wirings/cli/channel/index.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +3 -3
- package/dist/wirings/cli/cli-runner.js +12 -8
- package/dist/wirings/cli/cli.types.d.ts +9 -9
- package/dist/wirings/cli/command-parser.d.ts +1 -1
- package/dist/wirings/cli/define-cli-commands.d.ts +19 -0
- package/dist/wirings/cli/define-cli-commands.js +20 -0
- package/dist/wirings/cli/index.d.ts +2 -3
- package/dist/wirings/cli/index.js +1 -3
- package/dist/wirings/http/http-routes.d.ts +69 -0
- package/dist/wirings/http/http-routes.js +139 -0
- package/dist/wirings/http/http-runner.d.ts +9 -9
- package/dist/wirings/http/http-runner.js +79 -34
- package/dist/wirings/http/http.types.d.ts +77 -41
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- package/dist/wirings/http/log-http-routes.d.ts +1 -1
- package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -1
- package/dist/wirings/http/pikku-fetch-http-response.d.ts +2 -2
- package/dist/wirings/http/pikku-fetch-http-response.js +6 -1
- package/dist/wirings/http/routers/http-router.d.ts +1 -1
- package/dist/wirings/http/routers/path-to-regex.d.ts +2 -2
- package/dist/wirings/mcp/index.d.ts +4 -3
- package/dist/wirings/mcp/index.js +3 -3
- package/dist/wirings/mcp/mcp-endpoint-registry.d.ts +1 -1
- package/dist/wirings/mcp/mcp-runner.d.ts +1 -6
- package/dist/wirings/mcp/mcp-runner.js +28 -40
- package/dist/wirings/mcp/mcp.types.d.ts +5 -5
- package/dist/wirings/node/index.d.ts +2 -0
- package/dist/wirings/node/index.js +1 -0
- package/dist/wirings/node/node.types.d.ts +20 -0
- package/dist/wirings/node/node.types.js +1 -0
- package/dist/wirings/oauth2/index.d.ts +3 -0
- package/dist/wirings/oauth2/index.js +2 -0
- package/dist/wirings/oauth2/oauth2-client.d.ts +47 -0
- package/dist/wirings/oauth2/oauth2-client.js +267 -0
- package/dist/wirings/oauth2/oauth2.types.d.ts +65 -0
- package/dist/wirings/oauth2/oauth2.types.js +4 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.d.ts +20 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.js +21 -0
- package/dist/wirings/queue/index.d.ts +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +1 -5
- package/dist/wirings/queue/queue-runner.js +11 -8
- package/dist/wirings/queue/queue.types.d.ts +5 -5
- package/dist/wirings/queue/register-queue-helper.d.ts +2 -2
- package/dist/wirings/queue/register-queue-helper.js +1 -1
- package/dist/wirings/queue/validate-worker-config.d.ts +1 -1
- package/dist/wirings/rpc/index.d.ts +3 -1
- package/dist/wirings/rpc/index.js +2 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +58 -8
- package/dist/wirings/rpc/rpc-runner.js +177 -31
- package/dist/wirings/rpc/rpc-types.d.ts +20 -4
- package/dist/wirings/rpc/wire-addon.d.ts +10 -0
- package/dist/wirings/rpc/wire-addon.js +9 -0
- package/dist/wirings/scheduler/index.d.ts +2 -2
- package/dist/wirings/scheduler/index.js +1 -2
- package/dist/wirings/scheduler/log-schedulers.d.ts +1 -1
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -5
- package/dist/wirings/scheduler/scheduler-runner.js +11 -14
- package/dist/wirings/scheduler/scheduler.types.d.ts +2 -2
- package/dist/wirings/secret/index.d.ts +3 -0
- package/dist/wirings/secret/index.js +2 -0
- package/dist/wirings/secret/secret.types.d.ts +27 -0
- package/dist/wirings/secret/secret.types.js +1 -0
- package/dist/wirings/secret/validate-secret-definitions.d.ts +6 -0
- package/dist/wirings/secret/validate-secret-definitions.js +55 -0
- package/dist/wirings/trigger/index.d.ts +3 -2
- package/dist/wirings/trigger/index.js +2 -2
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +22 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +70 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +18 -9
- package/dist/wirings/trigger/trigger-runner.js +48 -19
- package/dist/wirings/trigger/trigger.types.d.ts +99 -11
- package/dist/wirings/trigger/trigger.types.js +40 -1
- package/dist/wirings/variable/index.d.ts +3 -0
- package/dist/wirings/variable/index.js +2 -0
- package/dist/wirings/variable/validate-variable-definitions.d.ts +6 -0
- package/dist/wirings/variable/validate-variable-definitions.js +45 -0
- package/dist/wirings/variable/variable.types.d.ts +18 -0
- package/dist/wirings/variable/variable.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +1 -1
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +7 -1
- package/dist/wirings/workflow/dsl/workflow-runner.js +3 -2
- package/dist/wirings/workflow/graph/graph-node.d.ts +1 -6
- package/dist/wirings/workflow/graph/graph-runner.d.ts +5 -31
- package/dist/wirings/workflow/graph/graph-runner.js +384 -296
- package/dist/wirings/workflow/graph/index.d.ts +4 -3
- package/dist/wirings/workflow/graph/index.js +3 -3
- package/dist/wirings/workflow/graph/template.d.ts +15 -0
- package/dist/wirings/workflow/graph/template.js +27 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +15 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.js +8 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +0 -13
- package/dist/wirings/workflow/index.d.ts +6 -6
- package/dist/wirings/workflow/index.js +6 -4
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +29 -19
- package/dist/wirings/workflow/pikku-workflow-service.js +217 -82
- package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
- package/dist/wirings/workflow/workflow-helpers.js +38 -0
- package/dist/wirings/workflow/workflow.types.d.ts +42 -95
- package/package.json +14 -15
- package/run-tests.sh +4 -1
- package/src/crypto-utils.test.ts +116 -0
- package/src/crypto-utils.ts +99 -0
- package/src/errors/error.test.ts +143 -2
- package/src/errors/errors.ts +27 -0
- package/src/errors/index.ts +1 -1
- package/src/factory-functions.test.ts +42 -2
- package/src/function/function-runner.test.ts +6 -13
- package/src/function/function-runner.ts +161 -53
- package/src/function/functions.types.ts +63 -132
- package/src/function/index.ts +5 -2
- package/src/handle-error.test.ts +361 -0
- package/src/handle-error.ts +6 -14
- package/src/index.ts +97 -30
- package/src/internal.ts +6 -0
- package/src/middleware/auth-apikey.test.ts +16 -13
- package/src/middleware/auth-apikey.ts +3 -3
- package/src/middleware/auth-bearer.test.ts +18 -15
- package/src/middleware/auth-bearer.ts +27 -32
- package/src/middleware/auth-cookie.test.ts +17 -14
- package/src/middleware/auth-cookie.ts +9 -13
- package/src/middleware/cors.test.ts +424 -0
- package/src/middleware/cors.ts +104 -0
- package/src/middleware/index.ts +5 -3
- package/src/middleware/remote-auth.test.ts +488 -0
- package/src/middleware/remote-auth.ts +68 -0
- package/src/middleware-runner.test.ts +123 -1
- package/src/middleware-runner.ts +13 -13
- package/src/permissions.test.ts +83 -9
- package/src/permissions.ts +17 -19
- package/src/pikku-state.test.ts +224 -0
- package/src/pikku-state.ts +59 -35
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.test.ts +198 -6
- package/src/schema.ts +28 -21
- package/src/services/ai-agent-runner-service.ts +41 -0
- package/src/services/ai-run-state-service.ts +20 -0
- package/src/services/ai-storage-service.ts +39 -0
- package/src/services/content-service.ts +7 -0
- package/src/services/deployment-service.ts +22 -0
- package/src/services/gopass-secrets.ts +98 -0
- package/src/services/in-memory-ai-run-state-service.ts +73 -0
- package/src/services/in-memory-trigger-service.ts +64 -0
- package/src/services/in-memory-workflow-service.test.ts +351 -0
- package/src/services/in-memory-workflow-service.ts +395 -0
- package/src/services/index.ts +50 -14
- package/src/services/local-content.ts +9 -3
- package/src/services/local-secrets.test.ts +80 -0
- package/src/services/local-secrets.ts +53 -2
- package/src/services/local-variables.test.ts +61 -0
- package/src/services/local-variables.ts +23 -1
- package/src/services/logger-console.test.ts +118 -0
- package/src/services/logger-console.ts +2 -1
- package/src/services/scheduler-service.ts +11 -1
- package/src/services/schema-service.ts +7 -0
- package/src/services/scoped-secret-service.test.ts +74 -0
- package/src/services/scoped-secret-service.ts +41 -0
- package/src/services/secret-service.ts +25 -4
- package/src/services/trigger-service.ts +17 -0
- package/src/services/typed-secret-service.test.ts +93 -0
- package/src/services/typed-secret-service.ts +70 -0
- package/src/services/typed-variables-service.test.ts +73 -0
- package/src/services/typed-variables-service.ts +81 -0
- package/src/services/user-session-service.test.ts +113 -0
- package/src/services/user-session-service.ts +25 -2
- package/src/services/variables-service.ts +5 -0
- package/src/services/workflow-service.ts +23 -13
- package/src/time-utils.test.ts +1 -1
- package/src/types/core.types.ts +95 -24
- package/src/types/state.types.ts +56 -73
- package/src/utils.test.ts +350 -0
- package/src/utils.ts +33 -18
- package/src/version.test.ts +80 -0
- package/src/version.ts +25 -0
- package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +363 -0
- package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +214 -0
- package/src/wirings/ai-agent/ai-agent-helpers.test.ts +152 -0
- package/src/wirings/ai-agent/ai-agent-helpers.ts +76 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
- package/src/wirings/ai-agent/ai-agent-model-config.test.ts +115 -0
- package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +504 -0
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +37 -0
- package/src/wirings/ai-agent/ai-agent-registry.ts +82 -0
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +317 -0
- package/src/wirings/ai-agent/ai-agent-runner.ts +251 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +652 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +1049 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +328 -0
- package/src/wirings/ai-agent/index.ts +39 -0
- package/src/wirings/channel/channel-common.ts +33 -20
- package/src/wirings/channel/channel-handler.ts +26 -9
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +15 -16
- package/src/wirings/channel/channel-store.ts +1 -1
- package/src/wirings/channel/channel.types.ts +21 -9
- package/src/wirings/channel/define-channel-routes.ts +25 -0
- package/src/wirings/channel/index.ts +23 -8
- package/src/wirings/channel/local/index.ts +3 -3
- package/src/wirings/channel/local/local-channel-runner.test.ts +57 -7
- package/src/wirings/channel/local/local-channel-runner.ts +40 -19
- package/src/wirings/channel/local/local-eventhub-service.test.ts +2 -2
- package/src/wirings/channel/local/local-eventhub-service.ts +2 -2
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +1 -1
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +57 -36
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +10 -10
- package/src/wirings/cli/cli-runner.ts +28 -14
- package/src/wirings/cli/cli.types.ts +14 -14
- package/src/wirings/cli/command-parser.test.ts +9 -9
- package/src/wirings/cli/command-parser.ts +1 -1
- package/src/wirings/cli/define-cli-commands.ts +24 -0
- package/src/wirings/cli/index.ts +10 -4
- package/src/wirings/http/http-routes.test.ts +322 -0
- package/src/wirings/http/http-routes.ts +198 -0
- package/src/wirings/http/http-runner.test.ts +12 -20
- package/src/wirings/http/http-runner.ts +101 -51
- package/src/wirings/http/http.types.ts +119 -48
- package/src/wirings/http/index.ts +16 -4
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-request.ts +1 -1
- package/src/wirings/http/pikku-fetch-http-response.ts +12 -5
- package/src/wirings/http/routers/http-router.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.ts +4 -3
- package/src/wirings/mcp/index.ts +27 -3
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
- package/src/wirings/mcp/mcp-endpoint-registry.ts +5 -1
- package/src/wirings/mcp/mcp-runner.ts +48 -65
- package/src/wirings/mcp/mcp.types.ts +5 -5
- package/src/wirings/node/index.ts +2 -0
- package/src/wirings/node/node.types.ts +23 -0
- package/src/wirings/oauth2/index.ts +3 -0
- package/src/wirings/oauth2/oauth2-client.test.ts +929 -0
- package/src/wirings/oauth2/oauth2-client.ts +335 -0
- package/src/wirings/oauth2/oauth2.types.ts +69 -0
- package/src/wirings/oauth2/wire-oauth2-credential.ts +23 -0
- package/src/wirings/queue/index.ts +13 -2
- package/src/wirings/queue/queue-runner.test.ts +142 -73
- package/src/wirings/queue/queue-runner.ts +18 -14
- package/src/wirings/queue/queue.types.ts +5 -5
- package/src/wirings/queue/register-queue-helper.ts +3 -5
- package/src/wirings/queue/validate-worker-config.test.ts +108 -0
- package/src/wirings/queue/validate-worker-config.ts +4 -1
- package/src/wirings/rpc/index.ts +3 -1
- package/src/wirings/rpc/rpc-runner.ts +254 -41
- package/src/wirings/rpc/rpc-types.ts +28 -4
- package/src/wirings/rpc/wire-addon.ts +20 -0
- package/src/wirings/scheduler/index.ts +6 -4
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +78 -45
- package/src/wirings/scheduler/scheduler-runner.ts +20 -27
- package/src/wirings/scheduler/scheduler.types.ts +2 -2
- package/src/wirings/secret/index.ts +9 -0
- package/src/wirings/secret/secret.types.ts +32 -0
- package/src/wirings/secret/validate-secret-definitions.test.ts +140 -0
- package/src/wirings/secret/validate-secret-definitions.ts +82 -0
- package/src/wirings/trigger/index.ts +10 -2
- package/src/wirings/trigger/pikku-trigger-service.ts +112 -0
- package/src/wirings/trigger/trigger-runner.test.ts +79 -0
- package/src/wirings/trigger/trigger-runner.ts +80 -41
- package/src/wirings/trigger/trigger.types.ts +144 -22
- package/src/wirings/variable/index.ts +8 -0
- package/src/wirings/variable/validate-variable-definitions.test.ts +91 -0
- package/src/wirings/variable/validate-variable-definitions.ts +69 -0
- package/src/wirings/variable/variable.types.ts +22 -0
- package/src/wirings/workflow/dsl/index.ts +1 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +9 -1
- package/src/wirings/workflow/dsl/workflow-runner.ts +4 -3
- package/src/wirings/workflow/graph/graph-node.ts +1 -6
- package/src/wirings/workflow/graph/graph-runner.test.ts +487 -0
- package/src/wirings/workflow/graph/graph-runner.ts +496 -374
- package/src/wirings/workflow/graph/index.ts +14 -3
- package/src/wirings/workflow/graph/template.test.ts +49 -0
- package/src/wirings/workflow/graph/template.ts +42 -0
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +29 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -22
- package/src/wirings/workflow/index.ts +21 -10
- package/src/wirings/workflow/pikku-workflow-service.test.ts +200 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +308 -105
- package/src/wirings/workflow/workflow-helpers.test.ts +129 -0
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow.types.ts +47 -92
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/forge-node/forge-node.types.d.ts +0 -120
- package/dist/wirings/forge-node/forge-node.types.js +0 -38
- package/dist/wirings/forge-node/index.d.ts +0 -1
- package/dist/wirings/forge-node/index.js +0 -1
- package/dist/wirings/workflow/wire-workflow.d.ts +0 -42
- package/dist/wirings/workflow/wire-workflow.js +0 -53
- package/dist/wirings/workflow/workflow-utils.d.ts +0 -23
- package/dist/wirings/workflow/workflow-utils.js +0 -66
- package/src/wirings/forge-node/forge-node.types.ts +0 -135
- package/src/wirings/forge-node/index.ts +0 -1
- package/src/wirings/workflow/wire-workflow.ts +0 -94
- package/src/wirings/workflow/workflow-utils.ts +0 -120
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { WorkflowWires } from './workflow.types.js';
|
|
2
|
-
import type { GraphNodeConfig } from './graph/workflow-graph.types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Workflow definition with DSL function
|
|
5
|
-
*/
|
|
6
|
-
export interface WorkflowDefinitionFunc {
|
|
7
|
-
wires: WorkflowWires;
|
|
8
|
-
func: {
|
|
9
|
-
func: (...args: any[]) => any;
|
|
10
|
-
} | ((...args: any[]) => any);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Workflow definition with graph
|
|
14
|
-
*/
|
|
15
|
-
export interface WorkflowDefinitionGraph<T extends Record<string, GraphNodeConfig<string>> = Record<string, GraphNodeConfig<string>>> {
|
|
16
|
-
wires: WorkflowWires;
|
|
17
|
-
graph: T;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Union type for workflow definitions
|
|
21
|
-
*/
|
|
22
|
-
export type WorkflowDefinition<T extends Record<string, GraphNodeConfig<string>> = Record<string, GraphNodeConfig<string>>> = WorkflowDefinitionFunc | WorkflowDefinitionGraph<T>;
|
|
23
|
-
/**
|
|
24
|
-
* Wire a workflow with triggers.
|
|
25
|
-
* Accepts either a DSL function (func) or a graph definition (graph).
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* // DSL workflow
|
|
30
|
-
* wireWorkflow({
|
|
31
|
-
* wires: { http: { route: '/start', method: 'post' } },
|
|
32
|
-
* func: myWorkflowFunc,
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* // Graph workflow
|
|
36
|
-
* wireWorkflow({
|
|
37
|
-
* wires: { http: { route: '/graph-start', method: 'post' } },
|
|
38
|
-
* graph: myGraphWorkflow,
|
|
39
|
-
* })
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function wireWorkflow<T extends Record<string, GraphNodeConfig<string>>>(definition: WorkflowDefinitionFunc | WorkflowDefinitionGraph<T>): void;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { pikkuState } from '../../pikku-state.js';
|
|
2
|
-
/**
|
|
3
|
-
* Type guard for DSL workflow definition
|
|
4
|
-
*/
|
|
5
|
-
function isWorkflowDefinitionFunc(def) {
|
|
6
|
-
return 'func' in def;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Type guard for graph workflow definition
|
|
10
|
-
*/
|
|
11
|
-
function isWorkflowDefinitionGraph(def) {
|
|
12
|
-
return 'graph' in def;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Wire a workflow with triggers.
|
|
16
|
-
* Accepts either a DSL function (func) or a graph definition (graph).
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // DSL workflow
|
|
21
|
-
* wireWorkflow({
|
|
22
|
-
* wires: { http: { route: '/start', method: 'post' } },
|
|
23
|
-
* func: myWorkflowFunc,
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* // Graph workflow
|
|
27
|
-
* wireWorkflow({
|
|
28
|
-
* wires: { http: { route: '/graph-start', method: 'post' } },
|
|
29
|
-
* graph: myGraphWorkflow,
|
|
30
|
-
* })
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export function wireWorkflow(definition) {
|
|
34
|
-
if (isWorkflowDefinitionFunc(definition)) {
|
|
35
|
-
// DSL workflow - store wiring for later registration by inspector
|
|
36
|
-
const wirings = pikkuState(null, 'workflows', 'wirings');
|
|
37
|
-
// The wiring will be matched to the function by the inspector
|
|
38
|
-
// Store the func reference and wires
|
|
39
|
-
wirings.set(definition.func, {
|
|
40
|
-
wires: definition.wires,
|
|
41
|
-
func: definition.func,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else if (isWorkflowDefinitionGraph(definition)) {
|
|
45
|
-
// Graph workflow - store for registration
|
|
46
|
-
const graphWirings = pikkuState(null, 'workflows', 'graphWirings');
|
|
47
|
-
// Store the graph reference and wires
|
|
48
|
-
graphWirings.set(definition.graph, {
|
|
49
|
-
wires: definition.wires,
|
|
50
|
-
graph: definition.graph,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { PikkuWire, CreateWireServices, CoreSingletonServices, CoreServices, CoreUserSession } from '../../types/core.types.js';
|
|
2
|
-
import { HTTPWiringMeta } from '../http/http.types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Result of finding a workflow by HTTP wire
|
|
5
|
-
*/
|
|
6
|
-
export interface WorkflowHttpMatch {
|
|
7
|
-
workflowName: string;
|
|
8
|
-
startNode?: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Find workflow name by matching route and method against workflow wires
|
|
12
|
-
*/
|
|
13
|
-
export declare const findWorkflowByHttpWire: (route: string, method: string) => WorkflowHttpMatch | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Start a workflow triggered by an HTTP wire
|
|
16
|
-
* The workflow is responsible for handling the HTTP response
|
|
17
|
-
*/
|
|
18
|
-
export declare const startWorkflowByHttpWire: (singletonServices: CoreSingletonServices, createWireServices: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession> | undefined, matchedRoute: {
|
|
19
|
-
matchedPath: any;
|
|
20
|
-
params: any;
|
|
21
|
-
route: any;
|
|
22
|
-
meta: HTTPWiringMeta;
|
|
23
|
-
}, wire: PikkuWire) => Promise<void>;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { pikkuState } from '../../pikku-state.js';
|
|
2
|
-
import { NotFoundError } from '../../errors/errors.js';
|
|
3
|
-
import { ContextAwareRPCService } from '../rpc/rpc-runner.js';
|
|
4
|
-
/**
|
|
5
|
-
* Find workflow name by matching route and method against workflow wires
|
|
6
|
-
*/
|
|
7
|
-
export const findWorkflowByHttpWire = (route, method) => {
|
|
8
|
-
const wirings = pikkuState(null, 'workflows', 'wirings');
|
|
9
|
-
const graphWirings = pikkuState(null, 'workflows', 'graphWirings');
|
|
10
|
-
// Check DSL workflow wirings
|
|
11
|
-
for (const [, wiring] of wirings) {
|
|
12
|
-
const httpWires = wiring.wires?.http;
|
|
13
|
-
if (httpWires) {
|
|
14
|
-
const matchedWire = httpWires.find((w) => w.route === route && w.method === method);
|
|
15
|
-
if (matchedWire) {
|
|
16
|
-
const meta = pikkuState(null, 'workflows', 'meta');
|
|
17
|
-
for (const [name, workflowMeta] of Object.entries(meta)) {
|
|
18
|
-
if (workflowMeta.source !== 'graph') {
|
|
19
|
-
const registrations = pikkuState(null, 'workflows', 'registrations');
|
|
20
|
-
if (registrations.has(name)) {
|
|
21
|
-
return { workflowName: name, startNode: matchedWire.startNode };
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// Check graph workflow wirings
|
|
29
|
-
for (const [, wiring] of graphWirings) {
|
|
30
|
-
const httpWires = wiring.wires?.http;
|
|
31
|
-
if (httpWires) {
|
|
32
|
-
const matchedWire = httpWires.find((w) => w.route === route && w.method === method);
|
|
33
|
-
if (matchedWire) {
|
|
34
|
-
const meta = pikkuState(null, 'workflows', 'meta');
|
|
35
|
-
for (const [name, workflowMeta] of Object.entries(meta)) {
|
|
36
|
-
if (workflowMeta.source === 'graph') {
|
|
37
|
-
return { workflowName: name, startNode: matchedWire.startNode };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Start a workflow triggered by an HTTP wire
|
|
47
|
-
* The workflow is responsible for handling the HTTP response
|
|
48
|
-
*/
|
|
49
|
-
export const startWorkflowByHttpWire = async (singletonServices, createWireServices, matchedRoute, wire) => {
|
|
50
|
-
const { meta } = matchedRoute;
|
|
51
|
-
const match = findWorkflowByHttpWire(meta.route, meta.method);
|
|
52
|
-
if (!match) {
|
|
53
|
-
throw new NotFoundError(`No workflow found for route ${meta.method.toUpperCase()} ${meta.route}`);
|
|
54
|
-
}
|
|
55
|
-
const workflowService = singletonServices.workflowService;
|
|
56
|
-
if (!workflowService) {
|
|
57
|
-
throw new Error('WorkflowService not available');
|
|
58
|
-
}
|
|
59
|
-
const data = await wire.http.request.data();
|
|
60
|
-
const wireServices = createWireServices?.(singletonServices, wire);
|
|
61
|
-
const rpcService = new ContextAwareRPCService({ ...singletonServices, ...wireServices }, wire, {});
|
|
62
|
-
await workflowService.startWorkflow(match.workflowName, data, rpcService, {
|
|
63
|
-
inline: true,
|
|
64
|
-
startNode: match.startNode,
|
|
65
|
-
});
|
|
66
|
-
};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Forge node types for workflow builder visualization.
|
|
3
|
-
* wireForgeNode is metadata-only - no runtime behavior.
|
|
4
|
-
* The CLI extracts this via AST and generates JSON metadata.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The type of forge node.
|
|
9
|
-
* - trigger: Starts workflows (webhooks, schedules, events)
|
|
10
|
-
* - action: Operations that do something (API calls, send email, database ops)
|
|
11
|
-
* - end: Terminal nodes with no outputs (logging, notifications)
|
|
12
|
-
*/
|
|
13
|
-
export type ForgeNodeType = 'trigger' | 'action' | 'end'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for wireForgeNode.
|
|
17
|
-
* This is the input type that developers use when defining nodes.
|
|
18
|
-
*/
|
|
19
|
-
export type CoreForgeNode = {
|
|
20
|
-
/** Unique identifier for this node */
|
|
21
|
-
name: string
|
|
22
|
-
/** Human-readable name for UI display */
|
|
23
|
-
displayName: string
|
|
24
|
-
/** Grouping category (validated against forge.node.categories in config) */
|
|
25
|
-
category: string
|
|
26
|
-
/** Node type determining behavior and outputs */
|
|
27
|
-
type: ForgeNodeType
|
|
28
|
-
/** RPC name to call when node executes (local name, Forge handles package aliasing) */
|
|
29
|
-
rpc: string
|
|
30
|
-
/** Optional description for UI */
|
|
31
|
-
description?: string
|
|
32
|
-
/** Whether to add an error output port alongside the default output */
|
|
33
|
-
errorOutput?: boolean
|
|
34
|
-
/** Optional tags for filtering/categorization */
|
|
35
|
-
tags?: string[]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Metadata generated for each forge node.
|
|
40
|
-
* This is the output type that the CLI generates.
|
|
41
|
-
*/
|
|
42
|
-
export type ForgeNodeMeta = {
|
|
43
|
-
name: string
|
|
44
|
-
displayName: string
|
|
45
|
-
category: string
|
|
46
|
-
type: ForgeNodeType
|
|
47
|
-
/** RPC name (local, remapped by Forge for external packages) */
|
|
48
|
-
rpc: string
|
|
49
|
-
description?: string
|
|
50
|
-
/** Whether node has error output port */
|
|
51
|
-
errorOutput: boolean
|
|
52
|
-
/** Input schema name extracted from RPC */
|
|
53
|
-
inputSchemaName: string | null
|
|
54
|
-
/** Output schema name extracted from RPC */
|
|
55
|
-
outputSchemaName: string | null
|
|
56
|
-
tags?: string[]
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Record of all forge node metadata, keyed by node name.
|
|
61
|
-
*/
|
|
62
|
-
export type ForgeNodesMeta = Record<string, ForgeNodeMeta>
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* No-op function for wireForgeNode.
|
|
66
|
-
* This exists purely for TypeScript type checking and will be tree-shaken.
|
|
67
|
-
* The CLI extracts metadata via AST parsing.
|
|
68
|
-
*/
|
|
69
|
-
export const wireForgeNode = (_config: CoreForgeNode): void => {
|
|
70
|
-
// No-op - metadata only, extracted by CLI via AST
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Configuration for wireForgeCredential.
|
|
75
|
-
* Declares credentials/secrets required by a Forge package.
|
|
76
|
-
* Uses Zod for schema definition - converted to JSON Schema at build time.
|
|
77
|
-
*/
|
|
78
|
-
export type CoreForgeCredential<T = unknown> = {
|
|
79
|
-
/** Unique identifier for this credential */
|
|
80
|
-
name: string
|
|
81
|
-
/** Human-readable name for UI display */
|
|
82
|
-
displayName: string
|
|
83
|
-
/** Optional description for UI */
|
|
84
|
-
description?: string
|
|
85
|
-
/** Key used with SecretService.getSecret() to retrieve the credential */
|
|
86
|
-
secretId: string
|
|
87
|
-
/** Zod schema defining the structure of the credential */
|
|
88
|
-
schema: T
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Metadata generated for each forge credential.
|
|
93
|
-
* Schema is converted from Zod to JSON Schema at build time.
|
|
94
|
-
*/
|
|
95
|
-
export type ForgeCredentialMeta = {
|
|
96
|
-
name: string
|
|
97
|
-
displayName: string
|
|
98
|
-
description?: string
|
|
99
|
-
secretId: string
|
|
100
|
-
/** JSON Schema (converted from Zod at build time) or zodLookup reference name */
|
|
101
|
-
schema: Record<string, unknown> | string
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Record of all forge credential metadata, keyed by credential name.
|
|
106
|
-
*/
|
|
107
|
-
export type ForgeCredentialsMeta = Record<string, ForgeCredentialMeta>
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* No-op function for wireForgeCredential.
|
|
111
|
-
* This exists purely for TypeScript type checking and will be tree-shaken.
|
|
112
|
-
* The CLI extracts metadata via AST parsing.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* import { z } from 'zod'
|
|
117
|
-
*
|
|
118
|
-
* const slackCredentials = z.object({
|
|
119
|
-
* botToken: z.string().describe('Bot OAuth token'),
|
|
120
|
-
* signingSecret: z.string().describe('Request signing secret')
|
|
121
|
-
* })
|
|
122
|
-
*
|
|
123
|
-
* wireForgeCredential({
|
|
124
|
-
* name: 'slack',
|
|
125
|
-
* displayName: 'Slack Credentials',
|
|
126
|
-
* secretId: 'SLACK_CREDENTIALS',
|
|
127
|
-
* schema: slackCredentials
|
|
128
|
-
* })
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export const wireForgeCredential = <T>(
|
|
132
|
-
_config: CoreForgeCredential<T>
|
|
133
|
-
): void => {
|
|
134
|
-
// No-op - metadata only, extracted by CLI via AST
|
|
135
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './forge-node.types.js'
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { pikkuState } from '../../pikku-state.js'
|
|
2
|
-
import type { WorkflowWires } from './workflow.types.js'
|
|
3
|
-
import type { GraphNodeConfig } from './graph/workflow-graph.types.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Workflow definition with DSL function
|
|
7
|
-
*/
|
|
8
|
-
export interface WorkflowDefinitionFunc {
|
|
9
|
-
wires: WorkflowWires
|
|
10
|
-
func: { func: (...args: any[]) => any } | ((...args: any[]) => any)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Workflow definition with graph
|
|
15
|
-
*/
|
|
16
|
-
export interface WorkflowDefinitionGraph<
|
|
17
|
-
T extends Record<string, GraphNodeConfig<string>> = Record<
|
|
18
|
-
string,
|
|
19
|
-
GraphNodeConfig<string>
|
|
20
|
-
>,
|
|
21
|
-
> {
|
|
22
|
-
wires: WorkflowWires
|
|
23
|
-
graph: T
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Union type for workflow definitions
|
|
28
|
-
*/
|
|
29
|
-
export type WorkflowDefinition<
|
|
30
|
-
T extends Record<string, GraphNodeConfig<string>> = Record<
|
|
31
|
-
string,
|
|
32
|
-
GraphNodeConfig<string>
|
|
33
|
-
>,
|
|
34
|
-
> = WorkflowDefinitionFunc | WorkflowDefinitionGraph<T>
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Type guard for DSL workflow definition
|
|
38
|
-
*/
|
|
39
|
-
function isWorkflowDefinitionFunc(
|
|
40
|
-
def: WorkflowDefinition
|
|
41
|
-
): def is WorkflowDefinitionFunc {
|
|
42
|
-
return 'func' in def
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Type guard for graph workflow definition
|
|
47
|
-
*/
|
|
48
|
-
function isWorkflowDefinitionGraph(
|
|
49
|
-
def: WorkflowDefinition
|
|
50
|
-
): def is WorkflowDefinitionGraph {
|
|
51
|
-
return 'graph' in def
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Wire a workflow with triggers.
|
|
56
|
-
* Accepts either a DSL function (func) or a graph definition (graph).
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* // DSL workflow
|
|
61
|
-
* wireWorkflow({
|
|
62
|
-
* wires: { http: { route: '/start', method: 'post' } },
|
|
63
|
-
* func: myWorkflowFunc,
|
|
64
|
-
* })
|
|
65
|
-
*
|
|
66
|
-
* // Graph workflow
|
|
67
|
-
* wireWorkflow({
|
|
68
|
-
* wires: { http: { route: '/graph-start', method: 'post' } },
|
|
69
|
-
* graph: myGraphWorkflow,
|
|
70
|
-
* })
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export function wireWorkflow<T extends Record<string, GraphNodeConfig<string>>>(
|
|
74
|
-
definition: WorkflowDefinitionFunc | WorkflowDefinitionGraph<T>
|
|
75
|
-
): void {
|
|
76
|
-
if (isWorkflowDefinitionFunc(definition)) {
|
|
77
|
-
// DSL workflow - store wiring for later registration by inspector
|
|
78
|
-
const wirings = pikkuState(null, 'workflows', 'wirings')
|
|
79
|
-
// The wiring will be matched to the function by the inspector
|
|
80
|
-
// Store the func reference and wires
|
|
81
|
-
wirings.set(definition.func, {
|
|
82
|
-
wires: definition.wires,
|
|
83
|
-
func: definition.func,
|
|
84
|
-
})
|
|
85
|
-
} else if (isWorkflowDefinitionGraph(definition)) {
|
|
86
|
-
// Graph workflow - store for registration
|
|
87
|
-
const graphWirings = pikkuState(null, 'workflows', 'graphWirings')
|
|
88
|
-
// Store the graph reference and wires
|
|
89
|
-
graphWirings.set(definition.graph, {
|
|
90
|
-
wires: definition.wires,
|
|
91
|
-
graph: definition.graph,
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { pikkuState } from '../../pikku-state.js'
|
|
2
|
-
import { NotFoundError } from '../../errors/errors.js'
|
|
3
|
-
import {
|
|
4
|
-
PikkuWire,
|
|
5
|
-
CreateWireServices,
|
|
6
|
-
CoreSingletonServices,
|
|
7
|
-
CoreServices,
|
|
8
|
-
CoreUserSession,
|
|
9
|
-
} from '../../types/core.types.js'
|
|
10
|
-
import { HTTPWiringMeta } from '../http/http.types.js'
|
|
11
|
-
import { ContextAwareRPCService } from '../rpc/rpc-runner.js'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Result of finding a workflow by HTTP wire
|
|
15
|
-
*/
|
|
16
|
-
export interface WorkflowHttpMatch {
|
|
17
|
-
workflowName: string
|
|
18
|
-
startNode?: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Find workflow name by matching route and method against workflow wires
|
|
23
|
-
*/
|
|
24
|
-
export const findWorkflowByHttpWire = (
|
|
25
|
-
route: string,
|
|
26
|
-
method: string
|
|
27
|
-
): WorkflowHttpMatch | undefined => {
|
|
28
|
-
const wirings = pikkuState(null, 'workflows', 'wirings')
|
|
29
|
-
const graphWirings = pikkuState(null, 'workflows', 'graphWirings')
|
|
30
|
-
|
|
31
|
-
// Check DSL workflow wirings
|
|
32
|
-
for (const [, wiring] of wirings) {
|
|
33
|
-
const httpWires = wiring.wires?.http
|
|
34
|
-
if (httpWires) {
|
|
35
|
-
const matchedWire = httpWires.find(
|
|
36
|
-
(w) => w.route === route && w.method === method
|
|
37
|
-
)
|
|
38
|
-
if (matchedWire) {
|
|
39
|
-
const meta = pikkuState(null, 'workflows', 'meta')
|
|
40
|
-
for (const [name, workflowMeta] of Object.entries(meta)) {
|
|
41
|
-
if (workflowMeta.source !== 'graph') {
|
|
42
|
-
const registrations = pikkuState(null, 'workflows', 'registrations')
|
|
43
|
-
if (registrations.has(name)) {
|
|
44
|
-
return { workflowName: name, startNode: matchedWire.startNode }
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Check graph workflow wirings
|
|
53
|
-
for (const [, wiring] of graphWirings) {
|
|
54
|
-
const httpWires = wiring.wires?.http
|
|
55
|
-
if (httpWires) {
|
|
56
|
-
const matchedWire = httpWires.find(
|
|
57
|
-
(w) => w.route === route && w.method === method
|
|
58
|
-
)
|
|
59
|
-
if (matchedWire) {
|
|
60
|
-
const meta = pikkuState(null, 'workflows', 'meta')
|
|
61
|
-
for (const [name, workflowMeta] of Object.entries(meta)) {
|
|
62
|
-
if (workflowMeta.source === 'graph') {
|
|
63
|
-
return { workflowName: name, startNode: matchedWire.startNode }
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return undefined
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Start a workflow triggered by an HTTP wire
|
|
75
|
-
* The workflow is responsible for handling the HTTP response
|
|
76
|
-
*/
|
|
77
|
-
export const startWorkflowByHttpWire = async (
|
|
78
|
-
singletonServices: CoreSingletonServices,
|
|
79
|
-
createWireServices:
|
|
80
|
-
| CreateWireServices<
|
|
81
|
-
CoreSingletonServices,
|
|
82
|
-
CoreServices<CoreSingletonServices>,
|
|
83
|
-
CoreUserSession
|
|
84
|
-
>
|
|
85
|
-
| undefined,
|
|
86
|
-
matchedRoute: {
|
|
87
|
-
matchedPath: any
|
|
88
|
-
params: any
|
|
89
|
-
route: any
|
|
90
|
-
meta: HTTPWiringMeta
|
|
91
|
-
},
|
|
92
|
-
wire: PikkuWire
|
|
93
|
-
): Promise<void> => {
|
|
94
|
-
const { meta } = matchedRoute
|
|
95
|
-
|
|
96
|
-
const match = findWorkflowByHttpWire(meta.route, meta.method)
|
|
97
|
-
if (!match) {
|
|
98
|
-
throw new NotFoundError(
|
|
99
|
-
`No workflow found for route ${meta.method.toUpperCase()} ${meta.route}`
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const workflowService = singletonServices.workflowService
|
|
104
|
-
if (!workflowService) {
|
|
105
|
-
throw new Error('WorkflowService not available')
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const data = await wire.http!.request!.data()
|
|
109
|
-
|
|
110
|
-
const wireServices = createWireServices?.(singletonServices, wire)
|
|
111
|
-
const rpcService = new ContextAwareRPCService(
|
|
112
|
-
{ ...singletonServices, ...wireServices },
|
|
113
|
-
wire,
|
|
114
|
-
{}
|
|
115
|
-
)
|
|
116
|
-
await workflowService.startWorkflow(match.workflowName, data, rpcService, {
|
|
117
|
-
inline: true,
|
|
118
|
-
startNode: match.startNode,
|
|
119
|
-
})
|
|
120
|
-
}
|