@trigger.dev/core 0.0.0-v3-prerelease-20240703181409 → 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 (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 +49 -38
  16. package/dist/v3/index.d.ts +49 -38
  17. package/dist/v3/index.js +432 -303
  18. package/dist/v3/index.js.map +1 -1
  19. package/dist/v3/index.mjs +430 -304
  20. package/dist/v3/index.mjs.map +1 -1
  21. package/dist/v3/otel/index.js +5 -2
  22. package/dist/v3/otel/index.js.map +1 -1
  23. package/dist/v3/otel/index.mjs +5 -2
  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 +202 -92
  36. package/dist/v3/workers/index.js.map +1 -1
  37. package/dist/v3/workers/index.mjs +202 -92
  38. package/dist/v3/workers/index.mjs.map +1 -1
  39. package/dist/v3/zodfetch.d.mts +14 -2
  40. package/dist/v3/zodfetch.d.ts +14 -2
  41. package/dist/v3/zodfetch.js +244 -28
  42. package/dist/v3/zodfetch.js.map +1 -1
  43. package/dist/v3/zodfetch.mjs +242 -29
  44. package/dist/v3/zodfetch.mjs.map +1 -1
  45. package/package.json +1 -1
package/dist/v3/index.mjs CHANGED
@@ -27,7 +27,7 @@ var __privateMethod = (obj, member, method) => {
27
27
  };
28
28
 
29
29
  // package.json
30
- var version = "0.0.0-v3-prerelease-20240703181409";
30
+ var version = "0.0.0-v3-prerelease-20240705100038";
31
31
  var dependencies = {
32
32
  "@google-cloud/precise-date": "^4.0.0",
33
33
  "@opentelemetry/api": "^1.8.0",
@@ -161,6 +161,7 @@ var TaskRun = z.object({
161
161
  createdAt: z.coerce.date(),
162
162
  startedAt: z.coerce.date().default(() => /* @__PURE__ */ new Date()),
163
163
  idempotencyKey: z.string().optional(),
164
+ maxAttempts: z.number().optional(),
164
165
  durationMs: z.number().default(0),
165
166
  costInCents: z.number().default(0),
166
167
  baseCostInCents: z.number().default(0)
@@ -479,6 +480,14 @@ var ImageDetailsMetadata = z.object({
479
480
  contentHash: z.string(),
480
481
  imageTag: z.string()
481
482
  });
483
+ var _AbortTaskRunError = class _AbortTaskRunError extends Error {
484
+ constructor(message) {
485
+ super(message);
486
+ this.name = "AbortTaskRunError";
487
+ }
488
+ };
489
+ __name(_AbortTaskRunError, "AbortTaskRunError");
490
+ var AbortTaskRunError = _AbortTaskRunError;
482
491
  function parseError(error) {
483
492
  if (error instanceof Error) {
484
493
  return {
@@ -674,7 +683,8 @@ var TriggerTaskRequestBody = z.object({
674
683
  test: z.boolean().optional(),
675
684
  payloadType: z.string().optional(),
676
685
  delay: z.string().or(z.coerce.date()).optional(),
677
- ttl: z.string().or(z.number().nonnegative().int()).optional()
686
+ ttl: z.string().or(z.number().nonnegative().int()).optional(),
687
+ maxAttempts: z.number().int().optional()
678
688
  }).optional()
679
689
  });
680
690
  var TriggerTaskResponse = z.object({
@@ -2138,7 +2148,10 @@ var SemanticInternalAttributes = {
2138
2148
  LINK_TITLE: "$link.title",
2139
2149
  IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
2140
2150
  USAGE_DURATION_MS: "$usage.durationMs",
2141
- USAGE_COST_IN_CENTS: "$usage.costInCents"
2151
+ USAGE_COST_IN_CENTS: "$usage.costInCents",
2152
+ RATE_LIMIT_LIMIT: "response.rateLimit.limit",
2153
+ RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
2154
+ RATE_LIMIT_RESET: "response.rateLimit.reset"
2142
2155
  };
2143
2156
 
2144
2157
  // src/v3/taskContext/index.ts
@@ -2228,10 +2241,118 @@ var TaskContextAPI = _TaskContextAPI;
2228
2241
  // src/v3/task-context-api.ts
2229
2242
  var taskContext = TaskContextAPI.getInstance();
2230
2243
 
2244
+ // src/retry.ts
2245
+ function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
2246
+ if (!resets)
2247
+ return;
2248
+ switch (format) {
2249
+ case "iso_8601_duration_openai_variant": {
2250
+ return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
2251
+ }
2252
+ case "iso_8601": {
2253
+ return calculateISO8601ResetAt(resets, now);
2254
+ }
2255
+ case "unix_timestamp": {
2256
+ return calculateUnixTimestampResetAt(resets, now);
2257
+ }
2258
+ case "unix_timestamp_in_ms": {
2259
+ return calculateUnixTimestampInMsResetAt(resets, now);
2260
+ }
2261
+ }
2262
+ }
2263
+ __name(calculateResetAt, "calculateResetAt");
2264
+ function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
2265
+ if (!resets)
2266
+ return void 0;
2267
+ const resetAt = parseInt(resets, 10);
2268
+ if (isNaN(resetAt))
2269
+ return void 0;
2270
+ return new Date(resetAt * 1e3);
2271
+ }
2272
+ __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
2273
+ function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
2274
+ if (!resets)
2275
+ return void 0;
2276
+ const resetAt = parseInt(resets, 10);
2277
+ if (isNaN(resetAt))
2278
+ return void 0;
2279
+ return new Date(resetAt);
2280
+ }
2281
+ __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
2282
+ function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
2283
+ if (!resets)
2284
+ return void 0;
2285
+ const resetAt = new Date(resets);
2286
+ if (isNaN(resetAt.getTime()))
2287
+ return void 0;
2288
+ return resetAt;
2289
+ }
2290
+ __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
2291
+ function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
2292
+ if (!resets)
2293
+ return void 0;
2294
+ const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
2295
+ const match = resets.match(pattern);
2296
+ if (!match)
2297
+ return void 0;
2298
+ const days = parseInt(match[1], 10) || 0;
2299
+ const hours = parseInt(match[2], 10) || 0;
2300
+ const minutes = parseInt(match[3], 10) || 0;
2301
+ const seconds = parseFloat(match[4]) || 0;
2302
+ const milliseconds = parseInt(match[5], 10) || 0;
2303
+ const resetAt = new Date(now);
2304
+ resetAt.setDate(resetAt.getDate() + days);
2305
+ resetAt.setHours(resetAt.getHours() + hours);
2306
+ resetAt.setMinutes(resetAt.getMinutes() + minutes);
2307
+ resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
2308
+ resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
2309
+ return resetAt;
2310
+ }
2311
+ __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
2312
+
2313
+ // src/v3/utils/retries.ts
2314
+ var defaultRetryOptions = {
2315
+ maxAttempts: 3,
2316
+ factor: 2,
2317
+ minTimeoutInMs: 1e3,
2318
+ maxTimeoutInMs: 6e4,
2319
+ randomize: true
2320
+ };
2321
+ var defaultFetchRetryOptions = {
2322
+ byStatus: {
2323
+ "429,408,409,5xx": {
2324
+ strategy: "backoff",
2325
+ ...defaultRetryOptions
2326
+ }
2327
+ },
2328
+ connectionError: defaultRetryOptions,
2329
+ timeout: defaultRetryOptions
2330
+ };
2331
+ function calculateNextRetryDelay(options, attempt) {
2332
+ const opts = {
2333
+ ...defaultRetryOptions,
2334
+ ...options
2335
+ };
2336
+ if (attempt >= opts.maxAttempts) {
2337
+ return;
2338
+ }
2339
+ const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
2340
+ const random = randomize ? Math.random() + 1 : 1;
2341
+ const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
2342
+ return Math.round(timeout);
2343
+ }
2344
+ __name(calculateNextRetryDelay, "calculateNextRetryDelay");
2345
+ function calculateResetAt2(resets, format, now = Date.now()) {
2346
+ const resetAt = calculateResetAt(resets, format, new Date(now));
2347
+ return resetAt?.getTime();
2348
+ }
2349
+ __name(calculateResetAt2, "calculateResetAt");
2350
+
2231
2351
  // src/v3/apiClient/errors.ts
2232
2352
  var _ApiError = class _ApiError extends Error {
2233
2353
  constructor(status, error, message, headers) {
2234
2354
  super(`${_ApiError.makeMessage(status, error, message)}`);
2355
+ this.name = "TriggerApiError";
2235
2356
  this.status = status;
2236
2357
  this.headers = headers;
2237
2358
  const data = error;
@@ -2352,6 +2473,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
2352
2473
  super(...arguments);
2353
2474
  __publicField(this, "status", 429);
2354
2475
  }
2476
+ get millisecondsUntilReset() {
2477
+ const resetAtUnixEpochMs = (this.headers ?? {})["x-ratelimit-reset"];
2478
+ if (typeof resetAtUnixEpochMs === "string") {
2479
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
2480
+ if (isNaN(resetAtUnixEpoch)) {
2481
+ return;
2482
+ }
2483
+ return Math.max(resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 2e3), 0);
2484
+ }
2485
+ }
2355
2486
  };
2356
2487
  __name(_RateLimitError, "RateLimitError");
2357
2488
  var RateLimitError = _RateLimitError;
@@ -2366,112 +2497,131 @@ function castToError(err) {
2366
2497
  }
2367
2498
  __name(castToError, "castToError");
2368
2499
 
2369
- // src/retry.ts
2370
- function calculateResetAt(resets, format, now = /* @__PURE__ */ new Date()) {
2371
- if (!resets)
2372
- return;
2373
- switch (format) {
2374
- case "iso_8601_duration_openai_variant": {
2375
- return calculateISO8601DurationOpenAIVariantResetAt(resets, now);
2376
- }
2377
- case "iso_8601": {
2378
- return calculateISO8601ResetAt(resets, now);
2379
- }
2380
- case "unix_timestamp": {
2381
- return calculateUnixTimestampResetAt(resets, now);
2382
- }
2383
- case "unix_timestamp_in_ms": {
2384
- return calculateUnixTimestampInMsResetAt(resets, now);
2500
+ // src/v3/utils/flattenAttributes.ts
2501
+ var NULL_SENTINEL = "$@null((";
2502
+ function flattenAttributes(obj, prefix) {
2503
+ const result = {};
2504
+ if (obj === void 0) {
2505
+ return result;
2506
+ }
2507
+ if (obj === null) {
2508
+ result[prefix || ""] = NULL_SENTINEL;
2509
+ return result;
2510
+ }
2511
+ if (typeof obj === "string") {
2512
+ result[prefix || ""] = obj;
2513
+ return result;
2514
+ }
2515
+ if (typeof obj === "number") {
2516
+ result[prefix || ""] = obj;
2517
+ return result;
2518
+ }
2519
+ if (typeof obj === "boolean") {
2520
+ result[prefix || ""] = obj;
2521
+ return result;
2522
+ }
2523
+ for (const [key, value] of Object.entries(obj)) {
2524
+ const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
2525
+ if (Array.isArray(value)) {
2526
+ for (let i = 0; i < value.length; i++) {
2527
+ if (typeof value[i] === "object" && value[i] !== null) {
2528
+ Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
2529
+ } else {
2530
+ if (value[i] === null) {
2531
+ result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
2532
+ } else {
2533
+ result[`${newPrefix}.[${i}]`] = value[i];
2534
+ }
2535
+ }
2536
+ }
2537
+ } else if (isRecord(value)) {
2538
+ Object.assign(result, flattenAttributes(value, newPrefix));
2539
+ } else {
2540
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
2541
+ result[newPrefix] = value;
2542
+ } else if (value === null) {
2543
+ result[newPrefix] = NULL_SENTINEL;
2544
+ }
2385
2545
  }
2386
2546
  }
2547
+ return result;
2387
2548
  }
2388
- __name(calculateResetAt, "calculateResetAt");
2389
- function calculateUnixTimestampResetAt(resets, now = /* @__PURE__ */ new Date()) {
2390
- if (!resets)
2391
- return void 0;
2392
- const resetAt = parseInt(resets, 10);
2393
- if (isNaN(resetAt))
2394
- return void 0;
2395
- return new Date(resetAt * 1e3);
2396
- }
2397
- __name(calculateUnixTimestampResetAt, "calculateUnixTimestampResetAt");
2398
- function calculateUnixTimestampInMsResetAt(resets, now = /* @__PURE__ */ new Date()) {
2399
- if (!resets)
2400
- return void 0;
2401
- const resetAt = parseInt(resets, 10);
2402
- if (isNaN(resetAt))
2403
- return void 0;
2404
- return new Date(resetAt);
2549
+ __name(flattenAttributes, "flattenAttributes");
2550
+ function isRecord(value) {
2551
+ return value !== null && typeof value === "object" && !Array.isArray(value);
2405
2552
  }
2406
- __name(calculateUnixTimestampInMsResetAt, "calculateUnixTimestampInMsResetAt");
2407
- function calculateISO8601ResetAt(resets, now = /* @__PURE__ */ new Date()) {
2408
- if (!resets)
2409
- return void 0;
2410
- const resetAt = new Date(resets);
2411
- if (isNaN(resetAt.getTime()))
2412
- return void 0;
2413
- return resetAt;
2553
+ __name(isRecord, "isRecord");
2554
+ function unflattenAttributes(obj) {
2555
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
2556
+ return obj;
2557
+ }
2558
+ if (typeof obj === "object" && obj !== null && Object.keys(obj).length === 1 && Object.keys(obj)[0] === "") {
2559
+ return rehydrateNull(obj[""]);
2560
+ }
2561
+ if (Object.keys(obj).length === 0) {
2562
+ return;
2563
+ }
2564
+ const result = {};
2565
+ for (const [key, value] of Object.entries(obj)) {
2566
+ const parts = key.split(".").reduce((acc, part) => {
2567
+ if (part.includes("[")) {
2568
+ const subparts = part.split(/\[|\]/).filter((p) => p !== "");
2569
+ acc.push(...subparts);
2570
+ } else {
2571
+ acc.push(part);
2572
+ }
2573
+ return acc;
2574
+ }, []);
2575
+ let current = result;
2576
+ for (let i = 0; i < parts.length - 1; i++) {
2577
+ const part = parts[i];
2578
+ const nextPart = parts[i + 1];
2579
+ const isArray = /^\d+$/.test(nextPart);
2580
+ if (isArray && !Array.isArray(current[part])) {
2581
+ current[part] = [];
2582
+ } else if (!isArray && current[part] === void 0) {
2583
+ current[part] = {};
2584
+ }
2585
+ current = current[part];
2586
+ }
2587
+ const lastPart = parts[parts.length - 1];
2588
+ current[lastPart] = rehydrateNull(value);
2589
+ }
2590
+ if (Object.keys(result).every((k) => /^\d+$/.test(k))) {
2591
+ const maxIndex = Math.max(...Object.keys(result).map((k) => parseInt(k)));
2592
+ const arrayResult = Array(maxIndex + 1);
2593
+ for (const key in result) {
2594
+ arrayResult[parseInt(key)] = result[key];
2595
+ }
2596
+ return arrayResult;
2597
+ }
2598
+ return result;
2414
2599
  }
2415
- __name(calculateISO8601ResetAt, "calculateISO8601ResetAt");
2416
- function calculateISO8601DurationOpenAIVariantResetAt(resets, now = /* @__PURE__ */ new Date()) {
2417
- if (!resets)
2418
- return void 0;
2419
- const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
2420
- const match = resets.match(pattern);
2421
- if (!match)
2422
- return void 0;
2423
- const days = parseInt(match[1], 10) || 0;
2424
- const hours = parseInt(match[2], 10) || 0;
2425
- const minutes = parseInt(match[3], 10) || 0;
2426
- const seconds = parseFloat(match[4]) || 0;
2427
- const milliseconds = parseInt(match[5], 10) || 0;
2428
- const resetAt = new Date(now);
2429
- resetAt.setDate(resetAt.getDate() + days);
2430
- resetAt.setHours(resetAt.getHours() + hours);
2431
- resetAt.setMinutes(resetAt.getMinutes() + minutes);
2432
- resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
2433
- resetAt.setMilliseconds(resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1e3 + milliseconds);
2434
- return resetAt;
2600
+ __name(unflattenAttributes, "unflattenAttributes");
2601
+ function primitiveValueOrflattenedAttributes(obj, prefix) {
2602
+ if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
2603
+ return obj;
2604
+ }
2605
+ const attributes = flattenAttributes(obj, prefix);
2606
+ if (prefix !== void 0 && typeof attributes[prefix] !== "undefined" && attributes[prefix] !== null) {
2607
+ return attributes[prefix];
2608
+ }
2609
+ return attributes;
2435
2610
  }
2436
- __name(calculateISO8601DurationOpenAIVariantResetAt, "calculateISO8601DurationOpenAIVariantResetAt");
2437
-
2438
- // src/v3/utils/retries.ts
2439
- var defaultRetryOptions = {
2440
- maxAttempts: 3,
2441
- factor: 2,
2442
- minTimeoutInMs: 1e3,
2443
- maxTimeoutInMs: 6e4,
2444
- randomize: true
2445
- };
2446
- var defaultFetchRetryOptions = {
2447
- byStatus: {
2448
- "429,408,409,5xx": {
2449
- strategy: "backoff",
2450
- ...defaultRetryOptions
2451
- }
2452
- },
2453
- connectionError: defaultRetryOptions,
2454
- timeout: defaultRetryOptions
2455
- };
2456
- function calculateNextRetryDelay(options, attempt) {
2457
- const opts = {
2458
- ...defaultRetryOptions,
2459
- ...options
2460
- };
2461
- if (attempt >= opts.maxAttempts) {
2462
- return;
2611
+ __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
2612
+ function rehydrateNull(value) {
2613
+ if (value === NULL_SENTINEL) {
2614
+ return null;
2463
2615
  }
2464
- const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
2465
- const random = randomize ? Math.random() + 1 : 1;
2466
- const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
2467
- return Math.round(timeout);
2616
+ return value;
2468
2617
  }
2469
- __name(calculateNextRetryDelay, "calculateNextRetryDelay");
2470
- function calculateResetAt2(resets, format, now = Date.now()) {
2471
- const resetAt = calculateResetAt(resets, format, new Date(now));
2472
- return resetAt?.getTime();
2618
+ __name(rehydrateNull, "rehydrateNull");
2619
+
2620
+ // src/v3/utils/styleAttributes.ts
2621
+ function accessoryAttributes(accessory) {
2622
+ return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
2473
2623
  }
2474
- __name(calculateResetAt2, "calculateResetAt");
2624
+ __name(accessoryAttributes, "accessoryAttributes");
2475
2625
 
2476
2626
  // src/v3/apiClient/pagination.ts
2477
2627
  var _CursorPage = class _CursorPage {
@@ -2581,6 +2731,12 @@ var defaultRetryOptions2 = {
2581
2731
  maxTimeoutInMs: 6e4,
2582
2732
  randomize: false
2583
2733
  };
2734
+ var requestOptionsKeys = {
2735
+ retry: true
2736
+ };
2737
+ var isRequestOptions = /* @__PURE__ */ __name((obj) => {
2738
+ return typeof obj === "object" && obj !== null && !isEmptyObj(obj) && Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k));
2739
+ }, "isRequestOptions");
2584
2740
  function zodfetch(schema, url, requestInit, options) {
2585
2741
  return new ApiPromise(_doZodFetch(schema, url, requestInit, options));
2586
2742
  }
@@ -2631,16 +2787,43 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
2631
2787
  return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
2632
2788
  }
2633
2789
  __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
2634
- async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2790
+ async function traceZodFetch(params, callback) {
2791
+ if (!params.options?.tracer) {
2792
+ return callback();
2793
+ }
2794
+ const url = new URL(params.url);
2795
+ const method = params.requestInit?.method ?? "GET";
2796
+ const name = params.options.name ?? `${method} ${url.pathname}`;
2797
+ return await params.options.tracer.startActiveSpan(name, async (span) => {
2798
+ return await callback(span);
2799
+ }, {
2800
+ attributes: {
2801
+ [SemanticInternalAttributes.STYLE_ICON]: params.options?.icon ?? "api",
2802
+ ...params.options.attributes
2803
+ }
2804
+ });
2805
+ }
2806
+ __name(traceZodFetch, "traceZodFetch");
2807
+ async function _doZodFetch(schema, url, requestInit, options) {
2808
+ const $requestInit = await requestInit;
2809
+ return traceZodFetch({
2810
+ url,
2811
+ requestInit: $requestInit,
2812
+ options
2813
+ }, async (span) => {
2814
+ return await _doZodFetchWithRetries(schema, url, $requestInit, options);
2815
+ });
2816
+ }
2817
+ __name(_doZodFetch, "_doZodFetch");
2818
+ async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
2635
2819
  try {
2636
- const $requestInit = await requestInit;
2637
- const response = await fetch(url, requestInitWithCache($requestInit));
2820
+ const response = await fetch(url, requestInitWithCache(requestInit));
2638
2821
  const responseHeaders = createResponseHeaders(response.headers);
2639
2822
  if (!response.ok) {
2640
2823
  const retryResult = shouldRetry(response, attempt, options?.retry);
2641
2824
  if (retryResult.retry) {
2642
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
2643
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2825
+ await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
2826
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
2644
2827
  } else {
2645
2828
  const errText = await response.text().catch((e) => castToError2(e).message);
2646
2829
  const errJSON = safeJsonParse(errText);
@@ -2668,8 +2851,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2668
2851
  };
2669
2852
  const delay = calculateNextRetryDelay(retry, attempt);
2670
2853
  if (delay) {
2671
- await new Promise((resolve) => setTimeout(resolve, delay));
2672
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
2854
+ await waitForRetry(url, attempt + 1, delay, options, requestInit);
2855
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
2673
2856
  }
2674
2857
  }
2675
2858
  throw new ApiConnectionError({
@@ -2677,7 +2860,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
2677
2860
  });
2678
2861
  }
2679
2862
  }
2680
- __name(_doZodFetch, "_doZodFetch");
2863
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
2681
2864
  function castToError2(err) {
2682
2865
  if (err instanceof Error)
2683
2866
  return err;
@@ -2714,8 +2897,25 @@ function shouldRetry(response, attempt, retryOptions) {
2714
2897
  return shouldRetryForOptions();
2715
2898
  if (response.status === 409)
2716
2899
  return shouldRetryForOptions();
2717
- if (response.status === 429)
2900
+ if (response.status === 429) {
2901
+ if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
2902
+ return {
2903
+ retry: false
2904
+ };
2905
+ }
2906
+ const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
2907
+ if (resetAtUnixEpochMs) {
2908
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
2909
+ const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
2910
+ if (delay > 0) {
2911
+ return {
2912
+ retry: true,
2913
+ delay
2914
+ };
2915
+ }
2916
+ }
2718
2917
  return shouldRetryForOptions();
2918
+ }
2719
2919
  if (response.status >= 500)
2720
2920
  return shouldRetryForOptions();
2721
2921
  return {
@@ -2878,9 +3078,44 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
2878
3078
  }, "#fetchPage");
2879
3079
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
2880
3080
  var OffsetLimitPagePromise = _OffsetLimitPagePromise;
3081
+ async function waitForRetry(url, attempt, delay, options, requestInit, response) {
3082
+ if (options?.tracer) {
3083
+ const method = requestInit?.method ?? "GET";
3084
+ return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
3085
+ await new Promise((resolve) => setTimeout(resolve, delay));
3086
+ }, {
3087
+ attributes: {
3088
+ [SemanticInternalAttributes.STYLE_ICON]: "wait",
3089
+ ...accessoryAttributes({
3090
+ items: [
3091
+ {
3092
+ text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
3093
+ variant: "normal"
3094
+ }
3095
+ ],
3096
+ style: "codepath"
3097
+ })
3098
+ }
3099
+ });
3100
+ }
3101
+ await new Promise((resolve) => setTimeout(resolve, delay));
3102
+ }
3103
+ __name(waitForRetry, "waitForRetry");
3104
+ function isEmptyObj(obj) {
3105
+ if (!obj)
3106
+ return true;
3107
+ for (const _k in obj)
3108
+ return false;
3109
+ return true;
3110
+ }
3111
+ __name(isEmptyObj, "isEmptyObj");
3112
+ function hasOwn(obj, key) {
3113
+ return Object.prototype.hasOwnProperty.call(obj, key);
3114
+ }
3115
+ __name(hasOwn, "hasOwn");
2881
3116
 
2882
3117
  // src/v3/apiClient/index.ts
2883
- var zodFetchOptions = {
3118
+ var DEFAULT_ZOD_FETCH_OPTIONS = {
2884
3119
  retry: {
2885
3120
  maxAttempts: 3,
2886
3121
  minTimeoutInMs: 1e3,
@@ -2891,17 +3126,18 @@ var zodFetchOptions = {
2891
3126
  };
2892
3127
  var _getHeaders, getHeaders_fn;
2893
3128
  var _ApiClient = class _ApiClient {
2894
- constructor(baseUrl, accessToken) {
3129
+ constructor(baseUrl, accessToken, requestOptions = {}) {
2895
3130
  __privateAdd(this, _getHeaders);
2896
3131
  this.accessToken = accessToken;
2897
3132
  this.baseUrl = baseUrl.replace(/\/$/, "");
3133
+ this.defaultRequestOptions = mergeRequestOptions(DEFAULT_ZOD_FETCH_OPTIONS, requestOptions);
2898
3134
  }
2899
- async getRunResult(runId) {
3135
+ async getRunResult(runId, requestOptions) {
2900
3136
  try {
2901
3137
  return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
2902
3138
  method: "GET",
2903
3139
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2904
- }, zodFetchOptions);
3140
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2905
3141
  } catch (error) {
2906
3142
  if (error instanceof ApiError) {
2907
3143
  if (error.status === 404) {
@@ -2911,47 +3147,47 @@ var _ApiClient = class _ApiClient {
2911
3147
  throw error;
2912
3148
  }
2913
3149
  }
2914
- async getBatchResults(batchId) {
3150
+ async getBatchResults(batchId, requestOptions) {
2915
3151
  return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
2916
3152
  method: "GET",
2917
3153
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2918
- }, zodFetchOptions);
3154
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2919
3155
  }
2920
- triggerTask(taskId, body, options) {
3156
+ triggerTask(taskId, body, options, requestOptions) {
2921
3157
  const encodedTaskId = encodeURIComponent(taskId);
2922
3158
  return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
2923
3159
  method: "POST",
2924
3160
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2925
3161
  body: JSON.stringify(body)
2926
- }, zodFetchOptions);
3162
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2927
3163
  }
2928
- batchTriggerTask(taskId, body, options) {
3164
+ batchTriggerTask(taskId, body, options, requestOptions) {
2929
3165
  const encodedTaskId = encodeURIComponent(taskId);
2930
3166
  return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
2931
3167
  method: "POST",
2932
3168
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
2933
3169
  body: JSON.stringify(body)
2934
- }, zodFetchOptions);
3170
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2935
3171
  }
2936
- createUploadPayloadUrl(filename) {
3172
+ createUploadPayloadUrl(filename, requestOptions) {
2937
3173
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2938
3174
  method: "PUT",
2939
3175
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2940
- }, zodFetchOptions);
3176
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2941
3177
  }
2942
- getPayloadUrl(filename) {
3178
+ getPayloadUrl(filename, requestOptions) {
2943
3179
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
2944
3180
  method: "GET",
2945
3181
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2946
- }, zodFetchOptions);
3182
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2947
3183
  }
2948
- retrieveRun(runId) {
3184
+ retrieveRun(runId, requestOptions) {
2949
3185
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v3/runs/${runId}`, {
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
- listRuns(query) {
3190
+ listRuns(query, requestOptions) {
2955
3191
  const searchParams = createSearchQueryForListRuns(query);
2956
3192
  return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
2957
3193
  query: searchParams,
@@ -2961,9 +3197,9 @@ var _ApiClient = class _ApiClient {
2961
3197
  }, {
2962
3198
  method: "GET",
2963
3199
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2964
- }, zodFetchOptions);
3200
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2965
3201
  }
2966
- listProjectRuns(projectRef, query) {
3202
+ listProjectRuns(projectRef, query, requestOptions) {
2967
3203
  const searchParams = createSearchQueryForListRuns(query);
2968
3204
  if (query?.env) {
2969
3205
  searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
@@ -2976,35 +3212,35 @@ var _ApiClient = class _ApiClient {
2976
3212
  }, {
2977
3213
  method: "GET",
2978
3214
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2979
- }, zodFetchOptions);
3215
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2980
3216
  }
2981
- replayRun(runId) {
3217
+ replayRun(runId, requestOptions) {
2982
3218
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
2983
3219
  method: "POST",
2984
3220
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2985
- }, zodFetchOptions);
3221
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2986
3222
  }
2987
- cancelRun(runId) {
3223
+ cancelRun(runId, requestOptions) {
2988
3224
  return zodfetch(CanceledRunResponse, `${this.baseUrl}/api/v2/runs/${runId}/cancel`, {
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
- rescheduleRun(runId, body) {
3229
+ rescheduleRun(runId, body, requestOptions) {
2994
3230
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/reschedule`, {
2995
3231
  method: "POST",
2996
3232
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2997
3233
  body: JSON.stringify(body)
2998
- }, zodFetchOptions);
3234
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2999
3235
  }
3000
- createSchedule(options) {
3236
+ createSchedule(options, requestOptions) {
3001
3237
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
3002
3238
  method: "POST",
3003
3239
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3004
3240
  body: JSON.stringify(options)
3005
- });
3241
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3006
3242
  }
3007
- listSchedules(options) {
3243
+ listSchedules(options, requestOptions) {
3008
3244
  const searchParams = new URLSearchParams();
3009
3245
  if (options?.page) {
3010
3246
  searchParams.append("page", options.page.toString());
@@ -3018,77 +3254,77 @@ var _ApiClient = class _ApiClient {
3018
3254
  }, {
3019
3255
  method: "GET",
3020
3256
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3021
- });
3257
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3022
3258
  }
3023
- retrieveSchedule(scheduleId) {
3259
+ retrieveSchedule(scheduleId, requestOptions) {
3024
3260
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3025
3261
  method: "GET",
3026
3262
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3027
- });
3263
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3028
3264
  }
3029
- updateSchedule(scheduleId, options) {
3265
+ updateSchedule(scheduleId, options, requestOptions) {
3030
3266
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3031
3267
  method: "PUT",
3032
3268
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3033
3269
  body: JSON.stringify(options)
3034
- });
3270
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3035
3271
  }
3036
- deactivateSchedule(scheduleId) {
3272
+ deactivateSchedule(scheduleId, requestOptions) {
3037
3273
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/deactivate`, {
3038
3274
  method: "POST",
3039
3275
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3040
- });
3276
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3041
3277
  }
3042
- activateSchedule(scheduleId) {
3278
+ activateSchedule(scheduleId, requestOptions) {
3043
3279
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/activate`, {
3044
3280
  method: "POST",
3045
3281
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3046
- });
3282
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3047
3283
  }
3048
- deleteSchedule(scheduleId) {
3284
+ deleteSchedule(scheduleId, requestOptions) {
3049
3285
  return zodfetch(DeletedScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
3050
3286
  method: "DELETE",
3051
3287
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3052
- });
3288
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3053
3289
  }
3054
- listEnvVars(projectRef, slug) {
3290
+ listEnvVars(projectRef, slug, requestOptions) {
3055
3291
  return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3056
3292
  method: "GET",
3057
3293
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3058
- });
3294
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3059
3295
  }
3060
- importEnvVars(projectRef, slug, body) {
3296
+ importEnvVars(projectRef, slug, body, requestOptions) {
3061
3297
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
3062
3298
  method: "POST",
3063
3299
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3064
3300
  body: JSON.stringify(body)
3065
- });
3301
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3066
3302
  }
3067
- retrieveEnvVar(projectRef, slug, key) {
3303
+ retrieveEnvVar(projectRef, slug, key, requestOptions) {
3068
3304
  return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3069
3305
  method: "GET",
3070
3306
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3071
- });
3307
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3072
3308
  }
3073
- createEnvVar(projectRef, slug, body) {
3309
+ createEnvVar(projectRef, slug, body, requestOptions) {
3074
3310
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
3075
3311
  method: "POST",
3076
3312
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3077
3313
  body: JSON.stringify(body)
3078
- });
3314
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3079
3315
  }
3080
- updateEnvVar(projectRef, slug, key, body) {
3316
+ updateEnvVar(projectRef, slug, key, body, requestOptions) {
3081
3317
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3082
3318
  method: "PUT",
3083
3319
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
3084
3320
  body: JSON.stringify(body)
3085
- });
3321
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3086
3322
  }
3087
- deleteEnvVar(projectRef, slug, key) {
3323
+ deleteEnvVar(projectRef, slug, key, requestOptions) {
3088
3324
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
3089
3325
  method: "DELETE",
3090
3326
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
3091
- });
3327
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
3092
3328
  }
3093
3329
  };
3094
3330
  _getHeaders = new WeakSet();
@@ -3143,6 +3379,20 @@ function createSearchQueryForListRuns(query) {
3143
3379
  return searchParams;
3144
3380
  }
3145
3381
  __name(createSearchQueryForListRuns, "createSearchQueryForListRuns");
3382
+ function mergeRequestOptions(defaultOptions, options) {
3383
+ if (!options) {
3384
+ return defaultOptions;
3385
+ }
3386
+ return {
3387
+ ...defaultOptions,
3388
+ ...options,
3389
+ retry: {
3390
+ ...defaultOptions.retry,
3391
+ ...options.retry
3392
+ }
3393
+ };
3394
+ }
3395
+ __name(mergeRequestOptions, "mergeRequestOptions");
3146
3396
  var _SimpleClock = class _SimpleClock {
3147
3397
  preciseNow() {
3148
3398
  const now = new PreciseDate();
@@ -3235,128 +3485,6 @@ function calculateAttributeValueLength(value) {
3235
3485
  return 0;
3236
3486
  }
3237
3487
  __name(calculateAttributeValueLength, "calculateAttributeValueLength");
3238
-
3239
- // src/v3/utils/flattenAttributes.ts
3240
- var NULL_SENTINEL = "$@null((";
3241
- function flattenAttributes(obj, prefix) {
3242
- const result = {};
3243
- if (obj === void 0) {
3244
- return result;
3245
- }
3246
- if (obj === null) {
3247
- result[prefix || ""] = NULL_SENTINEL;
3248
- return result;
3249
- }
3250
- if (typeof obj === "string") {
3251
- result[prefix || ""] = obj;
3252
- return result;
3253
- }
3254
- if (typeof obj === "number") {
3255
- result[prefix || ""] = obj;
3256
- return result;
3257
- }
3258
- if (typeof obj === "boolean") {
3259
- result[prefix || ""] = obj;
3260
- return result;
3261
- }
3262
- for (const [key, value] of Object.entries(obj)) {
3263
- const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
3264
- if (Array.isArray(value)) {
3265
- for (let i = 0; i < value.length; i++) {
3266
- if (typeof value[i] === "object" && value[i] !== null) {
3267
- Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
3268
- } else {
3269
- if (value[i] === null) {
3270
- result[`${newPrefix}.[${i}]`] = NULL_SENTINEL;
3271
- } else {
3272
- result[`${newPrefix}.[${i}]`] = value[i];
3273
- }
3274
- }
3275
- }
3276
- } else if (isRecord(value)) {
3277
- Object.assign(result, flattenAttributes(value, newPrefix));
3278
- } else {
3279
- if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
3280
- result[newPrefix] = value;
3281
- } else if (value === null) {
3282
- result[newPrefix] = NULL_SENTINEL;
3283
- }
3284
- }
3285
- }
3286
- return result;
3287
- }
3288
- __name(flattenAttributes, "flattenAttributes");
3289
- function isRecord(value) {
3290
- return value !== null && typeof value === "object" && !Array.isArray(value);
3291
- }
3292
- __name(isRecord, "isRecord");
3293
- function unflattenAttributes(obj) {
3294
- if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
3295
- return obj;
3296
- }
3297
- if (typeof obj === "object" && obj !== null && Object.keys(obj).length === 1 && Object.keys(obj)[0] === "") {
3298
- return rehydrateNull(obj[""]);
3299
- }
3300
- if (Object.keys(obj).length === 0) {
3301
- return;
3302
- }
3303
- const result = {};
3304
- for (const [key, value] of Object.entries(obj)) {
3305
- const parts = key.split(".").reduce((acc, part) => {
3306
- if (part.includes("[")) {
3307
- const subparts = part.split(/\[|\]/).filter((p) => p !== "");
3308
- acc.push(...subparts);
3309
- } else {
3310
- acc.push(part);
3311
- }
3312
- return acc;
3313
- }, []);
3314
- let current = result;
3315
- for (let i = 0; i < parts.length - 1; i++) {
3316
- const part = parts[i];
3317
- const nextPart = parts[i + 1];
3318
- const isArray = /^\d+$/.test(nextPart);
3319
- if (isArray && !Array.isArray(current[part])) {
3320
- current[part] = [];
3321
- } else if (!isArray && current[part] === void 0) {
3322
- current[part] = {};
3323
- }
3324
- current = current[part];
3325
- }
3326
- const lastPart = parts[parts.length - 1];
3327
- current[lastPart] = rehydrateNull(value);
3328
- }
3329
- if (Object.keys(result).every((k) => /^\d+$/.test(k))) {
3330
- const maxIndex = Math.max(...Object.keys(result).map((k) => parseInt(k)));
3331
- const arrayResult = Array(maxIndex + 1);
3332
- for (const key in result) {
3333
- arrayResult[parseInt(key)] = result[key];
3334
- }
3335
- return arrayResult;
3336
- }
3337
- return result;
3338
- }
3339
- __name(unflattenAttributes, "unflattenAttributes");
3340
- function primitiveValueOrflattenedAttributes(obj, prefix) {
3341
- if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
3342
- return obj;
3343
- }
3344
- const attributes = flattenAttributes(obj, prefix);
3345
- if (prefix !== void 0 && typeof attributes[prefix] !== "undefined" && attributes[prefix] !== null) {
3346
- return attributes[prefix];
3347
- }
3348
- return attributes;
3349
- }
3350
- __name(primitiveValueOrflattenedAttributes, "primitiveValueOrflattenedAttributes");
3351
- function rehydrateNull(value) {
3352
- if (value === NULL_SENTINEL) {
3353
- return null;
3354
- }
3355
- return value;
3356
- }
3357
- __name(rehydrateNull, "rehydrateNull");
3358
-
3359
- // src/v3/logger/taskLogger.ts
3360
3488
  var _NoopTaskLogger = class _NoopTaskLogger {
3361
3489
  debug() {
3362
3490
  }
@@ -3801,14 +3929,16 @@ var _TriggerTracer = class _TriggerTracer {
3801
3929
  attributes,
3802
3930
  startTime: clock.preciseNow()
3803
3931
  }, parentContext, async (span) => {
3804
- this.tracer.startSpan(name, {
3805
- ...options,
3806
- attributes: {
3807
- ...attributes,
3808
- [SemanticInternalAttributes.SPAN_PARTIAL]: true,
3809
- [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3810
- }
3811
- }, parentContext).end();
3932
+ if (taskContext.ctx) {
3933
+ this.tracer.startSpan(name, {
3934
+ ...options,
3935
+ attributes: {
3936
+ ...attributes,
3937
+ [SemanticInternalAttributes.SPAN_PARTIAL]: true,
3938
+ [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3939
+ }
3940
+ }, parentContext).end();
3941
+ }
3812
3942
  const usageMeasurement = usage.start();
3813
3943
  try {
3814
3944
  return await fn(span);
@@ -3821,12 +3951,14 @@ var _TriggerTracer = class _TriggerTracer {
3821
3951
  });
3822
3952
  throw e;
3823
3953
  } finally {
3824
- const usageSample = usage.stop(usageMeasurement);
3825
- const machine = taskContext.ctx?.machine;
3826
- span.setAttributes({
3827
- [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
3828
- [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
3829
- });
3954
+ if (taskContext.ctx) {
3955
+ const usageSample = usage.stop(usageMeasurement);
3956
+ const machine = taskContext.ctx.machine;
3957
+ span.setAttributes({
3958
+ [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
3959
+ [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
3960
+ });
3961
+ }
3830
3962
  span.end(clock.preciseNow());
3831
3963
  }
3832
3964
  });
@@ -4018,12 +4150,6 @@ function omit(obj, ...keys) {
4018
4150
  }
4019
4151
  __name(omit, "omit");
4020
4152
 
4021
- // src/v3/utils/styleAttributes.ts
4022
- function accessoryAttributes(accessory) {
4023
- return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
4024
- }
4025
- __name(accessoryAttributes, "accessoryAttributes");
4026
-
4027
4153
  // src/v3/utils/detectDependencyVersion.ts
4028
4154
  function detectDependencyVersion(dependency) {
4029
4155
  return dependencies[dependency];
@@ -4299,6 +4425,6 @@ function safeJsonParse2(value) {
4299
4425
  }
4300
4426
  __name(safeJsonParse2, "safeJsonParse");
4301
4427
 
4302
- export { ApiClient, ApiConnectionError, ApiError, AttemptStatus, AuthenticationError, BackgroundWorkerClientMessages, BackgroundWorkerMetadata, BackgroundWorkerProperties, BackgroundWorkerServerMessages, BadRequestError, BatchTaskRunExecutionResult, BatchTriggerTaskRequestBody, BatchTriggerTaskResponse, CanceledRunResponse, CancellationSpanEvent, ClientToSharedQueueMessages, Config, ConflictError, CoordinatorSocketData, CoordinatorToPlatformMessages, CoordinatorToProdWorkerMessages, CreateAuthorizationCodeResponseSchema, CreateBackgroundWorkerRequestBody, CreateBackgroundWorkerResponse, CreateEnvironmentVariableRequestBody, CreateScheduleOptions, CreateUploadPayloadUrlResponseBody, CursorPage, DeletedScheduleObject, DeploymentErrorData, EnvironmentType, EnvironmentVariable, EnvironmentVariableResponseBody, EnvironmentVariableValue, EnvironmentVariables, EventFilter, ExceptionEventProperties, ExceptionSpanEvent, ExternalBuildData, FetchRetryBackoffStrategy, FetchRetryByStatusOptions, FetchRetryHeadersStrategy, FetchRetryOptions, FetchRetryStrategy, FetchTimeoutOptions, FixedWindowRateLimit, GetBatchResponseBody, GetDeploymentResponseBody, GetEnvironmentVariablesResponseBody, GetPersonalAccessTokenRequestSchema, GetPersonalAccessTokenResponseSchema, GetProjectEnvResponse, GetProjectResponseBody, GetProjectsResponseBody, ImageDetailsMetadata, ImportEnvironmentVariablesRequestBody, InitializeDeploymentRequestBody, InitializeDeploymentResponseBody, InternalServerError, ListRunResponse, ListRunResponseItem, ListScheduleOptions, ListSchedulesResult, MachineConfig, MachineCpu, MachineMemory, MachinePreset, MachinePresetName, NULL_SENTINEL, NotFoundError, OFFLOAD_IO_PACKET_LENGTH_LIMIT, OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT, OTEL_LINK_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_EVENT_COUNT_LIMIT, OffsetLimitPage, OtherSpanEvent, PRIMARY_VARIANT, PermissionDeniedError, PlatformToCoordinatorMessages, PlatformToProviderMessages, PostStartCauses, PreStopCauses, ProdChildToWorkerMessages, ProdTaskRunExecution, ProdTaskRunExecutionPayload, ProdWorkerSocketData, ProdWorkerToChildMessages, ProdWorkerToCoordinatorMessages, ProviderToPlatformMessages, QueueOptions, RateLimitError, RateLimitOptions, ReplayRunResponse, RescheduleRunRequestBody, RetrieveRunResponse, RetryOptions, RunEnvironmentDetails, RunScheduleDetails, RunStatus, ScheduleGenerator, ScheduleObject, ScheduledTaskPayload, SemanticInternalAttributes, SerializedError, SharedQueueToClientMessages, SlidingWindowRateLimit, SpanEvent, SpanEvents, SpanMessagingEvent, StartDeploymentIndexingRequestBody, StartDeploymentIndexingResponseBody, TaskEventStyle, TaskFileMetadata, TaskMetadata, TaskMetadataFailedToParseData, TaskMetadataWithFilePath, TaskResource, TaskRun, TaskRunBuiltInError, TaskRunContext, TaskRunCustomErrorObject, TaskRunError, TaskRunErrorCodes, TaskRunExecution, TaskRunExecutionAttempt, TaskRunExecutionBatch, TaskRunExecutionEnvironment, TaskRunExecutionLazyAttemptPayload, TaskRunExecutionOrganization, TaskRunExecutionPayload, TaskRunExecutionProject, TaskRunExecutionQueue, TaskRunExecutionResult, TaskRunExecutionRetry, TaskRunExecutionTask, TaskRunExecutionUsage, TaskRunFailedExecutionResult, TaskRunInternalError, TaskRunStringError, TaskRunSuccessfulExecutionResult, TimezonesResult, TriggerTaskRequestBody, TriggerTaskResponse, TriggerTracer, UncaughtExceptionMessage, UnprocessableEntityError, UpdateEnvironmentVariableRequestBody, UpdateScheduleOptions, WaitReason, WhoAmIResponseSchema, accessoryAttributes, apiClientManager, calculateNextRetryDelay, calculateResetAt2 as calculateResetAt, childToWorkerMessages, clientWebsocketMessages, clock, conditionallyExportPacket, conditionallyImportPacket, correctErrorStackTrace, createErrorTaskError, createJsonErrorObject, createPacketAttributes, createPacketAttributesAsJson, defaultFetchRetryOptions, defaultRetryOptions, detectDependencyVersion, eventFilterMatches, flattenAttributes, formatDuration, formatDurationInDays, formatDurationMilliseconds, formatDurationNanoseconds, groupTaskMetadataIssuesByTask, imposeAttributeLimits, isCancellationSpanEvent, isExceptionSpanEvent, logger, millisecondsToNanoseconds, nanosecondsToMilliseconds, omit, packetRequiresOffloading, parseError, parsePacket, prettyPrintPacket, primitiveValueOrflattenedAttributes, runtime, serverWebsocketMessages, stringPatternMatchers, stringifyIO, taskCatalog, taskContext, unflattenAttributes, usage, workerToChildMessages };
4428
+ export { AbortTaskRunError, ApiClient, ApiConnectionError, ApiError, AttemptStatus, AuthenticationError, BackgroundWorkerClientMessages, BackgroundWorkerMetadata, BackgroundWorkerProperties, BackgroundWorkerServerMessages, BadRequestError, BatchTaskRunExecutionResult, BatchTriggerTaskRequestBody, BatchTriggerTaskResponse, CanceledRunResponse, CancellationSpanEvent, ClientToSharedQueueMessages, Config, ConflictError, CoordinatorSocketData, CoordinatorToPlatformMessages, CoordinatorToProdWorkerMessages, CreateAuthorizationCodeResponseSchema, CreateBackgroundWorkerRequestBody, CreateBackgroundWorkerResponse, CreateEnvironmentVariableRequestBody, CreateScheduleOptions, CreateUploadPayloadUrlResponseBody, CursorPage, DeletedScheduleObject, DeploymentErrorData, EnvironmentType, EnvironmentVariable, EnvironmentVariableResponseBody, EnvironmentVariableValue, EnvironmentVariables, EventFilter, ExceptionEventProperties, ExceptionSpanEvent, ExternalBuildData, FetchRetryBackoffStrategy, FetchRetryByStatusOptions, FetchRetryHeadersStrategy, FetchRetryOptions, FetchRetryStrategy, FetchTimeoutOptions, FixedWindowRateLimit, GetBatchResponseBody, GetDeploymentResponseBody, GetEnvironmentVariablesResponseBody, GetPersonalAccessTokenRequestSchema, GetPersonalAccessTokenResponseSchema, GetProjectEnvResponse, GetProjectResponseBody, GetProjectsResponseBody, ImageDetailsMetadata, ImportEnvironmentVariablesRequestBody, InitializeDeploymentRequestBody, InitializeDeploymentResponseBody, InternalServerError, ListRunResponse, ListRunResponseItem, ListScheduleOptions, ListSchedulesResult, MachineConfig, MachineCpu, MachineMemory, MachinePreset, MachinePresetName, NULL_SENTINEL, NotFoundError, OFFLOAD_IO_PACKET_LENGTH_LIMIT, OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT, OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT, OTEL_LINK_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_COUNT_LIMIT, OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT, OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT, OTEL_SPAN_EVENT_COUNT_LIMIT, OffsetLimitPage, OtherSpanEvent, PRIMARY_VARIANT, PermissionDeniedError, PlatformToCoordinatorMessages, PlatformToProviderMessages, PostStartCauses, PreStopCauses, ProdChildToWorkerMessages, ProdTaskRunExecution, ProdTaskRunExecutionPayload, ProdWorkerSocketData, ProdWorkerToChildMessages, ProdWorkerToCoordinatorMessages, ProviderToPlatformMessages, QueueOptions, RateLimitError, RateLimitOptions, ReplayRunResponse, RescheduleRunRequestBody, RetrieveRunResponse, RetryOptions, RunEnvironmentDetails, RunScheduleDetails, RunStatus, ScheduleGenerator, ScheduleObject, ScheduledTaskPayload, SemanticInternalAttributes, SerializedError, SharedQueueToClientMessages, SlidingWindowRateLimit, SpanEvent, SpanEvents, SpanMessagingEvent, StartDeploymentIndexingRequestBody, StartDeploymentIndexingResponseBody, TaskEventStyle, TaskFileMetadata, TaskMetadata, TaskMetadataFailedToParseData, TaskMetadataWithFilePath, TaskResource, TaskRun, TaskRunBuiltInError, TaskRunContext, TaskRunCustomErrorObject, TaskRunError, TaskRunErrorCodes, TaskRunExecution, TaskRunExecutionAttempt, TaskRunExecutionBatch, TaskRunExecutionEnvironment, TaskRunExecutionLazyAttemptPayload, TaskRunExecutionOrganization, TaskRunExecutionPayload, TaskRunExecutionProject, TaskRunExecutionQueue, TaskRunExecutionResult, TaskRunExecutionRetry, TaskRunExecutionTask, TaskRunExecutionUsage, TaskRunFailedExecutionResult, TaskRunInternalError, TaskRunStringError, TaskRunSuccessfulExecutionResult, TimezonesResult, TriggerTaskRequestBody, TriggerTaskResponse, TriggerTracer, UncaughtExceptionMessage, UnprocessableEntityError, UpdateEnvironmentVariableRequestBody, UpdateScheduleOptions, WaitReason, WhoAmIResponseSchema, accessoryAttributes, apiClientManager, calculateNextRetryDelay, calculateResetAt2 as calculateResetAt, childToWorkerMessages, clientWebsocketMessages, clock, conditionallyExportPacket, conditionallyImportPacket, correctErrorStackTrace, createErrorTaskError, createJsonErrorObject, createPacketAttributes, createPacketAttributesAsJson, defaultFetchRetryOptions, defaultRetryOptions, detectDependencyVersion, eventFilterMatches, flattenAttributes, formatDuration, formatDurationInDays, formatDurationMilliseconds, formatDurationNanoseconds, groupTaskMetadataIssuesByTask, imposeAttributeLimits, isCancellationSpanEvent, isExceptionSpanEvent, isRequestOptions, logger, mergeRequestOptions, millisecondsToNanoseconds, nanosecondsToMilliseconds, omit, packetRequiresOffloading, parseError, parsePacket, prettyPrintPacket, primitiveValueOrflattenedAttributes, runtime, serverWebsocketMessages, stringPatternMatchers, stringifyIO, taskCatalog, taskContext, unflattenAttributes, usage, workerToChildMessages };
4303
4429
  //# sourceMappingURL=out.js.map
4304
4430
  //# sourceMappingURL=index.mjs.map