@tanstack/ai-react 0.7.14 → 0.8.0

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.
@@ -6,6 +6,8 @@ export { useGeneration } from './use-generation.js';
6
6
  export type { UseGenerationOptions, UseGenerationReturn, } from './use-generation.js';
7
7
  export { useGenerateImage } from './use-generate-image.js';
8
8
  export type { UseGenerateImageOptions, UseGenerateImageReturn, } from './use-generate-image.js';
9
+ export { useGenerateAudio } from './use-generate-audio.js';
10
+ export type { UseGenerateAudioOptions, UseGenerateAudioReturn, } from './use-generate-audio.js';
9
11
  export { useGenerateSpeech } from './use-generate-speech.js';
10
12
  export type { UseGenerateSpeechOptions, UseGenerateSpeechReturn, } from './use-generate-speech.js';
11
13
  export { useTranscription } from './use-transcription.js';
@@ -14,4 +16,4 @@ export { useSummarize } from './use-summarize.js';
14
16
  export type { UseSummarizeOptions, UseSummarizeReturn } from './use-summarize.js';
15
17
  export { useGenerateVideo } from './use-generate-video.js';
16
18
  export type { UseGenerateVideoOptions, UseGenerateVideoReturn, } from './use-generate-video.js';
17
- 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';
19
+ export { fetchServerSentEvents, fetchHttpStream, stream, createChatClientOptions, type ConnectionAdapter, type FetchConnectionOptions, type InferChatMessages, type GenerationClientState, type ImageGenerateInput, type AudioGenerateInput, type SpeechGenerateInput, type TranscriptionGenerateInput, type SummarizeGenerateInput, type VideoGenerateInput, type VideoGenerateResult, type VideoStatusInfo, } from '@tanstack/ai-client';
package/dist/esm/index.js CHANGED
@@ -2,6 +2,7 @@ import { useChat } from "./use-chat.js";
2
2
  import { useRealtimeChat } from "./use-realtime-chat.js";
3
3
  import { useGeneration } from "./use-generation.js";
4
4
  import { useGenerateImage } from "./use-generate-image.js";
5
+ import { useGenerateAudio } from "./use-generate-audio.js";
5
6
  import { useGenerateSpeech } from "./use-generate-speech.js";
6
7
  import { useTranscription } from "./use-transcription.js";
7
8
  import { useSummarize } from "./use-summarize.js";
@@ -13,6 +14,7 @@ export {
13
14
  fetchServerSentEvents,
14
15
  stream,
15
16
  useChat,
17
+ useGenerateAudio,
16
18
  useGenerateImage,
17
19
  useGenerateSpeech,
18
20
  useGenerateVideo,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -27,8 +27,11 @@ function useChat(options) {
27
27
  id: clientId,
28
28
  initialMessages: messagesToUse,
29
29
  body: optionsRef.current.body,
30
- onResponse: optionsRef.current.onResponse,
31
- onChunk: optionsRef.current.onChunk,
30
+ // Wrap every callback so the latest options are read at call time.
31
+ // Capturing the function reference directly would freeze it to whatever
32
+ // the parent passed on the first render.
33
+ onResponse: (response) => optionsRef.current.onResponse?.(response),
34
+ onChunk: (chunk) => optionsRef.current.onChunk?.(chunk),
32
35
  onFinish: (message) => {
33
36
  optionsRef.current.onFinish?.(message);
34
37
  },
@@ -36,7 +39,7 @@ function useChat(options) {
36
39
  optionsRef.current.onError?.(error2);
37
40
  },
38
41
  tools: optionsRef.current.tools,
39
- onCustomEvent: optionsRef.current.onCustomEvent,
42
+ onCustomEvent: (eventType, data, context) => optionsRef.current.onCustomEvent?.(eventType, data, context),
40
43
  streamProcessor: options.streamProcessor,
41
44
  onMessagesChange: (newMessages) => {
42
45
  setMessages(newMessages);
@@ -1 +1 @@
1
- {"version":3,"file":"use-chat.js","sources":["../../src/use-chat.ts"],"sourcesContent":["import { ChatClient } from '@tanstack/ai-client'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport type { AnyClientTool, ModelMessage } from '@tanstack/ai'\nimport type { ChatClientState, ConnectionStatus } from '@tanstack/ai-client'\n\nimport type {\n MultimodalContent,\n UIMessage,\n UseChatOptions,\n UseChatReturn,\n} from './types'\n\nexport function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(\n options: UseChatOptions<TTools>,\n): UseChatReturn<TTools> {\n const hookId = useId()\n const clientId = options.id || hookId\n\n const [messages, setMessages] = useState<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<Error | undefined>(undefined)\n const [status, setStatus] = useState<ChatClientState>('ready')\n const [isSubscribed, setIsSubscribed] = useState(false)\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>('disconnected')\n const [sessionGenerating, setSessionGenerating] = useState(false)\n\n // Track current messages in a ref to preserve them when client is recreated\n const messagesRef = useRef<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const isFirstMountRef = useRef(true)\n\n // Update ref synchronously during render so it's always current when useMemo runs.\n // A useEffect here would be async and messagesRef could be stale on client recreation.\n messagesRef.current = messages\n\n // Track current options in a ref to avoid recreating client when options change\n const optionsRef = useRef<UseChatOptions<TTools>>(options)\n optionsRef.current = options\n\n // Create ChatClient instance with callbacks to sync state\n // Note: Options are captured at client creation time.\n // The connection adapter can use functions for dynamic values (url, headers, etc.)\n // which are evaluated lazily on each request.\n const client = useMemo(() => {\n // On first mount, use initialMessages. On subsequent recreations, preserve existing messages.\n const messagesToUse = isFirstMountRef.current\n ? options.initialMessages || []\n : messagesRef.current\n\n isFirstMountRef.current = false\n\n return new ChatClient({\n connection: optionsRef.current.connection,\n id: clientId,\n initialMessages: messagesToUse,\n body: optionsRef.current.body,\n onResponse: optionsRef.current.onResponse,\n onChunk: optionsRef.current.onChunk,\n onFinish: (message: UIMessage<TTools>) => {\n optionsRef.current.onFinish?.(message)\n },\n onError: (error: Error) => {\n optionsRef.current.onError?.(error)\n },\n tools: optionsRef.current.tools,\n onCustomEvent: optionsRef.current.onCustomEvent,\n streamProcessor: options.streamProcessor,\n onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {\n setMessages(newMessages)\n },\n onLoadingChange: (newIsLoading: boolean) => {\n setIsLoading(newIsLoading)\n },\n onErrorChange: (newError: Error | undefined) => {\n setError(newError)\n },\n onStatusChange: (status: ChatClientState) => {\n setStatus(status)\n },\n onSubscriptionChange: (nextIsSubscribed: boolean) => {\n setIsSubscribed(nextIsSubscribed)\n },\n onConnectionStatusChange: (nextStatus: ConnectionStatus) => {\n setConnectionStatus(nextStatus)\n },\n onSessionGeneratingChange: (isGenerating: boolean) => {\n setSessionGenerating(isGenerating)\n },\n })\n }, [clientId])\n\n // Sync body changes to the client\n // This allows dynamic body values (like model selection) to be updated without recreating the client\n useEffect(() => {\n client.updateOptions({ body: options.body })\n }, [client, options.body])\n\n // Sync initial messages on mount only\n // Note: initialMessages are passed to ChatClient constructor, but we also\n // set them here to ensure React state is in sync\n useEffect(() => {\n if (options.initialMessages && options.initialMessages.length > 0) {\n // Only set if current messages are empty (initial state)\n if (messages.length === 0) {\n client.setMessagesManually(options.initialMessages)\n }\n }\n }, []) // Only run on mount - initialMessages are handled by ChatClient constructor\n\n // Keep connection lifecycle opt-in and explicit.\n useEffect(() => {\n if (options.live) {\n client.subscribe()\n } else {\n client.unsubscribe()\n }\n }, [client, options.live])\n\n // Cleanup on unmount: stop any in-flight requests\n // Note: We only cleanup when client changes or component unmounts.\n // DO NOT include isLoading in dependencies - that would cause the cleanup\n // to run when isLoading changes, aborting continuation requests.\n useEffect(() => {\n return () => {\n // live mode owns the connection lifecycle; non-live keeps request-only stop.\n if (options.live) {\n client.unsubscribe()\n } else {\n client.stop()\n }\n }\n }, [client, options.live])\n\n // Note: Callback options (onResponse, onChunk, onFinish, onError, onToolCall)\n // are captured at client creation time. Changes to these callbacks require\n // remounting the component or changing the connection to recreate the client.\n\n const sendMessage = useCallback(\n async (content: string | MultimodalContent) => {\n await client.sendMessage(content)\n },\n [client],\n )\n\n const append = useCallback(\n async (message: ModelMessage | UIMessage) => {\n await client.append(message)\n },\n [client],\n )\n\n const reload = useCallback(async () => {\n await client.reload()\n }, [client])\n\n const stop = useCallback(() => {\n client.stop()\n }, [client])\n\n const clear = useCallback(() => {\n client.clear()\n }, [client])\n\n const setMessagesManually = useCallback(\n (newMessages: Array<UIMessage<TTools>>) => {\n client.setMessagesManually(newMessages)\n },\n [client],\n )\n\n const addToolResult = useCallback(\n async (result: {\n toolCallId: string\n tool: string\n output: any\n state?: 'output-available' | 'output-error'\n errorText?: string\n }) => {\n await client.addToolResult(result)\n },\n [client],\n )\n\n const addToolApprovalResponse = useCallback(\n async (response: { id: string; approved: boolean }) => {\n await client.addToolApprovalResponse(response)\n },\n [client],\n )\n\n return {\n messages,\n sendMessage,\n append,\n reload,\n stop,\n isLoading,\n error,\n status,\n isSubscribed,\n connectionStatus,\n sessionGenerating,\n setMessages: setMessagesManually,\n clear,\n addToolResult,\n addToolApprovalResponse,\n }\n}\n"],"names":["error","status"],"mappings":";;AAYO,SAAS,QACd,SACuB;AACvB,QAAM,SAAS,MAAA;AACf,QAAM,WAAW,QAAQ,MAAM;AAE/B,QAAM,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,QAAQ,mBAAmB,CAAA;AAAA,EAAC;AAE9B,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA4B,MAAS;AAC/D,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA0B,OAAO;AAC7D,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AACtD,QAAM,CAAC,kBAAkB,mBAAmB,IAC1C,SAA2B,cAAc;AAC3C,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAAS,KAAK;AAGhE,QAAM,cAAc;AAAA,IAClB,QAAQ,mBAAmB,CAAA;AAAA,EAAC;AAE9B,QAAM,kBAAkB,OAAO,IAAI;AAInC,cAAY,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Ac,MAAM;AAAA,IACnC;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,0BAA0B;AAAA,IAC9B,OAAO,aAAgD;AACrD,YAAM,OAAO,wBAAwB,QAAQ;AAAA,IAC/C;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"use-chat.js","sources":["../../src/use-chat.ts"],"sourcesContent":["import { ChatClient } from '@tanstack/ai-client'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport type { AnyClientTool, ModelMessage } from '@tanstack/ai'\nimport type { ChatClientState, ConnectionStatus } from '@tanstack/ai-client'\n\nimport type {\n MultimodalContent,\n UIMessage,\n UseChatOptions,\n UseChatReturn,\n} from './types'\n\nexport function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(\n options: UseChatOptions<TTools>,\n): UseChatReturn<TTools> {\n const hookId = useId()\n const clientId = options.id || hookId\n\n const [messages, setMessages] = useState<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const [isLoading, setIsLoading] = useState(false)\n const [error, setError] = useState<Error | undefined>(undefined)\n const [status, setStatus] = useState<ChatClientState>('ready')\n const [isSubscribed, setIsSubscribed] = useState(false)\n const [connectionStatus, setConnectionStatus] =\n useState<ConnectionStatus>('disconnected')\n const [sessionGenerating, setSessionGenerating] = useState(false)\n\n // Track current messages in a ref to preserve them when client is recreated\n const messagesRef = useRef<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const isFirstMountRef = useRef(true)\n\n // Update ref synchronously during render so it's always current when useMemo runs.\n // A useEffect here would be async and messagesRef could be stale on client recreation.\n messagesRef.current = messages\n\n // Track current options in a ref to avoid recreating client when options change\n const optionsRef = useRef<UseChatOptions<TTools>>(options)\n optionsRef.current = options\n\n // Create ChatClient instance with callbacks to sync state\n // Note: Options are captured at client creation time.\n // The connection adapter can use functions for dynamic values (url, headers, etc.)\n // which are evaluated lazily on each request.\n const client = useMemo(() => {\n // On first mount, use initialMessages. On subsequent recreations, preserve existing messages.\n const messagesToUse = isFirstMountRef.current\n ? options.initialMessages || []\n : messagesRef.current\n\n isFirstMountRef.current = false\n\n return new ChatClient({\n connection: optionsRef.current.connection,\n id: clientId,\n initialMessages: messagesToUse,\n body: optionsRef.current.body,\n // Wrap every callback so the latest options are read at call time.\n // Capturing the function reference directly would freeze it to whatever\n // the parent passed on the first render.\n onResponse: (response) => optionsRef.current.onResponse?.(response),\n onChunk: (chunk) => optionsRef.current.onChunk?.(chunk),\n onFinish: (message: UIMessage<TTools>) => {\n optionsRef.current.onFinish?.(message)\n },\n onError: (error: Error) => {\n optionsRef.current.onError?.(error)\n },\n tools: optionsRef.current.tools,\n onCustomEvent: (eventType, data, context) =>\n optionsRef.current.onCustomEvent?.(eventType, data, context),\n streamProcessor: options.streamProcessor,\n onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {\n setMessages(newMessages)\n },\n onLoadingChange: (newIsLoading: boolean) => {\n setIsLoading(newIsLoading)\n },\n onErrorChange: (newError: Error | undefined) => {\n setError(newError)\n },\n onStatusChange: (status: ChatClientState) => {\n setStatus(status)\n },\n onSubscriptionChange: (nextIsSubscribed: boolean) => {\n setIsSubscribed(nextIsSubscribed)\n },\n onConnectionStatusChange: (nextStatus: ConnectionStatus) => {\n setConnectionStatus(nextStatus)\n },\n onSessionGeneratingChange: (isGenerating: boolean) => {\n setSessionGenerating(isGenerating)\n },\n })\n }, [clientId])\n\n // Sync body changes to the client\n // This allows dynamic body values (like model selection) to be updated without recreating the client\n useEffect(() => {\n client.updateOptions({ body: options.body })\n }, [client, options.body])\n\n // Sync initial messages on mount only\n // Note: initialMessages are passed to ChatClient constructor, but we also\n // set them here to ensure React state is in sync\n useEffect(() => {\n if (options.initialMessages && options.initialMessages.length > 0) {\n // Only set if current messages are empty (initial state)\n if (messages.length === 0) {\n client.setMessagesManually(options.initialMessages)\n }\n }\n }, []) // Only run on mount - initialMessages are handled by ChatClient constructor\n\n // Keep connection lifecycle opt-in and explicit.\n useEffect(() => {\n if (options.live) {\n client.subscribe()\n } else {\n client.unsubscribe()\n }\n }, [client, options.live])\n\n // Cleanup on unmount: stop any in-flight requests\n // Note: We only cleanup when client changes or component unmounts.\n // DO NOT include isLoading in dependencies - that would cause the cleanup\n // to run when isLoading changes, aborting continuation requests.\n useEffect(() => {\n return () => {\n // live mode owns the connection lifecycle; non-live keeps request-only stop.\n if (options.live) {\n client.unsubscribe()\n } else {\n client.stop()\n }\n }\n }, [client, options.live])\n\n // All callback options are read through optionsRef at call time, so fresh\n // closures from each render are picked up without recreating the client.\n\n const sendMessage = useCallback(\n async (content: string | MultimodalContent) => {\n await client.sendMessage(content)\n },\n [client],\n )\n\n const append = useCallback(\n async (message: ModelMessage | UIMessage) => {\n await client.append(message)\n },\n [client],\n )\n\n const reload = useCallback(async () => {\n await client.reload()\n }, [client])\n\n const stop = useCallback(() => {\n client.stop()\n }, [client])\n\n const clear = useCallback(() => {\n client.clear()\n }, [client])\n\n const setMessagesManually = useCallback(\n (newMessages: Array<UIMessage<TTools>>) => {\n client.setMessagesManually(newMessages)\n },\n [client],\n )\n\n const addToolResult = useCallback(\n async (result: {\n toolCallId: string\n tool: string\n output: any\n state?: 'output-available' | 'output-error'\n errorText?: string\n }) => {\n await client.addToolResult(result)\n },\n [client],\n )\n\n const addToolApprovalResponse = useCallback(\n async (response: { id: string; approved: boolean }) => {\n await client.addToolApprovalResponse(response)\n },\n [client],\n )\n\n return {\n messages,\n sendMessage,\n append,\n reload,\n stop,\n isLoading,\n error,\n status,\n isSubscribed,\n connectionStatus,\n sessionGenerating,\n setMessages: setMessagesManually,\n clear,\n addToolResult,\n addToolApprovalResponse,\n }\n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AAG,CAAC,QAAQ,QAAQ,IAAI,CAAC;AAKzB,QAAM,cAAc;AAAA,IAClB,OAAO,YAAwC;AAC7C,YAAM,OAAO,YAAY,OAAO;AAAA,IAClC;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,SAAS;AAAA,IACb,OAAO,YAAsC;AAC3C,YAAM,OAAO,OAAO,OAAO;AAAA,IAC7B;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,SAAS,YAAY,YAAY;AACrC,UAAM,OAAO,OAAA;AAAA,EACf,GAAG,CAAC,MAAM,CAAC;AAEX,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,QAAM,sBAAsB;AAAA,IAC1B,CAAC,gBAA0C;AACzC,aAAO,oBAAoB,WAAW;AAAA,IACxC;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,gBAAgB;AAAA,IACpB,OAAO,WAMD;AACJ,YAAM,OAAO,cAAc,MAAM;AAAA,IACnC;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,QAAM,0BAA0B;AAAA,IAC9B,OAAO,aAAgD;AACrD,YAAM,OAAO,wBAAwB,QAAQ;AAAA,IAC/C;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAGT,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,85 @@
1
+ import { AudioGenerationResult, StreamChunk } from '@tanstack/ai';
2
+ import { AudioGenerateInput, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput } from '@tanstack/ai-client';
3
+ /**
4
+ * Options for the useGenerateAudio hook.
5
+ *
6
+ * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)
7
+ */
8
+ export interface UseGenerateAudioOptions<TOutput = AudioGenerationResult> {
9
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
10
+ connection?: ConnectConnectionAdapter;
11
+ /** Direct async function for audio generation */
12
+ fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>;
13
+ /** Unique identifier for this generation instance */
14
+ id?: string;
15
+ /** Additional body parameters to send with connect-based adapter requests */
16
+ body?: Record<string, any>;
17
+ /**
18
+ * Callback when audio 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: AudioGenerationResult) => 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 (connect-based adapter mode only) */
30
+ onChunk?: (chunk: StreamChunk) => void;
31
+ }
32
+ /**
33
+ * Return type for the useGenerateAudio hook.
34
+ *
35
+ * @template TOutput - The output type (after optional transform)
36
+ */
37
+ export interface UseGenerateAudioReturn<TOutput = AudioGenerationResult> {
38
+ /** Trigger audio generation */
39
+ generate: (input: AudioGenerateInput) => Promise<void>;
40
+ /** The generation result containing audio, 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 audio (music, sound effects) using AI models.
55
+ *
56
+ * Supports two transport modes:
57
+ * - **ConnectConnectionAdapter** — Streaming transport (SSE, HTTP stream, custom)
58
+ * - **Fetcher** — Direct async function call
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * import { useGenerateAudio } from '@tanstack/ai-react'
63
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
64
+ *
65
+ * function AudioGenerator() {
66
+ * const { generate, result, isLoading, error, reset } = useGenerateAudio({
67
+ * connection: fetchServerSentEvents('/api/generate/audio'),
68
+ * })
69
+ *
70
+ * return (
71
+ * <div>
72
+ * <button onClick={() => generate({ prompt: 'An upbeat electronic track', duration: 10 })}>
73
+ * Generate
74
+ * </button>
75
+ * {isLoading && <p>Generating...</p>}
76
+ * {error && <p>Error: {error.message}</p>}
77
+ * {result?.audio.url && <audio src={result.audio.url} controls />}
78
+ * </div>
79
+ * )
80
+ * }
81
+ * ```
82
+ */
83
+ export declare function useGenerateAudio<TOnResult extends ((result: AudioGenerationResult) => any) | undefined = undefined>(options: Omit<UseGenerateAudioOptions, 'onResult'> & {
84
+ onResult?: TOnResult;
85
+ }): UseGenerateAudioReturn<InferGenerationOutput<AudioGenerationResult, TOnResult>>;
@@ -0,0 +1,17 @@
1
+ import { useGeneration } from "./use-generation.js";
2
+ function useGenerateAudio(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
+ useGenerateAudio
16
+ };
17
+ //# sourceMappingURL=use-generate-audio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-generate-audio.js","sources":["../../src/use-generate-audio.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { AudioGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n AudioGenerateInput,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\n\n/**\n * Options for the useGenerateAudio hook.\n *\n * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)\n */\nexport interface UseGenerateAudioOptions<TOutput = AudioGenerationResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for audio generation */\n fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with connect-based adapter requests */\n body?: Record<string, any>\n /**\n * Callback when audio 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: AudioGenerationResult) => 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 (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateAudio hook.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface UseGenerateAudioReturn<TOutput = AudioGenerationResult> {\n /** Trigger audio generation */\n generate: (input: AudioGenerateInput) => Promise<void>\n /** The generation result containing audio, 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 audio (music, sound effects) using AI models.\n *\n * Supports two transport modes:\n * - **ConnectConnectionAdapter** — Streaming transport (SSE, HTTP stream, custom)\n * - **Fetcher** — Direct async function call\n *\n * @example\n * ```tsx\n * import { useGenerateAudio } from '@tanstack/ai-react'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function AudioGenerator() {\n * const { generate, result, isLoading, error, reset } = useGenerateAudio({\n * connection: fetchServerSentEvents('/api/generate/audio'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({ prompt: 'An upbeat electronic track', duration: 10 })}>\n * Generate\n * </button>\n * {isLoading && <p>Generating...</p>}\n * {error && <p>Error: {error.message}</p>}\n * {result?.audio.url && <audio src={result.audio.url} controls />}\n * </div>\n * )\n * }\n * ```\n */\nexport function useGenerateAudio<\n TOnResult extends ((result: AudioGenerationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseGenerateAudioOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseGenerateAudioReturn<\n InferGenerationOutput<AudioGenerationResult, TOnResult>\n> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<AudioGenerateInput, AudioGenerationResult, TOnResult>(options)\n\n return {\n generate: generate as (input: AudioGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"names":[],"mappings":";AA4FO,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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-react",
3
- "version": "0.7.14",
3
+ "version": "0.8.0",
4
4
  "description": "React hooks for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -31,12 +31,12 @@
31
31
  "streaming"
32
32
  ],
33
33
  "dependencies": {
34
- "@tanstack/ai-client": "0.7.13"
34
+ "@tanstack/ai-client": "0.8.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@types/react": ">=18.0.0",
38
38
  "react": ">=18.0.0",
39
- "@tanstack/ai": "^0.12.0"
39
+ "@tanstack/ai": "^0.14.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@testing-library/react": "^16.3.0",
@@ -45,7 +45,7 @@
45
45
  "jsdom": "^27.2.0",
46
46
  "react": "^19.2.3",
47
47
  "vite": "^7.2.7",
48
- "@tanstack/ai": "0.12.0"
48
+ "@tanstack/ai": "0.14.0"
49
49
  },
50
50
  "scripts": {
51
51
  "clean": "premove ./build ./dist",
package/src/index.ts CHANGED
@@ -24,6 +24,12 @@ export type {
24
24
  UseGenerateImageReturn,
25
25
  } from './use-generate-image'
26
26
 
27
+ export { useGenerateAudio } from './use-generate-audio'
28
+ export type {
29
+ UseGenerateAudioOptions,
30
+ UseGenerateAudioReturn,
31
+ } from './use-generate-audio'
32
+
27
33
  export { useGenerateSpeech } from './use-generate-speech'
28
34
  export type {
29
35
  UseGenerateSpeechOptions,
@@ -56,6 +62,7 @@ export {
56
62
  type InferChatMessages,
57
63
  type GenerationClientState,
58
64
  type ImageGenerateInput,
65
+ type AudioGenerateInput,
59
66
  type SpeechGenerateInput,
60
67
  type TranscriptionGenerateInput,
61
68
  type SummarizeGenerateInput,
package/src/use-chat.ts CHANGED
@@ -58,8 +58,11 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
58
58
  id: clientId,
59
59
  initialMessages: messagesToUse,
60
60
  body: optionsRef.current.body,
61
- onResponse: optionsRef.current.onResponse,
62
- onChunk: optionsRef.current.onChunk,
61
+ // Wrap every callback so the latest options are read at call time.
62
+ // Capturing the function reference directly would freeze it to whatever
63
+ // the parent passed on the first render.
64
+ onResponse: (response) => optionsRef.current.onResponse?.(response),
65
+ onChunk: (chunk) => optionsRef.current.onChunk?.(chunk),
63
66
  onFinish: (message: UIMessage<TTools>) => {
64
67
  optionsRef.current.onFinish?.(message)
65
68
  },
@@ -67,7 +70,8 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
67
70
  optionsRef.current.onError?.(error)
68
71
  },
69
72
  tools: optionsRef.current.tools,
70
- onCustomEvent: optionsRef.current.onCustomEvent,
73
+ onCustomEvent: (eventType, data, context) =>
74
+ optionsRef.current.onCustomEvent?.(eventType, data, context),
71
75
  streamProcessor: options.streamProcessor,
72
76
  onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {
73
77
  setMessages(newMessages)
@@ -135,9 +139,8 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
135
139
  }
136
140
  }, [client, options.live])
137
141
 
138
- // Note: Callback options (onResponse, onChunk, onFinish, onError, onToolCall)
139
- // are captured at client creation time. Changes to these callbacks require
140
- // remounting the component or changing the connection to recreate the client.
142
+ // All callback options are read through optionsRef at call time, so fresh
143
+ // closures from each render are picked up without recreating the client.
141
144
 
142
145
  const sendMessage = useCallback(
143
146
  async (content: string | MultimodalContent) => {
@@ -0,0 +1,115 @@
1
+ import { useGeneration } from './use-generation'
2
+ import type { AudioGenerationResult, StreamChunk } from '@tanstack/ai'
3
+ import type {
4
+ AudioGenerateInput,
5
+ ConnectConnectionAdapter,
6
+ GenerationClientState,
7
+ GenerationFetcher,
8
+ InferGenerationOutput,
9
+ } from '@tanstack/ai-client'
10
+
11
+ /**
12
+ * Options for the useGenerateAudio hook.
13
+ *
14
+ * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)
15
+ */
16
+ export interface UseGenerateAudioOptions<TOutput = AudioGenerationResult> {
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter
19
+ /** Direct async function for audio generation */
20
+ fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>
21
+ /** Unique identifier for this generation instance */
22
+ id?: string
23
+ /** Additional body parameters to send with connect-based adapter requests */
24
+ body?: Record<string, any>
25
+ /**
26
+ * Callback when audio is generated. Can optionally return a transformed value.
27
+ *
28
+ * - Return a non-null value to transform and store it as the result
29
+ * - Return `null` to keep the previous result unchanged
30
+ * - Return nothing (`void`) to store the raw result as-is
31
+ */
32
+ onResult?: (result: AudioGenerationResult) => TOutput | null | void
33
+ /** Callback when an error occurs */
34
+ onError?: (error: Error) => void
35
+ /** Callback when progress is reported (0-100) */
36
+ onProgress?: (progress: number, message?: string) => void
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
+ onChunk?: (chunk: StreamChunk) => void
39
+ }
40
+
41
+ /**
42
+ * Return type for the useGenerateAudio hook.
43
+ *
44
+ * @template TOutput - The output type (after optional transform)
45
+ */
46
+ export interface UseGenerateAudioReturn<TOutput = AudioGenerationResult> {
47
+ /** Trigger audio generation */
48
+ generate: (input: AudioGenerateInput) => Promise<void>
49
+ /** The generation result containing audio, or null */
50
+ result: TOutput | null
51
+ /** Whether generation is in progress */
52
+ isLoading: boolean
53
+ /** Current error, if any */
54
+ error: Error | undefined
55
+ /** Current state of the generation */
56
+ status: GenerationClientState
57
+ /** Abort the current generation */
58
+ stop: () => void
59
+ /** Clear result, error, and return to idle */
60
+ reset: () => void
61
+ }
62
+
63
+ /**
64
+ * React hook for generating audio (music, sound effects) using AI models.
65
+ *
66
+ * Supports two transport modes:
67
+ * - **ConnectConnectionAdapter** — Streaming transport (SSE, HTTP stream, custom)
68
+ * - **Fetcher** — Direct async function call
69
+ *
70
+ * @example
71
+ * ```tsx
72
+ * import { useGenerateAudio } from '@tanstack/ai-react'
73
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
74
+ *
75
+ * function AudioGenerator() {
76
+ * const { generate, result, isLoading, error, reset } = useGenerateAudio({
77
+ * connection: fetchServerSentEvents('/api/generate/audio'),
78
+ * })
79
+ *
80
+ * return (
81
+ * <div>
82
+ * <button onClick={() => generate({ prompt: 'An upbeat electronic track', duration: 10 })}>
83
+ * Generate
84
+ * </button>
85
+ * {isLoading && <p>Generating...</p>}
86
+ * {error && <p>Error: {error.message}</p>}
87
+ * {result?.audio.url && <audio src={result.audio.url} controls />}
88
+ * </div>
89
+ * )
90
+ * }
91
+ * ```
92
+ */
93
+ export function useGenerateAudio<
94
+ TOnResult extends ((result: AudioGenerationResult) => any) | undefined =
95
+ undefined,
96
+ >(
97
+ options: Omit<UseGenerateAudioOptions, 'onResult'> & {
98
+ onResult?: TOnResult
99
+ },
100
+ ): UseGenerateAudioReturn<
101
+ InferGenerationOutput<AudioGenerationResult, TOnResult>
102
+ > {
103
+ const { generate, result, isLoading, error, status, stop, reset } =
104
+ useGeneration<AudioGenerateInput, AudioGenerationResult, TOnResult>(options)
105
+
106
+ return {
107
+ generate: generate as (input: AudioGenerateInput) => Promise<void>,
108
+ result,
109
+ isLoading,
110
+ error,
111
+ status,
112
+ stop,
113
+ reset,
114
+ }
115
+ }