@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.
@@ -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
 
@@ -44557,6 +44557,33 @@ init_define_PACKAGE_VERSIONS();
44557
44557
  init_define_BUILD();
44558
44558
  init_define_PACKAGE_VERSIONS();
44559
44559
  import { z as z24 } from "@botpress/sdk";
44560
+
44561
+ // src/runtime/actions/order-recompute-columns.ts
44562
+ init_define_BUILD();
44563
+ init_define_PACKAGE_VERSIONS();
44564
+ function orderRecomputeColumns(toRecompute, staleColumns, columns) {
44565
+ const ordered = [];
44566
+ const visited = /* @__PURE__ */ new Set();
44567
+ function visit(colName) {
44568
+ if (visited.has(colName)) return;
44569
+ visited.add(colName);
44570
+ const deps = columns[colName]?.dependencies || [];
44571
+ for (const dep of deps) {
44572
+ if (staleColumns.has(dep)) {
44573
+ visit(dep);
44574
+ }
44575
+ }
44576
+ if (staleColumns.has(colName) || toRecompute.includes(colName)) {
44577
+ ordered.push(colName);
44578
+ }
44579
+ }
44580
+ for (const col of toRecompute) {
44581
+ visit(col);
44582
+ }
44583
+ return ordered;
44584
+ }
44585
+
44586
+ // src/runtime/actions/computed-columns.ts
44560
44587
  var tablesRecomputeRows = new BaseAction({
44561
44588
  name: "tablesRecomputeRows",
44562
44589
  // skynet/packages/tables-api/src/services/computed/compute-stale-rows.ts
@@ -44581,26 +44608,48 @@ var tablesRecomputeRows = new BaseAction({
44581
44608
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
44582
44609
  async function computeRow(row, columnsToRecompute) {
44583
44610
  const newRow = { id: row.id };
44584
- for (const colName of columnsToRecompute) {
44611
+ const recompute = orderRecomputeColumns(
44612
+ columnsToRecompute,
44613
+ new Set(row.stale ?? []),
44614
+ table?.columns || {}
44615
+ );
44616
+ for (const colName of recompute) {
44585
44617
  const col = table?.columns[colName];
44586
44618
  if (!col || !col.computed) {
44587
44619
  newRow[colName] = { status: "error", error: "Column not found or not computed" };
44588
44620
  continue;
44589
44621
  }
44622
+ const value = await col.value(row);
44623
+ row[colName] = value;
44590
44624
  newRow[colName] = {
44591
44625
  status: "computed",
44592
- value: await col.value(row)
44626
+ value
44593
44627
  };
44594
44628
  }
44595
44629
  return newRow;
44596
44630
  }
44597
- const computedRows = await Promise.all(
44631
+ const MIN_REMAINING_TIME_MS = 5e3;
44632
+ const BUFFER_TIME_MS = 5e3;
44633
+ let recomputed = [];
44634
+ let isFinished = true;
44635
+ const remainingTime = context2.get("runtime").getRemainingExecutionTimeInMs();
44636
+ if (remainingTime && remainingTime < MIN_REMAINING_TIME_MS) {
44637
+ return { isFinished: false, rows: [] };
44638
+ }
44639
+ const timeoutPromise = new Promise((resolve) => {
44640
+ setTimeout(() => {
44641
+ isFinished = false;
44642
+ resolve();
44643
+ }, remainingTime - BUFFER_TIME_MS);
44644
+ });
44645
+ const allRowsPromise = Promise.all(
44598
44646
  requests.map(async (r) => {
44599
44647
  const computedRow = await computeRow(r.row, r.columnsToRecompute);
44600
- return computedRow;
44648
+ recomputed.push(computedRow);
44601
44649
  })
44602
44650
  );
44603
- return { isFinished: true, rows: computedRows };
44651
+ await Promise.race([timeoutPromise, allRowsPromise]);
44652
+ return { isFinished, rows: recomputed };
44604
44653
  }
44605
44654
  });
44606
44655