@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/library.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Autonomous } from './runtime/autonomous';
2
2
  export { z } from '@botpress/sdk';
3
+ export { Cognitive } from '@botpress/cognitive';
4
+ export { Zai } from '@botpress/zai';
3
5
  export { context } from './runtime/index';
4
6
  export { Action, Knowledge, Conversation, Trigger, Table, Workflow, Primitives, DataSource, BaseConversationInstance, } from './primitives';
5
7
  export { isWorkflowDataRequest } from './primitives/workflow-utils';
@@ -1 +1 @@
1
- {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGjD,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAA;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,OAAO,EACL,MAAM,EACN,SAAS,EACT,YAAY,EACZ,OAAO,EACP,KAAK,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,wBAAwB,GACzB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGjD,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAA;AAEpC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,GAAG,EAAE,MAAM,eA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,CAAA;AACnC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG9D,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AACrE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACjD,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
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.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
 
@@ -34294,6 +34294,8 @@ var init_esm9 = __esm({
34294
34294
  init_define_BUILD();
34295
34295
  init_define_PACKAGE_VERSIONS();
34296
34296
  import { z as z25 } from "@botpress/sdk";
34297
+ import { Cognitive as Cognitive2 } from "@botpress/cognitive";
34298
+ import { Zai as Zai2 } from "@botpress/zai";
34297
34299
 
34298
34300
  // src/runtime/index.ts
34299
34301
  init_define_BUILD();
@@ -42101,6 +42103,31 @@ var BaseAction = class {
42101
42103
  }
42102
42104
  };
42103
42105
 
42106
+ // src/runtime/actions/order-recompute-columns.ts
42107
+ init_define_BUILD();
42108
+ init_define_PACKAGE_VERSIONS();
42109
+ function orderRecomputeColumns(toRecompute, staleColumns, columns) {
42110
+ const ordered = [];
42111
+ const visited = /* @__PURE__ */ new Set();
42112
+ function visit(colName) {
42113
+ if (visited.has(colName)) return;
42114
+ visited.add(colName);
42115
+ const deps = columns[colName]?.dependencies || [];
42116
+ for (const dep of deps) {
42117
+ if (staleColumns.has(dep)) {
42118
+ visit(dep);
42119
+ }
42120
+ }
42121
+ if (staleColumns.has(colName) || toRecompute.includes(colName)) {
42122
+ ordered.push(colName);
42123
+ }
42124
+ }
42125
+ for (const col of toRecompute) {
42126
+ visit(col);
42127
+ }
42128
+ return ordered;
42129
+ }
42130
+
42104
42131
  // src/runtime/actions/computed-columns.ts
42105
42132
  var tablesRecomputeRows = new BaseAction({
42106
42133
  name: "tablesRecomputeRows",
@@ -42126,26 +42153,48 @@ var tablesRecomputeRows = new BaseAction({
42126
42153
  const table = adk.project.tables.find((x) => x.name === remoteTable.name);
42127
42154
  async function computeRow(row, columnsToRecompute) {
42128
42155
  const newRow = { id: row.id };
42129
- for (const colName of columnsToRecompute) {
42156
+ const recompute = orderRecomputeColumns(
42157
+ columnsToRecompute,
42158
+ new Set(row.stale ?? []),
42159
+ table?.columns || {}
42160
+ );
42161
+ for (const colName of recompute) {
42130
42162
  const col = table?.columns[colName];
42131
42163
  if (!col || !col.computed) {
42132
42164
  newRow[colName] = { status: "error", error: "Column not found or not computed" };
42133
42165
  continue;
42134
42166
  }
42167
+ const value = await col.value(row);
42168
+ row[colName] = value;
42135
42169
  newRow[colName] = {
42136
42170
  status: "computed",
42137
- value: await col.value(row)
42171
+ value
42138
42172
  };
42139
42173
  }
42140
42174
  return newRow;
42141
42175
  }
42142
- const computedRows = await Promise.all(
42176
+ const MIN_REMAINING_TIME_MS = 5e3;
42177
+ const BUFFER_TIME_MS = 5e3;
42178
+ let recomputed = [];
42179
+ let isFinished = true;
42180
+ const remainingTime = context.get("runtime").getRemainingExecutionTimeInMs();
42181
+ if (remainingTime && remainingTime < MIN_REMAINING_TIME_MS) {
42182
+ return { isFinished: false, rows: [] };
42183
+ }
42184
+ const timeoutPromise = new Promise((resolve) => {
42185
+ setTimeout(() => {
42186
+ isFinished = false;
42187
+ resolve();
42188
+ }, remainingTime - BUFFER_TIME_MS);
42189
+ });
42190
+ const allRowsPromise = Promise.all(
42143
42191
  requests.map(async (r) => {
42144
42192
  const computedRow = await computeRow(r.row, r.columnsToRecompute);
42145
- return computedRow;
42193
+ recomputed.push(computedRow);
42146
42194
  })
42147
42195
  );
42148
- return { isFinished: true, rows: computedRows };
42196
+ await Promise.race([timeoutPromise, allRowsPromise]);
42197
+ return { isFinished, rows: recomputed };
42149
42198
  }
42150
42199
  });
42151
42200
 
@@ -45983,6 +46032,7 @@ export {
45983
46032
  Action,
45984
46033
  Autonomous,
45985
46034
  BaseConversationInstance,
46035
+ Cognitive2 as Cognitive,
45986
46036
  BaseConversation as Conversation,
45987
46037
  DataSource2 as DataSource,
45988
46038
  Errors,
@@ -45991,6 +46041,7 @@ export {
45991
46041
  BaseTable as Table,
45992
46042
  Trigger,
45993
46043
  BaseWorkflow as Workflow,
46044
+ Zai2 as Zai,
45994
46045
  actions,
45995
46046
  adk,
45996
46047
  bot,