@botpress/runtime 1.7.1 → 1.7.3

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.1", 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.3", 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
 
@@ -44494,6 +44494,33 @@ init_define_PACKAGE_VERSIONS();
44494
44494
  init_define_BUILD();
44495
44495
  init_define_PACKAGE_VERSIONS();
44496
44496
  import { z as z19 } from "@botpress/sdk";
44497
+
44498
+ // src/runtime/actions/order-recompute-columns.ts
44499
+ init_define_BUILD();
44500
+ init_define_PACKAGE_VERSIONS();
44501
+ function orderRecomputeColumns(toRecompute, staleColumns, columns) {
44502
+ const ordered = [];
44503
+ const visited = /* @__PURE__ */ new Set();
44504
+ function visit(colName) {
44505
+ if (visited.has(colName)) return;
44506
+ visited.add(colName);
44507
+ const deps = columns[colName]?.dependencies || [];
44508
+ for (const dep of deps) {
44509
+ if (staleColumns.has(dep)) {
44510
+ visit(dep);
44511
+ }
44512
+ }
44513
+ if (staleColumns.has(colName) || toRecompute.includes(colName)) {
44514
+ ordered.push(colName);
44515
+ }
44516
+ }
44517
+ for (const col of toRecompute) {
44518
+ visit(col);
44519
+ }
44520
+ return ordered;
44521
+ }
44522
+
44523
+ // src/runtime/actions/computed-columns.ts
44497
44524
  var tablesRecomputeRows = new BaseAction({
44498
44525
  name: "tablesRecomputeRows",
44499
44526
  // skynet/packages/tables-api/src/services/computed/compute-stale-rows.ts
@@ -44518,26 +44545,48 @@ var tablesRecomputeRows = new BaseAction({
44518
44545
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
44519
44546
  async function computeRow(row, columnsToRecompute) {
44520
44547
  const newRow = { id: row.id };
44521
- for (const colName of columnsToRecompute) {
44548
+ const recompute = orderRecomputeColumns(
44549
+ columnsToRecompute,
44550
+ new Set(row.stale ?? []),
44551
+ table?.columns || {}
44552
+ );
44553
+ for (const colName of recompute) {
44522
44554
  const col = table?.columns[colName];
44523
44555
  if (!col || !col.computed) {
44524
44556
  newRow[colName] = { status: "error", error: "Column not found or not computed" };
44525
44557
  continue;
44526
44558
  }
44559
+ const value = await col.value(row);
44560
+ row[colName] = value;
44527
44561
  newRow[colName] = {
44528
44562
  status: "computed",
44529
- value: await col.value(row)
44563
+ value
44530
44564
  };
44531
44565
  }
44532
44566
  return newRow;
44533
44567
  }
44534
- const computedRows = await Promise.all(
44568
+ const MIN_REMAINING_TIME_MS = 5e3;
44569
+ const BUFFER_TIME_MS = 5e3;
44570
+ let recomputed = [];
44571
+ let isFinished = true;
44572
+ const remainingTime = context2.get("runtime").getRemainingExecutionTimeInMs();
44573
+ if (remainingTime && remainingTime < MIN_REMAINING_TIME_MS) {
44574
+ return { isFinished: false, rows: [] };
44575
+ }
44576
+ const timeoutPromise = new Promise((resolve) => {
44577
+ setTimeout(() => {
44578
+ isFinished = false;
44579
+ resolve();
44580
+ }, remainingTime - BUFFER_TIME_MS);
44581
+ });
44582
+ const allRowsPromise = Promise.all(
44535
44583
  requests.map(async (r) => {
44536
44584
  const computedRow = await computeRow(r.row, r.columnsToRecompute);
44537
- return computedRow;
44585
+ recomputed.push(computedRow);
44538
44586
  })
44539
44587
  );
44540
- return { isFinished: true, rows: computedRows };
44588
+ await Promise.race([timeoutPromise, allRowsPromise]);
44589
+ return { isFinished, rows: recomputed };
44541
44590
  }
44542
44591
  });
44543
44592