@tanstack/ai-react 0.15.14 → 0.15.15
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/esm/index.d.ts +19 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/realtime-types.d.ts +109 -0
- package/dist/esm/types.d.ts +150 -0
- package/dist/esm/use-chat.d.ts +4 -0
- package/dist/esm/use-chat.js +258 -0
- package/dist/esm/use-chat.js.map +1 -0
- package/dist/esm/use-generate-audio.d.ts +87 -0
- package/dist/esm/use-generate-audio.js +26 -0
- package/dist/esm/use-generate-audio.js.map +1 -0
- package/dist/esm/use-generate-image.d.ts +89 -0
- package/dist/esm/use-generate-image.js +26 -0
- package/dist/esm/use-generate-image.js.map +1 -0
- package/dist/esm/use-generate-speech.d.ts +83 -0
- package/dist/esm/use-generate-speech.js +26 -0
- package/dist/esm/use-generate-speech.js.map +1 -0
- package/dist/esm/use-generate-video.d.ts +94 -0
- package/dist/esm/use-generate-video.js +104 -0
- package/dist/esm/use-generate-video.js.map +1 -0
- package/dist/esm/use-generation.d.ts +80 -0
- package/dist/esm/use-generation.js +91 -0
- package/dist/esm/use-generation.js.map +1 -0
- package/dist/esm/use-realtime-chat.d.ts +42 -0
- package/dist/esm/use-realtime-chat.js +189 -0
- package/dist/esm/use-realtime-chat.js.map +1 -0
- package/dist/esm/use-summarize.d.ts +86 -0
- package/dist/esm/use-summarize.js +26 -0
- package/dist/esm/use-summarize.js.map +1 -0
- package/dist/esm/use-transcription.d.ts +91 -0
- package/dist/esm/use-transcription.js +26 -0
- package/dist/esm/use-transcription.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useGeneration } from "./use-generation.js";
|
|
2
|
+
function useTranscription(options) {
|
|
3
|
+
const devtools = {
|
|
4
|
+
...options.devtools,
|
|
5
|
+
framework: "react",
|
|
6
|
+
hookName: "useTranscription",
|
|
7
|
+
outputKind: "text"
|
|
8
|
+
};
|
|
9
|
+
const { generate, result, isLoading, error, status, stop, reset } = useGeneration({
|
|
10
|
+
...options,
|
|
11
|
+
devtools
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
generate,
|
|
15
|
+
result,
|
|
16
|
+
isLoading,
|
|
17
|
+
error,
|
|
18
|
+
status,
|
|
19
|
+
stop,
|
|
20
|
+
reset
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
useTranscription
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=use-transcription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-transcription.js","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'\n\n/**\n * Options for the useTranscription hook.\n *\n * @template TOutput - The output type after optional transform (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 output type (after optional transform)\n */\nexport interface UseTranscriptionReturn<TOutput = TranscriptionResult> {\n /** Trigger transcription */\n generate: (input: TranscriptionGenerateInput) => Promise<void>\n /** The transcription result, or null */\n result: TOutput | null\n /** Whether transcription is in progress */\n isLoading: boolean\n /** Current error, if any */\n error: Error | undefined\n /** Current state of the generation */\n status: GenerationClientState\n /** Abort the current transcription */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * React hook for transcribing audio to text using AI models.\n *\n * @example\n * ```tsx\n * import { useTranscription } from '@tanstack/ai-react'\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: React.ChangeEvent<HTMLInputElement>) => {\n * const file = e.target.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: 'react',\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"],"names":[],"mappings":";AAmGO,SAAS,iBAId,SAKA;AACA,QAAM,WAAW;AAAA,IACf,GAAG,QAAQ;AAAA,IACX,WAAW;AAAA,IACX,UAAU;AAAA,IACV,YAAY;AAAA,EAAA;AAEd,QAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,MAAA,IACxD,cAA0E;AAAA,IACxE,GAAG;AAAA,IACH;AAAA,EAAA,CACD;AAEH,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-react",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.15",
|
|
4
4
|
"description": "React hooks for TanStack AI streaming chat, realtime voice, structured outputs, and media generation.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"media-generation"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@tanstack/ai-client": "0.18.
|
|
48
|
+
"@tanstack/ai-client": "0.18.6"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@types/react": ">=18.0.0",
|
|
52
52
|
"react": ">=18.0.0",
|
|
53
|
-
"@tanstack/ai": "^0.
|
|
53
|
+
"@tanstack/ai": "^0.37.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"jsdom": "^27.2.0",
|
|
61
61
|
"react": "^19.2.3",
|
|
62
62
|
"vite": "^7.3.3",
|
|
63
|
-
"@tanstack/ai": "0.
|
|
63
|
+
"@tanstack/ai": "0.37.0"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"clean": "premove ./build ./dist",
|