@trigger.dev/sdk 2.2.0 → 2.2.2

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/index.js CHANGED
@@ -478,19 +478,19 @@ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url,
478
478
  throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
479
479
  }
480
480
  const jsonBody = await response.json();
481
- const version = response.headers.get("trigger-version");
482
- if (!version) {
481
+ const version2 = response.headers.get("trigger-version");
482
+ if (!version2) {
483
483
  return {
484
484
  version: "unversioned",
485
485
  body: unversionedSchema.parse(jsonBody)
486
486
  };
487
487
  }
488
- const versionedSchema = versionedSchemaMap[version];
488
+ const versionedSchema = versionedSchemaMap[version2];
489
489
  if (!versionedSchema) {
490
- throw new Error(`Unknown version ${version}`);
490
+ throw new Error(`Unknown version ${version2}`);
491
491
  }
492
492
  return {
493
- version,
493
+ version: version2,
494
494
  body: versionedSchema.parse(jsonBody)
495
495
  };
496
496
  }
@@ -539,6 +539,23 @@ var YieldExecutionError = class {
539
539
  }
540
540
  };
541
541
  __name(YieldExecutionError, "YieldExecutionError");
542
+ var AutoYieldExecutionError = class {
543
+ constructor(location, timeRemaining, timeElapsed) {
544
+ this.location = location;
545
+ this.timeRemaining = timeRemaining;
546
+ this.timeElapsed = timeElapsed;
547
+ }
548
+ };
549
+ __name(AutoYieldExecutionError, "AutoYieldExecutionError");
550
+ var AutoYieldWithCompletedTaskExecutionError = class {
551
+ constructor(id, properties, output, data) {
552
+ this.id = id;
553
+ this.properties = properties;
554
+ this.output = output;
555
+ this.data = data;
556
+ }
557
+ };
558
+ __name(AutoYieldWithCompletedTaskExecutionError, "AutoYieldWithCompletedTaskExecutionError");
542
559
  var ParsedPayloadSchemaError = class {
543
560
  constructor(schemaErrors) {
544
561
  this.schemaErrors = schemaErrors;
@@ -546,7 +563,7 @@ var ParsedPayloadSchemaError = class {
546
563
  };
547
564
  __name(ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
548
565
  function isTriggerError(err) {
549
- return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError;
566
+ return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError || err instanceof AutoYieldExecutionError || err instanceof AutoYieldWithCompletedTaskExecutionError;
550
567
  }
551
568
  __name(isTriggerError, "isTriggerError");
552
569
 
@@ -602,10 +619,14 @@ var TriggerStatus = class {
602
619
  __name(TriggerStatus, "TriggerStatus");
603
620
 
604
621
  // src/io.ts
605
- var _addToCachedTasks, addToCachedTasks_fn;
622
+ var _addToCachedTasks, addToCachedTasks_fn, _detectAutoYield, detectAutoYield_fn, _forceYield, forceYield_fn, _getTimeElapsed, getTimeElapsed_fn, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn;
606
623
  var IO = class {
607
624
  constructor(options) {
608
625
  __privateAdd(this, _addToCachedTasks);
626
+ __privateAdd(this, _detectAutoYield);
627
+ __privateAdd(this, _forceYield);
628
+ __privateAdd(this, _getTimeElapsed);
629
+ __privateAdd(this, _getRemainingTimeInMillis);
609
630
  __publicField(this, "brb", this.yield.bind(this));
610
631
  this._id = options.id;
611
632
  this._apiClient = options.apiClient;
@@ -614,6 +635,8 @@ var IO = class {
614
635
  this._cachedTasks = /* @__PURE__ */ new Map();
615
636
  this._jobLogger = options.jobLogger;
616
637
  this._jobLogLevel = options.jobLogLevel;
638
+ this._timeOrigin = options.timeOrigin;
639
+ this._executionTimeout = options.executionTimeout;
617
640
  this._stats = {
618
641
  initialCachedTasks: 0,
619
642
  lazyLoadedCachedTasks: 0,
@@ -702,8 +725,8 @@ var IO = class {
702
725
  }
703
726
  });
704
727
  }
705
- async wait(key, seconds) {
706
- return await this.runTask(key, async (task) => {
728
+ async wait(cacheKey, seconds) {
729
+ return await this.runTask(cacheKey, async (task) => {
707
730
  }, {
708
731
  name: "wait",
709
732
  icon: "clock",
@@ -717,15 +740,15 @@ var IO = class {
717
740
  }
718
741
  });
719
742
  }
720
- async createStatus(key, initialStatus) {
721
- const id = typeof key === "string" ? key : key.join("-");
743
+ async createStatus(cacheKey, initialStatus) {
744
+ const id = typeof cacheKey === "string" ? cacheKey : cacheKey.join("-");
722
745
  const status = new TriggerStatus(id, this);
723
- await status.update(key, initialStatus);
746
+ await status.update(cacheKey, initialStatus);
724
747
  return status;
725
748
  }
726
- async backgroundFetch(key, url, requestInit, retry2) {
749
+ async backgroundFetch(cacheKey, url, requestInit, retry2) {
727
750
  const urlObject = new URL(url);
728
- return await this.runTask(key, async (task) => {
751
+ return await this.runTask(cacheKey, async (task) => {
729
752
  return task.output;
730
753
  }, {
731
754
  name: `fetch ${urlObject.hostname}${urlObject.pathname}`,
@@ -754,8 +777,8 @@ var IO = class {
754
777
  ]
755
778
  });
756
779
  }
757
- async sendEvent(key, event, options) {
758
- return await this.runTask(key, async (task) => {
780
+ async sendEvent(cacheKey, event, options) {
781
+ return await this.runTask(cacheKey, async (task) => {
759
782
  return await this._triggerClient.sendEvent(event, options);
760
783
  }, {
761
784
  name: "sendEvent",
@@ -777,8 +800,8 @@ var IO = class {
777
800
  ]
778
801
  });
779
802
  }
780
- async getEvent(key, id) {
781
- return await this.runTask(key, async (task) => {
803
+ async getEvent(cacheKey, id) {
804
+ return await this.runTask(cacheKey, async (task) => {
782
805
  return await this._triggerClient.getEvent(id);
783
806
  }, {
784
807
  name: "getEvent",
@@ -793,8 +816,8 @@ var IO = class {
793
816
  ]
794
817
  });
795
818
  }
796
- async cancelEvent(key, eventId) {
797
- return await this.runTask(key, async (task) => {
819
+ async cancelEvent(cacheKey, eventId) {
820
+ return await this.runTask(cacheKey, async (task) => {
798
821
  return await this._triggerClient.cancelEvent(eventId);
799
822
  }, {
800
823
  name: "cancelEvent",
@@ -809,8 +832,8 @@ var IO = class {
809
832
  ]
810
833
  });
811
834
  }
812
- async updateSource(key, options) {
813
- return this.runTask(key, async (task) => {
835
+ async updateSource(cacheKey, options) {
836
+ return this.runTask(cacheKey, async (task) => {
814
837
  return await this._apiClient.updateSource(this._triggerClient.id, options.key, options);
815
838
  }, {
816
839
  name: "Update Source",
@@ -829,8 +852,8 @@ var IO = class {
829
852
  }
830
853
  });
831
854
  }
832
- async registerInterval(key, dynamicSchedule, id, options) {
833
- return await this.runTask(key, async (task) => {
855
+ async registerInterval(cacheKey, dynamicSchedule, id, options) {
856
+ return await this.runTask(cacheKey, async (task) => {
834
857
  return dynamicSchedule.register(id, {
835
858
  type: "interval",
836
859
  options
@@ -854,8 +877,8 @@ var IO = class {
854
877
  params: options
855
878
  });
856
879
  }
857
- async unregisterInterval(key, dynamicSchedule, id) {
858
- return await this.runTask(key, async (task) => {
880
+ async unregisterInterval(cacheKey, dynamicSchedule, id) {
881
+ return await this.runTask(cacheKey, async (task) => {
859
882
  return dynamicSchedule.unregister(id);
860
883
  }, {
861
884
  name: "unregister-interval",
@@ -871,8 +894,8 @@ var IO = class {
871
894
  ]
872
895
  });
873
896
  }
874
- async registerCron(key, dynamicSchedule, id, options) {
875
- return await this.runTask(key, async (task) => {
897
+ async registerCron(cacheKey, dynamicSchedule, id, options) {
898
+ return await this.runTask(cacheKey, async (task) => {
876
899
  return dynamicSchedule.register(id, {
877
900
  type: "cron",
878
901
  options
@@ -896,8 +919,8 @@ var IO = class {
896
919
  params: options
897
920
  });
898
921
  }
899
- async unregisterCron(key, dynamicSchedule, id) {
900
- return await this.runTask(key, async (task) => {
922
+ async unregisterCron(cacheKey, dynamicSchedule, id) {
923
+ return await this.runTask(cacheKey, async (task) => {
901
924
  return dynamicSchedule.unregister(id);
902
925
  }, {
903
926
  name: "unregister-cron",
@@ -913,8 +936,8 @@ var IO = class {
913
936
  ]
914
937
  });
915
938
  }
916
- async registerTrigger(key, trigger, id, params) {
917
- return await this.runTask(key, async (task) => {
939
+ async registerTrigger(cacheKey, trigger, id, params) {
940
+ return await this.runTask(cacheKey, async (task) => {
918
941
  const registration = await this.runTask("register-source", async (subtask1) => {
919
942
  return trigger.register(id, params);
920
943
  }, {
@@ -939,29 +962,30 @@ var IO = class {
939
962
  params
940
963
  });
941
964
  }
942
- async getAuth(key, clientId) {
965
+ async getAuth(cacheKey, clientId) {
943
966
  if (!clientId) {
944
967
  return;
945
968
  }
946
- return this.runTask(key, async (task) => {
969
+ return this.runTask(cacheKey, async (task) => {
947
970
  return await this._triggerClient.getAuth(clientId);
948
971
  }, {
949
972
  name: "get-auth"
950
973
  });
951
974
  }
952
- async runTask(key, callback, options, onError) {
975
+ async runTask(cacheKey, callback, options, onError) {
976
+ __privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "start_task", 500);
953
977
  const parentId = this._taskStorage.getStore()?.taskId;
954
978
  if (parentId) {
955
979
  this._logger.debug("Using parent task", {
956
980
  parentId,
957
- key,
981
+ cacheKey,
958
982
  options
959
983
  });
960
984
  }
961
985
  const idempotencyKey = await generateIdempotencyKey([
962
986
  this._id,
963
987
  parentId ?? "",
964
- key
988
+ cacheKey
965
989
  ].flat());
966
990
  const cachedTask = this._cachedTasks.get(idempotencyKey);
967
991
  if (cachedTask && cachedTask.status === "COMPLETED") {
@@ -982,7 +1006,7 @@ var IO = class {
982
1006
  }
983
1007
  const response = await this._apiClient.runTask(this._id, {
984
1008
  idempotencyKey,
985
- displayKey: typeof key === "string" ? key : void 0,
1009
+ displayKey: typeof cacheKey === "string" ? cacheKey : void 0,
986
1010
  noop: false,
987
1011
  ...options ?? {},
988
1012
  parentId
@@ -990,6 +1014,12 @@ var IO = class {
990
1014
  cachedTasksCursor: this._cachedTasksCursor
991
1015
  });
992
1016
  const task = response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
1017
+ if (task.forceYield) {
1018
+ this._logger.debug("Forcing yield after run task", {
1019
+ idempotencyKey
1020
+ });
1021
+ __privateMethod(this, _forceYield, forceYield_fn).call(this, "after_run_task");
1022
+ }
993
1023
  if (response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
994
1024
  this._cachedTasksCursor = response.body.cachedTasks?.cursor;
995
1025
  for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
@@ -1031,6 +1061,7 @@ var IO = class {
1031
1061
  });
1032
1062
  throw new Error(task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored");
1033
1063
  }
1064
+ __privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_execute_task", 1500);
1034
1065
  const executeTask = /* @__PURE__ */ __name(async () => {
1035
1066
  try {
1036
1067
  const result = await callback(task, this);
@@ -1046,14 +1077,22 @@ var IO = class {
1046
1077
  idempotencyKey,
1047
1078
  task
1048
1079
  });
1080
+ __privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "before_complete_task", 500, task, output);
1049
1081
  const completedTask = await this._apiClient.completeTask(this._id, task.id, {
1050
1082
  output: output ?? void 0,
1051
1083
  properties: task.outputProperties ?? void 0
1052
1084
  });
1085
+ if (completedTask.forceYield) {
1086
+ this._logger.debug("Forcing yield after task completed", {
1087
+ idempotencyKey
1088
+ });
1089
+ __privateMethod(this, _forceYield, forceYield_fn).call(this, "after_complete_task");
1090
+ }
1053
1091
  this._stats.executedTasks++;
1054
1092
  if (completedTask.status === "CANCELED") {
1055
1093
  throw new CanceledWithTaskError(completedTask);
1056
1094
  }
1095
+ __privateMethod(this, _detectAutoYield, detectAutoYield_fn).call(this, "after_complete_task", 500);
1057
1096
  return output;
1058
1097
  } catch (error) {
1059
1098
  if (isTriggerError(error)) {
@@ -1130,15 +1169,15 @@ var IO = class {
1130
1169
  taskId: task.id
1131
1170
  }, executeTask);
1132
1171
  }
1133
- yield(key) {
1172
+ yield(cacheKey) {
1134
1173
  if (!(0, import_core3.supportsFeature)("yieldExecution", this._serverVersion)) {
1135
1174
  console.warn("[trigger.dev] io.yield() is not support by the version of the Trigger.dev server you are using, you will need to upgrade your self-hosted Trigger.dev instance.");
1136
1175
  return;
1137
1176
  }
1138
- if (this._yieldedExecutions.includes(key)) {
1177
+ if (this._yieldedExecutions.includes(cacheKey)) {
1139
1178
  return;
1140
1179
  }
1141
- throw new YieldExecutionError(key);
1180
+ throw new YieldExecutionError(cacheKey);
1142
1181
  }
1143
1182
  async try(tryCallback, catchCallback) {
1144
1183
  try {
@@ -1156,6 +1195,39 @@ _addToCachedTasks = new WeakSet();
1156
1195
  addToCachedTasks_fn = /* @__PURE__ */ __name(function(task) {
1157
1196
  this._cachedTasks.set(task.idempotencyKey, task);
1158
1197
  }, "#addToCachedTasks");
1198
+ _detectAutoYield = new WeakSet();
1199
+ detectAutoYield_fn = /* @__PURE__ */ __name(function(location, threshold = 1500, task1, output) {
1200
+ const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
1201
+ if (timeRemaining && timeRemaining < threshold) {
1202
+ if (task1) {
1203
+ throw new AutoYieldWithCompletedTaskExecutionError(task1.id, task1.outputProperties ?? [], output, {
1204
+ location,
1205
+ timeRemaining,
1206
+ timeElapsed: __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this)
1207
+ });
1208
+ } else {
1209
+ throw new AutoYieldExecutionError(location, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
1210
+ }
1211
+ }
1212
+ }, "#detectAutoYield");
1213
+ _forceYield = new WeakSet();
1214
+ forceYield_fn = /* @__PURE__ */ __name(function(location1) {
1215
+ const timeRemaining = __privateMethod(this, _getRemainingTimeInMillis, getRemainingTimeInMillis_fn).call(this);
1216
+ if (timeRemaining) {
1217
+ throw new AutoYieldExecutionError(location1, timeRemaining, __privateMethod(this, _getTimeElapsed, getTimeElapsed_fn).call(this));
1218
+ }
1219
+ }, "#forceYield");
1220
+ _getTimeElapsed = new WeakSet();
1221
+ getTimeElapsed_fn = /* @__PURE__ */ __name(function() {
1222
+ return performance.now() - this._timeOrigin;
1223
+ }, "#getTimeElapsed");
1224
+ _getRemainingTimeInMillis = new WeakSet();
1225
+ getRemainingTimeInMillis_fn = /* @__PURE__ */ __name(function() {
1226
+ if (this._executionTimeout) {
1227
+ return this._executionTimeout - (performance.now() - this._timeOrigin);
1228
+ }
1229
+ return void 0;
1230
+ }, "#getRemainingTimeInMillis");
1159
1231
  async function generateIdempotencyKey(keyMaterial) {
1160
1232
  const keys = keyMaterial.map((key2) => {
1161
1233
  if (typeof key2 === "string") {
@@ -1606,6 +1678,9 @@ var DynamicSchedule = class {
1606
1678
  };
1607
1679
  __name(DynamicSchedule, "DynamicSchedule");
1608
1680
 
1681
+ // package.json
1682
+ var version = "2.2.2";
1683
+
1609
1684
  // src/triggerClient.ts
1610
1685
  var registerSourceEvent = {
1611
1686
  name: import_core7.REGISTER_SOURCE_EVENT_V2,
@@ -1614,7 +1689,7 @@ var registerSourceEvent = {
1614
1689
  icon: "register-source",
1615
1690
  parsePayload: import_core7.RegisterSourceEventSchemaV2.parse
1616
1691
  };
1617
- var _options4, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _authResolvers, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _resolveConnections, resolveConnections_fn, _resolveConnection, resolveConnection_fn, _buildJobsIndex, buildJobsIndex_fn, _buildJobIndex, buildJobIndex_fn, _buildJobIntegrations, buildJobIntegrations_fn, _buildJobIntegration, buildJobIntegration_fn, _logIOStats, logIOStats_fn, _standardResponseHeaders, standardResponseHeaders_get;
1692
+ var _options4, _registeredJobs, _registeredSources, _registeredHttpSourceHandlers, _registeredDynamicTriggers, _jobMetadataByDynamicTriggers, _registeredSchedules, _authResolvers, _client2, _internalLogger, _preprocessRun, preprocessRun_fn, _executeJob, executeJob_fn, _createRunContext, createRunContext_fn, _createPreprocessRunContext, createPreprocessRunContext_fn, _handleHttpSourceRequest, handleHttpSourceRequest_fn, _resolveConnections, resolveConnections_fn, _resolveConnection, resolveConnection_fn, _buildJobsIndex, buildJobsIndex_fn, _buildJobIndex, buildJobIndex_fn, _buildJobIntegrations, buildJobIntegrations_fn, _buildJobIntegration, buildJobIntegration_fn, _logIOStats, logIOStats_fn, _standardResponseHeaders, standardResponseHeaders_fn;
1618
1693
  var TriggerClient = class {
1619
1694
  constructor(options) {
1620
1695
  __privateAdd(this, _preprocessRun);
@@ -1648,7 +1723,7 @@ var TriggerClient = class {
1648
1723
  "noopTasksSet"
1649
1724
  ]));
1650
1725
  }
1651
- async handleRequest(request) {
1726
+ async handleRequest(request, timeOrigin = performance.now()) {
1652
1727
  __privateGet(this, _internalLogger).debug("handling request", {
1653
1728
  url: request.url,
1654
1729
  headers: Object.fromEntries(request.headers.entries()),
@@ -1667,7 +1742,7 @@ var TriggerClient = class {
1667
1742
  body: {
1668
1743
  message: "Unauthorized: client missing apiKey"
1669
1744
  },
1670
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1745
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1671
1746
  };
1672
1747
  }
1673
1748
  case "missing-header": {
@@ -1676,7 +1751,7 @@ var TriggerClient = class {
1676
1751
  body: {
1677
1752
  message: "Unauthorized: missing x-trigger-api-key header"
1678
1753
  },
1679
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1754
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1680
1755
  };
1681
1756
  }
1682
1757
  case "unauthorized": {
@@ -1685,7 +1760,7 @@ var TriggerClient = class {
1685
1760
  body: {
1686
1761
  message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
1687
1762
  },
1688
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1763
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1689
1764
  };
1690
1765
  }
1691
1766
  }
@@ -1695,7 +1770,7 @@ var TriggerClient = class {
1695
1770
  body: {
1696
1771
  message: "Method not allowed (only POST is allowed)"
1697
1772
  },
1698
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1773
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1699
1774
  };
1700
1775
  }
1701
1776
  const action = request.headers.get("x-trigger-action");
@@ -1705,7 +1780,7 @@ var TriggerClient = class {
1705
1780
  body: {
1706
1781
  message: "Missing x-trigger-action header"
1707
1782
  },
1708
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1783
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1709
1784
  };
1710
1785
  }
1711
1786
  switch (action) {
@@ -1718,7 +1793,7 @@ var TriggerClient = class {
1718
1793
  ok: false,
1719
1794
  error: "Missing endpoint ID"
1720
1795
  },
1721
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1796
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1722
1797
  };
1723
1798
  }
1724
1799
  if (this.id !== endpointId) {
@@ -1728,7 +1803,7 @@ var TriggerClient = class {
1728
1803
  ok: false,
1729
1804
  error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
1730
1805
  },
1731
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1806
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1732
1807
  };
1733
1808
  }
1734
1809
  return {
@@ -1736,7 +1811,7 @@ var TriggerClient = class {
1736
1811
  body: {
1737
1812
  ok: true
1738
1813
  },
1739
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1814
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1740
1815
  };
1741
1816
  }
1742
1817
  case "INDEX_ENDPOINT": {
@@ -1759,7 +1834,7 @@ var TriggerClient = class {
1759
1834
  return {
1760
1835
  status: 200,
1761
1836
  body,
1762
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1837
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1763
1838
  };
1764
1839
  }
1765
1840
  case "INITIALIZE_TRIGGER": {
@@ -1785,7 +1860,7 @@ var TriggerClient = class {
1785
1860
  return {
1786
1861
  status: 200,
1787
1862
  body: dynamicTrigger.registeredTriggerForParams(body.data.params),
1788
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1863
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1789
1864
  };
1790
1865
  }
1791
1866
  case "EXECUTE_JOB": {
@@ -1808,11 +1883,11 @@ var TriggerClient = class {
1808
1883
  }
1809
1884
  };
1810
1885
  }
1811
- const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, triggerVersion);
1886
+ const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, timeOrigin, triggerVersion);
1812
1887
  return {
1813
1888
  status: 200,
1814
1889
  body: results,
1815
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1890
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1816
1891
  };
1817
1892
  }
1818
1893
  case "PREPROCESS_RUN": {
@@ -1842,7 +1917,7 @@ var TriggerClient = class {
1842
1917
  abort: results.abort,
1843
1918
  properties: results.properties
1844
1919
  },
1845
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1920
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1846
1921
  };
1847
1922
  }
1848
1923
  case "DELIVER_HTTP_SOURCE_REQUEST": {
@@ -1892,7 +1967,7 @@ var TriggerClient = class {
1892
1967
  response,
1893
1968
  metadata
1894
1969
  },
1895
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1970
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1896
1971
  };
1897
1972
  }
1898
1973
  case "VALIDATE": {
@@ -1902,7 +1977,19 @@ var TriggerClient = class {
1902
1977
  ok: true,
1903
1978
  endpointId: this.id
1904
1979
  },
1905
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1980
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1981
+ };
1982
+ }
1983
+ case "PROBE_EXECUTION_TIMEOUT": {
1984
+ const json = await request.json();
1985
+ const timeout = json?.timeout ?? 15 * 60 * 1e3;
1986
+ await new Promise((resolve) => setTimeout(resolve, timeout));
1987
+ return {
1988
+ status: 200,
1989
+ body: {
1990
+ ok: true
1991
+ },
1992
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1906
1993
  };
1907
1994
  }
1908
1995
  }
@@ -1911,7 +1998,7 @@ var TriggerClient = class {
1911
1998
  body: {
1912
1999
  message: "Method not allowed"
1913
2000
  },
1914
- headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
2001
+ headers: __privateMethod(this, _standardResponseHeaders, standardResponseHeaders_fn).call(this, timeOrigin)
1915
2002
  };
1916
2003
  }
1917
2004
  defineJob(options) {
@@ -2113,7 +2200,7 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
2113
2200
  };
2114
2201
  }, "#preprocessRun");
2115
2202
  _executeJob = new WeakSet();
2116
- executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersion) {
2203
+ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, timeOrigin, triggerVersion) {
2117
2204
  __privateGet(this, _internalLogger).debug("executing job", {
2118
2205
  execution: body1,
2119
2206
  job: job1.id,
@@ -2133,7 +2220,9 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersio
2133
2220
  context,
2134
2221
  jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
2135
2222
  jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new import_core7.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0,
2136
- serverVersion: triggerVersion
2223
+ serverVersion: triggerVersion,
2224
+ timeOrigin,
2225
+ executionTimeout: body1.runChunkExecutionLimit
2137
2226
  });
2138
2227
  const resolvedConnections = await __privateMethod(this, _resolveConnections, resolveConnections_fn).call(this, context, job1.options.integrations, body1.connections);
2139
2228
  if (!resolvedConnections.ok) {
@@ -2161,6 +2250,27 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersio
2161
2250
  if (__privateGet(this, _options4).verbose) {
2162
2251
  __privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
2163
2252
  }
2253
+ if (error instanceof AutoYieldExecutionError) {
2254
+ return {
2255
+ status: "AUTO_YIELD_EXECUTION",
2256
+ location: error.location,
2257
+ timeRemaining: error.timeRemaining,
2258
+ timeElapsed: error.timeElapsed,
2259
+ limit: body1.runChunkExecutionLimit
2260
+ };
2261
+ }
2262
+ if (error instanceof AutoYieldWithCompletedTaskExecutionError) {
2263
+ return {
2264
+ status: "AUTO_YIELD_EXECUTION_WITH_COMPLETED_TASK",
2265
+ id: error.id,
2266
+ properties: error.properties,
2267
+ output: error.output,
2268
+ data: {
2269
+ ...error.data,
2270
+ limit: body1.runChunkExecutionLimit
2271
+ }
2272
+ };
2273
+ }
2164
2274
  if (error instanceof YieldExecutionError) {
2165
2275
  return {
2166
2276
  status: "YIELD_EXECUTION",
@@ -2497,9 +2607,11 @@ logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
2497
2607
  });
2498
2608
  }, "#logIOStats");
2499
2609
  _standardResponseHeaders = new WeakSet();
2500
- standardResponseHeaders_get = /* @__PURE__ */ __name(function() {
2610
+ standardResponseHeaders_fn = /* @__PURE__ */ __name(function(start) {
2501
2611
  return {
2502
- "Trigger-Version": import_core7.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
2612
+ "Trigger-Version": import_core7.API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
2613
+ "Trigger-SDK-Version": version,
2614
+ "X-Trigger-Request-Timing": `dur=${performance.now() - start / 1e3}`
2503
2615
  };
2504
2616
  }, "#standardResponseHeaders");
2505
2617
  function dynamicTriggerRegisterSourceJobId(id) {