@trigger.dev/sdk 0.0.0-prerelease-20251215135620 → 0.0.0-prerelease-20260120115202

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,5 +1,6 @@
1
- import { createIdempotencyKey, type IdempotencyKey } from "@trigger.dev/core/v3";
1
+ import { createIdempotencyKey, resetIdempotencyKey, type IdempotencyKey } from "@trigger.dev/core/v3";
2
2
  export declare const idempotencyKeys: {
3
3
  create: typeof createIdempotencyKey;
4
+ reset: typeof resetIdempotencyKey;
4
5
  };
5
6
  export type { IdempotencyKey };
@@ -4,5 +4,6 @@ exports.idempotencyKeys = void 0;
4
4
  const v3_1 = require("@trigger.dev/core/v3");
5
5
  exports.idempotencyKeys = {
6
6
  create: v3_1.createIdempotencyKey,
7
+ reset: v3_1.resetIdempotencyKey,
7
8
  };
8
9
  //# sourceMappingURL=idempotencyKeys.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"idempotencyKeys.js","sourceRoot":"","sources":["../../../src/v3/idempotencyKeys.ts"],"names":[],"mappings":";;;AAAA,6CAAiF;AAEpE,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,yBAAoB;CAC7B,CAAC"}
1
+ {"version":3,"file":"idempotencyKeys.js","sourceRoot":"","sources":["../../../src/v3/idempotencyKeys.ts"],"names":[],"mappings":";;;AAAA,6CAAsG;AAEzF,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,yBAAoB;IAC5B,KAAK,EAAE,wBAAmB;CAC3B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export * from "./cache.js";
2
2
  export * from "./config.js";
3
3
  export { retry, type RetryOptions } from "./retry.js";
4
- export { queue } from "./shared.js";
4
+ export { queue, BatchTriggerError } from "./shared.js";
5
5
  export * from "./tasks.js";
6
6
  export * from "./batch.js";
7
7
  export * from "./wait.js";
@@ -26,13 +26,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.auth = exports.configure = exports.queues = exports.envvars = exports.schedules = exports.runs = exports.logger = exports.CompleteTaskWithOutput = exports.OutOfMemoryError = exports.AbortTaskRunError = exports.UnprocessableEntityError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ApiError = exports.queue = exports.retry = void 0;
29
+ exports.auth = exports.configure = exports.queues = exports.envvars = exports.schedules = exports.runs = exports.logger = exports.CompleteTaskWithOutput = exports.OutOfMemoryError = exports.AbortTaskRunError = exports.UnprocessableEntityError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ApiError = exports.BatchTriggerError = exports.queue = exports.retry = void 0;
30
30
  __exportStar(require("./cache.js"), exports);
31
31
  __exportStar(require("./config.js"), exports);
32
32
  var retry_js_1 = require("./retry.js");
33
33
  Object.defineProperty(exports, "retry", { enumerable: true, get: function () { return retry_js_1.retry; } });
34
34
  var shared_js_1 = require("./shared.js");
35
35
  Object.defineProperty(exports, "queue", { enumerable: true, get: function () { return shared_js_1.queue; } });
36
+ Object.defineProperty(exports, "BatchTriggerError", { enumerable: true, get: function () { return shared_js_1.BatchTriggerError; } });
36
37
  __exportStar(require("./tasks.js"), exports);
37
38
  __exportStar(require("./batch.js"), exports);
38
39
  __exportStar(require("./wait.js"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAoC;AAA3B,kGAAA,KAAK,OAAA;AACd,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,8CAA4B;AAC5B,4CAA0B;AAC1B,+CAA6B;AAC7B,kDAAgC;AAChC,+CAA6B;AAS7B,2CAe8B;AAd5B,8FAAA,QAAQ,OAAA;AACR,yGAAA,mBAAmB,OAAA;AACnB,qGAAA,eAAe,OAAA;AACf,mGAAA,aAAa,OAAA;AACb,yGAAA,mBAAmB,OAAA;AACnB,mGAAA,aAAa,OAAA;AACb,2GAAA,qBAAqB,OAAA;AACrB,oGAAA,cAAc,OAAA;AACd,8GAAA,wBAAwB,OAAA;AACxB,uGAAA,iBAAiB,OAAA;AACjB,sGAAA,gBAAgB,OAAA;AAChB,4GAAA,sBAAsB,OAAA;AACtB,4FAAA,MAAM,OAAA;AAIR,qCASmB;AARjB,+FAAA,IAAI,OAAA;AASN,kEAAkD;AAClD,wDAAwC;AACxC,sDAAsC;AAGtC,qCAA4C;AAAnC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAuD;AAA9C,kGAAA,KAAK,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AACjC,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,8CAA4B;AAC5B,4CAA0B;AAC1B,+CAA6B;AAC7B,kDAAgC;AAChC,+CAA6B;AAS7B,2CAe8B;AAd5B,8FAAA,QAAQ,OAAA;AACR,yGAAA,mBAAmB,OAAA;AACnB,qGAAA,eAAe,OAAA;AACf,mGAAA,aAAa,OAAA;AACb,yGAAA,mBAAmB,OAAA;AACnB,mGAAA,aAAa,OAAA;AACb,2GAAA,qBAAqB,OAAA;AACrB,oGAAA,cAAc,OAAA;AACd,8GAAA,wBAAwB,OAAA;AACxB,uGAAA,iBAAiB,OAAA;AACjB,sGAAA,gBAAgB,OAAA;AAChB,4GAAA,sBAAsB,OAAA;AACtB,4FAAA,MAAM,OAAA;AAIR,qCASmB;AARjB,+FAAA,IAAI,OAAA;AASN,kEAAkD;AAClD,wDAAwC;AACxC,sDAAsC;AAGtC,qCAA4C;AAAnC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
@@ -1,10 +1,9 @@
1
1
  import { SerializableJson } from "@trigger.dev/core";
2
- import { ApiRequestOptions, InitOutput, Queue, QueueOptions, SubtaskUnwrapError, TaskFromIdentifier, TaskRunContext, TaskRunPromise } from "@trigger.dev/core/v3";
2
+ import { ApiError, ApiRequestOptions, InitOutput, Queue, QueueOptions, SubtaskUnwrapError, TaskFromIdentifier, TaskRunContext, TaskRunPromise } from "@trigger.dev/core/v3";
3
3
  import type { AnyRunHandle, AnyTask, BatchByIdAndWaitItem, BatchByIdItem, BatchByIdResult, BatchByTaskAndWaitItem, BatchByTaskItem, BatchByTaskResult, BatchItem, BatchResult, BatchRunHandle, BatchRunHandleFromTypes, BatchTasksRunHandleFromTypes, BatchTriggerAndWaitOptions, BatchTriggerOptions, InferRunTypes, RunHandle, RunHandleFromTypes, RunHandleOutput, RunHandlePayload, Task, TaskBatchOutputHandle, TaskIdentifier, TaskOptions, TaskOptionsWithSchema, TaskOutput, TaskOutputHandle, TaskPayload, TaskRunResult, TaskSchema, TaskWithSchema, TaskWithSchemaOptions, TaskWithToolOptions, ToolTask, ToolTaskParameters, TriggerAndWaitOptions, TriggerApiRequestOptions, TriggerOptions } from "@trigger.dev/core/v3";
4
4
  export type { AnyRunHandle, AnyTask, BatchItem, BatchResult, BatchRunHandle, BatchTriggerOptions, Queue, RunHandle, RunHandleOutput, RunHandlePayload, SerializableJson, Task, TaskBatchOutputHandle, TaskFromIdentifier, TaskIdentifier, TaskOptions, TaskOutput, TaskOutputHandle, TaskPayload, TaskRunResult, TriggerOptions, TaskWithSchema, TaskWithSchemaOptions, TaskSchema, TaskOptionsWithSchema, };
5
5
  export { SubtaskUnwrapError, TaskRunPromise };
6
6
  export type Context = TaskRunContext;
7
- export { BatchTriggerError };
8
7
  export declare function queue(options: QueueOptions): Queue;
9
8
  export declare function createTask<TIdentifier extends string, TOutput = unknown, TInitOutput extends InitOutput = any>(params: TaskOptionsWithSchema<TIdentifier, TOutput, TInitOutput>): Task<TIdentifier, any, TOutput>;
10
9
  export declare function createTask<TIdentifier extends string, TInput = void, TOutput = unknown, TInitOutput extends InitOutput = any>(params: TaskOptions<TIdentifier, TInput, TOutput, TInitOutput>): Task<TIdentifier, TInput, TOutput>;
@@ -425,11 +424,23 @@ export declare function batchTriggerAndWaitTasks<TTasks extends readonly AnyTask
425
424
  /**
426
425
  * Error thrown when batch trigger operations fail.
427
426
  * Includes context about which phase failed and the batch details.
427
+ *
428
+ * When the underlying error is a rate limit (429), additional properties are exposed:
429
+ * - `isRateLimited`: true
430
+ * - `retryAfterMs`: milliseconds until the rate limit resets
428
431
  */
429
- declare class BatchTriggerError extends Error {
432
+ export declare class BatchTriggerError extends Error {
430
433
  readonly phase: "create" | "stream";
431
434
  readonly batchId?: string;
432
435
  readonly itemCount: number;
436
+ /** True if the error was caused by rate limiting (HTTP 429) */
437
+ readonly isRateLimited: boolean;
438
+ /** Milliseconds until the rate limit resets. Only set when `isRateLimited` is true. */
439
+ readonly retryAfterMs?: number;
440
+ /** The underlying API error, if the cause was an ApiError */
441
+ readonly apiError?: ApiError;
442
+ /** The underlying cause of the error */
443
+ readonly cause?: unknown;
433
444
  constructor(message: string, options: {
434
445
  cause?: unknown;
435
446
  phase: "create" | "stream";
@@ -273,6 +273,7 @@ async function batchTriggerById(...args) {
273
273
  priority: item.options?.priority,
274
274
  region: item.options?.region,
275
275
  lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
276
+ debounce: item.options?.debounce,
276
277
  },
277
278
  };
278
279
  }));
@@ -366,6 +367,7 @@ async function batchTriggerByIdAndWait(...args) {
366
367
  machine: item.options?.machine,
367
368
  priority: item.options?.priority,
368
369
  region: item.options?.region,
370
+ debounce: item.options?.debounce,
369
371
  },
370
372
  };
371
373
  }));
@@ -463,6 +465,7 @@ async function batchTriggerTasks(...args) {
463
465
  priority: item.options?.priority,
464
466
  region: item.options?.region,
465
467
  lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
468
+ debounce: item.options?.debounce,
466
469
  },
467
470
  };
468
471
  }));
@@ -557,6 +560,7 @@ async function batchTriggerAndWaitTasks(...args) {
557
560
  machine: item.options?.machine,
558
561
  priority: item.options?.priority,
559
562
  region: item.options?.region,
563
+ debounce: item.options?.debounce,
560
564
  },
561
565
  };
562
566
  }));
@@ -642,6 +646,7 @@ async function executeBatchTwoPhase(apiClient, items, options, requestOptions) {
642
646
  parentRunId: options.parentRunId,
643
647
  resumeParentOnCompletion: options.resumeParentOnCompletion,
644
648
  idempotencyKey: options.idempotencyKey,
649
+ idempotencyKeyOptions: options.idempotencyKeyOptions,
645
650
  }, { spanParentAsLink: options.spanParentAsLink }, requestOptions);
646
651
  }
647
652
  catch (error) {
@@ -672,20 +677,74 @@ async function executeBatchTwoPhase(apiClient, items, options, requestOptions) {
672
677
  /**
673
678
  * Error thrown when batch trigger operations fail.
674
679
  * Includes context about which phase failed and the batch details.
680
+ *
681
+ * When the underlying error is a rate limit (429), additional properties are exposed:
682
+ * - `isRateLimited`: true
683
+ * - `retryAfterMs`: milliseconds until the rate limit resets
675
684
  */
676
685
  class BatchTriggerError extends Error {
677
686
  phase;
678
687
  batchId;
679
688
  itemCount;
689
+ /** True if the error was caused by rate limiting (HTTP 429) */
690
+ isRateLimited;
691
+ /** Milliseconds until the rate limit resets. Only set when `isRateLimited` is true. */
692
+ retryAfterMs;
693
+ /** The underlying API error, if the cause was an ApiError */
694
+ apiError;
695
+ /** The underlying cause of the error */
696
+ cause;
680
697
  constructor(message, options) {
681
- super(message, { cause: options.cause });
698
+ // Build enhanced message that includes the cause's message
699
+ const fullMessage = buildBatchErrorMessage(message, options.cause);
700
+ super(fullMessage, { cause: options.cause });
682
701
  this.name = "BatchTriggerError";
702
+ this.cause = options.cause;
683
703
  this.phase = options.phase;
684
704
  this.batchId = options.batchId;
685
705
  this.itemCount = options.itemCount;
706
+ // Extract rate limit info from cause
707
+ if (options.cause instanceof v3_1.RateLimitError) {
708
+ this.isRateLimited = true;
709
+ this.retryAfterMs = options.cause.millisecondsUntilReset;
710
+ this.apiError = options.cause;
711
+ }
712
+ else if (options.cause instanceof v3_1.ApiError) {
713
+ this.isRateLimited = options.cause.status === 429;
714
+ this.apiError = options.cause;
715
+ }
716
+ else {
717
+ this.isRateLimited = false;
718
+ }
686
719
  }
687
720
  }
688
721
  exports.BatchTriggerError = BatchTriggerError;
722
+ /**
723
+ * Build an enhanced error message that includes context from the cause.
724
+ */
725
+ function buildBatchErrorMessage(baseMessage, cause) {
726
+ if (!cause) {
727
+ return baseMessage;
728
+ }
729
+ // Handle RateLimitError specifically for better messaging
730
+ if (cause instanceof v3_1.RateLimitError) {
731
+ const retryMs = cause.millisecondsUntilReset;
732
+ if (retryMs !== undefined) {
733
+ const retrySeconds = Math.ceil(retryMs / 1000);
734
+ return `${baseMessage}: Rate limit exceeded - retry after ${retrySeconds}s`;
735
+ }
736
+ return `${baseMessage}: Rate limit exceeded`;
737
+ }
738
+ // Handle other ApiErrors
739
+ if (cause instanceof v3_1.ApiError) {
740
+ return `${baseMessage}: ${cause.message}`;
741
+ }
742
+ // Handle generic errors
743
+ if (cause instanceof Error) {
744
+ return `${baseMessage}: ${cause.message}`;
745
+ }
746
+ return baseMessage;
747
+ }
689
748
  /**
690
749
  * Execute a streaming 2-phase batch trigger where items are streamed from an AsyncIterable.
691
750
  * Unlike executeBatchTwoPhase, this doesn't know the count upfront.
@@ -801,6 +860,7 @@ async function* transformBatchItemsStream(items, options) {
801
860
  priority: item.options?.priority,
802
861
  region: item.options?.region,
803
862
  lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
863
+ debounce: item.options?.debounce,
804
864
  },
805
865
  };
806
866
  }
@@ -841,6 +901,7 @@ async function* transformBatchItemsStreamForWait(items, options) {
841
901
  machine: item.options?.machine,
842
902
  priority: item.options?.priority,
843
903
  region: item.options?.region,
904
+ debounce: item.options?.debounce,
844
905
  },
845
906
  };
846
907
  }
@@ -880,6 +941,7 @@ async function* transformBatchByTaskItemsStream(items, options) {
880
941
  priority: item.options?.priority,
881
942
  region: item.options?.region,
882
943
  lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
944
+ debounce: item.options?.debounce,
883
945
  },
884
946
  };
885
947
  }
@@ -919,6 +981,7 @@ async function* transformBatchByTaskItemsStreamForWait(items, options) {
919
981
  machine: item.options?.machine,
920
982
  priority: item.options?.priority,
921
983
  region: item.options?.region,
984
+ debounce: item.options?.debounce,
922
985
  },
923
986
  };
924
987
  }
@@ -959,6 +1022,7 @@ async function* transformSingleTaskBatchItemsStream(taskIdentifier, items, parse
959
1022
  priority: item.options?.priority,
960
1023
  region: item.options?.region,
961
1024
  lockToVersion: item.options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
1025
+ debounce: item.options?.debounce,
962
1026
  },
963
1027
  };
964
1028
  }
@@ -974,6 +1038,12 @@ async function* transformSingleTaskBatchItemsStreamForWait(taskIdentifier, items
974
1038
  const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
975
1039
  const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
976
1040
  const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
1041
+ // Process item-specific idempotency key and extract options
1042
+ const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
1043
+ const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
1044
+ const idempotencyKeyOptions = itemIdempotencyKey
1045
+ ? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
1046
+ : undefined;
977
1047
  yield {
978
1048
  index: index++,
979
1049
  task: taskIdentifier,
@@ -994,11 +1064,13 @@ async function* transformSingleTaskBatchItemsStreamForWait(taskIdentifier, items
994
1064
  maxAttempts: item.options?.maxAttempts,
995
1065
  metadata: item.options?.metadata,
996
1066
  maxDuration: item.options?.maxDuration,
997
- idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
1067
+ idempotencyKey: finalIdempotencyKey?.toString(),
998
1068
  idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
1069
+ idempotencyKeyOptions,
999
1070
  machine: item.options?.machine,
1000
1071
  priority: item.options?.priority,
1001
1072
  region: item.options?.region,
1073
+ debounce: item.options?.debounce,
1002
1074
  },
1003
1075
  };
1004
1076
  }
@@ -1007,6 +1079,11 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
1007
1079
  const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
1008
1080
  const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
1009
1081
  const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
1082
+ // Process idempotency key and extract options for storage
1083
+ const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
1084
+ const idempotencyKeyOptions = processedIdempotencyKey
1085
+ ? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
1086
+ : undefined;
1010
1087
  const handle = await apiClient.triggerTask(id, {
1011
1088
  payload: payloadPacket.data,
1012
1089
  options: {
@@ -1014,8 +1091,9 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
1014
1091
  concurrencyKey: options?.concurrencyKey,
1015
1092
  test: v3_1.taskContext.ctx?.run.isTest,
1016
1093
  payloadType: payloadPacket.dataType,
1017
- idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
1094
+ idempotencyKey: processedIdempotencyKey?.toString(),
1018
1095
  idempotencyKeyTTL: options?.idempotencyKeyTTL,
1096
+ idempotencyKeyOptions,
1019
1097
  delay: options?.delay,
1020
1098
  ttl: options?.ttl,
1021
1099
  tags: options?.tags,
@@ -1027,6 +1105,7 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
1027
1105
  priority: options?.priority,
1028
1106
  region: options?.region,
1029
1107
  lockToVersion: options?.version ?? (0, v3_1.getEnvVar)("TRIGGER_VERSION"),
1108
+ debounce: options?.debounce,
1030
1109
  },
1031
1110
  }, {
1032
1111
  spanParentAsLink: true,
@@ -1055,6 +1134,12 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
1055
1134
  const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
1056
1135
  const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
1057
1136
  const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
1137
+ // Process item-specific idempotency key and extract options
1138
+ const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
1139
+ const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
1140
+ const idempotencyKeyOptions = itemIdempotencyKey
1141
+ ? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
1142
+ : undefined;
1058
1143
  return {
1059
1144
  index,
1060
1145
  task: taskIdentifier,
@@ -1074,8 +1159,9 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
1074
1159
  maxAttempts: item.options?.maxAttempts,
1075
1160
  metadata: item.options?.metadata,
1076
1161
  maxDuration: item.options?.maxDuration,
1077
- idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
1162
+ idempotencyKey: finalIdempotencyKey?.toString(),
1078
1163
  idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
1164
+ idempotencyKeyOptions,
1079
1165
  machine: item.options?.machine,
1080
1166
  priority: item.options?.priority,
1081
1167
  region: item.options?.region,
@@ -1084,10 +1170,16 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
1084
1170
  };
1085
1171
  }));
1086
1172
  // Execute 2-phase batch
1173
+ // Process batch-level idempotency key
1174
+ const batchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
1175
+ const batchIdempotencyKeyOptions = batchIdempotencyKey
1176
+ ? (0, v3_1.getIdempotencyKeyOptions)(batchIdempotencyKey)
1177
+ : undefined;
1087
1178
  const response = await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
1088
1179
  const result = await executeBatchTwoPhase(apiClient, ndJsonItems, {
1089
1180
  parentRunId: ctx?.run.id,
1090
- idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
1181
+ idempotencyKey: batchIdempotencyKey?.toString(),
1182
+ idempotencyKeyOptions: batchIdempotencyKeyOptions,
1091
1183
  spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
1092
1184
  }, requestOptions);
1093
1185
  span.setAttribute("batchId", result.id);
@@ -1120,10 +1212,16 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
1120
1212
  const asyncItems = normalizeToAsyncIterable(items);
1121
1213
  const transformedItems = transformSingleTaskBatchItemsStream(taskIdentifier, asyncItems, parsePayload, options, queue);
1122
1214
  // Execute streaming 2-phase batch
1215
+ // Process batch-level idempotency key
1216
+ const streamBatchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
1217
+ const streamBatchIdempotencyKeyOptions = streamBatchIdempotencyKey
1218
+ ? (0, v3_1.getIdempotencyKeyOptions)(streamBatchIdempotencyKey)
1219
+ : undefined;
1123
1220
  const response = await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
1124
1221
  const result = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
1125
1222
  parentRunId: ctx?.run.id,
1126
- idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
1223
+ idempotencyKey: streamBatchIdempotencyKey?.toString(),
1224
+ idempotencyKeyOptions: streamBatchIdempotencyKeyOptions,
1127
1225
  spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
1128
1226
  }, requestOptions);
1129
1227
  span.setAttribute("batchId", result.id);
@@ -1160,6 +1258,11 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
1160
1258
  const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
1161
1259
  const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
1162
1260
  const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
1261
+ // Process idempotency key and extract options for storage
1262
+ const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
1263
+ const idempotencyKeyOptions = processedIdempotencyKey
1264
+ ? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
1265
+ : undefined;
1163
1266
  return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
1164
1267
  const response = await apiClient.triggerTask(id, {
1165
1268
  payload: payloadPacket.data,
@@ -1177,11 +1280,13 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
1177
1280
  maxDuration: options?.maxDuration,
1178
1281
  resumeParentOnCompletion: true,
1179
1282
  parentRunId: ctx.run.id,
1180
- idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
1283
+ idempotencyKey: processedIdempotencyKey?.toString(),
1181
1284
  idempotencyKeyTTL: options?.idempotencyKeyTTL,
1285
+ idempotencyKeyOptions,
1182
1286
  machine: options?.machine,
1183
1287
  priority: options?.priority,
1184
1288
  region: options?.region,
1289
+ debounce: options?.debounce,
1185
1290
  },
1186
1291
  }, {}, requestOptions);
1187
1292
  span.setAttribute("runId", response.id);
@@ -1219,6 +1324,12 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
1219
1324
  const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
1220
1325
  const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
1221
1326
  const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
1327
+ // Process item-specific idempotency key and extract options
1328
+ const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
1329
+ const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
1330
+ const idempotencyKeyOptions = itemIdempotencyKey
1331
+ ? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
1332
+ : undefined;
1222
1333
  return {
1223
1334
  index,
1224
1335
  task: id,
@@ -1239,20 +1350,27 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
1239
1350
  maxAttempts: item.options?.maxAttempts,
1240
1351
  metadata: item.options?.metadata,
1241
1352
  maxDuration: item.options?.maxDuration,
1242
- idempotencyKey: (await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey)) ?? batchItemIdempotencyKey,
1353
+ idempotencyKey: finalIdempotencyKey?.toString(),
1243
1354
  idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
1355
+ idempotencyKeyOptions,
1244
1356
  machine: item.options?.machine,
1245
1357
  priority: item.options?.priority,
1246
1358
  region: item.options?.region,
1247
1359
  },
1248
1360
  };
1249
1361
  }));
1362
+ // Process batch-level idempotency key
1363
+ const batchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
1364
+ const batchIdempotencyKeyOptions = batchIdempotencyKey
1365
+ ? (0, v3_1.getIdempotencyKeyOptions)(batchIdempotencyKey)
1366
+ : undefined;
1250
1367
  return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
1251
1368
  // Execute 2-phase batch
1252
1369
  const response = await executeBatchTwoPhase(apiClient, ndJsonItems, {
1253
1370
  parentRunId: ctx.run.id,
1254
1371
  resumeParentOnCompletion: true,
1255
- idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
1372
+ idempotencyKey: batchIdempotencyKey?.toString(),
1373
+ idempotencyKeyOptions: batchIdempotencyKeyOptions,
1256
1374
  spanParentAsLink: false, // Waiting: child runs share parent's trace ID
1257
1375
  }, requestOptions);
1258
1376
  span.setAttribute("batchId", response.id);
@@ -1287,12 +1405,18 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
1287
1405
  // Stream path: convert to AsyncIterable and transform
1288
1406
  const asyncItems = normalizeToAsyncIterable(items);
1289
1407
  const transformedItems = transformSingleTaskBatchItemsStreamForWait(id, asyncItems, parsePayload, options, queue);
1408
+ // Process batch-level idempotency key for streaming path
1409
+ const streamBatchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
1410
+ const streamBatchIdempotencyKeyOptions = streamBatchIdempotencyKey
1411
+ ? (0, v3_1.getIdempotencyKeyOptions)(streamBatchIdempotencyKey)
1412
+ : undefined;
1290
1413
  return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
1291
1414
  // Execute streaming 2-phase batch
1292
1415
  const response = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
1293
1416
  parentRunId: ctx.run.id,
1294
1417
  resumeParentOnCompletion: true,
1295
- idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
1418
+ idempotencyKey: streamBatchIdempotencyKey?.toString(),
1419
+ idempotencyKeyOptions: streamBatchIdempotencyKeyOptions,
1296
1420
  spanParentAsLink: false, // Waiting: child runs share parent's trace ID
1297
1421
  }, requestOptions);
1298
1422
  span.setAttribute("batchId", response.id);