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