@botpress/runtime 1.6.9 → 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 (39) hide show
  1. package/dist/definition.js +117 -14
  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 +331 -217
  6. package/dist/internal.js.map +4 -4
  7. package/dist/library.js +296 -191
  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/conversation-instance.d.ts.map +1 -1
  12. package/dist/primitives/conversation.d.ts +30 -9
  13. package/dist/primitives/conversation.d.ts.map +1 -1
  14. package/dist/primitives/table.d.ts +11 -7
  15. package/dist/primitives/table.d.ts.map +1 -1
  16. package/dist/primitives/workflow.d.ts +18 -0
  17. package/dist/primitives/workflow.d.ts.map +1 -1
  18. package/dist/runtime/actions/computed-columns.d.ts +42 -0
  19. package/dist/runtime/actions/computed-columns.d.ts.map +1 -0
  20. package/dist/runtime/actions/index.d.ts +47 -0
  21. package/dist/runtime/actions/index.d.ts.map +1 -0
  22. package/dist/runtime/adk.d.ts.map +1 -1
  23. package/dist/runtime/context/http.d.ts +1 -1
  24. package/dist/runtime/context/http.d.ts.map +1 -1
  25. package/dist/runtime/handlers/actions.d.ts +3 -0
  26. package/dist/runtime/handlers/actions.d.ts.map +1 -0
  27. package/dist/runtime/handlers/event.d.ts.map +1 -1
  28. package/dist/runtime/handlers/index.d.ts +2 -0
  29. package/dist/runtime/handlers/index.d.ts.map +1 -1
  30. package/dist/runtime.js +207 -70
  31. package/dist/runtime.js.map +4 -4
  32. package/dist/telemetry/spans/index.d.ts +0 -52
  33. package/dist/telemetry/spans/index.d.ts.map +1 -1
  34. package/dist/ui.js +1 -2
  35. package/dist/ui.js.map +2 -2
  36. package/dist/workers/dev_worker.d.ts.map +1 -1
  37. package/dist/workers/parent_worker.d.ts.map +1 -1
  38. package/dist/workers/worker_pool.d.ts.map +1 -1
  39. package/package.json +1 -1
@@ -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.9", 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
 
@@ -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
  }
@@ -34328,7 +34328,7 @@ var TrackedStateSchema = z2.object({
34328
34328
  // src/runtime/tracked-state.ts
34329
34329
  init_define_BUILD();
34330
34330
  init_define_PACKAGE_VERSIONS();
34331
- import { z as z24 } from "@botpress/sdk";
34331
+ import { z as z25 } from "@botpress/sdk";
34332
34332
 
34333
34333
  // ../../node_modules/.bun/axios@1.12.2/node_modules/axios/index.js
34334
34334
  init_define_BUILD();
@@ -40057,7 +40057,7 @@ var actions = new Proxy({}, {
40057
40057
  const botAction = adk.project.actions.find((a) => a.name === propertyName);
40058
40058
  if (botAction) {
40059
40059
  const handler = async (input) => {
40060
- return botAction.handler(input);
40060
+ return await botAction.handler(input);
40061
40061
  };
40062
40062
  handler.asTool = () => new Autonomous.Tool({
40063
40063
  name: botAction.name,
@@ -40403,7 +40403,7 @@ var BaseConversationInstance = class {
40403
40403
  TrackedState;
40404
40404
  constructor(conversation, client) {
40405
40405
  this.id = conversation.id;
40406
- this.channel = conversation.channel;
40406
+ this.channel = `${conversation.integration}.${conversation.channel}`;
40407
40407
  this.integration = conversation.integration;
40408
40408
  this.tags = conversation.tags;
40409
40409
  this.conversation = conversation;
@@ -43048,6 +43048,7 @@ var BaseConversation = class {
43048
43048
  await this.#handler({
43049
43049
  type,
43050
43050
  message,
43051
+ channel: conversationInstance.channel,
43051
43052
  event,
43052
43053
  request: requestObject,
43053
43054
  conversation: conversationInstance,
@@ -43187,8 +43188,8 @@ var BaseAction = class {
43187
43188
  /**
43188
43189
  * Execute the action with input validation and output validation
43189
43190
  */
43190
- async execute({ input }) {
43191
- return this.handler(input);
43191
+ async execute({ input, client }) {
43192
+ return await this.handler({ input, client });
43192
43193
  }
43193
43194
  };
43194
43195
 
@@ -43213,6 +43214,14 @@ var BaseTable = class {
43213
43214
  return context2.get("client");
43214
43215
  }
43215
43216
  constructor(props) {
43217
+ const tableNameSchema = z14.string().min(1).refine((name) => !z14.string().uuid().safeParse(name).success, "Table name cannot be a UUID").refine(
43218
+ (name) => /^[a-zA-Z_$][a-zA-Z0-9_]{0,29}Table$/.test(name),
43219
+ "Table name must start with a letter/underscore, be 35 chars or less, contain only letters/numbers/underscores, and end with 'Table'"
43220
+ );
43221
+ const validation = tableNameSchema.safeParse(props.name);
43222
+ if (!validation.success) {
43223
+ throw new Errors.InvalidPrimitiveError(`Invalid table name '${props.name}'`, validation.error);
43224
+ }
43216
43225
  this.name = props.name;
43217
43226
  if (props.description !== void 0) {
43218
43227
  this.description = props.description;
@@ -44454,6 +44463,40 @@ var BaseWorkflow = class {
44454
44463
  workflow: res.workflow
44455
44464
  });
44456
44465
  }
44466
+ /**
44467
+ * Convert this workflow into an Autonomous.Tool that can be used with execute().
44468
+ * Starts the workflow and returns basic information about the workflow instance.
44469
+ *
44470
+ * @param options.description - Optional description override for the tool
44471
+ * @returns An Autonomous.Tool instance
44472
+ *
44473
+ * @example
44474
+ * const tool = MyWorkflow.asTool()
44475
+ *
44476
+ * await execute({
44477
+ * tools: [tool],
44478
+ * instructions: 'Use the workflow when needed'
44479
+ * })
44480
+ */
44481
+ asTool(options) {
44482
+ const description = options?.description || this.description || `Starts the ${this.name} workflow`;
44483
+ return new Autonomous.Tool({
44484
+ name: this.name,
44485
+ description,
44486
+ input: this._inputSchema,
44487
+ output: z22.object({
44488
+ workflowId: z22.string().describe("The ID of the started workflow"),
44489
+ status: z22.string().describe("The initial status of the workflow")
44490
+ }),
44491
+ handler: async (input) => {
44492
+ const instance = await this.start(input);
44493
+ return {
44494
+ workflowId: instance.id,
44495
+ status: instance.status
44496
+ };
44497
+ }
44498
+ });
44499
+ }
44457
44500
  };
44458
44501
 
44459
44502
  // src/runtime/workflows/knowledge-indexing.ts
@@ -44505,6 +44548,63 @@ var KnowledgeIndexingWorkflow = new BaseWorkflow({
44505
44548
 
44506
44549
  // src/runtime/adk.ts
44507
44550
  import { Zai } from "@botpress/zai";
44551
+
44552
+ // src/runtime/actions/index.ts
44553
+ init_define_BUILD();
44554
+ init_define_PACKAGE_VERSIONS();
44555
+
44556
+ // src/runtime/actions/computed-columns.ts
44557
+ init_define_BUILD();
44558
+ init_define_PACKAGE_VERSIONS();
44559
+ import { z as z24 } from "@botpress/sdk";
44560
+ var tablesRecomputeRows = new BaseAction({
44561
+ name: "tablesRecomputeRows",
44562
+ // skynet/packages/tables-api/src/services/computed/compute-stale-rows.ts
44563
+ input: z24.object({
44564
+ tableId: z24.string(),
44565
+ botId: z24.string(),
44566
+ schema: z24.any(),
44567
+ requests: z24.array(
44568
+ z24.object({
44569
+ row: z24.record(z24.any()),
44570
+ columnsToRecompute: z24.array(z24.string())
44571
+ })
44572
+ )
44573
+ }),
44574
+ output: z24.object({
44575
+ isFinished: z24.boolean(),
44576
+ rows: z24.array(z24.any())
44577
+ }),
44578
+ handler: async ({ input, client }) => {
44579
+ const { tableId, requests } = input;
44580
+ const { table: remoteTable } = await client._inner.getTable({ table: tableId });
44581
+ const table = adk.project.tables.find((x) => x.name === remoteTable.name);
44582
+ async function computeRow(row, columnsToRecompute) {
44583
+ const newRow = { id: row.id };
44584
+ for (const colName of columnsToRecompute) {
44585
+ const col = table?.columns[colName];
44586
+ if (!col || !col.computed) {
44587
+ newRow[colName] = { status: "error", error: "Column not found or not computed" };
44588
+ continue;
44589
+ }
44590
+ newRow[colName] = {
44591
+ status: "computed",
44592
+ value: await col.value(row)
44593
+ };
44594
+ }
44595
+ return newRow;
44596
+ }
44597
+ const computedRows = await Promise.all(
44598
+ requests.map(async (r) => {
44599
+ const computedRow = await computeRow(r.row, r.columnsToRecompute);
44600
+ return computedRow;
44601
+ })
44602
+ );
44603
+ return { isFinished: true, rows: computedRows };
44604
+ }
44605
+ });
44606
+
44607
+ // src/runtime/adk.ts
44508
44608
  var getState = () => getSingleton("__ADK_GLOBAL_PROJECT", () => {
44509
44609
  const state = {
44510
44610
  initialized: false,
@@ -44598,6 +44698,10 @@ var import_ms2 = __toESM(require_ms(), 1);
44598
44698
  init_define_BUILD();
44599
44699
  init_define_PACKAGE_VERSIONS();
44600
44700
 
44701
+ // src/runtime/handlers/actions.ts
44702
+ init_define_BUILD();
44703
+ init_define_PACKAGE_VERSIONS();
44704
+
44601
44705
  // src/telemetry/spans/index.ts
44602
44706
  init_define_BUILD();
44603
44707
  init_define_PACKAGE_VERSIONS();
@@ -44963,8 +45067,7 @@ var ActionHandlerSpan = {
44963
45067
  name: "handler.action",
44964
45068
  importance: "high",
44965
45069
  attributes: {
44966
- ...required("botId", "workflowId", "eventId", "event.type"),
44967
- ...optional("messageId", "userId", "integration", "channel", "conversationId", "parentWorkflowId"),
45070
+ ...required("botId"),
44968
45071
  "action.name": { type: "string", required: true },
44969
45072
  "action.input": { type: "json", required: true }
44970
45073
  }
@@ -45563,7 +45666,7 @@ var TrackedState = class _TrackedState {
45563
45666
  name: BUILT_IN_STATES.bot,
45564
45667
  type: "bot",
45565
45668
  id: botId,
45566
- schema: adk.project.config.bot?.state || z24.object({})
45669
+ schema: adk.project.config.bot?.state || z25.object({})
45567
45670
  });
45568
45671
  }
45569
45672
  if (user2) {
@@ -45572,7 +45675,7 @@ var TrackedState = class _TrackedState {
45572
45675
  name: BUILT_IN_STATES.user,
45573
45676
  type: "user",
45574
45677
  id: user2.id,
45575
- schema: adk.project.config.user?.state || z24.object({})
45678
+ schema: adk.project.config.user?.state || z25.object({})
45576
45679
  });
45577
45680
  }
45578
45681
  if (conversation) {
@@ -45589,7 +45692,7 @@ var TrackedState = class _TrackedState {
45589
45692
  name: BUILT_IN_STATES.conversation,
45590
45693
  type: "conversation",
45591
45694
  id: conversation.id,
45592
- schema: definition?.schema || z24.object({})
45695
+ schema: definition?.schema || z25.object({})
45593
45696
  });
45594
45697
  }
45595
45698
  const states = context2.get("states", { optional: true });