@tanstack/ai-solid 0.13.13 → 0.13.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
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 { createGenerationDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n createEffect,\n createMemo,\n createSignal,\n createUniqueId,\n onCleanup,\n onMount,\n} from 'solid-js'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\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 /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\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 // Conditional spread on `body`: `GenerationClientOptions.body` is a\n // strict optional (`body?: Record<string, any>`) and EOPT forbids\n // assigning the source `T | undefined` directly.\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n body: options.body,\n devtoolsBridgeFactory: createGenerationDevtoolsBridge,\n devtools: {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useGeneration',\n },\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({\n ...(currentBody !== undefined && { body: currentBody }),\n })\n })\n\n onMount(() => {\n client().mountDevtools()\n })\n\n // Cleanup on unmount: stop any in-flight requests and unregister devtools\n onCleanup(() => {\n client().dispose()\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":";;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,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;EAI9B,MAAMA,gBAAmE;GACvE,IAAI;GACJ,MAAM,QAAQ;GACd,uBAAuB;GACvB,UAAU;IACR,GAAG,QAAQ;IACX,WAAW;IACX,UAAU;IACX;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,EACrB,GAAI,gBAAgB,UAAa,EAAE,MAAM,aAAa,EACvD,CAAC;GACF;AAEF,eAAc;AACZ,UAAQ,CAAC,eAAe;GACxB;AAGF,iBAAgB;AACd,UAAQ,CAAC,SAAS;GAClB;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,93 +0,0 @@
1
- import { Accessor } from "solid-js";
2
- import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, SummarizeGenerateInput } from "@tanstack/ai-client";
3
- import { StreamChunk, SummarizationResult } from "@tanstack/ai";
4
-
5
- //#region src/use-summarize.d.ts
6
-
7
- /**
8
- * Options for the useSummarize hook.
9
- *
10
- * @template TOutput - The transformed output type (defaults to SummarizationResult)
11
- */
12
- interface UseSummarizeOptions<TOutput = SummarizationResult> {
13
- /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectConnectionAdapter;
15
- /** Direct async function for summarization */
16
- fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>;
17
- /** Unique identifier for this generation instance */
18
- id?: string;
19
- /** Additional body parameters to send with connect-based adapter requests */
20
- body?: Record<string, any>;
21
- /** Display options for TanStack AI Devtools. */
22
- devtools?: AIDevtoolsDisplayOptions;
23
- /**
24
- * Callback when summarization is complete. Can optionally return a transformed value.
25
- *
26
- * - Return a non-null value to transform and store it as the result
27
- * - Return `null` to keep the previous result unchanged
28
- * - Return nothing (`void`) to store the raw result as-is
29
- */
30
- onResult?: (result: SummarizationResult) => TOutput | null | void;
31
- /** Callback when an error occurs */
32
- onError?: (error: Error) => void;
33
- /** Callback when progress is reported (0-100) */
34
- onProgress?: (progress: number, message?: string) => void;
35
- /** Callback for each stream chunk (connect-based adapter mode only) */
36
- onChunk?: (chunk: StreamChunk) => void;
37
- }
38
- /**
39
- * Return type for the useSummarize hook.
40
- *
41
- * @template TOutput - The transformed output type (defaults to SummarizationResult)
42
- */
43
- interface UseSummarizeReturn<TOutput = SummarizationResult> {
44
- /** Trigger summarization */
45
- generate: (input: SummarizeGenerateInput) => Promise<void>;
46
- /** The summarization result, or null */
47
- result: Accessor<TOutput | null>;
48
- /** Whether summarization is in progress */
49
- isLoading: Accessor<boolean>;
50
- /** Current error, if any */
51
- error: Accessor<Error | undefined>;
52
- /** Current state of the generation */
53
- status: Accessor<GenerationClientState>;
54
- /** Abort the current summarization */
55
- stop: () => void;
56
- /** Clear result, error, and return to idle */
57
- reset: () => void;
58
- }
59
- /**
60
- * Solid hook for summarizing text using AI models.
61
- *
62
- * @example
63
- * ```tsx
64
- * import { useSummarize } from '@tanstack/ai-solid'
65
- * import { fetchServerSentEvents } from '@tanstack/ai-client'
66
- *
67
- * function Summarizer() {
68
- * const { generate, result, isLoading } = useSummarize({
69
- * connection: fetchServerSentEvents('/api/summarize'),
70
- * })
71
- *
72
- * return (
73
- * <div>
74
- * <button onClick={() => generate({
75
- * text: 'Long article text...',
76
- * style: 'bullet-points',
77
- * maxLength: 200,
78
- * })}>
79
- * Summarize
80
- * </button>
81
- * {isLoading() && <p>Summarizing...</p>}
82
- * {result() && <p>{result()!.summary}</p>}
83
- * </div>
84
- * )
85
- * }
86
- * ```
87
- */
88
- declare function useSummarize<TOnResult extends ((result: SummarizationResult) => any) | undefined = undefined>(options: Omit<UseSummarizeOptions, 'onResult'> & {
89
- onResult?: TOnResult;
90
- }): UseSummarizeReturn<InferGenerationOutput<SummarizationResult, TOnResult>>;
91
- //#endregion
92
- export { UseSummarizeOptions, UseSummarizeReturn, useSummarize };
93
- //# sourceMappingURL=use-summarize.d.ts.map
@@ -1,57 +0,0 @@
1
- import { useGeneration } from "./use-generation.js";
2
-
3
- //#region src/use-summarize.ts
4
- /**
5
- * Solid hook for summarizing text using AI models.
6
- *
7
- * @example
8
- * ```tsx
9
- * import { useSummarize } from '@tanstack/ai-solid'
10
- * import { fetchServerSentEvents } from '@tanstack/ai-client'
11
- *
12
- * function Summarizer() {
13
- * const { generate, result, isLoading } = useSummarize({
14
- * connection: fetchServerSentEvents('/api/summarize'),
15
- * })
16
- *
17
- * return (
18
- * <div>
19
- * <button onClick={() => generate({
20
- * text: 'Long article text...',
21
- * style: 'bullet-points',
22
- * maxLength: 200,
23
- * })}>
24
- * Summarize
25
- * </button>
26
- * {isLoading() && <p>Summarizing...</p>}
27
- * {result() && <p>{result()!.summary}</p>}
28
- * </div>
29
- * )
30
- * }
31
- * ```
32
- */
33
- function useSummarize(options) {
34
- const devtools = {
35
- ...options.devtools,
36
- framework: "solid",
37
- hookName: "useSummarize",
38
- outputKind: "text"
39
- };
40
- const { generate, result, isLoading, error, status, stop, reset } = useGeneration({
41
- ...options,
42
- devtools
43
- });
44
- return {
45
- generate,
46
- result,
47
- isLoading,
48
- error,
49
- status,
50
- stop,
51
- reset
52
- };
53
- }
54
-
55
- //#endregion
56
- export { useSummarize };
57
- //# sourceMappingURL=use-summarize.js.map
@@ -1 +0,0 @@
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 AIDevtoolsDisplayOptions,\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 /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\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 devtools = {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useSummarize',\n outputKind: 'text' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<SummarizeGenerateInput, SummarizationResult, TOnResult>({\n ...options,\n devtools,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,aAId,SAG2E;CAC3E,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAsE;EACpE,GAAG;EACH;EACD,CAAC;AAEJ,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -1,99 +0,0 @@
1
- import { Accessor } from "solid-js";
2
- import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutput, TranscriptionGenerateInput } from "@tanstack/ai-client";
3
- import { StreamChunk, TranscriptionResult } from "@tanstack/ai";
4
-
5
- //#region src/use-transcription.d.ts
6
-
7
- /**
8
- * Options for the useTranscription hook.
9
- *
10
- * @template TOutput - The transformed output type (defaults to TranscriptionResult)
11
- */
12
- interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
13
- /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
14
- connection?: ConnectConnectionAdapter;
15
- /** Direct async function for transcription */
16
- fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>;
17
- /** Unique identifier for this generation instance */
18
- id?: string;
19
- /** Additional body parameters to send with connect-based adapter requests */
20
- body?: Record<string, any>;
21
- /** Display options for TanStack AI Devtools. */
22
- devtools?: AIDevtoolsDisplayOptions;
23
- /**
24
- * Callback when transcription is complete. Can optionally return a transformed value.
25
- *
26
- * - Return a non-null value to transform and store it as the result
27
- * - Return `null` to keep the previous result unchanged
28
- * - Return nothing (`void`) to store the raw result as-is
29
- */
30
- onResult?: (result: TranscriptionResult) => TOutput | null | void;
31
- /** Callback when an error occurs */
32
- onError?: (error: Error) => void;
33
- /** Callback when progress is reported (0-100) */
34
- onProgress?: (progress: number, message?: string) => void;
35
- /** Callback for each stream chunk (connect-based adapter mode only) */
36
- onChunk?: (chunk: StreamChunk) => void;
37
- }
38
- /**
39
- * Return type for the useTranscription hook.
40
- *
41
- * @template TOutput - The transformed output type (defaults to TranscriptionResult)
42
- */
43
- interface UseTranscriptionReturn<TOutput = TranscriptionResult> {
44
- /** Trigger transcription */
45
- generate: (input: TranscriptionGenerateInput) => Promise<void>;
46
- /** The transcription result, or null */
47
- result: Accessor<TOutput | null>;
48
- /** Whether transcription is in progress */
49
- isLoading: Accessor<boolean>;
50
- /** Current error, if any */
51
- error: Accessor<Error | undefined>;
52
- /** Current state of the generation */
53
- status: Accessor<GenerationClientState>;
54
- /** Abort the current transcription */
55
- stop: () => void;
56
- /** Clear result, error, and return to idle */
57
- reset: () => void;
58
- }
59
- /**
60
- * Solid hook for transcribing audio to text using AI models.
61
- *
62
- * @example
63
- * ```tsx
64
- * import { useTranscription } from '@tanstack/ai-solid'
65
- * import { fetchServerSentEvents } from '@tanstack/ai-client'
66
- *
67
- * function Transcriber() {
68
- * const { generate, result, isLoading } = useTranscription({
69
- * connection: fetchServerSentEvents('/api/transcribe'),
70
- * })
71
- *
72
- * const handleFile = (e: Event) => {
73
- * const input = e.target as HTMLInputElement
74
- * const file = input.files?.[0]
75
- * if (file) {
76
- * const reader = new FileReader()
77
- * reader.onload = () => {
78
- * generate({ audio: reader.result as string, language: 'en' })
79
- * }
80
- * reader.readAsDataURL(file)
81
- * }
82
- * }
83
- *
84
- * return (
85
- * <div>
86
- * <input type="file" accept="audio/*" onChange={handleFile} />
87
- * {isLoading() && <p>Transcribing...</p>}
88
- * {result() && <p>{result()!.text}</p>}
89
- * </div>
90
- * )
91
- * }
92
- * ```
93
- */
94
- declare function useTranscription<TOnResult extends ((result: TranscriptionResult) => any) | undefined = undefined>(options: Omit<UseTranscriptionOptions, 'onResult'> & {
95
- onResult?: TOnResult;
96
- }): UseTranscriptionReturn<InferGenerationOutput<TranscriptionResult, TOnResult>>;
97
- //#endregion
98
- export { UseTranscriptionOptions, UseTranscriptionReturn, useTranscription };
99
- //# sourceMappingURL=use-transcription.d.ts.map
@@ -1,63 +0,0 @@
1
- import { useGeneration } from "./use-generation.js";
2
-
3
- //#region src/use-transcription.ts
4
- /**
5
- * Solid hook for transcribing audio to text using AI models.
6
- *
7
- * @example
8
- * ```tsx
9
- * import { useTranscription } from '@tanstack/ai-solid'
10
- * import { fetchServerSentEvents } from '@tanstack/ai-client'
11
- *
12
- * function Transcriber() {
13
- * const { generate, result, isLoading } = useTranscription({
14
- * connection: fetchServerSentEvents('/api/transcribe'),
15
- * })
16
- *
17
- * const handleFile = (e: Event) => {
18
- * const input = e.target as HTMLInputElement
19
- * const file = input.files?.[0]
20
- * if (file) {
21
- * const reader = new FileReader()
22
- * reader.onload = () => {
23
- * generate({ audio: reader.result as string, language: 'en' })
24
- * }
25
- * reader.readAsDataURL(file)
26
- * }
27
- * }
28
- *
29
- * return (
30
- * <div>
31
- * <input type="file" accept="audio/*" onChange={handleFile} />
32
- * {isLoading() && <p>Transcribing...</p>}
33
- * {result() && <p>{result()!.text}</p>}
34
- * </div>
35
- * )
36
- * }
37
- * ```
38
- */
39
- function useTranscription(options) {
40
- const devtools = {
41
- ...options.devtools,
42
- framework: "solid",
43
- hookName: "useTranscription",
44
- outputKind: "text"
45
- };
46
- const { generate, result, isLoading, error, status, stop, reset } = useGeneration({
47
- ...options,
48
- devtools
49
- });
50
- return {
51
- generate,
52
- result,
53
- isLoading,
54
- error,
55
- status,
56
- stop,
57
- reset
58
- };
59
- }
60
-
61
- //#endregion
62
- export { useTranscription };
63
- //# sourceMappingURL=use-transcription.js.map
@@ -1 +0,0 @@
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 AIDevtoolsDisplayOptions,\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 /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\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 devtools = {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useTranscription',\n outputKind: 'text' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<TranscriptionGenerateInput, TranscriptionResult, TOnResult>({\n ...options,\n devtools,\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGA,SAAgB,iBAId,SAKA;CACA,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAA0E;EACxE,GAAG;EACH;EACD,CAAC;AAEJ,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}