@botpress/adk 1.14.0 → 1.14.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.
@@ -1 +1 @@
1
- {"version":3,"file":"client-wrapper.d.ts","sourceRoot":"","sources":["../../src/generators/client-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAShE,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAibhF"}
1
+ {"version":3,"file":"client-wrapper.d.ts","sourceRoot":"","sources":["../../src/generators/client-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAShE,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA6dhF"}
package/dist/index.js CHANGED
@@ -1,20 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- var __create = Object.create;
3
- var __getProtoOf = Object.getPrototypeOf;
4
2
  var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
3
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
4
  var __export = (target, all) => {
20
5
  for (var name in all)
@@ -666,7 +651,7 @@ var PRETTIER_CONFIG, formatCode = async (code, filepath) => {
666
651
  `));
667
652
  return code;
668
653
  }
669
- }, ADK_VERSION = "1.14.0", relative2 = (from, to) => {
654
+ }, ADK_VERSION = "1.14.1", relative2 = (from, to) => {
670
655
  const fromDir = path10.dirname(from);
671
656
  const relative3 = path10.relative(fromDir, to);
672
657
  return relative3.startsWith(".") ? relative3 : `./${relative3}`;
@@ -809,7 +794,7 @@ var init_integration_action_types = __esm(() => {
809
794
  var require_package = __commonJS((exports, module) => {
810
795
  module.exports = {
811
796
  name: "@botpress/adk",
812
- version: "1.14.0",
797
+ version: "1.14.1",
813
798
  description: "Core ADK library for building AI agents on Botpress",
814
799
  type: "module",
815
800
  main: "dist/index.js",
@@ -856,7 +841,7 @@ var require_package = __commonJS((exports, module) => {
856
841
  "@botpress/cli": "^5.2.0",
857
842
  "@botpress/client": "^1.28.0",
858
843
  "@botpress/cognitive": "^0.3.3",
859
- "@botpress/runtime": "^1.14.0",
844
+ "@botpress/runtime": "^1.14.1",
860
845
  "@botpress/sdk": "^5.1.0",
861
846
  "@bpinternal/jex": "^1.2.4",
862
847
  "@bpinternal/yargs-extra": "^0.0.21",
@@ -6408,7 +6393,7 @@ class AgentProjectGenerator {
6408
6393
  deploy: "adk deploy"
6409
6394
  },
6410
6395
  dependencies: {
6411
- "@botpress/runtime": `^${"1.14.0"}`
6396
+ "@botpress/runtime": `^${"1.14.1"}`
6412
6397
  },
6413
6398
  devDependencies: {
6414
6399
  typescript: "^5.9.3"
@@ -7022,6 +7007,8 @@ Description: ${tag?.description}`);
7022
7007
  init_utils();
7023
7008
  init_fs();
7024
7009
  import path18 from "path";
7010
+ import crypto3 from "crypto";
7011
+ import { readFile as readFile3 } from "fs/promises";
7025
7012
  import { BuiltInWorkflows as BuiltInWorkflows2 } from "@botpress/runtime/internal";
7026
7013
  function isBuiltinWorkflow(name) {
7027
7014
  return !!Object.values(BuiltInWorkflows2).find((x) => x.name === name);
@@ -7032,57 +7019,32 @@ async function generateClientWrapper(project) {
7032
7019
  if (action.definition.attributes?.visibility === "hidden") {
7033
7020
  continue;
7034
7021
  }
7035
- try {
7036
- if (action.path === "<adk:builtin>") {
7037
- actionTypes.push({
7038
- name: action.definition.name,
7039
- inputType: "any",
7040
- outputType: "any"
7041
- });
7042
- continue;
7043
- }
7044
- const absolutePath = path18.join(project.path, action.path);
7045
- const actionModule = await import(`${absolutePath}?t=${Date.now()}`);
7046
- const actionInstance = actionModule[action.export] || actionModule.default;
7047
- if (actionInstance && actionInstance.input && actionInstance.output) {
7048
- const inputType = actionInstance.input.toTypescriptType ? actionInstance.input.toTypescriptType() : "any";
7049
- const outputType = actionInstance.output.toTypescriptType ? actionInstance.output.toTypescriptType() : "any";
7050
- actionTypes.push({
7051
- name: action.definition.name,
7052
- inputType,
7053
- outputType
7054
- });
7055
- }
7056
- } catch (error) {
7057
- console.warn(`Warning: Could not process action ${action.definition.name}:`, error);
7022
+ if (action.path === "<adk:builtin>") {
7058
7023
  actionTypes.push({
7059
7024
  name: action.definition.name,
7060
- inputType: "any",
7061
- outputType: "any"
7025
+ path: "",
7026
+ export: "",
7027
+ isBuiltin: true
7062
7028
  });
7029
+ continue;
7063
7030
  }
7031
+ actionTypes.push({
7032
+ name: action.definition.name,
7033
+ path: action.path,
7034
+ export: action.export,
7035
+ isBuiltin: false
7036
+ });
7064
7037
  }
7065
7038
  const workflowTypes = [];
7066
7039
  for (const workflow of project.workflows) {
7067
- try {
7068
- if (isBuiltinWorkflow(workflow.definition.name)) {
7069
- continue;
7070
- }
7071
- const workflowPath = path18.join(project.path, workflow.path);
7072
- const workflowModule = await import(`${workflowPath}?t=${Date.now()}`);
7073
- const workflowInstance = workflowModule[workflow.export] || workflowModule.default;
7074
- if (workflowInstance) {
7075
- const inputType = workflowInstance.inputSchema ? workflowInstance.inputSchema.toTypescriptType?.() || "any" : "{}";
7076
- const outputType = workflowInstance.outputSchema ? workflowInstance.outputSchema.toTypescriptType?.() || "any" : "{}";
7077
- workflowTypes.push({
7078
- name: workflow.definition.name,
7079
- inputType,
7080
- outputType
7081
- });
7082
- }
7083
- } catch (error) {
7084
- console.warn(`Warning: Could not process workflow ${workflow.definition.name}:`, error);
7040
+ if (isBuiltinWorkflow(workflow.definition.name)) {
7041
+ continue;
7085
7042
  }
7043
+ workflowTypes.push({
7044
+ name: workflow.definition.name,
7045
+ path: workflow.path,
7046
+ export: workflow.export
7047
+ });
7086
7048
  }
7087
7049
  const tableTypes = [];
7088
7050
  for (const table of project.tables) {
@@ -7118,6 +7080,21 @@ async function generateClientWrapper(project) {
7118
7080
  console.warn(`Warning: Could not process table ${table.definition.name}:`, error);
7119
7081
  }
7120
7082
  }
7083
+ const actionImportMap = new Map;
7084
+ let actionImportIndex = 0;
7085
+ const actionImports = actionTypes.filter((action) => !action.isBuiltin).map((action) => {
7086
+ const importPath = action.path.replace(/\.ts$/, ".js");
7087
+ actionImportMap.set(action.name, actionImportIndex);
7088
+ const importStatement = `import type * as Action${actionImportIndex} from '../${importPath}'`;
7089
+ actionImportIndex++;
7090
+ return importStatement;
7091
+ }).join(`
7092
+ `);
7093
+ const workflowImports = workflowTypes.map((workflow, index) => {
7094
+ const importPath = workflow.path.replace(/\.ts$/, ".js");
7095
+ return `import type * as Workflow${index} from '../${importPath}'`;
7096
+ }).join(`
7097
+ `);
7121
7098
  const content = `
7122
7099
  // @ts-nocheck
7123
7100
  ////////////////////////////////////////////////////////
@@ -7128,6 +7105,10 @@ async function generateClientWrapper(project) {
7128
7105
  ////////////////////////////////////////////////////////
7129
7106
 
7130
7107
  import type { Client, Workflow } from '@botpress/client'
7108
+ import type { z } from '@botpress/sdk'
7109
+
7110
+ ${actionImports}
7111
+ ${workflowImports}
7131
7112
 
7132
7113
  // Utility type to simplify complex types
7133
7114
  type Simplify<T> = T extends (...args: infer A) => infer R
@@ -7195,12 +7176,23 @@ export interface AdkClient {
7195
7176
  * Typed action calls
7196
7177
  */
7197
7178
  actions: {
7198
- ${actionTypes.map((action) => `
7179
+ ${actionTypes.map((action) => {
7180
+ if (action.isBuiltin) {
7181
+ return `
7199
7182
  /**
7200
7183
  * Call action: ${action.name}
7201
7184
  */
7202
- '${action.name}': (input: ${action.inputType}) => Promise<${action.outputType}>
7203
- `).join(`
7185
+ '${action.name}': (input: any) => Promise<any>
7186
+ `;
7187
+ }
7188
+ const importIndex = actionImportMap.get(action.name);
7189
+ return `
7190
+ /**
7191
+ * Call action: ${action.name}
7192
+ */
7193
+ '${action.name}': (input: z.input<typeof Action${importIndex}.default.input>) => Promise<z.infer<typeof Action${importIndex}.default.output>>
7194
+ `;
7195
+ }).join(`
7204
7196
  `)}
7205
7197
  }
7206
7198
 
@@ -7208,20 +7200,23 @@ export interface AdkClient {
7208
7200
  * Typed workflow operations
7209
7201
  */
7210
7202
  workflows: {
7211
- ${workflowTypes.map((workflow) => `
7203
+ ${workflowTypes.map((workflow, index) => {
7204
+ const inputType = `z.input<typeof Workflow${index}.default.inputSchema>`;
7205
+ const outputType = `z.infer<typeof Workflow${index}.default.outputSchema>`;
7206
+ return `
7212
7207
  '${workflow.name}': {
7213
7208
  /**
7214
7209
  * Create workflow: ${workflow.name}
7215
7210
  */
7216
- createWorkflow: (params: Omit<ParamCreateWorkflow, 'name' | 'input'> & { input?: ${workflow.inputType} }) => Promise<Omit<CreateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
7211
+ createWorkflow: (params: Omit<ParamCreateWorkflow, 'name' | 'input'> & { input?: ${inputType} }) => Promise<Omit<CreateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${inputType}, ${outputType}> }>
7217
7212
  /**
7218
7213
  * Get workflow by ID
7219
7214
  */
7220
- getWorkflow: (params: ParamGetWorkflow) => Promise<Omit<GetWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
7215
+ getWorkflow: (params: ParamGetWorkflow) => Promise<Omit<GetWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${inputType}, ${outputType}> }>
7221
7216
  /**
7222
7217
  * Update workflow
7223
7218
  */
7224
- updateWorkflow: (params: Omit<ParamUpdateWorkflow, 'output'> & { output?: ${workflow.outputType} }) => Promise<Omit<UpdateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
7219
+ updateWorkflow: (params: Omit<ParamUpdateWorkflow, 'output'> & { output?: ${outputType} }) => Promise<Omit<UpdateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${inputType}, ${outputType}> }>
7225
7220
  /**
7226
7221
  * Delete workflow
7227
7222
  */
@@ -7229,9 +7224,10 @@ export interface AdkClient {
7229
7224
  /**
7230
7225
  * Get or create workflow with deduplication key
7231
7226
  */
7232
- getOrCreateWorkflow: (params: Omit<ParamGetOrCreateWorkflow, 'name' | 'input'> & { input?: ${workflow.inputType} }) => Promise<Omit<GetOrCreateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${workflow.inputType}, ${workflow.outputType}> }>
7227
+ getOrCreateWorkflow: (params: Omit<ParamGetOrCreateWorkflow, 'name' | 'input'> & { input?: ${inputType} }) => Promise<Omit<GetOrCreateWorkflowResponse, 'workflow'> & { workflow: TypedWorkflow<${inputType}, ${outputType}> }>
7233
7228
  }
7234
- `).join(`
7229
+ `;
7230
+ }).join(`
7235
7231
  `)}
7236
7232
  }
7237
7233
 
@@ -7310,12 +7306,12 @@ export function createAdkClient(client: Client): AdkClient {
7310
7306
  return {
7311
7307
  actions: {
7312
7308
  ${actionTypes.map((action) => `
7313
- '${action.name}': async (input: ${action.inputType}) => {
7309
+ '${action.name}': async (input) => {
7314
7310
  const response = await client.callAction({
7315
7311
  type: '${action.name}',
7316
7312
  input,
7317
7313
  })
7318
- return response.output as ${action.outputType}
7314
+ return response.output as any
7319
7315
  }
7320
7316
  `).join(`,
7321
7317
  `)}
@@ -7399,7 +7395,16 @@ export function createAdkClient(client: Client): AdkClient {
7399
7395
  }
7400
7396
  `;
7401
7397
  const clientWrapperPath = path18.join(project.path, ".adk", "client.ts");
7402
- await createFile(clientWrapperPath, await formatCode(content));
7398
+ const formattedContent = await formatCode(content);
7399
+ const contentHash = crypto3.createHash("sha256").update(formattedContent.replace(/\/\/ Generated at: .+\n/, "")).digest("hex");
7400
+ try {
7401
+ const existingContent = await readFile3(clientWrapperPath, "utf-8");
7402
+ const existingHash = crypto3.createHash("sha256").update(existingContent.replace(/\/\/ Generated at: .+\n/, "")).digest("hex");
7403
+ if (contentHash === existingHash) {
7404
+ return;
7405
+ }
7406
+ } catch {}
7407
+ await createFile(clientWrapperPath, formattedContent);
7403
7408
  }
7404
7409
  // src/bot-generator/generator.ts
7405
7410
  import dedent from "dedent";
@@ -7409,7 +7414,7 @@ import path34 from "path";
7409
7414
 
7410
7415
  // src/generators/interface-types.ts
7411
7416
  import { transforms as transforms2 } from "@botpress/sdk";
7412
- import crypto3 from "crypto";
7417
+ import crypto4 from "crypto";
7413
7418
  import path19 from "path";
7414
7419
  init_utils();
7415
7420
  var sameMajorVersion = (a, b) => {
@@ -7422,7 +7427,7 @@ var getIntegrationInterface = (integration, int) => {
7422
7427
  };
7423
7428
  var getInterfaceHash = (int, integrations) => {
7424
7429
  const versions = integrations.filter((x) => !!getIntegrationInterface(x.definition, int)).map((x) => `${x.definition.id}|${x.definition.version}|${x.definition.updatedAt}|${x.alias}`).sort().join("|");
7425
- return crypto3.createHash("sha256").update(`${int.id}|${int.version}|${int.updatedAt}|${versions}`).digest("hex");
7430
+ return crypto4.createHash("sha256").update(`${int.id}|${int.version}|${int.updatedAt}|${versions}`).digest("hex");
7426
7431
  };
7427
7432
  var getInterfaceNames = (int) => ({
7428
7433
  name: camelCase(int.name),
@@ -8921,9 +8926,9 @@ declare module "@botpress/runtime/_types/state" {
8921
8926
  if (project.config?.workflow?.tags) {
8922
8927
  Object.assign(workflowTags, project.config.workflow.tags);
8923
8928
  }
8924
- const crypto4 = __require("crypto");
8929
+ const crypto5 = __require("crypto");
8925
8930
  const hashString = (str) => {
8926
- return crypto4.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
8931
+ return crypto5.createHash("md5").update(str).digest("hex").substring(0, 5).toUpperCase();
8927
8932
  };
8928
8933
  for (const trigger of project.triggers) {
8929
8934
  const triggerName = trigger.definition.name;
@@ -10174,7 +10179,7 @@ class TableManager {
10174
10179
  }
10175
10180
  }
10176
10181
  // src/knowledge/manager.ts
10177
- import crypto4 from "crypto";
10182
+ import crypto5 from "crypto";
10178
10183
  import path35 from "path";
10179
10184
  import fs17 from "fs/promises";
10180
10185
  import { glob } from "glob";
@@ -10265,7 +10270,7 @@ class KnowledgeManager {
10265
10270
  const sortedEntries = Object.entries(fileHashes).sort(([a], [b]) => a.localeCompare(b));
10266
10271
  const combined = sortedEntries.map(([filePath, hash]) => `${filePath}:${hash}`).join(`
10267
10272
  `);
10268
- return crypto4.createHash("sha256").update(combined).digest("hex");
10273
+ return crypto5.createHash("sha256").update(combined).digest("hex");
10269
10274
  }
10270
10275
  async listRemoteKnowledgeBases() {
10271
10276
  const client = await this.getClient();
@@ -10380,7 +10385,7 @@ class KnowledgeManager {
10380
10385
  }
10381
10386
  computeConfigHash(config) {
10382
10387
  const sortedConfig = JSON.stringify(config, Object.keys(config).sort());
10383
- return crypto4.createHash("sha256").update(sortedConfig).digest("hex");
10388
+ return crypto5.createHash("sha256").update(sortedConfig).digest("hex");
10384
10389
  }
10385
10390
  async syncWebsiteSource(kbName, kbId, force) {
10386
10391
  const client = await this.getClient();
@@ -10634,7 +10639,7 @@ class KnowledgeManager {
10634
10639
  for (const file of files) {
10635
10640
  const relPath = path35.relative(directory, file);
10636
10641
  const content = await fs17.readFile(file);
10637
- hashes[relPath] = crypto4.createHash("sha256").update(content).digest("hex");
10642
+ hashes[relPath] = crypto5.createHash("sha256").update(content).digest("hex");
10638
10643
  }
10639
10644
  this.fileHashCache.set(directory, hashes);
10640
10645
  return hashes;
@@ -10838,7 +10843,7 @@ class KnowledgeManager {
10838
10843
  async upsertFile(client, local, dsId, tags, force, cachedHash) {
10839
10844
  const key = `data_source://document/${dsId}/${local.rel}`;
10840
10845
  const content = await fs17.readFile(local.abs);
10841
- const hash = cachedHash ?? crypto4.createHash("sha256").update(content).digest("hex");
10846
+ const hash = cachedHash ?? crypto5.createHash("sha256").update(content).digest("hex");
10842
10847
  try {
10843
10848
  const { file } = await client.getFile({ id: key });
10844
10849
  if (!force && isFileMetadata(file.metadata) && file.metadata.hash === hash) {
@@ -11863,4 +11868,4 @@ export {
11863
11868
  AgentProject
11864
11869
  };
11865
11870
 
11866
- //# debugId=B2A1E741C14E701164756E2164756E21
11871
+ //# debugId=9C7E68110BCAF64064756E2164756E21