@trigger.dev/core 3.0.0-beta.36 → 3.0.0-beta.38

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 (37) hide show
  1. package/dist/{catalog-dRKTgwQ7.d.ts → catalog-Tdea4K0I.d.mts} +43 -3
  2. package/dist/{catalog-XTlJQaMn.d.mts → catalog-yeAHwmSe.d.ts} +43 -3
  3. package/dist/{manager-JkbddlcO.d.mts → manager-S98VaLUy.d.mts} +244 -1
  4. package/dist/{manager-JkbddlcO.d.ts → manager-S98VaLUy.d.ts} +244 -1
  5. package/dist/{messages-6_-q72KG.d.mts → messages-BD0yXLtn.d.mts} +2390 -188
  6. package/dist/{messages-6_-q72KG.d.ts → messages-BD0yXLtn.d.ts} +2390 -188
  7. package/dist/{schemas-r4ZP9S-F.d.mts → schemas-XNxZYXOy.d.mts} +199 -33
  8. package/dist/{schemas-r4ZP9S-F.d.ts → schemas-XNxZYXOy.d.ts} +199 -33
  9. package/dist/v3/dev/index.d.mts +1 -1
  10. package/dist/v3/dev/index.d.ts +1 -1
  11. package/dist/v3/index.d.mts +125 -52
  12. package/dist/v3/index.d.ts +125 -52
  13. package/dist/v3/index.js +214 -87
  14. package/dist/v3/index.js.map +1 -1
  15. package/dist/v3/index.mjs +209 -87
  16. package/dist/v3/index.mjs.map +1 -1
  17. package/dist/v3/otel/index.js +15 -5
  18. package/dist/v3/otel/index.js.map +1 -1
  19. package/dist/v3/otel/index.mjs +15 -5
  20. package/dist/v3/otel/index.mjs.map +1 -1
  21. package/dist/v3/prod/index.d.mts +2 -2
  22. package/dist/v3/prod/index.d.ts +2 -2
  23. package/dist/v3/prod/index.js.map +1 -1
  24. package/dist/v3/prod/index.mjs.map +1 -1
  25. package/dist/v3/workers/index.d.mts +54 -8
  26. package/dist/v3/workers/index.d.ts +54 -8
  27. package/dist/v3/workers/index.js +406 -44
  28. package/dist/v3/workers/index.js.map +1 -1
  29. package/dist/v3/workers/index.mjs +404 -45
  30. package/dist/v3/workers/index.mjs.map +1 -1
  31. package/dist/v3/zodIpc.js.map +1 -1
  32. package/dist/v3/zodIpc.mjs.map +1 -1
  33. package/dist/v3/zodMessageHandler.d.mts +1 -1
  34. package/dist/v3/zodMessageHandler.d.ts +1 -1
  35. package/dist/v3/zodfetch.d.mts +1 -1
  36. package/dist/v3/zodfetch.d.ts +1 -1
  37. package/package.json +1 -1
package/dist/v3/index.js CHANGED
@@ -35,7 +35,7 @@ var __privateMethod = (obj, member, method) => {
35
35
  };
36
36
 
37
37
  // package.json
38
- var version = "3.0.0-beta.36";
38
+ var version = "3.0.0-beta.38";
39
39
  var dependencies = {
40
40
  "@google-cloud/precise-date": "^4.0.0",
41
41
  "@opentelemetry/api": "^1.8.0",
@@ -71,6 +71,41 @@ var GetPersonalAccessTokenResponseSchema = zod.z.object({
71
71
  obfuscatedToken: zod.z.string()
72
72
  }).nullable()
73
73
  });
74
+ var MachineCpu = zod.z.union([
75
+ zod.z.literal(0.25),
76
+ zod.z.literal(0.5),
77
+ zod.z.literal(1),
78
+ zod.z.literal(2),
79
+ zod.z.literal(4)
80
+ ]);
81
+ var MachineMemory = zod.z.union([
82
+ zod.z.literal(0.25),
83
+ zod.z.literal(0.5),
84
+ zod.z.literal(1),
85
+ zod.z.literal(2),
86
+ zod.z.literal(4),
87
+ zod.z.literal(8)
88
+ ]);
89
+ var MachinePresetName = zod.z.enum([
90
+ "micro",
91
+ "small-1x",
92
+ "small-2x",
93
+ "medium-1x",
94
+ "medium-2x",
95
+ "large-1x",
96
+ "large-2x"
97
+ ]);
98
+ var MachineConfig = zod.z.object({
99
+ cpu: MachineCpu.optional(),
100
+ memory: MachineMemory.optional(),
101
+ preset: MachinePresetName.optional()
102
+ });
103
+ var MachinePreset = zod.z.object({
104
+ name: MachinePresetName,
105
+ cpu: zod.z.number(),
106
+ memory: zod.z.number(),
107
+ centsPerMs: zod.z.number()
108
+ });
74
109
  var TaskRunBuiltInError = zod.z.object({
75
110
  type: zod.z.literal("BUILT_IN_ERROR"),
76
111
  name: zod.z.string(),
@@ -132,7 +167,11 @@ var TaskRun = zod.z.object({
132
167
  tags: zod.z.array(zod.z.string()),
133
168
  isTest: zod.z.boolean().default(false),
134
169
  createdAt: zod.z.coerce.date(),
135
- idempotencyKey: zod.z.string().optional()
170
+ startedAt: zod.z.coerce.date().default(() => /* @__PURE__ */ new Date()),
171
+ idempotencyKey: zod.z.string().optional(),
172
+ durationMs: zod.z.number().default(0),
173
+ costInCents: zod.z.number().default(0),
174
+ baseCostInCents: zod.z.number().default(0)
136
175
  });
137
176
  var TaskRunExecutionTask = zod.z.object({
138
177
  id: zod.z.string(),
@@ -183,7 +222,8 @@ var TaskRunExecution = zod.z.object({
183
222
  environment: TaskRunExecutionEnvironment,
184
223
  organization: TaskRunExecutionOrganization,
185
224
  project: TaskRunExecutionProject,
186
- batch: TaskRunExecutionBatch.optional()
225
+ batch: TaskRunExecutionBatch.optional(),
226
+ machine: MachinePreset.optional()
187
227
  });
188
228
  var TaskRunContext = zod.z.object({
189
229
  task: TaskRunExecutionTask,
@@ -199,25 +239,31 @@ var TaskRunContext = zod.z.object({
199
239
  environment: TaskRunExecutionEnvironment,
200
240
  organization: TaskRunExecutionOrganization,
201
241
  project: TaskRunExecutionProject,
202
- batch: TaskRunExecutionBatch.optional()
242
+ batch: TaskRunExecutionBatch.optional(),
243
+ machine: MachinePreset.optional()
203
244
  });
204
245
  var TaskRunExecutionRetry = zod.z.object({
205
246
  timestamp: zod.z.number(),
206
247
  delay: zod.z.number(),
207
248
  error: zod.z.unknown().optional()
208
249
  });
250
+ var TaskRunExecutionUsage = zod.z.object({
251
+ durationMs: zod.z.number()
252
+ });
209
253
  var TaskRunFailedExecutionResult = zod.z.object({
210
254
  ok: zod.z.literal(false),
211
255
  id: zod.z.string(),
212
256
  error: TaskRunError,
213
257
  retry: TaskRunExecutionRetry.optional(),
214
- skippedRetrying: zod.z.boolean().optional()
258
+ skippedRetrying: zod.z.boolean().optional(),
259
+ usage: TaskRunExecutionUsage.optional()
215
260
  });
216
261
  var TaskRunSuccessfulExecutionResult = zod.z.object({
217
262
  ok: zod.z.literal(true),
218
263
  id: zod.z.string(),
219
264
  output: zod.z.string().optional(),
220
- outputType: zod.z.string()
265
+ outputType: zod.z.string(),
266
+ usage: TaskRunExecutionUsage.optional()
221
267
  });
222
268
  var TaskRunExecutionResult = zod.z.discriminatedUnion("ok", [
223
269
  TaskRunSuccessfulExecutionResult,
@@ -235,26 +281,6 @@ var EnvironmentType = zod.z.enum([
235
281
  "DEVELOPMENT",
236
282
  "PREVIEW"
237
283
  ]);
238
- var MachineCpu = zod.z.union([
239
- zod.z.literal(0.25),
240
- zod.z.literal(0.5),
241
- zod.z.literal(1),
242
- zod.z.literal(2),
243
- zod.z.literal(4)
244
- ]).default(0.5);
245
- var MachineMemory = zod.z.union([
246
- zod.z.literal(0.25),
247
- zod.z.literal(0.5),
248
- zod.z.literal(1),
249
- zod.z.literal(2),
250
- zod.z.literal(4),
251
- zod.z.literal(8)
252
- ]).default(1);
253
- var Machine = zod.z.object({
254
- version: zod.z.literal("v1").default("v1"),
255
- cpu: MachineCpu,
256
- memory: MachineMemory
257
- });
258
284
  var TaskRunExecutionPayload = zod.z.object({
259
285
  execution: TaskRunExecution,
260
286
  traceContext: zod.z.record(zod.z.unknown()),
@@ -265,7 +291,8 @@ var ProdTaskRunExecution = TaskRunExecution.extend({
265
291
  id: zod.z.string(),
266
292
  contentHash: zod.z.string(),
267
293
  version: zod.z.string()
268
- })
294
+ }),
295
+ machine: MachinePreset
269
296
  });
270
297
  var ProdTaskRunExecutionPayload = zod.z.object({
271
298
  execution: ProdTaskRunExecution,
@@ -369,7 +396,7 @@ var TaskMetadata = zod.z.object({
369
396
  packageVersion: zod.z.string(),
370
397
  queue: QueueOptions.optional(),
371
398
  retry: RetryOptions.optional(),
372
- machine: Machine.partial().optional(),
399
+ machine: MachineConfig.optional(),
373
400
  triggerSource: zod.z.string().optional()
374
401
  });
375
402
  var TaskFileMetadata = zod.z.object({
@@ -381,7 +408,7 @@ var TaskMetadataWithFilePath = zod.z.object({
381
408
  packageVersion: zod.z.string(),
382
409
  queue: QueueOptions.optional(),
383
410
  retry: RetryOptions.optional(),
384
- machine: Machine.partial().optional(),
411
+ machine: MachineConfig.optional(),
385
412
  triggerSource: zod.z.string().optional(),
386
413
  filePath: zod.z.string(),
387
414
  exportName: zod.z.string()
@@ -441,7 +468,7 @@ var TaskResource = zod.z.object({
441
468
  exportName: zod.z.string(),
442
469
  queue: QueueOptions.optional(),
443
470
  retry: RetryOptions.optional(),
444
- machine: Machine.partial().optional(),
471
+ machine: MachineConfig.optional(),
445
472
  triggerSource: zod.z.string().optional()
446
473
  });
447
474
  var BackgroundWorkerMetadata = zod.z.object({
@@ -706,7 +733,8 @@ var InitializeDeploymentRequestBody = zod.z.object({
706
733
  var DeploymentErrorData = zod.z.object({
707
734
  name: zod.z.string(),
708
735
  message: zod.z.string(),
709
- stack: zod.z.string().optional()
736
+ stack: zod.z.string().optional(),
737
+ stderr: zod.z.string().optional()
710
738
  });
711
739
  var GetDeploymentResponseBody = zod.z.object({
712
740
  id: zod.z.string(),
@@ -749,15 +777,26 @@ var ScheduledTaskPayload = zod.z.object({
749
777
  You can use this to remove the schedule, update it, etc */
750
778
  scheduleId: zod.z.string(),
751
779
  /** When the task was scheduled to run.
752
- * Note this will be slightly different from `new Date()` because it takes a few ms to run the task. */
780
+ * Note this will be slightly different from `new Date()` because it takes a few ms to run the task.
781
+ *
782
+ * This date is UTC. To output it as a string with a timezone you would do this:
783
+ * ```ts
784
+ * const formatted = payload.timestamp.toLocaleString("en-US", {
785
+ timeZone: payload.timezone,
786
+ });
787
+ ``` */
753
788
  timestamp: zod.z.date(),
754
789
  /** When the task was last run (it has been).
755
- This can be undefined if it's never been run */
790
+ This can be undefined if it's never been run. This date is UTC. */
756
791
  lastTimestamp: zod.z.date().optional(),
757
792
  /** You can optionally provide an external id when creating the schedule.
758
793
  Usually you would use a userId or some other unique identifier.
759
794
  This defaults to undefined if you didn't provide one. */
760
795
  externalId: zod.z.string().optional(),
796
+ /** The IANA timezone the schedule is set to. The default is UTC.
797
+ * You can see the full list of supported timezones here: https://cloud.trigger.dev/timezones
798
+ */
799
+ timezone: zod.z.string(),
761
800
  /** The next 5 dates this task is scheduled to run */
762
801
  upcoming: zod.z.array(zod.z.date())
763
802
  });
@@ -781,17 +820,30 @@ var CreateScheduleOptions = zod.z.object({
781
820
 
782
821
  */
783
822
  cron: zod.z.string(),
784
- /** (Optional) You can only create one schedule with this key. If you use it twice, the second call will update the schedule.
823
+ /** You can only create one schedule with this key. If you use it twice, the second call will update the schedule.
785
824
  *
786
- * This is useful if you don't want to create duplicate schedules for a user. */
787
- deduplicationKey: zod.z.string().optional(),
825
+ * This is required to prevent you from creating duplicate schedules. */
826
+ deduplicationKey: zod.z.string(),
788
827
  /** Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
789
828
  *
790
829
  * This allows you to have per-user CRON tasks.
791
830
  */
792
- externalId: zod.z.string().optional()
831
+ externalId: zod.z.string().optional(),
832
+ /** Optionally, you can specify a timezone in the IANA format. If unset it will use UTC.
833
+ * If specified then the CRON will be evaluated in that timezone and will respect daylight savings.
834
+ *
835
+ * If you set the CRON to `0 0 * * *` and the timezone to `America/New_York` then the task will run at midnight in New York time, no matter whether it's daylight savings or not.
836
+ *
837
+ * You can see the full list of supported timezones here: https://cloud.trigger.dev/timezones
838
+ *
839
+ * @example "America/New_York", "Europe/London", "Asia/Tokyo", "Africa/Cairo"
840
+ *
841
+ */
842
+ timezone: zod.z.string().optional()
843
+ });
844
+ var UpdateScheduleOptions = CreateScheduleOptions.omit({
845
+ deduplicationKey: true
793
846
  });
794
- var UpdateScheduleOptions = CreateScheduleOptions;
795
847
  var ScheduleGenerator = zod.z.object({
796
848
  type: zod.z.literal("CRON"),
797
849
  expression: zod.z.string(),
@@ -804,6 +856,7 @@ var ScheduleObject = zod.z.object({
804
856
  deduplicationKey: zod.z.string().nullish(),
805
857
  externalId: zod.z.string().nullish(),
806
858
  generator: ScheduleGenerator,
859
+ timezone: zod.z.string(),
807
860
  nextRun: zod.z.coerce.date().nullish(),
808
861
  environments: zod.z.array(zod.z.object({
809
862
  id: zod.z.string(),
@@ -826,6 +879,9 @@ var ListScheduleOptions = zod.z.object({
826
879
  page: zod.z.number().optional(),
827
880
  perPage: zod.z.number().optional()
828
881
  });
882
+ var TimezonesResult = zod.z.object({
883
+ timezones: zod.z.array(zod.z.string())
884
+ });
829
885
  var RunStatus = zod.z.enum([
830
886
  /// Task hasn't been deployed yet but is waiting to be executed
831
887
  "WAITING_FOR_DEPLOY",
@@ -949,7 +1005,7 @@ var BackgroundWorkerServerMessages = zod.z.discriminatedUnion("type", [
949
1005
  type: zod.z.literal("SCHEDULE_ATTEMPT"),
950
1006
  image: zod.z.string(),
951
1007
  version: zod.z.string(),
952
- machine: Machine,
1008
+ machine: MachinePreset,
953
1009
  // identifiers
954
1010
  id: zod.z.string().optional(),
955
1011
  envId: zod.z.string(),
@@ -1248,20 +1304,13 @@ var ProviderToPlatformMessages = {
1248
1304
  error: zod.z.object({
1249
1305
  name: zod.z.string(),
1250
1306
  message: zod.z.string(),
1251
- stack: zod.z.string().optional()
1307
+ stack: zod.z.string().optional(),
1308
+ stderr: zod.z.string().optional()
1252
1309
  })
1253
1310
  })
1254
1311
  }
1255
1312
  };
1256
1313
  var PlatformToProviderMessages = {
1257
- HEALTH: {
1258
- message: zod.z.object({
1259
- version: zod.z.literal("v1").default("v1")
1260
- }),
1261
- callback: zod.z.object({
1262
- status: zod.z.literal("ok")
1263
- })
1264
- },
1265
1314
  INDEX: {
1266
1315
  message: zod.z.object({
1267
1316
  version: zod.z.literal("v1").default("v1"),
@@ -1282,7 +1331,8 @@ var PlatformToProviderMessages = {
1282
1331
  error: zod.z.object({
1283
1332
  name: zod.z.string(),
1284
1333
  message: zod.z.string(),
1285
- stack: zod.z.string().optional()
1334
+ stack: zod.z.string().optional(),
1335
+ stderr: zod.z.string().optional()
1286
1336
  })
1287
1337
  }),
1288
1338
  zod.z.object({
@@ -1290,7 +1340,6 @@ var PlatformToProviderMessages = {
1290
1340
  })
1291
1341
  ])
1292
1342
  },
1293
- // TODO: this should be a shared queue message instead
1294
1343
  RESTORE: {
1295
1344
  message: zod.z.object({
1296
1345
  version: zod.z.literal("v1").default("v1"),
@@ -1301,7 +1350,7 @@ var PlatformToProviderMessages = {
1301
1350
  location: zod.z.string(),
1302
1351
  reason: zod.z.string().optional(),
1303
1352
  imageRef: zod.z.string(),
1304
- machine: Machine,
1353
+ machine: MachinePreset,
1305
1354
  // identifiers
1306
1355
  checkpointId: zod.z.string(),
1307
1356
  envId: zod.z.string(),
@@ -1310,21 +1359,6 @@ var PlatformToProviderMessages = {
1310
1359
  projectId: zod.z.string(),
1311
1360
  runId: zod.z.string()
1312
1361
  })
1313
- },
1314
- DELETE: {
1315
- message: zod.z.object({
1316
- version: zod.z.literal("v1").default("v1"),
1317
- name: zod.z.string()
1318
- }),
1319
- callback: zod.z.object({
1320
- message: zod.z.string()
1321
- })
1322
- },
1323
- GET: {
1324
- message: zod.z.object({
1325
- version: zod.z.literal("v1").default("v1"),
1326
- name: zod.z.string()
1327
- })
1328
1362
  }
1329
1363
  };
1330
1364
  var CreateWorkerMessage = zod.z.object({
@@ -1487,7 +1521,8 @@ var CoordinatorToPlatformMessages = {
1487
1521
  error: zod.z.object({
1488
1522
  name: zod.z.string(),
1489
1523
  message: zod.z.string(),
1490
- stack: zod.z.string().optional()
1524
+ stack: zod.z.string().optional(),
1525
+ stderr: zod.z.string().optional()
1491
1526
  })
1492
1527
  })
1493
1528
  },
@@ -1725,7 +1760,8 @@ var ProdWorkerToCoordinatorMessages = {
1725
1760
  error: zod.z.object({
1726
1761
  name: zod.z.string(),
1727
1762
  message: zod.z.string(),
1728
- stack: zod.z.string().optional()
1763
+ stack: zod.z.string().optional(),
1764
+ stderr: zod.z.string().optional()
1729
1765
  })
1730
1766
  })
1731
1767
  },
@@ -2064,6 +2100,10 @@ var SemanticInternalAttributes = {
2064
2100
  TASK_EXPORT_NAME: "ctx.task.exportName",
2065
2101
  QUEUE_NAME: "ctx.queue.name",
2066
2102
  QUEUE_ID: "ctx.queue.id",
2103
+ MACHINE_PRESET_NAME: "ctx.machine.name",
2104
+ MACHINE_PRESET_CPU: "ctx.machine.cpu",
2105
+ MACHINE_PRESET_MEMORY: "ctx.machine.memory",
2106
+ MACHINE_PRESET_CENTS_PER_MS: "ctx.machine.centsPerMs",
2067
2107
  SPAN_PARTIAL: "$span.partial",
2068
2108
  SPAN_ID: "$span.span_id",
2069
2109
  OUTPUT: "$output",
@@ -2087,7 +2127,9 @@ var SemanticInternalAttributes = {
2087
2127
  RETRY_DELAY: "retry.delay",
2088
2128
  RETRY_COUNT: "retry.count",
2089
2129
  LINK_TITLE: "$link.title",
2090
- IDEMPOTENCY_KEY: "ctx.run.idempotencyKey"
2130
+ IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
2131
+ USAGE_DURATION_MS: "$usage.durationMs",
2132
+ USAGE_COST_IN_CENTS: "$usage.costInCents"
2091
2133
  };
2092
2134
 
2093
2135
  // src/v3/taskContext/index.ts
@@ -2151,7 +2193,11 @@ var _TaskContextAPI = class _TaskContextAPI {
2151
2193
  [SemanticInternalAttributes.ORGANIZATION_SLUG]: this.ctx.organization.slug,
2152
2194
  [SemanticInternalAttributes.ORGANIZATION_NAME]: this.ctx.organization.name,
2153
2195
  [SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id,
2154
- [SemanticInternalAttributes.IDEMPOTENCY_KEY]: this.ctx.run.idempotencyKey
2196
+ [SemanticInternalAttributes.IDEMPOTENCY_KEY]: this.ctx.run.idempotencyKey,
2197
+ [SemanticInternalAttributes.MACHINE_PRESET_NAME]: this.ctx.machine?.name,
2198
+ [SemanticInternalAttributes.MACHINE_PRESET_CPU]: this.ctx.machine?.cpu,
2199
+ [SemanticInternalAttributes.MACHINE_PRESET_MEMORY]: this.ctx.machine?.memory,
2200
+ [SemanticInternalAttributes.MACHINE_PRESET_CENTS_PER_MS]: this.ctx.machine?.centsPerMs
2155
2201
  };
2156
2202
  }
2157
2203
  return {};
@@ -3519,8 +3565,77 @@ var _NoopRuntimeManager = class _NoopRuntimeManager {
3519
3565
  __name(_NoopRuntimeManager, "NoopRuntimeManager");
3520
3566
  var NoopRuntimeManager = _NoopRuntimeManager;
3521
3567
 
3568
+ // src/v3/usage/noopUsageManager.ts
3569
+ var _NoopUsageManager = class _NoopUsageManager {
3570
+ disable() {
3571
+ }
3572
+ start() {
3573
+ return {
3574
+ sample: () => ({
3575
+ cpuTime: 0,
3576
+ wallTime: 0
3577
+ })
3578
+ };
3579
+ }
3580
+ stop(measurement) {
3581
+ return measurement.sample();
3582
+ }
3583
+ pauseAsync(cb) {
3584
+ return cb();
3585
+ }
3586
+ sample() {
3587
+ return void 0;
3588
+ }
3589
+ };
3590
+ __name(_NoopUsageManager, "NoopUsageManager");
3591
+ var NoopUsageManager = _NoopUsageManager;
3592
+
3593
+ // src/v3/usage/api.ts
3594
+ var API_NAME4 = "usage";
3595
+ var NOOP_USAGE_MANAGER = new NoopUsageManager();
3596
+ var _getUsageManager, getUsageManager_fn;
3597
+ var _UsageAPI = class _UsageAPI {
3598
+ constructor() {
3599
+ __privateAdd(this, _getUsageManager);
3600
+ }
3601
+ static getInstance() {
3602
+ if (!this._instance) {
3603
+ this._instance = new _UsageAPI();
3604
+ }
3605
+ return this._instance;
3606
+ }
3607
+ setGlobalUsageManager(manager) {
3608
+ return registerGlobal(API_NAME4, manager);
3609
+ }
3610
+ disable() {
3611
+ __privateMethod(this, _getUsageManager, getUsageManager_fn).call(this).disable();
3612
+ unregisterGlobal(API_NAME4);
3613
+ }
3614
+ start() {
3615
+ return __privateMethod(this, _getUsageManager, getUsageManager_fn).call(this).start();
3616
+ }
3617
+ stop(measurement) {
3618
+ return __privateMethod(this, _getUsageManager, getUsageManager_fn).call(this).stop(measurement);
3619
+ }
3620
+ pauseAsync(cb) {
3621
+ return __privateMethod(this, _getUsageManager, getUsageManager_fn).call(this).pauseAsync(cb);
3622
+ }
3623
+ sample() {
3624
+ return __privateMethod(this, _getUsageManager, getUsageManager_fn).call(this).sample();
3625
+ }
3626
+ };
3627
+ _getUsageManager = new WeakSet();
3628
+ getUsageManager_fn = /* @__PURE__ */ __name(function() {
3629
+ return getGlobal(API_NAME4) ?? NOOP_USAGE_MANAGER;
3630
+ }, "#getUsageManager");
3631
+ __name(_UsageAPI, "UsageAPI");
3632
+ var UsageAPI = _UsageAPI;
3633
+
3634
+ // src/v3/usage-api.ts
3635
+ var usage = UsageAPI.getInstance();
3636
+
3522
3637
  // src/v3/runtime/index.ts
3523
- var API_NAME4 = "runtime";
3638
+ var API_NAME5 = "runtime";
3524
3639
  var NOOP_RUNTIME_MANAGER = new NoopRuntimeManager();
3525
3640
  var _getRuntimeManager, getRuntimeManager_fn;
3526
3641
  var _RuntimeAPI = class _RuntimeAPI {
@@ -3534,28 +3649,28 @@ var _RuntimeAPI = class _RuntimeAPI {
3534
3649
  return this._instance;
3535
3650
  }
3536
3651
  waitForDuration(ms) {
3537
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForDuration(ms);
3652
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForDuration(ms));
3538
3653
  }
3539
3654
  waitUntil(date) {
3540
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitUntil(date);
3655
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitUntil(date));
3541
3656
  }
3542
3657
  waitForTask(params) {
3543
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForTask(params);
3658
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForTask(params));
3544
3659
  }
3545
3660
  waitForBatch(params) {
3546
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForBatch(params);
3661
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForBatch(params));
3547
3662
  }
3548
3663
  setGlobalRuntimeManager(runtimeManager) {
3549
- return registerGlobal(API_NAME4, runtimeManager);
3664
+ return registerGlobal(API_NAME5, runtimeManager);
3550
3665
  }
3551
3666
  disable() {
3552
3667
  __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).disable();
3553
- unregisterGlobal(API_NAME4);
3668
+ unregisterGlobal(API_NAME5);
3554
3669
  }
3555
3670
  };
3556
3671
  _getRuntimeManager = new WeakSet();
3557
3672
  getRuntimeManager_fn = /* @__PURE__ */ __name(function() {
3558
- return getGlobal(API_NAME4) ?? NOOP_RUNTIME_MANAGER;
3673
+ return getGlobal(API_NAME5) ?? NOOP_RUNTIME_MANAGER;
3559
3674
  }, "#getRuntimeManager");
3560
3675
  __name(_RuntimeAPI, "RuntimeAPI");
3561
3676
  var RuntimeAPI = _RuntimeAPI;
@@ -3572,7 +3687,7 @@ function getEnvVar(name) {
3572
3687
  __name(getEnvVar, "getEnvVar");
3573
3688
 
3574
3689
  // src/v3/apiClientManager/index.ts
3575
- var API_NAME5 = "api-client";
3690
+ var API_NAME6 = "api-client";
3576
3691
  var _getConfig, getConfig_fn;
3577
3692
  var _APIClientManagerAPI = class _APIClientManagerAPI {
3578
3693
  constructor() {
@@ -3585,10 +3700,10 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
3585
3700
  return this._instance;
3586
3701
  }
3587
3702
  disable() {
3588
- unregisterGlobal(API_NAME5);
3703
+ unregisterGlobal(API_NAME6);
3589
3704
  }
3590
3705
  setGlobalAPIClientConfiguration(config) {
3591
- return registerGlobal(API_NAME5, config);
3706
+ return registerGlobal(API_NAME6, config);
3592
3707
  }
3593
3708
  get baseURL() {
3594
3709
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
@@ -3607,7 +3722,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
3607
3722
  };
3608
3723
  _getConfig = new WeakSet();
3609
3724
  getConfig_fn = /* @__PURE__ */ __name(function() {
3610
- return getGlobal(API_NAME5);
3725
+ return getGlobal(API_NAME6);
3611
3726
  }, "#getConfig");
3612
3727
  __name(_APIClientManagerAPI, "APIClientManagerAPI");
3613
3728
  var APIClientManagerAPI = _APIClientManagerAPI;
@@ -3642,7 +3757,7 @@ __name(_NoopTaskCatalog, "NoopTaskCatalog");
3642
3757
  var NoopTaskCatalog = _NoopTaskCatalog;
3643
3758
 
3644
3759
  // src/v3/task-catalog/index.ts
3645
- var API_NAME6 = "task-catalog";
3760
+ var API_NAME7 = "task-catalog";
3646
3761
  var NOOP_TASK_CATALOG = new NoopTaskCatalog();
3647
3762
  var _getCatalog, getCatalog_fn;
3648
3763
  var _TaskCatalogAPI = class _TaskCatalogAPI {
@@ -3656,10 +3771,10 @@ var _TaskCatalogAPI = class _TaskCatalogAPI {
3656
3771
  return this._instance;
3657
3772
  }
3658
3773
  setGlobalTaskCatalog(taskCatalog2) {
3659
- return registerGlobal(API_NAME6, taskCatalog2);
3774
+ return registerGlobal(API_NAME7, taskCatalog2);
3660
3775
  }
3661
3776
  disable() {
3662
- unregisterGlobal(API_NAME6);
3777
+ unregisterGlobal(API_NAME7);
3663
3778
  }
3664
3779
  registerTaskMetadata(task) {
3665
3780
  __privateMethod(this, _getCatalog, getCatalog_fn).call(this).registerTaskMetadata(task);
@@ -3685,7 +3800,7 @@ var _TaskCatalogAPI = class _TaskCatalogAPI {
3685
3800
  };
3686
3801
  _getCatalog = new WeakSet();
3687
3802
  getCatalog_fn = /* @__PURE__ */ __name(function() {
3688
- return getGlobal(API_NAME6) ?? NOOP_TASK_CATALOG;
3803
+ return getGlobal(API_NAME7) ?? NOOP_TASK_CATALOG;
3689
3804
  }, "#getCatalog");
3690
3805
  __name(_TaskCatalogAPI, "TaskCatalogAPI");
3691
3806
  var TaskCatalogAPI = _TaskCatalogAPI;
@@ -3805,6 +3920,7 @@ var _TriggerTracer = class _TriggerTracer {
3805
3920
  [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3806
3921
  }
3807
3922
  }, parentContext).end();
3923
+ const usageMeasurement = usage.start();
3808
3924
  try {
3809
3925
  return await fn(span);
3810
3926
  } catch (e) {
@@ -3816,6 +3932,12 @@ var _TriggerTracer = class _TriggerTracer {
3816
3932
  });
3817
3933
  throw e;
3818
3934
  } finally {
3935
+ const usageSample = usage.stop(usageMeasurement);
3936
+ const machine = taskContext.ctx?.machine;
3937
+ span.setAttributes({
3938
+ [SemanticInternalAttributes.USAGE_DURATION_MS]: usageSample.cpuTime,
3939
+ [SemanticInternalAttributes.USAGE_COST_IN_CENTS]: machine?.centsPerMs ? usageSample.cpuTime * machine.centsPerMs : 0
3940
+ });
3819
3941
  span.end(clock.preciseNow());
3820
3942
  }
3821
3943
  });
@@ -4350,9 +4472,11 @@ exports.ListRunResponse = ListRunResponse;
4350
4472
  exports.ListRunResponseItem = ListRunResponseItem;
4351
4473
  exports.ListScheduleOptions = ListScheduleOptions;
4352
4474
  exports.ListSchedulesResult = ListSchedulesResult;
4353
- exports.Machine = Machine;
4475
+ exports.MachineConfig = MachineConfig;
4354
4476
  exports.MachineCpu = MachineCpu;
4355
4477
  exports.MachineMemory = MachineMemory;
4478
+ exports.MachinePreset = MachinePreset;
4479
+ exports.MachinePresetName = MachinePresetName;
4356
4480
  exports.NULL_SENTINEL = NULL_SENTINEL;
4357
4481
  exports.NotFoundError = NotFoundError;
4358
4482
  exports.OFFLOAD_IO_PACKET_LENGTH_LIMIT = OFFLOAD_IO_PACKET_LENGTH_LIMIT;
@@ -4424,10 +4548,12 @@ exports.TaskRunExecutionQueue = TaskRunExecutionQueue;
4424
4548
  exports.TaskRunExecutionResult = TaskRunExecutionResult;
4425
4549
  exports.TaskRunExecutionRetry = TaskRunExecutionRetry;
4426
4550
  exports.TaskRunExecutionTask = TaskRunExecutionTask;
4551
+ exports.TaskRunExecutionUsage = TaskRunExecutionUsage;
4427
4552
  exports.TaskRunFailedExecutionResult = TaskRunFailedExecutionResult;
4428
4553
  exports.TaskRunInternalError = TaskRunInternalError;
4429
4554
  exports.TaskRunStringError = TaskRunStringError;
4430
4555
  exports.TaskRunSuccessfulExecutionResult = TaskRunSuccessfulExecutionResult;
4556
+ exports.TimezonesResult = TimezonesResult;
4431
4557
  exports.TriggerTaskRequestBody = TriggerTaskRequestBody;
4432
4558
  exports.TriggerTaskResponse = TriggerTaskResponse;
4433
4559
  exports.TriggerTracer = TriggerTracer;
@@ -4480,6 +4606,7 @@ exports.stringifyIO = stringifyIO;
4480
4606
  exports.taskCatalog = taskCatalog;
4481
4607
  exports.taskContext = taskContext;
4482
4608
  exports.unflattenAttributes = unflattenAttributes;
4609
+ exports.usage = usage;
4483
4610
  exports.workerToChildMessages = workerToChildMessages;
4484
4611
  //# sourceMappingURL=out.js.map
4485
4612
  //# sourceMappingURL=index.js.map