@trigger.dev/core 3.0.0-beta.46 → 3.0.0-beta.48

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 (45) hide show
  1. package/dist/{catalog-9G8AqnI9.d.ts → catalog-N-X0Te3W.d.mts} +5 -23
  2. package/dist/{catalog-Y0mRLMtJ.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-nXkzt5CT.d.mts → messages-Sggr4tid.d.mts} +162 -0
  8. package/dist/{messages-nXkzt5CT.d.ts → messages-Sggr4tid.d.ts} +162 -0
  9. package/dist/{schemas-CeAee_C2.d.mts → schemas-Zy7mGFgD.d.mts} +19 -0
  10. package/dist/{schemas-CeAee_C2.d.ts → schemas-Zy7mGFgD.d.ts} +19 -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/index.d.mts +50 -38
  16. package/dist/v3/index.d.ts +50 -38
  17. package/dist/v3/index.js +470 -303
  18. package/dist/v3/index.js.map +1 -1
  19. package/dist/v3/index.mjs +467 -304
  20. package/dist/v3/index.mjs.map +1 -1
  21. package/dist/v3/otel/index.js +15 -5
  22. package/dist/v3/otel/index.js.map +1 -1
  23. package/dist/v3/otel/index.mjs +15 -5
  24. package/dist/v3/otel/index.mjs.map +1 -1
  25. package/dist/v3/prod/index.d.mts +3 -3
  26. package/dist/v3/prod/index.d.ts +3 -3
  27. package/dist/v3/schemas/index.d.mts +16 -4
  28. package/dist/v3/schemas/index.d.ts +16 -4
  29. package/dist/v3/schemas/index.js +3 -1
  30. package/dist/v3/schemas/index.js.map +1 -1
  31. package/dist/v3/schemas/index.mjs +3 -1
  32. package/dist/v3/schemas/index.mjs.map +1 -1
  33. package/dist/v3/workers/index.d.mts +7 -6
  34. package/dist/v3/workers/index.d.ts +7 -6
  35. package/dist/v3/workers/index.js +250 -96
  36. package/dist/v3/workers/index.js.map +1 -1
  37. package/dist/v3/workers/index.mjs +250 -96
  38. package/dist/v3/workers/index.mjs.map +1 -1
  39. package/dist/v3/zodfetch.d.mts +15 -2
  40. package/dist/v3/zodfetch.d.ts +15 -2
  41. package/dist/v3/zodfetch.js +248 -28
  42. package/dist/v3/zodfetch.js.map +1 -1
  43. package/dist/v3/zodfetch.mjs +246 -29
  44. package/dist/v3/zodfetch.mjs.map +1 -1
  45. package/package.json +1 -1
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.46";
36
+ var version = "3.0.0-beta.48";
37
37
  var dependencies = {
38
38
  "@google-cloud/precise-date": "^4.0.0",
39
39
  "@opentelemetry/api": "^1.8.0",
@@ -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)
@@ -485,6 +486,14 @@ var ImageDetailsMetadata = zod.z.object({
485
486
  contentHash: zod.z.string(),
486
487
  imageTag: zod.z.string()
487
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;
488
497
  function parseError(error) {
489
498
  if (error instanceof Error) {
490
499
  return {
@@ -565,6 +574,39 @@ function createJsonErrorObject(error) {
565
574
  }
566
575
  }
567
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");
568
610
  function correctErrorStackTrace(stackTrace, projectDir, options) {
569
611
  const [errorLine, ...traceLines] = stackTrace.split("\n");
570
612
  return [
@@ -680,7 +722,8 @@ var TriggerTaskRequestBody = zod.z.object({
680
722
  test: zod.z.boolean().optional(),
681
723
  payloadType: zod.z.string().optional(),
682
724
  delay: zod.z.string().or(zod.z.coerce.date()).optional(),
683
- 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()
684
727
  }).optional()
685
728
  });
686
729
  var TriggerTaskResponse = zod.z.object({
@@ -2144,7 +2187,10 @@ var SemanticInternalAttributes = {
2144
2187
  LINK_TITLE: "$link.title",
2145
2188
  IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
2146
2189
  USAGE_DURATION_MS: "$usage.durationMs",
2147
- 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"
2148
2194
  };
2149
2195
 
2150
2196
  // src/v3/taskContext/index.ts
@@ -2234,10 +2280,118 @@ var TaskContextAPI = _TaskContextAPI;
2234
2280
  // src/v3/task-context-api.ts
2235
2281
  var taskContext = TaskContextAPI.getInstance();
2236
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
+
2237
2390
  // src/v3/apiClient/errors.ts
2238
2391
  var _ApiError = class _ApiError extends Error {
2239
2392
  constructor(status, error, message, headers) {
2240
2393
  super(`${_ApiError.makeMessage(status, error, message)}`);
2394
+ this.name = "TriggerApiError";
2241
2395
  this.status = status;
2242
2396
  this.headers = headers;
2243
2397
  const data = error;
@@ -2358,6 +2512,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
2358
2512
  super(...arguments);
2359
2513
  __publicField(this, "status", 429);
2360
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
+ }
2361
2525
  };
2362
2526
  __name(_RateLimitError, "RateLimitError");
2363
2527
  var RateLimitError = _RateLimitError;
@@ -2372,112 +2536,131 @@ function castToError(err) {
2372
2536
  }
2373
2537
  __name(castToError, "castToError");
2374
2538
 
2375
- // src/retry.ts
2376
- function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
2377
- if (!resets)
2378
- return;
2379
- switch (format) {
2380
- case "iso_8601_duration_openai_variant": {
2381
- return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
2382
- }
2383
- case "iso_8601": {
2384
- return calculateISO8601ResetAt(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
+ }
2385
2584
  }
2386
- case "unix_timestamp": {
2387
- return calculateUnixTimestampResetAt(resets, now);
2585
+ }
2586
+ return result;
2587
+ }
2588
+ __name(flattenAttributes, "flattenAttributes");
2589
+ function isRecord(value) {
2590
+ return value !== null && typeof value === "object" && !Array.isArray(value);
2591
+ }
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];
2388
2625
  }
2389
- case "unix_timestamp_in_ms": {
2390
- return calculateUnixTimestampInMsResetAt(resets, now);
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];
2391
2634
  }
2635
+ return arrayResult;
2392
2636
  }
2637
+ return result;
2393
2638
  }
2394
- __name(calculateResetAt, "calculateResetAt");
2395
- function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
2396
- if (!resets)
2397
- return void 0;
2398
- const resetAt = parseInt(resets, 10);
2399
- if (isNaN(resetAt))
2400
- return void 0;
2401
- return new Date(resetAt * 1e3);
2402
- }
2403
- __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
2404
- function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
2405
- if (!resets)
2406
- return void 0;
2407
- const resetAt = parseInt(resets, 10);
2408
- if (isNaN(resetAt))
2409
- return void 0;
2410
- return new Date(resetAt);
2411
- }
2412
- __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
2413
- function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
2414
- if (!resets)
2415
- return void 0;
2416
- const resetAt = new Date(resets);
2417
- if (isNaN(resetAt.getTime()))
2418
- return void 0;
2419
- return resetAt;
2420
- }
2421
- __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
2422
- function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
2423
- if (!resets)
2424
- return void 0;
2425
- const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
2426
- const match = resets.match(pattern);
2427
- if (!match)
2428
- return void 0;
2429
- const days = parseInt(match[1], 10) || 0;
2430
- const hours = parseInt(match[2], 10) || 0;
2431
- const minutes = parseInt(match[3], 10) || 0;
2432
- const seconds = parseFloat(match[4]) || 0;
2433
- const milliseconds = parseInt(match[5], 10) || 0;
2434
- const resetAt = new Date(now);
2435
- resetAt.setDate(resetAt.getDate() + days);
2436
- resetAt.setHours(resetAt.getHours() + hours);
2437
- resetAt.setMinutes(resetAt.getMinutes() + minutes);
2438
- resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
2439
- resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
2440
- 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;
2441
2649
  }
2442
- __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
2443
-
2444
- // src/v3/utils/retries.ts
2445
- var defaultRetryOptions = {
2446
- maxAttempts: 3,
2447
- factor: 2,
2448
- minTimeoutInMs: 1e3,
2449
- maxTimeoutInMs: 6e4,
2450
- randomize: true
2451
- };
2452
- var defaultFetchRetryOptions = {
2453
- byStatus: {
2454
- "429,408,409,5xx": {
2455
- strategy: "backoff",
2456
- ...defaultRetryOptions
2457
- }
2458
- },
2459
- connectionError: defaultRetryOptions,
2460
- timeout: defaultRetryOptions
2461
- };
2462
- function calculateNextRetryDelay(options, attempt) {
2463
- const opts = {
2464
- ...defaultRetryOptions,
2465
- ...options
2466
- };
2467
- if (attempt >= opts.maxAttempts) {
2468
- return;
2650
+ __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
2651
+ function rehydrateNull(value) {
2652
+ if (value === NULL_SENTINEL) {
2653
+ return null;
2469
2654
  }
2470
- const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
2471
- const random = randomize ? Math.random() + 1 : 1;
2472
- const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
2473
- return Math.round(timeout);
2655
+ return value;
2474
2656
  }
2475
- __name(calculateNextRetryDelay, "calculateNextRetryDelay");
2476
- function calculateResetAt2(resets, format, now = Date.now()) {
2477
- const resetAt = calculateResetAt(resets, format, new Date(now));
2478
- 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);
2479
2662
  }
2480
- __name(calculateResetAt2, "calculateResetAt");
2663
+ __name(accessoryAttributes, "accessoryAttributes");
2481
2664
 
2482
2665
  // src/v3/apiClient/pagination.ts
2483
2666
  var _CursorPage = class _CursorPage {
@@ -2587,6 +2770,12 @@ var defaultRetryOptions2 = {
2587
2770
  maxTimeoutInMs: 6e4,
2588
2771
  randomize: false
2589
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");
2590
2779
  function zodfetch(schema, url, requestInit, options) {
2591
2780
  return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
2592
2781
  }
@@ -2637,16 +2826,47 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
2637
2826
  return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
2638
2827
  }
2639
2828
  __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
2640
- 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) {
2641
2862
  try {
2642
- const $requestInit = await requestInit;
2643
- const response = await fetch(url, requestInitWithCache($requestInit));
2863
+ const response = await fetch(url, requestInitWithCache(requestInit));
2644
2864
  const responseHeaders = createResponseHeaders(response.headers);
2645
2865
  if (!response.ok) {
2646
2866
  const retryResult = shouldRetry(response, attempt, options?.retry);
2647
2867
  if (retryResult.retry) {
2648
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
2649
- 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);
2650
2870
  } else {
2651
2871
  const errText = await response.text().catch((e) => castToError2(e).message);
2652
2872
  const errJSON = safeJsonParse(errText);
@@ -2674,8 +2894,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2674
2894
  };
2675
2895
  const delay = calculateNextRetryDelay(retry, attempt);
2676
2896
  if (delay) {
2677
- await new Promise((resolve) => setTimeout(resolve, delay));
2678
- 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);
2679
2899
  }
2680
2900
  }
2681
2901
  throw new ApiConnectionError({
@@ -2683,7 +2903,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2683
2903
  });
2684
2904
  }
2685
2905
  }
2686
- __name(_doZodFetch, "_doZodFetch");
2906
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
2687
2907
  function castToError2(err) {
2688
2908
  if (err instanceof Error)
2689
2909
  return err;
@@ -2720,8 +2940,25 @@ function shouldRetry(response, attempt, retryOptions) {
2720
2940
  return shouldRetryForOptions();
2721
2941
  if (response.status === 409)
2722
2942
  return shouldRetryForOptions();
2723
- 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
+ }
2724
2960
  return shouldRetryForOptions();
2961
+ }
2725
2962
  if (response.status >= 500)
2726
2963
  return shouldRetryForOptions();
2727
2964
  return {
@@ -2884,9 +3121,44 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
2884
3121
  }, "#fetchPage");
2885
3122
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
2886
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");
2887
3159
 
2888
3160
  // src/v3/apiClient/index.ts
2889
- var zodFetchOptions = {
3161
+ var DEFAULT_ZOD_FETCH_OPTIONS = {
2890
3162
  retry: {
2891
3163
  maxAttempts: 3,
2892
3164
  minTimeoutInMs: 1e3,
@@ -2897,17 +3169,18 @@ var zodFetchOptions = {
2897
3169
  };
2898
3170
  var _getHeaders, getHeaders_fn;
2899
3171
  var _ApiClient = class _ApiClient {
2900
- constructor(baseUrl, accessToken) {
3172
+ constructor(baseUrl, accessToken, requestOptions = {}) {
2901
3173
  __privateAdd(this, _getHeaders);
2902
3174
  this.accessToken = accessToken;
2903
3175
  this.baseUrl = baseUrl.replace(/\/$/, "");
3176
+ this.defaultRequestOptions = mergeRequestOptions(DEFAULT_ZOD_FETCH_OPTIONS, requestOptions);
2904
3177
  }
2905
- async getRunResult(runId) {
3178
+ async getRunResult(runId, requestOptions) {
2906
3179
  try {
2907
3180
  return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
2908
3181
  method: "GET",
2909
3182
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2910
- }, zodFetchOptions);
3183
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2911
3184
  } catch (error) {
2912
3185
  if (error instanceof ApiError) {
2913
3186
  if (error.status === 404) {
@@ -2917,47 +3190,47 @@ var _ApiClient = class _ApiClient {
2917
3190
  throw error;
2918
3191
  }
2919
3192
  }
2920
- async getBatchResults(batchId) {
3193
+ async getBatchResults(batchId, requestOptions) {
2921
3194
  return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
2922
3195
  method: "GET",
2923
3196
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2924
- }, zodFetchOptions);
3197
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2925
3198
  }
2926
- triggerTask(taskId, body, options) {
3199
+ triggerTask(taskId, body, options, requestOptions) {
2927
3200
  const encodedTaskId = encodeURIComponent(taskId);
2928
3201
  return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
2929
3202
  method: "POST",
2930
3203
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2931
3204
  body: JSON.stringify(body)
2932
- }, zodFetchOptions);
3205
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2933
3206
  }
2934
- batchTriggerTask(taskId, body, options) {
3207
+ batchTriggerTask(taskId, body, options, requestOptions) {
2935
3208
  const encodedTaskId = encodeURIComponent(taskId);
2936
3209
  return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
2937
3210
  method: "POST",
2938
3211
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2939
3212
  body: JSON.stringify(body)
2940
- }, zodFetchOptions);
3213
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2941
3214
  }
2942
- createUploadPayloadUrl(filename) {
3215
+ createUploadPayloadUrl(filename, requestOptions) {
2943
3216
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2944
3217
  method: "PUT",
2945
3218
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2946
- }, zodFetchOptions);
3219
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2947
3220
  }
2948
- getPayloadUrl(filename) {
3221
+ getPayloadUrl(filename, requestOptions) {
2949
3222
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2950
3223
  method: "GET",
2951
3224
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2952
- }, zodFetchOptions);
3225
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2953
3226
  }
2954
- retrieveRun(runId) {
3227
+ retrieveRun(runId, requestOptions) {
2955
3228
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v3/runs/${runId}`, {
2956
3229
  method: "GET",
2957
3230
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2958
- }, zodFetchOptions);
3231
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2959
3232
  }
2960
- listRuns(query) {
3233
+ listRuns(query, requestOptions) {
2961
3234
  const searchParams = createSearchQueryForListRuns(query);
2962
3235
  return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
2963
3236
  query: searchParams,
@@ -2967,9 +3240,9 @@ var _ApiClient = class _ApiClient {
2967
3240
  }, {
2968
3241
  method: "GET",
2969
3242
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2970
- }, zodFetchOptions);
3243
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2971
3244
  }
2972
- listProjectRuns(projectRef, query) {
3245
+ listProjectRuns(projectRef, query, requestOptions) {
2973
3246
  const searchParams = createSearchQueryForListRuns(query);
2974
3247
  if (query?.env) {
2975
3248
  searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
@@ -2982,35 +3255,35 @@ var _ApiClient = class _ApiClient {
2982
3255
  }, {
2983
3256
  method: "GET",
2984
3257
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2985
- }, zodFetchOptions);
3258
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2986
3259
  }
2987
- replayRun(runId) {
3260
+ replayRun(runId, requestOptions) {
2988
3261
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
2989
3262
  method: "POST",
2990
3263
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2991
- }, zodFetchOptions);
3264
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2992
3265
  }
2993
- cancelRun(runId) {
3266
+ cancelRun(runId, requestOptions) {
2994
3267
  return zodfetch(CanceledRunResponse, `${this.baseUrl}/api/v2/runs/${runId}/cancel`, {
2995
3268
  method: "POST",
2996
3269
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2997
- }, zodFetchOptions);
3270
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2998
3271
  }
2999
- rescheduleRun(runId, body) {
3272
+ rescheduleRun(runId, body, requestOptions) {
3000
3273
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/reschedule`, {
3001
3274
  method: "POST",
3002
3275
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3003
3276
  body: JSON.stringify(body)
3004
- }, zodFetchOptions);
3277
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3005
3278
  }
3006
- createSchedule(options) {
3279
+ createSchedule(options, requestOptions) {
3007
3280
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
3008
3281
  method: "POST",
3009
3282
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3010
3283
  body: JSON.stringify(options)
3011
- });
3284
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3012
3285
  }
3013
- listSchedules(options) {
3286
+ listSchedules(options, requestOptions) {
3014
3287
  const searchParams = new URLSearchParams();
3015
3288
  if (options?.page) {
3016
3289
  searchParams.append("page", options.page.toString());
@@ -3024,77 +3297,77 @@ var _ApiClient = class _ApiClient {
3024
3297
  }, {
3025
3298
  method: "GET",
3026
3299
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3027
- });
3300
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3028
3301
  }
3029
- retrieveSchedule(scheduleId) {
3302
+ retrieveSchedule(scheduleId, requestOptions) {
3030
3303
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3031
3304
  method: "GET",
3032
3305
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3033
- });
3306
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3034
3307
  }
3035
- updateSchedule(scheduleId, options) {
3308
+ updateSchedule(scheduleId, options, requestOptions) {
3036
3309
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3037
3310
  method: "PUT",
3038
3311
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3039
3312
  body: JSON.stringify(options)
3040
- });
3313
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3041
3314
  }
3042
- deactivateSchedule(scheduleId) {
3315
+ deactivateSchedule(scheduleId, requestOptions) {
3043
3316
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/deactivate`, {
3044
3317
  method: "POST",
3045
3318
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3046
- });
3319
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3047
3320
  }
3048
- activateSchedule(scheduleId) {
3321
+ activateSchedule(scheduleId, requestOptions) {
3049
3322
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/activate`, {
3050
3323
  method: "POST",
3051
3324
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3052
- });
3325
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3053
3326
  }
3054
- deleteSchedule(scheduleId) {
3327
+ deleteSchedule(scheduleId, requestOptions) {
3055
3328
  return zodfetch(DeletedScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3056
3329
  method: "DELETE",
3057
3330
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3058
- });
3331
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3059
3332
  }
3060
- listEnvVars(projectRef, slug) {
3333
+ listEnvVars(projectRef, slug, requestOptions) {
3061
3334
  return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3062
3335
  method: "GET",
3063
3336
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3064
- });
3337
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3065
3338
  }
3066
- importEnvVars(projectRef, slug, body) {
3339
+ importEnvVars(projectRef, slug, body, requestOptions) {
3067
3340
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
3068
3341
  method: "POST",
3069
3342
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3070
3343
  body: JSON.stringify(body)
3071
- });
3344
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3072
3345
  }
3073
- retrieveEnvVar(projectRef, slug, key) {
3346
+ retrieveEnvVar(projectRef, slug, key, requestOptions) {
3074
3347
  return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3075
3348
  method: "GET",
3076
3349
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3077
- });
3350
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3078
3351
  }
3079
- createEnvVar(projectRef, slug, body) {
3352
+ createEnvVar(projectRef, slug, body, requestOptions) {
3080
3353
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3081
3354
  method: "POST",
3082
3355
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3083
3356
  body: JSON.stringify(body)
3084
- });
3357
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3085
3358
  }
3086
- updateEnvVar(projectRef, slug, key, body) {
3359
+ updateEnvVar(projectRef, slug, key, body, requestOptions) {
3087
3360
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3088
3361
  method: "PUT",
3089
3362
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3090
3363
  body: JSON.stringify(body)
3091
- });
3364
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3092
3365
  }
3093
- deleteEnvVar(projectRef, slug, key) {
3366
+ deleteEnvVar(projectRef, slug, key, requestOptions) {
3094
3367
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3095
3368
  method: "DELETE",
3096
3369
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3097
- });
3370
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3098
3371
  }
3099
3372
  };
3100
3373
  _getHeaders = new WeakSet();
@@ -3149,6 +3422,20 @@ function createSearchQueryForListRuns(query) {
3149
3422
  return searchParams;
3150
3423
  }
3151
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");
3152
3439
  var _SimpleClock = class _SimpleClock {
3153
3440
  preciseNow() {
3154
3441
  const now = new preciseDate.PreciseDate();
@@ -3241,128 +3528,6 @@ function calculateAttributeValueLength(value) {
3241
3528
  return 0;
3242
3529
  }
3243
3530
  __name(calculateAttributeValueLength, "calculateAttributeValueLength");
3244
-
3245
- // src/v3/utils/flattenAttributes.ts
3246
- var NULL_SENTINEL = "$@null((";
3247
- function flattenAttributes(obj, prefix) {
3248
- const result = {};
3249
- if (obj === void 0) {
3250
- return result;
3251
- }
3252
- if (obj === null) {
3253
- result[prefix || ""] = NULL_SENTINEL;
3254
- return result;
3255
- }
3256
- if (typeof obj === "string") {
3257
- result[prefix || ""] = obj;
3258
- return result;
3259
- }
3260
- if (typeof obj === "number") {
3261
- result[prefix || ""] = obj;
3262
- return result;
3263
- }
3264
- if (typeof obj === "boolean") {
3265
- result[prefix || ""] = obj;
3266
- return result;
3267
- }
3268
- for (const [key, value] of Object.entries(obj)) {
3269
- const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
3270
- if (Array.isArray(value)) {
3271
- for (let i = 0; i < value.length; i++) {
3272
- if (typeof value[i] === "object" && value[i] !== null) {
3273
- Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
3274
- } else {
3275
- if (value[i] === null) {
3276
- result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
3277
- } else {
3278
- result[`${newPrefix}.[${i}]`] = value[i];
3279
- }
3280
- }
3281
- }
3282
- } else if (isRecord(value)) {
3283
- Object.assign(result, flattenAttributes(value, newPrefix));
3284
- } else {
3285
- if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
3286
- result[newPrefix] = value;
3287
- } else if (value === null) {
3288
- result[newPrefix] = NULL_SENTINEL;
3289
- }
3290
- }
3291
- }
3292
- return result;
3293
- }
3294
- __name(flattenAttributes, "flattenAttributes");
3295
- function isRecord(value) {
3296
- return value !== null && typeof value === "object" && !Array.isArray(value);
3297
- }
3298
- __name(isRecord, "isRecord");
3299
- function unflattenAttributes(obj) {
3300
- if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
3301
- return obj;
3302
- }
3303
- if (typeof obj === "object" && obj !== null && Object.keys(obj).length === 1 && Object.keys(obj)[0] === "") {
3304
- return rehydrateNull(obj[""]);
3305
- }
3306
- if (Object.keys(obj).length === 0) {
3307
- return;
3308
- }
3309
- const result = {};
3310
- for (const [key, value] of Object.entries(obj)) {
3311
- const parts = key.split(".").reduce((acc, part) => {
3312
- if (part.includes("[")) {
3313
- const subparts = part.split(/\[|\]/).filter((p) => p !== "");
3314
- acc.push(...subparts);
3315
- } else {
3316
- acc.push(part);
3317
- }
3318
- return acc;
3319
- }, []);
3320
- let current = result;
3321
- for (let i = 0; i < parts.length - 1; i++) {
3322
- const part = parts[i];
3323
- const nextPart = parts[i + 1];
3324
- const isArray = /^\d+$/.test(nextPart);
3325
- if (isArray && !Array.isArray(current[part])) {
3326
- current[part] = [];
3327
- } else if (!isArray && current[part] === void 0) {
3328
- current[part] = {};
3329
- }
3330
- current = current[part];
3331
- }
3332
- const lastPart = parts[parts.length - 1];
3333
- current[lastPart] = rehydrateNull(value);
3334
- }
3335
- if (Object.keys(result).every((k) => /^\d+$/.test(k))) {
3336
- const maxIndex = Math.max(...Object.keys(result).map((k) => parseInt(k)));
3337
- const arrayResult = Array(maxIndex + 1);
3338
- for (const key in result) {
3339
- arrayResult[parseInt(key)] = result[key];
3340
- }
3341
- return arrayResult;
3342
- }
3343
- return result;
3344
- }
3345
- __name(unflattenAttributes, "unflattenAttributes");
3346
- function primitiveValueOrflattenedAttributes(obj, prefix) {
3347
- if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
3348
- return obj;
3349
- }
3350
- const attributes = flattenAttributes(obj, prefix);
3351
- if (prefix !== void 0 && typeof attributes[prefix] !== "undefined" && attributes[prefix] !== null) {
3352
- return attributes[prefix];
3353
- }
3354
- return attributes;
3355
- }
3356
- __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
3357
- function rehydrateNull(value) {
3358
- if (value === NULL_SENTINEL) {
3359
- return null;
3360
- }
3361
- return value;
3362
- }
3363
- __name(rehydrateNull, "rehydrateNull");
3364
-
3365
- // src/v3/logger/taskLogger.ts
3366
3531
  var _NoopTaskLogger = class _NoopTaskLogger {
3367
3532
  debug() {
3368
3533
  }
@@ -3807,14 +3972,16 @@ var _TriggerTracer = class _TriggerTracer {
3807
3972
  attributes,
3808
3973
  startTime: clock.preciseNow()
3809
3974
  }, parentContext, async (span) => {
3810
- this.tracer.startSpan(name, {
3811
- ...options,
3812
- attributes: {
3813
- ...attributes,
3814
- [SemanticInternalAttributes.SPAN_PARTIAL]: true,
3815
- [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3816
- }
3817
- }, 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
+ }
3818
3985
  const usageMeasurement = usage.start();
3819
3986
  try {
3820
3987
  return await fn(span);
@@ -3827,12 +3994,14 @@ var _TriggerTracer = class _TriggerTracer {
3827
3994
  });
3828
3995
  throw e;
3829
3996
  } finally {
3830
- const usageSample = usage.stop(usageMeasurement);
3831
- const machine = taskContext.ctx?.machine;
3832
- span.setAttributes({
3833
- [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
3834
- [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
3835
- });
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
+ }
3836
4005
  span.end(clock.preciseNow());
3837
4006
  }
3838
4007
  });
@@ -4024,12 +4193,6 @@ function omit(obj, ...keys) {
4024
4193
  }
4025
4194
  __name(omit, "omit");
4026
4195
 
4027
- // src/v3/utils/styleAttributes.ts
4028
- function accessoryAttributes(accessory) {
4029
- return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
4030
- }
4031
- __name(accessoryAttributes, "accessoryAttributes");
4032
-
4033
4196
  // src/v3/utils/detectDependencyVersion.ts
4034
4197
  function detectDependencyVersion(dependency) {
4035
4198
  return dependencies[dependency];
@@ -4305,6 +4468,7 @@ function safeJsonParse2(value) {
4305
4468
  }
4306
4469
  __name(safeJsonParse2, "safeJsonParse");
4307
4470
 
4471
+ exports.AbortTaskRunError = AbortTaskRunError;
4308
4472
  exports.ApiClient = ApiClient;
4309
4473
  exports.ApiConnectionError = ApiConnectionError;
4310
4474
  exports.ApiError = ApiError;
@@ -4487,7 +4651,9 @@ exports.groupTaskMetadataIssuesByTask = groupTaskMetadataIssuesByTask;
4487
4651
  exports.imposeAttributeLimits = imposeAttributeLimits;
4488
4652
  exports.isCancellationSpanEvent = isCancellationSpanEvent;
4489
4653
  exports.isExceptionSpanEvent = isExceptionSpanEvent;
4654
+ exports.isRequestOptions = isRequestOptions;
4490
4655
  exports.logger = logger;
4656
+ exports.mergeRequestOptions = mergeRequestOptions;
4491
4657
  exports.millisecondsToNanoseconds = millisecondsToNanoseconds;
4492
4658
  exports.nanosecondsToMilliseconds = nanosecondsToMilliseconds;
4493
4659
  exports.omit = omit;
@@ -4497,6 +4663,7 @@ exports.parsePacket = parsePacket;
4497
4663
  exports.prettyPrintPacket = prettyPrintPacket;
4498
4664
  exports.primitiveValueOrflattenedAttributes = primitiveValueOrflattenedAttributes;
4499
4665
  exports.runtime = runtime;
4666
+ exports.sanitizeError = sanitizeError;
4500
4667
  exports.serverWebsocketMessages = serverWebsocketMessages;
4501
4668
  exports.stringPatternMatchers = stringPatternMatchers;
4502
4669
  exports.stringifyIO = stringifyIO;