@botpress/runtime 1.11.9 → 1.12.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.
package/dist/library.js CHANGED
@@ -48,7 +48,7 @@ var init_define_BUILD = __esm({
48
48
  var define_PACKAGE_VERSIONS_default;
49
49
  var init_define_PACKAGE_VERSIONS = __esm({
50
50
  "<define:__PACKAGE_VERSIONS__>"() {
51
- define_PACKAGE_VERSIONS_default = { runtime: "1.11.9", adk: "1.11.9", sdk: "4.20.2", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.12.1", adk: "1.12.1", sdk: "4.20.2", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -34045,12 +34045,12 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
34045
34045
  input: z2.string().describe("The query to search for.").min(1).max(1024),
34046
34046
  output: z2.string().describe("The search results."),
34047
34047
  handler: async (query) => {
34048
- const client = context.get("client");
34048
+ const client2 = context.get("client");
34049
34049
  const citations = context.get("citations");
34050
- if (!client) {
34050
+ if (!client2) {
34051
34051
  throw new Error("Client is not available in this context. Make sure to run in a context with a client.");
34052
34052
  }
34053
- const { passages } = await client.searchFiles({
34053
+ const { passages } = await client2.searchFiles({
34054
34054
  query,
34055
34055
  withContext: true,
34056
34056
  includeBreadcrumb: true,
@@ -34431,9 +34431,9 @@ var init_actions = __esm({
34431
34431
  return handler;
34432
34432
  }
34433
34433
  let integrations;
34434
- let client;
34434
+ let client2;
34435
34435
  integrations ??= context.get("integrations", { optional: true });
34436
- client ??= context.get("client", { optional: true });
34436
+ client2 ??= context.get("client", { optional: true });
34437
34437
  const integrationName = propertyName.replace("__", "/");
34438
34438
  return new Proxy(
34439
34439
  {},
@@ -34443,19 +34443,19 @@ var init_actions = __esm({
34443
34443
  return void 0;
34444
34444
  }
34445
34445
  integrations ??= context.get("integrations", { optional: true });
34446
- client ??= context.get("client", { optional: true });
34446
+ client2 ??= context.get("client", { optional: true });
34447
34447
  const integration = integrations.find((i) => i.alias === integrationName);
34448
34448
  const actionDef = integration?.definition.actions?.[actionName];
34449
34449
  const handler = async (params) => {
34450
34450
  integrations ??= context.get("integrations", { optional: true });
34451
- client ??= context.get("client", { optional: true });
34451
+ client2 ??= context.get("client", { optional: true });
34452
34452
  if (!integration || !actionDef) {
34453
34453
  throw new Error(`Could not find integration "${integrationName}" and action "${actionName}"`);
34454
34454
  }
34455
34455
  if (!integration.definition.actions?.[actionName]) {
34456
34456
  throw new Error(`Action "${actionName}" not found in integration "${integrationName}"`);
34457
34457
  }
34458
- return client.callAction({
34458
+ return client2.callAction({
34459
34459
  type: `${integration.alias}:${actionName}`,
34460
34460
  input: params
34461
34461
  }).then((res) => res.output);
@@ -35107,7 +35107,7 @@ var init_workflow = __esm({
35107
35107
  * @returns The workflow instance
35108
35108
  */
35109
35109
  async getOrCreate(props) {
35110
- const client = context.get("client");
35110
+ const client2 = context.get("client");
35111
35111
  const statuses = props.statuses || ["pending", "in_progress", "listening", "paused"];
35112
35112
  const validatedInput = this._inputSchema.parse(props.input);
35113
35113
  const tags = {};
@@ -35125,10 +35125,10 @@ var init_workflow = __esm({
35125
35125
  timeoutAt: new Date(Date.now() + (this.timeout ?? (0, import_ms.default)("5m"))).toISOString(),
35126
35126
  ...discriminator && { discriminateBy: { tags: discriminator } }
35127
35127
  };
35128
- let { workflow } = await client._inner.getOrCreateWorkflow(createArgs);
35128
+ let { workflow } = await client2._inner.getOrCreateWorkflow(createArgs);
35129
35129
  if (props.key && !statuses.includes(workflow.status)) {
35130
- await client._inner.deleteWorkflow({ id: workflow.id });
35131
- ({ workflow } = await client._inner.getOrCreateWorkflow(createArgs));
35130
+ await client2._inner.deleteWorkflow({ id: workflow.id });
35131
+ ({ workflow } = await client2._inner.getOrCreateWorkflow(createArgs));
35132
35132
  }
35133
35133
  return await BaseWorkflowInstance.load({
35134
35134
  id: workflow.id,
@@ -35146,9 +35146,9 @@ var init_workflow = __esm({
35146
35146
  * }
35147
35147
  */
35148
35148
  async provide(event, data) {
35149
- const client = context.get("client");
35149
+ const client2 = context.get("client");
35150
35150
  const { workflowId, stepName } = event.payload;
35151
- const state = createWorkflowExecutionState(client._inner, workflowId);
35151
+ const state = createWorkflowExecutionState(client2._inner, workflowId);
35152
35152
  await state.load();
35153
35153
  if (!state.value) {
35154
35154
  throw new Error(`Workflow execution state not found for workflow ${workflowId}`);
@@ -35167,7 +35167,7 @@ var init_workflow = __esm({
35167
35167
  }
35168
35168
  state.value.revision++;
35169
35169
  await state.save();
35170
- await client.createEvent({
35170
+ await client2.createEvent({
35171
35171
  type: WorkflowContinueEvent.name,
35172
35172
  workflowId,
35173
35173
  payload: {}
@@ -35175,10 +35175,10 @@ var init_workflow = __esm({
35175
35175
  }
35176
35176
  async start(input) {
35177
35177
  const validatedInput = this._inputSchema.parse(input);
35178
- const client = context.get("client");
35178
+ const client2 = context.get("client");
35179
35179
  const event = context.get("event", { optional: true });
35180
35180
  const workflow = context.get("workflow", { optional: true });
35181
- const res = await client._inner.createWorkflow({
35181
+ const res = await client2._inner.createWorkflow({
35182
35182
  name: this.name,
35183
35183
  status: event ? "in_progress" : "pending",
35184
35184
  eventId: event?.id,
@@ -35432,8 +35432,8 @@ var init_action = __esm({
35432
35432
  /**
35433
35433
  * Execute the action with input validation and output validation
35434
35434
  */
35435
- async execute({ input, client }) {
35436
- return await this.handler({ input, client });
35435
+ async execute({ input, client: client2 }) {
35436
+ return await this.handler({ input, client: client2 });
35437
35437
  }
35438
35438
  };
35439
35439
  }
@@ -35499,9 +35499,9 @@ var init_computed_columns = __esm({
35499
35499
  isFinished: z9.boolean(),
35500
35500
  rows: z9.array(z9.any())
35501
35501
  }),
35502
- handler: async ({ input, client }) => {
35502
+ handler: async ({ input, client: client2 }) => {
35503
35503
  const { tableId, requests } = input;
35504
- const { table: remoteTable } = await client._inner.getTable({ table: tableId });
35504
+ const { table: remoteTable } = await client2._inner.getTable({ table: tableId });
35505
35505
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
35506
35506
  async function computeRow(row, columnsToRecompute) {
35507
35507
  const newRow = { id: row.id };
@@ -35574,7 +35574,35 @@ __export(adk_exports, {
35574
35574
  register: () => register,
35575
35575
  registerIntegration: () => registerIntegration
35576
35576
  });
35577
+ import { BotSpecificClient } from "@botpress/sdk";
35577
35578
  import { Zai } from "@botpress/zai";
35579
+ import { Cognitive as Cognitive2 } from "@botpress/cognitive";
35580
+ import { Client } from "@botpress/client";
35581
+ function getStandaloneCognitive() {
35582
+ return getSingleton("__ADK_GLOBAL_STANDALONE_COGNITIVE", () => {
35583
+ const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
35584
+ if (!token) {
35585
+ throw new Error(
35586
+ 'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
35587
+ );
35588
+ }
35589
+ const botId = process.env.ADK_BOT_ID;
35590
+ if (!botId) {
35591
+ throw new Error('No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".');
35592
+ }
35593
+ const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
35594
+ const vanillaClient = new Client({
35595
+ token,
35596
+ apiUrl,
35597
+ botId
35598
+ });
35599
+ const botClient = new BotSpecificClient(vanillaClient);
35600
+ return new Cognitive2({
35601
+ client: botClient,
35602
+ __experimental_beta: true
35603
+ });
35604
+ });
35605
+ }
35578
35606
  function initialize(options) {
35579
35607
  const state = getState();
35580
35608
  if (state.initialized) {
@@ -35662,8 +35690,10 @@ var init_adk = __esm({
35662
35690
  return Environment;
35663
35691
  },
35664
35692
  get zai() {
35693
+ const contextCognitive = context.get("cognitive", { optional: true });
35694
+ const cognitive = contextCognitive ?? getStandaloneCognitive();
35665
35695
  return new Zai({
35666
- client: context.get("cognitive"),
35696
+ client: cognitive,
35667
35697
  modelId: Array.isArray(adk.project.config.defaultModels.zai) ? adk.project.config.defaultModels.zai[0] ?? "auto" : adk.project.config.defaultModels.zai
35668
35698
  });
35669
35699
  },
@@ -35688,6 +35718,29 @@ var init_adk = __esm({
35688
35718
  conversations: state.primitives.conversations,
35689
35719
  triggers: state.primitives.triggers
35690
35720
  };
35721
+ },
35722
+ async execute(props) {
35723
+ const contextCognitive = context.get("cognitive", { optional: true });
35724
+ const cognitive = contextCognitive ?? getStandaloneCognitive();
35725
+ const defaultModel = adk.project.config.defaultModels.autonomous;
35726
+ const { execute: llmz_execute, getValue: getValue2 } = await import("llmz");
35727
+ return llmz_execute({
35728
+ client: cognitive,
35729
+ instructions: props.instructions,
35730
+ ...props.tools && { tools: props.tools },
35731
+ ...props.objects && { objects: props.objects },
35732
+ ...props.exits && { exits: props.exits },
35733
+ ...props.signal && { signal: props.signal },
35734
+ temperature: async (ctx) => props.temperature ? await getValue2(props.temperature, ctx) : 0.7,
35735
+ model: async (ctx) => props.model ? await getValue2(props.model, ctx) : defaultModel,
35736
+ options: { loop: props.iterations ?? 10 },
35737
+ ...props.hooks?.onTrace && { onTrace: props.hooks.onTrace },
35738
+ ...props.hooks?.onIterationEnd && { onIterationEnd: props.hooks.onIterationEnd },
35739
+ ...props.hooks?.onBeforeTool && { onBeforeTool: props.hooks.onBeforeTool },
35740
+ ...props.hooks?.onAfterTool && { onAfterTool: props.hooks.onAfterTool },
35741
+ ...props.hooks?.onBeforeExecution && { onBeforeExecution: props.hooks.onBeforeExecution },
35742
+ ...props.hooks?.onExit && { onExit: props.hooks.onExit }
35743
+ });
35691
35744
  }
35692
35745
  };
35693
35746
  }
@@ -35729,7 +35782,7 @@ var init_workflow_utils = __esm({
35729
35782
  init_runtime();
35730
35783
  init_events();
35731
35784
  updateWorkflow = async (props) => {
35732
- const client = context.get("client");
35785
+ const client2 = context.get("client");
35733
35786
  const workflowId = props.id;
35734
35787
  const workflowsToUpdate = [];
35735
35788
  const ctxWorkflow = context.get("workflow", { optional: true });
@@ -35748,7 +35801,7 @@ var init_workflow_utils = __esm({
35748
35801
  if (workflowAlreadyDone) {
35749
35802
  return { workflow: workflowAlreadyDone };
35750
35803
  }
35751
- const response = await client.updateWorkflow(props);
35804
+ const response = await client2.updateWorkflow(props);
35752
35805
  for (const wf of workflowsToUpdate) {
35753
35806
  Object.assign(wf, response.workflow);
35754
35807
  }
@@ -35986,9 +36039,9 @@ var init_workflow_step = __esm({
35986
36039
  async () => {
35987
36040
  const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
35988
36041
  if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms3 || ms3 >= 1e4) {
35989
- const client = context.get("client");
36042
+ const client2 = context.get("client");
35990
36043
  const workflowControlContext = context.get("workflowControlContext");
35991
- await client.createEvent({
36044
+ await client2.createEvent({
35992
36045
  type: WorkflowContinueEvent.name,
35993
36046
  payload: {},
35994
36047
  workflowId: workflowControlContext.workflow.id,
@@ -36024,13 +36077,13 @@ var init_workflow_step = __esm({
36024
36077
  return await _step(
36025
36078
  name,
36026
36079
  async () => {
36027
- const client = context.get("client");
36080
+ const client2 = context.get("client");
36028
36081
  const state = createWorkflowExecutionState(
36029
36082
  context.get("client")._inner,
36030
36083
  workflowControlContext.workflow.id
36031
36084
  );
36032
36085
  assert(state.value, "State is not loaded");
36033
- const { workflow } = await client.getWorkflow({ id: workflowId });
36086
+ const { workflow } = await client2.getWorkflow({ id: workflowId });
36034
36087
  if (isWorkflowFinished(workflow.status)) {
36035
36088
  return workflow;
36036
36089
  }
@@ -36118,7 +36171,7 @@ var init_workflow_step = __esm({
36118
36171
  actualStepName,
36119
36172
  async () => {
36120
36173
  const workflowControlContext = context.get("workflowControlContext");
36121
- const client = context.get("client");
36174
+ const client2 = context.get("client");
36122
36175
  if (!workflowControlContext.workflow.conversationId) {
36123
36176
  throw new Error(`Cannot request data: workflow ${workflowControlContext.workflow.id} has no conversationId`);
36124
36177
  }
@@ -36132,14 +36185,14 @@ var init_workflow_step = __esm({
36132
36185
  `Request "${request}" not found in workflow "${workflowDef.name}". Available requests: ${Object.keys(workflowDef._requestsSchemas || {}).join(", ") || "none"}`
36133
36186
  );
36134
36187
  }
36135
- const state = createWorkflowExecutionState(client._inner, workflowControlContext.workflow.id);
36188
+ const state = createWorkflowExecutionState(client2._inner, workflowControlContext.workflow.id);
36136
36189
  if (!state.value) {
36137
36190
  throw new Error("Workflow execution state not loaded");
36138
36191
  }
36139
36192
  if (state.value.steps?.[actualStepName]?.output !== void 0) {
36140
36193
  return requestSchema.parse(state.value.steps[actualStepName].output);
36141
36194
  }
36142
- await client.createEvent({
36195
+ await client2.createEvent({
36143
36196
  type: WorkflowDataRequestEvent2.name,
36144
36197
  conversationId: workflowControlContext.workflow.conversationId,
36145
36198
  payload: {
@@ -36169,7 +36222,7 @@ var init_workflow_step = __esm({
36169
36222
 
36170
36223
  // src/primitives/workflow-cancellation-monitor.ts
36171
36224
  function startWorkflowCancellationMonitor(props) {
36172
- const { client, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
36225
+ const { client: client2, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
36173
36226
  if (abortSignal.aborted) {
36174
36227
  return () => {
36175
36228
  };
@@ -36180,7 +36233,7 @@ function startWorkflowCancellationMonitor(props) {
36180
36233
  return;
36181
36234
  }
36182
36235
  try {
36183
- const { workflow } = await client.getWorkflow({ id: workflowId });
36236
+ const { workflow } = await client2.getWorkflow({ id: workflowId });
36184
36237
  const isTerminated = workflow.status === "cancelled" || workflow.status === "failed" || workflow.status === "timedout";
36185
36238
  if (isTerminated) {
36186
36239
  workflowControlContext.aborted = true;
@@ -36224,10 +36277,10 @@ function createStepSignal() {
36224
36277
  [StepSymbol]: true
36225
36278
  };
36226
36279
  }
36227
- function createWorkflowExecutionState(client, workflowId) {
36280
+ function createWorkflowExecutionState(client2, workflowId) {
36228
36281
  return TrackedState.create({
36229
36282
  type: "workflow",
36230
- client,
36283
+ client: client2,
36231
36284
  id: workflowId,
36232
36285
  schema: workflowExecutionContextSchema,
36233
36286
  name: BUILT_IN_STATES.workflowSteps
@@ -36285,18 +36338,18 @@ var init_workflow_instance = __esm({
36285
36338
  TrackedState;
36286
36339
  // @internal
36287
36340
  TrackedTags;
36288
- constructor(workflow, client) {
36341
+ constructor(workflow, client2) {
36289
36342
  const definition = adk.project.workflows.find((w) => w.name === workflow.name);
36290
36343
  this.TrackedState = TrackedState.create({
36291
36344
  type: "workflow",
36292
- client: client._inner,
36345
+ client: client2._inner,
36293
36346
  id: workflow.id,
36294
36347
  schema: definition?.stateSchema,
36295
36348
  name: BUILT_IN_STATES.workflowState
36296
36349
  });
36297
36350
  this.TrackedTags = TrackedTags.create({
36298
36351
  type: "workflow",
36299
- client: client._inner,
36352
+ client: client2._inner,
36300
36353
  id: workflow.id,
36301
36354
  initialTags: workflow.tags
36302
36355
  });
@@ -36306,7 +36359,7 @@ var init_workflow_instance = __esm({
36306
36359
  this.input = workflow.input;
36307
36360
  this.createdAt = new Date(workflow.createdAt);
36308
36361
  this.updatedAt = new Date(workflow.updatedAt);
36309
- this.client = client;
36362
+ this.client = client2;
36310
36363
  this.workflow = workflow;
36311
36364
  }
36312
36365
  get tags() {
@@ -36327,19 +36380,19 @@ var init_workflow_instance = __esm({
36327
36380
  }
36328
36381
  static Primitive = "workflow_instance";
36329
36382
  static async load(props) {
36330
- const client = context.get("client");
36331
- const workflow = props.workflow ? props.workflow : await client.getWorkflow({ id: props.id }).then((x) => x.workflow);
36383
+ const client2 = context.get("client");
36384
+ const workflow = props.workflow ? props.workflow : await client2.getWorkflow({ id: props.id }).then((x) => x.workflow);
36332
36385
  if (!adk.project.workflows.find((w) => w.name === workflow.name)) {
36333
36386
  throw new Error(`No ADK Workflow definition found for "${workflow.name}"`);
36334
36387
  }
36335
36388
  TrackedTags.create({
36336
36389
  type: "workflow",
36337
- client: client._inner,
36390
+ client: client2._inner,
36338
36391
  id: workflow.id,
36339
36392
  initialTags: workflow.tags
36340
36393
  });
36341
36394
  await TrackedTags.loadAll();
36342
- return new _BaseWorkflowInstance(workflow, client);
36395
+ return new _BaseWorkflowInstance(workflow, client2);
36343
36396
  }
36344
36397
  /**
36345
36398
  * Executes the workflow with the provided autonomous engine configuration.
@@ -36376,8 +36429,8 @@ var init_workflow_instance = __esm({
36376
36429
  * }
36377
36430
  */
36378
36431
  async provide(request, data) {
36379
- const client = context.get("client");
36380
- const state = createWorkflowExecutionState(client._inner, this.id);
36432
+ const client2 = context.get("client");
36433
+ const state = createWorkflowExecutionState(client2._inner, this.id);
36381
36434
  await state.load();
36382
36435
  if (!state.value) {
36383
36436
  throw new Error(`Workflow execution state not found for workflow ${this.id}`);
@@ -36396,7 +36449,7 @@ var init_workflow_instance = __esm({
36396
36449
  }
36397
36450
  state.value.revision++;
36398
36451
  await state.save();
36399
- await client.createEvent({
36452
+ await client2.createEvent({
36400
36453
  type: WorkflowContinueEvent.name,
36401
36454
  workflowId: this.id,
36402
36455
  payload: {}
@@ -36447,8 +36500,8 @@ var init_workflow_instance = __esm({
36447
36500
  }
36448
36501
  };
36449
36502
  try {
36450
- const client = context.get("client");
36451
- const workflowExecutionState = createWorkflowExecutionState(client._inner, this.id);
36503
+ const client2 = context.get("client");
36504
+ const workflowExecutionState = createWorkflowExecutionState(client2._inner, this.id);
36452
36505
  await workflowExecutionState.load();
36453
36506
  await this.TrackedState.load();
36454
36507
  abortSignal.throwIfAborted();
@@ -36470,7 +36523,7 @@ var init_workflow_instance = __esm({
36470
36523
  }
36471
36524
  context.set("workflowControlContext", workflowControlContext);
36472
36525
  const stopCancellationMonitor = startWorkflowCancellationMonitor({
36473
- client: client._inner,
36526
+ client: client2._inner,
36474
36527
  workflowId: this.id,
36475
36528
  workflowControlContext,
36476
36529
  abortSignal
@@ -36835,14 +36888,14 @@ var init_tracked_state = __esm({
36835
36888
  }
36836
36889
  static async loadAll() {
36837
36890
  await span("state.loadAll", {}, async () => {
36838
- const client = context.get("client")._inner;
36891
+ const client2 = context.get("client")._inner;
36839
36892
  const botId = context.get("botId", { optional: true });
36840
36893
  const user2 = context.get("user", { optional: true });
36841
36894
  const conversation = context.get("conversation", { optional: true });
36842
36895
  const { adk: adk2 } = await Promise.resolve().then(() => (init_adk(), adk_exports));
36843
36896
  if (botId) {
36844
36897
  _TrackedState.create({
36845
- client,
36898
+ client: client2,
36846
36899
  name: BUILT_IN_STATES.bot,
36847
36900
  type: "bot",
36848
36901
  id: botId,
@@ -36851,7 +36904,7 @@ var init_tracked_state = __esm({
36851
36904
  }
36852
36905
  if (user2) {
36853
36906
  _TrackedState.create({
36854
- client,
36907
+ client: client2,
36855
36908
  name: BUILT_IN_STATES.user,
36856
36909
  type: "user",
36857
36910
  id: user2.id,
@@ -36868,7 +36921,7 @@ var init_tracked_state = __esm({
36868
36921
  }
36869
36922
  });
36870
36923
  _TrackedState.create({
36871
- client,
36924
+ client: client2,
36872
36925
  name: BUILT_IN_STATES.conversation,
36873
36926
  type: "conversation",
36874
36927
  id: conversation.id,
@@ -37175,7 +37228,7 @@ var init_events2 = __esm({
37175
37228
  // src/runtime/context/handlers.ts
37176
37229
  import * as sdk from "@botpress/sdk";
37177
37230
  import { CitationsManager } from "llmz";
37178
- import { Client } from "@botpress/client";
37231
+ import { Client as Client2 } from "@botpress/client";
37179
37232
  import { ulid as ulid2 } from "ulid";
37180
37233
  var init_handlers = __esm({
37181
37234
  "src/runtime/context/handlers.ts"() {
@@ -37899,12 +37952,12 @@ var init_conversation_instance = __esm({
37899
37952
  TrackedState;
37900
37953
  // @internal
37901
37954
  TrackedTags;
37902
- constructor(conversation, client) {
37955
+ constructor(conversation, client2) {
37903
37956
  this.id = conversation.id;
37904
37957
  this.channel = `${conversation.integration}.${conversation.channel}`;
37905
37958
  this.integration = conversation.integration;
37906
37959
  this.conversation = conversation;
37907
- this.client = client;
37960
+ this.client = client2;
37908
37961
  const states = context.get("states", { optional: true });
37909
37962
  const existingState = states?.find(
37910
37963
  (s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
@@ -37918,7 +37971,7 @@ var init_conversation_instance = __esm({
37918
37971
  const tags = TrackedTags.create({
37919
37972
  type: "conversation",
37920
37973
  id: conversation.id,
37921
- client: client._inner,
37974
+ client: client2._inner,
37922
37975
  initialTags: conversation.tags
37923
37976
  });
37924
37977
  this.TrackedTags = tags;
@@ -38086,9 +38139,9 @@ var init_conversation = __esm({
38086
38139
  const message = context.get("message", { optional: true });
38087
38140
  const event = context.get("event", { optional: true });
38088
38141
  const chat = context.get("chat");
38089
- const client = context.get("client");
38142
+ const client2 = context.get("client");
38090
38143
  const botpressConversation = context.get("conversation");
38091
- const conversationInstance = new BaseConversationInstance(botpressConversation, client);
38144
+ const conversationInstance = new BaseConversationInstance(botpressConversation, client2);
38092
38145
  const startTypingPromise = conversationInstance.startTyping().catch(() => {
38093
38146
  });
38094
38147
  let type;
@@ -38125,7 +38178,7 @@ var init_conversation = __esm({
38125
38178
  if (controller.signal.aborted) {
38126
38179
  return;
38127
38180
  }
38128
- const { events } = await client.listEvents({
38181
+ const { events } = await client2.listEvents({
38129
38182
  conversationId: conversationInstance.id,
38130
38183
  status: "pending"
38131
38184
  });
@@ -38198,7 +38251,7 @@ var init_conversation = __esm({
38198
38251
  request: requestObject,
38199
38252
  conversation: conversationInstance,
38200
38253
  state: stateProxy,
38201
- client,
38254
+ client: client2,
38202
38255
  execute
38203
38256
  });
38204
38257
  controller.abort();
@@ -40463,7 +40516,7 @@ var init_source_website = __esm({
40463
40516
  return createSyncWorkflow({
40464
40517
  type: "website",
40465
40518
  state: State,
40466
- async handler({ input, step: step2, state, client }) {
40519
+ async handler({ input, step: step2, state, client: client2 }) {
40467
40520
  const crypto3 = await import("crypto");
40468
40521
  console.log(
40469
40522
  `Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
@@ -40484,7 +40537,7 @@ var init_source_website = __esm({
40484
40537
  console.log(`Will process up to ${this.maxPages} pages`);
40485
40538
  const existingFiles = await step2(
40486
40539
  "list existing files",
40487
- () => client._inner.list.files({
40540
+ () => client2._inner.list.files({
40488
40541
  tags
40489
40542
  }).collect()
40490
40543
  );
@@ -40495,7 +40548,7 @@ var init_source_website = __esm({
40495
40548
  await step2.map(
40496
40549
  "deleting all existing files for recrawl",
40497
40550
  existingFiles,
40498
- (f) => client.deleteFile({ id: f.id }).catch(() => null),
40551
+ (f) => client2.deleteFile({ id: f.id }).catch(() => null),
40499
40552
  { concurrency: 5 }
40500
40553
  );
40501
40554
  console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
@@ -40527,7 +40580,7 @@ var init_source_website = __esm({
40527
40580
  const deleted = await step2.map(
40528
40581
  "deleting removed urls",
40529
40582
  toRemove,
40530
- (f) => client.deleteFile({ id: f.id }).catch(() => null).then(
40583
+ (f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
40531
40584
  () => ({
40532
40585
  file: f.id,
40533
40586
  name: f.key,
@@ -40552,7 +40605,7 @@ var init_source_website = __esm({
40552
40605
  contentType = content.includes("<html") ? "text/html" : "text/markdown";
40553
40606
  }
40554
40607
  const key = `data_source://${this.type}/${this.id}/${encodeURIComponent(url2)}`;
40555
- const uploaded = await client.uploadFile({
40608
+ const uploaded = await client2.uploadFile({
40556
40609
  key,
40557
40610
  content,
40558
40611
  contentType,
@@ -40612,7 +40665,7 @@ var init_source_website = __esm({
40612
40665
  await step2("register web page source", async () => {
40613
40666
  try {
40614
40667
  const botId = context.get("botId");
40615
- const getStateResult = await client._inner.getState({ id: botId, type: "bot", name: "dsData" }).catch(() => ({ state: null }));
40668
+ const getStateResult = await client2._inner.getState({ id: botId, type: "bot", name: "dsData" }).catch(() => ({ state: null }));
40616
40669
  const freshState = getStateResult.state;
40617
40670
  const existingPayload = freshState?.payload || {};
40618
40671
  const kbPayload = existingPayload[input.kbId] || {};
@@ -40634,7 +40687,7 @@ var init_source_website = __esm({
40634
40687
  data: { websiteUrl, pages: [], indexingJobs: [] }
40635
40688
  };
40636
40689
  existingPayload[input.kbId] = kbPayload;
40637
- await client._inner.setState({
40690
+ await client2._inner.setState({
40638
40691
  id: botId,
40639
40692
  type: "bot",
40640
40693
  name: "dsData",
@@ -47512,7 +47565,7 @@ var init_source_directory = __esm({
47512
47565
  return createSyncWorkflow({
47513
47566
  type: "directory",
47514
47567
  state: z24.object({}),
47515
- handler: async ({ input, step: step2, client }) => {
47568
+ handler: async ({ input, step: step2, client: client2 }) => {
47516
47569
  if (!adk.environment.isDevelopment()) {
47517
47570
  console.log("Directory ingestion is only supported in development environment");
47518
47571
  return {
@@ -47564,7 +47617,7 @@ var init_source_directory = __esm({
47564
47617
  );
47565
47618
  const existingFiles = await step2(
47566
47619
  "list existing files",
47567
- () => client._inner.list.files({
47620
+ () => client2._inner.list.files({
47568
47621
  tags
47569
47622
  }).collect()
47570
47623
  );
@@ -47578,7 +47631,7 @@ var init_source_directory = __esm({
47578
47631
  const deleted = await step2.map(
47579
47632
  "deleting removed files",
47580
47633
  toRemove,
47581
- (f) => client.deleteFile({ id: f.id }).catch(() => null).then(
47634
+ (f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
47582
47635
  () => ({
47583
47636
  file: f.id,
47584
47637
  name: f.key,
@@ -47592,7 +47645,7 @@ var init_source_directory = __esm({
47592
47645
  const key = `data_source://${this.type}/${this.id}/${local.rel}`;
47593
47646
  const content = await fs3.readFile(local.abs);
47594
47647
  const hash = crypto3.createHash("sha256").update(content).digest("hex");
47595
- const { file } = await client.getFile({ id: key }).catch(() => ({ file: null }));
47648
+ const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
47596
47649
  if (!input.force && file?.metadata?.hash === hash) {
47597
47650
  console.log(`Skipping unchanged file: ${local.rel}`);
47598
47651
  return null;
@@ -47601,7 +47654,7 @@ var init_source_directory = __esm({
47601
47654
  console.log(`Force re-indexing file (unchanged): ${local.rel}`);
47602
47655
  }
47603
47656
  const title = path4.basename(local.name, path4.extname(local.name));
47604
- const uploaded = await client.uploadFile({
47657
+ const uploaded = await client2.uploadFile({
47605
47658
  key,
47606
47659
  content,
47607
47660
  accessPolicies: [],
@@ -47712,8 +47765,8 @@ var init_knowledge = __esm({
47712
47765
  * Look up the KB ID from Botpress
47713
47766
  */
47714
47767
  async getKbId() {
47715
- const client = context.get("client")._inner;
47716
- const kbs = await client.list.knowledgeBases({}).collect();
47768
+ const client2 = context.get("client")._inner;
47769
+ const kbs = await client2.list.knowledgeBases({}).collect();
47717
47770
  const remoteKb = kbs.find((k) => k.name === this.name);
47718
47771
  if (!remoteKb) {
47719
47772
  throw new Error(`KB '${this.name}' not found in Botpress - run 'adk deploy' or approve KB sync in 'adk dev'`);
@@ -47783,6 +47836,9 @@ var init_table = __esm({
47783
47836
  factor;
47784
47837
  columns;
47785
47838
  schema;
47839
+ type = "table";
47840
+ keyColumn;
47841
+ tags;
47786
47842
  nullableColumns = /* @__PURE__ */ new Set();
47787
47843
  searchableColumns = /* @__PURE__ */ new Set();
47788
47844
  computedColumns = /* @__PURE__ */ new Set();
@@ -47794,6 +47850,7 @@ var init_table = __esm({
47794
47850
  (name) => /^[a-zA-Z_$][a-zA-Z0-9_]{0,29}Table$/.test(name),
47795
47851
  "Table name must start with a letter/underscore, be 35 chars or less, contain only letters/numbers/underscores, and end with 'Table'"
47796
47852
  );
47853
+ const tagsSchema = z25.record(z25.string().min(3).max(50), z25.string().min(1).max(255)).optional();
47797
47854
  const validation = tableNameSchema.safeParse(props.name);
47798
47855
  if (!validation.success) {
47799
47856
  throw new Errors.InvalidPrimitiveError(`Invalid table name '${props.name}'`, validation.error);
@@ -47802,7 +47859,19 @@ var init_table = __esm({
47802
47859
  if (props.description !== void 0) {
47803
47860
  this.description = props.description;
47804
47861
  }
47862
+ if (props.factor !== void 0 && (props.factor < 1 || props.factor > 30)) {
47863
+ throw new Errors.InvalidPrimitiveError(
47864
+ `Invalid factor for table '${props.name}': must be between 1 and 30 but got ${props.factor}`
47865
+ );
47866
+ }
47805
47867
  this.factor = props.factor ?? 1;
47868
+ if (props.tags !== void 0) {
47869
+ const parsed = tagsSchema.safeParse(props.tags);
47870
+ if (!parsed.success) {
47871
+ throw new Errors.InvalidPrimitiveError(`Invalid tags for table '${props.name}'`, parsed.error);
47872
+ }
47873
+ this.tags = props.tags;
47874
+ }
47806
47875
  this.columns = {};
47807
47876
  let schema = z25.object({});
47808
47877
  for (const [key, value] of Object.entries(props.columns)) {
@@ -47852,6 +47921,14 @@ var init_table = __esm({
47852
47921
  };
47853
47922
  }
47854
47923
  }
47924
+ if (props.keyColumn) {
47925
+ if (typeof props.keyColumn !== "string" || !(props.keyColumn in this.columns)) {
47926
+ throw new Errors.InvalidPrimitiveError(
47927
+ `Invalid keyColumn '${String(props.keyColumn)}' for table '${props.name}': column does not exist`
47928
+ );
47929
+ }
47930
+ this.keyColumn = String(props.keyColumn);
47931
+ }
47855
47932
  this.schema = schema;
47856
47933
  }
47857
47934
  /** @internal */
@@ -47872,7 +47949,9 @@ var init_table = __esm({
47872
47949
  type: "table",
47873
47950
  name: this.name,
47874
47951
  schema,
47875
- factor: this.factor
47952
+ factor: this.factor,
47953
+ keyColumn: this.keyColumn,
47954
+ tags: this.tags
47876
47955
  };
47877
47956
  }
47878
47957
  async getRow(props) {
@@ -48206,7 +48285,7 @@ var init_tracked_tags = __esm({
48206
48285
  }
48207
48286
  static async loadAll() {
48208
48287
  await span("tags.loadAll", {}, async () => {
48209
- const client = context.get("client")._inner;
48288
+ const client2 = context.get("client")._inner;
48210
48289
  const bot2 = context.get("bot", { optional: true });
48211
48290
  const user2 = context.get("user", { optional: true });
48212
48291
  const conversation = context.get("conversation", { optional: true });
@@ -48214,7 +48293,7 @@ var init_tracked_tags = __esm({
48214
48293
  if (bot2) {
48215
48294
  const botTags = bot2.tags;
48216
48295
  _TrackedTags.create({
48217
- client,
48296
+ client: client2,
48218
48297
  type: "bot",
48219
48298
  id: bot2.id,
48220
48299
  ...botTags && { initialTags: botTags }
@@ -48223,7 +48302,7 @@ var init_tracked_tags = __esm({
48223
48302
  if (user2) {
48224
48303
  const userTags = user2.tags;
48225
48304
  _TrackedTags.create({
48226
- client,
48305
+ client: client2,
48227
48306
  type: "user",
48228
48307
  id: user2.id,
48229
48308
  ...userTags && { initialTags: userTags }
@@ -48232,7 +48311,7 @@ var init_tracked_tags = __esm({
48232
48311
  if (conversation) {
48233
48312
  const conversationTags = conversation.tags;
48234
48313
  _TrackedTags.create({
48235
- client,
48314
+ client: client2,
48236
48315
  type: "conversation",
48237
48316
  id: conversation.id,
48238
48317
  ...conversationTags && { initialTags: conversationTags }
@@ -48241,7 +48320,7 @@ var init_tracked_tags = __esm({
48241
48320
  if (workflow) {
48242
48321
  const workflowTags = workflow.tags;
48243
48322
  _TrackedTags.create({
48244
- client,
48323
+ client: client2,
48245
48324
  type: "workflow",
48246
48325
  id: workflow.id,
48247
48326
  ...workflowTags && { initialTags: workflowTags }
@@ -48381,6 +48460,51 @@ var init_tracked_tags = __esm({
48381
48460
  }
48382
48461
  });
48383
48462
 
48463
+ // src/runtime/client.ts
48464
+ import { Client as Client3 } from "@botpress/client";
48465
+ function getStandaloneClient() {
48466
+ return getSingleton("__ADK_GLOBAL_STANDALONE_CLIENT", () => {
48467
+ const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
48468
+ if (!token) {
48469
+ throw new Error(
48470
+ 'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
48471
+ );
48472
+ }
48473
+ const botId = process.env.ADK_BOT_ID;
48474
+ if (!botId) {
48475
+ throw new Error(
48476
+ 'No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".'
48477
+ );
48478
+ }
48479
+ const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
48480
+ return new Client3({
48481
+ token,
48482
+ apiUrl,
48483
+ botId
48484
+ });
48485
+ });
48486
+ }
48487
+ var client;
48488
+ var init_client = __esm({
48489
+ "src/runtime/client.ts"() {
48490
+ "use strict";
48491
+ init_define_BUILD();
48492
+ init_define_PACKAGE_VERSIONS();
48493
+ init_context();
48494
+ init_singletons();
48495
+ client = new Proxy({}, {
48496
+ get(_target, prop) {
48497
+ const contextClient = context.get("client", { optional: true });
48498
+ if (contextClient) {
48499
+ return contextClient[prop];
48500
+ }
48501
+ const standaloneClient = getStandaloneClient();
48502
+ return standaloneClient[prop];
48503
+ }
48504
+ });
48505
+ }
48506
+ });
48507
+
48384
48508
  // src/runtime/index.ts
48385
48509
  var init_runtime2 = __esm({
48386
48510
  "src/runtime/index.ts"() {
@@ -48399,18 +48523,20 @@ var init_runtime2 = __esm({
48399
48523
  init_tracked_tags();
48400
48524
  init_actions();
48401
48525
  init_events2();
48526
+ init_client();
48402
48527
  }
48403
48528
  });
48404
48529
 
48405
48530
  // src/library.ts
48406
48531
  import { z as z27 } from "@botpress/sdk";
48407
- import { Cognitive as Cognitive2 } from "@botpress/cognitive";
48532
+ import { Cognitive as Cognitive3 } from "@botpress/cognitive";
48408
48533
  import { Zai as Zai2 } from "@botpress/zai";
48409
48534
  var init_library = __esm({
48410
48535
  "src/library.ts"() {
48411
48536
  init_define_BUILD();
48412
48537
  init_define_PACKAGE_VERSIONS();
48413
48538
  init_runtime2();
48539
+ init_client();
48414
48540
  init_primitives();
48415
48541
  init_workflow_utils();
48416
48542
  init_events();
@@ -48429,7 +48555,7 @@ export {
48429
48555
  Action,
48430
48556
  Autonomous,
48431
48557
  BaseConversationInstance,
48432
- Cognitive2 as Cognitive,
48558
+ Cognitive3 as Cognitive,
48433
48559
  BaseConversation as Conversation,
48434
48560
  DataSource2 as DataSource,
48435
48561
  Errors,
@@ -48443,6 +48569,7 @@ export {
48443
48569
  actions,
48444
48570
  adk,
48445
48571
  bot,
48572
+ client,
48446
48573
  configuration,
48447
48574
  context,
48448
48575
  defineConfig,