@botpress/adk 1.7.19 → 1.8.1

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.
@@ -0,0 +1,6 @@
1
+ export { KnowledgeManager } from './manager.js';
2
+ export type { KnowledgeManagerOptions } from './manager.js';
3
+ export { KBSyncOperation } from './types.js';
4
+ export type { SyncOutputItem, SyncErrorItem, SyncOutput, LocalKnowledgeBase, KBSyncItem, KBSyncPlan, KBSyncOptions, KBSyncResult, WebsiteSyncInfo, OrphanedSource, OrphanedSourceStatus, SourceSyncStatus, FileChanges, } from './types.js';
5
+ export { KBSyncFormatter } from './sync-formatter.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/knowledge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,YAAY,EACV,cAAc,EACd,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,UAAU,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACZ,MAAM,YAAY,CAAA;AAGnB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,141 @@
1
+ import { Client } from '@botpress/client';
2
+ import { AgentProject } from '../agent-project/agent-project.js';
3
+ import { LocalKnowledgeBase, KBSyncPlan, KBSyncResult, KBSyncOptions, OrphanedSource } from './types.js';
4
+ type RemoteKnowledgeBase = Pick<Awaited<ReturnType<Client['listKnowledgeBases']>>['knowledgeBases'][number], 'id' | 'name' | 'tags'>;
5
+ export interface KnowledgeManagerOptions {
6
+ project: AgentProject;
7
+ botId?: string;
8
+ }
9
+ /**
10
+ * Manages knowledge base synchronization for ADK projects
11
+ */
12
+ export declare class KnowledgeManager {
13
+ private client?;
14
+ private botId?;
15
+ private project;
16
+ /** Cache of file hashes by directory path to avoid recalculating */
17
+ private fileHashCache;
18
+ constructor(options: KnowledgeManagerOptions);
19
+ /**
20
+ * Clear the file hash cache (call before a new sync operation)
21
+ */
22
+ clearHashCache(): void;
23
+ private getClient;
24
+ private assertBotId;
25
+ /**
26
+ * Format an error for display, including API response data if available
27
+ */
28
+ private formatError;
29
+ /**
30
+ * Get all knowledge bases from the project
31
+ */
32
+ getLocalKnowledgeBases(): LocalKnowledgeBase[];
33
+ /**
34
+ * Calculate content hash from individual file hashes
35
+ * This creates a deterministic hash of all file contents
36
+ */
37
+ private computeContentHash;
38
+ /**
39
+ * List all remote knowledge bases
40
+ */
41
+ private listRemoteKnowledgeBases;
42
+ /**
43
+ * Find remote KB by name
44
+ */
45
+ private findRemoteKB;
46
+ /**
47
+ * Create a new knowledge base
48
+ */
49
+ createKnowledgeBase(name: string): Promise<RemoteKnowledgeBase>;
50
+ /**
51
+ * Get remote KBs that don't exist locally (orphaned)
52
+ */
53
+ getOrphanedKBs(): Promise<RemoteKnowledgeBase[]>;
54
+ /**
55
+ * Get orphaned sources for a KB by listing files and extracting unique sourceIds from tags
56
+ * Returns sources that exist in remote files but not in local definition
57
+ */
58
+ getOrphanedSources(kbName: string, localSourceIds: string[]): Promise<OrphanedSource[]>;
59
+ /**
60
+ * Delete all files belonging to an orphaned source using direct sourceId tag query
61
+ */
62
+ deleteOrphanedSource(kbName: string, sourceId: string): Promise<{
63
+ deletedFiles: number;
64
+ errors: string[];
65
+ }>;
66
+ /**
67
+ * Clean up source tags from KB after deleting orphaned source
68
+ * Note: Botpress API merges tags, so we set to empty string to "delete" them
69
+ */
70
+ private cleanupSourceTags;
71
+ /**
72
+ * Delete a KB and all its associated files
73
+ */
74
+ deleteKnowledgeBase(kbId: string, kbName: string): Promise<{
75
+ deletedFiles: number;
76
+ }>;
77
+ /**
78
+ * Get stored hash for a specific source from KB tags
79
+ */
80
+ private getRemoteSourceHash;
81
+ /**
82
+ * Update source hash in KB tags after sync
83
+ */
84
+ private updateSourceHash;
85
+ /**
86
+ * Compute config hash for a data source (used for website sources)
87
+ */
88
+ private computeConfigHash;
89
+ /**
90
+ * Trigger website source sync by creating the builtin_knowledge_indexing workflow.
91
+ * This requires adk dev to be running as the workflow executes in the bot runtime.
92
+ */
93
+ syncWebsiteSource(kbName: string, force: boolean): Promise<{
94
+ workflowId: string;
95
+ }>;
96
+ /**
97
+ * Check if a KB has any website sources
98
+ */
99
+ hasWebsiteSources(kbName: string): boolean;
100
+ /**
101
+ * Get list of KB names that have website sources
102
+ */
103
+ getKBsWithWebsiteSources(): string[];
104
+ /**
105
+ * Compute content hash for a single directory source
106
+ */
107
+ private computeDirectorySourceHash;
108
+ /**
109
+ * Create a sync plan comparing local sources vs remote KB tags
110
+ * Uses per-source hashes stored in KB tags
111
+ */
112
+ createSyncPlan(): Promise<KBSyncPlan>;
113
+ /**
114
+ * Detect file changes for a single directory source
115
+ */
116
+ private detectDirectorySourceChanges;
117
+ /**
118
+ * Scan local files for a directory source and return their hashes
119
+ */
120
+ private scanLocalFileHashes;
121
+ /**
122
+ * Execute KB sync based on plan
123
+ * Directly uploads files to Botpress without requiring a running bot.
124
+ * For website sources that need sync, triggers the builtin_knowledge_indexing workflow.
125
+ */
126
+ executeSync(plan: KBSyncPlan, options?: KBSyncOptions): Promise<KBSyncResult>;
127
+ /**
128
+ * Sync a directory data source by uploading files directly
129
+ */
130
+ private syncDirectorySource;
131
+ /**
132
+ * List existing files in Botpress with given tags
133
+ */
134
+ private listExistingFiles;
135
+ /**
136
+ * Upload or update a file
137
+ */
138
+ private upsertFile;
139
+ }
140
+ export {};
141
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/knowledge/manager.ts"],"names":[],"mappings":"AAIA,OAAO,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oBAAoB,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IA0BtD;;;OAGG;YACW,iBAAiB;IAoB/B;;OAEG;IACG,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAyB1F;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;YACW,gBAAgB;IAc9B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;;OAGG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAaxF;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAM1C;;OAEG;IACH,wBAAwB,IAAI,MAAM,EAAE;IAMpC;;OAEG;YACW,0BAA0B;IAQxC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,UAAU,CAAC;IAuJ3C;;OAEG;YACW,4BAA4B;IAgD1C;;OAEG;YACW,mBAAmB;IA4BjC;;;;OAIG;IACG,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IA+IvF;;OAEG;YACW,mBAAmB;IA6GjC;;OAEG;YACW,iBAAiB;IAqB/B;;OAEG;YACW,UAAU;CAqDzB"}
@@ -0,0 +1,9 @@
1
+ import type { KBSyncPlan } from './types.js';
2
+ /**
3
+ * Plain text formatter for KB sync plan
4
+ * CLI-agnostic - the CLI should apply colors/styling
5
+ */
6
+ export declare class KBSyncFormatter {
7
+ static format(plan: KBSyncPlan, kbsWithWebsites?: string[]): string;
8
+ }
9
+ //# sourceMappingURL=sync-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-formatter.d.ts","sourceRoot":"","sources":["../../src/knowledge/sync-formatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAsB5C;;;GAGG;AACH,qBAAa,eAAe;IAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,eAAe,GAAE,MAAM,EAAO,GAAG,MAAM;CA0FxE"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Sync output from KB indexing workflow
3
+ * Mirrors the SyncOutput from runtime
4
+ */
5
+ export interface SyncOutputItem {
6
+ file: string;
7
+ name: string;
8
+ hash: string;
9
+ size: number;
10
+ }
11
+ export interface SyncErrorItem {
12
+ file: string;
13
+ error: string;
14
+ }
15
+ export interface SyncOutput {
16
+ processed: number;
17
+ added: SyncOutputItem[];
18
+ updated: SyncOutputItem[];
19
+ deleted: SyncOutputItem[];
20
+ errors: SyncErrorItem[];
21
+ }
22
+ /**
23
+ * Local knowledge base representation from project
24
+ */
25
+ export interface LocalKnowledgeBase {
26
+ name: string;
27
+ description?: string;
28
+ sourceCount: number;
29
+ }
30
+ /**
31
+ * Sync operation type for knowledge bases
32
+ */
33
+ export declare enum KBSyncOperation {
34
+ Sync = "sync",
35
+ Skip = "skip"
36
+ }
37
+ /**
38
+ * File changes detected during sync planning
39
+ */
40
+ export interface FileChanges {
41
+ added: string[];
42
+ modified: string[];
43
+ deleted: string[];
44
+ }
45
+ /**
46
+ * Sync status for a single data source
47
+ */
48
+ export interface SourceSyncStatus {
49
+ sourceId: string;
50
+ sourceType: 'directory' | 'website';
51
+ needsSync: boolean;
52
+ reason: string;
53
+ /** For directory sources, detailed file changes */
54
+ fileChanges?: FileChanges;
55
+ }
56
+ /**
57
+ * Represents an orphaned source (exists remotely but not in local definition)
58
+ */
59
+ export interface OrphanedSource {
60
+ sourceId: string;
61
+ fileCount: number;
62
+ }
63
+ /**
64
+ * Status for orphaned sources in the sync plan
65
+ */
66
+ export interface OrphanedSourceStatus {
67
+ sourceId: string;
68
+ fileCount: number;
69
+ willDelete: boolean;
70
+ }
71
+ /**
72
+ * Individual KB sync plan item
73
+ */
74
+ export interface KBSyncItem {
75
+ operation: KBSyncOperation;
76
+ kb: LocalKnowledgeBase;
77
+ reason: string;
78
+ /** Whether the KB needs to be created remotely first */
79
+ needsCreation?: boolean;
80
+ /** Per-source sync status */
81
+ sources?: SourceSyncStatus[];
82
+ /** Orphaned sources that exist remotely but not in local definition */
83
+ orphanedSources?: OrphanedSourceStatus[];
84
+ }
85
+ /**
86
+ * Sync plan for all knowledge bases
87
+ */
88
+ export interface KBSyncPlan {
89
+ items: KBSyncItem[];
90
+ toSync: number;
91
+ toSkip: number;
92
+ hasChanges: boolean;
93
+ /** Source-level counts */
94
+ sourcesToSync: number;
95
+ sourcesToSkip: number;
96
+ /** Number of orphaned sources to delete */
97
+ orphanedSourcesToDelete: number;
98
+ }
99
+ /**
100
+ * Options for KB sync execution
101
+ */
102
+ export interface KBSyncOptions {
103
+ /** Force sync even if config hash matches */
104
+ force?: boolean;
105
+ /** Timeout in ms for waiting for workflow completion (default: 300000 = 5 min) */
106
+ timeout?: number;
107
+ /** Auto-confirm operations without prompting */
108
+ autoConfirm?: boolean;
109
+ }
110
+ /**
111
+ * Website sync workflow info
112
+ */
113
+ export interface WebsiteSyncInfo {
114
+ kbName: string;
115
+ workflowId: string;
116
+ }
117
+ /**
118
+ * Result of KB sync execution
119
+ */
120
+ export interface KBSyncResult {
121
+ synced: Array<{
122
+ name: string;
123
+ result: SyncOutput;
124
+ }>;
125
+ skipped: Array<{
126
+ name: string;
127
+ reason: string;
128
+ }>;
129
+ failed: Array<{
130
+ name: string;
131
+ error: string;
132
+ }>;
133
+ /** Website sync workflows triggered (run asynchronously in bot runtime) */
134
+ websiteSyncs?: WebsiteSyncInfo[];
135
+ }
136
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
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,MAAM,CAAA;KAAE,CAAC,CAAA;IAChD,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC9C,2EAA2E;IAC3E,YAAY,CAAC,EAAE,eAAe,EAAE,CAAA;CACjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/adk",
3
- "version": "1.7.19",
3
+ "version": "1.8.1",
4
4
  "description": "Core ADK library for building AI agents on Botpress",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -47,7 +47,7 @@
47
47
  "@botpress/cli": "^4.23",
48
48
  "@botpress/client": "^1.27.2",
49
49
  "@botpress/cognitive": "^0.2.0",
50
- "@botpress/runtime": "^1.7.19",
50
+ "@botpress/runtime": "^1.8.1",
51
51
  "@botpress/sdk": "^4.18.1",
52
52
  "@bpinternal/yargs-extra": "^0.0.21",
53
53
  "@parcel/watcher": "^2.5.1",