@trigger.dev/sdk 2.1.6 → 2.1.8

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
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
10
  var __export = (target, all) => {
10
11
  for (var name in all)
@@ -23,6 +24,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
24
  mod
24
25
  ));
25
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var __publicField = (obj, key, value) => {
28
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
29
+ return value;
30
+ };
26
31
  var __accessCheck = (obj, member, msg) => {
27
32
  if (!member.has(obj))
28
33
  throw TypeError("Cannot " + msg);
@@ -189,17 +194,21 @@ var ApiClient = class {
189
194
  }
190
195
  return await response.json();
191
196
  }
192
- async runTask(runId, task) {
197
+ async runTask(runId, task, options = {}) {
193
198
  const apiKey = await __privateMethod(this, _apiKey, apiKey_fn).call(this);
194
199
  __privateGet(this, _logger).debug("Running Task", {
195
200
  task
196
201
  });
197
- return await zodfetch(import_core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
202
+ return await zodfetchWithVersions({
203
+ [import_core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS]: import_core.RunTaskResponseWithCachedTasksBodySchema
204
+ }, import_core.ServerTaskSchema, `${__privateGet(this, _apiUrl)}/api/v1/runs/${runId}/tasks`, {
198
205
  method: "POST",
199
206
  headers: {
200
207
  "Content-Type": "application/json",
201
208
  Authorization: `Bearer ${apiKey}`,
202
- "Idempotency-Key": task.idempotencyKey
209
+ "Idempotency-Key": task.idempotencyKey,
210
+ "X-Cached-Tasks-Cursor": options.cachedTasksCursor ?? "",
211
+ "Trigger-Version": import_core.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
203
212
  },
204
213
  body: JSON.stringify(task)
205
214
  });
@@ -444,6 +453,36 @@ function getApiKey(key) {
444
453
  };
445
454
  }
446
455
  __name(getApiKey, "getApiKey");
456
+ async function zodfetchWithVersions(versionedSchemaMap, unversionedSchema, url, requestInit, options) {
457
+ const response = await (0, import_node_fetch.default)(url, requestInit);
458
+ if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
459
+ return;
460
+ }
461
+ if (response.status >= 400 && response.status < 500) {
462
+ const body = await response.json();
463
+ throw new Error(body.error);
464
+ }
465
+ if (response.status !== 200) {
466
+ throw new Error(options?.errorMessage ?? `Failed to fetch ${url}, got status code ${response.status}`);
467
+ }
468
+ const jsonBody = await response.json();
469
+ const version = response.headers.get("trigger-version");
470
+ if (!version) {
471
+ return {
472
+ version: "unversioned",
473
+ body: unversionedSchema.parse(jsonBody)
474
+ };
475
+ }
476
+ const versionedSchema = versionedSchemaMap[version];
477
+ if (!versionedSchema) {
478
+ throw new Error(`Unknown version ${version}`);
479
+ }
480
+ return {
481
+ version,
482
+ body: versionedSchema.parse(jsonBody)
483
+ };
484
+ }
485
+ __name(zodfetchWithVersions, "zodfetchWithVersions");
447
486
  async function zodfetch(schema, url, requestInit, options) {
448
487
  const response = await (0, import_node_fetch.default)(url, requestInit);
449
488
  if ((!requestInit || requestInit.method === "GET") && response.status === 404 && options?.optional) {
@@ -482,6 +521,12 @@ var CanceledWithTaskError = class {
482
521
  }
483
522
  };
484
523
  __name(CanceledWithTaskError, "CanceledWithTaskError");
524
+ var YieldExecutionError = class {
525
+ constructor(key) {
526
+ this.key = key;
527
+ }
528
+ };
529
+ __name(YieldExecutionError, "YieldExecutionError");
485
530
  var ParsedPayloadSchemaError = class {
486
531
  constructor(schemaErrors) {
487
532
  this.schemaErrors = schemaErrors;
@@ -489,7 +534,7 @@ var ParsedPayloadSchemaError = class {
489
534
  };
490
535
  __name(ParsedPayloadSchemaError, "ParsedPayloadSchemaError");
491
536
  function isTriggerError(err) {
492
- return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError;
537
+ return err instanceof ResumeWithTaskError || err instanceof RetryWithTaskError || err instanceof CanceledWithTaskError || err instanceof YieldExecutionError;
493
538
  }
494
539
  __name(isTriggerError, "isTriggerError");
495
540
 
@@ -549,6 +594,7 @@ var _addToCachedTasks, addToCachedTasks_fn;
549
594
  var IO = class {
550
595
  constructor(options) {
551
596
  __privateAdd(this, _addToCachedTasks);
597
+ __publicField(this, "brb", this.yield.bind(this));
552
598
  this._id = options.id;
553
599
  this._apiClient = options.apiClient;
554
600
  this._triggerClient = options.client;
@@ -556,13 +602,32 @@ var IO = class {
556
602
  this._cachedTasks = /* @__PURE__ */ new Map();
557
603
  this._jobLogger = options.jobLogger;
558
604
  this._jobLogLevel = options.jobLogLevel;
605
+ this._stats = {
606
+ initialCachedTasks: 0,
607
+ lazyLoadedCachedTasks: 0,
608
+ executedTasks: 0,
609
+ cachedTaskHits: 0,
610
+ cachedTaskMisses: 0,
611
+ noopCachedTaskHits: 0,
612
+ noopCachedTaskMisses: 0
613
+ };
559
614
  if (options.cachedTasks) {
560
615
  options.cachedTasks.forEach((task) => {
561
616
  this._cachedTasks.set(task.idempotencyKey, task);
562
617
  });
618
+ this._stats.initialCachedTasks = options.cachedTasks.length;
563
619
  }
564
620
  this._taskStorage = new import_node_async_hooks.AsyncLocalStorage();
565
621
  this._context = options.context;
622
+ this._yieldedExecutions = options.yieldedExecutions ?? [];
623
+ if (options.noopTasksSet) {
624
+ this._noopTasksBloomFilter = import_core3.BloomFilter.deserialize(options.noopTasksSet, import_core3.BloomFilter.NOOP_TASK_SET_SIZE);
625
+ }
626
+ this._cachedTasksCursor = options.cachedTasksCursor;
627
+ this._serverVersion = options.serverVersion ?? "unversioned";
628
+ }
629
+ get stats() {
630
+ return this._stats;
566
631
  }
567
632
  get runId() {
568
633
  return this._id;
@@ -573,38 +638,38 @@ var IO = class {
573
638
  get logger() {
574
639
  return new IOLogger(async (level, message, data) => {
575
640
  let logLevel = "info";
576
- switch (level) {
577
- case "LOG": {
578
- this._jobLogger?.log(message, data);
579
- logLevel = "log";
580
- break;
581
- }
582
- case "DEBUG": {
583
- this._jobLogger?.debug(message, data);
584
- logLevel = "debug";
585
- break;
586
- }
587
- case "INFO": {
588
- this._jobLogger?.info(message, data);
589
- logLevel = "info";
590
- break;
591
- }
592
- case "WARN": {
593
- this._jobLogger?.warn(message, data);
594
- logLevel = "warn";
595
- break;
596
- }
597
- case "ERROR": {
598
- this._jobLogger?.error(message, data);
599
- logLevel = "error";
600
- break;
601
- }
602
- }
603
641
  if (import_core3.Logger.satisfiesLogLevel(logLevel, this._jobLogLevel)) {
604
642
  await this.runTask([
605
643
  message,
606
644
  level
607
645
  ], async (task) => {
646
+ switch (level) {
647
+ case "LOG": {
648
+ this._jobLogger?.log(message, data);
649
+ logLevel = "log";
650
+ break;
651
+ }
652
+ case "DEBUG": {
653
+ this._jobLogger?.debug(message, data);
654
+ logLevel = "debug";
655
+ break;
656
+ }
657
+ case "INFO": {
658
+ this._jobLogger?.info(message, data);
659
+ logLevel = "info";
660
+ break;
661
+ }
662
+ case "WARN": {
663
+ this._jobLogger?.warn(message, data);
664
+ logLevel = "warn";
665
+ break;
666
+ }
667
+ case "ERROR": {
668
+ this._jobLogger?.error(message, data);
669
+ logLevel = "error";
670
+ break;
671
+ }
672
+ }
608
673
  }, {
609
674
  name: "log",
610
675
  icon: "log",
@@ -889,18 +954,42 @@ var IO = class {
889
954
  const cachedTask = this._cachedTasks.get(idempotencyKey);
890
955
  if (cachedTask && cachedTask.status === "COMPLETED") {
891
956
  this._logger.debug("Using completed cached task", {
892
- idempotencyKey,
893
- cachedTask
957
+ idempotencyKey
894
958
  });
959
+ this._stats.cachedTaskHits++;
895
960
  return cachedTask.output;
896
961
  }
897
- const task = await this._apiClient.runTask(this._id, {
962
+ if (options?.noop && this._noopTasksBloomFilter) {
963
+ if (this._noopTasksBloomFilter.test(idempotencyKey)) {
964
+ this._logger.debug("task idempotency key exists in noopTasksBloomFilter", {
965
+ idempotencyKey
966
+ });
967
+ this._stats.noopCachedTaskHits++;
968
+ return {};
969
+ }
970
+ }
971
+ const response = await this._apiClient.runTask(this._id, {
898
972
  idempotencyKey,
899
- displayKey: typeof key === "string" ? key : key.join("."),
973
+ displayKey: typeof key === "string" ? key : void 0,
900
974
  noop: false,
901
975
  ...options ?? {},
902
976
  parentId
977
+ }, {
978
+ cachedTasksCursor: this._cachedTasksCursor
903
979
  });
980
+ const task = response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS ? response.body.task : response.body;
981
+ if (response.version === import_core3.API_VERSIONS.LAZY_LOADED_CACHED_TASKS) {
982
+ this._cachedTasksCursor = response.body.cachedTasks?.cursor;
983
+ for (const cachedTask2 of response.body.cachedTasks?.tasks ?? []) {
984
+ if (!this._cachedTasks.has(cachedTask2.idempotencyKey)) {
985
+ this._cachedTasks.set(cachedTask2.idempotencyKey, cachedTask2);
986
+ this._logger.debug("Injecting lazy loaded task into task cache", {
987
+ idempotencyKey: cachedTask2.idempotencyKey
988
+ });
989
+ this._stats.lazyLoadedCachedTasks++;
990
+ }
991
+ }
992
+ }
904
993
  if (task.status === "CANCELED") {
905
994
  this._logger.debug("Task canceled", {
906
995
  idempotencyKey,
@@ -909,11 +998,18 @@ var IO = class {
909
998
  throw new CanceledWithTaskError(task);
910
999
  }
911
1000
  if (task.status === "COMPLETED") {
912
- this._logger.debug("Using task output", {
913
- idempotencyKey,
914
- task
915
- });
916
- __privateMethod(this, _addToCachedTasks, addToCachedTasks_fn).call(this, task);
1001
+ if (task.noop) {
1002
+ this._logger.debug("Noop Task completed", {
1003
+ idempotencyKey
1004
+ });
1005
+ this._noopTasksBloomFilter?.add(task.idempotencyKey);
1006
+ } else {
1007
+ this._logger.debug("Cache miss", {
1008
+ idempotencyKey
1009
+ });
1010
+ this._stats.cachedTaskMisses++;
1011
+ __privateMethod(this, _addToCachedTasks, addToCachedTasks_fn).call(this, task);
1012
+ }
917
1013
  return task.output;
918
1014
  }
919
1015
  if (task.status === "ERRORED") {
@@ -923,23 +1019,16 @@ var IO = class {
923
1019
  });
924
1020
  throw new Error(task.error ?? task?.output ? JSON.stringify(task.output) : "Task errored");
925
1021
  }
926
- if (task.status === "WAITING") {
927
- this._logger.debug("Task waiting", {
928
- idempotencyKey,
929
- task
930
- });
931
- throw new ResumeWithTaskError(task);
932
- }
933
- if (task.status === "RUNNING" && typeof task.operation === "string") {
934
- this._logger.debug("Task running operation", {
935
- idempotencyKey,
936
- task
937
- });
938
- throw new ResumeWithTaskError(task);
939
- }
940
1022
  const executeTask = /* @__PURE__ */ __name(async () => {
941
1023
  try {
942
1024
  const result = await callback(task, this);
1025
+ if (task.status === "WAITING" && task.callbackUrl) {
1026
+ this._logger.debug("Waiting for remote callback", {
1027
+ idempotencyKey,
1028
+ task
1029
+ });
1030
+ return {};
1031
+ }
943
1032
  const output = import_core3.SerializableJsonSchema.parse(result);
944
1033
  this._logger.debug("Completing using output", {
945
1034
  idempotencyKey,
@@ -949,6 +1038,7 @@ var IO = class {
949
1038
  output: output ?? void 0,
950
1039
  properties: task.outputProperties ?? void 0
951
1040
  });
1041
+ this._stats.executedTasks++;
952
1042
  if (completedTask.status === "CANCELED") {
953
1043
  throw new CanceledWithTaskError(completedTask);
954
1044
  }
@@ -1005,10 +1095,39 @@ var IO = class {
1005
1095
  throw error;
1006
1096
  }
1007
1097
  }, "executeTask");
1098
+ if (task.status === "WAITING") {
1099
+ this._logger.debug("Task waiting", {
1100
+ idempotencyKey,
1101
+ task
1102
+ });
1103
+ if (task.callbackUrl) {
1104
+ await this._taskStorage.run({
1105
+ taskId: task.id
1106
+ }, executeTask);
1107
+ }
1108
+ throw new ResumeWithTaskError(task);
1109
+ }
1110
+ if (task.status === "RUNNING" && typeof task.operation === "string") {
1111
+ this._logger.debug("Task running operation", {
1112
+ idempotencyKey,
1113
+ task
1114
+ });
1115
+ throw new ResumeWithTaskError(task);
1116
+ }
1008
1117
  return this._taskStorage.run({
1009
1118
  taskId: task.id
1010
1119
  }, executeTask);
1011
1120
  }
1121
+ yield(key) {
1122
+ if (!(0, import_core3.supportsFeature)("yieldExecution", this._serverVersion)) {
1123
+ 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.");
1124
+ return;
1125
+ }
1126
+ if (this._yieldedExecutions.includes(key)) {
1127
+ return;
1128
+ }
1129
+ throw new YieldExecutionError(key);
1130
+ }
1012
1131
  async try(tryCallback, catchCallback) {
1013
1132
  try {
1014
1133
  return await tryCallback();
@@ -1483,7 +1602,7 @@ var registerSourceEvent = {
1483
1602
  icon: "register-source",
1484
1603
  parsePayload: import_core7.RegisterSourceEventSchemaV2.parse
1485
1604
  };
1486
- 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;
1605
+ 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;
1487
1606
  var TriggerClient = class {
1488
1607
  constructor(options) {
1489
1608
  __privateAdd(this, _preprocessRun);
@@ -1497,6 +1616,8 @@ var TriggerClient = class {
1497
1616
  __privateAdd(this, _buildJobIndex);
1498
1617
  __privateAdd(this, _buildJobIntegrations);
1499
1618
  __privateAdd(this, _buildJobIntegration);
1619
+ __privateAdd(this, _logIOStats);
1620
+ __privateAdd(this, _standardResponseHeaders);
1500
1621
  __privateAdd(this, _options4, void 0);
1501
1622
  __privateAdd(this, _registeredJobs, {});
1502
1623
  __privateAdd(this, _registeredSources, {});
@@ -1510,7 +1631,10 @@ var TriggerClient = class {
1510
1631
  this.id = options.id;
1511
1632
  __privateSet(this, _options4, options);
1512
1633
  __privateSet(this, _client2, new ApiClient(__privateGet(this, _options4)));
1513
- __privateSet(this, _internalLogger, new import_core7.Logger("trigger.dev", __privateGet(this, _options4).verbose ? "debug" : "log"));
1634
+ __privateSet(this, _internalLogger, new import_core7.Logger("trigger.dev", __privateGet(this, _options4).verbose ? "debug" : "log", [
1635
+ "output",
1636
+ "noopTasksSet"
1637
+ ]));
1514
1638
  }
1515
1639
  async handleRequest(request) {
1516
1640
  __privateGet(this, _internalLogger).debug("handling request", {
@@ -1519,6 +1643,7 @@ var TriggerClient = class {
1519
1643
  method: request.method
1520
1644
  });
1521
1645
  const apiKey = request.headers.get("x-trigger-api-key");
1646
+ const triggerVersion = request.headers.get("x-trigger-version");
1522
1647
  const authorization = this.authorized(apiKey);
1523
1648
  switch (authorization) {
1524
1649
  case "authorized": {
@@ -1529,7 +1654,8 @@ var TriggerClient = class {
1529
1654
  status: 401,
1530
1655
  body: {
1531
1656
  message: "Unauthorized: client missing apiKey"
1532
- }
1657
+ },
1658
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1533
1659
  };
1534
1660
  }
1535
1661
  case "missing-header": {
@@ -1537,7 +1663,8 @@ var TriggerClient = class {
1537
1663
  status: 401,
1538
1664
  body: {
1539
1665
  message: "Unauthorized: missing x-trigger-api-key header"
1540
- }
1666
+ },
1667
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1541
1668
  };
1542
1669
  }
1543
1670
  case "unauthorized": {
@@ -1545,7 +1672,8 @@ var TriggerClient = class {
1545
1672
  status: 401,
1546
1673
  body: {
1547
1674
  message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`
1548
- }
1675
+ },
1676
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1549
1677
  };
1550
1678
  }
1551
1679
  }
@@ -1554,7 +1682,8 @@ var TriggerClient = class {
1554
1682
  status: 405,
1555
1683
  body: {
1556
1684
  message: "Method not allowed (only POST is allowed)"
1557
- }
1685
+ },
1686
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1558
1687
  };
1559
1688
  }
1560
1689
  const action = request.headers.get("x-trigger-action");
@@ -1563,7 +1692,8 @@ var TriggerClient = class {
1563
1692
  status: 400,
1564
1693
  body: {
1565
1694
  message: "Missing x-trigger-action header"
1566
- }
1695
+ },
1696
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1567
1697
  };
1568
1698
  }
1569
1699
  switch (action) {
@@ -1575,7 +1705,8 @@ var TriggerClient = class {
1575
1705
  body: {
1576
1706
  ok: false,
1577
1707
  error: "Missing endpoint ID"
1578
- }
1708
+ },
1709
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1579
1710
  };
1580
1711
  }
1581
1712
  if (this.id !== endpointId) {
@@ -1584,14 +1715,16 @@ var TriggerClient = class {
1584
1715
  body: {
1585
1716
  ok: false,
1586
1717
  error: `Endpoint ID mismatch error. Expected ${this.id}, got ${endpointId}`
1587
- }
1718
+ },
1719
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1588
1720
  };
1589
1721
  }
1590
1722
  return {
1591
1723
  status: 200,
1592
1724
  body: {
1593
1725
  ok: true
1594
- }
1726
+ },
1727
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1595
1728
  };
1596
1729
  }
1597
1730
  case "INDEX_ENDPOINT": {
@@ -1613,7 +1746,8 @@ var TriggerClient = class {
1613
1746
  };
1614
1747
  return {
1615
1748
  status: 200,
1616
- body
1749
+ body,
1750
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1617
1751
  };
1618
1752
  }
1619
1753
  case "INITIALIZE_TRIGGER": {
@@ -1638,7 +1772,8 @@ var TriggerClient = class {
1638
1772
  }
1639
1773
  return {
1640
1774
  status: 200,
1641
- body: dynamicTrigger.registeredTriggerForParams(body.data.params)
1775
+ body: dynamicTrigger.registeredTriggerForParams(body.data.params),
1776
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1642
1777
  };
1643
1778
  }
1644
1779
  case "EXECUTE_JOB": {
@@ -1661,10 +1796,11 @@ var TriggerClient = class {
1661
1796
  }
1662
1797
  };
1663
1798
  }
1664
- const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job);
1799
+ const results = await __privateMethod(this, _executeJob, executeJob_fn).call(this, execution.data, job, triggerVersion);
1665
1800
  return {
1666
1801
  status: 200,
1667
- body: results
1802
+ body: results,
1803
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1668
1804
  };
1669
1805
  }
1670
1806
  case "PREPROCESS_RUN": {
@@ -1693,7 +1829,8 @@ var TriggerClient = class {
1693
1829
  body: {
1694
1830
  abort: results.abort,
1695
1831
  properties: results.properties
1696
- }
1832
+ },
1833
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1697
1834
  };
1698
1835
  }
1699
1836
  case "DELIVER_HTTP_SOURCE_REQUEST": {
@@ -1742,7 +1879,8 @@ var TriggerClient = class {
1742
1879
  events,
1743
1880
  response,
1744
1881
  metadata
1745
- }
1882
+ },
1883
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1746
1884
  };
1747
1885
  }
1748
1886
  case "VALIDATE": {
@@ -1751,7 +1889,8 @@ var TriggerClient = class {
1751
1889
  body: {
1752
1890
  ok: true,
1753
1891
  endpointId: this.id
1754
- }
1892
+ },
1893
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1755
1894
  };
1756
1895
  }
1757
1896
  }
@@ -1759,7 +1898,8 @@ var TriggerClient = class {
1759
1898
  status: 405,
1760
1899
  body: {
1761
1900
  message: "Method not allowed"
1762
- }
1901
+ },
1902
+ headers: __privateGet(this, _standardResponseHeaders, standardResponseHeaders_get)
1763
1903
  };
1764
1904
  }
1765
1905
  defineJob(options) {
@@ -1958,22 +2098,27 @@ preprocessRun_fn = /* @__PURE__ */ __name(async function(body, job) {
1958
2098
  };
1959
2099
  }, "#preprocessRun");
1960
2100
  _executeJob = new WeakSet();
1961
- executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
2101
+ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1, triggerVersion) {
1962
2102
  __privateGet(this, _internalLogger).debug("executing job", {
1963
2103
  execution: body1,
1964
2104
  job: job1.id,
1965
- version: job1.version
2105
+ version: job1.version,
2106
+ triggerVersion
1966
2107
  });
1967
2108
  const context = __privateMethod(this, _createRunContext, createRunContext_fn).call(this, body1);
1968
2109
  const io = new IO({
1969
2110
  id: body1.run.id,
1970
2111
  cachedTasks: body1.tasks,
2112
+ cachedTasksCursor: body1.cachedTaskCursor,
2113
+ yieldedExecutions: body1.yieldedExecutions ?? [],
2114
+ noopTasksSet: body1.noopTasksSet,
1971
2115
  apiClient: __privateGet(this, _client2),
1972
2116
  logger: __privateGet(this, _internalLogger),
1973
2117
  client: this,
1974
2118
  context,
1975
2119
  jobLogLevel: job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info",
1976
- jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new import_core7.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0
2120
+ jobLogger: __privateGet(this, _options4).ioLogLocalEnabled ? new import_core7.Logger(job1.id, job1.logLevel ?? __privateGet(this, _options4).logLevel ?? "info") : void 0,
2121
+ serverVersion: triggerVersion
1977
2122
  });
1978
2123
  const resolvedConnections = await __privateMethod(this, _resolveConnections, resolveConnections_fn).call(this, context, job1.options.integrations, body1.connections);
1979
2124
  if (!resolvedConnections.ok) {
@@ -1990,11 +2135,23 @@ executeJob_fn = /* @__PURE__ */ __name(async function(body1, job1) {
1990
2135
  }, () => {
1991
2136
  return job1.options.run(job1.trigger.event.parsePayload(body1.event.payload ?? {}), ioWithConnections, context);
1992
2137
  });
2138
+ if (__privateGet(this, _options4).verbose) {
2139
+ __privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
2140
+ }
1993
2141
  return {
1994
2142
  status: "SUCCESS",
1995
2143
  output
1996
2144
  };
1997
2145
  } catch (error) {
2146
+ if (__privateGet(this, _options4).verbose) {
2147
+ __privateMethod(this, _logIOStats, logIOStats_fn).call(this, io.stats);
2148
+ }
2149
+ if (error instanceof YieldExecutionError) {
2150
+ return {
2151
+ status: "YIELD_EXECUTION",
2152
+ key: error.key
2153
+ };
2154
+ }
1998
2155
  if (error instanceof ParsedPayloadSchemaError) {
1999
2156
  return {
2000
2157
  status: "INVALID_PAYLOAD",
@@ -2318,6 +2475,18 @@ buildJobIntegration_fn = /* @__PURE__ */ __name(function(integration1) {
2318
2475
  authSource
2319
2476
  };
2320
2477
  }, "#buildJobIntegration");
2478
+ _logIOStats = new WeakSet();
2479
+ logIOStats_fn = /* @__PURE__ */ __name(function(stats) {
2480
+ __privateGet(this, _internalLogger).debug("IO stats", {
2481
+ stats
2482
+ });
2483
+ }, "#logIOStats");
2484
+ _standardResponseHeaders = new WeakSet();
2485
+ standardResponseHeaders_get = /* @__PURE__ */ __name(function() {
2486
+ return {
2487
+ "Trigger-Version": import_core7.API_VERSIONS.LAZY_LOADED_CACHED_TASKS
2488
+ };
2489
+ }, "#standardResponseHeaders");
2321
2490
  function dynamicTriggerRegisterSourceJobId(id) {
2322
2491
  return `register-dynamic-trigger-${id}`;
2323
2492
  }