@pikku/core 0.12.20 → 0.12.21
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 +11 -0
- package/dist/dev/hot-reload.js +20 -6
- package/dist/errors/error-handler.d.ts +1 -1
- package/dist/errors/error-handler.js +2 -2
- package/dist/function/functions.types.d.ts +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/middleware/index.d.ts +2 -2
- package/dist/middleware/index.js +2 -2
- package/dist/middleware/telemetry.d.ts +2 -2
- package/dist/middleware/telemetry.js +2 -2
- package/dist/middleware-runner.d.ts +15 -27
- package/dist/middleware-runner.js +25 -30
- package/dist/permissions.d.ts +15 -22
- package/dist/permissions.js +30 -25
- package/dist/pikku-request.js +1 -1
- package/dist/pikku-state.js +2 -3
- package/dist/services/ai-agent-runner-service.d.ts +1 -0
- package/dist/services/in-memory-queue-service.js +1 -1
- package/dist/services/in-memory-workflow-service.d.ts +15 -13
- package/dist/services/in-memory-workflow-service.js +31 -13
- package/dist/services/local-content.js +8 -1
- package/dist/services/user-session-service.d.ts +1 -1
- package/dist/testing/service-tests.js +24 -0
- package/dist/types/core.types.d.ts +4 -0
- package/dist/types/state.types.d.ts +2 -18
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +24 -5
- package/dist/wirings/ai-agent/ai-agent-memory.js +128 -23
- package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +10 -1
- package/dist/wirings/ai-agent/ai-agent-model-config.js +15 -35
- package/dist/wirings/ai-agent/ai-agent-prepare.js +4 -1
- package/dist/wirings/ai-agent/ai-agent-runner.js +45 -31
- package/dist/wirings/ai-agent/ai-agent-stream.js +63 -34
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +20 -0
- package/dist/wirings/channel/channel-handler.js +1 -1
- package/dist/wirings/channel/channel-store.d.ts +13 -0
- package/dist/wirings/channel/channel.types.d.ts +3 -0
- package/dist/wirings/channel/local/local-channel-runner.js +23 -5
- package/dist/wirings/channel/pikku-abstract-channel-handler.js +8 -0
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +9 -0
- package/dist/wirings/cli/cli-runner.js +24 -5
- package/dist/wirings/cli/command-parser.js +19 -4
- package/dist/wirings/http/http-runner.js +72 -36
- package/dist/wirings/http/http.types.d.ts +1 -0
- package/dist/wirings/http/pikku-fetch-http-request.js +3 -1
- package/dist/wirings/http/web-request.js +32 -0
- package/dist/wirings/rpc/rpc-runner.js +13 -3
- package/dist/wirings/workflow/graph/graph-node.d.ts +8 -0
- package/dist/wirings/workflow/graph/graph-node.js +4 -0
- package/dist/wirings/workflow/graph/graph-runner.js +12 -10
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +4 -0
- package/dist/wirings/workflow/index.d.ts +1 -1
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +81 -16
- package/dist/wirings/workflow/pikku-workflow-service.js +266 -45
- package/dist/wirings/workflow/workflow.types.d.ts +34 -0
- package/package.json +1 -1
- package/run-tests.sh +4 -1
- package/src/dev/hot-reload.test.ts +62 -11
- package/src/dev/hot-reload.ts +28 -7
- package/src/errors/error-handler.ts +8 -2
- package/src/errors/error.test.ts +2 -0
- package/src/function/function-runner.test.ts +500 -10
- package/src/function/functions.types.ts +3 -2
- package/src/index.ts +12 -2
- package/src/middleware/index.ts +11 -2
- package/src/middleware/telemetry.ts +2 -2
- package/src/middleware-runner.test.ts +16 -16
- package/src/middleware-runner.ts +42 -30
- package/src/permissions.test.ts +27 -24
- package/src/permissions.ts +41 -25
- package/src/pikku-request.test.ts +35 -0
- package/src/pikku-request.ts +1 -1
- package/src/pikku-state.ts +2 -3
- package/src/run-tests-script.test.ts +18 -0
- package/src/services/ai-agent-runner-service.ts +1 -0
- package/src/services/in-memory-queue-service.ts +1 -1
- package/src/services/in-memory-session-store.ts +1 -2
- package/src/services/in-memory-workflow-service.test.ts +33 -11
- package/src/services/in-memory-workflow-service.ts +49 -13
- package/src/services/local-content.test.ts +54 -0
- package/src/services/local-content.ts +12 -1
- package/src/services/typed-credential-service.ts +3 -3
- package/src/services/typed-secret-service.ts +3 -3
- package/src/services/typed-variables-service.ts +3 -3
- package/src/services/user-session-service.ts +4 -4
- package/src/testing/service-tests.ts +30 -0
- package/src/types/core.types.ts +6 -2
- package/src/types/state.types.ts +2 -13
- package/src/wirings/ai-agent/ai-agent-memory.test.ts +324 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +187 -36
- package/src/wirings/ai-agent/ai-agent-model-config.test.ts +12 -90
- package/src/wirings/ai-agent/ai-agent-model-config.ts +14 -38
- package/src/wirings/ai-agent/ai-agent-prepare.test.ts +292 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +4 -1
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +230 -3
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +625 -6
- package/src/wirings/ai-agent/ai-agent-runner.ts +65 -50
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +544 -5
- package/src/wirings/ai-agent/ai-agent-stream.ts +71 -69
- package/src/wirings/ai-agent/ai-agent.types.ts +24 -0
- package/src/wirings/channel/channel-handler.test.ts +272 -0
- package/src/wirings/channel/channel-handler.ts +1 -1
- package/src/wirings/channel/channel-middleware-runner.test.ts +163 -0
- package/src/wirings/channel/channel-store.ts +19 -0
- package/src/wirings/channel/channel.types.ts +4 -0
- package/src/wirings/channel/local/local-channel-runner.test.ts +63 -0
- package/src/wirings/channel/local/local-channel-runner.ts +41 -5
- package/src/wirings/channel/local/local-eventhub-service.ts +3 -3
- package/src/wirings/channel/pikku-abstract-channel-handler.ts +9 -2
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +23 -5
- package/src/wirings/cli/channel/cli-raw-channel-runner.ts +7 -2
- package/src/wirings/cli/cli-runner.test.ts +255 -2
- package/src/wirings/cli/cli-runner.ts +31 -10
- package/src/wirings/cli/cli.types.ts +4 -8
- package/src/wirings/cli/command-parser.test.ts +83 -0
- package/src/wirings/cli/command-parser.ts +23 -4
- package/src/wirings/http/http-runner.test.ts +296 -1
- package/src/wirings/http/http-runner.ts +87 -57
- package/src/wirings/http/http.types.ts +11 -26
- package/src/wirings/http/pikku-fetch-http-request.ts +8 -4
- package/src/wirings/http/pikku-fetch-http-response.test.ts +41 -0
- package/src/wirings/http/web-request.test.ts +115 -0
- package/src/wirings/http/web-request.ts +43 -5
- package/src/wirings/mcp/mcp-runner.test.ts +367 -0
- package/src/wirings/queue/queue.types.ts +2 -5
- package/src/wirings/rpc/rpc-runner.test.ts +511 -0
- package/src/wirings/rpc/rpc-runner.ts +15 -3
- package/src/wirings/rpc/wire-addon.test.ts +57 -0
- package/src/wirings/workflow/graph/graph-node.ts +12 -0
- package/src/wirings/workflow/graph/graph-runner.test.ts +98 -0
- package/src/wirings/workflow/graph/graph-runner.ts +28 -10
- package/src/wirings/workflow/graph/workflow-graph.types.ts +4 -0
- package/src/wirings/workflow/index.ts +1 -0
- package/src/wirings/workflow/pikku-workflow-service.test.ts +19 -2
- package/src/wirings/workflow/pikku-workflow-service.ts +370 -71
- package/src/wirings/workflow/workflow-queue-workers.test.ts +131 -0
- package/src/wirings/workflow/workflow.types.ts +68 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { beforeEach, describe, test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { resetPikkuState, pikkuState } from '../../pikku-state.js'
|
|
5
|
+
import {
|
|
6
|
+
pikkuWorkflowWorkerFunc,
|
|
7
|
+
pikkuWorkflowOrchestratorFunc,
|
|
8
|
+
pikkuWorkflowSleeperFunc,
|
|
9
|
+
} from './workflow-queue-workers.js'
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
resetPikkuState()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
describe('workflow-queue-workers', () => {
|
|
16
|
+
test('worker calls executeWorkflowStep on the workflow service', async () => {
|
|
17
|
+
const calls: unknown[][] = []
|
|
18
|
+
const rpc = { rpcWithWire: async () => ({ ok: true }) }
|
|
19
|
+
|
|
20
|
+
pikkuState(null, 'package', 'singletonServices', {
|
|
21
|
+
workflowService: {
|
|
22
|
+
executeWorkflowStep: async (...args: unknown[]) => {
|
|
23
|
+
calls.push(args)
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
} as never)
|
|
27
|
+
|
|
28
|
+
await pikkuWorkflowWorkerFunc(
|
|
29
|
+
{},
|
|
30
|
+
{
|
|
31
|
+
runId: 'run-1',
|
|
32
|
+
stepName: 'step-a',
|
|
33
|
+
rpcName: 'rpc.doThing',
|
|
34
|
+
data: { ok: true },
|
|
35
|
+
},
|
|
36
|
+
{ rpc: rpc as never }
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
assert.deepEqual(calls, [
|
|
40
|
+
['run-1', 'step-a', 'rpc.doThing', { ok: true }, rpc],
|
|
41
|
+
])
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('worker throws when workflow service is missing', async () => {
|
|
45
|
+
pikkuState(null, 'package', 'singletonServices', {} as never)
|
|
46
|
+
|
|
47
|
+
await assert.rejects(
|
|
48
|
+
() =>
|
|
49
|
+
pikkuWorkflowWorkerFunc(
|
|
50
|
+
{},
|
|
51
|
+
{
|
|
52
|
+
runId: 'run-1',
|
|
53
|
+
stepName: 'step-a',
|
|
54
|
+
rpcName: 'rpc.doThing',
|
|
55
|
+
data: {},
|
|
56
|
+
},
|
|
57
|
+
{ rpc: {} as never }
|
|
58
|
+
),
|
|
59
|
+
{
|
|
60
|
+
message:
|
|
61
|
+
'Workflow service not initialized: cannot execute workflow step for runId run-1, stepName step-a',
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('orchestrator calls orchestrateWorkflow on the workflow service', async () => {
|
|
67
|
+
const calls: unknown[][] = []
|
|
68
|
+
const rpc = { rpcWithWire: async () => ({ ok: true }) }
|
|
69
|
+
|
|
70
|
+
pikkuState(null, 'package', 'singletonServices', {
|
|
71
|
+
workflowService: {
|
|
72
|
+
orchestrateWorkflow: async (...args: unknown[]) => {
|
|
73
|
+
calls.push(args)
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
} as never)
|
|
77
|
+
|
|
78
|
+
await pikkuWorkflowOrchestratorFunc(
|
|
79
|
+
{},
|
|
80
|
+
{ runId: 'run-2' },
|
|
81
|
+
{ rpc: rpc as never }
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
assert.deepEqual(calls, [['run-2', rpc]])
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('orchestrator throws when workflow service is missing', async () => {
|
|
88
|
+
pikkuState(null, 'package', 'singletonServices', {} as never)
|
|
89
|
+
|
|
90
|
+
await assert.rejects(
|
|
91
|
+
() =>
|
|
92
|
+
pikkuWorkflowOrchestratorFunc(
|
|
93
|
+
{},
|
|
94
|
+
{ runId: 'run-2' },
|
|
95
|
+
{ rpc: {} as never }
|
|
96
|
+
),
|
|
97
|
+
{
|
|
98
|
+
message:
|
|
99
|
+
'Workflow service not initialized: cannot orchestrate workflow for runId run-2',
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('sleeper calls executeWorkflowSleepCompleted on the workflow service', async () => {
|
|
105
|
+
const calls: unknown[][] = []
|
|
106
|
+
|
|
107
|
+
pikkuState(null, 'package', 'singletonServices', {
|
|
108
|
+
workflowService: {
|
|
109
|
+
executeWorkflowSleepCompleted: async (...args: unknown[]) => {
|
|
110
|
+
calls.push(args)
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
} as never)
|
|
114
|
+
|
|
115
|
+
await pikkuWorkflowSleeperFunc({}, { runId: 'run-3', stepId: 'step-3' })
|
|
116
|
+
|
|
117
|
+
assert.deepEqual(calls, [['run-3', 'step-3']])
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test('sleeper throws when workflow service is missing', async () => {
|
|
121
|
+
pikkuState(null, 'package', 'singletonServices', {} as never)
|
|
122
|
+
|
|
123
|
+
await assert.rejects(
|
|
124
|
+
() => pikkuWorkflowSleeperFunc({}, { runId: 'run-3', stepId: 'step-3' }),
|
|
125
|
+
{
|
|
126
|
+
message:
|
|
127
|
+
'Workflow service not initialized: cannot execute workflow sleep completed for runId run-3, stepId step-3',
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -191,15 +191,78 @@ export interface WorkflowRunService {
|
|
|
191
191
|
deleteRun(id: string): Promise<boolean>
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Write-only companion to `WorkflowRunService`. An executor (a
|
|
196
|
+
* `PikkuWorkflowService` subclass) can be given a mirror; every write
|
|
197
|
+
* the executor makes to its own canonical store is then forwarded here,
|
|
198
|
+
* so an external read store (e.g. a DB queried by the console UI) stays
|
|
199
|
+
* in sync with DO/Redis/etc-driven runs.
|
|
200
|
+
*
|
|
201
|
+
* Mirror failures are logged but never fail the workflow — the mirror is
|
|
202
|
+
* an index, not the source of truth.
|
|
203
|
+
*/
|
|
204
|
+
export interface WorkflowRunMirror {
|
|
205
|
+
createRun(
|
|
206
|
+
runId: string,
|
|
207
|
+
workflowName: string,
|
|
208
|
+
input: any,
|
|
209
|
+
inline: boolean,
|
|
210
|
+
graphHash: string,
|
|
211
|
+
wire: WorkflowRunWire,
|
|
212
|
+
options?: {
|
|
213
|
+
deterministic?: boolean
|
|
214
|
+
plannedSteps?: WorkflowPlannedStep[]
|
|
215
|
+
}
|
|
216
|
+
): Promise<void>
|
|
217
|
+
|
|
218
|
+
updateRunStatus(
|
|
219
|
+
id: string,
|
|
220
|
+
status: WorkflowStatus,
|
|
221
|
+
output?: any,
|
|
222
|
+
error?: SerializedError
|
|
223
|
+
): Promise<void>
|
|
224
|
+
|
|
225
|
+
insertStepState(
|
|
226
|
+
runId: string,
|
|
227
|
+
step: StepState & { stepName: string; rpcName: string | null; data: any }
|
|
228
|
+
): Promise<void>
|
|
229
|
+
|
|
230
|
+
setStepRunning(stepId: string): Promise<void>
|
|
231
|
+
setStepScheduled(stepId: string): Promise<void>
|
|
232
|
+
setStepResult(stepId: string, result: any): Promise<void>
|
|
233
|
+
setStepChildRunId(stepId: string, childRunId: string): Promise<void>
|
|
234
|
+
setStepError(stepId: string, error: SerializedError): Promise<void>
|
|
235
|
+
|
|
236
|
+
createRetryAttempt(
|
|
237
|
+
failedStepId: string,
|
|
238
|
+
newStep: StepState & { stepName: string }
|
|
239
|
+
): Promise<void>
|
|
240
|
+
|
|
241
|
+
setBranchTaken(stepId: string, branchKey: string): Promise<void>
|
|
242
|
+
|
|
243
|
+
updateRunState(runId: string, name: string, value: unknown): Promise<void>
|
|
244
|
+
|
|
245
|
+
upsertWorkflowVersion(
|
|
246
|
+
name: string,
|
|
247
|
+
graphHash: string,
|
|
248
|
+
graph: any,
|
|
249
|
+
source: string,
|
|
250
|
+
status?: WorkflowVersionStatus
|
|
251
|
+
): Promise<void>
|
|
252
|
+
|
|
253
|
+
updateWorkflowVersionStatus(
|
|
254
|
+
name: string,
|
|
255
|
+
graphHash: string,
|
|
256
|
+
status: WorkflowVersionStatus
|
|
257
|
+
): Promise<void>
|
|
258
|
+
}
|
|
259
|
+
|
|
194
260
|
/**
|
|
195
261
|
* Core workflow definition
|
|
196
262
|
*/
|
|
197
263
|
export type CoreWorkflow<
|
|
198
|
-
PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
199
|
-
any,
|
|
200
|
-
any,
|
|
201
|
-
any
|
|
202
|
-
> = CorePikkuFunctionConfig<any, any, any>,
|
|
264
|
+
PikkuFunctionConfig extends CorePikkuFunctionConfig<any, any, any> =
|
|
265
|
+
CorePikkuFunctionConfig<any, any, any>,
|
|
203
266
|
> = {
|
|
204
267
|
/** Unique workflow name */
|
|
205
268
|
name: string
|