@@ -19,15 +19,41 @@ import {
1919 UseRealtimeRunWithStreamsInstance ,
2020} from "./useRealtime.js" ;
2121
22+ /**
23+ * Base interface for task trigger instances.
24+ *
25+ * @template TTask - The type of the task
26+ */
2227export interface TriggerInstance < TTask extends AnyTask > {
28+ /** Function to submit the task with a payload */
2329 submit : ( payload : TaskPayload < TTask > ) => void ;
30+ /** Whether the task is currently being submitted */
2431 isLoading : boolean ;
32+ /** The handle returned after successful task submission */
2533 handle ?: RunHandleFromTypes < InferRunTypes < TTask > > ;
34+ /** Any error that occurred during submission */
2635 error ?: Error ;
2736}
2837
2938export type UseTaskTriggerOptions = UseApiClientOptions ;
3039
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+ */
3157export function useTaskTrigger < TTask extends AnyTask > (
3258 id : TaskIdentifier < TTask > ,
3359 options ?: UseTaskTriggerOptions
@@ -74,8 +100,13 @@ export function useTaskTrigger<TTask extends AnyTask>(
74100 } ;
75101}
76102
103+ /**
104+ * Configuration options for task triggers with realtime updates.
105+ */
77106export type UseRealtimeTaskTriggerOptions = UseTaskTriggerOptions & {
107+ /** Whether the realtime subscription is enabled */
78108 enabled ?: boolean ;
109+ /** Optional throttle time in milliseconds for stream updates */
79110 experimental_throttleInMs ?: number ;
80111} ;
81112
@@ -88,6 +119,28 @@ export type RealtimeTriggerInstanceWithStreams<
88119 handle ?: RunHandleFromTypes < InferRunTypes < TTask > > ;
89120} ;
90121
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+ */
91144export function useRealtimeTaskTriggerWithStreams <
92145 TTask extends AnyTask ,
93146 TStreams extends Record < string , any > = Record < string , any > ,
@@ -114,6 +167,28 @@ export type RealtimeTriggerInstance<TTask extends AnyTask> = UseRealtimeRunInsta
114167 handle ?: RunHandleFromTypes < InferRunTypes < TTask > > ;
115168} ;
116169
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+
117192export function useRealtimeTaskTrigger < TTask extends AnyTask > (
118193 id : TaskIdentifier < TTask > ,
119194 options ?: UseRealtimeTaskTriggerOptions
0 commit comments