@botpress/adk 1.19.0-beta.9 → 2.0.0-alpha.0

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 (199) hide show
  1. package/dist/agent-init/agent-project-generator.d.ts +5 -1
  2. package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
  3. package/dist/agent-project/agent-project.d.ts +3 -3
  4. package/dist/agent-project/agent-project.d.ts.map +1 -1
  5. package/dist/agent-project/agent-resolver.d.ts.map +1 -1
  6. package/dist/agent-project/config-writer.d.ts +1 -1
  7. package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
  8. package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
  9. package/dist/agent-project/types.d.ts +9 -4
  10. package/dist/agent-project/types.d.ts.map +1 -1
  11. package/dist/agent0/capabilities/commands/adk-build.md +6 -5
  12. package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
  13. package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
  14. package/dist/agent0/capabilities/commands/adk-document.md +10 -2
  15. package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
  16. package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
  17. package/dist/agent0/capabilities/commands/adk-init.md +2 -2
  18. package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
  19. package/dist/agent0/capabilities/commands/adk-test.md +3 -3
  20. package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
  21. package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
  22. package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
  23. package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
  24. package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
  25. package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
  26. package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
  27. package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
  28. package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
  29. package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
  30. package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
  31. package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
  32. package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
  33. package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
  34. package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
  35. package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
  36. package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
  37. package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
  38. package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
  39. package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
  40. package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
  41. package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
  42. package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
  43. package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
  44. package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
  45. package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
  46. package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
  47. package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
  48. package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
  49. package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
  50. package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
  51. package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
  52. package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
  53. package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
  54. package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
  55. package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
  56. package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
  57. package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
  58. package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
  59. package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
  60. package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
  61. package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
  62. package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
  63. package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
  64. package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
  65. package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
  66. package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
  67. package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
  68. package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
  69. package/dist/agent0/index.js +41 -19
  70. package/dist/agent0/index.js.map +7 -7
  71. package/dist/agent0/runtime/client.d.ts +2 -0
  72. package/dist/agent0/runtime/client.d.ts.map +1 -1
  73. package/dist/agent0/runtime/engine.d.ts +2 -1
  74. package/dist/agent0/runtime/engine.d.ts.map +1 -1
  75. package/dist/agent0/runtime/process.d.ts +1 -0
  76. package/dist/agent0/runtime/process.d.ts.map +1 -1
  77. package/dist/assets/manager.d.ts +3 -0
  78. package/dist/assets/manager.d.ts.map +1 -1
  79. package/dist/auth/credentials.d.ts +1 -1
  80. package/dist/bot-generator/generator.d.ts +22 -0
  81. package/dist/bot-generator/generator.d.ts.map +1 -1
  82. package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
  83. package/dist/commands/base-command.d.ts +1 -0
  84. package/dist/commands/base-command.d.ts.map +1 -1
  85. package/dist/commands/bp-dev-command.d.ts +1 -1
  86. package/dist/commands/bp-dev-command.d.ts.map +1 -1
  87. package/dist/commands/bp-dev-stderr.d.ts +9 -0
  88. package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
  89. package/dist/commands/index.d.ts +1 -0
  90. package/dist/commands/index.d.ts.map +1 -1
  91. package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
  92. package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
  93. package/dist/dependencies/catalog/client-factory.d.ts +33 -0
  94. package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
  95. package/dist/dependencies/catalog/integration-source.d.ts +34 -0
  96. package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
  97. package/dist/dependencies/catalog/interface-source.d.ts +23 -0
  98. package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
  99. package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
  100. package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
  101. package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
  102. package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
  103. package/dist/dependencies/dependency-manager.d.ts +31 -16
  104. package/dist/dependencies/dependency-manager.d.ts.map +1 -1
  105. package/dist/dependencies/errors.d.ts +2 -2
  106. package/dist/dependencies/errors.d.ts.map +1 -1
  107. package/dist/dependencies/index.d.ts +5 -4
  108. package/dist/dependencies/index.d.ts.map +1 -1
  109. package/dist/dependencies/index.js +2089 -1670
  110. package/dist/dependencies/index.js.map +37 -30
  111. package/dist/dependencies/legacy-lock-file.d.ts +15 -0
  112. package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
  113. package/dist/dependencies/migration.d.ts +19 -0
  114. package/dist/dependencies/migration.d.ts.map +1 -1
  115. package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
  116. package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
  117. package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
  118. package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
  119. package/dist/dependencies/snapshot-store.d.ts +59 -0
  120. package/dist/dependencies/snapshot-store.d.ts.map +1 -0
  121. package/dist/dependencies/status-resolver.d.ts +36 -0
  122. package/dist/dependencies/status-resolver.d.ts.map +1 -0
  123. package/dist/dependencies/status.d.ts +214 -0
  124. package/dist/dependencies/status.d.ts.map +1 -0
  125. package/dist/dependencies/types.d.ts +380 -29
  126. package/dist/dependencies/types.d.ts.map +1 -1
  127. package/dist/file-watcher/watcher.d.ts +21 -5
  128. package/dist/file-watcher/watcher.d.ts.map +1 -1
  129. package/dist/generators/action-types.d.ts.map +1 -1
  130. package/dist/generators/client-wrapper.d.ts.map +1 -1
  131. package/dist/index.d.ts +4 -5
  132. package/dist/index.d.ts.map +1 -1
  133. package/dist/index.js +3134 -2226
  134. package/dist/index.js.map +55 -48
  135. package/dist/integrations/config-utils.d.ts +11 -7
  136. package/dist/integrations/config-utils.d.ts.map +1 -1
  137. package/dist/integrations/hub-cache.d.ts +0 -58
  138. package/dist/integrations/hub-cache.d.ts.map +1 -1
  139. package/dist/integrations/index.d.ts +1 -3
  140. package/dist/integrations/index.d.ts.map +1 -1
  141. package/dist/integrations/manager.d.ts +19 -53
  142. package/dist/integrations/manager.d.ts.map +1 -1
  143. package/dist/interfaces/enhanced-cache.d.ts +7 -7
  144. package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
  145. package/dist/interfaces/manager.d.ts +11 -17
  146. package/dist/interfaces/manager.d.ts.map +1 -1
  147. package/dist/knowledge/manager.d.ts +3 -0
  148. package/dist/knowledge/manager.d.ts.map +1 -1
  149. package/dist/plugins/index.d.ts +0 -1
  150. package/dist/plugins/index.d.ts.map +1 -1
  151. package/dist/plugins/manager.d.ts +16 -48
  152. package/dist/plugins/manager.d.ts.map +1 -1
  153. package/dist/preflight/checker.d.ts +6 -1
  154. package/dist/preflight/checker.d.ts.map +1 -1
  155. package/dist/preflight/dependency-gate.d.ts +37 -0
  156. package/dist/preflight/dependency-gate.d.ts.map +1 -0
  157. package/dist/preflight/index.d.ts +2 -1
  158. package/dist/preflight/index.d.ts.map +1 -1
  159. package/dist/preflight/types.d.ts +18 -0
  160. package/dist/preflight/types.d.ts.map +1 -1
  161. package/dist/runner/script-runner.d.ts.map +1 -1
  162. package/dist/tables/table-manager.d.ts +3 -0
  163. package/dist/tables/table-manager.d.ts.map +1 -1
  164. package/dist/templates/README.md +23 -13
  165. package/dist/templates/blank/agent.config.ts +3 -3
  166. package/dist/templates/blank/src/triggers/index.ts +1 -1
  167. package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
  168. package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
  169. package/dist/templates/crm-enrichment/README.md +3 -3
  170. package/dist/templates/crm-enrichment/agent.config.ts +2 -2
  171. package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
  172. package/dist/templates/hello-world/agent.config.ts +3 -3
  173. package/dist/templates/hello-world/src/triggers/index.ts +1 -1
  174. package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
  175. package/dist/templates/template.config.json +3 -3
  176. package/dist/utils/ids.d.ts +10 -0
  177. package/dist/utils/ids.d.ts.map +1 -1
  178. package/dist/workspace/workspace-cache.d.ts +2 -1
  179. package/dist/workspace/workspace-cache.d.ts.map +1 -1
  180. package/package.json +3 -3
  181. package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
  182. package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
  183. package/dist/dependencies/lock-file.d.ts +0 -15
  184. package/dist/dependencies/lock-file.d.ts.map +0 -1
  185. package/dist/integrations/enhanced-cache.d.ts +0 -53
  186. package/dist/integrations/enhanced-cache.d.ts.map +0 -1
  187. package/dist/plugins/enhanced-cache.d.ts +0 -53
  188. package/dist/plugins/enhanced-cache.d.ts.map +0 -1
  189. package/dist/templates/blank/package.json +0 -17
  190. package/dist/templates/blank/tsconfig.json +0 -25
  191. package/dist/templates/botpress-desk/package.json +0 -17
  192. package/dist/templates/crm-enrichment/package.json +0 -18
  193. package/dist/templates/crm-enrichment/tsconfig.json +0 -25
  194. package/dist/templates/hello-world/package.json +0 -18
  195. package/dist/templates/hello-world/tsconfig.json +0 -25
  196. package/dist/templates/knowledge-assistant/package.json +0 -18
  197. package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
  198. package/dist/templates/slack-triage/package.json +0 -18
  199. package/dist/templates/slack-triage/tsconfig.json +0 -25
@@ -5,6 +5,7 @@ Complete reference for every method on the `step` object inside workflow handler
5
5
  > **Prerequisites:** See [workflows.md](./workflows.md) for workflow basics — creating workflows, input/output/state schemas, request/notification definitions, instance management, and scheduling. This file covers only the step execution surface.
6
6
 
7
7
  ## Table of Contents
8
+
8
9
  - [step() — Named Steps](#step--named-steps)
9
10
  - [step.request() — Pause for Conversation Data](#steprequest--pause-for-conversation-data)
10
11
  - [step.notify() — Send Typed Notifications](#stepnotify--send-typed-notifications)
@@ -40,11 +41,11 @@ step<T>(
40
41
 
41
42
  ### Parameters
42
43
 
43
- | Parameter | Type | Default | Description |
44
- |-----------|------|---------|-------------|
45
- | `name` | `string` | required | Unique identifier within the workflow. Must be stable across executions. |
46
- | `run` | `({ attempt }) => T \| Promise<T>` | required | Function to execute. Receives current attempt number (0-indexed). |
47
- | `options.maxAttempts` | `number` | `5` | Maximum retry attempts before the step fails permanently. |
44
+ | Parameter | Type | Default | Description |
45
+ | --------------------- | ---------------------------------- | -------- | ------------------------------------------------------------------------ |
46
+ | `name` | `string` | required | Unique identifier within the workflow. Must be stable across executions. |
47
+ | `run` | `({ attempt }) => T \| Promise<T>` | required | Function to execute. Receives current attempt number (0-indexed). |
48
+ | `options.maxAttempts` | `number` | `5` | Maximum retry attempts before the step fails permanently. |
48
49
 
49
50
  ### Behavior
50
51
 
@@ -62,10 +63,14 @@ const user = await step('fetch-user', async () => {
62
63
  })
63
64
 
64
65
  // Step with retry awareness
65
- const result = await step('call-api', async ({ attempt }) => {
66
- console.log(`Attempt ${attempt}`)
67
- return await externalApi.call(input.data)
68
- }, { maxAttempts: 3 })
66
+ const result = await step(
67
+ 'call-api',
68
+ async ({ attempt }) => {
69
+ console.log(`Attempt ${attempt}`)
70
+ return await externalApi.call(input.data)
71
+ },
72
+ { maxAttempts: 3 }
73
+ )
69
74
 
70
75
  // Nested steps — each sub-step is independently retried and cached
71
76
  const processed = await step('process', async () => {
@@ -97,10 +102,10 @@ step.request(
97
102
 
98
103
  ### Parameters
99
104
 
100
- | Parameter | Type | Default | Description |
101
- |-----------|------|---------|-------------|
102
- | `request` | `string` | required | Name of a request type defined in the workflow's `requests` schema. |
103
- | `message` | `string` | required | Prompt message sent to the conversation as context. |
105
+ | Parameter | Type | Default | Description |
106
+ | ---------- | -------- | ---------------------------------- | ----------------------------------------------------------------------------- |
107
+ | `request` | `string` | required | Name of a request type defined in the workflow's `requests` schema. |
108
+ | `message` | `string` | required | Prompt message sent to the conversation as context. |
104
109
  | `stepName` | `string` | defaults to the value of `request` | Custom step name. Required when the same request type is used multiple times. |
105
110
 
106
111
  ### Behavior
@@ -162,17 +167,10 @@ export const SoftwareRequestWorkflow = new Workflow({
162
167
  'collect-justification'
163
168
  )
164
169
 
165
- const manager = await step.request(
166
- 'text_input',
167
- "Who is your manager?",
168
- 'collect-manager'
169
- )
170
+ const manager = await step.request('text_input', 'Who is your manager?', 'collect-manager')
170
171
 
171
172
  // Different request type — step name defaults to 'confirmation'
172
- const confirmed = await step.request(
173
- 'confirmation',
174
- `Submit request for ${software}?`
175
- )
173
+ const confirmed = await step.request('confirmation', `Submit request for ${software}?`)
176
174
 
177
175
  if (!confirmed) {
178
176
  return { status: 'cancelled', summary: 'Cancelled by user.' }
@@ -191,6 +189,7 @@ export const SoftwareRequestWorkflow = new Workflow({
191
189
  ### Step Name Resolution Rules
192
190
 
193
191
  When `workflow.provide(request, data)` is called without an explicit step name:
192
+
194
193
  1. If exactly one pending step matches the request type, it resolves automatically.
195
194
  2. If multiple pending steps match, it throws — you must pass the step name explicitly.
196
195
  3. If no pending step matches, it throws.
@@ -215,11 +214,11 @@ step.notify(
215
214
 
216
215
  ### Parameters
217
216
 
218
- | Parameter | Type | Default | Description |
219
- |-----------|------|---------|-------------|
220
- | `notification` | `string` | required | Name of a notification defined in the workflow's `notifications` schema. |
221
- | `payload` | `object` | required | Payload validated against the notification's Zod schema. |
222
- | `stepName` | `string` | defaults to the value of `notification` | Custom step name. Required when emitting the same notification multiple times. |
217
+ | Parameter | Type | Default | Description |
218
+ | -------------- | -------- | --------------------------------------- | ------------------------------------------------------------------------------ |
219
+ | `notification` | `string` | required | Name of a notification defined in the workflow's `notifications` schema. |
220
+ | `payload` | `object` | required | Payload validated against the notification's Zod schema. |
221
+ | `stepName` | `string` | defaults to the value of `notification` | Custom step name. Required when emitting the same notification multiple times. |
223
222
 
224
223
  ### Behavior
225
224
 
@@ -247,24 +246,41 @@ export const TicketReviewWorkflow = new Workflow({
247
246
  }),
248
247
  },
249
248
  async handler({ input, step }) {
250
- await step.notify('progress', {
251
- phase: 'scanning', reviewed: 0, total: 0,
252
- message: `Scanning tickets for ${input.department}...`,
253
- }, 'progress-start')
254
-
255
- const tickets = await step('fetch-tickets', async () => { /* ... */ })
249
+ await step.notify(
250
+ 'progress',
251
+ {
252
+ phase: 'scanning',
253
+ reviewed: 0,
254
+ total: 0,
255
+ message: `Scanning tickets for ${input.department}...`,
256
+ },
257
+ 'progress-start'
258
+ )
256
259
 
257
- await step.forEach('review-tickets', tickets, async (ticket, { i }) => {
258
- // Process ticket...
260
+ const tickets = await step('fetch-tickets', async () => {
261
+ /* ... */
262
+ })
259
263
 
260
- // Each notification needs a unique step name
261
- await step.notify('progress', {
262
- phase: i + 1 >= tickets.length ? 'complete' : 'reviewing',
263
- reviewed: i + 1,
264
- total: tickets.length,
265
- message: `Reviewed ${i + 1} of ${tickets.length}...`,
266
- }, `progress-ticket-${i}`)
267
- }, { concurrency: 1 })
264
+ await step.forEach(
265
+ 'review-tickets',
266
+ tickets,
267
+ async (ticket, { i }) => {
268
+ // Process ticket...
269
+
270
+ // Each notification needs a unique step name
271
+ await step.notify(
272
+ 'progress',
273
+ {
274
+ phase: i + 1 >= tickets.length ? 'complete' : 'reviewing',
275
+ reviewed: i + 1,
276
+ total: tickets.length,
277
+ message: `Reviewed ${i + 1} of ${tickets.length}...`,
278
+ },
279
+ `progress-ticket-${i}`
280
+ )
281
+ },
282
+ { concurrency: 1 }
283
+ )
268
284
 
269
285
  return { reviewed: tickets.length, escalated: 0, summary: '...' }
270
286
  },
@@ -309,10 +325,12 @@ step.sleepUntil(name: string, date: Date | string): Promise<void>
309
325
  ### Behavior
310
326
 
311
327
  **step.sleep():**
328
+
312
329
  - For delays >= 10 seconds (or when remaining execution time is insufficient): schedules a `WorkflowContinueEvent` with the specified delay, sets status to `listening`, and aborts. The workflow resumes automatically when the timer fires.
313
330
  - For delays < 10 seconds with sufficient execution time: uses an in-memory `setTimeout`. The workflow stays active.
314
331
 
315
332
  **step.sleepUntil():**
333
+
316
334
  - Computes `ms = targetDate - now - 10s buffer` and delegates to `step.sleep()`.
317
335
  - If the date is in the past (or within the 10s buffer), returns immediately.
318
336
 
@@ -348,13 +366,13 @@ step.map<T, U>(
348
366
 
349
367
  ### Parameters
350
368
 
351
- | Parameter | Type | Default | Description |
352
- |-----------|------|---------|-------------|
353
- | `name` | `string` | required | Name for the map operation. |
354
- | `items` | `T[]` | required | Array of items to process. |
355
- | `run` | `(item, { i }) => Promise<U>` | required | Processing function per item. Receives the item and its index. |
356
- | `opts.maxAttempts` | `number` | `5` | Max retries per item. |
357
- | `opts.concurrency` | `number` | `1` | Max parallel item executions. |
369
+ | Parameter | Type | Default | Description |
370
+ | ------------------ | ----------------------------- | -------- | -------------------------------------------------------------- |
371
+ | `name` | `string` | required | Name for the map operation. |
372
+ | `items` | `T[]` | required | Array of items to process. |
373
+ | `run` | `(item, { i }) => Promise<U>` | required | Processing function per item. Receives the item and its index. |
374
+ | `opts.maxAttempts` | `number` | `5` | Max retries per item. |
375
+ | `opts.concurrency` | `number` | `1` | Max parallel item executions. |
358
376
 
359
377
  ### Behavior
360
378
 
@@ -372,13 +390,19 @@ const workflows = await step.map(
372
390
  'index-sources',
373
391
  kb.sources,
374
392
  async (source) => {
375
- const workflowId = await step('create-sync-workflow', async () =>
376
- await source.syncWorkflow
377
- .getOrCreate({ key: `${kbName}:${source.id}`, input: { /* ... */ } })
378
- .then((x) => x.id)
393
+ const workflowId = await step(
394
+ 'create-sync-workflow',
395
+ async () =>
396
+ await source.syncWorkflow
397
+ .getOrCreate({
398
+ key: `${kbName}:${source.id}`,
399
+ input: {
400
+ /* ... */
401
+ },
402
+ })
403
+ .then((x) => x.id)
379
404
  )
380
- return await step.waitForWorkflow(source.id, workflowId)
381
- .then((x) => x.output)
405
+ return await step.waitForWorkflow(source.id, workflowId).then((x) => x.output)
382
406
  },
383
407
  { concurrency: 10, maxAttempts: 1 }
384
408
  )
@@ -390,12 +414,13 @@ From the directory source — deleting files with concurrency:
390
414
  const deleted = await step.map(
391
415
  'deleting removed files',
392
416
  toRemove,
393
- (f) => client.deleteFile({ id: f.id }).then(() => ({
394
- file: f.id,
395
- name: f.key,
396
- hash: f.metadata?.hash || '',
397
- size: f.size ?? -1,
398
- })),
417
+ (f) =>
418
+ client.deleteFile({ id: f.id }).then(() => ({
419
+ file: f.id,
420
+ name: f.key,
421
+ hash: f.metadata?.hash || '',
422
+ size: f.size ?? -1,
423
+ })),
399
424
  { concurrency: 5 }
400
425
  )
401
426
  ```
@@ -457,13 +482,13 @@ step.batch<T>(
457
482
 
458
483
  ### Parameters
459
484
 
460
- | Parameter | Type | Default | Description |
461
- |-----------|------|---------|-------------|
462
- | `name` | `string` | required | Name for the batch operation. |
463
- | `items` | `T[]` | required | Full array of items. |
464
- | `run` | `(batch, { i }) => Promise<void>` | required | Function receiving a batch slice and the starting index. |
465
- | `opts.batchSize` | `number` | `20` | Number of items per batch. |
466
- | `opts.maxAttempts` | `number` | `5` | Max retries per batch. |
485
+ | Parameter | Type | Default | Description |
486
+ | ------------------ | --------------------------------- | -------- | -------------------------------------------------------- |
487
+ | `name` | `string` | required | Name for the batch operation. |
488
+ | `items` | `T[]` | required | Full array of items. |
489
+ | `run` | `(batch, { i }) => Promise<void>` | required | Function receiving a batch slice and the starting index. |
490
+ | `opts.batchSize` | `number` | `20` | Number of items per batch. |
491
+ | `opts.maxAttempts` | `number` | `5` | Max retries per batch. |
467
492
 
468
493
  ### Behavior
469
494
 
@@ -487,11 +512,11 @@ await step.batch(
487
512
 
488
513
  ### When to Use batch vs map/forEach
489
514
 
490
- | Use | When |
491
- |-----|------|
492
- | `step.batch()` | External API accepts arrays (bulk insert, batch API) |
493
- | `step.map()` | Need individual results per item, want concurrency |
494
- | `step.forEach()` | Side effects per item, want concurrency |
515
+ | Use | When |
516
+ | ---------------- | ---------------------------------------------------- |
517
+ | `step.batch()` | External API accepts arrays (bulk insert, batch API) |
518
+ | `step.map()` | Need individual results per item, want concurrency |
519
+ | `step.forEach()` | Side effects per item, want concurrency |
495
520
 
496
521
  ---
497
522
 
@@ -521,11 +546,7 @@ Internally creates three sub-steps: `{name}-key`, `{name}-start`, `{name}-wait`.
521
546
  ### Examples
522
547
 
523
548
  ```typescript
524
- const result = await step.executeWorkflow(
525
- 'run-analysis',
526
- AnalysisWorkflow,
527
- { data: input.rawData }
528
- )
549
+ const result = await step.executeWorkflow('run-analysis', AnalysisWorkflow, { data: input.rawData })
529
550
  // result is typed as AnalysisWorkflow's output
530
551
  ```
531
552
 
@@ -658,6 +679,7 @@ if (shouldPauseForLater) {
658
679
  ### Caching and Idempotency
659
680
 
660
681
  Every step is identified by its name. When a workflow resumes:
682
+
661
683
  1. Steps that already have a `finishedAt` timestamp return their cached output immediately.
662
684
  2. Steps that failed with `maxAttemptsReached` re-throw their stored error.
663
685
  3. Only steps that haven't completed yet actually execute their `run` function.
@@ -671,6 +693,7 @@ Failed steps retry with exponential backoff: `min(100ms * e^attempt, 5000ms)`. A
671
693
  ### Execution Time Management
672
694
 
673
695
  The runtime monitors remaining execution time. If less than 10 seconds remain:
696
+
674
697
  - New steps will not start.
675
698
  - The workflow enters a brief sleep and then aborts.
676
699
  - On next invocation, execution resumes from the last incomplete step.
@@ -724,15 +747,26 @@ export const BulkProcessWorkflow = new Workflow({
724
747
  status: z.object({ processed: z.number(), total: z.number() }),
725
748
  },
726
749
  handler: async ({ input, step }) => {
727
- const items = await step('fetch-items', async () => { /* ... */ })
750
+ const items = await step('fetch-items', async () => {
751
+ /* ... */
752
+ })
728
753
 
729
- await step.forEach('process', items, async (item, { i }) => {
730
- await processItem(item)
731
- await step.notify('status', {
732
- processed: i + 1,
733
- total: items.length,
734
- }, `status-${i}`)
735
- }, { concurrency: 5 })
754
+ await step.forEach(
755
+ 'process',
756
+ items,
757
+ async (item, { i }) => {
758
+ await processItem(item)
759
+ await step.notify(
760
+ 'status',
761
+ {
762
+ processed: i + 1,
763
+ total: items.length,
764
+ },
765
+ `status-${i}`
766
+ )
767
+ },
768
+ { concurrency: 5 }
769
+ )
736
770
 
737
771
  return { total: items.length }
738
772
  },
@@ -749,11 +783,7 @@ handler: async ({ input, step }) => {
749
783
  'run-children',
750
784
  input.tasks,
751
785
  async (task) => {
752
- return await step.executeWorkflow(
753
- `child-${task.id}`,
754
- ChildWorkflow,
755
- { data: task.data }
756
- )
786
+ return await step.executeWorkflow(`child-${task.id}`, ChildWorkflow, { data: task.data })
757
787
  },
758
788
  { concurrency: 3 }
759
789
  )
@@ -772,11 +802,15 @@ Every step in a workflow must have a unique name that does not change between ex
772
802
  ```typescript
773
803
  // WRONG — dynamic names break on resume if items change
774
804
  for (const item of items) {
775
- await step(`process-${item.id}`, async () => { /* ... */ })
805
+ await step(`process-${item.id}`, async () => {
806
+ /* ... */
807
+ })
776
808
  }
777
809
 
778
810
  // CORRECT — use step.map() or step.forEach() for iteration
779
- await step.map('process-items', items, async (item) => { /* ... */ })
811
+ await step.map('process-items', items, async (item) => {
812
+ /* ... */
813
+ })
780
814
  ```
781
815
 
782
816
  ### step.request() needs custom stepName for repeated types
@@ -815,7 +849,7 @@ await step.forEach('process', items, async (item, { i }) => {
815
849
 
816
850
  ```typescript
817
851
  step.abort()
818
- console.log('never printed') // unreachable
852
+ console.log('never printed') // unreachable
819
853
  ```
820
854
 
821
855
  ### step.fail() reason string becomes the step name
@@ -829,7 +863,9 @@ All work inside a workflow handler should be wrapped in steps. Code between step
829
863
  ```typescript
830
864
  // WRONG — this runs on every resume
831
865
  const processed = heavyComputation(input.data)
832
- await step('use-result', async () => { /* ... */ })
866
+ await step('use-result', async () => {
867
+ /* ... */
868
+ })
833
869
 
834
870
  // CORRECT — wrap in a step
835
871
  const processed = await step('compute', async () => {