@botpress/runtime 1.6.10 → 1.7.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.
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
@@ -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.1", adk: "1.7.0", sdk: "4.18.1", 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,
@@ -43188,8 +43188,8 @@ var BaseAction = class {
43188
43188
  /**
43189
43189
  * Execute the action with input validation and output validation
43190
43190
  */
43191
- async execute({ input }) {
43192
- return this.handler(input);
43191
+ async execute({ input, client }) {
43192
+ return await this.handler({ input, client });
43193
43193
  }
43194
43194
  };
43195
43195
 
@@ -43214,6 +43214,14 @@ var BaseTable = class {
43214
43214
  return context2.get("client");
43215
43215
  }
43216
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
+ }
43217
43225
  this.name = props.name;
43218
43226
  if (props.description !== void 0) {
43219
43227
  this.description = props.description;
@@ -44455,6 +44463,40 @@ var BaseWorkflow = class {
44455
44463
  workflow: res.workflow
44456
44464
  });
44457
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
+ }
44458
44500
  };
44459
44501
 
44460
44502
  // src/runtime/workflows/knowledge-indexing.ts
@@ -44506,6 +44548,63 @@ var KnowledgeIndexingWorkflow = new BaseWorkflow({
44506
44548
 
44507
44549
  // src/runtime/adk.ts
44508
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
44509
44608
  var getState = () => getSingleton("__ADK_GLOBAL_PROJECT", () => {
44510
44609
  const state = {
44511
44610
  initialized: false,
@@ -44599,6 +44698,10 @@ var import_ms2 = __toESM(require_ms(), 1);
44599
44698
  init_define_BUILD();
44600
44699
  init_define_PACKAGE_VERSIONS();
44601
44700
 
44701
+ // src/runtime/handlers/actions.ts
44702
+ init_define_BUILD();
44703
+ init_define_PACKAGE_VERSIONS();
44704
+
44602
44705
  // src/telemetry/spans/index.ts
44603
44706
  init_define_BUILD();
44604
44707
  init_define_PACKAGE_VERSIONS();
@@ -44964,8 +45067,7 @@ var ActionHandlerSpan = {
44964
45067
  name: "handler.action",
44965
45068
  importance: "high",
44966
45069
  attributes: {
44967
- ...required("botId", "workflowId", "eventId", "event.type"),
44968
- ...optional("messageId", "userId", "integration", "channel", "conversationId", "parentWorkflowId"),
45070
+ ...required("botId"),
44969
45071
  "action.name": { type: "string", required: true },
44970
45072
  "action.input": { type: "json", required: true }
44971
45073
  }
@@ -45564,7 +45666,7 @@ var TrackedState = class _TrackedState {
45564
45666
  name: BUILT_IN_STATES.bot,
45565
45667
  type: "bot",
45566
45668
  id: botId,
45567
- schema: adk.project.config.bot?.state || z24.object({})
45669
+ schema: adk.project.config.bot?.state || z25.object({})
45568
45670
  });
45569
45671
  }
45570
45672
  if (user2) {
@@ -45573,7 +45675,7 @@ var TrackedState = class _TrackedState {
45573
45675
  name: BUILT_IN_STATES.user,
45574
45676
  type: "user",
45575
45677
  id: user2.id,
45576
- schema: adk.project.config.user?.state || z24.object({})
45678
+ schema: adk.project.config.user?.state || z25.object({})
45577
45679
  });
45578
45680
  }
45579
45681
  if (conversation) {
@@ -45590,7 +45692,7 @@ var TrackedState = class _TrackedState {
45590
45692
  name: BUILT_IN_STATES.conversation,
45591
45693
  type: "conversation",
45592
45694
  id: conversation.id,
45593
- schema: definition?.schema || z24.object({})
45695
+ schema: definition?.schema || z25.object({})
45594
45696
  });
45595
45697
  }
45596
45698
  const states = context2.get("states", { optional: true });