@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.
package/dist/internal.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
 
@@ -41381,6 +41381,31 @@ var BaseAction = class {
41381
41381
  }
41382
41382
  };
41383
41383
 
41384
+ // src/runtime/actions/order-recompute-columns.ts
41385
+ init_define_BUILD();
41386
+ init_define_PACKAGE_VERSIONS();
41387
+ function orderRecomputeColumns(toRecompute, staleColumns, columns) {
41388
+ const ordered = [];
41389
+ const visited = /* @__PURE__ */ new Set();
41390
+ function visit(colName) {
41391
+ if (visited.has(colName)) return;
41392
+ visited.add(colName);
41393
+ const deps = columns[colName]?.dependencies || [];
41394
+ for (const dep of deps) {
41395
+ if (staleColumns.has(dep)) {
41396
+ visit(dep);
41397
+ }
41398
+ }
41399
+ if (staleColumns.has(colName) || toRecompute.includes(colName)) {
41400
+ ordered.push(colName);
41401
+ }
41402
+ }
41403
+ for (const col of toRecompute) {
41404
+ visit(col);
41405
+ }
41406
+ return ordered;
41407
+ }
41408
+
41384
41409
  // src/runtime/actions/computed-columns.ts
41385
41410
  var tablesRecomputeRows = new BaseAction({
41386
41411
  name: "tablesRecomputeRows",
@@ -41406,26 +41431,48 @@ var tablesRecomputeRows = new BaseAction({
41406
41431
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
41407
41432
  async function computeRow(row, columnsToRecompute) {
41408
41433
  const newRow = { id: row.id };
41409
- for (const colName of columnsToRecompute) {
41434
+ const recompute = orderRecomputeColumns(
41435
+ columnsToRecompute,
41436
+ new Set(row.stale ?? []),
41437
+ table?.columns || {}
41438
+ );
41439
+ for (const colName of recompute) {
41410
41440
  const col = table?.columns[colName];
41411
41441
  if (!col || !col.computed) {
41412
41442
  newRow[colName] = { status: "error", error: "Column not found or not computed" };
41413
41443
  continue;
41414
41444
  }
41445
+ const value = await col.value(row);
41446
+ row[colName] = value;
41415
41447
  newRow[colName] = {
41416
41448
  status: "computed",
41417
- value: await col.value(row)
41449
+ value
41418
41450
  };
41419
41451
  }
41420
41452
  return newRow;
41421
41453
  }
41422
- const computedRows = await Promise.all(
41454
+ const MIN_REMAINING_TIME_MS = 5e3;
41455
+ const BUFFER_TIME_MS = 5e3;
41456
+ let recomputed = [];
41457
+ let isFinished = true;
41458
+ const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
41459
+ if (remainingTime && remainingTime < MIN_REMAINING_TIME_MS) {
41460
+ return { isFinished: false, rows: [] };
41461
+ }
41462
+ const timeoutPromise = new Promise((resolve) => {
41463
+ setTimeout(() => {
41464
+ isFinished = false;
41465
+ resolve();
41466
+ }, remainingTime - BUFFER_TIME_MS);
41467
+ });
41468
+ const allRowsPromise = Promise.all(
41423
41469
  requests.map(async (r) => {
41424
41470
  const computedRow = await computeRow(r.row, r.columnsToRecompute);
41425
- return computedRow;
41471
+ recomputed.push(computedRow);
41426
41472
  })
41427
41473
  );
41428
- return { isFinished: true, rows: computedRows };
41474
+ await Promise.race([timeoutPromise, allRowsPromise]);
41475
+ return { isFinished, rows: recomputed };
41429
41476
  }
41430
41477
  });
41431
41478