@trigger.dev/core 0.0.0-v3-prerelease-20240703161020 → 0.0.0-v3-prerelease-20240705100038

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 (53) 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/dev/index.js.map +1 -1
  16. package/dist/v3/dev/index.mjs.map +1 -1
  17. package/dist/v3/index.d.mts +49 -38
  18. package/dist/v3/index.d.ts +49 -38
  19. package/dist/v3/index.js +432 -303
  20. package/dist/v3/index.js.map +1 -1
  21. package/dist/v3/index.mjs +430 -304
  22. package/dist/v3/index.mjs.map +1 -1
  23. package/dist/v3/otel/index.js +5 -2
  24. package/dist/v3/otel/index.js.map +1 -1
  25. package/dist/v3/otel/index.mjs +5 -2
  26. package/dist/v3/otel/index.mjs.map +1 -1
  27. package/dist/v3/prod/index.d.mts +3 -3
  28. package/dist/v3/prod/index.d.ts +3 -3
  29. package/dist/v3/schemas/index.d.mts +16 -4
  30. package/dist/v3/schemas/index.d.ts +16 -4
  31. package/dist/v3/schemas/index.js +3 -1
  32. package/dist/v3/schemas/index.js.map +1 -1
  33. package/dist/v3/schemas/index.mjs +3 -1
  34. package/dist/v3/schemas/index.mjs.map +1 -1
  35. package/dist/v3/utils/timers.d.mts +6 -0
  36. package/dist/v3/utils/timers.d.ts +6 -0
  37. package/dist/v3/utils/timers.js +31 -0
  38. package/dist/v3/utils/timers.js.map +1 -0
  39. package/dist/v3/utils/timers.mjs +28 -0
  40. package/dist/v3/utils/timers.mjs.map +1 -0
  41. package/dist/v3/workers/index.d.mts +7 -6
  42. package/dist/v3/workers/index.d.ts +7 -6
  43. package/dist/v3/workers/index.js +202 -92
  44. package/dist/v3/workers/index.js.map +1 -1
  45. package/dist/v3/workers/index.mjs +202 -92
  46. package/dist/v3/workers/index.mjs.map +1 -1
  47. package/dist/v3/zodfetch.d.mts +14 -2
  48. package/dist/v3/zodfetch.d.ts +14 -2
  49. package/dist/v3/zodfetch.js +244 -28
  50. package/dist/v3/zodfetch.js.map +1 -1
  51. package/dist/v3/zodfetch.mjs +242 -29
  52. package/dist/v3/zodfetch.mjs.map +1 -1
  53. package/package.json +9 -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 = "0.0.0-v3-prerelease-20240703161020";
36
+ var version = "0.0.0-v3-prerelease-20240705100038";
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 {
@@ -680,7 +689,8 @@ var TriggerTaskRequestBody = zod.z.object({
680
689
  test: zod.z.boolean().optional(),
681
690
  payloadType: zod.z.string().optional(),
682
691
  delay: zod.z.string().or(zod.z.coerce.date()).optional(),
683
- ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional()
692
+ ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional(),
693
+ maxAttempts: zod.z.number().int().optional()
684
694
  }).optional()
685
695
  });
686
696
  var TriggerTaskResponse = zod.z.object({
@@ -2144,7 +2154,10 @@ var SemanticInternalAttributes = {
2144
2154
  LINK_TITLE: "$link.title",
2145
2155
  IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
2146
2156
  USAGE_DURATION_MS: "$usage.durationMs",
2147
- USAGE_COST_IN_CENTS: "$usage.costInCents"
2157
+ USAGE_COST_IN_CENTS: "$usage.costInCents",
2158
+ RATE_LIMIT_LIMIT: "response.rateLimit.limit",
2159
+ RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
2160
+ RATE_LIMIT_RESET: "response.rateLimit.reset"
2148
2161
  };
2149
2162
 
2150
2163
  // src/v3/taskContext/index.ts
@@ -2234,10 +2247,118 @@ var TaskContextAPI = _TaskContextAPI;
2234
2247
  // src/v3/task-context-api.ts
2235
2248
  var taskContext = TaskContextAPI.getInstance();
2236
2249
 
2250
+ // src/retry.ts
2251
+ function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
2252
+ if (!resets)
2253
+ return;
2254
+ switch (format) {
2255
+ case "iso_8601_duration_openai_variant": {
2256
+ return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
2257
+ }
2258
+ case "iso_8601": {
2259
+ return calculateISO8601ResetAt(resets, now);
2260
+ }
2261
+ case "unix_timestamp": {
2262
+ return calculateUnixTimestampResetAt(resets, now);
2263
+ }
2264
+ case "unix_timestamp_in_ms": {
2265
+ return calculateUnixTimestampInMsResetAt(resets, now);
2266
+ }
2267
+ }
2268
+ }
2269
+ __name(calculateResetAt, "calculateResetAt");
2270
+ function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
2271
+ if (!resets)
2272
+ return void 0;
2273
+ const resetAt = parseInt(resets, 10);
2274
+ if (isNaN(resetAt))
2275
+ return void 0;
2276
+ return new Date(resetAt * 1e3);
2277
+ }
2278
+ __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
2279
+ function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
2280
+ if (!resets)
2281
+ return void 0;
2282
+ const resetAt = parseInt(resets, 10);
2283
+ if (isNaN(resetAt))
2284
+ return void 0;
2285
+ return new Date(resetAt);
2286
+ }
2287
+ __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
2288
+ function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
2289
+ if (!resets)
2290
+ return void 0;
2291
+ const resetAt = new Date(resets);
2292
+ if (isNaN(resetAt.getTime()))
2293
+ return void 0;
2294
+ return resetAt;
2295
+ }
2296
+ __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
2297
+ function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
2298
+ if (!resets)
2299
+ return void 0;
2300
+ const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
2301
+ const match = resets.match(pattern);
2302
+ if (!match)
2303
+ return void 0;
2304
+ const days = parseInt(match[1], 10) || 0;
2305
+ const hours = parseInt(match[2], 10) || 0;
2306
+ const minutes = parseInt(match[3], 10) || 0;
2307
+ const seconds = parseFloat(match[4]) || 0;
2308
+ const milliseconds = parseInt(match[5], 10) || 0;
2309
+ const resetAt = new Date(now);
2310
+ resetAt.setDate(resetAt.getDate() + days);
2311
+ resetAt.setHours(resetAt.getHours() + hours);
2312
+ resetAt.setMinutes(resetAt.getMinutes() + minutes);
2313
+ resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
2314
+ resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
2315
+ return resetAt;
2316
+ }
2317
+ __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
2318
+
2319
+ // src/v3/utils/retries.ts
2320
+ var defaultRetryOptions = {
2321
+ maxAttempts: 3,
2322
+ factor: 2,
2323
+ minTimeoutInMs: 1e3,
2324
+ maxTimeoutInMs: 6e4,
2325
+ randomize: true
2326
+ };
2327
+ var defaultFetchRetryOptions = {
2328
+ byStatus: {
2329
+ "429,408,409,5xx": {
2330
+ strategy: "backoff",
2331
+ ...defaultRetryOptions
2332
+ }
2333
+ },
2334
+ connectionError: defaultRetryOptions,
2335
+ timeout: defaultRetryOptions
2336
+ };
2337
+ function calculateNextRetryDelay(options, attempt) {
2338
+ const opts = {
2339
+ ...defaultRetryOptions,
2340
+ ...options
2341
+ };
2342
+ if (attempt >= opts.maxAttempts) {
2343
+ return;
2344
+ }
2345
+ const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
2346
+ const random = randomize ? Math.random() + 1 : 1;
2347
+ const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
2348
+ return Math.round(timeout);
2349
+ }
2350
+ __name(calculateNextRetryDelay, "calculateNextRetryDelay");
2351
+ function calculateResetAt2(resets, format, now = Date.now()) {
2352
+ const resetAt = calculateResetAt(resets, format, new Date(now));
2353
+ return resetAt?.getTime();
2354
+ }
2355
+ __name(calculateResetAt2, "calculateResetAt");
2356
+
2237
2357
  // src/v3/apiClient/errors.ts
2238
2358
  var _ApiError = class _ApiError extends Error {
2239
2359
  constructor(status, error, message, headers) {
2240
2360
  super(`${_ApiError.makeMessage(status, error, message)}`);
2361
+ this.name = "TriggerApiError";
2241
2362
  this.status = status;
2242
2363
  this.headers = headers;
2243
2364
  const data = error;
@@ -2358,6 +2479,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
2358
2479
  super(...arguments);
2359
2480
  __publicField(this, "status", 429);
2360
2481
  }
2482
+ get millisecondsUntilReset() {
2483
+ const resetAtUnixEpochMs = (this.headers ?? {})["x-ratelimit-reset"];
2484
+ if (typeof resetAtUnixEpochMs === "string") {
2485
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
2486
+ if (isNaN(resetAtUnixEpoch)) {
2487
+ return;
2488
+ }
2489
+ return Math.max(resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 2e3), 0);
2490
+ }
2491
+ }
2361
2492
  };
2362
2493
  __name(_RateLimitError, "RateLimitError");
2363
2494
  var RateLimitError = _RateLimitError;
@@ -2372,112 +2503,131 @@ function castToError(err) {
2372
2503
  }
2373
2504
  __name(castToError, "castToError");
2374
2505
 
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);
2385
- }
2386
- case "unix_timestamp": {
2387
- return calculateUnixTimestampResetAt(resets, now);
2388
- }
2389
- case "unix_timestamp_in_ms": {
2390
- return calculateUnixTimestampInMsResetAt(resets, now);
2506
+ // src/v3/utils/flattenAttributes.ts
2507
+ var NULL_SENTINEL = "$@null((";
2508
+ function flattenAttributes(obj, prefix) {
2509
+ const result = {};
2510
+ if (obj === void 0) {
2511
+ return result;
2512
+ }
2513
+ if (obj === null) {
2514
+ result[prefix || ""] = NULL_SENTINEL;
2515
+ return result;
2516
+ }
2517
+ if (typeof obj === "string") {
2518
+ result[prefix || ""] = obj;
2519
+ return result;
2520
+ }
2521
+ if (typeof obj === "number") {
2522
+ result[prefix || ""] = obj;
2523
+ return result;
2524
+ }
2525
+ if (typeof obj === "boolean") {
2526
+ result[prefix || ""] = obj;
2527
+ return result;
2528
+ }
2529
+ for (const [key, value] of Object.entries(obj)) {
2530
+ const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
2531
+ if (Array.isArray(value)) {
2532
+ for (let i = 0; i < value.length; i++) {
2533
+ if (typeof value[i] === "object" && value[i] !== null) {
2534
+ Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
2535
+ } else {
2536
+ if (value[i] === null) {
2537
+ result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
2538
+ } else {
2539
+ result[`${newPrefix}.[${i}]`] = value[i];
2540
+ }
2541
+ }
2542
+ }
2543
+ } else if (isRecord(value)) {
2544
+ Object.assign(result, flattenAttributes(value, newPrefix));
2545
+ } else {
2546
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
2547
+ result[newPrefix] = value;
2548
+ } else if (value === null) {
2549
+ result[newPrefix] = NULL_SENTINEL;
2550
+ }
2391
2551
  }
2392
2552
  }
2553
+ return result;
2393
2554
  }
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);
2555
+ __name(flattenAttributes, "flattenAttributes");
2556
+ function isRecord(value) {
2557
+ return value !== null && typeof value === "object" && !Array.isArray(value);
2411
2558
  }
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;
2559
+ __name(isRecord, "isRecord");
2560
+ function unflattenAttributes(obj) {
2561
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
2562
+ return obj;
2563
+ }
2564
+ if (typeof obj === "object" && obj !== null && Object.keys(obj).length === 1 && Object.keys(obj)[0] === "") {
2565
+ return rehydrateNull(obj[""]);
2566
+ }
2567
+ if (Object.keys(obj).length === 0) {
2568
+ return;
2569
+ }
2570
+ const result = {};
2571
+ for (const [key, value] of Object.entries(obj)) {
2572
+ const parts = key.split(".").reduce((acc, part) => {
2573
+ if (part.includes("[")) {
2574
+ const subparts = part.split(/\[|\]/).filter((p) => p !== "");
2575
+ acc.push(...subparts);
2576
+ } else {
2577
+ acc.push(part);
2578
+ }
2579
+ return acc;
2580
+ }, []);
2581
+ let current = result;
2582
+ for (let i = 0; i < parts.length - 1; i++) {
2583
+ const part = parts[i];
2584
+ const nextPart = parts[i + 1];
2585
+ const isArray = /^\d+$/.test(nextPart);
2586
+ if (isArray && !Array.isArray(current[part])) {
2587
+ current[part] = [];
2588
+ } else if (!isArray && current[part] === void 0) {
2589
+ current[part] = {};
2590
+ }
2591
+ current = current[part];
2592
+ }
2593
+ const lastPart = parts[parts.length - 1];
2594
+ current[lastPart] = rehydrateNull(value);
2595
+ }
2596
+ if (Object.keys(result).every((k) => /^\d+$/.test(k))) {
2597
+ const maxIndex = Math.max(...Object.keys(result).map((k) => parseInt(k)));
2598
+ const arrayResult = Array(maxIndex + 1);
2599
+ for (const key in result) {
2600
+ arrayResult[parseInt(key)] = result[key];
2601
+ }
2602
+ return arrayResult;
2603
+ }
2604
+ return result;
2420
2605
  }
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;
2606
+ __name(unflattenAttributes, "unflattenAttributes");
2607
+ function primitiveValueOrflattenedAttributes(obj, prefix) {
2608
+ if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
2609
+ return obj;
2610
+ }
2611
+ const attributes = flattenAttributes(obj, prefix);
2612
+ if (prefix !== void 0 && typeof attributes[prefix] !== "undefined" && attributes[prefix] !== null) {
2613
+ return attributes[prefix];
2614
+ }
2615
+ return attributes;
2441
2616
  }
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;
2617
+ __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
2618
+ function rehydrateNull(value) {
2619
+ if (value === NULL_SENTINEL) {
2620
+ return null;
2469
2621
  }
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);
2622
+ return value;
2474
2623
  }
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();
2624
+ __name(rehydrateNull, "rehydrateNull");
2625
+
2626
+ // src/v3/utils/styleAttributes.ts
2627
+ function accessoryAttributes(accessory) {
2628
+ return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
2479
2629
  }
2480
- __name(calculateResetAt2, "calculateResetAt");
2630
+ __name(accessoryAttributes, "accessoryAttributes");
2481
2631
 
2482
2632
  // src/v3/apiClient/pagination.ts
2483
2633
  var _CursorPage = class _CursorPage {
@@ -2587,6 +2737,12 @@ var defaultRetryOptions2 = {
2587
2737
  maxTimeoutInMs: 6e4,
2588
2738
  randomize: false
2589
2739
  };
2740
+ var requestOptionsKeys = {
2741
+ retry: true
2742
+ };
2743
+ var isRequestOptions = /* @__PURE__ */ __name((obj) => {
2744
+ return typeof obj === "object" && obj !== null && !isEmptyObj(obj) && Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k));
2745
+ }, "isRequestOptions");
2590
2746
  function zodfetch(schema, url, requestInit, options) {
2591
2747
  return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
2592
2748
  }
@@ -2637,16 +2793,43 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
2637
2793
  return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
2638
2794
  }
2639
2795
  __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
2640
- async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2796
+ async function traceZodFetch(params, callback) {
2797
+ if (!params.options?.tracer) {
2798
+ return callback();
2799
+ }
2800
+ const url = new URL(params.url);
2801
+ const method = params.requestInit?.method ?? "GET";
2802
+ const name = params.options.name ?? `${method} ${url.pathname}`;
2803
+ return await params.options.tracer.startActiveSpan(name, async (span) => {
2804
+ return await callback(span);
2805
+ }, {
2806
+ attributes: {
2807
+ [SemanticInternalAttributes.STYLE_ICON]: params.options?.icon ?? "api",
2808
+ ...params.options.attributes
2809
+ }
2810
+ });
2811
+ }
2812
+ __name(traceZodFetch, "traceZodFetch");
2813
+ async function _doZodFetch(schema, url, requestInit, options) {
2814
+ const $requestInit = await requestInit;
2815
+ return traceZodFetch({
2816
+ url,
2817
+ requestInit: $requestInit,
2818
+ options
2819
+ }, async (span) => {
2820
+ return await _doZodFetchWithRetries(schema, url, $requestInit, options);
2821
+ });
2822
+ }
2823
+ __name(_doZodFetch, "_doZodFetch");
2824
+ async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
2641
2825
  try {
2642
- const $requestInit = await requestInit;
2643
- const response = await fetch(url, requestInitWithCache($requestInit));
2826
+ const response = await fetch(url, requestInitWithCache(requestInit));
2644
2827
  const responseHeaders = createResponseHeaders(response.headers);
2645
2828
  if (!response.ok) {
2646
2829
  const retryResult = shouldRetry(response, attempt, options?.retry);
2647
2830
  if (retryResult.retry) {
2648
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
2649
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2831
+ await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
2832
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
2650
2833
  } else {
2651
2834
  const errText = await response.text().catch((e) => castToError2(e).message);
2652
2835
  const errJSON = safeJsonParse(errText);
@@ -2674,8 +2857,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2674
2857
  };
2675
2858
  const delay = calculateNextRetryDelay(retry, attempt);
2676
2859
  if (delay) {
2677
- await new Promise((resolve) => setTimeout(resolve, delay));
2678
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2860
+ await waitForRetry(url, attempt + 1, delay, options, requestInit);
2861
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
2679
2862
  }
2680
2863
  }
2681
2864
  throw new ApiConnectionError({
@@ -2683,7 +2866,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2683
2866
  });
2684
2867
  }
2685
2868
  }
2686
- __name(_doZodFetch, "_doZodFetch");
2869
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
2687
2870
  function castToError2(err) {
2688
2871
  if (err instanceof Error)
2689
2872
  return err;
@@ -2720,8 +2903,25 @@ function shouldRetry(response, attempt, retryOptions) {
2720
2903
  return shouldRetryForOptions();
2721
2904
  if (response.status === 409)
2722
2905
  return shouldRetryForOptions();
2723
- if (response.status === 429)
2906
+ if (response.status === 429) {
2907
+ if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
2908
+ return {
2909
+ retry: false
2910
+ };
2911
+ }
2912
+ const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
2913
+ if (resetAtUnixEpochMs) {
2914
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
2915
+ const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
2916
+ if (delay > 0) {
2917
+ return {
2918
+ retry: true,
2919
+ delay
2920
+ };
2921
+ }
2922
+ }
2724
2923
  return shouldRetryForOptions();
2924
+ }
2725
2925
  if (response.status >= 500)
2726
2926
  return shouldRetryForOptions();
2727
2927
  return {
@@ -2884,9 +3084,44 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
2884
3084
  }, "#fetchPage");
2885
3085
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
2886
3086
  var OffsetLimitPagePromise = _OffsetLimitPagePromise;
3087
+ async function waitForRetry(url, attempt, delay, options, requestInit, response) {
3088
+ if (options?.tracer) {
3089
+ const method = requestInit?.method ?? "GET";
3090
+ return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
3091
+ await new Promise((resolve) => setTimeout(resolve, delay));
3092
+ }, {
3093
+ attributes: {
3094
+ [SemanticInternalAttributes.STYLE_ICON]: "wait",
3095
+ ...accessoryAttributes({
3096
+ items: [
3097
+ {
3098
+ text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
3099
+ variant: "normal"
3100
+ }
3101
+ ],
3102
+ style: "codepath"
3103
+ })
3104
+ }
3105
+ });
3106
+ }
3107
+ await new Promise((resolve) => setTimeout(resolve, delay));
3108
+ }
3109
+ __name(waitForRetry, "waitForRetry");
3110
+ function isEmptyObj(obj) {
3111
+ if (!obj)
3112
+ return true;
3113
+ for (const _k in obj)
3114
+ return false;
3115
+ return true;
3116
+ }
3117
+ __name(isEmptyObj, "isEmptyObj");
3118
+ function hasOwn(obj, key) {
3119
+ return Object.prototype.hasOwnProperty.call(obj, key);
3120
+ }
3121
+ __name(hasOwn, "hasOwn");
2887
3122
 
2888
3123
  // src/v3/apiClient/index.ts
2889
- var zodFetchOptions = {
3124
+ var DEFAULT_ZOD_FETCH_OPTIONS = {
2890
3125
  retry: {
2891
3126
  maxAttempts: 3,
2892
3127
  minTimeoutInMs: 1e3,
@@ -2897,17 +3132,18 @@ var zodFetchOptions = {
2897
3132
  };
2898
3133
  var _getHeaders, getHeaders_fn;
2899
3134
  var _ApiClient = class _ApiClient {
2900
- constructor(baseUrl, accessToken) {
3135
+ constructor(baseUrl, accessToken, requestOptions = {}) {
2901
3136
  __privateAdd(this, _getHeaders);
2902
3137
  this.accessToken = accessToken;
2903
3138
  this.baseUrl = baseUrl.replace(/\/$/, "");
3139
+ this.defaultRequestOptions = mergeRequestOptions(DEFAULT_ZOD_FETCH_OPTIONS, requestOptions);
2904
3140
  }
2905
- async getRunResult(runId) {
3141
+ async getRunResult(runId, requestOptions) {
2906
3142
  try {
2907
3143
  return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
2908
3144
  method: "GET",
2909
3145
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2910
- }, zodFetchOptions);
3146
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2911
3147
  } catch (error) {
2912
3148
  if (error instanceof ApiError) {
2913
3149
  if (error.status === 404) {
@@ -2917,47 +3153,47 @@ var _ApiClient = class _ApiClient {
2917
3153
  throw error;
2918
3154
  }
2919
3155
  }
2920
- async getBatchResults(batchId) {
3156
+ async getBatchResults(batchId, requestOptions) {
2921
3157
  return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
2922
3158
  method: "GET",
2923
3159
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2924
- }, zodFetchOptions);
3160
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2925
3161
  }
2926
- triggerTask(taskId, body, options) {
3162
+ triggerTask(taskId, body, options, requestOptions) {
2927
3163
  const encodedTaskId = encodeURIComponent(taskId);
2928
3164
  return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
2929
3165
  method: "POST",
2930
3166
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2931
3167
  body: JSON.stringify(body)
2932
- }, zodFetchOptions);
3168
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2933
3169
  }
2934
- batchTriggerTask(taskId, body, options) {
3170
+ batchTriggerTask(taskId, body, options, requestOptions) {
2935
3171
  const encodedTaskId = encodeURIComponent(taskId);
2936
3172
  return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
2937
3173
  method: "POST",
2938
3174
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2939
3175
  body: JSON.stringify(body)
2940
- }, zodFetchOptions);
3176
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2941
3177
  }
2942
- createUploadPayloadUrl(filename) {
3178
+ createUploadPayloadUrl(filename, requestOptions) {
2943
3179
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2944
3180
  method: "PUT",
2945
3181
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2946
- }, zodFetchOptions);
3182
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2947
3183
  }
2948
- getPayloadUrl(filename) {
3184
+ getPayloadUrl(filename, requestOptions) {
2949
3185
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2950
3186
  method: "GET",
2951
3187
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2952
- }, zodFetchOptions);
3188
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2953
3189
  }
2954
- retrieveRun(runId) {
3190
+ retrieveRun(runId, requestOptions) {
2955
3191
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v3/runs/${runId}`, {
2956
3192
  method: "GET",
2957
3193
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2958
- }, zodFetchOptions);
3194
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2959
3195
  }
2960
- listRuns(query) {
3196
+ listRuns(query, requestOptions) {
2961
3197
  const searchParams = createSearchQueryForListRuns(query);
2962
3198
  return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
2963
3199
  query: searchParams,
@@ -2967,9 +3203,9 @@ var _ApiClient = class _ApiClient {
2967
3203
  }, {
2968
3204
  method: "GET",
2969
3205
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2970
- }, zodFetchOptions);
3206
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2971
3207
  }
2972
- listProjectRuns(projectRef, query) {
3208
+ listProjectRuns(projectRef, query, requestOptions) {
2973
3209
  const searchParams = createSearchQueryForListRuns(query);
2974
3210
  if (query?.env) {
2975
3211
  searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
@@ -2982,35 +3218,35 @@ var _ApiClient = class _ApiClient {
2982
3218
  }, {
2983
3219
  method: "GET",
2984
3220
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2985
- }, zodFetchOptions);
3221
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2986
3222
  }
2987
- replayRun(runId) {
3223
+ replayRun(runId, requestOptions) {
2988
3224
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
2989
3225
  method: "POST",
2990
3226
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2991
- }, zodFetchOptions);
3227
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2992
3228
  }
2993
- cancelRun(runId) {
3229
+ cancelRun(runId, requestOptions) {
2994
3230
  return zodfetch(CanceledRunResponse, `${this.baseUrl}/api/v2/runs/${runId}/cancel`, {
2995
3231
  method: "POST",
2996
3232
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2997
- }, zodFetchOptions);
3233
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2998
3234
  }
2999
- rescheduleRun(runId, body) {
3235
+ rescheduleRun(runId, body, requestOptions) {
3000
3236
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/reschedule`, {
3001
3237
  method: "POST",
3002
3238
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3003
3239
  body: JSON.stringify(body)
3004
- }, zodFetchOptions);
3240
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3005
3241
  }
3006
- createSchedule(options) {
3242
+ createSchedule(options, requestOptions) {
3007
3243
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
3008
3244
  method: "POST",
3009
3245
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3010
3246
  body: JSON.stringify(options)
3011
- });
3247
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3012
3248
  }
3013
- listSchedules(options) {
3249
+ listSchedules(options, requestOptions) {
3014
3250
  const searchParams = new URLSearchParams();
3015
3251
  if (options?.page) {
3016
3252
  searchParams.append("page", options.page.toString());
@@ -3024,77 +3260,77 @@ var _ApiClient = class _ApiClient {
3024
3260
  }, {
3025
3261
  method: "GET",
3026
3262
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3027
- });
3263
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3028
3264
  }
3029
- retrieveSchedule(scheduleId) {
3265
+ retrieveSchedule(scheduleId, requestOptions) {
3030
3266
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3031
3267
  method: "GET",
3032
3268
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3033
- });
3269
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3034
3270
  }
3035
- updateSchedule(scheduleId, options) {
3271
+ updateSchedule(scheduleId, options, requestOptions) {
3036
3272
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3037
3273
  method: "PUT",
3038
3274
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3039
3275
  body: JSON.stringify(options)
3040
- });
3276
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3041
3277
  }
3042
- deactivateSchedule(scheduleId) {
3278
+ deactivateSchedule(scheduleId, requestOptions) {
3043
3279
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/deactivate`, {
3044
3280
  method: "POST",
3045
3281
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3046
- });
3282
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3047
3283
  }
3048
- activateSchedule(scheduleId) {
3284
+ activateSchedule(scheduleId, requestOptions) {
3049
3285
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/activate`, {
3050
3286
  method: "POST",
3051
3287
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3052
- });
3288
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3053
3289
  }
3054
- deleteSchedule(scheduleId) {
3290
+ deleteSchedule(scheduleId, requestOptions) {
3055
3291
  return zodfetch(DeletedScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3056
3292
  method: "DELETE",
3057
3293
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3058
- });
3294
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3059
3295
  }
3060
- listEnvVars(projectRef, slug) {
3296
+ listEnvVars(projectRef, slug, requestOptions) {
3061
3297
  return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3062
3298
  method: "GET",
3063
3299
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3064
- });
3300
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3065
3301
  }
3066
- importEnvVars(projectRef, slug, body) {
3302
+ importEnvVars(projectRef, slug, body, requestOptions) {
3067
3303
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
3068
3304
  method: "POST",
3069
3305
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3070
3306
  body: JSON.stringify(body)
3071
- });
3307
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3072
3308
  }
3073
- retrieveEnvVar(projectRef, slug, key) {
3309
+ retrieveEnvVar(projectRef, slug, key, requestOptions) {
3074
3310
  return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3075
3311
  method: "GET",
3076
3312
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3077
- });
3313
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3078
3314
  }
3079
- createEnvVar(projectRef, slug, body) {
3315
+ createEnvVar(projectRef, slug, body, requestOptions) {
3080
3316
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3081
3317
  method: "POST",
3082
3318
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3083
3319
  body: JSON.stringify(body)
3084
- });
3320
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3085
3321
  }
3086
- updateEnvVar(projectRef, slug, key, body) {
3322
+ updateEnvVar(projectRef, slug, key, body, requestOptions) {
3087
3323
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3088
3324
  method: "PUT",
3089
3325
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3090
3326
  body: JSON.stringify(body)
3091
- });
3327
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3092
3328
  }
3093
- deleteEnvVar(projectRef, slug, key) {
3329
+ deleteEnvVar(projectRef, slug, key, requestOptions) {
3094
3330
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3095
3331
  method: "DELETE",
3096
3332
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3097
- });
3333
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3098
3334
  }
3099
3335
  };
3100
3336
  _getHeaders = new WeakSet();
@@ -3149,6 +3385,20 @@ function createSearchQueryForListRuns(query) {
3149
3385
  return searchParams;
3150
3386
  }
3151
3387
  __name(createSearchQueryForListRuns, "createSearchQueryForListRuns");
3388
+ function mergeRequestOptions(defaultOptions, options) {
3389
+ if (!options) {
3390
+ return defaultOptions;
3391
+ }
3392
+ return {
3393
+ ...defaultOptions,
3394
+ ...options,
3395
+ retry: {
3396
+ ...defaultOptions.retry,
3397
+ ...options.retry
3398
+ }
3399
+ };
3400
+ }
3401
+ __name(mergeRequestOptions, "mergeRequestOptions");
3152
3402
  var _SimpleClock = class _SimpleClock {
3153
3403
  preciseNow() {
3154
3404
  const now = new preciseDate.PreciseDate();
@@ -3241,128 +3491,6 @@ function calculateAttributeValueLength(value) {
3241
3491
  return 0;
3242
3492
  }
3243
3493
  __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
3494
  var _NoopTaskLogger = class _NoopTaskLogger {
3367
3495
  debug() {
3368
3496
  }
@@ -3807,14 +3935,16 @@ var _TriggerTracer = class _TriggerTracer {
3807
3935
  attributes,
3808
3936
  startTime: clock.preciseNow()
3809
3937
  }, 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();
3938
+ if (taskContext.ctx) {
3939
+ this.tracer.startSpan(name, {
3940
+ ...options,
3941
+ attributes: {
3942
+ ...attributes,
3943
+ [SemanticInternalAttributes.SPAN_PARTIAL]: true,
3944
+ [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3945
+ }
3946
+ }, parentContext).end();
3947
+ }
3818
3948
  const usageMeasurement = usage.start();
3819
3949
  try {
3820
3950
  return await fn(span);
@@ -3827,12 +3957,14 @@ var _TriggerTracer = class _TriggerTracer {
3827
3957
  });
3828
3958
  throw e;
3829
3959
  } 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
- });
3960
+ if (taskContext.ctx) {
3961
+ const usageSample = usage.stop(usageMeasurement);
3962
+ const machine = taskContext.ctx.machine;
3963
+ span.setAttributes({
3964
+ [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
3965
+ [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
3966
+ });
3967
+ }
3836
3968
  span.end(clock.preciseNow());
3837
3969
  }
3838
3970
  });
@@ -4024,12 +4156,6 @@ function omit(obj, ...keys) {
4024
4156
  }
4025
4157
  __name(omit, "omit");
4026
4158
 
4027
- // src/v3/utils/styleAttributes.ts
4028
- function accessoryAttributes(accessory) {
4029
- return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
4030
- }
4031
- __name(accessoryAttributes, "accessoryAttributes");
4032
-
4033
4159
  // src/v3/utils/detectDependencyVersion.ts
4034
4160
  function detectDependencyVersion(dependency) {
4035
4161
  return dependencies[dependency];
@@ -4305,6 +4431,7 @@ function safeJsonParse2(value) {
4305
4431
  }
4306
4432
  __name(safeJsonParse2, "safeJsonParse");
4307
4433
 
4434
+ exports.AbortTaskRunError = AbortTaskRunError;
4308
4435
  exports.ApiClient = ApiClient;
4309
4436
  exports.ApiConnectionError = ApiConnectionError;
4310
4437
  exports.ApiError = ApiError;
@@ -4487,7 +4614,9 @@ exports.groupTaskMetadataIssuesByTask = groupTaskMetadataIssuesByTask;
4487
4614
  exports.imposeAttributeLimits = imposeAttributeLimits;
4488
4615
  exports.isCancellationSpanEvent = isCancellationSpanEvent;
4489
4616
  exports.isExceptionSpanEvent = isExceptionSpanEvent;
4617
+ exports.isRequestOptions = isRequestOptions;
4490
4618
  exports.logger = logger;
4619
+ exports.mergeRequestOptions = mergeRequestOptions;
4491
4620
  exports.millisecondsToNanoseconds = millisecondsToNanoseconds;
4492
4621
  exports.nanosecondsToMilliseconds = nanosecondsToMilliseconds;
4493
4622
  exports.omit = omit;