@pikku/core 0.11.2 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -2
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- package/dist/errors/errors.d.ts +8 -0
- package/dist/errors/errors.js +16 -0
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/function/function-runner.d.ts +7 -1
- package/dist/function/function-runner.js +82 -23
- package/dist/function/functions.types.d.ts +31 -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.js +1 -10
- package/dist/index.d.ts +28 -26
- package/dist/index.js +18 -29
- package/dist/middleware/auth-apikey.d.ts +2 -2
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +2 -2
- package/dist/middleware/auth-bearer.js +3 -6
- package/dist/middleware/auth-cookie.d.ts +2 -2
- package/dist/middleware/auth-cookie.js +6 -8
- package/dist/middleware/cors.d.ts +46 -0
- package/dist/middleware/cors.js +73 -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.js +8 -10
- package/dist/permissions.js +11 -15
- package/dist/pikku-state.d.ts +1 -0
- package/dist/pikku-state.js +18 -8
- package/dist/schema.js +12 -11
- package/dist/services/ai-agent-runner-service.d.ts +24 -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/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 +94 -0
- package/dist/services/in-memory-trigger-service.d.ts +23 -0
- package/dist/services/in-memory-trigger-service.js +50 -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 +25 -11
- package/dist/services/index.js +10 -13
- package/dist/services/local-secrets.d.ts +23 -0
- package/dist/services/local-secrets.js +45 -0
- package/dist/services/local-variables.d.ts +5 -0
- package/dist/services/local-variables.js +18 -0
- package/dist/services/scheduler-service.d.ts +21 -1
- package/dist/services/scheduler-service.js +14 -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 +23 -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 +13 -0
- 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 -4
- package/dist/types/core.types.d.ts +48 -12
- package/dist/types/core.types.js +8 -1
- package/dist/types/state.types.d.ts +43 -51
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +15 -3
- package/dist/version.d.ts +6 -0
- package/dist/version.js +19 -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 +60 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.js +312 -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 +96 -0
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +11 -0
- package/dist/wirings/ai-agent/ai-agent-stream.js +503 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +254 -0
- package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
- package/dist/wirings/ai-agent/index.d.ts +5 -0
- package/dist/wirings/ai-agent/index.js +4 -0
- package/dist/wirings/channel/channel-common.d.ts +7 -4
- package/dist/wirings/channel/channel-common.js +15 -8
- package/dist/wirings/channel/channel-handler.js +12 -3
- 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.js +7 -7
- package/dist/wirings/channel/channel.types.d.ts +5 -1
- 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.js +18 -6
- 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.js +15 -4
- 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 +1 -1
- package/dist/wirings/cli/cli-runner.js +12 -8
- package/dist/wirings/cli/cli.types.d.ts +6 -6
- 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.js +49 -23
- package/dist/wirings/http/http.types.d.ts +78 -38
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- package/dist/wirings/mcp/index.d.ts +4 -3
- package/dist/wirings/mcp/index.js +3 -3
- package/dist/wirings/mcp/mcp-runner.d.ts +1 -3
- package/dist/wirings/mcp/mcp-runner.js +25 -39
- package/dist/wirings/mcp/mcp.types.d.ts +3 -3
- 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 +2 -2
- package/dist/wirings/queue/index.js +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +7 -0
- package/dist/wirings/queue/queue-runner.js +17 -6
- package/dist/wirings/queue/queue.types.d.ts +8 -2
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +33 -5
- package/dist/wirings/rpc/rpc-runner.js +134 -16
- package/dist/wirings/rpc/rpc-types.d.ts +8 -4
- package/dist/wirings/scheduler/index.d.ts +3 -3
- package/dist/wirings/scheduler/index.js +2 -3
- package/dist/wirings/scheduler/scheduler-runner.d.ts +5 -0
- package/dist/wirings/scheduler/scheduler-runner.js +23 -5
- 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 +26 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +75 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +21 -8
- package/dist/wirings/trigger/trigger-runner.js +46 -18
- 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 +28 -14
- package/dist/wirings/workflow/pikku-workflow-service.js +200 -56
- package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
- package/dist/wirings/workflow/workflow-helpers.js +38 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +1 -23
- package/dist/wirings/workflow/workflow-utils.js +1 -66
- package/dist/wirings/workflow/workflow.types.d.ts +40 -93
- package/package.json +13 -15
- package/run-tests.sh +4 -1
- package/src/crypto-utils.ts +99 -0
- package/src/errors/errors.ts +17 -0
- package/src/errors/index.ts +0 -1
- package/src/factory-functions.test.ts +42 -2
- package/src/function/function-runner.test.ts +4 -11
- package/src/function/function-runner.ts +114 -29
- package/src/function/functions.types.ts +62 -132
- package/src/function/index.ts +5 -2
- package/src/handle-error.ts +2 -10
- package/src/index.ts +99 -25
- package/src/middleware/auth-apikey.test.ts +15 -12
- package/src/middleware/auth-apikey.ts +3 -3
- package/src/middleware/auth-bearer.test.ts +17 -14
- package/src/middleware/auth-bearer.ts +25 -27
- package/src/middleware/auth-cookie.test.ts +16 -13
- package/src/middleware/auth-cookie.ts +6 -8
- package/src/middleware/cors.ts +96 -0
- package/src/middleware/index.ts +5 -3
- package/src/middleware/remote-auth.ts +68 -0
- package/src/middleware-runner.test.ts +122 -0
- package/src/middleware-runner.ts +12 -12
- package/src/permissions.test.ts +81 -7
- package/src/permissions.ts +15 -17
- package/src/pikku-state.ts +20 -8
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.ts +18 -15
- package/src/services/ai-agent-runner-service.ts +29 -0
- package/src/services/ai-run-state-service.ts +20 -0
- package/src/services/ai-storage-service.ts +39 -0
- package/src/services/deployment-service.ts +22 -0
- package/src/services/gopass-secrets.ts +95 -0
- package/src/services/in-memory-trigger-service.ts +68 -0
- package/src/services/in-memory-workflow-service.ts +395 -0
- package/src/services/index.ts +49 -14
- package/src/services/local-secrets.ts +51 -0
- package/src/services/local-variables.ts +22 -0
- package/src/services/scheduler-service.ts +29 -1
- package/src/services/schema-service.ts +7 -0
- package/src/services/scoped-secret-service.ts +41 -0
- package/src/services/secret-service.ts +25 -4
- package/src/services/trigger-service.ts +38 -0
- package/src/services/typed-secret-service.ts +70 -0
- package/src/services/typed-variables-service.ts +81 -0
- package/src/services/user-session-service.ts +23 -0
- package/src/services/variables-service.ts +5 -0
- package/src/services/workflow-service.ts +22 -2
- package/src/types/core.types.ts +76 -11
- package/src/types/state.types.ts +37 -63
- package/src/utils.ts +20 -6
- package/src/version.test.ts +80 -0
- package/src/version.ts +25 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
- package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +470 -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 +75 -0
- package/src/wirings/ai-agent/ai-agent-runner.ts +137 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +246 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +774 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +273 -0
- package/src/wirings/ai-agent/index.ts +28 -0
- package/src/wirings/channel/channel-common.ts +32 -19
- package/src/wirings/channel/channel-handler.ts +17 -4
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +9 -10
- package/src/wirings/channel/channel.types.ts +17 -1
- 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 +44 -1
- package/src/wirings/channel/local/local-channel-runner.ts +22 -6
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +20 -4
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +9 -9
- package/src/wirings/cli/cli-runner.ts +17 -10
- package/src/wirings/cli/cli.types.ts +11 -11
- package/src/wirings/cli/command-parser.test.ts +8 -8
- 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 +3 -3
- package/src/wirings/http/http-runner.ts +63 -29
- package/src/wirings/http/http.types.ts +121 -37
- package/src/wirings/http/index.ts +16 -4
- package/src/wirings/mcp/index.ts +27 -3
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
- package/src/wirings/mcp/mcp-runner.ts +39 -50
- package/src/wirings/mcp/mcp.types.ts +3 -3
- 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 +14 -2
- package/src/wirings/queue/queue-runner.test.ts +97 -55
- package/src/wirings/queue/queue-runner.ts +33 -7
- package/src/wirings/queue/queue.types.ts +12 -2
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +187 -17
- package/src/wirings/rpc/rpc-types.ts +13 -4
- package/src/wirings/scheduler/index.ts +7 -4
- package/src/wirings/scheduler/scheduler-runner.test.ts +70 -26
- package/src/wirings/scheduler/scheduler-runner.ts +45 -5
- package/src/wirings/secret/index.ts +9 -0
- package/src/wirings/secret/secret.types.ts +32 -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 +134 -0
- package/src/wirings/trigger/trigger-runner.ts +80 -38
- package/src/wirings/trigger/trigger.types.ts +144 -22
- package/src/wirings/variable/index.ts +8 -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 +495 -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.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 +212 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +285 -66
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow-utils.ts +0 -120
- package/src/wirings/workflow/workflow.types.ts +45 -90
- 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/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
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { runMiddleware, combineMiddleware } from '../middleware-runner.js'
|
|
2
|
+
import {
|
|
3
|
+
combineChannelMiddleware,
|
|
4
|
+
wrapChannelWithMiddleware,
|
|
5
|
+
} from '../wirings/channel/channel-middleware-runner.js'
|
|
2
6
|
import { runPermissions } from '../permissions.js'
|
|
3
7
|
import { pikkuState } from '../pikku-state.js'
|
|
4
8
|
import { coerceTopLevelDataFromSchema, validateSchema } from '../schema.js'
|
|
@@ -14,12 +18,17 @@ import {
|
|
|
14
18
|
CreateWireServices,
|
|
15
19
|
CoreConfig,
|
|
16
20
|
} from '../types/core.types.js'
|
|
21
|
+
import type { CorePikkuChannelMiddleware } from '../wirings/channel/channel.types.js'
|
|
17
22
|
import {
|
|
18
23
|
CorePermissionGroup,
|
|
19
24
|
CorePikkuFunctionConfig,
|
|
20
25
|
CorePikkuPermission,
|
|
21
26
|
} from './functions.types.js'
|
|
22
|
-
import {
|
|
27
|
+
import { parseVersionedId } from '../version.js'
|
|
28
|
+
import {
|
|
29
|
+
SessionService,
|
|
30
|
+
createFunctionSessionWireProps,
|
|
31
|
+
} from '../services/user-session-service.js'
|
|
23
32
|
import { ForbiddenError } from '../errors/errors.js'
|
|
24
33
|
import { rpcService } from '../wirings/rpc/rpc-runner.js'
|
|
25
34
|
import { closeWireServices } from '../utils.js'
|
|
@@ -75,6 +84,30 @@ export const addFunction = (
|
|
|
75
84
|
pikkuState(packageName, 'function', 'functions').set(funcName, funcConfig)
|
|
76
85
|
}
|
|
77
86
|
|
|
87
|
+
export const getFunctionNames = (
|
|
88
|
+
packageName: string | null = null
|
|
89
|
+
): string[] => {
|
|
90
|
+
const functionsMeta = pikkuState(packageName, 'function', 'meta')
|
|
91
|
+
return Object.keys(functionsMeta)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const getAllFunctionNames = (): string[] => {
|
|
95
|
+
const functions: string[] = []
|
|
96
|
+
|
|
97
|
+
const mainFunctionsMeta = pikkuState(null, 'function', 'meta')
|
|
98
|
+
functions.push(...Object.keys(mainFunctionsMeta))
|
|
99
|
+
|
|
100
|
+
const externalPackages = pikkuState(null, 'rpc', 'externalPackages')
|
|
101
|
+
for (const [namespace, config] of externalPackages) {
|
|
102
|
+
const packageFunctionsMeta = pikkuState(config.package, 'function', 'meta')
|
|
103
|
+
for (const funcName of Object.keys(packageFunctionsMeta)) {
|
|
104
|
+
functions.push(`${namespace}:${funcName}`)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return functions
|
|
109
|
+
}
|
|
110
|
+
|
|
78
111
|
export const runPikkuFuncDirectly = async <In, Out>(
|
|
79
112
|
funcName: string,
|
|
80
113
|
allServices: CoreServices,
|
|
@@ -89,10 +122,9 @@ export const runPikkuFuncDirectly = async <In, Out>(
|
|
|
89
122
|
if (!funcConfig) {
|
|
90
123
|
throw new Error(`Function not found: ${funcName}`)
|
|
91
124
|
}
|
|
92
|
-
// Inject session into wire
|
|
93
125
|
const wireWithSession = {
|
|
94
126
|
...wire,
|
|
95
|
-
|
|
127
|
+
...(userSession && createFunctionSessionWireProps(userSession)),
|
|
96
128
|
}
|
|
97
129
|
return (await funcConfig.func(allServices, data, wireWithSession)) as Out
|
|
98
130
|
}
|
|
@@ -108,11 +140,14 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
108
140
|
auth: wiringAuth,
|
|
109
141
|
inheritedMiddleware,
|
|
110
142
|
wireMiddleware,
|
|
143
|
+
inheritedChannelMiddleware,
|
|
144
|
+
wireChannelMiddleware,
|
|
111
145
|
inheritedPermissions,
|
|
112
146
|
wirePermissions,
|
|
113
147
|
coerceDataFromSchema,
|
|
114
148
|
tags = [],
|
|
115
149
|
wire,
|
|
150
|
+
sessionService,
|
|
116
151
|
packageName = null,
|
|
117
152
|
}: {
|
|
118
153
|
singletonServices: CoreSingletonServices
|
|
@@ -121,22 +156,44 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
121
156
|
auth?: boolean
|
|
122
157
|
inheritedMiddleware?: MiddlewareMetadata[]
|
|
123
158
|
wireMiddleware?: CorePikkuMiddleware[]
|
|
159
|
+
inheritedChannelMiddleware?: MiddlewareMetadata[]
|
|
160
|
+
wireChannelMiddleware?: CorePikkuChannelMiddleware[]
|
|
124
161
|
inheritedPermissions?: PermissionMetadata[]
|
|
125
162
|
wirePermissions?: CorePermissionGroup | CorePikkuPermission[]
|
|
126
163
|
coerceDataFromSchema?: boolean
|
|
127
164
|
tags?: string[]
|
|
128
165
|
wire: PikkuWire
|
|
166
|
+
sessionService?: SessionService<CoreUserSession>
|
|
129
167
|
packageName?: string | null
|
|
130
168
|
}
|
|
131
169
|
): Promise<Out> => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
170
|
+
wire = {
|
|
171
|
+
...wire,
|
|
172
|
+
wireType: wire.wireType ?? wireType,
|
|
173
|
+
wireId: wire.wireId ?? wireId,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const funcMap = pikkuState(packageName, 'function', 'functions')
|
|
177
|
+
let funcConfig = funcMap.get(funcName)
|
|
178
|
+
const allMeta = pikkuState(packageName, 'function', 'meta')
|
|
179
|
+
let funcMeta = allMeta[funcName]
|
|
180
|
+
|
|
181
|
+
if (!funcConfig || !funcMeta) {
|
|
182
|
+
const { baseName, version } = parseVersionedId(funcName)
|
|
183
|
+
if (version !== null) {
|
|
184
|
+
funcConfig = funcConfig || funcMap.get(baseName)
|
|
185
|
+
funcMeta = funcMeta || allMeta[baseName]
|
|
186
|
+
if (funcConfig && funcMeta) {
|
|
187
|
+
singletonServices.logger.warn(
|
|
188
|
+
`Version '${funcName}' not registered, resolved to '${baseName}'`
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
135
194
|
if (!funcConfig) {
|
|
136
195
|
throw new Error(`Function not found: ${funcName}`)
|
|
137
196
|
}
|
|
138
|
-
const allMeta = pikkuState(packageName, 'function', 'meta')
|
|
139
|
-
const funcMeta = allMeta[funcName]
|
|
140
197
|
if (!funcMeta) {
|
|
141
198
|
throw new Error(`Function meta not found: ${funcName}`)
|
|
142
199
|
}
|
|
@@ -155,6 +212,21 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
155
212
|
}
|
|
156
213
|
}
|
|
157
214
|
|
|
215
|
+
const allChannelMiddleware = combineChannelMiddleware(wireType, wireId, {
|
|
216
|
+
wireInheritedChannelMiddleware: inheritedChannelMiddleware,
|
|
217
|
+
wireChannelMiddleware,
|
|
218
|
+
packageName,
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
const resolvedWire =
|
|
222
|
+
allChannelMiddleware.length > 0 && wire.channel
|
|
223
|
+
? wrapChannelWithMiddleware(
|
|
224
|
+
wire,
|
|
225
|
+
resolvedSingletonServices,
|
|
226
|
+
allChannelMiddleware
|
|
227
|
+
)
|
|
228
|
+
: wire
|
|
229
|
+
|
|
158
230
|
// Convert tags to PermissionMetadata and merge with inheritedPermissions
|
|
159
231
|
const mergedInheritedPermissions: PermissionMetadata[] = [
|
|
160
232
|
...(inheritedPermissions || []),
|
|
@@ -163,24 +235,38 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
163
235
|
|
|
164
236
|
// Helper function to run permissions and execute the function
|
|
165
237
|
const executeFunction = async () => {
|
|
166
|
-
const
|
|
238
|
+
const functionWireProps = sessionService
|
|
239
|
+
? createFunctionSessionWireProps(sessionService)
|
|
240
|
+
: undefined
|
|
167
241
|
|
|
168
|
-
const
|
|
169
|
-
...
|
|
170
|
-
|
|
242
|
+
const wireWithSession: PikkuWire = {
|
|
243
|
+
...resolvedWire,
|
|
244
|
+
...functionWireProps,
|
|
171
245
|
}
|
|
172
246
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
247
|
+
const session = wireWithSession.session
|
|
248
|
+
|
|
249
|
+
if (funcMeta.sessionless) {
|
|
250
|
+
if (wiringAuth === true || funcConfig.auth === true) {
|
|
251
|
+
if (!session) {
|
|
252
|
+
throw new ForbiddenError('Authentication required')
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else if (funcMeta.sessionless === false) {
|
|
256
|
+
if (wiringAuth === false || funcConfig.auth === false) {
|
|
257
|
+
resolvedSingletonServices.logger.warn(
|
|
258
|
+
`Function '${funcName}' requires a session but auth was explicitly disabled — use pikkuSessionlessFunc instead.`
|
|
259
|
+
)
|
|
260
|
+
} else if (!session) {
|
|
176
261
|
throw new ForbiddenError('Authentication required')
|
|
177
262
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
//
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
263
|
+
} else {
|
|
264
|
+
// TODO: Remove after a couple of releases — backward compat for
|
|
265
|
+
// generated metadata that doesn't include the `sessionless` field yet.
|
|
266
|
+
if (wiringAuth === true || funcConfig.auth === true) {
|
|
267
|
+
if (!session) {
|
|
268
|
+
throw new ForbiddenError('Authentication required')
|
|
269
|
+
}
|
|
184
270
|
}
|
|
185
271
|
}
|
|
186
272
|
|
|
@@ -210,23 +296,22 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
210
296
|
funcInheritedPermissions: funcMeta.permissions,
|
|
211
297
|
funcPermissions: funcConfig.permissions,
|
|
212
298
|
services: resolvedSingletonServices,
|
|
213
|
-
wire: { ...
|
|
299
|
+
wire: { ...wireWithSession, rpc: undefined } as any,
|
|
214
300
|
data: actualData,
|
|
215
301
|
packageName,
|
|
216
302
|
})
|
|
217
303
|
|
|
218
304
|
const wireServices = await resolvedCreateWireServices?.(
|
|
219
305
|
resolvedSingletonServices,
|
|
220
|
-
|
|
306
|
+
wireWithSession
|
|
221
307
|
)
|
|
222
308
|
try {
|
|
223
309
|
const services = { ...resolvedSingletonServices, ...wireServices }
|
|
224
|
-
const rpc = rpcService.getContextRPCService(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
)
|
|
310
|
+
const rpc = rpcService.getContextRPCService(services, wireWithSession, {
|
|
311
|
+
sessionService,
|
|
312
|
+
})
|
|
228
313
|
return await funcConfig.func(services, actualData, {
|
|
229
|
-
...
|
|
314
|
+
...wireWithSession,
|
|
230
315
|
rpc,
|
|
231
316
|
})
|
|
232
317
|
} finally {
|
|
@@ -247,7 +332,7 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
247
332
|
if (allMiddleware.length > 0) {
|
|
248
333
|
return (await runMiddleware<CorePikkuMiddleware>(
|
|
249
334
|
resolvedSingletonServices,
|
|
250
|
-
|
|
335
|
+
resolvedWire,
|
|
251
336
|
allMiddleware,
|
|
252
337
|
executeFunction
|
|
253
338
|
)) as Out
|
|
@@ -6,7 +6,14 @@ import type {
|
|
|
6
6
|
PikkuWire,
|
|
7
7
|
PickRequired,
|
|
8
8
|
} from '../types/core.types.js'
|
|
9
|
-
import {
|
|
9
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
10
|
+
import type { CoreNodeConfig } from '../wirings/node/node.types.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use StandardSchemaV1 from @standard-schema/spec instead.
|
|
14
|
+
* This alias exists only for backward compatibility with generated code.
|
|
15
|
+
*/
|
|
16
|
+
export type ZodLike<T = any> = StandardSchemaV1<T, T>
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
19
|
* Represents a core API function that performs an operation using core services and a user session.
|
|
@@ -20,6 +27,7 @@ export type CorePikkuFunction<
|
|
|
20
27
|
In,
|
|
21
28
|
Out,
|
|
22
29
|
Services extends CoreSingletonServices = CoreServices,
|
|
30
|
+
Session extends CoreUserSession = CoreUserSession,
|
|
23
31
|
Wire extends PikkuWire<In, Out> = PikkuWire<In, Out, true, Session>,
|
|
24
32
|
> = (
|
|
25
33
|
services: Services,
|
|
@@ -39,15 +47,16 @@ export type CorePikkuFunctionSessionless<
|
|
|
39
47
|
In,
|
|
40
48
|
Out,
|
|
41
49
|
Services extends CoreSingletonServices = CoreServices,
|
|
42
|
-
|
|
50
|
+
Session extends CoreUserSession = CoreUserSession,
|
|
51
|
+
Wire extends PikkuWire<In, Out, false, Session, any, any, any> = PikkuWire<
|
|
43
52
|
In,
|
|
44
53
|
Out,
|
|
45
54
|
false,
|
|
46
|
-
|
|
55
|
+
Session,
|
|
47
56
|
any,
|
|
48
57
|
any,
|
|
49
58
|
any
|
|
50
|
-
|
|
59
|
+
>,
|
|
51
60
|
> = (
|
|
52
61
|
services: Services,
|
|
53
62
|
data: In,
|
|
@@ -94,8 +103,8 @@ export type CorePikkuPermissionConfig<
|
|
|
94
103
|
> = {
|
|
95
104
|
/** The permission function */
|
|
96
105
|
func: CorePikkuPermission<In, Services, Wire>
|
|
97
|
-
/** Optional human-readable
|
|
98
|
-
|
|
106
|
+
/** Optional human-readable name for the permission */
|
|
107
|
+
name?: string
|
|
99
108
|
/** Optional description of what the permission checks */
|
|
100
109
|
description?: string
|
|
101
110
|
}
|
|
@@ -108,18 +117,18 @@ export type CorePikkuPermissionConfig<
|
|
|
108
117
|
* ```typescript
|
|
109
118
|
* // Direct function syntax
|
|
110
119
|
* export const adminPermission = pikkuPermission(
|
|
111
|
-
* async ({ logger }, _data, {
|
|
112
|
-
* const currentSession = await
|
|
120
|
+
* async ({ logger }, _data, { getSession }) => {
|
|
121
|
+
* const currentSession = await getSession()
|
|
113
122
|
* return currentSession?.role === 'admin'
|
|
114
123
|
* }
|
|
115
124
|
* )
|
|
116
125
|
*
|
|
117
126
|
* // Configuration object syntax with metadata
|
|
118
127
|
* export const adminPermission = pikkuPermission({
|
|
119
|
-
*
|
|
128
|
+
* name: 'Admin Permission',
|
|
120
129
|
* description: 'Checks if user has admin role',
|
|
121
|
-
* func: async ({ logger }, _data, {
|
|
122
|
-
* const currentSession = await
|
|
130
|
+
* func: async ({ logger }, _data, { getSession }) => {
|
|
131
|
+
* const currentSession = await getSession()
|
|
123
132
|
* return currentSession?.role === 'admin'
|
|
124
133
|
* }
|
|
125
134
|
* })
|
|
@@ -168,8 +177,8 @@ export type CorePikkuPermissionFactory<
|
|
|
168
177
|
* export const requireRole = pikkuPermissionFactory<{ role: string }>(({
|
|
169
178
|
* role
|
|
170
179
|
* }) => {
|
|
171
|
-
* return pikkuPermission(async ({ logger }, data, {
|
|
172
|
-
* const currentSession = await
|
|
180
|
+
* return pikkuPermission(async ({ logger }, data, { getSession }) => {
|
|
181
|
+
* const currentSession = await getSession()
|
|
173
182
|
* if (!currentSession || currentSession.role !== role) {
|
|
174
183
|
* logger.warn(`Permission denied: required role '${role}'`)
|
|
175
184
|
* return false
|
|
@@ -185,23 +194,45 @@ export const pikkuPermissionFactory = <In = any>(
|
|
|
185
194
|
return factory
|
|
186
195
|
}
|
|
187
196
|
|
|
197
|
+
export type CorePikkuAuth<
|
|
198
|
+
Services extends CoreSingletonServices = CoreServices,
|
|
199
|
+
Session extends CoreUserSession = CoreUserSession,
|
|
200
|
+
> = (services: Services, session: Session) => Promise<boolean> | boolean
|
|
201
|
+
|
|
202
|
+
export type CorePikkuAuthConfig<
|
|
203
|
+
Services extends CoreSingletonServices = CoreServices,
|
|
204
|
+
Session extends CoreUserSession = CoreUserSession,
|
|
205
|
+
> = {
|
|
206
|
+
func: CorePikkuAuth<Services, Session>
|
|
207
|
+
name?: string
|
|
208
|
+
description?: string
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const pikkuAuth = <
|
|
212
|
+
Services extends CoreSingletonServices = CoreServices,
|
|
213
|
+
Session extends CoreUserSession = CoreUserSession,
|
|
214
|
+
>(
|
|
215
|
+
auth:
|
|
216
|
+
| CorePikkuAuth<Services, Session>
|
|
217
|
+
| CorePikkuAuthConfig<Services, Session>
|
|
218
|
+
): CorePikkuPermission<any, Services, any> => {
|
|
219
|
+
const fn = typeof auth === 'function' ? auth : auth.func
|
|
220
|
+
const wrapper = async (services: Services, _data: any, wire: any) => {
|
|
221
|
+
const session = wire.session
|
|
222
|
+
if (!session) return false
|
|
223
|
+
return fn(services, session as Session)
|
|
224
|
+
}
|
|
225
|
+
return wrapper as any
|
|
226
|
+
}
|
|
227
|
+
|
|
188
228
|
export type CorePermissionGroup<PikkuPermission = CorePikkuPermission<any>> =
|
|
189
229
|
| Record<string, PikkuPermission | PikkuPermission[]>
|
|
190
230
|
| undefined
|
|
191
231
|
|
|
192
|
-
/**
|
|
193
|
-
* Zod schema type - matches z.ZodType shape for type inference
|
|
194
|
-
* This avoids requiring zod as a dependency while allowing schema inference
|
|
195
|
-
*/
|
|
196
|
-
export type ZodLike<T = any> = {
|
|
197
|
-
_input: T
|
|
198
|
-
_output: T
|
|
199
|
-
}
|
|
200
|
-
|
|
201
232
|
export type CorePikkuFunctionConfig<
|
|
202
233
|
PikkuFunction extends
|
|
203
|
-
| CorePikkuFunction<any, any, any, any>
|
|
204
|
-
| CorePikkuFunctionSessionless<any, any, any, any>,
|
|
234
|
+
| CorePikkuFunction<any, any, any, any, any>
|
|
235
|
+
| CorePikkuFunctionSessionless<any, any, any, any, any>,
|
|
205
236
|
PikkuPermission extends CorePikkuPermission<
|
|
206
237
|
any,
|
|
207
238
|
any,
|
|
@@ -211,126 +242,25 @@ export type CorePikkuFunctionConfig<
|
|
|
211
242
|
any,
|
|
212
243
|
any
|
|
213
244
|
>,
|
|
214
|
-
InputSchema extends
|
|
215
|
-
OutputSchema extends
|
|
245
|
+
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
246
|
+
OutputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
216
247
|
> = {
|
|
217
248
|
/** Optional human-readable title for the function */
|
|
218
249
|
title?: string
|
|
219
250
|
/** Optional description of what the function does */
|
|
220
251
|
description?: string
|
|
221
252
|
override?: string
|
|
253
|
+
version?: number
|
|
222
254
|
tags?: string[]
|
|
223
255
|
expose?: boolean
|
|
224
|
-
|
|
256
|
+
remote?: boolean
|
|
257
|
+
mcp?: boolean
|
|
258
|
+
requiresApproval?: boolean
|
|
225
259
|
func: PikkuFunction
|
|
226
260
|
auth?: boolean
|
|
227
261
|
permissions?: CorePermissionGroup<PikkuPermission>
|
|
228
262
|
middleware?: PikkuMiddleware[]
|
|
229
263
|
input?: InputSchema
|
|
230
264
|
output?: OutputSchema
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* A trigger function that sets up a subscription and returns a teardown function.
|
|
235
|
-
* The trigger is fired via wire.trigger.trigger(data).
|
|
236
|
-
*
|
|
237
|
-
* @template TConfig - Configuration type (hardcoded when wired)
|
|
238
|
-
* @template TOutput - Output type produced when trigger fires
|
|
239
|
-
* @template Services - Services available to the trigger
|
|
240
|
-
*/
|
|
241
|
-
export type CorePikkuTriggerFunction<
|
|
242
|
-
TConfig = unknown,
|
|
243
|
-
TOutput = unknown,
|
|
244
|
-
Services extends CoreSingletonServices = CoreSingletonServices,
|
|
245
|
-
> = (
|
|
246
|
-
services: Services,
|
|
247
|
-
config: TConfig,
|
|
248
|
-
wire: { trigger: { trigger: (data: TOutput) => void } }
|
|
249
|
-
) => Promise<() => void | Promise<void>>
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Configuration object for creating a trigger function with metadata
|
|
253
|
-
*/
|
|
254
|
-
export type CorePikkuTriggerFunctionConfig<
|
|
255
|
-
TConfig = unknown,
|
|
256
|
-
TOutput = unknown,
|
|
257
|
-
Services extends CoreSingletonServices = CoreSingletonServices,
|
|
258
|
-
ConfigSchema extends ZodLike | undefined = undefined,
|
|
259
|
-
OutputSchema extends ZodLike | undefined = undefined,
|
|
260
|
-
> = {
|
|
261
|
-
/** Optional human-readable title for the trigger */
|
|
262
|
-
title?: string
|
|
263
|
-
/** Optional description of what the trigger does */
|
|
264
|
-
description?: string
|
|
265
|
-
/** Optional tags for categorization */
|
|
266
|
-
tags?: string[]
|
|
267
|
-
/** The trigger function */
|
|
268
|
-
func: CorePikkuTriggerFunction<TConfig, TOutput, Services>
|
|
269
|
-
/** Optional Zod schema for config validation */
|
|
270
|
-
config?: ConfigSchema
|
|
271
|
-
/** Optional Zod schema for output validation */
|
|
272
|
-
output?: OutputSchema
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Factory function for creating trigger functions
|
|
277
|
-
* Supports both direct function and configuration object syntax
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* // Direct function syntax
|
|
282
|
-
* export const redisSubscribeTrigger = pikkuTriggerFunc<
|
|
283
|
-
* { channel: string },
|
|
284
|
-
* { message: string }
|
|
285
|
-
* >(async ({ redis }, { channel }, { trigger }) => {
|
|
286
|
-
* const subscriber = redis.duplicate()
|
|
287
|
-
* await subscriber.subscribe(channel, (msg) => {
|
|
288
|
-
* trigger.trigger({ message: msg })
|
|
289
|
-
* })
|
|
290
|
-
* return () => subscriber.unsubscribe()
|
|
291
|
-
* })
|
|
292
|
-
*
|
|
293
|
-
* // Configuration object syntax with metadata
|
|
294
|
-
* export const redisSubscribeTrigger = pikkuTriggerFunc({
|
|
295
|
-
* title: 'Redis Subscribe Trigger',
|
|
296
|
-
* description: 'Listens to Redis pub/sub channel',
|
|
297
|
-
* config: z.object({ channel: z.string() }),
|
|
298
|
-
* output: z.object({ message: z.string() }),
|
|
299
|
-
* func: async ({ redis }, { channel }, { trigger }) => {
|
|
300
|
-
* const subscriber = redis.duplicate()
|
|
301
|
-
* await subscriber.subscribe(channel, (msg) => {
|
|
302
|
-
* trigger.trigger({ message: msg })
|
|
303
|
-
* })
|
|
304
|
-
* return () => subscriber.unsubscribe()
|
|
305
|
-
* }
|
|
306
|
-
* })
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
export const pikkuTriggerFunc = <
|
|
310
|
-
TConfig = unknown,
|
|
311
|
-
TOutput = unknown,
|
|
312
|
-
Services extends CoreSingletonServices = CoreSingletonServices,
|
|
313
|
-
ConfigSchema extends ZodLike | undefined = undefined,
|
|
314
|
-
OutputSchema extends ZodLike | undefined = undefined,
|
|
315
|
-
>(
|
|
316
|
-
triggerOrConfig:
|
|
317
|
-
| CorePikkuTriggerFunction<TConfig, TOutput, Services>
|
|
318
|
-
| CorePikkuTriggerFunctionConfig<
|
|
319
|
-
TConfig,
|
|
320
|
-
TOutput,
|
|
321
|
-
Services,
|
|
322
|
-
ConfigSchema,
|
|
323
|
-
OutputSchema
|
|
324
|
-
>
|
|
325
|
-
): CorePikkuTriggerFunctionConfig<
|
|
326
|
-
TConfig,
|
|
327
|
-
TOutput,
|
|
328
|
-
Services,
|
|
329
|
-
ConfigSchema,
|
|
330
|
-
OutputSchema
|
|
331
|
-
> => {
|
|
332
|
-
if (typeof triggerOrConfig === 'function') {
|
|
333
|
-
return { func: triggerOrConfig }
|
|
334
|
-
}
|
|
335
|
-
return triggerOrConfig
|
|
265
|
+
node?: CoreNodeConfig
|
|
336
266
|
}
|
package/src/function/index.ts
CHANGED
package/src/handle-error.ts
CHANGED
|
@@ -57,17 +57,9 @@ export const handleHTTPError = (
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// Handle 404 errors specifically
|
|
61
|
-
if (e instanceof NotFoundError) {
|
|
62
|
-
// TODO
|
|
63
|
-
// http?.response?.end()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Either bubble up or end the response
|
|
67
60
|
if (bubbleError) {
|
|
68
61
|
throw e
|
|
69
|
-
} else {
|
|
70
|
-
// TODO
|
|
71
|
-
// http?.response?.end()
|
|
72
62
|
}
|
|
63
|
+
|
|
64
|
+
http?.response?.close?.()
|
|
73
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,37 +1,111 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @pikku/core
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
4
|
+
export type {
|
|
5
|
+
CommonWireMeta,
|
|
6
|
+
CoreConfig,
|
|
7
|
+
CorePikkuMiddleware,
|
|
8
|
+
CorePikkuMiddlewareConfig,
|
|
9
|
+
CorePikkuMiddlewareFactory,
|
|
10
|
+
CorePikkuMiddlewareGroup,
|
|
11
|
+
CoreServices,
|
|
12
|
+
CoreSingletonServices,
|
|
13
|
+
CoreUserSession,
|
|
14
|
+
CreateConfig,
|
|
15
|
+
CreateSingletonServices,
|
|
16
|
+
CreateWireServices,
|
|
17
|
+
FunctionMeta,
|
|
18
|
+
FunctionRuntimeMeta,
|
|
19
|
+
FunctionServicesMeta,
|
|
20
|
+
FunctionWiresMeta,
|
|
21
|
+
FunctionsMeta,
|
|
22
|
+
FunctionsRuntimeMeta,
|
|
23
|
+
JSONPrimitive,
|
|
24
|
+
JSONValue,
|
|
25
|
+
MakeRequired,
|
|
26
|
+
MiddlewareMetadata,
|
|
27
|
+
PermissionMetadata,
|
|
28
|
+
PickOptional,
|
|
29
|
+
PickRequired,
|
|
30
|
+
PikkuAIMiddlewareHooks,
|
|
31
|
+
PikkuWire,
|
|
32
|
+
PikkuWiringTypes,
|
|
33
|
+
RequireAtLeastOne,
|
|
34
|
+
SerializedError,
|
|
35
|
+
WireServices,
|
|
36
|
+
} from './types/core.types.js'
|
|
37
|
+
export {
|
|
38
|
+
pikkuAIMiddleware,
|
|
39
|
+
pikkuChannelMiddleware,
|
|
40
|
+
pikkuChannelMiddlewareFactory,
|
|
41
|
+
pikkuMiddleware,
|
|
42
|
+
pikkuMiddlewareFactory,
|
|
43
|
+
} from './types/core.types.js'
|
|
44
|
+
export type {
|
|
45
|
+
CorePikkuAuth,
|
|
46
|
+
CorePikkuAuthConfig,
|
|
47
|
+
CorePikkuFunction,
|
|
48
|
+
CorePikkuFunctionConfig,
|
|
49
|
+
CorePikkuPermission,
|
|
50
|
+
CorePikkuPermissionConfig,
|
|
51
|
+
CorePikkuPermissionFactory,
|
|
52
|
+
CorePermissionGroup,
|
|
53
|
+
ZodLike,
|
|
54
|
+
} from './function/functions.types.js'
|
|
55
|
+
export {
|
|
56
|
+
pikkuAuth,
|
|
57
|
+
pikkuPermission,
|
|
58
|
+
pikkuPermissionFactory,
|
|
59
|
+
} from './function/functions.types.js'
|
|
60
|
+
export { addFunction, getAllFunctionNames } from './function/index.js'
|
|
61
|
+
export { PikkuRequest } from './pikku-request.js'
|
|
62
|
+
export {
|
|
63
|
+
getRelativeTimeOffsetFromNow,
|
|
64
|
+
parseDurationString,
|
|
65
|
+
} from './time-utils.js'
|
|
66
|
+
export type { RelativeTimeInput } from './time-utils.js'
|
|
67
|
+
export {
|
|
68
|
+
formatVersionedId,
|
|
69
|
+
isVersionedId,
|
|
70
|
+
parseVersionedId,
|
|
71
|
+
} from './version.js'
|
|
29
72
|
export {
|
|
30
73
|
pikkuState,
|
|
31
74
|
initializePikkuState,
|
|
32
75
|
resetPikkuState,
|
|
33
76
|
addPackageServiceFactories,
|
|
77
|
+
getPikkuMetaDir,
|
|
34
78
|
} from './pikku-state.js'
|
|
79
|
+
export { runPikkuFunc } from './function/function-runner.js'
|
|
80
|
+
export { runCLICommand, pikkuCLIRender } from './wirings/cli/cli-runner.js'
|
|
81
|
+
export { fetch } from './wirings/http/http-runner.js'
|
|
82
|
+
export {
|
|
83
|
+
runMCPTool,
|
|
84
|
+
runMCPResource,
|
|
85
|
+
runMCPPrompt,
|
|
86
|
+
} from './wirings/mcp/mcp-runner.js'
|
|
87
|
+
export type {
|
|
88
|
+
MCPToolResponse,
|
|
89
|
+
MCPResourceResponse,
|
|
90
|
+
MCPPromptResponse,
|
|
91
|
+
} from './wirings/mcp/mcp.types.js'
|
|
92
|
+
export { runQueueJob } from './wirings/queue/queue-runner.js'
|
|
93
|
+
export { runScheduledTask } from './wirings/scheduler/scheduler-runner.js'
|
|
94
|
+
export { NotFoundError } from './errors/errors.js'
|
|
95
|
+
export type { EventHubService } from './wirings/channel/eventhub-service.js'
|
|
96
|
+
export type { QueueService } from './wirings/queue/queue.types.js'
|
|
97
|
+
export type { JWTService } from './services/jwt-service.js'
|
|
98
|
+
export type { HTTPMethod } from './wirings/http/http.types.js'
|
|
99
|
+
export type { GraphNodeConfig } from './wirings/workflow/graph/workflow-graph.types.js'
|
|
100
|
+
export { createGraph } from './wirings/workflow/graph/graph-node.js'
|
|
101
|
+
export { workflow as wireWorkflow } from './wirings/workflow/workflow-helpers.js'
|
|
35
102
|
export type { PikkuPackageState } from './types/state.types.js'
|
|
36
103
|
export { runMiddleware, addMiddleware } from './middleware-runner.js'
|
|
37
104
|
export { addPermission } from './permissions.js'
|
|
105
|
+
export { isSerializable, stopSingletonServices } from './utils.js'
|
|
106
|
+
export {
|
|
107
|
+
type ScheduledTaskInfo,
|
|
108
|
+
type ScheduledTaskSummary,
|
|
109
|
+
type SchedulerRuntimeHandlers,
|
|
110
|
+
} from './services/scheduler-service.js'
|
|
111
|
+
export { SchedulerService } from './services/scheduler-service.js'
|