@trigger.dev/core 3.0.0-beta.37 → 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-9lty-Du5.d.mts → messages-BD0yXLtn.d.mts} +2370 -141
  6. package/dist/{messages-9lty-Du5.d.ts → messages-BD0yXLtn.d.ts} +2370 -141
  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 +117 -52
  12. package/dist/v3/index.d.ts +117 -52
  13. package/dist/v3/index.js +204 -58
  14. package/dist/v3/index.js.map +1 -1
  15. package/dist/v3/index.mjs +199 -58
  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 +404 -43
  28. package/dist/v3/workers/index.js.map +1 -1
  29. package/dist/v3/workers/index.mjs +402 -44
  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.37";
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({
@@ -750,15 +777,26 @@ var ScheduledTaskPayload = zod.z.object({
750
777
  You can use this to remove the schedule, update it, etc */
751
778
  scheduleId: zod.z.string(),
752
779
  /** When the task was scheduled to run.
753
- * 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
+ ``` */
754
788
  timestamp: zod.z.date(),
755
789
  /** When the task was last run (it has been).
756
- 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. */
757
791
  lastTimestamp: zod.z.date().optional(),
758
792
  /** You can optionally provide an external id when creating the schedule.
759
793
  Usually you would use a userId or some other unique identifier.
760
794
  This defaults to undefined if you didn't provide one. */
761
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(),
762
800
  /** The next 5 dates this task is scheduled to run */
763
801
  upcoming: zod.z.array(zod.z.date())
764
802
  });
@@ -782,17 +820,30 @@ var CreateScheduleOptions = zod.z.object({
782
820
 
783
821
  */
784
822
  cron: zod.z.string(),
785
- /** (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.
786
824
  *
787
- * This is useful if you don't want to create duplicate schedules for a user. */
788
- deduplicationKey: zod.z.string().optional(),
825
+ * This is required to prevent you from creating duplicate schedules. */
826
+ deduplicationKey: zod.z.string(),
789
827
  /** Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
790
828
  *
791
829
  * This allows you to have per-user CRON tasks.
792
830
  */
793
- 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
794
846
  });
795
- var UpdateScheduleOptions = CreateScheduleOptions;
796
847
  var ScheduleGenerator = zod.z.object({
797
848
  type: zod.z.literal("CRON"),
798
849
  expression: zod.z.string(),
@@ -805,6 +856,7 @@ var ScheduleObject = zod.z.object({
805
856
  deduplicationKey: zod.z.string().nullish(),
806
857
  externalId: zod.z.string().nullish(),
807
858
  generator: ScheduleGenerator,
859
+ timezone: zod.z.string(),
808
860
  nextRun: zod.z.coerce.date().nullish(),
809
861
  environments: zod.z.array(zod.z.object({
810
862
  id: zod.z.string(),
@@ -827,6 +879,9 @@ var ListScheduleOptions = zod.z.object({
827
879
  page: zod.z.number().optional(),
828
880
  perPage: zod.z.number().optional()
829
881
  });
882
+ var TimezonesResult = zod.z.object({
883
+ timezones: zod.z.array(zod.z.string())
884
+ });
830
885
  var RunStatus = zod.z.enum([
831
886
  /// Task hasn't been deployed yet but is waiting to be executed
832
887
  "WAITING_FOR_DEPLOY",
@@ -950,7 +1005,7 @@ var BackgroundWorkerServerMessages = zod.z.discriminatedUnion("type", [
950
1005
  type: zod.z.literal("SCHEDULE_ATTEMPT"),
951
1006
  image: zod.z.string(),
952
1007
  version: zod.z.string(),
953
- machine: Machine,
1008
+ machine: MachinePreset,
954
1009
  // identifiers
955
1010
  id: zod.z.string().optional(),
956
1011
  envId: zod.z.string(),
@@ -1295,7 +1350,7 @@ var PlatformToProviderMessages = {
1295
1350
  location: zod.z.string(),
1296
1351
  reason: zod.z.string().optional(),
1297
1352
  imageRef: zod.z.string(),
1298
- machine: Machine,
1353
+ machine: MachinePreset,
1299
1354
  // identifiers
1300
1355
  checkpointId: zod.z.string(),
1301
1356
  envId: zod.z.string(),
@@ -2045,6 +2100,10 @@ var SemanticInternalAttributes = {
2045
2100
  TASK_EXPORT_NAME: "ctx.task.exportName",
2046
2101
  QUEUE_NAME: "ctx.queue.name",
2047
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",
2048
2107
  SPAN_PARTIAL: "$span.partial",
2049
2108
  SPAN_ID: "$span.span_id",
2050
2109
  OUTPUT: "$output",
@@ -2068,7 +2127,9 @@ var SemanticInternalAttributes = {
2068
2127
  RETRY_DELAY: "retry.delay",
2069
2128
  RETRY_COUNT: "retry.count",
2070
2129
  LINK_TITLE: "$link.title",
2071
- IDEMPOTENCY_KEY: "ctx.run.idempotencyKey"
2130
+ IDEMPOTENCY_KEY: "ctx.run.idempotencyKey",
2131
+ USAGE_DURATION_MS: "$usage.durationMs",
2132
+ USAGE_COST_IN_CENTS: "$usage.costInCents"
2072
2133
  };
2073
2134
 
2074
2135
  // src/v3/taskContext/index.ts
@@ -2132,7 +2193,11 @@ var _TaskContextAPI = class _TaskContextAPI {
2132
2193
  [SemanticInternalAttributes.ORGANIZATION_SLUG]: this.ctx.organization.slug,
2133
2194
  [SemanticInternalAttributes.ORGANIZATION_NAME]: this.ctx.organization.name,
2134
2195
  [SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id,
2135
- [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
2136
2201
  };
2137
2202
  }
2138
2203
  return {};
@@ -3500,8 +3565,77 @@ var _NoopRuntimeManager = class _NoopRuntimeManager {
3500
3565
  __name(_NoopRuntimeManager, "NoopRuntimeManager");
3501
3566
  var NoopRuntimeManager = _NoopRuntimeManager;
3502
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
+
3503
3637
  // src/v3/runtime/index.ts
3504
- var API_NAME4 = "runtime";
3638
+ var API_NAME5 = "runtime";
3505
3639
  var NOOP_RUNTIME_MANAGER = new NoopRuntimeManager();
3506
3640
  var _getRuntimeManager, getRuntimeManager_fn;
3507
3641
  var _RuntimeAPI = class _RuntimeAPI {
@@ -3515,28 +3649,28 @@ var _RuntimeAPI = class _RuntimeAPI {
3515
3649
  return this._instance;
3516
3650
  }
3517
3651
  waitForDuration(ms) {
3518
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForDuration(ms);
3652
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForDuration(ms));
3519
3653
  }
3520
3654
  waitUntil(date) {
3521
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitUntil(date);
3655
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitUntil(date));
3522
3656
  }
3523
3657
  waitForTask(params) {
3524
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForTask(params);
3658
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForTask(params));
3525
3659
  }
3526
3660
  waitForBatch(params) {
3527
- return __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForBatch(params);
3661
+ return usage.pauseAsync(() => __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).waitForBatch(params));
3528
3662
  }
3529
3663
  setGlobalRuntimeManager(runtimeManager) {
3530
- return registerGlobal(API_NAME4, runtimeManager);
3664
+ return registerGlobal(API_NAME5, runtimeManager);
3531
3665
  }
3532
3666
  disable() {
3533
3667
  __privateMethod(this, _getRuntimeManager, getRuntimeManager_fn).call(this).disable();
3534
- unregisterGlobal(API_NAME4);
3668
+ unregisterGlobal(API_NAME5);
3535
3669
  }
3536
3670
  };
3537
3671
  _getRuntimeManager = new WeakSet();
3538
3672
  getRuntimeManager_fn = /* @__PURE__ */ __name(function() {
3539
- return getGlobal(API_NAME4) ?? NOOP_RUNTIME_MANAGER;
3673
+ return getGlobal(API_NAME5) ?? NOOP_RUNTIME_MANAGER;
3540
3674
  }, "#getRuntimeManager");
3541
3675
  __name(_RuntimeAPI, "RuntimeAPI");
3542
3676
  var RuntimeAPI = _RuntimeAPI;
@@ -3553,7 +3687,7 @@ function getEnvVar(name) {
3553
3687
  __name(getEnvVar, "getEnvVar");
3554
3688
 
3555
3689
  // src/v3/apiClientManager/index.ts
3556
- var API_NAME5 = "api-client";
3690
+ var API_NAME6 = "api-client";
3557
3691
  var _getConfig, getConfig_fn;
3558
3692
  var _APIClientManagerAPI = class _APIClientManagerAPI {
3559
3693
  constructor() {
@@ -3566,10 +3700,10 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
3566
3700
  return this._instance;
3567
3701
  }
3568
3702
  disable() {
3569
- unregisterGlobal(API_NAME5);
3703
+ unregisterGlobal(API_NAME6);
3570
3704
  }
3571
3705
  setGlobalAPIClientConfiguration(config) {
3572
- return registerGlobal(API_NAME5, config);
3706
+ return registerGlobal(API_NAME6, config);
3573
3707
  }
3574
3708
  get baseURL() {
3575
3709
  const store = __privateMethod(this, _getConfig, getConfig_fn).call(this);
@@ -3588,7 +3722,7 @@ var _APIClientManagerAPI = class _APIClientManagerAPI {
3588
3722
  };
3589
3723
  _getConfig = new WeakSet();
3590
3724
  getConfig_fn = /* @__PURE__ */ __name(function() {
3591
- return getGlobal(API_NAME5);
3725
+ return getGlobal(API_NAME6);
3592
3726
  }, "#getConfig");
3593
3727
  __name(_APIClientManagerAPI, "APIClientManagerAPI");
3594
3728
  var APIClientManagerAPI = _APIClientManagerAPI;
@@ -3623,7 +3757,7 @@ __name(_NoopTaskCatalog, "NoopTaskCatalog");
3623
3757
  var NoopTaskCatalog = _NoopTaskCatalog;
3624
3758
 
3625
3759
  // src/v3/task-catalog/index.ts
3626
- var API_NAME6 = "task-catalog";
3760
+ var API_NAME7 = "task-catalog";
3627
3761
  var NOOP_TASK_CATALOG = new NoopTaskCatalog();
3628
3762
  var _getCatalog, getCatalog_fn;
3629
3763
  var _TaskCatalogAPI = class _TaskCatalogAPI {
@@ -3637,10 +3771,10 @@ var _TaskCatalogAPI = class _TaskCatalogAPI {
3637
3771
  return this._instance;
3638
3772
  }
3639
3773
  setGlobalTaskCatalog(taskCatalog2) {
3640
- return registerGlobal(API_NAME6, taskCatalog2);
3774
+ return registerGlobal(API_NAME7, taskCatalog2);
3641
3775
  }
3642
3776
  disable() {
3643
- unregisterGlobal(API_NAME6);
3777
+ unregisterGlobal(API_NAME7);
3644
3778
  }
3645
3779
  registerTaskMetadata(task) {
3646
3780
  __privateMethod(this, _getCatalog, getCatalog_fn).call(this).registerTaskMetadata(task);
@@ -3666,7 +3800,7 @@ var _TaskCatalogAPI = class _TaskCatalogAPI {
3666
3800
  };
3667
3801
  _getCatalog = new WeakSet();
3668
3802
  getCatalog_fn = /* @__PURE__ */ __name(function() {
3669
- return getGlobal(API_NAME6) ?? NOOP_TASK_CATALOG;
3803
+ return getGlobal(API_NAME7) ?? NOOP_TASK_CATALOG;
3670
3804
  }, "#getCatalog");
3671
3805
  __name(_TaskCatalogAPI, "TaskCatalogAPI");
3672
3806
  var TaskCatalogAPI = _TaskCatalogAPI;
@@ -3786,6 +3920,7 @@ var _TriggerTracer = class _TriggerTracer {
3786
3920
  [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId
3787
3921
  }
3788
3922
  }, parentContext).end();
3923
+ const usageMeasurement = usage.start();
3789
3924
  try {
3790
3925
  return await fn(span);
3791
3926
  } catch (e) {
@@ -3797,6 +3932,12 @@ var _TriggerTracer = class _TriggerTracer {
3797
3932
  });
3798
3933
  throw e;
3799
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
+ });
3800
3941
  span.end(clock.preciseNow());
3801
3942
  }
3802
3943
  });
@@ -4331,9 +4472,11 @@ exports.ListRunResponse = ListRunResponse;
4331
4472
  exports.ListRunResponseItem = ListRunResponseItem;
4332
4473
  exports.ListScheduleOptions = ListScheduleOptions;
4333
4474
  exports.ListSchedulesResult = ListSchedulesResult;
4334
- exports.Machine = Machine;
4475
+ exports.MachineConfig = MachineConfig;
4335
4476
  exports.MachineCpu = MachineCpu;
4336
4477
  exports.MachineMemory = MachineMemory;
4478
+ exports.MachinePreset = MachinePreset;
4479
+ exports.MachinePresetName = MachinePresetName;
4337
4480
  exports.NULL_SENTINEL = NULL_SENTINEL;
4338
4481
  exports.NotFoundError = NotFoundError;
4339
4482
  exports.OFFLOAD_IO_PACKET_LENGTH_LIMIT = OFFLOAD_IO_PACKET_LENGTH_LIMIT;
@@ -4405,10 +4548,12 @@ exports.TaskRunExecutionQueue = TaskRunExecutionQueue;
4405
4548
  exports.TaskRunExecutionResult = TaskRunExecutionResult;
4406
4549
  exports.TaskRunExecutionRetry = TaskRunExecutionRetry;
4407
4550
  exports.TaskRunExecutionTask = TaskRunExecutionTask;
4551
+ exports.TaskRunExecutionUsage = TaskRunExecutionUsage;
4408
4552
  exports.TaskRunFailedExecutionResult = TaskRunFailedExecutionResult;
4409
4553
  exports.TaskRunInternalError = TaskRunInternalError;
4410
4554
  exports.TaskRunStringError = TaskRunStringError;
4411
4555
  exports.TaskRunSuccessfulExecutionResult = TaskRunSuccessfulExecutionResult;
4556
+ exports.TimezonesResult = TimezonesResult;
4412
4557
  exports.TriggerTaskRequestBody = TriggerTaskRequestBody;
4413
4558
  exports.TriggerTaskResponse = TriggerTaskResponse;
4414
4559
  exports.TriggerTracer = TriggerTracer;
@@ -4461,6 +4606,7 @@ exports.stringifyIO = stringifyIO;
4461
4606
  exports.taskCatalog = taskCatalog;
4462
4607
  exports.taskContext = taskContext;
4463
4608
  exports.unflattenAttributes = unflattenAttributes;
4609
+ exports.usage = usage;
4464
4610
  exports.workerToChildMessages = workerToChildMessages;
4465
4611
  //# sourceMappingURL=out.js.map
4466
4612
  //# sourceMappingURL=index.js.map