@pikku/core 0.11.0 → 0.11.2

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.
Files changed (184) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/dist/errors/error-handler.js +3 -3
  3. package/dist/errors/errors.d.ts +1 -1
  4. package/dist/errors/errors.js +3 -3
  5. package/dist/function/function-runner.d.ts +8 -8
  6. package/dist/function/function-runner.js +88 -23
  7. package/dist/function/functions.types.d.ts +104 -33
  8. package/dist/function/functions.types.js +50 -7
  9. package/dist/handle-error.d.ts +1 -1
  10. package/dist/handle-error.js +1 -1
  11. package/dist/index.d.ts +6 -2
  12. package/dist/index.js +5 -2
  13. package/dist/middleware/auth-apikey.d.ts +1 -1
  14. package/dist/middleware/auth-apikey.js +3 -3
  15. package/dist/middleware/auth-bearer.d.ts +1 -1
  16. package/dist/middleware/auth-bearer.js +3 -3
  17. package/dist/middleware/auth-cookie.d.ts +1 -1
  18. package/dist/middleware/auth-cookie.js +5 -5
  19. package/dist/middleware/timeout.d.ts +1 -1
  20. package/dist/middleware/timeout.js +3 -2
  21. package/dist/middleware-runner.d.ts +6 -20
  22. package/dist/middleware-runner.js +19 -20
  23. package/dist/permissions.d.ts +6 -89
  24. package/dist/permissions.js +24 -81
  25. package/dist/pikku-state.d.ts +32 -104
  26. package/dist/pikku-state.js +140 -66
  27. package/dist/schema.d.ts +8 -6
  28. package/dist/schema.js +25 -13
  29. package/dist/services/user-session-service.d.ts +7 -3
  30. package/dist/services/user-session-service.js +8 -1
  31. package/dist/services/workflow-service.d.ts +38 -0
  32. package/dist/services/workflow-service.js +1 -0
  33. package/dist/types/core.types.d.ts +40 -41
  34. package/dist/types/core.types.js +4 -15
  35. package/dist/types/state.types.d.ts +135 -0
  36. package/dist/types/state.types.js +1 -0
  37. package/dist/utils.d.ts +9 -1
  38. package/dist/utils.js +48 -3
  39. package/dist/wirings/channel/channel-common.js +2 -3
  40. package/dist/wirings/channel/channel-handler.d.ts +3 -2
  41. package/dist/wirings/channel/channel-handler.js +7 -10
  42. package/dist/wirings/channel/channel-runner.d.ts +2 -2
  43. package/dist/wirings/channel/channel-runner.js +5 -5
  44. package/dist/wirings/channel/channel.types.d.ts +10 -5
  45. package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
  46. package/dist/wirings/channel/local/local-channel-runner.js +19 -26
  47. package/dist/wirings/channel/log-channels.js +1 -1
  48. package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
  49. package/dist/wirings/channel/serverless/serverless-channel-runner.js +43 -48
  50. package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
  51. package/dist/wirings/cli/cli-runner.d.ts +5 -5
  52. package/dist/wirings/cli/cli-runner.js +20 -38
  53. package/dist/wirings/cli/cli.types.d.ts +16 -11
  54. package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
  55. package/dist/wirings/forge-node/forge-node.types.js +38 -0
  56. package/dist/wirings/forge-node/index.d.ts +1 -0
  57. package/dist/wirings/forge-node/index.js +1 -0
  58. package/dist/wirings/http/http-runner.d.ts +8 -8
  59. package/dist/wirings/http/http-runner.js +46 -51
  60. package/dist/wirings/http/http.types.d.ts +19 -11
  61. package/dist/wirings/http/log-http-routes.js +1 -1
  62. package/dist/wirings/http/routers/path-to-regex.js +2 -2
  63. package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
  64. package/dist/wirings/mcp/mcp-runner.js +33 -40
  65. package/dist/wirings/mcp/mcp.types.d.ts +6 -0
  66. package/dist/wirings/queue/queue-runner.d.ts +3 -3
  67. package/dist/wirings/queue/queue-runner.js +13 -23
  68. package/dist/wirings/queue/queue.types.d.ts +4 -11
  69. package/dist/wirings/rpc/index.d.ts +1 -1
  70. package/dist/wirings/rpc/index.js +1 -1
  71. package/dist/wirings/rpc/rpc-runner.d.ts +17 -16
  72. package/dist/wirings/rpc/rpc-runner.js +98 -61
  73. package/dist/wirings/rpc/rpc-types.d.ts +7 -0
  74. package/dist/wirings/scheduler/log-schedulers.js +1 -1
  75. package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
  76. package/dist/wirings/scheduler/scheduler-runner.js +18 -29
  77. package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
  78. package/dist/wirings/trigger/index.d.ts +2 -0
  79. package/dist/wirings/trigger/index.js +2 -0
  80. package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
  81. package/dist/wirings/trigger/trigger-runner.js +57 -0
  82. package/dist/wirings/trigger/trigger.types.d.ts +42 -0
  83. package/dist/wirings/trigger/trigger.types.js +1 -0
  84. package/dist/wirings/workflow/dsl/index.d.ts +5 -0
  85. package/dist/wirings/workflow/dsl/index.js +4 -0
  86. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
  87. package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
  88. package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
  89. package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
  90. package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
  91. package/dist/wirings/workflow/graph/graph-node.js +58 -0
  92. package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
  93. package/dist/wirings/workflow/graph/graph-runner.js +452 -0
  94. package/dist/wirings/workflow/graph/index.d.ts +3 -0
  95. package/dist/wirings/workflow/graph/index.js +3 -0
  96. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
  97. package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
  98. package/dist/wirings/workflow/index.d.ts +7 -3
  99. package/dist/wirings/workflow/index.js +6 -3
  100. package/dist/wirings/workflow/pikku-workflow-service.d.ts +108 -10
  101. package/dist/wirings/workflow/pikku-workflow-service.js +274 -165
  102. package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
  103. package/dist/wirings/workflow/wire-workflow.js +53 -0
  104. package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
  105. package/dist/wirings/workflow/workflow-utils.js +66 -0
  106. package/dist/wirings/workflow/workflow.types.d.ts +135 -128
  107. package/package.json +11 -2
  108. package/src/errors/error-handler.ts +3 -3
  109. package/src/errors/errors.ts +3 -3
  110. package/src/factory-functions.test.ts +9 -36
  111. package/src/function/function-runner.test.ts +58 -69
  112. package/src/function/function-runner.ts +130 -37
  113. package/src/function/functions.types.ts +193 -54
  114. package/src/handle-error.ts +1 -1
  115. package/src/index.ts +10 -5
  116. package/src/middleware/auth-apikey.test.ts +360 -0
  117. package/src/middleware/auth-apikey.ts +3 -7
  118. package/src/middleware/auth-bearer.test.ts +447 -0
  119. package/src/middleware/auth-bearer.ts +27 -33
  120. package/src/middleware/auth-cookie.test.ts +525 -0
  121. package/src/middleware/auth-cookie.ts +6 -6
  122. package/src/middleware/timeout.ts +4 -2
  123. package/src/middleware-runner.test.ts +58 -127
  124. package/src/middleware-runner.ts +29 -25
  125. package/src/permissions.test.ts +68 -130
  126. package/src/permissions.ts +41 -100
  127. package/src/pikku-state.ts +156 -201
  128. package/src/schema.ts +42 -13
  129. package/src/services/user-session-service.ts +14 -4
  130. package/src/services/workflow-service.ts +74 -0
  131. package/src/types/core.types.ts +79 -58
  132. package/src/types/state.types.ts +195 -0
  133. package/src/utils.ts +59 -4
  134. package/src/wirings/channel/channel-common.ts +4 -7
  135. package/src/wirings/channel/channel-handler.ts +17 -23
  136. package/src/wirings/channel/channel-runner.ts +7 -7
  137. package/src/wirings/channel/channel.types.ts +14 -11
  138. package/src/wirings/channel/local/local-channel-runner.test.ts +8 -4
  139. package/src/wirings/channel/local/local-channel-runner.ts +23 -38
  140. package/src/wirings/channel/log-channels.ts +1 -1
  141. package/src/wirings/channel/serverless/serverless-channel-runner.ts +53 -79
  142. package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
  143. package/src/wirings/cli/cli-runner.test.ts +26 -26
  144. package/src/wirings/cli/cli-runner.ts +34 -71
  145. package/src/wirings/cli/cli.types.ts +23 -16
  146. package/src/wirings/forge-node/forge-node.types.ts +135 -0
  147. package/src/wirings/forge-node/index.ts +1 -0
  148. package/src/wirings/http/http-runner.test.ts +10 -10
  149. package/src/wirings/http/http-runner.ts +56 -66
  150. package/src/wirings/http/http.types.ts +19 -14
  151. package/src/wirings/http/log-http-routes.ts +1 -1
  152. package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
  153. package/src/wirings/http/routers/path-to-regex.ts +2 -2
  154. package/src/wirings/mcp/mcp-runner.ts +44 -69
  155. package/src/wirings/mcp/mcp.types.ts +6 -0
  156. package/src/wirings/queue/queue-runner.test.ts +641 -0
  157. package/src/wirings/queue/queue-runner.ts +16 -38
  158. package/src/wirings/queue/queue.types.ts +4 -11
  159. package/src/wirings/rpc/index.ts +1 -1
  160. package/src/wirings/rpc/rpc-runner.ts +129 -77
  161. package/src/wirings/rpc/rpc-types.ts +8 -0
  162. package/src/wirings/scheduler/log-schedulers.ts +1 -1
  163. package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
  164. package/src/wirings/scheduler/scheduler-runner.ts +29 -55
  165. package/src/wirings/scheduler/scheduler.types.ts +3 -9
  166. package/src/wirings/trigger/index.ts +2 -0
  167. package/src/wirings/trigger/trigger-runner.ts +96 -0
  168. package/src/wirings/trigger/trigger.types.ts +56 -0
  169. package/src/wirings/workflow/dsl/index.ts +30 -0
  170. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
  171. package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
  172. package/src/wirings/workflow/graph/graph-node.ts +227 -0
  173. package/src/wirings/workflow/graph/graph-runner.ts +694 -0
  174. package/src/wirings/workflow/graph/index.ts +3 -0
  175. package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
  176. package/src/wirings/workflow/index.ts +60 -12
  177. package/src/wirings/workflow/pikku-workflow-service.ts +401 -195
  178. package/src/wirings/workflow/wire-workflow.ts +94 -0
  179. package/src/wirings/workflow/workflow-utils.ts +120 -0
  180. package/src/wirings/workflow/workflow.types.ts +167 -188
  181. package/tsconfig.tsbuildinfo +1 -1
  182. package/dist/wirings/workflow/workflow-runner.d.ts +0 -35
  183. package/dist/wirings/workflow/workflow-runner.js +0 -68
  184. package/src/wirings/workflow/workflow-runner.ts +0 -85
@@ -1,18 +1,16 @@
1
1
  import {
2
- PikkuInteraction,
3
- PikkuWiringTypes,
2
+ PikkuWire,
4
3
  type CoreServices,
5
4
  type CoreSingletonServices,
6
5
  type CoreUserSession,
7
- type CreateSessionServices,
6
+ type CreateWireServices,
8
7
  } from '../../types/core.types.js'
9
8
  import type { CoreScheduledTask } from './scheduler.types.js'
10
9
  import { getErrorResponse, PikkuError } from '../../errors/error-handler.js'
11
- import { closeSessionServices } from '../../utils.js'
10
+ import { closeWireServices } from '../../utils.js'
12
11
  import { pikkuState } from '../../pikku-state.js'
13
12
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
14
- import { rpcService } from '../rpc/rpc-runner.js'
15
- import { PikkuUserSessionService } from '../../services/user-session-service.js'
13
+ import { PikkuSessionService } from '../../services/user-session-service.js'
16
14
  import {
17
15
  CorePikkuFunctionConfig,
18
16
  CorePikkuFunctionSessionless,
@@ -22,7 +20,7 @@ export type RunScheduledTasksParams = {
22
20
  name: string
23
21
  session?: CoreUserSession
24
22
  singletonServices: CoreSingletonServices
25
- createSessionServices?: CreateSessionServices<
23
+ createWireServices?: CreateWireServices<
26
24
  CoreSingletonServices,
27
25
  CoreServices<CoreSingletonServices>,
28
26
  CoreUserSession
@@ -36,7 +34,7 @@ export const wireScheduler = <
36
34
  >(
37
35
  scheduledTask: CoreScheduledTask<PikkuFunctionConfig>
38
36
  ) => {
39
- const meta = pikkuState('scheduler', 'meta')
37
+ const meta = pikkuState(null, 'scheduler', 'meta')
40
38
  const taskMeta = meta[scheduledTask.name]
41
39
  if (!taskMeta) {
42
40
  throw new Error('Task metadata not found')
@@ -45,12 +43,11 @@ export const wireScheduler = <
45
43
  func: scheduledTask.func.func,
46
44
  auth: scheduledTask.func.auth,
47
45
  permissions: scheduledTask.func.permissions,
48
- middleware: scheduledTask.func.middleware as any,
46
+ middleware: scheduledTask.func.middleware,
49
47
  tags: scheduledTask.func.tags,
50
- docs: scheduledTask.func.docs as any,
51
48
  })
52
49
 
53
- const tasks = pikkuState('scheduler', 'tasks')
50
+ const tasks = pikkuState(null, 'scheduler', 'tasks')
54
51
  if (tasks.has(scheduledTask.name)) {
55
52
  throw new Error(`Scheduled task already exists: ${scheduledTask.name}`)
56
53
  }
@@ -76,13 +73,13 @@ export async function runScheduledTask({
76
73
  name,
77
74
  session,
78
75
  singletonServices,
79
- createSessionServices,
76
+ createWireServices,
80
77
  }: RunScheduledTasksParams): Promise<void> {
81
- let sessionServices: any
82
- const task = pikkuState('scheduler', 'tasks').get(name)
83
- const meta = pikkuState('scheduler', 'meta')[name]
78
+ let wireServices: any
79
+ const task = pikkuState(null, 'scheduler', 'tasks').get(name)
80
+ const meta = pikkuState(null, 'scheduler', 'meta')[name]
84
81
 
85
- const userSession = new PikkuUserSessionService()
82
+ const userSession = new PikkuSessionService()
86
83
  if (session) {
87
84
  userSession.set(session)
88
85
  }
@@ -96,8 +93,8 @@ export async function runScheduledTask({
96
93
  )
97
94
  }
98
95
 
99
- // Create the scheduled task interaction object
100
- const interaction: PikkuInteraction = {
96
+ // Create the scheduled task wire object
97
+ const wire: PikkuWire = {
101
98
  scheduledTask: {
102
99
  name,
103
100
  schedule: task.schedule,
@@ -106,6 +103,7 @@ export async function runScheduledTask({
106
103
  throw new ScheduledTaskSkippedError(name, reason)
107
104
  },
108
105
  },
106
+ session: userSession,
109
107
  }
110
108
 
111
109
  try {
@@ -113,40 +111,16 @@ export async function runScheduledTask({
113
111
  `Running schedule task: ${name} | schedule: ${task.schedule}`
114
112
  )
115
113
 
116
- const getAllServices = async () => {
117
- sessionServices = await createSessionServices?.(
118
- singletonServices,
119
- interaction,
120
- session
121
- )
122
-
123
- return rpcService.injectRPCService(
124
- {
125
- ...singletonServices,
126
- ...sessionServices,
127
- },
128
- interaction
129
- )
130
- }
131
-
132
- const result = await runPikkuFunc(
133
- PikkuWiringTypes.scheduler,
134
- meta.name,
135
- meta.pikkuFuncName,
136
- {
137
- singletonServices,
138
- getAllServices,
139
- userSession,
140
- auth: false,
141
- data: () => undefined,
142
- inheritedMiddleware: meta.middleware,
143
- wireMiddleware: task.middleware,
144
- tags: task.tags,
145
- interaction,
146
- }
147
- )
148
-
149
- return result
114
+ await runPikkuFunc('scheduler', meta.name, meta.pikkuFuncName, {
115
+ singletonServices,
116
+ createWireServices,
117
+ auth: false,
118
+ data: () => undefined,
119
+ inheritedMiddleware: meta.middleware,
120
+ wireMiddleware: task.middleware,
121
+ tags: task.tags,
122
+ wire,
123
+ })
150
124
  } catch (e: any) {
151
125
  const errorResponse = getErrorResponse(e)
152
126
  if (errorResponse != null) {
@@ -154,12 +128,12 @@ export async function runScheduledTask({
154
128
  }
155
129
  throw e
156
130
  } finally {
157
- if (sessionServices) {
158
- await closeSessionServices(singletonServices.logger, sessionServices)
131
+ if (wireServices) {
132
+ await closeWireServices(singletonServices.logger, wireServices)
159
133
  }
160
134
  }
161
135
  }
162
136
 
163
137
  export const getScheduledTasks = () => {
164
- return pikkuState('scheduler', 'tasks')
138
+ return pikkuState(null, 'scheduler', 'tasks')
165
139
  }
@@ -1,8 +1,7 @@
1
1
  import {
2
- PikkuDocs,
3
2
  CoreUserSession,
4
3
  CorePikkuMiddleware,
5
- MiddlewareMetadata,
4
+ CommonWireMeta,
6
5
  } from '../../types/core.types.js'
7
6
  import {
8
7
  CorePikkuFunctionConfig,
@@ -15,14 +14,10 @@ import {
15
14
  export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> =
16
15
  Record<
17
16
  string,
18
- {
19
- pikkuFuncName: string
17
+ CommonWireMeta & {
20
18
  name: string
21
19
  schedule: string
22
20
  session?: UserSession
23
- docs?: PikkuDocs
24
- tags?: string[]
25
- middleware?: MiddlewareMetadata[] // Pre-resolved middleware chain (tag + explicit)
26
21
  }
27
22
  >
28
23
 
@@ -38,13 +33,12 @@ export type CoreScheduledTask<
38
33
  name: string
39
34
  schedule: string
40
35
  func: PikkuFunctionConfig
41
- docs?: PikkuDocs
42
36
  tags?: string[]
43
37
  middleware?: PikkuMiddleware[]
44
38
  }
45
39
 
46
40
  /**
47
- * Represents a scheduled task interaction object for middleware
41
+ * Represents a scheduled task wire object for middleware
48
42
  * Provides information about the current scheduled task execution
49
43
  */
50
44
  export interface PikkuScheduledTask {
@@ -0,0 +1,2 @@
1
+ export * from './trigger.types.js'
2
+ export * from './trigger-runner.js'
@@ -0,0 +1,96 @@
1
+ import type { CoreSingletonServices } from '../../types/core.types.js'
2
+ import type { CoreTrigger, TriggerInstance } from './trigger.types.js'
3
+ import { pikkuState } from '../../pikku-state.js'
4
+ import type { CorePikkuTriggerFunctionConfig } from '../../function/functions.types.js'
5
+
6
+ /**
7
+ * Registers a trigger with the Pikku framework.
8
+ * The trigger will be available for setup via setupTrigger.
9
+ */
10
+ export const wireTrigger = <
11
+ TConfig = unknown,
12
+ TOutput = unknown,
13
+ TriggerFunctionConfig extends CorePikkuTriggerFunctionConfig<
14
+ TConfig,
15
+ TOutput
16
+ > = CorePikkuTriggerFunctionConfig<TConfig, TOutput>,
17
+ >(
18
+ trigger: CoreTrigger<TConfig, TOutput, TriggerFunctionConfig>
19
+ ) => {
20
+ const meta = pikkuState(null, 'trigger', 'meta')
21
+ const triggerMeta = meta[trigger.name]
22
+ if (!triggerMeta) {
23
+ throw new Error(`Trigger metadata not found: ${trigger.name}`)
24
+ }
25
+
26
+ const triggers = pikkuState(null, 'trigger', 'triggers')
27
+ if (triggers.has(trigger.name)) {
28
+ throw new Error(`Trigger already exists: ${trigger.name}`)
29
+ }
30
+ triggers.set(trigger.name, trigger as any)
31
+ }
32
+
33
+ /**
34
+ * Parameters for setting up a trigger
35
+ */
36
+ export type SetupTriggerParams<TOutput = unknown> = {
37
+ name: string
38
+ singletonServices: CoreSingletonServices
39
+ onTrigger: (data: TOutput) => void | Promise<void>
40
+ }
41
+
42
+ /**
43
+ * Sets up a registered trigger and starts listening for events.
44
+ * Returns a TriggerInstance with a teardown function.
45
+ */
46
+ export async function setupTrigger<TOutput = unknown>({
47
+ name,
48
+ singletonServices,
49
+ onTrigger,
50
+ }: SetupTriggerParams<TOutput>): Promise<TriggerInstance> {
51
+ const trigger = pikkuState(null, 'trigger', 'triggers').get(name)
52
+ const meta = pikkuState(null, 'trigger', 'meta')[name]
53
+
54
+ if (!trigger) {
55
+ throw new Error(`Trigger not found: ${name}`)
56
+ }
57
+ if (!meta) {
58
+ throw new Error(`Trigger metadata not found: ${name}`)
59
+ }
60
+
61
+ const wire = {
62
+ trigger: {
63
+ trigger: (data: TOutput) => {
64
+ singletonServices.logger.info(`Trigger fired: ${name}`)
65
+ onTrigger(data)
66
+ },
67
+ },
68
+ }
69
+
70
+ singletonServices.logger.info(`Setting up trigger: ${name}`)
71
+
72
+ const teardown = await trigger.func.func(
73
+ singletonServices,
74
+ trigger.config,
75
+ wire as any
76
+ )
77
+
78
+ return {
79
+ name,
80
+ teardown,
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Gets all registered triggers
86
+ */
87
+ export const getRegisteredTriggers = () => {
88
+ return pikkuState(null, 'trigger', 'triggers')
89
+ }
90
+
91
+ /**
92
+ * Gets trigger metadata
93
+ */
94
+ export const getTriggerMeta = () => {
95
+ return pikkuState(null, 'trigger', 'meta')
96
+ }
@@ -0,0 +1,56 @@
1
+ import type { CorePikkuTriggerFunctionConfig } from '../../function/functions.types.js'
2
+
3
+ /**
4
+ * The trigger interaction object passed to trigger functions via the wire.
5
+ * Call trigger() to fire the trigger and start a new workflow/execution.
6
+ */
7
+ export interface PikkuTrigger<TOutput = unknown> {
8
+ trigger: (data: TOutput) => void
9
+ }
10
+
11
+ /**
12
+ * Metadata for registered triggers stored in state.
13
+ */
14
+ export type TriggerMeta = Record<
15
+ string,
16
+ {
17
+ pikkuFuncName: string
18
+ name: string
19
+ description?: string
20
+ tags?: string[]
21
+ }
22
+ >
23
+
24
+ /**
25
+ * Core trigger definition for registration.
26
+ *
27
+ * @template TConfig - Configuration type
28
+ * @template TOutput - Output type
29
+ */
30
+ export interface CoreTrigger<
31
+ TConfig = unknown,
32
+ TOutput = unknown,
33
+ TriggerFunctionConfig extends CorePikkuTriggerFunctionConfig<
34
+ TConfig,
35
+ TOutput
36
+ > = CorePikkuTriggerFunctionConfig<TConfig, TOutput>,
37
+ > {
38
+ /** Unique name for this trigger */
39
+ name: string
40
+ /** The trigger function configuration */
41
+ func: TriggerFunctionConfig
42
+ /** Configuration to pass to the trigger function */
43
+ config: TConfig
44
+ /** Optional description */
45
+ description?: string
46
+ /** Optional tags for categorization */
47
+ tags?: string[]
48
+ }
49
+
50
+ /**
51
+ * Represents a trigger instance with teardown capability
52
+ */
53
+ export interface TriggerInstance {
54
+ name: string
55
+ teardown: () => void | Promise<void>
56
+ }
@@ -0,0 +1,30 @@
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
+ InputSource,
12
+ OutputBinding,
13
+ RpcStepMeta,
14
+ SimpleCondition,
15
+ Condition,
16
+ BranchStepMeta,
17
+ ParallelGroupStepMeta,
18
+ FanoutStepMeta,
19
+ ReturnStepMeta,
20
+ InlineStepMeta,
21
+ SleepStepMeta,
22
+ CancelStepMeta,
23
+ SwitchCaseMeta,
24
+ SwitchStepMeta,
25
+ FilterStepMeta,
26
+ ArrayPredicateStepMeta,
27
+ WorkflowStepMeta,
28
+ WorkflowStepWire,
29
+ PikkuWorkflowWire,
30
+ } from './workflow-dsl.types.js'
@@ -0,0 +1,312 @@
1
+ /**
2
+ * DSL (Domain Specific Language) workflow types
3
+ * These types define the step-based workflow format extracted by the inspector
4
+ */
5
+
6
+ import type { WorkflowRun } from '../workflow.types.js'
7
+
8
+ /**
9
+ * Workflow step options
10
+ */
11
+ export interface WorkflowStepOptions {
12
+ /** Display name for logs/UI (optional, doesn't affect execution) */
13
+ description?: string
14
+ /** Number of retry attempts for failed steps (only applies to local execution) */
15
+ retries?: number
16
+ /** Delay between retry attempts (e.g., '1s', '2s', '2min') */
17
+ retryDelay?: string | number
18
+ // Future: timeout, failFast, priority
19
+ }
20
+
21
+ /**
22
+ * Type signature for workflow.do() RPC form - used by inspector
23
+ */
24
+ export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(
25
+ stepName: string,
26
+ rpcName: string,
27
+ data: TInput,
28
+ options?: WorkflowStepOptions
29
+ ) => Promise<TOutput>
30
+
31
+ /**
32
+ * Type signature for workflow.do() inline form - used by inspector
33
+ */
34
+ export type WorkflowWireDoInline = <T>(
35
+ stepName: string,
36
+ fn: () => Promise<T> | T,
37
+ options?: WorkflowStepOptions
38
+ ) => Promise<T>
39
+
40
+ /**
41
+ * Type signature for workflow.sleep() - used by inspector
42
+ */
43
+ export type WorkflowWireSleep = (
44
+ stepName: string,
45
+ duration: string
46
+ ) => Promise<void>
47
+
48
+ /**
49
+ * Input source for step arguments in DSL workflows
50
+ */
51
+ export type InputSource =
52
+ | { from: 'input'; path: string }
53
+ | { from: 'outputVar'; name: string; path?: string }
54
+ | { from: 'item'; path: string }
55
+ | { from: 'literal'; value: unknown }
56
+ | { from: 'template'; parts: string[]; expressions: InputSource[] }
57
+
58
+ /**
59
+ * Output binding for return statements in DSL workflows
60
+ */
61
+ export type OutputBinding =
62
+ | { from: 'outputVar'; name: string; path?: string }
63
+ | { from: 'stateVar'; name: string; path?: string }
64
+ | { from: 'input'; path: string }
65
+ | { from: 'literal'; value: unknown }
66
+ | { from: 'expression'; expression: string }
67
+
68
+ /**
69
+ * RPC step metadata (base form)
70
+ */
71
+ export interface RpcStepMeta {
72
+ /** RPC form - generates queue worker */
73
+ type: 'rpc'
74
+ /** Cache key (stepName from workflow.do) */
75
+ stepName: string
76
+ /** RPC to invoke */
77
+ rpcName: string
78
+ /** Output variable name (if assigned) */
79
+ outputVar?: string
80
+ /** Input source mappings, or 'passthrough' when entire data is passed */
81
+ inputs?: Record<string, InputSource> | 'passthrough'
82
+ /** Step options */
83
+ options?: WorkflowStepOptions
84
+ }
85
+
86
+ /**
87
+ * Simple condition expression (leaf node)
88
+ */
89
+ export interface SimpleCondition {
90
+ type: 'simple'
91
+ expression: string
92
+ }
93
+
94
+ /**
95
+ * Nested condition structure supporting AND/OR operations
96
+ */
97
+ export type Condition =
98
+ | SimpleCondition
99
+ | { type: 'and'; conditions: Condition[] }
100
+ | { type: 'or'; conditions: Condition[] }
101
+
102
+ /**
103
+ * A single branch in an if/else-if chain
104
+ */
105
+ export interface BranchCase {
106
+ /** Condition for this branch */
107
+ condition: Condition
108
+ /** Steps to execute when condition is true */
109
+ steps: WorkflowStepMeta[]
110
+ }
111
+
112
+ /**
113
+ * Branch step metadata (if/else-if/else control flow)
114
+ */
115
+ export interface BranchStepMeta {
116
+ type: 'branch'
117
+ /** Branches in order: first is "if", rest are "else if" */
118
+ branches: BranchCase[]
119
+ /** Else branch steps (when no conditions match) */
120
+ elseSteps?: WorkflowStepMeta[]
121
+ }
122
+
123
+ /**
124
+ * Parallel group step metadata (Promise.all with multiple steps)
125
+ */
126
+ export interface ParallelGroupStepMeta {
127
+ type: 'parallel'
128
+ /** Child steps to execute in parallel */
129
+ children: RpcStepMeta[]
130
+ }
131
+
132
+ /**
133
+ * Fanout step metadata (parallel or sequential iteration)
134
+ */
135
+ export interface FanoutStepMeta {
136
+ type: 'fanout'
137
+ /** Step name for this fanout */
138
+ stepName: string
139
+ /** Source array variable name */
140
+ sourceVar: string
141
+ /** Iterator variable name */
142
+ itemVar: string
143
+ /** Execution mode */
144
+ mode: 'parallel' | 'sequential'
145
+ /** Child step to execute per iteration */
146
+ child: RpcStepMeta
147
+ /** Time between iterations (sequential mode only) */
148
+ timeBetween?: string
149
+ }
150
+
151
+ /**
152
+ * Return step metadata (workflow output)
153
+ */
154
+ export interface ReturnStepMeta {
155
+ type: 'return'
156
+ /** Output bindings */
157
+ outputs: Record<string, OutputBinding>
158
+ }
159
+
160
+ /**
161
+ * Inline step metadata (legacy support)
162
+ */
163
+ export interface InlineStepMeta {
164
+ /** Inline form - local execution */
165
+ type: 'inline'
166
+ /** Cache key (stepName from workflow.do) */
167
+ stepName: string
168
+ /** Display name */
169
+ description?: string
170
+ /** Step options */
171
+ options?: WorkflowStepOptions
172
+ }
173
+
174
+ /**
175
+ * Sleep step metadata
176
+ */
177
+ export interface SleepStepMeta {
178
+ /** Sleep step */
179
+ type: 'sleep'
180
+ /** Cache key (stepName from workflow.sleep) */
181
+ stepName: string
182
+ /** Sleep duration */
183
+ duration: string | number
184
+ }
185
+
186
+ /**
187
+ * Cancel step metadata
188
+ */
189
+ export interface CancelStepMeta {
190
+ /** Cancel step */
191
+ type: 'cancel'
192
+ /** Optional cancellation reason */
193
+ reason?: string
194
+ }
195
+
196
+ /**
197
+ * Set step metadata (context variable assignment)
198
+ */
199
+ export interface SetStepMeta {
200
+ /** Set step */
201
+ type: 'set'
202
+ /** Variable name to set (must be in context) */
203
+ variable: string
204
+ /** Value to assign (literal or expression) */
205
+ value: unknown
206
+ }
207
+
208
+ /**
209
+ * Switch case metadata
210
+ */
211
+ export interface SwitchCaseMeta {
212
+ /** Case value (literal) or expression */
213
+ value?: string | number | boolean | null
214
+ /** Case expression (for complex cases) */
215
+ expression?: string
216
+ /** Steps to execute for this case */
217
+ steps: WorkflowStepMeta[]
218
+ }
219
+
220
+ /**
221
+ * Switch step metadata (switch/case control flow)
222
+ */
223
+ export interface SwitchStepMeta {
224
+ type: 'switch'
225
+ /** Expression being switched on */
226
+ expression: string
227
+ /** Case branches */
228
+ cases: SwitchCaseMeta[]
229
+ /** Default case steps (optional) */
230
+ defaultSteps?: WorkflowStepMeta[]
231
+ }
232
+
233
+ /**
234
+ * Filter step metadata (array.filter)
235
+ */
236
+ export interface FilterStepMeta {
237
+ type: 'filter'
238
+ /** Source array variable name */
239
+ sourceVar: string
240
+ /** Iterator variable name */
241
+ itemVar: string
242
+ /** Filter condition */
243
+ condition: Condition
244
+ /** Output variable name (if assigned) */
245
+ outputVar?: string
246
+ }
247
+
248
+ /**
249
+ * Array predicate step metadata (array.some, array.every)
250
+ */
251
+ export interface ArrayPredicateStepMeta {
252
+ type: 'arrayPredicate'
253
+ /** Predicate mode */
254
+ mode: 'some' | 'every'
255
+ /** Source array variable name */
256
+ sourceVar: string
257
+ /** Iterator variable name */
258
+ itemVar: string
259
+ /** Predicate condition */
260
+ condition: Condition
261
+ /** Output variable name (if assigned) */
262
+ outputVar?: string
263
+ }
264
+
265
+ /**
266
+ * Workflow step metadata (extracted by inspector)
267
+ */
268
+ export type WorkflowStepMeta =
269
+ | RpcStepMeta
270
+ | BranchStepMeta
271
+ | ParallelGroupStepMeta
272
+ | FanoutStepMeta
273
+ | ReturnStepMeta
274
+ | InlineStepMeta
275
+ | SleepStepMeta
276
+ | CancelStepMeta
277
+ | SwitchStepMeta
278
+ | FilterStepMeta
279
+ | ArrayPredicateStepMeta
280
+ | SetStepMeta
281
+
282
+ /**
283
+ * Workflow step wire context for RPC functions
284
+ * Provides step-level metadata including retry attempt tracking
285
+ */
286
+ export interface WorkflowStepWire {
287
+ /** The workflow run ID */
288
+ runId: string
289
+ /** The unique step ID */
290
+ stepId: string
291
+ /** Current attempt number (1-indexed, increments on retry) */
292
+ attemptCount: number
293
+ }
294
+
295
+ /**
296
+ * Workflow wire object for DSL workflows
297
+ * Provides workflow-specific capabilities to function execution
298
+ */
299
+ export interface PikkuWorkflowWire {
300
+ /** The workflow name */
301
+ workflowName: string
302
+ /** The current run ID */
303
+ runId: string
304
+ /** Get the current workflow run */
305
+ getRun: () => Promise<WorkflowRun>
306
+
307
+ /** Execute a workflow step (overloaded - RPC or inline form) */
308
+ do: WorkflowWireDoRPC & WorkflowWireDoInline
309
+
310
+ /** Sleep for a duration */
311
+ sleep: WorkflowWireSleep
312
+ }