@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.
Files changed (71) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1 -0
  3. package/dist/commonjs/contexts.d.ts +4 -0
  4. package/dist/commonjs/contexts.js +10 -0
  5. package/dist/commonjs/contexts.js.map +1 -0
  6. package/dist/commonjs/hooks/useApiClient.d.ts +41 -0
  7. package/dist/commonjs/hooks/useApiClient.js +44 -0
  8. package/dist/commonjs/hooks/useApiClient.js.map +1 -0
  9. package/dist/commonjs/hooks/useInputStreamSend.d.ts +26 -0
  10. package/dist/commonjs/hooks/useInputStreamSend.js +45 -0
  11. package/dist/commonjs/hooks/useInputStreamSend.js.map +1 -0
  12. package/dist/commonjs/hooks/useRealtime.d.ts +294 -0
  13. package/dist/commonjs/hooks/useRealtime.js +549 -0
  14. package/dist/commonjs/hooks/useRealtime.js.map +1 -0
  15. package/dist/commonjs/hooks/useRun.d.ts +22 -0
  16. package/dist/commonjs/hooks/useRun.js +40 -0
  17. package/dist/commonjs/hooks/useRun.js.map +1 -0
  18. package/dist/commonjs/hooks/useTaskTrigger.d.ts +107 -0
  19. package/dist/commonjs/hooks/useTaskTrigger.js +138 -0
  20. package/dist/commonjs/hooks/useTaskTrigger.js.map +1 -0
  21. package/dist/commonjs/hooks/useWaitToken.d.ts +35 -0
  22. package/dist/commonjs/hooks/useWaitToken.js +52 -0
  23. package/dist/commonjs/hooks/useWaitToken.js.map +1 -0
  24. package/dist/commonjs/index.d.ts +7 -0
  25. package/dist/commonjs/index.js +24 -0
  26. package/dist/commonjs/index.js.map +1 -0
  27. package/dist/commonjs/package.json +3 -0
  28. package/dist/commonjs/utils/createContextAndHook.d.ts +15 -0
  29. package/dist/commonjs/utils/createContextAndHook.js +39 -0
  30. package/dist/commonjs/utils/createContextAndHook.js.map +1 -0
  31. package/dist/commonjs/utils/throttle.d.ts +6 -0
  32. package/dist/commonjs/utils/throttle.js +50 -0
  33. package/dist/commonjs/utils/throttle.js.map +1 -0
  34. package/dist/commonjs/utils/trigger-swr.d.ts +19 -0
  35. package/dist/commonjs/utils/trigger-swr.js +28 -0
  36. package/dist/commonjs/utils/trigger-swr.js.map +1 -0
  37. package/dist/esm/contexts.d.ts +4 -0
  38. package/dist/esm/contexts.js +5 -0
  39. package/dist/esm/contexts.js.map +1 -0
  40. package/dist/esm/hooks/useApiClient.d.ts +41 -0
  41. package/dist/esm/hooks/useApiClient.js +41 -0
  42. package/dist/esm/hooks/useApiClient.js.map +1 -0
  43. package/dist/esm/hooks/useInputStreamSend.d.ts +26 -0
  44. package/dist/esm/hooks/useInputStreamSend.js +39 -0
  45. package/dist/esm/hooks/useInputStreamSend.js.map +1 -0
  46. package/dist/esm/hooks/useRealtime.d.ts +294 -0
  47. package/dist/esm/hooks/useRealtime.js +542 -0
  48. package/dist/esm/hooks/useRealtime.js.map +1 -0
  49. package/dist/esm/hooks/useRun.d.ts +22 -0
  50. package/dist/esm/hooks/useRun.js +37 -0
  51. package/dist/esm/hooks/useRun.js.map +1 -0
  52. package/dist/esm/hooks/useTaskTrigger.d.ts +107 -0
  53. package/dist/esm/hooks/useTaskTrigger.js +130 -0
  54. package/dist/esm/hooks/useTaskTrigger.js.map +1 -0
  55. package/dist/esm/hooks/useWaitToken.d.ts +35 -0
  56. package/dist/esm/hooks/useWaitToken.js +46 -0
  57. package/dist/esm/hooks/useWaitToken.js.map +1 -0
  58. package/dist/esm/index.d.ts +7 -0
  59. package/dist/esm/index.js +8 -0
  60. package/dist/esm/index.js.map +1 -0
  61. package/dist/esm/package.json +3 -0
  62. package/dist/esm/utils/createContextAndHook.d.ts +15 -0
  63. package/dist/esm/utils/createContextAndHook.js +31 -0
  64. package/dist/esm/utils/createContextAndHook.js.map +1 -0
  65. package/dist/esm/utils/throttle.d.ts +6 -0
  66. package/dist/esm/utils/throttle.js +47 -0
  67. package/dist/esm/utils/throttle.js.map +1 -0
  68. package/dist/esm/utils/trigger-swr.d.ts +19 -0
  69. package/dist/esm/utils/trigger-swr.js +6 -0
  70. package/dist/esm/utils/trigger-swr.js.map +1 -0
  71. package/package.json +75 -0
@@ -0,0 +1,107 @@
1
+ import { type AnyTask, type TaskIdentifier, type TaskPayload, InferRunTypes, RunHandleFromTypes, type TriggerOptions, type RealtimeRunSkipColumns } from "@trigger.dev/core/v3";
2
+ import { UseApiClientOptions } from "./useApiClient.js";
3
+ import { UseRealtimeRunInstance, UseRealtimeRunWithStreamsInstance } from "./useRealtime.js";
4
+ /**
5
+ * Base interface for task trigger instances.
6
+ *
7
+ * @template TTask - The type of the task
8
+ */
9
+ export interface TriggerInstance<TTask extends AnyTask> {
10
+ /** Function to submit the task with a payload */
11
+ submit: (payload: TaskPayload<TTask>, options?: TriggerOptions) => void;
12
+ /** Whether the task is currently being submitted */
13
+ isLoading: boolean;
14
+ /** The handle returned after successful task submission */
15
+ handle?: RunHandleFromTypes<InferRunTypes<TTask>>;
16
+ /** Any error that occurred during submission */
17
+ error?: Error;
18
+ }
19
+ export type UseTaskTriggerOptions = UseApiClientOptions;
20
+ /**
21
+ * Hook to trigger a task and manage its initial execution state.
22
+ *
23
+ * @template TTask - The type of the task
24
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
25
+ * @param {UseTaskTriggerOptions} [options] - Configuration options for the task trigger
26
+ * @returns {TriggerInstance<TTask>} An object containing the submit function, loading state, handle, and any errors
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import type { myTask } from './path/to/task';
31
+ * const { submit, isLoading, handle, error } = useTaskTrigger<typeof myTask>('my-task-id');
32
+ *
33
+ * // Submit the task with payload
34
+ * submit({ foo: 'bar' });
35
+ * ```
36
+ */
37
+ export declare function useTaskTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, options?: UseTaskTriggerOptions): TriggerInstance<TTask>;
38
+ /**
39
+ * Configuration options for task triggers with realtime updates.
40
+ */
41
+ export type UseRealtimeTaskTriggerOptions = UseTaskTriggerOptions & {
42
+ /** Whether the realtime subscription is enabled */
43
+ enabled?: boolean;
44
+ /** Optional throttle time in milliseconds for stream updates */
45
+ experimental_throttleInMs?: number;
46
+ /**
47
+ * Skip columns from the subscription.
48
+ *
49
+ * @default []
50
+ */
51
+ skipColumns?: RealtimeRunSkipColumns;
52
+ };
53
+ export type RealtimeTriggerInstanceWithStreams<TTask extends AnyTask, TStreams extends Record<string, any> = Record<string, any>> = UseRealtimeRunWithStreamsInstance<TTask, TStreams> & {
54
+ submit: (payload: TaskPayload<TTask>, options?: TriggerOptions) => void;
55
+ isLoading: boolean;
56
+ handle?: RunHandleFromTypes<InferRunTypes<TTask>>;
57
+ };
58
+ /**
59
+ * Hook to trigger a task and subscribe to its realtime updates including stream data.
60
+ *
61
+ * @template TTask - The type of the task
62
+ * @template TStreams - The type of the streams data
63
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
64
+ * @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
65
+ * @returns {RealtimeTriggerInstanceWithStreams<TTask, TStreams>} An object containing the submit function, loading state,
66
+ * handle, run state, streams data, and error handling
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import type { myTask } from './path/to/task';
71
+ * const { submit, run, streams, error } = useRealtimeTaskTriggerWithStreams<
72
+ * typeof myTask,
73
+ * { output: string }
74
+ * >('my-task-id');
75
+ *
76
+ * // Submit and monitor the task with streams
77
+ * submit({ foo: 'bar' });
78
+ * ```
79
+ */
80
+ export declare function useRealtimeTaskTriggerWithStreams<TTask extends AnyTask, TStreams extends Record<string, any> = Record<string, any>>(id: TaskIdentifier<TTask>, options?: UseRealtimeTaskTriggerOptions): RealtimeTriggerInstanceWithStreams<TTask, TStreams>;
81
+ export type RealtimeTriggerInstance<TTask extends AnyTask> = UseRealtimeRunInstance<TTask> & {
82
+ submit: (payload: TaskPayload<TTask>, options?: TriggerOptions) => void;
83
+ isLoading: boolean;
84
+ handle?: RunHandleFromTypes<InferRunTypes<TTask>>;
85
+ };
86
+ /**
87
+ * Hook to trigger a task and subscribe to its realtime updates.
88
+ *
89
+ * @template TTask - The type of the task
90
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
91
+ * @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
92
+ * @returns {RealtimeTriggerInstance<TTask>} An object containing the submit function, loading state,
93
+ * handle, run state, and error handling
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import type { myTask } from './path/to/task';
98
+ * const { submit, run, error, stop } = useRealtimeTaskTrigger<typeof myTask>('my-task-id');
99
+ *
100
+ * // Submit and monitor the task
101
+ * submit({ foo: 'bar' });
102
+ *
103
+ * // Stop monitoring when needed
104
+ * stop();
105
+ * ```
106
+ */
107
+ export declare function useRealtimeTaskTrigger<TTask extends AnyTask>(id: TaskIdentifier<TTask>, options?: UseRealtimeTaskTriggerOptions): RealtimeTriggerInstance<TTask>;
@@ -0,0 +1,138 @@
1
+ "use client";
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.useTaskTrigger = useTaskTrigger;
8
+ exports.useRealtimeTaskTriggerWithStreams = useRealtimeTaskTriggerWithStreams;
9
+ exports.useRealtimeTaskTrigger = useRealtimeTaskTrigger;
10
+ const v3_1 = require("@trigger.dev/core/v3");
11
+ const mutation_1 = __importDefault(require("swr/mutation"));
12
+ const useApiClient_js_1 = require("./useApiClient.js");
13
+ const useRealtime_js_1 = require("./useRealtime.js");
14
+ /**
15
+ * Hook to trigger a task and manage its initial execution state.
16
+ *
17
+ * @template TTask - The type of the task
18
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
19
+ * @param {UseTaskTriggerOptions} [options] - Configuration options for the task trigger
20
+ * @returns {TriggerInstance<TTask>} An object containing the submit function, loading state, handle, and any errors
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import type { myTask } from './path/to/task';
25
+ * const { submit, isLoading, handle, error } = useTaskTrigger<typeof myTask>('my-task-id');
26
+ *
27
+ * // Submit the task with payload
28
+ * submit({ foo: 'bar' });
29
+ * ```
30
+ */
31
+ function useTaskTrigger(id, options) {
32
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
33
+ async function triggerTask(id, { arg: { payload, options }, }) {
34
+ if (!apiClient) {
35
+ throw new Error("Could not trigger task in useTaskTrigger: Missing access token");
36
+ }
37
+ const payloadPacket = await (0, v3_1.stringifyIO)(payload);
38
+ const handle = await apiClient.triggerTask(id, {
39
+ payload: payloadPacket.data,
40
+ options: {
41
+ queue: options?.queue ? { name: options.queue } : undefined,
42
+ concurrencyKey: options?.concurrencyKey,
43
+ payloadType: payloadPacket.dataType,
44
+ idempotencyKey: await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey),
45
+ delay: options?.delay,
46
+ ttl: options?.ttl,
47
+ tags: options?.tags,
48
+ maxAttempts: options?.maxAttempts,
49
+ metadata: options?.metadata,
50
+ maxDuration: options?.maxDuration,
51
+ lockToVersion: options?.version,
52
+ },
53
+ });
54
+ return { ...handle, taskIdentifier: id };
55
+ }
56
+ const mutation = (0, mutation_1.default)(id, triggerTask);
57
+ return {
58
+ submit: (payload, options) => {
59
+ // trigger the task with the given payload
60
+ mutation.trigger({ payload, options });
61
+ },
62
+ isLoading: mutation.isMutating,
63
+ handle: mutation.data,
64
+ error: mutation.error,
65
+ };
66
+ }
67
+ /**
68
+ * Hook to trigger a task and subscribe to its realtime updates including stream data.
69
+ *
70
+ * @template TTask - The type of the task
71
+ * @template TStreams - The type of the streams data
72
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
73
+ * @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
74
+ * @returns {RealtimeTriggerInstanceWithStreams<TTask, TStreams>} An object containing the submit function, loading state,
75
+ * handle, run state, streams data, and error handling
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import type { myTask } from './path/to/task';
80
+ * const { submit, run, streams, error } = useRealtimeTaskTriggerWithStreams<
81
+ * typeof myTask,
82
+ * { output: string }
83
+ * >('my-task-id');
84
+ *
85
+ * // Submit and monitor the task with streams
86
+ * submit({ foo: 'bar' });
87
+ * ```
88
+ */
89
+ function useRealtimeTaskTriggerWithStreams(id, options) {
90
+ const triggerInstance = useTaskTrigger(id, options);
91
+ const realtimeInstance = (0, useRealtime_js_1.useRealtimeRunWithStreams)(triggerInstance.handle?.id, {
92
+ ...options,
93
+ id: triggerInstance.handle?.id,
94
+ accessToken: triggerInstance.handle?.publicAccessToken ?? options?.accessToken,
95
+ });
96
+ return {
97
+ ...realtimeInstance,
98
+ ...triggerInstance,
99
+ };
100
+ }
101
+ /**
102
+ * Hook to trigger a task and subscribe to its realtime updates.
103
+ *
104
+ * @template TTask - The type of the task
105
+ * @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
106
+ * @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
107
+ * @returns {RealtimeTriggerInstance<TTask>} An object containing the submit function, loading state,
108
+ * handle, run state, and error handling
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import type { myTask } from './path/to/task';
113
+ * const { submit, run, error, stop } = useRealtimeTaskTrigger<typeof myTask>('my-task-id');
114
+ *
115
+ * // Submit and monitor the task
116
+ * submit({ foo: 'bar' });
117
+ *
118
+ * // Stop monitoring when needed
119
+ * stop();
120
+ * ```
121
+ */
122
+ function useRealtimeTaskTrigger(id, options) {
123
+ const triggerInstance = useTaskTrigger(id, options);
124
+ const realtimeInstance = (0, useRealtime_js_1.useRealtimeRun)(triggerInstance.handle?.id, {
125
+ ...options,
126
+ id: triggerInstance.handle?.id,
127
+ accessToken: triggerInstance.handle?.publicAccessToken ?? options?.accessToken,
128
+ });
129
+ return {
130
+ submit: triggerInstance.submit,
131
+ isLoading: triggerInstance.isLoading,
132
+ handle: triggerInstance.handle,
133
+ run: realtimeInstance.run,
134
+ error: realtimeInstance.error ?? triggerInstance.error,
135
+ stop: realtimeInstance.stop,
136
+ };
137
+ }
138
+ //# sourceMappingURL=useTaskTrigger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTaskTrigger.js","sourceRoot":"","sources":["../../../src/hooks/useTaskTrigger.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,35 @@
1
+ import { UseApiClientOptions } from "./useApiClient.js";
2
+ /**
3
+ * Base interface for task trigger instances.
4
+ *
5
+ * @template TOutput - The type of the output
6
+ */
7
+ export interface WaitTokenInstance<TOutput> {
8
+ /** Function to complete the waitpoint with an output */
9
+ complete: (output: TOutput) => void;
10
+ /** Whether the waitpoint is currently being completed */
11
+ isLoading: boolean;
12
+ /** Whether the waitpoint has been completed */
13
+ isCompleted: boolean;
14
+ /** Any error that occurred during completion */
15
+ error?: Error;
16
+ /** Whether the waitpoint is ready to be completed */
17
+ isReady: boolean;
18
+ }
19
+ /**
20
+ * Hook to complete a waitpoint and manage its completion state.
21
+ *
22
+ * @template TOutput - The type of the output
23
+ * @param {string} waitpointId - The identifier of the waitpoint to complete
24
+ * @returns {WaitTokenInstance<TOutput>} An object containing the complete function, loading state, isCompleted, and any errors
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import type { myTask } from './path/to/task';
29
+ * const { complete, isLoading, isCompleted, error } = useWaitToken('waitpoint-id');
30
+ *
31
+ * // Complete the waitpoint with an output
32
+ * complete({ foo: 'bar' });
33
+ * ```
34
+ */
35
+ export declare function useWaitToken<TOutput>(waitpointId?: string, options?: UseApiClientOptions): WaitTokenInstance<TOutput>;
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.useWaitToken = useWaitToken;
8
+ const mutation_1 = __importDefault(require("swr/mutation"));
9
+ const useApiClient_js_1 = require("./useApiClient.js");
10
+ /**
11
+ * Hook to complete a waitpoint and manage its completion state.
12
+ *
13
+ * @template TOutput - The type of the output
14
+ * @param {string} waitpointId - The identifier of the waitpoint to complete
15
+ * @returns {WaitTokenInstance<TOutput>} An object containing the complete function, loading state, isCompleted, and any errors
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import type { myTask } from './path/to/task';
20
+ * const { complete, isLoading, isCompleted, error } = useWaitToken('waitpoint-id');
21
+ *
22
+ * // Complete the waitpoint with an output
23
+ * complete({ foo: 'bar' });
24
+ * ```
25
+ */
26
+ function useWaitToken(waitpointId, options) {
27
+ const apiClient = (0, useApiClient_js_1.useApiClient)(options);
28
+ async function completeWaitpoint(id, { arg: { output } }) {
29
+ if (!apiClient) {
30
+ throw new Error("Could not complete waitpoint in useWaitToken: Missing access token");
31
+ }
32
+ if (!waitpointId) {
33
+ throw new Error("Could not complete waitpoint in useWaitToken: Missing waitpoint ID");
34
+ }
35
+ const result = await apiClient.completeWaitpointToken(waitpointId, {
36
+ data: output,
37
+ });
38
+ return result;
39
+ }
40
+ const mutation = (0, mutation_1.default)(waitpointId, completeWaitpoint);
41
+ return {
42
+ complete: (output) => {
43
+ // trigger the task with the given payload
44
+ mutation.trigger({ output });
45
+ },
46
+ isLoading: mutation.isMutating,
47
+ isCompleted: !!mutation.data?.success,
48
+ isReady: !!waitpointId,
49
+ error: mutation.error,
50
+ };
51
+ }
52
+ //# sourceMappingURL=useWaitToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWaitToken.js","sourceRoot":"","sources":["../../../src/hooks/useWaitToken.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAuCb,oCAkCC;AAvED,4DAA0C;AAC1C,uDAAsE;AAoBtE;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,YAAY,CAC1B,WAAoB,EACpB,OAA6B;IAE7B,MAAM,SAAS,GAAG,IAAA,8BAAY,EAAC,OAAO,CAAC,CAAC;IAExC,KAAK,UAAU,iBAAiB,CAAC,EAAU,EAAE,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAgC;QAC5F,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;QACxF,CAAC;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;QACxF,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,sBAAsB,CAAC,WAAW,EAAE;YACjE,IAAI,EAAE,MAAM;SACb,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,kBAAc,EAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;IAEhE,OAAO;QACL,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE;YACnB,0CAA0C;YAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,SAAS,EAAE,QAAQ,CAAC,UAAU;QAC9B,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO;QACrC,OAAO,EAAE,CAAC,CAAC,WAAW;QACtB,KAAK,EAAE,QAAQ,CAAC,KAAK;KACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./contexts.js";
2
+ export * from "./hooks/useApiClient.js";
3
+ export * from "./hooks/useRun.js";
4
+ export * from "./hooks/useRealtime.js";
5
+ export * from "./hooks/useTaskTrigger.js";
6
+ export * from "./hooks/useWaitToken.js";
7
+ export * from "./hooks/useInputStreamSend.js";
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./contexts.js"), exports);
18
+ __exportStar(require("./hooks/useApiClient.js"), exports);
19
+ __exportStar(require("./hooks/useRun.js"), exports);
20
+ __exportStar(require("./hooks/useRealtime.js"), exports);
21
+ __exportStar(require("./hooks/useTaskTrigger.js"), exports);
22
+ __exportStar(require("./hooks/useWaitToken.js"), exports);
23
+ __exportStar(require("./hooks/useInputStreamSend.js"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ export declare function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal;
3
+ type Options = {
4
+ assertCtxFn?: (v: unknown, msg: string) => void;
5
+ };
6
+ type ContextOf<T> = React.Context<T | undefined>;
7
+ type UseCtxFn<T> = () => T;
8
+ /**
9
+ * Creates and returns a Context and two hooks that return the context value.
10
+ * The Context type is derived from the type passed in by the user.
11
+ * The first hook returned guarantees that the context exists so the returned value is always CtxValue
12
+ * The second hook makes no guarantees, so the returned value can be CtxValue | undefined
13
+ */
14
+ export declare const createContextAndHook: <CtxVal>(displayName: string, options?: Options) => [ContextOf<CtxVal>, UseCtxFn<CtxVal>, UseCtxFn<CtxVal | Partial<CtxVal>>];
15
+ export {};
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.createContextAndHook = void 0;
8
+ exports.assertContextExists = assertContextExists;
9
+ const react_1 = __importDefault(require("react"));
10
+ function assertContextExists(contextVal, msgOrCtx) {
11
+ if (!contextVal) {
12
+ throw typeof msgOrCtx === "string"
13
+ ? new Error(msgOrCtx)
14
+ : new Error(`${msgOrCtx.displayName} not found`);
15
+ }
16
+ }
17
+ /**
18
+ * Creates and returns a Context and two hooks that return the context value.
19
+ * The Context type is derived from the type passed in by the user.
20
+ * The first hook returned guarantees that the context exists so the returned value is always CtxValue
21
+ * The second hook makes no guarantees, so the returned value can be CtxValue | undefined
22
+ */
23
+ const createContextAndHook = (displayName, options) => {
24
+ const { assertCtxFn = assertContextExists } = options || {};
25
+ const Ctx = react_1.default.createContext(undefined);
26
+ Ctx.displayName = displayName;
27
+ const useCtx = () => {
28
+ const ctx = react_1.default.useContext(Ctx);
29
+ assertCtxFn(ctx, `${displayName} not found`);
30
+ return ctx;
31
+ };
32
+ const useCtxWithoutGuarantee = () => {
33
+ const ctx = react_1.default.useContext(Ctx);
34
+ return ctx ? ctx : {};
35
+ };
36
+ return [Ctx, useCtx, useCtxWithoutGuarantee];
37
+ };
38
+ exports.createContextAndHook = createContextAndHook;
39
+ //# sourceMappingURL=createContextAndHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createContextAndHook.js","sourceRoot":"","sources":["../../../src/utils/createContextAndHook.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;AAGb,kDASC;AAXD,kDAA0B;AAE1B,SAAgB,mBAAmB,CACjC,UAAmB,EACnB,QAAqC;IAErC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,OAAO,QAAQ,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC;YACrB,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,YAAY,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAMD;;;;;GAKG;AACI,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,OAAiB,EAC0D,EAAE;IAC7E,MAAM,EAAE,WAAW,GAAG,mBAAmB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC5D,MAAM,GAAG,GAAG,eAAK,CAAC,aAAa,CAAqB,SAAS,CAAC,CAAC;IAC/D,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;IAE9B,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,MAAM,GAAG,GAAG,eAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClC,WAAW,CAAC,GAAG,EAAE,GAAG,WAAW,YAAY,CAAC,CAAC;QAC7C,OAAO,GAAa,CAAC;IACvB,CAAC,CAAC;IAEF,MAAM,sBAAsB,GAAG,GAAG,EAAE;QAClC,MAAM,GAAG,GAAG,eAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,CAAC,CAAC;IAEF,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAC/C,CAAC,CAAC;AApBW,QAAA,oBAAoB,wBAoB/B"}
@@ -0,0 +1,6 @@
1
+ export type ThrottledQueue<T> = {
2
+ add: (item: T) => void;
3
+ flush: () => Promise<void>;
4
+ isEmpty: () => boolean;
5
+ };
6
+ export declare function createThrottledQueue<T>(onFlush: (items: T[]) => Promise<void>, throttleInMs?: number): ThrottledQueue<T>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createThrottledQueue = createThrottledQueue;
4
+ function createThrottledQueue(onFlush, throttleInMs) {
5
+ let queue = [];
6
+ let lastFlushTime = 0;
7
+ let flushPromise = null;
8
+ const scheduleFlush = async () => {
9
+ // If no throttle specified or there's already a flush in progress, return
10
+ if (!throttleInMs) {
11
+ // Immediately flush when no throttling is specified
12
+ const itemsToFlush = [...queue];
13
+ queue = [];
14
+ await onFlush(itemsToFlush);
15
+ return;
16
+ }
17
+ if (queue.length === 0 || flushPromise)
18
+ return;
19
+ const now = Date.now();
20
+ const timeUntilNextFlush = Math.max(0, lastFlushTime + throttleInMs - now);
21
+ if (timeUntilNextFlush === 0) {
22
+ const itemsToFlush = [...queue];
23
+ queue = [];
24
+ lastFlushTime = now;
25
+ flushPromise = onFlush(itemsToFlush).finally(() => {
26
+ flushPromise = null;
27
+ // Check if more items accumulated during flush
28
+ scheduleFlush();
29
+ });
30
+ }
31
+ else {
32
+ setTimeout(scheduleFlush, timeUntilNextFlush);
33
+ }
34
+ };
35
+ return {
36
+ add: (item) => {
37
+ queue.push(item);
38
+ scheduleFlush();
39
+ },
40
+ flush: async () => {
41
+ if (queue.length === 0)
42
+ return;
43
+ const itemsToFlush = [...queue];
44
+ queue = [];
45
+ await onFlush(itemsToFlush);
46
+ },
47
+ isEmpty: () => queue.length === 0,
48
+ };
49
+ }
50
+ //# sourceMappingURL=throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../../src/utils/throttle.ts"],"names":[],"mappings":";;AAOA,oDAkDC;AAlDD,SAAgB,oBAAoB,CAClC,OAAsC,EACtC,YAAqB;IAErB,IAAI,KAAK,GAAQ,EAAE,CAAC;IACpB,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,YAAY,GAAyB,IAAI,CAAC;IAE9C,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;QAC/B,0EAA0E;QAC1E,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,oDAAoD;YACpD,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAChC,KAAK,GAAG,EAAE,CAAC;YACX,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY;YAAE,OAAO;QAE/C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,GAAG,CAAC,CAAC;QAE3E,IAAI,kBAAkB,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAChC,KAAK,GAAG,EAAE,CAAC;YACX,aAAa,GAAG,GAAG,CAAC;YACpB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;gBAChD,YAAY,GAAG,IAAI,CAAC;gBACpB,+CAA+C;gBAC/C,aAAa,EAAE,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,EAAE,CAAC,IAAO,EAAE,EAAE;YACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,aAAa,EAAE,CAAC;QAClB,CAAC;QACD,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO;YAC/B,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAChC,KAAK,GAAG,EAAE,CAAC;YACX,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;KAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { ApiRequestOptions } from "@trigger.dev/core/v3";
2
+ export * from "swr";
3
+ export { default as useSWR, SWRConfig } from "swr";
4
+ export type CommonTriggerHookOptions = {
5
+ /**
6
+ * Poll for updates at the specified interval (in milliseconds). Polling is not recommended for most use-cases. Use the Realtime hooks instead.
7
+ */
8
+ refreshInterval?: number;
9
+ /** Revalidate the data when the browser regains a network connection. */
10
+ revalidateOnReconnect?: boolean;
11
+ /** Revalidate the data when the window regains focus. */
12
+ revalidateOnFocus?: boolean;
13
+ /** Optional access token for authentication */
14
+ accessToken?: string;
15
+ /** Optional base URL for the API endpoints */
16
+ baseURL?: string;
17
+ /** Optional additional request configuration */
18
+ requestOptions?: ApiRequestOptions;
19
+ };
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.SWRConfig = exports.useSWR = void 0;
22
+ // eslint-disable-next-line import/export
23
+ __exportStar(require("swr"), exports);
24
+ // eslint-disable-next-line import/export
25
+ var swr_1 = require("swr");
26
+ Object.defineProperty(exports, "useSWR", { enumerable: true, get: function () { return __importDefault(swr_1).default; } });
27
+ Object.defineProperty(exports, "SWRConfig", { enumerable: true, get: function () { return swr_1.SWRConfig; } });
28
+ //# sourceMappingURL=trigger-swr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trigger-swr.js","sourceRoot":"","sources":["../../../src/utils/trigger-swr.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;AAIb,yCAAyC;AACzC,sCAAoB;AACpB,yCAAyC;AACzC,2BAAmD;AAA1C,8GAAA,OAAO,OAAU;AAAE,gGAAA,SAAS,OAAA"}
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
3
+ declare const TriggerAuthContext: React.Context<ApiClientConfiguration | undefined>, useTriggerAuthContext: () => ApiClientConfiguration, useTriggerAuthContextOptional: () => ApiClientConfiguration | Partial<ApiClientConfiguration>;
4
+ export { TriggerAuthContext, useTriggerAuthContext, useTriggerAuthContextOptional };
@@ -0,0 +1,5 @@
1
+ "use client";
2
+ import { createContextAndHook } from "./utils/createContextAndHook.js";
3
+ const [TriggerAuthContext, useTriggerAuthContext, useTriggerAuthContextOptional] = createContextAndHook("TriggerAuthContext");
4
+ export { TriggerAuthContext, useTriggerAuthContext, useTriggerAuthContextOptional };
5
+ //# sourceMappingURL=contexts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contexts.js","sourceRoot":"","sources":["../../src/contexts.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,CAAC,GAC9E,oBAAoB,CAAyB,oBAAoB,CAAC,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,CAAC"}
@@ -0,0 +1,41 @@
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 preview branch name for preview environments */
11
+ previewBranch?: string;
12
+ /** Optional additional request configuration */
13
+ requestOptions?: ApiRequestOptions;
14
+ /**
15
+ * Enable or disable the API client instance.
16
+ *
17
+ * Set enabled to false if you don't have an accessToken and don't want to throw an error.
18
+ */
19
+ enabled?: boolean;
20
+ };
21
+ /**
22
+ * Hook to create an API client instance using authentication context or provided options.
23
+ *
24
+ * @param {UseApiClientOptions} [options] - Configuration options for the API client
25
+ * @returns {ApiClient} An initialized API client instance
26
+ * @throws {Error} When no access token is available in either context or options
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * // Using context authentication
31
+ * const apiClient = useApiClient();
32
+ *
33
+ * // Using custom options
34
+ * const apiClient = useApiClient({
35
+ * accessToken: "your-access-token",
36
+ * baseURL: "https://api.my-trigger.com",
37
+ * requestOptions: { retry: { maxAttempts: 10 } }
38
+ * });
39
+ * ```
40
+ */
41
+ export declare function useApiClient(options?: UseApiClientOptions): ApiClient | undefined;