@trigger.dev/core 3.0.0-beta.14 → 3.0.0-beta.15

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.
package/dist/v3/index.js CHANGED
@@ -133,7 +133,8 @@ var TaskRun = zod.z.object({
133
133
  context: zod.z.any(),
134
134
  tags: zod.z.array(zod.z.string()),
135
135
  isTest: zod.z.boolean().default(false),
136
- createdAt: zod.z.coerce.date()
136
+ createdAt: zod.z.coerce.date(),
137
+ idempotencyKey: zod.z.string().optional()
137
138
  });
138
139
  var TaskRunExecutionTask = zod.z.object({
139
140
  id: zod.z.string(),
@@ -2069,7 +2070,8 @@ var SemanticInternalAttributes = {
2069
2070
  RETRY_AT: "retry.at",
2070
2071
  RETRY_DELAY: "retry.delay",
2071
2072
  RETRY_COUNT: "retry.count",
2072
- LINK_TITLE: "$link.title"
2073
+ LINK_TITLE: "$link.title",
2074
+ IDEMPOTENCY_KEY: "ctx.run.idempotencyKey"
2073
2075
  };
2074
2076
 
2075
2077
  // src/v3/tasks/taskContextManager.ts
@@ -2128,7 +2130,8 @@ var _TaskContextManager = class _TaskContextManager {
2128
2130
  [SemanticInternalAttributes.RUN_IS_TEST]: this.ctx.run.isTest,
2129
2131
  [SemanticInternalAttributes.ORGANIZATION_SLUG]: this.ctx.organization.slug,
2130
2132
  [SemanticInternalAttributes.ORGANIZATION_NAME]: this.ctx.organization.name,
2131
- [SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id
2133
+ [SemanticInternalAttributes.BATCH_ID]: this.ctx.batch?.id,
2134
+ [SemanticInternalAttributes.IDEMPOTENCY_KEY]: this.ctx.run.idempotencyKey
2132
2135
  };
2133
2136
  }
2134
2137
  return {};
@@ -2219,6 +2222,27 @@ var _ApiClient = class _ApiClient {
2219
2222
  this.accessToken = accessToken;
2220
2223
  this.baseUrl = baseUrl.replace(/\/$/, "");
2221
2224
  }
2225
+ async getRunResult(runId) {
2226
+ try {
2227
+ return await zodfetch(TaskRunExecutionResult, `${this.baseUrl}/api/v1/runs/${runId}/result`, {
2228
+ method: "GET",
2229
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2230
+ }, zodFetchOptions);
2231
+ } catch (error) {
2232
+ if (error instanceof APIError) {
2233
+ if (error.status === 404) {
2234
+ return void 0;
2235
+ }
2236
+ }
2237
+ throw error;
2238
+ }
2239
+ }
2240
+ async getBatchResults(batchId) {
2241
+ return await zodfetch(BatchTaskRunExecutionResult, `${this.baseUrl}/api/v1/batches/${batchId}/results`, {
2242
+ method: "GET",
2243
+ headers: __privateMethod(this, _getHeaders, getHeaders_fn).call(this, false)
2244
+ }, zodFetchOptions);
2245
+ }
2222
2246
  triggerTask(taskId, body, options) {
2223
2247
  return zodfetch(TriggerTaskResponse, `${this.baseUrl}/api/v1/tasks/${taskId}/trigger`, {
2224
2248
  method: "POST",
@@ -3464,12 +3488,23 @@ __name(_NoopTaskLogger, "NoopTaskLogger");
3464
3488
  var NoopTaskLogger = _NoopTaskLogger;
3465
3489
  function safeJsonProcess(value) {
3466
3490
  try {
3467
- return JSON.parse(JSON.stringify(value));
3491
+ return JSON.parse(JSON.stringify(value, jsonErrorReplacer));
3468
3492
  } catch {
3469
3493
  return value;
3470
3494
  }
3471
3495
  }
3472
3496
  __name(safeJsonProcess, "safeJsonProcess");
3497
+ function jsonErrorReplacer(key, value) {
3498
+ if (value instanceof Error) {
3499
+ return {
3500
+ name: value.name,
3501
+ message: value.message,
3502
+ stack: value.stack
3503
+ };
3504
+ }
3505
+ return value;
3506
+ }
3507
+ __name(jsonErrorReplacer, "jsonErrorReplacer");
3473
3508
 
3474
3509
  // src/v3/logger/index.ts
3475
3510
  var API_NAME3 = "logger";
@@ -3742,10 +3777,9 @@ var _DevRuntimeManager = class _DevRuntimeManager {
3742
3777
  this._pendingCompletionNotifications.delete(params.id);
3743
3778
  return pendingCompletion;
3744
3779
  }
3745
- const promise = new Promise((resolve, reject) => {
3780
+ const promise = new Promise((resolve) => {
3746
3781
  this._taskWaits.set(params.id, {
3747
- resolve,
3748
- reject
3782
+ resolve
3749
3783
  });
3750
3784
  });
3751
3785
  return await promise;
@@ -3762,16 +3796,11 @@ var _DevRuntimeManager = class _DevRuntimeManager {
3762
3796
  const pendingCompletion = this._pendingCompletionNotifications.get(runId);
3763
3797
  if (pendingCompletion) {
3764
3798
  this._pendingCompletionNotifications.delete(runId);
3765
- if (pendingCompletion.ok) {
3766
- resolve(pendingCompletion);
3767
- } else {
3768
- reject(pendingCompletion);
3769
- }
3799
+ resolve(pendingCompletion);
3770
3800
  return;
3771
3801
  }
3772
3802
  this._taskWaits.set(runId, {
3773
- resolve,
3774
- reject
3803
+ resolve
3775
3804
  });
3776
3805
  });
3777
3806
  }));
@@ -3787,11 +3816,7 @@ var _DevRuntimeManager = class _DevRuntimeManager {
3787
3816
  this._pendingCompletionNotifications.set(execution.run.id, completion);
3788
3817
  return;
3789
3818
  }
3790
- if (completion.ok) {
3791
- wait.resolve(completion);
3792
- } else {
3793
- wait.reject(completion);
3794
- }
3819
+ wait.resolve(completion);
3795
3820
  this._taskWaits.delete(execution.run.id);
3796
3821
  }
3797
3822
  };
@@ -3848,16 +3873,17 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3848
3873
  return this.waitForDuration(date.getTime() - Date.now());
3849
3874
  }
3850
3875
  async waitForTask(params) {
3851
- const promise = new Promise((resolve, reject) => {
3876
+ const promise = new Promise((resolve) => {
3852
3877
  this._taskWaits.set(params.id, {
3853
- resolve,
3854
- reject
3878
+ resolve
3855
3879
  });
3856
3880
  });
3857
3881
  await this.ipc.send("WAIT_FOR_TASK", {
3858
3882
  friendlyId: params.id
3859
3883
  });
3860
- return await promise;
3884
+ const result = await promise;
3885
+ clock.reset();
3886
+ return result;
3861
3887
  }
3862
3888
  async waitForBatch(params) {
3863
3889
  if (!params.runs.length) {
@@ -3869,8 +3895,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3869
3895
  const promise = Promise.all(params.runs.map((runId) => {
3870
3896
  return new Promise((resolve, reject) => {
3871
3897
  this._taskWaits.set(runId, {
3872
- resolve,
3873
- reject
3898
+ resolve
3874
3899
  });
3875
3900
  });
3876
3901
  }));
@@ -3879,6 +3904,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3879
3904
  runFriendlyIds: params.runs
3880
3905
  });
3881
3906
  const results = await promise;
3907
+ clock.reset();
3882
3908
  return {
3883
3909
  id: params.id,
3884
3910
  items: results
@@ -3889,11 +3915,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
3889
3915
  if (!wait) {
3890
3916
  return;
3891
3917
  }
3892
- if (completion.ok) {
3893
- wait.resolve(completion);
3894
- } else {
3895
- wait.reject(completion);
3896
- }
3918
+ wait.resolve(completion);
3897
3919
  this._taskWaits.delete(execution.run.id);
3898
3920
  }
3899
3921
  get waitThresholdInMs() {
@@ -4782,7 +4804,7 @@ var _TaskExecutor = class _TaskExecutor {
4782
4804
  }
4783
4805
  return {
4784
4806
  ok: true,
4785
- id: execution.attempt.id,
4807
+ id: execution.run.id,
4786
4808
  output: finalOutput.data,
4787
4809
  outputType: finalOutput.dataType
4788
4810
  };
@@ -4790,7 +4812,7 @@ var _TaskExecutor = class _TaskExecutor {
4790
4812
  recordSpanException(span, stringifyError);
4791
4813
  return {
4792
4814
  ok: false,
4793
- id: execution.attempt.id,
4815
+ id: execution.run.id,
4794
4816
  error: {
4795
4817
  type: "INTERNAL_ERROR",
4796
4818
  code: TaskRunErrorCodes.TASK_OUTPUT_ERROR,
@@ -4803,7 +4825,7 @@ var _TaskExecutor = class _TaskExecutor {
4803
4825
  const handleErrorResult = await __privateMethod(this, _handleError, handleError_fn).call(this, execution, runError, parsedPayload, ctx);
4804
4826
  recordSpanException(span, handleErrorResult.error ?? runError);
4805
4827
  return {
4806
- id: execution.attempt.id,
4828
+ id: execution.run.id,
4807
4829
  ok: false,
4808
4830
  error: handleErrorResult.error ? parseError(handleErrorResult.error) : parseError(runError),
4809
4831
  retry: handleErrorResult.status === "retry" ? handleErrorResult.retry : void 0,
@@ -4813,7 +4835,7 @@ var _TaskExecutor = class _TaskExecutor {
4813
4835
  recordSpanException(span, handleErrorError);
4814
4836
  return {
4815
4837
  ok: false,
4816
- id: execution.attempt.id,
4838
+ id: execution.run.id,
4817
4839
  error: {
4818
4840
  type: "INTERNAL_ERROR",
4819
4841
  code: TaskRunErrorCodes.HANDLE_ERROR_ERROR,