@tanstack/ai-solid 0.6.6 → 0.6.9

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.
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ChatClientOptions, ChatClientState, ChatRequestBody, MultimodalContent, UIMessage } from "@tanstack/ai-client";
2
+ import { ChatClientOptions, ChatClientState, ChatRequestBody, ConnectionStatus, MultimodalContent, UIMessage } from "@tanstack/ai-client";
3
3
  import { AnyClientTool, ModelMessage } from "@tanstack/ai";
4
4
 
5
5
  //#region src/types.d.ts
@@ -20,7 +20,9 @@ import { AnyClientTool, ModelMessage } from "@tanstack/ai";
20
20
  * Note: Connection and body changes will recreate the ChatClient instance.
21
21
  * To update these options, remount the component or use a key prop.
22
22
  */
23
- type UseChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> = Omit<ChatClientOptions<TTools>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange'>;
23
+ type UseChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> = Omit<ChatClientOptions<TTools>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange'> & {
24
+ live?: boolean;
25
+ };
24
26
  interface UseChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any> {
25
27
  /**
26
28
  * Current messages in the conversation
@@ -80,6 +82,21 @@ interface UseChatReturn<TTools extends ReadonlyArray<AnyClientTool> = any> {
80
82
  * Current generation status
81
83
  */
82
84
  status: Accessor<ChatClientState>;
85
+ /**
86
+ * Whether the subscription loop is currently active
87
+ */
88
+ isSubscribed: Accessor<boolean>;
89
+ /**
90
+ * Current connection lifecycle status
91
+ */
92
+ connectionStatus: Accessor<ConnectionStatus>;
93
+ /**
94
+ * Whether the shared session is actively generating.
95
+ * Derived from stream run events (RUN_STARTED / RUN_FINISHED / RUN_ERROR).
96
+ * Unlike `isLoading` (request-local), this reflects shared generation
97
+ * activity visible to all subscribers (e.g. across tabs/devices).
98
+ */
99
+ sessionGenerating: Accessor<boolean>;
83
100
  }
84
101
  //#endregion
85
102
  export { type ChatRequestBody, type UIMessage, UseChatOptions, UseChatReturn };
package/dist/use-chat.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createEffect, createMemo, createSignal, createUniqueId } from "solid-js";
1
+ import { createEffect, createMemo, createSignal, createUniqueId, onCleanup } from "solid-js";
2
2
  import { ChatClient } from "@tanstack/ai-client";
3
3
 
4
4
  //#region src/use-chat.ts
@@ -9,6 +9,9 @@ function useChat(options = {}) {
9
9
  const [isLoading, setIsLoading] = createSignal(false);
10
10
  const [error, setError] = createSignal(void 0);
11
11
  const [status, setStatus] = createSignal("ready");
12
+ const [isSubscribed, setIsSubscribed] = createSignal(false);
13
+ const [connectionStatus, setConnectionStatus] = createSignal("disconnected");
14
+ const [sessionGenerating, setSessionGenerating] = createSignal(false);
12
15
  const client = createMemo(() => {
13
16
  return new ChatClient({
14
17
  connection: options.connection,
@@ -37,6 +40,15 @@ function useChat(options = {}) {
37
40
  },
38
41
  onErrorChange: (newError) => {
39
42
  setError(newError);
43
+ },
44
+ onSubscriptionChange: (nextIsSubscribed) => {
45
+ setIsSubscribed(nextIsSubscribed);
46
+ },
47
+ onConnectionStatusChange: (nextStatus) => {
48
+ setConnectionStatus(nextStatus);
49
+ },
50
+ onSessionGeneratingChange: (isGenerating) => {
51
+ setSessionGenerating(isGenerating);
40
52
  }
41
53
  });
42
54
  }, [clientId]);
@@ -49,10 +61,15 @@ function useChat(options = {}) {
49
61
  if (messages().length === 0) client().setMessagesManually(options.initialMessages);
50
62
  }
51
63
  });
64
+ if (options.live) client().subscribe();
65
+ else client().unsubscribe();
52
66
  createEffect(() => {
53
- return () => {
54
- client().stop();
55
- };
67
+ if (options.live) client().subscribe();
68
+ else client().unsubscribe();
69
+ });
70
+ onCleanup(() => {
71
+ if (options.live) client().unsubscribe();
72
+ else client().stop();
56
73
  });
57
74
  const sendMessage = async (content) => {
58
75
  await client().sendMessage(content);
@@ -87,6 +104,9 @@ function useChat(options = {}) {
87
104
  isLoading,
88
105
  error,
89
106
  status,
107
+ isSubscribed,
108
+ connectionStatus,
109
+ sessionGenerating,
90
110
  setMessages: setMessagesManually,
91
111
  clear,
92
112
  addToolResult,
@@ -1 +1 @@
1
- {"version":3,"file":"use-chat.js","names":[],"sources":["../src/use-chat.ts"],"sourcesContent":["import {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n} from 'solid-js'\n\nimport { ChatClient } from '@tanstack/ai-client'\nimport type { ChatClientState } from '@tanstack/ai-client'\nimport type { AnyClientTool, ModelMessage } from '@tanstack/ai'\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> = {} as UseChatOptions<TTools>,\n): UseChatReturn<TTools> {\n const hookId = createUniqueId()\n const clientId = options.id || hookId\n\n const [messages, setMessages] = createSignal<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<ChatClientState>('ready')\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 = createMemo(() => {\n return new ChatClient({\n connection: options.connection,\n id: clientId,\n initialMessages: options.initialMessages,\n body: options.body,\n onResponse: options.onResponse,\n onChunk: options.onChunk,\n onFinish: (message) => {\n options.onFinish?.(message)\n },\n onError: (err) => {\n options.onError?.(err)\n },\n tools: options.tools,\n onCustomEvent: options.onCustomEvent,\n streamProcessor: options.streamProcessor,\n onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {\n setMessages(newMessages)\n },\n onLoadingChange: (newIsLoading: boolean) => {\n setIsLoading(newIsLoading)\n },\n onStatusChange: (newStatus: ChatClientState) => {\n setStatus(newStatus)\n },\n onErrorChange: (newError: Error | undefined) => {\n setError(newError)\n },\n })\n // Only recreate when clientId changes\n // Connection and other options are captured at creation time\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 createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\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 createEffect(() => {\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 // Cleanup on unmount: stop any in-flight requests\n // Note: We use createEffect with a cleanup return to handle component unmount.\n // The cleanup only runs on disposal (unmount), not on signal changes.\n createEffect(() => {\n return () => {\n // Stop any active generation when component unmounts\n client().stop()\n }\n })\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 = async (content: string | MultimodalContent) => {\n await client().sendMessage(content)\n }\n\n const append = async (message: ModelMessage | UIMessage<TTools>) => {\n await client().append(message)\n }\n\n const reload = async () => {\n await client().reload()\n }\n\n const stop = () => {\n client().stop()\n }\n\n const clear = () => {\n client().clear()\n }\n\n const setMessagesManually = (newMessages: Array<UIMessage<TTools>>) => {\n client().setMessagesManually(newMessages)\n }\n\n const addToolResult = 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\n const addToolApprovalResponse = async (response: {\n id: string\n approved: boolean\n }) => {\n await client().addToolApprovalResponse(response)\n }\n\n return {\n messages,\n sendMessage,\n append,\n reload,\n stop,\n isLoading,\n error,\n status,\n setMessages: setMessagesManually,\n clear,\n addToolResult,\n addToolApprovalResponse,\n }\n}\n"],"mappings":";;;;AAiBA,SAAgB,QACd,UAAkC,EAAE,EACb;CACvB,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,UAAU,eAAe,aAC9B,QAAQ,mBAAmB,EAAE,CAC9B;CACD,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAA8B,QAAQ;CAMlE,MAAM,SAAS,iBAAiB;AAC9B,SAAO,IAAI,WAAW;GACpB,YAAY,QAAQ;GACpB,IAAI;GACJ,iBAAiB,QAAQ;GACzB,MAAM,QAAQ;GACd,YAAY,QAAQ;GACpB,SAAS,QAAQ;GACjB,WAAW,YAAY;AACrB,YAAQ,WAAW,QAAQ;;GAE7B,UAAU,QAAQ;AAChB,YAAQ,UAAU,IAAI;;GAExB,OAAO,QAAQ;GACf,eAAe,QAAQ;GACvB,iBAAiB,QAAQ;GACzB,mBAAmB,gBAA0C;AAC3D,gBAAY,YAAY;;GAE1B,kBAAkB,iBAA0B;AAC1C,iBAAa,aAAa;;GAE5B,iBAAiB,cAA+B;AAC9C,cAAU,UAAU;;GAEtB,gBAAgB,aAAgC;AAC9C,aAAS,SAAS;;GAErB,CAAC;IAGD,CAAC,SAAS,CAAC;AAId,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAKF,oBAAmB;AACjB,MAAI,QAAQ,mBAAmB,QAAQ,gBAAgB,SAAS,GAE9D;OAAI,UAAU,CAAC,WAAW,EACxB,SAAQ,CAAC,oBAAoB,QAAQ,gBAAgB;;GAGzD;AAKF,oBAAmB;AACjB,eAAa;AAEX,WAAQ,CAAC,MAAM;;GAEjB;CAMF,MAAM,cAAc,OAAO,YAAwC;AACjE,QAAM,QAAQ,CAAC,YAAY,QAAQ;;CAGrC,MAAM,SAAS,OAAO,YAA8C;AAClE,QAAM,QAAQ,CAAC,OAAO,QAAQ;;CAGhC,MAAM,SAAS,YAAY;AACzB,QAAM,QAAQ,CAAC,QAAQ;;CAGzB,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;CAGlB,MAAM,uBAAuB,gBAA0C;AACrE,UAAQ,CAAC,oBAAoB,YAAY;;CAG3C,MAAM,gBAAgB,OAAO,WAMvB;AACJ,QAAM,QAAQ,CAAC,cAAc,OAAO;;CAGtC,MAAM,0BAA0B,OAAO,aAGjC;AACJ,QAAM,QAAQ,CAAC,wBAAwB,SAAS;;AAGlD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-chat.js","names":[],"sources":["../src/use-chat.ts"],"sourcesContent":["import {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n onCleanup,\n} from 'solid-js'\n\nimport { ChatClient } from '@tanstack/ai-client'\nimport type { ChatClientState, ConnectionStatus } from '@tanstack/ai-client'\nimport type { AnyClientTool, ModelMessage } from '@tanstack/ai'\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> = {} as UseChatOptions<TTools>,\n): UseChatReturn<TTools> {\n const hookId = createUniqueId()\n const clientId = options.id || hookId\n\n const [messages, setMessages] = createSignal<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<ChatClientState>('ready')\n const [isSubscribed, setIsSubscribed] = createSignal(false)\n const [connectionStatus, setConnectionStatus] =\n createSignal<ConnectionStatus>('disconnected')\n const [sessionGenerating, setSessionGenerating] = createSignal(false)\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 = createMemo(() => {\n return new ChatClient({\n connection: options.connection,\n id: clientId,\n initialMessages: options.initialMessages,\n body: options.body,\n onResponse: options.onResponse,\n onChunk: options.onChunk,\n onFinish: (message) => {\n options.onFinish?.(message)\n },\n onError: (err) => {\n options.onError?.(err)\n },\n tools: options.tools,\n onCustomEvent: options.onCustomEvent,\n streamProcessor: options.streamProcessor,\n onMessagesChange: (newMessages: Array<UIMessage<TTools>>) => {\n setMessages(newMessages)\n },\n onLoadingChange: (newIsLoading: boolean) => {\n setIsLoading(newIsLoading)\n },\n onStatusChange: (newStatus: ChatClientState) => {\n setStatus(newStatus)\n },\n onErrorChange: (newError: Error | undefined) => {\n setError(newError)\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 // Only recreate when clientId changes\n // Connection and other options are captured at creation time\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 createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\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 createEffect(() => {\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 // Apply initial live mode immediately on hook creation.\n if (options.live) {\n client().subscribe()\n } else {\n client().unsubscribe()\n }\n\n createEffect(() => {\n if (options.live) {\n client().subscribe()\n } else {\n client().unsubscribe()\n }\n })\n\n // Cleanup on unmount: stop any in-flight requests.\n onCleanup(() => {\n if (options.live) {\n client().unsubscribe()\n } else {\n client().stop()\n }\n })\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 = async (content: string | MultimodalContent) => {\n await client().sendMessage(content)\n }\n\n const append = async (message: ModelMessage | UIMessage<TTools>) => {\n await client().append(message)\n }\n\n const reload = async () => {\n await client().reload()\n }\n\n const stop = () => {\n client().stop()\n }\n\n const clear = () => {\n client().clear()\n }\n\n const setMessagesManually = (newMessages: Array<UIMessage<TTools>>) => {\n client().setMessagesManually(newMessages)\n }\n\n const addToolResult = 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\n const addToolApprovalResponse = async (response: {\n id: string\n approved: boolean\n }) => {\n await client().addToolApprovalResponse(response)\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"],"mappings":";;;;AAkBA,SAAgB,QACd,UAAkC,EAAE,EACb;CACvB,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,UAAU,eAAe,aAC9B,QAAQ,mBAAmB,EAAE,CAC9B;CACD,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAA8B,QAAQ;CAClE,MAAM,CAAC,cAAc,mBAAmB,aAAa,MAAM;CAC3D,MAAM,CAAC,kBAAkB,uBACvB,aAA+B,eAAe;CAChD,MAAM,CAAC,mBAAmB,wBAAwB,aAAa,MAAM;CAMrE,MAAM,SAAS,iBAAiB;AAC9B,SAAO,IAAI,WAAW;GACpB,YAAY,QAAQ;GACpB,IAAI;GACJ,iBAAiB,QAAQ;GACzB,MAAM,QAAQ;GACd,YAAY,QAAQ;GACpB,SAAS,QAAQ;GACjB,WAAW,YAAY;AACrB,YAAQ,WAAW,QAAQ;;GAE7B,UAAU,QAAQ;AAChB,YAAQ,UAAU,IAAI;;GAExB,OAAO,QAAQ;GACf,eAAe,QAAQ;GACvB,iBAAiB,QAAQ;GACzB,mBAAmB,gBAA0C;AAC3D,gBAAY,YAAY;;GAE1B,kBAAkB,iBAA0B;AAC1C,iBAAa,aAAa;;GAE5B,iBAAiB,cAA+B;AAC9C,cAAU,UAAU;;GAEtB,gBAAgB,aAAgC;AAC9C,aAAS,SAAS;;GAEpB,uBAAuB,qBAA8B;AACnD,oBAAgB,iBAAiB;;GAEnC,2BAA2B,eAAiC;AAC1D,wBAAoB,WAAW;;GAEjC,4BAA4B,iBAA0B;AACpD,yBAAqB,aAAa;;GAErC,CAAC;IAGD,CAAC,SAAS,CAAC;AAId,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAKF,oBAAmB;AACjB,MAAI,QAAQ,mBAAmB,QAAQ,gBAAgB,SAAS,GAE9D;OAAI,UAAU,CAAC,WAAW,EACxB,SAAQ,CAAC,oBAAoB,QAAQ,gBAAgB;;GAGzD;AAGF,KAAI,QAAQ,KACV,SAAQ,CAAC,WAAW;KAEpB,SAAQ,CAAC,aAAa;AAGxB,oBAAmB;AACjB,MAAI,QAAQ,KACV,SAAQ,CAAC,WAAW;MAEpB,SAAQ,CAAC,aAAa;GAExB;AAGF,iBAAgB;AACd,MAAI,QAAQ,KACV,SAAQ,CAAC,aAAa;MAEtB,SAAQ,CAAC,MAAM;GAEjB;CAMF,MAAM,cAAc,OAAO,YAAwC;AACjE,QAAM,QAAQ,CAAC,YAAY,QAAQ;;CAGrC,MAAM,SAAS,OAAO,YAA8C;AAClE,QAAM,QAAQ,CAAC,OAAO,QAAQ;;CAGhC,MAAM,SAAS,YAAY;AACzB,QAAM,QAAQ,CAAC,QAAQ;;CAGzB,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;CAGlB,MAAM,uBAAuB,gBAA0C;AACrE,UAAQ,CAAC,oBAAoB,YAAY;;CAG3C,MAAM,gBAAgB,OAAO,WAMvB;AACJ,QAAM,QAAQ,CAAC,cAAc,OAAO;;CAGtC,MAAM,0BAA0B,OAAO,aAGjC;AACJ,QAAM,QAAQ,CAAC,wBAAwB,SAAS;;AAGlD,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACD"}
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput, InferGenerationOutput } from "@tanstack/ai-client";
2
+ import { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput, InferGenerationOutput } from "@tanstack/ai-client";
3
3
  import { ImageGenerationResult, StreamChunk } from "@tanstack/ai";
4
4
 
5
5
  //#region src/use-generate-image.d.ts
@@ -10,13 +10,13 @@ import { ImageGenerationResult, StreamChunk } from "@tanstack/ai";
10
10
  * @template TOutput - The transformed output type (defaults to ImageGenerationResult)
11
11
  */
12
12
  interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {
13
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectionAdapter;
13
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
+ connection?: ConnectConnectionAdapter;
15
15
  /** Direct async function for image generation */
16
16
  fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>;
17
17
  /** Unique identifier for this generation instance */
18
18
  id?: string;
19
- /** Additional body parameters to send with ConnectionAdapter requests */
19
+ /** Additional body parameters to send with connect-based adapter requests */
20
20
  body?: Record<string, any>;
21
21
  /**
22
22
  * Callback when images are generated. Can optionally return a transformed value.
@@ -30,7 +30,7 @@ interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {
30
30
  onError?: (error: Error) => void;
31
31
  /** Callback when progress is reported (0-100) */
32
32
  onProgress?: (progress: number, message?: string) => void;
33
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
33
+ /** Callback for each stream chunk (connect-based adapter mode only) */
34
34
  onChunk?: (chunk: StreamChunk) => void;
35
35
  }
36
36
  /**
@@ -58,7 +58,7 @@ interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {
58
58
  * Solid hook for generating images using AI models.
59
59
  *
60
60
  * Supports two transport modes:
61
- * - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
61
+ * - **ConnectConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
62
62
  * - **Fetcher** -- Direct async function call
63
63
  *
64
64
  * @example
@@ -5,7 +5,7 @@ import { useGeneration } from "./use-generation.js";
5
5
  * Solid hook for generating images using AI models.
6
6
  *
7
7
  * Supports two transport modes:
8
- * - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
8
+ * - **ConnectConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
9
9
  * - **Fetcher** -- Direct async function call
10
10
  *
11
11
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"use-generate-image.js","names":[],"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'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateImage hook.\n *\n * @template TOutput - The transformed output type (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 transformed output type (defaults to ImageGenerationResult)\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: Accessor<TOutput | null>\n /** Whether generation is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid 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-solid'\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 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,iBAId,SAKA;CACA,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAoE,QAAQ;AAE9E,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-generate-image.js","names":[],"sources":["../src/use-generate-image.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { ImageGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n ImageGenerateInput,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateImage hook.\n *\n * @template TOutput - The transformed output type (defaults to ImageGenerationResult)\n */\nexport interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\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 connect-based adapter 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 (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateImage hook.\n *\n * @template TOutput - The transformed output type (defaults to ImageGenerationResult)\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: Accessor<TOutput | null>\n /** Whether generation is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for generating images 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 { useGenerateImage } from '@tanstack/ai-solid'\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 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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,iBAId,SAKA;CACA,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAoE,QAAQ;AAE9E,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SpeechGenerateInput } from "@tanstack/ai-client";
2
+ import { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SpeechGenerateInput } from "@tanstack/ai-client";
3
3
  import { StreamChunk, TTSResult } from "@tanstack/ai";
4
4
 
5
5
  //#region src/use-generate-speech.d.ts
@@ -10,13 +10,13 @@ import { StreamChunk, TTSResult } from "@tanstack/ai";
10
10
  * @template TOutput - The transformed output type (defaults to TTSResult)
11
11
  */
12
12
  interface UseGenerateSpeechOptions<TOutput = TTSResult> {
13
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectionAdapter;
13
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
+ connection?: ConnectConnectionAdapter;
15
15
  /** Direct async function for speech generation */
16
16
  fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>;
17
17
  /** Unique identifier for this generation instance */
18
18
  id?: string;
19
- /** Additional body parameters to send with ConnectionAdapter requests */
19
+ /** Additional body parameters to send with connect-based adapter requests */
20
20
  body?: Record<string, any>;
21
21
  /**
22
22
  * Callback when speech is generated. Can optionally return a transformed value.
@@ -30,7 +30,7 @@ interface UseGenerateSpeechOptions<TOutput = TTSResult> {
30
30
  onError?: (error: Error) => void;
31
31
  /** Callback when progress is reported (0-100) */
32
32
  onProgress?: (progress: number, message?: string) => void;
33
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
33
+ /** Callback for each stream chunk (connect-based adapter mode only) */
34
34
  onChunk?: (chunk: StreamChunk) => void;
35
35
  }
36
36
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"use-generate-speech.js","names":[],"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'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateSpeech hook.\n *\n * @template TOutput - The transformed output type (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 transformed output type (defaults to TTSResult)\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: Accessor<TOutput | null>\n /** Whether generation is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for generating speech (text-to-speech) using AI models.\n *\n * @example\n * ```tsx\n * import { useGenerateSpeech } from '@tanstack/ai-solid'\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,kBAGd,SAGsE;CACtE,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAyD,QAAQ;AAEnE,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-generate-speech.js","names":[],"sources":["../src/use-generate-speech.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, TTSResult } from '@tanstack/ai'\nimport type {\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n SpeechGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateSpeech hook.\n *\n * @template TOutput - The transformed output type (defaults to TTSResult)\n */\nexport interface UseGenerateSpeechOptions<TOutput = TTSResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\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 connect-based adapter 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 (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateSpeech hook.\n *\n * @template TOutput - The transformed output type (defaults to TTSResult)\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: Accessor<TOutput | null>\n /** Whether generation is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for generating speech (text-to-speech) using AI models.\n *\n * @example\n * ```tsx\n * import { useGenerateSpeech } from '@tanstack/ai-solid'\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,kBAGd,SAGsE;CACtE,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAyD,QAAQ;AAEnE,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from "@tanstack/ai-client";
2
+ import { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo } from "@tanstack/ai-client";
3
3
  import { StreamChunk } from "@tanstack/ai";
4
4
 
5
5
  //#region src/use-generate-video.d.ts
@@ -10,13 +10,13 @@ import { StreamChunk } from "@tanstack/ai";
10
10
  * @template TOutput - The transformed output type (defaults to VideoGenerateResult)
11
11
  */
12
12
  interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {
13
- /** Connection adapter for streaming transport (server handles polling) */
14
- connection?: ConnectionAdapter;
13
+ /** Connect-based adapter for streaming transport (server handles polling) */
14
+ connection?: ConnectConnectionAdapter;
15
15
  /** Direct async function that returns a completed video result */
16
16
  fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>;
17
17
  /** Unique identifier for this generation instance */
18
18
  id?: string;
19
- /** Additional body parameters to send with ConnectionAdapter requests */
19
+ /** Additional body parameters to send with connect-based adapter requests */
20
20
  body?: Record<string, any>;
21
21
  /**
22
22
  * Callback when video generation completes. Can optionally return a transformed value.
@@ -34,7 +34,7 @@ interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {
34
34
  onJobCreated?: (jobId: string) => void;
35
35
  /** Callback on each status update */
36
36
  onStatusUpdate?: (status: VideoStatusInfo) => void;
37
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
38
  onChunk?: (chunk: StreamChunk) => void;
39
39
  }
40
40
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"use-generate-video.js","names":[],"sources":["../src/use-generate-video.ts"],"sourcesContent":["import { VideoGenerationClient } from '@tanstack/ai-client'\nimport {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n} from 'solid-js'\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'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateVideo hook.\n *\n * @template TOutput - The transformed output type (defaults to VideoGenerateResult)\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 transformed output type (defaults to VideoGenerateResult)\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: Accessor<TOutput | null>\n /** The current job ID, or null */\n jobId: Accessor<string | null>\n /** Current video generation status info, or null */\n videoStatus: Accessor<VideoStatusInfo | null>\n /** Whether generation/polling is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<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 * Solid 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-solid'\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 = createUniqueId()\n const clientId = options.id || hookId\n\n const [result, setResult] = createSignal<TOutput | null>(null)\n const [jobId, setJobId] = createSignal<string | null>(null)\n const [videoStatus, setVideoStatus] = createSignal<VideoStatusInfo | null>(\n null,\n )\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<GenerationClientState>('idle')\n\n const client = createMemo(() => {\n const baseOptions = {\n id: clientId,\n body: options.body,\n onResult: (r: VideoGenerateResult) => options.onResult?.(r),\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onJobCreated: (id: string) => options.onJobCreated?.(id),\n onStatusUpdate: (s: VideoStatusInfo) => options.onStatusUpdate?.(s),\n onResultChange: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n onJobIdChange: setJobId,\n onVideoStatusChange: setVideoStatus,\n }\n\n if (options.connection) {\n return new VideoGenerationClient<TOutput>({\n ...baseOptions,\n connection: options.connection,\n })\n }\n\n if (options.fetcher) {\n return new VideoGenerationClient<TOutput>({\n ...baseOptions,\n fetcher: options.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 createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\n\n // Cleanup on unmount: stop any in-flight requests\n createEffect(() => {\n return () => {\n client().stop()\n }\n })\n\n const generate = async (input: VideoGenerateInput) => {\n await client().generate(input)\n }\n\n const stop = () => {\n client().stop()\n }\n\n const reset = () => {\n client().reset()\n }\n\n return {\n generate,\n result,\n jobId,\n videoStatus,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8GA,SAAgB,iBAId,SAKA;CAEA,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,QAAQ,aAAa,aAA6B,KAAK;CAC9D,MAAM,CAAC,OAAO,YAAY,aAA4B,KAAK;CAC3D,MAAM,CAAC,aAAa,kBAAkB,aACpC,KACD;CACD,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAAoC,OAAO;CAEvE,MAAM,SAAS,iBAAiB;EAC9B,MAAM,cAAc;GAClB,IAAI;GACJ,MAAM,QAAQ;GACd,WAAW,MAA2B,QAAQ,WAAW,EAAE;GAC3D,UAAU,MAAa,QAAQ,UAAU,EAAE;GAC3C,aAAa,GAAW,MAAe,QAAQ,aAAa,GAAG,EAAE;GACjE,UAAU,MAAmB,QAAQ,UAAU,EAAE;GACjD,eAAe,OAAe,QAAQ,eAAe,GAAG;GACxD,iBAAiB,MAAuB,QAAQ,iBAAiB,EAAE;GACnE,gBAAgB;GAChB,iBAAiB;GACjB,eAAe;GACf,gBAAgB;GAChB,eAAe;GACf,qBAAqB;GACtB;AAED,MAAI,QAAQ,WACV,QAAO,IAAI,sBAA+B;GACxC,GAAG;GACH,YAAY,QAAQ;GACrB,CAAC;AAGJ,MAAI,QAAQ,QACV,QAAO,IAAI,sBAA+B;GACxC,GAAG;GACH,SAAS,QAAQ;GAClB,CAAC;AAGJ,QAAM,IAAI,MACR,kEACD;IACA,CAAC,SAAS,CAAC;AAGd,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAGF,oBAAmB;AACjB,eAAa;AACX,WAAQ,CAAC,MAAM;;GAEjB;CAEF,MAAM,WAAW,OAAO,UAA8B;AACpD,QAAM,QAAQ,CAAC,SAAS,MAAM;;CAGhC,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;AAGlB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-generate-video.js","names":[],"sources":["../src/use-generate-video.ts"],"sourcesContent":["import { VideoGenerationClient } from '@tanstack/ai-client'\nimport {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n} from 'solid-js'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n VideoGenerateInput,\n VideoGenerateResult,\n VideoStatusInfo,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateVideo hook.\n *\n * @template TOutput - The transformed output type (defaults to VideoGenerateResult)\n */\nexport interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {\n /** Connect-based adapter for streaming transport (server handles polling) */\n connection?: ConnectConnectionAdapter\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 connect-based adapter 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 (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateVideo hook.\n *\n * @template TOutput - The transformed output type (defaults to VideoGenerateResult)\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: Accessor<TOutput | null>\n /** The current job ID, or null */\n jobId: Accessor<string | null>\n /** Current video generation status info, or null */\n videoStatus: Accessor<VideoStatusInfo | null>\n /** Whether generation/polling is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<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 * Solid 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-solid'\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 = createUniqueId()\n const clientId = options.id || hookId\n\n const [result, setResult] = createSignal<TOutput | null>(null)\n const [jobId, setJobId] = createSignal<string | null>(null)\n const [videoStatus, setVideoStatus] = createSignal<VideoStatusInfo | null>(\n null,\n )\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<GenerationClientState>('idle')\n\n const client = createMemo(() => {\n const baseOptions = {\n id: clientId,\n body: options.body,\n onResult: (r: VideoGenerateResult) => options.onResult?.(r),\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onJobCreated: (id: string) => options.onJobCreated?.(id),\n onStatusUpdate: (s: VideoStatusInfo) => options.onStatusUpdate?.(s),\n onResultChange: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n onJobIdChange: setJobId,\n onVideoStatusChange: setVideoStatus,\n }\n\n if (options.connection) {\n return new VideoGenerationClient<TOutput>({\n ...baseOptions,\n connection: options.connection,\n })\n }\n\n if (options.fetcher) {\n return new VideoGenerationClient<TOutput>({\n ...baseOptions,\n fetcher: options.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 createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\n\n // Cleanup on unmount: stop any in-flight requests\n createEffect(() => {\n return () => {\n client().stop()\n }\n })\n\n const generate = async (input: VideoGenerateInput) => {\n await client().generate(input)\n }\n\n const stop = () => {\n client().stop()\n }\n\n const reset = () => {\n client().reset()\n }\n\n return {\n generate,\n result,\n jobId,\n videoStatus,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8GA,SAAgB,iBAId,SAKA;CAEA,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,QAAQ,aAAa,aAA6B,KAAK;CAC9D,MAAM,CAAC,OAAO,YAAY,aAA4B,KAAK;CAC3D,MAAM,CAAC,aAAa,kBAAkB,aACpC,KACD;CACD,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAAoC,OAAO;CAEvE,MAAM,SAAS,iBAAiB;EAC9B,MAAM,cAAc;GAClB,IAAI;GACJ,MAAM,QAAQ;GACd,WAAW,MAA2B,QAAQ,WAAW,EAAE;GAC3D,UAAU,MAAa,QAAQ,UAAU,EAAE;GAC3C,aAAa,GAAW,MAAe,QAAQ,aAAa,GAAG,EAAE;GACjE,UAAU,MAAmB,QAAQ,UAAU,EAAE;GACjD,eAAe,OAAe,QAAQ,eAAe,GAAG;GACxD,iBAAiB,MAAuB,QAAQ,iBAAiB,EAAE;GACnE,gBAAgB;GAChB,iBAAiB;GACjB,eAAe;GACf,gBAAgB;GAChB,eAAe;GACf,qBAAqB;GACtB;AAED,MAAI,QAAQ,WACV,QAAO,IAAI,sBAA+B;GACxC,GAAG;GACH,YAAY,QAAQ;GACrB,CAAC;AAGJ,MAAI,QAAQ,QACV,QAAO,IAAI,sBAA+B;GACxC,GAAG;GACH,SAAS,QAAQ;GAClB,CAAC;AAGJ,QAAM,IAAI,MACR,kEACD;IACA,CAAC,SAAS,CAAC;AAGd,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAGF,oBAAmB;AACjB,eAAa;AACX,WAAQ,CAAC,MAAM;;GAEjB;CAEF,MAAM,WAAW,OAAO,UAA8B;AACpD,QAAM,QAAQ,CAAC,SAAS,MAAM;;CAGhC,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;AAGlB,QAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput } from "@tanstack/ai-client";
2
+ import { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput } from "@tanstack/ai-client";
3
3
  import { StreamChunk } from "@tanstack/ai";
4
4
 
5
5
  //#region src/use-generation.d.ts
@@ -14,13 +14,13 @@ import { StreamChunk } from "@tanstack/ai";
14
14
  * @template TOutput - The transformed output type (defaults to TResult)
15
15
  */
16
16
  interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
17
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
18
- connection?: ConnectionAdapter;
17
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
18
+ connection?: ConnectConnectionAdapter;
19
19
  /** Direct async function for one-shot generation (no streaming protocol needed) */
20
20
  fetcher?: GenerationFetcher<TInput, TResult>;
21
21
  /** Unique identifier for this generation instance */
22
22
  id?: string;
23
- /** Additional body parameters to send with ConnectionAdapter requests */
23
+ /** Additional body parameters to send with connect-based adapter requests */
24
24
  body?: Record<string, any>;
25
25
  /**
26
26
  * Callback when a result is received. Can optionally return a transformed value.
@@ -34,7 +34,7 @@ interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
34
34
  onError?: (error: Error) => void;
35
35
  /** Callback when progress is reported (0-100) */
36
36
  onProgress?: (progress: number, message?: string) => void;
37
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
37
+ /** Callback for each stream chunk (connect-based adapter mode only) */
38
38
  onChunk?: (chunk: StreamChunk) => void;
39
39
  }
40
40
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"use-generation.js","names":["clientOptions: GenerationClientOptions<TInput, TResult, TOutput>"],"sources":["../src/use-generation.ts"],"sourcesContent":["import { GenerationClient } from '@tanstack/ai-client'\nimport {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n} from 'solid-js'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientOptions,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\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 transformed output type (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 (possibly transformed from the raw result)\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: Accessor<TOutput | null>\n /** Whether a generation is currently in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation client */\n status: Accessor<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 Solid 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 * @template TOutput - The transformed output type (defaults to TResult)\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 = createUniqueId()\n const clientId = options.id || hookId\n\n const [result, setResult] = createSignal<TOutput | null>(null)\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<GenerationClientState>('idle')\n\n const client = createMemo(() => {\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n body: options.body,\n onResult: (r: TResult) => options.onResult?.(r),\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onResultChange: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n }\n\n if (options.connection) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n connection: options.connection,\n })\n }\n\n if (options.fetcher) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n fetcher: options.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 createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\n\n // Cleanup on unmount: stop any in-flight requests\n createEffect(() => {\n return () => {\n client().stop()\n }\n })\n\n const generate = async (input: TInput) => {\n await client().generate(input)\n }\n\n const stop = () => {\n client().stop()\n }\n\n const reset = () => {\n client().reset()\n }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,cAKd,SAGgE;CAEhE,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,QAAQ,aAAa,aAA6B,KAAK;CAC9D,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAAoC,OAAO;CAEvE,MAAM,SAAS,iBAAiB;EAC9B,MAAMA,gBAAmE;GACvE,IAAI;GACJ,MAAM,QAAQ;GACd,WAAW,MAAe,QAAQ,WAAW,EAAE;GAC/C,UAAU,MAAa,QAAQ,UAAU,EAAE;GAC3C,aAAa,GAAW,MAAe,QAAQ,aAAa,GAAG,EAAE;GACjE,UAAU,MAAmB,QAAQ,UAAU,EAAE;GACjD,gBAAgB;GAChB,iBAAiB;GACjB,eAAe;GACf,gBAAgB;GACjB;AAED,MAAI,QAAQ,WACV,QAAO,IAAI,iBAA2C;GACpD,GAAG;GACH,YAAY,QAAQ;GACrB,CAAC;AAGJ,MAAI,QAAQ,QACV,QAAO,IAAI,iBAA2C;GACpD,GAAG;GACH,SAAS,QAAQ;GAClB,CAAC;AAGJ,QAAM,IAAI,MACR,+DACD;IACA,CAAC,SAAS,CAAC;AAGd,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAGF,oBAAmB;AACjB,eAAa;AACX,WAAQ,CAAC,MAAM;;GAEjB;CAEF,MAAM,WAAW,OAAO,UAAkB;AACxC,QAAM,QAAQ,CAAC,SAAS,MAAM;;CAGhC,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;AAGlB,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-generation.js","names":["clientOptions: GenerationClientOptions<TInput, TResult, TOutput>"],"sources":["../src/use-generation.ts"],"sourcesContent":["import { GenerationClient } from '@tanstack/ai-client'\nimport {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n} from 'solid-js'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n ConnectConnectionAdapter,\n GenerationClientOptions,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\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 transformed output type (defaults to TResult)\n */\nexport interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\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 connect-based adapter 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 (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGeneration hook.\n *\n * @template TOutput - The output type (possibly transformed from the raw result)\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: Accessor<TOutput | null>\n /** Whether a generation is currently in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation client */\n status: Accessor<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 Solid 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 * @template TOutput - The transformed output type (defaults to TResult)\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 = createUniqueId()\n const clientId = options.id || hookId\n\n const [result, setResult] = createSignal<TOutput | null>(null)\n const [isLoading, setIsLoading] = createSignal(false)\n const [error, setError] = createSignal<Error | undefined>(undefined)\n const [status, setStatus] = createSignal<GenerationClientState>('idle')\n\n const client = createMemo(() => {\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n body: options.body,\n onResult: (r: TResult) => options.onResult?.(r),\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onResultChange: setResult,\n onLoadingChange: setIsLoading,\n onErrorChange: setError,\n onStatusChange: setStatus,\n }\n\n if (options.connection) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n connection: options.connection,\n })\n }\n\n if (options.fetcher) {\n return new GenerationClient<TInput, TResult, TOutput>({\n ...clientOptions,\n fetcher: options.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 createEffect(() => {\n const currentBody = options.body\n client().updateOptions({ body: currentBody })\n })\n\n // Cleanup on unmount: stop any in-flight requests\n createEffect(() => {\n return () => {\n client().stop()\n }\n })\n\n const generate = async (input: TInput) => {\n await client().generate(input)\n }\n\n const stop = () => {\n client().stop()\n }\n\n const reset = () => {\n client().reset()\n }\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6FA,SAAgB,cAKd,SAGgE;CAEhE,MAAM,SAAS,gBAAgB;CAC/B,MAAM,WAAW,QAAQ,MAAM;CAE/B,MAAM,CAAC,QAAQ,aAAa,aAA6B,KAAK;CAC9D,MAAM,CAAC,WAAW,gBAAgB,aAAa,MAAM;CACrD,MAAM,CAAC,OAAO,YAAY,aAAgC,OAAU;CACpE,MAAM,CAAC,QAAQ,aAAa,aAAoC,OAAO;CAEvE,MAAM,SAAS,iBAAiB;EAC9B,MAAMA,gBAAmE;GACvE,IAAI;GACJ,MAAM,QAAQ;GACd,WAAW,MAAe,QAAQ,WAAW,EAAE;GAC/C,UAAU,MAAa,QAAQ,UAAU,EAAE;GAC3C,aAAa,GAAW,MAAe,QAAQ,aAAa,GAAG,EAAE;GACjE,UAAU,MAAmB,QAAQ,UAAU,EAAE;GACjD,gBAAgB;GAChB,iBAAiB;GACjB,eAAe;GACf,gBAAgB;GACjB;AAED,MAAI,QAAQ,WACV,QAAO,IAAI,iBAA2C;GACpD,GAAG;GACH,YAAY,QAAQ;GACrB,CAAC;AAGJ,MAAI,QAAQ,QACV,QAAO,IAAI,iBAA2C;GACpD,GAAG;GACH,SAAS,QAAQ;GAClB,CAAC;AAGJ,QAAM,IAAI,MACR,+DACD;IACA,CAAC,SAAS,CAAC;AAGd,oBAAmB;EACjB,MAAM,cAAc,QAAQ;AAC5B,UAAQ,CAAC,cAAc,EAAE,MAAM,aAAa,CAAC;GAC7C;AAGF,oBAAmB;AACjB,eAAa;AACX,WAAQ,CAAC,MAAM;;GAEjB;CAEF,MAAM,WAAW,OAAO,UAAkB;AACxC,QAAM,QAAQ,CAAC,SAAS,MAAM;;CAGhC,MAAM,aAAa;AACjB,UAAQ,CAAC,MAAM;;CAGjB,MAAM,cAAc;AAClB,UAAQ,CAAC,OAAO;;AAGlB,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SummarizeGenerateInput } from "@tanstack/ai-client";
2
+ import { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SummarizeGenerateInput } from "@tanstack/ai-client";
3
3
  import { StreamChunk, SummarizationResult } from "@tanstack/ai";
4
4
 
5
5
  //#region src/use-summarize.d.ts
@@ -10,13 +10,13 @@ import { StreamChunk, SummarizationResult } from "@tanstack/ai";
10
10
  * @template TOutput - The transformed output type (defaults to SummarizationResult)
11
11
  */
12
12
  interface UseSummarizeOptions<TOutput = SummarizationResult> {
13
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectionAdapter;
13
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
+ connection?: ConnectConnectionAdapter;
15
15
  /** Direct async function for summarization */
16
16
  fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>;
17
17
  /** Unique identifier for this generation instance */
18
18
  id?: string;
19
- /** Additional body parameters to send with ConnectionAdapter requests */
19
+ /** Additional body parameters to send with connect-based adapter requests */
20
20
  body?: Record<string, any>;
21
21
  /**
22
22
  * Callback when summarization is complete. Can optionally return a transformed value.
@@ -30,7 +30,7 @@ interface UseSummarizeOptions<TOutput = SummarizationResult> {
30
30
  onError?: (error: Error) => void;
31
31
  /** Callback when progress is reported (0-100) */
32
32
  onProgress?: (progress: number, message?: string) => void;
33
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
33
+ /** Callback for each stream chunk (connect-based adapter mode only) */
34
34
  onChunk?: (chunk: StreamChunk) => void;
35
35
  }
36
36
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"use-summarize.js","names":[],"sources":["../src/use-summarize.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, SummarizationResult } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n SummarizeGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useSummarize hook.\n *\n * @template TOutput - The transformed output type (defaults to SummarizationResult)\n */\nexport interface UseSummarizeOptions<TOutput = SummarizationResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for summarization */\n fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>\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 summarization is complete. 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: SummarizationResult) => 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 useSummarize hook.\n *\n * @template TOutput - The transformed output type (defaults to SummarizationResult)\n */\nexport interface UseSummarizeReturn<TOutput = SummarizationResult> {\n /** Trigger summarization */\n generate: (input: SummarizeGenerateInput) => Promise<void>\n /** The summarization result, or null */\n result: Accessor<TOutput | null>\n /** Whether summarization is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current summarization */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for summarizing text using AI models.\n *\n * @example\n * ```tsx\n * import { useSummarize } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function Summarizer() {\n * const { generate, result, isLoading } = useSummarize({\n * connection: fetchServerSentEvents('/api/summarize'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({\n * text: 'Long article text...',\n * style: 'bullet-points',\n * maxLength: 200,\n * })}>\n * Summarize\n * </button>\n * {isLoading() && <p>Summarizing...</p>}\n * {result() && <p>{result()!.summary}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useSummarize<\n TOnResult extends ((result: SummarizationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseSummarizeOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseSummarizeReturn<InferGenerationOutput<SummarizationResult, TOnResult>> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<SummarizeGenerateInput, SummarizationResult, TOnResult>(\n options,\n )\n\n return {\n generate: generate as (input: SummarizeGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,aAId,SAG2E;CAC3E,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cACE,QACD;AAEH,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-summarize.js","names":[],"sources":["../src/use-summarize.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, SummarizationResult } from '@tanstack/ai'\nimport type {\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n SummarizeGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useSummarize hook.\n *\n * @template TOutput - The transformed output type (defaults to SummarizationResult)\n */\nexport interface UseSummarizeOptions<TOutput = SummarizationResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for summarization */\n fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>\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 summarization is complete. 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: SummarizationResult) => 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 useSummarize hook.\n *\n * @template TOutput - The transformed output type (defaults to SummarizationResult)\n */\nexport interface UseSummarizeReturn<TOutput = SummarizationResult> {\n /** Trigger summarization */\n generate: (input: SummarizeGenerateInput) => Promise<void>\n /** The summarization result, or null */\n result: Accessor<TOutput | null>\n /** Whether summarization is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current summarization */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for summarizing text using AI models.\n *\n * @example\n * ```tsx\n * import { useSummarize } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function Summarizer() {\n * const { generate, result, isLoading } = useSummarize({\n * connection: fetchServerSentEvents('/api/summarize'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({\n * text: 'Long article text...',\n * style: 'bullet-points',\n * maxLength: 200,\n * })}>\n * Summarize\n * </button>\n * {isLoading() && <p>Summarizing...</p>}\n * {result() && <p>{result()!.summary}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useSummarize<\n TOnResult extends ((result: SummarizationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseSummarizeOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseSummarizeReturn<InferGenerationOutput<SummarizationResult, TOnResult>> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<SummarizeGenerateInput, SummarizationResult, TOnResult>(\n options,\n )\n\n return {\n generate: generate as (input: SummarizeGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,aAId,SAG2E;CAC3E,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cACE,QACD;AAEH,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,5 +1,5 @@
1
1
  import { Accessor } from "solid-js";
2
- import { ConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, TranscriptionGenerateInput } from "@tanstack/ai-client";
2
+ import { ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, TranscriptionGenerateInput } from "@tanstack/ai-client";
3
3
  import { StreamChunk, TranscriptionResult } from "@tanstack/ai";
4
4
 
5
5
  //#region src/use-transcription.d.ts
@@ -10,13 +10,13 @@ import { StreamChunk, TranscriptionResult } from "@tanstack/ai";
10
10
  * @template TOutput - The transformed output type (defaults to TranscriptionResult)
11
11
  */
12
12
  interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
13
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectionAdapter;
13
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
+ connection?: ConnectConnectionAdapter;
15
15
  /** Direct async function for transcription */
16
16
  fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>;
17
17
  /** Unique identifier for this generation instance */
18
18
  id?: string;
19
- /** Additional body parameters to send with ConnectionAdapter requests */
19
+ /** Additional body parameters to send with connect-based adapter requests */
20
20
  body?: Record<string, any>;
21
21
  /**
22
22
  * Callback when transcription is complete. Can optionally return a transformed value.
@@ -30,7 +30,7 @@ interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
30
30
  onError?: (error: Error) => void;
31
31
  /** Callback when progress is reported (0-100) */
32
32
  onProgress?: (progress: number, message?: string) => void;
33
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
33
+ /** Callback for each stream chunk (connect-based adapter mode only) */
34
34
  onChunk?: (chunk: StreamChunk) => void;
35
35
  }
36
36
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"use-transcription.js","names":[],"sources":["../src/use-transcription.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, TranscriptionResult } from '@tanstack/ai'\nimport type {\n ConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n TranscriptionGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useTranscription hook.\n *\n * @template TOutput - The transformed output type (defaults to TranscriptionResult)\n */\nexport interface UseTranscriptionOptions<TOutput = TranscriptionResult> {\n /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectionAdapter\n /** Direct async function for transcription */\n fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>\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 transcription is complete. 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: TranscriptionResult) => 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 useTranscription hook.\n *\n * @template TOutput - The transformed output type (defaults to TranscriptionResult)\n */\nexport interface UseTranscriptionReturn<TOutput = TranscriptionResult> {\n /** Trigger transcription */\n generate: (input: TranscriptionGenerateInput) => Promise<void>\n /** The transcription result, or null */\n result: Accessor<TOutput | null>\n /** Whether transcription is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current transcription */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for transcribing audio to text using AI models.\n *\n * @example\n * ```tsx\n * import { useTranscription } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function Transcriber() {\n * const { generate, result, isLoading } = useTranscription({\n * connection: fetchServerSentEvents('/api/transcribe'),\n * })\n *\n * const handleFile = (e: Event) => {\n * const input = e.target as HTMLInputElement\n * const file = input.files?.[0]\n * if (file) {\n * const reader = new FileReader()\n * reader.onload = () => {\n * generate({ audio: reader.result as string, language: 'en' })\n * }\n * reader.readAsDataURL(file)\n * }\n * }\n *\n * return (\n * <div>\n * <input type=\"file\" accept=\"audio/*\" onChange={handleFile} />\n * {isLoading() && <p>Transcribing...</p>}\n * {result() && <p>{result()!.text}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useTranscription<\n TOnResult extends ((result: TranscriptionResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseTranscriptionOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseTranscriptionReturn<\n InferGenerationOutput<TranscriptionResult, TOnResult>\n> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<TranscriptionGenerateInput, TranscriptionResult, TOnResult>(\n options,\n )\n\n return {\n generate: generate as (input: TranscriptionGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,iBAId,SAKA;CACA,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cACE,QACD;AAEH,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"use-transcription.js","names":[],"sources":["../src/use-transcription.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { StreamChunk, TranscriptionResult } from '@tanstack/ai'\nimport type {\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n TranscriptionGenerateInput,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useTranscription hook.\n *\n * @template TOutput - The transformed output type (defaults to TranscriptionResult)\n */\nexport interface UseTranscriptionOptions<TOutput = TranscriptionResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for transcription */\n fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>\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 transcription is complete. 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: TranscriptionResult) => 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 useTranscription hook.\n *\n * @template TOutput - The transformed output type (defaults to TranscriptionResult)\n */\nexport interface UseTranscriptionReturn<TOutput = TranscriptionResult> {\n /** Trigger transcription */\n generate: (input: TranscriptionGenerateInput) => Promise<void>\n /** The transcription result, or null */\n result: Accessor<TOutput | null>\n /** Whether transcription is in progress */\n isLoading: Accessor<boolean>\n /** Current error, if any */\n error: Accessor<Error | undefined>\n /** Current state of the generation */\n status: Accessor<GenerationClientState>\n /** Abort the current transcription */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Solid hook for transcribing audio to text using AI models.\n *\n * @example\n * ```tsx\n * import { useTranscription } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function Transcriber() {\n * const { generate, result, isLoading } = useTranscription({\n * connection: fetchServerSentEvents('/api/transcribe'),\n * })\n *\n * const handleFile = (e: Event) => {\n * const input = e.target as HTMLInputElement\n * const file = input.files?.[0]\n * if (file) {\n * const reader = new FileReader()\n * reader.onload = () => {\n * generate({ audio: reader.result as string, language: 'en' })\n * }\n * reader.readAsDataURL(file)\n * }\n * }\n *\n * return (\n * <div>\n * <input type=\"file\" accept=\"audio/*\" onChange={handleFile} />\n * {isLoading() && <p>Transcribing...</p>}\n * {result() && <p>{result()!.text}</p>}\n * </div>\n * )\n * }\n * ```\n */\nexport function useTranscription<\n TOnResult extends ((result: TranscriptionResult) => any) | undefined =\n undefined,\n>(\n options: Omit<UseTranscriptionOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): UseTranscriptionReturn<\n InferGenerationOutput<TranscriptionResult, TOnResult>\n> {\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<TranscriptionGenerateInput, TranscriptionResult, TOnResult>(\n options,\n )\n\n return {\n generate: generate as (input: TranscriptionGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,iBAId,SAKA;CACA,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cACE,QACD;AAEH,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-solid",
3
- "version": "0.6.6",
3
+ "version": "0.6.9",
4
4
  "description": "Solid hooks for TanStack AI",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -31,11 +31,11 @@
31
31
  "streaming"
32
32
  ],
33
33
  "dependencies": {
34
- "@tanstack/ai-client": "0.7.1"
34
+ "@tanstack/ai-client": "0.7.4"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "solid-js": ">=1.9.10",
38
- "@tanstack/ai": "^0.8.0"
38
+ "@tanstack/ai": "^0.9.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@solidjs/testing-library": "^0.8.10",
@@ -46,7 +46,7 @@
46
46
  "tsdown": "^0.17.0-beta.6",
47
47
  "typescript": "5.9.3",
48
48
  "vitest": "^4.0.14",
49
- "@tanstack/ai": "0.8.0"
49
+ "@tanstack/ai": "0.9.1"
50
50
  },
51
51
  "scripts": {
52
52
  "clean": "premove ./build ./dist",
package/src/types.ts CHANGED
@@ -3,6 +3,7 @@ import type {
3
3
  ChatClientOptions,
4
4
  ChatClientState,
5
5
  ChatRequestBody,
6
+ ConnectionStatus,
6
7
  MultimodalContent,
7
8
  UIMessage,
8
9
  } from '@tanstack/ai-client'
@@ -30,8 +31,16 @@ export type { ChatRequestBody, MultimodalContent, UIMessage }
30
31
  export type UseChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any> =
31
32
  Omit<
32
33
  ChatClientOptions<TTools>,
33
- 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange'
34
- >
34
+ | 'onMessagesChange'
35
+ | 'onLoadingChange'
36
+ | 'onErrorChange'
37
+ | 'onStatusChange'
38
+ | 'onSubscriptionChange'
39
+ | 'onConnectionStatusChange'
40
+ | 'onSessionGeneratingChange'
41
+ > & {
42
+ live?: boolean
43
+ }
35
44
 
36
45
  export interface UseChatReturn<
37
46
  TTools extends ReadonlyArray<AnyClientTool> = any,
@@ -105,6 +114,24 @@ export interface UseChatReturn<
105
114
  * Current generation status
106
115
  */
107
116
  status: Accessor<ChatClientState>
117
+
118
+ /**
119
+ * Whether the subscription loop is currently active
120
+ */
121
+ isSubscribed: Accessor<boolean>
122
+
123
+ /**
124
+ * Current connection lifecycle status
125
+ */
126
+ connectionStatus: Accessor<ConnectionStatus>
127
+
128
+ /**
129
+ * Whether the shared session is actively generating.
130
+ * Derived from stream run events (RUN_STARTED / RUN_FINISHED / RUN_ERROR).
131
+ * Unlike `isLoading` (request-local), this reflects shared generation
132
+ * activity visible to all subscribers (e.g. across tabs/devices).
133
+ */
134
+ sessionGenerating: Accessor<boolean>
108
135
  }
109
136
 
110
137
  // Note: createChatClientOptions and InferChatMessages are now in @tanstack/ai-client
package/src/use-chat.ts CHANGED
@@ -3,10 +3,11 @@ import {
3
3
  createMemo,
4
4
  createSignal,
5
5
  createUniqueId,
6
+ onCleanup,
6
7
  } from 'solid-js'
7
8
 
8
9
  import { ChatClient } from '@tanstack/ai-client'
9
- import type { ChatClientState } from '@tanstack/ai-client'
10
+ import type { ChatClientState, ConnectionStatus } from '@tanstack/ai-client'
10
11
  import type { AnyClientTool, ModelMessage } from '@tanstack/ai'
11
12
  import type {
12
13
  MultimodalContent,
@@ -27,6 +28,10 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
27
28
  const [isLoading, setIsLoading] = createSignal(false)
28
29
  const [error, setError] = createSignal<Error | undefined>(undefined)
29
30
  const [status, setStatus] = createSignal<ChatClientState>('ready')
31
+ const [isSubscribed, setIsSubscribed] = createSignal(false)
32
+ const [connectionStatus, setConnectionStatus] =
33
+ createSignal<ConnectionStatus>('disconnected')
34
+ const [sessionGenerating, setSessionGenerating] = createSignal(false)
30
35
 
31
36
  // Create ChatClient instance with callbacks to sync state
32
37
  // Note: Options are captured at client creation time.
@@ -61,6 +66,15 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
61
66
  onErrorChange: (newError: Error | undefined) => {
62
67
  setError(newError)
63
68
  },
69
+ onSubscriptionChange: (nextIsSubscribed: boolean) => {
70
+ setIsSubscribed(nextIsSubscribed)
71
+ },
72
+ onConnectionStatusChange: (nextStatus: ConnectionStatus) => {
73
+ setConnectionStatus(nextStatus)
74
+ },
75
+ onSessionGeneratingChange: (isGenerating: boolean) => {
76
+ setSessionGenerating(isGenerating)
77
+ },
64
78
  })
65
79
  // Only recreate when clientId changes
66
80
  // Connection and other options are captured at creation time
@@ -85,12 +99,26 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
85
99
  }
86
100
  }) // Only run on mount - initialMessages are handled by ChatClient constructor
87
101
 
88
- // Cleanup on unmount: stop any in-flight requests
89
- // Note: We use createEffect with a cleanup return to handle component unmount.
90
- // The cleanup only runs on disposal (unmount), not on signal changes.
102
+ // Apply initial live mode immediately on hook creation.
103
+ if (options.live) {
104
+ client().subscribe()
105
+ } else {
106
+ client().unsubscribe()
107
+ }
108
+
91
109
  createEffect(() => {
92
- return () => {
93
- // Stop any active generation when component unmounts
110
+ if (options.live) {
111
+ client().subscribe()
112
+ } else {
113
+ client().unsubscribe()
114
+ }
115
+ })
116
+
117
+ // Cleanup on unmount: stop any in-flight requests.
118
+ onCleanup(() => {
119
+ if (options.live) {
120
+ client().unsubscribe()
121
+ } else {
94
122
  client().stop()
95
123
  }
96
124
  })
@@ -149,6 +177,9 @@ export function useChat<TTools extends ReadonlyArray<AnyClientTool> = any>(
149
177
  isLoading,
150
178
  error,
151
179
  status,
180
+ isSubscribed,
181
+ connectionStatus,
182
+ sessionGenerating,
152
183
  setMessages: setMessagesManually,
153
184
  clear,
154
185
  addToolResult,
@@ -1,7 +1,7 @@
1
1
  import { useGeneration } from './use-generation'
2
2
  import type { ImageGenerationResult, StreamChunk } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  ImageGenerateInput,
@@ -15,13 +15,13 @@ import type { Accessor } from 'solid-js'
15
15
  * @template TOutput - The transformed output type (defaults to ImageGenerationResult)
16
16
  */
17
17
  export interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {
18
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
19
- connection?: ConnectionAdapter
18
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
19
+ connection?: ConnectConnectionAdapter
20
20
  /** Direct async function for image generation */
21
21
  fetcher?: GenerationFetcher<ImageGenerateInput, ImageGenerationResult>
22
22
  /** Unique identifier for this generation instance */
23
23
  id?: string
24
- /** Additional body parameters to send with ConnectionAdapter requests */
24
+ /** Additional body parameters to send with connect-based adapter requests */
25
25
  body?: Record<string, any>
26
26
  /**
27
27
  * Callback when images are generated. Can optionally return a transformed value.
@@ -35,7 +35,7 @@ export interface UseGenerateImageOptions<TOutput = ImageGenerationResult> {
35
35
  onError?: (error: Error) => void
36
36
  /** Callback when progress is reported (0-100) */
37
37
  onProgress?: (progress: number, message?: string) => void
38
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
38
+ /** Callback for each stream chunk (connect-based adapter mode only) */
39
39
  onChunk?: (chunk: StreamChunk) => void
40
40
  }
41
41
 
@@ -65,7 +65,7 @@ export interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {
65
65
  * Solid hook for generating images using AI models.
66
66
  *
67
67
  * Supports two transport modes:
68
- * - **ConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
68
+ * - **ConnectConnectionAdapter** -- Streaming transport (SSE, HTTP stream, custom)
69
69
  * - **Fetcher** -- Direct async function call
70
70
  *
71
71
  * @example
@@ -1,7 +1,7 @@
1
1
  import { useGeneration } from './use-generation'
2
2
  import type { StreamChunk, TTSResult } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -15,13 +15,13 @@ import type { Accessor } from 'solid-js'
15
15
  * @template TOutput - The transformed output type (defaults to TTSResult)
16
16
  */
17
17
  export interface UseGenerateSpeechOptions<TOutput = TTSResult> {
18
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
19
- connection?: ConnectionAdapter
18
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
19
+ connection?: ConnectConnectionAdapter
20
20
  /** Direct async function for speech generation */
21
21
  fetcher?: GenerationFetcher<SpeechGenerateInput, TTSResult>
22
22
  /** Unique identifier for this generation instance */
23
23
  id?: string
24
- /** Additional body parameters to send with ConnectionAdapter requests */
24
+ /** Additional body parameters to send with connect-based adapter requests */
25
25
  body?: Record<string, any>
26
26
  /**
27
27
  * Callback when speech is generated. Can optionally return a transformed value.
@@ -35,7 +35,7 @@ export interface UseGenerateSpeechOptions<TOutput = TTSResult> {
35
35
  onError?: (error: Error) => void
36
36
  /** Callback when progress is reported (0-100) */
37
37
  onProgress?: (progress: number, message?: string) => void
38
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
38
+ /** Callback for each stream chunk (connect-based adapter mode only) */
39
39
  onChunk?: (chunk: StreamChunk) => void
40
40
  }
41
41
 
@@ -7,7 +7,7 @@ import {
7
7
  } from 'solid-js'
8
8
  import type { StreamChunk } from '@tanstack/ai'
9
9
  import type {
10
- ConnectionAdapter,
10
+ ConnectConnectionAdapter,
11
11
  GenerationClientState,
12
12
  GenerationFetcher,
13
13
  InferGenerationOutput,
@@ -23,13 +23,13 @@ import type { Accessor } from 'solid-js'
23
23
  * @template TOutput - The transformed output type (defaults to VideoGenerateResult)
24
24
  */
25
25
  export interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {
26
- /** Connection adapter for streaming transport (server handles polling) */
27
- connection?: ConnectionAdapter
26
+ /** Connect-based adapter for streaming transport (server handles polling) */
27
+ connection?: ConnectConnectionAdapter
28
28
  /** Direct async function that returns a completed video result */
29
29
  fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>
30
30
  /** Unique identifier for this generation instance */
31
31
  id?: string
32
- /** Additional body parameters to send with ConnectionAdapter requests */
32
+ /** Additional body parameters to send with connect-based adapter requests */
33
33
  body?: Record<string, any>
34
34
  /**
35
35
  * Callback when video generation completes. Can optionally return a transformed value.
@@ -47,7 +47,7 @@ export interface UseGenerateVideoOptions<TOutput = VideoGenerateResult> {
47
47
  onJobCreated?: (jobId: string) => void
48
48
  /** Callback on each status update */
49
49
  onStatusUpdate?: (status: VideoStatusInfo) => void
50
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
50
+ /** Callback for each stream chunk (connect-based adapter mode only) */
51
51
  onChunk?: (chunk: StreamChunk) => void
52
52
  }
53
53
 
@@ -7,7 +7,7 @@ import {
7
7
  } from 'solid-js'
8
8
  import type { StreamChunk } from '@tanstack/ai'
9
9
  import type {
10
- ConnectionAdapter,
10
+ ConnectConnectionAdapter,
11
11
  GenerationClientOptions,
12
12
  GenerationClientState,
13
13
  GenerationFetcher,
@@ -25,13 +25,13 @@ import type { Accessor } from 'solid-js'
25
25
  * @template TOutput - The transformed output type (defaults to TResult)
26
26
  */
27
27
  export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
28
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
29
- connection?: ConnectionAdapter
28
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
29
+ connection?: ConnectConnectionAdapter
30
30
  /** Direct async function for one-shot generation (no streaming protocol needed) */
31
31
  fetcher?: GenerationFetcher<TInput, TResult>
32
32
  /** Unique identifier for this generation instance */
33
33
  id?: string
34
- /** Additional body parameters to send with ConnectionAdapter requests */
34
+ /** Additional body parameters to send with connect-based adapter requests */
35
35
  body?: Record<string, any>
36
36
  /**
37
37
  * Callback when a result is received. Can optionally return a transformed value.
@@ -45,7 +45,7 @@ export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
45
45
  onError?: (error: Error) => void
46
46
  /** Callback when progress is reported (0-100) */
47
47
  onProgress?: (progress: number, message?: string) => void
48
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
48
+ /** Callback for each stream chunk (connect-based adapter mode only) */
49
49
  onChunk?: (chunk: StreamChunk) => void
50
50
  }
51
51
 
@@ -1,7 +1,7 @@
1
1
  import { useGeneration } from './use-generation'
2
2
  import type { StreamChunk, SummarizationResult } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -15,13 +15,13 @@ import type { Accessor } from 'solid-js'
15
15
  * @template TOutput - The transformed output type (defaults to SummarizationResult)
16
16
  */
17
17
  export interface UseSummarizeOptions<TOutput = SummarizationResult> {
18
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
19
- connection?: ConnectionAdapter
18
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
19
+ connection?: ConnectConnectionAdapter
20
20
  /** Direct async function for summarization */
21
21
  fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>
22
22
  /** Unique identifier for this generation instance */
23
23
  id?: string
24
- /** Additional body parameters to send with ConnectionAdapter requests */
24
+ /** Additional body parameters to send with connect-based adapter requests */
25
25
  body?: Record<string, any>
26
26
  /**
27
27
  * Callback when summarization is complete. Can optionally return a transformed value.
@@ -35,7 +35,7 @@ export interface UseSummarizeOptions<TOutput = SummarizationResult> {
35
35
  onError?: (error: Error) => void
36
36
  /** Callback when progress is reported (0-100) */
37
37
  onProgress?: (progress: number, message?: string) => void
38
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
38
+ /** Callback for each stream chunk (connect-based adapter mode only) */
39
39
  onChunk?: (chunk: StreamChunk) => void
40
40
  }
41
41
 
@@ -1,7 +1,7 @@
1
1
  import { useGeneration } from './use-generation'
2
2
  import type { StreamChunk, TranscriptionResult } from '@tanstack/ai'
3
3
  import type {
4
- ConnectionAdapter,
4
+ ConnectConnectionAdapter,
5
5
  GenerationClientState,
6
6
  GenerationFetcher,
7
7
  InferGenerationOutput,
@@ -15,13 +15,13 @@ import type { Accessor } from 'solid-js'
15
15
  * @template TOutput - The transformed output type (defaults to TranscriptionResult)
16
16
  */
17
17
  export interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
18
- /** Connection adapter for streaming transport (SSE, HTTP stream, custom) */
19
- connection?: ConnectionAdapter
18
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
19
+ connection?: ConnectConnectionAdapter
20
20
  /** Direct async function for transcription */
21
21
  fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>
22
22
  /** Unique identifier for this generation instance */
23
23
  id?: string
24
- /** Additional body parameters to send with ConnectionAdapter requests */
24
+ /** Additional body parameters to send with connect-based adapter requests */
25
25
  body?: Record<string, any>
26
26
  /**
27
27
  * Callback when transcription is complete. Can optionally return a transformed value.
@@ -35,7 +35,7 @@ export interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
35
35
  onError?: (error: Error) => void
36
36
  /** Callback when progress is reported (0-100) */
37
37
  onProgress?: (progress: number, message?: string) => void
38
- /** Callback for each stream chunk (ConnectionAdapter mode only) */
38
+ /** Callback for each stream chunk (connect-based adapter mode only) */
39
39
  onChunk?: (chunk: StreamChunk) => void
40
40
  }
41
41