@pikku/core 0.12.2 → 0.12.4
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 +24 -0
- package/dist/crypto-utils.d.ts +10 -0
- package/dist/crypto-utils.js +62 -0
- package/dist/function/function-runner.js +4 -4
- package/dist/function/functions.types.d.ts +26 -1
- package/dist/function/functions.types.js +16 -0
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +7 -3
- package/dist/index.d.ts +14 -2
- package/dist/index.js +1 -1
- package/dist/pikku-state.js +3 -1
- package/dist/schema.js +1 -1
- package/dist/services/in-memory-workflow-service.d.ts +22 -3
- package/dist/services/in-memory-workflow-service.js +77 -1
- package/dist/services/workflow-service.d.ts +8 -2
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/service-tests.d.ts +31 -0
- package/dist/testing/service-tests.js +598 -0
- package/dist/types/core.types.d.ts +9 -1
- package/dist/types/state.types.d.ts +4 -2
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +23 -0
- package/dist/wirings/ai-agent/agent-dynamic-workflow.d.ts +6 -0
- package/dist/wirings/ai-agent/agent-dynamic-workflow.js +348 -0
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +1 -1
- package/dist/wirings/ai-agent/ai-agent-memory.js +6 -5
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +10 -7
- package/dist/wirings/ai-agent/ai-agent-prepare.js +127 -47
- package/dist/wirings/ai-agent/ai-agent-runner.d.ts +4 -0
- package/dist/wirings/ai-agent/ai-agent-runner.js +381 -27
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +7 -2
- package/dist/wirings/ai-agent/ai-agent-stream.js +109 -46
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +22 -1
- package/dist/wirings/ai-agent/index.d.ts +1 -2
- package/dist/wirings/ai-agent/index.js +1 -2
- package/dist/wirings/channel/channel-handler.js +5 -1
- package/dist/wirings/channel/channel.types.d.ts +1 -7
- package/dist/wirings/channel/local/local-channel-handler.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-handler.js +5 -3
- package/dist/wirings/channel/local/local-channel-runner.js +14 -4
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +4 -1
- package/dist/wirings/cli/cli-runner.js +10 -2
- package/dist/wirings/cli/cli.types.d.ts +1 -0
- package/dist/wirings/http/http-routes.js +0 -1
- package/dist/wirings/http/http-runner.d.ts +1 -1
- package/dist/wirings/http/http-runner.js +25 -3
- package/dist/wirings/http/http.types.d.ts +3 -11
- package/dist/wirings/http/index.d.ts +2 -1
- package/dist/wirings/http/index.js +1 -0
- package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -0
- package/dist/wirings/http/pikku-fetch-http-request.js +3 -0
- package/dist/wirings/http/pikku-fetch-http-response.d.ts +1 -0
- package/dist/wirings/http/pikku-fetch-http-response.js +4 -4
- package/dist/wirings/http/web-request.d.ts +12 -0
- package/dist/wirings/http/web-request.js +85 -0
- package/dist/wirings/mcp/mcp-endpoint-registry.js +1 -1
- package/dist/wirings/mcp/mcp-runner.js +13 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +30 -6
- package/dist/wirings/rpc/rpc-runner.js +36 -14
- package/dist/wirings/rpc/rpc-types.d.ts +6 -1
- package/dist/wirings/rpc/wire-addon.d.ts +1 -0
- package/dist/wirings/rpc/wire-addon.js +1 -1
- package/dist/wirings/scheduler/scheduler-runner.js +1 -0
- package/dist/wirings/workflow/graph/graph-validation.d.ts +3 -0
- package/dist/wirings/workflow/graph/graph-validation.js +175 -0
- package/dist/wirings/workflow/graph/index.d.ts +1 -0
- package/dist/wirings/workflow/graph/index.js +1 -0
- package/dist/wirings/workflow/index.d.ts +1 -1
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +8 -2
- package/dist/wirings/workflow/pikku-workflow-service.js +1 -2
- package/dist/wirings/workflow/workflow.types.d.ts +10 -1
- package/lcov.info +18891 -0
- package/package.json +4 -2
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +0 -5
- package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +0 -168
- package/src/crypto-utils.test.ts +0 -116
- package/src/crypto-utils.ts +0 -99
- package/src/errors/error-handler.ts +0 -62
- package/src/errors/error.test.ts +0 -195
- package/src/errors/errors.ts +0 -374
- package/src/errors/index.ts +0 -2
- package/src/factory-functions.test.ts +0 -109
- package/src/function/function-runner.test.ts +0 -536
- package/src/function/function-runner.ts +0 -365
- package/src/function/functions.types.ts +0 -267
- package/src/function/index.ts +0 -5
- package/src/handle-error.test.ts +0 -361
- package/src/handle-error.ts +0 -65
- package/src/index.ts +0 -104
- package/src/internal.ts +0 -6
- package/src/middleware/auth-apikey.test.ts +0 -363
- package/src/middleware/auth-apikey.ts +0 -47
- package/src/middleware/auth-bearer.test.ts +0 -450
- package/src/middleware/auth-bearer.ts +0 -72
- package/src/middleware/auth-cookie.test.ts +0 -528
- package/src/middleware/auth-cookie.ts +0 -80
- package/src/middleware/cors.test.ts +0 -424
- package/src/middleware/cors.ts +0 -104
- package/src/middleware/index.ts +0 -5
- package/src/middleware/remote-auth.test.ts +0 -488
- package/src/middleware/remote-auth.ts +0 -68
- package/src/middleware/timeout.ts +0 -15
- package/src/middleware-runner.test.ts +0 -418
- package/src/middleware-runner.ts +0 -234
- package/src/permissions.test.ts +0 -434
- package/src/permissions.ts +0 -319
- package/src/pikku-request.ts +0 -23
- package/src/pikku-response.ts +0 -5
- package/src/pikku-state.test.ts +0 -224
- package/src/pikku-state.ts +0 -214
- package/src/run-tests-script.test.ts +0 -49
- package/src/schema.test.ts +0 -249
- package/src/schema.ts +0 -151
- package/src/services/ai-agent-runner-service.ts +0 -41
- package/src/services/ai-run-state-service.ts +0 -20
- package/src/services/ai-storage-service.ts +0 -39
- package/src/services/content-service.ts +0 -76
- package/src/services/deployment-service.ts +0 -22
- package/src/services/gateway-service.ts +0 -20
- package/src/services/gopass-secrets.ts +0 -98
- package/src/services/in-memory-ai-run-state-service.ts +0 -73
- package/src/services/in-memory-trigger-service.ts +0 -64
- package/src/services/in-memory-workflow-service.test.ts +0 -351
- package/src/services/in-memory-workflow-service.ts +0 -395
- package/src/services/index.ts +0 -56
- package/src/services/jwt-service.ts +0 -30
- package/src/services/local-content.ts +0 -120
- package/src/services/local-gateway-service.ts +0 -62
- package/src/services/local-secrets.test.ts +0 -80
- package/src/services/local-secrets.ts +0 -94
- package/src/services/local-variables.test.ts +0 -61
- package/src/services/local-variables.ts +0 -39
- package/src/services/logger-console.test.ts +0 -118
- package/src/services/logger-console.ts +0 -98
- package/src/services/logger.ts +0 -57
- package/src/services/scheduler-service.ts +0 -86
- package/src/services/schema-service.ts +0 -33
- package/src/services/scoped-secret-service.test.ts +0 -74
- package/src/services/scoped-secret-service.ts +0 -41
- package/src/services/secret-service.ts +0 -38
- package/src/services/trigger-service.ts +0 -17
- package/src/services/typed-secret-service.test.ts +0 -93
- package/src/services/typed-secret-service.ts +0 -70
- package/src/services/typed-variables-service.test.ts +0 -73
- package/src/services/typed-variables-service.ts +0 -81
- package/src/services/user-session-service.test.ts +0 -113
- package/src/services/user-session-service.ts +0 -86
- package/src/services/variables-service.ts +0 -11
- package/src/services/workflow-service.ts +0 -84
- package/src/time-utils.test.ts +0 -56
- package/src/time-utils.ts +0 -107
- package/src/types/core.types.ts +0 -470
- package/src/types/state.types.ts +0 -186
- package/src/utils.test.ts +0 -350
- package/src/utils.ts +0 -129
- package/src/version.test.ts +0 -80
- package/src/version.ts +0 -25
- package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +0 -363
- package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +0 -238
- package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
- package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
- package/src/wirings/ai-agent/ai-agent-memory.ts +0 -309
- package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
- package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
- package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -522
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
- package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -317
- package/src/wirings/ai-agent/ai-agent-runner.ts +0 -251
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -652
- package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1060
- package/src/wirings/ai-agent/ai-agent.types.ts +0 -360
- package/src/wirings/ai-agent/index.ts +0 -41
- package/src/wirings/channel/channel-common.ts +0 -90
- package/src/wirings/channel/channel-handler.ts +0 -241
- package/src/wirings/channel/channel-middleware-runner.ts +0 -120
- package/src/wirings/channel/channel-runner.ts +0 -166
- package/src/wirings/channel/channel-store.ts +0 -29
- package/src/wirings/channel/channel.types.ts +0 -178
- package/src/wirings/channel/define-channel-routes.ts +0 -25
- package/src/wirings/channel/eventhub-service.ts +0 -34
- package/src/wirings/channel/eventhub-store.ts +0 -13
- package/src/wirings/channel/index.ts +0 -24
- package/src/wirings/channel/local/index.ts +0 -3
- package/src/wirings/channel/local/local-channel-handler.ts +0 -79
- package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
- package/src/wirings/channel/local/local-channel-runner.ts +0 -200
- package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
- package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
- package/src/wirings/channel/log-channels.ts +0 -20
- package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
- package/src/wirings/channel/serverless/index.ts +0 -5
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -286
- package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
- package/src/wirings/cli/channel/index.ts +0 -1
- package/src/wirings/cli/cli-runner.test.ts +0 -403
- package/src/wirings/cli/cli-runner.ts +0 -519
- package/src/wirings/cli/cli.types.ts +0 -357
- package/src/wirings/cli/command-parser.test.ts +0 -445
- package/src/wirings/cli/command-parser.ts +0 -504
- package/src/wirings/cli/define-cli-commands.ts +0 -24
- package/src/wirings/cli/index.ts +0 -19
- package/src/wirings/gateway/gateway-runner.test.ts +0 -474
- package/src/wirings/gateway/gateway-runner.ts +0 -411
- package/src/wirings/gateway/gateway.types.ts +0 -149
- package/src/wirings/gateway/index.ts +0 -13
- package/src/wirings/http/http-routes.test.ts +0 -322
- package/src/wirings/http/http-routes.ts +0 -198
- package/src/wirings/http/http-runner.test.ts +0 -144
- package/src/wirings/http/http-runner.ts +0 -563
- package/src/wirings/http/http.types.ts +0 -378
- package/src/wirings/http/index.ts +0 -25
- package/src/wirings/http/log-http-routes.ts +0 -22
- package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
- package/src/wirings/http/pikku-fetch-http-request.ts +0 -166
- package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
- package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
- package/src/wirings/http/routers/http-router.ts +0 -13
- package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
- package/src/wirings/http/routers/path-to-regex.ts +0 -126
- package/src/wirings/mcp/index.ts +0 -27
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
- package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
- package/src/wirings/mcp/mcp-runner.ts +0 -305
- package/src/wirings/mcp/mcp.types.ts +0 -216
- package/src/wirings/node/index.ts +0 -2
- package/src/wirings/node/node.types.ts +0 -23
- package/src/wirings/oauth2/index.ts +0 -3
- package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
- package/src/wirings/oauth2/oauth2-client.ts +0 -335
- package/src/wirings/oauth2/oauth2.types.ts +0 -69
- package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
- package/src/wirings/queue/index.ts +0 -31
- package/src/wirings/queue/queue-runner.test.ts +0 -710
- package/src/wirings/queue/queue-runner.ts +0 -192
- package/src/wirings/queue/queue.types.ts +0 -189
- package/src/wirings/queue/register-queue-helper.ts +0 -60
- package/src/wirings/queue/validate-worker-config.test.ts +0 -108
- package/src/wirings/queue/validate-worker-config.ts +0 -116
- package/src/wirings/rpc/index.ts +0 -4
- package/src/wirings/rpc/rpc-runner.ts +0 -439
- package/src/wirings/rpc/rpc-types.ts +0 -51
- package/src/wirings/rpc/wire-addon.ts +0 -20
- package/src/wirings/scheduler/index.ts +0 -11
- package/src/wirings/scheduler/log-schedulers.ts +0 -20
- package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
- package/src/wirings/scheduler/scheduler-runner.ts +0 -132
- package/src/wirings/scheduler/scheduler.types.ts +0 -53
- package/src/wirings/secret/index.ts +0 -9
- package/src/wirings/secret/secret.types.ts +0 -32
- package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
- package/src/wirings/secret/validate-secret-definitions.ts +0 -82
- package/src/wirings/trigger/index.ts +0 -10
- package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
- package/src/wirings/trigger/trigger-runner.test.ts +0 -79
- package/src/wirings/trigger/trigger-runner.ts +0 -135
- package/src/wirings/trigger/trigger.types.ts +0 -178
- package/src/wirings/variable/index.ts +0 -8
- package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
- package/src/wirings/variable/validate-variable-definitions.ts +0 -69
- package/src/wirings/variable/variable.types.ts +0 -22
- package/src/wirings/workflow/dsl/index.ts +0 -31
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
- package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
- package/src/wirings/workflow/graph/graph-node.ts +0 -222
- package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
- package/src/wirings/workflow/graph/graph-runner.ts +0 -816
- package/src/wirings/workflow/graph/index.ts +0 -14
- package/src/wirings/workflow/graph/template.test.ts +0 -49
- package/src/wirings/workflow/graph/template.ts +0 -42
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
- package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
- package/src/wirings/workflow/index.ts +0 -81
- package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
- package/src/wirings/workflow/pikku-workflow-service.ts +0 -1165
- package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
- package/src/wirings/workflow/workflow-helpers.ts +0 -79
- package/src/wirings/workflow/workflow.types.ts +0 -266
- package/tsconfig.json +0 -14
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { PikkuWire } from '../../types/core.types.js'
|
|
2
|
-
import type {
|
|
3
|
-
CoreTrigger,
|
|
4
|
-
CoreTriggerSource,
|
|
5
|
-
TriggerInstance,
|
|
6
|
-
} from './trigger.types.js'
|
|
7
|
-
import {
|
|
8
|
-
pikkuState,
|
|
9
|
-
getSingletonServices,
|
|
10
|
-
getCreateWireServices,
|
|
11
|
-
} from '../../pikku-state.js'
|
|
12
|
-
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
13
|
-
import { PikkuMissingMetaError } from '../../errors/errors.js'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Registers a trigger with the Pikku framework.
|
|
17
|
-
* Declares a trigger name and its target pikku function.
|
|
18
|
-
* Runs everywhere. Inspector extracts at build time.
|
|
19
|
-
*/
|
|
20
|
-
export const wireTrigger = (trigger: CoreTrigger) => {
|
|
21
|
-
const meta = pikkuState(null, 'trigger', 'meta')
|
|
22
|
-
const triggerMeta = meta[trigger.name]
|
|
23
|
-
if (!triggerMeta) {
|
|
24
|
-
throw new PikkuMissingMetaError(
|
|
25
|
-
`Missing generated metadata for trigger '${trigger.name}'`
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
addFunction(triggerMeta.pikkuFuncId, trigger.func as any)
|
|
30
|
-
|
|
31
|
-
const triggers = pikkuState(null, 'trigger', 'triggers')
|
|
32
|
-
triggers.set(trigger.name, trigger as any)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Registers a trigger source with the Pikku framework.
|
|
37
|
-
* Provides the actual subscription function and input data.
|
|
38
|
-
* Only imported in the trigger worker process.
|
|
39
|
-
*/
|
|
40
|
-
export const wireTriggerSource = <TInput = unknown, TOutput = unknown>(
|
|
41
|
-
source: CoreTriggerSource<TInput, TOutput>
|
|
42
|
-
) => {
|
|
43
|
-
const sourceMeta = pikkuState(null, 'trigger', 'sourceMeta')
|
|
44
|
-
const triggerSourceMeta = sourceMeta[source.name]
|
|
45
|
-
if (!triggerSourceMeta) {
|
|
46
|
-
throw new PikkuMissingMetaError(
|
|
47
|
-
`Missing generated metadata for trigger source '${source.name}'`
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const triggerSources = pikkuState(null, 'trigger', 'triggerSources')
|
|
52
|
-
if (triggerSources.has(source.name)) {
|
|
53
|
-
throw new Error(`Trigger source already exists: ${source.name}`)
|
|
54
|
-
}
|
|
55
|
-
triggerSources.set(source.name, source as any)
|
|
56
|
-
|
|
57
|
-
addFunction(
|
|
58
|
-
triggerSourceMeta.pikkuFuncId,
|
|
59
|
-
source.func as any,
|
|
60
|
-
triggerSourceMeta.packageName
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Parameters for setting up a trigger
|
|
66
|
-
*/
|
|
67
|
-
export type SetupTriggerParams<TInput = unknown, TOutput = unknown> = {
|
|
68
|
-
name: string
|
|
69
|
-
input?: TInput
|
|
70
|
-
onTrigger: (data: TOutput) => void | Promise<void>
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Sets up a registered trigger and starts listening for events.
|
|
75
|
-
* Returns a TriggerInstance with a teardown function.
|
|
76
|
-
*
|
|
77
|
-
* @param name - The trigger name (must be registered via wireTrigger)
|
|
78
|
-
* @param input - The input to pass to the trigger function
|
|
79
|
-
* @param onTrigger - Callback invoked when the trigger fires
|
|
80
|
-
*/
|
|
81
|
-
export async function setupTrigger<TInput = unknown, TOutput = unknown>({
|
|
82
|
-
name,
|
|
83
|
-
input,
|
|
84
|
-
onTrigger,
|
|
85
|
-
}: SetupTriggerParams<TInput, TOutput>): Promise<TriggerInstance> {
|
|
86
|
-
const singletonServices = getSingletonServices()
|
|
87
|
-
const createWireServices = getCreateWireServices()
|
|
88
|
-
const source = pikkuState(null, 'trigger', 'triggerSources').get(name)
|
|
89
|
-
const sourceMeta = pikkuState(null, 'trigger', 'sourceMeta')[name]
|
|
90
|
-
|
|
91
|
-
if (!source) {
|
|
92
|
-
throw new Error(`Trigger source not found: ${name}`)
|
|
93
|
-
}
|
|
94
|
-
if (!sourceMeta) {
|
|
95
|
-
throw new PikkuMissingMetaError(
|
|
96
|
-
`Missing generated metadata for trigger source '${name}'`
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const wire: PikkuWire = {
|
|
101
|
-
trigger: {
|
|
102
|
-
invoke: (data: unknown) => {
|
|
103
|
-
singletonServices.logger.info(`Trigger fired: ${name}`)
|
|
104
|
-
onTrigger(data as TOutput)
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
singletonServices.logger.info(`Setting up trigger: ${name}`)
|
|
110
|
-
|
|
111
|
-
const teardown = await runPikkuFunc('trigger', name, sourceMeta.pikkuFuncId, {
|
|
112
|
-
singletonServices,
|
|
113
|
-
createWireServices,
|
|
114
|
-
auth: false,
|
|
115
|
-
data: () => input as any,
|
|
116
|
-
wire,
|
|
117
|
-
packageName: sourceMeta.packageName || null,
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
return { name, teardown }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Gets all registered triggers
|
|
125
|
-
*/
|
|
126
|
-
export const getRegisteredTriggers = () => {
|
|
127
|
-
return pikkuState(null, 'trigger', 'triggers')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Gets trigger metadata
|
|
132
|
-
*/
|
|
133
|
-
export const getTriggerMeta = () => {
|
|
134
|
-
return pikkuState(null, 'trigger', 'meta')
|
|
135
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CommonWireMeta,
|
|
3
|
-
CoreSingletonServices,
|
|
4
|
-
} from '../../types/core.types.js'
|
|
5
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
6
|
-
import type { CoreNodeConfig } from '../node/node.types.js'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The trigger interaction object passed to trigger functions via the wire.
|
|
10
|
-
* Call trigger() to fire the trigger and start a new workflow/execution.
|
|
11
|
-
*/
|
|
12
|
-
export interface PikkuTrigger<TOutput = unknown> {
|
|
13
|
-
invoke: (data: TOutput) => void
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Metadata for registered triggers stored in state.
|
|
18
|
-
*/
|
|
19
|
-
export type TriggerMeta = Record<string, CommonWireMeta & { name: string }>
|
|
20
|
-
|
|
21
|
-
export type TriggerSourceMeta = Record<
|
|
22
|
-
string,
|
|
23
|
-
{ name: string; pikkuFuncId: string; packageName?: string }
|
|
24
|
-
>
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A trigger function that sets up a subscription and returns a teardown function.
|
|
28
|
-
* The trigger is fired via wire.trigger.invoke(data).
|
|
29
|
-
*
|
|
30
|
-
* @template TInput - Input type (configuration passed when wired)
|
|
31
|
-
* @template TOutput - Output type produced when trigger fires
|
|
32
|
-
* @template Services - Services available to the trigger
|
|
33
|
-
*/
|
|
34
|
-
export type CorePikkuTriggerFunction<
|
|
35
|
-
TInput = unknown,
|
|
36
|
-
TOutput = unknown,
|
|
37
|
-
Services extends CoreSingletonServices = CoreSingletonServices,
|
|
38
|
-
> = (
|
|
39
|
-
services: Services,
|
|
40
|
-
input: TInput,
|
|
41
|
-
wire: { trigger: { invoke: (data: TOutput) => void } }
|
|
42
|
-
) => Promise<() => void | Promise<void>>
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Configuration object for creating a trigger function with metadata
|
|
46
|
-
*/
|
|
47
|
-
export type CorePikkuTriggerFunctionConfig<
|
|
48
|
-
TInput = unknown,
|
|
49
|
-
TOutput = unknown,
|
|
50
|
-
Services extends CoreSingletonServices = CoreSingletonServices,
|
|
51
|
-
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
52
|
-
OutputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
53
|
-
> = {
|
|
54
|
-
/** Optional human-readable title for the trigger */
|
|
55
|
-
title?: string
|
|
56
|
-
/** Optional description of what the trigger does */
|
|
57
|
-
description?: string
|
|
58
|
-
/** Optional tags for categorization */
|
|
59
|
-
tags?: string[]
|
|
60
|
-
/** The trigger function */
|
|
61
|
-
func: CorePikkuTriggerFunction<TInput, TOutput, Services>
|
|
62
|
-
/** Optional Zod schema for input validation */
|
|
63
|
-
input?: InputSchema
|
|
64
|
-
/** Optional Zod schema for output validation */
|
|
65
|
-
output?: OutputSchema
|
|
66
|
-
/** Optional node configuration */
|
|
67
|
-
node?: CoreNodeConfig
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Factory function for creating trigger functions
|
|
72
|
-
* Supports both direct function and configuration object syntax
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // Direct function syntax
|
|
77
|
-
* export const redisSubscribeTrigger = pikkuTriggerFunc<
|
|
78
|
-
* { channel: string },
|
|
79
|
-
* { message: string }
|
|
80
|
-
* >(async ({ redis }, { channel }, { trigger }) => {
|
|
81
|
-
* const subscriber = redis.duplicate()
|
|
82
|
-
* await subscriber.subscribe(channel, (msg) => {
|
|
83
|
-
* trigger.invoke({ message: msg })
|
|
84
|
-
* })
|
|
85
|
-
* return () => subscriber.unsubscribe()
|
|
86
|
-
* })
|
|
87
|
-
*
|
|
88
|
-
* // Configuration object syntax with metadata
|
|
89
|
-
* export const redisSubscribeTrigger = pikkuTriggerFunc({
|
|
90
|
-
* title: 'Redis Subscribe Trigger',
|
|
91
|
-
* description: 'Listens to Redis pub/sub channel',
|
|
92
|
-
* input: z.object({ channel: z.string() }),
|
|
93
|
-
* output: z.object({ message: z.string() }),
|
|
94
|
-
* func: async ({ redis }, { channel }, { trigger }) => {
|
|
95
|
-
* const subscriber = redis.duplicate()
|
|
96
|
-
* await subscriber.subscribe(channel, (msg) => {
|
|
97
|
-
* trigger.invoke({ message: msg })
|
|
98
|
-
* })
|
|
99
|
-
* return () => subscriber.unsubscribe()
|
|
100
|
-
* }
|
|
101
|
-
* })
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
export const pikkuTriggerFunc = <
|
|
105
|
-
TInput = unknown,
|
|
106
|
-
TOutput = unknown,
|
|
107
|
-
Services extends CoreSingletonServices = CoreSingletonServices,
|
|
108
|
-
InputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
109
|
-
OutputSchema extends StandardSchemaV1 | undefined = undefined,
|
|
110
|
-
>(
|
|
111
|
-
triggerOrConfig:
|
|
112
|
-
| CorePikkuTriggerFunction<TInput, TOutput, Services>
|
|
113
|
-
| CorePikkuTriggerFunctionConfig<
|
|
114
|
-
TInput,
|
|
115
|
-
TOutput,
|
|
116
|
-
Services,
|
|
117
|
-
InputSchema,
|
|
118
|
-
OutputSchema
|
|
119
|
-
>
|
|
120
|
-
): CorePikkuTriggerFunctionConfig<
|
|
121
|
-
TInput,
|
|
122
|
-
TOutput,
|
|
123
|
-
Services,
|
|
124
|
-
InputSchema,
|
|
125
|
-
OutputSchema
|
|
126
|
-
> => {
|
|
127
|
-
if (typeof triggerOrConfig === 'function') {
|
|
128
|
-
return { func: triggerOrConfig }
|
|
129
|
-
}
|
|
130
|
-
return triggerOrConfig
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Core trigger definition for registration.
|
|
135
|
-
*
|
|
136
|
-
* @template TInput - Input type (configuration passed when wired)
|
|
137
|
-
* @template TOutput - Output type
|
|
138
|
-
*/
|
|
139
|
-
export interface CoreTrigger<PikkuFunctionConfig = any> {
|
|
140
|
-
/** Unique name for this trigger */
|
|
141
|
-
name: string
|
|
142
|
-
/** The target RPC function to invoke when the trigger fires */
|
|
143
|
-
func: PikkuFunctionConfig
|
|
144
|
-
/** Optional description */
|
|
145
|
-
description?: string
|
|
146
|
-
/** Optional tags for categorization */
|
|
147
|
-
tags?: string[]
|
|
148
|
-
/** Whether this trigger is used by a graph workflow */
|
|
149
|
-
graph?: true
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Represents a trigger instance with teardown capability
|
|
154
|
-
*/
|
|
155
|
-
export interface TriggerInstance {
|
|
156
|
-
name: string
|
|
157
|
-
teardown: () => void | Promise<void>
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* A trigger source that provides the subscription function.
|
|
162
|
-
* Only imported in the trigger worker process.
|
|
163
|
-
*
|
|
164
|
-
* @template TInput - Input type passed to the trigger function
|
|
165
|
-
* @template TOutput - Output type produced when trigger fires
|
|
166
|
-
*/
|
|
167
|
-
export type CoreTriggerSource<TInput = unknown, TOutput = unknown> = {
|
|
168
|
-
/** Must match a wireTrigger name */
|
|
169
|
-
name: string
|
|
170
|
-
/** The trigger function config that sets up the subscription */
|
|
171
|
-
func: CorePikkuTriggerFunctionConfig<
|
|
172
|
-
TInput,
|
|
173
|
-
TOutput,
|
|
174
|
-
CoreSingletonServices,
|
|
175
|
-
StandardSchemaV1 | undefined,
|
|
176
|
-
StandardSchemaV1 | undefined
|
|
177
|
-
>
|
|
178
|
-
} & (unknown extends TInput ? { input?: TInput } : { input: TInput })
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { wireVariable } from './variable.types.js'
|
|
2
|
-
export type {
|
|
3
|
-
CoreVariable,
|
|
4
|
-
VariableDefinitionMeta,
|
|
5
|
-
VariableDefinitionsMeta,
|
|
6
|
-
VariableDefinitions,
|
|
7
|
-
} from './variable.types.js'
|
|
8
|
-
export { validateAndBuildVariableDefinitionsMeta } from './validate-variable-definitions.js'
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { describe, test } from 'node:test'
|
|
2
|
-
import assert from 'node:assert'
|
|
3
|
-
import { validateAndBuildVariableDefinitionsMeta } from './validate-variable-definitions.js'
|
|
4
|
-
|
|
5
|
-
describe('validateAndBuildVariableDefinitionsMeta', () => {
|
|
6
|
-
test('should build meta from single definition', () => {
|
|
7
|
-
const definitions = [
|
|
8
|
-
{
|
|
9
|
-
name: 'dbUrl',
|
|
10
|
-
displayName: 'Database URL',
|
|
11
|
-
description: 'Connection string',
|
|
12
|
-
variableId: 'DB_URL',
|
|
13
|
-
sourceFile: 'a.ts',
|
|
14
|
-
},
|
|
15
|
-
]
|
|
16
|
-
const result = validateAndBuildVariableDefinitionsMeta(
|
|
17
|
-
definitions as any,
|
|
18
|
-
new Map()
|
|
19
|
-
)
|
|
20
|
-
assert.ok(result['dbUrl'])
|
|
21
|
-
assert.strictEqual(result['dbUrl'].variableId, 'DB_URL')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
test('should allow duplicate variableId with same schema', () => {
|
|
25
|
-
const schemaLookup = new Map([
|
|
26
|
-
['schema1', { variableName: 'Schema', sourceFile: 'types.ts' }],
|
|
27
|
-
])
|
|
28
|
-
const definitions = [
|
|
29
|
-
{
|
|
30
|
-
name: 'var1',
|
|
31
|
-
displayName: 'Var 1',
|
|
32
|
-
description: 'd',
|
|
33
|
-
variableId: 'SHARED',
|
|
34
|
-
schema: 'schema1',
|
|
35
|
-
sourceFile: 'a.ts',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'var2',
|
|
39
|
-
displayName: 'Var 2',
|
|
40
|
-
description: 'd',
|
|
41
|
-
variableId: 'SHARED',
|
|
42
|
-
schema: 'schema1',
|
|
43
|
-
sourceFile: 'b.ts',
|
|
44
|
-
},
|
|
45
|
-
]
|
|
46
|
-
const result = validateAndBuildVariableDefinitionsMeta(
|
|
47
|
-
definitions as any,
|
|
48
|
-
schemaLookup
|
|
49
|
-
)
|
|
50
|
-
assert.ok(result['var1'])
|
|
51
|
-
assert.ok(result['var2'])
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test('should throw when duplicate variableId has different schemas', () => {
|
|
55
|
-
const schemaLookup = new Map([
|
|
56
|
-
['schema1', { variableName: 'SchemaA', sourceFile: 'types.ts' }],
|
|
57
|
-
['schema2', { variableName: 'SchemaB', sourceFile: 'types2.ts' }],
|
|
58
|
-
])
|
|
59
|
-
const definitions = [
|
|
60
|
-
{
|
|
61
|
-
name: 'var1',
|
|
62
|
-
displayName: 'Var 1',
|
|
63
|
-
description: 'd',
|
|
64
|
-
variableId: 'SHARED',
|
|
65
|
-
schema: 'schema1',
|
|
66
|
-
sourceFile: 'a.ts',
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: 'var2',
|
|
70
|
-
displayName: 'Var 2',
|
|
71
|
-
description: 'd',
|
|
72
|
-
variableId: 'SHARED',
|
|
73
|
-
schema: 'schema2',
|
|
74
|
-
sourceFile: 'b.ts',
|
|
75
|
-
},
|
|
76
|
-
]
|
|
77
|
-
assert.throws(
|
|
78
|
-
() =>
|
|
79
|
-
validateAndBuildVariableDefinitionsMeta(
|
|
80
|
-
definitions as any,
|
|
81
|
-
schemaLookup
|
|
82
|
-
),
|
|
83
|
-
(err: any) => err.message.includes('different schemas')
|
|
84
|
-
)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('should handle empty definitions', () => {
|
|
88
|
-
const result = validateAndBuildVariableDefinitionsMeta([], new Map())
|
|
89
|
-
assert.deepStrictEqual(result, {})
|
|
90
|
-
})
|
|
91
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
VariableDefinitions,
|
|
3
|
-
VariableDefinitionsMeta,
|
|
4
|
-
} from './variable.types.js'
|
|
5
|
-
|
|
6
|
-
export interface SchemaRefLike {
|
|
7
|
-
variableName: string
|
|
8
|
-
sourceFile: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function validateAndBuildVariableDefinitionsMeta(
|
|
12
|
-
definitions: VariableDefinitions,
|
|
13
|
-
schemaLookup: Map<string, SchemaRefLike>
|
|
14
|
-
): VariableDefinitionsMeta {
|
|
15
|
-
const meta: VariableDefinitionsMeta = {}
|
|
16
|
-
const variableIdToDefinition: Map<string, VariableDefinitions[0]> = new Map()
|
|
17
|
-
|
|
18
|
-
for (const def of definitions) {
|
|
19
|
-
const existingDef = variableIdToDefinition.get(def.variableId)
|
|
20
|
-
|
|
21
|
-
if (existingDef) {
|
|
22
|
-
if (def.schema && existingDef.schema) {
|
|
23
|
-
const defSchemaRef = schemaLookup.get(def.schema as string)
|
|
24
|
-
const existingSchemaRef = schemaLookup.get(existingDef.schema as string)
|
|
25
|
-
|
|
26
|
-
if (defSchemaRef && existingSchemaRef) {
|
|
27
|
-
if (
|
|
28
|
-
defSchemaRef.variableName !== existingSchemaRef.variableName ||
|
|
29
|
-
defSchemaRef.sourceFile !== existingSchemaRef.sourceFile
|
|
30
|
-
) {
|
|
31
|
-
throw new Error(
|
|
32
|
-
`Variable '${def.variableId}' is defined with different schemas.\n` +
|
|
33
|
-
` First definition: ${existingDef.sourceFile} (schema: ${existingSchemaRef.variableName})\n` +
|
|
34
|
-
` Second definition: ${def.sourceFile} (schema: ${defSchemaRef.variableName})\n` +
|
|
35
|
-
`Variables sharing a variableId must use the same schema.`
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!meta[def.name]) {
|
|
42
|
-
meta[def.name] = {
|
|
43
|
-
name: def.name,
|
|
44
|
-
displayName: def.displayName,
|
|
45
|
-
description: def.description,
|
|
46
|
-
variableId: def.variableId,
|
|
47
|
-
schema: def.schema,
|
|
48
|
-
sourceFile: def.sourceFile,
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
continue
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
variableIdToDefinition.set(def.variableId, def)
|
|
55
|
-
|
|
56
|
-
if (!meta[def.name]) {
|
|
57
|
-
meta[def.name] = {
|
|
58
|
-
name: def.name,
|
|
59
|
-
displayName: def.displayName,
|
|
60
|
-
description: def.description,
|
|
61
|
-
variableId: def.variableId,
|
|
62
|
-
schema: def.schema,
|
|
63
|
-
sourceFile: def.sourceFile,
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return meta
|
|
69
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type CoreVariable<T = unknown> = {
|
|
2
|
-
name: string
|
|
3
|
-
displayName: string
|
|
4
|
-
description?: string
|
|
5
|
-
variableId: string
|
|
6
|
-
schema: T
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type VariableDefinitionMeta = {
|
|
10
|
-
name: string
|
|
11
|
-
displayName: string
|
|
12
|
-
description?: string
|
|
13
|
-
variableId: string
|
|
14
|
-
schema?: Record<string, unknown> | string
|
|
15
|
-
sourceFile?: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type VariableDefinitionsMeta = Record<string, VariableDefinitionMeta>
|
|
19
|
-
|
|
20
|
-
export type VariableDefinitions = VariableDefinitionMeta[]
|
|
21
|
-
|
|
22
|
-
export const wireVariable = <T>(_config: CoreVariable<T>): void => {}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DSL (Domain Specific Language) workflow exports
|
|
3
|
-
*/
|
|
4
|
-
export { addWorkflow } from './workflow-runner.js'
|
|
5
|
-
|
|
6
|
-
export type {
|
|
7
|
-
WorkflowStepOptions,
|
|
8
|
-
WorkflowWireDoRPC,
|
|
9
|
-
WorkflowWireDoInline,
|
|
10
|
-
WorkflowWireSleep,
|
|
11
|
-
WorkflowWireSuspend,
|
|
12
|
-
InputSource,
|
|
13
|
-
OutputBinding,
|
|
14
|
-
RpcStepMeta,
|
|
15
|
-
SimpleCondition,
|
|
16
|
-
Condition,
|
|
17
|
-
BranchStepMeta,
|
|
18
|
-
ParallelGroupStepMeta,
|
|
19
|
-
FanoutStepMeta,
|
|
20
|
-
ReturnStepMeta,
|
|
21
|
-
InlineStepMeta,
|
|
22
|
-
SleepStepMeta,
|
|
23
|
-
CancelStepMeta,
|
|
24
|
-
SwitchCaseMeta,
|
|
25
|
-
SwitchStepMeta,
|
|
26
|
-
FilterStepMeta,
|
|
27
|
-
ArrayPredicateStepMeta,
|
|
28
|
-
WorkflowStepMeta,
|
|
29
|
-
WorkflowStepWire,
|
|
30
|
-
PikkuWorkflowWire,
|
|
31
|
-
} from './workflow-dsl.types.js'
|