@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,94 @@
|
|
|
1
|
+
import { pikkuState } from '../../pikku-state.js'
|
|
2
|
+
import type { WorkflowWires } from './workflow.types.js'
|
|
3
|
+
import type { GraphNodeConfig } from './graph/workflow-graph.types.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Workflow definition with DSL function
|
|
7
|
+
*/
|
|
8
|
+
export interface WorkflowDefinitionFunc {
|
|
9
|
+
wires: WorkflowWires
|
|
10
|
+
func: { func: (...args: any[]) => any } | ((...args: any[]) => any)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Workflow definition with graph
|
|
15
|
+
*/
|
|
16
|
+
export interface WorkflowDefinitionGraph<
|
|
17
|
+
T extends Record<string, GraphNodeConfig<string>> = Record<
|
|
18
|
+
string,
|
|
19
|
+
GraphNodeConfig<string>
|
|
20
|
+
>,
|
|
21
|
+
> {
|
|
22
|
+
wires: WorkflowWires
|
|
23
|
+
graph: T
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Union type for workflow definitions
|
|
28
|
+
*/
|
|
29
|
+
export type WorkflowDefinition<
|
|
30
|
+
T extends Record<string, GraphNodeConfig<string>> = Record<
|
|
31
|
+
string,
|
|
32
|
+
GraphNodeConfig<string>
|
|
33
|
+
>,
|
|
34
|
+
> = WorkflowDefinitionFunc | WorkflowDefinitionGraph<T>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Type guard for DSL workflow definition
|
|
38
|
+
*/
|
|
39
|
+
function isWorkflowDefinitionFunc(
|
|
40
|
+
def: WorkflowDefinition
|
|
41
|
+
): def is WorkflowDefinitionFunc {
|
|
42
|
+
return 'func' in def
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Type guard for graph workflow definition
|
|
47
|
+
*/
|
|
48
|
+
function isWorkflowDefinitionGraph(
|
|
49
|
+
def: WorkflowDefinition
|
|
50
|
+
): def is WorkflowDefinitionGraph {
|
|
51
|
+
return 'graph' in def
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wire a workflow with triggers.
|
|
56
|
+
* Accepts either a DSL function (func) or a graph definition (graph).
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // DSL workflow
|
|
61
|
+
* wireWorkflow({
|
|
62
|
+
* wires: { http: { route: '/start', method: 'post' } },
|
|
63
|
+
* func: myWorkflowFunc,
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* // Graph workflow
|
|
67
|
+
* wireWorkflow({
|
|
68
|
+
* wires: { http: { route: '/graph-start', method: 'post' } },
|
|
69
|
+
* graph: myGraphWorkflow,
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function wireWorkflow<T extends Record<string, GraphNodeConfig<string>>>(
|
|
74
|
+
definition: WorkflowDefinitionFunc | WorkflowDefinitionGraph<T>
|
|
75
|
+
): void {
|
|
76
|
+
if (isWorkflowDefinitionFunc(definition)) {
|
|
77
|
+
// DSL workflow - store wiring for later registration by inspector
|
|
78
|
+
const wirings = pikkuState(null, 'workflows', 'wirings')
|
|
79
|
+
// The wiring will be matched to the function by the inspector
|
|
80
|
+
// Store the func reference and wires
|
|
81
|
+
wirings.set(definition.func, {
|
|
82
|
+
wires: definition.wires,
|
|
83
|
+
func: definition.func,
|
|
84
|
+
})
|
|
85
|
+
} else if (isWorkflowDefinitionGraph(definition)) {
|
|
86
|
+
// Graph workflow - store for registration
|
|
87
|
+
const graphWirings = pikkuState(null, 'workflows', 'graphWirings')
|
|
88
|
+
// Store the graph reference and wires
|
|
89
|
+
graphWirings.set(definition.graph, {
|
|
90
|
+
wires: definition.wires,
|
|
91
|
+
graph: definition.graph,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { pikkuState } from '../../pikku-state.js'
|
|
2
|
+
import { NotFoundError } from '../../errors/errors.js'
|
|
3
|
+
import {
|
|
4
|
+
PikkuWire,
|
|
5
|
+
CreateWireServices,
|
|
6
|
+
CoreSingletonServices,
|
|
7
|
+
CoreServices,
|
|
8
|
+
CoreUserSession,
|
|
9
|
+
} from '../../types/core.types.js'
|
|
10
|
+
import { HTTPWiringMeta } from '../http/http.types.js'
|
|
11
|
+
import { ContextAwareRPCService } from '../rpc/rpc-runner.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Result of finding a workflow by HTTP wire
|
|
15
|
+
*/
|
|
16
|
+
export interface WorkflowHttpMatch {
|
|
17
|
+
workflowName: string
|
|
18
|
+
startNode?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Find workflow name by matching route and method against workflow wires
|
|
23
|
+
*/
|
|
24
|
+
export const findWorkflowByHttpWire = (
|
|
25
|
+
route: string,
|
|
26
|
+
method: string
|
|
27
|
+
): WorkflowHttpMatch | undefined => {
|
|
28
|
+
const wirings = pikkuState(null, 'workflows', 'wirings')
|
|
29
|
+
const graphWirings = pikkuState(null, 'workflows', 'graphWirings')
|
|
30
|
+
|
|
31
|
+
// Check DSL workflow wirings
|
|
32
|
+
for (const [, wiring] of wirings) {
|
|
33
|
+
const httpWires = wiring.wires?.http
|
|
34
|
+
if (httpWires) {
|
|
35
|
+
const matchedWire = httpWires.find(
|
|
36
|
+
(w) => w.route === route && w.method === method
|
|
37
|
+
)
|
|
38
|
+
if (matchedWire) {
|
|
39
|
+
const meta = pikkuState(null, 'workflows', 'meta')
|
|
40
|
+
for (const [name, workflowMeta] of Object.entries(meta)) {
|
|
41
|
+
if (workflowMeta.source !== 'graph') {
|
|
42
|
+
const registrations = pikkuState(null, 'workflows', 'registrations')
|
|
43
|
+
if (registrations.has(name)) {
|
|
44
|
+
return { workflowName: name, startNode: matchedWire.startNode }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Check graph workflow wirings
|
|
53
|
+
for (const [, wiring] of graphWirings) {
|
|
54
|
+
const httpWires = wiring.wires?.http
|
|
55
|
+
if (httpWires) {
|
|
56
|
+
const matchedWire = httpWires.find(
|
|
57
|
+
(w) => w.route === route && w.method === method
|
|
58
|
+
)
|
|
59
|
+
if (matchedWire) {
|
|
60
|
+
const meta = pikkuState(null, 'workflows', 'meta')
|
|
61
|
+
for (const [name, workflowMeta] of Object.entries(meta)) {
|
|
62
|
+
if (workflowMeta.source === 'graph') {
|
|
63
|
+
return { workflowName: name, startNode: matchedWire.startNode }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return undefined
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Start a workflow triggered by an HTTP wire
|
|
75
|
+
* The workflow is responsible for handling the HTTP response
|
|
76
|
+
*/
|
|
77
|
+
export const startWorkflowByHttpWire = async (
|
|
78
|
+
singletonServices: CoreSingletonServices,
|
|
79
|
+
createWireServices:
|
|
80
|
+
| CreateWireServices<
|
|
81
|
+
CoreSingletonServices,
|
|
82
|
+
CoreServices<CoreSingletonServices>,
|
|
83
|
+
CoreUserSession
|
|
84
|
+
>
|
|
85
|
+
| undefined,
|
|
86
|
+
matchedRoute: {
|
|
87
|
+
matchedPath: any
|
|
88
|
+
params: any
|
|
89
|
+
route: any
|
|
90
|
+
meta: HTTPWiringMeta
|
|
91
|
+
},
|
|
92
|
+
wire: PikkuWire
|
|
93
|
+
): Promise<void> => {
|
|
94
|
+
const { meta } = matchedRoute
|
|
95
|
+
|
|
96
|
+
const match = findWorkflowByHttpWire(meta.route, meta.method)
|
|
97
|
+
if (!match) {
|
|
98
|
+
throw new NotFoundError(
|
|
99
|
+
`No workflow found for route ${meta.method.toUpperCase()} ${meta.route}`
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const workflowService = singletonServices.workflowService
|
|
104
|
+
if (!workflowService) {
|
|
105
|
+
throw new Error('WorkflowService not available')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const data = await wire.http!.request!.data()
|
|
109
|
+
|
|
110
|
+
const wireServices = createWireServices?.(singletonServices, wire)
|
|
111
|
+
const rpcService = new ContextAwareRPCService(
|
|
112
|
+
{ ...singletonServices, ...wireServices },
|
|
113
|
+
wire,
|
|
114
|
+
{}
|
|
115
|
+
)
|
|
116
|
+
await workflowService.startWorkflow(match.workflowName, data, rpcService, {
|
|
117
|
+
inline: true,
|
|
118
|
+
startNode: match.startNode,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
@@ -1,12 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SerializedError,
|
|
3
|
-
CoreSingletonServices,
|
|
4
|
-
CreateWireServices,
|
|
5
|
-
CoreConfig,
|
|
6
|
-
CommonWireMeta,
|
|
7
|
-
} from '../../types/core.types.js'
|
|
1
|
+
import { SerializedError, CommonWireMeta } from '../../types/core.types.js'
|
|
8
2
|
import { CorePikkuFunctionConfig } from '../../function/functions.types.js'
|
|
9
3
|
|
|
4
|
+
// Re-export WorkflowService from services module
|
|
5
|
+
export type { WorkflowService } from '../../services/workflow-service.js'
|
|
6
|
+
|
|
7
|
+
// Re-export DSL types from dsl module
|
|
8
|
+
export type {
|
|
9
|
+
WorkflowStepOptions,
|
|
10
|
+
WorkflowWireDoRPC,
|
|
11
|
+
WorkflowWireDoInline,
|
|
12
|
+
WorkflowWireSleep,
|
|
13
|
+
InputSource,
|
|
14
|
+
OutputBinding,
|
|
15
|
+
RpcStepMeta,
|
|
16
|
+
SimpleCondition,
|
|
17
|
+
Condition,
|
|
18
|
+
BranchCase,
|
|
19
|
+
BranchStepMeta,
|
|
20
|
+
ParallelGroupStepMeta,
|
|
21
|
+
FanoutStepMeta,
|
|
22
|
+
ReturnStepMeta,
|
|
23
|
+
InlineStepMeta,
|
|
24
|
+
SleepStepMeta,
|
|
25
|
+
CancelStepMeta,
|
|
26
|
+
SetStepMeta,
|
|
27
|
+
SwitchCaseMeta,
|
|
28
|
+
SwitchStepMeta,
|
|
29
|
+
FilterStepMeta,
|
|
30
|
+
ArrayPredicateStepMeta,
|
|
31
|
+
WorkflowStepMeta,
|
|
32
|
+
WorkflowStepWire,
|
|
33
|
+
PikkuWorkflowWire,
|
|
34
|
+
} from './dsl/workflow-dsl.types.js'
|
|
35
|
+
|
|
36
|
+
import type { WorkflowStepMeta } from './dsl/workflow-dsl.types.js'
|
|
37
|
+
|
|
10
38
|
export interface WorkflowServiceConfig {
|
|
11
39
|
retries: number
|
|
12
40
|
retryDelay: number
|
|
@@ -15,6 +43,90 @@ export interface WorkflowServiceConfig {
|
|
|
15
43
|
sleeperRPCName: string
|
|
16
44
|
}
|
|
17
45
|
|
|
46
|
+
/**
|
|
47
|
+
* HTTP wire configuration for workflows
|
|
48
|
+
*/
|
|
49
|
+
export interface WorkflowHTTPWire {
|
|
50
|
+
route: string
|
|
51
|
+
method: 'get' | 'post' | 'put' | 'patch' | 'delete'
|
|
52
|
+
startNode: string
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Channel wire configuration for workflows
|
|
57
|
+
*/
|
|
58
|
+
export interface WorkflowChannelWire {
|
|
59
|
+
name: string
|
|
60
|
+
onConnect?: string
|
|
61
|
+
onDisconnect?: string
|
|
62
|
+
onMessage?: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Queue wire configuration for workflows
|
|
67
|
+
*/
|
|
68
|
+
export interface WorkflowQueueWire {
|
|
69
|
+
name: string
|
|
70
|
+
startNode: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* CLI wire configuration for workflows
|
|
75
|
+
*/
|
|
76
|
+
export interface WorkflowCliWire {
|
|
77
|
+
command: string
|
|
78
|
+
startNode: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* MCP wire configurations for workflows
|
|
83
|
+
*/
|
|
84
|
+
export interface WorkflowMcpWires {
|
|
85
|
+
tool?: Array<{ name: string; startNode: string }>
|
|
86
|
+
prompt?: Array<{ name: string; startNode: string }>
|
|
87
|
+
resource?: Array<{ uri: string; startNode: string }>
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Schedule wire configuration for workflows
|
|
92
|
+
*/
|
|
93
|
+
export interface WorkflowScheduleWire {
|
|
94
|
+
cron?: string
|
|
95
|
+
interval?: string
|
|
96
|
+
startNode: string
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Trigger wire configuration for workflows
|
|
101
|
+
*/
|
|
102
|
+
export interface WorkflowTriggerWire {
|
|
103
|
+
name: string
|
|
104
|
+
startNode: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Wire configuration for workflows
|
|
109
|
+
* Defines how a workflow can be triggered
|
|
110
|
+
*/
|
|
111
|
+
export interface WorkflowWires {
|
|
112
|
+
/** API entry point - node ID for startWorkflow() calls */
|
|
113
|
+
api?: string
|
|
114
|
+
/** HTTP triggers */
|
|
115
|
+
http?: WorkflowHTTPWire[]
|
|
116
|
+
/** Channel triggers */
|
|
117
|
+
channel?: WorkflowChannelWire[]
|
|
118
|
+
/** Queue triggers */
|
|
119
|
+
queue?: WorkflowQueueWire[]
|
|
120
|
+
/** CLI triggers */
|
|
121
|
+
cli?: WorkflowCliWire[]
|
|
122
|
+
/** MCP triggers (tool, prompt, resource) */
|
|
123
|
+
mcp?: WorkflowMcpWires
|
|
124
|
+
/** Schedule triggers */
|
|
125
|
+
schedule?: WorkflowScheduleWire[]
|
|
126
|
+
/** Named trigger wires */
|
|
127
|
+
trigger?: WorkflowTriggerWire[]
|
|
128
|
+
}
|
|
129
|
+
|
|
18
130
|
/**
|
|
19
131
|
* Workflow run status
|
|
20
132
|
*/
|
|
@@ -46,6 +158,8 @@ export interface WorkflowRun {
|
|
|
46
158
|
output?: any
|
|
47
159
|
/** Error (if failed) */
|
|
48
160
|
error?: SerializedError
|
|
161
|
+
/** If true, workflow executes inline without queues */
|
|
162
|
+
inline?: boolean
|
|
49
163
|
/** Creation timestamp */
|
|
50
164
|
createdAt: Date
|
|
51
165
|
/** Last update timestamp */
|
|
@@ -106,215 +220,6 @@ export type CoreWorkflow<
|
|
|
106
220
|
tags?: string[]
|
|
107
221
|
}
|
|
108
222
|
|
|
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
223
|
/**
|
|
319
224
|
* Workflow client interface
|
|
320
225
|
*/
|
|
@@ -328,80 +233,64 @@ export interface PikkuWorkflow {
|
|
|
328
233
|
}
|
|
329
234
|
|
|
330
235
|
/**
|
|
331
|
-
*
|
|
236
|
+
* Context variable definition (serialized from Zod schema or type inference)
|
|
237
|
+
*/
|
|
238
|
+
export interface ContextVariable {
|
|
239
|
+
/** Variable type */
|
|
240
|
+
type: 'string' | 'number' | 'boolean' | 'object' | 'array'
|
|
241
|
+
/** Default value */
|
|
242
|
+
default?: unknown
|
|
243
|
+
/** Description for UI/docs */
|
|
244
|
+
description?: string
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Workflow context - state variables with defaults and types
|
|
249
|
+
*/
|
|
250
|
+
export type WorkflowContext = Record<string, ContextVariable>
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Workflows metadata for inspector/CLI (DSL step-based format)
|
|
332
254
|
*/
|
|
333
255
|
export type WorkflowsMeta = Record<
|
|
334
256
|
string,
|
|
335
257
|
CommonWireMeta & {
|
|
336
258
|
workflowName: string
|
|
337
259
|
steps: WorkflowStepMeta[]
|
|
338
|
-
|
|
339
|
-
|
|
260
|
+
context?: WorkflowContext
|
|
261
|
+
dsl?: boolean
|
|
340
262
|
}
|
|
341
263
|
>
|
|
342
264
|
|
|
343
265
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
266
|
+
* Unified workflow runtime meta (used by runtime to execute workflows)
|
|
267
|
+
* This is the format stored in pikkuState('workflows', 'meta')
|
|
268
|
+
* Both DSL and graph-based workflows are converted to this format
|
|
346
269
|
*/
|
|
347
|
-
export interface
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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>
|
|
270
|
+
export interface WorkflowRuntimeMeta {
|
|
271
|
+
/** Workflow name (used as key in registrations) */
|
|
272
|
+
name: string
|
|
273
|
+
/** Pikku function name (for execution) */
|
|
274
|
+
pikkuFuncName: string
|
|
275
|
+
/** Source type: 'dsl' (serializable), 'complex' (has inline steps), 'graph' */
|
|
276
|
+
source?: 'dsl' | 'complex' | 'graph'
|
|
277
|
+
/** Optional description */
|
|
278
|
+
description?: string
|
|
279
|
+
/** Tags for organization */
|
|
280
|
+
tags?: string[]
|
|
281
|
+
/** Wires - how the workflow is triggered */
|
|
282
|
+
wires?: WorkflowWires
|
|
283
|
+
/** Serialized nodes */
|
|
284
|
+
nodes?: Record<string, any>
|
|
285
|
+
/** Entry node IDs for graph workflows (computed at build time) */
|
|
286
|
+
entryNodeIds?: string[]
|
|
403
287
|
}
|
|
404
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Unified workflow runtime metadata map
|
|
291
|
+
*/
|
|
292
|
+
export type WorkflowsRuntimeMeta = Record<string, WorkflowRuntimeMeta>
|
|
293
|
+
|
|
405
294
|
/**
|
|
406
295
|
* Worker input types for generated queue workers
|
|
407
296
|
*/
|