@tanstack/ai-react 0.6.3 → 0.6.4

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.
@@ -1,3 +1,15 @@
1
1
  export { useChat } from './use-chat.js';
2
2
  export type { UseChatOptions, UseChatReturn, UIMessage, ChatRequestBody, } from './types.js';
3
- export { fetchServerSentEvents, fetchHttpStream, stream, createChatClientOptions, type ConnectionAdapter, type FetchConnectionOptions, type InferChatMessages, } from '@tanstack/ai-client';
3
+ export { useGeneration } from './use-generation.js';
4
+ export type { UseGenerationOptions, UseGenerationReturn, } from './use-generation.js';
5
+ export { useGenerateImage } from './use-generate-image.js';
6
+ export type { UseGenerateImageOptions, UseGenerateImageReturn, } from './use-generate-image.js';
7
+ export { useGenerateSpeech } from './use-generate-speech.js';
8
+ export type { UseGenerateSpeechOptions, UseGenerateSpeechReturn, } from './use-generate-speech.js';
9
+ export { useTranscription } from './use-transcription.js';
10
+ export type { UseTranscriptionOptions, UseTranscriptionReturn, } from './use-transcription.js';
11
+ export { useSummarize } from './use-summarize.js';
12
+ export type { UseSummarizeOptions, UseSummarizeReturn } from './use-summarize.js';
13
+ export { useGenerateVideo } from './use-generate-video.js';
14
+ export type { UseGenerateVideoOptions, UseGenerateVideoReturn, } from './use-generate-video.js';
15
+ export { fetchServerSentEvents, fetchHttpStream, stream, createChatClientOptions, type ConnectionAdapter, type FetchConnectionOptions, type InferChatMessages, type GenerationClientState, type ImageGenerateInput, type SpeechGenerateInput, type TranscriptionGenerateInput, type SummarizeGenerateInput, type VideoGenerateInput, type VideoGenerateResult, type VideoStatusInfo, } from '@tanstack/ai-client';
package/dist/esm/index.js CHANGED
@@ -1,10 +1,22 @@
1
1
  import { useChat } from "./use-chat.js";
2
+ import { useGeneration } from "./use-generation.js";
3
+ import { useGenerateImage } from "./use-generate-image.js";
4
+ import { useGenerateSpeech } from "./use-generate-speech.js";
5
+ import { useTranscription } from "./use-transcription.js";
6
+ import { useSummarize } from "./use-summarize.js";
7
+ import { useGenerateVideo } from "./use-generate-video.js";
2
8
  import { createChatClientOptions, fetchHttpStream, fetchServerSentEvents, stream } from "@tanstack/ai-client";
3
9
  export {
4
10
  createChatClientOptions,
5
11
  fetchHttpStream,
6
12
  fetchServerSentEvents,
7
13
  stream,
8
- useChat
14
+ useChat,
15
+ useGenerateImage,
16
+ useGenerateSpeech,
17
+ useGenerateVideo,
18
+ useGeneration,
19
+ useSummarize,
20
+ useTranscription
9
21
  };
10
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,87 @@
1
+ import { ImageGenerationResult, StreamChunk } from '@tanstack/ai';
2
+ import { ConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput, InferGenerationOutput } from '@tanstack/ai-client';
3
+ /**
4
+ * Options for the useGenerateImage hook.
5
+ *
6
+ * @template TOutput - The output type after optional transform (defaults to ImageGenerationResult)
7
+ */
8
+ export interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {
9
+ /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectionAdapter;
11
+ /** Direct async function for image generation */
12
+ fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>;
13
+ /** Unique identifier for this generation instance */
14
+ id?: string;
15
+ /** Additional body parameters to send with ConnectionAdapter requests */
16
+ body?: Record<string, any>;
17
+ /**
18
+ * Callback when images are generated. Can optionally return a transformed value.
19
+ *
20
+ * - Return a non-null value to transform and store it as the result
21
+ * - Return `null` to keep the previous result unchanged
22
+ * - Return nothing (`void`) to store the raw result as-is
23
+ */
24
+ onResult?: (result: ImageGenerationResult) => TOutput | null | void;
25
+ /** Callback when an error occurs */
26
+ onError?: (error: Error) => void;
27
+ /** Callback when progress is reported (0-100) */
28
+ onProgress?: (progress: number, message?: string) => void;
29
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
30
+ onChunk?: (chunk: StreamChunk) => void;
31
+ }
32
+ /**
33
+ * Return type for the useGenerateImage hook.
34
+ *
35
+ * @template TOutput - The output type (after optional transform)
36
+ */
37
+ export interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {
38
+ /** Trigger image generation */
39
+ generate: (input: ImageGenerateInput) => Promise<void>;
40
+ /** The generation result containing images, or null */
41
+ result: TOutput | null;
42
+ /** Whether generation is in progress */
43
+ isLoading: boolean;
44
+ /** Current error, if any */
45
+ error: Error | undefined;
46
+ /** Current state of the generation */
47
+ status: GenerationClientState;
48
+ /** Abort the current generation */
49
+ stop: () => void;
50
+ /** Clear result, error, and return to idle */
51
+ reset: () => void;
52
+ }
53
+ /**
54
+ * React hook for generating images using AI models.
55
+ *
56
+ * Supports two transport modes:
57
+ * - **ConnectionAdapter** — Streaming transport (SSE, HTTP stream, custom)
58
+ * - **Fetcher** — Direct async function call
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * import { useGenerateImage } from '@tanstack/ai-react'
63
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
64
+ *
65
+ * function ImageGenerator() {
66
+ * const { generate, result, isLoading, error, reset } = useGenerateImage({
67
+ * connection: fetchServerSentEvents('/api/generate/image'),
68
+ * })
69
+ *
70
+ * return (
71
+ * <div>
72
+ * <button onClick={() => generate({ prompt: 'A sunset over mountains' })}>
73
+ * Generate
74
+ * </button>
75
+ * {isLoading && <p>Generating...</p>}
76
+ * {error && <p>Error: {error.message}</p>}
77
+ * {result?.images.map((img, i) => (
78
+ * <img key={i} src={img.url || `data:image/png;base64,${img.b64Json}`} />
79
+ * ))}
80
+ * </div>
81
+ * )
82
+ * }
83
+ * ```
84
+ */
85
+ export declare function useGenerateImage<TOnResult extends ((result: ImageGenerationResult) => any) | undefined = undefined>(options: Omit<UseGenerateImageOptions, 'onResult'> & {
86
+ onResult?: TOnResult;
87
+ }): UseGenerateImageReturn<InferGenerationOutput<ImageGenerationResult, TOnResult>>;
@@ -0,0 +1,17 @@
1
+ import { useGeneration } from "./use-generation.js";
2
+ function useGenerateImage(options) {
3
+ const { generate, result, isLoading, error, status, stop, reset } = useGeneration(options);
4
+ return {
5
+ generate,
6
+ result,
7
+ isLoading,
8
+ error,
9
+ status,
10
+ stop,
11
+ reset
12
+ };
13
+ }
14
+ export {
15
+ useGenerateImage
16
+ };
17
+ //# sourceMappingURL=use-generate-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-generate-image.js","sources":["../../src/use-generate-image.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { ImageGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n ImageGenerateInput,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\n\n/**\n * Options for the useGenerateImage hook.\n *\n * @template TOutput - The output type after optional transform (defaults to ImageGenerationResult)\n */\nexport interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for image generation */\n fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\n /**\n * Callback when images are generated. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: ImageGenerationResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateImage hook.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {\n /** Trigger image generation */\n generate: (input: ImageGenerateInput) => Promise<void>\n /** The generation result containing images, or null */\n result: TOutput | null\n /** Whether generation is in progress */\n isLoading: boolean\n /** Current error, if any */\n error: Error | undefined\n /** Current state of the generation */\n status: GenerationClientState\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * React hook for generating images using AI models.\n *\n * Supports two transport modes:\n * - **ConnectionAdapter** — Streaming transport (SSE, HTTP stream, custom)\n * - **Fetcher** — Direct async function call\n *\n * @example\n * ```tsx\n * import { useGenerateImage } from '@tanstack/ai-react'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function ImageGenerator() {\n * const { generate, result, isLoading, error, reset } = useGenerateImage({\n * connection: fetchServerSentEvents('/api/generate/image'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({ prompt: 'A sunset over mountains' })}>\n * Generate\n * </button>\n * {isLoading && <p>Generating...</p>}\n * {error && <p>Error: {error.message}</p>}\n * {result?.images.map((img, i) => (\n * <img key={i} src={img.url || `data:image/png;base64,${img.b64Json}`} />\n * ))}\n * </div>\n * )\n * }\n * ```\n */\nexport function useGenerateImage<\n TOnResult extends ((result: ImageGenerationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseGenerateImageOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseGenerateImageReturn<\n InferGenerationOutput<ImageGenerationResult, TOnResult>\n> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<ImageGenerateInput, ImageGenerationResult, TOnResult>(options)\n\n return {\n generate: generate as (input: ImageGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"names":[],"mappings":";AA8FO,SAAS,iBAId,SAKA;AACA,QAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,MAAA,IACxD,cAAoE,OAAO;AAE7E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,81 @@
1
+ import { StreamChunk, TTSResult } from '@tanstack/ai';
2
+ import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SpeechGenerateInput } from '@tanstack/ai-client';
3
+ /**
4
+ * Options for the useGenerateSpeech hook.
5
+ *
6
+ * @template TOutput - The output type after optional transform (defaults to TTSResult)
7
+ */
8
+ export interface UseGenerateSpeechOptions<TOutput = TTSResult> {
9
+ /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectionAdapter;
11
+ /** Direct async function for speech generation */
12
+ fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>;
13
+ /** Unique identifier for this generation instance */
14
+ id?: string;
15
+ /** Additional body parameters to send with ConnectionAdapter requests */
16
+ body?: Record<string, any>;
17
+ /**
18
+ * Callback when speech is generated. Can optionally return a transformed value.
19
+ *
20
+ * - Return a non-null value to transform and store it as the result
21
+ * - Return `null` to keep the previous result unchanged
22
+ * - Return nothing (`void`) to store the raw result as-is
23
+ */
24
+ onResult?: (result: TTSResult) => TOutput | null | void;
25
+ /** Callback when an error occurs */
26
+ onError?: (error: Error) => void;
27
+ /** Callback when progress is reported (0-100) */
28
+ onProgress?: (progress: number, message?: string) => void;
29
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
30
+ onChunk?: (chunk: StreamChunk) => void;
31
+ }
32
+ /**
33
+ * Return type for the useGenerateSpeech hook.
34
+ *
35
+ * @template TOutput - The output type (after optional transform)
36
+ */
37
+ export interface UseGenerateSpeechReturn<TOutput = TTSResult> {
38
+ /** Trigger speech generation */
39
+ generate: (input: SpeechGenerateInput) => Promise<void>;
40
+ /** The TTS result containing audio data, or null */
41
+ result: TOutput | null;
42
+ /** Whether generation is in progress */
43
+ isLoading: boolean;
44
+ /** Current error, if any */
45
+ error: Error | undefined;
46
+ /** Current state of the generation */
47
+ status: GenerationClientState;
48
+ /** Abort the current generation */
49
+ stop: () => void;
50
+ /** Clear result, error, and return to idle */
51
+ reset: () => void;
52
+ }
53
+ /**
54
+ * React hook for generating speech (text-to-speech) using AI models.
55
+ *
56
+ * @example
57
+ * ```tsx
58
+ * import { useGenerateSpeech } from '@tanstack/ai-react'
59
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
60
+ *
61
+ * function SpeechGenerator() {
62
+ * const { generate, result, isLoading } = useGenerateSpeech({
63
+ * connection: fetchServerSentEvents('/api/generate/speech'),
64
+ * })
65
+ *
66
+ * return (
67
+ * <div>
68
+ * <button onClick={() => generate({ text: 'Hello world', voice: 'alloy' })}>
69
+ * Generate Speech
70
+ * </button>
71
+ * {result && (
72
+ * <audio src={`data:audio/${result.format};base64,${result.audio}`} controls />
73
+ * )}
74
+ * </div>
75
+ * )
76
+ * }
77
+ * ```
78
+ */
79
+ export declare function useGenerateSpeech<TOnResult extends ((result: TTSResult) => any) | undefined = undefined>(options: Omit<UseGenerateSpeechOptions, 'onResult'> & {
80
+ onResult?: TOnResult;
81
+ }): UseGenerateSpeechReturn<InferGenerationOutput<TTSResult, TOnResult>>;
@@ -0,0 +1,17 @@
1
+ import { useGeneration } from "./use-generation.js";
2
+ function useGenerateSpeech(options) {
3
+ const { generate, result, isLoading, error, status, stop, reset } = useGeneration(options);
4
+ return {
5
+ generate,
6
+ result,
7
+ isLoading,
8
+ error,
9
+ status,
10
+ stop,
11
+ reset
12
+ };
13
+ }
14
+ export {
15
+ useGenerateSpeech
16
+ };
17
+ //# sourceMappingURL=use-generate-speech.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-generate-speech.js","sources":["../../src/use-generate-speech.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, TTSResult } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n SpeechGenerateInput,\n} from '@tanstack/ai-client'\n\n/**\n * Options for the useGenerateSpeech hook.\n *\n * @template TOutput - The output type after optional transform (defaults to TTSResult)\n */\nexport interface UseGenerateSpeechOptions<TOutput = TTSResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for speech generation */\n fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\n /**\n * Callback when speech is generated. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: TTSResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateSpeech hook.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface UseGenerateSpeechReturn<TOutput = TTSResult> {\n /** Trigger speech generation */\n generate: (input: SpeechGenerateInput) => Promise<void>\n /** The TTS result containing audio data, or null */\n result: TOutput | null\n /** Whether generation is in progress */\n isLoading: boolean\n /** Current error, if any */\n error: Error | undefined\n /** Current state of the generation */\n status: GenerationClientState\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * React hook for generating speech (text-to-speech) using AI models.\n *\n * @example\n * ```tsx\n * import { useGenerateSpeech } from '@tanstack/ai-react'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function SpeechGenerator() {\n * const { generate, result, isLoading } = useGenerateSpeech({\n * connection: fetchServerSentEvents('/api/generate/speech'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({ text: 'Hello world', voice: 'alloy' })}>\n * Generate Speech\n * </button>\n * {result && (\n * <audio src={`data:audio/${result.format};base64,${result.audio}`} controls />\n * )}\n * </div>\n * )\n * }\n * ```\n */\nexport function useGenerateSpeech<\n TOnResult extends ((result: TTSResult) => any) | undefined = undefined,\n>(\n options: Omit<UseGenerateSpeechOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseGenerateSpeechReturn<InferGenerationOutput<TTSResult, TOnResult>> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<SpeechGenerateInput, TTSResult, TOnResult>(options)\n\n return {\n generate: generate as (input: SpeechGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"names":[],"mappings":";AAwFO,SAAS,kBAGd,SAGsE;AACtE,QAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,MAAA,IACxD,cAAyD,OAAO;AAElE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,92 @@
1
+ import { StreamChunk } from '@tanstack/ai';
2
+ import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from '@tanstack/ai-client';
3
+ /**
4
+ * Options for the useGenerateVideo hook.
5
+ */
6
+ export interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {
7
+ /** Connection adapter for streaming transport (server handles polling) */
8
+ connection?: ConnectionAdapter;
9
+ /** Direct async function that returns a completed video result */
10
+ fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>;
11
+ /** Unique identifier for this generation instance */
12
+ id?: string;
13
+ /** Additional body parameters to send with ConnectionAdapter requests */
14
+ body?: Record<string, any>;
15
+ /**
16
+ * Callback when video generation completes. Can optionally return a transformed value.
17
+ *
18
+ * - Return a non-null value to transform and store it as the result
19
+ * - Return `null` to keep the previous result unchanged
20
+ * - Return nothing (`void`) to store the raw result as-is
21
+ */
22
+ onResult?: (result: VideoGenerateResult) => TOutput | null | void;
23
+ /** Callback when an error occurs */
24
+ onError?: (error: Error) => void;
25
+ /** Callback when progress is reported (0-100) */
26
+ onProgress?: (progress: number, message?: string) => void;
27
+ /** Callback when a video job is created */
28
+ onJobCreated?: (jobId: string) => void;
29
+ /** Callback on each status update */
30
+ onStatusUpdate?: (status: VideoStatusInfo) => void;
31
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
32
+ onChunk?: (chunk: StreamChunk) => void;
33
+ }
34
+ /**
35
+ * Return type for the useGenerateVideo hook.
36
+ *
37
+ * @template TOutput - The output type (after optional transform)
38
+ */
39
+ export interface UseGenerateVideoReturn<TOutput = VideoGenerateResult> {
40
+ /** Trigger video generation */
41
+ generate: (input: VideoGenerateInput) => Promise<void>;
42
+ /** The final video result (with URL), or null */
43
+ result: TOutput | null;
44
+ /** The current job ID, or null */
45
+ jobId: string | null;
46
+ /** Current video generation status info, or null */
47
+ videoStatus: VideoStatusInfo | null;
48
+ /** Whether generation/polling is in progress */
49
+ isLoading: boolean;
50
+ /** Current error, if any */
51
+ error: Error | undefined;
52
+ /** Current state of the generation */
53
+ status: GenerationClientState;
54
+ /** Abort the current generation/polling */
55
+ stop: () => void;
56
+ /** Clear all state and return to idle */
57
+ reset: () => void;
58
+ }
59
+ /**
60
+ * React hook for generating videos using AI models.
61
+ *
62
+ * Video generation is asynchronous: a job is created, then polled for status
63
+ * until completion. This hook handles the full lifecycle.
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * import { useGenerateVideo } from '@tanstack/ai-react'
68
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
69
+ *
70
+ * function VideoGenerator() {
71
+ * const { generate, result, videoStatus, isLoading } = useGenerateVideo({
72
+ * connection: fetchServerSentEvents('/api/generate/video'),
73
+ * onStatusUpdate: (status) => console.log(`Progress: ${status.progress}%`),
74
+ * })
75
+ *
76
+ * return (
77
+ * <div>
78
+ * <button onClick={() => generate({ prompt: 'A flying car over a city' })}>
79
+ * Generate Video
80
+ * </button>
81
+ * {isLoading && videoStatus && (
82
+ * <p>Status: {videoStatus.status} ({videoStatus.progress}%)</p>
83
+ * )}
84
+ * {result && <video src={result.url} controls />}
85
+ * </div>
86
+ * )
87
+ * }
88
+ * ```
89
+ */
90
+ export declare function useGenerateVideo<TOnResult extends ((result: VideoGenerateResult) => any) | undefined = undefined>(options: Omit<UseGenerateVideoOptions, 'onResult'> & {
91
+ onResult?: TOnResult;
92
+ }): UseGenerateVideoReturn<InferGenerationOutput<VideoGenerateResult, TOnResult>>;
@@ -0,0 +1,83 @@
1
+ import { VideoGenerationClient } from "@tanstack/ai-client";
2
+ import { useId, useState, useRef, useMemo, useEffect, useCallback } from "react";
3
+ function useGenerateVideo(options) {
4
+ const hookId = useId();
5
+ const clientId = options.id || hookId;
6
+ const [result, setResult] = useState(null);
7
+ const [jobId, setJobId] = useState(null);
8
+ const [videoStatus, setVideoStatus] = useState(null);
9
+ const [isLoading, setIsLoading] = useState(false);
10
+ const [error, setError] = useState(void 0);
11
+ const [status, setStatus] = useState("idle");
12
+ const optionsRef = useRef(options);
13
+ optionsRef.current = options;
14
+ const client = useMemo(() => {
15
+ const opts = optionsRef.current;
16
+ const baseOptions = {
17
+ id: clientId,
18
+ body: opts.body,
19
+ onResult: (r) => optionsRef.current.onResult?.(r),
20
+ onError: (e) => optionsRef.current.onError?.(e),
21
+ onProgress: (p, m) => optionsRef.current.onProgress?.(p, m),
22
+ onChunk: (c) => optionsRef.current.onChunk?.(c),
23
+ onJobCreated: (id) => optionsRef.current.onJobCreated?.(id),
24
+ onStatusUpdate: (s) => optionsRef.current.onStatusUpdate?.(s),
25
+ onResultChange: setResult,
26
+ onLoadingChange: setIsLoading,
27
+ onErrorChange: setError,
28
+ onStatusChange: setStatus,
29
+ onJobIdChange: setJobId,
30
+ onVideoStatusChange: setVideoStatus
31
+ };
32
+ if (opts.connection) {
33
+ return new VideoGenerationClient({
34
+ ...baseOptions,
35
+ connection: opts.connection
36
+ });
37
+ }
38
+ if (opts.fetcher) {
39
+ return new VideoGenerationClient({
40
+ ...baseOptions,
41
+ fetcher: opts.fetcher
42
+ });
43
+ }
44
+ throw new Error(
45
+ "useGenerateVideo requires either a connection or fetcher option"
46
+ );
47
+ }, [clientId]);
48
+ useEffect(() => {
49
+ client.updateOptions({ body: options.body });
50
+ }, [client, options.body]);
51
+ useEffect(() => {
52
+ return () => {
53
+ client.stop();
54
+ };
55
+ }, [client]);
56
+ const generate = useCallback(
57
+ async (input) => {
58
+ await client.generate(input);
59
+ },
60
+ [client]
61
+ );
62
+ const stop = useCallback(() => {
63
+ client.stop();
64
+ }, [client]);
65
+ const reset = useCallback(() => {
66
+ client.reset();
67
+ }, [client]);
68
+ return {
69
+ generate,
70
+ result,
71
+ jobId,
72
+ videoStatus,
73
+ isLoading,
74
+ error,
75
+ status,
76
+ stop,
77
+ reset
78
+ };
79
+ }
80
+ export {
81
+ useGenerateVideo
82
+ };
83
+ //# sourceMappingURL=use-generate-video.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-generate-video.js","sources":["../../src/use-generate-video.ts"],"sourcesContent":["import { VideoGenerationClient } from '@tanstack/ai-client'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n VideoGenerateInput,\n VideoGenerateResult,\n VideoStatusInfo,\n} from '@tanstack/ai-client'\n\n/**\n * Options for the useGenerateVideo hook.\n */\nexport interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {\n /** Connection adapter for streaming transport (server handles polling) */\n connection?: ConnectionAdapter\n /** Direct async function that returns a completed video result */\n fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\n /**\n * Callback when video generation completes. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: VideoGenerateResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback when a video job is created */\n onJobCreated?: (jobId: string) => void\n /** Callback on each status update */\n onStatusUpdate?: (status: VideoStatusInfo) => void\n /** Callback for each stream chunk (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateVideo hook.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface UseGenerateVideoReturn<TOutput = VideoGenerateResult> {\n /** Trigger video generation */\n generate: (input: VideoGenerateInput) => Promise<void>\n /** The final video result (with URL), or null */\n result: TOutput | null\n /** The current job ID, or null */\n jobId: string | null\n /** Current video generation status info, or null */\n videoStatus: VideoStatusInfo | null\n /** Whether generation/polling is in progress */\n isLoading: boolean\n /** Current error, if any */\n error: Error | undefined\n /** Current state of the generation */\n status: GenerationClientState\n /** Abort the current generation/polling */\n stop: () => void\n /** Clear all state and return to idle */\n reset: () => void\n}\n\n/**\n * React hook for generating videos using AI models.\n *\n * Video generation is asynchronous: a job is created, then polled for status\n * until completion. This hook handles the full lifecycle.\n *\n * @example\n * ```tsx\n * import { useGenerateVideo } from '@tanstack/ai-react'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function VideoGenerator() {\n * const { generate, result, videoStatus, isLoading } = useGenerateVideo({\n * connection: fetchServerSentEvents('/api/generate/video'),\n * onStatusUpdate: (status) => console.log(`Progress: ${status.progress}%`),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({ prompt: 'A flying car over a city' })}>\n * Generate Video\n * </button>\n * {isLoading && videoStatus && (\n * <p>Status: {videoStatus.status} ({videoStatus.progress}%)</p>\n * )}\n * {result && <video src={result.url} controls />}\n * </div>\n * )\n * }\n * ```\n */\nexport function useGenerateVideo<\n TOnResult extends ((result: VideoGenerateResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseGenerateVideoOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseGenerateVideoReturn<\n InferGenerationOutput<VideoGenerateResult, TOnResult>\n> {\n type TOutput = InferGenerationOutput<VideoGenerateResult, TOnResult>\n const hookId = useId()\n const clientId = options.id || hookId\n\n const [result, setResult] = useState<TOutput | null>(null)\n const [jobId, setJobId] = useState<string | null>(null)\n const [videoStatus, setVideoStatus] = useState<VideoStatusInfo | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<Error | undefined>(undefined)\n const [status, setStatus] = useState<GenerationClientState>('idle')\n\n const optionsRef = useRef(options)\n optionsRef.current = options\n\n const client = useMemo(() => {\n const opts = optionsRef.current\n\n const baseOptions = {\n id: clientId,\n body: opts.body,\n onResult: (r: VideoGenerateResult) => optionsRef.current.onResult?.(r),\n onError: (e: Error) => optionsRef.current.onError?.(e),\n onProgress: (p: number, m?: string) =>\n optionsRef.current.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => optionsRef.current.onChunk?.(c),\n onJobCreated: (id: string) => optionsRef.current.onJobCreated?.(id),\n onStatusUpdate: (s: VideoStatusInfo) =>\n optionsRef.current.onStatusUpdate?.(s),\n onResultChange: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n onJobIdChange: setJobId,\n onVideoStatusChange: setVideoStatus,\n }\n\n if (opts.connection) {\n return new VideoGenerationClient<TOutput>({\n ...baseOptions,\n connection: opts.connection,\n })\n }\n\n if (opts.fetcher) {\n return new VideoGenerationClient<TOutput>({\n ...baseOptions,\n fetcher: opts.fetcher,\n })\n }\n\n throw new Error(\n 'useGenerateVideo requires either a connection or fetcher option',\n )\n }, [clientId])\n\n // Sync body changes without recreating client\n useEffect(() => {\n client.updateOptions({ body: options.body })\n }, [client, options.body])\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n client.stop()\n }\n }, [client])\n\n const generate = useCallback(\n async (input: VideoGenerateInput) => {\n await client.generate(input)\n },\n [client],\n )\n\n const stop = useCallback(() => {\n client.stop()\n }, [client])\n\n const reset = useCallback(() => {\n client.reset()\n }, [client])\n\n return {\n generate,\n result,\n jobId,\n videoStatus,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"names":[],"mappings":";;AAsGO,SAAS,iBAId,SAKA;AAEA,QAAM,SAAS,MAAA;AACf,QAAM,WAAW,QAAQ,MAAM;AAE/B,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAyB,IAAI;AACzD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAiC,IAAI;AAC3E,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA4B,MAAS;AAC/D,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAgC,MAAM;AAElE,QAAM,aAAa,OAAO,OAAO;AACjC,aAAW,UAAU;AAErB,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAM,OAAO,WAAW;AAExB,UAAM,cAAc;AAAA,MAClB,IAAI;AAAA,MACJ,MAAM,KAAK;AAAA,MACX,UAAU,CAAC,MAA2B,WAAW,QAAQ,WAAW,CAAC;AAAA,MACrE,SAAS,CAAC,MAAa,WAAW,QAAQ,UAAU,CAAC;AAAA,MACrD,YAAY,CAAC,GAAW,MACtB,WAAW,QAAQ,aAAa,GAAG,CAAC;AAAA,MACtC,SAAS,CAAC,MAAmB,WAAW,QAAQ,UAAU,CAAC;AAAA,MAC3D,cAAc,CAAC,OAAe,WAAW,QAAQ,eAAe,EAAE;AAAA,MAClE,gBAAgB,CAAC,MACf,WAAW,QAAQ,iBAAiB,CAAC;AAAA,MACvC,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,eAAe;AAAA,MACf,gBAAgB;AAAA,MAChB,eAAe;AAAA,MACf,qBAAqB;AAAA,IAAA;AAGvB,QAAI,KAAK,YAAY;AACnB,aAAO,IAAI,sBAA+B;AAAA,QACxC,GAAG;AAAA,QACH,YAAY,KAAK;AAAA,MAAA,CAClB;AAAA,IACH;AAEA,QAAI,KAAK,SAAS;AAChB,aAAO,IAAI,sBAA+B;AAAA,QACxC,GAAG;AAAA,QACH,SAAS,KAAK;AAAA,MAAA,CACf;AAAA,IACH;AAEA,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ,GAAG,CAAC,QAAQ,CAAC;AAGb,YAAU,MAAM;AACd,WAAO,cAAc,EAAE,MAAM,QAAQ,MAAM;AAAA,EAC7C,GAAG,CAAC,QAAQ,QAAQ,IAAI,CAAC;AAGzB,YAAU,MAAM;AACd,WAAO,MAAM;AACX,aAAO,KAAA;AAAA,IACT;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,WAAW;AAAA,IACf,OAAO,UAA8B;AACnC,YAAM,OAAO,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,OAAO,YAAY,MAAM;AAC7B,WAAO,KAAA;AAAA,EACT,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,QAAQ,YAAY,MAAM;AAC9B,WAAO,MAAA;AAAA,EACT,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,78 @@
1
+ import { StreamChunk } from '@tanstack/ai';
2
+ import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput } from '@tanstack/ai-client';
3
+ /**
4
+ * Options for the useGeneration hook.
5
+ *
6
+ * Accepts either a `connection` (streaming transport) or a `fetcher` (direct async call).
7
+ *
8
+ * @template TInput - The input type for the generation request
9
+ * @template TResult - The result type returned by the generation
10
+ * @template TOutput - The output type after optional transform (defaults to TResult)
11
+ */
12
+ export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
13
+ /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
14
+ connection?: ConnectionAdapter;
15
+ /** Direct async function for one-shot generation (no streaming protocol needed) */
16
+ fetcher?: GenerationFetcher<TInput, TResult>;
17
+ /** Unique identifier for this generation instance */
18
+ id?: string;
19
+ /** Additional body parameters to send with ConnectionAdapter requests */
20
+ body?: Record<string, any>;
21
+ /**
22
+ * Callback when a result is received. Can optionally return a transformed value.
23
+ *
24
+ * - Return a non-null value to transform and store it as the result
25
+ * - Return `null` to keep the previous result unchanged
26
+ * - Return nothing (`void`) to store the raw result as-is
27
+ */
28
+ onResult?: (result: TResult) => TOutput | null | void;
29
+ /** Callback when an error occurs */
30
+ onError?: (error: Error) => void;
31
+ /** Callback when progress is reported (0-100) */
32
+ onProgress?: (progress: number, message?: string) => void;
33
+ /** Callback for each stream chunk (ConnectionAdapter mode only) */
34
+ onChunk?: (chunk: StreamChunk) => void;
35
+ }
36
+ /**
37
+ * Return type for the useGeneration hook.
38
+ *
39
+ * @template TOutput - The output type (after optional transform)
40
+ */
41
+ export interface UseGenerationReturn<TOutput> {
42
+ /** Trigger a generation request */
43
+ generate: (input: Record<string, any>) => Promise<void>;
44
+ /** The generation result, or null if not yet generated */
45
+ result: TOutput | null;
46
+ /** Whether a generation is currently in progress */
47
+ isLoading: boolean;
48
+ /** Current error, if any */
49
+ error: Error | undefined;
50
+ /** Current state of the generation client */
51
+ status: GenerationClientState;
52
+ /** Abort the current generation */
53
+ stop: () => void;
54
+ /** Clear result, error, and return to idle */
55
+ reset: () => void;
56
+ }
57
+ /**
58
+ * Generic React hook for one-shot generation tasks.
59
+ *
60
+ * This is the base hook used by `useGenerateImage`, `useGenerateSpeech`,
61
+ * `useTranscription`, and `useSummarize`. You can also use it directly
62
+ * for custom generation types.
63
+ *
64
+ * @template TInput - The input type for the generation request
65
+ * @template TResult - The result type returned by the generation
66
+ *
67
+ * @example
68
+ * ```tsx
69
+ * const { generate, result, isLoading } = useGeneration<MyInput, MyResult>({
70
+ * connection: fetchServerSentEvents('/api/generate/custom'),
71
+ * })
72
+ *
73
+ * await generate({ prompt: 'Hello' })
74
+ * ```
75
+ */
76
+ export declare function useGeneration<TInput extends Record<string, any>, TResult, TOnResult extends ((result: TResult) => any) | undefined = undefined>(options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {
77
+ onResult?: TOnResult;
78
+ }): UseGenerationReturn<InferGenerationOutput<TResult, TOnResult>>;
@@ -0,0 +1,75 @@
1
+ import { GenerationClient } from "@tanstack/ai-client";
2
+ import { useId, useState, useRef, useMemo, useEffect, useCallback } from "react";
3
+ function useGeneration(options) {
4
+ const hookId = useId();
5
+ const clientId = options.id || hookId;
6
+ const [result, setResult] = useState(null);
7
+ const [isLoading, setIsLoading] = useState(false);
8
+ const [error, setError] = useState(void 0);
9
+ const [status, setStatus] = useState("idle");
10
+ const optionsRef = useRef(options);
11
+ optionsRef.current = options;
12
+ const client = useMemo(() => {
13
+ const opts = optionsRef.current;
14
+ const clientOptions = {
15
+ id: clientId,
16
+ body: opts.body,
17
+ onResult: (r) => optionsRef.current.onResult?.(r),
18
+ onError: (e) => optionsRef.current.onError?.(e),
19
+ onProgress: (p, m) => optionsRef.current.onProgress?.(p, m),
20
+ onChunk: (c) => optionsRef.current.onChunk?.(c),
21
+ onResultChange: setResult,
22
+ onLoadingChange: setIsLoading,
23
+ onErrorChange: setError,
24
+ onStatusChange: setStatus
25
+ };
26
+ if (opts.connection) {
27
+ return new GenerationClient({
28
+ ...clientOptions,
29
+ connection: opts.connection
30
+ });
31
+ }
32
+ if (opts.fetcher) {
33
+ return new GenerationClient({
34
+ ...clientOptions,
35
+ fetcher: opts.fetcher
36
+ });
37
+ }
38
+ throw new Error(
39
+ "useGeneration requires either a connection or fetcher option"
40
+ );
41
+ }, [clientId]);
42
+ useEffect(() => {
43
+ client.updateOptions({ body: options.body });
44
+ }, [client, options.body]);
45
+ useEffect(() => {
46
+ return () => {
47
+ client.stop();
48
+ };
49
+ }, [client]);
50
+ const generate = useCallback(
51
+ async (input) => {
52
+ await client.generate(input);
53
+ },
54
+ [client]
55
+ );
56
+ const stop = useCallback(() => {
57
+ client.stop();
58
+ }, [client]);
59
+ const reset = useCallback(() => {
60
+ client.reset();
61
+ }, [client]);
62
+ return {
63
+ generate,
64
+ result,
65
+ isLoading,
66
+ error,
67
+ status,
68
+ stop,
69
+ reset
70
+ };
71
+ }
72
+ export {
73
+ useGeneration
74
+ };
75
+ //# sourceMappingURL=use-generation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-generation.js","sources":["../../src/use-generation.ts"],"sourcesContent":["import { GenerationClient } from '@tanstack/ai-client'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientOptions,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\n\n/**\n * Options for the useGeneration hook.\n *\n * Accepts either a `connection` (streaming transport) or a `fetcher` (direct async call).\n *\n * @template TInput - The input type for the generation request\n * @template TResult - The result type returned by the generation\n * @template TOutput - The output type after optional transform (defaults to TResult)\n */\nexport interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for one-shot generation (no streaming protocol needed) */\n fetcher?: GenerationFetcher<TInput, TResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with ConnectionAdapter requests */\n body?: Record<string, any>\n /**\n * Callback when a result is received. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: TResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (ConnectionAdapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGeneration hook.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface UseGenerationReturn<TOutput> {\n /** Trigger a generation request */\n generate: (input: Record<string, any>) => Promise<void>\n /** The generation result, or null if not yet generated */\n result: TOutput | null\n /** Whether a generation is currently in progress */\n isLoading: boolean\n /** Current error, if any */\n error: Error | undefined\n /** Current state of the generation client */\n status: GenerationClientState\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Generic React hook for one-shot generation tasks.\n *\n * This is the base hook used by `useGenerateImage`, `useGenerateSpeech`,\n * `useTranscription`, and `useSummarize`. You can also use it directly\n * for custom generation types.\n *\n * @template TInput - The input type for the generation request\n * @template TResult - The result type returned by the generation\n *\n * @example\n * ```tsx\n * const { generate, result, isLoading } = useGeneration<MyInput, MyResult>({\n * connection: fetchServerSentEvents('/api/generate/custom'),\n * })\n *\n * await generate({ prompt: 'Hello' })\n * ```\n */\nexport function useGeneration<\n TInput extends Record<string, any>,\n TResult,\n TOnResult extends ((result: TResult) => any) | undefined = undefined,\n>(\n options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseGenerationReturn<InferGenerationOutput<TResult, TOnResult>> {\n type TOutput = InferGenerationOutput<TResult, TOnResult>\n const hookId = useId()\n const clientId = options.id || hookId\n\n const [result, setResult] = useState<TOutput | null>(null)\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<Error | undefined>(undefined)\n const [status, setStatus] = useState<GenerationClientState>('idle')\n\n const optionsRef = useRef(options)\n optionsRef.current = options\n\n const client = useMemo(() => {\n const opts = optionsRef.current\n\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n body: opts.body,\n onResult: (r: TResult) => optionsRef.current.onResult?.(r),\n onError: (e: Error) => optionsRef.current.onError?.(e),\n onProgress: (p: number, m?: string) =>\n optionsRef.current.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => optionsRef.current.onChunk?.(c),\n onResultChange: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n }\n\n if (opts.connection) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n connection: opts.connection,\n })\n }\n\n if (opts.fetcher) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n fetcher: opts.fetcher,\n })\n }\n\n throw new Error(\n 'useGeneration requires either a connection or fetcher option',\n )\n }, [clientId])\n\n // Sync body changes without recreating client\n useEffect(() => {\n client.updateOptions({ body: options.body })\n }, [client, options.body])\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n client.stop()\n }\n }, [client])\n\n const generate = useCallback(\n async (input: TInput) => {\n await client.generate(input)\n },\n [client],\n )\n\n const stop = useCallback(() => {\n client.stop()\n }, [client])\n\n const reset = useCallback(() => {\n client.reset()\n }, [client])\n\n return {\n generate: generate as (input: Record<string, any>) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"names":[],"mappings":";;AAsFO,SAAS,cAKd,SAGgE;AAEhE,QAAM,SAAS,MAAA;AACf,QAAM,WAAW,QAAQ,MAAM;AAE/B,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAyB,IAAI;AACzD,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA4B,MAAS;AAC/D,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAgC,MAAM;AAElE,QAAM,aAAa,OAAO,OAAO;AACjC,aAAW,UAAU;AAErB,QAAM,SAAS,QAAQ,MAAM;AAC3B,UAAM,OAAO,WAAW;AAExB,UAAM,gBAAmE;AAAA,MACvE,IAAI;AAAA,MACJ,MAAM,KAAK;AAAA,MACX,UAAU,CAAC,MAAe,WAAW,QAAQ,WAAW,CAAC;AAAA,MACzD,SAAS,CAAC,MAAa,WAAW,QAAQ,UAAU,CAAC;AAAA,MACrD,YAAY,CAAC,GAAW,MACtB,WAAW,QAAQ,aAAa,GAAG,CAAC;AAAA,MACtC,SAAS,CAAC,MAAmB,WAAW,QAAQ,UAAU,CAAC;AAAA,MAC3D,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,eAAe;AAAA,MACf,gBAAgB;AAAA,IAAA;AAGlB,QAAI,KAAK,YAAY;AACnB,aAAO,IAAI,iBAA2C;AAAA,QACpD,GAAG;AAAA,QACH,YAAY,KAAK;AAAA,MAAA,CAClB;AAAA,IACH;AAEA,QAAI,KAAK,SAAS;AAChB,aAAO,IAAI,iBAA2C;AAAA,QACpD,GAAG;AAAA,QACH,SAAS,KAAK;AAAA,MAAA,CACf;AAAA,IACH;AAEA,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ,GAAG,CAAC,QAAQ,CAAC;AAGb,YAAU,MAAM;AACd,WAAO,cAAc,EAAE,MAAM,QAAQ,MAAM;AAAA,EAC7C,GAAG,CAAC,QAAQ,QAAQ,IAAI,CAAC;AAGzB,YAAU,MAAM;AACd,WAAO,MAAM;AACX,aAAO,KAAA;AAAA,IACT;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,WAAW;AAAA,IACf,OAAO,UAAkB;AACvB,YAAM,OAAO,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,OAAO,YAAY,MAAM;AAC7B,WAAO,KAAA;AAAA,EACT,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,QAAQ,YAAY,MAAM;AAC9B,WAAO,MAAA;AAAA,EACT,GAAG,CAAC,MAAM,CAAC;AAEX,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}