@pikku/core 0.12.2 → 0.12.4

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 (282) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/crypto-utils.d.ts +10 -0
  3. package/dist/crypto-utils.js +62 -0
  4. package/dist/function/function-runner.js +4 -4
  5. package/dist/function/functions.types.d.ts +26 -1
  6. package/dist/function/functions.types.js +16 -0
  7. package/dist/handle-error.d.ts +1 -1
  8. package/dist/handle-error.js +7 -3
  9. package/dist/index.d.ts +14 -2
  10. package/dist/index.js +1 -1
  11. package/dist/pikku-state.js +3 -1
  12. package/dist/schema.js +1 -1
  13. package/dist/services/in-memory-workflow-service.d.ts +22 -3
  14. package/dist/services/in-memory-workflow-service.js +77 -1
  15. package/dist/services/workflow-service.d.ts +8 -2
  16. package/dist/testing/index.d.ts +2 -0
  17. package/dist/testing/index.js +1 -0
  18. package/dist/testing/service-tests.d.ts +31 -0
  19. package/dist/testing/service-tests.js +598 -0
  20. package/dist/types/core.types.d.ts +9 -1
  21. package/dist/types/state.types.d.ts +4 -2
  22. package/dist/utils/hash.d.ts +2 -0
  23. package/dist/utils/hash.js +23 -0
  24. package/dist/wirings/ai-agent/agent-dynamic-workflow.d.ts +6 -0
  25. package/dist/wirings/ai-agent/agent-dynamic-workflow.js +348 -0
  26. package/dist/wirings/ai-agent/ai-agent-memory.d.ts +1 -1
  27. package/dist/wirings/ai-agent/ai-agent-memory.js +6 -5
  28. package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +10 -7
  29. package/dist/wirings/ai-agent/ai-agent-prepare.js +127 -47
  30. package/dist/wirings/ai-agent/ai-agent-runner.d.ts +4 -0
  31. package/dist/wirings/ai-agent/ai-agent-runner.js +381 -27
  32. package/dist/wirings/ai-agent/ai-agent-stream.d.ts +7 -2
  33. package/dist/wirings/ai-agent/ai-agent-stream.js +109 -46
  34. package/dist/wirings/ai-agent/ai-agent.types.d.ts +22 -1
  35. package/dist/wirings/ai-agent/index.d.ts +1 -2
  36. package/dist/wirings/ai-agent/index.js +1 -2
  37. package/dist/wirings/channel/channel-handler.js +5 -1
  38. package/dist/wirings/channel/channel.types.d.ts +1 -7
  39. package/dist/wirings/channel/local/local-channel-handler.d.ts +1 -1
  40. package/dist/wirings/channel/local/local-channel-handler.js +5 -3
  41. package/dist/wirings/channel/local/local-channel-runner.js +14 -4
  42. package/dist/wirings/channel/serverless/serverless-channel-runner.js +4 -1
  43. package/dist/wirings/cli/cli-runner.js +10 -2
  44. package/dist/wirings/cli/cli.types.d.ts +1 -0
  45. package/dist/wirings/http/http-routes.js +0 -1
  46. package/dist/wirings/http/http-runner.d.ts +1 -1
  47. package/dist/wirings/http/http-runner.js +25 -3
  48. package/dist/wirings/http/http.types.d.ts +3 -11
  49. package/dist/wirings/http/index.d.ts +2 -1
  50. package/dist/wirings/http/index.js +1 -0
  51. package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -0
  52. package/dist/wirings/http/pikku-fetch-http-request.js +3 -0
  53. package/dist/wirings/http/pikku-fetch-http-response.d.ts +1 -0
  54. package/dist/wirings/http/pikku-fetch-http-response.js +4 -4
  55. package/dist/wirings/http/web-request.d.ts +12 -0
  56. package/dist/wirings/http/web-request.js +85 -0
  57. package/dist/wirings/mcp/mcp-endpoint-registry.js +1 -1
  58. package/dist/wirings/mcp/mcp-runner.js +13 -1
  59. package/dist/wirings/rpc/rpc-runner.d.ts +30 -6
  60. package/dist/wirings/rpc/rpc-runner.js +36 -14
  61. package/dist/wirings/rpc/rpc-types.d.ts +6 -1
  62. package/dist/wirings/rpc/wire-addon.d.ts +1 -0
  63. package/dist/wirings/rpc/wire-addon.js +1 -1
  64. package/dist/wirings/scheduler/scheduler-runner.js +1 -0
  65. package/dist/wirings/workflow/graph/graph-validation.d.ts +3 -0
  66. package/dist/wirings/workflow/graph/graph-validation.js +175 -0
  67. package/dist/wirings/workflow/graph/index.d.ts +1 -0
  68. package/dist/wirings/workflow/graph/index.js +1 -0
  69. package/dist/wirings/workflow/index.d.ts +1 -1
  70. package/dist/wirings/workflow/pikku-workflow-service.d.ts +8 -2
  71. package/dist/wirings/workflow/pikku-workflow-service.js +1 -2
  72. package/dist/wirings/workflow/workflow.types.d.ts +10 -1
  73. package/lcov.info +18891 -0
  74. package/package.json +4 -2
  75. package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +0 -5
  76. package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +0 -168
  77. package/src/crypto-utils.test.ts +0 -116
  78. package/src/crypto-utils.ts +0 -99
  79. package/src/errors/error-handler.ts +0 -62
  80. package/src/errors/error.test.ts +0 -195
  81. package/src/errors/errors.ts +0 -374
  82. package/src/errors/index.ts +0 -2
  83. package/src/factory-functions.test.ts +0 -109
  84. package/src/function/function-runner.test.ts +0 -536
  85. package/src/function/function-runner.ts +0 -365
  86. package/src/function/functions.types.ts +0 -267
  87. package/src/function/index.ts +0 -5
  88. package/src/handle-error.test.ts +0 -361
  89. package/src/handle-error.ts +0 -65
  90. package/src/index.ts +0 -104
  91. package/src/internal.ts +0 -6
  92. package/src/middleware/auth-apikey.test.ts +0 -363
  93. package/src/middleware/auth-apikey.ts +0 -47
  94. package/src/middleware/auth-bearer.test.ts +0 -450
  95. package/src/middleware/auth-bearer.ts +0 -72
  96. package/src/middleware/auth-cookie.test.ts +0 -528
  97. package/src/middleware/auth-cookie.ts +0 -80
  98. package/src/middleware/cors.test.ts +0 -424
  99. package/src/middleware/cors.ts +0 -104
  100. package/src/middleware/index.ts +0 -5
  101. package/src/middleware/remote-auth.test.ts +0 -488
  102. package/src/middleware/remote-auth.ts +0 -68
  103. package/src/middleware/timeout.ts +0 -15
  104. package/src/middleware-runner.test.ts +0 -418
  105. package/src/middleware-runner.ts +0 -234
  106. package/src/permissions.test.ts +0 -434
  107. package/src/permissions.ts +0 -319
  108. package/src/pikku-request.ts +0 -23
  109. package/src/pikku-response.ts +0 -5
  110. package/src/pikku-state.test.ts +0 -224
  111. package/src/pikku-state.ts +0 -214
  112. package/src/run-tests-script.test.ts +0 -49
  113. package/src/schema.test.ts +0 -249
  114. package/src/schema.ts +0 -151
  115. package/src/services/ai-agent-runner-service.ts +0 -41
  116. package/src/services/ai-run-state-service.ts +0 -20
  117. package/src/services/ai-storage-service.ts +0 -39
  118. package/src/services/content-service.ts +0 -76
  119. package/src/services/deployment-service.ts +0 -22
  120. package/src/services/gateway-service.ts +0 -20
  121. package/src/services/gopass-secrets.ts +0 -98
  122. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  123. package/src/services/in-memory-trigger-service.ts +0 -64
  124. package/src/services/in-memory-workflow-service.test.ts +0 -351
  125. package/src/services/in-memory-workflow-service.ts +0 -395
  126. package/src/services/index.ts +0 -56
  127. package/src/services/jwt-service.ts +0 -30
  128. package/src/services/local-content.ts +0 -120
  129. package/src/services/local-gateway-service.ts +0 -62
  130. package/src/services/local-secrets.test.ts +0 -80
  131. package/src/services/local-secrets.ts +0 -94
  132. package/src/services/local-variables.test.ts +0 -61
  133. package/src/services/local-variables.ts +0 -39
  134. package/src/services/logger-console.test.ts +0 -118
  135. package/src/services/logger-console.ts +0 -98
  136. package/src/services/logger.ts +0 -57
  137. package/src/services/scheduler-service.ts +0 -86
  138. package/src/services/schema-service.ts +0 -33
  139. package/src/services/scoped-secret-service.test.ts +0 -74
  140. package/src/services/scoped-secret-service.ts +0 -41
  141. package/src/services/secret-service.ts +0 -38
  142. package/src/services/trigger-service.ts +0 -17
  143. package/src/services/typed-secret-service.test.ts +0 -93
  144. package/src/services/typed-secret-service.ts +0 -70
  145. package/src/services/typed-variables-service.test.ts +0 -73
  146. package/src/services/typed-variables-service.ts +0 -81
  147. package/src/services/user-session-service.test.ts +0 -113
  148. package/src/services/user-session-service.ts +0 -86
  149. package/src/services/variables-service.ts +0 -11
  150. package/src/services/workflow-service.ts +0 -84
  151. package/src/time-utils.test.ts +0 -56
  152. package/src/time-utils.ts +0 -107
  153. package/src/types/core.types.ts +0 -470
  154. package/src/types/state.types.ts +0 -186
  155. package/src/utils.test.ts +0 -350
  156. package/src/utils.ts +0 -129
  157. package/src/version.test.ts +0 -80
  158. package/src/version.ts +0 -25
  159. package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +0 -363
  160. package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +0 -238
  161. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  162. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  163. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -309
  164. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  165. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  166. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -522
  167. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  168. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  169. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -317
  170. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -251
  171. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -652
  172. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1060
  173. package/src/wirings/ai-agent/ai-agent.types.ts +0 -360
  174. package/src/wirings/ai-agent/index.ts +0 -41
  175. package/src/wirings/channel/channel-common.ts +0 -90
  176. package/src/wirings/channel/channel-handler.ts +0 -241
  177. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  178. package/src/wirings/channel/channel-runner.ts +0 -166
  179. package/src/wirings/channel/channel-store.ts +0 -29
  180. package/src/wirings/channel/channel.types.ts +0 -178
  181. package/src/wirings/channel/define-channel-routes.ts +0 -25
  182. package/src/wirings/channel/eventhub-service.ts +0 -34
  183. package/src/wirings/channel/eventhub-store.ts +0 -13
  184. package/src/wirings/channel/index.ts +0 -24
  185. package/src/wirings/channel/local/index.ts +0 -3
  186. package/src/wirings/channel/local/local-channel-handler.ts +0 -79
  187. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  188. package/src/wirings/channel/local/local-channel-runner.ts +0 -200
  189. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  190. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  191. package/src/wirings/channel/log-channels.ts +0 -20
  192. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  193. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  194. package/src/wirings/channel/serverless/index.ts +0 -5
  195. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -286
  196. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  197. package/src/wirings/cli/channel/index.ts +0 -1
  198. package/src/wirings/cli/cli-runner.test.ts +0 -403
  199. package/src/wirings/cli/cli-runner.ts +0 -519
  200. package/src/wirings/cli/cli.types.ts +0 -357
  201. package/src/wirings/cli/command-parser.test.ts +0 -445
  202. package/src/wirings/cli/command-parser.ts +0 -504
  203. package/src/wirings/cli/define-cli-commands.ts +0 -24
  204. package/src/wirings/cli/index.ts +0 -19
  205. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  206. package/src/wirings/gateway/gateway-runner.ts +0 -411
  207. package/src/wirings/gateway/gateway.types.ts +0 -149
  208. package/src/wirings/gateway/index.ts +0 -13
  209. package/src/wirings/http/http-routes.test.ts +0 -322
  210. package/src/wirings/http/http-routes.ts +0 -198
  211. package/src/wirings/http/http-runner.test.ts +0 -144
  212. package/src/wirings/http/http-runner.ts +0 -563
  213. package/src/wirings/http/http.types.ts +0 -378
  214. package/src/wirings/http/index.ts +0 -25
  215. package/src/wirings/http/log-http-routes.ts +0 -22
  216. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  217. package/src/wirings/http/pikku-fetch-http-request.ts +0 -166
  218. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  219. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  220. package/src/wirings/http/routers/http-router.ts +0 -13
  221. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  222. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  223. package/src/wirings/mcp/index.ts +0 -27
  224. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  225. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  226. package/src/wirings/mcp/mcp-runner.ts +0 -305
  227. package/src/wirings/mcp/mcp.types.ts +0 -216
  228. package/src/wirings/node/index.ts +0 -2
  229. package/src/wirings/node/node.types.ts +0 -23
  230. package/src/wirings/oauth2/index.ts +0 -3
  231. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  232. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  233. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  234. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  235. package/src/wirings/queue/index.ts +0 -31
  236. package/src/wirings/queue/queue-runner.test.ts +0 -710
  237. package/src/wirings/queue/queue-runner.ts +0 -192
  238. package/src/wirings/queue/queue.types.ts +0 -189
  239. package/src/wirings/queue/register-queue-helper.ts +0 -60
  240. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  241. package/src/wirings/queue/validate-worker-config.ts +0 -116
  242. package/src/wirings/rpc/index.ts +0 -4
  243. package/src/wirings/rpc/rpc-runner.ts +0 -439
  244. package/src/wirings/rpc/rpc-types.ts +0 -51
  245. package/src/wirings/rpc/wire-addon.ts +0 -20
  246. package/src/wirings/scheduler/index.ts +0 -11
  247. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  248. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  249. package/src/wirings/scheduler/scheduler-runner.ts +0 -132
  250. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  251. package/src/wirings/secret/index.ts +0 -9
  252. package/src/wirings/secret/secret.types.ts +0 -32
  253. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  254. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  255. package/src/wirings/trigger/index.ts +0 -10
  256. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  257. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  258. package/src/wirings/trigger/trigger-runner.ts +0 -135
  259. package/src/wirings/trigger/trigger.types.ts +0 -178
  260. package/src/wirings/variable/index.ts +0 -8
  261. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  262. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  263. package/src/wirings/variable/variable.types.ts +0 -22
  264. package/src/wirings/workflow/dsl/index.ts +0 -31
  265. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  266. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  267. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  268. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  269. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  270. package/src/wirings/workflow/graph/index.ts +0 -14
  271. package/src/wirings/workflow/graph/template.test.ts +0 -49
  272. package/src/wirings/workflow/graph/template.ts +0 -42
  273. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  274. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  275. package/src/wirings/workflow/index.ts +0 -81
  276. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  277. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1165
  278. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  279. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  280. package/src/wirings/workflow/workflow.types.ts +0 -266
  281. package/tsconfig.json +0 -14
  282. package/tsconfig.tsbuildinfo +0 -1
@@ -1,129 +0,0 @@
1
- import { describe, test } from 'node:test'
2
- import assert from 'node:assert'
3
- import {
4
- workflow,
5
- workflowStart,
6
- workflowStatus,
7
- graphStart,
8
- } from './workflow-helpers.js'
9
-
10
- describe('workflow helpers', () => {
11
- describe('workflow', () => {
12
- test('should return an object with func', () => {
13
- const wf = workflow('myWorkflow')
14
- assert.strictEqual(typeof wf.func, 'function')
15
- })
16
-
17
- test('func should call workflowService.runToCompletion', async () => {
18
- const wf = workflow('myWorkflow', { pollIntervalMs: 500 })
19
- let calledWith: any
20
- const services = {
21
- workflowService: {
22
- runToCompletion: async (...args: any[]) => {
23
- calledWith = args
24
- return { result: 'done' }
25
- },
26
- },
27
- }
28
- const result = await wf.func(services, { input: 1 }, { rpc: {} })
29
- assert.strictEqual(calledWith[0], 'myWorkflow')
30
- assert.deepStrictEqual(calledWith[1], { input: 1 })
31
- assert.deepStrictEqual(result, { result: 'done' })
32
- })
33
- })
34
-
35
- describe('workflowStart', () => {
36
- test('should return an object with func', () => {
37
- const wfs = workflowStart('myWorkflow')
38
- assert.strictEqual(typeof wfs.func, 'function')
39
- })
40
-
41
- test('func should call rpc.startWorkflow', async () => {
42
- const wfs = workflowStart('myWorkflow')
43
- let calledWith: any
44
- const rpc = {
45
- startWorkflow: async (...args: any[]) => {
46
- calledWith = args
47
- return { runId: 'run-1' }
48
- },
49
- }
50
- const result = await wfs.func({}, { input: 1 }, { rpc })
51
- assert.strictEqual(calledWith[0], 'myWorkflow')
52
- assert.deepStrictEqual(calledWith[1], { input: 1 })
53
- assert.deepStrictEqual(result, { runId: 'run-1' })
54
- })
55
- })
56
-
57
- describe('workflowStatus', () => {
58
- test('should return an object with func', () => {
59
- const wfst = workflowStatus('myWorkflow')
60
- assert.strictEqual(typeof wfst.func, 'function')
61
- })
62
-
63
- test('func should return run status', async () => {
64
- const wfst = workflowStatus('myWorkflow')
65
- const services = {
66
- workflowService: {
67
- getRun: async (runId: string) => ({
68
- id: runId,
69
- status: 'completed',
70
- output: { data: 'ok' },
71
- }),
72
- },
73
- }
74
- const result = await wfst.func(services, { runId: 'run-1' })
75
- assert.strictEqual(result.id, 'run-1')
76
- assert.strictEqual(result.status, 'completed')
77
- assert.deepStrictEqual(result.output, { data: 'ok' })
78
- })
79
-
80
- test('func should throw WorkflowRunNotFoundError for missing run', async () => {
81
- const wfst = workflowStatus('myWorkflow')
82
- const services = {
83
- workflowService: { getRun: async () => null },
84
- }
85
- await assert.rejects(
86
- () => wfst.func(services, { runId: 'non-existent' }),
87
- (err: any) => err.message.includes('non-existent')
88
- )
89
- })
90
-
91
- test('func should include error message when run has error', async () => {
92
- const wfst = workflowStatus('myWorkflow')
93
- const services = {
94
- workflowService: {
95
- getRun: async () => ({
96
- id: 'run-2',
97
- status: 'failed',
98
- error: { message: 'step failed', name: 'Error' },
99
- }),
100
- },
101
- }
102
- const result = await wfst.func(services, { runId: 'run-2' })
103
- assert.strictEqual(result.status, 'failed')
104
- assert.deepStrictEqual(result.error, { message: 'step failed' })
105
- })
106
- })
107
-
108
- describe('graphStart', () => {
109
- test('should return an object with func', () => {
110
- const gs = graphStart('myGraph', 'startNode')
111
- assert.strictEqual(typeof gs.func, 'function')
112
- })
113
-
114
- test('func should call rpc.startWorkflow with startNode', async () => {
115
- const gs = graphStart('myGraph', 'nodeA')
116
- let calledWith: any
117
- const rpc = {
118
- startWorkflow: async (...args: any[]) => {
119
- calledWith = args
120
- return { runId: 'run-3' }
121
- },
122
- }
123
- const result = await gs.func({}, { input: 1 }, { rpc })
124
- assert.strictEqual(calledWith[0], 'myGraph')
125
- assert.deepStrictEqual(calledWith[2], { startNode: 'nodeA' })
126
- assert.deepStrictEqual(result, { runId: 'run-3' })
127
- })
128
- })
129
- })
@@ -1,79 +0,0 @@
1
- import { WorkflowRunNotFoundError } from './pikku-workflow-service.js'
2
-
3
- export function workflow<
4
- TWorkflowMap extends Record<string, { input: any; output: any }>,
5
- >(
6
- workflowName: string & keyof TWorkflowMap,
7
- options?: { pollIntervalMs?: number }
8
- ): { func: (services: any, data: any, wire: any) => Promise<any> } {
9
- return {
10
- func: async (services: any, data: any, { rpc }: any) => {
11
- return services.workflowService.runToCompletion(
12
- workflowName,
13
- data,
14
- rpc,
15
- options
16
- )
17
- },
18
- }
19
- }
20
-
21
- export function workflowStart<
22
- TWorkflowMap extends Record<string, { input: any; output: any }>,
23
- >(
24
- workflowName: string & keyof TWorkflowMap
25
- ): {
26
- func: (services: any, data: any, wire: any) => Promise<{ runId: string }>
27
- } {
28
- return {
29
- func: async (_services: any, data: any, { rpc }: any) => {
30
- return rpc.startWorkflow(workflowName, data)
31
- },
32
- }
33
- }
34
-
35
- export function workflowStatus<
36
- TWorkflowMap extends Record<string, { input: any; output: any }>,
37
- >(
38
- _workflowName: string & keyof TWorkflowMap
39
- ): {
40
- func: (
41
- services: any,
42
- data: { runId: string }
43
- ) => Promise<{
44
- id: string
45
- status: 'running' | 'suspended' | 'completed' | 'failed' | 'cancelled'
46
- output?: any
47
- error?: { message?: string }
48
- }>
49
- } {
50
- return {
51
- func: async (services: any, data: { runId: string }) => {
52
- const run = await services.workflowService.getRun(data.runId)
53
- if (!run) {
54
- throw new WorkflowRunNotFoundError(data.runId)
55
- }
56
- return {
57
- id: run.id,
58
- status: run.status,
59
- output: run.output,
60
- error: run.error ? { message: run.error.message } : undefined,
61
- }
62
- },
63
- }
64
- }
65
-
66
- export function graphStart<
67
- TGraphsMap extends Record<string, Record<string, any>>,
68
- >(
69
- graphName: string & keyof TGraphsMap,
70
- startNode: string
71
- ): {
72
- func: (services: any, data: any, wire: any) => Promise<{ runId: string }>
73
- } {
74
- return {
75
- func: async (_services: any, data: any, { rpc }: any) => {
76
- return rpc.startWorkflow(graphName, data, { startNode })
77
- },
78
- }
79
- }
@@ -1,266 +0,0 @@
1
- import type { SerializedError, CommonWireMeta } from '../../types/core.types.js'
2
- import type { CorePikkuFunctionConfig } from '../../function/functions.types.js'
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
- WorkflowWireSuspend,
14
- InputSource,
15
- OutputBinding,
16
- RpcStepMeta,
17
- SimpleCondition,
18
- Condition,
19
- BranchCase,
20
- BranchStepMeta,
21
- ParallelGroupStepMeta,
22
- FanoutStepMeta,
23
- ReturnStepMeta,
24
- InlineStepMeta,
25
- SleepStepMeta,
26
- CancelStepMeta,
27
- SetStepMeta,
28
- SwitchCaseMeta,
29
- SwitchStepMeta,
30
- FilterStepMeta,
31
- ArrayPredicateStepMeta,
32
- WorkflowStepMeta,
33
- WorkflowStepWire,
34
- PikkuWorkflowWire,
35
- } from './dsl/workflow-dsl.types.js'
36
-
37
- import type { WorkflowStepMeta } from './dsl/workflow-dsl.types.js'
38
-
39
- export interface WorkflowRunWire {
40
- type: string
41
- id?: string
42
- parentRunId?: string
43
- }
44
-
45
- export interface WorkflowServiceConfig {
46
- retries: number
47
- retryDelay: number
48
- orchestratorQueueName: string
49
- stepWorkerQueueName: string
50
- sleeperRPCName: string
51
- }
52
-
53
- /**
54
- * Workflow run status
55
- */
56
- export type WorkflowStatus =
57
- | 'running'
58
- | 'suspended'
59
- | 'completed'
60
- | 'failed'
61
- | 'cancelled'
62
-
63
- /**
64
- * Workflow step status
65
- */
66
- export type StepStatus =
67
- | 'pending'
68
- | 'running'
69
- | 'scheduled'
70
- | 'succeeded'
71
- | 'failed'
72
- | 'suspended'
73
-
74
- /**
75
- * Workflow run representation
76
- */
77
- export interface WorkflowRun {
78
- /** Unique run ID */
79
- id: string
80
- /** Workflow name */
81
- workflow: string
82
- /** Current status */
83
- status: WorkflowStatus
84
- /** Input data */
85
- input: any
86
- /** Output data (if completed) */
87
- output?: any
88
- /** Error (if failed) */
89
- error?: SerializedError
90
- /** If true, workflow executes inline without queues */
91
- inline?: boolean
92
- /** Graph hash of the workflow definition at run creation time */
93
- graphHash?: string
94
- /** Wire origin info (how this run was started) */
95
- wire: WorkflowRunWire
96
- /** Creation timestamp */
97
- createdAt: Date
98
- /** Last update timestamp */
99
- updatedAt: Date
100
- }
101
-
102
- /**
103
- * Step state representation
104
- */
105
- export interface StepState {
106
- /** Unique step ID */
107
- stepId: string
108
- /** Step status */
109
- status: StepStatus
110
- /** Step result (if done) */
111
- result?: any
112
- /** Step error (if error) */
113
- error?: SerializedError
114
- /** Number of attempts made (starts at 1) */
115
- attemptCount: number
116
- /** Maximum retry attempts allowed */
117
- retries?: number
118
- /** Delay between retries */
119
- retryDelay?: string | number
120
- /** Creation timestamp */
121
- createdAt: Date
122
- /** Last update timestamp */
123
- updatedAt: Date
124
- /** Timestamp when step started running */
125
- runningAt?: Date
126
- /** Timestamp when step was scheduled */
127
- scheduledAt?: Date
128
- /** Timestamp when step succeeded */
129
- succeededAt?: Date
130
- /** Timestamp when step failed */
131
- failedAt?: Date
132
- }
133
-
134
- export interface WorkflowRunService {
135
- listRuns(options?: {
136
- workflowName?: string
137
- status?: string
138
- limit?: number
139
- offset?: number
140
- }): Promise<WorkflowRun[]>
141
- getRun(id: string): Promise<WorkflowRun | null>
142
- getRunSteps(
143
- runId: string
144
- ): Promise<
145
- Array<StepState & { stepName: string; rpcName?: string; data?: any }>
146
- >
147
- getRunHistory(runId: string): Promise<Array<StepState & { stepName: string }>>
148
- getDistinctWorkflowNames(): Promise<string[]>
149
- getWorkflowVersion(
150
- name: string,
151
- graphHash: string
152
- ): Promise<{ graph: any; source: string } | null>
153
- deleteRun(id: string): Promise<boolean>
154
- }
155
-
156
- /**
157
- * Core workflow definition
158
- */
159
- export type CoreWorkflow<
160
- PikkuFunctionConfig extends CorePikkuFunctionConfig<
161
- any,
162
- any,
163
- any
164
- > = CorePikkuFunctionConfig<any, any, any>,
165
- > = {
166
- /** Unique workflow name */
167
- name: string
168
- /** The workflow function */
169
- func: PikkuFunctionConfig
170
- /** Middleware chain for this workflow */
171
- middleware?: PikkuFunctionConfig['middleware']
172
- /** Permission requirements */
173
- permissions?: PikkuFunctionConfig['permissions']
174
- /** Tags for organization and filtering */
175
- tags?: string[]
176
- }
177
-
178
- /**
179
- * Workflow client interface
180
- */
181
- export interface PikkuWorkflow {
182
- /** Start a new workflow run */
183
- start: <I>(input: I) => Promise<{ runId: string }>
184
- /** Get a workflow run by ID */
185
- getRun: (runId: string) => Promise<WorkflowRun>
186
- /** Cancel a running workflow */
187
- cancelRun: (runId: string) => Promise<void>
188
- }
189
-
190
- /**
191
- * Context variable definition (serialized from Zod schema or type inference)
192
- */
193
- export interface ContextVariable {
194
- /** Variable type */
195
- type: 'string' | 'number' | 'boolean' | 'object' | 'array'
196
- /** Default value */
197
- default?: unknown
198
- /** Description for UI/docs */
199
- description?: string
200
- }
201
-
202
- /**
203
- * Workflow context - state variables with defaults and types
204
- */
205
- export type WorkflowContext = Record<string, ContextVariable>
206
-
207
- /**
208
- * Workflows metadata for inspector/CLI (DSL step-based format)
209
- */
210
- export type WorkflowsMeta = Record<
211
- string,
212
- CommonWireMeta & {
213
- name: string
214
- steps: WorkflowStepMeta[]
215
- context?: WorkflowContext
216
- dsl?: boolean
217
- }
218
- >
219
-
220
- /**
221
- * Unified workflow runtime meta (used by runtime to execute workflows)
222
- * This is the format stored in pikkuState('workflows', 'meta')
223
- * Both DSL and graph-based workflows are converted to this format
224
- */
225
- export interface WorkflowRuntimeMeta {
226
- /** Workflow name (used as key in registrations) */
227
- name: string
228
- /** Pikku function name (for execution) */
229
- pikkuFuncId: string
230
- /** Source type: 'dsl' (serializable), 'complex' (has inline steps), 'graph' */
231
- source: 'dsl' | 'complex' | 'graph'
232
- /** Optional description */
233
- description?: string
234
- /** Tags for organization */
235
- tags?: string[]
236
- /** Serialized nodes */
237
- nodes?: Record<string, any>
238
- /** Entry node IDs for graph workflows (computed at build time) */
239
- entryNodeIds?: string[]
240
- /** Hash of graph topology (nodes, edges, input mappings) */
241
- graphHash?: string
242
- }
243
-
244
- /**
245
- * Unified workflow runtime metadata map
246
- */
247
- export type WorkflowsRuntimeMeta = Record<string, WorkflowRuntimeMeta>
248
-
249
- /**
250
- * Worker input types for generated queue workers
251
- */
252
- export type WorkflowStepInput = {
253
- runId: string
254
- stepName: string
255
- rpcName: string
256
- data: any
257
- }
258
-
259
- export type WorkflowOrchestratorInput = {
260
- runId: string
261
- }
262
-
263
- export type WorkflowSleeperInput = {
264
- runId: string
265
- stepId: string
266
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "composite": true,
6
- "module": "Node18",
7
- "outDir": "dist",
8
- "target": "esnext",
9
- "moduleResolution": "node16",
10
- "tsBuildInfoFile": null
11
- },
12
- "exclude": ["**/*.test.ts", "node_modules", "dist"],
13
- "references": []
14
- }