@trigger.dev/react-hooks 0.0.0-v3-prerelease-20241105122139 → 0.0.0-v3-prerelease-20241203112040

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 (63) hide show
  1. package/dist/commonjs/contexts.d.ts +2 -2
  2. package/dist/commonjs/contexts.js +3 -2
  3. package/dist/commonjs/contexts.js.map +1 -1
  4. package/dist/commonjs/hooks/useApiClient.d.ts +39 -2
  5. package/dist/commonjs/hooks/useApiClient.js +34 -6
  6. package/dist/commonjs/hooks/useApiClient.js.map +1 -1
  7. package/dist/commonjs/hooks/useRealtime.d.ts +100 -0
  8. package/dist/commonjs/hooks/useRealtime.js +393 -0
  9. package/dist/commonjs/hooks/useRealtime.js.map +1 -0
  10. package/dist/commonjs/hooks/useRun.js +7 -2
  11. package/dist/commonjs/hooks/useRun.js.map +1 -1
  12. package/dist/commonjs/hooks/useTaskTrigger.d.ts +101 -0
  13. package/dist/commonjs/hooks/useTaskTrigger.js +137 -0
  14. package/dist/commonjs/hooks/useTaskTrigger.js.map +1 -0
  15. package/dist/commonjs/index.d.ts +2 -3
  16. package/dist/commonjs/index.js +2 -3
  17. package/dist/commonjs/index.js.map +1 -1
  18. package/dist/commonjs/utils/throttle.d.ts +6 -0
  19. package/dist/commonjs/utils/throttle.js +50 -0
  20. package/dist/commonjs/utils/throttle.js.map +1 -0
  21. package/dist/commonjs/utils/trigger-swr.d.ts +12 -0
  22. package/dist/commonjs/utils/trigger-swr.js.map +1 -1
  23. package/dist/esm/contexts.d.ts +2 -2
  24. package/dist/esm/contexts.js +2 -2
  25. package/dist/esm/contexts.js.map +1 -1
  26. package/dist/esm/hooks/useApiClient.d.ts +39 -2
  27. package/dist/esm/hooks/useApiClient.js +35 -7
  28. package/dist/esm/hooks/useApiClient.js.map +1 -1
  29. package/dist/esm/hooks/useRealtime.d.ts +100 -0
  30. package/dist/esm/hooks/useRealtime.js +387 -0
  31. package/dist/esm/hooks/useRealtime.js.map +1 -0
  32. package/dist/esm/hooks/useRun.js +7 -2
  33. package/dist/esm/hooks/useRun.js.map +1 -1
  34. package/dist/esm/hooks/useTaskTrigger.d.ts +101 -0
  35. package/dist/esm/hooks/useTaskTrigger.js +129 -0
  36. package/dist/esm/hooks/useTaskTrigger.js.map +1 -0
  37. package/dist/esm/index.d.ts +2 -3
  38. package/dist/esm/index.js +2 -3
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/esm/utils/throttle.d.ts +6 -0
  41. package/dist/esm/utils/throttle.js +47 -0
  42. package/dist/esm/utils/throttle.js.map +1 -0
  43. package/dist/esm/utils/trigger-swr.d.ts +12 -0
  44. package/dist/esm/utils/trigger-swr.js.map +1 -1
  45. package/package.json +2 -2
  46. package/dist/commonjs/hooks/useRealtimeBatch.d.ts +0 -19
  47. package/dist/commonjs/hooks/useRealtimeBatch.js +0 -56
  48. package/dist/commonjs/hooks/useRealtimeBatch.js.map +0 -1
  49. package/dist/commonjs/hooks/useRealtimeRun.d.ts +0 -18
  50. package/dist/commonjs/hooks/useRealtimeRun.js +0 -40
  51. package/dist/commonjs/hooks/useRealtimeRun.js.map +0 -1
  52. package/dist/commonjs/hooks/useRealtimeRunsWithTag.d.ts +0 -5
  53. package/dist/commonjs/hooks/useRealtimeRunsWithTag.js +0 -45
  54. package/dist/commonjs/hooks/useRealtimeRunsWithTag.js.map +0 -1
  55. package/dist/esm/hooks/useRealtimeBatch.d.ts +0 -19
  56. package/dist/esm/hooks/useRealtimeBatch.js +0 -53
  57. package/dist/esm/hooks/useRealtimeBatch.js.map +0 -1
  58. package/dist/esm/hooks/useRealtimeRun.d.ts +0 -18
  59. package/dist/esm/hooks/useRealtimeRun.js +0 -37
  60. package/dist/esm/hooks/useRealtimeRun.js.map +0 -1
  61. package/dist/esm/hooks/useRealtimeRunsWithTag.d.ts +0 -5
  62. package/dist/esm/hooks/useRealtimeRunsWithTag.js +0 -42
  63. package/dist/esm/hooks/useRealtimeRunsWithTag.js.map +0 -1
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
3
- declare const TriggerAuthContext: React.Context<ApiClientConfiguration | undefined>, useTriggerAuthContext: () => ApiClientConfiguration;
4
- export { TriggerAuthContext, useTriggerAuthContext };
3
+ declare const TriggerAuthContext: React.Context<ApiClientConfiguration | undefined>, useTriggerAuthContext: () => ApiClientConfiguration, useTriggerAuthContextOptional: () => ApiClientConfiguration | Partial<ApiClientConfiguration>;
4
+ export { TriggerAuthContext, useTriggerAuthContext, useTriggerAuthContextOptional };
@@ -1,9 +1,10 @@
1
1
  "use client";
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useTriggerAuthContext = exports.TriggerAuthContext = void 0;
4
+ exports.useTriggerAuthContextOptional = exports.useTriggerAuthContext = exports.TriggerAuthContext = void 0;
5
5
  const createContextAndHook_js_1 = require("./utils/createContextAndHook.js");
6
- const [TriggerAuthContext, useTriggerAuthContext] = (0, createContextAndHook_js_1.createContextAndHook)("TriggerAuthContext");
6
+ const [TriggerAuthContext, useTriggerAuthContext, useTriggerAuthContextOptional] = (0, createContextAndHook_js_1.createContextAndHook)("TriggerAuthContext");
7
7
  exports.TriggerAuthContext = TriggerAuthContext;
8
8
  exports.useTriggerAuthContext = useTriggerAuthContext;
9
+ exports.useTriggerAuthContextOptional = useTriggerAuthContextOptional;
9
10
  //# sourceMappingURL=contexts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../src/contexts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;AAGb,6EAAuE;AAGvE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAC/C,IAAA,8CAAoB,EAAyB,oBAAoB,CAAC,CAAC;AAE5D,gDAAkB;AAAE,sDAAqB"}
1
+ {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../src/contexts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;AAGb,6EAAuE;AAGvE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,CAAC,GAC9E,IAAA,8CAAoB,EAAyB,oBAAoB,CAAC,CAAC;AAE5D,gDAAkB;AAAE,sDAAqB;AAAE,sEAA6B"}
@@ -1,2 +1,39 @@
1
- import { ApiClient } from "@trigger.dev/core/v3";
2
- export declare function useApiClient(): ApiClient;
1
+ import { ApiClient, ApiRequestOptions } from "@trigger.dev/core/v3";
2
+ /**
3
+ * Configuration options for creating an API client instance.
4
+ */
5
+ export type UseApiClientOptions = {
6
+ /** Optional access token for authentication */
7
+ accessToken?: string;
8
+ /** Optional base URL for the API endpoints */
9
+ baseURL?: string;
10
+ /** Optional additional request configuration */
11
+ requestOptions?: ApiRequestOptions;
12
+ /**
13
+ * Enable or disable the API client instance.
14
+ *
15
+ * Set enabled to false if you don't have an accessToken and don't want to throw an error.
16
+ */
17
+ enabled?: boolean;
18
+ };
19
+ /**
20
+ * Hook to create an API client instance using authentication context or provided options.
21
+ *
22
+ * @param {UseApiClientOptions} [options] - Configuration options for the API client
23
+ * @returns {ApiClient} An initialized API client instance
24
+ * @throws {Error} When no access token is available in either context or options
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * // Using context authentication
29
+ * const apiClient = useApiClient();
30
+ *
31
+ * // Using custom options
32
+ * const apiClient = useApiClient({
33
+ * accessToken: "your-access-token",
34
+ * baseURL: "https://api.my-trigger.com",
35
+ * requestOptions: { retry: { maxAttempts: 10 } }
36
+ * });
37
+ * ```
38
+ */
39
+ export declare function useApiClient(options?: UseApiClientOptions): ApiClient | undefined;
@@ -4,12 +4,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.useApiClient = useApiClient;
5
5
  const v3_1 = require("@trigger.dev/core/v3");
6
6
  const contexts_js_1 = require("../contexts.js");
7
- function useApiClient() {
8
- const auth = (0, contexts_js_1.useTriggerAuthContext)();
9
- const baseUrl = auth.baseURL ?? "https://api.trigger.dev";
10
- if (!auth.accessToken) {
11
- throw new Error("Missing accessToken in TriggerAuthContext");
7
+ /**
8
+ * Hook to create an API client instance using authentication context or provided options.
9
+ *
10
+ * @param {UseApiClientOptions} [options] - Configuration options for the API client
11
+ * @returns {ApiClient} An initialized API client instance
12
+ * @throws {Error} When no access token is available in either context or options
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Using context authentication
17
+ * const apiClient = useApiClient();
18
+ *
19
+ * // Using custom options
20
+ * const apiClient = useApiClient({
21
+ * accessToken: "your-access-token",
22
+ * baseURL: "https://api.my-trigger.com",
23
+ * requestOptions: { retry: { maxAttempts: 10 } }
24
+ * });
25
+ * ```
26
+ */
27
+ function useApiClient(options) {
28
+ const auth = (0, contexts_js_1.useTriggerAuthContextOptional)();
29
+ const baseUrl = options?.baseURL ?? auth?.baseURL ?? "https://api.trigger.dev";
30
+ const accessToken = options?.accessToken ?? auth?.accessToken;
31
+ if (!accessToken) {
32
+ if (options?.enabled === false) {
33
+ return undefined;
34
+ }
35
+ throw new Error("Missing accessToken in TriggerAuthContext or useApiClient options");
12
36
  }
13
- return new v3_1.ApiClient(baseUrl, auth.accessToken, auth.requestOptions);
37
+ const requestOptions = {
38
+ ...auth?.requestOptions,
39
+ ...options?.requestOptions,
40
+ };
41
+ return new v3_1.ApiClient(baseUrl, accessToken, requestOptions);
14
42
  }
15
43
  //# sourceMappingURL=useApiClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useApiClient.js","sourceRoot":"","sources":["../../../src/hooks/useApiClient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAKb,oCAUC;AAbD,6CAAiD;AACjD,gDAAuD;AAEvD,SAAgB,YAAY;IAC1B,MAAM,IAAI,GAAG,IAAA,mCAAqB,GAAE,CAAC;IAErC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,yBAAyB,CAAC;IAE1D,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,IAAI,cAAS,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;AACvE,CAAC"}
1
+ {"version":3,"file":"useApiClient.js","sourceRoot":"","sources":["../../../src/hooks/useApiClient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AA4Cb,oCAoBC;AA9DD,6CAAoE;AACpE,gDAA+D;AAqB/D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,YAAY,CAAC,OAA6B;IACxD,MAAM,IAAI,GAAG,IAAA,2CAA6B,GAAE,CAAC;IAE7C,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,OAAO,IAAI,yBAAyB,CAAC;IAC/E,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,IAAI,EAAE,WAAW,CAAC;IAE9D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,OAAO,EAAE,OAAO,KAAK,KAAK,EAAE,CAAC;YAC/B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,cAAc,GAAsB;QACxC,GAAG,IAAI,EAAE,cAAc;QACvB,GAAG,OAAO,EAAE,cAAc;KAC3B,CAAC;IAEF,OAAO,IAAI,cAAS,CAAC,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,100 @@
1
+ import { AnyTask, RealtimeRun } from "@trigger.dev/core/v3";
2
+ import { UseApiClientOptions } from "./useApiClient.js";
3
+ export type UseRealtimeRunOptions = UseApiClientOptions & {
4
+ id?: string;
5
+ enabled?: boolean;
6
+ experimental_throttleInMs?: number;
7
+ };
8
+ export type UseRealtimeRunInstance<TTask extends AnyTask = AnyTask> = {
9
+ run: RealtimeRun<TTask> | undefined;
10
+ error: Error | undefined;
11
+ /**
12
+ * Abort the current request immediately.
13
+ */
14
+ stop: () => void;
15
+ };
16
+ /**
17
+ * Hook to subscribe to realtime updates of a task run.
18
+ *
19
+ * @template TTask - The type of the task
20
+ * @param {string} [runId] - The unique identifier of the run to subscribe to
21
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
22
+ * @returns {UseRealtimeRunInstance<TTask>} An object containing the current state of the run, error handling, and control methods
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import type { myTask } from './path/to/task';
27
+ * const { run, error } = useRealtimeRun<typeof myTask>('run-id-123');
28
+ * ```
29
+ */
30
+ export declare function useRealtimeRun<TTask extends AnyTask>(runId?: string, options?: UseRealtimeRunOptions): UseRealtimeRunInstance<TTask>;
31
+ export type StreamResults<TStreams extends Record<string, any>> = {
32
+ [K in keyof TStreams]: Array<TStreams[K]>;
33
+ };
34
+ export type UseRealtimeRunWithStreamsInstance<TTask extends AnyTask = AnyTask, TStreams extends Record<string, any> = Record<string, any>> = {
35
+ run: RealtimeRun<TTask> | undefined;
36
+ streams: StreamResults<TStreams>;
37
+ error: Error | undefined;
38
+ /**
39
+ * Abort the current request immediately, keep the generated tokens if any.
40
+ */
41
+ stop: () => void;
42
+ };
43
+ /**
44
+ * Hook to subscribe to realtime updates of a task run with associated data streams.
45
+ *
46
+ * @template TTask - The type of the task
47
+ * @template TStreams - The type of the streams data
48
+ * @param {string} [runId] - The unique identifier of the run to subscribe to
49
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
50
+ * @returns {UseRealtimeRunWithStreamsInstance<TTask, TStreams>} An object containing the current state of the run, streams data, and error handling
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import type { myTask } from './path/to/task';
55
+ * const { run, streams, error } = useRealtimeRunWithStreams<typeof myTask, {
56
+ * output: string;
57
+ * }>('run-id-123');
58
+ * ```
59
+ */
60
+ export declare function useRealtimeRunWithStreams<TTask extends AnyTask = AnyTask, TStreams extends Record<string, any> = Record<string, any>>(runId?: string, options?: UseRealtimeRunOptions): UseRealtimeRunWithStreamsInstance<TTask, TStreams>;
61
+ export type UseRealtimeRunsInstance<TTask extends AnyTask = AnyTask> = {
62
+ runs: RealtimeRun<TTask>[];
63
+ error: Error | undefined;
64
+ /**
65
+ * Abort the current request immediately.
66
+ */
67
+ stop: () => void;
68
+ };
69
+ /**
70
+ * Hook to subscribe to realtime updates of task runs filtered by tag(s).
71
+ *
72
+ * @template TTask - The type of the task
73
+ * @param {string | string[]} tag - The tag or array of tags to filter runs by
74
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
75
+ * @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs and any error encountered
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import type { myTask } from './path/to/task';
80
+ * const { runs, error } = useRealtimeRunsWithTag<typeof myTask>('my-tag');
81
+ * // Or with multiple tags
82
+ * const { runs, error } = useRealtimeRunsWithTag<typeof myTask>(['tag1', 'tag2']);
83
+ * ```
84
+ */
85
+ export declare function useRealtimeRunsWithTag<TTask extends AnyTask>(tag: string | string[], options?: UseRealtimeRunOptions): UseRealtimeRunsInstance<TTask>;
86
+ /**
87
+ * Hook to subscribe to realtime updates of a batch of task runs.
88
+ *
89
+ * @template TTask - The type of the task
90
+ * @param {string} batchId - The unique identifier of the batch to subscribe to
91
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
92
+ * @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs, error handling, and control methods
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import type { myTask } from './path/to/task';
97
+ * const { runs, error } = useRealtimeBatch<typeof myTask>('batch-id-123');
98
+ * ```
99
+ */
100
+ export declare function useRealtimeBatch<TTask extends AnyTask>(batchId: string, options?: UseRealtimeRunOptions): UseRealtimeRunsInstance<TTask>;
@@ -0,0 +1,393 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useRealtimeRun = useRealtimeRun;
5
+ exports.useRealtimeRunWithStreams = useRealtimeRunWithStreams;
6
+ exports.useRealtimeRunsWithTag = useRealtimeRunsWithTag;
7
+ exports.useRealtimeBatch = useRealtimeBatch;
8
+ const react_1 = require("react");
9
+ const trigger_swr_js_1 = require("../utils/trigger-swr.js");
10
+ const useApiClient_js_1 = require("./useApiClient.js");
11
+ const throttle_js_1 = require("../utils/throttle.js");
12
+ /**
13
+ * Hook to subscribe to realtime updates of a task run.
14
+ *
15
+ * @template TTask - The type of the task
16
+ * @param {string} [runId] - The unique identifier of the run to subscribe to
17
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
18
+ * @returns {UseRealtimeRunInstance<TTask>} An object containing the current state of the run, error handling, and control methods
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import type { myTask } from './path/to/task';
23
+ * const { run, error } = useRealtimeRun<typeof myTask>('run-id-123');
24
+ * ```
25
+ */
26
+ function useRealtimeRun(runId, options) {
27
+ const hookId = (0, react_1.useId)();
28
+ const idKey = options?.id ?? hookId;
29
+ // Store the streams state in SWR, using the idKey as the key to share states.
30
+ const { data: run, mutate: mutateRun } = (0, trigger_swr_js_1.useSWR)([idKey, "run"], null);
31
+ // Keep the latest streams in a ref.
32
+ const runRef = (0, react_1.useRef)();
33
+ (0, react_1.useEffect)(() => {
34
+ runRef.current = run;
35
+ }, [run]);
36
+ const { data: error = undefined, mutate: setError } = (0, trigger_swr_js_1.useSWR)([idKey, "error"], null);
37
+ // Abort controller to cancel the current API call.
38
+ const abortControllerRef = (0, react_1.useRef)(null);
39
+ const stop = (0, react_1.useCallback)(() => {
40
+ if (abortControllerRef.current) {
41
+ abortControllerRef.current.abort();
42
+ abortControllerRef.current = null;
43
+ }
44
+ }, []);
45
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
46
+ const triggerRequest = (0, react_1.useCallback)(async () => {
47
+ try {
48
+ if (!runId || !apiClient) {
49
+ return;
50
+ }
51
+ const abortController = new AbortController();
52
+ abortControllerRef.current = abortController;
53
+ await processRealtimeRun(runId, apiClient, mutateRun, abortControllerRef);
54
+ }
55
+ catch (err) {
56
+ // Ignore abort errors as they are expected.
57
+ if (err.name === "AbortError") {
58
+ abortControllerRef.current = null;
59
+ return;
60
+ }
61
+ setError(err);
62
+ }
63
+ finally {
64
+ if (abortControllerRef.current) {
65
+ abortControllerRef.current = null;
66
+ }
67
+ }
68
+ }, [runId, mutateRun, abortControllerRef, apiClient, setError]);
69
+ (0, react_1.useEffect)(() => {
70
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
71
+ return;
72
+ }
73
+ if (!runId) {
74
+ return;
75
+ }
76
+ triggerRequest().finally(() => { });
77
+ return () => {
78
+ stop();
79
+ };
80
+ }, [runId, stop, options?.enabled]);
81
+ return { run, error, stop };
82
+ }
83
+ /**
84
+ * Hook to subscribe to realtime updates of a task run with associated data streams.
85
+ *
86
+ * @template TTask - The type of the task
87
+ * @template TStreams - The type of the streams data
88
+ * @param {string} [runId] - The unique identifier of the run to subscribe to
89
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
90
+ * @returns {UseRealtimeRunWithStreamsInstance<TTask, TStreams>} An object containing the current state of the run, streams data, and error handling
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import type { myTask } from './path/to/task';
95
+ * const { run, streams, error } = useRealtimeRunWithStreams<typeof myTask, {
96
+ * output: string;
97
+ * }>('run-id-123');
98
+ * ```
99
+ */
100
+ function useRealtimeRunWithStreams(runId, options) {
101
+ const hookId = (0, react_1.useId)();
102
+ const idKey = options?.id ?? hookId;
103
+ const [initialStreamsFallback] = (0, react_1.useState)({});
104
+ // Store the streams state in SWR, using the idKey as the key to share states.
105
+ const { data: streams, mutate: mutateStreams } = (0, trigger_swr_js_1.useSWR)([idKey, "streams"], null, {
106
+ fallbackData: initialStreamsFallback,
107
+ });
108
+ // Keep the latest streams in a ref.
109
+ const streamsRef = (0, react_1.useRef)(streams ?? {});
110
+ (0, react_1.useEffect)(() => {
111
+ streamsRef.current = streams || {};
112
+ }, [streams]);
113
+ // Store the streams state in SWR, using the idKey as the key to share states.
114
+ const { data: run, mutate: mutateRun } = (0, trigger_swr_js_1.useSWR)([idKey, "run"], null);
115
+ // Keep the latest streams in a ref.
116
+ const runRef = (0, react_1.useRef)();
117
+ (0, react_1.useEffect)(() => {
118
+ runRef.current = run;
119
+ }, [run]);
120
+ const { data: error = undefined, mutate: setError } = (0, trigger_swr_js_1.useSWR)([idKey, "error"], null);
121
+ // Abort controller to cancel the current API call.
122
+ const abortControllerRef = (0, react_1.useRef)(null);
123
+ const stop = (0, react_1.useCallback)(() => {
124
+ if (abortControllerRef.current) {
125
+ abortControllerRef.current.abort();
126
+ abortControllerRef.current = null;
127
+ }
128
+ }, []);
129
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
130
+ const triggerRequest = (0, react_1.useCallback)(async () => {
131
+ try {
132
+ if (!runId || !apiClient) {
133
+ return;
134
+ }
135
+ const abortController = new AbortController();
136
+ abortControllerRef.current = abortController;
137
+ await processRealtimeRunWithStreams(runId, apiClient, mutateRun, mutateStreams, streamsRef, abortControllerRef, options?.experimental_throttleInMs);
138
+ }
139
+ catch (err) {
140
+ // Ignore abort errors as they are expected.
141
+ if (err.name === "AbortError") {
142
+ abortControllerRef.current = null;
143
+ return;
144
+ }
145
+ setError(err);
146
+ }
147
+ finally {
148
+ if (abortControllerRef.current) {
149
+ abortControllerRef.current = null;
150
+ }
151
+ }
152
+ }, [runId, mutateRun, mutateStreams, streamsRef, abortControllerRef, apiClient, setError]);
153
+ (0, react_1.useEffect)(() => {
154
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
155
+ return;
156
+ }
157
+ if (!runId) {
158
+ return;
159
+ }
160
+ triggerRequest().finally(() => { });
161
+ return () => {
162
+ stop();
163
+ };
164
+ }, [runId, stop, options?.enabled]);
165
+ return { run, streams: streams ?? initialStreamsFallback, error, stop };
166
+ }
167
+ /**
168
+ * Hook to subscribe to realtime updates of task runs filtered by tag(s).
169
+ *
170
+ * @template TTask - The type of the task
171
+ * @param {string | string[]} tag - The tag or array of tags to filter runs by
172
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
173
+ * @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs and any error encountered
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * import type { myTask } from './path/to/task';
178
+ * const { runs, error } = useRealtimeRunsWithTag<typeof myTask>('my-tag');
179
+ * // Or with multiple tags
180
+ * const { runs, error } = useRealtimeRunsWithTag<typeof myTask>(['tag1', 'tag2']);
181
+ * ```
182
+ */
183
+ function useRealtimeRunsWithTag(tag, options) {
184
+ const hookId = (0, react_1.useId)();
185
+ const idKey = options?.id ?? hookId;
186
+ // Store the streams state in SWR, using the idKey as the key to share states.
187
+ const { data: runs, mutate: mutateRuns } = (0, trigger_swr_js_1.useSWR)([idKey, "run"], null, {
188
+ fallbackData: [],
189
+ });
190
+ // Keep the latest streams in a ref.
191
+ const runsRef = (0, react_1.useRef)([]);
192
+ (0, react_1.useEffect)(() => {
193
+ runsRef.current = runs ?? [];
194
+ }, [runs]);
195
+ const { data: error = undefined, mutate: setError } = (0, trigger_swr_js_1.useSWR)([idKey, "error"], null);
196
+ // Abort controller to cancel the current API call.
197
+ const abortControllerRef = (0, react_1.useRef)(null);
198
+ const stop = (0, react_1.useCallback)(() => {
199
+ if (abortControllerRef.current) {
200
+ abortControllerRef.current.abort();
201
+ abortControllerRef.current = null;
202
+ }
203
+ }, []);
204
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
205
+ const triggerRequest = (0, react_1.useCallback)(async () => {
206
+ try {
207
+ if (!apiClient) {
208
+ return;
209
+ }
210
+ const abortController = new AbortController();
211
+ abortControllerRef.current = abortController;
212
+ await processRealtimeRunsWithTag(tag, apiClient, mutateRuns, runsRef, abortControllerRef);
213
+ }
214
+ catch (err) {
215
+ // Ignore abort errors as they are expected.
216
+ if (err.name === "AbortError") {
217
+ abortControllerRef.current = null;
218
+ return;
219
+ }
220
+ setError(err);
221
+ }
222
+ finally {
223
+ if (abortControllerRef.current) {
224
+ abortControllerRef.current = null;
225
+ }
226
+ }
227
+ }, [tag, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
228
+ (0, react_1.useEffect)(() => {
229
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
230
+ return;
231
+ }
232
+ triggerRequest().finally(() => { });
233
+ return () => {
234
+ stop();
235
+ };
236
+ }, [tag, stop, options?.enabled]);
237
+ return { runs: runs ?? [], error, stop };
238
+ }
239
+ /**
240
+ * Hook to subscribe to realtime updates of a batch of task runs.
241
+ *
242
+ * @template TTask - The type of the task
243
+ * @param {string} batchId - The unique identifier of the batch to subscribe to
244
+ * @param {UseRealtimeRunOptions} [options] - Configuration options for the subscription
245
+ * @returns {UseRealtimeRunsInstance<TTask>} An object containing the current state of the runs, error handling, and control methods
246
+ *
247
+ * @example
248
+ * ```ts
249
+ * import type { myTask } from './path/to/task';
250
+ * const { runs, error } = useRealtimeBatch<typeof myTask>('batch-id-123');
251
+ * ```
252
+ */
253
+ function useRealtimeBatch(batchId, options) {
254
+ const hookId = (0, react_1.useId)();
255
+ const idKey = options?.id ?? hookId;
256
+ // Store the streams state in SWR, using the idKey as the key to share states.
257
+ const { data: runs, mutate: mutateRuns } = (0, trigger_swr_js_1.useSWR)([idKey, "run"], null, {
258
+ fallbackData: [],
259
+ });
260
+ // Keep the latest streams in a ref.
261
+ const runsRef = (0, react_1.useRef)([]);
262
+ (0, react_1.useEffect)(() => {
263
+ runsRef.current = runs ?? [];
264
+ }, [runs]);
265
+ const { data: error = undefined, mutate: setError } = (0, trigger_swr_js_1.useSWR)([idKey, "error"], null);
266
+ // Abort controller to cancel the current API call.
267
+ const abortControllerRef = (0, react_1.useRef)(null);
268
+ const stop = (0, react_1.useCallback)(() => {
269
+ if (abortControllerRef.current) {
270
+ abortControllerRef.current.abort();
271
+ abortControllerRef.current = null;
272
+ }
273
+ }, []);
274
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
275
+ const triggerRequest = (0, react_1.useCallback)(async () => {
276
+ try {
277
+ if (!apiClient) {
278
+ return;
279
+ }
280
+ const abortController = new AbortController();
281
+ abortControllerRef.current = abortController;
282
+ await processRealtimeBatch(batchId, apiClient, mutateRuns, runsRef, abortControllerRef);
283
+ }
284
+ catch (err) {
285
+ // Ignore abort errors as they are expected.
286
+ if (err.name === "AbortError") {
287
+ abortControllerRef.current = null;
288
+ return;
289
+ }
290
+ setError(err);
291
+ }
292
+ finally {
293
+ if (abortControllerRef.current) {
294
+ abortControllerRef.current = null;
295
+ }
296
+ }
297
+ }, [batchId, mutateRuns, runsRef, abortControllerRef, apiClient, setError]);
298
+ (0, react_1.useEffect)(() => {
299
+ if (typeof options?.enabled === "boolean" && !options.enabled) {
300
+ return;
301
+ }
302
+ triggerRequest().finally(() => { });
303
+ return () => {
304
+ stop();
305
+ };
306
+ }, [batchId, stop, options?.enabled]);
307
+ return { runs: runs ?? [], error, stop };
308
+ }
309
+ async function processRealtimeBatch(batchId, apiClient, mutateRunsData, existingRunsRef, abortControllerRef) {
310
+ const subscription = apiClient.subscribeToBatch(batchId, {
311
+ signal: abortControllerRef.current?.signal,
312
+ });
313
+ for await (const part of subscription) {
314
+ mutateRunsData(insertRunShapeInOrder(existingRunsRef.current, part));
315
+ }
316
+ }
317
+ // Inserts and then orders by the run number, and ensures that the run is not duplicated
318
+ function insertRunShapeInOrder(previousRuns, run) {
319
+ const existingRun = previousRuns.find((r) => r.id === run.id);
320
+ if (existingRun) {
321
+ return previousRuns.map((r) => (r.id === run.id ? run : r));
322
+ }
323
+ const runNumber = run.number;
324
+ const index = previousRuns.findIndex((r) => r.number > runNumber);
325
+ if (index === -1) {
326
+ return [...previousRuns, run];
327
+ }
328
+ return [...previousRuns.slice(0, index), run, ...previousRuns.slice(index)];
329
+ }
330
+ async function processRealtimeRunsWithTag(tag, apiClient, mutateRunsData, existingRunsRef, abortControllerRef) {
331
+ const subscription = apiClient.subscribeToRunsWithTag(tag, {
332
+ signal: abortControllerRef.current?.signal,
333
+ });
334
+ for await (const part of subscription) {
335
+ mutateRunsData(insertRunShape(existingRunsRef.current, part));
336
+ }
337
+ }
338
+ // Replaces or inserts a run shape, ordered by the createdAt timestamp
339
+ function insertRunShape(previousRuns, run) {
340
+ const existingRun = previousRuns.find((r) => r.id === run.id);
341
+ if (existingRun) {
342
+ return previousRuns.map((r) => (r.id === run.id ? run : r));
343
+ }
344
+ const createdAt = run.createdAt;
345
+ const index = previousRuns.findIndex((r) => r.createdAt > createdAt);
346
+ if (index === -1) {
347
+ return [...previousRuns, run];
348
+ }
349
+ return [...previousRuns.slice(0, index), run, ...previousRuns.slice(index)];
350
+ }
351
+ async function processRealtimeRunWithStreams(runId, apiClient, mutateRunData, mutateStreamData, existingDataRef, abortControllerRef, throttleInMs) {
352
+ const subscription = apiClient.subscribeToRun(runId, {
353
+ signal: abortControllerRef.current?.signal,
354
+ });
355
+ const streamQueue = (0, throttle_js_1.createThrottledQueue)(async (updates) => {
356
+ const nextStreamData = { ...existingDataRef.current };
357
+ // Group updates by type
358
+ const updatesByType = updates.reduce((acc, update) => {
359
+ if (!acc[update.type]) {
360
+ acc[update.type] = [];
361
+ }
362
+ acc[update.type].push(update.chunk);
363
+ return acc;
364
+ }, {});
365
+ // Apply all updates
366
+ for (const [type, chunks] of Object.entries(updatesByType)) {
367
+ // @ts-ignore
368
+ nextStreamData[type] = [...(existingDataRef.current[type] || []), ...chunks];
369
+ }
370
+ await mutateStreamData(nextStreamData);
371
+ }, throttleInMs);
372
+ for await (const part of subscription.withStreams()) {
373
+ if (part.type === "run") {
374
+ mutateRunData(part.run);
375
+ }
376
+ else {
377
+ streamQueue.add({
378
+ type: part.type,
379
+ // @ts-ignore
380
+ chunk: part.chunk,
381
+ });
382
+ }
383
+ }
384
+ }
385
+ async function processRealtimeRun(runId, apiClient, mutateRunData, abortControllerRef) {
386
+ const subscription = apiClient.subscribeToRun(runId, {
387
+ signal: abortControllerRef.current?.signal,
388
+ });
389
+ for await (const part of subscription) {
390
+ mutateRunData(part);
391
+ }
392
+ }
393
+ //# sourceMappingURL=useRealtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRealtime.js","sourceRoot":"","sources":["../../../src/hooks/useRealtime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;AAwCb,wCA2EC;AAuCD,8DAuGC;AA6BD,wDAyEC;AAiBD,4CAyEC;AA9bD,iCAAwE;AACxE,4DAA+D;AAC/D,uDAAsE;AACtE,sDAA4D;AAmB5D;;;;;;;;;;;;;GAaG;AAEH,SAAgB,cAAc,CAC5B,KAAc,EACd,OAA+B;IAE/B,MAAM,MAAM,GAAG,IAAA,aAAK,GAAE,CAAC;IACvB,MAAM,KAAK,GAAG,OAAO,EAAE,EAAE,IAAI,MAAM,CAAC;IAEpC,8EAA8E;IAC9E,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,uBAAM,EAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;IAE1F,oCAAoC;IACpC,MAAM,MAAM,GAAG,IAAA,cAAM,GAAkC,CAAC;IACxD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC;IACvB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,uBAAM,EAC1D,CAAC,KAAK,EAAE,OAAO,CAAC,EAChB,IAAI,CACL,CAAC;IAEF,mDAAmD;IACnD,MAAM,kBAAkB,GAAG,IAAA,cAAM,EAAyB,IAAI,CAAC,CAAC;IAEhE,MAAM,IAAI,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC5B,IAAI,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAC/B,kBAAkB,CAAC,OAAO,CA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aAAa,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
@@ -18,8 +18,13 @@ const useApiClient_js_1 = require("./useApiClient.js");
18
18
  * @returns {boolean} isError - Indicates if an error occurred during the retrieval of the run data.
19
19
  */
20
20
  function useRun(runId, options) {
21
- const apiClient = (0, useApiClient_js_1.useApiClient)();
22
- const { data: run, error, isLoading, isValidating, } = (0, trigger_swr_js_1.useSWR)(runId, () => apiClient.retrieveRun(runId), {
21
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
22
+ const { data: run, error, isLoading, isValidating, } = (0, trigger_swr_js_1.useSWR)(runId, () => {
23
+ if (!apiClient) {
24
+ throw new Error("Could not call useRun: Missing access token");
25
+ }
26
+ return apiClient.retrieveRun(runId);
27
+ }, {
23
28
  revalidateOnReconnect: options?.revalidateOnReconnect,
24
29
  refreshInterval: (run) => {
25
30
  if (!run)