@trigger.dev/react-hooks 0.0.0-chat-prerelease-20260401205942
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/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/commonjs/contexts.d.ts +4 -0
- package/dist/commonjs/contexts.js +10 -0
- package/dist/commonjs/contexts.js.map +1 -0
- package/dist/commonjs/hooks/useApiClient.d.ts +41 -0
- package/dist/commonjs/hooks/useApiClient.js +44 -0
- package/dist/commonjs/hooks/useApiClient.js.map +1 -0
- package/dist/commonjs/hooks/useInputStreamSend.d.ts +26 -0
- package/dist/commonjs/hooks/useInputStreamSend.js +45 -0
- package/dist/commonjs/hooks/useInputStreamSend.js.map +1 -0
- package/dist/commonjs/hooks/useRealtime.d.ts +294 -0
- package/dist/commonjs/hooks/useRealtime.js +549 -0
- package/dist/commonjs/hooks/useRealtime.js.map +1 -0
- package/dist/commonjs/hooks/useRun.d.ts +22 -0
- package/dist/commonjs/hooks/useRun.js +40 -0
- package/dist/commonjs/hooks/useRun.js.map +1 -0
- package/dist/commonjs/hooks/useTaskTrigger.d.ts +107 -0
- package/dist/commonjs/hooks/useTaskTrigger.js +138 -0
- package/dist/commonjs/hooks/useTaskTrigger.js.map +1 -0
- package/dist/commonjs/hooks/useWaitToken.d.ts +35 -0
- package/dist/commonjs/hooks/useWaitToken.js +52 -0
- package/dist/commonjs/hooks/useWaitToken.js.map +1 -0
- package/dist/commonjs/index.d.ts +7 -0
- package/dist/commonjs/index.js +24 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/utils/createContextAndHook.d.ts +15 -0
- package/dist/commonjs/utils/createContextAndHook.js +39 -0
- package/dist/commonjs/utils/createContextAndHook.js.map +1 -0
- package/dist/commonjs/utils/throttle.d.ts +6 -0
- package/dist/commonjs/utils/throttle.js +50 -0
- package/dist/commonjs/utils/throttle.js.map +1 -0
- package/dist/commonjs/utils/trigger-swr.d.ts +19 -0
- package/dist/commonjs/utils/trigger-swr.js +28 -0
- package/dist/commonjs/utils/trigger-swr.js.map +1 -0
- package/dist/esm/contexts.d.ts +4 -0
- package/dist/esm/contexts.js +5 -0
- package/dist/esm/contexts.js.map +1 -0
- package/dist/esm/hooks/useApiClient.d.ts +41 -0
- package/dist/esm/hooks/useApiClient.js +41 -0
- package/dist/esm/hooks/useApiClient.js.map +1 -0
- package/dist/esm/hooks/useInputStreamSend.d.ts +26 -0
- package/dist/esm/hooks/useInputStreamSend.js +39 -0
- package/dist/esm/hooks/useInputStreamSend.js.map +1 -0
- package/dist/esm/hooks/useRealtime.d.ts +294 -0
- package/dist/esm/hooks/useRealtime.js +542 -0
- package/dist/esm/hooks/useRealtime.js.map +1 -0
- package/dist/esm/hooks/useRun.d.ts +22 -0
- package/dist/esm/hooks/useRun.js +37 -0
- package/dist/esm/hooks/useRun.js.map +1 -0
- package/dist/esm/hooks/useTaskTrigger.d.ts +107 -0
- package/dist/esm/hooks/useTaskTrigger.js +130 -0
- package/dist/esm/hooks/useTaskTrigger.js.map +1 -0
- package/dist/esm/hooks/useWaitToken.d.ts +35 -0
- package/dist/esm/hooks/useWaitToken.js +46 -0
- package/dist/esm/hooks/useWaitToken.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/utils/createContextAndHook.d.ts +15 -0
- package/dist/esm/utils/createContextAndHook.js +31 -0
- package/dist/esm/utils/createContextAndHook.js.map +1 -0
- package/dist/esm/utils/throttle.d.ts +6 -0
- package/dist/esm/utils/throttle.js +47 -0
- package/dist/esm/utils/throttle.js.map +1 -0
- package/dist/esm/utils/trigger-swr.d.ts +19 -0
- package/dist/esm/utils/trigger-swr.js +6 -0
- package/dist/esm/utils/trigger-swr.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,542 @@
|
|
|
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, { skipColumns: options?.skipColumns }, 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
|
+
// Only call onComplete when the run has actually finished (has finishedAt),
|
|
65
|
+
// not just when the subscription stream ends (which can happen due to network issues)
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (isComplete && run?.finishedAt && options?.onComplete && !hasCalledOnCompleteRef.current) {
|
|
68
|
+
options.onComplete(run, error);
|
|
69
|
+
hasCalledOnCompleteRef.current = true;
|
|
70
|
+
}
|
|
71
|
+
}, [isComplete, run, error, options?.onComplete]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (typeof options?.enabled === "boolean" && !options.enabled) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!runId) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
triggerRequest().finally(() => { });
|
|
80
|
+
return () => {
|
|
81
|
+
stop();
|
|
82
|
+
};
|
|
83
|
+
}, [runId, stop, options?.enabled]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (run?.finishedAt) {
|
|
86
|
+
setIsComplete(true);
|
|
87
|
+
}
|
|
88
|
+
}, [run]);
|
|
89
|
+
return { run, error, stop };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Hook to subscribe to realtime updates of a task run with associated data streams.
|
|
93
|
+
*
|
|
94
|
+
* @template TTask - The type of the task
|
|
95
|
+
* @template TStreams - The type of the streams data
|
|
96
|
+
* @param {string} [runId] - The unique identifier of the run to subscribe to
|
|
97
|
+
* @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
|
|
98
|
+
* @returns {UseRealtimeRunWithStreamsInstance<TTask, TStreams>} An object containing the current state of the run, streams data, and error handling
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import type { myTask } from './path/to/task';
|
|
103
|
+
* const { run, streams, error } = useRealtimeRunWithStreams<typeof myTask, {
|
|
104
|
+
* output: string;
|
|
105
|
+
* }>('run-id-123');
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function useRealtimeRunWithStreams(runId, options) {
|
|
109
|
+
const hookId = useId();
|
|
110
|
+
const idKey = options?.id ?? hookId;
|
|
111
|
+
const [initialStreamsFallback] = useState({});
|
|
112
|
+
// Store the streams state in SWR, using the idKey as the key to share states.
|
|
113
|
+
const { data: streams, mutate: mutateStreams } = useSWR([idKey, "streams"], null, {
|
|
114
|
+
fallbackData: initialStreamsFallback,
|
|
115
|
+
});
|
|
116
|
+
// Keep the latest streams in a ref.
|
|
117
|
+
const streamsRef = useRef(streams ?? {});
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
streamsRef.current = streams || {};
|
|
120
|
+
}, [streams]);
|
|
121
|
+
// Store the streams state in SWR, using the idKey as the key to share states.
|
|
122
|
+
const { data: run, mutate: mutateRun } = useSWR([idKey, "run"], null);
|
|
123
|
+
// Add state to track when the subscription is complete
|
|
124
|
+
const { data: isComplete = false, mutate: setIsComplete } = useSWR([idKey, "complete"], null);
|
|
125
|
+
const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
|
|
126
|
+
// Abort controller to cancel the current API call.
|
|
127
|
+
const abortControllerRef = useRef(null);
|
|
128
|
+
const stop = useCallback(() => {
|
|
129
|
+
if (abortControllerRef.current) {
|
|
130
|
+
abortControllerRef.current.abort();
|
|
131
|
+
abortControllerRef.current = null;
|
|
132
|
+
}
|
|
133
|
+
}, []);
|
|
134
|
+
const apiClient = useApiClient(options);
|
|
135
|
+
const triggerRequest = useCallback(async () => {
|
|
136
|
+
try {
|
|
137
|
+
if (!runId || !apiClient) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const abortController = new AbortController();
|
|
141
|
+
abortControllerRef.current = abortController;
|
|
142
|
+
await processRealtimeRunWithStreams(runId, { skipColumns: options?.skipColumns }, apiClient, mutateRun, mutateStreams, streamsRef, setError, abortControllerRef, typeof options?.stopOnCompletion === "boolean" ? options.stopOnCompletion : true, options?.throttleInMs ?? 16);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
// Ignore abort errors as they are expected.
|
|
146
|
+
if (err.name === "AbortError") {
|
|
147
|
+
abortControllerRef.current = null;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
setError(err);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
if (abortControllerRef.current) {
|
|
154
|
+
abortControllerRef.current = null;
|
|
155
|
+
}
|
|
156
|
+
// Mark the subscription as complete
|
|
157
|
+
setIsComplete(true);
|
|
158
|
+
}
|
|
159
|
+
}, [runId, mutateRun, mutateStreams, streamsRef, abortControllerRef, apiClient, setError]);
|
|
160
|
+
const hasCalledOnCompleteRef = useRef(false);
|
|
161
|
+
// Effect to handle onComplete callback
|
|
162
|
+
// Only call onComplete when the run has actually finished (has finishedAt),
|
|
163
|
+
// not just when the subscription stream ends (which can happen due to network issues)
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (isComplete && run?.finishedAt && options?.onComplete && !hasCalledOnCompleteRef.current) {
|
|
166
|
+
options.onComplete(run, error);
|
|
167
|
+
hasCalledOnCompleteRef.current = true;
|
|
168
|
+
}
|
|
169
|
+
}, [isComplete, run, error, options?.onComplete]);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (typeof options?.enabled === "boolean" && !options.enabled) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (!runId) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
triggerRequest().finally(() => { });
|
|
178
|
+
return () => {
|
|
179
|
+
stop();
|
|
180
|
+
};
|
|
181
|
+
}, [runId, stop, options?.enabled]);
|
|
182
|
+
useEffect(() => {
|
|
183
|
+
if (run?.finishedAt) {
|
|
184
|
+
setIsComplete(true);
|
|
185
|
+
}
|
|
186
|
+
}, [run]);
|
|
187
|
+
return { run, streams: streams ?? initialStreamsFallback, error, stop };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Hook to subscribe to realtime updates of task runs filtered by tag(s).
|
|
191
|
+
*
|
|
192
|
+
* @template TTask - The type of the task
|
|
193
|
+
* @param {string | string[]} tag - The tag or array of tags to filter runs by
|
|
194
|
+
* @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
|
|
195
|
+
* @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs and any error encountered
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* import type { myTask } from './path/to/task';
|
|
200
|
+
* const { runs, error } = useRealtimeRunsWithTag<typeof myTask>('my-tag');
|
|
201
|
+
* // Or with multiple tags
|
|
202
|
+
* const { runs, error } = useRealtimeRunsWithTag<typeof myTask>(['tag1', 'tag2']);
|
|
203
|
+
* // Or with a createdAt filter
|
|
204
|
+
* const { runs, error } = useRealtimeRunsWithTag<typeof myTask>('my-tag', { createdAt: '1h' });
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export function useRealtimeRunsWithTag(tag, options) {
|
|
208
|
+
const normalizedTag = (Array.isArray(tag) ? tag : [tag]).join("-");
|
|
209
|
+
const hookId = useId();
|
|
210
|
+
const idKey = options?.id ?? hookId;
|
|
211
|
+
// Store the streams state in SWR, using the idKey as the key to share states.
|
|
212
|
+
const { data: runs, mutate: mutateRuns } = useSWR([idKey, "run"], null, {
|
|
213
|
+
fallbackData: [],
|
|
214
|
+
});
|
|
215
|
+
// Keep the latest streams in a ref.
|
|
216
|
+
const runsRef = useRef([]);
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
runsRef.current = runs ?? [];
|
|
219
|
+
}, [runs]);
|
|
220
|
+
const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
|
|
221
|
+
// Abort controller to cancel the current API call.
|
|
222
|
+
const abortControllerRef = useRef(null);
|
|
223
|
+
const stop = useCallback(() => {
|
|
224
|
+
if (abortControllerRef.current) {
|
|
225
|
+
abortControllerRef.current.abort();
|
|
226
|
+
abortControllerRef.current = null;
|
|
227
|
+
}
|
|
228
|
+
}, []);
|
|
229
|
+
const apiClient = useApiClient(options);
|
|
230
|
+
const triggerRequest = useCallback(async () => {
|
|
231
|
+
try {
|
|
232
|
+
if (!apiClient) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const abortController = new AbortController();
|
|
236
|
+
abortControllerRef.current = abortController;
|
|
237
|
+
await processRealtimeRunsWithTag(tag, { createdAt: options?.createdAt, skipColumns: options?.skipColumns }, apiClient, mutateRuns, runsRef, setError, abortControllerRef);
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
// Ignore abort errors as they are expected.
|
|
241
|
+
if (err.name === "AbortError") {
|
|
242
|
+
abortControllerRef.current = null;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
setError(err);
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
if (abortControllerRef.current) {
|
|
249
|
+
abortControllerRef.current = null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}, [normalizedTag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
if (typeof options?.enabled === "boolean" && !options.enabled) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
triggerRequest().finally(() => { });
|
|
258
|
+
return () => {
|
|
259
|
+
stop();
|
|
260
|
+
};
|
|
261
|
+
}, [normalizedTag, stop, options?.enabled]);
|
|
262
|
+
return { runs: runs ?? [], error, stop };
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Hook to subscribe to realtime updates of a batch of task runs.
|
|
266
|
+
*
|
|
267
|
+
* @template TTask - The type of the task
|
|
268
|
+
* @param {string} batchId - The unique identifier of the batch to subscribe to
|
|
269
|
+
* @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
|
|
270
|
+
* @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs, error handling, and control methods
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* import type { myTask } from './path/to/task';
|
|
275
|
+
* const { runs, error } = useRealtimeBatch<typeof myTask>('batch-id-123');
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export function useRealtimeBatch(batchId, options) {
|
|
279
|
+
const hookId = useId();
|
|
280
|
+
const idKey = options?.id ?? hookId;
|
|
281
|
+
// Store the streams state in SWR, using the idKey as the key to share states.
|
|
282
|
+
const { data: runs, mutate: mutateRuns } = useSWR([idKey, "run"], null, {
|
|
283
|
+
fallbackData: [],
|
|
284
|
+
});
|
|
285
|
+
// Keep the latest streams in a ref.
|
|
286
|
+
const runsRef = useRef([]);
|
|
287
|
+
useEffect(() => {
|
|
288
|
+
runsRef.current = runs ?? [];
|
|
289
|
+
}, [runs]);
|
|
290
|
+
const { data: error = undefined, mutate: setError } = useSWR([idKey, "error"], null);
|
|
291
|
+
// Abort controller to cancel the current API call.
|
|
292
|
+
const abortControllerRef = useRef(null);
|
|
293
|
+
const stop = useCallback(() => {
|
|
294
|
+
if (abortControllerRef.current) {
|
|
295
|
+
abortControllerRef.current.abort();
|
|
296
|
+
abortControllerRef.current = null;
|
|
297
|
+
}
|
|
298
|
+
}, []);
|
|
299
|
+
const apiClient = useApiClient(options);
|
|
300
|
+
const triggerRequest = useCallback(async () => {
|
|
301
|
+
try {
|
|
302
|
+
if (!apiClient) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const abortController = new AbortController();
|
|
306
|
+
abortControllerRef.current = abortController;
|
|
307
|
+
await processRealtimeBatch(batchId, apiClient, mutateRuns, runsRef, setError, abortControllerRef);
|
|
308
|
+
}
|
|
309
|
+
catch (err) {
|
|
310
|
+
// Ignore abort errors as they are expected.
|
|
311
|
+
if (err.name === "AbortError") {
|
|
312
|
+
abortControllerRef.current = null;
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
setError(err);
|
|
316
|
+
}
|
|
317
|
+
finally {
|
|
318
|
+
if (abortControllerRef.current) {
|
|
319
|
+
abortControllerRef.current = null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}, [batchId, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
if (typeof options?.enabled === "boolean" && !options.enabled) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
triggerRequest().finally(() => { });
|
|
328
|
+
return () => {
|
|
329
|
+
stop();
|
|
330
|
+
};
|
|
331
|
+
}, [batchId, stop, options?.enabled]);
|
|
332
|
+
return { runs: runs ?? [], error, stop };
|
|
333
|
+
}
|
|
334
|
+
export function useRealtimeStream(runIdOrDefinedStream, streamKeyOrOptionsOrRunId, options) {
|
|
335
|
+
if (typeof runIdOrDefinedStream === "string") {
|
|
336
|
+
if (typeof streamKeyOrOptionsOrRunId === "string") {
|
|
337
|
+
return useRealtimeStreamImplementation(runIdOrDefinedStream, streamKeyOrOptionsOrRunId, options);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
return useRealtimeStreamImplementation(runIdOrDefinedStream, "default", streamKeyOrOptionsOrRunId);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
if (typeof streamKeyOrOptionsOrRunId === "string") {
|
|
345
|
+
return useRealtimeStreamImplementation(streamKeyOrOptionsOrRunId, runIdOrDefinedStream.id, options);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
throw new Error("Invalid second argument to useRealtimeStream. When using a defined stream instance, the second argument to useRealtimeStream must be a run ID.");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function useRealtimeStreamImplementation(runId, streamKey, options) {
|
|
353
|
+
const hookId = useId();
|
|
354
|
+
const idKey = options?.id ?? hookId;
|
|
355
|
+
const [initialPartsFallback] = useState([]);
|
|
356
|
+
// Store the streams state in SWR, using the idKey as the key to share states.
|
|
357
|
+
const { data: parts, mutate: mutateParts } = useSWR([idKey, runId, streamKey, "parts"], null, {
|
|
358
|
+
fallbackData: initialPartsFallback,
|
|
359
|
+
});
|
|
360
|
+
// Keep the latest streams in a ref.
|
|
361
|
+
const partsRef = useRef(parts ?? []);
|
|
362
|
+
useEffect(() => {
|
|
363
|
+
partsRef.current = parts || [];
|
|
364
|
+
}, [parts]);
|
|
365
|
+
// Add state to track when the subscription is complete
|
|
366
|
+
const { data: isComplete = false, mutate: setIsComplete } = useSWR([idKey, runId, streamKey, "complete"], null);
|
|
367
|
+
const { data: error = undefined, mutate: setError } = useSWR([idKey, runId, streamKey, "error"], null);
|
|
368
|
+
// Abort controller to cancel the current API call.
|
|
369
|
+
const abortControllerRef = useRef(null);
|
|
370
|
+
const stop = useCallback(() => {
|
|
371
|
+
if (abortControllerRef.current) {
|
|
372
|
+
abortControllerRef.current.abort();
|
|
373
|
+
abortControllerRef.current = null;
|
|
374
|
+
}
|
|
375
|
+
}, []);
|
|
376
|
+
const onData = useCallback((data) => {
|
|
377
|
+
if (options?.onData) {
|
|
378
|
+
options.onData(data);
|
|
379
|
+
}
|
|
380
|
+
}, [options?.onData]);
|
|
381
|
+
const apiClient = useApiClient(options);
|
|
382
|
+
const triggerRequest = useCallback(async () => {
|
|
383
|
+
try {
|
|
384
|
+
if (!runId || !apiClient) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const abortController = new AbortController();
|
|
388
|
+
abortControllerRef.current = abortController;
|
|
389
|
+
await processRealtimeStream(runId, streamKey, apiClient, mutateParts, partsRef, setError, onData, abortControllerRef, options?.timeoutInSeconds, options?.startIndex, options?.throttleInMs ?? 16);
|
|
390
|
+
}
|
|
391
|
+
catch (err) {
|
|
392
|
+
// Ignore abort errors as they are expected.
|
|
393
|
+
if (err.name === "AbortError") {
|
|
394
|
+
abortControllerRef.current = null;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
setError(err);
|
|
398
|
+
}
|
|
399
|
+
finally {
|
|
400
|
+
if (abortControllerRef.current) {
|
|
401
|
+
abortControllerRef.current = null;
|
|
402
|
+
}
|
|
403
|
+
// Mark the subscription as complete
|
|
404
|
+
setIsComplete(true);
|
|
405
|
+
}
|
|
406
|
+
}, [runId, streamKey, mutateParts, partsRef, abortControllerRef, apiClient, setError]);
|
|
407
|
+
useEffect(() => {
|
|
408
|
+
if (typeof options?.enabled === "boolean" && !options.enabled) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (!runId) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
triggerRequest().finally(() => { });
|
|
415
|
+
return () => {
|
|
416
|
+
stop();
|
|
417
|
+
};
|
|
418
|
+
}, [runId, stop, options?.enabled]);
|
|
419
|
+
return { parts: parts ?? initialPartsFallback, error, stop };
|
|
420
|
+
}
|
|
421
|
+
async function processRealtimeBatch(batchId, apiClient, mutateRunsData, existingRunsRef, onError, abortControllerRef) {
|
|
422
|
+
const subscription = apiClient.subscribeToBatch(batchId, {
|
|
423
|
+
signal: abortControllerRef.current?.signal,
|
|
424
|
+
onFetchError: onError,
|
|
425
|
+
});
|
|
426
|
+
for await (const part of subscription) {
|
|
427
|
+
mutateRunsData(insertRunShapeInOrder(existingRunsRef.current, part));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
// Inserts and then orders by the run createdAt timestamp, and ensures that the run is not duplicated
|
|
431
|
+
function insertRunShapeInOrder(previousRuns, run) {
|
|
432
|
+
const existingRun = previousRuns.find((r) => r.id === run.id);
|
|
433
|
+
if (existingRun) {
|
|
434
|
+
return previousRuns.map((r) => (r.id === run.id ? run : r));
|
|
435
|
+
}
|
|
436
|
+
const runCreatedAt = run.createdAt;
|
|
437
|
+
const index = previousRuns.findIndex((r) => r.createdAt > runCreatedAt);
|
|
438
|
+
if (index === -1) {
|
|
439
|
+
return [...previousRuns, run];
|
|
440
|
+
}
|
|
441
|
+
return [...previousRuns.slice(0, index), run, ...previousRuns.slice(index)];
|
|
442
|
+
}
|
|
443
|
+
async function processRealtimeRunsWithTag(tag, filters, apiClient, mutateRunsData, existingRunsRef, onError, abortControllerRef) {
|
|
444
|
+
const subscription = apiClient.subscribeToRunsWithTag(tag, filters, {
|
|
445
|
+
signal: abortControllerRef.current?.signal,
|
|
446
|
+
onFetchError: onError,
|
|
447
|
+
});
|
|
448
|
+
for await (const part of subscription) {
|
|
449
|
+
mutateRunsData(insertRunShape(existingRunsRef.current, part));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
// Replaces or inserts a run shape, ordered by the createdAt timestamp
|
|
453
|
+
function insertRunShape(previousRuns, run) {
|
|
454
|
+
const existingRun = previousRuns.find((r) => r.id === run.id);
|
|
455
|
+
if (existingRun) {
|
|
456
|
+
return previousRuns.map((r) => (r.id === run.id ? run : r));
|
|
457
|
+
}
|
|
458
|
+
const createdAt = run.createdAt;
|
|
459
|
+
const index = previousRuns.findIndex((r) => r.createdAt > createdAt);
|
|
460
|
+
if (index === -1) {
|
|
461
|
+
return [...previousRuns, run];
|
|
462
|
+
}
|
|
463
|
+
return [...previousRuns.slice(0, index), run, ...previousRuns.slice(index)];
|
|
464
|
+
}
|
|
465
|
+
async function processRealtimeRunWithStreams(runId, filters, apiClient, mutateRunData, mutateStreamData, existingDataRef, onError, abortControllerRef, stopOnCompletion = true, throttleInMs) {
|
|
466
|
+
const subscription = apiClient.subscribeToRun(runId, {
|
|
467
|
+
signal: abortControllerRef.current?.signal,
|
|
468
|
+
closeOnComplete: stopOnCompletion,
|
|
469
|
+
onFetchError: onError,
|
|
470
|
+
skipColumns: filters.skipColumns,
|
|
471
|
+
});
|
|
472
|
+
const streamQueue = createThrottledQueue(async (updates) => {
|
|
473
|
+
const nextStreamData = { ...existingDataRef.current };
|
|
474
|
+
// Group updates by type
|
|
475
|
+
const updatesByType = updates.reduce((acc, update) => {
|
|
476
|
+
if (!acc[update.type]) {
|
|
477
|
+
acc[update.type] = [];
|
|
478
|
+
}
|
|
479
|
+
acc[update.type].push(update.chunk);
|
|
480
|
+
return acc;
|
|
481
|
+
}, {});
|
|
482
|
+
// Apply all updates
|
|
483
|
+
for (const [type, chunks] of Object.entries(updatesByType)) {
|
|
484
|
+
// @ts-ignore
|
|
485
|
+
nextStreamData[type] = [...(existingDataRef.current[type] || []), ...chunks];
|
|
486
|
+
}
|
|
487
|
+
mutateStreamData(nextStreamData);
|
|
488
|
+
}, throttleInMs);
|
|
489
|
+
for await (const part of subscription.withStreams()) {
|
|
490
|
+
if (part.type === "run") {
|
|
491
|
+
mutateRunData(part.run);
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
streamQueue.add({
|
|
495
|
+
type: part.type,
|
|
496
|
+
// @ts-ignore
|
|
497
|
+
chunk: part.chunk,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async function processRealtimeRun(runId, filters, apiClient, mutateRunData, onError, abortControllerRef, stopOnCompletion = true) {
|
|
503
|
+
const subscription = apiClient.subscribeToRun(runId, {
|
|
504
|
+
signal: abortControllerRef.current?.signal,
|
|
505
|
+
closeOnComplete: stopOnCompletion,
|
|
506
|
+
onFetchError: onError,
|
|
507
|
+
skipColumns: filters.skipColumns,
|
|
508
|
+
});
|
|
509
|
+
for await (const part of subscription) {
|
|
510
|
+
mutateRunData(part);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async function processRealtimeStream(runId, streamKey, apiClient, mutatePartsData, existingPartsRef, onError, onData, abortControllerRef, timeoutInSeconds, startIndex, throttleInMs) {
|
|
514
|
+
try {
|
|
515
|
+
const stream = await apiClient.fetchStream(runId, streamKey, {
|
|
516
|
+
signal: abortControllerRef.current?.signal,
|
|
517
|
+
timeoutInSeconds,
|
|
518
|
+
lastEventId: startIndex ? (startIndex - 1).toString() : undefined,
|
|
519
|
+
});
|
|
520
|
+
// Throttle the stream
|
|
521
|
+
const streamQueue = createThrottledQueue(async (parts) => {
|
|
522
|
+
mutatePartsData([...existingPartsRef.current, ...parts]);
|
|
523
|
+
}, throttleInMs);
|
|
524
|
+
for await (const part of stream) {
|
|
525
|
+
onData(part);
|
|
526
|
+
streamQueue.add(part);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
catch (err) {
|
|
530
|
+
if (err.name === "AbortError") {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (err instanceof Error) {
|
|
534
|
+
onError(err);
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
onError(new Error(String(err)));
|
|
538
|
+
}
|
|
539
|
+
throw err;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
//# sourceMappingURL=useRealtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRealtime.js","sourceRoot":"","sources":["../../../src/hooks/useRealtime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAWb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAgB,MA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,EAAE,EAAE;YAC9D,eAAe,CAAC,CAAC,GAAG,gBAAgB,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QAC3D,CAAC,EAAE,YAAY,CAAC,CAAC;QAEjB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,CAAC;YACb,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAAW,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YACvC,OAAO;QACT,CAAC;QAED,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;QAED,MAAM,GAAG,CAAC;IACZ,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"}
|