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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{catalog-9G8AqnI9.d.ts → catalog-N-X0Te3W.d.mts} +5 -23
  2. package/dist/{catalog-Y0mRLMtJ.d.mts → catalog-NxVZnWZh.d.ts} +5 -23
  3. package/dist/{common-55Mqj8JP.d.mts → common-fIyU5pmz.d.mts} +13 -0
  4. package/dist/{common-55Mqj8JP.d.ts → common-fIyU5pmz.d.ts} +13 -0
  5. package/dist/{manager-6NRInm7C.d.ts → manager-2ZQ3_twq.d.ts} +1 -1
  6. package/dist/{manager-2AqSY67c.d.mts → manager-X_HrWQ7_.d.mts} +1 -1
  7. package/dist/{messages-nXkzt5CT.d.mts → messages-Sggr4tid.d.mts} +162 -0
  8. package/dist/{messages-nXkzt5CT.d.ts → messages-Sggr4tid.d.ts} +162 -0
  9. package/dist/{schemas-CeAee_C2.d.mts → schemas-Zy7mGFgD.d.mts} +19 -0
  10. package/dist/{schemas-CeAee_C2.d.ts → schemas-Zy7mGFgD.d.ts} +19 -0
  11. package/dist/tracer-N0p2Fuuv.d.mts +23 -0
  12. package/dist/tracer-N0p2Fuuv.d.ts +23 -0
  13. package/dist/v3/dev/index.d.mts +2 -2
  14. package/dist/v3/dev/index.d.ts +2 -2
  15. package/dist/v3/index.d.mts +50 -38
  16. package/dist/v3/index.d.ts +50 -38
  17. package/dist/v3/index.js +470 -303
  18. package/dist/v3/index.js.map +1 -1
  19. package/dist/v3/index.mjs +467 -304
  20. package/dist/v3/index.mjs.map +1 -1
  21. package/dist/v3/otel/index.js +15 -5
  22. package/dist/v3/otel/index.js.map +1 -1
  23. package/dist/v3/otel/index.mjs +15 -5
  24. package/dist/v3/otel/index.mjs.map +1 -1
  25. package/dist/v3/prod/index.d.mts +3 -3
  26. package/dist/v3/prod/index.d.ts +3 -3
  27. package/dist/v3/schemas/index.d.mts +16 -4
  28. package/dist/v3/schemas/index.d.ts +16 -4
  29. package/dist/v3/schemas/index.js +3 -1
  30. package/dist/v3/schemas/index.js.map +1 -1
  31. package/dist/v3/schemas/index.mjs +3 -1
  32. package/dist/v3/schemas/index.mjs.map +1 -1
  33. package/dist/v3/workers/index.d.mts +7 -6
  34. package/dist/v3/workers/index.d.ts +7 -6
  35. package/dist/v3/workers/index.js +250 -96
  36. package/dist/v3/workers/index.js.map +1 -1
  37. package/dist/v3/workers/index.mjs +250 -96
  38. package/dist/v3/workers/index.mjs.map +1 -1
  39. package/dist/v3/zodfetch.d.mts +15 -2
  40. package/dist/v3/zodfetch.d.ts +15 -2
  41. package/dist/v3/zodfetch.js +248 -28
  42. package/dist/v3/zodfetch.js.map +1 -1
  43. package/dist/v3/zodfetch.mjs +246 -29
  44. package/dist/v3/zodfetch.mjs.map +1 -1
  45. package/package.json +1 -1
@@ -1,12 +1,13 @@
1
1
  import * as logsAPI from '@opentelemetry/api-logs';
2
2
  import { TracingSDK } from '../otel/index.mjs';
3
3
  export { TracingDiagnosticLogLevel, recordSpanException } from '../otel/index.mjs';
4
- import { b as TaskRunExecution, T as TaskRunExecutionResult } from '../../common-55Mqj8JP.mjs';
5
- import { B as BackgroundWorkerProperties } from '../../messages-nXkzt5CT.mjs';
6
- import { C as Config, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from '../../schemas-CeAee_C2.mjs';
7
- import { T as TriggerTracer, P as ProjectConfig, H as HandleErrorFunction, a as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, b as ClockTime, c as TaskCatalog, d as UsageManager, e as UsageSample } from '../../catalog-Y0mRLMtJ.mjs';
8
- export { O as OtelTaskLogger, l as logLevels, u as usage } from '../../catalog-Y0mRLMtJ.mjs';
9
- export { R as RuntimeManager } from '../../manager-2AqSY67c.mjs';
4
+ import { b as TaskRunExecution, T as TaskRunExecutionResult } from '../../common-fIyU5pmz.mjs';
5
+ import { B as BackgroundWorkerProperties } from '../../messages-Sggr4tid.mjs';
6
+ import { C as Config, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from '../../schemas-Zy7mGFgD.mjs';
7
+ import { P as ProjectConfig, H as HandleErrorFunction, T as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, a as ClockTime, b as TaskCatalog, c as UsageManager, d as UsageSample } from '../../catalog-N-X0Te3W.mjs';
8
+ export { O as OtelTaskLogger, l as logLevels, u as usage } from '../../catalog-N-X0Te3W.mjs';
9
+ import { T as TriggerTracer } from '../../tracer-N0p2Fuuv.mjs';
10
+ export { R as RuntimeManager } from '../../manager-X_HrWQ7_.mjs';
10
11
  import { PreciseDate } from '@google-cloud/precise-date';
11
12
  import { LogRecordProcessor, LogRecord } from '@opentelemetry/sdk-logs';
12
13
  import { SpanProcessor, Span } from '@opentelemetry/sdk-trace-base';
@@ -1,12 +1,13 @@
1
1
  import * as logsAPI from '@opentelemetry/api-logs';
2
2
  import { TracingSDK } from '../otel/index.js';
3
3
  export { TracingDiagnosticLogLevel, recordSpanException } from '../otel/index.js';
4
- import { b as TaskRunExecution, T as TaskRunExecutionResult } from '../../common-55Mqj8JP.js';
5
- import { B as BackgroundWorkerProperties } from '../../messages-nXkzt5CT.js';
6
- import { C as Config, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from '../../schemas-CeAee_C2.js';
7
- import { T as TriggerTracer, P as ProjectConfig, H as HandleErrorFunction, a as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, b as ClockTime, c as TaskCatalog, d as UsageManager, e as UsageSample } from '../../catalog-9G8AqnI9.js';
8
- export { O as OtelTaskLogger, l as logLevels, u as usage } from '../../catalog-9G8AqnI9.js';
9
- export { R as RuntimeManager } from '../../manager-6NRInm7C.js';
4
+ import { b as TaskRunExecution, T as TaskRunExecutionResult } from '../../common-fIyU5pmz.js';
5
+ import { B as BackgroundWorkerProperties } from '../../messages-Sggr4tid.js';
6
+ import { C as Config, T as TaskFileMetadata, a as TaskMetadataWithFilePath } from '../../schemas-Zy7mGFgD.js';
7
+ import { P as ProjectConfig, H as HandleErrorFunction, T as TaskMetadataWithFunctions, U as UsageMeasurement, C as Clock, a as ClockTime, b as TaskCatalog, c as UsageManager, d as UsageSample } from '../../catalog-NxVZnWZh.js';
8
+ export { O as OtelTaskLogger, l as logLevels, u as usage } from '../../catalog-NxVZnWZh.js';
9
+ import { T as TriggerTracer } from '../../tracer-N0p2Fuuv.js';
10
+ export { R as RuntimeManager } from '../../manager-2ZQ3_twq.js';
10
11
  import { PreciseDate } from '@google-cloud/precise-date';
11
12
  import { LogRecordProcessor, LogRecord } from '@opentelemetry/sdk-logs';
12
13
  import { SpanProcessor, Span } from '@opentelemetry/sdk-trace-base';
@@ -76,6 +76,39 @@ var SerializedError = zod.z.object({
76
76
  name: zod.z.string().optional(),
77
77
  stackTrace: zod.z.string().optional()
78
78
  });
79
+ function sanitizeError(error) {
80
+ switch (error.type) {
81
+ case "BUILT_IN_ERROR": {
82
+ return {
83
+ type: "BUILT_IN_ERROR",
84
+ message: error.message?.replace(/\0/g, ""),
85
+ name: error.name?.replace(/\0/g, ""),
86
+ stackTrace: error.stackTrace?.replace(/\0/g, "")
87
+ };
88
+ }
89
+ case "STRING_ERROR": {
90
+ return {
91
+ type: "STRING_ERROR",
92
+ raw: error.raw.replace(/\0/g, "")
93
+ };
94
+ }
95
+ case "CUSTOM_ERROR": {
96
+ return {
97
+ type: "CUSTOM_ERROR",
98
+ raw: error.raw.replace(/\0/g, "")
99
+ };
100
+ }
101
+ case "INTERNAL_ERROR": {
102
+ return {
103
+ type: "INTERNAL_ERROR",
104
+ code: error.code,
105
+ message: error.message?.replace(/\0/g, ""),
106
+ stackTrace: error.stackTrace?.replace(/\0/g, "")
107
+ };
108
+ }
109
+ }
110
+ }
111
+ __name(sanitizeError, "sanitizeError");
79
112
 
80
113
  // src/v3/limits.ts
81
114
  var OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 256;
@@ -138,7 +171,10 @@ var SemanticInternalAttributes = {
138
171
  LINK_TITLE: "$link.title",
139
172
  IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
140
173
  USAGE_DURATION_MS: "$usage.durationMs",
141
- USAGE_COST_IN_CENTS: "$usage.costInCents"
174
+ USAGE_COST_IN_CENTS: "$usage.costInCents",
175
+ RATE_LIMIT_LIMIT: "response.rateLimit.limit",
176
+ RATE_LIMIT_REMAINING: "response.rateLimit.remaining",
177
+ RATE_LIMIT_RESET: "response.rateLimit.reset"
142
178
  };
143
179
 
144
180
  // src/v3/utils/flattenAttributes.ts
@@ -370,7 +406,7 @@ function getEnvVar(name) {
370
406
  __name(getEnvVar, "getEnvVar");
371
407
 
372
408
  // package.json
373
- var version = "3.0.0-beta.46";
409
+ var version = "3.0.0-beta.47";
374
410
 
375
411
  // src/v3/otel/tracingSDK.ts
376
412
  var _a;
@@ -511,17 +547,24 @@ __name(setLogLevel, "setLogLevel");
511
547
  // src/v3/otel/index.ts
512
548
  function recordSpanException(span, error) {
513
549
  if (error instanceof Error) {
514
- span.recordException(error);
550
+ span.recordException(sanitizeSpanError(error));
515
551
  } else if (typeof error === "string") {
516
- span.recordException(new Error(error));
552
+ span.recordException(error.replace(/\0/g, ""));
517
553
  } else {
518
- span.recordException(new Error(JSON.stringify(error)));
554
+ span.recordException(JSON.stringify(error).replace(/\0/g, ""));
519
555
  }
520
556
  span.setStatus({
521
557
  code: api.SpanStatusCode.ERROR
522
558
  });
523
559
  }
524
560
  __name(recordSpanException, "recordSpanException");
561
+ function sanitizeSpanError(error) {
562
+ const sanitizedError = new Error(error.message.replace(/\0/g, ""));
563
+ sanitizedError.name = error.name.replace(/\0/g, "");
564
+ sanitizedError.stack = error.stack?.replace(/\0/g, "");
565
+ return sanitizedError;
566
+ }
567
+ __name(sanitizeSpanError, "sanitizeSpanError");
525
568
  var MachineCpu = zod.z.union([
526
569
  zod.z.literal(0.25),
527
570
  zod.z.literal(0.5),
@@ -621,6 +664,7 @@ var TaskRun = zod.z.object({
621
664
  createdAt: zod.z.coerce.date(),
622
665
  startedAt: zod.z.coerce.date().default(() => /* @__PURE__ */ new Date()),
623
666
  idempotencyKey: zod.z.string().optional(),
667
+ maxAttempts: zod.z.number().optional(),
624
668
  durationMs: zod.z.number().default(0),
625
669
  costInCents: zod.z.number().default(0),
626
670
  baseCostInCents: zod.z.number().default(0)
@@ -988,7 +1032,8 @@ var TriggerTaskRequestBody = zod.z.object({
988
1032
  test: zod.z.boolean().optional(),
989
1033
  payloadType: zod.z.string().optional(),
990
1034
  delay: zod.z.string().or(zod.z.coerce.date()).optional(),
991
- ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional()
1035
+ ttl: zod.z.string().or(zod.z.number().nonnegative().int()).optional(),
1036
+ maxAttempts: zod.z.number().int().optional()
992
1037
  }).optional()
993
1038
  });
994
1039
  var TriggerTaskResponse = zod.z.object({
@@ -1318,10 +1363,34 @@ var EnvironmentVariable = zod.z.object({
1318
1363
  });
1319
1364
  var EnvironmentVariables = zod.z.array(EnvironmentVariable);
1320
1365
 
1366
+ // src/v3/utils/retries.ts
1367
+ var defaultRetryOptions = {
1368
+ maxAttempts: 3,
1369
+ factor: 2,
1370
+ minTimeoutInMs: 1e3,
1371
+ maxTimeoutInMs: 6e4,
1372
+ randomize: true
1373
+ };
1374
+ function calculateNextRetryDelay(options, attempt) {
1375
+ const opts = {
1376
+ ...defaultRetryOptions,
1377
+ ...options
1378
+ };
1379
+ if (attempt >= opts.maxAttempts) {
1380
+ return;
1381
+ }
1382
+ const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
1383
+ const random = randomize ? Math.random() + 1 : 1;
1384
+ const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
1385
+ return Math.round(timeout);
1386
+ }
1387
+ __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1388
+
1321
1389
  // src/v3/apiClient/errors.ts
1322
1390
  var _ApiError = class _ApiError extends Error {
1323
1391
  constructor(status, error, message, headers) {
1324
1392
  super(`${_ApiError.makeMessage(status, error, message)}`);
1393
+ this.name = "TriggerApiError";
1325
1394
  this.status = status;
1326
1395
  this.headers = headers;
1327
1396
  const data = error;
@@ -1442,6 +1511,16 @@ var _RateLimitError = class _RateLimitError extends ApiError {
1442
1511
  super(...arguments);
1443
1512
  __publicField(this, "status", 429);
1444
1513
  }
1514
+ get millisecondsUntilReset() {
1515
+ const resetAtUnixEpochMs = (this.headers ?? {})["x-ratelimit-reset"];
1516
+ if (typeof resetAtUnixEpochMs === "string") {
1517
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
1518
+ if (isNaN(resetAtUnixEpoch)) {
1519
+ return;
1520
+ }
1521
+ return Math.max(resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 2e3), 0);
1522
+ }
1523
+ }
1445
1524
  };
1446
1525
  __name(_RateLimitError, "RateLimitError");
1447
1526
  var RateLimitError = _RateLimitError;
@@ -1456,28 +1535,11 @@ function castToError(err) {
1456
1535
  }
1457
1536
  __name(castToError, "castToError");
1458
1537
 
1459
- // src/v3/utils/retries.ts
1460
- var defaultRetryOptions = {
1461
- maxAttempts: 3,
1462
- factor: 2,
1463
- minTimeoutInMs: 1e3,
1464
- maxTimeoutInMs: 6e4,
1465
- randomize: true
1466
- };
1467
- function calculateNextRetryDelay(options, attempt) {
1468
- const opts = {
1469
- ...defaultRetryOptions,
1470
- ...options
1471
- };
1472
- if (attempt >= opts.maxAttempts) {
1473
- return;
1474
- }
1475
- const { factor, minTimeoutInMs, maxTimeoutInMs, randomize } = opts;
1476
- const random = randomize ? Math.random() + 1 : 1;
1477
- const timeout = Math.min(maxTimeoutInMs, random * minTimeoutInMs * Math.pow(factor, attempt - 1));
1478
- return Math.round(timeout);
1538
+ // src/v3/utils/styleAttributes.ts
1539
+ function accessoryAttributes(accessory) {
1540
+ return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
1479
1541
  }
1480
- __name(calculateNextRetryDelay, "calculateNextRetryDelay");
1542
+ __name(accessoryAttributes, "accessoryAttributes");
1481
1543
 
1482
1544
  // src/v3/apiClient/pagination.ts
1483
1545
  var _CursorPage = class _CursorPage {
@@ -1637,16 +1699,47 @@ function zodfetchOffsetLimitPage(schema, url, params, requestInit, options) {
1637
1699
  return new OffsetLimitPagePromise(fetchResult, schema, url, params, requestInit, options);
1638
1700
  }
1639
1701
  __name(zodfetchOffsetLimitPage, "zodfetchOffsetLimitPage");
1640
- async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1702
+ async function traceZodFetch(params, callback) {
1703
+ if (!params.options?.tracer) {
1704
+ return callback();
1705
+ }
1706
+ const url = new URL(params.url);
1707
+ const method = params.requestInit?.method ?? "GET";
1708
+ const name = params.options.name ?? `${method} ${url.pathname}`;
1709
+ return await params.options.tracer.startActiveSpan(name, async (span) => {
1710
+ return await callback(span);
1711
+ }, {
1712
+ attributes: {
1713
+ [SemanticInternalAttributes.STYLE_ICON]: params.options?.icon ?? "api",
1714
+ ...params.options.attributes
1715
+ }
1716
+ });
1717
+ }
1718
+ __name(traceZodFetch, "traceZodFetch");
1719
+ async function _doZodFetch(schema, url, requestInit, options) {
1720
+ const $requestInit = await requestInit;
1721
+ return traceZodFetch({
1722
+ url,
1723
+ requestInit: $requestInit,
1724
+ options
1725
+ }, async (span) => {
1726
+ const result = await _doZodFetchWithRetries(schema, url, $requestInit, options);
1727
+ if (options?.onResponseBody && span) {
1728
+ options.onResponseBody(result.data, span);
1729
+ }
1730
+ return result;
1731
+ });
1732
+ }
1733
+ __name(_doZodFetch, "_doZodFetch");
1734
+ async function _doZodFetchWithRetries(schema, url, requestInit, options, attempt = 1) {
1641
1735
  try {
1642
- const $requestInit = await requestInit;
1643
- const response = await fetch(url, requestInitWithCache($requestInit));
1736
+ const response = await fetch(url, requestInitWithCache(requestInit));
1644
1737
  const responseHeaders = createResponseHeaders(response.headers);
1645
1738
  if (!response.ok) {
1646
1739
  const retryResult = shouldRetry(response, attempt, options?.retry);
1647
1740
  if (retryResult.retry) {
1648
- await new Promise((resolve) => setTimeout(resolve, retryResult.delay));
1649
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
1741
+ await waitForRetry(url, attempt + 1, retryResult.delay, options, requestInit, response);
1742
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
1650
1743
  } else {
1651
1744
  const errText = await response.text().catch((e) => castToError2(e).message);
1652
1745
  const errJSON = safeJsonParse(errText);
@@ -1674,8 +1767,8 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1674
1767
  };
1675
1768
  const delay = calculateNextRetryDelay(retry, attempt);
1676
1769
  if (delay) {
1677
- await new Promise((resolve) => setTimeout(resolve, delay));
1678
- return await _doZodFetch(schema, url, requestInit, options, attempt + 1);
1770
+ await waitForRetry(url, attempt + 1, delay, options, requestInit);
1771
+ return await _doZodFetchWithRetries(schema, url, requestInit, options, attempt + 1);
1679
1772
  }
1680
1773
  }
1681
1774
  throw new ApiConnectionError({
@@ -1683,7 +1776,7 @@ async function _doZodFetch(schema, url, requestInit, options, attempt = 1) {
1683
1776
  });
1684
1777
  }
1685
1778
  }
1686
- __name(_doZodFetch, "_doZodFetch");
1779
+ __name(_doZodFetchWithRetries, "_doZodFetchWithRetries");
1687
1780
  function castToError2(err) {
1688
1781
  if (err instanceof Error)
1689
1782
  return err;
@@ -1720,8 +1813,25 @@ function shouldRetry(response, attempt, retryOptions) {
1720
1813
  return shouldRetryForOptions();
1721
1814
  if (response.status === 409)
1722
1815
  return shouldRetryForOptions();
1723
- if (response.status === 429)
1816
+ if (response.status === 429) {
1817
+ if (attempt >= (typeof retryOptions?.maxAttempts === "number" ? retryOptions?.maxAttempts : 3)) {
1818
+ return {
1819
+ retry: false
1820
+ };
1821
+ }
1822
+ const resetAtUnixEpochMs = response.headers.get("x-ratelimit-reset");
1823
+ if (resetAtUnixEpochMs) {
1824
+ const resetAtUnixEpoch = parseInt(resetAtUnixEpochMs, 10);
1825
+ const delay = resetAtUnixEpoch - Date.now() + Math.floor(Math.random() * 1e3);
1826
+ if (delay > 0) {
1827
+ return {
1828
+ retry: true,
1829
+ delay
1830
+ };
1831
+ }
1832
+ }
1724
1833
  return shouldRetryForOptions();
1834
+ }
1725
1835
  if (response.status >= 500)
1726
1836
  return shouldRetryForOptions();
1727
1837
  return {
@@ -1884,9 +1994,32 @@ fetchPage_fn2 = /* @__PURE__ */ __name(function(params1) {
1884
1994
  }, "#fetchPage");
1885
1995
  __name(_OffsetLimitPagePromise, "OffsetLimitPagePromise");
1886
1996
  var OffsetLimitPagePromise = _OffsetLimitPagePromise;
1997
+ async function waitForRetry(url, attempt, delay, options, requestInit, response) {
1998
+ if (options?.tracer) {
1999
+ const method = requestInit?.method ?? "GET";
2000
+ return options.tracer.startActiveSpan(response ? `wait after ${response.status}` : `wait after error`, async (span) => {
2001
+ await new Promise((resolve) => setTimeout(resolve, delay));
2002
+ }, {
2003
+ attributes: {
2004
+ [SemanticInternalAttributes.STYLE_ICON]: "wait",
2005
+ ...accessoryAttributes({
2006
+ items: [
2007
+ {
2008
+ text: `retrying ${options?.name ?? method.toUpperCase()} in ${delay}ms`,
2009
+ variant: "normal"
2010
+ }
2011
+ ],
2012
+ style: "codepath"
2013
+ })
2014
+ }
2015
+ });
2016
+ }
2017
+ await new Promise((resolve) => setTimeout(resolve, delay));
2018
+ }
2019
+ __name(waitForRetry, "waitForRetry");
1887
2020
 
1888
2021
  // src/v3/apiClient/index.ts
1889
- var zodFetchOptions = {
2022
+ var DEFAULT_ZOD_FETCH_OPTIONS = {
1890
2023
  retry: {
1891
2024
  maxAttempts: 3,
1892
2025
  minTimeoutInMs: 1e3,
@@ -1897,17 +2030,18 @@ var zodFetchOptions = {
1897
2030
  };
1898
2031
  var _getHeaders, getHeaders_fn;
1899
2032
  var _ApiClient = class _ApiClient {
1900
- constructor(baseUrl, accessToken) {
2033
+ constructor(baseUrl, accessToken, requestOptions = {}) {
1901
2034
  __privateAdd(this, _getHeaders);
1902
2035
  this.accessToken = accessToken;
1903
2036
  this.baseUrl = baseUrl.replace(/\/$/, "");
2037
+ this.defaultRequestOptions = mergeRequestOptions(DEFAULT_ZOD_FETCH_OPTIONS, requestOptions);
1904
2038
  }
1905
- async getRunResult(runId) {
2039
+ async getRunResult(runId, requestOptions) {
1906
2040
  try {
1907
2041
  return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
1908
2042
  method: "GET",
1909
2043
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1910
- }, zodFetchOptions);
2044
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1911
2045
  } catch (error) {
1912
2046
  if (error instanceof ApiError) {
1913
2047
  if (error.status === 404) {
@@ -1917,47 +2051,47 @@ var _ApiClient = class _ApiClient {
1917
2051
  throw error;
1918
2052
  }
1919
2053
  }
1920
- async getBatchResults(batchId) {
2054
+ async getBatchResults(batchId, requestOptions) {
1921
2055
  return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
1922
2056
  method: "GET",
1923
2057
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1924
- }, zodFetchOptions);
2058
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1925
2059
  }
1926
- triggerTask(taskId, body, options) {
2060
+ triggerTask(taskId, body, options, requestOptions) {
1927
2061
  const encodedTaskId = encodeURIComponent(taskId);
1928
2062
  return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/trigger`, {
1929
2063
  method: "POST",
1930
2064
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
1931
2065
  body: JSON.stringify(body)
1932
- }, zodFetchOptions);
2066
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1933
2067
  }
1934
- batchTriggerTask(taskId, body, options) {
2068
+ batchTriggerTask(taskId, body, options, requestOptions) {
1935
2069
  const encodedTaskId = encodeURIComponent(taskId);
1936
2070
  return zodfetch(BatchTriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${encodedTaskId}/batch`, {
1937
2071
  method: "POST",
1938
2072
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, options?.spanParentAsLink ?? false),
1939
2073
  body: JSON.stringify(body)
1940
- }, zodFetchOptions);
2074
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1941
2075
  }
1942
- createUploadPayloadUrl(filename) {
2076
+ createUploadPayloadUrl(filename, requestOptions) {
1943
2077
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
1944
2078
  method: "PUT",
1945
2079
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1946
- }, zodFetchOptions);
2080
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1947
2081
  }
1948
- getPayloadUrl(filename) {
2082
+ getPayloadUrl(filename, requestOptions) {
1949
2083
  return zodfetch(CreateUploadPayloadUrlResponseBody, `${this.baseUrl}/api/v1/packets/${filename}`, {
1950
2084
  method: "GET",
1951
2085
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1952
- }, zodFetchOptions);
2086
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1953
2087
  }
1954
- retrieveRun(runId) {
2088
+ retrieveRun(runId, requestOptions) {
1955
2089
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v3/runs/${runId}`, {
1956
2090
  method: "GET",
1957
2091
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1958
- }, zodFetchOptions);
2092
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1959
2093
  }
1960
- listRuns(query) {
2094
+ listRuns(query, requestOptions) {
1961
2095
  const searchParams = createSearchQueryForListRuns(query);
1962
2096
  return zodfetchCursorPage(ListRunResponseItem, `${this.baseUrl}/api/v1/runs`, {
1963
2097
  query: searchParams,
@@ -1967,9 +2101,9 @@ var _ApiClient = class _ApiClient {
1967
2101
  }, {
1968
2102
  method: "GET",
1969
2103
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1970
- }, zodFetchOptions);
2104
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1971
2105
  }
1972
- listProjectRuns(projectRef, query) {
2106
+ listProjectRuns(projectRef, query, requestOptions) {
1973
2107
  const searchParams = createSearchQueryForListRuns(query);
1974
2108
  if (query?.env) {
1975
2109
  searchParams.append("filter[env]", Array.isArray(query.env) ? query.env.join(",") : query.env);
@@ -1982,35 +2116,35 @@ var _ApiClient = class _ApiClient {
1982
2116
  }, {
1983
2117
  method: "GET",
1984
2118
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1985
- }, zodFetchOptions);
2119
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1986
2120
  }
1987
- replayRun(runId) {
2121
+ replayRun(runId, requestOptions) {
1988
2122
  return zodfetch(ReplayRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/replay`, {
1989
2123
  method: "POST",
1990
2124
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1991
- }, zodFetchOptions);
2125
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1992
2126
  }
1993
- cancelRun(runId) {
2127
+ cancelRun(runId, requestOptions) {
1994
2128
  return zodfetch(CanceledRunResponse, `${this.baseUrl}/api/v2/runs/${runId}/cancel`, {
1995
2129
  method: "POST",
1996
2130
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
1997
- }, zodFetchOptions);
2131
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
1998
2132
  }
1999
- rescheduleRun(runId, body) {
2133
+ rescheduleRun(runId, body, requestOptions) {
2000
2134
  return zodfetch(RetrieveRunResponse, `${this.baseUrl}/api/v1/runs/${runId}/reschedule`, {
2001
2135
  method: "POST",
2002
2136
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2003
2137
  body: JSON.stringify(body)
2004
- }, zodFetchOptions);
2138
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2005
2139
  }
2006
- createSchedule(options) {
2140
+ createSchedule(options, requestOptions) {
2007
2141
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules`, {
2008
2142
  method: "POST",
2009
2143
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2010
2144
  body: JSON.stringify(options)
2011
- });
2145
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2012
2146
  }
2013
- listSchedules(options) {
2147
+ listSchedules(options, requestOptions) {
2014
2148
  const searchParams = new URLSearchParams();
2015
2149
  if (options?.page) {
2016
2150
  searchParams.append("page", options.page.toString());
@@ -2024,77 +2158,77 @@ var _ApiClient = class _ApiClient {
2024
2158
  }, {
2025
2159
  method: "GET",
2026
2160
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2027
- });
2161
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2028
2162
  }
2029
- retrieveSchedule(scheduleId) {
2163
+ retrieveSchedule(scheduleId, requestOptions) {
2030
2164
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
2031
2165
  method: "GET",
2032
2166
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2033
- });
2167
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2034
2168
  }
2035
- updateSchedule(scheduleId, options) {
2169
+ updateSchedule(scheduleId, options, requestOptions) {
2036
2170
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
2037
2171
  method: "PUT",
2038
2172
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2039
2173
  body: JSON.stringify(options)
2040
- });
2174
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2041
2175
  }
2042
- deactivateSchedule(scheduleId) {
2176
+ deactivateSchedule(scheduleId, requestOptions) {
2043
2177
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/deactivate`, {
2044
2178
  method: "POST",
2045
2179
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2046
- });
2180
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2047
2181
  }
2048
- activateSchedule(scheduleId) {
2182
+ activateSchedule(scheduleId, requestOptions) {
2049
2183
  return zodfetch(ScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}/activate`, {
2050
2184
  method: "POST",
2051
2185
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2052
- });
2186
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2053
2187
  }
2054
- deleteSchedule(scheduleId) {
2188
+ deleteSchedule(scheduleId, requestOptions) {
2055
2189
  return zodfetch(DeletedScheduleObject, `${this.baseUrl}/api/v1/schedules/${scheduleId}`, {
2056
2190
  method: "DELETE",
2057
2191
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2058
- });
2192
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2059
2193
  }
2060
- listEnvVars(projectRef, slug) {
2194
+ listEnvVars(projectRef, slug, requestOptions) {
2061
2195
  return zodfetch(EnvironmentVariables, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
2062
2196
  method: "GET",
2063
2197
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2064
- });
2198
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2065
2199
  }
2066
- importEnvVars(projectRef, slug, body) {
2200
+ importEnvVars(projectRef, slug, body, requestOptions) {
2067
2201
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/import`, {
2068
2202
  method: "POST",
2069
2203
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2070
2204
  body: JSON.stringify(body)
2071
- });
2205
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2072
2206
  }
2073
- retrieveEnvVar(projectRef, slug, key) {
2207
+ retrieveEnvVar(projectRef, slug, key, requestOptions) {
2074
2208
  return zodfetch(EnvironmentVariableValue, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
2075
2209
  method: "GET",
2076
2210
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2077
- });
2211
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2078
2212
  }
2079
- createEnvVar(projectRef, slug, body) {
2213
+ createEnvVar(projectRef, slug, body, requestOptions) {
2080
2214
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}`, {
2081
2215
  method: "POST",
2082
2216
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2083
2217
  body: JSON.stringify(body)
2084
- });
2218
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2085
2219
  }
2086
- updateEnvVar(projectRef, slug, key, body) {
2220
+ updateEnvVar(projectRef, slug, key, body, requestOptions) {
2087
2221
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
2088
2222
  method: "PUT",
2089
2223
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false),
2090
2224
  body: JSON.stringify(body)
2091
- });
2225
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2092
2226
  }
2093
- deleteEnvVar(projectRef, slug, key) {
2227
+ deleteEnvVar(projectRef, slug, key, requestOptions) {
2094
2228
  return zodfetch(EnvironmentVariableResponseBody, `${this.baseUrl}/api/v1/projects/${projectRef}/envvars/${slug}/${key}`, {
2095
2229
  method: "DELETE",
2096
2230
  headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2097
- });
2231
+ }, mergeRequestOptions(this.defaultRequestOptions, requestOptions));
2098
2232
  }
2099
2233
  };
2100
2234
  _getHeaders = new WeakSet();
@@ -2149,6 +2283,20 @@ function createSearchQueryForListRuns(query) {
2149
2283
  return searchParams;
2150
2284
  }
2151
2285
  __name(createSearchQueryForListRuns, "createSearchQueryForListRuns");
2286
+ function mergeRequestOptions(defaultOptions, options) {
2287
+ if (!options) {
2288
+ return defaultOptions;
2289
+ }
2290
+ return {
2291
+ ...defaultOptions,
2292
+ ...options,
2293
+ retry: {
2294
+ ...defaultOptions.retry,
2295
+ ...options.retry
2296
+ }
2297
+ };
2298
+ }
2299
+ __name(mergeRequestOptions, "mergeRequestOptions");
2152
2300
 
2153
2301
  // src/v3/apiClientManager/index.ts
2154
2302
  var API_NAME2 = "api-client";
@@ -2413,12 +2561,6 @@ async function loadSuperJSON() {
2413
2561
  }
2414
2562
  __name(loadSuperJSON, "loadSuperJSON");
2415
2563
 
2416
- // src/v3/utils/styleAttributes.ts
2417
- function accessoryAttributes(accessory) {
2418
- return flattenAttributes(accessory, SemanticInternalAttributes.STYLE_ACCESSORY);
2419
- }
2420
- __name(accessoryAttributes, "accessoryAttributes");
2421
-
2422
2564
  // src/v3/workers/taskExecutor.ts
2423
2565
  var _callRun, callRun_fn, _callInitFunctions, callInitFunctions_fn, _callConfigInit, callConfigInit_fn, _callOnSuccessFunctions, callOnSuccessFunctions_fn, _callOnSuccessFunction, callOnSuccessFunction_fn, _callOnFailureFunctions, callOnFailureFunctions_fn, _callOnFailureFunction, callOnFailureFunction_fn, _callOnStartFunctions, callOnStartFunctions_fn, _callOnStartFunction, callOnStartFunction_fn, _callTaskCleanup, callTaskCleanup_fn, _handleError, handleError_fn;
2424
2566
  var _TaskExecutor = class _TaskExecutor {
@@ -2506,7 +2648,7 @@ var _TaskExecutor = class _TaskExecutor {
2506
2648
  return {
2507
2649
  id: execution.run.id,
2508
2650
  ok: false,
2509
- error: handleErrorResult.error ? parseError(handleErrorResult.error) : parseError(runError),
2651
+ error: sanitizeError(handleErrorResult.error ? parseError(handleErrorResult.error) : parseError(runError)),
2510
2652
  retry: handleErrorResult.status === "retry" ? handleErrorResult.retry : void 0,
2511
2653
  skippedRetrying: handleErrorResult.status === "skipped"
2512
2654
  };
@@ -2695,7 +2837,19 @@ handleError_fn = /* @__PURE__ */ __name(async function(execution, error2, payloa
2695
2837
  status: "noop"
2696
2838
  };
2697
2839
  }
2698
- const delay = calculateNextRetryDelay(retry, execution.attempt.number);
2840
+ if (error2 instanceof Error && error2.name === "AbortTaskRunError") {
2841
+ return {
2842
+ status: "skipped"
2843
+ };
2844
+ }
2845
+ if (execution.run.maxAttempts) {
2846
+ retry.maxAttempts = Math.max(execution.run.maxAttempts, 1);
2847
+ }
2848
+ let delay = calculateNextRetryDelay(retry, execution.attempt.number);
2849
+ if (delay && error2 instanceof Error && error2.name === "TriggerApiError" && error2.status === 429) {
2850
+ const rateLimitError = error2;
2851
+ delay = rateLimitError.millisecondsUntilReset;
2852
+ }
2699
2853
  if (execution.environment.type === "DEVELOPMENT" && typeof retriesConfig?.enabledInDev === "boolean" && !retriesConfig.enabledInDev) {
2700
2854
  return {
2701
2855
  status: "skipped"