@botpress/runtime 1.7.2 → 1.7.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"computed-columns.d.ts","sourceRoot":"","sources":["../../../src/runtime/actions/computed-columns.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAGpD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkD9B,CAAA"}
1
+ {"version":3,"file":"computed-columns.d.ts","sourceRoot":"","sources":["../../../src/runtime/actions/computed-columns.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKpD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+E9B,CAAA"}
@@ -0,0 +1,30 @@
1
+ type ColumnDefinition = {
2
+ computed: boolean;
3
+ dependencies?: string[];
4
+ value: (row: Record<string, any>) => Promise<any>;
5
+ };
6
+ /**
7
+ * Orders columns for recomputation based on their dependencies using topological sort.
8
+ * Ensures that dependencies are computed before columns that depend on them.
9
+ *
10
+ * @param toRecompute - Array of column names that need to be recomputed
11
+ * @param staleColumns - Set of column names that are currently stale (need recomputation)
12
+ * @param columns - Record of all column definitions with their dependencies
13
+ * @returns Array of column names in the order they should be computed
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // Column C depends on B, B depends on A
18
+ * const columns = {
19
+ * a: { computed: true, dependencies: [], value: async (row) => row.base * 2 },
20
+ * b: { computed: true, dependencies: ['a'], value: async (row) => row.a + 10 },
21
+ * c: { computed: true, dependencies: ['b'], value: async (row) => row.b * 3 }
22
+ * }
23
+ *
24
+ * const ordered = orderRecomputeColumns(['c'], new Set(['a', 'b', 'c']), columns)
25
+ * // Result: ['a', 'b', 'c'] - dependencies computed first
26
+ * ```
27
+ */
28
+ export declare function orderRecomputeColumns(toRecompute: string[], staleColumns: Set<string>, columns: Record<string, ColumnDefinition>): string[];
29
+ export {};
30
+ //# sourceMappingURL=order-recompute-columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-recompute-columns.d.ts","sourceRoot":"","sources":["../../../src/runtime/actions/order-recompute-columns.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;CAClD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EAAE,EACrB,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GACxC,MAAM,EAAE,CA2BV"}
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.7.2", adk: "1.7.0", sdk: "4.18.1", llmz: "0.0.27", zai: "2.5.0", cognitive: "0.2.0" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.7.4", adk: "1.7.2", sdk: "4.18.1", llmz: "0.0.27", zai: "2.5.0", cognitive: "0.2.0" };
52
52
  }
53
53
  });
54
54
 
@@ -40349,6 +40349,8 @@ ${issues.join("\n")}`;
40349
40349
  init_define_BUILD();
40350
40350
  init_define_PACKAGE_VERSIONS();
40351
40351
  import { z as z14 } from "@botpress/sdk";
40352
+ import { Cognitive as Cognitive2 } from "@botpress/cognitive";
40353
+ import { Zai } from "@botpress/zai";
40352
40354
 
40353
40355
  // src/primitives/index.ts
40354
40356
  init_define_BUILD();
@@ -44484,7 +44486,7 @@ var BuiltInWorkflows = {
44484
44486
  };
44485
44487
 
44486
44488
  // src/runtime/adk.ts
44487
- import { Zai } from "@botpress/zai";
44489
+ import { Zai as Zai2 } from "@botpress/zai";
44488
44490
 
44489
44491
  // src/runtime/actions/index.ts
44490
44492
  init_define_BUILD();
@@ -44494,6 +44496,33 @@ init_define_PACKAGE_VERSIONS();
44494
44496
  init_define_BUILD();
44495
44497
  init_define_PACKAGE_VERSIONS();
44496
44498
  import { z as z19 } from "@botpress/sdk";
44499
+
44500
+ // src/runtime/actions/order-recompute-columns.ts
44501
+ init_define_BUILD();
44502
+ init_define_PACKAGE_VERSIONS();
44503
+ function orderRecomputeColumns(toRecompute, staleColumns, columns) {
44504
+ const ordered = [];
44505
+ const visited = /* @__PURE__ */ new Set();
44506
+ function visit(colName) {
44507
+ if (visited.has(colName)) return;
44508
+ visited.add(colName);
44509
+ const deps = columns[colName]?.dependencies || [];
44510
+ for (const dep of deps) {
44511
+ if (staleColumns.has(dep)) {
44512
+ visit(dep);
44513
+ }
44514
+ }
44515
+ if (staleColumns.has(colName) || toRecompute.includes(colName)) {
44516
+ ordered.push(colName);
44517
+ }
44518
+ }
44519
+ for (const col of toRecompute) {
44520
+ visit(col);
44521
+ }
44522
+ return ordered;
44523
+ }
44524
+
44525
+ // src/runtime/actions/computed-columns.ts
44497
44526
  var tablesRecomputeRows = new BaseAction({
44498
44527
  name: "tablesRecomputeRows",
44499
44528
  // skynet/packages/tables-api/src/services/computed/compute-stale-rows.ts
@@ -44518,26 +44547,48 @@ var tablesRecomputeRows = new BaseAction({
44518
44547
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
44519
44548
  async function computeRow(row, columnsToRecompute) {
44520
44549
  const newRow = { id: row.id };
44521
- for (const colName of columnsToRecompute) {
44550
+ const recompute = orderRecomputeColumns(
44551
+ columnsToRecompute,
44552
+ new Set(row.stale ?? []),
44553
+ table?.columns || {}
44554
+ );
44555
+ for (const colName of recompute) {
44522
44556
  const col = table?.columns[colName];
44523
44557
  if (!col || !col.computed) {
44524
44558
  newRow[colName] = { status: "error", error: "Column not found or not computed" };
44525
44559
  continue;
44526
44560
  }
44561
+ const value = await col.value(row);
44562
+ row[colName] = value;
44527
44563
  newRow[colName] = {
44528
44564
  status: "computed",
44529
- value: await col.value(row)
44565
+ value
44530
44566
  };
44531
44567
  }
44532
44568
  return newRow;
44533
44569
  }
44534
- const computedRows = await Promise.all(
44570
+ const MIN_REMAINING_TIME_MS = 5e3;
44571
+ const BUFFER_TIME_MS = 5e3;
44572
+ let recomputed = [];
44573
+ let isFinished = true;
44574
+ const remainingTime = context2.get("runtime").getRemainingExecutionTimeInMs();
44575
+ if (remainingTime && remainingTime < MIN_REMAINING_TIME_MS) {
44576
+ return { isFinished: false, rows: [] };
44577
+ }
44578
+ const timeoutPromise = new Promise((resolve) => {
44579
+ setTimeout(() => {
44580
+ isFinished = false;
44581
+ resolve();
44582
+ }, remainingTime - BUFFER_TIME_MS);
44583
+ });
44584
+ const allRowsPromise = Promise.all(
44535
44585
  requests.map(async (r) => {
44536
44586
  const computedRow = await computeRow(r.row, r.columnsToRecompute);
44537
- return computedRow;
44587
+ recomputed.push(computedRow);
44538
44588
  })
44539
44589
  );
44540
- return { isFinished: true, rows: computedRows };
44590
+ await Promise.race([timeoutPromise, allRowsPromise]);
44591
+ return { isFinished, rows: recomputed };
44541
44592
  }
44542
44593
  });
44543
44594
 
@@ -44622,7 +44673,7 @@ var adk = {
44622
44673
  return Environment;
44623
44674
  },
44624
44675
  get zai() {
44625
- return new Zai({
44676
+ return new Zai2({
44626
44677
  client: context2.get("cognitive"),
44627
44678
  modelId: Array.isArray(adk.project.config.defaultModels.zai) ? adk.project.config.defaultModels.zai[0] ?? "auto" : adk.project.config.defaultModels.zai
44628
44679
  });