@pikku/core 0.11.1 → 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.
- package/CHANGELOG.md +24 -0
- package/dist/errors/error-handler.js +3 -3
- package/dist/function/function-runner.d.ts +4 -3
- package/dist/function/function-runner.js +60 -14
- package/dist/function/functions.types.d.ts +84 -5
- package/dist/function/functions.types.js +41 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +5 -2
- package/dist/middleware/auth-apikey.d.ts +1 -1
- package/dist/middleware/auth-bearer.d.ts +1 -1
- package/dist/middleware/auth-cookie.d.ts +1 -1
- package/dist/middleware/timeout.d.ts +1 -1
- package/dist/middleware-runner.d.ts +3 -14
- package/dist/middleware-runner.js +8 -8
- package/dist/permissions.d.ts +3 -86
- package/dist/permissions.js +11 -67
- package/dist/pikku-state.d.ts +32 -104
- package/dist/pikku-state.js +140 -66
- package/dist/schema.d.ts +8 -6
- package/dist/schema.js +25 -13
- package/dist/services/workflow-service.d.ts +38 -0
- package/dist/services/workflow-service.js +1 -0
- package/dist/types/core.types.d.ts +12 -4
- package/dist/types/core.types.js +1 -1
- package/dist/types/state.types.d.ts +135 -0
- package/dist/types/state.types.js +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +45 -0
- package/dist/wirings/channel/channel-handler.js +1 -1
- package/dist/wirings/channel/channel-runner.js +5 -5
- package/dist/wirings/channel/log-channels.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +2 -2
- package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
- package/dist/wirings/cli/cli-runner.js +10 -10
- package/dist/wirings/cli/cli.types.d.ts +1 -0
- package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
- package/dist/wirings/forge-node/forge-node.types.js +38 -0
- package/dist/wirings/forge-node/index.d.ts +1 -0
- package/dist/wirings/forge-node/index.js +1 -0
- package/dist/wirings/http/http-runner.d.ts +2 -2
- package/dist/wirings/http/http-runner.js +21 -12
- package/dist/wirings/http/http.types.d.ts +14 -1
- package/dist/wirings/http/log-http-routes.js +1 -1
- package/dist/wirings/http/routers/path-to-regex.js +2 -2
- package/dist/wirings/mcp/mcp-runner.js +21 -21
- package/dist/wirings/queue/queue-runner.js +6 -6
- 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 +7 -8
- package/dist/wirings/rpc/rpc-runner.js +62 -14
- package/dist/wirings/rpc/rpc-types.d.ts +7 -0
- package/dist/wirings/scheduler/log-schedulers.js +1 -1
- package/dist/wirings/scheduler/scheduler-runner.js +5 -5
- package/dist/wirings/trigger/index.d.ts +2 -0
- package/dist/wirings/trigger/index.js +2 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
- package/dist/wirings/trigger/trigger-runner.js +57 -0
- package/dist/wirings/trigger/trigger.types.d.ts +42 -0
- package/dist/wirings/trigger/trigger.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +5 -0
- package/dist/wirings/workflow/dsl/index.js +4 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
- package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
- package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
- package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
- package/dist/wirings/workflow/graph/graph-node.js +58 -0
- package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
- package/dist/wirings/workflow/graph/graph-runner.js +452 -0
- package/dist/wirings/workflow/graph/index.d.ts +3 -0
- package/dist/wirings/workflow/graph/index.js +3 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
- package/dist/wirings/workflow/index.d.ts +7 -12
- package/dist/wirings/workflow/index.js +6 -11
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +96 -6
- package/dist/wirings/workflow/pikku-workflow-service.js +230 -103
- package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
- package/dist/wirings/workflow/wire-workflow.js +53 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
- package/dist/wirings/workflow/workflow-utils.js +66 -0
- package/dist/wirings/workflow/workflow.types.d.ts +133 -211
- package/package.json +10 -1
- package/src/errors/error-handler.ts +3 -3
- package/src/function/function-runner.test.ts +1 -1
- package/src/function/function-runner.ts +86 -16
- package/src/function/functions.types.ts +126 -4
- package/src/index.ts +10 -5
- package/src/middleware-runner.ts +16 -9
- package/src/permissions.test.ts +28 -86
- package/src/permissions.ts +21 -80
- package/src/pikku-state.ts +156 -201
- package/src/schema.ts +42 -13
- package/src/services/workflow-service.ts +74 -0
- package/src/types/core.types.ts +12 -3
- package/src/types/state.types.ts +195 -0
- package/src/utils.ts +55 -0
- package/src/wirings/channel/channel-handler.ts +1 -1
- package/src/wirings/channel/channel-runner.ts +5 -5
- package/src/wirings/channel/local/local-channel-runner.test.ts +3 -1
- package/src/wirings/channel/log-channels.ts +1 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +2 -2
- package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
- package/src/wirings/cli/cli-runner.test.ts +19 -19
- package/src/wirings/cli/cli-runner.ts +10 -9
- package/src/wirings/cli/cli.types.ts +1 -0
- package/src/wirings/forge-node/forge-node.types.ts +135 -0
- package/src/wirings/forge-node/index.ts +1 -0
- package/src/wirings/http/http-runner.test.ts +2 -2
- package/src/wirings/http/http-runner.ts +30 -13
- package/src/wirings/http/http.types.ts +14 -0
- package/src/wirings/http/log-http-routes.ts +1 -1
- package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
- package/src/wirings/http/routers/path-to-regex.ts +2 -2
- package/src/wirings/mcp/mcp-runner.ts +21 -21
- package/src/wirings/queue/queue-runner.test.ts +19 -19
- package/src/wirings/queue/queue-runner.ts +6 -6
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +88 -22
- package/src/wirings/rpc/rpc-types.ts +8 -0
- package/src/wirings/scheduler/log-schedulers.ts +1 -1
- package/src/wirings/scheduler/scheduler-runner.test.ts +27 -27
- package/src/wirings/scheduler/scheduler-runner.ts +5 -5
- package/src/wirings/trigger/index.ts +2 -0
- package/src/wirings/trigger/trigger-runner.ts +96 -0
- package/src/wirings/trigger/trigger.types.ts +56 -0
- package/src/wirings/workflow/dsl/index.ts +30 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
- package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
- package/src/wirings/workflow/graph/graph-node.ts +227 -0
- package/src/wirings/workflow/graph/graph-runner.ts +694 -0
- package/src/wirings/workflow/graph/index.ts +3 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
- package/src/wirings/workflow/index.ts +53 -26
- package/src/wirings/workflow/pikku-workflow-service.ts +333 -117
- package/src/wirings/workflow/wire-workflow.ts +94 -0
- package/src/wirings/workflow/workflow-utils.ts +120 -0
- package/src/wirings/workflow/workflow.types.ts +166 -277
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/workflow/workflow-runner.d.ts +0 -34
- package/dist/wirings/workflow/workflow-runner.js +0 -65
- package/src/function/function-runner.ts.bak +0 -188
- package/src/wirings/workflow/workflow-runner.ts +0 -72
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CorePikkuTriggerFunctionConfig } from '../../function/functions.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The trigger interaction object passed to trigger functions via the wire.
|
|
4
|
+
* Call trigger() to fire the trigger and start a new workflow/execution.
|
|
5
|
+
*/
|
|
6
|
+
export interface PikkuTrigger<TOutput = unknown> {
|
|
7
|
+
trigger: (data: TOutput) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Metadata for registered triggers stored in state.
|
|
11
|
+
*/
|
|
12
|
+
export type TriggerMeta = Record<string, {
|
|
13
|
+
pikkuFuncName: string;
|
|
14
|
+
name: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
tags?: string[];
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Core trigger definition for registration.
|
|
20
|
+
*
|
|
21
|
+
* @template TConfig - Configuration type
|
|
22
|
+
* @template TOutput - Output type
|
|
23
|
+
*/
|
|
24
|
+
export interface CoreTrigger<TConfig = unknown, TOutput = unknown, TriggerFunctionConfig extends CorePikkuTriggerFunctionConfig<TConfig, TOutput> = CorePikkuTriggerFunctionConfig<TConfig, TOutput>> {
|
|
25
|
+
/** Unique name for this trigger */
|
|
26
|
+
name: string;
|
|
27
|
+
/** The trigger function configuration */
|
|
28
|
+
func: TriggerFunctionConfig;
|
|
29
|
+
/** Configuration to pass to the trigger function */
|
|
30
|
+
config: TConfig;
|
|
31
|
+
/** Optional description */
|
|
32
|
+
description?: string;
|
|
33
|
+
/** Optional tags for categorization */
|
|
34
|
+
tags?: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Represents a trigger instance with teardown capability
|
|
38
|
+
*/
|
|
39
|
+
export interface TriggerInstance {
|
|
40
|
+
name: string;
|
|
41
|
+
teardown: () => void | Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSL (Domain Specific Language) workflow exports
|
|
3
|
+
*/
|
|
4
|
+
export { addWorkflow } from './workflow-runner.js';
|
|
5
|
+
export type { WorkflowStepOptions, WorkflowWireDoRPC, WorkflowWireDoInline, WorkflowWireSleep, InputSource, OutputBinding, RpcStepMeta, SimpleCondition, Condition, BranchStepMeta, ParallelGroupStepMeta, FanoutStepMeta, ReturnStepMeta, InlineStepMeta, SleepStepMeta, CancelStepMeta, SwitchCaseMeta, SwitchStepMeta, FilterStepMeta, ArrayPredicateStepMeta, WorkflowStepMeta, WorkflowStepWire, PikkuWorkflowWire, } from './workflow-dsl.types.js';
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSL (Domain Specific Language) workflow types
|
|
3
|
+
* These types define the step-based workflow format extracted by the inspector
|
|
4
|
+
*/
|
|
5
|
+
import type { WorkflowRun } from '../workflow.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Workflow step options
|
|
8
|
+
*/
|
|
9
|
+
export interface WorkflowStepOptions {
|
|
10
|
+
/** Display name for logs/UI (optional, doesn't affect execution) */
|
|
11
|
+
description?: string;
|
|
12
|
+
/** Number of retry attempts for failed steps (only applies to local execution) */
|
|
13
|
+
retries?: number;
|
|
14
|
+
/** Delay between retry attempts (e.g., '1s', '2s', '2min') */
|
|
15
|
+
retryDelay?: string | number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Type signature for workflow.do() RPC form - used by inspector
|
|
19
|
+
*/
|
|
20
|
+
export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(stepName: string, rpcName: string, data: TInput, options?: WorkflowStepOptions) => Promise<TOutput>;
|
|
21
|
+
/**
|
|
22
|
+
* Type signature for workflow.do() inline form - used by inspector
|
|
23
|
+
*/
|
|
24
|
+
export type WorkflowWireDoInline = <T>(stepName: string, fn: () => Promise<T> | T, options?: WorkflowStepOptions) => Promise<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Type signature for workflow.sleep() - used by inspector
|
|
27
|
+
*/
|
|
28
|
+
export type WorkflowWireSleep = (stepName: string, duration: string) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Input source for step arguments in DSL workflows
|
|
31
|
+
*/
|
|
32
|
+
export type InputSource = {
|
|
33
|
+
from: 'input';
|
|
34
|
+
path: string;
|
|
35
|
+
} | {
|
|
36
|
+
from: 'outputVar';
|
|
37
|
+
name: string;
|
|
38
|
+
path?: string;
|
|
39
|
+
} | {
|
|
40
|
+
from: 'item';
|
|
41
|
+
path: string;
|
|
42
|
+
} | {
|
|
43
|
+
from: 'literal';
|
|
44
|
+
value: unknown;
|
|
45
|
+
} | {
|
|
46
|
+
from: 'template';
|
|
47
|
+
parts: string[];
|
|
48
|
+
expressions: InputSource[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Output binding for return statements in DSL workflows
|
|
52
|
+
*/
|
|
53
|
+
export type OutputBinding = {
|
|
54
|
+
from: 'outputVar';
|
|
55
|
+
name: string;
|
|
56
|
+
path?: string;
|
|
57
|
+
} | {
|
|
58
|
+
from: 'stateVar';
|
|
59
|
+
name: string;
|
|
60
|
+
path?: string;
|
|
61
|
+
} | {
|
|
62
|
+
from: 'input';
|
|
63
|
+
path: string;
|
|
64
|
+
} | {
|
|
65
|
+
from: 'literal';
|
|
66
|
+
value: unknown;
|
|
67
|
+
} | {
|
|
68
|
+
from: 'expression';
|
|
69
|
+
expression: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* RPC step metadata (base form)
|
|
73
|
+
*/
|
|
74
|
+
export interface RpcStepMeta {
|
|
75
|
+
/** RPC form - generates queue worker */
|
|
76
|
+
type: 'rpc';
|
|
77
|
+
/** Cache key (stepName from workflow.do) */
|
|
78
|
+
stepName: string;
|
|
79
|
+
/** RPC to invoke */
|
|
80
|
+
rpcName: string;
|
|
81
|
+
/** Output variable name (if assigned) */
|
|
82
|
+
outputVar?: string;
|
|
83
|
+
/** Input source mappings, or 'passthrough' when entire data is passed */
|
|
84
|
+
inputs?: Record<string, InputSource> | 'passthrough';
|
|
85
|
+
/** Step options */
|
|
86
|
+
options?: WorkflowStepOptions;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Simple condition expression (leaf node)
|
|
90
|
+
*/
|
|
91
|
+
export interface SimpleCondition {
|
|
92
|
+
type: 'simple';
|
|
93
|
+
expression: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Nested condition structure supporting AND/OR operations
|
|
97
|
+
*/
|
|
98
|
+
export type Condition = SimpleCondition | {
|
|
99
|
+
type: 'and';
|
|
100
|
+
conditions: Condition[];
|
|
101
|
+
} | {
|
|
102
|
+
type: 'or';
|
|
103
|
+
conditions: Condition[];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* A single branch in an if/else-if chain
|
|
107
|
+
*/
|
|
108
|
+
export interface BranchCase {
|
|
109
|
+
/** Condition for this branch */
|
|
110
|
+
condition: Condition;
|
|
111
|
+
/** Steps to execute when condition is true */
|
|
112
|
+
steps: WorkflowStepMeta[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Branch step metadata (if/else-if/else control flow)
|
|
116
|
+
*/
|
|
117
|
+
export interface BranchStepMeta {
|
|
118
|
+
type: 'branch';
|
|
119
|
+
/** Branches in order: first is "if", rest are "else if" */
|
|
120
|
+
branches: BranchCase[];
|
|
121
|
+
/** Else branch steps (when no conditions match) */
|
|
122
|
+
elseSteps?: WorkflowStepMeta[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Parallel group step metadata (Promise.all with multiple steps)
|
|
126
|
+
*/
|
|
127
|
+
export interface ParallelGroupStepMeta {
|
|
128
|
+
type: 'parallel';
|
|
129
|
+
/** Child steps to execute in parallel */
|
|
130
|
+
children: RpcStepMeta[];
|
|
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
|
+
* Return step metadata (workflow output)
|
|
152
|
+
*/
|
|
153
|
+
export interface ReturnStepMeta {
|
|
154
|
+
type: 'return';
|
|
155
|
+
/** Output bindings */
|
|
156
|
+
outputs: Record<string, OutputBinding>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Inline step metadata (legacy support)
|
|
160
|
+
*/
|
|
161
|
+
export interface InlineStepMeta {
|
|
162
|
+
/** Inline form - local execution */
|
|
163
|
+
type: 'inline';
|
|
164
|
+
/** Cache key (stepName from workflow.do) */
|
|
165
|
+
stepName: string;
|
|
166
|
+
/** Display name */
|
|
167
|
+
description?: string;
|
|
168
|
+
/** Step options */
|
|
169
|
+
options?: WorkflowStepOptions;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Sleep step metadata
|
|
173
|
+
*/
|
|
174
|
+
export interface SleepStepMeta {
|
|
175
|
+
/** Sleep step */
|
|
176
|
+
type: 'sleep';
|
|
177
|
+
/** Cache key (stepName from workflow.sleep) */
|
|
178
|
+
stepName: string;
|
|
179
|
+
/** Sleep duration */
|
|
180
|
+
duration: string | number;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Cancel step metadata
|
|
184
|
+
*/
|
|
185
|
+
export interface CancelStepMeta {
|
|
186
|
+
/** Cancel step */
|
|
187
|
+
type: 'cancel';
|
|
188
|
+
/** Optional cancellation reason */
|
|
189
|
+
reason?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Set step metadata (context variable assignment)
|
|
193
|
+
*/
|
|
194
|
+
export interface SetStepMeta {
|
|
195
|
+
/** Set step */
|
|
196
|
+
type: 'set';
|
|
197
|
+
/** Variable name to set (must be in context) */
|
|
198
|
+
variable: string;
|
|
199
|
+
/** Value to assign (literal or expression) */
|
|
200
|
+
value: unknown;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Switch case metadata
|
|
204
|
+
*/
|
|
205
|
+
export interface SwitchCaseMeta {
|
|
206
|
+
/** Case value (literal) or expression */
|
|
207
|
+
value?: string | number | boolean | null;
|
|
208
|
+
/** Case expression (for complex cases) */
|
|
209
|
+
expression?: string;
|
|
210
|
+
/** Steps to execute for this case */
|
|
211
|
+
steps: WorkflowStepMeta[];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Switch step metadata (switch/case control flow)
|
|
215
|
+
*/
|
|
216
|
+
export interface SwitchStepMeta {
|
|
217
|
+
type: 'switch';
|
|
218
|
+
/** Expression being switched on */
|
|
219
|
+
expression: string;
|
|
220
|
+
/** Case branches */
|
|
221
|
+
cases: SwitchCaseMeta[];
|
|
222
|
+
/** Default case steps (optional) */
|
|
223
|
+
defaultSteps?: WorkflowStepMeta[];
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Filter step metadata (array.filter)
|
|
227
|
+
*/
|
|
228
|
+
export interface FilterStepMeta {
|
|
229
|
+
type: 'filter';
|
|
230
|
+
/** Source array variable name */
|
|
231
|
+
sourceVar: string;
|
|
232
|
+
/** Iterator variable name */
|
|
233
|
+
itemVar: string;
|
|
234
|
+
/** Filter condition */
|
|
235
|
+
condition: Condition;
|
|
236
|
+
/** Output variable name (if assigned) */
|
|
237
|
+
outputVar?: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Array predicate step metadata (array.some, array.every)
|
|
241
|
+
*/
|
|
242
|
+
export interface ArrayPredicateStepMeta {
|
|
243
|
+
type: 'arrayPredicate';
|
|
244
|
+
/** Predicate mode */
|
|
245
|
+
mode: 'some' | 'every';
|
|
246
|
+
/** Source array variable name */
|
|
247
|
+
sourceVar: string;
|
|
248
|
+
/** Iterator variable name */
|
|
249
|
+
itemVar: string;
|
|
250
|
+
/** Predicate condition */
|
|
251
|
+
condition: Condition;
|
|
252
|
+
/** Output variable name (if assigned) */
|
|
253
|
+
outputVar?: string;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Workflow step metadata (extracted by inspector)
|
|
257
|
+
*/
|
|
258
|
+
export type WorkflowStepMeta = RpcStepMeta | BranchStepMeta | ParallelGroupStepMeta | FanoutStepMeta | ReturnStepMeta | InlineStepMeta | SleepStepMeta | CancelStepMeta | SwitchStepMeta | FilterStepMeta | ArrayPredicateStepMeta | SetStepMeta;
|
|
259
|
+
/**
|
|
260
|
+
* Workflow step wire context for RPC functions
|
|
261
|
+
* Provides step-level metadata including retry attempt tracking
|
|
262
|
+
*/
|
|
263
|
+
export interface WorkflowStepWire {
|
|
264
|
+
/** The workflow run ID */
|
|
265
|
+
runId: string;
|
|
266
|
+
/** The unique step ID */
|
|
267
|
+
stepId: string;
|
|
268
|
+
/** Current attempt number (1-indexed, increments on retry) */
|
|
269
|
+
attemptCount: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Workflow wire object for DSL workflows
|
|
273
|
+
* Provides workflow-specific capabilities to function execution
|
|
274
|
+
*/
|
|
275
|
+
export interface PikkuWorkflowWire {
|
|
276
|
+
/** The workflow name */
|
|
277
|
+
workflowName: string;
|
|
278
|
+
/** The current run ID */
|
|
279
|
+
runId: string;
|
|
280
|
+
/** Get the current workflow run */
|
|
281
|
+
getRun: () => Promise<WorkflowRun>;
|
|
282
|
+
/** Execute a workflow step (overloaded - RPC or inline form) */
|
|
283
|
+
do: WorkflowWireDoRPC & WorkflowWireDoInline;
|
|
284
|
+
/** Sleep for a duration */
|
|
285
|
+
sleep: WorkflowWireSleep;
|
|
286
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pikkuState } from '../../../pikku-state.js';
|
|
2
|
+
import { addFunction } from '../../../function/function-runner.js';
|
|
3
|
+
/**
|
|
4
|
+
* Add a workflow to the system
|
|
5
|
+
* This is called by the generated workflow wirings
|
|
6
|
+
*/
|
|
7
|
+
export const addWorkflow = (workflowName, workflowFunc) => {
|
|
8
|
+
// Get workflow metadata from inspector
|
|
9
|
+
const meta = pikkuState(null, 'workflows', 'meta');
|
|
10
|
+
const workflowMeta = meta[workflowName];
|
|
11
|
+
if (!workflowMeta) {
|
|
12
|
+
throw new Error(`Workflow metadata not found for '${workflowName}'. Make sure to run the CLI to generate metadata.`);
|
|
13
|
+
}
|
|
14
|
+
// Store workflow definition in state
|
|
15
|
+
const registrations = pikkuState(null, 'workflows', 'registrations');
|
|
16
|
+
registrations.set(workflowName, {
|
|
17
|
+
name: workflowName,
|
|
18
|
+
func: workflowFunc,
|
|
19
|
+
});
|
|
20
|
+
// Register the function with pikku
|
|
21
|
+
addFunction(workflowMeta.pikkuFuncName, workflowFunc);
|
|
22
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { GraphNodeConfig, NextConfig, RefValue } from './workflow-graph.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Standard RPC handler interface (matches generated FlattenedRPCMap entries)
|
|
4
|
+
*/
|
|
5
|
+
export interface RPCHandler<I = any, O = any> {
|
|
6
|
+
input: I;
|
|
7
|
+
output: O;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Compute output types for all nodes based on their func (RPC name)
|
|
11
|
+
*/
|
|
12
|
+
export type NodeOutputMap<Nodes extends Record<string, {
|
|
13
|
+
func: string;
|
|
14
|
+
}>, RPCMap extends Record<string, RPCHandler>> = {
|
|
15
|
+
[K in keyof Nodes]: Nodes[K]['func'] extends keyof RPCMap ? RPCMap[Nodes[K]['func']]['output'] : unknown;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Node definition with RPC name reference
|
|
19
|
+
*/
|
|
20
|
+
export interface GraphNodeDef<RPCMap extends Record<string, RPCHandler>, NodeIds extends string = string, NodeOutputs extends Record<string, any> = Record<string, any>> {
|
|
21
|
+
/** RPC function name (must be a key in RPCMap) */
|
|
22
|
+
func: keyof RPCMap & string;
|
|
23
|
+
/** Input mapping - reference outputs from other nodes with autocomplete */
|
|
24
|
+
input?: (ref: <N extends keyof NodeOutputs & string>(nodeId: N, path: keyof NodeOutputs[N] & string) => RefValue) => Record<string, unknown>;
|
|
25
|
+
/** Next node(s) to execute */
|
|
26
|
+
next?: NextConfig<NodeIds>;
|
|
27
|
+
/** Error handling - node(s) to execute on error */
|
|
28
|
+
onError?: NodeIds | NodeIds[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Helper to create a type-safe graph definition with RPC autocomplete.
|
|
32
|
+
* Pass node IDs as first type parameter for type-safe next/ref/output key completion.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Import the typed graph from generated types
|
|
37
|
+
* import { pikkuWorkflowGraph, wireWorkflow } from './.pikku/workflow/pikku-workflow-types.gen.js'
|
|
38
|
+
*
|
|
39
|
+
* export const myGraph = pikkuWorkflowGraph({
|
|
40
|
+
* name: 'myWorkflow',
|
|
41
|
+
* nodes: {
|
|
42
|
+
* entry: 'createUserProfile', // autocompletes RPC names
|
|
43
|
+
* sendWelcome: 'sendEmail',
|
|
44
|
+
* },
|
|
45
|
+
* config: {
|
|
46
|
+
* entry: { next: 'sendWelcome' },
|
|
47
|
+
* sendWelcome: {
|
|
48
|
+
* input: (ref) => ({
|
|
49
|
+
* to: ref('entry', 'email'), // 'entry' and 'email' both autocomplete
|
|
50
|
+
* }),
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
*
|
|
55
|
+
* wireWorkflow({
|
|
56
|
+
* wires: { http: { route: '/start', method: 'post' } },
|
|
57
|
+
* graph: myGraph,
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Type to compute output types for all nodes based on their func mapping
|
|
63
|
+
*/
|
|
64
|
+
type ComputeNodeOutputs<FuncMap extends Record<string, string>, RPCMap extends Record<string, RPCHandler>> = {
|
|
65
|
+
[K in keyof FuncMap]: FuncMap[K] extends keyof RPCMap ? RPCMap[FuncMap[K]]['output'] : unknown;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Type to compute input types for all nodes based on their func mapping
|
|
69
|
+
*/
|
|
70
|
+
type ComputeNodeInputs<FuncMap extends Record<string, string>, RPCMap extends Record<string, RPCHandler>> = {
|
|
71
|
+
[K in keyof FuncMap]: FuncMap[K] extends keyof RPCMap ? RPCMap[FuncMap[K]]['input'] : unknown;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Typed ref value - carries the type of the referenced field as a phantom type.
|
|
75
|
+
* At runtime this is just RefValue, but TypeScript tracks the type T.
|
|
76
|
+
*/
|
|
77
|
+
export type TypedRef<T> = RefValue & {
|
|
78
|
+
__phantomType?: T;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Map input type fields to allow TypedRef of matching type as an alternative
|
|
82
|
+
*/
|
|
83
|
+
type InputWithRefs<T> = {
|
|
84
|
+
[K in keyof T]: T[K] | TypedRef<T[K]>;
|
|
85
|
+
};
|
|
86
|
+
export declare function createGraph<RPCMap extends Record<string, RPCHandler>>(): <const FuncMap extends Record<string, keyof RPCMap & string>>(funcMap: FuncMap, nodesOrBuilder?: GraphNodeConfigMap<FuncMap, RPCMap> | ((nodes: FuncMap) => GraphNodeConfigMap<FuncMap, RPCMap>)) => Record<Extract<keyof FuncMap, string>, GraphNodeConfig<Extract<keyof FuncMap, string>>>;
|
|
87
|
+
/**
|
|
88
|
+
* Type helper for node configuration map
|
|
89
|
+
*/
|
|
90
|
+
type GraphNodeConfigMap<FuncMap extends Record<string, string>, RPCMap extends Record<string, RPCHandler>> = {
|
|
91
|
+
[K in Extract<keyof FuncMap, string>]?: {
|
|
92
|
+
next?: NextConfig<Extract<keyof FuncMap, string>>;
|
|
93
|
+
input?: (ref: <N extends Extract<keyof FuncMap, string>, P extends keyof ComputeNodeOutputs<FuncMap, RPCMap>[N] & string>(nodeId: N, path: P) => TypedRef<ComputeNodeOutputs<FuncMap, RPCMap>[N][P]>) => InputWithRefs<ComputeNodeInputs<FuncMap, RPCMap>[K]>;
|
|
94
|
+
onError?: Extract<keyof FuncMap, string> | Extract<keyof FuncMap, string>[];
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Untyped graph for use without RPC map.
|
|
99
|
+
* Pass node IDs as type parameter for type-safe next/ref, or omit for untyped usage.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Typed usage - next and ref are type-checked
|
|
104
|
+
* graph<'entry' | 'sendWelcome'>({
|
|
105
|
+
* entry: { func: 'createUserProfile', next: 'sendWelcome' },
|
|
106
|
+
* sendWelcome: { func: 'sendEmail', input: (ref) => ({ to: ref('entry', 'email') }) },
|
|
107
|
+
* })
|
|
108
|
+
*
|
|
109
|
+
* // Untyped usage - no type checking on next/ref
|
|
110
|
+
* graph({
|
|
111
|
+
* entry: { func: 'createUserProfile', next: 'sendWelcome' },
|
|
112
|
+
* sendWelcome: { func: 'sendEmail' },
|
|
113
|
+
* })
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare function graph<NodeIds extends string = string>(nodes: Record<NodeIds, {
|
|
117
|
+
func: string;
|
|
118
|
+
next?: NextConfig<NodeIds>;
|
|
119
|
+
input?: (ref: (nodeId: NodeIds, path: string) => RefValue) => Record<string, unknown>;
|
|
120
|
+
onError?: NodeIds | NodeIds[];
|
|
121
|
+
}>): Record<NodeIds, GraphNodeConfig<NodeIds>>;
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function createGraph() {
|
|
2
|
+
return (funcMap, nodesOrBuilder) => {
|
|
3
|
+
// If no nodes provided, return just the funcMap converted to graph nodes
|
|
4
|
+
if (!nodesOrBuilder) {
|
|
5
|
+
const result = {};
|
|
6
|
+
for (const [nodeId, rpcName] of Object.entries(funcMap)) {
|
|
7
|
+
result[nodeId] = {
|
|
8
|
+
func: rpcName,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
const nodes = typeof nodesOrBuilder === 'function'
|
|
14
|
+
? nodesOrBuilder(funcMap)
|
|
15
|
+
: nodesOrBuilder;
|
|
16
|
+
const result = {};
|
|
17
|
+
for (const [nodeId, def] of Object.entries(nodes)) {
|
|
18
|
+
result[nodeId] = {
|
|
19
|
+
func: funcMap[nodeId],
|
|
20
|
+
input: def?.input,
|
|
21
|
+
next: def?.next,
|
|
22
|
+
onError: def?.onError,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Untyped graph for use without RPC map.
|
|
30
|
+
* Pass node IDs as type parameter for type-safe next/ref, or omit for untyped usage.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Typed usage - next and ref are type-checked
|
|
35
|
+
* graph<'entry' | 'sendWelcome'>({
|
|
36
|
+
* entry: { func: 'createUserProfile', next: 'sendWelcome' },
|
|
37
|
+
* sendWelcome: { func: 'sendEmail', input: (ref) => ({ to: ref('entry', 'email') }) },
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // Untyped usage - no type checking on next/ref
|
|
41
|
+
* graph({
|
|
42
|
+
* entry: { func: 'createUserProfile', next: 'sendWelcome' },
|
|
43
|
+
* sendWelcome: { func: 'sendEmail' },
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function graph(nodes) {
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const [nodeId, def] of Object.entries(nodes)) {
|
|
50
|
+
result[nodeId] = {
|
|
51
|
+
func: def.func,
|
|
52
|
+
input: def.input,
|
|
53
|
+
next: def.next,
|
|
54
|
+
onError: def.onError,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PikkuWorkflowService } from '../pikku-workflow-service.js';
|
|
2
|
+
import type { GraphNodeConfig, WorkflowGraphDefinition } from './workflow-graph.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Add a workflow graph to the system
|
|
5
|
+
* This is called by the generated workflow wirings
|
|
6
|
+
*/
|
|
7
|
+
export declare const addWorkflowGraph: (workflowName: string, graphResult: {
|
|
8
|
+
graph: Record<string, GraphNodeConfig<string>>;
|
|
9
|
+
wires?: any;
|
|
10
|
+
}) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Get a registered workflow graph by name
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWorkflowGraph(name: string): WorkflowGraphDefinition<any> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Continue graph execution
|
|
17
|
+
* Non-blocking - finds pending nodes, resolves inputs, queues them for execution
|
|
18
|
+
*/
|
|
19
|
+
export declare function continueGraph(workflowService: PikkuWorkflowService, runId: string, graphName: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Execute a graph step with wire context.
|
|
22
|
+
* Called by the step worker when executing graph nodes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function executeGraphStep(workflowService: PikkuWorkflowService, rpcService: any, runId: string, stepId: string, stepName: string, rpcName: string, data: any, graphName: string): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Handle node completion - re-triggers graph continuation
|
|
27
|
+
*/
|
|
28
|
+
export declare function onGraphNodeComplete(workflowService: PikkuWorkflowService, runId: string, graphName: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Start a workflow graph execution
|
|
31
|
+
* @param startNode - Optional starting node ID (from wire config). If not provided, uses wires.api from graph definition.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runWorkflowGraph(workflowService: PikkuWorkflowService, graphName: string, triggerInput: any, rpcService?: any, inline?: boolean, startNode?: string): Promise<{
|
|
34
|
+
runId: string;
|
|
35
|
+
}>;
|