@botpress/adk-cli 1.19.0-beta.4 → 1.19.0-beta.6

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 (87) hide show
  1. package/{dist/index-a3ZL0_Jr-q145h35p.js → assets/ui-dist/assets/index-BC_iUF2d.js} +2 -2
  2. package/assets/ui-dist/assets/index-BxpvDT_K.css +1 -0
  3. package/{dist/index-BESZeTO5-2rpmcefa.js → assets/ui-dist/assets/index-C7gAokRv.js} +2 -2
  4. package/assets/ui-dist/assets/{index-B3b7PPgV.js → index-exyr_Djl.js} +424 -424
  5. package/assets/ui-dist/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  6. package/assets/ui-dist/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  7. package/assets/ui-dist/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  8. package/assets/ui-dist/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  9. package/assets/ui-dist/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  10. package/assets/ui-dist/index.html +2 -2
  11. package/dist/{README-wjb7z7f0.md → README-824wa4jj.md} +1 -1
  12. package/dist/SKILL-75ym6tcj.md +257 -0
  13. package/dist/SKILL-chnwzmt1.md +548 -0
  14. package/dist/SKILL-d4bs53y3.md +244 -0
  15. package/dist/SKILL-h4b2f1n9.md +114 -0
  16. package/dist/SKILL-hbw5nt95.md +111 -0
  17. package/dist/actions-h7hxxvxr.md +823 -0
  18. package/dist/adk-build-emhwd0tg.md +39 -0
  19. package/dist/adk-debug-yrrdtpmb.md +23 -0
  20. package/dist/adk-dev-console-7z9rtjpy.md +17 -0
  21. package/dist/adk-document-ras6zzzh.md +68 -0
  22. package/dist/adk-eval-vx76dwq0.md +17 -0
  23. package/dist/adk-explain-fcsaw852.md +22 -0
  24. package/dist/adk-init-9kmxmbbe.md +30 -0
  25. package/dist/adk-ship-dybzn884.md +29 -0
  26. package/dist/adk-test-xq67savs.md +27 -0
  27. package/dist/adk-validate-1p4skv4m.md +31 -0
  28. package/dist/advanced-patterns-z86m9h1a.md +669 -0
  29. package/dist/agent-config-1aqvkrgf.md +450 -0
  30. package/dist/agent-steps-zj4c1n9t.md +115 -0
  31. package/dist/assets-q7jt8r2q.md +237 -0
  32. package/dist/autonomous-execution-fymc12e5.md +747 -0
  33. package/dist/cli-c31e06yr.md +1334 -0
  34. package/dist/cli.js +4241 -6449
  35. package/dist/commands.json +25 -4
  36. package/dist/common-failures-ht29w2db.md +231 -0
  37. package/dist/component-registry-bbpw0see.md +43 -0
  38. package/dist/context-api-760cvh0h.md +461 -0
  39. package/dist/conversation-analysis-8ka4nrm4.md +420 -0
  40. package/dist/conversation-lifecycle-4seqqjc1.md +311 -0
  41. package/dist/conversations-gwfvxaee.md +1111 -0
  42. package/dist/custom-components-y5wdgpey.md +167 -0
  43. package/dist/debug-workflow-vz84q80v.md +239 -0
  44. package/dist/desk-k54ktvsd.md +852 -0
  45. package/dist/doc-standards-ck6ax2jd.md +124 -0
  46. package/dist/eval-format-7n9brja4.md +354 -0
  47. package/dist/evals-y1zcr1mc.md +11 -0
  48. package/dist/explain-config-1yaq3zzd.md +424 -0
  49. package/dist/files-dzt0wxn3.md +918 -0
  50. package/dist/{index-3t354nbw.html → index-0qts7wfk.html} +2 -2
  51. package/{assets/ui-dist/assets/index-a3ZL0_Jr.js → dist/index-BC_iUF2d-3h9mqazs.js} +2 -2
  52. package/dist/index-BxpvDT_K-62864175.css +1 -0
  53. package/{assets/ui-dist/assets/index-BESZeTO5.js → dist/index-C7gAokRv-zr7dzkba.js} +2 -2
  54. package/dist/{index-B3b7PPgV-zetkb01w.js → index-exyr_Djl-ksys08wc.js} +424 -424
  55. package/dist/integration-actions-xang7tma.md +659 -0
  56. package/dist/integrations-k5ss07f4.md +266 -0
  57. package/dist/interfaces-6t0bpxs4.md +97 -0
  58. package/dist/jetbrains-mono-cyrillic-wght-normal-D73BlboJ-6vpq1jfh.woff2 +0 -0
  59. package/dist/jetbrains-mono-greek-wght-normal-Bw9x6K1M-jv5dqe09.woff2 +0 -0
  60. package/dist/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a-h2ysfc3f.woff2 +0 -0
  61. package/dist/jetbrains-mono-latin-wght-normal-B9CIFXIH-hj2e42wt.woff2 +0 -0
  62. package/dist/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq-wttk1pwp.woff2 +0 -0
  63. package/dist/knowledge-bases-20rg8p5c.md +456 -0
  64. package/dist/llm-debugging-76ng8rzm.md +209 -0
  65. package/dist/mcp-server-n1asyzhv.md +112 -0
  66. package/dist/messages-gkkg0b54.md +769 -0
  67. package/dist/model-configuration-f273kgd0.md +201 -0
  68. package/dist/multi-agent-dashboard-1mdfjdts.md +70 -0
  69. package/dist/pages-xn18xn73.md +273 -0
  70. package/dist/patterns-mistakes-5vb99dhf.md +469 -0
  71. package/dist/plugins-ttnx8f49.md +280 -0
  72. package/dist/tables-x45t36dd.md +1136 -0
  73. package/dist/tags-46td3qrg.md +516 -0
  74. package/dist/test-patterns-hj47w4nc.md +355 -0
  75. package/dist/testing-workflow-2vkp932f.md +225 -0
  76. package/dist/tools-wk7bq24z.md +581 -0
  77. package/dist/trace-summarization-hdyx1c2e.md +313 -0
  78. package/dist/traces-and-logs-f2kjfh19.md +203 -0
  79. package/dist/triggers-4j2cc86x.md +719 -0
  80. package/dist/ui-server-entry.js +1839 -791
  81. package/dist/workflow-steps-mrdrf1c5.md +851 -0
  82. package/dist/workflows-gadx3s69.md +1408 -0
  83. package/dist/zai-agent-reference-e6644aad.md +454 -0
  84. package/dist/zai-complete-guide-mnna5d6f.md +1408 -0
  85. package/package.json +4 -4
  86. package/assets/ui-dist/assets/index-DIFGtVmI.css +0 -1
  87. package/dist/index-DIFGtVmI-d4dhjg97.css +0 -1
@@ -0,0 +1,461 @@
1
+ # Context API Reference
2
+
3
+ Access runtime services like the Botpress client and citations manager within your ADK handlers.
4
+
5
+ ## Quick Start
6
+
7
+ ```typescript
8
+ import { context } from "@botpress/runtime";
9
+
10
+ // Get Botpress client
11
+ const client = context.get("client");
12
+
13
+ // Get citations manager
14
+ const citations = context.get("citations");
15
+
16
+ // Use services
17
+ const { passages } = await client.searchFiles({
18
+ query: "search term",
19
+ withContext: true,
20
+ });
21
+ ```
22
+
23
+ ## Overview
24
+
25
+ The `context` API provides access to runtime services within your ADK handlers (actions, tools, workflows, conversations, triggers). The ADK automatically sets up context for you - you just need to call `context.get()` to access services.
26
+
27
+ **Available in:**
28
+ - Action handlers
29
+ - Tool handlers
30
+ - Workflow handlers
31
+ - Conversation handlers
32
+ - Trigger handlers
33
+
34
+ ## Primary Context Keys
35
+
36
+ These are the context keys you'll commonly use as an ADK developer:
37
+
38
+ ### client
39
+
40
+ The Botpress API client for your bot. Use this to interact with Botpress services like files, tables, messages, etc.
41
+
42
+ ```typescript
43
+ const client = context.get("client");
44
+
45
+ // Search files/knowledge base
46
+ const { passages } = await client.searchFiles({
47
+ query: "search query",
48
+ tags: { type: "knowledge" },
49
+ withContext: true
50
+ });
51
+
52
+ // Create message
53
+ await client.createMessage({
54
+ conversationId,
55
+ type: "text",
56
+ payload: { text: "Hello!" }
57
+ });
58
+
59
+ // Query tables (low-level client API)
60
+ const { rows } = await client.tables.findMany({
61
+ table: "users",
62
+ filter: { email: { eq: "user@example.com" } }
63
+ });
64
+ ```
65
+
66
+ > **Note:** For table operations, prefer using the direct Table class methods (e.g., `UsersTable.findRows()`) over `client.tables.*`. The Table class provides better type safety and a cleaner API. See [Tables documentation](./tables.md) for details.
67
+
68
+ **Type:** `BotSpecificClient<TBot>`
69
+
70
+ ### citations
71
+
72
+ Citation manager for tracking sources in AI responses. Essential for RAG implementations.
73
+
74
+ ```typescript
75
+ const citations = context.get("citations");
76
+
77
+ // Register a source
78
+ const { tag } = citations.registerSource({
79
+ url: "https://docs.example.com/page",
80
+ title: "Documentation Page",
81
+ favicon: "https://docs.example.com/favicon.ico"
82
+ });
83
+
84
+ // Use in response
85
+ const response = `According to the documentation${tag}, the answer is...`;
86
+ ```
87
+
88
+ **Type:** `CitationsManager`
89
+
90
+ See **[Knowledge Bases](./knowledge-bases.md)** for complete citation examples with RAG.
91
+
92
+ ## Optional Context Keys
93
+
94
+ These keys may or may not be available depending on the handler context. Always use `{ optional: true }` when accessing them.
95
+
96
+ ### user
97
+
98
+ Current user object (available in conversation handlers).
99
+
100
+ ```typescript
101
+ const user = context.get("user", { optional: true });
102
+
103
+ if (user) {
104
+ console.log(user.id);
105
+ console.log(user.name);
106
+ console.log(user.tags);
107
+ }
108
+ ```
109
+
110
+ **Type:** `User | null`
111
+
112
+ ### conversation
113
+
114
+ Current conversation object. Available optionally in Actions, Tools, and Triggers when they are invoked within a conversation context.
115
+
116
+ > **Note:** In `Conversation` handlers, the `conversation` object is already provided as a handler parameter — use that directly instead of `context.get("conversation")`.
117
+
118
+ ```typescript
119
+ // In Actions, Tools, or Triggers — use context.get() with { optional: true }
120
+ const conversation = context.get("conversation", { optional: true });
121
+
122
+ if (conversation) {
123
+ console.log(conversation.id);
124
+ console.log(conversation.tags);
125
+ }
126
+
127
+ // In Conversation handlers — use the handler parameter directly
128
+ // async handler({ conversation }) { ... }
129
+ ```
130
+
131
+ **Type:** `Conversation | null`
132
+
133
+ ### message
134
+
135
+ Incoming message (when triggered by a message event).
136
+
137
+ ```typescript
138
+ const message = context.get("message", { optional: true });
139
+
140
+ if (message?.type === "text") {
141
+ console.log(message.payload.text);
142
+ }
143
+ ```
144
+
145
+ **Type:** `AnyIncomingMessage<TBot> | null`
146
+
147
+ ### event
148
+
149
+ Incoming event (available in trigger handlers).
150
+
151
+ ```typescript
152
+ const event = context.get("event", { optional: true });
153
+
154
+ if (event) {
155
+ console.log(`Event type: ${event.type}`);
156
+ console.log(event.payload);
157
+ }
158
+ ```
159
+
160
+ **Type:** `AnyIncomingEvent<TBot> | null`
161
+
162
+ See **[Triggers](./triggers.md)** for event handling examples.
163
+
164
+ ### workflow
165
+
166
+ Current workflow instance (available in workflow handlers).
167
+
168
+ ```typescript
169
+ const workflow = context.get("workflow", { optional: true });
170
+
171
+ if (workflow) {
172
+ console.log(`Workflow ID: ${workflow.id}`);
173
+ console.log(`Conversation ID: ${workflow.conversationId}`);
174
+ }
175
+ ```
176
+
177
+ **Type:** `Workflow | null`
178
+
179
+ See **[Workflows](./workflows.md)** for workflow context examples.
180
+
181
+ ### workflowControlContext
182
+
183
+ Workflow control operations (available in workflow handlers).
184
+
185
+ ```typescript
186
+ const control = context.get("workflowControlContext", { optional: true });
187
+
188
+ if (control) {
189
+ // Access workflow controls
190
+ await control.ack();
191
+ control.complete({ result: "success" });
192
+ }
193
+ ```
194
+
195
+ **Type:** `WorkflowControlContext | null`
196
+
197
+ ### chat
198
+
199
+ Chat instance for accessing conversation transcripts (available in conversation handlers).
200
+
201
+ ```typescript
202
+ const chat = context.get("chat", { optional: true });
203
+
204
+ if (chat) {
205
+ // Fetch conversation transcript
206
+ const transcript = await chat.fetchTranscript();
207
+ console.log(`Messages: ${transcript.length}`);
208
+ }
209
+ ```
210
+
211
+ **Type:** `BotpressChat | null`
212
+
213
+ See **[Conversations](./conversations.md)** for chat context examples.
214
+
215
+ ## Less Common Keys
216
+
217
+ These are available but less frequently needed:
218
+
219
+ ### cognitive
220
+
221
+ AI model client for direct LLM operations. Most of the time you'll use `execute()` instead.
222
+
223
+ ```typescript
224
+ const cognitive = context.get("cognitive");
225
+
226
+ const response = await cognitive.generateText({
227
+ model: "openai:gpt-4o",
228
+ messages: [{ role: "user", content: "Hello" }]
229
+ });
230
+ ```
231
+
232
+ **Type:** `Cognitive`
233
+
234
+ **Note:** Usually you'll use `execute()` for AI interactions rather than calling cognitive directly.
235
+
236
+ ### logger
237
+
238
+ Structured logger for the current bot.
239
+
240
+ ```typescript
241
+ const logger = context.get("logger");
242
+
243
+ logger.info("Processing request");
244
+ logger.error("Failed to process", { error });
245
+ logger.debug("Debug info", { data });
246
+ ```
247
+
248
+ **Type:** `BotLogger`
249
+
250
+ ### botId
251
+
252
+ Current bot identifier.
253
+
254
+ ```typescript
255
+ const botId = context.get("botId");
256
+ console.log(`Running in bot: ${botId}`);
257
+ ```
258
+
259
+ **Type:** `string`
260
+
261
+ ## Using context.get()
262
+
263
+ ### Basic Syntax
264
+
265
+ ```typescript
266
+ context.get<T extends keyof BotContext>(
267
+ key: T,
268
+ opts?: { optional?: boolean }
269
+ ): Required<BotContext>[T]
270
+ ```
271
+
272
+ ### Required Keys
273
+
274
+ ```typescript
275
+ // Will throw if not available (use for keys that should always exist)
276
+ const client = context.get("client");
277
+ const citations = context.get("citations");
278
+ ```
279
+
280
+ ### Optional Keys
281
+
282
+ ```typescript
283
+ // Returns null if not available (use for conditional keys)
284
+ const user = context.get("user", { optional: true });
285
+ const conversation = context.get("conversation", { optional: true });
286
+
287
+ if (user && conversation) {
288
+ // Both available
289
+ } else {
290
+ // Handle missing context
291
+ }
292
+ ```
293
+
294
+ ## Common Patterns
295
+
296
+ ### Conditional User Context
297
+
298
+ ```typescript
299
+ export const myAction = new Action({
300
+ async handler({ input }) {
301
+ const client = context.get("client");
302
+ const user = context.get("user", { optional: true });
303
+
304
+ if (user) {
305
+ // Personalized response
306
+ console.log(`Processing for user ${user.id}`);
307
+ } else {
308
+ // Generic response
309
+ console.log("Processing without user context");
310
+ }
311
+
312
+ return await client.doSomething();
313
+ }
314
+ });
315
+ ```
316
+
317
+ ### Using Context Across Handler Types
318
+
319
+ The `context.get()` syntax is identical across all handler types (Actions, Tools, Workflows, Conversations, Triggers):
320
+
321
+ ```typescript
322
+ // Same pattern everywhere
323
+ const client = context.get("client");
324
+ const citations = context.get("citations");
325
+ const user = context.get("user", { optional: true });
326
+ ```
327
+
328
+ See individual documentation for handler-specific examples: **[Actions](./actions.md)**, **[Tools](./tools.md)**, **[Workflows](./workflows.md)**, **[Conversations](./conversations.md)**.
329
+
330
+ ## Error Handling
331
+
332
+ ### Required Keys
333
+
334
+ ```typescript
335
+ // ❌ WRONG - Will throw if key doesn't exist
336
+ try {
337
+ const user = context.get("user");
338
+ } catch (error) {
339
+ // Hard to handle gracefully
340
+ }
341
+
342
+ // ✅ CORRECT - Use optional for conditional keys
343
+ const user = context.get("user", { optional: true });
344
+ if (!user) {
345
+ console.log("No user context available");
346
+ return defaultResponse;
347
+ }
348
+ ```
349
+
350
+ ### Always-Available Keys
351
+
352
+ Keys like `client`, `citations` should always be available. If they're not, it's a framework error:
353
+
354
+ ```typescript
355
+ // These should never throw in normal operation
356
+ const client = context.get("client");
357
+ const citations = context.get("citations");
358
+ ```
359
+
360
+ ## Best Practices
361
+
362
+ ### 1. Know Which Keys Are Always Available
363
+
364
+ **Always available:**
365
+ - `client` - Botpress API client
366
+ - `citations` - Citation manager
367
+ - `cognitive` - AI model client
368
+ - `logger` - Structured logger
369
+ - `botId` - Current bot ID
370
+ **Conditionally available (use `{ optional: true }`):**
371
+ - `user` - Only in conversation context
372
+ - `conversation` - Only in conversation context
373
+ - `message` - Only when triggered by message
374
+ - `event` - Only in trigger handlers
375
+ - `workflow` - Only in workflow handlers
376
+ - `workflowControlContext` - Only in workflow handlers
377
+ - `chat` - Only in conversation handlers
378
+
379
+ ### 2. Access Context at Call Time
380
+
381
+ ```typescript
382
+ // ✅ GOOD - Get context when needed
383
+ export const myAction = new Action({
384
+ async handler({ input }) {
385
+ const client = context.get("client"); // Get when you need it
386
+ const result = await client.searchFiles({ query: input.query });
387
+ return result;
388
+ }
389
+ });
390
+
391
+ // ❌ BAD - Don't store context globally
392
+ let globalClient; // Don't do this!
393
+
394
+ export const badAction = new Action({
395
+ async handler({ input }) {
396
+ globalClient = context.get("client"); // Context might change
397
+ }
398
+ });
399
+ ```
400
+
401
+ ### 3. Use TypeScript's Type Safety
402
+
403
+ ```typescript
404
+ // TypeScript knows the types
405
+ const client = context.get("client");
406
+ // client is typed as BotSpecificClient<TBot>
407
+
408
+ const user = context.get("user", { optional: true });
409
+ // user is typed as User | null
410
+ ```
411
+
412
+ ## Direct Imports vs Context API
413
+
414
+ For `bot`, `user`, and `adk`, you can use direct imports instead of `context.get()`:
415
+
416
+ ```typescript
417
+ import { bot, user, adk } from "@botpress/runtime";
418
+
419
+ bot.state.version; // Instead of context.get("bot").state
420
+ user.state.preferredLanguage; // Instead of context.get("user").state
421
+ ```
422
+
423
+ See **[Actions](./actions.md)** for comparison of both approaches.
424
+
425
+ ## Troubleshooting
426
+
427
+ ### "Context key not found" Error
428
+
429
+ ```typescript
430
+ // Error: Context key "user" not found
431
+ const user = context.get("user");
432
+ ```
433
+
434
+ **Solution:** Use `{ optional: true }` for conditional keys:
435
+ ```typescript
436
+ const user = context.get("user", { optional: true });
437
+ ```
438
+
439
+ ### "Cannot read property of undefined"
440
+
441
+ ```typescript
442
+ // Error: Cannot read property 'id' of undefined
443
+ const userId = context.get("user", { optional: true }).id;
444
+ ```
445
+
446
+ **Solution:** Check if key exists before accessing properties:
447
+ ```typescript
448
+ const user = context.get("user", { optional: true });
449
+ if (user) {
450
+ const userId = user.id;
451
+ }
452
+ ```
453
+
454
+ ## See Also
455
+
456
+ - **[Actions](./actions.md)** - Using context in actions
457
+ - **[Tools](./tools.md)** - Using context in tools
458
+ - **[Integration Actions](./integration-actions.md)** - Using the client for integration actions
459
+ - **[Workflows](./workflows.md)** - Workflow context
460
+ - **[Conversations](./conversations.md)** - Conversation context
461
+ - **[Knowledge Bases](./knowledge-bases.md)** - Using citations for RAG