@botpress/runtime 1.3.10 → 1.3.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/runtime/handlers/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAiB/E,eAAO,MAAM,KAAK,GAAI,KAAK,iBAAiB,SAgH3C,CAAC"}
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/runtime/handlers/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAiB/E,eAAO,MAAM,KAAK,GAAI,KAAK,iBAAiB,SA+H3C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/runtime/handlers/workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAkB/E,eAAO,MAAM,KAAK,GAAI,KAAK,iBAAiB,SA0O3C,CAAC"}
1
+ {"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../../src/runtime/handlers/workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAmB/E,eAAO,MAAM,KAAK,GAAI,KAAK,iBAAiB,SAsQ3C,CAAC"}
package/dist/runtime.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.3.10", adk: "not-installed", sdk: "4.17.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
51
+ define_PACKAGE_VERSIONS_default = { runtime: "1.3.12", adk: "not-installed", sdk: "4.17.0", llmz: "0.0.26", zai: "2.1.16", cognitive: "0.1.47" };
52
52
  }
53
53
  });
54
54
 
@@ -24244,41 +24244,41 @@ var require_ms = __commonJS({
24244
24244
  return void 0;
24245
24245
  }
24246
24246
  }
24247
- function fmtShort(ms2) {
24248
- var msAbs = Math.abs(ms2);
24247
+ function fmtShort(ms3) {
24248
+ var msAbs = Math.abs(ms3);
24249
24249
  if (msAbs >= d) {
24250
- return Math.round(ms2 / d) + "d";
24250
+ return Math.round(ms3 / d) + "d";
24251
24251
  }
24252
24252
  if (msAbs >= h) {
24253
- return Math.round(ms2 / h) + "h";
24253
+ return Math.round(ms3 / h) + "h";
24254
24254
  }
24255
24255
  if (msAbs >= m) {
24256
- return Math.round(ms2 / m) + "m";
24256
+ return Math.round(ms3 / m) + "m";
24257
24257
  }
24258
24258
  if (msAbs >= s) {
24259
- return Math.round(ms2 / s) + "s";
24259
+ return Math.round(ms3 / s) + "s";
24260
24260
  }
24261
- return ms2 + "ms";
24261
+ return ms3 + "ms";
24262
24262
  }
24263
- function fmtLong(ms2) {
24264
- var msAbs = Math.abs(ms2);
24263
+ function fmtLong(ms3) {
24264
+ var msAbs = Math.abs(ms3);
24265
24265
  if (msAbs >= d) {
24266
- return plural(ms2, msAbs, d, "day");
24266
+ return plural(ms3, msAbs, d, "day");
24267
24267
  }
24268
24268
  if (msAbs >= h) {
24269
- return plural(ms2, msAbs, h, "hour");
24269
+ return plural(ms3, msAbs, h, "hour");
24270
24270
  }
24271
24271
  if (msAbs >= m) {
24272
- return plural(ms2, msAbs, m, "minute");
24272
+ return plural(ms3, msAbs, m, "minute");
24273
24273
  }
24274
24274
  if (msAbs >= s) {
24275
- return plural(ms2, msAbs, s, "second");
24275
+ return plural(ms3, msAbs, s, "second");
24276
24276
  }
24277
- return ms2 + " ms";
24277
+ return ms3 + " ms";
24278
24278
  }
24279
- function plural(ms2, msAbs, n, name) {
24279
+ function plural(ms3, msAbs, n, name) {
24280
24280
  var isPlural = msAbs >= n * 1.5;
24281
- return Math.round(ms2 / n) + " " + name + (isPlural ? "s" : "");
24281
+ return Math.round(ms3 / n) + " " + name + (isPlural ? "s" : "");
24282
24282
  }
24283
24283
  }
24284
24284
  });
@@ -24323,8 +24323,8 @@ var require_common = __commonJS({
24323
24323
  }
24324
24324
  const self2 = debug;
24325
24325
  const curr = Number(/* @__PURE__ */ new Date());
24326
- const ms2 = curr - (prevTime || curr);
24327
- self2.diff = ms2;
24326
+ const ms3 = curr - (prevTime || curr);
24327
+ self2.diff = ms3;
24328
24328
  self2.prev = prevTime;
24329
24329
  self2.curr = curr;
24330
24330
  prevTime = curr;
@@ -43831,12 +43831,12 @@ step.abort = () => {
43831
43831
  workflowControlContext.abort();
43832
43832
  throw createStepSignal();
43833
43833
  };
43834
- step.sleep = async (name, ms2) => {
43834
+ step.sleep = async (name, ms3) => {
43835
43835
  await _step(
43836
43836
  name,
43837
43837
  async () => {
43838
43838
  const remainingTime = context2.get("runtime").getRemainingExecutionTimeInMs();
43839
- if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms2 || ms2 >= 1e4) {
43839
+ if (remainingTime - MIN_STEP_REMAINING_TIME_MS <= ms3 || ms3 >= 1e4) {
43840
43840
  const client = context2.get("client");
43841
43841
  const workflowControlContext = context2.get("workflowControlContext");
43842
43842
  await client.createEvent({
@@ -43844,7 +43844,7 @@ step.sleep = async (name, ms2) => {
43844
43844
  payload: {},
43845
43845
  workflowId: workflowControlContext.workflow.id,
43846
43846
  schedule: {
43847
- delay: ms2
43847
+ delay: ms3
43848
43848
  }
43849
43849
  });
43850
43850
  await updateWorkflow({
@@ -43853,7 +43853,7 @@ step.sleep = async (name, ms2) => {
43853
43853
  });
43854
43854
  workflowControlContext.abort();
43855
43855
  } else {
43856
- await new Promise((resolve) => void setTimeout(resolve, ms2));
43856
+ await new Promise((resolve) => void setTimeout(resolve, ms3));
43857
43857
  }
43858
43858
  },
43859
43859
  {},
@@ -43863,11 +43863,11 @@ step.sleep = async (name, ms2) => {
43863
43863
  );
43864
43864
  };
43865
43865
  step.sleepUntil = async (name, date) => {
43866
- const ms2 = Math.max(
43866
+ const ms3 = Math.max(
43867
43867
  0,
43868
43868
  new Date(date).getTime() - Date.now() - MIN_STEP_REMAINING_TIME_MS
43869
43869
  );
43870
- await step.sleep(name, ms2);
43870
+ await step.sleep(name, ms3);
43871
43871
  };
43872
43872
  step.waitForWorkflow = async (name, workflowId) => {
43873
43873
  const workflowControlContext = context2.get("workflowControlContext");
@@ -46377,6 +46377,7 @@ __export(workflow_exports, {
46377
46377
  init_define_BUILD();
46378
46378
  init_define_PACKAGE_VERSIONS();
46379
46379
  init_esm();
46380
+ var import_ms2 = __toESM(require_ms(), 1);
46380
46381
  var setup3 = (bot2) => {
46381
46382
  const handler = async function({
46382
46383
  workflow,
@@ -46400,10 +46401,10 @@ var setup3 = (bot2) => {
46400
46401
  "workflow.status.initial": workflow.status
46401
46402
  },
46402
46403
  async (s) => {
46403
- const handler2 = adk.project.workflows.find(
46404
+ const workflowDefinition = adk.project.workflows.find(
46404
46405
  (w) => w.name === workflow.name
46405
- )?._handler;
46406
- if (!handler2) {
46406
+ );
46407
+ if (!workflowDefinition?._handler) {
46407
46408
  console.warn(`No ADK Workflow handler found for "${workflow.name}"`);
46408
46409
  s.setAttribute("handler", false);
46409
46410
  s.setStatus({
@@ -46412,6 +46413,26 @@ var setup3 = (bot2) => {
46412
46413
  });
46413
46414
  return;
46414
46415
  }
46416
+ const DEFAULT_TIMEOUT_MS = (0, import_ms2.default)("5m");
46417
+ const configuredTimeout = workflowDefinition.timeout;
46418
+ if (workflow.timeoutAt && configuredTimeout !== DEFAULT_TIMEOUT_MS) {
46419
+ const workflowStartedAt = new Date(workflow.createdAt).getTime();
46420
+ const currentTimeoutAt = new Date(workflow.timeoutAt).getTime();
46421
+ const currentTimeoutDuration = currentTimeoutAt - workflowStartedAt;
46422
+ const isDefaultTimeout = Math.abs(currentTimeoutDuration - DEFAULT_TIMEOUT_MS) < 1e4;
46423
+ if (isDefaultTimeout) {
46424
+ const newTimeoutAt = new Date(
46425
+ workflowStartedAt + configuredTimeout
46426
+ ).toISOString();
46427
+ await updateWorkflow({
46428
+ id: workflow.id,
46429
+ timeoutAt: newTimeoutAt
46430
+ });
46431
+ s.setAttribute("workflow.timeout.updated", true);
46432
+ s.setAttribute("workflow.timeout.from", currentTimeoutDuration);
46433
+ s.setAttribute("workflow.timeout.to", configuredTimeout);
46434
+ }
46435
+ }
46415
46436
  const instance = await BaseWorkflowInstance.load({
46416
46437
  id: workflow.id,
46417
46438
  workflow
@@ -46600,10 +46621,22 @@ var setup4 = (bot2) => {
46600
46621
  `Executing scheduled workflow: ${workflowName} at ${(/* @__PURE__ */ new Date()).toISOString()}`
46601
46622
  );
46602
46623
  try {
46624
+ const workflowDefinition = adk.project.workflows.find(
46625
+ (w) => w.name === workflowName
46626
+ );
46627
+ if (!workflowDefinition) {
46628
+ logger.error(
46629
+ `Workflow definition not found for: ${workflowName}`
46630
+ );
46631
+ return;
46632
+ }
46603
46633
  await client._inner.createWorkflow({
46604
46634
  name: workflowName,
46605
46635
  status: "pending",
46606
- input: {}
46636
+ input: {},
46637
+ timeoutAt: new Date(
46638
+ Date.now() + workflowDefinition.timeout
46639
+ ).toISOString()
46607
46640
  });
46608
46641
  logger.info(
46609
46642
  `Successfully created workflow instance for: ${workflowName}`