@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.
Files changed (143) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/errors/error-handler.js +3 -3
  3. package/dist/function/function-runner.d.ts +4 -3
  4. package/dist/function/function-runner.js +60 -14
  5. package/dist/function/functions.types.d.ts +84 -5
  6. package/dist/function/functions.types.js +41 -1
  7. package/dist/index.d.ts +6 -2
  8. package/dist/index.js +5 -2
  9. package/dist/middleware/auth-apikey.d.ts +1 -1
  10. package/dist/middleware/auth-bearer.d.ts +1 -1
  11. package/dist/middleware/auth-cookie.d.ts +1 -1
  12. package/dist/middleware/timeout.d.ts +1 -1
  13. package/dist/middleware-runner.d.ts +3 -14
  14. package/dist/middleware-runner.js +8 -8
  15. package/dist/permissions.d.ts +3 -86
  16. package/dist/permissions.js +11 -67
  17. package/dist/pikku-state.d.ts +32 -104
  18. package/dist/pikku-state.js +140 -66
  19. package/dist/schema.d.ts +8 -6
  20. package/dist/schema.js +25 -13
  21. package/dist/services/workflow-service.d.ts +38 -0
  22. package/dist/services/workflow-service.js +1 -0
  23. package/dist/types/core.types.d.ts +12 -4
  24. package/dist/types/core.types.js +1 -1
  25. package/dist/types/state.types.d.ts +135 -0
  26. package/dist/types/state.types.js +1 -0
  27. package/dist/utils.d.ts +8 -0
  28. package/dist/utils.js +45 -0
  29. package/dist/wirings/channel/channel-handler.js +1 -1
  30. package/dist/wirings/channel/channel-runner.js +5 -5
  31. package/dist/wirings/channel/log-channels.js +1 -1
  32. package/dist/wirings/channel/serverless/serverless-channel-runner.js +2 -2
  33. package/dist/wirings/cli/channel/cli-channel-runner.js +3 -2
  34. package/dist/wirings/cli/cli-runner.js +10 -10
  35. package/dist/wirings/cli/cli.types.d.ts +1 -0
  36. package/dist/wirings/forge-node/forge-node.types.d.ts +120 -0
  37. package/dist/wirings/forge-node/forge-node.types.js +38 -0
  38. package/dist/wirings/forge-node/index.d.ts +1 -0
  39. package/dist/wirings/forge-node/index.js +1 -0
  40. package/dist/wirings/http/http-runner.d.ts +2 -2
  41. package/dist/wirings/http/http-runner.js +21 -12
  42. package/dist/wirings/http/http.types.d.ts +14 -1
  43. package/dist/wirings/http/log-http-routes.js +1 -1
  44. package/dist/wirings/http/routers/path-to-regex.js +2 -2
  45. package/dist/wirings/mcp/mcp-runner.js +21 -21
  46. package/dist/wirings/queue/queue-runner.js +6 -6
  47. package/dist/wirings/rpc/index.d.ts +1 -1
  48. package/dist/wirings/rpc/index.js +1 -1
  49. package/dist/wirings/rpc/rpc-runner.d.ts +7 -8
  50. package/dist/wirings/rpc/rpc-runner.js +62 -14
  51. package/dist/wirings/rpc/rpc-types.d.ts +7 -0
  52. package/dist/wirings/scheduler/log-schedulers.js +1 -1
  53. package/dist/wirings/scheduler/scheduler-runner.js +5 -5
  54. package/dist/wirings/trigger/index.d.ts +2 -0
  55. package/dist/wirings/trigger/index.js +2 -0
  56. package/dist/wirings/trigger/trigger-runner.d.ts +29 -0
  57. package/dist/wirings/trigger/trigger-runner.js +57 -0
  58. package/dist/wirings/trigger/trigger.types.d.ts +42 -0
  59. package/dist/wirings/trigger/trigger.types.js +1 -0
  60. package/dist/wirings/workflow/dsl/index.d.ts +5 -0
  61. package/dist/wirings/workflow/dsl/index.js +4 -0
  62. package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +286 -0
  63. package/dist/wirings/workflow/dsl/workflow-dsl.types.js +5 -0
  64. package/dist/wirings/workflow/dsl/workflow-runner.d.ts +5 -0
  65. package/dist/wirings/workflow/dsl/workflow-runner.js +22 -0
  66. package/dist/wirings/workflow/graph/graph-node.d.ts +122 -0
  67. package/dist/wirings/workflow/graph/graph-node.js +58 -0
  68. package/dist/wirings/workflow/graph/graph-runner.d.ts +35 -0
  69. package/dist/wirings/workflow/graph/graph-runner.js +452 -0
  70. package/dist/wirings/workflow/graph/index.d.ts +3 -0
  71. package/dist/wirings/workflow/graph/index.js +3 -0
  72. package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +95 -0
  73. package/dist/wirings/workflow/graph/workflow-graph.types.js +15 -0
  74. package/dist/wirings/workflow/index.d.ts +7 -12
  75. package/dist/wirings/workflow/index.js +6 -11
  76. package/dist/wirings/workflow/pikku-workflow-service.d.ts +96 -6
  77. package/dist/wirings/workflow/pikku-workflow-service.js +230 -103
  78. package/dist/wirings/workflow/wire-workflow.d.ts +42 -0
  79. package/dist/wirings/workflow/wire-workflow.js +53 -0
  80. package/dist/wirings/workflow/workflow-utils.d.ts +23 -0
  81. package/dist/wirings/workflow/workflow-utils.js +66 -0
  82. package/dist/wirings/workflow/workflow.types.d.ts +133 -211
  83. package/package.json +10 -1
  84. package/src/errors/error-handler.ts +3 -3
  85. package/src/function/function-runner.test.ts +1 -1
  86. package/src/function/function-runner.ts +86 -16
  87. package/src/function/functions.types.ts +126 -4
  88. package/src/index.ts +10 -5
  89. package/src/middleware-runner.ts +16 -9
  90. package/src/permissions.test.ts +28 -86
  91. package/src/permissions.ts +21 -80
  92. package/src/pikku-state.ts +156 -201
  93. package/src/schema.ts +42 -13
  94. package/src/services/workflow-service.ts +74 -0
  95. package/src/types/core.types.ts +12 -3
  96. package/src/types/state.types.ts +195 -0
  97. package/src/utils.ts +55 -0
  98. package/src/wirings/channel/channel-handler.ts +1 -1
  99. package/src/wirings/channel/channel-runner.ts +5 -5
  100. package/src/wirings/channel/local/local-channel-runner.test.ts +3 -1
  101. package/src/wirings/channel/log-channels.ts +1 -1
  102. package/src/wirings/channel/serverless/serverless-channel-runner.ts +2 -2
  103. package/src/wirings/cli/channel/cli-channel-runner.ts +4 -3
  104. package/src/wirings/cli/cli-runner.test.ts +19 -19
  105. package/src/wirings/cli/cli-runner.ts +10 -9
  106. package/src/wirings/cli/cli.types.ts +1 -0
  107. package/src/wirings/forge-node/forge-node.types.ts +135 -0
  108. package/src/wirings/forge-node/index.ts +1 -0
  109. package/src/wirings/http/http-runner.test.ts +2 -2
  110. package/src/wirings/http/http-runner.ts +30 -13
  111. package/src/wirings/http/http.types.ts +14 -0
  112. package/src/wirings/http/log-http-routes.ts +1 -1
  113. package/src/wirings/http/routers/path-to-regex.test.ts +30 -19
  114. package/src/wirings/http/routers/path-to-regex.ts +2 -2
  115. package/src/wirings/mcp/mcp-runner.ts +21 -21
  116. package/src/wirings/queue/queue-runner.test.ts +19 -19
  117. package/src/wirings/queue/queue-runner.ts +6 -6
  118. package/src/wirings/rpc/index.ts +1 -1
  119. package/src/wirings/rpc/rpc-runner.ts +88 -22
  120. package/src/wirings/rpc/rpc-types.ts +8 -0
  121. package/src/wirings/scheduler/log-schedulers.ts +1 -1
  122. package/src/wirings/scheduler/scheduler-runner.test.ts +27 -27
  123. package/src/wirings/scheduler/scheduler-runner.ts +5 -5
  124. package/src/wirings/trigger/index.ts +2 -0
  125. package/src/wirings/trigger/trigger-runner.ts +96 -0
  126. package/src/wirings/trigger/trigger.types.ts +56 -0
  127. package/src/wirings/workflow/dsl/index.ts +30 -0
  128. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +312 -0
  129. package/src/wirings/workflow/dsl/workflow-runner.ts +27 -0
  130. package/src/wirings/workflow/graph/graph-node.ts +227 -0
  131. package/src/wirings/workflow/graph/graph-runner.ts +694 -0
  132. package/src/wirings/workflow/graph/index.ts +3 -0
  133. package/src/wirings/workflow/graph/workflow-graph.types.ts +126 -0
  134. package/src/wirings/workflow/index.ts +53 -26
  135. package/src/wirings/workflow/pikku-workflow-service.ts +333 -117
  136. package/src/wirings/workflow/wire-workflow.ts +94 -0
  137. package/src/wirings/workflow/workflow-utils.ts +120 -0
  138. package/src/wirings/workflow/workflow.types.ts +166 -277
  139. package/tsconfig.tsbuildinfo +1 -1
  140. package/dist/wirings/workflow/workflow-runner.d.ts +0 -34
  141. package/dist/wirings/workflow/workflow-runner.js +0 -65
  142. package/src/function/function-runner.ts.bak +0 -188
  143. package/src/wirings/workflow/workflow-runner.ts +0 -72
@@ -0,0 +1,53 @@
1
+ import { pikkuState } from '../../pikku-state.js';
2
+ /**
3
+ * Type guard for DSL workflow definition
4
+ */
5
+ function isWorkflowDefinitionFunc(def) {
6
+ return 'func' in def;
7
+ }
8
+ /**
9
+ * Type guard for graph workflow definition
10
+ */
11
+ function isWorkflowDefinitionGraph(def) {
12
+ return 'graph' in def;
13
+ }
14
+ /**
15
+ * Wire a workflow with triggers.
16
+ * Accepts either a DSL function (func) or a graph definition (graph).
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // DSL workflow
21
+ * wireWorkflow({
22
+ * wires: { http: { route: '/start', method: 'post' } },
23
+ * func: myWorkflowFunc,
24
+ * })
25
+ *
26
+ * // Graph workflow
27
+ * wireWorkflow({
28
+ * wires: { http: { route: '/graph-start', method: 'post' } },
29
+ * graph: myGraphWorkflow,
30
+ * })
31
+ * ```
32
+ */
33
+ export function wireWorkflow(definition) {
34
+ if (isWorkflowDefinitionFunc(definition)) {
35
+ // DSL workflow - store wiring for later registration by inspector
36
+ const wirings = pikkuState(null, 'workflows', 'wirings');
37
+ // The wiring will be matched to the function by the inspector
38
+ // Store the func reference and wires
39
+ wirings.set(definition.func, {
40
+ wires: definition.wires,
41
+ func: definition.func,
42
+ });
43
+ }
44
+ else if (isWorkflowDefinitionGraph(definition)) {
45
+ // Graph workflow - store for registration
46
+ const graphWirings = pikkuState(null, 'workflows', 'graphWirings');
47
+ // Store the graph reference and wires
48
+ graphWirings.set(definition.graph, {
49
+ wires: definition.wires,
50
+ graph: definition.graph,
51
+ });
52
+ }
53
+ }
@@ -0,0 +1,23 @@
1
+ import { PikkuWire, CreateWireServices, CoreSingletonServices, CoreServices, CoreUserSession } from '../../types/core.types.js';
2
+ import { HTTPWiringMeta } from '../http/http.types.js';
3
+ /**
4
+ * Result of finding a workflow by HTTP wire
5
+ */
6
+ export interface WorkflowHttpMatch {
7
+ workflowName: string;
8
+ startNode?: string;
9
+ }
10
+ /**
11
+ * Find workflow name by matching route and method against workflow wires
12
+ */
13
+ export declare const findWorkflowByHttpWire: (route: string, method: string) => WorkflowHttpMatch | undefined;
14
+ /**
15
+ * Start a workflow triggered by an HTTP wire
16
+ * The workflow is responsible for handling the HTTP response
17
+ */
18
+ export declare const startWorkflowByHttpWire: (singletonServices: CoreSingletonServices, createWireServices: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession> | undefined, matchedRoute: {
19
+ matchedPath: any;
20
+ params: any;
21
+ route: any;
22
+ meta: HTTPWiringMeta;
23
+ }, wire: PikkuWire) => Promise<void>;
@@ -0,0 +1,66 @@
1
+ import { pikkuState } from '../../pikku-state.js';
2
+ import { NotFoundError } from '../../errors/errors.js';
3
+ import { ContextAwareRPCService } from '../rpc/rpc-runner.js';
4
+ /**
5
+ * Find workflow name by matching route and method against workflow wires
6
+ */
7
+ export const findWorkflowByHttpWire = (route, method) => {
8
+ const wirings = pikkuState(null, 'workflows', 'wirings');
9
+ const graphWirings = pikkuState(null, 'workflows', 'graphWirings');
10
+ // Check DSL workflow wirings
11
+ for (const [, wiring] of wirings) {
12
+ const httpWires = wiring.wires?.http;
13
+ if (httpWires) {
14
+ const matchedWire = httpWires.find((w) => w.route === route && w.method === method);
15
+ if (matchedWire) {
16
+ const meta = pikkuState(null, 'workflows', 'meta');
17
+ for (const [name, workflowMeta] of Object.entries(meta)) {
18
+ if (workflowMeta.source !== 'graph') {
19
+ const registrations = pikkuState(null, 'workflows', 'registrations');
20
+ if (registrations.has(name)) {
21
+ return { workflowName: name, startNode: matchedWire.startNode };
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ // Check graph workflow wirings
29
+ for (const [, wiring] of graphWirings) {
30
+ const httpWires = wiring.wires?.http;
31
+ if (httpWires) {
32
+ const matchedWire = httpWires.find((w) => w.route === route && w.method === method);
33
+ if (matchedWire) {
34
+ const meta = pikkuState(null, 'workflows', 'meta');
35
+ for (const [name, workflowMeta] of Object.entries(meta)) {
36
+ if (workflowMeta.source === 'graph') {
37
+ return { workflowName: name, startNode: matchedWire.startNode };
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ return undefined;
44
+ };
45
+ /**
46
+ * Start a workflow triggered by an HTTP wire
47
+ * The workflow is responsible for handling the HTTP response
48
+ */
49
+ export const startWorkflowByHttpWire = async (singletonServices, createWireServices, matchedRoute, wire) => {
50
+ const { meta } = matchedRoute;
51
+ const match = findWorkflowByHttpWire(meta.route, meta.method);
52
+ if (!match) {
53
+ throw new NotFoundError(`No workflow found for route ${meta.method.toUpperCase()} ${meta.route}`);
54
+ }
55
+ const workflowService = singletonServices.workflowService;
56
+ if (!workflowService) {
57
+ throw new Error('WorkflowService not available');
58
+ }
59
+ const data = await wire.http.request.data();
60
+ const wireServices = createWireServices?.(singletonServices, wire);
61
+ const rpcService = new ContextAwareRPCService({ ...singletonServices, ...wireServices }, wire, {});
62
+ await workflowService.startWorkflow(match.workflowName, data, rpcService, {
63
+ inline: true,
64
+ startNode: match.startNode,
65
+ });
66
+ };
@@ -1,5 +1,8 @@
1
- import { SerializedError, CoreSingletonServices, CreateWireServices, CoreConfig, CommonWireMeta } from '../../types/core.types.js';
1
+ import { SerializedError, CommonWireMeta } from '../../types/core.types.js';
2
2
  import { CorePikkuFunctionConfig } from '../../function/functions.types.js';
3
+ export type { WorkflowService } from '../../services/workflow-service.js';
4
+ export type { WorkflowStepOptions, WorkflowWireDoRPC, WorkflowWireDoInline, WorkflowWireSleep, InputSource, OutputBinding, RpcStepMeta, SimpleCondition, Condition, BranchCase, BranchStepMeta, ParallelGroupStepMeta, FanoutStepMeta, ReturnStepMeta, InlineStepMeta, SleepStepMeta, CancelStepMeta, SetStepMeta, SwitchCaseMeta, SwitchStepMeta, FilterStepMeta, ArrayPredicateStepMeta, WorkflowStepMeta, WorkflowStepWire, PikkuWorkflowWire, } from './dsl/workflow-dsl.types.js';
5
+ import type { WorkflowStepMeta } from './dsl/workflow-dsl.types.js';
3
6
  export interface WorkflowServiceConfig {
4
7
  retries: number;
5
8
  retryDelay: number;
@@ -7,6 +10,91 @@ export interface WorkflowServiceConfig {
7
10
  stepWorkerQueueName: string;
8
11
  sleeperRPCName: string;
9
12
  }
13
+ /**
14
+ * HTTP wire configuration for workflows
15
+ */
16
+ export interface WorkflowHTTPWire {
17
+ route: string;
18
+ method: 'get' | 'post' | 'put' | 'patch' | 'delete';
19
+ startNode: string;
20
+ }
21
+ /**
22
+ * Channel wire configuration for workflows
23
+ */
24
+ export interface WorkflowChannelWire {
25
+ name: string;
26
+ onConnect?: string;
27
+ onDisconnect?: string;
28
+ onMessage?: string;
29
+ }
30
+ /**
31
+ * Queue wire configuration for workflows
32
+ */
33
+ export interface WorkflowQueueWire {
34
+ name: string;
35
+ startNode: string;
36
+ }
37
+ /**
38
+ * CLI wire configuration for workflows
39
+ */
40
+ export interface WorkflowCliWire {
41
+ command: string;
42
+ startNode: string;
43
+ }
44
+ /**
45
+ * MCP wire configurations for workflows
46
+ */
47
+ export interface WorkflowMcpWires {
48
+ tool?: Array<{
49
+ name: string;
50
+ startNode: string;
51
+ }>;
52
+ prompt?: Array<{
53
+ name: string;
54
+ startNode: string;
55
+ }>;
56
+ resource?: Array<{
57
+ uri: string;
58
+ startNode: string;
59
+ }>;
60
+ }
61
+ /**
62
+ * Schedule wire configuration for workflows
63
+ */
64
+ export interface WorkflowScheduleWire {
65
+ cron?: string;
66
+ interval?: string;
67
+ startNode: string;
68
+ }
69
+ /**
70
+ * Trigger wire configuration for workflows
71
+ */
72
+ export interface WorkflowTriggerWire {
73
+ name: string;
74
+ startNode: string;
75
+ }
76
+ /**
77
+ * Wire configuration for workflows
78
+ * Defines how a workflow can be triggered
79
+ */
80
+ export interface WorkflowWires {
81
+ /** API entry point - node ID for startWorkflow() calls */
82
+ api?: string;
83
+ /** HTTP triggers */
84
+ http?: WorkflowHTTPWire[];
85
+ /** Channel triggers */
86
+ channel?: WorkflowChannelWire[];
87
+ /** Queue triggers */
88
+ queue?: WorkflowQueueWire[];
89
+ /** CLI triggers */
90
+ cli?: WorkflowCliWire[];
91
+ /** MCP triggers (tool, prompt, resource) */
92
+ mcp?: WorkflowMcpWires;
93
+ /** Schedule triggers */
94
+ schedule?: WorkflowScheduleWire[];
95
+ /** Named trigger wires */
96
+ trigger?: WorkflowTriggerWire[];
97
+ }
10
98
  /**
11
99
  * Workflow run status
12
100
  */
@@ -31,6 +119,8 @@ export interface WorkflowRun {
31
119
  output?: any;
32
120
  /** Error (if failed) */
33
121
  error?: SerializedError;
122
+ /** If true, workflow executes inline without queues */
123
+ inline?: boolean;
34
124
  /** Creation timestamp */
35
125
  createdAt: Date;
36
126
  /** Last update timestamp */
@@ -82,183 +172,6 @@ export type CoreWorkflow<PikkuFunctionConfig extends CorePikkuFunctionConfig<any
82
172
  /** Tags for organization and filtering */
83
173
  tags?: string[];
84
174
  };
85
- /**
86
- * Workflow step options
87
- */
88
- export interface WorkflowStepOptions {
89
- /** Display name for logs/UI (optional, doesn't affect execution) */
90
- description?: string;
91
- /** Number of retry attempts for failed steps (only applies to local execution) */
92
- retries?: number;
93
- /** Delay between retry attempts (e.g., '1s', '2s', '2min') */
94
- retryDelay?: string | number;
95
- }
96
- /**
97
- * Type signature for workflow.do() RPC form - used by inspector
98
- */
99
- export type WorkflowWireDoRPC = <TOutput = any, TInput = any>(stepName: string, rpcName: string, data: TInput, options?: WorkflowStepOptions) => Promise<TOutput>;
100
- /**
101
- * Type signature for workflow.do() inline form - used by inspector
102
- */
103
- export type WorkflowWireDoInline = <T>(stepName: string, fn: () => Promise<T> | T, options?: WorkflowStepOptions) => Promise<T>;
104
- /**
105
- * Type signature for workflow.sleep() - used by inspector
106
- */
107
- export type WorkflowWireSleep = (stepName: string, duration: string) => Promise<void>;
108
- /**
109
- * Input source for step arguments in simple workflows
110
- */
111
- export type InputSource = {
112
- from: 'input';
113
- path: string;
114
- } | {
115
- from: 'outputVar';
116
- name: string;
117
- path?: string;
118
- } | {
119
- from: 'item';
120
- path: string;
121
- } | {
122
- from: 'literal';
123
- value: unknown;
124
- };
125
- /**
126
- * Output binding for return statements in simple workflows
127
- */
128
- export interface OutputBinding {
129
- from: 'outputVar' | 'input';
130
- name?: string;
131
- path?: string;
132
- }
133
- /**
134
- * RPC step metadata (base form)
135
- */
136
- export interface RpcStepMeta {
137
- /** RPC form - generates queue worker */
138
- type: 'rpc';
139
- /** Cache key (stepName from workflow.do) */
140
- stepName: string;
141
- /** RPC to invoke */
142
- rpcName: string;
143
- /** Output variable name (if assigned) */
144
- outputVar?: string;
145
- /** Input source mappings */
146
- inputs?: Record<string, InputSource>;
147
- /** Step options */
148
- options?: WorkflowStepOptions;
149
- }
150
- /**
151
- * Branch step metadata (if/else control flow)
152
- */
153
- export interface BranchStepMeta {
154
- type: 'branch';
155
- /** Condition expression (as source string) */
156
- condition: string;
157
- /** Branch paths */
158
- branches: {
159
- then: WorkflowStepMeta[];
160
- else?: WorkflowStepMeta[];
161
- };
162
- }
163
- /**
164
- * Parallel group step metadata (Promise.all with multiple steps)
165
- */
166
- export interface ParallelGroupStepMeta {
167
- type: 'parallel';
168
- /** Child steps to execute in parallel */
169
- children: RpcStepMeta[];
170
- }
171
- /**
172
- * Fanout step metadata (parallel or sequential iteration)
173
- */
174
- export interface FanoutStepMeta {
175
- type: 'fanout';
176
- /** Step name for this fanout */
177
- stepName: string;
178
- /** Source array variable name */
179
- sourceVar: string;
180
- /** Iterator variable name */
181
- itemVar: string;
182
- /** Execution mode */
183
- mode: 'parallel' | 'sequential';
184
- /** Child step to execute per iteration */
185
- child: RpcStepMeta;
186
- /** Time between iterations (sequential mode only) */
187
- timeBetween?: string;
188
- }
189
- /**
190
- * Return step metadata (workflow output)
191
- */
192
- export interface ReturnStepMeta {
193
- type: 'return';
194
- /** Output bindings */
195
- outputs: Record<string, OutputBinding>;
196
- }
197
- /**
198
- * Inline step metadata (legacy support)
199
- */
200
- export interface InlineStepMeta {
201
- /** Inline form - local execution */
202
- type: 'inline';
203
- /** Cache key (stepName from workflow.do) */
204
- stepName: string;
205
- /** Display name */
206
- description?: string;
207
- /** Step options */
208
- options?: WorkflowStepOptions;
209
- }
210
- /**
211
- * Sleep step metadata
212
- */
213
- export interface SleepStepMeta {
214
- /** Sleep step */
215
- type: 'sleep';
216
- /** Cache key (stepName from workflow.sleep) */
217
- stepName: string;
218
- /** Sleep duration */
219
- duration: string | number;
220
- }
221
- /**
222
- * Cancel step metadata
223
- */
224
- export interface CancelStepMeta {
225
- /** Cancel step */
226
- type: 'cancel';
227
- }
228
- /**
229
- * Workflow step metadata (extracted by inspector)
230
- */
231
- export type WorkflowStepMeta = RpcStepMeta | BranchStepMeta | ParallelGroupStepMeta | FanoutStepMeta | ReturnStepMeta | InlineStepMeta | SleepStepMeta | CancelStepMeta;
232
- /**
233
- * Workflow step wire context for RPC functions
234
- * Provides step-level metadata including retry attempt tracking
235
- */
236
- export interface WorkflowStepWire {
237
- /** The workflow run ID */
238
- runId: string;
239
- /** The unique step ID */
240
- stepId: string;
241
- /** Current attempt number (1-indexed, increments on retry) */
242
- attemptCount: number;
243
- }
244
- /**
245
- * Workflow wire object for middleware
246
- * Provides workflow-specific capabilities to function execution
247
- */
248
- export interface PikkuWorkflowWire {
249
- /** The workflow name */
250
- workflowName: string;
251
- /** The current run ID */
252
- runId: string;
253
- /** Get the current workflow run */
254
- getRun: () => Promise<WorkflowRun>;
255
- /** Execute a workflow step (overloaded - RPC or inline form) */
256
- do: WorkflowWireDoRPC & WorkflowWireDoInline;
257
- /** Sleep for a duration */
258
- sleep: WorkflowWireSleep;
259
- /** Cancel the current workflow run */
260
- cancel: (reason?: string) => Promise<void>;
261
- }
262
175
  /**
263
176
  * Workflow client interface
264
177
  */
@@ -273,47 +186,56 @@ export interface PikkuWorkflow {
273
186
  cancelRun: (runId: string) => Promise<void>;
274
187
  }
275
188
  /**
276
- * Workflows metadata for inspector/CLI
189
+ * Context variable definition (serialized from Zod schema or type inference)
190
+ */
191
+ export interface ContextVariable {
192
+ /** Variable type */
193
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
194
+ /** Default value */
195
+ default?: unknown;
196
+ /** Description for UI/docs */
197
+ description?: string;
198
+ }
199
+ /**
200
+ * Workflow context - state variables with defaults and types
201
+ */
202
+ export type WorkflowContext = Record<string, ContextVariable>;
203
+ /**
204
+ * Workflows metadata for inspector/CLI (DSL step-based format)
277
205
  */
278
206
  export type WorkflowsMeta = Record<string, CommonWireMeta & {
279
207
  workflowName: string;
280
208
  steps: WorkflowStepMeta[];
281
- /** Whether this workflow conforms to simple workflow DSL */
282
- simple?: boolean;
209
+ context?: WorkflowContext;
210
+ dsl?: boolean;
283
211
  }>;
284
212
  /**
285
- * Interface for workflow orchestration
286
- * Handles workflow execution, replay, orchestration logic, and run-level state
213
+ * Unified workflow runtime meta (used by runtime to execute workflows)
214
+ * This is the format stored in pikkuState('workflows', 'meta')
215
+ * Both DSL and graph-based workflows are converted to this format
287
216
  */
288
- export interface WorkflowService {
289
- createRun(workflowName: string, input: any): Promise<string>;
290
- getRun(id: string): Promise<WorkflowRun | null>;
291
- getRunHistory(runId: string): Promise<Array<StepState & {
292
- stepName: string;
293
- }>>;
294
- updateRunStatus(id: string, status: WorkflowStatus, output?: any, error?: SerializedError): Promise<void>;
295
- withRunLock<T>(id: string, fn: () => Promise<T>): Promise<T>;
296
- close(): Promise<void>;
297
- resumeWorkflow(runId: string): Promise<void>;
298
- setServices(singletonServices: CoreSingletonServices, createWireServices: CreateWireServices, config: CoreConfig): void;
299
- startWorkflow<I>(name: string, input: I, rpcService: any): Promise<{
300
- runId: string;
301
- }>;
302
- runWorkflowJob(runId: string, rpcService: any): Promise<void>;
303
- orchestrateWorkflow(runId: string, rpcService: any): Promise<void>;
304
- executeWorkflowSleep(runId: string, stepId: string): Promise<void>;
305
- insertStepState(runId: string, stepName: string, rpcName: string, data: any, stepOptions?: {
306
- retries?: number;
307
- retryDelay?: string | number;
308
- }): Promise<StepState>;
309
- getStepState(runId: string, stepName: string): Promise<StepState>;
310
- setStepRunning(stepId: string): Promise<void>;
311
- setStepScheduled(stepId: string): Promise<void>;
312
- setStepResult(stepId: string, result: any): Promise<void>;
313
- setStepError(stepId: string, error: Error): Promise<void>;
314
- createRetryAttempt(stepId: string, status: 'pending' | 'running'): Promise<StepState>;
315
- executeWorkflowStep(runId: string, stepName: string, rpcName: string | null, data: any, rpcService: any): Promise<void>;
217
+ export interface WorkflowRuntimeMeta {
218
+ /** Workflow name (used as key in registrations) */
219
+ name: string;
220
+ /** Pikku function name (for execution) */
221
+ pikkuFuncName: string;
222
+ /** Source type: 'dsl' (serializable), 'complex' (has inline steps), 'graph' */
223
+ source?: 'dsl' | 'complex' | 'graph';
224
+ /** Optional description */
225
+ description?: string;
226
+ /** Tags for organization */
227
+ tags?: string[];
228
+ /** Wires - how the workflow is triggered */
229
+ wires?: WorkflowWires;
230
+ /** Serialized nodes */
231
+ nodes?: Record<string, any>;
232
+ /** Entry node IDs for graph workflows (computed at build time) */
233
+ entryNodeIds?: string[];
316
234
  }
235
+ /**
236
+ * Unified workflow runtime metadata map
237
+ */
238
+ export type WorkflowsRuntimeMeta = Record<string, WorkflowRuntimeMeta>;
317
239
  /**
318
240
  * Worker input types for generated queue workers
319
241
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/core",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -30,6 +30,7 @@
30
30
  "./mcp": "./dist/wirings/mcp/index.js",
31
31
  "./cli": "./dist/wirings/cli/index.js",
32
32
  "./cli/channel": "./dist/wirings/cli/channel/index.js",
33
+ "./forge-node": "./dist/wirings/forge-node/index.js",
33
34
  "./errors": "./dist/errors/index.js",
34
35
  "./services": "./dist/services/index.js",
35
36
  "./services/local-content": "./dist/services/local-content.js",
@@ -46,6 +47,14 @@
46
47
  "tsx": "^4.20.6",
47
48
  "typescript": "^5.9"
48
49
  },
50
+ "peerDependencies": {
51
+ "zod": "^4.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "zod": {
55
+ "optional": true
56
+ }
57
+ },
49
58
  "engines": {
50
59
  "node": ">=18"
51
60
  }
@@ -30,7 +30,7 @@ export interface ErrorDetails {
30
30
  * @param details - The details of the error.
31
31
  */
32
32
  export const addError = (error: any, { status, message }: ErrorDetails) => {
33
- pikkuState('misc', 'errors').set(error, { status, message })
33
+ pikkuState(null, 'misc', 'errors').set(error, { status, message })
34
34
  }
35
35
 
36
36
  /**
@@ -53,10 +53,10 @@ export const addErrors = (
53
53
  export const getErrorResponse = (
54
54
  error: Error
55
55
  ): { status: number; message: string; mcpCode?: number } | undefined => {
56
- const errors = Array.from(pikkuState('misc', 'errors').entries())
56
+ const errors = Array.from(pikkuState(null, 'misc', 'errors').entries())
57
57
  const foundError = errors.find(([e]) => e.name === error.constructor.name)
58
58
  if (foundError) {
59
59
  return foundError[1]
60
60
  }
61
- return pikkuState('misc', 'errors').get(error)
61
+ return pikkuState(null, 'misc', 'errors').get(error)
62
62
  }
@@ -21,7 +21,7 @@ const addTestFunction = (funcName: string, funcConfig: any) => {
21
21
  const permissions = funcConfig.tags
22
22
  ? funcConfig.tags.map((tag: string) => ({ type: 'tag' as const, tag }))
23
23
  : undefined
24
- pikkuState('function', 'meta')[funcName] = {
24
+ pikkuState(null, 'function', 'meta')[funcName] = {
25
25
  pikkuFuncName: funcName,
26
26
  inputSchemaName: null,
27
27
  outputSchemaName: null,