@trigger.dev/react-hooks 4.5.14 → 4.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ import type { AnySessionChannel, ControlEvent, SessionChannelIn, SessionChannelName, SessionChannelOut, SSEStreamPart } from "@trigger.dev/core/v3";
2
+ import type { UseApiClientOptions } from "./useApiClient.js";
3
+ type ChannelRecord<TChannel extends AnySessionChannel, S extends "in" | "out"> = S extends "out" ? SessionChannelOut<TChannel> : SessionChannelIn<TChannel>;
4
+ export type UseSessionStreamChannelInstance<TRecord> = {
5
+ /** The records received so far on the channel, in arrival order. */
6
+ records: Array<TRecord>;
7
+ /** The cursor of the last record seen; pass back as `lastEventId` to resume. */
8
+ lastEventId: string | undefined;
9
+ /** The last control record seen on the channel. */
10
+ lastControl: ControlEvent | undefined;
11
+ error: Error | undefined;
12
+ /** Abort the current request immediately, keep the records received so far. */
13
+ stop: () => void;
14
+ };
15
+ export type UseSessionStreamChannelOptions<TChannel extends AnySessionChannel, S extends "in" | "out"> = UseApiClientOptions & {
16
+ /**
17
+ * The id or external id of the session that owns the channel. May be
18
+ * undefined while it resolves; the subscription starts once it is set.
19
+ */
20
+ sessionId?: string;
21
+ id?: string;
22
+ enabled?: boolean;
23
+ /**
24
+ * Which side of the channel to read.
25
+ *
26
+ * @default "out"
27
+ */
28
+ io?: S;
29
+ /**
30
+ * The number of milliseconds to throttle the record updates.
31
+ *
32
+ * @default 16
33
+ */
34
+ throttleInMs?: number;
35
+ /**
36
+ * The number of seconds to wait for new data before the stream closes.
37
+ *
38
+ * @default 60 seconds
39
+ */
40
+ timeoutInSeconds?: number;
41
+ /** The cursor to resume from. If not provided, reads per `from`. */
42
+ lastEventId?: string | number;
43
+ /**
44
+ * Where a fresh subscription (no `lastEventId`) starts reading.
45
+ *
46
+ * - `"beginning"` (default): replay the full channel history, then live-tail.
47
+ * - `"latest"`: start at the current tail, for a last-value / live view.
48
+ *
49
+ * Ignored when `lastEventId` is set.
50
+ */
51
+ from?: "beginning" | "latest";
52
+ /**
53
+ * Cap the number of records kept in `records`. Use `maxRecords: 1` with
54
+ * `from: "latest"` for a bounded last-value view.
55
+ */
56
+ maxRecords?: number;
57
+ /** Invoked once per throttled flush with the batch of records (control records included). */
58
+ onRecords?: (records: Array<SSEStreamPart<ChannelRecord<TChannel, S>>>) => void;
59
+ /** Called when a control record is received on the channel. */
60
+ onControl?: (event: ControlEvent) => void;
61
+ };
62
+ /**
63
+ * Read one side of a named Session side channel, with record types inferred
64
+ * from a `defineSessionChannel` declaration passed as the type argument.
65
+ *
66
+ * The channel name is typesafe (`SessionChannelName<TChannel>`) and `records`
67
+ * is typed from the channel's `.out` / `.in` record type. Called without the
68
+ * type argument, the channel name is any string and `records` is `unknown`.
69
+ *
70
+ * Requires a Public Access Token scoped to the session (or to the channel).
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * import type { screenshotsChannel } from "./shared/channels";
75
+ *
76
+ * const { records } = useSessionStreamChannel<typeof screenshotsChannel>("screenshots", {
77
+ * sessionId,
78
+ * accessToken,
79
+ * io: "out",
80
+ * from: "latest",
81
+ * maxRecords: 1,
82
+ * });
83
+ * ```
84
+ */
85
+ export declare function useSessionStreamChannel<TChannel extends AnySessionChannel = AnySessionChannel, S extends "in" | "out" = "out">(channel: SessionChannelName<TChannel>, options: UseSessionStreamChannelOptions<TChannel, S>): UseSessionStreamChannelInstance<ChannelRecord<TChannel, S>>;
86
+ export {};
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useSessionStreamChannel = useSessionStreamChannel;
5
+ const react_1 = require("react");
6
+ const throttle_js_1 = require("../utils/throttle.js");
7
+ const trigger_swr_js_1 = require("../utils/trigger-swr.js");
8
+ const useStableRequestCallback_js_1 = require("../utils/useStableRequestCallback.js");
9
+ const useApiClient_js_1 = require("./useApiClient.js");
10
+ /**
11
+ * Read one side of a named Session side channel, with record types inferred
12
+ * from a `defineSessionChannel` declaration passed as the type argument.
13
+ *
14
+ * The channel name is typesafe (`SessionChannelName<TChannel>`) and `records`
15
+ * is typed from the channel's `.out` / `.in` record type. Called without the
16
+ * type argument, the channel name is any string and `records` is `unknown`.
17
+ *
18
+ * Requires a Public Access Token scoped to the session (or to the channel).
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import type { screenshotsChannel } from "./shared/channels";
23
+ *
24
+ * const { records } = useSessionStreamChannel<typeof screenshotsChannel>("screenshots", {
25
+ * sessionId,
26
+ * accessToken,
27
+ * io: "out",
28
+ * from: "latest",
29
+ * maxRecords: 1,
30
+ * });
31
+ * ```
32
+ */
33
+ function useSessionStreamChannel(channel, options) {
34
+ const hookId = (0, react_1.useId)();
35
+ const idKey = options.id ?? hookId;
36
+ const io = (options.io ?? "out");
37
+ const sessionId = options.sessionId;
38
+ const channelName = channel;
39
+ const [initialRecordsFallback] = (0, react_1.useState)([]);
40
+ const { data: records, mutate: mutateRecords } = (0, trigger_swr_js_1.useSWR)([idKey, sessionId, channelName, io, "records"], null, { fallbackData: initialRecordsFallback });
41
+ const recordsRef = (0, react_1.useRef)(records ?? []);
42
+ (0, react_1.useEffect)(() => {
43
+ recordsRef.current = records || [];
44
+ }, [records]);
45
+ const { data: lastEventId = undefined, mutate: setLastEventId } = (0, trigger_swr_js_1.useSWR)([idKey, sessionId, channelName, io, "lastEventId"], null);
46
+ const lastEventIdRef = (0, react_1.useRef)(lastEventId);
47
+ const channelIdentityRef = (0, react_1.useRef)(`${idKey}:${sessionId}:${channelName}:${io}`);
48
+ (0, react_1.useEffect)(() => {
49
+ const identity = `${idKey}:${sessionId}:${channelName}:${io}`;
50
+ if (channelIdentityRef.current !== identity) {
51
+ channelIdentityRef.current = identity;
52
+ lastEventIdRef.current = lastEventId;
53
+ }
54
+ }, [idKey, sessionId, channelName, io, lastEventId]);
55
+ const { data: lastControl = undefined, mutate: setLastControl } = (0, trigger_swr_js_1.useSWR)([idKey, sessionId, channelName, io, "lastControl"], null);
56
+ const { data: _isComplete = false, mutate: setIsComplete } = (0, trigger_swr_js_1.useSWR)([idKey, sessionId, channelName, io, "complete"], null);
57
+ const { data: error = undefined, mutate: setError } = (0, trigger_swr_js_1.useSWR)([idKey, sessionId, channelName, io, "error"], null);
58
+ const abortControllerRef = (0, react_1.useRef)(null);
59
+ const stop = (0, react_1.useCallback)(() => {
60
+ if (abortControllerRef.current) {
61
+ abortControllerRef.current.abort();
62
+ abortControllerRef.current = null;
63
+ }
64
+ }, []);
65
+ const onRecordsCallback = options.onRecords;
66
+ const onRecords = (0, react_1.useCallback)((recordsBatch) => {
67
+ if (onRecordsCallback) {
68
+ onRecordsCallback(recordsBatch);
69
+ }
70
+ }, [onRecordsCallback]);
71
+ const onControlCallback = options.onControl;
72
+ const onControl = (0, react_1.useCallback)((event) => {
73
+ if (onControlCallback) {
74
+ onControlCallback(event);
75
+ }
76
+ }, [onControlCallback]);
77
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
78
+ const timeoutInSeconds = options.timeoutInSeconds;
79
+ const startEventId = options.lastEventId;
80
+ const throttleInMs = options.throttleInMs;
81
+ const from = options.from;
82
+ const maxRecords = options.maxRecords;
83
+ (0, react_1.useEffect)(() => {
84
+ if (maxRecords != null && maxRecords >= 0) {
85
+ const current = recordsRef.current;
86
+ if (current.length > maxRecords) {
87
+ mutateRecords(current.slice(current.length - maxRecords));
88
+ }
89
+ }
90
+ }, [maxRecords, mutateRecords]);
91
+ const triggerRequest = (0, react_1.useCallback)(async () => {
92
+ let abortController = null;
93
+ try {
94
+ if (!sessionId || !apiClient) {
95
+ return;
96
+ }
97
+ abortController = new AbortController();
98
+ abortControllerRef.current = abortController;
99
+ await processSessionChannelStream(sessionId, io, channelName, apiClient, mutateRecords, recordsRef, setLastEventId, setLastControl, setError, onRecords, onControl, abortControllerRef, timeoutInSeconds, startEventId !== undefined ? String(startEventId) : lastEventIdRef.current, throttleInMs ?? 16, from, maxRecords);
100
+ }
101
+ catch (err) {
102
+ if (err.name === "AbortError") {
103
+ return;
104
+ }
105
+ setError(err);
106
+ }
107
+ finally {
108
+ if (abortControllerRef.current === abortController) {
109
+ abortControllerRef.current = null;
110
+ }
111
+ setIsComplete(true);
112
+ }
113
+ }, [
114
+ sessionId,
115
+ io,
116
+ channelName,
117
+ apiClient,
118
+ mutateRecords,
119
+ setLastEventId,
120
+ setLastControl,
121
+ setError,
122
+ setIsComplete,
123
+ onRecords,
124
+ onControl,
125
+ timeoutInSeconds,
126
+ startEventId,
127
+ throttleInMs,
128
+ from,
129
+ maxRecords,
130
+ ]);
131
+ const requestSubscription = (0, useStableRequestCallback_js_1.useStableRequestCallback)(triggerRequest);
132
+ (0, react_1.useEffect)(() => {
133
+ if (typeof options.enabled === "boolean" && !options.enabled) {
134
+ return;
135
+ }
136
+ if (!sessionId) {
137
+ return;
138
+ }
139
+ requestSubscription().finally(() => { });
140
+ return () => {
141
+ stop();
142
+ };
143
+ }, [sessionId, channelName, io, stop, options.enabled, requestSubscription]);
144
+ return { records: records ?? initialRecordsFallback, lastEventId, lastControl, error, stop };
145
+ }
146
+ async function processSessionChannelStream(sessionIdOrExternalId, io, channel, apiClient, mutateRecordsData, existingRecordsRef, setLastEventId, setLastControl, onError, onRecords, onControl, abortControllerRef, timeoutInSeconds, lastEventId, throttleInMs, from, maxRecords) {
147
+ let lastSeenEventId;
148
+ let publishedEventId;
149
+ let partsBatch = [];
150
+ const publishLastEventId = () => {
151
+ if (lastSeenEventId !== publishedEventId) {
152
+ publishedEventId = lastSeenEventId;
153
+ setLastEventId(lastSeenEventId);
154
+ }
155
+ };
156
+ const flushParts = () => {
157
+ if (partsBatch.length === 0)
158
+ return;
159
+ const batch = partsBatch;
160
+ partsBatch = [];
161
+ onRecords(batch);
162
+ };
163
+ try {
164
+ const stream = await apiClient.subscribeToSessionStream(sessionIdOrExternalId, io, {
165
+ signal: abortControllerRef.current?.signal,
166
+ channel,
167
+ timeoutInSeconds,
168
+ lastEventId,
169
+ from,
170
+ onPart: (part) => {
171
+ lastSeenEventId = part.id;
172
+ partsBatch.push(part);
173
+ },
174
+ onControl: (event) => {
175
+ setLastControl(event);
176
+ onControl(event);
177
+ },
178
+ });
179
+ const recordsQueue = (0, throttle_js_1.createThrottledQueue)(async (newRecords) => {
180
+ const combined = [...existingRecordsRef.current, ...newRecords];
181
+ const bounded = maxRecords != null && maxRecords >= 0 && combined.length > maxRecords
182
+ ? combined.slice(combined.length - maxRecords)
183
+ : combined;
184
+ existingRecordsRef.current = bounded;
185
+ mutateRecordsData(bounded);
186
+ publishLastEventId();
187
+ flushParts();
188
+ }, throttleInMs);
189
+ for await (const record of stream) {
190
+ recordsQueue.add(record);
191
+ }
192
+ await recordsQueue.flush();
193
+ publishLastEventId();
194
+ flushParts();
195
+ }
196
+ catch (err) {
197
+ if (err.name === "AbortError") {
198
+ return;
199
+ }
200
+ if (err instanceof Error) {
201
+ onError(err);
202
+ }
203
+ else {
204
+ onError(new Error(String(err)));
205
+ }
206
+ throw err;
207
+ }
208
+ }
209
+ //# sourceMappingURL=useSessionStreamChannel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSessionStreamChannel.js","sourceRoot":"","sources":["../../../src/hooks/useSessionStreamChannel.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAWb,iCAAwE;AACxE,sDAA4D;AAE5D,4DAAiD;AACjD,sFAAgF;AAEhF,uDAAiD;AAqEjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,iCAIE,OAAqC,EACrC,OAAoD;IAIpD,MAAM,MAAM,GAAG,IAAA,aAAK,GAAE,CAAC;IACvB,MAAM,KAAK,GAAG,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC;IACnC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,CAAiB,CAAC;IACjD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACpC,MAAM,WAAW,GAAG,OAAi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C;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"}
@@ -6,3 +6,4 @@ export * from "./hooks/useTaskTrigger.js";
6
6
  export * from "./hooks/useWaitToken.js";
7
7
  export * from "./hooks/useInputStreamSend.js";
8
8
  export * from "./hooks/useSessionStream.js";
9
+ export * from "./hooks/useSessionStreamChannel.js";
@@ -22,4 +22,5 @@ __exportStar(require("./hooks/useTaskTrigger.js"), exports);
22
22
  __exportStar(require("./hooks/useWaitToken.js"), exports);
23
23
  __exportStar(require("./hooks/useInputStreamSend.js"), exports);
24
24
  __exportStar(require("./hooks/useSessionStream.js"), exports);
25
+ __exportStar(require("./hooks/useSessionStreamChannel.js"), exports);
25
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0DAAwC;AACxC,oDAAkC;AAClC,yDAAuC;AACvC,4DAA0C;AAC1C,0DAAwC;AACxC,gEAA8C;AAC9C,8DAA4C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0DAAwC;AACxC,oDAAkC;AAClC,yDAAuC;AACvC,4DAA0C;AAC1C,0DAAwC;AACxC,gEAA8C;AAC9C,8DAA4C;AAC5C,qEAAmD"}
@@ -0,0 +1,86 @@
1
+ import type { AnySessionChannel, ControlEvent, SessionChannelIn, SessionChannelName, SessionChannelOut, SSEStreamPart } from "@trigger.dev/core/v3";
2
+ import type { UseApiClientOptions } from "./useApiClient.js";
3
+ type ChannelRecord<TChannel extends AnySessionChannel, S extends "in" | "out"> = S extends "out" ? SessionChannelOut<TChannel> : SessionChannelIn<TChannel>;
4
+ export type UseSessionStreamChannelInstance<TRecord> = {
5
+ /** The records received so far on the channel, in arrival order. */
6
+ records: Array<TRecord>;
7
+ /** The cursor of the last record seen; pass back as `lastEventId` to resume. */
8
+ lastEventId: string | undefined;
9
+ /** The last control record seen on the channel. */
10
+ lastControl: ControlEvent | undefined;
11
+ error: Error | undefined;
12
+ /** Abort the current request immediately, keep the records received so far. */
13
+ stop: () => void;
14
+ };
15
+ export type UseSessionStreamChannelOptions<TChannel extends AnySessionChannel, S extends "in" | "out"> = UseApiClientOptions & {
16
+ /**
17
+ * The id or external id of the session that owns the channel. May be
18
+ * undefined while it resolves; the subscription starts once it is set.
19
+ */
20
+ sessionId?: string;
21
+ id?: string;
22
+ enabled?: boolean;
23
+ /**
24
+ * Which side of the channel to read.
25
+ *
26
+ * @default "out"
27
+ */
28
+ io?: S;
29
+ /**
30
+ * The number of milliseconds to throttle the record updates.
31
+ *
32
+ * @default 16
33
+ */
34
+ throttleInMs?: number;
35
+ /**
36
+ * The number of seconds to wait for new data before the stream closes.
37
+ *
38
+ * @default 60 seconds
39
+ */
40
+ timeoutInSeconds?: number;
41
+ /** The cursor to resume from. If not provided, reads per `from`. */
42
+ lastEventId?: string | number;
43
+ /**
44
+ * Where a fresh subscription (no `lastEventId`) starts reading.
45
+ *
46
+ * - `"beginning"` (default): replay the full channel history, then live-tail.
47
+ * - `"latest"`: start at the current tail, for a last-value / live view.
48
+ *
49
+ * Ignored when `lastEventId` is set.
50
+ */
51
+ from?: "beginning" | "latest";
52
+ /**
53
+ * Cap the number of records kept in `records`. Use `maxRecords: 1` with
54
+ * `from: "latest"` for a bounded last-value view.
55
+ */
56
+ maxRecords?: number;
57
+ /** Invoked once per throttled flush with the batch of records (control records included). */
58
+ onRecords?: (records: Array<SSEStreamPart<ChannelRecord<TChannel, S>>>) => void;
59
+ /** Called when a control record is received on the channel. */
60
+ onControl?: (event: ControlEvent) => void;
61
+ };
62
+ /**
63
+ * Read one side of a named Session side channel, with record types inferred
64
+ * from a `defineSessionChannel` declaration passed as the type argument.
65
+ *
66
+ * The channel name is typesafe (`SessionChannelName<TChannel>`) and `records`
67
+ * is typed from the channel's `.out` / `.in` record type. Called without the
68
+ * type argument, the channel name is any string and `records` is `unknown`.
69
+ *
70
+ * Requires a Public Access Token scoped to the session (or to the channel).
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * import type { screenshotsChannel } from "./shared/channels";
75
+ *
76
+ * const { records } = useSessionStreamChannel<typeof screenshotsChannel>("screenshots", {
77
+ * sessionId,
78
+ * accessToken,
79
+ * io: "out",
80
+ * from: "latest",
81
+ * maxRecords: 1,
82
+ * });
83
+ * ```
84
+ */
85
+ export declare function useSessionStreamChannel<TChannel extends AnySessionChannel = AnySessionChannel, S extends "in" | "out" = "out">(channel: SessionChannelName<TChannel>, options: UseSessionStreamChannelOptions<TChannel, S>): UseSessionStreamChannelInstance<ChannelRecord<TChannel, S>>;
86
+ export {};
@@ -0,0 +1,206 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useId, useRef, useState } from "react";
3
+ import { createThrottledQueue } from "../utils/throttle.js";
4
+ import { useSWR } from "../utils/trigger-swr.js";
5
+ import { useStableRequestCallback } from "../utils/useStableRequestCallback.js";
6
+ import { useApiClient } from "./useApiClient.js";
7
+ /**
8
+ * Read one side of a named Session side channel, with record types inferred
9
+ * from a `defineSessionChannel` declaration passed as the type argument.
10
+ *
11
+ * The channel name is typesafe (`SessionChannelName<TChannel>`) and `records`
12
+ * is typed from the channel's `.out` / `.in` record type. Called without the
13
+ * type argument, the channel name is any string and `records` is `unknown`.
14
+ *
15
+ * Requires a Public Access Token scoped to the session (or to the channel).
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * import type { screenshotsChannel } from "./shared/channels";
20
+ *
21
+ * const { records } = useSessionStreamChannel<typeof screenshotsChannel>("screenshots", {
22
+ * sessionId,
23
+ * accessToken,
24
+ * io: "out",
25
+ * from: "latest",
26
+ * maxRecords: 1,
27
+ * });
28
+ * ```
29
+ */
30
+ export function useSessionStreamChannel(channel, options) {
31
+ const hookId = useId();
32
+ const idKey = options.id ?? hookId;
33
+ const io = (options.io ?? "out");
34
+ const sessionId = options.sessionId;
35
+ const channelName = channel;
36
+ const [initialRecordsFallback] = useState([]);
37
+ const { data: records, mutate: mutateRecords } = useSWR([idKey, sessionId, channelName, io, "records"], null, { fallbackData: initialRecordsFallback });
38
+ const recordsRef = useRef(records ?? []);
39
+ useEffect(() => {
40
+ recordsRef.current = records || [];
41
+ }, [records]);
42
+ const { data: lastEventId = undefined, mutate: setLastEventId } = useSWR([idKey, sessionId, channelName, io, "lastEventId"], null);
43
+ const lastEventIdRef = useRef(lastEventId);
44
+ const channelIdentityRef = useRef(`${idKey}:${sessionId}:${channelName}:${io}`);
45
+ useEffect(() => {
46
+ const identity = `${idKey}:${sessionId}:${channelName}:${io}`;
47
+ if (channelIdentityRef.current !== identity) {
48
+ channelIdentityRef.current = identity;
49
+ lastEventIdRef.current = lastEventId;
50
+ }
51
+ }, [idKey, sessionId, channelName, io, lastEventId]);
52
+ const { data: lastControl = undefined, mutate: setLastControl } = useSWR([idKey, sessionId, channelName, io, "lastControl"], null);
53
+ const { data: _isComplete = false, mutate: setIsComplete } = useSWR([idKey, sessionId, channelName, io, "complete"], null);
54
+ const { data: error = undefined, mutate: setError } = useSWR([idKey, sessionId, channelName, io, "error"], null);
55
+ const abortControllerRef = useRef(null);
56
+ const stop = useCallback(() => {
57
+ if (abortControllerRef.current) {
58
+ abortControllerRef.current.abort();
59
+ abortControllerRef.current = null;
60
+ }
61
+ }, []);
62
+ const onRecordsCallback = options.onRecords;
63
+ const onRecords = useCallback((recordsBatch) => {
64
+ if (onRecordsCallback) {
65
+ onRecordsCallback(recordsBatch);
66
+ }
67
+ }, [onRecordsCallback]);
68
+ const onControlCallback = options.onControl;
69
+ const onControl = useCallback((event) => {
70
+ if (onControlCallback) {
71
+ onControlCallback(event);
72
+ }
73
+ }, [onControlCallback]);
74
+ const apiClient = useApiClient(options);
75
+ const timeoutInSeconds = options.timeoutInSeconds;
76
+ const startEventId = options.lastEventId;
77
+ const throttleInMs = options.throttleInMs;
78
+ const from = options.from;
79
+ const maxRecords = options.maxRecords;
80
+ useEffect(() => {
81
+ if (maxRecords != null && maxRecords >= 0) {
82
+ const current = recordsRef.current;
83
+ if (current.length > maxRecords) {
84
+ mutateRecords(current.slice(current.length - maxRecords));
85
+ }
86
+ }
87
+ }, [maxRecords, mutateRecords]);
88
+ const triggerRequest = useCallback(async () => {
89
+ let abortController = null;
90
+ try {
91
+ if (!sessionId || !apiClient) {
92
+ return;
93
+ }
94
+ abortController = new AbortController();
95
+ abortControllerRef.current = abortController;
96
+ await processSessionChannelStream(sessionId, io, channelName, apiClient, mutateRecords, recordsRef, setLastEventId, setLastControl, setError, onRecords, onControl, abortControllerRef, timeoutInSeconds, startEventId !== undefined ? String(startEventId) : lastEventIdRef.current, throttleInMs ?? 16, from, maxRecords);
97
+ }
98
+ catch (err) {
99
+ if (err.name === "AbortError") {
100
+ return;
101
+ }
102
+ setError(err);
103
+ }
104
+ finally {
105
+ if (abortControllerRef.current === abortController) {
106
+ abortControllerRef.current = null;
107
+ }
108
+ setIsComplete(true);
109
+ }
110
+ }, [
111
+ sessionId,
112
+ io,
113
+ channelName,
114
+ apiClient,
115
+ mutateRecords,
116
+ setLastEventId,
117
+ setLastControl,
118
+ setError,
119
+ setIsComplete,
120
+ onRecords,
121
+ onControl,
122
+ timeoutInSeconds,
123
+ startEventId,
124
+ throttleInMs,
125
+ from,
126
+ maxRecords,
127
+ ]);
128
+ const requestSubscription = useStableRequestCallback(triggerRequest);
129
+ useEffect(() => {
130
+ if (typeof options.enabled === "boolean" && !options.enabled) {
131
+ return;
132
+ }
133
+ if (!sessionId) {
134
+ return;
135
+ }
136
+ requestSubscription().finally(() => { });
137
+ return () => {
138
+ stop();
139
+ };
140
+ }, [sessionId, channelName, io, stop, options.enabled, requestSubscription]);
141
+ return { records: records ?? initialRecordsFallback, lastEventId, lastControl, error, stop };
142
+ }
143
+ async function processSessionChannelStream(sessionIdOrExternalId, io, channel, apiClient, mutateRecordsData, existingRecordsRef, setLastEventId, setLastControl, onError, onRecords, onControl, abortControllerRef, timeoutInSeconds, lastEventId, throttleInMs, from, maxRecords) {
144
+ let lastSeenEventId;
145
+ let publishedEventId;
146
+ let partsBatch = [];
147
+ const publishLastEventId = () => {
148
+ if (lastSeenEventId !== publishedEventId) {
149
+ publishedEventId = lastSeenEventId;
150
+ setLastEventId(lastSeenEventId);
151
+ }
152
+ };
153
+ const flushParts = () => {
154
+ if (partsBatch.length === 0)
155
+ return;
156
+ const batch = partsBatch;
157
+ partsBatch = [];
158
+ onRecords(batch);
159
+ };
160
+ try {
161
+ const stream = await apiClient.subscribeToSessionStream(sessionIdOrExternalId, io, {
162
+ signal: abortControllerRef.current?.signal,
163
+ channel,
164
+ timeoutInSeconds,
165
+ lastEventId,
166
+ from,
167
+ onPart: (part) => {
168
+ lastSeenEventId = part.id;
169
+ partsBatch.push(part);
170
+ },
171
+ onControl: (event) => {
172
+ setLastControl(event);
173
+ onControl(event);
174
+ },
175
+ });
176
+ const recordsQueue = createThrottledQueue(async (newRecords) => {
177
+ const combined = [...existingRecordsRef.current, ...newRecords];
178
+ const bounded = maxRecords != null && maxRecords >= 0 && combined.length > maxRecords
179
+ ? combined.slice(combined.length - maxRecords)
180
+ : combined;
181
+ existingRecordsRef.current = bounded;
182
+ mutateRecordsData(bounded);
183
+ publishLastEventId();
184
+ flushParts();
185
+ }, throttleInMs);
186
+ for await (const record of stream) {
187
+ recordsQueue.add(record);
188
+ }
189
+ await recordsQueue.flush();
190
+ publishLastEventId();
191
+ flushParts();
192
+ }
193
+ catch (err) {
194
+ if (err.name === "AbortError") {
195
+ return;
196
+ }
197
+ if (err instanceof Error) {
198
+ onError(err);
199
+ }
200
+ else {
201
+ onError(new Error(String(err)));
202
+ }
203
+ throw err;
204
+ }
205
+ }
206
+ //# sourceMappingURL=useSessionStreamChannel.js.map
@@ -0,0 +1 @@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gBAC9C,CAAC,CAAC,QAAQ,CAAC;YACf,kBAAkB,CAAC,OAAO,GAAG,OAAO,CAAC;YACrC,iBAAiB,CAAC,OAAO,CAAC,CAAC;YAC3B,kBAAkB,EAAE,CAAC;YACrB,UAAU,EAAE,CAAC;QACf,CAAC,EAAE,YAAY,CAAC,CAAC;QAEjB,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,MAAM,EAAE,CAAC;YAClC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC;QAED,MAAM,YAAY,CAAC,KAAK,EAAE,CAAC;QAC3B,kBAAkB,EAAE,CAAC;QACrB,UAAU,EAAE,CAAC;IACf,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"}
@@ -6,3 +6,4 @@ export * from "./hooks/useTaskTrigger.js";
6
6
  export * from "./hooks/useWaitToken.js";
7
7
  export * from "./hooks/useInputStreamSend.js";
8
8
  export * from "./hooks/useSessionStream.js";
9
+ export * from "./hooks/useSessionStreamChannel.js";
package/dist/esm/index.js CHANGED
@@ -6,4 +6,5 @@ export * from "./hooks/useTaskTrigger.js";
6
6
  export * from "./hooks/useWaitToken.js";
7
7
  export * from "./hooks/useInputStreamSend.js";
8
8
  export * from "./hooks/useSessionStream.js";
9
+ export * from "./hooks/useSessionStreamChannel.js";
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigger.dev/react-hooks",
3
- "version": "4.5.14",
3
+ "version": "4.5.15",
4
4
  "description": "trigger.dev react hooks",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -29,7 +29,7 @@
29
29
  ]
30
30
  },
31
31
  "dependencies": {
32
- "@trigger.dev/core": "^4.5.14",
32
+ "@trigger.dev/core": "^4.5.15",
33
33
  "swr": "^2.2.5"
34
34
  },
35
35
  "devDependencies": {