@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 @@ Actions are callable, strongly-typed functions that encapsulate reusable logic a
5
5
  ## Overview
6
6
 
7
7
  Actions enable you to:
8
+
8
9
  - Create reusable business logic across your bot
9
10
  - Call integration APIs with type safety
10
11
  - Expose functionality as AI-callable tools
@@ -53,22 +54,23 @@ export default new Action({
53
54
  ```
54
55
 
55
56
  **Why use `export const`?**
57
+
56
58
  - Enables direct imports: `import { myAction } from "./actions/myAction"`
57
59
  - Can pass to `execute()`: `tools: [myAction.asTool()]`
58
60
  - Better for action composition and reusability
59
61
 
60
62
  ## Action Properties
61
63
 
62
- | Property | Type | Required | Description |
63
- |----------|------|----------|-------------|
64
- | **name** | `string` | Yes | Unique alphanumeric identifier (no spaces or special characters) |
65
- | **input** | `z.ZodTypeAny` | Yes | Zod schema defining input parameters |
66
- | **output** | `z.ZodTypeAny` | Yes | Zod schema defining return type |
67
- | **handler** | `function` | Yes | Async function implementing the action logic |
68
- | **title** | `string` | No | Human-readable display name |
69
- | **description** | `string` | No | Description of the action's functionality |
70
- | **attributes** | `Record<string, string>` | No | Custom metadata for categorization |
71
- | **cached** | `boolean` | No | Enable caching for identical inputs (defaults to `false`) |
64
+ | Property | Type | Required | Description |
65
+ | --------------- | ------------------------ | -------- | ---------------------------------------------------------------- |
66
+ | **name** | `string` | Yes | Unique alphanumeric identifier (no spaces or special characters) |
67
+ | **input** | `z.ZodTypeAny` | Yes | Zod schema defining input parameters |
68
+ | **output** | `z.ZodTypeAny` | Yes | Zod schema defining return type |
69
+ | **handler** | `function` | Yes | Async function implementing the action logic |
70
+ | **title** | `string` | No | Human-readable display name |
71
+ | **description** | `string` | No | Description of the action's functionality |
72
+ | **attributes** | `Record<string, string>` | No | Custom metadata for categorization |
73
+ | **cached** | `boolean` | No | Enable caching for identical inputs (defaults to `false`) |
72
74
 
73
75
  ## Handler Syntax
74
76
 
@@ -78,44 +80,44 @@ Action handlers receive a props object containing `input` and `client`. Both met
78
80
 
79
81
  ```typescript
80
82
  export const fetchUser = new Action({
81
- name: "fetchUser",
83
+ name: 'fetchUser',
82
84
  input: z.object({ userId: z.string() }),
83
85
  output: z.object({
84
86
  name: z.string(),
85
- email: z.string()
87
+ email: z.string(),
86
88
  }),
87
89
 
88
90
  async handler({ input, client }) {
89
91
  // input: validated input matching your input schema
90
92
  // client: Botpress API client for making API calls
91
- const { user } = await client.getUser({ id: input.userId });
93
+ const { user } = await client.getUser({ id: input.userId })
92
94
  return {
93
95
  name: user.name,
94
- email: user.tags.email
95
- };
96
- }
97
- });
96
+ email: user.tags.email,
97
+ }
98
+ },
99
+ })
98
100
  ```
99
101
 
100
102
  ### Arrow Function Syntax
101
103
 
102
104
  ```typescript
103
105
  export const updateUser = new Action({
104
- name: "updateUser",
106
+ name: 'updateUser',
105
107
  input: z.object({
106
108
  userId: z.string(),
107
- name: z.string()
109
+ name: z.string(),
108
110
  }),
109
111
  output: z.object({ success: z.boolean() }),
110
112
 
111
113
  handler: async ({ input, client }) => {
112
114
  await client.updateUser({
113
115
  id: input.userId,
114
- name: input.name
115
- });
116
- return { success: true };
117
- }
118
- });
116
+ name: input.name,
117
+ })
118
+ return { success: true }
119
+ },
120
+ })
119
121
  ```
120
122
 
121
123
  ### Common Mistakes
@@ -123,29 +125,32 @@ export const updateUser = new Action({
123
125
  ```typescript
124
126
  // ❌ WRONG - Destructuring input fields directly
125
127
  export const fetchUser = new Action({
126
- name: "fetchUser",
128
+ name: 'fetchUser',
127
129
  input: z.object({ userId: z.string() }),
128
130
  output: z.object({ name: z.string() }),
129
131
 
130
- async handler({ userId }) { // ❌ Wrong! Must be { input }
131
- return { name: userId };
132
- }
133
- });
132
+ async handler({ userId }) {
133
+ // ❌ Wrong! Must be { input }
134
+ return { name: userId }
135
+ },
136
+ })
134
137
 
135
138
  // ✅ CORRECT - Use { input } wrapper
136
139
  export const fetchUser = new Action({
137
- name: "fetchUser",
140
+ name: 'fetchUser',
138
141
  input: z.object({ userId: z.string() }),
139
142
  output: z.object({ name: z.string() }),
140
143
 
141
- async handler({ input }) { // ✅ Correct
142
- const { userId } = input; // Destructure inside handler
143
- return { name: userId };
144
- }
145
- });
144
+ async handler({ input }) {
145
+ // ✅ Correct
146
+ const { userId } = input // Destructure inside handler
147
+ return { name: userId }
148
+ },
149
+ })
146
150
  ```
147
151
 
148
152
  **Key points:**
153
+
149
154
  - Handler receives `{ input, client }` props object
150
155
  - Both method syntax and arrow functions work
151
156
  - Destructure input fields **inside** the handler body, not in the parameter
@@ -157,39 +162,39 @@ export const fetchUser = new Action({
157
162
  ### From Workflows
158
163
 
159
164
  ```typescript
160
- import { Workflow, actions } from "@botpress/runtime";
165
+ import { Workflow, actions } from '@botpress/runtime'
161
166
 
162
167
  export default new Workflow({
163
- name: "processOrder",
168
+ name: 'processOrder',
164
169
  input: z.object({ orderId: z.string() }),
165
170
 
166
171
  handler: async ({ input }) => {
167
172
  // Call your custom actions
168
- const order = await actions.fetchOrder({ orderId: input.orderId });
169
- const result = await actions.processPayment({ order });
173
+ const order = await actions.fetchOrder({ orderId: input.orderId })
174
+ const result = await actions.processPayment({ order })
170
175
 
171
- return result;
172
- }
173
- });
176
+ return result
177
+ },
178
+ })
174
179
  ```
175
180
 
176
181
  ### From Other Actions
177
182
 
178
183
  ```typescript
179
- import { Action, actions, z } from "@botpress/runtime";
184
+ import { Action, actions, z } from '@botpress/runtime'
180
185
 
181
186
  export default new Action({
182
- name: "compositeAction",
187
+ name: 'compositeAction',
183
188
  input: z.object({ userId: z.string() }),
184
189
  output: z.object({ success: z.boolean() }),
185
190
 
186
191
  async handler({ input }) {
187
192
  // Compose multiple actions
188
- const userData = await actions.fetchUser({ userId: input.userId });
189
- const profile = await actions.buildProfile({ user: userData });
190
- return { success: true };
191
- }
192
- });
193
+ const userData = await actions.fetchUser({ userId: input.userId })
194
+ const profile = await actions.buildProfile({ user: userData })
195
+ return { success: true }
196
+ },
197
+ })
193
198
  ```
194
199
 
195
200
  ### Integration Actions
@@ -197,15 +202,15 @@ export default new Action({
197
202
  Call integration actions from within your actions:
198
203
 
199
204
  ```typescript
200
- import { actions } from "@botpress/runtime";
205
+ import { actions } from '@botpress/runtime'
201
206
 
202
207
  // Inside action handler
203
208
  await actions.slack.sendMessage({
204
- channel: "#general",
205
- text: "Message from bot"
206
- });
209
+ channel: '#general',
210
+ text: 'Message from bot',
211
+ })
207
212
 
208
- await actions.linear.issueList({ first: 10 });
213
+ await actions.linear.issueList({ first: 10 })
209
214
  ```
210
215
 
211
216
  See **[Integration Actions](./integration-actions.md)** for complete guide.
@@ -219,64 +224,61 @@ Direct imports are best for the global proxies that actually exist at runtime, s
219
224
  ### Method 1: Direct Imports (Global Context Proxies)
220
225
 
221
226
  ```typescript
222
- import { Action, z, user, bot, adk } from "@botpress/runtime";
223
- import { context } from "@botpress/runtime";
227
+ import { Action, z, user, bot, adk } from '@botpress/runtime'
228
+ import { context } from '@botpress/runtime'
224
229
 
225
230
  export default new Action({
226
- name: "updateUserProfile",
231
+ name: 'updateUserProfile',
227
232
  input: z.object({ name: z.string() }),
228
233
  output: z.object({ success: z.boolean() }),
229
234
 
230
235
  async handler({ input }) {
231
236
  // Access user state directly (when in conversation context)
232
- user.state.profileName = input.name;
233
- user.tags.profileComplete = "true";
237
+ user.state.profileName = input.name
238
+ user.tags.profileComplete = 'true'
234
239
 
235
240
  // Access bot state
236
- bot.state.totalUsers += 1;
241
+ bot.state.totalUsers += 1
237
242
 
238
243
  // Access conversation (when in conversation context)
239
- const conversation = context.get("conversation", { optional: true });
240
- console.log(conversation?.id);
244
+ const conversation = context.get('conversation', { optional: true })
245
+ console.log(conversation?.id)
241
246
 
242
247
  // Use ADK utilities
243
- const extracted = await adk.zai.extract(
244
- input.name,
245
- z.object({ firstName: z.string(), lastName: z.string() })
246
- );
248
+ const extracted = await adk.zai.extract(input.name, z.object({ firstName: z.string(), lastName: z.string() }))
247
249
 
248
- return { success: true };
249
- }
250
- });
250
+ return { success: true }
251
+ },
252
+ })
251
253
  ```
252
254
 
253
255
  ### Method 2: Context API (Explicit Retrieval)
254
256
 
255
257
  ```typescript
256
- import { Action, z, context } from "@botpress/runtime";
258
+ import { Action, z, context } from '@botpress/runtime'
257
259
 
258
260
  export default new Action({
259
- name: "checkContext",
261
+ name: 'checkContext',
260
262
  input: z.object({}),
261
263
  output: z.object({ hasUser: z.boolean() }),
262
264
 
263
265
  async handler({ input }) {
264
266
  // Optional context (may not be available in all scenarios)
265
- const user = context.get("user", { optional: true });
266
- const conversation = context.get("conversation", { optional: true });
267
- const message = context.get("message", { optional: true });
267
+ const user = context.get('user', { optional: true })
268
+ const conversation = context.get('conversation', { optional: true })
269
+ const message = context.get('message', { optional: true })
268
270
 
269
271
  // Always available
270
- const client = context.get("client");
271
- const citations = context.get("citations");
272
+ const client = context.get('client')
273
+ const citations = context.get('citations')
272
274
 
273
275
  if (user) {
274
- console.log(`User: ${user.id}`);
276
+ console.log(`User: ${user.id}`)
275
277
  }
276
278
 
277
- return { hasUser: !!user };
278
- }
279
- });
279
+ return { hasUser: !!user }
280
+ },
281
+ })
280
282
  ```
281
283
 
282
284
  **Which method to use?**
@@ -296,6 +298,7 @@ See **[Context API](./context-api.md)** for complete details on all context keys
296
298
  **Purpose:** Wrap integration actions with bot-specific logic, data transformation, and local persistence.
297
299
 
298
300
  **When to use:**
301
+
299
302
  - Syncing external resources (products, issues, orders) to local tables
300
303
  - Normalizing data from different integrations
301
304
  - Adding business logic or validation
@@ -305,49 +308,49 @@ See **[Context API](./context-api.md)** for complete details on all context keys
305
308
 
306
309
  ```typescript
307
310
  export default new Action({
308
- name: "syncResource",
309
- description: "Fetch and sync external resource to local storage",
311
+ name: 'syncResource',
312
+ description: 'Fetch and sync external resource to local storage',
310
313
 
311
314
  input: z.object({
312
- resourceId: z.string().describe("External resource identifier"),
315
+ resourceId: z.string().describe('External resource identifier'),
313
316
  }),
314
317
 
315
- output: BotResourceSchema, // Your normalized schema
318
+ output: BotResourceSchema, // Your normalized schema
316
319
 
317
320
  async handler({ input }) {
318
321
  // 1. Call integration action
319
322
  const externalData = await actions.integration.getResource({
320
- id: input.resourceId
321
- });
323
+ id: input.resourceId,
324
+ })
322
325
 
323
326
  // 2. Transform to bot schema
324
- const normalizedData = transformToBotSchema(externalData);
327
+ const normalizedData = transformToBotSchema(externalData)
325
328
 
326
329
  // 3. Persist to table (prevents duplicates)
327
330
  await ResourceTable.upsertRows({
328
331
  rows: [normalizedData],
329
- keyColumn: "id" // Unique identifier
330
- });
332
+ keyColumn: 'id', // Unique identifier
333
+ })
331
334
 
332
335
  // 4. Return normalized data
333
- return normalizedData;
334
- }
335
- });
336
+ return normalizedData
337
+ },
338
+ })
336
339
  ```
337
340
 
338
341
  **Real Example - Shopify: Sync Products**
339
342
 
340
343
  ```typescript
341
- import { Action, actions, z } from "@botpress/runtime";
342
- import { ProductsTable } from "../tables/shopify";
344
+ import { Action, actions, z } from '@botpress/runtime'
345
+ import { ProductsTable } from '../tables/shopify'
343
346
 
344
347
  export default new Action({
345
- name: "syncProduct",
346
- description: "Sync a Shopify product to local database",
348
+ name: 'syncProduct',
349
+ description: 'Sync a Shopify product to local database',
347
350
 
348
351
  input: z.object({
349
- productId: z.string().describe("Shopify product ID"),
350
- includeVariants: z.boolean().default(true)
352
+ productId: z.string().describe('Shopify product ID'),
353
+ includeVariants: z.boolean().default(true),
351
354
  }),
352
355
 
353
356
  output: z.object({
@@ -355,15 +358,15 @@ export default new Action({
355
358
  title: z.string(),
356
359
  price: z.number(),
357
360
  inventory: z.number(),
358
- lastSynced: z.string()
361
+ lastSynced: z.string(),
359
362
  }),
360
363
 
361
364
  async handler({ input }) {
362
365
  // 1. Fetch from Shopify
363
366
  const shopifyProduct = await actions.shopify.getProduct({
364
367
  id: input.productId,
365
- fields: ["id", "title", "variants", "inventory"]
366
- });
368
+ fields: ['id', 'title', 'variants', 'inventory'],
369
+ })
367
370
 
368
371
  // 2. Transform to bot schema
369
372
  const product = {
@@ -371,21 +374,22 @@ export default new Action({
371
374
  title: shopifyProduct.title,
372
375
  price: shopifyProduct.variants[0].price,
373
376
  inventory: shopifyProduct.variants.reduce((sum, v) => sum + v.inventory_quantity, 0),
374
- lastSynced: new Date().toISOString()
375
- };
377
+ lastSynced: new Date().toISOString(),
378
+ }
376
379
 
377
380
  // 3. Upsert to table
378
381
  await ProductsTable.upsertRows({
379
382
  rows: [product],
380
- keyColumn: "id"
381
- });
383
+ keyColumn: 'id',
384
+ })
382
385
 
383
- return product;
384
- }
385
- });
386
+ return product
387
+ },
388
+ })
386
389
  ```
387
390
 
388
391
  **Key Benefits:**
392
+
389
393
  - **Consistency**: All external data follows your bot's schema
390
394
  - **Performance**: Local table queries are faster than API calls
391
395
  - **Reliability**: Works even if integration is temporarily unavailable
@@ -398,23 +402,23 @@ export default new Action({
398
402
  **Real Example - Linear: Update Issue Status**
399
403
 
400
404
  ```typescript
401
- import { Action, actions, z } from "@botpress/runtime";
402
- import { IssuesTable } from "../tables/linear";
405
+ import { Action, actions, z } from '@botpress/runtime'
406
+ import { IssuesTable } from '../tables/linear'
403
407
 
404
408
  export default new Action({
405
- name: "updateIssueStatus",
409
+ name: 'updateIssueStatus',
406
410
 
407
411
  input: z.object({
408
412
  issueId: z.string(),
409
413
  stateId: z.string(),
410
- comment: z.string().optional()
414
+ comment: z.string().optional(),
411
415
  }),
412
416
 
413
417
  output: z.object({
414
418
  id: z.string(),
415
419
  title: z.string(),
416
420
  state: z.string(),
417
- updatedAt: z.string()
421
+ updatedAt: z.string(),
418
422
  }),
419
423
 
420
424
  async handler({ input }) {
@@ -423,29 +427,30 @@ export default new Action({
423
427
  id: input.issueId,
424
428
  stateId: input.stateId,
425
429
  ...(input.comment && {
426
- commentBody: input.comment
427
- })
428
- });
430
+ commentBody: input.comment,
431
+ }),
432
+ })
429
433
 
430
434
  // 2. Transform and sync to table
431
435
  const normalized = {
432
436
  id: issue.id,
433
437
  title: issue.title,
434
438
  state: issue.state.name,
435
- updatedAt: new Date().toISOString()
436
- };
439
+ updatedAt: new Date().toISOString(),
440
+ }
437
441
 
438
442
  await IssuesTable.upsertRows({
439
443
  rows: [normalized],
440
- keyColumn: "id"
441
- });
444
+ keyColumn: 'id',
445
+ })
442
446
 
443
- return normalized;
444
- }
445
- });
447
+ return normalized
448
+ },
449
+ })
446
450
  ```
447
451
 
448
452
  **When to use this pattern:**
453
+
449
454
  - Tracking order fulfillment status
450
455
  - Managing ticket/issue lifecycle
451
456
  - Handling conversation states
@@ -456,53 +461,57 @@ export default new Action({
456
461
  **Core Principles:**
457
462
 
458
463
  ```typescript
459
- import { z } from "@botpress/runtime";
464
+ import { z } from '@botpress/runtime'
460
465
 
461
466
  // 1. Always export both type and schema
462
- export type Product = z.infer<typeof ProductSchema>;
467
+ export type Product = z.infer<typeof ProductSchema>
463
468
  export const ProductSchema = z.object({
464
469
  id: z.string(),
465
470
  name: z.string(),
466
- price: z.number()
467
- });
471
+ price: z.number(),
472
+ })
468
473
 
469
474
  // 2. Use .describe() on every field (helps AI tools)
470
475
  const schema = z.object({
471
- productId: z.string().describe("Unique product identifier"),
472
- price: z.number().describe("Price in cents"),
473
- inStock: z.boolean().describe("Whether product is available")
474
- });
476
+ productId: z.string().describe('Unique product identifier'),
477
+ price: z.number().describe('Price in cents'),
478
+ inStock: z.boolean().describe('Whether product is available'),
479
+ })
475
480
 
476
481
  // 3. ISO strings for dates (NOT z.date())
477
482
  const timeFields = z.object({
478
- createdAt: z.string().describe("Creation date as ISO 8601 string"),
479
- updatedAt: z.string().optional().describe("Last update date")
480
- });
483
+ createdAt: z.string().describe('Creation date as ISO 8601 string'),
484
+ updatedAt: z.string().optional().describe('Last update date'),
485
+ })
481
486
 
482
487
  // 4. Use .optional() for optional fields
483
488
  const optionalFields = z.object({
484
- name: z.string(), // Required
485
- description: z.string().optional(), // Optional
486
- metadata: z.record(z.unknown()).optional()
487
- });
489
+ name: z.string(), // Required
490
+ description: z.string().optional(), // Optional
491
+ metadata: z.record(z.unknown()).optional(),
492
+ })
488
493
 
489
494
  // 5. Use .passthrough() for external API data
490
- const externalData = z.object({
491
- id: z.string(),
492
- // Allow unknown fields from external API
493
- }).passthrough();
495
+ const externalData = z
496
+ .object({
497
+ id: z.string(),
498
+ // Allow unknown fields from external API
499
+ })
500
+ .passthrough()
494
501
 
495
502
  // 6. Define nested objects explicitly
496
503
  const structured = z.object({
497
- product: z.object({ // ✅ Explicit structure
504
+ product: z.object({
505
+ // ✅ Explicit structure
498
506
  id: z.string(),
499
- name: z.string()
507
+ name: z.string(),
500
508
  }),
501
- metadata: z.record(z.unknown()) // ❌ Use only when structure is truly unknown
502
- });
509
+ metadata: z.record(z.unknown()), // ❌ Use only when structure is truly unknown
510
+ })
503
511
  ```
504
512
 
505
513
  **Key Patterns:**
514
+
506
515
  1. **Export both type and schema** - TypeScript type from `z.infer<>`
507
516
  2. **Describe every field** - Helps AI tools and documentation
508
517
  3. **ISO strings for dates** - Use `z.string()` not `z.date()`
@@ -518,70 +527,70 @@ Actions can be converted to AI-callable tools using the `.asTool()` method. This
518
527
  ### Basic Usage
519
528
 
520
529
  ```typescript
521
- import { actions, Conversation } from "@botpress/runtime";
530
+ import { actions, Conversation } from '@botpress/runtime'
522
531
 
523
532
  export default new Conversation({
524
533
  handler: async ({ execute }) => {
525
534
  await execute({
526
- instructions: "Help the user with their request",
535
+ instructions: 'Help the user with their request',
527
536
  tools: [
528
537
  // Convert existing actions to tools
529
538
  actions.fetchUser.asTool(),
530
539
  actions.sendEmail.asTool(),
531
- actions.searchDatabase.asTool()
532
- ]
533
- });
534
- }
535
- });
540
+ actions.searchDatabase.asTool(),
541
+ ],
542
+ })
543
+ },
544
+ })
536
545
  ```
537
546
 
538
547
  ### Tool Patterns: Blocking vs Non-Blocking
539
548
 
540
549
  #### Pattern Comparison
541
550
 
542
- | Pattern | Returns | Execution | Example |
543
- |---------|---------|-----------|---------|
544
- | **Direct Action** | Final result | Synchronous | `fetchUser()` |
545
- | **Workflow Wrapper** | Workflow ID | Asynchronous | `startIndexing()` |
551
+ | Pattern | Returns | Execution | Example |
552
+ | -------------------- | ------------ | ------------ | ----------------- |
553
+ | **Direct Action** | Final result | Synchronous | `fetchUser()` |
554
+ | **Workflow Wrapper** | Workflow ID | Asynchronous | `startIndexing()` |
546
555
 
547
556
  #### 1. Direct Actions
548
557
 
549
558
  Actions that complete and return results immediately:
550
559
 
551
560
  ```typescript
552
- import { Action, z } from "@botpress/runtime";
561
+ import { Action, z } from '@botpress/runtime'
553
562
 
554
563
  export default new Action({
555
- name: "calculateShipping",
556
- description: "Calculate shipping cost for an order",
564
+ name: 'calculateShipping',
565
+ description: 'Calculate shipping cost for an order',
557
566
 
558
567
  input: z.object({
559
568
  weight: z.number(),
560
- destination: z.string()
569
+ destination: z.string(),
561
570
  }),
562
571
 
563
572
  output: z.object({
564
573
  cost: z.number(),
565
- estimatedDays: z.number()
574
+ estimatedDays: z.number(),
566
575
  }),
567
576
 
568
577
  async handler({ input }) {
569
578
  // Business logic that completes immediately
570
- const baseRate = 5.99;
571
- const perKg = 2.50;
572
- const cost = baseRate + (input.weight * perKg);
579
+ const baseRate = 5.99
580
+ const perKg = 2.5
581
+ const cost = baseRate + input.weight * perKg
573
582
 
574
- const estimatedDays = input.destination === "domestic" ? 3 : 7;
583
+ const estimatedDays = input.destination === 'domestic' ? 3 : 7
575
584
 
576
- return { cost, estimatedDays };
577
- }
578
- });
585
+ return { cost, estimatedDays }
586
+ },
587
+ })
579
588
 
580
589
  // Use as tool - AI can call this during conversation
581
590
  await execute({
582
- instructions: "Help the user with shipping",
583
- tools: [actions.calculateShipping.asTool()]
584
- });
591
+ instructions: 'Help the user with shipping',
592
+ tools: [actions.calculateShipping.asTool()],
593
+ })
585
594
  ```
586
595
 
587
596
  #### 2. Workflow Wrappers
@@ -589,69 +598,66 @@ await execute({
589
598
  Actions that start workflows and return workflow ID:
590
599
 
591
600
  ```typescript
592
- import { Action, z } from "@botpress/runtime";
593
- import { DataAnalysisWorkflow } from "../workflows/data-analysis";
601
+ import { Action, z } from '@botpress/runtime'
602
+ import { DataAnalysisWorkflow } from '../workflows/data-analysis'
594
603
 
595
604
  export default new Action({
596
- name: "startDataAnalysis",
597
- description: "Start data analysis workflow",
605
+ name: 'startDataAnalysis',
606
+ description: 'Start data analysis workflow',
598
607
 
599
608
  input: z.object({
600
- datasetId: z.string()
609
+ datasetId: z.string(),
601
610
  }),
602
611
 
603
612
  output: z.object({
604
- workflowId: z.string()
613
+ workflowId: z.string(),
605
614
  }),
606
615
 
607
616
  async handler({ input }) {
608
617
  // Calls workflow.start() - returns immediately
609
618
  const instance = await DataAnalysisWorkflow.start({
610
- datasetId: input.datasetId
611
- });
612
- return { workflowId: instance.id };
613
- }
614
- });
619
+ datasetId: input.datasetId,
620
+ })
621
+ return { workflowId: instance.id }
622
+ },
623
+ })
615
624
 
616
625
  // Companion action to check status
617
626
  export const checkAnalysisStatus = new Action({
618
- name: "checkAnalysisStatus",
619
- description: "Check workflow status",
627
+ name: 'checkAnalysisStatus',
628
+ description: 'Check workflow status',
620
629
 
621
630
  input: z.object({
622
- workflowId: z.string()
631
+ workflowId: z.string(),
623
632
  }),
624
633
 
625
634
  output: z.object({
626
- status: z.string()
635
+ status: z.string(),
627
636
  }),
628
637
 
629
638
  async handler({ input, client }) {
630
- const { workflow } = await client.getWorkflow({ id: input.workflowId });
631
- return { status: workflow.status };
632
- }
633
- });
639
+ const { workflow } = await client.getWorkflow({ id: input.workflowId })
640
+ return { status: workflow.status }
641
+ },
642
+ })
634
643
 
635
644
  // Use both as tools
636
645
  await execute({
637
- instructions: "Help the user",
638
- tools: [
639
- actions.startDataAnalysis.asTool(),
640
- actions.checkAnalysisStatus.asTool()
641
- ]
642
- });
646
+ instructions: 'Help the user',
647
+ tools: [actions.startDataAnalysis.asTool(), actions.checkAnalysisStatus.asTool()],
648
+ })
643
649
  ```
644
650
 
645
651
  ### Custom Tool Conversion
646
652
 
647
653
  ```typescript
648
654
  // Basic conversion
649
- const shippingTool = actions.calculateShipping.asTool();
655
+ const shippingTool = actions.calculateShipping.asTool()
650
656
 
651
657
  // With custom description
652
658
  const analysisTool = actions.startDataAnalysis.asTool({
653
- description: "Analyze dataset and return workflow ID"
654
- });
659
+ description: 'Analyze dataset and return workflow ID',
660
+ })
655
661
  ```
656
662
 
657
663
  > **See Also:** [Exposing Workflows as Tools](./workflows.md#exposing-workflows-as-tools-non-blocking-pattern) for comprehensive workflow wrapper patterns and tracking examples.
@@ -667,50 +673,50 @@ const analysisTool = actions.startDataAnalysis.asTool({
667
673
 
668
674
  ```typescript
669
675
  export default new Action({
670
- name: "fetchUserProfile",
671
- description: "Fetches complete user profile with preferences",
676
+ name: 'fetchUserProfile',
677
+ description: 'Fetches complete user profile with preferences',
672
678
 
673
679
  input: z.object({
674
680
  userId: z.string().uuid(), // Validate UUID format
675
- includePreferences: z.boolean().default(false)
681
+ includePreferences: z.boolean().default(false),
676
682
  }),
677
683
 
678
684
  output: z.object({
679
685
  user: z.object({
680
686
  id: z.string(),
681
687
  name: z.string(),
682
- email: z.string().email()
688
+ email: z.string().email(),
683
689
  }),
684
- preferences: z.object({
685
- language: z.string(),
686
- timezone: z.string()
687
- }).optional()
690
+ preferences: z
691
+ .object({
692
+ language: z.string(),
693
+ timezone: z.string(),
694
+ })
695
+ .optional(),
688
696
  }),
689
697
 
690
698
  cached: true, // Cache for performance
691
699
 
692
700
  async handler({ input, client }) {
693
701
  // Validate user exists
694
- const { user } = await client.getUser({ id: input.userId });
702
+ const { user } = await client.getUser({ id: input.userId })
695
703
  if (!user) {
696
- throw new Error(`User ${input.userId} not found`);
704
+ throw new Error(`User ${input.userId} not found`)
697
705
  }
698
706
 
699
707
  // Conditionally fetch preferences
700
- const preferences = input.includePreferences
701
- ? await fetchUserPreferences(input.userId)
702
- : undefined;
708
+ const preferences = input.includePreferences ? await fetchUserPreferences(input.userId) : undefined
703
709
 
704
710
  return {
705
711
  user: {
706
712
  id: user.id,
707
713
  name: user.name,
708
- email: user.tags.email
714
+ email: user.tags.email,
709
715
  },
710
- preferences
711
- };
712
- }
713
- });
716
+ preferences,
717
+ }
718
+ },
719
+ })
714
720
  ```
715
721
 
716
722
  ## Common Patterns
@@ -721,27 +727,27 @@ Combine multiple actions for complex operations:
721
727
 
722
728
  ```typescript
723
729
  export default new Action({
724
- name: "processOrder",
730
+ name: 'processOrder',
725
731
  input: z.object({ orderId: z.string() }),
726
732
  output: z.object({ success: z.boolean() }),
727
733
 
728
734
  async handler({ input }) {
729
735
  // Compose multiple actions
730
- const order = await actions.fetchOrder({ id: input.orderId });
731
- const validated = await actions.validateOrder({ order });
736
+ const order = await actions.fetchOrder({ id: input.orderId })
737
+ const validated = await actions.validateOrder({ order })
732
738
 
733
739
  if (validated.isValid) {
734
740
  await actions.chargePayment({
735
741
  amount: order.total,
736
- customerId: order.customerId
737
- });
738
- await actions.sendConfirmation({ order });
739
- await actions.updateInventory({ items: order.items });
742
+ customerId: order.customerId,
743
+ })
744
+ await actions.sendConfirmation({ order })
745
+ await actions.updateInventory({ items: order.items })
740
746
  }
741
747
 
742
- return { success: validated.isValid };
743
- }
744
- });
748
+ return { success: validated.isValid }
749
+ },
750
+ })
745
751
  ```
746
752
 
747
753
  ### Error Recovery Pattern
@@ -750,33 +756,33 @@ Handle failures gracefully with retries:
750
756
 
751
757
  ```typescript
752
758
  export default new Action({
753
- name: "resilientFetch",
759
+ name: 'resilientFetch',
754
760
  input: z.object({ url: z.string().url() }),
755
761
  output: z.object({ data: z.unknown() }),
756
762
 
757
763
  async handler({ input }) {
758
- const maxRetries = 3;
759
- let lastError;
764
+ const maxRetries = 3
765
+ let lastError
760
766
 
761
767
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
762
768
  try {
763
- const response = await fetch(input.url);
769
+ const response = await fetch(input.url)
764
770
  if (!response.ok) {
765
- throw new Error(`HTTP ${response.status}`);
771
+ throw new Error(`HTTP ${response.status}`)
766
772
  }
767
- return { data: await response.json() };
773
+ return { data: await response.json() }
768
774
  } catch (error) {
769
- lastError = error;
775
+ lastError = error
770
776
  if (attempt < maxRetries) {
771
777
  // Exponential backoff
772
- await new Promise(r => setTimeout(r, 1000 * Math.pow(2, attempt)));
778
+ await new Promise((r) => setTimeout(r, 1000 * Math.pow(2, attempt)))
773
779
  }
774
780
  }
775
781
  }
776
782
 
777
- throw new Error(`Failed after ${maxRetries} attempts: ${lastError.message}`);
778
- }
779
- });
783
+ throw new Error(`Failed after ${maxRetries} attempts: ${lastError.message}`)
784
+ },
785
+ })
780
786
  ```
781
787
 
782
788
  ## Troubleshooting