@botpress/runtime 1.11.9 → 1.12.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.
@@ -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.0", adk: "1.12.0", sdk: "4.20.2", llmz: "0.0.33", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -33412,12 +33412,12 @@ If the question is not related to the knowledge bases, do NOT use this tool.`.tr
33412
33412
  input: z5.string().describe("The query to search for.").min(1).max(1024),
33413
33413
  output: z5.string().describe("The search results."),
33414
33414
  handler: async (query) => {
33415
- const client = context2.get("client");
33415
+ const client2 = context2.get("client");
33416
33416
  const citations = context2.get("citations");
33417
- if (!client) {
33417
+ if (!client2) {
33418
33418
  throw new Error("Client is not available in this context. Make sure to run in a context with a client.");
33419
33419
  }
33420
- const { passages } = await client.searchFiles({
33420
+ const { passages } = await client2.searchFiles({
33421
33421
  query,
33422
33422
  withContext: true,
33423
33423
  includeBreadcrumb: true,
@@ -33798,9 +33798,9 @@ var init_actions = __esm({
33798
33798
  return handler;
33799
33799
  }
33800
33800
  let integrations;
33801
- let client;
33801
+ let client2;
33802
33802
  integrations ??= context2.get("integrations", { optional: true });
33803
- client ??= context2.get("client", { optional: true });
33803
+ client2 ??= context2.get("client", { optional: true });
33804
33804
  const integrationName = propertyName.replace("__", "/");
33805
33805
  return new Proxy(
33806
33806
  {},
@@ -33810,19 +33810,19 @@ var init_actions = __esm({
33810
33810
  return void 0;
33811
33811
  }
33812
33812
  integrations ??= context2.get("integrations", { optional: true });
33813
- client ??= context2.get("client", { optional: true });
33813
+ client2 ??= context2.get("client", { optional: true });
33814
33814
  const integration = integrations.find((i) => i.alias === integrationName);
33815
33815
  const actionDef = integration?.definition.actions?.[actionName];
33816
33816
  const handler = async (params) => {
33817
33817
  integrations ??= context2.get("integrations", { optional: true });
33818
- client ??= context2.get("client", { optional: true });
33818
+ client2 ??= context2.get("client", { optional: true });
33819
33819
  if (!integration || !actionDef) {
33820
33820
  throw new Error(`Could not find integration "${integrationName}" and action "${actionName}"`);
33821
33821
  }
33822
33822
  if (!integration.definition.actions?.[actionName]) {
33823
33823
  throw new Error(`Action "${actionName}" not found in integration "${integrationName}"`);
33824
33824
  }
33825
- return client.callAction({
33825
+ return client2.callAction({
33826
33826
  type: `${integration.alias}:${actionName}`,
33827
33827
  input: params
33828
33828
  }).then((res) => res.output);
@@ -34092,6 +34092,51 @@ ${issues.join("\n")}`;
34092
34092
  }
34093
34093
  });
34094
34094
 
34095
+ // src/runtime/client.ts
34096
+ import { Client as Client2 } from "@botpress/client";
34097
+ function getStandaloneClient() {
34098
+ return getSingleton("__ADK_GLOBAL_STANDALONE_CLIENT", () => {
34099
+ const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
34100
+ if (!token) {
34101
+ throw new Error(
34102
+ 'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
34103
+ );
34104
+ }
34105
+ const botId = process.env.ADK_BOT_ID;
34106
+ if (!botId) {
34107
+ throw new Error(
34108
+ 'No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".'
34109
+ );
34110
+ }
34111
+ const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
34112
+ return new Client2({
34113
+ token,
34114
+ apiUrl,
34115
+ botId
34116
+ });
34117
+ });
34118
+ }
34119
+ var client;
34120
+ var init_client = __esm({
34121
+ "src/runtime/client.ts"() {
34122
+ "use strict";
34123
+ init_define_BUILD();
34124
+ init_define_PACKAGE_VERSIONS();
34125
+ init_context3();
34126
+ init_singletons();
34127
+ client = new Proxy({}, {
34128
+ get(_target, prop) {
34129
+ const contextClient = context2.get("client", { optional: true });
34130
+ if (contextClient) {
34131
+ return contextClient[prop];
34132
+ }
34133
+ const standaloneClient = getStandaloneClient();
34134
+ return standaloneClient[prop];
34135
+ }
34136
+ });
34137
+ }
34138
+ });
34139
+
34095
34140
  // src/primitives/asset.ts
34096
34141
  var init_asset = __esm({
34097
34142
  "src/primitives/asset.ts"() {
@@ -34161,12 +34206,12 @@ var init_conversation_instance = __esm({
34161
34206
  TrackedState;
34162
34207
  // @internal
34163
34208
  TrackedTags;
34164
- constructor(conversation, client) {
34209
+ constructor(conversation, client2) {
34165
34210
  this.id = conversation.id;
34166
34211
  this.channel = `${conversation.integration}.${conversation.channel}`;
34167
34212
  this.integration = conversation.integration;
34168
34213
  this.conversation = conversation;
34169
- this.client = client;
34214
+ this.client = client2;
34170
34215
  const states = context2.get("states", { optional: true });
34171
34216
  const existingState = states?.find(
34172
34217
  (s) => s.type === "conversation" && s.id === conversation.id && s.name === BUILT_IN_STATES.conversation
@@ -34180,7 +34225,7 @@ var init_conversation_instance = __esm({
34180
34225
  const tags = TrackedTags.create({
34181
34226
  type: "conversation",
34182
34227
  id: conversation.id,
34183
- client: client._inner,
34228
+ client: client2._inner,
34184
34229
  initialTags: conversation.tags
34185
34230
  });
34186
34231
  this.TrackedTags = tags;
@@ -36564,7 +36609,7 @@ var init_source_website = __esm({
36564
36609
  return createSyncWorkflow({
36565
36610
  type: "website",
36566
36611
  state: State,
36567
- async handler({ input, step: step2, state, client }) {
36612
+ async handler({ input, step: step2, state, client: client2 }) {
36568
36613
  const crypto3 = await import("crypto");
36569
36614
  console.log(
36570
36615
  `Starting sync for WebsiteSource [${this.id}] in mode [${this.mode}, maxPages=${this.maxPages}, maxDepth=${this.maxDepth}, baseUrl=${this.baseUrl}, sitemapUrl=${this.sitemapUrl}]`
@@ -36585,7 +36630,7 @@ var init_source_website = __esm({
36585
36630
  console.log(`Will process up to ${this.maxPages} pages`);
36586
36631
  const existingFiles = await step2(
36587
36632
  "list existing files",
36588
- () => client._inner.list.files({
36633
+ () => client2._inner.list.files({
36589
36634
  tags
36590
36635
  }).collect()
36591
36636
  );
@@ -36596,7 +36641,7 @@ var init_source_website = __esm({
36596
36641
  await step2.map(
36597
36642
  "deleting all existing files for recrawl",
36598
36643
  existingFiles,
36599
- (f) => client.deleteFile({ id: f.id }).catch(() => null),
36644
+ (f) => client2.deleteFile({ id: f.id }).catch(() => null),
36600
36645
  { concurrency: 5 }
36601
36646
  );
36602
36647
  console.log(`\u2705 Deleted ${existingFiles.length} files, starting fresh crawl`);
@@ -36628,7 +36673,7 @@ var init_source_website = __esm({
36628
36673
  const deleted = await step2.map(
36629
36674
  "deleting removed urls",
36630
36675
  toRemove,
36631
- (f) => client.deleteFile({ id: f.id }).catch(() => null).then(
36676
+ (f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
36632
36677
  () => ({
36633
36678
  file: f.id,
36634
36679
  name: f.key,
@@ -36653,7 +36698,7 @@ var init_source_website = __esm({
36653
36698
  contentType = content.includes("<html") ? "text/html" : "text/markdown";
36654
36699
  }
36655
36700
  const key = `data_source://${this.type}/${this.id}/${encodeURIComponent(url2)}`;
36656
- const uploaded = await client.uploadFile({
36701
+ const uploaded = await client2.uploadFile({
36657
36702
  key,
36658
36703
  content,
36659
36704
  contentType,
@@ -36713,7 +36758,7 @@ var init_source_website = __esm({
36713
36758
  await step2("register web page source", async () => {
36714
36759
  try {
36715
36760
  const botId = context2.get("botId");
36716
- const getStateResult = await client._inner.getState({ id: botId, type: "bot", name: "dsData" }).catch(() => ({ state: null }));
36761
+ const getStateResult = await client2._inner.getState({ id: botId, type: "bot", name: "dsData" }).catch(() => ({ state: null }));
36717
36762
  const freshState = getStateResult.state;
36718
36763
  const existingPayload = freshState?.payload || {};
36719
36764
  const kbPayload = existingPayload[input.kbId] || {};
@@ -36735,7 +36780,7 @@ var init_source_website = __esm({
36735
36780
  data: { websiteUrl, pages: [], indexingJobs: [] }
36736
36781
  };
36737
36782
  existingPayload[input.kbId] = kbPayload;
36738
- await client._inner.setState({
36783
+ await client2._inner.setState({
36739
36784
  id: botId,
36740
36785
  type: "bot",
36741
36786
  name: "dsData",
@@ -43613,7 +43658,7 @@ var init_source_directory = __esm({
43613
43658
  return createSyncWorkflow({
43614
43659
  type: "directory",
43615
43660
  state: z12.object({}),
43616
- handler: async ({ input, step: step2, client }) => {
43661
+ handler: async ({ input, step: step2, client: client2 }) => {
43617
43662
  if (!adk.environment.isDevelopment()) {
43618
43663
  console.log("Directory ingestion is only supported in development environment");
43619
43664
  return {
@@ -43665,7 +43710,7 @@ var init_source_directory = __esm({
43665
43710
  );
43666
43711
  const existingFiles = await step2(
43667
43712
  "list existing files",
43668
- () => client._inner.list.files({
43713
+ () => client2._inner.list.files({
43669
43714
  tags
43670
43715
  }).collect()
43671
43716
  );
@@ -43679,7 +43724,7 @@ var init_source_directory = __esm({
43679
43724
  const deleted = await step2.map(
43680
43725
  "deleting removed files",
43681
43726
  toRemove,
43682
- (f) => client.deleteFile({ id: f.id }).catch(() => null).then(
43727
+ (f) => client2.deleteFile({ id: f.id }).catch(() => null).then(
43683
43728
  () => ({
43684
43729
  file: f.id,
43685
43730
  name: f.key,
@@ -43693,7 +43738,7 @@ var init_source_directory = __esm({
43693
43738
  const key = `data_source://${this.type}/${this.id}/${local.rel}`;
43694
43739
  const content = await fs3.readFile(local.abs);
43695
43740
  const hash = crypto3.createHash("sha256").update(content).digest("hex");
43696
- const { file } = await client.getFile({ id: key }).catch(() => ({ file: null }));
43741
+ const { file } = await client2.getFile({ id: key }).catch(() => ({ file: null }));
43697
43742
  if (!input.force && file?.metadata?.hash === hash) {
43698
43743
  console.log(`Skipping unchanged file: ${local.rel}`);
43699
43744
  return null;
@@ -43702,7 +43747,7 @@ var init_source_directory = __esm({
43702
43747
  console.log(`Force re-indexing file (unchanged): ${local.rel}`);
43703
43748
  }
43704
43749
  const title = path4.basename(local.name, path4.extname(local.name));
43705
- const uploaded = await client.uploadFile({
43750
+ const uploaded = await client2.uploadFile({
43706
43751
  key,
43707
43752
  content,
43708
43753
  accessPolicies: [],
@@ -43843,9 +43888,9 @@ var init_conversation = __esm({
43843
43888
  const message = context2.get("message", { optional: true });
43844
43889
  const event = context2.get("event", { optional: true });
43845
43890
  const chat = context2.get("chat");
43846
- const client = context2.get("client");
43891
+ const client2 = context2.get("client");
43847
43892
  const botpressConversation = context2.get("conversation");
43848
- const conversationInstance = new BaseConversationInstance(botpressConversation, client);
43893
+ const conversationInstance = new BaseConversationInstance(botpressConversation, client2);
43849
43894
  const startTypingPromise = conversationInstance.startTyping().catch(() => {
43850
43895
  });
43851
43896
  let type;
@@ -43882,7 +43927,7 @@ var init_conversation = __esm({
43882
43927
  if (controller.signal.aborted) {
43883
43928
  return;
43884
43929
  }
43885
- const { events } = await client.listEvents({
43930
+ const { events } = await client2.listEvents({
43886
43931
  conversationId: conversationInstance.id,
43887
43932
  status: "pending"
43888
43933
  });
@@ -43955,7 +44000,7 @@ var init_conversation = __esm({
43955
44000
  request: requestObject,
43956
44001
  conversation: conversationInstance,
43957
44002
  state: stateProxy,
43958
- client,
44003
+ client: client2,
43959
44004
  execute
43960
44005
  });
43961
44006
  controller.abort();
@@ -44330,8 +44375,8 @@ var init_action = __esm({
44330
44375
  /**
44331
44376
  * Execute the action with input validation and output validation
44332
44377
  */
44333
- async execute({ input, client }) {
44334
- return await this.handler({ input, client });
44378
+ async execute({ input, client: client2 }) {
44379
+ return await this.handler({ input, client: client2 });
44335
44380
  }
44336
44381
  };
44337
44382
  }
@@ -44430,7 +44475,7 @@ var init_workflow_utils = __esm({
44430
44475
  init_runtime();
44431
44476
  init_events2();
44432
44477
  updateWorkflow = async (props) => {
44433
- const client = context2.get("client");
44478
+ const client2 = context2.get("client");
44434
44479
  const workflowId = props.id;
44435
44480
  const workflowsToUpdate = [];
44436
44481
  const ctxWorkflow = context2.get("workflow", { optional: true });
@@ -44449,7 +44494,7 @@ var init_workflow_utils = __esm({
44449
44494
  if (workflowAlreadyDone) {
44450
44495
  return { workflow: workflowAlreadyDone };
44451
44496
  }
44452
- const response = await client.updateWorkflow(props);
44497
+ const response = await client2.updateWorkflow(props);
44453
44498
  for (const wf of workflowsToUpdate) {
44454
44499
  Object.assign(wf, response.workflow);
44455
44500
  }
@@ -44468,6 +44513,7 @@ var init_library = __esm({
44468
44513
  init_define_BUILD();
44469
44514
  init_define_PACKAGE_VERSIONS();
44470
44515
  init_runtime2();
44516
+ init_client();
44471
44517
  init_primitives();
44472
44518
  init_workflow_utils();
44473
44519
  init_events2();
@@ -44711,9 +44757,9 @@ var init_workflow_step = __esm({
44711
44757
  async () => {
44712
44758
  const remainingTime = context2.get("runtime").getRemainingExecutionTimeInMs();
44713
44759
  if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms3 || ms3 >= 1e4) {
44714
- const client = context2.get("client");
44760
+ const client2 = context2.get("client");
44715
44761
  const workflowControlContext = context2.get("workflowControlContext");
44716
- await client.createEvent({
44762
+ await client2.createEvent({
44717
44763
  type: WorkflowContinueEvent.name,
44718
44764
  payload: {},
44719
44765
  workflowId: workflowControlContext.workflow.id,
@@ -44749,13 +44795,13 @@ var init_workflow_step = __esm({
44749
44795
  return await _step(
44750
44796
  name,
44751
44797
  async () => {
44752
- const client = context2.get("client");
44798
+ const client2 = context2.get("client");
44753
44799
  const state = createWorkflowExecutionState(
44754
44800
  context2.get("client")._inner,
44755
44801
  workflowControlContext.workflow.id
44756
44802
  );
44757
44803
  assert(state.value, "State is not loaded");
44758
- const { workflow } = await client.getWorkflow({ id: workflowId });
44804
+ const { workflow } = await client2.getWorkflow({ id: workflowId });
44759
44805
  if (isWorkflowFinished(workflow.status)) {
44760
44806
  return workflow;
44761
44807
  }
@@ -44843,7 +44889,7 @@ var init_workflow_step = __esm({
44843
44889
  actualStepName,
44844
44890
  async () => {
44845
44891
  const workflowControlContext = context2.get("workflowControlContext");
44846
- const client = context2.get("client");
44892
+ const client2 = context2.get("client");
44847
44893
  if (!workflowControlContext.workflow.conversationId) {
44848
44894
  throw new Error(`Cannot request data: workflow ${workflowControlContext.workflow.id} has no conversationId`);
44849
44895
  }
@@ -44857,14 +44903,14 @@ var init_workflow_step = __esm({
44857
44903
  `Request "${request}" not found in workflow "${workflowDef.name}". Available requests: ${Object.keys(workflowDef._requestsSchemas || {}).join(", ") || "none"}`
44858
44904
  );
44859
44905
  }
44860
- const state = createWorkflowExecutionState(client._inner, workflowControlContext.workflow.id);
44906
+ const state = createWorkflowExecutionState(client2._inner, workflowControlContext.workflow.id);
44861
44907
  if (!state.value) {
44862
44908
  throw new Error("Workflow execution state not loaded");
44863
44909
  }
44864
44910
  if (state.value.steps?.[actualStepName]?.output !== void 0) {
44865
44911
  return requestSchema.parse(state.value.steps[actualStepName].output);
44866
44912
  }
44867
- await client.createEvent({
44913
+ await client2.createEvent({
44868
44914
  type: WorkflowDataRequestEvent.name,
44869
44915
  conversationId: workflowControlContext.workflow.conversationId,
44870
44916
  payload: {
@@ -44894,7 +44940,7 @@ var init_workflow_step = __esm({
44894
44940
 
44895
44941
  // src/primitives/workflow-cancellation-monitor.ts
44896
44942
  function startWorkflowCancellationMonitor(props) {
44897
- const { client, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
44943
+ const { client: client2, workflowId, workflowControlContext, abortSignal, pollIntervalMs = 1e3 } = props;
44898
44944
  if (abortSignal.aborted) {
44899
44945
  return () => {
44900
44946
  };
@@ -44905,7 +44951,7 @@ function startWorkflowCancellationMonitor(props) {
44905
44951
  return;
44906
44952
  }
44907
44953
  try {
44908
- const { workflow } = await client.getWorkflow({ id: workflowId });
44954
+ const { workflow } = await client2.getWorkflow({ id: workflowId });
44909
44955
  const isTerminated = workflow.status === "cancelled" || workflow.status === "failed" || workflow.status === "timedout";
44910
44956
  if (isTerminated) {
44911
44957
  workflowControlContext.aborted = true;
@@ -44949,10 +44995,10 @@ function createStepSignal() {
44949
44995
  [StepSymbol]: true
44950
44996
  };
44951
44997
  }
44952
- function createWorkflowExecutionState(client, workflowId) {
44998
+ function createWorkflowExecutionState(client2, workflowId) {
44953
44999
  return TrackedState.create({
44954
45000
  type: "workflow",
44955
- client,
45001
+ client: client2,
44956
45002
  id: workflowId,
44957
45003
  schema: workflowExecutionContextSchema,
44958
45004
  name: BUILT_IN_STATES.workflowSteps
@@ -45010,18 +45056,18 @@ var init_workflow_instance = __esm({
45010
45056
  TrackedState;
45011
45057
  // @internal
45012
45058
  TrackedTags;
45013
- constructor(workflow, client) {
45059
+ constructor(workflow, client2) {
45014
45060
  const definition = adk.project.workflows.find((w) => w.name === workflow.name);
45015
45061
  this.TrackedState = TrackedState.create({
45016
45062
  type: "workflow",
45017
- client: client._inner,
45063
+ client: client2._inner,
45018
45064
  id: workflow.id,
45019
45065
  schema: definition?.stateSchema,
45020
45066
  name: BUILT_IN_STATES.workflowState
45021
45067
  });
45022
45068
  this.TrackedTags = TrackedTags.create({
45023
45069
  type: "workflow",
45024
- client: client._inner,
45070
+ client: client2._inner,
45025
45071
  id: workflow.id,
45026
45072
  initialTags: workflow.tags
45027
45073
  });
@@ -45031,7 +45077,7 @@ var init_workflow_instance = __esm({
45031
45077
  this.input = workflow.input;
45032
45078
  this.createdAt = new Date(workflow.createdAt);
45033
45079
  this.updatedAt = new Date(workflow.updatedAt);
45034
- this.client = client;
45080
+ this.client = client2;
45035
45081
  this.workflow = workflow;
45036
45082
  }
45037
45083
  get tags() {
@@ -45052,19 +45098,19 @@ var init_workflow_instance = __esm({
45052
45098
  }
45053
45099
  static Primitive = "workflow_instance";
45054
45100
  static async load(props) {
45055
- const client = context2.get("client");
45056
- const workflow = props.workflow ? props.workflow : await client.getWorkflow({ id: props.id }).then((x) => x.workflow);
45101
+ const client2 = context2.get("client");
45102
+ const workflow = props.workflow ? props.workflow : await client2.getWorkflow({ id: props.id }).then((x) => x.workflow);
45057
45103
  if (!adk.project.workflows.find((w) => w.name === workflow.name)) {
45058
45104
  throw new Error(`No ADK Workflow definition found for "${workflow.name}"`);
45059
45105
  }
45060
45106
  TrackedTags.create({
45061
45107
  type: "workflow",
45062
- client: client._inner,
45108
+ client: client2._inner,
45063
45109
  id: workflow.id,
45064
45110
  initialTags: workflow.tags
45065
45111
  });
45066
45112
  await TrackedTags.loadAll();
45067
- return new _BaseWorkflowInstance(workflow, client);
45113
+ return new _BaseWorkflowInstance(workflow, client2);
45068
45114
  }
45069
45115
  /**
45070
45116
  * Executes the workflow with the provided autonomous engine configuration.
@@ -45101,8 +45147,8 @@ var init_workflow_instance = __esm({
45101
45147
  * }
45102
45148
  */
45103
45149
  async provide(request, data) {
45104
- const client = context2.get("client");
45105
- const state = createWorkflowExecutionState(client._inner, this.id);
45150
+ const client2 = context2.get("client");
45151
+ const state = createWorkflowExecutionState(client2._inner, this.id);
45106
45152
  await state.load();
45107
45153
  if (!state.value) {
45108
45154
  throw new Error(`Workflow execution state not found for workflow ${this.id}`);
@@ -45121,7 +45167,7 @@ var init_workflow_instance = __esm({
45121
45167
  }
45122
45168
  state.value.revision++;
45123
45169
  await state.save();
45124
- await client.createEvent({
45170
+ await client2.createEvent({
45125
45171
  type: WorkflowContinueEvent.name,
45126
45172
  workflowId: this.id,
45127
45173
  payload: {}
@@ -45172,8 +45218,8 @@ var init_workflow_instance = __esm({
45172
45218
  }
45173
45219
  };
45174
45220
  try {
45175
- const client = context2.get("client");
45176
- const workflowExecutionState = createWorkflowExecutionState(client._inner, this.id);
45221
+ const client2 = context2.get("client");
45222
+ const workflowExecutionState = createWorkflowExecutionState(client2._inner, this.id);
45177
45223
  await workflowExecutionState.load();
45178
45224
  await this.TrackedState.load();
45179
45225
  abortSignal.throwIfAborted();
@@ -45195,7 +45241,7 @@ var init_workflow_instance = __esm({
45195
45241
  }
45196
45242
  context2.set("workflowControlContext", workflowControlContext);
45197
45243
  const stopCancellationMonitor = startWorkflowCancellationMonitor({
45198
- client: client._inner,
45244
+ client: client2._inner,
45199
45245
  workflowId: this.id,
45200
45246
  workflowControlContext,
45201
45247
  abortSignal
@@ -45356,7 +45402,7 @@ var init_workflow = __esm({
45356
45402
  * @returns The workflow instance
45357
45403
  */
45358
45404
  async getOrCreate(props) {
45359
- const client = context2.get("client");
45405
+ const client2 = context2.get("client");
45360
45406
  const statuses = props.statuses || ["pending", "in_progress", "listening", "paused"];
45361
45407
  const validatedInput = this._inputSchema.parse(props.input);
45362
45408
  const tags = {};
@@ -45374,10 +45420,10 @@ var init_workflow = __esm({
45374
45420
  timeoutAt: new Date(Date.now() + (this.timeout ?? (0, import_ms.default)("5m"))).toISOString(),
45375
45421
  ...discriminator && { discriminateBy: { tags: discriminator } }
45376
45422
  };
45377
- let { workflow } = await client._inner.getOrCreateWorkflow(createArgs);
45423
+ let { workflow } = await client2._inner.getOrCreateWorkflow(createArgs);
45378
45424
  if (props.key && !statuses.includes(workflow.status)) {
45379
- await client._inner.deleteWorkflow({ id: workflow.id });
45380
- ({ workflow } = await client._inner.getOrCreateWorkflow(createArgs));
45425
+ await client2._inner.deleteWorkflow({ id: workflow.id });
45426
+ ({ workflow } = await client2._inner.getOrCreateWorkflow(createArgs));
45381
45427
  }
45382
45428
  return await BaseWorkflowInstance.load({
45383
45429
  id: workflow.id,
@@ -45395,9 +45441,9 @@ var init_workflow = __esm({
45395
45441
  * }
45396
45442
  */
45397
45443
  async provide(event, data) {
45398
- const client = context2.get("client");
45444
+ const client2 = context2.get("client");
45399
45445
  const { workflowId, stepName } = event.payload;
45400
- const state = createWorkflowExecutionState(client._inner, workflowId);
45446
+ const state = createWorkflowExecutionState(client2._inner, workflowId);
45401
45447
  await state.load();
45402
45448
  if (!state.value) {
45403
45449
  throw new Error(`Workflow execution state not found for workflow ${workflowId}`);
@@ -45416,7 +45462,7 @@ var init_workflow = __esm({
45416
45462
  }
45417
45463
  state.value.revision++;
45418
45464
  await state.save();
45419
- await client.createEvent({
45465
+ await client2.createEvent({
45420
45466
  type: WorkflowContinueEvent.name,
45421
45467
  workflowId,
45422
45468
  payload: {}
@@ -45424,10 +45470,10 @@ var init_workflow = __esm({
45424
45470
  }
45425
45471
  async start(input) {
45426
45472
  const validatedInput = this._inputSchema.parse(input);
45427
- const client = context2.get("client");
45473
+ const client2 = context2.get("client");
45428
45474
  const event = context2.get("event", { optional: true });
45429
45475
  const workflow = context2.get("workflow", { optional: true });
45430
- const res = await client._inner.createWorkflow({
45476
+ const res = await client2._inner.createWorkflow({
45431
45477
  name: this.name,
45432
45478
  status: event ? "in_progress" : "pending",
45433
45479
  eventId: event?.id,
@@ -45613,9 +45659,9 @@ var init_computed_columns = __esm({
45613
45659
  isFinished: z25.boolean(),
45614
45660
  rows: z25.array(z25.any())
45615
45661
  }),
45616
- handler: async ({ input, client }) => {
45662
+ handler: async ({ input, client: client2 }) => {
45617
45663
  const { tableId, requests } = input;
45618
- const { table: remoteTable } = await client._inner.getTable({ table: tableId });
45664
+ const { table: remoteTable } = await client2._inner.getTable({ table: tableId });
45619
45665
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
45620
45666
  async function computeRow(row, columnsToRecompute) {
45621
45667
  const newRow = { id: row.id };
@@ -45688,7 +45734,35 @@ __export(adk_exports, {
45688
45734
  register: () => register,
45689
45735
  registerIntegration: () => registerIntegration
45690
45736
  });
45737
+ import { BotSpecificClient as BotSpecificClient2 } from "@botpress/sdk";
45691
45738
  import { Zai as Zai2 } from "@botpress/zai";
45739
+ import { Cognitive as Cognitive3 } from "@botpress/cognitive";
45740
+ import { Client as Client3 } from "@botpress/client";
45741
+ function getStandaloneCognitive() {
45742
+ return getSingleton("__ADK_GLOBAL_STANDALONE_COGNITIVE", () => {
45743
+ const token = process.env.BP_TOKEN || process.env.ADK_TOKEN;
45744
+ if (!token) {
45745
+ throw new Error(
45746
+ 'No token found. Set BP_TOKEN or ADK_TOKEN environment variable, or run this script using "adk run".'
45747
+ );
45748
+ }
45749
+ const botId = process.env.ADK_BOT_ID;
45750
+ if (!botId) {
45751
+ throw new Error('No bot ID found. Set ADK_BOT_ID environment variable, or run this script using "adk run".');
45752
+ }
45753
+ const apiUrl = process.env.ADK_API_URL || "https://api.botpress.cloud";
45754
+ const vanillaClient = new Client3({
45755
+ token,
45756
+ apiUrl,
45757
+ botId
45758
+ });
45759
+ const botClient = new BotSpecificClient2(vanillaClient);
45760
+ return new Cognitive3({
45761
+ client: botClient,
45762
+ __experimental_beta: true
45763
+ });
45764
+ });
45765
+ }
45692
45766
  function initialize(options) {
45693
45767
  const state = getState();
45694
45768
  if (state.initialized) {
@@ -45776,8 +45850,10 @@ var init_adk = __esm({
45776
45850
  return Environment;
45777
45851
  },
45778
45852
  get zai() {
45853
+ const contextCognitive = context2.get("cognitive", { optional: true });
45854
+ const cognitive = contextCognitive ?? getStandaloneCognitive();
45779
45855
  return new Zai2({
45780
- client: context2.get("cognitive"),
45856
+ client: cognitive,
45781
45857
  modelId: Array.isArray(adk.project.config.defaultModels.zai) ? adk.project.config.defaultModels.zai[0] ?? "auto" : adk.project.config.defaultModels.zai
45782
45858
  });
45783
45859
  },
@@ -45802,6 +45878,29 @@ var init_adk = __esm({
45802
45878
  conversations: state.primitives.conversations,
45803
45879
  triggers: state.primitives.triggers
45804
45880
  };
45881
+ },
45882
+ async execute(props) {
45883
+ const contextCognitive = context2.get("cognitive", { optional: true });
45884
+ const cognitive = contextCognitive ?? getStandaloneCognitive();
45885
+ const defaultModel = adk.project.config.defaultModels.autonomous;
45886
+ const { execute: llmz_execute, getValue: getValue2 } = await import("llmz");
45887
+ return llmz_execute({
45888
+ client: cognitive,
45889
+ instructions: props.instructions,
45890
+ ...props.tools && { tools: props.tools },
45891
+ ...props.objects && { objects: props.objects },
45892
+ ...props.exits && { exits: props.exits },
45893
+ ...props.signal && { signal: props.signal },
45894
+ temperature: async (ctx) => props.temperature ? await getValue2(props.temperature, ctx) : 0.7,
45895
+ model: async (ctx) => props.model ? await getValue2(props.model, ctx) : defaultModel,
45896
+ options: { loop: props.iterations ?? 10 },
45897
+ ...props.hooks?.onTrace && { onTrace: props.hooks.onTrace },
45898
+ ...props.hooks?.onIterationEnd && { onIterationEnd: props.hooks.onIterationEnd },
45899
+ ...props.hooks?.onBeforeTool && { onBeforeTool: props.hooks.onBeforeTool },
45900
+ ...props.hooks?.onAfterTool && { onAfterTool: props.hooks.onAfterTool },
45901
+ ...props.hooks?.onBeforeExecution && { onBeforeExecution: props.hooks.onBeforeExecution },
45902
+ ...props.hooks?.onExit && { onExit: props.hooks.onExit }
45903
+ });
45805
45904
  }
45806
45905
  };
45807
45906
  }
@@ -46308,7 +46407,7 @@ var init_tracked_tags = __esm({
46308
46407
  }
46309
46408
  static async loadAll() {
46310
46409
  await span("tags.loadAll", {}, async () => {
46311
- const client = context2.get("client")._inner;
46410
+ const client2 = context2.get("client")._inner;
46312
46411
  const bot2 = context2.get("bot", { optional: true });
46313
46412
  const user2 = context2.get("user", { optional: true });
46314
46413
  const conversation = context2.get("conversation", { optional: true });
@@ -46316,7 +46415,7 @@ var init_tracked_tags = __esm({
46316
46415
  if (bot2) {
46317
46416
  const botTags = bot2.tags;
46318
46417
  _TrackedTags.create({
46319
- client,
46418
+ client: client2,
46320
46419
  type: "bot",
46321
46420
  id: bot2.id,
46322
46421
  ...botTags && { initialTags: botTags }
@@ -46325,7 +46424,7 @@ var init_tracked_tags = __esm({
46325
46424
  if (user2) {
46326
46425
  const userTags = user2.tags;
46327
46426
  _TrackedTags.create({
46328
- client,
46427
+ client: client2,
46329
46428
  type: "user",
46330
46429
  id: user2.id,
46331
46430
  ...userTags && { initialTags: userTags }
@@ -46334,7 +46433,7 @@ var init_tracked_tags = __esm({
46334
46433
  if (conversation) {
46335
46434
  const conversationTags = conversation.tags;
46336
46435
  _TrackedTags.create({
46337
- client,
46436
+ client: client2,
46338
46437
  type: "conversation",
46339
46438
  id: conversation.id,
46340
46439
  ...conversationTags && { initialTags: conversationTags }
@@ -46343,7 +46442,7 @@ var init_tracked_tags = __esm({
46343
46442
  if (workflow) {
46344
46443
  const workflowTags = workflow.tags;
46345
46444
  _TrackedTags.create({
46346
- client,
46445
+ client: client2,
46347
46446
  type: "workflow",
46348
46447
  id: workflow.id,
46349
46448
  ...workflowTags && { initialTags: workflowTags }
@@ -46501,6 +46600,7 @@ var init_runtime2 = __esm({
46501
46600
  init_tracked_tags();
46502
46601
  init_actions();
46503
46602
  init_events();
46603
+ init_client();
46504
46604
  }
46505
46605
  });
46506
46606
 
@@ -47703,14 +47803,14 @@ var init_tracked_state = __esm({
47703
47803
  }
47704
47804
  static async loadAll() {
47705
47805
  await span("state.loadAll", {}, async () => {
47706
- const client = context2.get("client")._inner;
47806
+ const client2 = context2.get("client")._inner;
47707
47807
  const botId = context2.get("botId", { optional: true });
47708
47808
  const user2 = context2.get("user", { optional: true });
47709
47809
  const conversation = context2.get("conversation", { optional: true });
47710
47810
  const { adk: adk2 } = await Promise.resolve().then(() => (init_adk(), adk_exports));
47711
47811
  if (botId) {
47712
47812
  _TrackedState.create({
47713
- client,
47813
+ client: client2,
47714
47814
  name: BUILT_IN_STATES.bot,
47715
47815
  type: "bot",
47716
47816
  id: botId,
@@ -47719,7 +47819,7 @@ var init_tracked_state = __esm({
47719
47819
  }
47720
47820
  if (user2) {
47721
47821
  _TrackedState.create({
47722
- client,
47822
+ client: client2,
47723
47823
  name: BUILT_IN_STATES.user,
47724
47824
  type: "user",
47725
47825
  id: user2.id,
@@ -47736,7 +47836,7 @@ var init_tracked_state = __esm({
47736
47836
  }
47737
47837
  });
47738
47838
  _TrackedState.create({
47739
- client,
47839
+ client: client2,
47740
47840
  name: BUILT_IN_STATES.conversation,
47741
47841
  type: "conversation",
47742
47842
  id: conversation.id,