@trigger.dev/sdk 3.0.0-beta.50 → 3.0.0-beta.51

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
@@ -19,7 +19,7 @@ var __publicField = (obj, key, value) => {
19
19
  };
20
20
 
21
21
  // package.json
22
- var version = "3.0.0-beta.50";
22
+ var version = "3.0.0-beta.51";
23
23
 
24
24
  // src/v3/tracer.ts
25
25
  var tracer = new v3.TriggerTracer({
@@ -686,16 +686,16 @@ function rescheduleRun(runId, body, requestOptions) {
686
686
  }
687
687
  __name(rescheduleRun, "rescheduleRun");
688
688
  var MAX_POLL_ATTEMPTS = 500;
689
- async function poll(handle, options, requestOptions) {
689
+ async function poll(runId, options, requestOptions) {
690
690
  let attempts = 0;
691
691
  while (attempts++ < MAX_POLL_ATTEMPTS) {
692
- const run = await runs.retrieve(handle, requestOptions);
692
+ const run = await runs.retrieve(runId, requestOptions);
693
693
  if (run.isCompleted) {
694
694
  return run;
695
695
  }
696
696
  await new Promise((resolve) => setTimeout(resolve, options?.pollIntervalMs ?? 1e3));
697
697
  }
698
- throw new Error(`Run ${handle} did not complete after ${MAX_POLL_ATTEMPTS} attempts`);
698
+ throw new Error(`Run ${typeof runId === "string" ? runId : runId.id} did not complete after ${MAX_POLL_ATTEMPTS} attempts`);
699
699
  }
700
700
  __name(poll, "poll");
701
701
  var idempotencyKeys = {
@@ -749,265 +749,20 @@ function createTask(params) {
749
749
  const task3 = {
750
750
  id: params.id,
751
751
  trigger: async (payload, options) => {
752
- const apiClient = v3.apiClientManager.client;
753
- if (!apiClient) {
754
- throw apiClientMissingError();
755
- }
756
752
  const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
757
- const payloadPacket = await v3.stringifyIO(payload);
758
- const handle = await apiClient.triggerTask(params.id, {
759
- payload: payloadPacket.data,
760
- options: {
761
- queue: options?.queue ?? params.queue,
762
- concurrencyKey: options?.concurrencyKey,
763
- test: v3.taskContext.ctx?.run.isTest,
764
- payloadType: payloadPacket.dataType,
765
- idempotencyKey: await makeKey(options?.idempotencyKey),
766
- delay: options?.delay,
767
- ttl: options?.ttl,
768
- maxAttempts: options?.maxAttempts
769
- }
770
- }, {
771
- spanParentAsLink: true
772
- }, {
773
- name: taskMetadata ? `${taskMetadata.exportName}.trigger()` : `trigger()`,
774
- tracer,
775
- icon: "trigger",
776
- attributes: {
777
- [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
778
- ["messaging.client_id"]: v3.taskContext.worker?.id,
779
- [semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
780
- [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
781
- ...v3.accessoryAttributes({
782
- items: [
783
- {
784
- text: params.id,
785
- variant: "normal"
786
- }
787
- ],
788
- style: "codepath"
789
- })
790
- },
791
- onResponseBody: (body, span) => {
792
- body && typeof body === "object" && !Array.isArray(body) && "id" in body && typeof body.id === "string" && span.setAttribute("messaging.message.id", body.id);
793
- }
794
- });
795
- return handle;
753
+ return await trigger_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.trigger()` : `trigger()`, params.id, payload, options);
796
754
  },
797
755
  batchTrigger: async (items) => {
798
- const apiClient = v3.apiClientManager.client;
799
- if (!apiClient) {
800
- throw apiClientMissingError();
801
- }
802
756
  const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
803
- const response = await apiClient.batchTriggerTask(params.id, {
804
- items: await Promise.all(items.map(async (item) => {
805
- const payloadPacket = await v3.stringifyIO(item.payload);
806
- return {
807
- payload: payloadPacket.data,
808
- options: {
809
- queue: item.options?.queue ?? params.queue,
810
- concurrencyKey: item.options?.concurrencyKey,
811
- test: v3.taskContext.ctx?.run.isTest,
812
- payloadType: payloadPacket.dataType,
813
- idempotencyKey: await makeKey(item.options?.idempotencyKey),
814
- delay: item.options?.delay,
815
- ttl: item.options?.ttl,
816
- maxAttempts: item.options?.maxAttempts
817
- }
818
- };
819
- }))
820
- }, {
821
- spanParentAsLink: true
822
- }, {
823
- name: taskMetadata ? `${taskMetadata.exportName}.batchTrigger()` : `batchTrigger()`,
824
- icon: "trigger",
825
- tracer,
826
- attributes: {
827
- [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
828
- ["messaging.batch.message_count"]: items.length,
829
- ["messaging.client_id"]: v3.taskContext.worker?.id,
830
- [semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
831
- [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
832
- ...v3.accessoryAttributes({
833
- items: [
834
- {
835
- text: params.id,
836
- variant: "normal"
837
- }
838
- ],
839
- style: "codepath"
840
- })
841
- }
842
- });
843
- const handle = {
844
- batchId: response.batchId,
845
- runs: response.runs.map((id) => ({
846
- id
847
- }))
848
- };
849
- return handle;
757
+ return await batchTrigger_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.batchTrigger()` : `batchTrigger()`, params.id, items);
850
758
  },
851
759
  triggerAndWait: async (payload, options) => {
852
- const ctx = v3.taskContext.ctx;
853
- if (!ctx) {
854
- throw new Error("triggerAndWait can only be used from inside a task.run()");
855
- }
856
- const apiClient = v3.apiClientManager.client;
857
- if (!apiClient) {
858
- throw apiClientMissingError();
859
- }
860
760
  const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
861
- const payloadPacket = await v3.stringifyIO(payload);
862
- return await tracer.startActiveSpan(taskMetadata ? `${taskMetadata.exportName}.triggerAndWait()` : `triggerAndWait()`, async (span) => {
863
- const response = await apiClient.triggerTask(params.id, {
864
- payload: payloadPacket.data,
865
- options: {
866
- dependentAttempt: ctx.attempt.id,
867
- lockToVersion: v3.taskContext.worker?.version,
868
- queue: options?.queue ?? params.queue,
869
- concurrencyKey: options?.concurrencyKey,
870
- test: v3.taskContext.ctx?.run.isTest,
871
- payloadType: payloadPacket.dataType,
872
- idempotencyKey: await makeKey(options?.idempotencyKey),
873
- delay: options?.delay,
874
- ttl: options?.ttl,
875
- maxAttempts: options?.maxAttempts
876
- }
877
- });
878
- span.setAttribute("messaging.message.id", response.id);
879
- if (options?.idempotencyKey) {
880
- const result2 = await apiClient.getRunResult(response.id);
881
- if (result2) {
882
- v3.logger.log(`Result reused from previous task run with idempotency key '${options.idempotencyKey}'.`, {
883
- runId: response.id,
884
- idempotencyKey: options.idempotencyKey
885
- });
886
- return await handleTaskRunExecutionResult(result2);
887
- }
888
- }
889
- const result = await v3.runtime.waitForTask({
890
- id: response.id,
891
- ctx
892
- });
893
- return await handleTaskRunExecutionResult(result);
894
- }, {
895
- kind: api.SpanKind.PRODUCER,
896
- attributes: {
897
- [v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
898
- [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
899
- ["messaging.client_id"]: v3.taskContext.worker?.id,
900
- [semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
901
- [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
902
- ...v3.accessoryAttributes({
903
- items: [
904
- {
905
- text: params.id,
906
- variant: "normal"
907
- }
908
- ],
909
- style: "codepath"
910
- })
911
- }
912
- });
761
+ return await triggerAndWait_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.triggerAndWait()` : `triggerAndWait()`, params.id, payload, options);
913
762
  },
914
763
  batchTriggerAndWait: async (items) => {
915
- const ctx = v3.taskContext.ctx;
916
- if (!ctx) {
917
- throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
918
- }
919
- const apiClient = v3.apiClientManager.client;
920
- if (!apiClient) {
921
- throw apiClientMissingError();
922
- }
923
764
  const taskMetadata = v3.taskCatalog.getTaskMetadata(params.id);
924
- return await tracer.startActiveSpan(taskMetadata ? `${taskMetadata.exportName}.batchTriggerAndWait()` : `batchTriggerAndWait()`, async (span) => {
925
- const response = await apiClient.batchTriggerTask(params.id, {
926
- items: await Promise.all(items.map(async (item) => {
927
- const payloadPacket = await v3.stringifyIO(item.payload);
928
- return {
929
- payload: payloadPacket.data,
930
- options: {
931
- lockToVersion: v3.taskContext.worker?.version,
932
- queue: item.options?.queue ?? params.queue,
933
- concurrencyKey: item.options?.concurrencyKey,
934
- test: v3.taskContext.ctx?.run.isTest,
935
- payloadType: payloadPacket.dataType,
936
- idempotencyKey: await makeKey(item.options?.idempotencyKey),
937
- delay: item.options?.delay,
938
- ttl: item.options?.ttl,
939
- maxAttempts: item.options?.maxAttempts
940
- }
941
- };
942
- })),
943
- dependentAttempt: ctx.attempt.id
944
- });
945
- span.setAttribute("messaging.message.id", response.batchId);
946
- const getBatchResults = /* @__PURE__ */ __name(async () => {
947
- const hasIdempotencyKey = items.some((item) => item.options?.idempotencyKey);
948
- if (hasIdempotencyKey) {
949
- const results = await apiClient.getBatchResults(response.batchId);
950
- if (results) {
951
- return results;
952
- }
953
- }
954
- return {
955
- id: response.batchId,
956
- items: []
957
- };
958
- }, "getBatchResults");
959
- const existingResults = await getBatchResults();
960
- const incompleteRuns = response.runs.filter((runId) => !existingResults.items.some((item) => item.id === runId));
961
- if (incompleteRuns.length === 0) {
962
- v3.logger.log(`Results reused from previous task runs because of the provided idempotency keys.`);
963
- const runs3 = await handleBatchTaskRunExecutionResult(existingResults.items);
964
- return {
965
- id: existingResults.id,
966
- runs: runs3
967
- };
968
- }
969
- const result = await v3.runtime.waitForBatch({
970
- id: response.batchId,
971
- runs: incompleteRuns,
972
- ctx
973
- });
974
- const combinedItems = [];
975
- for (const runId of response.runs) {
976
- const existingItem = existingResults.items.find((item) => item.id === runId);
977
- if (existingItem) {
978
- combinedItems.push(existingItem);
979
- } else {
980
- const newItem = result.items.find((item) => item.id === runId);
981
- if (newItem) {
982
- combinedItems.push(newItem);
983
- }
984
- }
985
- }
986
- const runs2 = await handleBatchTaskRunExecutionResult(combinedItems);
987
- return {
988
- id: result.id,
989
- runs: runs2
990
- };
991
- }, {
992
- kind: api.SpanKind.PRODUCER,
993
- attributes: {
994
- [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
995
- ["messaging.batch.message_count"]: items.length,
996
- ["messaging.client_id"]: v3.taskContext.worker?.id,
997
- [semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: params.queue?.name ?? params.id,
998
- [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
999
- [v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
1000
- ...v3.accessoryAttributes({
1001
- items: [
1002
- {
1003
- text: params.id,
1004
- variant: "normal"
1005
- }
1006
- ],
1007
- style: "codepath"
1008
- })
1009
- }
1010
- });
765
+ return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.batchTriggerAndWait()` : `batchTriggerAndWait()`, params.id, items);
1011
766
  }
1012
767
  };
1013
768
  v3.taskCatalog.registerTaskMetadata({
@@ -1034,6 +789,27 @@ function createTask(params) {
1034
789
  }
1035
790
  __name(createTask, "createTask");
1036
791
  async function trigger(id, payload, options, requestOptions) {
792
+ return await trigger_internal("tasks.trigger()", id, payload, options, requestOptions);
793
+ }
794
+ __name(trigger, "trigger");
795
+ async function triggerAndWait(id, payload, options, requestOptions) {
796
+ return await triggerAndWait_internal("tasks.triggerAndWait()", id, payload, options, requestOptions);
797
+ }
798
+ __name(triggerAndWait, "triggerAndWait");
799
+ async function batchTriggerAndWait(id, items, requestOptions) {
800
+ return await batchTriggerAndWait_internal("tasks.batchTriggerAndWait()", id, items, requestOptions);
801
+ }
802
+ __name(batchTriggerAndWait, "batchTriggerAndWait");
803
+ async function triggerAndPoll(id, payload, options, requestOptions) {
804
+ const handle = await trigger(id, payload, options, requestOptions);
805
+ return runs.poll(handle, options, requestOptions);
806
+ }
807
+ __name(triggerAndPoll, "triggerAndPoll");
808
+ async function batchTrigger(id, items, requestOptions) {
809
+ return await batchTrigger_internal("tasks.batchTrigger()", id, items, requestOptions);
810
+ }
811
+ __name(batchTrigger, "batchTrigger");
812
+ async function trigger_internal(name2, id, payload, options, requestOptions) {
1037
813
  const apiClient = v3.apiClientManager.client;
1038
814
  if (!apiClient) {
1039
815
  throw apiClientMissingError();
@@ -1049,12 +825,13 @@ async function trigger(id, payload, options, requestOptions) {
1049
825
  idempotencyKey: await makeKey(options?.idempotencyKey),
1050
826
  delay: options?.delay,
1051
827
  ttl: options?.ttl,
828
+ tags: options?.tags,
1052
829
  maxAttempts: options?.maxAttempts
1053
830
  }
1054
831
  }, {
1055
832
  spanParentAsLink: true
1056
833
  }, {
1057
- name: `tasks.trigger()`,
834
+ name: name2,
1058
835
  tracer,
1059
836
  icon: "trigger",
1060
837
  attributes: {
@@ -1078,18 +855,72 @@ async function trigger(id, payload, options, requestOptions) {
1078
855
  });
1079
856
  return handle;
1080
857
  }
1081
- __name(trigger, "trigger");
1082
- async function triggerAndWait(id, payload, options, requestOptions) {
858
+ __name(trigger_internal, "trigger_internal");
859
+ async function batchTrigger_internal(name2, id, items, requestOptions) {
860
+ const apiClient = v3.apiClientManager.client;
861
+ if (!apiClient) {
862
+ throw apiClientMissingError();
863
+ }
864
+ const response = await apiClient.batchTriggerTask(id, {
865
+ items: await Promise.all(items.map(async (item) => {
866
+ const payloadPacket = await v3.stringifyIO(item.payload);
867
+ return {
868
+ payload: payloadPacket.data,
869
+ options: {
870
+ queue: item.options?.queue,
871
+ concurrencyKey: item.options?.concurrencyKey,
872
+ test: v3.taskContext.ctx?.run.isTest,
873
+ payloadType: payloadPacket.dataType,
874
+ idempotencyKey: await makeKey(item.options?.idempotencyKey),
875
+ delay: item.options?.delay,
876
+ ttl: item.options?.ttl,
877
+ tags: item.options?.tags,
878
+ maxAttempts: item.options?.maxAttempts
879
+ }
880
+ };
881
+ }))
882
+ }, {
883
+ spanParentAsLink: true
884
+ }, {
885
+ name: name2,
886
+ tracer,
887
+ icon: "trigger",
888
+ attributes: {
889
+ [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
890
+ ["messaging.client_id"]: v3.taskContext.worker?.id,
891
+ [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
892
+ ...v3.accessoryAttributes({
893
+ items: [
894
+ {
895
+ text: id,
896
+ variant: "normal"
897
+ }
898
+ ],
899
+ style: "codepath"
900
+ })
901
+ },
902
+ ...requestOptions
903
+ });
904
+ const handle = {
905
+ batchId: response.batchId,
906
+ runs: response.runs.map((id2) => ({
907
+ id: id2
908
+ }))
909
+ };
910
+ return handle;
911
+ }
912
+ __name(batchTrigger_internal, "batchTrigger_internal");
913
+ async function triggerAndWait_internal(name2, id, payload, options, requestOptions) {
1083
914
  const ctx = v3.taskContext.ctx;
1084
915
  if (!ctx) {
1085
- throw new Error("tasks.triggerAndWait can only be used from inside a task.run()");
916
+ throw new Error("triggerAndWait can only be used from inside a task.run()");
1086
917
  }
1087
918
  const apiClient = v3.apiClientManager.client;
1088
919
  if (!apiClient) {
1089
920
  throw apiClientMissingError();
1090
921
  }
1091
922
  const payloadPacket = await v3.stringifyIO(payload);
1092
- return await tracer.startActiveSpan("tasks.triggerAndWait()", async (span) => {
923
+ return await tracer.startActiveSpan(name2, async (span) => {
1093
924
  const response = await apiClient.triggerTask(id, {
1094
925
  payload: payloadPacket.data,
1095
926
  options: {
@@ -1102,6 +933,7 @@ async function triggerAndWait(id, payload, options, requestOptions) {
1102
933
  idempotencyKey: await makeKey(options?.idempotencyKey),
1103
934
  delay: options?.delay,
1104
935
  ttl: options?.ttl,
936
+ tags: options?.tags,
1105
937
  maxAttempts: options?.maxAttempts
1106
938
  }
1107
939
  }, {}, requestOptions);
@@ -1141,43 +973,92 @@ async function triggerAndWait(id, payload, options, requestOptions) {
1141
973
  }
1142
974
  });
1143
975
  }
1144
- __name(triggerAndWait, "triggerAndWait");
1145
- async function triggerAndPoll(id, payload, options, requestOptions) {
1146
- const handle = await trigger(id, payload, options, requestOptions);
1147
- return runs.poll(handle, options, requestOptions);
1148
- }
1149
- __name(triggerAndPoll, "triggerAndPoll");
1150
- async function batchTrigger(id, items, requestOptions) {
976
+ __name(triggerAndWait_internal, "triggerAndWait_internal");
977
+ async function batchTriggerAndWait_internal(name2, id, items, requestOptions) {
978
+ const ctx = v3.taskContext.ctx;
979
+ if (!ctx) {
980
+ throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
981
+ }
1151
982
  const apiClient = v3.apiClientManager.client;
1152
983
  if (!apiClient) {
1153
984
  throw apiClientMissingError();
1154
985
  }
1155
- const response = await apiClient.batchTriggerTask(id, {
1156
- items: await Promise.all(items.map(async (item) => {
1157
- const payloadPacket = await v3.stringifyIO(item.payload);
1158
- return {
1159
- payload: payloadPacket.data,
1160
- options: {
1161
- queue: item.options?.queue,
1162
- concurrencyKey: item.options?.concurrencyKey,
1163
- test: v3.taskContext.ctx?.run.isTest,
1164
- payloadType: payloadPacket.dataType,
1165
- idempotencyKey: await makeKey(item.options?.idempotencyKey),
1166
- delay: item.options?.delay,
1167
- ttl: item.options?.ttl,
1168
- maxAttempts: item.options?.maxAttempts
986
+ return await tracer.startActiveSpan(name2, async (span) => {
987
+ const response = await apiClient.batchTriggerTask(id, {
988
+ items: await Promise.all(items.map(async (item) => {
989
+ const payloadPacket = await v3.stringifyIO(item.payload);
990
+ return {
991
+ payload: payloadPacket.data,
992
+ options: {
993
+ lockToVersion: v3.taskContext.worker?.version,
994
+ queue: item.options?.queue,
995
+ concurrencyKey: item.options?.concurrencyKey,
996
+ test: v3.taskContext.ctx?.run.isTest,
997
+ payloadType: payloadPacket.dataType,
998
+ idempotencyKey: await makeKey(item.options?.idempotencyKey),
999
+ delay: item.options?.delay,
1000
+ ttl: item.options?.ttl,
1001
+ tags: item.options?.tags,
1002
+ maxAttempts: item.options?.maxAttempts
1003
+ }
1004
+ };
1005
+ })),
1006
+ dependentAttempt: ctx.attempt.id
1007
+ }, {}, requestOptions);
1008
+ span.setAttribute("messaging.message.id", response.batchId);
1009
+ const getBatchResults = /* @__PURE__ */ __name(async () => {
1010
+ const hasIdempotencyKey = items.some((item) => item.options?.idempotencyKey);
1011
+ if (hasIdempotencyKey) {
1012
+ const results = await apiClient.getBatchResults(response.batchId);
1013
+ if (results) {
1014
+ return results;
1169
1015
  }
1016
+ }
1017
+ return {
1018
+ id: response.batchId,
1019
+ items: []
1170
1020
  };
1171
- }))
1172
- }, {
1173
- spanParentAsLink: true
1021
+ }, "getBatchResults");
1022
+ const existingResults = await getBatchResults();
1023
+ const incompleteRuns = response.runs.filter((runId) => !existingResults.items.some((item) => item.id === runId));
1024
+ if (incompleteRuns.length === 0) {
1025
+ v3.logger.log(`Results reused from previous task runs because of the provided idempotency keys.`);
1026
+ const runs3 = await handleBatchTaskRunExecutionResult(existingResults.items);
1027
+ return {
1028
+ id: existingResults.id,
1029
+ runs: runs3
1030
+ };
1031
+ }
1032
+ const result = await v3.runtime.waitForBatch({
1033
+ id: response.batchId,
1034
+ runs: incompleteRuns,
1035
+ ctx
1036
+ });
1037
+ const combinedItems = [];
1038
+ for (const runId of response.runs) {
1039
+ const existingItem = existingResults.items.find((item) => item.id === runId);
1040
+ if (existingItem) {
1041
+ combinedItems.push(existingItem);
1042
+ } else {
1043
+ const newItem = result.items.find((item) => item.id === runId);
1044
+ if (newItem) {
1045
+ combinedItems.push(newItem);
1046
+ }
1047
+ }
1048
+ }
1049
+ const runs2 = await handleBatchTaskRunExecutionResult(combinedItems);
1050
+ return {
1051
+ id: result.id,
1052
+ runs: runs2
1053
+ };
1174
1054
  }, {
1175
- name: `tasks.batchTrigger()`,
1176
- tracer,
1177
- icon: "trigger",
1055
+ kind: api.SpanKind.PRODUCER,
1178
1056
  attributes: {
1057
+ [v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
1058
+ ["messaging.batch.message_count"]: items.length,
1179
1059
  [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
1180
1060
  ["messaging.client_id"]: v3.taskContext.worker?.id,
1061
+ [semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: id,
1181
1062
  [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
1182
1063
  ...v3.accessoryAttributes({
1183
1064
  items: [
@@ -1188,18 +1069,10 @@ async function batchTrigger(id, items, requestOptions) {
1188
1069
  ],
1189
1070
  style: "codepath"
1190
1071
  })
1191
- },
1192
- ...requestOptions
1072
+ }
1193
1073
  });
1194
- const handle = {
1195
- batchId: response.batchId,
1196
- runs: response.runs.map((id2) => ({
1197
- id: id2
1198
- }))
1199
- };
1200
- return handle;
1201
1074
  }
1202
- __name(batchTrigger, "batchTrigger");
1075
+ __name(batchTriggerAndWait_internal, "batchTriggerAndWait_internal");
1203
1076
  async function handleBatchTaskRunExecutionResult(items) {
1204
1077
  const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
1205
1078
  if (!someObjectStoreOutputs) {
@@ -1275,7 +1148,8 @@ var tasks = {
1275
1148
  trigger,
1276
1149
  triggerAndPoll,
1277
1150
  batchTrigger,
1278
- triggerAndWait
1151
+ triggerAndWait,
1152
+ batchTriggerAndWait
1279
1153
  };
1280
1154
  var wait = {
1281
1155
  for: async (options) => {
@@ -1481,6 +1355,53 @@ var usage = {
1481
1355
  };
1482
1356
  }
1483
1357
  };
1358
+ var tags = {
1359
+ add: addTags
1360
+ };
1361
+ async function addTags(tags2, requestOptions) {
1362
+ const apiClient = v3.apiClientManager.client;
1363
+ if (!apiClient) {
1364
+ throw apiClientMissingError();
1365
+ }
1366
+ const run = v3.taskContext.ctx?.run;
1367
+ if (!run) {
1368
+ throw new Error("Can't set tags outside of a run. You can trigger a task and set tags in the options.");
1369
+ }
1370
+ const $requestOptions = v3.mergeRequestOptions({
1371
+ tracer,
1372
+ name: "tags.set()",
1373
+ icon: "tag",
1374
+ attributes: {
1375
+ ...v3.accessoryAttributes({
1376
+ items: [
1377
+ {
1378
+ text: typeof tags2 === "string" ? tags2 : tags2.join(", "),
1379
+ variant: "normal"
1380
+ }
1381
+ ],
1382
+ style: "codepath"
1383
+ })
1384
+ }
1385
+ }, requestOptions);
1386
+ try {
1387
+ await apiClient.addTags(run.id, {
1388
+ tags: tags2
1389
+ }, $requestOptions);
1390
+ } catch (error) {
1391
+ if (error instanceof v3.UnprocessableEntityError) {
1392
+ v3.logger.error(error.message, {
1393
+ existingTags: run.tags,
1394
+ newTags: tags2
1395
+ });
1396
+ return;
1397
+ }
1398
+ v3.logger.error("Failed to set tags", {
1399
+ error
1400
+ });
1401
+ throw error;
1402
+ }
1403
+ }
1404
+ __name(addTags, "addTags");
1484
1405
 
1485
1406
  // src/v3/schedules/index.ts
1486
1407
  var schedules_exports = {};
@@ -1969,6 +1890,7 @@ exports.queue = queue;
1969
1890
  exports.retry = retry;
1970
1891
  exports.runs = runs;
1971
1892
  exports.schedules = schedules_exports;
1893
+ exports.tags = tags;
1972
1894
  exports.task = task;
1973
1895
  exports.tasks = tasks;
1974
1896
  exports.usage = usage;