@botpress/runtime 1.7.2 → 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/library.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.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
 
@@ -42101,6 +42101,31 @@ var BaseAction = class {
42101
42101
  }
42102
42102
  };
42103
42103
 
42104
+ // src/runtime/actions/order-recompute-columns.ts
42105
+ init_define_BUILD();
42106
+ init_define_PACKAGE_VERSIONS();
42107
+ function orderRecomputeColumns(toRecompute, staleColumns, columns) {
42108
+ const ordered = [];
42109
+ const visited = /* @__PURE__ */ new Set();
42110
+ function visit(colName) {
42111
+ if (visited.has(colName)) return;
42112
+ visited.add(colName);
42113
+ const deps = columns[colName]?.dependencies || [];
42114
+ for (const dep of deps) {
42115
+ if (staleColumns.has(dep)) {
42116
+ visit(dep);
42117
+ }
42118
+ }
42119
+ if (staleColumns.has(colName) || toRecompute.includes(colName)) {
42120
+ ordered.push(colName);
42121
+ }
42122
+ }
42123
+ for (const col of toRecompute) {
42124
+ visit(col);
42125
+ }
42126
+ return ordered;
42127
+ }
42128
+
42104
42129
  // src/runtime/actions/computed-columns.ts
42105
42130
  var tablesRecomputeRows = new BaseAction({
42106
42131
  name: "tablesRecomputeRows",
@@ -42126,26 +42151,48 @@ var tablesRecomputeRows = new BaseAction({
42126
42151
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
42127
42152
  async function computeRow(row, columnsToRecompute) {
42128
42153
  const newRow = { id: row.id };
42129
- for (const colName of columnsToRecompute) {
42154
+ const recompute = orderRecomputeColumns(
42155
+ columnsToRecompute,
42156
+ new Set(row.stale ?? []),
42157
+ table?.columns || {}
42158
+ );
42159
+ for (const colName of recompute) {
42130
42160
  const col = table?.columns[colName];
42131
42161
  if (!col || !col.computed) {
42132
42162
  newRow[colName] = { status: "error", error: "Column not found or not computed" };
42133
42163
  continue;
42134
42164
  }
42165
+ const value = await col.value(row);
42166
+ row[colName] = value;
42135
42167
  newRow[colName] = {
42136
42168
  status: "computed",
42137
- value: await col.value(row)
42169
+ value
42138
42170
  };
42139
42171
  }
42140
42172
  return newRow;
42141
42173
  }
42142
- const computedRows = await Promise.all(
42174
+ const MIN_REMAINING_TIME_MS = 5e3;
42175
+ const BUFFER_TIME_MS = 5e3;
42176
+ let recomputed = [];
42177
+ let isFinished = true;
42178
+ const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
42179
+ if (remainingTime && remainingTime < MIN_REMAINING_TIME_MS) {
42180
+ return { isFinished: false, rows: [] };
42181
+ }
42182
+ const timeoutPromise = new Promise((resolve) => {
42183
+ setTimeout(() => {
42184
+ isFinished = false;
42185
+ resolve();
42186
+ }, remainingTime - BUFFER_TIME_MS);
42187
+ });
42188
+ const allRowsPromise = Promise.all(
42143
42189
  requests.map(async (r) => {
42144
42190
  const computedRow = await computeRow(r.row, r.columnsToRecompute);
42145
- return computedRow;
42191
+ recomputed.push(computedRow);
42146
42192
  })
42147
42193
  );
42148
- return { isFinished: true, rows: computedRows };
42194
+ await Promise.race([timeoutPromise, allRowsPromise]);
42195
+ return { isFinished, rows: recomputed };
42149
42196
  }
42150
42197
  });
42151
42198