@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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORS middleware that handles cross-origin requests including OPTIONS preflight.
|
|
3
|
+
*
|
|
4
|
+
* Sets appropriate CORS headers on all responses and short-circuits OPTIONS
|
|
5
|
+
* preflight requests with a 204 No Content response.
|
|
6
|
+
*
|
|
7
|
+
* @param options.origin - Allowed origin(s). Use `'*'` for any origin, `true` to reflect the request origin, a string for a single origin, or an array for multiple origins. Defaults to `'*'`.
|
|
8
|
+
* @param options.methods - Allowed HTTP methods. Defaults to common methods.
|
|
9
|
+
* @param options.headers - Allowed request headers. Defaults to common headers.
|
|
10
|
+
* @param options.credentials - Whether to allow credentials. Defaults to `false`.
|
|
11
|
+
* @param options.maxAge - Preflight cache duration in seconds. Defaults to `86400` (24 hours).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { cors } from '@pikku/core/middleware'
|
|
16
|
+
*
|
|
17
|
+
* // Allow all origins
|
|
18
|
+
* addHTTPMiddleware('*', [cors()])
|
|
19
|
+
*
|
|
20
|
+
* // Specific origin with credentials
|
|
21
|
+
* addHTTPMiddleware('*', [
|
|
22
|
+
* cors({
|
|
23
|
+
* origin: 'https://app.example.com',
|
|
24
|
+
* credentials: true,
|
|
25
|
+
* })
|
|
26
|
+
* ])
|
|
27
|
+
*
|
|
28
|
+
* // Multiple origins
|
|
29
|
+
* addHTTPMiddleware('*', [
|
|
30
|
+
* cors({
|
|
31
|
+
* origin: ['https://app.example.com', 'https://admin.example.com'],
|
|
32
|
+
* })
|
|
33
|
+
* ])
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const cors: import("../types/core.types.js").CorePikkuMiddlewareFactory<{
|
|
37
|
+
origin?: string | string[] | true;
|
|
38
|
+
methods?: string[];
|
|
39
|
+
headers?: string[];
|
|
40
|
+
credentials?: boolean;
|
|
41
|
+
maxAge?: number;
|
|
42
|
+
}, import("../types/core.types.js").CoreSingletonServices<{
|
|
43
|
+
logLevel?: import("../services/logger.js").LogLevel;
|
|
44
|
+
secrets?: {};
|
|
45
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
46
|
+
}>, import("../types/core.types.js").CoreUserSession>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { pikkuMiddleware, pikkuMiddlewareFactory } from '../types/core.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* CORS middleware that handles cross-origin requests including OPTIONS preflight.
|
|
4
|
+
*
|
|
5
|
+
* Sets appropriate CORS headers on all responses and short-circuits OPTIONS
|
|
6
|
+
* preflight requests with a 204 No Content response.
|
|
7
|
+
*
|
|
8
|
+
* @param options.origin - Allowed origin(s). Use `'*'` for any origin, `true` to reflect the request origin, a string for a single origin, or an array for multiple origins. Defaults to `'*'`.
|
|
9
|
+
* @param options.methods - Allowed HTTP methods. Defaults to common methods.
|
|
10
|
+
* @param options.headers - Allowed request headers. Defaults to common headers.
|
|
11
|
+
* @param options.credentials - Whether to allow credentials. Defaults to `false`.
|
|
12
|
+
* @param options.maxAge - Preflight cache duration in seconds. Defaults to `86400` (24 hours).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { cors } from '@pikku/core/middleware'
|
|
17
|
+
*
|
|
18
|
+
* // Allow all origins
|
|
19
|
+
* addHTTPMiddleware('*', [cors()])
|
|
20
|
+
*
|
|
21
|
+
* // Specific origin with credentials
|
|
22
|
+
* addHTTPMiddleware('*', [
|
|
23
|
+
* cors({
|
|
24
|
+
* origin: 'https://app.example.com',
|
|
25
|
+
* credentials: true,
|
|
26
|
+
* })
|
|
27
|
+
* ])
|
|
28
|
+
*
|
|
29
|
+
* // Multiple origins
|
|
30
|
+
* addHTTPMiddleware('*', [
|
|
31
|
+
* cors({
|
|
32
|
+
* origin: ['https://app.example.com', 'https://admin.example.com'],
|
|
33
|
+
* })
|
|
34
|
+
* ])
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export const cors = pikkuMiddlewareFactory(({ origin = '*', methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], headers = ['Content-Type', 'Authorization', 'x-api-key'], credentials = false, maxAge = 86400, } = {}) => {
|
|
38
|
+
if (origin === '*' && credentials) {
|
|
39
|
+
throw new Error('CORS misconfiguration: wildcard origin (*) cannot be used with credentials: true');
|
|
40
|
+
}
|
|
41
|
+
return pikkuMiddleware({
|
|
42
|
+
name: 'CORS',
|
|
43
|
+
description: 'Handles cross-origin requests including OPTIONS preflight',
|
|
44
|
+
func: async (_services, wires, next) => {
|
|
45
|
+
const request = wires.http?.request;
|
|
46
|
+
const response = wires.http?.response;
|
|
47
|
+
if (!request || !response) {
|
|
48
|
+
return next();
|
|
49
|
+
}
|
|
50
|
+
const requestOrigin = request.header('origin');
|
|
51
|
+
let allowedOrigin;
|
|
52
|
+
if (origin === true) {
|
|
53
|
+
allowedOrigin = requestOrigin || '*';
|
|
54
|
+
}
|
|
55
|
+
else if (Array.isArray(origin)) {
|
|
56
|
+
allowedOrigin =
|
|
57
|
+
requestOrigin && origin.includes(requestOrigin)
|
|
58
|
+
? requestOrigin
|
|
59
|
+
: origin[0];
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
allowedOrigin = origin;
|
|
63
|
+
}
|
|
64
|
+
response.header('Access-Control-Allow-Origin', allowedOrigin);
|
|
65
|
+
response.header('Access-Control-Allow-Methods', methods.join(', '));
|
|
66
|
+
response.header('Access-Control-Allow-Headers', headers.join(', '));
|
|
67
|
+
if (credentials) {
|
|
68
|
+
response.header('Access-Control-Allow-Credentials', 'true');
|
|
69
|
+
}
|
|
70
|
+
if (origin === true || Array.isArray(origin)) {
|
|
71
|
+
response.header('Vary', 'Origin');
|
|
72
|
+
}
|
|
73
|
+
if (request.method() === 'options') {
|
|
74
|
+
response.header('Access-Control-Max-Age', String(maxAge));
|
|
75
|
+
response.status(204).json(undefined);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return next();
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { authAPIKey } from './auth-apikey.js';
|
|
2
|
+
export { authCookie } from './auth-cookie.js';
|
|
3
|
+
export { authBearer } from './auth-bearer.js';
|
|
4
|
+
export { pikkuRemoteAuthMiddleware } from './remote-auth.js';
|
|
5
|
+
export { cors } from './cors.js';
|
package/dist/middleware/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { authAPIKey } from './auth-apikey.js';
|
|
2
|
+
export { authCookie } from './auth-cookie.js';
|
|
3
|
+
export { authBearer } from './auth-bearer.js';
|
|
4
|
+
export { pikkuRemoteAuthMiddleware } from './remote-auth.js';
|
|
5
|
+
export { cors } from './cors.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const pikkuRemoteAuthMiddleware: import("../types/core.types.js").CorePikkuMiddleware<import("../types/core.types.js").CoreSingletonServices<{
|
|
2
|
+
logLevel?: import("../services/logger.js").LogLevel;
|
|
3
|
+
secrets?: {};
|
|
4
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
5
|
+
}>, import("../types/core.types.js").CoreUserSession>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { UnauthorizedError } from '../errors/errors.js';
|
|
2
|
+
import { pikkuMiddleware } from '../types/core.types.js';
|
|
3
|
+
import { decryptJSON } from '../crypto-utils.js';
|
|
4
|
+
export const pikkuRemoteAuthMiddleware = pikkuMiddleware(async ({ secrets, jwt }, { http, setSession }, next) => {
|
|
5
|
+
if (!http?.request || !secrets) {
|
|
6
|
+
return next();
|
|
7
|
+
}
|
|
8
|
+
let secret;
|
|
9
|
+
try {
|
|
10
|
+
secret = await secrets.getSecret('PIKKU_REMOTE_SECRET');
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return next();
|
|
14
|
+
}
|
|
15
|
+
if (!jwt) {
|
|
16
|
+
throw new Error('PIKKU_REMOTE_SECRET set but JWT service missing');
|
|
17
|
+
}
|
|
18
|
+
const authHeader = http.request.header('authorization') ||
|
|
19
|
+
http.request.header('Authorization');
|
|
20
|
+
if (!authHeader) {
|
|
21
|
+
throw new UnauthorizedError();
|
|
22
|
+
}
|
|
23
|
+
const [scheme, token] = authHeader.split(' ');
|
|
24
|
+
if (scheme !== 'Bearer' || !token) {
|
|
25
|
+
throw new UnauthorizedError();
|
|
26
|
+
}
|
|
27
|
+
let payload;
|
|
28
|
+
try {
|
|
29
|
+
payload = await jwt.decode(token);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new UnauthorizedError();
|
|
33
|
+
}
|
|
34
|
+
if (payload?.aud !== 'pikku-remote') {
|
|
35
|
+
throw new UnauthorizedError();
|
|
36
|
+
}
|
|
37
|
+
if (payload?.fn && http.request.path().startsWith('/rpc/')) {
|
|
38
|
+
const fn = decodeURIComponent(http.request.path().slice('/rpc/'.length));
|
|
39
|
+
if (fn && payload.fn !== fn) {
|
|
40
|
+
throw new UnauthorizedError();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (payload?.session) {
|
|
44
|
+
try {
|
|
45
|
+
const decrypted = await decryptJSON(secret, payload.session);
|
|
46
|
+
if (decrypted?.session && setSession) {
|
|
47
|
+
await setSession(decrypted.session);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new UnauthorizedError();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return next();
|
|
55
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const timeout: () => import("../types/core.types.js").CorePikkuMiddlewareFactory<{
|
|
2
2
|
timeout: number;
|
|
3
3
|
}, import("../types/core.types.js").CoreSingletonServices<{
|
|
4
|
-
logLevel?: import("../
|
|
4
|
+
logLevel?: import("../services/logger.js").LogLevel;
|
|
5
5
|
secrets?: {};
|
|
6
|
-
workflow?: import("../
|
|
6
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
7
7
|
}>, import("../types/core.types.js").CoreUserSession>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoreSingletonServices, PikkuWire, CorePikkuMiddleware, CorePikkuMiddlewareGroup, PikkuWiringTypes, MiddlewareMetadata } from './types/core.types.js';
|
|
1
|
+
import type { CoreSingletonServices, PikkuWire, CorePikkuMiddleware, CorePikkuMiddlewareGroup, PikkuWiringTypes, MiddlewareMetadata } from './types/core.types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Runs a chain of middleware functions in sequence before executing the main function.
|
|
4
4
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { pikkuState } from './pikku-state.js';
|
|
2
|
-
import { freezeDedupe } from './utils.js';
|
|
2
|
+
import { freezeDedupe, getTagGroups } from './utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* Runs a chain of middleware functions in sequence before executing the main function.
|
|
5
5
|
*
|
|
@@ -75,7 +75,7 @@ export const addMiddleware = (tag, middleware, packageName = null) => {
|
|
|
75
75
|
* This function looks up middleware that was registered with registerMiddleware.
|
|
76
76
|
* It's used internally by the framework to resolve middleware references in metadata.
|
|
77
77
|
*
|
|
78
|
-
* @param {string} name - The unique name (
|
|
78
|
+
* @param {string} name - The unique name (pikkuFuncId) of the middleware function.
|
|
79
79
|
* @returns {CorePikkuMiddleware | undefined} The middleware function, or undefined if not found.
|
|
80
80
|
*
|
|
81
81
|
* @internal
|
|
@@ -91,7 +91,9 @@ const middlewareCache = {
|
|
|
91
91
|
channel: {},
|
|
92
92
|
queue: {},
|
|
93
93
|
scheduler: {},
|
|
94
|
+
trigger: {},
|
|
94
95
|
mcp: {},
|
|
96
|
+
agent: {},
|
|
95
97
|
cli: {},
|
|
96
98
|
workflow: {},
|
|
97
99
|
};
|
|
@@ -134,10 +136,8 @@ export const combineMiddleware = (wireType, uid, { wireInheritedMiddleware, wire
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
else if (meta.type === 'tag') {
|
|
137
|
-
|
|
138
|
-
const group
|
|
139
|
-
if (group) {
|
|
140
|
-
// At runtime, all factories should be resolved to middleware
|
|
139
|
+
const groups = getTagGroups(pikkuState(packageName, 'middleware', 'tagGroup'), meta.tag);
|
|
140
|
+
for (const group of groups) {
|
|
141
141
|
resolved.push(...group);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -158,10 +158,8 @@ export const combineMiddleware = (wireType, uid, { wireInheritedMiddleware, wire
|
|
|
158
158
|
if (funcInheritedMiddleware) {
|
|
159
159
|
for (const meta of funcInheritedMiddleware) {
|
|
160
160
|
if (meta.type === 'tag') {
|
|
161
|
-
|
|
162
|
-
const group
|
|
163
|
-
if (group) {
|
|
164
|
-
// At runtime, all factories should be resolved to middleware
|
|
161
|
+
const groups = getTagGroups(pikkuState(packageName, 'middleware', 'tagGroup'), meta.tag);
|
|
162
|
+
for (const group of groups) {
|
|
165
163
|
resolved.push(...group);
|
|
166
164
|
}
|
|
167
165
|
}
|
package/dist/permissions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CoreServices, PikkuWiringTypes, PermissionMetadata, PikkuWire } from './types/core.types.js';
|
|
2
|
-
import { CorePermissionGroup, CorePikkuPermission } from './function/functions.types.js';
|
|
1
|
+
import type { CoreServices, PikkuWiringTypes, PermissionMetadata, PikkuWire } from './types/core.types.js';
|
|
2
|
+
import type { CorePermissionGroup, CorePikkuPermission } from './function/functions.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Adds global permissions for a specific tag.
|
|
5
5
|
*
|
package/dist/permissions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pikkuState } from './pikku-state.js';
|
|
2
2
|
import { ForbiddenError } from './errors/errors.js';
|
|
3
|
-
import { freezeDedupe } from './utils.js';
|
|
3
|
+
import { freezeDedupe, getTagGroups } from './utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* This function validates permissions by iterating over permission groups and executing the corresponding permission functions. If all functions in at least one group return true, the permission is considered valid.
|
|
6
6
|
* @param services - The core services required for permission validation.
|
|
@@ -39,7 +39,7 @@ const verifyPermissions = async (permissions, services, data, wire) => {
|
|
|
39
39
|
* This function looks up permissions that was registered with registerPermission.
|
|
40
40
|
* It's used internally by the framework to resolve permission references in metadata.
|
|
41
41
|
*
|
|
42
|
-
* @param {string} name - The unique name (
|
|
42
|
+
* @param {string} name - The unique name (pikkuFuncId) of the permission function.
|
|
43
43
|
* @returns {CorePikkuPermission | undefined} The permission function, or undefined if not found.
|
|
44
44
|
*
|
|
45
45
|
* @internal
|
|
@@ -94,7 +94,9 @@ const combinedPermissionsCache = {
|
|
|
94
94
|
channel: {},
|
|
95
95
|
queue: {},
|
|
96
96
|
scheduler: {},
|
|
97
|
+
trigger: {},
|
|
97
98
|
mcp: {},
|
|
99
|
+
agent: {},
|
|
98
100
|
cli: {},
|
|
99
101
|
workflow: {},
|
|
100
102
|
};
|
|
@@ -143,9 +145,8 @@ const combinePermissions = (wireType, uid, { wireInheritedPermissions, wirePermi
|
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
else if (meta.type === 'tag') {
|
|
146
|
-
|
|
147
|
-
const group
|
|
148
|
-
if (group) {
|
|
148
|
+
const groups = getTagGroups(pikkuState(packageName, 'permissions', 'tagGroup'), meta.tag);
|
|
149
|
+
for (const group of groups) {
|
|
149
150
|
if (Array.isArray(group)) {
|
|
150
151
|
resolved.push(...group);
|
|
151
152
|
}
|
|
@@ -176,9 +177,8 @@ const combinePermissions = (wireType, uid, { wireInheritedPermissions, wirePermi
|
|
|
176
177
|
if (funcInheritedPermissions) {
|
|
177
178
|
for (const meta of funcInheritedPermissions) {
|
|
178
179
|
if (meta.type === 'tag') {
|
|
179
|
-
|
|
180
|
-
const group
|
|
181
|
-
if (group) {
|
|
180
|
+
const groups = getTagGroups(pikkuState(packageName, 'permissions', 'tagGroup'), meta.tag);
|
|
181
|
+
for (const group of groups) {
|
|
182
182
|
if (Array.isArray(group)) {
|
|
183
183
|
resolved.push(...group);
|
|
184
184
|
}
|
|
@@ -218,17 +218,13 @@ export const runPermissions = async (wireType, uid, { wireInheritedPermissions,
|
|
|
218
218
|
});
|
|
219
219
|
// Check all combined permissions - at least one must pass if any exist
|
|
220
220
|
if (allPermissions.length > 0) {
|
|
221
|
-
let permissioned = false;
|
|
222
221
|
for (const permission of allPermissions) {
|
|
223
222
|
const result = await verifyPermissions(typeof permission === 'function' ? { permission } : permission, services, data, wire);
|
|
224
223
|
if (result) {
|
|
225
|
-
|
|
226
|
-
// Continue executing all permissions (don't break early)
|
|
224
|
+
return;
|
|
227
225
|
}
|
|
228
226
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
throw new ForbiddenError('Permission denied');
|
|
232
|
-
}
|
|
227
|
+
services.logger.debug('Permission denied - combined permissions');
|
|
228
|
+
throw new ForbiddenError('Permission denied');
|
|
233
229
|
}
|
|
234
230
|
};
|
package/dist/pikku-state.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { PikkuPackageState } from './index.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
import type { PikkuPackageState } from './index.js';
|
|
2
|
+
import type { CoreSingletonServices, CreateWireServices } from './types/core.types.js';
|
|
3
|
+
export declare const getAllPackageStates: () => Map<string, PikkuPackageState>;
|
|
5
4
|
/**
|
|
6
5
|
* Get or set package-scoped pikku state
|
|
7
6
|
*
|
|
8
|
-
* @param packageName - Package name (null for main package, '@scope/package' for
|
|
7
|
+
* @param packageName - Package name (null for main package, '@scope/package' for addon packages)
|
|
9
8
|
* @param type - State category (function, rpc, http, etc.)
|
|
10
9
|
* @param content - Content key within the category
|
|
11
10
|
* @param value - Optional value to set
|
|
@@ -15,7 +14,7 @@ declare global {
|
|
|
15
14
|
* // Main package
|
|
16
15
|
* pikkuState(null, 'function', 'functions').get(funcName)
|
|
17
16
|
*
|
|
18
|
-
* //
|
|
17
|
+
* // Addon package
|
|
19
18
|
* pikkuState('@acme/stripe-functions', 'rpc', 'meta')
|
|
20
19
|
*/
|
|
21
20
|
export declare const pikkuState: <Type extends keyof PikkuPackageState, Content extends keyof PikkuPackageState[Type]>(packageName: string | null, type: Type, content: Content, value?: PikkuPackageState[Type][Content]) => PikkuPackageState[Type][Content];
|
|
@@ -24,11 +23,14 @@ export declare const pikkuState: <Type extends keyof PikkuPackageState, Content
|
|
|
24
23
|
*/
|
|
25
24
|
export declare const initializePikkuState: (packageName: string) => void;
|
|
26
25
|
export declare const resetPikkuState: () => void;
|
|
26
|
+
export declare const getPikkuMetaDir: (packageName?: string | null) => string | null;
|
|
27
|
+
export declare const getSingletonServices: () => CoreSingletonServices;
|
|
28
|
+
export declare const getCreateWireServices: () => CreateWireServices | undefined;
|
|
27
29
|
/**
|
|
28
|
-
* Register service factories for an
|
|
30
|
+
* Register service factories for an addon package.
|
|
29
31
|
* These factories are used to create services when the package's functions are invoked.
|
|
30
32
|
*
|
|
31
|
-
* @param packageName - The package name (e.g., '@pikku/templates-function-
|
|
33
|
+
* @param packageName - The package name (e.g., '@pikku/templates-function-addon')
|
|
32
34
|
* @param factories - The service factory functions
|
|
33
35
|
*/
|
|
34
36
|
export declare const addPackageServiceFactories: (packageName: string, factories: NonNullable<PikkuPackageState["package"]["factories"]>) => void;
|
package/dist/pikku-state.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
const PIKKU_STATE_KEY = Symbol.for('@pikku/core/state');
|
|
2
|
+
export const getAllPackageStates = () => {
|
|
3
|
+
if (!globalThis[PIKKU_STATE_KEY]) {
|
|
4
|
+
;
|
|
5
|
+
globalThis[PIKKU_STATE_KEY] = new Map();
|
|
6
|
+
}
|
|
7
|
+
return globalThis[PIKKU_STATE_KEY];
|
|
8
|
+
};
|
|
1
9
|
/**
|
|
2
10
|
* Get or set package-scoped pikku state
|
|
3
11
|
*
|
|
4
|
-
* @param packageName - Package name (null for main package, '@scope/package' for
|
|
12
|
+
* @param packageName - Package name (null for main package, '@scope/package' for addon packages)
|
|
5
13
|
* @param type - State category (function, rpc, http, etc.)
|
|
6
14
|
* @param content - Content key within the category
|
|
7
15
|
* @param value - Optional value to set
|
|
@@ -11,17 +19,16 @@
|
|
|
11
19
|
* // Main package
|
|
12
20
|
* pikkuState(null, 'function', 'functions').get(funcName)
|
|
13
21
|
*
|
|
14
|
-
* //
|
|
22
|
+
* // Addon package
|
|
15
23
|
* pikkuState('@acme/stripe-functions', 'rpc', 'meta')
|
|
16
24
|
*/
|
|
17
25
|
export const pikkuState = (packageName, type, content, value) => {
|
|
18
26
|
const resolvedPackageName = packageName ?? '__main__';
|
|
19
27
|
// Initialize package state if it doesn't exist
|
|
20
|
-
if (!
|
|
21
|
-
!globalThis.pikkuState.has(resolvedPackageName)) {
|
|
28
|
+
if (!getAllPackageStates().has(resolvedPackageName)) {
|
|
22
29
|
initializePikkuState(resolvedPackageName);
|
|
23
30
|
}
|
|
24
|
-
const packageState =
|
|
31
|
+
const packageState = getAllPackageStates().get(resolvedPackageName);
|
|
25
32
|
if (value !== undefined) {
|
|
26
33
|
packageState[type][content] = value;
|
|
27
34
|
}
|
|
@@ -35,7 +42,7 @@ const createEmptyPackageState = () => ({
|
|
|
35
42
|
rpc: {
|
|
36
43
|
meta: {},
|
|
37
44
|
files: new Map(),
|
|
38
|
-
|
|
45
|
+
addons: new Map(),
|
|
39
46
|
},
|
|
40
47
|
http: {
|
|
41
48
|
middleware: new Map(),
|
|
@@ -65,23 +72,26 @@ const createEmptyPackageState = () => ({
|
|
|
65
72
|
},
|
|
66
73
|
workflows: {
|
|
67
74
|
registrations: new Map(),
|
|
68
|
-
graphRegistrations: new Map(),
|
|
69
|
-
wirings: new Map(),
|
|
70
|
-
graphWirings: new Map(),
|
|
71
75
|
meta: {},
|
|
72
76
|
},
|
|
73
77
|
trigger: {
|
|
78
|
+
functions: new Map(),
|
|
74
79
|
triggers: new Map(),
|
|
80
|
+
triggerSources: new Map(),
|
|
75
81
|
meta: {},
|
|
82
|
+
sourceMeta: {},
|
|
76
83
|
},
|
|
77
84
|
mcp: {
|
|
78
85
|
resources: new Map(),
|
|
79
86
|
resourcesMeta: {},
|
|
80
|
-
tools: new Map(),
|
|
81
87
|
toolsMeta: {},
|
|
82
88
|
prompts: new Map(),
|
|
83
89
|
promptsMeta: {},
|
|
84
90
|
},
|
|
91
|
+
agent: {
|
|
92
|
+
agents: new Map(),
|
|
93
|
+
agentsMeta: {},
|
|
94
|
+
},
|
|
85
95
|
cli: {
|
|
86
96
|
meta: { programs: {}, renderers: {} },
|
|
87
97
|
programs: {},
|
|
@@ -89,56 +99,69 @@ const createEmptyPackageState = () => ({
|
|
|
89
99
|
middleware: {
|
|
90
100
|
tagGroup: {},
|
|
91
101
|
httpGroup: {},
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
},
|
|
103
|
+
channelMiddleware: {
|
|
104
|
+
tagGroup: {},
|
|
94
105
|
},
|
|
95
106
|
permissions: {
|
|
96
107
|
tagGroup: {},
|
|
97
108
|
httpGroup: {},
|
|
98
|
-
tagGroupMeta: {},
|
|
99
|
-
httpGroupMeta: {},
|
|
100
109
|
},
|
|
101
110
|
misc: {
|
|
102
111
|
errors: new Map(),
|
|
103
112
|
schemas: new Map(),
|
|
104
113
|
middleware: {},
|
|
114
|
+
channelMiddleware: {},
|
|
105
115
|
permissions: {},
|
|
106
116
|
},
|
|
117
|
+
models: {
|
|
118
|
+
config: null,
|
|
119
|
+
},
|
|
107
120
|
package: {
|
|
108
121
|
factories: null,
|
|
109
122
|
singletonServices: null,
|
|
123
|
+
metaDir: null,
|
|
110
124
|
},
|
|
111
125
|
});
|
|
112
126
|
/**
|
|
113
127
|
* Initialize state for a new package
|
|
114
128
|
*/
|
|
115
129
|
export const initializePikkuState = (packageName) => {
|
|
116
|
-
if (!
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
if (!globalThis.pikkuState.has(packageName)) {
|
|
120
|
-
globalThis.pikkuState.set(packageName, createEmptyPackageState());
|
|
130
|
+
if (!getAllPackageStates().has(packageName)) {
|
|
131
|
+
getAllPackageStates().set(packageName, createEmptyPackageState());
|
|
121
132
|
}
|
|
122
133
|
};
|
|
123
134
|
export const resetPikkuState = () => {
|
|
124
135
|
// Preserve the errors map before resetting
|
|
125
|
-
const existingErrors =
|
|
126
|
-
globalThis
|
|
136
|
+
const existingErrors = getAllPackageStates().get('__main__')?.misc.errors;
|
|
137
|
+
globalThis[PIKKU_STATE_KEY] = new Map();
|
|
127
138
|
initializePikkuState('__main__');
|
|
128
139
|
// Restore the errors map if it existed
|
|
129
140
|
if (existingErrors) {
|
|
130
|
-
const mainState =
|
|
141
|
+
const mainState = getAllPackageStates().get('__main__');
|
|
131
142
|
mainState.misc.errors = existingErrors;
|
|
132
143
|
}
|
|
133
144
|
};
|
|
134
|
-
if (!
|
|
145
|
+
if (!getAllPackageStates().has('__main__')) {
|
|
135
146
|
resetPikkuState();
|
|
136
147
|
}
|
|
148
|
+
export const getPikkuMetaDir = (packageName) => {
|
|
149
|
+
return pikkuState(packageName ?? null, 'package', 'metaDir');
|
|
150
|
+
};
|
|
151
|
+
export const getSingletonServices = () => {
|
|
152
|
+
const services = pikkuState(null, 'package', 'singletonServices');
|
|
153
|
+
if (!services)
|
|
154
|
+
throw new Error('Singleton services not initialized');
|
|
155
|
+
return services;
|
|
156
|
+
};
|
|
157
|
+
export const getCreateWireServices = () => {
|
|
158
|
+
return pikkuState(null, 'package', 'factories')?.createWireServices;
|
|
159
|
+
};
|
|
137
160
|
/**
|
|
138
|
-
* Register service factories for an
|
|
161
|
+
* Register service factories for an addon package.
|
|
139
162
|
* These factories are used to create services when the package's functions are invoked.
|
|
140
163
|
*
|
|
141
|
-
* @param packageName - The package name (e.g., '@pikku/templates-function-
|
|
164
|
+
* @param packageName - The package name (e.g., '@pikku/templates-function-addon')
|
|
142
165
|
* @param factories - The service factory functions
|
|
143
166
|
*/
|
|
144
167
|
export const addPackageServiceFactories = (packageName, factories) => {
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Logger } from './services/logger.js';
|
|
2
|
-
import { SchemaService } from './services/schema-service.js';
|
|
1
|
+
import type { Logger } from './services/logger.js';
|
|
2
|
+
import type { SchemaService } from './services/schema-service.js';
|
|
3
3
|
/**
|
|
4
4
|
* Adds a schema to the schemas map for a specific package.
|
|
5
5
|
* @param name - The name of the schema.
|
|
6
6
|
* @param value - The schema value.
|
|
7
|
-
* @param packageName - The package name (null for main package, '@scope/package' for
|
|
7
|
+
* @param packageName - The package name (null for main package, '@scope/package' for addon packages).
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
export declare const addSchema: (name: string, value: any, packageName?: string | null) => void;
|
|
11
11
|
/**
|
|
12
12
|
* Retrieves a schema from the schemas map for a specific package.
|
|
13
13
|
* @param name - The name of the schema.
|
|
14
|
-
* @param packageName - The package name (null for main package, '@scope/package' for
|
|
14
|
+
* @param packageName - The package name (null for main package, '@scope/package' for addon packages).
|
|
15
15
|
* @returns The schema value or undefined if not found.
|
|
16
16
|
* @ignore
|
|
17
17
|
*/
|