@botpress/runtime 1.6.10 → 1.7.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.
Files changed (36) hide show
  1. package/dist/definition.js +115 -13
  2. package/dist/definition.js.map +4 -4
  3. package/dist/internal.d.ts +1 -0
  4. package/dist/internal.d.ts.map +1 -1
  5. package/dist/internal.js +329 -216
  6. package/dist/internal.js.map +4 -4
  7. package/dist/library.js +294 -190
  8. package/dist/library.js.map +4 -4
  9. package/dist/primitives/action.d.ts +7 -3
  10. package/dist/primitives/action.d.ts.map +1 -1
  11. package/dist/primitives/table.d.ts +11 -7
  12. package/dist/primitives/table.d.ts.map +1 -1
  13. package/dist/primitives/workflow.d.ts +18 -0
  14. package/dist/primitives/workflow.d.ts.map +1 -1
  15. package/dist/runtime/actions/computed-columns.d.ts +42 -0
  16. package/dist/runtime/actions/computed-columns.d.ts.map +1 -0
  17. package/dist/runtime/actions/index.d.ts +47 -0
  18. package/dist/runtime/actions/index.d.ts.map +1 -0
  19. package/dist/runtime/adk.d.ts.map +1 -1
  20. package/dist/runtime/context/http.d.ts +1 -1
  21. package/dist/runtime/context/http.d.ts.map +1 -1
  22. package/dist/runtime/handlers/actions.d.ts +3 -0
  23. package/dist/runtime/handlers/actions.d.ts.map +1 -0
  24. package/dist/runtime/handlers/event.d.ts.map +1 -1
  25. package/dist/runtime/handlers/index.d.ts +2 -0
  26. package/dist/runtime/handlers/index.d.ts.map +1 -1
  27. package/dist/runtime.js +205 -69
  28. package/dist/runtime.js.map +4 -4
  29. package/dist/telemetry/spans/index.d.ts +0 -52
  30. package/dist/telemetry/spans/index.d.ts.map +1 -1
  31. package/dist/ui.js +1 -2
  32. package/dist/ui.js.map +2 -2
  33. package/dist/workers/dev_worker.d.ts.map +1 -1
  34. package/dist/workers/parent_worker.d.ts.map +1 -1
  35. package/dist/workers/worker_pool.d.ts.map +1 -1
  36. package/package.json +1 -1
package/dist/runtime.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.6.10", adk: "not-installed", sdk: "4.17.3", llmz: "0.0.27", zai: "2.5.0", cognitive: "0.2.0" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.7.0", adk: "not-installed", sdk: "4.17.3", llmz: "0.0.27", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -24288,7 +24288,7 @@ var require_common = __commonJS({
24288
24288
  "../../node_modules/.bun/debug@4.4.3/node_modules/debug/src/common.js"(exports2, module) {
24289
24289
  init_define_BUILD();
24290
24290
  init_define_PACKAGE_VERSIONS();
24291
- function setup5(env2) {
24291
+ function setup6(env2) {
24292
24292
  createDebug.debug = createDebug;
24293
24293
  createDebug.default = createDebug;
24294
24294
  createDebug.coerce = coerce;
@@ -24458,7 +24458,7 @@ var require_common = __commonJS({
24458
24458
  createDebug.enable(createDebug.load());
24459
24459
  return createDebug;
24460
24460
  }
24461
- module.exports = setup5;
24461
+ module.exports = setup6;
24462
24462
  }
24463
24463
  });
24464
24464
 
@@ -27678,11 +27678,11 @@ function expand_(str, isTop) {
27678
27678
  if (pad) {
27679
27679
  const need = width - c.length;
27680
27680
  if (need > 0) {
27681
- const z25 = new Array(need + 1).join("0");
27681
+ const z26 = new Array(need + 1).join("0");
27682
27682
  if (i < 0) {
27683
- c = "-" + z25 + c.slice(1);
27683
+ c = "-" + z26 + c.slice(1);
27684
27684
  } else {
27685
- c = z25 + c;
27685
+ c = z26 + c;
27686
27686
  }
27687
27687
  }
27688
27688
  }
@@ -35741,7 +35741,7 @@ var agentRegistry = getSingleton("__ADK_GLOBAL_AGENT_REGISTRY", () => new AgentR
35741
35741
  // src/runtime/tracked-state.ts
35742
35742
  init_define_BUILD();
35743
35743
  init_define_PACKAGE_VERSIONS();
35744
- import { z as z20 } from "@botpress/sdk";
35744
+ import { z as z21 } from "@botpress/sdk";
35745
35745
 
35746
35746
  // ../../node_modules/.bun/axios@1.12.2/node_modules/axios/index.js
35747
35747
  init_define_BUILD();
@@ -40027,7 +40027,7 @@ var actions = new Proxy({}, {
40027
40027
  const botAction = adk.project.actions.find((a) => a.name === propertyName);
40028
40028
  if (botAction) {
40029
40029
  const handler = async (input) => {
40030
- return botAction.handler(input);
40030
+ return await botAction.handler(input);
40031
40031
  };
40032
40032
  handler.asTool = () => new Autonomous.Tool({
40033
40033
  name: botAction.name,
@@ -43177,8 +43177,8 @@ var BaseAction = class {
43177
43177
  /**
43178
43178
  * Execute the action with input validation and output validation
43179
43179
  */
43180
- async execute({ input }) {
43181
- return this.handler(input);
43180
+ async execute({ input, client }) {
43181
+ return await this.handler({ input, client });
43182
43182
  }
43183
43183
  };
43184
43184
 
@@ -43203,6 +43203,14 @@ var BaseTable = class {
43203
43203
  return context2.get("client");
43204
43204
  }
43205
43205
  constructor(props) {
43206
+ const tableNameSchema = z10.string().min(1).refine((name) => !z10.string().uuid().safeParse(name).success, "Table name cannot be a UUID").refine(
43207
+ (name) => /^[a-zA-Z_$][a-zA-Z0-9_]{0,29}Table$/.test(name),
43208
+ "Table name must start with a letter/underscore, be 35 chars or less, contain only letters/numbers/underscores, and end with 'Table'"
43209
+ );
43210
+ const validation = tableNameSchema.safeParse(props.name);
43211
+ if (!validation.success) {
43212
+ throw new Errors.InvalidPrimitiveError(`Invalid table name '${props.name}'`, validation.error);
43213
+ }
43206
43214
  this.name = props.name;
43207
43215
  if (props.description !== void 0) {
43208
43216
  this.description = props.description;
@@ -44387,6 +44395,40 @@ var BaseWorkflow = class {
44387
44395
  workflow: res.workflow
44388
44396
  });
44389
44397
  }
44398
+ /**
44399
+ * Convert this workflow into an Autonomous.Tool that can be used with execute().
44400
+ * Starts the workflow and returns basic information about the workflow instance.
44401
+ *
44402
+ * @param options.description - Optional description override for the tool
44403
+ * @returns An Autonomous.Tool instance
44404
+ *
44405
+ * @example
44406
+ * const tool = MyWorkflow.asTool()
44407
+ *
44408
+ * await execute({
44409
+ * tools: [tool],
44410
+ * instructions: 'Use the workflow when needed'
44411
+ * })
44412
+ */
44413
+ asTool(options) {
44414
+ const description = options?.description || this.description || `Starts the ${this.name} workflow`;
44415
+ return new Autonomous.Tool({
44416
+ name: this.name,
44417
+ description,
44418
+ input: this._inputSchema,
44419
+ output: z17.object({
44420
+ workflowId: z17.string().describe("The ID of the started workflow"),
44421
+ status: z17.string().describe("The initial status of the workflow")
44422
+ }),
44423
+ handler: async (input) => {
44424
+ const instance = await this.start(input);
44425
+ return {
44426
+ workflowId: instance.id,
44427
+ status: instance.status
44428
+ };
44429
+ }
44430
+ });
44431
+ }
44390
44432
  };
44391
44433
 
44392
44434
  // src/runtime/workflows/knowledge-indexing.ts
@@ -44443,6 +44485,68 @@ var BuiltInWorkflows = {
44443
44485
 
44444
44486
  // src/runtime/adk.ts
44445
44487
  import { Zai } from "@botpress/zai";
44488
+
44489
+ // src/runtime/actions/index.ts
44490
+ init_define_BUILD();
44491
+ init_define_PACKAGE_VERSIONS();
44492
+
44493
+ // src/runtime/actions/computed-columns.ts
44494
+ init_define_BUILD();
44495
+ init_define_PACKAGE_VERSIONS();
44496
+ import { z as z19 } from "@botpress/sdk";
44497
+ var tablesRecomputeRows = new BaseAction({
44498
+ name: "tablesRecomputeRows",
44499
+ // skynet/packages/tables-api/src/services/computed/compute-stale-rows.ts
44500
+ input: z19.object({
44501
+ tableId: z19.string(),
44502
+ botId: z19.string(),
44503
+ schema: z19.any(),
44504
+ requests: z19.array(
44505
+ z19.object({
44506
+ row: z19.record(z19.any()),
44507
+ columnsToRecompute: z19.array(z19.string())
44508
+ })
44509
+ )
44510
+ }),
44511
+ output: z19.object({
44512
+ isFinished: z19.boolean(),
44513
+ rows: z19.array(z19.any())
44514
+ }),
44515
+ handler: async ({ input, client }) => {
44516
+ const { tableId, requests } = input;
44517
+ const { table: remoteTable } = await client._inner.getTable({ table: tableId });
44518
+ const table = adk.project.tables.find((x) => x.name === remoteTable.name);
44519
+ async function computeRow(row, columnsToRecompute) {
44520
+ const newRow = { id: row.id };
44521
+ for (const colName of columnsToRecompute) {
44522
+ const col = table?.columns[colName];
44523
+ if (!col || !col.computed) {
44524
+ newRow[colName] = { status: "error", error: "Column not found or not computed" };
44525
+ continue;
44526
+ }
44527
+ newRow[colName] = {
44528
+ status: "computed",
44529
+ value: await col.value(row)
44530
+ };
44531
+ }
44532
+ return newRow;
44533
+ }
44534
+ const computedRows = await Promise.all(
44535
+ requests.map(async (r) => {
44536
+ const computedRow = await computeRow(r.row, r.columnsToRecompute);
44537
+ return computedRow;
44538
+ })
44539
+ );
44540
+ return { isFinished: true, rows: computedRows };
44541
+ }
44542
+ });
44543
+
44544
+ // src/runtime/actions/index.ts
44545
+ var BuiltInActions = {
44546
+ tablesRecomputeRows
44547
+ };
44548
+
44549
+ // src/runtime/adk.ts
44446
44550
  var getState = () => getSingleton("__ADK_GLOBAL_PROJECT", () => {
44447
44551
  const state = {
44448
44552
  initialized: false,
@@ -44466,6 +44570,7 @@ function initialize(options) {
44466
44570
  state.projectConfig = options.config;
44467
44571
  state.initialized = true;
44468
44572
  state.primitives.workflows.push(...Object.values(BuiltInWorkflows));
44573
+ state.primitives.actions.push(...Object.values(BuiltInActions));
44469
44574
  }
44470
44575
  function register(...primitives) {
44471
44576
  const state = getState();
@@ -44578,12 +44683,12 @@ var importScheduledHeavyImports = async () => {
44578
44683
  // src/runtime/tracked-state-schema.ts
44579
44684
  init_define_BUILD();
44580
44685
  init_define_PACKAGE_VERSIONS();
44581
- import { z as z19 } from "@botpress/sdk";
44582
- var TrackedStateSchema = z19.object({
44583
- value: z19.any(),
44584
- location: z19.discriminatedUnion("type", [
44585
- z19.object({ type: z19.literal("state") }),
44586
- z19.object({ type: z19.literal("file"), key: z19.string() })
44686
+ import { z as z20 } from "@botpress/sdk";
44687
+ var TrackedStateSchema = z20.object({
44688
+ value: z20.any(),
44689
+ location: z20.discriminatedUnion("type", [
44690
+ z20.object({ type: z20.literal("state") }),
44691
+ z20.object({ type: z20.literal("file"), key: z20.string() })
44587
44692
  ])
44588
44693
  });
44589
44694
 
@@ -44680,7 +44785,7 @@ var TrackedState2 = class _TrackedState {
44680
44785
  name: BUILT_IN_STATES.bot,
44681
44786
  type: "bot",
44682
44787
  id: botId,
44683
- schema: adk.project.config.bot?.state || z20.object({})
44788
+ schema: adk.project.config.bot?.state || z21.object({})
44684
44789
  });
44685
44790
  }
44686
44791
  if (user2) {
@@ -44689,7 +44794,7 @@ var TrackedState2 = class _TrackedState {
44689
44794
  name: BUILT_IN_STATES.user,
44690
44795
  type: "user",
44691
44796
  id: user2.id,
44692
- schema: adk.project.config.user?.state || z20.object({})
44797
+ schema: adk.project.config.user?.state || z21.object({})
44693
44798
  });
44694
44799
  }
44695
44800
  if (conversation) {
@@ -44706,7 +44811,7 @@ var TrackedState2 = class _TrackedState {
44706
44811
  name: BUILT_IN_STATES.conversation,
44707
44812
  type: "conversation",
44708
44813
  id: conversation.id,
44709
- schema: definition?.schema || z20.object({})
44814
+ schema: definition?.schema || z21.object({})
44710
44815
  });
44711
44816
  }
44712
44817
  const states = context2.get("states", { optional: true });
@@ -44998,48 +45103,48 @@ async function handleInspectorChrome() {
44998
45103
  // src/runtime/events.ts
44999
45104
  init_define_BUILD();
45000
45105
  init_define_PACKAGE_VERSIONS();
45001
- import { z as z21 } from "@botpress/sdk";
45106
+ import { z as z22 } from "@botpress/sdk";
45002
45107
  var WorkflowCallbackEvent = {
45003
45108
  name: "workflowCallback",
45004
- schema: z21.object({
45005
- workflow: z21.string(),
45006
- workflowId: z21.string(),
45007
- target: z21.union([
45008
- z21.object({
45009
- conversationId: z21.string()
45109
+ schema: z22.object({
45110
+ workflow: z22.string(),
45111
+ workflowId: z22.string(),
45112
+ target: z22.union([
45113
+ z22.object({
45114
+ conversationId: z22.string()
45010
45115
  }),
45011
- z21.object({
45012
- workflowId: z21.string()
45116
+ z22.object({
45117
+ workflowId: z22.string()
45013
45118
  })
45014
45119
  ]),
45015
- status: z21.enum(["completed", "failed", "canceled", "timed_out"]),
45016
- output: z21.any().optional(),
45017
- error: z21.string().optional()
45120
+ status: z22.enum(["completed", "failed", "canceled", "timed_out"]),
45121
+ output: z22.any().optional(),
45122
+ error: z22.string().optional()
45018
45123
  })
45019
45124
  };
45020
45125
  var WorkflowScheduleEvent = {
45021
45126
  name: "workflowSchedule",
45022
- schema: z21.object({
45023
- workflow: z21.string()
45127
+ schema: z22.object({
45128
+ workflow: z22.string()
45024
45129
  })
45025
45130
  };
45026
45131
  var WorkflowContinueEvent = {
45027
45132
  name: "workflowContinue",
45028
- schema: z21.object({})
45133
+ schema: z22.object({})
45029
45134
  };
45030
45135
  var SubworkflowFinished = {
45031
45136
  name: "subworkflowFinished",
45032
- schema: z21.object({})
45137
+ schema: z22.object({})
45033
45138
  };
45034
45139
  var WorkflowDataRequestEvent = {
45035
45140
  name: "workflowDataRequest",
45036
- schema: z21.object({
45037
- workflowId: z21.string(),
45038
- workflowName: z21.string(),
45039
- stepName: z21.string(),
45040
- request: z21.string(),
45041
- message: z21.string(),
45042
- schema: z21.any()
45141
+ schema: z22.object({
45142
+ workflowId: z22.string(),
45143
+ workflowName: z22.string(),
45144
+ stepName: z22.string(),
45145
+ request: z22.string(),
45146
+ message: z22.string(),
45147
+ schema: z22.any()
45043
45148
  // JSON Schema
45044
45149
  })
45045
45150
  };
@@ -45420,7 +45525,7 @@ function getItemSize(item) {
45420
45525
  // src/runtime/chat/messages.ts
45421
45526
  init_define_BUILD();
45422
45527
  init_define_PACKAGE_VERSIONS();
45423
- import { z as z22 } from "@bpinternal/zui";
45528
+ import { z as z23 } from "@bpinternal/zui";
45424
45529
  import { isAnyComponent } from "llmz";
45425
45530
 
45426
45531
  // src/runtime/chat/html.ts
@@ -45558,13 +45663,13 @@ function joinMarkdownChildren(children, stringify3 = (el) => JSON.stringify(el,
45558
45663
  return [...acc, prev, str];
45559
45664
  }, []).join("").trim();
45560
45665
  }
45561
- var Message = z22.object({
45562
- __jsx: z22.literal(true),
45563
- type: z22.literal("MESSAGE"),
45564
- props: z22.object({
45565
- type: z22.enum(["error", "info", "success", "prompt"]).default("info").catch(() => "info")
45666
+ var Message = z23.object({
45667
+ __jsx: z23.literal(true),
45668
+ type: z23.literal("MESSAGE"),
45669
+ props: z23.object({
45670
+ type: z23.enum(["error", "info", "success", "prompt"]).default("info").catch(() => "info")
45566
45671
  }).passthrough(),
45567
- children: z22.array(z22.any()).default([]).transform((children) => {
45672
+ children: z23.array(z23.any()).default([]).transform((children) => {
45568
45673
  children = children.map((child) => Array.isArray(child) ? child : [child]).flat();
45569
45674
  const text = joinMarkdownChildren(
45570
45675
  children.filter((x) => !isAnyComponent(x)).map((x) => rebuildTSXCode(x, false))
@@ -46051,21 +46156,21 @@ ${footer}`.trim();
46051
46156
  // src/runtime/chat/transcript.ts
46052
46157
  init_define_BUILD();
46053
46158
  init_define_PACKAGE_VERSIONS();
46054
- import { z as z23 } from "@botpress/sdk";
46055
- var AttachmentSchema = z23.object({
46056
- type: z23.literal("image"),
46057
- url: z23.string()
46058
- });
46059
- var TranscriptItemSchema = z23.object({
46060
- id: z23.string(),
46061
- role: z23.union([z23.literal("assistant"), z23.literal("user"), z23.literal("event"), z23.literal("summary")]),
46062
- name: z23.string().optional(),
46063
- createdAt: z23.string().optional(),
46064
- content: z23.string().optional(),
46065
- attachments: z23.array(AttachmentSchema).optional(),
46066
- payload: z23.unknown().optional()
46067
- });
46068
- var TranscriptSchema = z23.array(TranscriptItemSchema);
46159
+ import { z as z24 } from "@botpress/sdk";
46160
+ var AttachmentSchema = z24.object({
46161
+ type: z24.literal("image"),
46162
+ url: z24.string()
46163
+ });
46164
+ var TranscriptItemSchema = z24.object({
46165
+ id: z24.string(),
46166
+ role: z24.union([z24.literal("assistant"), z24.literal("user"), z24.literal("event"), z24.literal("summary")]),
46167
+ name: z24.string().optional(),
46168
+ createdAt: z24.string().optional(),
46169
+ content: z24.string().optional(),
46170
+ attachments: z24.array(AttachmentSchema).optional(),
46171
+ payload: z24.unknown().optional()
46172
+ });
46173
+ var TranscriptSchema = z24.array(TranscriptItemSchema);
46069
46174
 
46070
46175
  // src/runtime/handlers/index.ts
46071
46176
  init_define_BUILD();
@@ -46445,12 +46550,44 @@ var setup4 = (bot2) => {
46445
46550
  });
46446
46551
  };
46447
46552
 
46553
+ // src/runtime/handlers/actions.ts
46554
+ var actions_exports = {};
46555
+ __export(actions_exports, {
46556
+ setup: () => setup5
46557
+ });
46558
+ init_define_BUILD();
46559
+ init_define_PACKAGE_VERSIONS();
46560
+ var setup5 = (bot2) => {
46561
+ const handlers2 = bot2._actionHandlers;
46562
+ for (const action of adk.project.actions) {
46563
+ handlers2[action.name] = async (props) => {
46564
+ return await span(
46565
+ "handler.action",
46566
+ {
46567
+ "action.input": props.input,
46568
+ "action.name": action.name,
46569
+ botId: props.ctx.botId
46570
+ },
46571
+ async () => {
46572
+ await TrackedState2.loadAll();
46573
+ try {
46574
+ return await action.execute(props);
46575
+ } finally {
46576
+ await TrackedState2.saveAllDirty();
46577
+ }
46578
+ }
46579
+ );
46580
+ };
46581
+ }
46582
+ };
46583
+
46448
46584
  // src/runtime/handlers/index.ts
46449
46585
  var handlers = {
46450
46586
  conversation: conversation_exports,
46451
46587
  trigger: trigger_exports,
46452
46588
  workflow: workflow_exports,
46453
- event: event_exports
46589
+ event: event_exports,
46590
+ actions: actions_exports
46454
46591
  };
46455
46592
 
46456
46593
  // src/telemetry/spans/index.ts
@@ -46818,8 +46955,7 @@ var ActionHandlerSpan = {
46818
46955
  name: "handler.action",
46819
46956
  importance: "high",
46820
46957
  attributes: {
46821
- ...required("botId", "workflowId", "eventId", "event.type"),
46822
- ...optional("messageId", "userId", "integration", "channel", "conversationId", "parentWorkflowId"),
46958
+ ...required("botId"),
46823
46959
  "action.name": { type: "string", required: true },
46824
46960
  "action.input": { type: "json", required: true }
46825
46961
  }
@@ -47381,7 +47517,7 @@ function installStructuredLogging() {
47381
47517
 
47382
47518
  // src/runtime.ts
47383
47519
  init_trigger_tags();
47384
- import { z as z24 } from "@botpress/sdk";
47520
+ import { z as z25 } from "@botpress/sdk";
47385
47521
  if (Environment.isDevelopment()) {
47386
47522
  installStructuredLogging();
47387
47523
  }
@@ -47423,7 +47559,7 @@ export {
47423
47559
  shutdownPromiseTracker,
47424
47560
  trackPromise,
47425
47561
  user,
47426
- z24 as z
47562
+ z25 as z
47427
47563
  };
47428
47564
  /*! Bundled license information:
47429
47565