@trigger.dev/core 3.0.0-beta.45 → 3.0.0-beta.47

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.
Files changed (67) hide show
  1. package/dist/{catalog-mlNxCacM.d.ts → catalog-N-X0Te3W.d.mts} +5 -23
  2. package/dist/{catalog-QcLmPVsr.d.mts → catalog-NxVZnWZh.d.ts} +5 -23
  3. package/dist/{common-55Mqj8JP.d.mts → common-fIyU5pmz.d.mts} +13 -0
  4. package/dist/{common-55Mqj8JP.d.ts → common-fIyU5pmz.d.ts} +13 -0
  5. package/dist/{manager-6NRInm7C.d.ts → manager-2ZQ3_twq.d.ts} +1 -1
  6. package/dist/{manager-2AqSY67c.d.mts → manager-X_HrWQ7_.d.mts} +1 -1
  7. package/dist/{messages-EJX0bMsF.d.mts → messages-Sggr4tid.d.mts} +233 -70
  8. package/dist/{messages-EJX0bMsF.d.ts → messages-Sggr4tid.d.ts} +233 -70
  9. package/dist/{schemas-Sb0sJcEt.d.mts → schemas-Zy7mGFgD.d.mts} +22 -0
  10. package/dist/{schemas-Sb0sJcEt.d.ts → schemas-Zy7mGFgD.d.ts} +22 -0
  11. package/dist/tracer-N0p2Fuuv.d.mts +23 -0
  12. package/dist/tracer-N0p2Fuuv.d.ts +23 -0
  13. package/dist/v3/dev/index.d.mts +2 -2
  14. package/dist/v3/dev/index.d.ts +2 -2
  15. package/dist/v3/dev/index.js.map +1 -1
  16. package/dist/v3/dev/index.mjs.map +1 -1
  17. package/dist/v3/index.d.mts +50 -38
  18. package/dist/v3/index.d.ts +50 -38
  19. package/dist/v3/index.js +503 -343
  20. package/dist/v3/index.js.map +1 -1
  21. package/dist/v3/index.mjs +499 -344
  22. package/dist/v3/index.mjs.map +1 -1
  23. package/dist/v3/otel/index.js +15 -5
  24. package/dist/v3/otel/index.js.map +1 -1
  25. package/dist/v3/otel/index.mjs +15 -5
  26. package/dist/v3/otel/index.mjs.map +1 -1
  27. package/dist/v3/prod/index.d.mts +4 -4
  28. package/dist/v3/prod/index.d.ts +4 -4
  29. package/dist/v3/prod/index.js +7 -131
  30. package/dist/v3/prod/index.js.map +1 -1
  31. package/dist/v3/prod/index.mjs +7 -131
  32. package/dist/v3/prod/index.mjs.map +1 -1
  33. package/dist/v3/schemas/index.d.mts +16 -4
  34. package/dist/v3/schemas/index.d.ts +16 -4
  35. package/dist/v3/schemas/index.js +35 -40
  36. package/dist/v3/schemas/index.js.map +1 -1
  37. package/dist/v3/schemas/index.mjs +35 -41
  38. package/dist/v3/schemas/index.mjs.map +1 -1
  39. package/dist/v3/utils/timers.d.mts +6 -0
  40. package/dist/v3/utils/timers.d.ts +6 -0
  41. package/dist/v3/utils/timers.js +31 -0
  42. package/dist/v3/utils/timers.js.map +1 -0
  43. package/dist/v3/utils/timers.mjs +28 -0
  44. package/dist/v3/utils/timers.mjs.map +1 -0
  45. package/dist/v3/workers/index.d.mts +7 -6
  46. package/dist/v3/workers/index.d.ts +7 -6
  47. package/dist/v3/workers/index.js +251 -96
  48. package/dist/v3/workers/index.js.map +1 -1
  49. package/dist/v3/workers/index.mjs +251 -96
  50. package/dist/v3/workers/index.mjs.map +1 -1
  51. package/dist/v3/zodNamespace.js +41 -18
  52. package/dist/v3/zodNamespace.js.map +1 -1
  53. package/dist/v3/zodNamespace.mjs +42 -19
  54. package/dist/v3/zodNamespace.mjs.map +1 -1
  55. package/dist/v3/zodSocket.d.mts +8 -3
  56. package/dist/v3/zodSocket.d.ts +8 -3
  57. package/dist/v3/zodSocket.js +56 -25
  58. package/dist/v3/zodSocket.js.map +1 -1
  59. package/dist/v3/zodSocket.mjs +57 -26
  60. package/dist/v3/zodSocket.mjs.map +1 -1
  61. package/dist/v3/zodfetch.d.mts +15 -2
  62. package/dist/v3/zodfetch.d.ts +15 -2
  63. package/dist/v3/zodfetch.js +248 -28
  64. package/dist/v3/zodfetch.js.map +1 -1
  65. package/dist/v3/zodfetch.mjs +246 -29
  66. package/dist/v3/zodfetch.mjs.map +1 -1
  67. package/package.json +10 -2
package/dist/v3/index.js CHANGED
@@ -33,7 +33,7 @@ var __privateMethod = (obj, member, method) => {
33
33
  };
34
34
 
35
35
  // package.json
36
- var version = "3.0.0-beta.45";
36
+ var version = "3.0.0-beta.47";
37
37
  var dependencies = {
38
38
  "@google-cloud/precise-date": "^4.0.0",
39
39
  "@opentelemetry/api": "^1.8.0",
@@ -48,7 +48,7 @@ var dependencies = {
48
48
  "@opentelemetry/sdk-trace-node": "^1.22.0",
49
49
  "@opentelemetry/semantic-conventions": "^1.22.0",
50
50
  "humanize-duration": "^3.27.3",
51
- "socket.io-client": "4.7.4",
51
+ "socket.io-client": "4.7.5",
52
52
  superjson: "^2.2.1",
53
53
  ulidx: "^2.2.1",
54
54
  zod: "3.22.3",
@@ -167,6 +167,7 @@ var TaskRun = zod.z.object({
167
167
  createdAt: zod.z.coerce.date(),
168
168
  startedAt: zod.z.coerce.date().default(() => /* @__PURE__ */ new Date()),
169
169
  idempotencyKey: zod.z.string().optional(),
170
+ maxAttempts: zod.z.number().optional(),
170
171
  durationMs: zod.z.number().default(0),
171
172
  costInCents: zod.z.number().default(0),
172
173
  baseCostInCents: zod.z.number().default(0)
@@ -458,6 +459,7 @@ var WaitReason = zod.z.enum([
458
459
  ]);
459
460
  var TaskRunExecutionLazyAttemptPayload = zod.z.object({
460
461
  runId: zod.z.string(),
462
+ attemptCount: zod.z.number().optional(),
461
463
  messageId: zod.z.string(),
462
464
  isTest: zod.z.boolean(),
463
465
  traceContext: zod.z.record(zod.z.unknown()),
@@ -484,6 +486,14 @@ var ImageDetailsMetadata = zod.z.object({
484
486
  contentHash: zod.z.string(),
485
487
  imageTag: zod.z.string()
486
488
  });
489
+ var _AbortTaskRunError = class _AbortTaskRunError extends Error {
490
+ constructor(message) {
491
+ super(message);
492
+ this.name = "AbortTaskRunError";
493
+ }
494
+ };
495
+ __name(_AbortTaskRunError, "AbortTaskRunError");
496
+ var AbortTaskRunError = _AbortTaskRunError;
487
497
  function parseError(error) {
488
498
  if (error instanceof Error) {
489
499
  return {
@@ -564,6 +574,39 @@ function createJsonErrorObject(error) {
564
574
  }
565
575
  }
566
576
  __name(createJsonErrorObject, "createJsonErrorObject");
577
+ function sanitizeError(error) {
578
+ switch (error.type) {
579
+ case "BUILT_IN_ERROR": {
580
+ return {
581
+ type: "BUILT_IN_ERROR",
582
+ message: error.message?.replace(/\0/g, ""),
583
+ name: error.name?.replace(/\0/g, ""),
584
+ stackTrace: error.stackTrace?.replace(/\0/g, "")
585
+ };
586
+ }
587
+ case "STRING_ERROR": {
588
+ return {
589
+ type: "STRING_ERROR",
590
+ raw: error.raw.replace(/\0/g, "")
591
+ };
592
+ }
593
+ case "CUSTOM_ERROR": {
594
+ return {
595
+ type: "CUSTOM_ERROR",
596
+ raw: error.raw.replace(/\0/g, "")
597
+ };
598
+ }
599
+ case "INTERNAL_ERROR": {
600
+ return {
601
+ type: "INTERNAL_ERROR",
602
+ code: error.code,
603
+ message: error.message?.replace(/\0/g, ""),
604
+ stackTrace: error.stackTrace?.replace(/\0/g, "")
605
+ };
606
+ }
607
+ }
608
+ }
609
+ __name(sanitizeError, "sanitizeError");
567
610
  function correctErrorStackTrace(stackTrace, projectDir, options) {
568
611
  const [errorLine, ...traceLines] = stackTrace.split("\n");
569
612
  return [
@@ -679,7 +722,8 @@ var TriggerTaskRequestBody = zod.z.object({
679
722
  test: zod.z.boolean().optional(),
680
723
  payloadType: zod.z.string().optional(),
681
724
  delay: zod.z.string().or(zod.z.coerce.date()).optional(),
682
- ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional()
725
+ ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional(),
726
+ maxAttempts: zod.z.number().int().optional()
683
727
  }).optional()
684
728
  });
685
729
  var TriggerTaskResponse = zod.z.object({
@@ -1192,47 +1236,15 @@ var ProdChildToWorkerMessages = {
1192
1236
  id: zod.z.string()
1193
1237
  })
1194
1238
  },
1195
- TASK_RUN_HEARTBEAT: {
1196
- message: zod.z.object({
1197
- version: zod.z.literal("v1").default("v1"),
1198
- id: zod.z.string()
1199
- })
1200
- },
1201
1239
  READY_TO_DISPOSE: {
1202
1240
  message: zod.z.undefined()
1203
1241
  },
1204
- READY_FOR_CHECKPOINT: {
1205
- message: zod.z.object({
1206
- version: zod.z.literal("v1").default("v1")
1207
- })
1208
- },
1209
- CANCEL_CHECKPOINT: {
1210
- message: zod.z.discriminatedUnion("version", [
1211
- zod.z.object({
1212
- version: zod.z.literal("v1")
1213
- }),
1214
- zod.z.object({
1215
- version: zod.z.literal("v2"),
1216
- reason: WaitReason.optional()
1217
- })
1218
- ]).default({
1219
- version: "v1"
1220
- }),
1221
- callback: zod.z.object({
1222
- // TODO: Figure out how best to handle callback schema parsing in zod IPC
1223
- version: zod.z.literal("v2"),
1224
- checkpointCanceled: zod.z.boolean(),
1225
- reason: WaitReason.optional()
1226
- })
1227
- },
1228
1242
  WAIT_FOR_DURATION: {
1229
1243
  message: zod.z.object({
1230
1244
  version: zod.z.literal("v1").default("v1"),
1231
1245
  ms: zod.z.number(),
1232
- now: zod.z.number()
1233
- }),
1234
- callback: zod.z.object({
1235
- willCheckpointAndRestore: zod.z.boolean()
1246
+ now: zod.z.number(),
1247
+ waitThresholdInMs: zod.z.number()
1236
1248
  })
1237
1249
  },
1238
1250
  WAIT_FOR_TASK: {
@@ -1435,6 +1447,7 @@ var CoordinatorToPlatformMessages = {
1435
1447
  })
1436
1448
  ])
1437
1449
  },
1450
+ // Deprecated: Only workers without lazy attempt support will use this
1438
1451
  READY_FOR_EXECUTION: {
1439
1452
  message: zod.z.object({
1440
1453
  version: zod.z.literal("v1").default("v1"),
@@ -1598,6 +1611,12 @@ var PlatformToCoordinatorMessages = {
1598
1611
  version: zod.z.literal("v1").default("v1"),
1599
1612
  runId: zod.z.string()
1600
1613
  })
1614
+ },
1615
+ DYNAMIC_CONFIG: {
1616
+ message: zod.z.object({
1617
+ version: zod.z.literal("v1").default("v1"),
1618
+ checkpointThresholdInMs: zod.z.number()
1619
+ })
1601
1620
  }
1602
1621
  };
1603
1622
  var ClientToSharedQueueMessages = {
@@ -1643,10 +1662,9 @@ var IndexTasksMessage = zod.z.object({
1643
1662
  packageVersion: zod.z.string()
1644
1663
  });
1645
1664
  var ProdWorkerToCoordinatorMessages = {
1646
- LOG: {
1665
+ TEST: {
1647
1666
  message: zod.z.object({
1648
- version: zod.z.literal("v1").default("v1"),
1649
- text: zod.z.string()
1667
+ version: zod.z.literal("v1").default("v1")
1650
1668
  }),
1651
1669
  callback: zod.z.void()
1652
1670
  },
@@ -1669,6 +1687,7 @@ var ProdWorkerToCoordinatorMessages = {
1669
1687
  })
1670
1688
  ])
1671
1689
  },
1690
+ // Deprecated: Only workers without lazy attempt support will use this
1672
1691
  READY_FOR_EXECUTION: {
1673
1692
  message: zod.z.object({
1674
1693
  version: zod.z.literal("v1").default("v1"),
@@ -1755,7 +1774,10 @@ var ProdWorkerToCoordinatorMessages = {
1755
1774
  },
1756
1775
  WAIT_FOR_TASK: {
1757
1776
  message: zod.z.object({
1758
- version: zod.z.literal("v1").default("v1"),
1777
+ version: zod.z.enum([
1778
+ "v1",
1779
+ "v2"
1780
+ ]).default("v1"),
1759
1781
  friendlyId: zod.z.string(),
1760
1782
  // This is the attempt that is waiting
1761
1783
  attemptFriendlyId: zod.z.string()
@@ -1766,7 +1788,10 @@ var ProdWorkerToCoordinatorMessages = {
1766
1788
  },
1767
1789
  WAIT_FOR_BATCH: {
1768
1790
  message: zod.z.object({
1769
- version: zod.z.literal("v1").default("v1"),
1791
+ version: zod.z.enum([
1792
+ "v1",
1793
+ "v2"
1794
+ ]).default("v1"),
1770
1795
  batchFriendlyId: zod.z.string(),
1771
1796
  runFriendlyIds: zod.z.string().array(),
1772
1797
  // This is the attempt that is waiting
@@ -1813,6 +1838,12 @@ var ProdWorkerToCoordinatorMessages = {
1813
1838
  stack: zod.z.string().optional()
1814
1839
  })
1815
1840
  })
1841
+ },
1842
+ SET_STATE: {
1843
+ message: zod.z.object({
1844
+ version: zod.z.literal("v1").default("v1"),
1845
+ attemptFriendlyId: zod.z.string().optional()
1846
+ })
1816
1847
  }
1817
1848
  };
1818
1849
  var CoordinatorToProdWorkerMessages = {
@@ -1830,6 +1861,7 @@ var CoordinatorToProdWorkerMessages = {
1830
1861
  attemptId: zod.z.string()
1831
1862
  })
1832
1863
  },
1864
+ // Deprecated: Only workers without lazy attempt support will use this
1833
1865
  EXECUTE_TASK_RUN: {
1834
1866
  message: zod.z.object({
1835
1867
  version: zod.z.literal("v1").default("v1"),
@@ -1876,6 +1908,9 @@ var ProdWorkerSocketData = zod.z.object({
1876
1908
  deploymentId: zod.z.string(),
1877
1909
  deploymentVersion: zod.z.string()
1878
1910
  });
1911
+ var CoordinatorSocketData = zod.z.object({
1912
+ supportsDynamicConfig: zod.z.string().optional()
1913
+ });
1879
1914
  var PRIMARY_VARIANT = "primary";
1880
1915
  var Variant = zod.z.enum([
1881
1916
  PRIMARY_VARIANT
@@ -2152,7 +2187,10 @@ var SemanticInternalAttributes = {
2152
2187
  LINK_TITLE: "$link.title",
2153
2188
  IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
2154
2189
  USAGE_DURATION_MS: "$usage.durationMs",
2155
- USAGE_COST_IN_CENTS: "$usage.costInCents"
2190
+ USAGE_COST_IN_CENTS: "$usage.costInCents",
2191
+ RATE_LIMIT_LIMIT: "response.rateLimit.limit",
2192
+ RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
2193
+ RATE_LIMIT_RESET: "response.rateLimit.reset"
2156
2194
  };
2157
2195
 
2158
2196
  // src/v3/taskContext/index.ts
@@ -2242,10 +2280,118 @@ var TaskContextAPI = _TaskContextAPI;
2242
2280
  // src/v3/task-context-api.ts
2243
2281
  var taskContext = TaskContextAPI.getInstance();
2244
2282
 
2283
+ // src/retry.ts
2284
+ function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
2285
+ if (!resets)
2286
+ return;
2287
+ switch (format) {
2288
+ case "iso_8601_duration_openai_variant": {
2289
+ return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
2290
+ }
2291
+ case "iso_8601": {
2292
+ return calculateISO8601ResetAt(resets, now);
2293
+ }
2294
+ case "unix_timestamp": {
2295
+ return calculateUnixTimestampResetAt(resets, now);
2296
+ }
2297
+ case "unix_timestamp_in_ms": {
2298
+ return calculateUnixTimestampInMsResetAt(resets, now);
2299
+ }
2300
+ }
2301
+ }
2302
+ __name(calculateResetAt, "calculateResetAt");
2303
+ function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
2304
+ if (!resets)
2305
+ return void 0;
2306
+ const resetAt = parseInt(resets, 10);
2307
+ if (isNaN(resetAt))
2308
+ return void 0;
2309
+ return new Date(resetAt * 1e3);
2310
+ }
2311
+ __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
2312
+ function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
2313
+ if (!resets)
2314
+ return void 0;
2315
+ const resetAt = parseInt(resets, 10);
2316
+ if (isNaN(resetAt))
2317
+ return void 0;
2318
+ return new Date(resetAt);
2319
+ }
2320
+ __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
2321
+ function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
2322
+ if (!resets)
2323
+ return void 0;
2324
+ const resetAt = new Date(resets);
2325
+ if (isNaN(resetAt.getTime()))
2326
+ return void 0;
2327
+ return resetAt;
2328
+ }
2329
+ __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
2330
+ function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
2331
+ if (!resets)
2332
+ return void 0;
2333
+ const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
2334
+ const match = resets.match(pattern);
2335
+ if (!match)
2336
+ return void 0;
2337
+ const days = parseInt(match[1], 10) || 0;
2338
+ const hours = parseInt(match[2], 10) || 0;
2339
+ const minutes = parseInt(match[3], 10) || 0;
2340
+ const seconds = parseFloat(match[4]) || 0;
2341
+ const milliseconds = parseInt(match[5], 10) || 0;
2342
+ const resetAt = new Date(now);
2343
+ resetAt.setDate(resetAt.getDate() + days);
2344
+ resetAt.setHours(resetAt.getHours() + hours);
2345
+ resetAt.setMinutes(resetAt.getMinutes() + minutes);
2346
+ resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
2347
+ resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
2348
+ return resetAt;
2349
+ }
2350
+ __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
2351
+
2352
+ // src/v3/utils/retries.ts
2353
+ var defaultRetryOptions = {
2354
+ maxAttempts: 3,
2355
+ factor: 2,
2356
+ minTimeoutInMs: 1e3,
2357
+ maxTimeoutInMs: 6e4,
2358
+ randomize: true
2359
+ };
2360
+ var defaultFetchRetryOptions = {
2361
+ byStatus: {
2362
+ "429,408,409,5xx": {
2363
+ strategy: "backoff",
2364
+ ...defaultRetryOptions
2365
+ }
2366
+ },
2367
+ connectionError: defaultRetryOptions,
2368
+ timeout: defaultRetryOptions
2369
+ };
2370
+ function calculateNextRetryDelay(options, attempt) {
2371
+ const opts = {
2372
+ ...defaultRetryOptions,
2373
+ ...options
2374
+ };
2375
+ if (attempt >= opts.maxAttempts) {
2376
+ return;
2377
+ }
2378
+ const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
2379
+ const random = randomize ? Math.random() + 1 : 1;
2380
+ const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
2381
+ return Math.round(timeout);
2382
+ }
2383
+ __name(calculateNextRetryDelay, "calculateNextRetryDelay");
2384
+ function calculateResetAt2(resets, format, now = Date.now()) {
2385
+ const resetAt = calculateResetAt(resets, format, new Date(now));
2386
+ return resetAt?.getTime();
2387
+ }
2388
+ __name(calculateResetAt2, "calculateResetAt");
2389
+
2245
2390
  // src/v3/apiClient/errors.ts
2246
2391
  var _ApiError = class _ApiError extends Error {
2247
2392
  constructor(status, error, message, headers) {
2248
2393
  super(`${_ApiError.makeMessage(status, error, message)}`);
2394
+ this.name = "TriggerApiError";
2249
2395
  this.status = status;
2250
2396
  this.headers = headers;
2251
2397
  const data = error;
@@ -2366,6 +2512,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
2366
2512
  super(...arguments);
2367
2513
  __publicField(this, "status", 429);
2368
2514
  }
2515
+ get millisecondsUntilReset() {
2516
+ const resetAtUnixEpochMs = (this.headers ?? {})["x-ratelimit-reset"];
2517
+ if (typeof resetAtUnixEpochMs === "string") {
2518
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
2519
+ if (isNaN(resetAtUnixEpoch)) {
2520
+ return;
2521
+ }
2522
+ return Math.max(resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 2e3), 0);
2523
+ }
2524
+ }
2369
2525
  };
2370
2526
  __name(_RateLimitError, "RateLimitError");
2371
2527
  var RateLimitError = _RateLimitError;
@@ -2380,112 +2536,131 @@ function castToError(err) {
2380
2536
  }
2381
2537
  __name(castToError, "castToError");
2382
2538
 
2383
- // src/retry.ts
2384
- function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
2385
- if (!resets)
2386
- return;
2387
- switch (format) {
2388
- case "iso_8601_duration_openai_variant": {
2389
- return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
2390
- }
2391
- case "iso_8601": {
2392
- return calculateISO8601ResetAt(resets, now);
2393
- }
2394
- case "unix_timestamp": {
2395
- return calculateUnixTimestampResetAt(resets, now);
2396
- }
2397
- case "unix_timestamp_in_ms": {
2398
- return calculateUnixTimestampInMsResetAt(resets, now);
2539
+ // src/v3/utils/flattenAttributes.ts
2540
+ var NULL_SENTINEL = "$@null((";
2541
+ function flattenAttributes(obj, prefix) {
2542
+ const result = {};
2543
+ if (obj === void 0) {
2544
+ return result;
2545
+ }
2546
+ if (obj === null) {
2547
+ result[prefix || ""] = NULL_SENTINEL;
2548
+ return result;
2549
+ }
2550
+ if (typeof obj === "string") {
2551
+ result[prefix || ""] = obj;
2552
+ return result;
2553
+ }
2554
+ if (typeof obj === "number") {
2555
+ result[prefix || ""] = obj;
2556
+ return result;
2557
+ }
2558
+ if (typeof obj === "boolean") {
2559
+ result[prefix || ""] = obj;
2560
+ return result;
2561
+ }
2562
+ for (const [key, value] of Object.entries(obj)) {
2563
+ const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
2564
+ if (Array.isArray(value)) {
2565
+ for (let i = 0; i < value.length; i++) {
2566
+ if (typeof value[i] === "object" && value[i] !== null) {
2567
+ Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
2568
+ } else {
2569
+ if (value[i] === null) {
2570
+ result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
2571
+ } else {
2572
+ result[`${newPrefix}.[${i}]`] = value[i];
2573
+ }
2574
+ }
2575
+ }
2576
+ } else if (isRecord(value)) {
2577
+ Object.assign(result, flattenAttributes(value, newPrefix));
2578
+ } else {
2579
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
2580
+ result[newPrefix] = value;
2581
+ } else if (value === null) {
2582
+ result[newPrefix] = NULL_SENTINEL;
2583
+ }
2399
2584
  }
2400
2585
  }
2586
+ return result;
2401
2587
  }
2402
- __name(calculateResetAt, "calculateResetAt");
2403
- function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
2404
- if (!resets)
2405
- return void 0;
2406
- const resetAt = parseInt(resets, 10);
2407
- if (isNaN(resetAt))
2408
- return void 0;
2409
- return new Date(resetAt * 1e3);
2588
+ __name(flattenAttributes, "flattenAttributes");
2589
+ function isRecord(value) {
2590
+ return value !== null && typeof value === "object" && !Array.isArray(value);
2410
2591
  }
2411
- __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
2412
- function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
2413
- if (!resets)
2414
- return void 0;
2415
- const resetAt = parseInt(resets, 10);
2416
- if (isNaN(resetAt))
2417
- return void 0;
2418
- return new Date(resetAt);
2419
- }
2420
- __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
2421
- function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
2422
- if (!resets)
2423
- return void 0;
2424
- const resetAt = new Date(resets);
2425
- if (isNaN(resetAt.getTime()))
2426
- return void 0;
2427
- return resetAt;
2592
+ __name(isRecord, "isRecord");
2593
+ function unflattenAttributes(obj) {
2594
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
2595
+ return obj;
2596
+ }
2597
+ if (typeof obj === "object" && obj !== null && Object.keys(obj).length === 1 && Object.keys(obj)[0] === "") {
2598
+ return rehydrateNull(obj[""]);
2599
+ }
2600
+ if (Object.keys(obj).length === 0) {
2601
+ return;
2602
+ }
2603
+ const result = {};
2604
+ for (const [key, value] of Object.entries(obj)) {
2605
+ const parts = key.split(".").reduce((acc, part) => {
2606
+ if (part.includes("[")) {
2607
+ const subparts = part.split(/\[|\]/).filter((p) => p !== "");
2608
+ acc.push(...subparts);
2609
+ } else {
2610
+ acc.push(part);
2611
+ }
2612
+ return acc;
2613
+ }, []);
2614
+ let current = result;
2615
+ for (let i = 0; i < parts.length - 1; i++) {
2616
+ const part = parts[i];
2617
+ const nextPart = parts[i + 1];
2618
+ const isArray = /^\d+$/.test(nextPart);
2619
+ if (isArray && !Array.isArray(current[part])) {
2620
+ current[part] = [];
2621
+ } else if (!isArray && current[part] === void 0) {
2622
+ current[part] = {};
2623
+ }
2624
+ current = current[part];
2625
+ }
2626
+ const lastPart = parts[parts.length - 1];
2627
+ current[lastPart] = rehydrateNull(value);
2628
+ }
2629
+ if (Object.keys(result).every((k) => /^\d+$/.test(k))) {
2630
+ const maxIndex = Math.max(...Object.keys(result).map((k) => parseInt(k)));
2631
+ const arrayResult = Array(maxIndex + 1);
2632
+ for (const key in result) {
2633
+ arrayResult[parseInt(key)] = result[key];
2634
+ }
2635
+ return arrayResult;
2636
+ }
2637
+ return result;
2428
2638
  }
2429
- __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
2430
- function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
2431
- if (!resets)
2432
- return void 0;
2433
- const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
2434
- const match = resets.match(pattern);
2435
- if (!match)
2436
- return void 0;
2437
- const days = parseInt(match[1], 10) || 0;
2438
- const hours = parseInt(match[2], 10) || 0;
2439
- const minutes = parseInt(match[3], 10) || 0;
2440
- const seconds = parseFloat(match[4]) || 0;
2441
- const milliseconds = parseInt(match[5], 10) || 0;
2442
- const resetAt = new Date(now);
2443
- resetAt.setDate(resetAt.getDate() + days);
2444
- resetAt.setHours(resetAt.getHours() + hours);
2445
- resetAt.setMinutes(resetAt.getMinutes() + minutes);
2446
- resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
2447
- resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
2448
- return resetAt;
2639
+ __name(unflattenAttributes, "unflattenAttributes");
2640
+ function primitiveValueOrflattenedAttributes(obj, prefix) {
2641
+ if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
2642
+ return obj;
2643
+ }
2644
+ const attributes = flattenAttributes(obj, prefix);
2645
+ if (prefix !== void 0 && typeof attributes[prefix] !== "undefined" && attributes[prefix] !== null) {
2646
+ return attributes[prefix];
2647
+ }
2648
+ return attributes;
2449
2649
  }
2450
- __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
2451
-
2452
- // src/v3/utils/retries.ts
2453
- var defaultRetryOptions = {
2454
- maxAttempts: 3,
2455
- factor: 2,
2456
- minTimeoutInMs: 1e3,
2457
- maxTimeoutInMs: 6e4,
2458
- randomize: true
2459
- };
2460
- var defaultFetchRetryOptions = {
2461
- byStatus: {
2462
- "429,408,409,5xx": {
2463
- strategy: "backoff",
2464
- ...defaultRetryOptions
2465
- }
2466
- },
2467
- connectionError: defaultRetryOptions,
2468
- timeout: defaultRetryOptions
2469
- };
2470
- function calculateNextRetryDelay(options, attempt) {
2471
- const opts = {
2472
- ...defaultRetryOptions,
2473
- ...options
2474
- };
2475
- if (attempt >= opts.maxAttempts) {
2476
- return;
2650
+ __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
2651
+ function rehydrateNull(value) {
2652
+ if (value === NULL_SENTINEL) {
2653
+ return null;
2477
2654
  }
2478
- const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
2479
- const random = randomize ? Math.random() + 1 : 1;
2480
- const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
2481
- return Math.round(timeout);
2655
+ return value;
2482
2656
  }
2483
- __name(calculateNextRetryDelay, "calculateNextRetryDelay");
2484
- function calculateResetAt2(resets, format, now = Date.now()) {
2485
- const resetAt = calculateResetAt(resets, format, new Date(now));
2486
- return resetAt?.getTime();
2657
+ __name(rehydrateNull, "rehydrateNull");
2658
+
2659
+ // src/v3/utils/styleAttributes.ts
2660
+ function accessoryAttributes(accessory) {
2661
+ return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
2487
2662
  }
2488
- __name(calculateResetAt2, "calculateResetAt");
2663
+ __name(accessoryAttributes, "accessoryAttributes");
2489
2664
 
2490
2665
  // src/v3/apiClient/pagination.ts
2491
2666
  var _CursorPage = class _CursorPage {
@@ -2595,6 +2770,12 @@ var defaultRetryOptions2 = {
2595
2770
  maxTimeoutInMs: 6e4,
2596
2771
  randomize: false
2597
2772
  };
2773
+ var requestOptionsKeys = {
2774
+ retry: true
2775
+ };
2776
+ var isRequestOptions = /* @__PURE__ */ __name((obj) => {
2777
+ return typeof obj === "object" && obj !== null && !isEmptyObj(obj) && Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k));
2778
+ }, "isRequestOptions");
2598
2779
  function zodfetch(schema, url, requestInit, options) {
2599
2780
  return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
2600
2781
  }
@@ -2645,16 +2826,47 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
2645
2826
  return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
2646
2827
  }
2647
2828
  __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
2648
- async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2829
+ async function traceZodFetch(params, callback) {
2830
+ if (!params.options?.tracer) {
2831
+ return callback();
2832
+ }
2833
+ const url = new URL(params.url);
2834
+ const method = params.requestInit?.method ?? "GET";
2835
+ const name = params.options.name ?? `${method} ${url.pathname}`;
2836
+ return await params.options.tracer.startActiveSpan(name, async (span) => {
2837
+ return await callback(span);
2838
+ }, {
2839
+ attributes: {
2840
+ [SemanticInternalAttributes.STYLE_ICON]: params.options?.icon ?? "api",
2841
+ ...params.options.attributes
2842
+ }
2843
+ });
2844
+ }
2845
+ __name(traceZodFetch, "traceZodFetch");
2846
+ async function _doZodFetch(schema, url, requestInit, options) {
2847
+ const $requestInit = await requestInit;
2848
+ return traceZodFetch({
2849
+ url,
2850
+ requestInit: $requestInit,
2851
+ options
2852
+ }, async (span) => {
2853
+ const result = await _doZodFetchWithRetries(schema, url, $requestInit, options);
2854
+ if (options?.onResponseBody && span) {
2855
+ options.onResponseBody(result.data, span);
2856
+ }
2857
+ return result;
2858
+ });
2859
+ }
2860
+ __name(_doZodFetch, "_doZodFetch");
2861
+ async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
2649
2862
  try {
2650
- const $requestInit = await requestInit;
2651
- const response = await fetch(url, requestInitWithCache($requestInit));
2863
+ const response = await fetch(url, requestInitWithCache(requestInit));
2652
2864
  const responseHeaders = createResponseHeaders(response.headers);
2653
2865
  if (!response.ok) {
2654
2866
  const retryResult = shouldRetry(response, attempt, options?.retry);
2655
2867
  if (retryResult.retry) {
2656
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
2657
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2868
+ await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
2869
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
2658
2870
  } else {
2659
2871
  const errText = await response.text().catch((e) => castToError2(e).message);
2660
2872
  const errJSON = safeJsonParse(errText);
@@ -2682,8 +2894,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2682
2894
  };
2683
2895
  const delay = calculateNextRetryDelay(retry, attempt);
2684
2896
  if (delay) {
2685
- await new Promise((resolve) => setTimeout(resolve, delay));
2686
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2897
+ await waitForRetry(url, attempt + 1, delay, options, requestInit);
2898
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
2687
2899
  }
2688
2900
  }
2689
2901
  throw new ApiConnectionError({
@@ -2691,7 +2903,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2691
2903
  });
2692
2904
  }
2693
2905
  }
2694
- __name(_doZodFetch, "_doZodFetch");
2906
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
2695
2907
  function castToError2(err) {
2696
2908
  if (err instanceof Error)
2697
2909
  return err;
@@ -2728,8 +2940,25 @@ function shouldRetry(response, attempt, retryOptions) {
2728
2940
  return shouldRetryForOptions();
2729
2941
  if (response.status === 409)
2730
2942
  return shouldRetryForOptions();
2731
- if (response.status === 429)
2943
+ if (response.status === 429) {
2944
+ if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
2945
+ return {
2946
+ retry: false
2947
+ };
2948
+ }
2949
+ const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
2950
+ if (resetAtUnixEpochMs) {
2951
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
2952
+ const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
2953
+ if (delay > 0) {
2954
+ return {
2955
+ retry: true,
2956
+ delay
2957
+ };
2958
+ }
2959
+ }
2732
2960
  return shouldRetryForOptions();
2961
+ }
2733
2962
  if (response.status >= 500)
2734
2963
  return shouldRetryForOptions();
2735
2964
  return {
@@ -2892,9 +3121,44 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
2892
3121
  }, "#fetchPage");
2893
3122
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
2894
3123
  var OffsetLimitPagePromise = _OffsetLimitPagePromise;
3124
+ async function waitForRetry(url, attempt, delay, options, requestInit, response) {
3125
+ if (options?.tracer) {
3126
+ const method = requestInit?.method ?? "GET";
3127
+ return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
3128
+ await new Promise((resolve) => setTimeout(resolve, delay));
3129
+ }, {
3130
+ attributes: {
3131
+ [SemanticInternalAttributes.STYLE_ICON]: "wait",
3132
+ ...accessoryAttributes({
3133
+ items: [
3134
+ {
3135
+ text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
3136
+ variant: "normal"
3137
+ }
3138
+ ],
3139
+ style: "codepath"
3140
+ })
3141
+ }
3142
+ });
3143
+ }
3144
+ await new Promise((resolve) => setTimeout(resolve, delay));
3145
+ }
3146
+ __name(waitForRetry, "waitForRetry");
3147
+ function isEmptyObj(obj) {
3148
+ if (!obj)
3149
+ return true;
3150
+ for (const _k in obj)
3151
+ return false;
3152
+ return true;
3153
+ }
3154
+ __name(isEmptyObj, "isEmptyObj");
3155
+ function hasOwn(obj, key) {
3156
+ return Object.prototype.hasOwnProperty.call(obj, key);
3157
+ }
3158
+ __name(hasOwn, "hasOwn");
2895
3159
 
2896
3160
  // src/v3/apiClient/index.ts
2897
- var zodFetchOptions = {
3161
+ var DEFAULT_ZOD_FETCH_OPTIONS = {
2898
3162
  retry: {
2899
3163
  maxAttempts: 3,
2900
3164
  minTimeoutInMs: 1e3,
@@ -2905,17 +3169,18 @@ var zodFetchOptions = {
2905
3169
  };
2906
3170
  var _getHeaders, getHeaders_fn;
2907
3171
  var _ApiClient = class _ApiClient {
2908
- constructor(baseUrl, accessToken) {
3172
+ constructor(baseUrl, accessToken, requestOptions = {}) {
2909
3173
  __privateAdd(this, _getHeaders);
2910
3174
  this.accessToken = accessToken;
2911
3175
  this.baseUrl = baseUrl.replace(/\/$/, "");
3176
+ this.defaultRequestOptions = mergeRequestOptions(DEFAULT_ZOD_FETCH_OPTIONS, requestOptions);
2912
3177
  }
2913
- async getRunResult(runId) {
3178
+ async getRunResult(runId, requestOptions) {
2914
3179
  try {
2915
3180
  return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
2916
3181
  method: "GET",
2917
3182
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2918
- }, zodFetchOptions);
3183
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2919
3184
  } catch (error) {
2920
3185
  if (error instanceof ApiError) {
2921
3186
  if (error.status === 404) {
@@ -2925,47 +3190,47 @@ var _ApiClient = class _ApiClient {
2925
3190
  throw error;
2926
3191
  }
2927
3192
  }
2928
- async getBatchResults(batchId) {
3193
+ async getBatchResults(batchId, requestOptions) {
2929
3194
  return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
2930
3195
  method: "GET",
2931
3196
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2932
- }, zodFetchOptions);
3197
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2933
3198
  }
2934
- triggerTask(taskId, body, options) {
3199
+ triggerTask(taskId, body, options, requestOptions) {
2935
3200
  const encodedTaskId = encodeURIComponent(taskId);
2936
3201
  return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
2937
3202
  method: "POST",
2938
3203
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2939
3204
  body: JSON.stringify(body)
2940
- }, zodFetchOptions);
3205
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2941
3206
  }
2942
- batchTriggerTask(taskId, body, options) {
3207
+ batchTriggerTask(taskId, body, options, requestOptions) {
2943
3208
  const encodedTaskId = encodeURIComponent(taskId);
2944
3209
  return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
2945
3210
  method: "POST",
2946
3211
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2947
3212
  body: JSON.stringify(body)
2948
- }, zodFetchOptions);
3213
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2949
3214
  }
2950
- createUploadPayloadUrl(filename) {
3215
+ createUploadPayloadUrl(filename, requestOptions) {
2951
3216
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2952
3217
  method: "PUT",
2953
3218
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2954
- }, zodFetchOptions);
3219
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2955
3220
  }
2956
- getPayloadUrl(filename) {
3221
+ getPayloadUrl(filename, requestOptions) {
2957
3222
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2958
3223
  method: "GET",
2959
3224
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2960
- }, zodFetchOptions);
3225
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2961
3226
  }
2962
- retrieveRun(runId) {
3227
+ retrieveRun(runId, requestOptions) {
2963
3228
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v3/runs/${runId}`, {
2964
3229
  method: "GET",
2965
3230
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2966
- }, zodFetchOptions);
3231
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2967
3232
  }
2968
- listRuns(query) {
3233
+ listRuns(query, requestOptions) {
2969
3234
  const searchParams = createSearchQueryForListRuns(query);
2970
3235
  return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
2971
3236
  query: searchParams,
@@ -2975,9 +3240,9 @@ var _ApiClient = class _ApiClient {
2975
3240
  }, {
2976
3241
  method: "GET",
2977
3242
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2978
- }, zodFetchOptions);
3243
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2979
3244
  }
2980
- listProjectRuns(projectRef, query) {
3245
+ listProjectRuns(projectRef, query, requestOptions) {
2981
3246
  const searchParams = createSearchQueryForListRuns(query);
2982
3247
  if (query?.env) {
2983
3248
  searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
@@ -2990,35 +3255,35 @@ var _ApiClient = class _ApiClient {
2990
3255
  }, {
2991
3256
  method: "GET",
2992
3257
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2993
- }, zodFetchOptions);
3258
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2994
3259
  }
2995
- replayRun(runId) {
3260
+ replayRun(runId, requestOptions) {
2996
3261
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
2997
3262
  method: "POST",
2998
3263
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2999
- }, zodFetchOptions);
3264
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3000
3265
  }
3001
- cancelRun(runId) {
3266
+ cancelRun(runId, requestOptions) {
3002
3267
  return zodfetch(CanceledRunResponse, `${this.baseUrl}/api/v2/runs/${runId}/cancel`, {
3003
3268
  method: "POST",
3004
3269
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3005
- }, zodFetchOptions);
3270
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3006
3271
  }
3007
- rescheduleRun(runId, body) {
3272
+ rescheduleRun(runId, body, requestOptions) {
3008
3273
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/reschedule`, {
3009
3274
  method: "POST",
3010
3275
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3011
3276
  body: JSON.stringify(body)
3012
- }, zodFetchOptions);
3277
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3013
3278
  }
3014
- createSchedule(options) {
3279
+ createSchedule(options, requestOptions) {
3015
3280
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
3016
3281
  method: "POST",
3017
3282
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3018
3283
  body: JSON.stringify(options)
3019
- });
3284
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3020
3285
  }
3021
- listSchedules(options) {
3286
+ listSchedules(options, requestOptions) {
3022
3287
  const searchParams = new URLSearchParams();
3023
3288
  if (options?.page) {
3024
3289
  searchParams.append("page", options.page.toString());
@@ -3032,77 +3297,77 @@ var _ApiClient = class _ApiClient {
3032
3297
  }, {
3033
3298
  method: "GET",
3034
3299
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3035
- });
3300
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3036
3301
  }
3037
- retrieveSchedule(scheduleId) {
3302
+ retrieveSchedule(scheduleId, requestOptions) {
3038
3303
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3039
3304
  method: "GET",
3040
3305
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3041
- });
3306
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3042
3307
  }
3043
- updateSchedule(scheduleId, options) {
3308
+ updateSchedule(scheduleId, options, requestOptions) {
3044
3309
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3045
3310
  method: "PUT",
3046
3311
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3047
3312
  body: JSON.stringify(options)
3048
- });
3313
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3049
3314
  }
3050
- deactivateSchedule(scheduleId) {
3315
+ deactivateSchedule(scheduleId, requestOptions) {
3051
3316
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/deactivate`, {
3052
3317
  method: "POST",
3053
3318
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3054
- });
3319
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3055
3320
  }
3056
- activateSchedule(scheduleId) {
3321
+ activateSchedule(scheduleId, requestOptions) {
3057
3322
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/activate`, {
3058
3323
  method: "POST",
3059
3324
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3060
- });
3325
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3061
3326
  }
3062
- deleteSchedule(scheduleId) {
3327
+ deleteSchedule(scheduleId, requestOptions) {
3063
3328
  return zodfetch(DeletedScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3064
3329
  method: "DELETE",
3065
3330
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3066
- });
3331
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3067
3332
  }
3068
- listEnvVars(projectRef, slug) {
3333
+ listEnvVars(projectRef, slug, requestOptions) {
3069
3334
  return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3070
3335
  method: "GET",
3071
3336
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3072
- });
3337
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3073
3338
  }
3074
- importEnvVars(projectRef, slug, body) {
3339
+ importEnvVars(projectRef, slug, body, requestOptions) {
3075
3340
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
3076
3341
  method: "POST",
3077
3342
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3078
3343
  body: JSON.stringify(body)
3079
- });
3344
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3080
3345
  }
3081
- retrieveEnvVar(projectRef, slug, key) {
3346
+ retrieveEnvVar(projectRef, slug, key, requestOptions) {
3082
3347
  return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3083
3348
  method: "GET",
3084
3349
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3085
- });
3350
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3086
3351
  }
3087
- createEnvVar(projectRef, slug, body) {
3352
+ createEnvVar(projectRef, slug, body, requestOptions) {
3088
3353
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3089
3354
  method: "POST",
3090
3355
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3091
3356
  body: JSON.stringify(body)
3092
- });
3357
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3093
3358
  }
3094
- updateEnvVar(projectRef, slug, key, body) {
3359
+ updateEnvVar(projectRef, slug, key, body, requestOptions) {
3095
3360
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3096
3361
  method: "PUT",
3097
3362
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3098
3363
  body: JSON.stringify(body)
3099
- });
3364
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3100
3365
  }
3101
- deleteEnvVar(projectRef, slug, key) {
3366
+ deleteEnvVar(projectRef, slug, key, requestOptions) {
3102
3367
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3103
3368
  method: "DELETE",
3104
3369
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3105
- });
3370
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3106
3371
  }
3107
3372
  };
3108
3373
  _getHeaders = new WeakSet();
@@ -3157,6 +3422,20 @@ function createSearchQueryForListRuns(query) {
3157
3422
  return searchParams;
3158
3423
  }
3159
3424
  __name(createSearchQueryForListRuns, "createSearchQueryForListRuns");
3425
+ function mergeRequestOptions(defaultOptions, options) {
3426
+ if (!options) {
3427
+ return defaultOptions;
3428
+ }
3429
+ return {
3430
+ ...defaultOptions,
3431
+ ...options,
3432
+ retry: {
3433
+ ...defaultOptions.retry,
3434
+ ...options.retry
3435
+ }
3436
+ };
3437
+ }
3438
+ __name(mergeRequestOptions, "mergeRequestOptions");
3160
3439
  var _SimpleClock = class _SimpleClock {
3161
3440
  preciseNow() {
3162
3441
  const now = new preciseDate.PreciseDate();
@@ -3249,128 +3528,6 @@ function calculateAttributeValueLength(value) {
3249
3528
  return 0;
3250
3529
  }
3251
3530
  __name(calculateAttributeValueLength, "calculateAttributeValueLength");
3252
-
3253
- // src/v3/utils/flattenAttributes.ts
3254
- var NULL_SENTINEL = "$@null((";
3255
- function flattenAttributes(obj, prefix) {
3256
- const result = {};
3257
- if (obj === void 0) {
3258
- return result;
3259
- }
3260
- if (obj === null) {
3261
- result[prefix || ""] = NULL_SENTINEL;
3262
- return result;
3263
- }
3264
- if (typeof obj === "string") {
3265
- result[prefix || ""] = obj;
3266
- return result;
3267
- }
3268
- if (typeof obj === "number") {
3269
- result[prefix || ""] = obj;
3270
- return result;
3271
- }
3272
- if (typeof obj === "boolean") {
3273
- result[prefix || ""] = obj;
3274
- return result;
3275
- }
3276
- for (const [key, value] of Object.entries(obj)) {
3277
- const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
3278
- if (Array.isArray(value)) {
3279
- for (let i = 0; i < value.length; i++) {
3280
- if (typeof value[i] === "object" && value[i] !== null) {
3281
- Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
3282
- } else {
3283
- if (value[i] === null) {
3284
- result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
3285
- } else {
3286
- result[`${newPrefix}.[${i}]`] = value[i];
3287
- }
3288
- }
3289
- }
3290
- } else if (isRecord(value)) {
3291
- Object.assign(result, flattenAttributes(value, newPrefix));
3292
- } else {
3293
- if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
3294
- result[newPrefix] = value;
3295
- } else if (value === null) {
3296
- result[newPrefix] = NULL_SENTINEL;
3297
- }
3298
- }
3299
- }
3300
- return result;
3301
- }
3302
- __name(flattenAttributes, "flattenAttributes");
3303
- function isRecord(value) {
3304
- return value !== null && typeof value === "object" && !Array.isArray(value);
3305
- }
3306
- __name(isRecord, "isRecord");
3307
- function unflattenAttributes(obj) {
3308
- if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
3309
- return obj;
3310
- }
3311
- if (typeof obj === "object" && obj !== null && Object.keys(obj).length === 1 && Object.keys(obj)[0] === "") {
3312
- return rehydrateNull(obj[""]);
3313
- }
3314
- if (Object.keys(obj).length === 0) {
3315
- return;
3316
- }
3317
- const result = {};
3318
- for (const [key, value] of Object.entries(obj)) {
3319
- const parts = key.split(".").reduce((acc, part) => {
3320
- if (part.includes("[")) {
3321
- const subparts = part.split(/\[|\]/).filter((p) => p !== "");
3322
- acc.push(...subparts);
3323
- } else {
3324
- acc.push(part);
3325
- }
3326
- return acc;
3327
- }, []);
3328
- let current = result;
3329
- for (let i = 0; i < parts.length - 1; i++) {
3330
- const part = parts[i];
3331
- const nextPart = parts[i + 1];
3332
- const isArray = /^\d+$/.test(nextPart);
3333
- if (isArray && !Array.isArray(current[part])) {
3334
- current[part] = [];
3335
- } else if (!isArray && current[part] === void 0) {
3336
- current[part] = {};
3337
- }
3338
- current = current[part];
3339
- }
3340
- const lastPart = parts[parts.length - 1];
3341
- current[lastPart] = rehydrateNull(value);
3342
- }
3343
- if (Object.keys(result).every((k) => /^\d+$/.test(k))) {
3344
- const maxIndex = Math.max(...Object.keys(result).map((k) => parseInt(k)));
3345
- const arrayResult = Array(maxIndex + 1);
3346
- for (const key in result) {
3347
- arrayResult[parseInt(key)] = result[key];
3348
- }
3349
- return arrayResult;
3350
- }
3351
- return result;
3352
- }
3353
- __name(unflattenAttributes, "unflattenAttributes");
3354
- function primitiveValueOrflattenedAttributes(obj, prefix) {
3355
- if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
3356
- return obj;
3357
- }
3358
- const attributes = flattenAttributes(obj, prefix);
3359
- if (prefix !== void 0 && typeof attributes[prefix] !== "undefined" && attributes[prefix] !== null) {
3360
- return attributes[prefix];
3361
- }
3362
- return attributes;
3363
- }
3364
- __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
3365
- function rehydrateNull(value) {
3366
- if (value === NULL_SENTINEL) {
3367
- return null;
3368
- }
3369
- return value;
3370
- }
3371
- __name(rehydrateNull, "rehydrateNull");
3372
-
3373
- // src/v3/logger/taskLogger.ts
3374
3531
  var _NoopTaskLogger = class _NoopTaskLogger {
3375
3532
  debug() {
3376
3533
  }
@@ -3815,14 +3972,16 @@ var _TriggerTracer = class _TriggerTracer {
3815
3972
  attributes,
3816
3973
  startTime: clock.preciseNow()
3817
3974
  }, parentContext, async (span) => {
3818
- this.tracer.startSpan(name, {
3819
- ...options,
3820
- attributes: {
3821
- ...attributes,
3822
- [SemanticInternalAttributes.SPAN_PARTIAL]: true,
3823
- [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3824
- }
3825
- }, parentContext).end();
3975
+ if (taskContext.ctx) {
3976
+ this.tracer.startSpan(name, {
3977
+ ...options,
3978
+ attributes: {
3979
+ ...attributes,
3980
+ [SemanticInternalAttributes.SPAN_PARTIAL]: true,
3981
+ [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3982
+ }
3983
+ }, parentContext).end();
3984
+ }
3826
3985
  const usageMeasurement = usage.start();
3827
3986
  try {
3828
3987
  return await fn(span);
@@ -3835,12 +3994,14 @@ var _TriggerTracer = class _TriggerTracer {
3835
3994
  });
3836
3995
  throw e;
3837
3996
  } finally {
3838
- const usageSample = usage.stop(usageMeasurement);
3839
- const machine = taskContext.ctx?.machine;
3840
- span.setAttributes({
3841
- [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
3842
- [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
3843
- });
3997
+ if (taskContext.ctx) {
3998
+ const usageSample = usage.stop(usageMeasurement);
3999
+ const machine = taskContext.ctx.machine;
4000
+ span.setAttributes({
4001
+ [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
4002
+ [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
4003
+ });
4004
+ }
3844
4005
  span.end(clock.preciseNow());
3845
4006
  }
3846
4007
  });
@@ -4032,12 +4193,6 @@ function omit(obj, ...keys) {
4032
4193
  }
4033
4194
  __name(omit, "omit");
4034
4195
 
4035
- // src/v3/utils/styleAttributes.ts
4036
- function accessoryAttributes(accessory) {
4037
- return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
4038
- }
4039
- __name(accessoryAttributes, "accessoryAttributes");
4040
-
4041
4196
  // src/v3/utils/detectDependencyVersion.ts
4042
4197
  function detectDependencyVersion(dependency) {
4043
4198
  return dependencies[dependency];
@@ -4313,6 +4468,7 @@ function safeJsonParse2(value) {
4313
4468
  }
4314
4469
  __name(safeJsonParse2, "safeJsonParse");
4315
4470
 
4471
+ exports.AbortTaskRunError = AbortTaskRunError;
4316
4472
  exports.ApiClient = ApiClient;
4317
4473
  exports.ApiConnectionError = ApiConnectionError;
4318
4474
  exports.ApiError = ApiError;
@@ -4331,6 +4487,7 @@ exports.CancellationSpanEvent = CancellationSpanEvent;
4331
4487
  exports.ClientToSharedQueueMessages = ClientToSharedQueueMessages;
4332
4488
  exports.Config = Config;
4333
4489
  exports.ConflictError = ConflictError;
4490
+ exports.CoordinatorSocketData = CoordinatorSocketData;
4334
4491
  exports.CoordinatorToPlatformMessages = CoordinatorToPlatformMessages;
4335
4492
  exports.CoordinatorToProdWorkerMessages = CoordinatorToProdWorkerMessages;
4336
4493
  exports.CreateAuthorizationCodeResponseSchema = CreateAuthorizationCodeResponseSchema;
@@ -4494,7 +4651,9 @@ exports.groupTaskMetadataIssuesByTask = groupTaskMetadataIssuesByTask;
4494
4651
  exports.imposeAttributeLimits = imposeAttributeLimits;
4495
4652
  exports.isCancellationSpanEvent = isCancellationSpanEvent;
4496
4653
  exports.isExceptionSpanEvent = isExceptionSpanEvent;
4654
+ exports.isRequestOptions = isRequestOptions;
4497
4655
  exports.logger = logger;
4656
+ exports.mergeRequestOptions = mergeRequestOptions;
4498
4657
  exports.millisecondsToNanoseconds = millisecondsToNanoseconds;
4499
4658
  exports.nanosecondsToMilliseconds = nanosecondsToMilliseconds;
4500
4659
  exports.omit = omit;
@@ -4504,6 +4663,7 @@ exports.parsePacket = parsePacket;
4504
4663
  exports.prettyPrintPacket = prettyPrintPacket;
4505
4664
  exports.primitiveValueOrflattenedAttributes = primitiveValueOrflattenedAttributes;
4506
4665
  exports.runtime = runtime;
4666
+ exports.sanitizeError = sanitizeError;
4507
4667
  exports.serverWebsocketMessages = serverWebsocketMessages;
4508
4668
  exports.stringPatternMatchers = stringPatternMatchers;
4509
4669
  exports.stringifyIO = stringifyIO;