@trigger.dev/sdk 3.0.0-beta.37 → 3.0.0-beta.39

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.
@@ -1,7 +1,6 @@
1
- import { RetryOptions, FetchRetryOptions, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ListProjectRunsQueryParams, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RetrieveRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
1
+ import { RetryOptions, FetchRetryOptions, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ListProjectRunsQueryParams, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RetrieveRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
2
  export { ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { HttpHandler } from 'msw';
4
- import { CursorPagePromise, OffsetLimitPagePromise } from '@trigger.dev/core/v3/apiClient/core';
5
4
 
6
5
  type CacheMetadata = {
7
6
  createdTime: number;
@@ -129,6 +128,7 @@ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOut
129
128
  * - 1
130
129
  * - 2
131
130
  * - 4
131
+ * @deprecated use preset instead
132
132
  */
133
133
  cpu?: MachineCpu;
134
134
  /** In GBs of RAM. The default is 1.
@@ -140,8 +140,11 @@ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOut
140
140
  * - 2
141
141
  * - 4
142
142
  * - 8
143
+ * * @deprecated use preset instead
143
144
  */
144
145
  memory?: MachineMemory;
146
+ /** Preset to use for the machine. Defaults to small-1x */
147
+ preset?: "micro" | "small-1x" | "small-2x" | "medium-1x" | "medium-2x" | "large-1x" | "large-2x";
145
148
  };
146
149
  /** This gets called when a task is triggered. It's where you put the code you want to execute.
147
150
  *
@@ -332,6 +335,84 @@ declare const wait: {
332
335
  }) => Promise<void>;
333
336
  };
334
337
 
338
+ type ComputeUsage = {
339
+ costInCents: number;
340
+ durationMs: number;
341
+ };
342
+ type CurrentUsage = {
343
+ compute: {
344
+ attempt: ComputeUsage;
345
+ total: ComputeUsage;
346
+ };
347
+ baseCostInCents: number;
348
+ totalCostInCents: number;
349
+ };
350
+ declare const usage: {
351
+ /**
352
+ * Get the current running usage of this task run.
353
+ *
354
+ * @example
355
+ *
356
+ * ```typescript
357
+ * import { usage, task } from "@trigger.dev/sdk/v3";
358
+ *
359
+ * export const myTask = task({
360
+ * id: "my-task",
361
+ * run: async (payload, { ctx }) => {
362
+ * // ... Do a bunch of work
363
+ *
364
+ * const currentUsage = usage.getCurrent();
365
+ *
366
+ * // You have access to the current compute cost and duration up to this point
367
+ * console.log("Current attempt compute cost and duration", {
368
+ * cost: currentUsage.compute.attempt.costInCents,
369
+ * duration: currentUsage.compute.attempt.durationMs,
370
+ * });
371
+ *
372
+ * // You also can see the total compute cost and duration up to this point in the run, across all attempts
373
+ * console.log("Current total compute cost and duration", {
374
+ * cost: currentUsage.compute.total.costInCents,
375
+ * duration: currentUsage.compute.total.durationMs,
376
+ * });
377
+ *
378
+ * // You can see the base cost of the run, which is the cost of the run before any compute costs
379
+ * console.log("Total cost", {
380
+ * cost: currentUsage.totalCostInCents,
381
+ * baseCost: currentUsage.baseCostInCents,
382
+ * });
383
+ * },
384
+ * });
385
+ * ```
386
+ */
387
+ getCurrent: () => CurrentUsage;
388
+ /**
389
+ * Measure the cost and duration of a function.
390
+ *
391
+ * @example
392
+ *
393
+ * ```typescript
394
+ * import { usage } from "@trigger.dev/sdk/v3";
395
+ *
396
+ * export const myTask = task({
397
+ * id: "my-task",
398
+ * run: async (payload, { ctx }) => {
399
+ * const { result, compute } = await usage.measure(async () => {
400
+ * // Do some work
401
+ * return "result";
402
+ * });
403
+ *
404
+ * console.log("Result", result);
405
+ * console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
406
+ * },
407
+ * });
408
+ * ```
409
+ */
410
+ measure: <T>(cb: () => Promise<T>) => Promise<{
411
+ result: T;
412
+ compute: ComputeUsage;
413
+ }>;
414
+ };
415
+
335
416
  type RetrieveRunResult = RetrieveRunResponse;
336
417
  declare const runs: {
337
418
  replay: typeof replayRun;
@@ -351,6 +432,7 @@ declare function task<TOutput, TInitOutput extends InitOutput>(params: TaskOptio
351
432
  * @param options
352
433
  * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
353
434
  * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
435
+ * @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
354
436
  * @param options.externalId - An optional external identifier for the schedule
355
437
  * @param options.deduplicationKey - An optional deduplication key for the schedule
356
438
  * @returns The created schedule
@@ -368,6 +450,7 @@ declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
368
450
  * @param options - The updated schedule options
369
451
  * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
370
452
  * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
453
+ * @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
371
454
  * @param options.externalId - An optional external identifier for the schedule
372
455
  * @returns The updated schedule
373
456
  */
@@ -395,12 +478,22 @@ declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
395
478
  * @returns The list of schedules
396
479
  */
397
480
  declare function list$1(options?: ListScheduleOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
481
+ /**
482
+ * Lists the possible timezones we support
483
+ * @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
484
+ */
485
+ declare function timezones(options?: {
486
+ excludeUtc?: boolean;
487
+ }): ApiPromise<{
488
+ timezones: string[];
489
+ }>;
398
490
 
399
491
  declare const index_activate: typeof activate;
400
492
  declare const index_deactivate: typeof deactivate;
401
493
  declare const index_task: typeof task;
494
+ declare const index_timezones: typeof timezones;
402
495
  declare namespace index {
403
- export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, update$1 as update };
496
+ export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, index_timezones as timezones, update$1 as update };
404
497
  }
405
498
 
406
499
  declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
@@ -447,4 +540,4 @@ declare namespace envvars {
447
540
  */
448
541
  declare function configure(options: ApiClientConfiguration): void;
449
542
 
450
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, wait };
543
+ export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, usage, wait };
@@ -1,7 +1,6 @@
1
- import { RetryOptions, FetchRetryOptions, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ListProjectRunsQueryParams, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RetrieveRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
1
+ import { RetryOptions, FetchRetryOptions, TaskRunContext, QueueOptions, InitOutput, MachineCpu, MachineMemory, RunFnParams, InitFnParams, HandleErrorFnParams, HandleErrorResult, MiddlewareFnParams, StartFnParams, SuccessFnParams, FailureFnParams, ListProjectRunsQueryParams, CursorPagePromise, ListRunResponseItem, ListRunsQueryParams, ApiPromise, ReplayRunResponse, CanceledRunResponse, RetrieveRunResponse, ScheduledTaskPayload, CreateScheduleOptions, ScheduleObject, UpdateScheduleOptions, DeletedScheduleObject, ListScheduleOptions, OffsetLimitPagePromise, ImportEnvironmentVariablesParams, EnvironmentVariableResponseBody, EnvironmentVariables, CreateEnvironmentVariableParams, EnvironmentVariableValue, UpdateEnvironmentVariableParams, ApiClientConfiguration } from '@trigger.dev/core/v3';
2
2
  export { ApiClientConfiguration, ApiError, AuthenticationError, BadRequestError, ConflictError, HandleErrorArgs, HandleErrorFunction, ImportEnvironmentVariablesParams, InternalServerError, LogLevel, NotFoundError, PermissionDeniedError, RateLimitError, ResolveEnvironmentVariablesFunction, ResolveEnvironmentVariablesParams, ResolveEnvironmentVariablesResult, RetryOptions, ProjectConfig as TriggerConfig, UnprocessableEntityError, logger } from '@trigger.dev/core/v3';
3
3
  import { HttpHandler } from 'msw';
4
- import { CursorPagePromise, OffsetLimitPagePromise } from '@trigger.dev/core/v3/apiClient/core';
5
4
 
6
5
  type CacheMetadata = {
7
6
  createdTime: number;
@@ -129,6 +128,7 @@ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOut
129
128
  * - 1
130
129
  * - 2
131
130
  * - 4
131
+ * @deprecated use preset instead
132
132
  */
133
133
  cpu?: MachineCpu;
134
134
  /** In GBs of RAM. The default is 1.
@@ -140,8 +140,11 @@ type TaskOptions<TPayload = void, TOutput = unknown, TInitOutput extends InitOut
140
140
  * - 2
141
141
  * - 4
142
142
  * - 8
143
+ * * @deprecated use preset instead
143
144
  */
144
145
  memory?: MachineMemory;
146
+ /** Preset to use for the machine. Defaults to small-1x */
147
+ preset?: "micro" | "small-1x" | "small-2x" | "medium-1x" | "medium-2x" | "large-1x" | "large-2x";
145
148
  };
146
149
  /** This gets called when a task is triggered. It's where you put the code you want to execute.
147
150
  *
@@ -332,6 +335,84 @@ declare const wait: {
332
335
  }) => Promise<void>;
333
336
  };
334
337
 
338
+ type ComputeUsage = {
339
+ costInCents: number;
340
+ durationMs: number;
341
+ };
342
+ type CurrentUsage = {
343
+ compute: {
344
+ attempt: ComputeUsage;
345
+ total: ComputeUsage;
346
+ };
347
+ baseCostInCents: number;
348
+ totalCostInCents: number;
349
+ };
350
+ declare const usage: {
351
+ /**
352
+ * Get the current running usage of this task run.
353
+ *
354
+ * @example
355
+ *
356
+ * ```typescript
357
+ * import { usage, task } from "@trigger.dev/sdk/v3";
358
+ *
359
+ * export const myTask = task({
360
+ * id: "my-task",
361
+ * run: async (payload, { ctx }) => {
362
+ * // ... Do a bunch of work
363
+ *
364
+ * const currentUsage = usage.getCurrent();
365
+ *
366
+ * // You have access to the current compute cost and duration up to this point
367
+ * console.log("Current attempt compute cost and duration", {
368
+ * cost: currentUsage.compute.attempt.costInCents,
369
+ * duration: currentUsage.compute.attempt.durationMs,
370
+ * });
371
+ *
372
+ * // You also can see the total compute cost and duration up to this point in the run, across all attempts
373
+ * console.log("Current total compute cost and duration", {
374
+ * cost: currentUsage.compute.total.costInCents,
375
+ * duration: currentUsage.compute.total.durationMs,
376
+ * });
377
+ *
378
+ * // You can see the base cost of the run, which is the cost of the run before any compute costs
379
+ * console.log("Total cost", {
380
+ * cost: currentUsage.totalCostInCents,
381
+ * baseCost: currentUsage.baseCostInCents,
382
+ * });
383
+ * },
384
+ * });
385
+ * ```
386
+ */
387
+ getCurrent: () => CurrentUsage;
388
+ /**
389
+ * Measure the cost and duration of a function.
390
+ *
391
+ * @example
392
+ *
393
+ * ```typescript
394
+ * import { usage } from "@trigger.dev/sdk/v3";
395
+ *
396
+ * export const myTask = task({
397
+ * id: "my-task",
398
+ * run: async (payload, { ctx }) => {
399
+ * const { result, compute } = await usage.measure(async () => {
400
+ * // Do some work
401
+ * return "result";
402
+ * });
403
+ *
404
+ * console.log("Result", result);
405
+ * console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
406
+ * },
407
+ * });
408
+ * ```
409
+ */
410
+ measure: <T>(cb: () => Promise<T>) => Promise<{
411
+ result: T;
412
+ compute: ComputeUsage;
413
+ }>;
414
+ };
415
+
335
416
  type RetrieveRunResult = RetrieveRunResponse;
336
417
  declare const runs: {
337
418
  replay: typeof replayRun;
@@ -351,6 +432,7 @@ declare function task<TOutput, TInitOutput extends InitOutput>(params: TaskOptio
351
432
  * @param options
352
433
  * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
353
434
  * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
435
+ * @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
354
436
  * @param options.externalId - An optional external identifier for the schedule
355
437
  * @param options.deduplicationKey - An optional deduplication key for the schedule
356
438
  * @returns The created schedule
@@ -368,6 +450,7 @@ declare function retrieve$1(scheduleId: string): ApiPromise<ScheduleObject>;
368
450
  * @param options - The updated schedule options
369
451
  * @param options.task - The identifier of the task to be scheduled (Must already exist and be a scheduled task)
370
452
  * @param options.cron - The cron expression for the schedule (e.g. `0 0 * * *`)
453
+ * @param options.timezone - An optional timezone for the schedule in the IANA format (e.g. `America/Los_Angeles`). Defaults to "UTC".
371
454
  * @param options.externalId - An optional external identifier for the schedule
372
455
  * @returns The updated schedule
373
456
  */
@@ -395,12 +478,22 @@ declare function activate(scheduleId: string): ApiPromise<ScheduleObject>;
395
478
  * @returns The list of schedules
396
479
  */
397
480
  declare function list$1(options?: ListScheduleOptions): OffsetLimitPagePromise<typeof ScheduleObject>;
481
+ /**
482
+ * Lists the possible timezones we support
483
+ * @param excludeUtc - By default "UTC" is included and is first. If true, "UTC" will be excluded.
484
+ */
485
+ declare function timezones(options?: {
486
+ excludeUtc?: boolean;
487
+ }): ApiPromise<{
488
+ timezones: string[];
489
+ }>;
398
490
 
399
491
  declare const index_activate: typeof activate;
400
492
  declare const index_deactivate: typeof deactivate;
401
493
  declare const index_task: typeof task;
494
+ declare const index_timezones: typeof timezones;
402
495
  declare namespace index {
403
- export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, update$1 as update };
496
+ export { index_activate as activate, create$1 as create, index_deactivate as deactivate, del$1 as del, list$1 as list, retrieve$1 as retrieve, index_task as task, index_timezones as timezones, update$1 as update };
404
497
  }
405
498
 
406
499
  declare function upload(projectRef: string, slug: string, params: ImportEnvironmentVariablesParams): ApiPromise<EnvironmentVariableResponseBody>;
@@ -447,4 +540,4 @@ declare namespace envvars {
447
540
  */
448
541
  declare function configure(options: ApiClientConfiguration): void;
449
542
 
450
- export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type Context, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, wait };
543
+ export { type CacheEntry, type CacheFunction, type CacheMetadata, type CacheStore, type ComputeUsage, type Context, type CurrentUsage, type Eventually, InMemoryCache, type Task, type TaskOptions, type WaitOptions, configure, createCache, envvars, queue, retry, runs, index as schedules, task$1 as task, usage, wait };
package/dist/v3/index.js CHANGED
@@ -4,6 +4,7 @@ var v3 = require('@trigger.dev/core/v3');
4
4
  var api = require('@opentelemetry/api');
5
5
  var semanticConventions = require('@opentelemetry/semantic-conventions');
6
6
  var node_async_hooks = require('node:async_hooks');
7
+ var zodfetch = require('@trigger.dev/core/v3/zodfetch');
7
8
 
8
9
  var __defProp = Object.defineProperty;
9
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -18,7 +19,7 @@ var __publicField = (obj, key, value) => {
18
19
  };
19
20
 
20
21
  // package.json
21
- var version = "3.0.0-beta.37";
22
+ var version = "3.0.0-beta.39";
22
23
 
23
24
  // src/v3/tracer.ts
24
25
  var tracer = new v3.TriggerTracer({
@@ -931,6 +932,116 @@ function calculateDurationInMs(options) {
931
932
  throw new Error("Invalid options");
932
933
  }
933
934
  __name(calculateDurationInMs, "calculateDurationInMs");
935
+ var usage = {
936
+ /**
937
+ * Get the current running usage of this task run.
938
+ *
939
+ * @example
940
+ *
941
+ * ```typescript
942
+ * import { usage, task } from "@trigger.dev/sdk/v3";
943
+ *
944
+ * export const myTask = task({
945
+ * id: "my-task",
946
+ * run: async (payload, { ctx }) => {
947
+ * // ... Do a bunch of work
948
+ *
949
+ * const currentUsage = usage.getCurrent();
950
+ *
951
+ * // You have access to the current compute cost and duration up to this point
952
+ * console.log("Current attempt compute cost and duration", {
953
+ * cost: currentUsage.compute.attempt.costInCents,
954
+ * duration: currentUsage.compute.attempt.durationMs,
955
+ * });
956
+ *
957
+ * // You also can see the total compute cost and duration up to this point in the run, across all attempts
958
+ * console.log("Current total compute cost and duration", {
959
+ * cost: currentUsage.compute.total.costInCents,
960
+ * duration: currentUsage.compute.total.durationMs,
961
+ * });
962
+ *
963
+ * // You can see the base cost of the run, which is the cost of the run before any compute costs
964
+ * console.log("Total cost", {
965
+ * cost: currentUsage.totalCostInCents,
966
+ * baseCost: currentUsage.baseCostInCents,
967
+ * });
968
+ * },
969
+ * });
970
+ * ```
971
+ */
972
+ getCurrent: () => {
973
+ const sample = v3.usage.sample();
974
+ const machine = v3.taskContext.ctx?.machine;
975
+ const run = v3.taskContext.ctx?.run;
976
+ if (!sample) {
977
+ return {
978
+ compute: {
979
+ attempt: {
980
+ costInCents: 0,
981
+ durationMs: 0
982
+ },
983
+ total: {
984
+ costInCents: run?.costInCents ?? 0,
985
+ durationMs: run?.durationMs ?? 0
986
+ }
987
+ },
988
+ baseCostInCents: run?.baseCostInCents ?? 0,
989
+ totalCostInCents: (run?.costInCents ?? 0) + (run?.baseCostInCents ?? 0)
990
+ };
991
+ }
992
+ const currentCostInCents = machine?.centsPerMs ? sample.cpuTime * machine.centsPerMs : 0;
993
+ return {
994
+ compute: {
995
+ attempt: {
996
+ costInCents: currentCostInCents,
997
+ durationMs: sample.cpuTime
998
+ },
999
+ total: {
1000
+ costInCents: (run?.costInCents ?? 0) + currentCostInCents,
1001
+ durationMs: (run?.durationMs ?? 0) + sample.cpuTime
1002
+ }
1003
+ },
1004
+ baseCostInCents: run?.baseCostInCents ?? 0,
1005
+ totalCostInCents: (run?.costInCents ?? 0) + currentCostInCents + (run?.baseCostInCents ?? 0)
1006
+ };
1007
+ },
1008
+ /**
1009
+ * Measure the cost and duration of a function.
1010
+ *
1011
+ * @example
1012
+ *
1013
+ * ```typescript
1014
+ * import { usage } from "@trigger.dev/sdk/v3";
1015
+ *
1016
+ * export const myTask = task({
1017
+ * id: "my-task",
1018
+ * run: async (payload, { ctx }) => {
1019
+ * const { result, compute } = await usage.measure(async () => {
1020
+ * // Do some work
1021
+ * return "result";
1022
+ * });
1023
+ *
1024
+ * console.log("Result", result);
1025
+ * console.log("Cost and duration", { cost: compute.costInCents, duration: compute.durationMs });
1026
+ * },
1027
+ * });
1028
+ * ```
1029
+ */
1030
+ measure: async (cb) => {
1031
+ const measurement = v3.usage.start();
1032
+ const result = await cb();
1033
+ const sample = v3.usage.stop(measurement);
1034
+ const machine = v3.taskContext.ctx?.machine;
1035
+ const costInCents = machine?.centsPerMs ? sample.cpuTime * machine.centsPerMs : 0;
1036
+ return {
1037
+ result,
1038
+ compute: {
1039
+ costInCents,
1040
+ durationMs: sample.cpuTime
1041
+ }
1042
+ };
1043
+ }
1044
+ };
934
1045
  var runs = {
935
1046
  replay: replayRun,
936
1047
  cancel: cancelRun,
@@ -983,6 +1094,7 @@ __export(schedules_exports, {
983
1094
  list: () => list,
984
1095
  retrieve: () => retrieve,
985
1096
  task: () => task2,
1097
+ timezones: () => timezones,
986
1098
  update: () => update
987
1099
  });
988
1100
  function task2(params) {
@@ -1049,6 +1161,19 @@ function list(options) {
1049
1161
  return apiClient.listSchedules(options);
1050
1162
  }
1051
1163
  __name(list, "list");
1164
+ function timezones(options) {
1165
+ const baseUrl = v3.apiClientManager.baseURL;
1166
+ if (!baseUrl) {
1167
+ throw apiClientMissingError();
1168
+ }
1169
+ return zodfetch.zodfetch(v3.TimezonesResult, `${baseUrl}/api/v1/timezones${options?.excludeUtc === true ? "?excludeUtc=true" : ""}`, {
1170
+ method: "GET",
1171
+ headers: {
1172
+ "Content-Type": "application/json"
1173
+ }
1174
+ });
1175
+ }
1176
+ __name(timezones, "timezones");
1052
1177
 
1053
1178
  // src/v3/envvars.ts
1054
1179
  var envvars_exports = {};
@@ -1302,6 +1427,7 @@ exports.retry = retry;
1302
1427
  exports.runs = runs;
1303
1428
  exports.schedules = schedules_exports;
1304
1429
  exports.task = task;
1430
+ exports.usage = usage;
1305
1431
  exports.wait = wait;
1306
1432
  //# sourceMappingURL=out.js.map
1307
1433
  //# sourceMappingURL=index.js.map