@pikku/core 0.10.2 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/errors/errors.d.ts +1 -1
- package/dist/errors/errors.js +3 -3
- package/dist/function/function-runner.d.ts +6 -7
- package/dist/function/function-runner.js +35 -16
- package/dist/function/functions.types.d.ts +23 -30
- package/dist/function/functions.types.js +9 -6
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +3 -6
- package/dist/middleware-runner.js +11 -11
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +15 -15
- package/dist/pikku-state.d.ts +7 -2
- package/dist/pikku-state.js +4 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/scheduler-service.d.ts +63 -0
- package/dist/services/scheduler-service.js +6 -0
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/time-utils.d.ts +14 -0
- package/dist/time-utils.js +62 -0
- package/dist/types/core.types.d.ts +48 -35
- package/dist/types/core.types.js +3 -13
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/dist/wirings/channel/channel-common.js +2 -3
- package/dist/wirings/channel/channel-handler.d.ts +3 -2
- package/dist/wirings/channel/channel-handler.js +6 -9
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel.types.d.ts +10 -5
- package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-runner.js +19 -26
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
- package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +11 -29
- package/dist/wirings/cli/cli.types.d.ts +15 -11
- package/dist/wirings/http/http-runner.d.ts +6 -6
- package/dist/wirings/http/http-runner.js +25 -39
- package/dist/wirings/http/http.types.d.ts +5 -10
- package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
- package/dist/wirings/mcp/mcp-runner.js +12 -19
- package/dist/wirings/mcp/mcp.types.d.ts +6 -0
- package/dist/wirings/queue/queue-runner.d.ts +3 -3
- package/dist/wirings/queue/queue-runner.js +7 -14
- package/dist/wirings/queue/queue.types.d.ts +4 -13
- 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 +13 -7
- package/dist/wirings/rpc/rpc-runner.js +50 -26
- package/dist/wirings/rpc/rpc-types.d.ts +1 -0
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler-runner.js +13 -24
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
- package/dist/wirings/workflow/index.d.ts +15 -0
- package/dist/wirings/workflow/index.js +14 -0
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +160 -0
- package/dist/wirings/workflow/pikku-workflow-service.js +430 -0
- package/dist/wirings/workflow/workflow-runner.d.ts +34 -0
- package/dist/wirings/workflow/workflow-runner.js +65 -0
- package/dist/wirings/workflow/workflow.types.d.ts +332 -0
- package/dist/wirings/workflow/workflow.types.js +1 -0
- package/package.json +3 -4
- package/src/errors/errors.ts +3 -3
- package/src/factory-functions.test.ts +9 -36
- package/src/function/function-runner.test.ts +57 -68
- package/src/function/function-runner.ts +51 -28
- package/src/function/function-runner.ts.bak +188 -0
- package/src/function/functions.types.ts +69 -51
- package/src/handle-error.ts +1 -1
- package/src/index.ts +2 -0
- package/src/middleware/auth-apikey.test.ts +360 -0
- package/src/middleware/auth-apikey.ts +3 -7
- package/src/middleware/auth-bearer.test.ts +447 -0
- package/src/middleware/auth-bearer.ts +27 -33
- package/src/middleware/auth-cookie.test.ts +525 -0
- package/src/middleware/auth-cookie.ts +6 -6
- package/src/middleware/timeout.ts +4 -2
- package/src/middleware-runner.test.ts +58 -127
- package/src/middleware-runner.ts +13 -15
- package/src/permissions.test.ts +41 -45
- package/src/permissions.ts +21 -20
- package/src/pikku-state.ts +14 -2
- package/src/services/index.ts +1 -0
- package/src/services/scheduler-service.ts +76 -0
- package/src/services/user-session-service.ts +14 -4
- package/src/time-utils.ts +75 -0
- package/src/types/core.types.ts +92 -51
- package/src/utils.ts +4 -4
- package/src/wirings/channel/channel-common.ts +4 -7
- package/src/wirings/channel/channel-handler.ts +16 -22
- package/src/wirings/channel/channel-runner.ts +2 -2
- package/src/wirings/channel/channel.types.ts +14 -11
- package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
- package/src/wirings/channel/local/local-channel-runner.ts +23 -38
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +7 -7
- package/src/wirings/cli/cli-runner.ts +25 -63
- package/src/wirings/cli/cli.types.ts +22 -16
- package/src/wirings/http/http-runner.test.ts +8 -8
- package/src/wirings/http/http-runner.ts +29 -56
- package/src/wirings/http/http.types.ts +5 -14
- package/src/wirings/mcp/mcp-runner.ts +23 -48
- package/src/wirings/mcp/mcp.types.ts +6 -0
- package/src/wirings/queue/queue-runner.test.ts +641 -0
- package/src/wirings/queue/queue-runner.ts +10 -24
- package/src/wirings/queue/queue.types.ts +5 -15
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +71 -32
- package/src/wirings/rpc/rpc-types.ts +1 -0
- package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
- package/src/wirings/scheduler/scheduler-runner.ts +24 -50
- package/src/wirings/scheduler/scheduler.types.ts +3 -9
- package/src/wirings/workflow/index.ts +43 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +746 -0
- package/src/wirings/workflow/workflow-runner.ts +72 -0
- package/src/wirings/workflow/workflow.types.ts +422 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/services/file-channel-store.d.ts +0 -19
- package/dist/services/file-channel-store.js +0 -69
- package/dist/services/file-eventhub-store.d.ts +0 -17
- package/dist/services/file-eventhub-store.js +0 -71
- package/src/services/file-channel-store.ts +0 -86
- package/src/services/file-eventhub-store.ts +0 -90
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { pikkuState } from '../../pikku-state.js'
|
|
2
|
+
import { PikkuError } from '../../errors/error-handler.js'
|
|
3
|
+
import { addFunction } from '../../function/function-runner.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Exception thrown when workflow needs to pause for async step
|
|
7
|
+
*/
|
|
8
|
+
export class WorkflowAsyncException extends Error {
|
|
9
|
+
constructor(
|
|
10
|
+
public readonly runId: string,
|
|
11
|
+
public readonly stepName: string
|
|
12
|
+
) {
|
|
13
|
+
super(`Workflow paused at step: ${stepName}`)
|
|
14
|
+
this.name = 'WorkflowAsyncException'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Exception thrown when workflow is cancelled
|
|
20
|
+
*/
|
|
21
|
+
export class WorkflowCancelledException extends Error {
|
|
22
|
+
constructor(
|
|
23
|
+
public readonly runId: string,
|
|
24
|
+
public readonly reason?: string
|
|
25
|
+
) {
|
|
26
|
+
super(reason || 'Workflow cancelled')
|
|
27
|
+
this.name = 'WorkflowCancelledException'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Error class for workflow not found
|
|
33
|
+
*/
|
|
34
|
+
export class WorkflowNotFoundError extends PikkuError {
|
|
35
|
+
constructor(name: string) {
|
|
36
|
+
super(`Workflow not found: ${name}`)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Error class for workflow not found
|
|
42
|
+
*/
|
|
43
|
+
export class WorkflowRunNotFound extends PikkuError {
|
|
44
|
+
constructor(runId: string) {
|
|
45
|
+
super(`Workflow run not found: ${runId}`)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Add a workflow to the system
|
|
51
|
+
* This is called by the generated workflow wirings
|
|
52
|
+
*/
|
|
53
|
+
export const addWorkflow = (workflowName: string, workflowFunc: any) => {
|
|
54
|
+
// Get workflow metadata from inspector
|
|
55
|
+
const meta = pikkuState('workflows', 'meta')
|
|
56
|
+
const workflowMeta = meta[workflowName]
|
|
57
|
+
if (!workflowMeta) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Workflow metadata not found for '${workflowName}'. Make sure to run the CLI to generate metadata.`
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Store workflow definition in state
|
|
64
|
+
const registrations = pikkuState('workflows', 'registrations')
|
|
65
|
+
registrations.set(workflowName, {
|
|
66
|
+
name: workflowName,
|
|
67
|
+
func: workflowFunc,
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
// Register the function with pikku
|
|
71
|
+
addFunction(workflowMeta.pikkuFuncName, workflowFunc)
|
|
72
|
+
}
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SerializedError,
|
|
3
|
+
CoreSingletonServices,
|
|
4
|
+
CreateWireServices,
|
|
5
|
+
CoreConfig,
|
|
6
|
+
CommonWireMeta,
|
|
7
|
+
} from '../../types/core.types.js'
|
|
8
|
+
import { CorePikkuFunctionConfig } from '../../function/functions.types.js'
|
|
9
|
+
|
|
10
|
+
export interface WorkflowServiceConfig {
|
|
11
|
+
retries: number
|
|
12
|
+
retryDelay: number
|
|
13
|
+
orchestratorQueueName: string
|
|
14
|
+
stepWorkerQueueName: string
|
|
15
|
+
sleeperRPCName: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Workflow run status
|
|
20
|
+
*/
|
|
21
|
+
export type WorkflowStatus = 'running' | 'completed' | 'failed' | 'cancelled'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Workflow step status
|
|
25
|
+
*/
|
|
26
|
+
export type StepStatus =
|
|
27
|
+
| 'pending'
|
|
28
|
+
| 'running'
|
|
29
|
+
| 'scheduled'
|
|
30
|
+
| 'succeeded'
|
|
31
|
+
| 'failed'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Workflow run representation
|
|
35
|
+
*/
|
|
36
|
+
export interface WorkflowRun {
|
|
37
|
+
/** Unique run ID */
|
|
38
|
+
id: string
|
|
39
|
+
/** Workflow name */
|
|
40
|
+
workflow: string
|
|
41
|
+
/** Current status */
|
|
42
|
+
status: WorkflowStatus
|
|
43
|
+
/** Input data */
|
|
44
|
+
input: any
|
|
45
|
+
/** Output data (if completed) */
|
|
46
|
+
output?: any
|
|
47
|
+
/** Error (if failed) */
|
|
48
|
+
error?: SerializedError
|
|
49
|
+
/** Creation timestamp */
|
|
50
|
+
createdAt: Date
|
|
51
|
+
/** Last update timestamp */
|
|
52
|
+
updatedAt: Date
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Step state representation
|
|
57
|
+
*/
|
|
58
|
+
export interface StepState {
|
|
59
|
+
/** Unique step ID */
|
|
60
|
+
stepId: string
|
|
61
|
+
/** Step status */
|
|
62
|
+
status: StepStatus
|
|
63
|
+
/** Step result (if done) */
|
|
64
|
+
result?: any
|
|
65
|
+
/** Step error (if error) */
|
|
66
|
+
error?: SerializedError
|
|
67
|
+
/** Number of attempts made (starts at 1) */
|
|
68
|
+
attemptCount: number
|
|
69
|
+
/** Maximum retry attempts allowed */
|
|
70
|
+
retries?: number
|
|
71
|
+
/** Delay between retries */
|
|
72
|
+
retryDelay?: string | number
|
|
73
|
+
/** Creation timestamp */
|
|
74
|
+
createdAt: Date
|
|
75
|
+
/** Last update timestamp */
|
|
76
|
+
updatedAt: Date
|
|
77
|
+
/** Timestamp when step started running */
|
|
78
|
+
runningAt?: Date
|
|
79
|
+
/** Timestamp when step was scheduled */
|
|
80
|
+
scheduledAt?: Date
|
|
81
|
+
/** Timestamp when step succeeded */
|
|
82
|
+
succeededAt?: Date
|
|
83
|
+
/** Timestamp when step failed */
|
|
84
|
+
failedAt?: Date
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Core workflow definition
|
|
89
|
+
*/
|
|
90
|
+
export type CoreWorkflow<
|
|
91
|
+
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
92
|
+
any,
|
|
93
|
+
any,
|
|
94
|
+
any
|
|
95
|
+
> = CorePikkuFunctionConfig<any, any, any>,
|
|
96
|
+
> = {
|
|
97
|
+
/** Unique workflow name */
|
|
98
|
+
name: string
|
|
99
|
+
/** The workflow function */
|
|
100
|
+
func: PikkuFunctionConfig
|
|
101
|
+
/** Middleware chain for this workflow */
|
|
102
|
+
middleware?: PikkuFunctionConfig['middleware']
|
|
103
|
+
/** Permission requirements */
|
|
104
|
+
permissions?: PikkuFunctionConfig['permissions']
|
|
105
|
+
/** Tags for organization and filtering */
|
|
106
|
+
tags?: string[]
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Workflow step options
|
|
111
|
+
*/
|
|
112
|
+
export interface WorkflowStepOptions {
|
|
113
|
+
/** Display name for logs/UI (optional, doesn't affect execution) */
|
|
114
|
+
description?: string
|
|
115
|
+
/** Number of retry attempts for failed steps (only applies to local execution) */
|
|
116
|
+
retries?: number
|
|
117
|
+
/** Delay between retry attempts (e.g., '1s', '2s', '2min') */
|
|
118
|
+
retryDelay?: string | number
|
|
119
|
+
// Future: timeout, failFast, priority
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Type signature for workflow.do() RPC form - used by inspector
|
|
124
|
+
*/
|
|
125
|
+
export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(
|
|
126
|
+
stepName: string,
|
|
127
|
+
rpcName: string,
|
|
128
|
+
data: TInput,
|
|
129
|
+
options?: WorkflowStepOptions
|
|
130
|
+
) => Promise<TOutput>
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Type signature for workflow.do() inline form - used by inspector
|
|
134
|
+
*/
|
|
135
|
+
export type WorkflowWireDoInline = <T>(
|
|
136
|
+
stepName: string,
|
|
137
|
+
fn: () => Promise<T> | T,
|
|
138
|
+
options?: WorkflowStepOptions
|
|
139
|
+
) => Promise<T>
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Type signature for workflow.sleep() - used by inspector
|
|
143
|
+
*/
|
|
144
|
+
export type WorkflowWireSleep = (
|
|
145
|
+
stepName: string,
|
|
146
|
+
duration: string
|
|
147
|
+
) => Promise<void>
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Input source for step arguments in simple workflows
|
|
151
|
+
*/
|
|
152
|
+
export type InputSource =
|
|
153
|
+
| { from: 'input'; path: string }
|
|
154
|
+
| { from: 'outputVar'; name: string; path?: string }
|
|
155
|
+
| { from: 'item'; path: string }
|
|
156
|
+
| { from: 'literal'; value: unknown }
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Output binding for return statements in simple workflows
|
|
160
|
+
*/
|
|
161
|
+
export interface OutputBinding {
|
|
162
|
+
from: 'outputVar' | 'input'
|
|
163
|
+
name?: string
|
|
164
|
+
path?: string
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* RPC step metadata (base form)
|
|
169
|
+
*/
|
|
170
|
+
export interface RpcStepMeta {
|
|
171
|
+
/** RPC form - generates queue worker */
|
|
172
|
+
type: 'rpc'
|
|
173
|
+
/** Cache key (stepName from workflow.do) */
|
|
174
|
+
stepName: string
|
|
175
|
+
/** RPC to invoke */
|
|
176
|
+
rpcName: string
|
|
177
|
+
/** Output variable name (if assigned) */
|
|
178
|
+
outputVar?: string
|
|
179
|
+
/** Input source mappings */
|
|
180
|
+
inputs?: Record<string, InputSource>
|
|
181
|
+
/** Step options */
|
|
182
|
+
options?: WorkflowStepOptions
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Branch step metadata (if/else control flow)
|
|
187
|
+
*/
|
|
188
|
+
export interface BranchStepMeta {
|
|
189
|
+
type: 'branch'
|
|
190
|
+
/** Condition expression (as source string) */
|
|
191
|
+
condition: string
|
|
192
|
+
/** Branch paths */
|
|
193
|
+
branches: {
|
|
194
|
+
then: WorkflowStepMeta[]
|
|
195
|
+
else?: WorkflowStepMeta[]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Parallel group step metadata (Promise.all with multiple steps)
|
|
201
|
+
*/
|
|
202
|
+
export interface ParallelGroupStepMeta {
|
|
203
|
+
type: 'parallel'
|
|
204
|
+
/** Child steps to execute in parallel */
|
|
205
|
+
children: RpcStepMeta[]
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Fanout step metadata (parallel or sequential iteration)
|
|
210
|
+
*/
|
|
211
|
+
export interface FanoutStepMeta {
|
|
212
|
+
type: 'fanout'
|
|
213
|
+
/** Step name for this fanout */
|
|
214
|
+
stepName: string
|
|
215
|
+
/** Source array variable name */
|
|
216
|
+
sourceVar: string
|
|
217
|
+
/** Iterator variable name */
|
|
218
|
+
itemVar: string
|
|
219
|
+
/** Execution mode */
|
|
220
|
+
mode: 'parallel' | 'sequential'
|
|
221
|
+
/** Child step to execute per iteration */
|
|
222
|
+
child: RpcStepMeta
|
|
223
|
+
/** Time between iterations (sequential mode only) */
|
|
224
|
+
timeBetween?: string
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Return step metadata (workflow output)
|
|
229
|
+
*/
|
|
230
|
+
export interface ReturnStepMeta {
|
|
231
|
+
type: 'return'
|
|
232
|
+
/** Output bindings */
|
|
233
|
+
outputs: Record<string, OutputBinding>
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Inline step metadata (legacy support)
|
|
238
|
+
*/
|
|
239
|
+
export interface InlineStepMeta {
|
|
240
|
+
/** Inline form - local execution */
|
|
241
|
+
type: 'inline'
|
|
242
|
+
/** Cache key (stepName from workflow.do) */
|
|
243
|
+
stepName: string
|
|
244
|
+
/** Display name */
|
|
245
|
+
description?: string
|
|
246
|
+
/** Step options */
|
|
247
|
+
options?: WorkflowStepOptions
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Sleep step metadata
|
|
252
|
+
*/
|
|
253
|
+
export interface SleepStepMeta {
|
|
254
|
+
/** Sleep step */
|
|
255
|
+
type: 'sleep'
|
|
256
|
+
/** Cache key (stepName from workflow.sleep) */
|
|
257
|
+
stepName: string
|
|
258
|
+
/** Sleep duration */
|
|
259
|
+
duration: string | number
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Cancel step metadata
|
|
264
|
+
*/
|
|
265
|
+
export interface CancelStepMeta {
|
|
266
|
+
/** Cancel step */
|
|
267
|
+
type: 'cancel'
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Workflow step metadata (extracted by inspector)
|
|
272
|
+
*/
|
|
273
|
+
export type WorkflowStepMeta =
|
|
274
|
+
| RpcStepMeta
|
|
275
|
+
| BranchStepMeta
|
|
276
|
+
| ParallelGroupStepMeta
|
|
277
|
+
| FanoutStepMeta
|
|
278
|
+
| ReturnStepMeta
|
|
279
|
+
| InlineStepMeta
|
|
280
|
+
| SleepStepMeta
|
|
281
|
+
| CancelStepMeta
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Workflow step wire context for RPC functions
|
|
285
|
+
* Provides step-level metadata including retry attempt tracking
|
|
286
|
+
*/
|
|
287
|
+
export interface WorkflowStepWire {
|
|
288
|
+
/** The workflow run ID */
|
|
289
|
+
runId: string
|
|
290
|
+
/** The unique step ID */
|
|
291
|
+
stepId: string
|
|
292
|
+
/** Current attempt number (1-indexed, increments on retry) */
|
|
293
|
+
attemptCount: number
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Workflow wire object for middleware
|
|
298
|
+
* Provides workflow-specific capabilities to function execution
|
|
299
|
+
*/
|
|
300
|
+
export interface PikkuWorkflowWire {
|
|
301
|
+
/** The workflow name */
|
|
302
|
+
workflowName: string
|
|
303
|
+
/** The current run ID */
|
|
304
|
+
runId: string
|
|
305
|
+
/** Get the current workflow run */
|
|
306
|
+
getRun: () => Promise<WorkflowRun>
|
|
307
|
+
|
|
308
|
+
/** Execute a workflow step (overloaded - RPC or inline form) */
|
|
309
|
+
do: WorkflowWireDoRPC & WorkflowWireDoInline
|
|
310
|
+
|
|
311
|
+
/** Sleep for a duration */
|
|
312
|
+
sleep: WorkflowWireSleep
|
|
313
|
+
|
|
314
|
+
/** Cancel the current workflow run */
|
|
315
|
+
cancel: (reason?: string) => Promise<void>
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Workflow client interface
|
|
320
|
+
*/
|
|
321
|
+
export interface PikkuWorkflow {
|
|
322
|
+
/** Start a new workflow run */
|
|
323
|
+
start: <I>(input: I) => Promise<{ runId: string }>
|
|
324
|
+
/** Get a workflow run by ID */
|
|
325
|
+
getRun: (runId: string) => Promise<WorkflowRun>
|
|
326
|
+
/** Cancel a running workflow */
|
|
327
|
+
cancelRun: (runId: string) => Promise<void>
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Workflows metadata for inspector/CLI
|
|
332
|
+
*/
|
|
333
|
+
export type WorkflowsMeta = Record<
|
|
334
|
+
string,
|
|
335
|
+
CommonWireMeta & {
|
|
336
|
+
workflowName: string
|
|
337
|
+
steps: WorkflowStepMeta[]
|
|
338
|
+
/** Whether this workflow conforms to simple workflow DSL */
|
|
339
|
+
simple?: boolean
|
|
340
|
+
}
|
|
341
|
+
>
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Interface for workflow orchestration
|
|
345
|
+
* Handles workflow execution, replay, orchestration logic, and run-level state
|
|
346
|
+
*/
|
|
347
|
+
export interface WorkflowService {
|
|
348
|
+
// Run-level state operations
|
|
349
|
+
createRun(workflowName: string, input: any): Promise<string>
|
|
350
|
+
getRun(id: string): Promise<WorkflowRun | null>
|
|
351
|
+
getRunHistory(runId: string): Promise<Array<StepState & { stepName: string }>>
|
|
352
|
+
updateRunStatus(
|
|
353
|
+
id: string,
|
|
354
|
+
status: WorkflowStatus,
|
|
355
|
+
output?: any,
|
|
356
|
+
error?: SerializedError
|
|
357
|
+
): Promise<void>
|
|
358
|
+
withRunLock<T>(id: string, fn: () => Promise<T>): Promise<T>
|
|
359
|
+
close(): Promise<void>
|
|
360
|
+
|
|
361
|
+
// Orchestration operations
|
|
362
|
+
resumeWorkflow(runId: string): Promise<void>
|
|
363
|
+
setServices(
|
|
364
|
+
singletonServices: CoreSingletonServices,
|
|
365
|
+
createWireServices: CreateWireServices,
|
|
366
|
+
config: CoreConfig
|
|
367
|
+
): void
|
|
368
|
+
startWorkflow<I>(
|
|
369
|
+
name: string,
|
|
370
|
+
input: I,
|
|
371
|
+
rpcService: any
|
|
372
|
+
): Promise<{ runId: string }>
|
|
373
|
+
runWorkflowJob(runId: string, rpcService: any): Promise<void>
|
|
374
|
+
orchestrateWorkflow(runId: string, rpcService: any): Promise<void>
|
|
375
|
+
executeWorkflowSleep(runId: string, stepId: string): Promise<void>
|
|
376
|
+
|
|
377
|
+
// Step-level state operations
|
|
378
|
+
insertStepState(
|
|
379
|
+
runId: string,
|
|
380
|
+
stepName: string,
|
|
381
|
+
rpcName: string,
|
|
382
|
+
data: any,
|
|
383
|
+
stepOptions?: { retries?: number; retryDelay?: string | number }
|
|
384
|
+
): Promise<StepState>
|
|
385
|
+
getStepState(runId: string, stepName: string): Promise<StepState>
|
|
386
|
+
setStepRunning(stepId: string): Promise<void>
|
|
387
|
+
setStepScheduled(stepId: string): Promise<void>
|
|
388
|
+
setStepResult(stepId: string, result: any): Promise<void>
|
|
389
|
+
setStepError(stepId: string, error: Error): Promise<void>
|
|
390
|
+
createRetryAttempt(
|
|
391
|
+
stepId: string,
|
|
392
|
+
status: 'pending' | 'running'
|
|
393
|
+
): Promise<StepState>
|
|
394
|
+
|
|
395
|
+
// Step execution
|
|
396
|
+
executeWorkflowStep(
|
|
397
|
+
runId: string,
|
|
398
|
+
stepName: string,
|
|
399
|
+
rpcName: string | null,
|
|
400
|
+
data: any,
|
|
401
|
+
rpcService: any
|
|
402
|
+
): Promise<void>
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Worker input types for generated queue workers
|
|
407
|
+
*/
|
|
408
|
+
export type WorkflowStepInput = {
|
|
409
|
+
runId: string
|
|
410
|
+
stepName: string
|
|
411
|
+
rpcName: string
|
|
412
|
+
data: any
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export type WorkflowOrchestratorInput = {
|
|
416
|
+
runId: string
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export type WorkflowSleeperInput = {
|
|
420
|
+
runId: string
|
|
421
|
+
stepId: string
|
|
422
|
+
}
|