@botpress/adk 1.19.0-beta.7 → 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/config-writer.d.ts.map +1 -1
- package/dist/agent-project/dependencies-parser.d.ts.map +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/file-watcher.d.ts.map +1 -1
- 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/config/schema.d.ts.map +1 -1
- package/dist/agent0/config/store.d.ts +8 -3
- package/dist/agent0/config/store.d.ts.map +1 -1
- package/dist/agent0/index.js +214 -59
- package/dist/agent0/index.js.map +17 -15
- package/dist/agent0/providers/catalog.d.ts.map +1 -1
- package/dist/agent0/providers/registry.d.ts.map +1 -1
- package/dist/agent0/providers/source.d.ts +8 -3
- package/dist/agent0/providers/source.d.ts.map +1 -1
- package/dist/agent0/runtime/client.d.ts +4 -3
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +7 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/manager.d.ts +2 -3
- package/dist/agent0/runtime/manager.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +10 -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/auth/credentials.d.ts.map +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/service.d.ts.map +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/integration-sync.d.ts +2 -0
- package/dist/bot-generator/integration-sync.d.ts.map +1 -1
- package/dist/bot-generator/interface-sync.d.ts +2 -0
- package/dist/bot-generator/interface-sync.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts +2 -0
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/cognitive/models.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-cli.d.ts.map +1 -1
- package/dist/commands/bp-cli.js +147 -0
- package/dist/commands/bp-cli.js.map +12 -0
- package/dist/commands/bp-dev-command.d.ts +3 -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/bp-dev-worker-env.d.ts +7 -0
- package/dist/commands/bp-dev-worker-env.d.ts.map +1 -0
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/config/manager.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 +9 -6
- 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 +2309 -1697
- package/dist/dependencies/index.js.map +41 -32
- 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 +388 -37
- 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 +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3643 -2345
- package/dist/index.js.map +68 -58
- 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/interfaces/parser.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/secrets/manager.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/test-utils/mock-module.d.ts +29 -0
- package/dist/test-utils/mock-module.d.ts.map +1 -0
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -1
- package/dist/utils/require-chat.d.ts.map +1 -1
- package/dist/utils/source-map-optimizer.d.ts +10 -11
- package/dist/utils/source-map-optimizer.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 +8 -4
- 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,19 +5,19 @@ Access runtime services like the Botpress client and citations manager within yo
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
7
|
```typescript
|
|
8
|
-
import { context } from
|
|
8
|
+
import { context } from '@botpress/runtime'
|
|
9
9
|
|
|
10
10
|
// Get Botpress client
|
|
11
|
-
const client = context.get(
|
|
11
|
+
const client = context.get('client')
|
|
12
12
|
|
|
13
13
|
// Get citations manager
|
|
14
|
-
const citations = context.get(
|
|
14
|
+
const citations = context.get('citations')
|
|
15
15
|
|
|
16
16
|
// Use services
|
|
17
17
|
const { passages } = await client.searchFiles({
|
|
18
|
-
query:
|
|
18
|
+
query: 'search term',
|
|
19
19
|
withContext: true,
|
|
20
|
-
})
|
|
20
|
+
})
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Overview
|
|
@@ -25,6 +25,7 @@ const { passages } = await client.searchFiles({
|
|
|
25
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
26
|
|
|
27
27
|
**Available in:**
|
|
28
|
+
|
|
28
29
|
- Action handlers
|
|
29
30
|
- Tool handlers
|
|
30
31
|
- Workflow handlers
|
|
@@ -40,27 +41,27 @@ These are the context keys you'll commonly use as an ADK developer:
|
|
|
40
41
|
The Botpress API client for your bot. Use this to interact with Botpress services like files, tables, messages, etc.
|
|
41
42
|
|
|
42
43
|
```typescript
|
|
43
|
-
const client = context.get(
|
|
44
|
+
const client = context.get('client')
|
|
44
45
|
|
|
45
46
|
// Search files/knowledge base
|
|
46
47
|
const { passages } = await client.searchFiles({
|
|
47
|
-
query:
|
|
48
|
-
tags: { type:
|
|
49
|
-
withContext: true
|
|
50
|
-
})
|
|
48
|
+
query: 'search query',
|
|
49
|
+
tags: { type: 'knowledge' },
|
|
50
|
+
withContext: true,
|
|
51
|
+
})
|
|
51
52
|
|
|
52
53
|
// Create message
|
|
53
54
|
await client.createMessage({
|
|
54
55
|
conversationId,
|
|
55
|
-
type:
|
|
56
|
-
payload: { text:
|
|
57
|
-
})
|
|
56
|
+
type: 'text',
|
|
57
|
+
payload: { text: 'Hello!' },
|
|
58
|
+
})
|
|
58
59
|
|
|
59
60
|
// Query tables (low-level client API)
|
|
60
61
|
const { rows } = await client.tables.findMany({
|
|
61
|
-
table:
|
|
62
|
-
filter: { email: { eq:
|
|
63
|
-
})
|
|
62
|
+
table: 'users',
|
|
63
|
+
filter: { email: { eq: 'user@example.com' } },
|
|
64
|
+
})
|
|
64
65
|
```
|
|
65
66
|
|
|
66
67
|
> **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.
|
|
@@ -72,17 +73,17 @@ const { rows } = await client.tables.findMany({
|
|
|
72
73
|
Citation manager for tracking sources in AI responses. Essential for RAG implementations.
|
|
73
74
|
|
|
74
75
|
```typescript
|
|
75
|
-
const citations = context.get(
|
|
76
|
+
const citations = context.get('citations')
|
|
76
77
|
|
|
77
78
|
// Register a source
|
|
78
79
|
const { tag } = citations.registerSource({
|
|
79
|
-
url:
|
|
80
|
-
title:
|
|
81
|
-
favicon:
|
|
82
|
-
})
|
|
80
|
+
url: 'https://docs.example.com/page',
|
|
81
|
+
title: 'Documentation Page',
|
|
82
|
+
favicon: 'https://docs.example.com/favicon.ico',
|
|
83
|
+
})
|
|
83
84
|
|
|
84
85
|
// Use in response
|
|
85
|
-
const response = `According to the documentation${tag}, the answer is
|
|
86
|
+
const response = `According to the documentation${tag}, the answer is...`
|
|
86
87
|
```
|
|
87
88
|
|
|
88
89
|
**Type:** `CitationsManager`
|
|
@@ -98,12 +99,12 @@ These keys may or may not be available depending on the handler context. Always
|
|
|
98
99
|
Current user object (available in conversation handlers).
|
|
99
100
|
|
|
100
101
|
```typescript
|
|
101
|
-
const user = context.get(
|
|
102
|
+
const user = context.get('user', { optional: true })
|
|
102
103
|
|
|
103
104
|
if (user) {
|
|
104
|
-
console.log(user.id)
|
|
105
|
-
console.log(user.name)
|
|
106
|
-
console.log(user.tags)
|
|
105
|
+
console.log(user.id)
|
|
106
|
+
console.log(user.name)
|
|
107
|
+
console.log(user.tags)
|
|
107
108
|
}
|
|
108
109
|
```
|
|
109
110
|
|
|
@@ -117,11 +118,11 @@ Current conversation object. Available optionally in Actions, Tools, and Trigger
|
|
|
117
118
|
|
|
118
119
|
```typescript
|
|
119
120
|
// In Actions, Tools, or Triggers — use context.get() with { optional: true }
|
|
120
|
-
const conversation = context.get(
|
|
121
|
+
const conversation = context.get('conversation', { optional: true })
|
|
121
122
|
|
|
122
123
|
if (conversation) {
|
|
123
|
-
console.log(conversation.id)
|
|
124
|
-
console.log(conversation.tags)
|
|
124
|
+
console.log(conversation.id)
|
|
125
|
+
console.log(conversation.tags)
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
// In Conversation handlers — use the handler parameter directly
|
|
@@ -135,10 +136,10 @@ if (conversation) {
|
|
|
135
136
|
Incoming message (when triggered by a message event).
|
|
136
137
|
|
|
137
138
|
```typescript
|
|
138
|
-
const message = context.get(
|
|
139
|
+
const message = context.get('message', { optional: true })
|
|
139
140
|
|
|
140
|
-
if (message?.type ===
|
|
141
|
-
console.log(message.payload.text)
|
|
141
|
+
if (message?.type === 'text') {
|
|
142
|
+
console.log(message.payload.text)
|
|
142
143
|
}
|
|
143
144
|
```
|
|
144
145
|
|
|
@@ -149,11 +150,11 @@ if (message?.type === "text") {
|
|
|
149
150
|
Incoming event (available in trigger handlers).
|
|
150
151
|
|
|
151
152
|
```typescript
|
|
152
|
-
const event = context.get(
|
|
153
|
+
const event = context.get('event', { optional: true })
|
|
153
154
|
|
|
154
155
|
if (event) {
|
|
155
|
-
console.log(`Event type: ${event.type}`)
|
|
156
|
-
console.log(event.payload)
|
|
156
|
+
console.log(`Event type: ${event.type}`)
|
|
157
|
+
console.log(event.payload)
|
|
157
158
|
}
|
|
158
159
|
```
|
|
159
160
|
|
|
@@ -166,11 +167,11 @@ See **[Triggers](./triggers.md)** for event handling examples.
|
|
|
166
167
|
Current workflow instance (available in workflow handlers).
|
|
167
168
|
|
|
168
169
|
```typescript
|
|
169
|
-
const workflow = context.get(
|
|
170
|
+
const workflow = context.get('workflow', { optional: true })
|
|
170
171
|
|
|
171
172
|
if (workflow) {
|
|
172
|
-
console.log(`Workflow ID: ${workflow.id}`)
|
|
173
|
-
console.log(`Conversation ID: ${workflow.conversationId}`)
|
|
173
|
+
console.log(`Workflow ID: ${workflow.id}`)
|
|
174
|
+
console.log(`Conversation ID: ${workflow.conversationId}`)
|
|
174
175
|
}
|
|
175
176
|
```
|
|
176
177
|
|
|
@@ -183,12 +184,12 @@ See **[Workflows](./workflows.md)** for workflow context examples.
|
|
|
183
184
|
Workflow control operations (available in workflow handlers).
|
|
184
185
|
|
|
185
186
|
```typescript
|
|
186
|
-
const control = context.get(
|
|
187
|
+
const control = context.get('workflowControlContext', { optional: true })
|
|
187
188
|
|
|
188
189
|
if (control) {
|
|
189
190
|
// Access workflow controls
|
|
190
|
-
await control.ack()
|
|
191
|
-
control.complete({ result:
|
|
191
|
+
await control.ack()
|
|
192
|
+
control.complete({ result: 'success' })
|
|
192
193
|
}
|
|
193
194
|
```
|
|
194
195
|
|
|
@@ -199,12 +200,12 @@ if (control) {
|
|
|
199
200
|
Chat instance for accessing conversation transcripts (available in conversation handlers).
|
|
200
201
|
|
|
201
202
|
```typescript
|
|
202
|
-
const chat = context.get(
|
|
203
|
+
const chat = context.get('chat', { optional: true })
|
|
203
204
|
|
|
204
205
|
if (chat) {
|
|
205
206
|
// Fetch conversation transcript
|
|
206
|
-
const transcript = await chat.fetchTranscript()
|
|
207
|
-
console.log(`Messages: ${transcript.length}`)
|
|
207
|
+
const transcript = await chat.fetchTranscript()
|
|
208
|
+
console.log(`Messages: ${transcript.length}`)
|
|
208
209
|
}
|
|
209
210
|
```
|
|
210
211
|
|
|
@@ -221,12 +222,12 @@ These are available but less frequently needed:
|
|
|
221
222
|
AI model client for direct LLM operations. Most of the time you'll use `execute()` instead.
|
|
222
223
|
|
|
223
224
|
```typescript
|
|
224
|
-
const cognitive = context.get(
|
|
225
|
+
const cognitive = context.get('cognitive')
|
|
225
226
|
|
|
226
227
|
const response = await cognitive.generateText({
|
|
227
|
-
model:
|
|
228
|
-
messages: [{ role:
|
|
229
|
-
})
|
|
228
|
+
model: 'openai:gpt-4o',
|
|
229
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
230
|
+
})
|
|
230
231
|
```
|
|
231
232
|
|
|
232
233
|
**Type:** `Cognitive`
|
|
@@ -238,11 +239,11 @@ const response = await cognitive.generateText({
|
|
|
238
239
|
Structured logger for the current bot.
|
|
239
240
|
|
|
240
241
|
```typescript
|
|
241
|
-
const logger = context.get(
|
|
242
|
+
const logger = context.get('logger')
|
|
242
243
|
|
|
243
|
-
logger.info(
|
|
244
|
-
logger.error(
|
|
245
|
-
logger.debug(
|
|
244
|
+
logger.info('Processing request')
|
|
245
|
+
logger.error('Failed to process', { error })
|
|
246
|
+
logger.debug('Debug info', { data })
|
|
246
247
|
```
|
|
247
248
|
|
|
248
249
|
**Type:** `BotLogger`
|
|
@@ -252,8 +253,8 @@ logger.debug("Debug info", { data });
|
|
|
252
253
|
Current bot identifier.
|
|
253
254
|
|
|
254
255
|
```typescript
|
|
255
|
-
const botId = context.get(
|
|
256
|
-
console.log(`Running in bot: ${botId}`)
|
|
256
|
+
const botId = context.get('botId')
|
|
257
|
+
console.log(`Running in bot: ${botId}`)
|
|
257
258
|
```
|
|
258
259
|
|
|
259
260
|
**Type:** `string`
|
|
@@ -273,16 +274,16 @@ context.get<T extends keyof BotContext>(
|
|
|
273
274
|
|
|
274
275
|
```typescript
|
|
275
276
|
// Will throw if not available (use for keys that should always exist)
|
|
276
|
-
const client = context.get(
|
|
277
|
-
const citations = context.get(
|
|
277
|
+
const client = context.get('client')
|
|
278
|
+
const citations = context.get('citations')
|
|
278
279
|
```
|
|
279
280
|
|
|
280
281
|
### Optional Keys
|
|
281
282
|
|
|
282
283
|
```typescript
|
|
283
284
|
// Returns null if not available (use for conditional keys)
|
|
284
|
-
const user = context.get(
|
|
285
|
-
const conversation = context.get(
|
|
285
|
+
const user = context.get('user', { optional: true })
|
|
286
|
+
const conversation = context.get('conversation', { optional: true })
|
|
286
287
|
|
|
287
288
|
if (user && conversation) {
|
|
288
289
|
// Both available
|
|
@@ -298,20 +299,20 @@ if (user && conversation) {
|
|
|
298
299
|
```typescript
|
|
299
300
|
export const myAction = new Action({
|
|
300
301
|
async handler({ input }) {
|
|
301
|
-
const client = context.get(
|
|
302
|
-
const user = context.get(
|
|
302
|
+
const client = context.get('client')
|
|
303
|
+
const user = context.get('user', { optional: true })
|
|
303
304
|
|
|
304
305
|
if (user) {
|
|
305
306
|
// Personalized response
|
|
306
|
-
console.log(`Processing for user ${user.id}`)
|
|
307
|
+
console.log(`Processing for user ${user.id}`)
|
|
307
308
|
} else {
|
|
308
309
|
// Generic response
|
|
309
|
-
console.log(
|
|
310
|
+
console.log('Processing without user context')
|
|
310
311
|
}
|
|
311
312
|
|
|
312
|
-
return await client.doSomething()
|
|
313
|
-
}
|
|
314
|
-
})
|
|
313
|
+
return await client.doSomething()
|
|
314
|
+
},
|
|
315
|
+
})
|
|
315
316
|
```
|
|
316
317
|
|
|
317
318
|
### Using Context Across Handler Types
|
|
@@ -320,9 +321,9 @@ The `context.get()` syntax is identical across all handler types (Actions, Tools
|
|
|
320
321
|
|
|
321
322
|
```typescript
|
|
322
323
|
// Same pattern everywhere
|
|
323
|
-
const client = context.get(
|
|
324
|
-
const citations = context.get(
|
|
325
|
-
const user = context.get(
|
|
324
|
+
const client = context.get('client')
|
|
325
|
+
const citations = context.get('citations')
|
|
326
|
+
const user = context.get('user', { optional: true })
|
|
326
327
|
```
|
|
327
328
|
|
|
328
329
|
See individual documentation for handler-specific examples: **[Actions](./actions.md)**, **[Tools](./tools.md)**, **[Workflows](./workflows.md)**, **[Conversations](./conversations.md)**.
|
|
@@ -334,16 +335,16 @@ See individual documentation for handler-specific examples: **[Actions](./action
|
|
|
334
335
|
```typescript
|
|
335
336
|
// ❌ WRONG - Will throw if key doesn't exist
|
|
336
337
|
try {
|
|
337
|
-
const user = context.get(
|
|
338
|
+
const user = context.get('user')
|
|
338
339
|
} catch (error) {
|
|
339
340
|
// Hard to handle gracefully
|
|
340
341
|
}
|
|
341
342
|
|
|
342
343
|
// ✅ CORRECT - Use optional for conditional keys
|
|
343
|
-
const user = context.get(
|
|
344
|
+
const user = context.get('user', { optional: true })
|
|
344
345
|
if (!user) {
|
|
345
|
-
console.log(
|
|
346
|
-
return defaultResponse
|
|
346
|
+
console.log('No user context available')
|
|
347
|
+
return defaultResponse
|
|
347
348
|
}
|
|
348
349
|
```
|
|
349
350
|
|
|
@@ -353,8 +354,8 @@ Keys like `client`, `citations` should always be available. If they're not, it's
|
|
|
353
354
|
|
|
354
355
|
```typescript
|
|
355
356
|
// These should never throw in normal operation
|
|
356
|
-
const client = context.get(
|
|
357
|
-
const citations = context.get(
|
|
357
|
+
const client = context.get('client')
|
|
358
|
+
const citations = context.get('citations')
|
|
358
359
|
```
|
|
359
360
|
|
|
360
361
|
## Best Practices
|
|
@@ -362,12 +363,13 @@ const citations = context.get("citations");
|
|
|
362
363
|
### 1. Know Which Keys Are Always Available
|
|
363
364
|
|
|
364
365
|
**Always available:**
|
|
366
|
+
|
|
365
367
|
- `client` - Botpress API client
|
|
366
368
|
- `citations` - Citation manager
|
|
367
369
|
- `cognitive` - AI model client
|
|
368
370
|
- `logger` - Structured logger
|
|
369
371
|
- `botId` - Current bot ID
|
|
370
|
-
**Conditionally available (use `{ optional: true }`):**
|
|
372
|
+
**Conditionally available (use `{ optional: true }`):**
|
|
371
373
|
- `user` - Only in conversation context
|
|
372
374
|
- `conversation` - Only in conversation context
|
|
373
375
|
- `message` - Only when triggered by message
|
|
@@ -382,30 +384,30 @@ const citations = context.get("citations");
|
|
|
382
384
|
// ✅ GOOD - Get context when needed
|
|
383
385
|
export const myAction = new Action({
|
|
384
386
|
async handler({ input }) {
|
|
385
|
-
const client = context.get(
|
|
386
|
-
const result = await client.searchFiles({ query: input.query })
|
|
387
|
-
return result
|
|
388
|
-
}
|
|
389
|
-
})
|
|
387
|
+
const client = context.get('client') // Get when you need it
|
|
388
|
+
const result = await client.searchFiles({ query: input.query })
|
|
389
|
+
return result
|
|
390
|
+
},
|
|
391
|
+
})
|
|
390
392
|
|
|
391
393
|
// ❌ BAD - Don't store context globally
|
|
392
|
-
let globalClient
|
|
394
|
+
let globalClient // Don't do this!
|
|
393
395
|
|
|
394
396
|
export const badAction = new Action({
|
|
395
397
|
async handler({ input }) {
|
|
396
|
-
globalClient = context.get(
|
|
397
|
-
}
|
|
398
|
-
})
|
|
398
|
+
globalClient = context.get('client') // Context might change
|
|
399
|
+
},
|
|
400
|
+
})
|
|
399
401
|
```
|
|
400
402
|
|
|
401
403
|
### 3. Use TypeScript's Type Safety
|
|
402
404
|
|
|
403
405
|
```typescript
|
|
404
406
|
// TypeScript knows the types
|
|
405
|
-
const client = context.get(
|
|
407
|
+
const client = context.get('client')
|
|
406
408
|
// client is typed as BotSpecificClient<TBot>
|
|
407
409
|
|
|
408
|
-
const user = context.get(
|
|
410
|
+
const user = context.get('user', { optional: true })
|
|
409
411
|
// user is typed as User | null
|
|
410
412
|
```
|
|
411
413
|
|
|
@@ -414,10 +416,10 @@ const user = context.get("user", { optional: true });
|
|
|
414
416
|
For `bot`, `user`, and `adk`, you can use direct imports instead of `context.get()`:
|
|
415
417
|
|
|
416
418
|
```typescript
|
|
417
|
-
import { bot, user, adk } from
|
|
419
|
+
import { bot, user, adk } from '@botpress/runtime'
|
|
418
420
|
|
|
419
|
-
bot.state.version
|
|
420
|
-
user.state.preferredLanguage
|
|
421
|
+
bot.state.version // Instead of context.get("bot").state
|
|
422
|
+
user.state.preferredLanguage // Instead of context.get("user").state
|
|
421
423
|
```
|
|
422
424
|
|
|
423
425
|
See **[Actions](./actions.md)** for comparison of both approaches.
|
|
@@ -428,26 +430,28 @@ See **[Actions](./actions.md)** for comparison of both approaches.
|
|
|
428
430
|
|
|
429
431
|
```typescript
|
|
430
432
|
// Error: Context key "user" not found
|
|
431
|
-
const user = context.get(
|
|
433
|
+
const user = context.get('user')
|
|
432
434
|
```
|
|
433
435
|
|
|
434
436
|
**Solution:** Use `{ optional: true }` for conditional keys:
|
|
437
|
+
|
|
435
438
|
```typescript
|
|
436
|
-
const user = context.get(
|
|
439
|
+
const user = context.get('user', { optional: true })
|
|
437
440
|
```
|
|
438
441
|
|
|
439
442
|
### "Cannot read property of undefined"
|
|
440
443
|
|
|
441
444
|
```typescript
|
|
442
445
|
// Error: Cannot read property 'id' of undefined
|
|
443
|
-
const userId = context.get(
|
|
446
|
+
const userId = context.get('user', { optional: true }).id
|
|
444
447
|
```
|
|
445
448
|
|
|
446
449
|
**Solution:** Check if key exists before accessing properties:
|
|
450
|
+
|
|
447
451
|
```typescript
|
|
448
|
-
const user = context.get(
|
|
452
|
+
const user = context.get('user', { optional: true })
|
|
449
453
|
if (user) {
|
|
450
|
-
const userId = user.id
|
|
454
|
+
const userId = user.id
|
|
451
455
|
}
|
|
452
456
|
```
|
|
453
457
|
|