@@ -19,15 +19,41 @@ import {
19
19
UseRealtimeRunWithStreamsInstance ,
20
20
} from "./useRealtime.js" ;
21
21
22
+ /**
23
+ * Base interface for task trigger instances.
24
+ *
25
+ * @template TTask - The type of the task
26
+ */
22
27
export interface TriggerInstance < TTask extends AnyTask > {
28
+ /** Function to submit the task with a payload */
23
29
submit : ( payload : TaskPayload < TTask > ) => void ;
30
+ /** Whether the task is currently being submitted */
24
31
isLoading : boolean ;
32
+ /** The handle returned after successful task submission */
25
33
handle ?: RunHandleFromTypes < InferRunTypes < TTask > > ;
34
+ /** Any error that occurred during submission */
26
35
error ?: Error ;
27
36
}
28
37
29
38
export type UseTaskTriggerOptions = UseApiClientOptions ;
30
39
40
+ /**
41
+ * Hook to trigger a task and manage its initial execution state.
42
+ *
43
+ * @template TTask - The type of the task
44
+ * @param {TaskIdentifier<TTask> } id - The identifier of the task to trigger
45
+ * @param {UseTaskTriggerOptions } [options] - Configuration options for the task trigger
46
+ * @returns {TriggerInstance<TTask> } An object containing the submit function, loading state, handle, and any errors
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import type { myTask } from './path/to/task';
51
+ * const { submit, isLoading, handle, error } = useTaskTrigger<typeof myTask>('my-task-id');
52
+ *
53
+ * // Submit the task with payload
54
+ * submit({ foo: 'bar' });
55
+ * ```
56
+ */
31
57
export function useTaskTrigger < TTask extends AnyTask > (
32
58
id : TaskIdentifier < TTask > ,
33
59
options ?: UseTaskTriggerOptions
@@ -74,8 +100,13 @@ export function useTaskTrigger<TTask extends AnyTask>(
74
100
} ;
75
101
}
76
102
103
+ /**
104
+ * Configuration options for task triggers with realtime updates.
105
+ */
77
106
export type UseRealtimeTaskTriggerOptions = UseTaskTriggerOptions & {
107
+ /** Whether the realtime subscription is enabled */
78
108
enabled ?: boolean ;
109
+ /** Optional throttle time in milliseconds for stream updates */
79
110
experimental_throttleInMs ?: number ;
80
111
} ;
81
112
@@ -88,6 +119,28 @@ export type RealtimeTriggerInstanceWithStreams<
88
119
handle ?: RunHandleFromTypes < InferRunTypes < TTask > > ;
89
120
} ;
90
121
122
+ /**
123
+ * Hook to trigger a task and subscribe to its realtime updates including stream data.
124
+ *
125
+ * @template TTask - The type of the task
126
+ * @template TStreams - The type of the streams data
127
+ * @param {TaskIdentifier<TTask> } id - The identifier of the task to trigger
128
+ * @param {UseRealtimeTaskTriggerOptions } [options] - Configuration options for the task trigger and realtime updates
129
+ * @returns {RealtimeTriggerInstanceWithStreams<TTask, TStreams> } An object containing the submit function, loading state,
130
+ * handle, run state, streams data, and error handling
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import type { myTask } from './path/to/task';
135
+ * const { submit, run, streams, error } = useRealtimeTaskTriggerWithStreams<
136
+ * typeof myTask,
137
+ * { output: string }
138
+ * >('my-task-id');
139
+ *
140
+ * // Submit and monitor the task with streams
141
+ * submit({ foo: 'bar' });
142
+ * ```
143
+ */
91
144
export function useRealtimeTaskTriggerWithStreams <
92
145
TTask extends AnyTask ,
93
146
TStreams extends Record < string , any > = Record < string , any > ,
@@ -114,6 +167,28 @@ export type RealtimeTriggerInstance<TTask extends AnyTask> = UseRealtimeRunInsta
114
167
handle ?: RunHandleFromTypes < InferRunTypes < TTask > > ;
115
168
} ;
116
169
170
+ /**
171
+ * Hook to trigger a task and subscribe to its realtime updates.
172
+ *
173
+ * @template TTask - The type of the task
174
+ * @param {TaskIdentifier<TTask> } id - The identifier of the task to trigger
175
+ * @param {UseRealtimeTaskTriggerOptions } [options] - Configuration options for the task trigger and realtime updates
176
+ * @returns {RealtimeTriggerInstance<TTask> } An object containing the submit function, loading state,
177
+ * handle, run state, and error handling
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * import type { myTask } from './path/to/task';
182
+ * const { submit, run, error, stop } = useRealtimeTaskTrigger<typeof myTask>('my-task-id');
183
+ *
184
+ * // Submit and monitor the task
185
+ * submit({ foo: 'bar' });
186
+ *
187
+ * // Stop monitoring when needed
188
+ * stop();
189
+ * ```
190
+ */
191
+
117
192
export function useRealtimeTaskTrigger < TTask extends AnyTask > (
118
193
id : TaskIdentifier < TTask > ,
119
194
options ?: UseRealtimeTaskTriggerOptions
0 commit comments