@botpress/adk 1.19.0-beta.9 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-init/agent-project-generator.d.ts +5 -1
- package/dist/agent-init/agent-project-generator.d.ts.map +1 -1
- package/dist/agent-project/agent-project.d.ts +3 -3
- package/dist/agent-project/agent-project.d.ts.map +1 -1
- package/dist/agent-project/agent-resolver.d.ts.map +1 -1
- package/dist/agent-project/config-writer.d.ts +1 -1
- package/dist/agent-project/dependency-state-to-dependencies.d.ts +11 -0
- package/dist/agent-project/dependency-state-to-dependencies.d.ts.map +1 -0
- package/dist/agent-project/types.d.ts +9 -4
- package/dist/agent-project/types.d.ts.map +1 -1
- package/dist/agent0/capabilities/commands/adk-build.md +6 -5
- package/dist/agent0/capabilities/commands/adk-debug.md +1 -1
- package/dist/agent0/capabilities/commands/adk-dev-console.md +1 -1
- package/dist/agent0/capabilities/commands/adk-document.md +10 -2
- package/dist/agent0/capabilities/commands/adk-eval.md +1 -1
- package/dist/agent0/capabilities/commands/adk-explain.md +2 -2
- package/dist/agent0/capabilities/commands/adk-init.md +2 -2
- package/dist/agent0/capabilities/commands/adk-ship.md +1 -1
- package/dist/agent0/capabilities/commands/adk-test.md +3 -3
- package/dist/agent0/capabilities/commands/adk-validate.md +3 -3
- package/dist/agent0/capabilities/skills/adk/SKILL.md +21 -21
- package/dist/agent0/capabilities/skills/adk/references/actions.md +245 -239
- package/dist/agent0/capabilities/skills/adk/references/advanced-patterns.md +185 -218
- package/dist/agent0/capabilities/skills/adk/references/agent-config.md +74 -71
- package/dist/agent0/capabilities/skills/adk/references/assets.md +45 -48
- package/dist/agent0/capabilities/skills/adk/references/autonomous-execution.md +40 -46
- package/dist/agent0/capabilities/skills/adk/references/cli.md +17 -7
- package/dist/agent0/capabilities/skills/adk/references/context-api.md +98 -94
- package/dist/agent0/capabilities/skills/adk/references/conversation-lifecycle.md +65 -62
- package/dist/agent0/capabilities/skills/adk/references/conversations.md +395 -385
- package/dist/agent0/capabilities/skills/adk/references/custom-components.md +1 -1
- package/dist/agent0/capabilities/skills/adk/references/desk.md +236 -234
- package/dist/agent0/capabilities/skills/adk/references/explain-config.md +54 -37
- package/dist/agent0/capabilities/skills/adk/references/files.md +301 -306
- package/dist/agent0/capabilities/skills/adk/references/integration-actions.md +211 -214
- package/dist/agent0/capabilities/skills/adk/references/integrations.md +33 -31
- package/dist/agent0/capabilities/skills/adk/references/interfaces.md +13 -12
- package/dist/agent0/capabilities/skills/adk/references/knowledge-bases.md +98 -111
- package/dist/agent0/capabilities/skills/adk/references/mcp-server.md +6 -0
- package/dist/agent0/capabilities/skills/adk/references/messages.md +280 -256
- package/dist/agent0/capabilities/skills/adk/references/model-configuration.md +52 -49
- package/dist/agent0/capabilities/skills/adk/references/patterns-mistakes.md +102 -101
- package/dist/agent0/capabilities/skills/adk/references/plugins.md +15 -15
- package/dist/agent0/capabilities/skills/adk/references/tables.md +204 -210
- package/dist/agent0/capabilities/skills/adk/references/tags.md +141 -143
- package/dist/agent0/capabilities/skills/adk/references/tools.md +191 -199
- package/dist/agent0/capabilities/skills/adk/references/triggers.md +331 -336
- package/dist/agent0/capabilities/skills/adk/references/workflow-steps.md +132 -96
- package/dist/agent0/capabilities/skills/adk/references/workflows.md +479 -464
- package/dist/agent0/capabilities/skills/adk/references/zai-agent-reference.md +127 -129
- package/dist/agent0/capabilities/skills/adk/references/zai-complete-guide.md +255 -276
- package/dist/agent0/capabilities/skills/adk-debugger/SKILL.md +21 -17
- package/dist/agent0/capabilities/skills/adk-debugger/references/common-failures.md +25 -25
- package/dist/agent0/capabilities/skills/adk-debugger/references/conversation-analysis.md +49 -41
- package/dist/agent0/capabilities/skills/adk-debugger/references/debug-workflow.md +20 -14
- package/dist/agent0/capabilities/skills/adk-debugger/references/llm-debugging.md +13 -13
- package/dist/agent0/capabilities/skills/adk-debugger/references/trace-summarization.md +18 -18
- package/dist/agent0/capabilities/skills/adk-debugger/references/traces-and-logs.md +67 -67
- package/dist/agent0/capabilities/skills/adk-dev-console/SKILL.md +36 -36
- package/dist/agent0/capabilities/skills/adk-dev-console/references/agent-steps.md +14 -6
- package/dist/agent0/capabilities/skills/adk-dev-console/references/multi-agent-dashboard.md +13 -13
- package/dist/agent0/capabilities/skills/adk-dev-console/references/pages.md +18 -0
- package/dist/agent0/capabilities/skills/adk-docs/SKILL.md +13 -13
- package/dist/agent0/capabilities/skills/adk-docs/references/doc-standards.md +15 -0
- package/dist/agent0/capabilities/skills/adk-evals/SKILL.md +29 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/eval-format.md +31 -23
- package/dist/agent0/capabilities/skills/adk-evals/references/test-patterns.md +25 -36
- package/dist/agent0/capabilities/skills/adk-evals/references/testing-workflow.md +6 -4
- package/dist/agent0/index.js +41 -19
- package/dist/agent0/index.js.map +7 -7
- package/dist/agent0/runtime/client.d.ts +2 -0
- package/dist/agent0/runtime/client.d.ts.map +1 -1
- package/dist/agent0/runtime/engine.d.ts +2 -1
- package/dist/agent0/runtime/engine.d.ts.map +1 -1
- package/dist/agent0/runtime/process.d.ts +1 -0
- package/dist/agent0/runtime/process.d.ts.map +1 -1
- package/dist/assets/manager.d.ts +3 -0
- package/dist/assets/manager.d.ts.map +1 -1
- package/dist/auth/credentials.d.ts +1 -1
- package/dist/bot-generator/generator.d.ts +22 -0
- package/dist/bot-generator/generator.d.ts.map +1 -1
- package/dist/bot-generator/plugin-sync.d.ts.map +1 -1
- package/dist/commands/base-command.d.ts +1 -0
- package/dist/commands/base-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-command.d.ts +1 -1
- package/dist/commands/bp-dev-command.d.ts.map +1 -1
- package/dist/commands/bp-dev-stderr.d.ts +9 -0
- package/dist/commands/bp-dev-stderr.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/dependencies/catalog/catalog-service.d.ts +53 -0
- package/dist/dependencies/catalog/catalog-service.d.ts.map +1 -0
- package/dist/dependencies/catalog/client-factory.d.ts +33 -0
- package/dist/dependencies/catalog/client-factory.d.ts.map +1 -0
- package/dist/dependencies/catalog/integration-source.d.ts +34 -0
- package/dist/dependencies/catalog/integration-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/interface-source.d.ts +23 -0
- package/dist/dependencies/catalog/interface-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/plugin-source.d.ts +49 -0
- package/dist/dependencies/catalog/plugin-source.d.ts.map +1 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts +76 -0
- package/dist/dependencies/catalog/resolution-cache.d.ts.map +1 -0
- package/dist/dependencies/dependency-manager.d.ts +31 -16
- package/dist/dependencies/dependency-manager.d.ts.map +1 -1
- package/dist/dependencies/errors.d.ts +2 -2
- package/dist/dependencies/errors.d.ts.map +1 -1
- package/dist/dependencies/index.d.ts +5 -4
- package/dist/dependencies/index.d.ts.map +1 -1
- package/dist/dependencies/index.js +2089 -1670
- package/dist/dependencies/index.js.map +37 -30
- package/dist/dependencies/legacy-lock-file.d.ts +15 -0
- package/dist/dependencies/legacy-lock-file.d.ts.map +1 -0
- package/dist/dependencies/migration.d.ts +19 -0
- package/dist/dependencies/migration.d.ts.map +1 -1
- package/dist/dependencies/resolvers/integration-resolver.d.ts +4 -3
- package/dist/dependencies/resolvers/integration-resolver.d.ts.map +1 -1
- package/dist/dependencies/resolvers/plugin-resolver.d.ts +4 -4
- package/dist/dependencies/resolvers/plugin-resolver.d.ts.map +1 -1
- package/dist/dependencies/snapshot-store.d.ts +59 -0
- package/dist/dependencies/snapshot-store.d.ts.map +1 -0
- package/dist/dependencies/status-resolver.d.ts +36 -0
- package/dist/dependencies/status-resolver.d.ts.map +1 -0
- package/dist/dependencies/status.d.ts +214 -0
- package/dist/dependencies/status.d.ts.map +1 -0
- package/dist/dependencies/types.d.ts +380 -29
- package/dist/dependencies/types.d.ts.map +1 -1
- package/dist/file-watcher/watcher.d.ts +21 -5
- package/dist/file-watcher/watcher.d.ts.map +1 -1
- package/dist/generators/action-types.d.ts.map +1 -1
- package/dist/generators/client-wrapper.d.ts.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3134 -2226
- package/dist/index.js.map +55 -48
- package/dist/integrations/config-utils.d.ts +11 -7
- package/dist/integrations/config-utils.d.ts.map +1 -1
- package/dist/integrations/hub-cache.d.ts +0 -58
- package/dist/integrations/hub-cache.d.ts.map +1 -1
- package/dist/integrations/index.d.ts +1 -3
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/manager.d.ts +19 -53
- package/dist/integrations/manager.d.ts.map +1 -1
- package/dist/interfaces/enhanced-cache.d.ts +7 -7
- package/dist/interfaces/enhanced-cache.d.ts.map +1 -1
- package/dist/interfaces/manager.d.ts +11 -17
- package/dist/interfaces/manager.d.ts.map +1 -1
- package/dist/knowledge/manager.d.ts +3 -0
- package/dist/knowledge/manager.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/manager.d.ts +16 -48
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/preflight/checker.d.ts +6 -1
- package/dist/preflight/checker.d.ts.map +1 -1
- package/dist/preflight/dependency-gate.d.ts +37 -0
- package/dist/preflight/dependency-gate.d.ts.map +1 -0
- package/dist/preflight/index.d.ts +2 -1
- package/dist/preflight/index.d.ts.map +1 -1
- package/dist/preflight/types.d.ts +18 -0
- package/dist/preflight/types.d.ts.map +1 -1
- package/dist/runner/script-runner.d.ts.map +1 -1
- package/dist/tables/table-manager.d.ts +3 -0
- package/dist/tables/table-manager.d.ts.map +1 -1
- package/dist/templates/README.md +23 -13
- package/dist/templates/blank/agent.config.ts +3 -3
- package/dist/templates/blank/src/triggers/index.ts +1 -1
- package/dist/templates/botpress-desk/evals/index.eval.ts +1 -1
- package/dist/templates/botpress-desk/src/triggers/index.ts +1 -1
- package/dist/templates/crm-enrichment/README.md +3 -3
- package/dist/templates/crm-enrichment/agent.config.ts +2 -2
- package/dist/templates/crm-enrichment/src/conversations/index.ts +1 -1
- package/dist/templates/hello-world/agent.config.ts +3 -3
- package/dist/templates/hello-world/src/triggers/index.ts +1 -1
- package/dist/templates/knowledge-assistant/src/triggers/index.ts +1 -1
- package/dist/templates/template.config.json +3 -3
- package/dist/utils/ids.d.ts +10 -0
- package/dist/utils/ids.d.ts.map +1 -1
- package/dist/workspace/workspace-cache.d.ts +2 -1
- package/dist/workspace/workspace-cache.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/agent-project/lock-to-dependencies.d.ts +0 -11
- package/dist/agent-project/lock-to-dependencies.d.ts.map +0 -1
- package/dist/dependencies/lock-file.d.ts +0 -15
- package/dist/dependencies/lock-file.d.ts.map +0 -1
- package/dist/integrations/enhanced-cache.d.ts +0 -53
- package/dist/integrations/enhanced-cache.d.ts.map +0 -1
- package/dist/plugins/enhanced-cache.d.ts +0 -53
- package/dist/plugins/enhanced-cache.d.ts.map +0 -1
- package/dist/templates/blank/package.json +0 -17
- package/dist/templates/blank/tsconfig.json +0 -25
- package/dist/templates/botpress-desk/package.json +0 -17
- package/dist/templates/crm-enrichment/package.json +0 -18
- package/dist/templates/crm-enrichment/tsconfig.json +0 -25
- package/dist/templates/hello-world/package.json +0 -18
- package/dist/templates/hello-world/tsconfig.json +0 -25
- package/dist/templates/knowledge-assistant/package.json +0 -18
- package/dist/templates/knowledge-assistant/tsconfig.json +0 -25
- package/dist/templates/slack-triage/package.json +0 -18
- package/dist/templates/slack-triage/tsconfig.json +0 -25
|
@@ -32,43 +32,43 @@ Tables provide structured data storage with automatic schema management, CRUD op
|
|
|
32
32
|
```typescript
|
|
33
33
|
// ✅ CORRECT
|
|
34
34
|
export const UsersTable = new Table({
|
|
35
|
-
name:
|
|
35
|
+
name: 'UsersTable',
|
|
36
36
|
columns: {
|
|
37
37
|
// No id field - it's automatic!
|
|
38
38
|
name: z.string(),
|
|
39
39
|
email: z.string(),
|
|
40
40
|
},
|
|
41
|
-
})
|
|
41
|
+
})
|
|
42
42
|
|
|
43
43
|
// ❌ WRONG - id is defined (will fail!)
|
|
44
44
|
export const Users = new Table({
|
|
45
45
|
// Also missing "Table" suffix on variable name
|
|
46
|
-
name:
|
|
46
|
+
name: 'UsersTable',
|
|
47
47
|
columns: {
|
|
48
48
|
id: z.string(), // ❌ Don't define id!
|
|
49
49
|
name: z.string(),
|
|
50
50
|
},
|
|
51
|
-
})
|
|
51
|
+
})
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
### Basic Table Structure
|
|
55
55
|
|
|
56
56
|
```typescript
|
|
57
|
-
import { Table, z } from
|
|
57
|
+
import { Table, z } from '@botpress/runtime'
|
|
58
58
|
|
|
59
59
|
export const UsersTable = new Table({
|
|
60
|
-
name:
|
|
61
|
-
description:
|
|
60
|
+
name: 'UsersTable',
|
|
61
|
+
description: 'Stores user information',
|
|
62
62
|
|
|
63
63
|
columns: {
|
|
64
64
|
// Note: id is NOT defined - it's automatic!
|
|
65
65
|
name: z.string(),
|
|
66
66
|
email: z.string().email(),
|
|
67
|
-
role: z.enum([
|
|
67
|
+
role: z.enum(['admin', 'user', 'guest']),
|
|
68
68
|
createdAt: z.date(),
|
|
69
69
|
metadata: z.object({}).passthrough(), // Flexible object
|
|
70
70
|
},
|
|
71
|
-
})
|
|
71
|
+
})
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
### Table with Key Column and Tags
|
|
@@ -76,20 +76,20 @@ export const UsersTable = new Table({
|
|
|
76
76
|
Use `keyColumn` to document the logical key for the table and `tags` for table metadata:
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
|
-
import { Table, z } from
|
|
79
|
+
import { Table, z } from '@botpress/runtime'
|
|
80
80
|
|
|
81
81
|
export const ExternalUsersTable = new Table({
|
|
82
|
-
name:
|
|
83
|
-
description:
|
|
82
|
+
name: 'ExternalUsersTable',
|
|
83
|
+
description: 'Users synced from external system',
|
|
84
84
|
|
|
85
85
|
// Key column for upsert operations - must be a column name
|
|
86
|
-
keyColumn:
|
|
86
|
+
keyColumn: 'externalId',
|
|
87
87
|
|
|
88
88
|
// Tags for table metadata (key-value pairs)
|
|
89
89
|
tags: {
|
|
90
|
-
source:
|
|
91
|
-
syncType:
|
|
92
|
-
version:
|
|
90
|
+
source: 'salesforce',
|
|
91
|
+
syncType: 'incremental',
|
|
92
|
+
version: '2.0',
|
|
93
93
|
},
|
|
94
94
|
|
|
95
95
|
columns: {
|
|
@@ -98,15 +98,17 @@ export const ExternalUsersTable = new Table({
|
|
|
98
98
|
email: z.string().email(),
|
|
99
99
|
lastSyncedAt: z.date(),
|
|
100
100
|
},
|
|
101
|
-
})
|
|
101
|
+
})
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
**Key Column Notes:**
|
|
105
|
+
|
|
105
106
|
- `keyColumn` documents the intended unique key for the table.
|
|
106
107
|
- Current runtime upsert helpers may still require `keyColumn` to be passed explicitly per `upsertRows()` call.
|
|
107
108
|
- Do not assume table-level `keyColumn` is automatically applied everywhere.
|
|
108
109
|
|
|
109
110
|
**Tags Use Cases:**
|
|
111
|
+
|
|
110
112
|
- Track data source/origin
|
|
111
113
|
- Version control for schemas
|
|
112
114
|
- Environment markers (staging, production)
|
|
@@ -118,13 +120,13 @@ Tables support complex nested structures and flexible schemas:
|
|
|
118
120
|
|
|
119
121
|
```typescript
|
|
120
122
|
export const ConversationsTable = new Table({
|
|
121
|
-
name:
|
|
122
|
-
description:
|
|
123
|
+
name: 'ConversationsTable',
|
|
124
|
+
description: 'Store conversation data with complex metadata',
|
|
123
125
|
|
|
124
126
|
columns: {
|
|
125
127
|
// ISO date strings (common pattern for API data)
|
|
126
|
-
createdAt: z.string().describe(
|
|
127
|
-
updatedAt: z.string().describe(
|
|
128
|
+
createdAt: z.string().describe('ISO 8601 date string'),
|
|
129
|
+
updatedAt: z.string().describe('ISO 8601 date string'),
|
|
128
130
|
|
|
129
131
|
// Optional fields
|
|
130
132
|
waitingSince: z.string().optional(),
|
|
@@ -156,7 +158,7 @@ export const ConversationsTable = new Table({
|
|
|
156
158
|
id: z.string(),
|
|
157
159
|
name: z.string().optional(),
|
|
158
160
|
email: z.string().optional(),
|
|
159
|
-
})
|
|
161
|
+
})
|
|
160
162
|
)
|
|
161
163
|
.optional(),
|
|
162
164
|
|
|
@@ -164,13 +166,13 @@ export const ConversationsTable = new Table({
|
|
|
164
166
|
metadata: z.object({}).passthrough(),
|
|
165
167
|
|
|
166
168
|
// Discriminated unions for type safety
|
|
167
|
-
status: z.discriminatedUnion(
|
|
168
|
-
z.object({ type: z.literal(
|
|
169
|
-
z.object({ type: z.literal(
|
|
170
|
-
z.object({ type: z.literal(
|
|
169
|
+
status: z.discriminatedUnion('type', [
|
|
170
|
+
z.object({ type: z.literal('active'), reason: z.string() }),
|
|
171
|
+
z.object({ type: z.literal('snoozed'), until: z.string() }),
|
|
172
|
+
z.object({ type: z.literal('closed'), closedAt: z.string() }),
|
|
171
173
|
]),
|
|
172
174
|
},
|
|
173
|
-
})
|
|
175
|
+
})
|
|
174
176
|
```
|
|
175
177
|
|
|
176
178
|
### Searchable Columns
|
|
@@ -179,14 +181,14 @@ Enable semantic search on specific columns:
|
|
|
179
181
|
|
|
180
182
|
```typescript
|
|
181
183
|
export const DocumentsTable = new Table({
|
|
182
|
-
name:
|
|
183
|
-
description:
|
|
184
|
+
name: 'DocumentsTable',
|
|
185
|
+
description: 'Document storage with search',
|
|
184
186
|
|
|
185
187
|
columns: {
|
|
186
188
|
// Searchable field with shorthand syntax
|
|
187
189
|
title: {
|
|
188
190
|
searchable: true,
|
|
189
|
-
schema: z.string().describe(
|
|
191
|
+
schema: z.string().describe('Document title'),
|
|
190
192
|
},
|
|
191
193
|
|
|
192
194
|
// Enable semantic search on content
|
|
@@ -210,7 +212,7 @@ export const DocumentsTable = new Table({
|
|
|
210
212
|
// Higher values (e.g., 5, 10, 20) give this table higher priority in search
|
|
211
213
|
// Default is 1 if not specified
|
|
212
214
|
factor: 5,
|
|
213
|
-
})
|
|
215
|
+
})
|
|
214
216
|
```
|
|
215
217
|
|
|
216
218
|
### Important Column Syntax
|
|
@@ -237,38 +239,38 @@ columns: {
|
|
|
237
239
|
### Creating Rows
|
|
238
240
|
|
|
239
241
|
```typescript
|
|
240
|
-
import { UsersTable } from
|
|
242
|
+
import { UsersTable } from './tables/Users'
|
|
241
243
|
|
|
242
244
|
// Create single row (id is auto-assigned)
|
|
243
245
|
await UsersTable.createRows({
|
|
244
246
|
rows: [
|
|
245
247
|
{
|
|
246
|
-
name:
|
|
247
|
-
email:
|
|
248
|
-
role:
|
|
248
|
+
name: 'John Doe',
|
|
249
|
+
email: 'john@example.com',
|
|
250
|
+
role: 'user',
|
|
249
251
|
createdAt: new Date(),
|
|
250
|
-
metadata: { source:
|
|
252
|
+
metadata: { source: 'signup' },
|
|
251
253
|
},
|
|
252
254
|
],
|
|
253
|
-
})
|
|
255
|
+
})
|
|
254
256
|
|
|
255
257
|
// Create multiple rows (ids are auto-assigned)
|
|
256
258
|
await UsersTable.createRows({
|
|
257
259
|
rows: [
|
|
258
260
|
{
|
|
259
|
-
name:
|
|
260
|
-
email:
|
|
261
|
-
role:
|
|
261
|
+
name: 'Alice',
|
|
262
|
+
email: 'alice@example.com',
|
|
263
|
+
role: 'admin',
|
|
262
264
|
createdAt: new Date(),
|
|
263
265
|
},
|
|
264
266
|
{
|
|
265
|
-
name:
|
|
266
|
-
email:
|
|
267
|
-
role:
|
|
267
|
+
name: 'Bob',
|
|
268
|
+
email: 'bob@example.com',
|
|
269
|
+
role: 'user',
|
|
268
270
|
createdAt: new Date(),
|
|
269
271
|
},
|
|
270
272
|
],
|
|
271
|
-
})
|
|
273
|
+
})
|
|
272
274
|
```
|
|
273
275
|
|
|
274
276
|
### Finding Rows
|
|
@@ -276,36 +278,36 @@ await UsersTable.createRows({
|
|
|
276
278
|
```typescript
|
|
277
279
|
// Find by condition
|
|
278
280
|
const { rows } = await UsersTable.findRows({
|
|
279
|
-
filter: { role:
|
|
280
|
-
orderBy:
|
|
281
|
-
orderDirection:
|
|
281
|
+
filter: { role: 'admin' },
|
|
282
|
+
orderBy: 'createdAt',
|
|
283
|
+
orderDirection: 'desc',
|
|
282
284
|
limit: 10,
|
|
283
285
|
offset: 0,
|
|
284
|
-
})
|
|
286
|
+
})
|
|
285
287
|
|
|
286
288
|
// Find by multiple conditions
|
|
287
289
|
const { rows } = await UsersTable.findRows({
|
|
288
290
|
filter: {
|
|
289
|
-
role:
|
|
290
|
-
email:
|
|
291
|
+
role: 'user',
|
|
292
|
+
email: 'john@example.com',
|
|
291
293
|
},
|
|
292
|
-
})
|
|
294
|
+
})
|
|
293
295
|
|
|
294
296
|
// Find with complex conditions
|
|
295
297
|
const { rows } = await UsersTable.findRows({
|
|
296
298
|
filter: {
|
|
297
|
-
createdAt: { $gte: new Date(
|
|
299
|
+
createdAt: { $gte: new Date('2024-01-01') },
|
|
298
300
|
},
|
|
299
|
-
orderBy:
|
|
300
|
-
orderDirection:
|
|
301
|
-
})
|
|
301
|
+
orderBy: 'name',
|
|
302
|
+
orderDirection: 'asc',
|
|
303
|
+
})
|
|
302
304
|
|
|
303
305
|
// Complex filters with logical operators
|
|
304
306
|
const { rows } = await UsersTable.findRows({
|
|
305
307
|
filter: {
|
|
306
|
-
$and: [{ role:
|
|
308
|
+
$and: [{ role: 'user' }, { createdAt: { $gte: new Date('2024-01-01') } }],
|
|
307
309
|
},
|
|
308
|
-
})
|
|
310
|
+
})
|
|
309
311
|
```
|
|
310
312
|
|
|
311
313
|
### Getting Single Row
|
|
@@ -314,11 +316,11 @@ Get a specific row by its id:
|
|
|
314
316
|
|
|
315
317
|
```typescript
|
|
316
318
|
// Get row by id
|
|
317
|
-
const row = await UsersTable.getRow({ id: 123 })
|
|
319
|
+
const row = await UsersTable.getRow({ id: 123 })
|
|
318
320
|
|
|
319
|
-
console.log(row.id)
|
|
320
|
-
console.log(row.name)
|
|
321
|
-
console.log(row.createdAt)
|
|
321
|
+
console.log(row.id) // 123
|
|
322
|
+
console.log(row.name) // Access row properties
|
|
323
|
+
console.log(row.createdAt) // Auto-generated timestamp
|
|
322
324
|
```
|
|
323
325
|
|
|
324
326
|
### Semantic Search
|
|
@@ -328,21 +330,21 @@ Search across searchable columns using the `search` parameter:
|
|
|
328
330
|
```typescript
|
|
329
331
|
// Search documents
|
|
330
332
|
const { rows } = await DocumentsTable.findRows({
|
|
331
|
-
search:
|
|
333
|
+
search: 'machine learning algorithms',
|
|
332
334
|
limit: 5,
|
|
333
|
-
})
|
|
335
|
+
})
|
|
334
336
|
|
|
335
337
|
// Results are ranked by semantic similarity
|
|
336
338
|
rows.forEach((doc) => {
|
|
337
|
-
console.log(doc.title, doc.content)
|
|
338
|
-
})
|
|
339
|
+
console.log(doc.title, doc.content)
|
|
340
|
+
})
|
|
339
341
|
|
|
340
342
|
// Combine search with filters
|
|
341
343
|
const { rows } = await DocumentsTable.findRows({
|
|
342
|
-
search:
|
|
343
|
-
filter: { tags: { $in: [
|
|
344
|
+
search: 'machine learning',
|
|
345
|
+
filter: { tags: { $in: ['ai', 'ml'] } },
|
|
344
346
|
limit: 10,
|
|
345
|
-
})
|
|
347
|
+
})
|
|
346
348
|
```
|
|
347
349
|
|
|
348
350
|
### Upsert Operations
|
|
@@ -354,25 +356,25 @@ Upsert allows inserting or updating rows based on a key column:
|
|
|
354
356
|
await MessagesTable.upsertRows({
|
|
355
357
|
rows: [
|
|
356
358
|
{
|
|
357
|
-
messageId:
|
|
358
|
-
content:
|
|
359
|
+
messageId: 'msg-123', // Key column
|
|
360
|
+
content: 'Updated content',
|
|
359
361
|
timestamp: new Date(),
|
|
360
362
|
},
|
|
361
363
|
],
|
|
362
|
-
keyColumn:
|
|
363
|
-
})
|
|
364
|
+
keyColumn: 'messageId', // Updates if messageId exists, inserts if not
|
|
365
|
+
})
|
|
364
366
|
|
|
365
367
|
// Upsert with id (optional, as number)
|
|
366
368
|
await UsersTable.upsertRows({
|
|
367
369
|
rows: [
|
|
368
370
|
{
|
|
369
371
|
id: 123, // Optional: provide id to update specific row
|
|
370
|
-
name:
|
|
371
|
-
email:
|
|
372
|
+
name: 'Jane Doe',
|
|
373
|
+
email: 'jane@example.com',
|
|
372
374
|
},
|
|
373
375
|
],
|
|
374
|
-
keyColumn:
|
|
375
|
-
})
|
|
376
|
+
keyColumn: 'id',
|
|
377
|
+
})
|
|
376
378
|
|
|
377
379
|
// Bulk upsert with multiple rows
|
|
378
380
|
await ContactsTable.upsertRows({
|
|
@@ -382,8 +384,8 @@ await ContactsTable.upsertRows({
|
|
|
382
384
|
email: contact.email,
|
|
383
385
|
updatedAt: new Date(),
|
|
384
386
|
})),
|
|
385
|
-
keyColumn:
|
|
386
|
-
})
|
|
387
|
+
keyColumn: 'contactId',
|
|
388
|
+
})
|
|
387
389
|
```
|
|
388
390
|
|
|
389
391
|
### Updating Rows
|
|
@@ -396,19 +398,19 @@ await UsersTable.updateRows({
|
|
|
396
398
|
rows: [
|
|
397
399
|
{
|
|
398
400
|
id: 123, // Row ID (required)
|
|
399
|
-
role:
|
|
401
|
+
role: 'admin',
|
|
400
402
|
metadata: { promoted: true },
|
|
401
403
|
},
|
|
402
404
|
],
|
|
403
|
-
})
|
|
405
|
+
})
|
|
404
406
|
|
|
405
407
|
// Update multiple rows
|
|
406
408
|
await UsersTable.updateRows({
|
|
407
409
|
rows: [
|
|
408
|
-
{ id: 123, role:
|
|
409
|
-
{ id: 456, role:
|
|
410
|
+
{ id: 123, role: 'admin' },
|
|
411
|
+
{ id: 456, role: 'user' },
|
|
410
412
|
],
|
|
411
|
-
})
|
|
413
|
+
})
|
|
412
414
|
```
|
|
413
415
|
|
|
414
416
|
**Note:** For tables with computed columns, see "Computed Columns" section below for the `waitComputed` option.
|
|
@@ -418,19 +420,19 @@ await UsersTable.updateRows({
|
|
|
418
420
|
```typescript
|
|
419
421
|
// Delete by filter condition
|
|
420
422
|
await UsersTable.deleteRows({
|
|
421
|
-
role:
|
|
422
|
-
})
|
|
423
|
+
role: 'guest',
|
|
424
|
+
})
|
|
423
425
|
|
|
424
426
|
// Delete with complex filter
|
|
425
427
|
await UsersTable.deleteRows({
|
|
426
|
-
$and: [{ role:
|
|
427
|
-
})
|
|
428
|
+
$and: [{ role: 'guest' }, { createdAt: { $lt: new Date('2024-01-01') } }],
|
|
429
|
+
})
|
|
428
430
|
|
|
429
431
|
// Delete by specific IDs
|
|
430
|
-
await UsersTable.deleteRowIds([123, 456, 789])
|
|
432
|
+
await UsersTable.deleteRowIds([123, 456, 789])
|
|
431
433
|
|
|
432
434
|
// Delete all rows (use with caution!)
|
|
433
|
-
await UsersTable.deleteAllRows()
|
|
435
|
+
await UsersTable.deleteAllRows()
|
|
434
436
|
```
|
|
435
437
|
|
|
436
438
|
### Advanced: Direct Table Operations
|
|
@@ -438,19 +440,19 @@ await UsersTable.deleteAllRows();
|
|
|
438
440
|
In workflows, you can also use the client for low-level table operations:
|
|
439
441
|
|
|
440
442
|
```typescript
|
|
441
|
-
import { Workflow } from
|
|
443
|
+
import { Workflow } from '@botpress/runtime'
|
|
442
444
|
|
|
443
445
|
export const ResetTablesWorkflow = new Workflow({
|
|
444
|
-
name:
|
|
445
|
-
description:
|
|
446
|
+
name: 'resetTables',
|
|
447
|
+
description: 'Resets specific tables',
|
|
446
448
|
async handler({ client }) {
|
|
447
449
|
// Delete entire table (drops and recreates)
|
|
448
|
-
await client._inner.deleteTable({ table:
|
|
450
|
+
await client._inner.deleteTable({ table: 'MyTable' })
|
|
449
451
|
|
|
450
452
|
// Other low-level operations available via client._inner
|
|
451
453
|
// Use with caution as these bypass type safety
|
|
452
454
|
},
|
|
453
|
-
})
|
|
455
|
+
})
|
|
454
456
|
```
|
|
455
457
|
|
|
456
458
|
## Complex Schemas
|
|
@@ -459,7 +461,7 @@ export const ResetTablesWorkflow = new Workflow({
|
|
|
459
461
|
|
|
460
462
|
```typescript
|
|
461
463
|
export const OrdersTable = new Table({
|
|
462
|
-
name:
|
|
464
|
+
name: 'OrdersTable',
|
|
463
465
|
|
|
464
466
|
columns: {
|
|
465
467
|
customer: z.object({
|
|
@@ -472,7 +474,7 @@ export const OrdersTable = new Table({
|
|
|
472
474
|
productId: z.string(),
|
|
473
475
|
quantity: z.number().int().positive(),
|
|
474
476
|
price: z.number().positive(),
|
|
475
|
-
})
|
|
477
|
+
})
|
|
476
478
|
),
|
|
477
479
|
shipping: z.object({
|
|
478
480
|
address: z.string(),
|
|
@@ -480,19 +482,19 @@ export const OrdersTable = new Table({
|
|
|
480
482
|
country: z.string(),
|
|
481
483
|
postalCode: z.string(),
|
|
482
484
|
}),
|
|
483
|
-
status: z.enum([
|
|
485
|
+
status: z.enum(['pending', 'processing', 'shipped', 'delivered']),
|
|
484
486
|
total: z.number().positive(),
|
|
485
487
|
createdAt: z.date(),
|
|
486
488
|
updatedAt: z.date(),
|
|
487
489
|
},
|
|
488
|
-
})
|
|
490
|
+
})
|
|
489
491
|
```
|
|
490
492
|
|
|
491
493
|
### Optional and Default Values
|
|
492
494
|
|
|
493
495
|
```typescript
|
|
494
496
|
export const ProductsTable = new Table({
|
|
495
|
-
name:
|
|
497
|
+
name: 'ProductsTable',
|
|
496
498
|
|
|
497
499
|
columns: {
|
|
498
500
|
name: z.string(),
|
|
@@ -503,14 +505,14 @@ export const ProductsTable = new Table({
|
|
|
503
505
|
inStock: z.boolean().default(true),
|
|
504
506
|
|
|
505
507
|
// Optional with default
|
|
506
|
-
category: z.string().optional().default(
|
|
508
|
+
category: z.string().optional().default('uncategorized'),
|
|
507
509
|
|
|
508
510
|
// Nullable field
|
|
509
511
|
discountPrice: z.number().positive().nullable(),
|
|
510
512
|
|
|
511
513
|
metadata: z.object({}).passthrough().optional(),
|
|
512
514
|
},
|
|
513
|
-
})
|
|
515
|
+
})
|
|
514
516
|
```
|
|
515
517
|
|
|
516
518
|
### Computed Columns
|
|
@@ -518,10 +520,10 @@ export const ProductsTable = new Table({
|
|
|
518
520
|
Computed columns are automatically calculated based on other column values. They support dependencies and are recomputed when their dependencies change.
|
|
519
521
|
|
|
520
522
|
```typescript
|
|
521
|
-
import { Table, z } from
|
|
523
|
+
import { Table, z } from '@botpress/runtime'
|
|
522
524
|
|
|
523
525
|
export const ProfilesTable = new Table({
|
|
524
|
-
name:
|
|
526
|
+
name: 'ProfilesTable',
|
|
525
527
|
|
|
526
528
|
columns: {
|
|
527
529
|
firstName: z.string(),
|
|
@@ -531,9 +533,9 @@ export const ProfilesTable = new Table({
|
|
|
531
533
|
fullName: {
|
|
532
534
|
computed: true,
|
|
533
535
|
schema: z.string(),
|
|
534
|
-
dependencies: [
|
|
536
|
+
dependencies: ['firstName', 'lastName'],
|
|
535
537
|
value: async (row) => {
|
|
536
|
-
return `${row.firstName} ${row.lastName}
|
|
538
|
+
return `${row.firstName} ${row.lastName}`
|
|
537
539
|
},
|
|
538
540
|
},
|
|
539
541
|
|
|
@@ -543,13 +545,13 @@ export const ProfilesTable = new Table({
|
|
|
543
545
|
ageInMonths: {
|
|
544
546
|
computed: true,
|
|
545
547
|
schema: z.number(),
|
|
546
|
-
dependencies: [
|
|
548
|
+
dependencies: ['age'],
|
|
547
549
|
value: async (row) => {
|
|
548
|
-
return row.age * 12
|
|
550
|
+
return row.age * 12
|
|
549
551
|
},
|
|
550
552
|
},
|
|
551
553
|
},
|
|
552
|
-
})
|
|
554
|
+
})
|
|
553
555
|
```
|
|
554
556
|
|
|
555
557
|
#### Using Computed Columns
|
|
@@ -561,14 +563,14 @@ Computed columns are calculated automatically when rows are created or updated:
|
|
|
561
563
|
await ProfilesTable.createRows({
|
|
562
564
|
rows: [
|
|
563
565
|
{
|
|
564
|
-
firstName:
|
|
565
|
-
lastName:
|
|
566
|
+
firstName: 'John',
|
|
567
|
+
lastName: 'Doe',
|
|
566
568
|
age: 30,
|
|
567
569
|
// fullName and ageInMonths will be computed automatically
|
|
568
570
|
// id is auto-assigned by server
|
|
569
571
|
},
|
|
570
572
|
],
|
|
571
|
-
})
|
|
573
|
+
})
|
|
572
574
|
|
|
573
575
|
// The created row will have: id (number), fullName = "John Doe", ageInMonths = 360
|
|
574
576
|
```
|
|
@@ -583,17 +585,17 @@ await ProfilesTable.updateRows({
|
|
|
583
585
|
rows: [
|
|
584
586
|
{
|
|
585
587
|
id: 123, // Row id as number
|
|
586
|
-
firstName:
|
|
588
|
+
firstName: 'Jane', // fullName will be recomputed
|
|
587
589
|
},
|
|
588
590
|
],
|
|
589
591
|
waitComputed: true, // Wait for fullName to finish computing
|
|
590
|
-
})
|
|
592
|
+
})
|
|
591
593
|
|
|
592
594
|
// Without waitComputed, computed columns update eventually
|
|
593
595
|
await ProfilesTable.updateRows({
|
|
594
|
-
rows: [{ id: 123, firstName:
|
|
596
|
+
rows: [{ id: 123, firstName: 'Jane' }],
|
|
595
597
|
// Returns immediately, computed columns update in background
|
|
596
|
-
})
|
|
598
|
+
})
|
|
597
599
|
```
|
|
598
600
|
|
|
599
601
|
#### Complex Dependencies
|
|
@@ -602,7 +604,7 @@ Computed columns can have multiple dependencies and form dependency chains:
|
|
|
602
604
|
|
|
603
605
|
```typescript
|
|
604
606
|
export const OrdersTable = new Table({
|
|
605
|
-
name:
|
|
607
|
+
name: 'OrdersTable',
|
|
606
608
|
|
|
607
609
|
columns: {
|
|
608
610
|
price: z.number(),
|
|
@@ -613,7 +615,7 @@ export const OrdersTable = new Table({
|
|
|
613
615
|
subtotal: {
|
|
614
616
|
computed: true,
|
|
615
617
|
schema: z.number(),
|
|
616
|
-
dependencies: [
|
|
618
|
+
dependencies: ['price', 'quantity'],
|
|
617
619
|
value: async (row) => row.price * row.quantity,
|
|
618
620
|
},
|
|
619
621
|
|
|
@@ -621,7 +623,7 @@ export const OrdersTable = new Table({
|
|
|
621
623
|
tax: {
|
|
622
624
|
computed: true,
|
|
623
625
|
schema: z.number(),
|
|
624
|
-
dependencies: [
|
|
626
|
+
dependencies: ['subtotal', 'taxRate'],
|
|
625
627
|
value: async (row) => row.subtotal * row.taxRate,
|
|
626
628
|
},
|
|
627
629
|
|
|
@@ -629,11 +631,11 @@ export const OrdersTable = new Table({
|
|
|
629
631
|
total: {
|
|
630
632
|
computed: true,
|
|
631
633
|
schema: z.number(),
|
|
632
|
-
dependencies: [
|
|
634
|
+
dependencies: ['subtotal', 'tax'],
|
|
633
635
|
value: async (row) => row.subtotal + row.tax,
|
|
634
636
|
},
|
|
635
637
|
},
|
|
636
|
-
})
|
|
638
|
+
})
|
|
637
639
|
```
|
|
638
640
|
|
|
639
641
|
#### Computed Column Use Cases
|
|
@@ -642,7 +644,7 @@ export const OrdersTable = new Table({
|
|
|
642
644
|
|
|
643
645
|
```typescript
|
|
644
646
|
export const UsersTable = new Table({
|
|
645
|
-
name:
|
|
647
|
+
name: 'UsersTable',
|
|
646
648
|
columns: {
|
|
647
649
|
firstName: z.string(),
|
|
648
650
|
lastName: z.string(),
|
|
@@ -653,20 +655,20 @@ export const UsersTable = new Table({
|
|
|
653
655
|
bio: {
|
|
654
656
|
computed: true,
|
|
655
657
|
schema: z.string(),
|
|
656
|
-
dependencies: [
|
|
658
|
+
dependencies: ['firstName', 'lastName', 'age'],
|
|
657
659
|
value: async (row) => {
|
|
658
|
-
return `Name: ${row.firstName} ${row.lastName}, Age: ${row.age}
|
|
660
|
+
return `Name: ${row.firstName} ${row.lastName}, Age: ${row.age}`
|
|
659
661
|
},
|
|
660
662
|
},
|
|
661
663
|
},
|
|
662
|
-
})
|
|
664
|
+
})
|
|
663
665
|
```
|
|
664
666
|
|
|
665
667
|
**Calculations:**
|
|
666
668
|
|
|
667
669
|
```typescript
|
|
668
670
|
export const ProductsTable = new Table({
|
|
669
|
-
name:
|
|
671
|
+
name: 'ProductsTable',
|
|
670
672
|
columns: {
|
|
671
673
|
price: z.number(),
|
|
672
674
|
cost: z.number(),
|
|
@@ -675,20 +677,20 @@ export const ProductsTable = new Table({
|
|
|
675
677
|
profitMargin: {
|
|
676
678
|
computed: true,
|
|
677
679
|
schema: z.number(),
|
|
678
|
-
dependencies: [
|
|
680
|
+
dependencies: ['price', 'cost'],
|
|
679
681
|
value: async (row) => {
|
|
680
|
-
return ((row.price - row.cost) / row.price) * 100
|
|
682
|
+
return ((row.price - row.cost) / row.price) * 100
|
|
681
683
|
},
|
|
682
684
|
},
|
|
683
685
|
},
|
|
684
|
-
})
|
|
686
|
+
})
|
|
685
687
|
```
|
|
686
688
|
|
|
687
689
|
**Data Transformations:**
|
|
688
690
|
|
|
689
691
|
```typescript
|
|
690
692
|
export const ContactsTable = new Table({
|
|
691
|
-
name:
|
|
693
|
+
name: 'ContactsTable',
|
|
692
694
|
columns: {
|
|
693
695
|
phone: z.string(),
|
|
694
696
|
|
|
@@ -696,14 +698,14 @@ export const ContactsTable = new Table({
|
|
|
696
698
|
phoneNormalized: {
|
|
697
699
|
computed: true,
|
|
698
700
|
schema: z.string(),
|
|
699
|
-
dependencies: [
|
|
701
|
+
dependencies: ['phone'],
|
|
700
702
|
value: async (row) => {
|
|
701
703
|
// Remove all non-digit characters
|
|
702
|
-
return row.phone.replace(/\D/g,
|
|
704
|
+
return row.phone.replace(/\D/g, '')
|
|
703
705
|
},
|
|
704
706
|
},
|
|
705
707
|
},
|
|
706
|
-
})
|
|
708
|
+
})
|
|
707
709
|
```
|
|
708
710
|
|
|
709
711
|
#### Important Notes
|
|
@@ -720,15 +722,15 @@ export const ContactsTable = new Table({
|
|
|
720
722
|
### In Actions
|
|
721
723
|
|
|
722
724
|
```typescript
|
|
723
|
-
import { Action, z } from
|
|
724
|
-
import { UsersTable } from
|
|
725
|
+
import { Action, z } from '@botpress/runtime'
|
|
726
|
+
import { UsersTable } from '../tables/Users'
|
|
725
727
|
|
|
726
728
|
export const createUser = new Action({
|
|
727
|
-
name:
|
|
729
|
+
name: 'createUser',
|
|
728
730
|
input: z.object({
|
|
729
731
|
name: z.string(),
|
|
730
732
|
email: z.string().email(),
|
|
731
|
-
role: z.enum([
|
|
733
|
+
role: z.enum(['admin', 'user', 'guest']),
|
|
732
734
|
}),
|
|
733
735
|
output: z.object({
|
|
734
736
|
userId: z.string(),
|
|
@@ -740,13 +742,13 @@ export const createUser = new Action({
|
|
|
740
742
|
const existing = await UsersTable.findRows({
|
|
741
743
|
filter: { email: input.email },
|
|
742
744
|
limit: 1,
|
|
743
|
-
})
|
|
745
|
+
})
|
|
744
746
|
|
|
745
747
|
if (existing.rows.length > 0) {
|
|
746
748
|
return {
|
|
747
749
|
userId: existing.rows[0].id,
|
|
748
750
|
created: false,
|
|
749
|
-
}
|
|
751
|
+
}
|
|
750
752
|
}
|
|
751
753
|
|
|
752
754
|
// Create new user
|
|
@@ -760,75 +762,75 @@ export const createUser = new Action({
|
|
|
760
762
|
metadata: {},
|
|
761
763
|
},
|
|
762
764
|
],
|
|
763
|
-
})
|
|
765
|
+
})
|
|
764
766
|
|
|
765
767
|
return {
|
|
766
768
|
userId: result.rows[0].id.toString(),
|
|
767
769
|
created: true,
|
|
768
|
-
}
|
|
770
|
+
}
|
|
769
771
|
},
|
|
770
|
-
})
|
|
772
|
+
})
|
|
771
773
|
```
|
|
772
774
|
|
|
773
775
|
### In Workflows
|
|
774
776
|
|
|
775
777
|
```typescript
|
|
776
|
-
import { Workflow, z } from
|
|
777
|
-
import { AuditLogTable } from
|
|
778
|
+
import { Workflow, z } from '@botpress/runtime'
|
|
779
|
+
import { AuditLogTable } from '../tables/AuditLog'
|
|
778
780
|
|
|
779
781
|
export const ProcessingWorkflow = new Workflow({
|
|
780
|
-
name:
|
|
782
|
+
name: 'processing',
|
|
781
783
|
input: z.object({ data: z.string() }),
|
|
782
784
|
|
|
783
785
|
handler: async ({ input, step }) => {
|
|
784
786
|
// Log workflow start
|
|
785
|
-
await step(
|
|
787
|
+
await step('log-start', async () => {
|
|
786
788
|
await AuditLogTable.createRows({
|
|
787
789
|
rows: [
|
|
788
790
|
{
|
|
789
|
-
action:
|
|
790
|
-
details: { workflow:
|
|
791
|
+
action: 'workflow_started',
|
|
792
|
+
details: { workflow: 'processing', input },
|
|
791
793
|
timestamp: new Date(),
|
|
792
794
|
},
|
|
793
795
|
],
|
|
794
|
-
})
|
|
795
|
-
})
|
|
796
|
+
})
|
|
797
|
+
})
|
|
796
798
|
|
|
797
799
|
// Process data
|
|
798
|
-
const result = await step(
|
|
799
|
-
return await processData(input.data)
|
|
800
|
-
})
|
|
800
|
+
const result = await step('process', async () => {
|
|
801
|
+
return await processData(input.data)
|
|
802
|
+
})
|
|
801
803
|
|
|
802
804
|
// Log completion
|
|
803
|
-
await step(
|
|
805
|
+
await step('log-complete', async () => {
|
|
804
806
|
await AuditLogTable.createRows({
|
|
805
807
|
rows: [
|
|
806
808
|
{
|
|
807
|
-
action:
|
|
808
|
-
details: { workflow:
|
|
809
|
+
action: 'workflow_completed',
|
|
810
|
+
details: { workflow: 'processing', result },
|
|
809
811
|
timestamp: new Date(),
|
|
810
812
|
},
|
|
811
813
|
],
|
|
812
|
-
})
|
|
813
|
-
})
|
|
814
|
+
})
|
|
815
|
+
})
|
|
814
816
|
|
|
815
|
-
return { success: true }
|
|
817
|
+
return { success: true }
|
|
816
818
|
},
|
|
817
|
-
})
|
|
819
|
+
})
|
|
818
820
|
```
|
|
819
821
|
|
|
820
822
|
### In Conversations
|
|
821
823
|
|
|
822
824
|
```typescript
|
|
823
|
-
import { Conversation, user } from
|
|
824
|
-
import { ConversationHistoryTable } from
|
|
825
|
+
import { Conversation, user } from '@botpress/runtime'
|
|
826
|
+
import { ConversationHistoryTable } from '../tables/ConversationHistory'
|
|
825
827
|
|
|
826
828
|
export const Chat = new Conversation({
|
|
827
|
-
channel:
|
|
829
|
+
channel: 'chat.channel',
|
|
828
830
|
|
|
829
831
|
async handler({ message, conversation }) {
|
|
830
832
|
// Store message in history
|
|
831
|
-
if (message?.type ===
|
|
833
|
+
if (message?.type === 'text') {
|
|
832
834
|
await ConversationHistoryTable.createRows({
|
|
833
835
|
rows: [
|
|
834
836
|
{
|
|
@@ -838,27 +840,27 @@ export const Chat = new Conversation({
|
|
|
838
840
|
timestamp: new Date(),
|
|
839
841
|
},
|
|
840
842
|
],
|
|
841
|
-
})
|
|
843
|
+
})
|
|
842
844
|
}
|
|
843
845
|
|
|
844
846
|
// Search previous conversations
|
|
845
|
-
if (message?.payload.text?.startsWith(
|
|
846
|
-
const query = message.payload.text.substring(7).trim()
|
|
847
|
+
if (message?.payload.text?.startsWith('/search')) {
|
|
848
|
+
const query = message.payload.text.substring(7).trim()
|
|
847
849
|
|
|
848
850
|
const { rows } = await ConversationHistoryTable.findRows({
|
|
849
851
|
search: query,
|
|
850
852
|
limit: 5,
|
|
851
|
-
})
|
|
853
|
+
})
|
|
852
854
|
|
|
853
855
|
await conversation.send({
|
|
854
|
-
type:
|
|
856
|
+
type: 'text',
|
|
855
857
|
payload: {
|
|
856
858
|
text: `Found ${rows.length} matching conversations`,
|
|
857
859
|
},
|
|
858
|
-
})
|
|
860
|
+
})
|
|
859
861
|
}
|
|
860
862
|
},
|
|
861
|
-
})
|
|
863
|
+
})
|
|
862
864
|
```
|
|
863
865
|
|
|
864
866
|
## Using Tables with Knowledge Bases
|
|
@@ -902,17 +904,17 @@ export const fetchPaginatedData = new Action({
|
|
|
902
904
|
}),
|
|
903
905
|
|
|
904
906
|
async handler({ input }) {
|
|
905
|
-
const offset = (input.page - 1) * input.pageSize
|
|
907
|
+
const offset = (input.page - 1) * input.pageSize
|
|
906
908
|
|
|
907
909
|
const { rows } = await MyTable.findRows({
|
|
908
910
|
limit: input.pageSize,
|
|
909
911
|
offset,
|
|
910
|
-
orderBy:
|
|
911
|
-
orderDirection:
|
|
912
|
-
})
|
|
912
|
+
orderBy: 'createdAt',
|
|
913
|
+
orderDirection: 'desc',
|
|
914
|
+
})
|
|
913
915
|
|
|
914
916
|
// Get total row count
|
|
915
|
-
const { rows: totalRows } = await MyTable.getTable()
|
|
917
|
+
const { rows: totalRows } = await MyTable.getTable()
|
|
916
918
|
|
|
917
919
|
return {
|
|
918
920
|
rows,
|
|
@@ -922,9 +924,9 @@ export const fetchPaginatedData = new Action({
|
|
|
922
924
|
total: totalRows,
|
|
923
925
|
totalPages: Math.ceil(totalRows / input.pageSize),
|
|
924
926
|
},
|
|
925
|
-
}
|
|
927
|
+
}
|
|
926
928
|
},
|
|
927
|
-
})
|
|
929
|
+
})
|
|
928
930
|
```
|
|
929
931
|
|
|
930
932
|
### 4. Optimize Searchable Content
|
|
@@ -940,7 +942,7 @@ export const DocumentsTable = new Table({
|
|
|
940
942
|
searchable: true, // Optimized for search
|
|
941
943
|
},
|
|
942
944
|
},
|
|
943
|
-
})
|
|
945
|
+
})
|
|
944
946
|
|
|
945
947
|
// When creating rows
|
|
946
948
|
await DocumentsTable.createRows({
|
|
@@ -950,7 +952,7 @@ await DocumentsTable.createRows({
|
|
|
950
952
|
searchContent: stripHtml(originalContent).toLowerCase(), // Optimized
|
|
951
953
|
},
|
|
952
954
|
],
|
|
953
|
-
})
|
|
955
|
+
})
|
|
954
956
|
```
|
|
955
957
|
|
|
956
958
|
## Common Patterns
|
|
@@ -959,7 +961,7 @@ await DocumentsTable.createRows({
|
|
|
959
961
|
|
|
960
962
|
```typescript
|
|
961
963
|
export const AuditLogTable = new Table({
|
|
962
|
-
name:
|
|
964
|
+
name: 'AuditLogTable',
|
|
963
965
|
columns: {
|
|
964
966
|
userId: z.string(),
|
|
965
967
|
action: z.string(),
|
|
@@ -969,14 +971,10 @@ export const AuditLogTable = new Table({
|
|
|
969
971
|
metadata: z.object({}).passthrough(),
|
|
970
972
|
timestamp: z.date(),
|
|
971
973
|
},
|
|
972
|
-
})
|
|
974
|
+
})
|
|
973
975
|
|
|
974
976
|
// Helper function
|
|
975
|
-
export async function logAction(
|
|
976
|
-
userId: string,
|
|
977
|
-
action: string,
|
|
978
|
-
details: Record<string, any>,
|
|
979
|
-
) {
|
|
977
|
+
export async function logAction(userId: string, action: string, details: Record<string, any>) {
|
|
980
978
|
await AuditLogTable.createRows({
|
|
981
979
|
rows: [
|
|
982
980
|
{
|
|
@@ -986,7 +984,7 @@ export async function logAction(
|
|
|
986
984
|
timestamp: new Date(),
|
|
987
985
|
},
|
|
988
986
|
],
|
|
989
|
-
})
|
|
987
|
+
})
|
|
990
988
|
}
|
|
991
989
|
```
|
|
992
990
|
|
|
@@ -994,34 +992,30 @@ export async function logAction(
|
|
|
994
992
|
|
|
995
993
|
```typescript
|
|
996
994
|
export const CacheTable = new Table({
|
|
997
|
-
name:
|
|
995
|
+
name: 'CacheTable',
|
|
998
996
|
columns: {
|
|
999
997
|
key: z.string(),
|
|
1000
998
|
value: z.unknown(),
|
|
1001
999
|
expiresAt: z.date(),
|
|
1002
1000
|
createdAt: z.date(),
|
|
1003
1001
|
},
|
|
1004
|
-
})
|
|
1002
|
+
})
|
|
1005
1003
|
|
|
1006
1004
|
// Cache helper
|
|
1007
|
-
export async function getCached<T>(
|
|
1008
|
-
key: string,
|
|
1009
|
-
fetcher: () => Promise<T>,
|
|
1010
|
-
ttlMinutes: number = 60,
|
|
1011
|
-
): Promise<T> {
|
|
1005
|
+
export async function getCached<T>(key: string, fetcher: () => Promise<T>, ttlMinutes: number = 60): Promise<T> {
|
|
1012
1006
|
// Check cache
|
|
1013
1007
|
const { rows } = await CacheTable.findRows({
|
|
1014
1008
|
filter: { key },
|
|
1015
1009
|
limit: 1,
|
|
1016
|
-
})
|
|
1010
|
+
})
|
|
1017
1011
|
|
|
1018
|
-
const cached = rows[0]
|
|
1012
|
+
const cached = rows[0]
|
|
1019
1013
|
if (cached && cached.expiresAt > new Date()) {
|
|
1020
|
-
return cached.value as T
|
|
1014
|
+
return cached.value as T
|
|
1021
1015
|
}
|
|
1022
1016
|
|
|
1023
1017
|
// Fetch new value
|
|
1024
|
-
const value = await fetcher()
|
|
1018
|
+
const value = await fetcher()
|
|
1025
1019
|
|
|
1026
1020
|
// Store in cache
|
|
1027
1021
|
await CacheTable.upsertRows({
|
|
@@ -1033,10 +1027,10 @@ export async function getCached<T>(
|
|
|
1033
1027
|
createdAt: new Date(),
|
|
1034
1028
|
},
|
|
1035
1029
|
],
|
|
1036
|
-
keyColumn:
|
|
1037
|
-
})
|
|
1030
|
+
keyColumn: 'key',
|
|
1031
|
+
})
|
|
1038
1032
|
|
|
1039
|
-
return value
|
|
1033
|
+
return value
|
|
1040
1034
|
}
|
|
1041
1035
|
```
|
|
1042
1036
|
|
|
@@ -1068,22 +1062,22 @@ When table schemas change:
|
|
|
1068
1062
|
```typescript
|
|
1069
1063
|
// Original table
|
|
1070
1064
|
export const UsersTable = new Table({
|
|
1071
|
-
name:
|
|
1065
|
+
name: 'UsersTable',
|
|
1072
1066
|
columns: {
|
|
1073
1067
|
name: z.string(),
|
|
1074
1068
|
email: z.string(),
|
|
1075
1069
|
},
|
|
1076
|
-
})
|
|
1070
|
+
})
|
|
1077
1071
|
|
|
1078
1072
|
// After adding a column - sync handles this automatically
|
|
1079
1073
|
export const UsersTable = new Table({
|
|
1080
|
-
name:
|
|
1074
|
+
name: 'UsersTable',
|
|
1081
1075
|
columns: {
|
|
1082
1076
|
name: z.string(),
|
|
1083
1077
|
email: z.string(),
|
|
1084
|
-
role: z.string().default(
|
|
1078
|
+
role: z.string().default('user'), // New column with default
|
|
1085
1079
|
},
|
|
1086
|
-
})
|
|
1080
|
+
})
|
|
1087
1081
|
```
|
|
1088
1082
|
|
|
1089
1083
|
**Important:** Adding columns with defaults is safe. Removing columns or changing types may require manual migration.
|
|
@@ -1093,18 +1087,18 @@ export const UsersTable = new Table({
|
|
|
1093
1087
|
For advanced scenarios, you can use the client directly:
|
|
1094
1088
|
|
|
1095
1089
|
```typescript
|
|
1096
|
-
import { Workflow } from
|
|
1090
|
+
import { Workflow } from '@botpress/runtime'
|
|
1097
1091
|
|
|
1098
1092
|
export const MigrateTablesWorkflow = new Workflow({
|
|
1099
|
-
name:
|
|
1093
|
+
name: 'migrateTables',
|
|
1100
1094
|
|
|
1101
1095
|
async handler({ client }) {
|
|
1102
1096
|
// Delete and recreate a table (use with caution!)
|
|
1103
|
-
await client._inner.deleteTable({ table:
|
|
1097
|
+
await client._inner.deleteTable({ table: 'MyTable' })
|
|
1104
1098
|
|
|
1105
1099
|
// Note: The table will be recreated on next sync
|
|
1106
1100
|
},
|
|
1107
|
-
})
|
|
1101
|
+
})
|
|
1108
1102
|
```
|
|
1109
1103
|
|
|
1110
1104
|
## Troubleshooting
|