@trigger.dev/react-hooks 0.0.0-langsmith-ai-20250111212321

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1 -0
  3. package/dist/commonjs/contexts.d.ts +4 -0
  4. package/dist/commonjs/contexts.js +10 -0
  5. package/dist/commonjs/contexts.js.map +1 -0
  6. package/dist/commonjs/hooks/useApiClient.d.ts +39 -0
  7. package/dist/commonjs/hooks/useApiClient.js +43 -0
  8. package/dist/commonjs/hooks/useApiClient.js.map +1 -0
  9. package/dist/commonjs/hooks/useRealtime.d.ts +117 -0
  10. package/dist/commonjs/hooks/useRealtime.js +423 -0
  11. package/dist/commonjs/hooks/useRealtime.js.map +1 -0
  12. package/dist/commonjs/hooks/useRun.d.ts +22 -0
  13. package/dist/commonjs/hooks/useRun.js +40 -0
  14. package/dist/commonjs/hooks/useRun.js.map +1 -0
  15. package/dist/commonjs/hooks/useTaskTrigger.d.ts +101 -0
  16. package/dist/commonjs/hooks/useTaskTrigger.js +137 -0
  17. package/dist/commonjs/hooks/useTaskTrigger.js.map +1 -0
  18. package/dist/commonjs/index.d.ts +5 -0
  19. package/dist/commonjs/index.js +22 -0
  20. package/dist/commonjs/index.js.map +1 -0
  21. package/dist/commonjs/package.json +3 -0
  22. package/dist/commonjs/utils/createContextAndHook.d.ts +15 -0
  23. package/dist/commonjs/utils/createContextAndHook.js +39 -0
  24. package/dist/commonjs/utils/createContextAndHook.js.map +1 -0
  25. package/dist/commonjs/utils/throttle.d.ts +6 -0
  26. package/dist/commonjs/utils/throttle.js +50 -0
  27. package/dist/commonjs/utils/throttle.js.map +1 -0
  28. package/dist/commonjs/utils/trigger-swr.d.ts +19 -0
  29. package/dist/commonjs/utils/trigger-swr.js +28 -0
  30. package/dist/commonjs/utils/trigger-swr.js.map +1 -0
  31. package/dist/esm/contexts.d.ts +4 -0
  32. package/dist/esm/contexts.js +5 -0
  33. package/dist/esm/contexts.js.map +1 -0
  34. package/dist/esm/hooks/useApiClient.d.ts +39 -0
  35. package/dist/esm/hooks/useApiClient.js +40 -0
  36. package/dist/esm/hooks/useApiClient.js.map +1 -0
  37. package/dist/esm/hooks/useRealtime.d.ts +117 -0
  38. package/dist/esm/hooks/useRealtime.js +417 -0
  39. package/dist/esm/hooks/useRealtime.js.map +1 -0
  40. package/dist/esm/hooks/useRun.d.ts +22 -0
  41. package/dist/esm/hooks/useRun.js +37 -0
  42. package/dist/esm/hooks/useRun.js.map +1 -0
  43. package/dist/esm/hooks/useTaskTrigger.d.ts +101 -0
  44. package/dist/esm/hooks/useTaskTrigger.js +129 -0
  45. package/dist/esm/hooks/useTaskTrigger.js.map +1 -0
  46. package/dist/esm/index.d.ts +5 -0
  47. package/dist/esm/index.js +6 -0
  48. package/dist/esm/index.js.map +1 -0
  49. package/dist/esm/package.json +3 -0
  50. package/dist/esm/utils/createContextAndHook.d.ts +15 -0
  51. package/dist/esm/utils/createContextAndHook.js +31 -0
  52. package/dist/esm/utils/createContextAndHook.js.map +1 -0
  53. package/dist/esm/utils/throttle.d.ts +6 -0
  54. package/dist/esm/utils/throttle.js +47 -0
  55. package/dist/esm/utils/throttle.js.map +1 -0
  56. package/dist/esm/utils/trigger-swr.d.ts +19 -0
  57. package/dist/esm/utils/trigger-swr.js +6 -0
  58. package/dist/esm/utils/trigger-swr.js.map +1 -0
  59. package/package.json +77 -0
@@ -0,0 +1,417 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useId, useRef, useState } from "react";
3
+ import { useSWR } from "../utils/trigger-swr.js";
4
+ import { useApiClient } from "./useApiClient.js";
5
+ import { createThrottledQueue } from "../utils/throttle.js";
6
+ /**
7
+ * Hook to subscribe to realtime updates of a task run.
8
+ *
9
+ * @template TTask - The type of the task
10
+ * @param {string} [runId] - The unique identifier of the run to subscribe to
11
+ * @param {UseRealtimeSingleRunOptions} [options] - Configuration options for the subscription
12
+ * @returns {UseRealtimeRunInstance<TTask>} An object containing the current state of the run, error handling, and control methods
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import type { myTask } from './path/to/task';
17
+ * const { run, error } = useRealtimeRun<typeof myTask>('run-id-123');
18
+ * ```
19
+ */
20
+ export function useRealtimeRun(runId, options) {
21
+ const hookId = useId();
22
+ const idKey = options?.id ?? hookId;
23
+ // Store the streams state in SWR, using the idKey as the key to share states.
24
+ const { data: run, mutate: mutateRun } = useSWR([idKey, "run"], null);
25
+ const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
26
+ // Add state to track when the subscription is complete
27
+ const { data: isComplete = false, mutate: setIsComplete } = useSWR([idKey, "complete"], null);
28
+ // Abort controller to cancel the current API call.
29
+ const abortControllerRef = useRef(null);
30
+ const stop = useCallback(() => {
31
+ if (abortControllerRef.current) {
32
+ abortControllerRef.current.abort();
33
+ abortControllerRef.current = null;
34
+ }
35
+ }, []);
36
+ const apiClient = useApiClient(options);
37
+ const triggerRequest = useCallback(async () => {
38
+ try {
39
+ if (!runId || !apiClient) {
40
+ return;
41
+ }
42
+ const abortController = new AbortController();
43
+ abortControllerRef.current = abortController;
44
+ await processRealtimeRun(runId, apiClient, mutateRun, setError, abortControllerRef, typeof options?.stopOnCompletion === "boolean" ? options.stopOnCompletion : true);
45
+ }
46
+ catch (err) {
47
+ // Ignore abort errors as they are expected.
48
+ if (err.name === "AbortError") {
49
+ abortControllerRef.current = null;
50
+ return;
51
+ }
52
+ setError(err);
53
+ }
54
+ finally {
55
+ if (abortControllerRef.current) {
56
+ abortControllerRef.current = null;
57
+ }
58
+ // Mark the subscription as complete
59
+ setIsComplete(true);
60
+ }
61
+ }, [runId, mutateRun, abortControllerRef, apiClient, setError]);
62
+ const hasCalledOnCompleteRef = useRef(false);
63
+ // Effect to handle onComplete callback
64
+ useEffect(() => {
65
+ if (isComplete && run && options?.onComplete && !hasCalledOnCompleteRef.current) {
66
+ options.onComplete(run, error);
67
+ hasCalledOnCompleteRef.current = true;
68
+ }
69
+ }, [isComplete, run, error, options?.onComplete]);
70
+ useEffect(() => {
71
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
72
+ return;
73
+ }
74
+ if (!runId) {
75
+ return;
76
+ }
77
+ triggerRequest().finally(() => { });
78
+ return () => {
79
+ stop();
80
+ };
81
+ }, [runId, stop, options?.enabled]);
82
+ useEffect(() => {
83
+ if (run?.finishedAt) {
84
+ setIsComplete(true);
85
+ }
86
+ }, [run]);
87
+ return { run, error, stop };
88
+ }
89
+ /**
90
+ * Hook to subscribe to realtime updates of a task run with associated data streams.
91
+ *
92
+ * @template TTask - The type of the task
93
+ * @template TStreams - The type of the streams data
94
+ * @param {string} [runId] - The unique identifier of the run to subscribe to
95
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
96
+ * @returns {UseRealtimeRunWithStreamsInstance<TTask, TStreams>} An object containing the current state of the run, streams data, and error handling
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import type { myTask } from './path/to/task';
101
+ * const { run, streams, error } = useRealtimeRunWithStreams<typeof myTask, {
102
+ * output: string;
103
+ * }>('run-id-123');
104
+ * ```
105
+ */
106
+ export function useRealtimeRunWithStreams(runId, options) {
107
+ const hookId = useId();
108
+ const idKey = options?.id ?? hookId;
109
+ const [initialStreamsFallback] = useState({});
110
+ // Store the streams state in SWR, using the idKey as the key to share states.
111
+ const { data: streams, mutate: mutateStreams } = useSWR([idKey, "streams"], null, {
112
+ fallbackData: initialStreamsFallback,
113
+ });
114
+ // Keep the latest streams in a ref.
115
+ const streamsRef = useRef(streams ?? {});
116
+ useEffect(() => {
117
+ streamsRef.current = streams || {};
118
+ }, [streams]);
119
+ // Store the streams state in SWR, using the idKey as the key to share states.
120
+ const { data: run, mutate: mutateRun } = useSWR([idKey, "run"], null);
121
+ // Add state to track when the subscription is complete
122
+ const { data: isComplete = false, mutate: setIsComplete } = useSWR([idKey, "complete"], null);
123
+ const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
124
+ // Abort controller to cancel the current API call.
125
+ const abortControllerRef = useRef(null);
126
+ const stop = useCallback(() => {
127
+ if (abortControllerRef.current) {
128
+ abortControllerRef.current.abort();
129
+ abortControllerRef.current = null;
130
+ }
131
+ }, []);
132
+ const apiClient = useApiClient(options);
133
+ const triggerRequest = useCallback(async () => {
134
+ try {
135
+ if (!runId || !apiClient) {
136
+ return;
137
+ }
138
+ const abortController = new AbortController();
139
+ abortControllerRef.current = abortController;
140
+ await processRealtimeRunWithStreams(runId, apiClient, mutateRun, mutateStreams, streamsRef, setError, abortControllerRef, typeof options?.stopOnCompletion === "boolean" ? options.stopOnCompletion : true, options?.experimental_throttleInMs);
141
+ }
142
+ catch (err) {
143
+ // Ignore abort errors as they are expected.
144
+ if (err.name === "AbortError") {
145
+ abortControllerRef.current = null;
146
+ return;
147
+ }
148
+ setError(err);
149
+ }
150
+ finally {
151
+ if (abortControllerRef.current) {
152
+ abortControllerRef.current = null;
153
+ }
154
+ // Mark the subscription as complete
155
+ setIsComplete(true);
156
+ }
157
+ }, [runId, mutateRun, mutateStreams, streamsRef, abortControllerRef, apiClient, setError]);
158
+ const hasCalledOnCompleteRef = useRef(false);
159
+ // Effect to handle onComplete callback
160
+ useEffect(() => {
161
+ if (isComplete && run && options?.onComplete && !hasCalledOnCompleteRef.current) {
162
+ options.onComplete(run, error);
163
+ hasCalledOnCompleteRef.current = true;
164
+ }
165
+ }, [isComplete, run, error, options?.onComplete]);
166
+ useEffect(() => {
167
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
168
+ return;
169
+ }
170
+ if (!runId) {
171
+ return;
172
+ }
173
+ triggerRequest().finally(() => { });
174
+ return () => {
175
+ stop();
176
+ };
177
+ }, [runId, stop, options?.enabled]);
178
+ useEffect(() => {
179
+ if (run?.finishedAt) {
180
+ setIsComplete(true);
181
+ }
182
+ }, [run]);
183
+ return { run, streams: streams ?? initialStreamsFallback, error, stop };
184
+ }
185
+ /**
186
+ * Hook to subscribe to realtime updates of task runs filtered by tag(s).
187
+ *
188
+ * @template TTask - The type of the task
189
+ * @param {string | string[]} tag - The tag or array of tags to filter runs by
190
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
191
+ * @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs and any error encountered
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * import type { myTask } from './path/to/task';
196
+ * const { runs, error } = useRealtimeRunsWithTag<typeof myTask>('my-tag');
197
+ * // Or with multiple tags
198
+ * const { runs, error } = useRealtimeRunsWithTag<typeof myTask>(['tag1', 'tag2']);
199
+ * ```
200
+ */
201
+ export function useRealtimeRunsWithTag(tag, options) {
202
+ const hookId = useId();
203
+ const idKey = options?.id ?? hookId;
204
+ // Store the streams state in SWR, using the idKey as the key to share states.
205
+ const { data: runs, mutate: mutateRuns } = useSWR([idKey, "run"], null, {
206
+ fallbackData: [],
207
+ });
208
+ // Keep the latest streams in a ref.
209
+ const runsRef = useRef([]);
210
+ useEffect(() => {
211
+ runsRef.current = runs ?? [];
212
+ }, [runs]);
213
+ const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
214
+ // Abort controller to cancel the current API call.
215
+ const abortControllerRef = useRef(null);
216
+ const stop = useCallback(() => {
217
+ if (abortControllerRef.current) {
218
+ abortControllerRef.current.abort();
219
+ abortControllerRef.current = null;
220
+ }
221
+ }, []);
222
+ const apiClient = useApiClient(options);
223
+ const triggerRequest = useCallback(async () => {
224
+ try {
225
+ if (!apiClient) {
226
+ return;
227
+ }
228
+ const abortController = new AbortController();
229
+ abortControllerRef.current = abortController;
230
+ await processRealtimeRunsWithTag(tag, apiClient, mutateRuns, runsRef, setError, abortControllerRef);
231
+ }
232
+ catch (err) {
233
+ // Ignore abort errors as they are expected.
234
+ if (err.name === "AbortError") {
235
+ abortControllerRef.current = null;
236
+ return;
237
+ }
238
+ setError(err);
239
+ }
240
+ finally {
241
+ if (abortControllerRef.current) {
242
+ abortControllerRef.current = null;
243
+ }
244
+ }
245
+ }, [tag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
246
+ useEffect(() => {
247
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
248
+ return;
249
+ }
250
+ triggerRequest().finally(() => { });
251
+ return () => {
252
+ stop();
253
+ };
254
+ }, [tag, stop, options?.enabled]);
255
+ return { runs: runs ?? [], error, stop };
256
+ }
257
+ /**
258
+ * Hook to subscribe to realtime updates of a batch of task runs.
259
+ *
260
+ * @template TTask - The type of the task
261
+ * @param {string} batchId - The unique identifier of the batch to subscribe to
262
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
263
+ * @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs, error handling, and control methods
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * import type { myTask } from './path/to/task';
268
+ * const { runs, error } = useRealtimeBatch<typeof myTask>('batch-id-123');
269
+ * ```
270
+ */
271
+ export function useRealtimeBatch(batchId, options) {
272
+ const hookId = useId();
273
+ const idKey = options?.id ?? hookId;
274
+ // Store the streams state in SWR, using the idKey as the key to share states.
275
+ const { data: runs, mutate: mutateRuns } = useSWR([idKey, "run"], null, {
276
+ fallbackData: [],
277
+ });
278
+ // Keep the latest streams in a ref.
279
+ const runsRef = useRef([]);
280
+ useEffect(() => {
281
+ runsRef.current = runs ?? [];
282
+ }, [runs]);
283
+ const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
284
+ // Abort controller to cancel the current API call.
285
+ const abortControllerRef = useRef(null);
286
+ const stop = useCallback(() => {
287
+ if (abortControllerRef.current) {
288
+ abortControllerRef.current.abort();
289
+ abortControllerRef.current = null;
290
+ }
291
+ }, []);
292
+ const apiClient = useApiClient(options);
293
+ const triggerRequest = useCallback(async () => {
294
+ try {
295
+ if (!apiClient) {
296
+ return;
297
+ }
298
+ const abortController = new AbortController();
299
+ abortControllerRef.current = abortController;
300
+ await processRealtimeBatch(batchId, apiClient, mutateRuns, runsRef, setError, abortControllerRef);
301
+ }
302
+ catch (err) {
303
+ // Ignore abort errors as they are expected.
304
+ if (err.name === "AbortError") {
305
+ abortControllerRef.current = null;
306
+ return;
307
+ }
308
+ setError(err);
309
+ }
310
+ finally {
311
+ if (abortControllerRef.current) {
312
+ abortControllerRef.current = null;
313
+ }
314
+ }
315
+ }, [batchId, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
316
+ useEffect(() => {
317
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
318
+ return;
319
+ }
320
+ triggerRequest().finally(() => { });
321
+ return () => {
322
+ stop();
323
+ };
324
+ }, [batchId, stop, options?.enabled]);
325
+ return { runs: runs ?? [], error, stop };
326
+ }
327
+ async function processRealtimeBatch(batchId, apiClient, mutateRunsData, existingRunsRef, onError, abortControllerRef) {
328
+ const subscription = apiClient.subscribeToBatch(batchId, {
329
+ signal: abortControllerRef.current?.signal,
330
+ onFetchError: onError,
331
+ });
332
+ for await (const part of subscription) {
333
+ mutateRunsData(insertRunShapeInOrder(existingRunsRef.current, part));
334
+ }
335
+ }
336
+ // Inserts and then orders by the run number, and ensures that the run is not duplicated
337
+ function insertRunShapeInOrder(previousRuns, run) {
338
+ const existingRun = previousRuns.find((r) => r.id === run.id);
339
+ if (existingRun) {
340
+ return previousRuns.map((r) => (r.id === run.id ? run : r));
341
+ }
342
+ const runNumber = run.number;
343
+ const index = previousRuns.findIndex((r) => r.number > runNumber);
344
+ if (index === -1) {
345
+ return [...previousRuns, run];
346
+ }
347
+ return [...previousRuns.slice(0, index), run, ...previousRuns.slice(index)];
348
+ }
349
+ async function processRealtimeRunsWithTag(tag, apiClient, mutateRunsData, existingRunsRef, onError, abortControllerRef) {
350
+ const subscription = apiClient.subscribeToRunsWithTag(tag, {
351
+ signal: abortControllerRef.current?.signal,
352
+ onFetchError: onError,
353
+ });
354
+ for await (const part of subscription) {
355
+ mutateRunsData(insertRunShape(existingRunsRef.current, part));
356
+ }
357
+ }
358
+ // Replaces or inserts a run shape, ordered by the createdAt timestamp
359
+ function insertRunShape(previousRuns, run) {
360
+ const existingRun = previousRuns.find((r) => r.id === run.id);
361
+ if (existingRun) {
362
+ return previousRuns.map((r) => (r.id === run.id ? run : r));
363
+ }
364
+ const createdAt = run.createdAt;
365
+ const index = previousRuns.findIndex((r) => r.createdAt > createdAt);
366
+ if (index === -1) {
367
+ return [...previousRuns, run];
368
+ }
369
+ return [...previousRuns.slice(0, index), run, ...previousRuns.slice(index)];
370
+ }
371
+ async function processRealtimeRunWithStreams(runId, apiClient, mutateRunData, mutateStreamData, existingDataRef, onError, abortControllerRef, stopOnCompletion = true, throttleInMs) {
372
+ const subscription = apiClient.subscribeToRun(runId, {
373
+ signal: abortControllerRef.current?.signal,
374
+ closeOnComplete: stopOnCompletion,
375
+ onFetchError: onError,
376
+ });
377
+ const streamQueue = createThrottledQueue(async (updates) => {
378
+ const nextStreamData = { ...existingDataRef.current };
379
+ // Group updates by type
380
+ const updatesByType = updates.reduce((acc, update) => {
381
+ if (!acc[update.type]) {
382
+ acc[update.type] = [];
383
+ }
384
+ acc[update.type].push(update.chunk);
385
+ return acc;
386
+ }, {});
387
+ // Apply all updates
388
+ for (const [type, chunks] of Object.entries(updatesByType)) {
389
+ // @ts-ignore
390
+ nextStreamData[type] = [...(existingDataRef.current[type] || []), ...chunks];
391
+ }
392
+ mutateStreamData(nextStreamData);
393
+ }, throttleInMs);
394
+ for await (const part of subscription.withStreams()) {
395
+ if (part.type === "run") {
396
+ mutateRunData(part.run);
397
+ }
398
+ else {
399
+ streamQueue.add({
400
+ type: part.type,
401
+ // @ts-ignore
402
+ chunk: part.chunk,
403
+ });
404
+ }
405
+ }
406
+ }
407
+ async function processRealtimeRun(runId, apiClient, mutateRunData, onError, abortControllerRef, stopOnCompletion = true) {
408
+ const subscription = apiClient.subscribeToRun(runId, {
409
+ signal: abortControllerRef.current?.signal,
410
+ closeOnComplete: stopOnCompletion,
411
+ onFetchError: onError,
412
+ });
413
+ for await (const part of subscription) {
414
+ mutateRunData(part);
415
+ }
416
+ }
417
+ //# sourceMappingURL=useRealtime.js.map
@@ -0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M,YAAY,GAAG,SAAS,CAAC,cAAc,CAAuB,KAAK,EAAE;QACzE,MAAM,EAAE,kBAAkB,CAAC,OAAO,EAAE,MAAM;QAC1C,eAAe,EAAE,gBAAgB;QACjC,YAAY,EAAE,OAAO;KACtB,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QACtC,aAAa,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { AnyTask, RetrieveRunResult } from "@trigger.dev/core/v3";
2
+ import { CommonTriggerHookOptions } from "../utils/trigger-swr.js";
3
+ /**
4
+ * Custom hook to retrieve and manage the state of a run by its ID.
5
+ *
6
+ * @template TTask - The type of the task associated with the run.
7
+ * @param {string} runId - The unique identifier of the run to retrieve.
8
+ * @param {CommonTriggerHookOptions} [options] - Optional configuration for the hook's behavior.
9
+ * @returns {Object} An object containing the run data, error, loading state, validation state, and error state.
10
+ * @returns {RetrieveRunResult<TTask> | undefined} run - The retrieved run data.
11
+ * @returns {Error | undefined} error - The error object if an error occurred.
12
+ * @returns {boolean} isLoading - Indicates if the run data is currently being loaded.
13
+ * @returns {boolean} isValidating - Indicates if the run data is currently being validated.
14
+ * @returns {boolean} isError - Indicates if an error occurred during the retrieval of the run data.
15
+ */
16
+ export declare function useRun<TTask extends AnyTask>(runId: string, options?: CommonTriggerHookOptions): {
17
+ run: RetrieveRunResult<TTask> | undefined;
18
+ error: Error | undefined;
19
+ isLoading: boolean;
20
+ isValidating: boolean;
21
+ isError: boolean;
22
+ };
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { useSWR } from "../utils/trigger-swr.js";
3
+ import { useApiClient } from "./useApiClient.js";
4
+ /**
5
+ * Custom hook to retrieve and manage the state of a run by its ID.
6
+ *
7
+ * @template TTask - The type of the task associated with the run.
8
+ * @param {string} runId - The unique identifier of the run to retrieve.
9
+ * @param {CommonTriggerHookOptions} [options] - Optional configuration for the hook's behavior.
10
+ * @returns {Object} An object containing the run data, error, loading state, validation state, and error state.
11
+ * @returns {RetrieveRunResult<TTask> | undefined} run - The retrieved run data.
12
+ * @returns {Error | undefined} error - The error object if an error occurred.
13
+ * @returns {boolean} isLoading - Indicates if the run data is currently being loaded.
14
+ * @returns {boolean} isValidating - Indicates if the run data is currently being validated.
15
+ * @returns {boolean} isError - Indicates if an error occurred during the retrieval of the run data.
16
+ */
17
+ export function useRun(runId, options) {
18
+ const apiClient = useApiClient(options);
19
+ const { data: run, error, isLoading, isValidating, } = useSWR(runId, () => {
20
+ if (!apiClient) {
21
+ throw new Error("Could not call useRun: Missing access token");
22
+ }
23
+ return apiClient.retrieveRun(runId);
24
+ }, {
25
+ revalidateOnReconnect: options?.revalidateOnReconnect,
26
+ refreshInterval: (run) => {
27
+ if (!run)
28
+ return options?.refreshInterval ?? 0;
29
+ if (run.isCompleted)
30
+ return 0;
31
+ return options?.refreshInterval ?? 0;
32
+ },
33
+ revalidateOnFocus: options?.revalidateOnFocus,
34
+ });
35
+ return { run, error, isLoading, isValidating, isError: !!error };
36
+ }
37
+ //# sourceMappingURL=useRun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRun.js","sourceRoot":"","sources":["../../../src/hooks/useRun.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAA4B,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CACpB,KAAa,EACb,OAAkC;IAQlC,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,EACJ,IAAI,EAAE,GAAG,EACT,KAAK,EACL,SAAS,EACT,YAAY,GACb,GAAG,MAAM,CACR,KAAK,EACL,GAAG,EAAE;QACH,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,OAAO,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,EACD;QACE,qBAAqB,EAAE,OAAO,EAAE,qBAAqB;QACrD,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE;YACvB,IAAI,CAAC,GAAG;gBAAE,OAAO,OAAO,EAAE,eAAe,IAAI,CAAC,CAAC;YAE/C,IAAI,GAAG,CAAC,WAAW;gBAAE,OAAO,CAAC,CAAC;YAE9B,OAAO,OAAO,EAAE,eAAe,IAAI,CAAC,CAAC;QACvC,CAAC;QACD,iBAAiB,EAAE,OAAO,EAAE,iBAAiB;KAC9C,CACF,CAAC;IAEF,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;AACnE,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { type AnyTask, type TaskIdentifier, type TaskPayload, InferRunTypes, RunHandleFromTypes, type TriggerOptions } from "@trigger.dev/core/v3";
2
+ import { UseApiClientOptions } from "./useApiClient.js";
3
+ import { UseRealtimeRunInstance, UseRealtimeRunWithStreamsInstance } from "./useRealtime.js";
4
+ /**
5
+ * Base interface for task trigger instances.
6
+ *
7
+ * @template TTask - The type of the task
8
+ */
9
+ export interface TriggerInstance<TTask extends AnyTask> {
10
+ /** Function to submit the task with a payload */
11
+ submit: (payload: TaskPayload<TTask>, options?: TriggerOptions) => void;
12
+ /** Whether the task is currently being submitted */
13
+ isLoading: boolean;
14
+ /** The handle returned after successful task submission */
15
+ handle?: RunHandleFromTypes<InferRunTypes<TTask>>;
16
+ /** Any error that occurred during submission */
17
+ error?: Error;
18
+ }
19
+ export type UseTaskTriggerOptions = UseApiClientOptions;
20
+ /**
21
+ * Hook to trigger a task and manage its initial execution state.
22
+ *
23
+ * @template TTask - The type of the task
24
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
25
+ * @param {UseTaskTriggerOptions} [options] - Configuration options for the task trigger
26
+ * @returns {TriggerInstance<TTask>} An object containing the submit function, loading state, handle, and any errors
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import type { myTask } from './path/to/task';
31
+ * const { submit, isLoading, handle, error } = useTaskTrigger<typeof myTask>('my-task-id');
32
+ *
33
+ * // Submit the task with payload
34
+ * submit({ foo: 'bar' });
35
+ * ```
36
+ */
37
+ export declare function useTaskTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, options?: UseTaskTriggerOptions): TriggerInstance<TTask>;
38
+ /**
39
+ * Configuration options for task triggers with realtime updates.
40
+ */
41
+ export type UseRealtimeTaskTriggerOptions = UseTaskTriggerOptions & {
42
+ /** Whether the realtime subscription is enabled */
43
+ enabled?: boolean;
44
+ /** Optional throttle time in milliseconds for stream updates */
45
+ experimental_throttleInMs?: number;
46
+ };
47
+ export type RealtimeTriggerInstanceWithStreams<TTask extends AnyTask, TStreams extends Record<string, any> = Record<string, any>> = UseRealtimeRunWithStreamsInstance<TTask, TStreams> & {
48
+ submit: (payload: TaskPayload<TTask>, options?: TriggerOptions) => void;
49
+ isLoading: boolean;
50
+ handle?: RunHandleFromTypes<InferRunTypes<TTask>>;
51
+ };
52
+ /**
53
+ * Hook to trigger a task and subscribe to its realtime updates including stream data.
54
+ *
55
+ * @template TTask - The type of the task
56
+ * @template TStreams - The type of the streams data
57
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
58
+ * @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
59
+ * @returns {RealtimeTriggerInstanceWithStreams<TTask, TStreams>} An object containing the submit function, loading state,
60
+ * handle, run state, streams data, and error handling
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import type { myTask } from './path/to/task';
65
+ * const { submit, run, streams, error } = useRealtimeTaskTriggerWithStreams<
66
+ * typeof myTask,
67
+ * { output: string }
68
+ * >('my-task-id');
69
+ *
70
+ * // Submit and monitor the task with streams
71
+ * submit({ foo: 'bar' });
72
+ * ```
73
+ */
74
+ export declare function useRealtimeTaskTriggerWithStreams<TTask extends AnyTask, TStreams extends Record<string, any> = Record<string, any>>(id: TaskIdentifier<TTask>, options?: UseRealtimeTaskTriggerOptions): RealtimeTriggerInstanceWithStreams<TTask, TStreams>;
75
+ export type RealtimeTriggerInstance<TTask extends AnyTask> = UseRealtimeRunInstance<TTask> & {
76
+ submit: (payload: TaskPayload<TTask>, options?: TriggerOptions) => void;
77
+ isLoading: boolean;
78
+ handle?: RunHandleFromTypes<InferRunTypes<TTask>>;
79
+ };
80
+ /**
81
+ * Hook to trigger a task and subscribe to its realtime updates.
82
+ *
83
+ * @template TTask - The type of the task
84
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
85
+ * @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
86
+ * @returns {RealtimeTriggerInstance<TTask>} An object containing the submit function, loading state,
87
+ * handle, run state, and error handling
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import type { myTask } from './path/to/task';
92
+ * const { submit, run, error, stop } = useRealtimeTaskTrigger<typeof myTask>('my-task-id');
93
+ *
94
+ * // Submit and monitor the task
95
+ * submit({ foo: 'bar' });
96
+ *
97
+ * // Stop monitoring when needed
98
+ * stop();
99
+ * ```
100
+ */
101
+ export declare function useRealtimeTaskTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, options?: UseRealtimeTaskTriggerOptions): RealtimeTriggerInstance<TTask>;