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

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.52";
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 = {
@@ -746,268 +746,33 @@ function queue(options) {
746
746
  }
747
747
  __name(queue, "queue");
748
748
  function createTask(params) {
749
+ const customQueue = params.queue ? queue({
750
+ name: params.queue?.name ?? `task/${params.id}`,
751
+ ...params.queue
752
+ }) : void 0;
749
753
  const task3 = {
750
754
  id: params.id,
751
755
  trigger: async (payload, options) => {
752
- const apiClient = v3.apiClientManager.client;
753
- if (!apiClient) {
754
- throw apiClientMissingError();
755
- }
756
756
  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
- }
757
+ return await trigger_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.trigger()` : `trigger()`, params.id, payload, {
758
+ queue: customQueue,
759
+ ...options
794
760
  });
795
- return handle;
796
761
  },
797
762
  batchTrigger: async (items) => {
798
- const apiClient = v3.apiClientManager.client;
799
- if (!apiClient) {
800
- throw apiClientMissingError();
801
- }
802
763
  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;
764
+ return await batchTrigger_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.batchTrigger()` : `batchTrigger()`, params.id, items, void 0, customQueue);
850
765
  },
851
766
  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
767
  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
- }
768
+ return await triggerAndWait_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.triggerAndWait()` : `triggerAndWait()`, params.id, payload, {
769
+ queue: customQueue,
770
+ ...options
912
771
  });
913
772
  },
914
773
  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
774
  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
- });
775
+ return await batchTriggerAndWait_internal(taskMetadata && taskMetadata.exportName ? `${taskMetadata.exportName}.batchTriggerAndWait()` : `batchTriggerAndWait()`, params.id, items, void 0, customQueue);
1011
776
  }
1012
777
  };
1013
778
  v3.taskCatalog.registerTaskMetadata({
@@ -1034,6 +799,27 @@ function createTask(params) {
1034
799
  }
1035
800
  __name(createTask, "createTask");
1036
801
  async function trigger(id, payload, options, requestOptions) {
802
+ return await trigger_internal("tasks.trigger()", id, payload, options, requestOptions);
803
+ }
804
+ __name(trigger, "trigger");
805
+ async function triggerAndWait(id, payload, options, requestOptions) {
806
+ return await triggerAndWait_internal("tasks.triggerAndWait()", id, payload, options, requestOptions);
807
+ }
808
+ __name(triggerAndWait, "triggerAndWait");
809
+ async function batchTriggerAndWait(id, items, requestOptions) {
810
+ return await batchTriggerAndWait_internal("tasks.batchTriggerAndWait()", id, items, requestOptions);
811
+ }
812
+ __name(batchTriggerAndWait, "batchTriggerAndWait");
813
+ async function triggerAndPoll(id, payload, options, requestOptions) {
814
+ const handle = await trigger(id, payload, options, requestOptions);
815
+ return runs.poll(handle, options, requestOptions);
816
+ }
817
+ __name(triggerAndPoll, "triggerAndPoll");
818
+ async function batchTrigger(id, items, requestOptions) {
819
+ return await batchTrigger_internal("tasks.batchTrigger()", id, items, requestOptions);
820
+ }
821
+ __name(batchTrigger, "batchTrigger");
822
+ async function trigger_internal(name2, id, payload, options, requestOptions) {
1037
823
  const apiClient = v3.apiClientManager.client;
1038
824
  if (!apiClient) {
1039
825
  throw apiClientMissingError();
@@ -1049,12 +835,13 @@ async function trigger(id, payload, options, requestOptions) {
1049
835
  idempotencyKey: await makeKey(options?.idempotencyKey),
1050
836
  delay: options?.delay,
1051
837
  ttl: options?.ttl,
838
+ tags: options?.tags,
1052
839
  maxAttempts: options?.maxAttempts
1053
840
  }
1054
841
  }, {
1055
842
  spanParentAsLink: true
1056
843
  }, {
1057
- name: `tasks.trigger()`,
844
+ name: name2,
1058
845
  tracer,
1059
846
  icon: "trigger",
1060
847
  attributes: {
@@ -1078,18 +865,72 @@ async function trigger(id, payload, options, requestOptions) {
1078
865
  });
1079
866
  return handle;
1080
867
  }
1081
- __name(trigger, "trigger");
1082
- async function triggerAndWait(id, payload, options, requestOptions) {
868
+ __name(trigger_internal, "trigger_internal");
869
+ async function batchTrigger_internal(name2, id, items, requestOptions, queue2) {
870
+ const apiClient = v3.apiClientManager.client;
871
+ if (!apiClient) {
872
+ throw apiClientMissingError();
873
+ }
874
+ const response = await apiClient.batchTriggerTask(id, {
875
+ items: await Promise.all(items.map(async (item) => {
876
+ const payloadPacket = await v3.stringifyIO(item.payload);
877
+ return {
878
+ payload: payloadPacket.data,
879
+ options: {
880
+ queue: item.options?.queue ?? queue2,
881
+ concurrencyKey: item.options?.concurrencyKey,
882
+ test: v3.taskContext.ctx?.run.isTest,
883
+ payloadType: payloadPacket.dataType,
884
+ idempotencyKey: await makeKey(item.options?.idempotencyKey),
885
+ delay: item.options?.delay,
886
+ ttl: item.options?.ttl,
887
+ tags: item.options?.tags,
888
+ maxAttempts: item.options?.maxAttempts
889
+ }
890
+ };
891
+ }))
892
+ }, {
893
+ spanParentAsLink: true
894
+ }, {
895
+ name: name2,
896
+ tracer,
897
+ icon: "trigger",
898
+ attributes: {
899
+ [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
900
+ ["messaging.client_id"]: v3.taskContext.worker?.id,
901
+ [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
902
+ ...v3.accessoryAttributes({
903
+ items: [
904
+ {
905
+ text: id,
906
+ variant: "normal"
907
+ }
908
+ ],
909
+ style: "codepath"
910
+ })
911
+ },
912
+ ...requestOptions
913
+ });
914
+ const handle = {
915
+ batchId: response.batchId,
916
+ runs: response.runs.map((id2) => ({
917
+ id: id2
918
+ }))
919
+ };
920
+ return handle;
921
+ }
922
+ __name(batchTrigger_internal, "batchTrigger_internal");
923
+ async function triggerAndWait_internal(name2, id, payload, options, requestOptions) {
1083
924
  const ctx = v3.taskContext.ctx;
1084
925
  if (!ctx) {
1085
- throw new Error("tasks.triggerAndWait can only be used from inside a task.run()");
926
+ throw new Error("triggerAndWait can only be used from inside a task.run()");
1086
927
  }
1087
928
  const apiClient = v3.apiClientManager.client;
1088
929
  if (!apiClient) {
1089
930
  throw apiClientMissingError();
1090
931
  }
1091
932
  const payloadPacket = await v3.stringifyIO(payload);
1092
- return await tracer.startActiveSpan("tasks.triggerAndWait()", async (span) => {
933
+ return await tracer.startActiveSpan(name2, async (span) => {
1093
934
  const response = await apiClient.triggerTask(id, {
1094
935
  payload: payloadPacket.data,
1095
936
  options: {
@@ -1102,6 +943,7 @@ async function triggerAndWait(id, payload, options, requestOptions) {
1102
943
  idempotencyKey: await makeKey(options?.idempotencyKey),
1103
944
  delay: options?.delay,
1104
945
  ttl: options?.ttl,
946
+ tags: options?.tags,
1105
947
  maxAttempts: options?.maxAttempts
1106
948
  }
1107
949
  }, {}, requestOptions);
@@ -1141,43 +983,92 @@ async function triggerAndWait(id, payload, options, requestOptions) {
1141
983
  }
1142
984
  });
1143
985
  }
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) {
986
+ __name(triggerAndWait_internal, "triggerAndWait_internal");
987
+ async function batchTriggerAndWait_internal(name2, id, items, requestOptions, queue2) {
988
+ const ctx = v3.taskContext.ctx;
989
+ if (!ctx) {
990
+ throw new Error("batchTriggerAndWait can only be used from inside a task.run()");
991
+ }
1151
992
  const apiClient = v3.apiClientManager.client;
1152
993
  if (!apiClient) {
1153
994
  throw apiClientMissingError();
1154
995
  }
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
996
+ return await tracer.startActiveSpan(name2, async (span) => {
997
+ const response = await apiClient.batchTriggerTask(id, {
998
+ items: await Promise.all(items.map(async (item) => {
999
+ const payloadPacket = await v3.stringifyIO(item.payload);
1000
+ return {
1001
+ payload: payloadPacket.data,
1002
+ options: {
1003
+ lockToVersion: v3.taskContext.worker?.version,
1004
+ queue: item.options?.queue ?? queue2,
1005
+ concurrencyKey: item.options?.concurrencyKey,
1006
+ test: v3.taskContext.ctx?.run.isTest,
1007
+ payloadType: payloadPacket.dataType,
1008
+ idempotencyKey: await makeKey(item.options?.idempotencyKey),
1009
+ delay: item.options?.delay,
1010
+ ttl: item.options?.ttl,
1011
+ tags: item.options?.tags,
1012
+ maxAttempts: item.options?.maxAttempts
1013
+ }
1014
+ };
1015
+ })),
1016
+ dependentAttempt: ctx.attempt.id
1017
+ }, {}, requestOptions);
1018
+ span.setAttribute("messaging.message.id", response.batchId);
1019
+ const getBatchResults = /* @__PURE__ */ __name(async () => {
1020
+ const hasIdempotencyKey = items.some((item) => item.options?.idempotencyKey);
1021
+ if (hasIdempotencyKey) {
1022
+ const results = await apiClient.getBatchResults(response.batchId);
1023
+ if (results) {
1024
+ return results;
1169
1025
  }
1026
+ }
1027
+ return {
1028
+ id: response.batchId,
1029
+ items: []
1170
1030
  };
1171
- }))
1172
- }, {
1173
- spanParentAsLink: true
1031
+ }, "getBatchResults");
1032
+ const existingResults = await getBatchResults();
1033
+ const incompleteRuns = response.runs.filter((runId) => !existingResults.items.some((item) => item.id === runId));
1034
+ if (incompleteRuns.length === 0) {
1035
+ v3.logger.log(`Results reused from previous task runs because of the provided idempotency keys.`);
1036
+ const runs3 = await handleBatchTaskRunExecutionResult(existingResults.items);
1037
+ return {
1038
+ id: existingResults.id,
1039
+ runs: runs3
1040
+ };
1041
+ }
1042
+ const result = await v3.runtime.waitForBatch({
1043
+ id: response.batchId,
1044
+ runs: incompleteRuns,
1045
+ ctx
1046
+ });
1047
+ const combinedItems = [];
1048
+ for (const runId of response.runs) {
1049
+ const existingItem = existingResults.items.find((item) => item.id === runId);
1050
+ if (existingItem) {
1051
+ combinedItems.push(existingItem);
1052
+ } else {
1053
+ const newItem = result.items.find((item) => item.id === runId);
1054
+ if (newItem) {
1055
+ combinedItems.push(newItem);
1056
+ }
1057
+ }
1058
+ }
1059
+ const runs2 = await handleBatchTaskRunExecutionResult(combinedItems);
1060
+ return {
1061
+ id: result.id,
1062
+ runs: runs2
1063
+ };
1174
1064
  }, {
1175
- name: `tasks.batchTrigger()`,
1176
- tracer,
1177
- icon: "trigger",
1065
+ kind: api.SpanKind.PRODUCER,
1178
1066
  attributes: {
1067
+ [v3.SemanticInternalAttributes.STYLE_ICON]: "trigger",
1068
+ ["messaging.batch.message_count"]: items.length,
1179
1069
  [semanticConventions.SEMATTRS_MESSAGING_OPERATION]: "publish",
1180
1070
  ["messaging.client_id"]: v3.taskContext.worker?.id,
1071
+ [semanticConventions.SEMATTRS_MESSAGING_DESTINATION]: id,
1181
1072
  [semanticConventions.SEMATTRS_MESSAGING_SYSTEM]: "trigger.dev",
1182
1073
  ...v3.accessoryAttributes({
1183
1074
  items: [
@@ -1188,18 +1079,10 @@ async function batchTrigger(id, items, requestOptions) {
1188
1079
  ],
1189
1080
  style: "codepath"
1190
1081
  })
1191
- },
1192
- ...requestOptions
1082
+ }
1193
1083
  });
1194
- const handle = {
1195
- batchId: response.batchId,
1196
- runs: response.runs.map((id2) => ({
1197
- id: id2
1198
- }))
1199
- };
1200
- return handle;
1201
1084
  }
1202
- __name(batchTrigger, "batchTrigger");
1085
+ __name(batchTriggerAndWait_internal, "batchTriggerAndWait_internal");
1203
1086
  async function handleBatchTaskRunExecutionResult(items) {
1204
1087
  const someObjectStoreOutputs = items.some((item) => item.ok && item.outputType === "application/store");
1205
1088
  if (!someObjectStoreOutputs) {
@@ -1275,7 +1158,8 @@ var tasks = {
1275
1158
  trigger,
1276
1159
  triggerAndPoll,
1277
1160
  batchTrigger,
1278
- triggerAndWait
1161
+ triggerAndWait,
1162
+ batchTriggerAndWait
1279
1163
  };
1280
1164
  var wait = {
1281
1165
  for: async (options) => {
@@ -1481,6 +1365,53 @@ var usage = {
1481
1365
  };
1482
1366
  }
1483
1367
  };
1368
+ var tags = {
1369
+ add: addTags
1370
+ };
1371
+ async function addTags(tags2, requestOptions) {
1372
+ const apiClient = v3.apiClientManager.client;
1373
+ if (!apiClient) {
1374
+ throw apiClientMissingError();
1375
+ }
1376
+ const run = v3.taskContext.ctx?.run;
1377
+ if (!run) {
1378
+ throw new Error("Can't set tags outside of a run. You can trigger a task and set tags in the options.");
1379
+ }
1380
+ const $requestOptions = v3.mergeRequestOptions({
1381
+ tracer,
1382
+ name: "tags.set()",
1383
+ icon: "tag",
1384
+ attributes: {
1385
+ ...v3.accessoryAttributes({
1386
+ items: [
1387
+ {
1388
+ text: typeof tags2 === "string" ? tags2 : tags2.join(", "),
1389
+ variant: "normal"
1390
+ }
1391
+ ],
1392
+ style: "codepath"
1393
+ })
1394
+ }
1395
+ }, requestOptions);
1396
+ try {
1397
+ await apiClient.addTags(run.id, {
1398
+ tags: tags2
1399
+ }, $requestOptions);
1400
+ } catch (error) {
1401
+ if (error instanceof v3.UnprocessableEntityError) {
1402
+ v3.logger.error(error.message, {
1403
+ existingTags: run.tags,
1404
+ newTags: tags2
1405
+ });
1406
+ return;
1407
+ }
1408
+ v3.logger.error("Failed to set tags", {
1409
+ error
1410
+ });
1411
+ throw error;
1412
+ }
1413
+ }
1414
+ __name(addTags, "addTags");
1484
1415
 
1485
1416
  // src/v3/schedules/index.ts
1486
1417
  var schedules_exports = {};
@@ -1969,6 +1900,7 @@ exports.queue = queue;
1969
1900
  exports.retry = retry;
1970
1901
  exports.runs = runs;
1971
1902
  exports.schedules = schedules_exports;
1903
+ exports.tags = tags;
1972
1904
  exports.task = task;
1973
1905
  exports.tasks = tasks;
1974
1906
  exports.usage = usage;