@botpress/adk 1.19.0-beta.2 → 1.19.0-beta.4
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 +1 -1
- package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent0/capabilities/commands/adk-build.md +39 -0
- package/dist/agent0/capabilities/commands/adk-debug.md +23 -0
- package/dist/agent0/capabilities/commands/adk-dev-console.md +17 -0
- package/dist/agent0/capabilities/commands/adk-document.md +68 -0
- package/dist/agent0/capabilities/commands/adk-eval.md +17 -0
- package/dist/agent0/capabilities/commands/adk-explain.md +22 -0
- package/dist/agent0/capabilities/commands/adk-init.md +30 -0
- package/dist/agent0/capabilities/commands/adk-ship.md +29 -0
- package/dist/agent0/capabilities/commands/adk-test.md +27 -0
- package/dist/agent0/capabilities/commands/adk-validate.md +31 -0
- package/dist/agent0/capabilities/skills/adk/SKILL.md +548 -0
- package/dist/agent0/capabilities/skills/adk/references/actions.md +823 -0
- package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +669 -0
- package/dist/agent0/capabilities/skills/adk/references/agent-config.md +450 -0
- package/dist/agent0/capabilities/skills/adk/references/assets.md +237 -0
- package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +747 -0
- package/dist/agent0/capabilities/skills/adk/references/cli.md +1334 -0
- package/dist/agent0/capabilities/skills/adk/references/context-api.md +461 -0
- package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +311 -0
- package/dist/agent0/capabilities/skills/adk/references/conversations.md +1111 -0
- package/dist/agent0/capabilities/skills/adk/references/custom-components.md +167 -0
- package/dist/agent0/capabilities/skills/adk/references/desk.md +852 -0
- package/dist/agent0/capabilities/skills/adk/references/evals.md +11 -0
- package/dist/agent0/capabilities/skills/adk/references/explain-config.md +424 -0
- package/dist/agent0/capabilities/skills/adk/references/files.md +918 -0
- package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +659 -0
- package/dist/agent0/capabilities/skills/adk/references/integrations.md +266 -0
- package/dist/agent0/capabilities/skills/adk/references/interfaces.md +97 -0
- package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +456 -0
- package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +112 -0
- package/dist/agent0/capabilities/skills/adk/references/messages.md +769 -0
- package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +201 -0
- package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +469 -0
- package/dist/agent0/capabilities/skills/adk/references/plugins.md +280 -0
- package/dist/agent0/capabilities/skills/adk/references/tables.md +1136 -0
- package/dist/agent0/capabilities/skills/adk/references/tags.md +516 -0
- package/dist/agent0/capabilities/skills/adk/references/tools.md +581 -0
- package/dist/agent0/capabilities/skills/adk/references/triggers.md +719 -0
- package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +851 -0
- package/dist/agent0/capabilities/skills/adk/references/workflows.md +1408 -0
- package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +454 -0
- package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +1408 -0
- package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +257 -0
- package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +231 -0
- package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +420 -0
- package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +239 -0
- package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +209 -0
- package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +313 -0
- package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +203 -0
- package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +111 -0
- package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +115 -0
- package/dist/agent0/capabilities/skills/adk-dev-console/references/component-registry.md +43 -0
- package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +70 -0
- package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +273 -0
- package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +114 -0
- package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +124 -0
- package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +244 -0
- package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +354 -0
- package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +355 -0
- package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +225 -0
- package/dist/agent0/config/index.d.ts +5 -0
- package/dist/agent0/config/index.d.ts.map +1 -0
- package/dist/agent0/config/paths.d.ts +12 -0
- package/dist/agent0/config/paths.d.ts.map +1 -0
- package/dist/agent0/config/schema.d.ts +171 -0
- package/dist/agent0/config/schema.d.ts.map +1 -0
- package/dist/agent0/config/secrets.d.ts +4 -0
- package/dist/agent0/config/secrets.d.ts.map +1 -0
- package/dist/agent0/config/store.d.ts +21 -0
- package/dist/agent0/config/store.d.ts.map +1 -0
- package/dist/agent0/index.d.ts +6 -0
- package/dist/agent0/index.d.ts.map +1 -0
- package/dist/agent0/index.js +3226 -0
- package/dist/agent0/index.js.map +27 -0
- package/dist/agent0/providers/catalog.d.ts +189 -0
- package/dist/agent0/providers/catalog.d.ts.map +1 -0
- package/dist/agent0/providers/index.d.ts +4 -0
- package/dist/agent0/providers/index.d.ts.map +1 -0
- package/dist/agent0/providers/registry.d.ts +32 -0
- package/dist/agent0/providers/registry.d.ts.map +1 -0
- package/dist/agent0/providers/source.d.ts +100 -0
- package/dist/agent0/providers/source.d.ts.map +1 -0
- package/dist/agent0/runtime/client.d.ts +50 -0
- package/dist/agent0/runtime/client.d.ts.map +1 -0
- package/dist/agent0/runtime/engine.d.ts +74 -0
- package/dist/agent0/runtime/engine.d.ts.map +1 -0
- package/dist/agent0/runtime/index.d.ts +7 -0
- package/dist/agent0/runtime/index.d.ts.map +1 -0
- package/dist/agent0/runtime/manager.d.ts +82 -0
- package/dist/agent0/runtime/manager.d.ts.map +1 -0
- package/dist/agent0/runtime/permissions.d.ts +9 -0
- package/dist/agent0/runtime/permissions.d.ts.map +1 -0
- package/dist/agent0/runtime/process.d.ts +43 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -0
- package/dist/agent0/runtime/project-discovery.d.ts +5 -0
- package/dist/agent0/runtime/project-discovery.d.ts.map +1 -0
- package/dist/agent0/types.d.ts +447 -0
- package/dist/agent0/types.d.ts.map +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/cognitive/models.d.ts +32 -0
- package/dist/cognitive/models.d.ts.map +1 -0
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +21 -0
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -0
- package/dist/commands/index.d.ts +0 -5
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/dependencies/dependency-manager.d.ts +0 -1
- package/dist/dependencies/dependency-manager.d.ts.map +1 -1
- package/dist/dependencies/errors.d.ts +1 -1
- package/dist/dependencies/errors.d.ts.map +1 -1
- package/dist/dependencies/index.d.ts +0 -2
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +125 -149
- package/dist/dependencies/index.js.map +11 -13
- package/dist/dependencies/migration.d.ts +0 -2
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +0 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts +0 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
- package/dist/dependencies/types.d.ts +1 -2
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/generators/tests.d.ts.map +1 -1
- package/dist/index.js +501 -998
- package/dist/index.js.map +16 -20
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/runner/supervise-child.d.ts +24 -0
- package/dist/runner/supervise-child.d.ts.map +1 -0
- package/dist/templates/blank/package.json +0 -1
- package/dist/templates/template.config.json +10 -9
- package/package.json +12 -8
- package/dist/commands/copilot-config-reader.d.ts +0 -3
- package/dist/commands/copilot-config-reader.d.ts.map +0 -1
- package/dist/commands/copilot-config.d.ts +0 -42
- package/dist/commands/copilot-config.d.ts.map +0 -1
- package/dist/commands/copilot-server.d.ts +0 -29
- package/dist/commands/copilot-server.d.ts.map +0 -1
- package/dist/commands/opencode-config.d.ts +0 -30
- package/dist/commands/opencode-config.d.ts.map +0 -1
- package/dist/dependencies/env-substitution.d.ts +0 -3
- package/dist/dependencies/env-substitution.d.ts.map +0 -1
- package/dist/dependencies/secrets-rewriter.d.ts +0 -25
- package/dist/dependencies/secrets-rewriter.d.ts.map +0 -1
- package/dist/templates/blank/dependencies.dev.lock.json +0 -6
- package/dist/templates/botpress-desk/dependencies.dev.lock.json +0 -6
- package/dist/templates/crm-enrichment/dependencies.dev.lock.json +0 -6
- package/dist/templates/hello-world/dependencies.dev.lock.json +0 -6
- package/dist/templates/knowledge-assistant/dependencies.dev.lock.json +0 -6
- package/dist/templates/slack-triage/dependencies.dev.lock.json +0 -6
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
Configure your bot's behavior, integrations, dependencies, and global state through the unified `agent.config.ts` file.
|
|
4
|
+
|
|
5
|
+
## agent.config.ts
|
|
6
|
+
|
|
7
|
+
The main configuration file defines your bot's core settings, AI models, dependencies, and state schemas.
|
|
8
|
+
|
|
9
|
+
### Configuration Example
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { defineConfig, z } from "@botpress/runtime";
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
name: "customer-support-bot",
|
|
16
|
+
description: "Customer support assistant with knowledge base",
|
|
17
|
+
|
|
18
|
+
// AI Model Configuration
|
|
19
|
+
defaultModels: {
|
|
20
|
+
autonomous: "openai:gpt-4o", // For execute() function
|
|
21
|
+
zai: "openai:gpt-4o-mini", // For zai operations
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// User State Schema
|
|
25
|
+
user: {
|
|
26
|
+
state: z.object({
|
|
27
|
+
preferredLanguage: z.enum(["en", "es", "fr", "de"]).default("en"),
|
|
28
|
+
timezone: z.string().default("UTC"),
|
|
29
|
+
name: z.string().optional(),
|
|
30
|
+
email: z.string().email().optional(),
|
|
31
|
+
notificationsEnabled: z.boolean().default(true),
|
|
32
|
+
accountTier: z.enum(["free", "pro", "enterprise"]).default("free"),
|
|
33
|
+
metadata: z.object({}).passthrough().default({}),
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// Bot Global State Schema
|
|
38
|
+
bot: {
|
|
39
|
+
state: z.object({
|
|
40
|
+
version: z.number().default(1),
|
|
41
|
+
maintenanceMode: z.boolean().default(false),
|
|
42
|
+
|
|
43
|
+
// Feature flags
|
|
44
|
+
features: z.object({
|
|
45
|
+
advancedSearch: z.boolean().default(false),
|
|
46
|
+
multiLanguage: z.boolean().default(true),
|
|
47
|
+
}).default({}),
|
|
48
|
+
|
|
49
|
+
// Analytics
|
|
50
|
+
totalConversations: z.number().default(0),
|
|
51
|
+
totalUsers: z.number().default(0),
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
// Integrations are managed via lock files (dependencies.dev.lock.json / dependencies.prod.lock.json)
|
|
56
|
+
// Use `adk integrations add/remove/configure` to manage them — see integrations.md
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Additional Configuration Fields
|
|
61
|
+
|
|
62
|
+
#### Tags
|
|
63
|
+
|
|
64
|
+
Tags are key-value pairs for categorizing entities. All entities (`user`, `bot`, `conversation`, `message`, `workflow`) support tags. See **[Tags](./tags.md)** for complete documentation.
|
|
65
|
+
|
|
66
|
+
#### Bot Configuration Schema
|
|
67
|
+
|
|
68
|
+
Define a custom configuration schema for bot-level settings accessible via the Context API:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
export default defineConfig({
|
|
72
|
+
name: "my-bot",
|
|
73
|
+
|
|
74
|
+
configuration: {
|
|
75
|
+
schema: z.object({
|
|
76
|
+
maxRetries: z.number().default(3),
|
|
77
|
+
apiEndpoint: z.string(),
|
|
78
|
+
featureFlags: z.object({
|
|
79
|
+
enableBetaFeatures: z.boolean().default(false),
|
|
80
|
+
}),
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Access via direct import from `@botpress/runtime`:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { configuration } from "@botpress/runtime";
|
|
90
|
+
|
|
91
|
+
if (configuration.featureFlags.enableBetaFeatures) {
|
|
92
|
+
// Use beta features
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
See **[Context API](./context-api.md)** for details on accessing other runtime values.
|
|
97
|
+
|
|
98
|
+
### Model Configuration
|
|
99
|
+
|
|
100
|
+
**Default Models:**
|
|
101
|
+
|
|
102
|
+
If you don't specify `defaultModels`, the ADK uses these defaults:
|
|
103
|
+
- `zai`: `"openai:gpt-4.1-2025-04-14"`
|
|
104
|
+
- `autonomous`: `"openai:gpt-4.1-mini-2025-04-14"`
|
|
105
|
+
|
|
106
|
+
**Available Models:**
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// OpenAI
|
|
110
|
+
"openai:gpt-4o"
|
|
111
|
+
"openai:gpt-4o-mini"
|
|
112
|
+
"openai:gpt-4-turbo"
|
|
113
|
+
"openai:gpt-4.1-2025-04-14"
|
|
114
|
+
"openai:gpt-4.1-mini-2025-04-14"
|
|
115
|
+
|
|
116
|
+
// Anthropic
|
|
117
|
+
"anthropic:claude-3-5-sonnet"
|
|
118
|
+
"anthropic:claude-3-opus"
|
|
119
|
+
"anthropic:claude-3-haiku"
|
|
120
|
+
|
|
121
|
+
// Google
|
|
122
|
+
"google:gemini-1.5-pro"
|
|
123
|
+
"google:gemini-1.5-flash"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Model Fallback Arrays:**
|
|
127
|
+
|
|
128
|
+
You can specify multiple models as fallbacks:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
defaultModels: {
|
|
132
|
+
autonomous: [
|
|
133
|
+
"openai:gpt-4o",
|
|
134
|
+
"anthropic:claude-3-5-sonnet",
|
|
135
|
+
"openai:gpt-4o-mini"
|
|
136
|
+
],
|
|
137
|
+
zai: "openai:gpt-4o-mini"
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Accessing Configuration
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { bot, user } from "@botpress/runtime";
|
|
145
|
+
|
|
146
|
+
// In any handler (action, workflow, conversation)
|
|
147
|
+
|
|
148
|
+
// Access bot state
|
|
149
|
+
const version = bot.state.version;
|
|
150
|
+
const maintenanceMode = bot.state.maintenanceMode;
|
|
151
|
+
|
|
152
|
+
// Modify bot state
|
|
153
|
+
bot.state.totalConversations += 1;
|
|
154
|
+
bot.state.features.advancedSearch = true;
|
|
155
|
+
|
|
156
|
+
// Access user state
|
|
157
|
+
const language = user.state.preferredLanguage;
|
|
158
|
+
const tier = user.state.accountTier;
|
|
159
|
+
|
|
160
|
+
// Modify user state
|
|
161
|
+
user.state.lastActiveDate = new Date();
|
|
162
|
+
user.state.metadata.lastQuery = "product pricing";
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Dependencies (Integrations, Plugins, Interfaces)
|
|
166
|
+
|
|
167
|
+
Integration state lives in per-environment lock files at the project root, not in `agent.config.ts`:
|
|
168
|
+
|
|
169
|
+
- `dependencies.dev.lock.json` — development environment
|
|
170
|
+
- `dependencies.prod.lock.json` — production environment
|
|
171
|
+
|
|
172
|
+
Cloud is the source of truth. Lock files are local reflections refreshed after every mutation. Never edit lock files by hand.
|
|
173
|
+
|
|
174
|
+
> **Migration:** Projects with a legacy `dependencies` block in `agent.config.ts` are auto-migrated to lock files on the first CLI command.
|
|
175
|
+
|
|
176
|
+
### Managing Dependencies
|
|
177
|
+
|
|
178
|
+
Use the `adk integrations` CLI subcommands. See **[CLI Reference](./cli.md)** and **[Integrations](./integrations.md)** for full details:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
adk integrations search <query> # Search for integrations
|
|
182
|
+
adk integrations add <name>@<version> # Add integration
|
|
183
|
+
adk integrations configure <alias> --set key=value # Configure
|
|
184
|
+
adk integrations enable <alias> # Enable
|
|
185
|
+
adk integrations remove <alias> # Remove
|
|
186
|
+
adk integrations upgrade [alias] # Upgrade
|
|
187
|
+
adk integrations list # List installed
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Using Integration Actions
|
|
191
|
+
|
|
192
|
+
See **[Integration Actions](./integration-actions.md)** for calling integration functionality from your code.
|
|
193
|
+
|
|
194
|
+
## Environment Variables
|
|
195
|
+
|
|
196
|
+
### .env File
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Bot Configuration
|
|
200
|
+
BOT_NAME=customer-support-bot
|
|
201
|
+
NODE_ENV=development
|
|
202
|
+
|
|
203
|
+
# API Keys
|
|
204
|
+
OPENAI_API_KEY=sk-...
|
|
205
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
206
|
+
|
|
207
|
+
# Integration Tokens
|
|
208
|
+
SLACK_BOT_TOKEN=xoxb-...
|
|
209
|
+
LINEAR_API_KEY=lin_api_...
|
|
210
|
+
|
|
211
|
+
# ADK Development (CLI-specific)
|
|
212
|
+
ADK_DEV_PORT=3000 # Bot port (default: 3000)
|
|
213
|
+
ADK_CONSOLE_PORT=3001 # UI console port (default: 3001)
|
|
214
|
+
DEBUG=adk:* # Enable ADK debug logs
|
|
215
|
+
|
|
216
|
+
# Feature Flags (optional)
|
|
217
|
+
ENABLE_ADVANCED_SEARCH=true
|
|
218
|
+
|
|
219
|
+
# External Services (optional)
|
|
220
|
+
WEBHOOK_URL=https://api.example.com/webhooks
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Accessing Environment Variables
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
// In configuration
|
|
227
|
+
export default defineConfig({
|
|
228
|
+
name: process.env.BOT_NAME || "my-bot",
|
|
229
|
+
|
|
230
|
+
defaultModels: {
|
|
231
|
+
autonomous: process.env.AI_MODEL || "openai:gpt-4o",
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// In handlers
|
|
236
|
+
export const myAction = new Action({
|
|
237
|
+
async handler({ input }) {
|
|
238
|
+
const apiKey = process.env.EXTERNAL_API_KEY;
|
|
239
|
+
|
|
240
|
+
if (!apiKey) {
|
|
241
|
+
throw new Error("EXTERNAL_API_KEY not configured");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Use the API key
|
|
245
|
+
const response = await fetch("https://api.example.com", {
|
|
246
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## State Management Patterns
|
|
253
|
+
|
|
254
|
+
### User State Patterns
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
// Progressive profile building
|
|
258
|
+
export const Chat = new Conversation({
|
|
259
|
+
async handler({ message, conversation, execute }) {
|
|
260
|
+
// Collect user info progressively
|
|
261
|
+
if (!user.state.name && message?.type === "text") {
|
|
262
|
+
user.state.name = extractName(message.payload.text);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!user.state.email) {
|
|
266
|
+
// Ask for email if needed
|
|
267
|
+
await conversation.send({
|
|
268
|
+
type: "text",
|
|
269
|
+
payload: { text: "What's your email address?" },
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Use preferences
|
|
274
|
+
const language = user.state.preferredLanguage;
|
|
275
|
+
await execute({
|
|
276
|
+
instructions: `Respond in ${language}`,
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Bot State Patterns
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
export const Chat = new Conversation({
|
|
286
|
+
async handler({ conversation }) {
|
|
287
|
+
// Feature flag checking
|
|
288
|
+
if (bot.state.features.advancedSearch) {
|
|
289
|
+
// Use advanced search
|
|
290
|
+
const results = await advancedSearch(query);
|
|
291
|
+
} else {
|
|
292
|
+
// Use basic search
|
|
293
|
+
const results = await basicSearch(query);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Maintenance mode
|
|
297
|
+
if (bot.state.maintenanceMode) {
|
|
298
|
+
await conversation.send({
|
|
299
|
+
type: "text",
|
|
300
|
+
payload: {
|
|
301
|
+
text: "The bot is currently under maintenance. Please try again later.",
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Business hours check (example)
|
|
308
|
+
const supportHours = "9:00 AM to 5:00 PM EST";
|
|
309
|
+
await conversation.send({
|
|
310
|
+
type: "text",
|
|
311
|
+
payload: { text: `Our support hours are ${supportHours}` },
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## Best Practices
|
|
318
|
+
|
|
319
|
+
### 1. Use Environment Variables for Secrets
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
// ❌ Bad - hardcoded secrets
|
|
323
|
+
config: {
|
|
324
|
+
apiKey: "sk-abc123def456";
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ✅ Good - environment variable
|
|
328
|
+
config: {
|
|
329
|
+
apiKey: process.env.OPENAI_API_KEY;
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 2. Validate Configuration
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
export default defineConfig({
|
|
337
|
+
name: validateBotName(process.env.BOT_NAME),
|
|
338
|
+
|
|
339
|
+
user: {
|
|
340
|
+
state: z.object({
|
|
341
|
+
// Use strict validation
|
|
342
|
+
email: z.string().email(),
|
|
343
|
+
age: z.number().int().min(0).max(150),
|
|
344
|
+
}),
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### 3. Provide Defaults
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
user: {
|
|
353
|
+
state: z.object({
|
|
354
|
+
// Always provide sensible defaults
|
|
355
|
+
language: z.string().default("en"),
|
|
356
|
+
notifications: z.boolean().default(true),
|
|
357
|
+
theme: z.enum(["light", "dark"]).default("light"),
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### 4. Document State Schema
|
|
363
|
+
|
|
364
|
+
```typescript
|
|
365
|
+
bot: {
|
|
366
|
+
state: z.object({
|
|
367
|
+
/**
|
|
368
|
+
* Current version of the bot configuration
|
|
369
|
+
* Increment when making breaking changes
|
|
370
|
+
*/
|
|
371
|
+
version: z.number().default(1),
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Feature flags for gradual rollout
|
|
375
|
+
* @example { "newUI": true, "betaFeatures": false }
|
|
376
|
+
*/
|
|
377
|
+
features: z.record(z.boolean()).default({}),
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### 5. Separate Concerns
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
// Separate configuration by domain
|
|
386
|
+
const userConfig = {
|
|
387
|
+
state: userStateSchema,
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const botConfig = {
|
|
391
|
+
state: botStateSchema,
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
const integrationConfig = {
|
|
395
|
+
slack: slackConfig,
|
|
396
|
+
discord: discordConfig,
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export default defineConfig({
|
|
400
|
+
...baseConfig,
|
|
401
|
+
user: userConfig,
|
|
402
|
+
bot: botConfig,
|
|
403
|
+
});
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## Project Files
|
|
407
|
+
|
|
408
|
+
### agent.json
|
|
409
|
+
|
|
410
|
+
The `agent.json` file stores bot and workspace IDs for deployment. This file is automatically created by `adk link` or `adk dev`.
|
|
411
|
+
|
|
412
|
+
```json
|
|
413
|
+
{
|
|
414
|
+
"botId": "bot_abc123",
|
|
415
|
+
"workspaceId": "ws_xyz789",
|
|
416
|
+
"devId": "bot_dev_123"
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
**Fields:**
|
|
421
|
+
|
|
422
|
+
- `botId` - Production bot ID (used by `adk deploy`)
|
|
423
|
+
- `workspaceId` - Workspace ID
|
|
424
|
+
- `devId` - Development bot ID (used by `adk dev`)
|
|
425
|
+
|
|
426
|
+
**Important:**
|
|
427
|
+
|
|
428
|
+
- Add `agent.json` to `.gitignore` if you do not want environment-specific IDs committed
|
|
429
|
+
- Each developer/environment can have different IDs
|
|
430
|
+
- Created automatically by `adk link` or `adk dev`
|
|
431
|
+
- Current scaffolds do not add `agent.json` to `.gitignore` automatically
|
|
432
|
+
|
|
433
|
+
### package.json
|
|
434
|
+
|
|
435
|
+
Standard Node.js package file with ADK-specific scripts.
|
|
436
|
+
|
|
437
|
+
```json
|
|
438
|
+
{
|
|
439
|
+
"scripts": {
|
|
440
|
+
"dev": "adk dev",
|
|
441
|
+
"build": "adk build",
|
|
442
|
+
"deploy": "adk deploy"
|
|
443
|
+
},
|
|
444
|
+
"dependencies": {
|
|
445
|
+
"@botpress/runtime": "workspace:*"
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
See **[CLI Reference](./cli.md)** for complete command documentation.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Assets
|
|
2
|
+
|
|
3
|
+
Assets are static files (images, documents, media) that ship with your agent. Place files in the `assets/` directory at the project root, and they get synced to Botpress Cloud with permanent URLs accessible at runtime via the global `assets` object.
|
|
4
|
+
|
|
5
|
+
## Basic Concepts
|
|
6
|
+
|
|
7
|
+
### What are Assets?
|
|
8
|
+
|
|
9
|
+
- **Static file storage**: Ship images, PDFs, stylesheets, or any file alongside your agent
|
|
10
|
+
- **Permanent URLs**: Each asset gets a CDN-backed URL after sync
|
|
11
|
+
- **Auto-typed**: TypeScript paths are generated so `assets.get()` autocompletes
|
|
12
|
+
- **Sync-aware**: Runtime warns when assets are stale or never synced
|
|
13
|
+
- **Content-hashed**: Changes are detected via SHA-256 hashing
|
|
14
|
+
|
|
15
|
+
### File Location
|
|
16
|
+
|
|
17
|
+
- **Location**: `assets/` directory at the project root (not inside `src/`)
|
|
18
|
+
- **Subdirectories supported**: `assets/images/logo.png` → referenced as `"images/logo.png"`
|
|
19
|
+
- **Generated files**: `.adk/assets.d.ts` (types) and `.adk/assets-runtime.ts` (metadata)
|
|
20
|
+
|
|
21
|
+
### Supported File Types
|
|
22
|
+
|
|
23
|
+
Images, documents, media, and more — MIME type is auto-detected from the extension:
|
|
24
|
+
|
|
25
|
+
| Category | Extensions |
|
|
26
|
+
| ---------- | ---------------------------------------------- |
|
|
27
|
+
| Images | `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`, `.webp` |
|
|
28
|
+
| Documents | `.pdf`, `.txt`, `.md`, `.html` |
|
|
29
|
+
| Styles | `.css` |
|
|
30
|
+
| Data | `.js`, `.json`, `.xml` |
|
|
31
|
+
| Video | `.mp4`, `.webm` |
|
|
32
|
+
| Audio | `.mp3`, `.wav`, `.ogg` |
|
|
33
|
+
| Archives | `.zip` |
|
|
34
|
+
|
|
35
|
+
Unrecognized extensions default to `application/octet-stream`.
|
|
36
|
+
|
|
37
|
+
## Project Structure
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
/ # Project root
|
|
41
|
+
├── assets/ # ← Asset files live here
|
|
42
|
+
│ ├── logo.png
|
|
43
|
+
│ ├── onboarding.pdf
|
|
44
|
+
│ └── images/
|
|
45
|
+
│ └── header.webp
|
|
46
|
+
├── src/
|
|
47
|
+
│ └── ...
|
|
48
|
+
├── .adk/
|
|
49
|
+
│ ├── assets.d.ts # Auto-generated types
|
|
50
|
+
│ ├── assets-runtime.ts # Auto-generated metadata
|
|
51
|
+
│ └── assets-cache.json # Sync state cache
|
|
52
|
+
└── agent.config.ts
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Using Assets at Runtime
|
|
56
|
+
|
|
57
|
+
The global `assets` object is available in any action, tool, workflow, or conversation handler.
|
|
58
|
+
|
|
59
|
+
### Get an Asset
|
|
60
|
+
|
|
61
|
+
`assets.get()` is async and throws an `Error` if the path does not match any known asset.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const logo = await assets.get("logo.png");
|
|
65
|
+
console.log(logo.url); // CDN URL
|
|
66
|
+
console.log(logo.mime); // "image/png"
|
|
67
|
+
console.log(logo.size); // bytes
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### List All Assets
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const all = assets.list();
|
|
74
|
+
for (const asset of all) {
|
|
75
|
+
console.log(`${asset.path}: ${asset.url}`);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Check Sync Status
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const status = assets.getSyncStatus();
|
|
83
|
+
if (!status.synced) {
|
|
84
|
+
console.warn("Unsynced assets:", status.neverSynced);
|
|
85
|
+
console.warn("Stale assets:", status.stale);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Asset Properties
|
|
90
|
+
|
|
91
|
+
Each `Asset` object has these fields:
|
|
92
|
+
|
|
93
|
+
| Field | Type | Description |
|
|
94
|
+
| ----------- | -------- | ---------------------------------- |
|
|
95
|
+
| `url` | `string` | Permanent CDN URL |
|
|
96
|
+
| `path` | `string` | Relative path (e.g., `"logo.png"`) |
|
|
97
|
+
| `name` | `string` | Filename |
|
|
98
|
+
| `size` | `number` | File size in bytes |
|
|
99
|
+
| `mime` | `string` | MIME type |
|
|
100
|
+
| `hash` | `string` | SHA-256 content hash |
|
|
101
|
+
| `fileId` | `string` | Unique file ID in Botpress |
|
|
102
|
+
| `createdAt` | `string` | ISO timestamp |
|
|
103
|
+
| `updatedAt` | `string` | ISO timestamp |
|
|
104
|
+
|
|
105
|
+
## CLI Commands
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Sync local assets to Botpress Cloud
|
|
109
|
+
adk assets sync
|
|
110
|
+
|
|
111
|
+
# Dry run — see what would change without uploading
|
|
112
|
+
adk assets sync --dry-run
|
|
113
|
+
|
|
114
|
+
# Force re-upload all assets
|
|
115
|
+
adk assets sync --force
|
|
116
|
+
|
|
117
|
+
# Auto-confirm sync without prompts
|
|
118
|
+
adk assets sync --yes
|
|
119
|
+
|
|
120
|
+
# List assets (local, remote, or both)
|
|
121
|
+
adk assets list
|
|
122
|
+
adk assets list --local
|
|
123
|
+
adk assets list --remote
|
|
124
|
+
adk assets list --format json
|
|
125
|
+
|
|
126
|
+
# Check sync status
|
|
127
|
+
adk assets status
|
|
128
|
+
adk assets status --format json
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Assets are also synced automatically during `adk deploy`.
|
|
132
|
+
|
|
133
|
+
## Sync Lifecycle
|
|
134
|
+
|
|
135
|
+
1. Local files in `assets/` are hashed (SHA-256)
|
|
136
|
+
2. Hashes are compared against the remote versions in Botpress Cloud
|
|
137
|
+
3. A sync plan is computed: create / update / delete
|
|
138
|
+
4. Files are uploaded with metadata tags (`type: "asset"`, `adk: "true"`, `path`, `hash`)
|
|
139
|
+
5. Cache is updated in `.adk/assets-cache.json`
|
|
140
|
+
6. TypeScript types and runtime metadata are regenerated
|
|
141
|
+
|
|
142
|
+
### Sync States
|
|
143
|
+
|
|
144
|
+
| State | Meaning |
|
|
145
|
+
| -------------- | --------------------------------------------- |
|
|
146
|
+
| **Up to date** | Local and remote hashes match |
|
|
147
|
+
| **Stale** | Local file changed since last sync |
|
|
148
|
+
| **Never synced** | File exists locally but was never uploaded |
|
|
149
|
+
|
|
150
|
+
The runtime emits a console warning the first time you access a stale or never-synced asset.
|
|
151
|
+
|
|
152
|
+
## Practical Examples
|
|
153
|
+
|
|
154
|
+
### Send an Image in a Conversation
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { Conversation } from "@botpress/runtime";
|
|
158
|
+
|
|
159
|
+
export default new Conversation({
|
|
160
|
+
channel: "webchat",
|
|
161
|
+
async handler({ conversation }) {
|
|
162
|
+
const logo = await assets.get("logo.png");
|
|
163
|
+
await conversation.send({
|
|
164
|
+
type: "image",
|
|
165
|
+
payload: { imageUrl: logo.url },
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Use an Asset URL in a Tool Response
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { Autonomous } from "@botpress/runtime";
|
|
175
|
+
|
|
176
|
+
export const getBranding = new Autonomous.Tool({
|
|
177
|
+
description: "Returns branding assets",
|
|
178
|
+
handler: async () => {
|
|
179
|
+
const logo = await assets.get("logo.png");
|
|
180
|
+
const header = await assets.get("images/header.webp");
|
|
181
|
+
return {
|
|
182
|
+
logoUrl: logo.url,
|
|
183
|
+
headerUrl: header.url,
|
|
184
|
+
};
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Check Asset Health in an Action
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { Action, z } from "@botpress/runtime";
|
|
193
|
+
|
|
194
|
+
export const checkAssets = new Action({
|
|
195
|
+
name: "checkAssets",
|
|
196
|
+
input: {},
|
|
197
|
+
output: { synced: z.boolean(), issues: z.array(z.string()) },
|
|
198
|
+
async handler() {
|
|
199
|
+
const status = assets.getSyncStatus();
|
|
200
|
+
return {
|
|
201
|
+
synced: status.synced,
|
|
202
|
+
issues: [
|
|
203
|
+
...status.neverSynced.map((p) => `Never synced: ${p}`),
|
|
204
|
+
...status.stale.map((p) => `Stale: ${p}`),
|
|
205
|
+
],
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Common Mistakes
|
|
212
|
+
|
|
213
|
+
### Putting assets inside `src/`
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
# ❌ Wrong — assets/ must be at the project root
|
|
217
|
+
src/assets/logo.png
|
|
218
|
+
|
|
219
|
+
# ✅ Correct
|
|
220
|
+
assets/logo.png
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Forgetting to sync before deploy
|
|
224
|
+
|
|
225
|
+
Assets with placeholder URLs will not be accessible at runtime. Always run `adk assets sync` or `adk deploy` (which syncs automatically) before going live.
|
|
226
|
+
|
|
227
|
+
### Referencing assets by absolute path
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// ❌ Wrong
|
|
231
|
+
await assets.get("/assets/logo.png");
|
|
232
|
+
await assets.get("assets/logo.png");
|
|
233
|
+
|
|
234
|
+
// ✅ Correct — use the path relative to assets/
|
|
235
|
+
await assets.get("logo.png");
|
|
236
|
+
await assets.get("images/header.webp");
|
|
237
|
+
```
|