@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.
- package/dist/agent-init/agent-project-generator.d.ts +5 -1
- package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent-project/agent-project.d.ts +3 -3
- package/dist/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/agent-resolver.d.ts.map +1 -1
- package/dist/agent-project/config-writer.d.ts +1 -1
- package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
- package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
- package/dist/agent-project/types.d.ts +9 -4
- package/dist/agent-project/types.d.ts.map +1 -1
- package/dist/agent0/capabilities/commands/adk-build.md +6 -5
- package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
- package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
- package/dist/agent0/capabilities/commands/adk-document.md +10 -2
- package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
- package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
- package/dist/agent0/capabilities/commands/adk-init.md +2 -2
- package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
- package/dist/agent0/capabilities/commands/adk-test.md +3 -3
- package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
- package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
- package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
- package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
- package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
- package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
- package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
- package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
- package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
- package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
- package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
- package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
- package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
- package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
- package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
- package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
- package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
- package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
- package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
- package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
- package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
- package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
- package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
- package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
- package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
- package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
- package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
- package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
- package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
- package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
- package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
- package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
- package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
- package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
- package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
- package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
- package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
- package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
- package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
- package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
- package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
- package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
- package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
- package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
- package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
- package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
- package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
- package/dist/agent0/index.js +41 -19
- package/dist/agent0/index.js.map +7 -7
- package/dist/agent0/runtime/client.d.ts +2 -0
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +2 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +1 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -1
- package/dist/assets/manager.d.ts +3 -0
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/auth/credentials.d.ts +1 -1
- package/dist/bot-generator/generator.d.ts +22 -0
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/commands/base-command.d.ts +1 -0
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-command.d.ts +1 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +9 -0
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
- package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
- package/dist/dependencies/catalog/client-factory.d.ts +33 -0
- package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
- package/dist/dependencies/catalog/integration-source.d.ts +34 -0
- package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/interface-source.d.ts +23 -0
- package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
- package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
- package/dist/dependencies/dependency-manager.d.ts +31 -16
- package/dist/dependencies/dependency-manager.d.ts.map +1 -1
- package/dist/dependencies/errors.d.ts +2 -2
- package/dist/dependencies/errors.d.ts.map +1 -1
- package/dist/dependencies/index.d.ts +5 -4
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +2089 -1670
- package/dist/dependencies/index.js.map +37 -30
- package/dist/dependencies/legacy-lock-file.d.ts +15 -0
- package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
- package/dist/dependencies/migration.d.ts +19 -0
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
- package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
- package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
- package/dist/dependencies/snapshot-store.d.ts +59 -0
- package/dist/dependencies/snapshot-store.d.ts.map +1 -0
- package/dist/dependencies/status-resolver.d.ts +36 -0
- package/dist/dependencies/status-resolver.d.ts.map +1 -0
- package/dist/dependencies/status.d.ts +214 -0
- package/dist/dependencies/status.d.ts.map +1 -0
- package/dist/dependencies/types.d.ts +380 -29
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/file-watcher/watcher.d.ts +21 -5
- package/dist/file-watcher/watcher.d.ts.map +1 -1
- package/dist/generators/action-types.d.ts.map +1 -1
- package/dist/generators/client-wrapper.d.ts.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3134 -2226
- package/dist/index.js.map +55 -48
- package/dist/integrations/config-utils.d.ts +11 -7
- package/dist/integrations/config-utils.d.ts.map +1 -1
- package/dist/integrations/hub-cache.d.ts +0 -58
- package/dist/integrations/hub-cache.d.ts.map +1 -1
- package/dist/integrations/index.d.ts +1 -3
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts +19 -53
- package/dist/integrations/manager.d.ts.map +1 -1
- package/dist/interfaces/enhanced-cache.d.ts +7 -7
- package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
- package/dist/interfaces/manager.d.ts +11 -17
- package/dist/interfaces/manager.d.ts.map +1 -1
- package/dist/knowledge/manager.d.ts +3 -0
- package/dist/knowledge/manager.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts +16 -48
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts +6 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/preflight/dependency-gate.d.ts +37 -0
- package/dist/preflight/dependency-gate.d.ts.map +1 -0
- package/dist/preflight/index.d.ts +2 -1
- package/dist/preflight/index.d.ts.map +1 -1
- package/dist/preflight/types.d.ts +18 -0
- package/dist/preflight/types.d.ts.map +1 -1
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/tables/table-manager.d.ts +3 -0
- package/dist/tables/table-manager.d.ts.map +1 -1
- package/dist/templates/README.md +23 -13
- package/dist/templates/blank/agent.config.ts +3 -3
- package/dist/templates/blank/src/triggers/index.ts +1 -1
- package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
- package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
- package/dist/templates/crm-enrichment/README.md +3 -3
- package/dist/templates/crm-enrichment/agent.config.ts +2 -2
- package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
- package/dist/templates/hello-world/agent.config.ts +3 -3
- package/dist/templates/hello-world/src/triggers/index.ts +1 -1
- package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
- package/dist/templates/template.config.json +3 -3
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -1
- package/dist/workspace/workspace-cache.d.ts +2 -1
- package/dist/workspace/workspace-cache.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
- package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
- package/dist/dependencies/lock-file.d.ts +0 -15
- package/dist/dependencies/lock-file.d.ts.map +0 -1
- package/dist/integrations/enhanced-cache.d.ts +0 -53
- package/dist/integrations/enhanced-cache.d.ts.map +0 -1
- package/dist/plugins/enhanced-cache.d.ts +0 -53
- package/dist/plugins/enhanced-cache.d.ts.map +0 -1
- package/dist/templates/blank/package.json +0 -17
- package/dist/templates/blank/tsconfig.json +0 -25
- package/dist/templates/botpress-desk/package.json +0 -17
- package/dist/templates/crm-enrichment/package.json +0 -18
- package/dist/templates/crm-enrichment/tsconfig.json +0 -25
- package/dist/templates/hello-world/package.json +0 -18
- package/dist/templates/hello-world/tsconfig.json +0 -25
- package/dist/templates/knowledge-assistant/package.json +0 -18
- package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
- package/dist/templates/slack-triage/package.json +0 -18
- 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
|
|
44
|
-
|
|
45
|
-
| `name`
|
|
46
|
-
| `run`
|
|
47
|
-
| `options.maxAttempts` | `number`
|
|
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(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
101
|
-
|
|
102
|
-
| `request`
|
|
103
|
-
| `message`
|
|
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
|
|
219
|
-
|
|
220
|
-
| `notification` | `string` | required
|
|
221
|
-
| `payload`
|
|
222
|
-
| `stepName`
|
|
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(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
|
258
|
-
|
|
260
|
+
const tickets = await step('fetch-tickets', async () => {
|
|
261
|
+
/* ... */
|
|
262
|
+
})
|
|
259
263
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
|
352
|
-
|
|
353
|
-
| `name`
|
|
354
|
-
| `items`
|
|
355
|
-
| `run`
|
|
356
|
-
| `opts.maxAttempts` | `number`
|
|
357
|
-
| `opts.concurrency` | `number`
|
|
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(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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) =>
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
|
461
|
-
|
|
462
|
-
| `name`
|
|
463
|
-
| `items`
|
|
464
|
-
| `run`
|
|
465
|
-
| `opts.batchSize`
|
|
466
|
-
| `opts.maxAttempts` | `number`
|
|
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
|
|
491
|
-
|
|
492
|
-
| `step.batch()`
|
|
493
|
-
| `step.map()`
|
|
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(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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')
|
|
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 () => {
|