@tanstack/ai-solid 0.13.15 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/use-audio-recorder.d.ts +37 -0
- package/dist/use-audio-recorder.js +39 -0
- package/dist/use-audio-recorder.js.map +1 -0
- package/dist/use-generate-audio.d.ts +4 -4
- package/dist/use-generate-audio.js.map +1 -1
- package/dist/use-generate-image.d.ts +4 -4
- package/dist/use-generate-image.js.map +1 -1
- package/dist/use-generate-speech.d.ts +4 -4
- package/dist/use-generate-speech.js.map +1 -1
- package/dist/use-generate-video.d.ts +4 -4
- package/dist/use-generate-video.js +1 -1
- package/dist/use-generate-video.js.map +1 -1
- package/dist/use-generation.d.ts +4 -4
- package/dist/use-generation.js +1 -1
- package/dist/use-generation.js.map +1 -1
- package/dist/use-summarize.d.ts +4 -4
- package/dist/use-summarize.js.map +1 -1
- package/dist/use-transcription.d.ts +4 -4
- package/dist/use-transcription.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +6 -0
- package/src/use-audio-recorder.ts +87 -0
- package/src/use-generate-audio.ts +5 -8
- package/src/use-generate-image.ts +5 -8
- package/src/use-generate-speech.ts +7 -7
- package/src/use-generate-video.ts +17 -9
- package/src/use-generation.ts +17 -6
- package/src/use-summarize.ts +7 -8
- package/src/use-transcription.ts +9 -11
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ import { UseGenerateSpeechOptions, UseGenerateSpeechReturn, useGenerateSpeech }
|
|
|
7
7
|
import { UseTranscriptionOptions, UseTranscriptionReturn, useTranscription } from "./use-transcription.js";
|
|
8
8
|
import { UseSummarizeOptions, UseSummarizeReturn, useSummarize } from "./use-summarize.js";
|
|
9
9
|
import { UseGenerateVideoOptions, UseGenerateVideoReturn, useGenerateVideo } from "./use-generate-video.js";
|
|
10
|
+
import { UseAudioRecorderOptions, UseAudioRecorderReturn, useAudioRecorder } from "./use-audio-recorder.js";
|
|
10
11
|
import { AudioGenerateInput, ConnectConnectionAdapter, ConnectionAdapter, FetchConnectionOptions, GenerationClientState, ImageGenerateInput, InferChatMessages, RunAgentInputContext, SpeechGenerateInput, SubscribeConnectionAdapter, SummarizeGenerateInput, TranscriptionGenerateInput, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo, XhrConnectionOptions, createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, xhrHttpStream, xhrServerSentEvents } from "@tanstack/ai-client";
|
|
11
|
-
export { type AudioGenerateInput, type ChatRequestBody, type ConnectConnectionAdapter, type ConnectionAdapter, type DeepPartial, type FetchConnectionOptions, type GenerationClientState, type ImageGenerateInput, type InferChatMessages, type RunAgentInputContext, type SpeechGenerateInput, type SubscribeConnectionAdapter, type SummarizeGenerateInput, type TranscriptionGenerateInput, type UIMessage, type UseChatOptions, type UseChatReturn, type UseGenerateAudioOptions, type UseGenerateAudioReturn, type UseGenerateImageOptions, type UseGenerateImageReturn, type UseGenerateSpeechOptions, type UseGenerateSpeechReturn, type UseGenerateVideoOptions, type UseGenerateVideoReturn, type UseGenerationOptions, type UseGenerationReturn, type UseSummarizeOptions, type UseSummarizeReturn, type UseTranscriptionOptions, type UseTranscriptionReturn, type VideoGenerateInput, type VideoGenerateResult, type VideoStatusInfo, type XhrConnectionOptions, createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, useChat, useGenerateAudio, useGenerateImage, useGenerateSpeech, useGenerateVideo, useGeneration, useSummarize, useTranscription, xhrHttpStream, xhrServerSentEvents };
|
|
12
|
+
export { type AudioGenerateInput, type ChatRequestBody, type ConnectConnectionAdapter, type ConnectionAdapter, type DeepPartial, type FetchConnectionOptions, type GenerationClientState, type ImageGenerateInput, type InferChatMessages, type RunAgentInputContext, type SpeechGenerateInput, type SubscribeConnectionAdapter, type SummarizeGenerateInput, type TranscriptionGenerateInput, type UIMessage, type UseAudioRecorderOptions, type UseAudioRecorderReturn, type UseChatOptions, type UseChatReturn, type UseGenerateAudioOptions, type UseGenerateAudioReturn, type UseGenerateImageOptions, type UseGenerateImageReturn, type UseGenerateSpeechOptions, type UseGenerateSpeechReturn, type UseGenerateVideoOptions, type UseGenerateVideoReturn, type UseGenerationOptions, type UseGenerationReturn, type UseSummarizeOptions, type UseSummarizeReturn, type UseTranscriptionOptions, type UseTranscriptionReturn, type VideoGenerateInput, type VideoGenerateResult, type VideoStatusInfo, type XhrConnectionOptions, createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, useAudioRecorder, useChat, useGenerateAudio, useGenerateImage, useGenerateSpeech, useGenerateVideo, useGeneration, useSummarize, useTranscription, xhrHttpStream, xhrServerSentEvents };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { useGenerateSpeech } from "./use-generate-speech.js";
|
|
|
6
6
|
import { useTranscription } from "./use-transcription.js";
|
|
7
7
|
import { useSummarize } from "./use-summarize.js";
|
|
8
8
|
import { useGenerateVideo } from "./use-generate-video.js";
|
|
9
|
+
import { useAudioRecorder } from "./use-audio-recorder.js";
|
|
9
10
|
import { createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, xhrHttpStream, xhrServerSentEvents } from "@tanstack/ai-client";
|
|
10
11
|
|
|
11
|
-
export { createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, useChat, useGenerateAudio, useGenerateImage, useGenerateSpeech, useGenerateVideo, useGeneration, useSummarize, useTranscription, xhrHttpStream, xhrServerSentEvents };
|
|
12
|
+
export { createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, useAudioRecorder, useChat, useGenerateAudio, useGenerateImage, useGenerateSpeech, useGenerateVideo, useGeneration, useSummarize, useTranscription, xhrHttpStream, xhrServerSentEvents };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AudioRecorderOptions, AudioRecording, InferAudioRecordingOutput } from "@tanstack/ai-client";
|
|
2
|
+
|
|
3
|
+
//#region src/use-audio-recorder.d.ts
|
|
4
|
+
type UseAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {
|
|
5
|
+
/**
|
|
6
|
+
* Optional transform applied to the recording when `stop()` resolves. Its
|
|
7
|
+
* (awaited) return value becomes `recording` and the resolved value of
|
|
8
|
+
* `stop()`. Return nothing to keep the raw `AudioRecording`.
|
|
9
|
+
*/
|
|
10
|
+
onComplete?: TOnComplete;
|
|
11
|
+
};
|
|
12
|
+
interface UseAudioRecorderReturn<TOutput> {
|
|
13
|
+
/** Solid accessor: latest recording (transformed if `onComplete` provided), or null. */
|
|
14
|
+
recording: () => TOutput | null;
|
|
15
|
+
/** Solid accessor: true while actively capturing audio. */
|
|
16
|
+
isRecording: () => boolean;
|
|
17
|
+
/** Whether the browser supports recording. */
|
|
18
|
+
isSupported: boolean;
|
|
19
|
+
start: () => Promise<void>;
|
|
20
|
+
/** Stop and resolve with the completed recording (transformed if `onComplete` provided). */
|
|
21
|
+
stop: () => Promise<TOutput>;
|
|
22
|
+
/** Discard the in-progress recording and release the mic. */
|
|
23
|
+
cancel: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Solid hook for recording an audio message. The resolved recording carries
|
|
27
|
+
* `.part` (for `useChat.sendMessage`) and `.base64` (for generation hooks).
|
|
28
|
+
*
|
|
29
|
+
* Errors are delivered via `onError`. `start()` and `stop()` also reject on
|
|
30
|
+
* failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs
|
|
31
|
+
* while a stop is in flight, e.g. on unmount) — handle one channel, not both.
|
|
32
|
+
*/
|
|
33
|
+
declare function useAudioRecorder<TOnComplete extends (recording: AudioRecording) => unknown>(options: UseAudioRecorderOptions<TOnComplete>): UseAudioRecorderReturn<InferAudioRecordingOutput<TOnComplete>>;
|
|
34
|
+
declare function useAudioRecorder(options?: UseAudioRecorderOptions<undefined>): UseAudioRecorderReturn<AudioRecording>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { UseAudioRecorderOptions, UseAudioRecorderReturn, useAudioRecorder };
|
|
37
|
+
//# sourceMappingURL=use-audio-recorder.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
2
|
+
import { AudioRecorder } from "@tanstack/ai-client";
|
|
3
|
+
|
|
4
|
+
//#region src/use-audio-recorder.ts
|
|
5
|
+
function useAudioRecorder(options = {}) {
|
|
6
|
+
const recorder = new AudioRecorder({
|
|
7
|
+
...options.audio !== void 0 && { audio: options.audio },
|
|
8
|
+
...options.mimeType !== void 0 && { mimeType: options.mimeType },
|
|
9
|
+
...options.onError !== void 0 && { onError: options.onError }
|
|
10
|
+
});
|
|
11
|
+
const [isRecording, setIsRecording] = createSignal(false);
|
|
12
|
+
const [recording, setRecording] = createSignal(null);
|
|
13
|
+
const unsubscribe = recorder.subscribe((state) => {
|
|
14
|
+
setIsRecording(state === "recording");
|
|
15
|
+
});
|
|
16
|
+
onCleanup(() => {
|
|
17
|
+
unsubscribe();
|
|
18
|
+
recorder.cancel();
|
|
19
|
+
});
|
|
20
|
+
const stop = async () => {
|
|
21
|
+
const rawRecording = await recorder.stop();
|
|
22
|
+
const transformed = await options.onComplete?.(rawRecording);
|
|
23
|
+
const output = transformed === void 0 ? rawRecording : transformed;
|
|
24
|
+
setRecording(() => output);
|
|
25
|
+
return output;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
recording,
|
|
29
|
+
isRecording,
|
|
30
|
+
isSupported: AudioRecorder.isSupported(),
|
|
31
|
+
start: () => recorder.start(),
|
|
32
|
+
stop,
|
|
33
|
+
cancel: () => recorder.cancel()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useAudioRecorder };
|
|
39
|
+
//# sourceMappingURL=use-audio-recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-audio-recorder.js","names":[],"sources":["../src/use-audio-recorder.ts"],"sourcesContent":["import { createSignal, onCleanup } from 'solid-js'\nimport { AudioRecorder } from '@tanstack/ai-client'\nimport type {\n AudioRecorderOptions,\n AudioRecording,\n InferAudioRecordingOutput,\n} from '@tanstack/ai-client'\n\nexport type UseAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {\n /**\n * Optional transform applied to the recording when `stop()` resolves. Its\n * (awaited) return value becomes `recording` and the resolved value of\n * `stop()`. Return nothing to keep the raw `AudioRecording`.\n */\n onComplete?: TOnComplete\n}\n\nexport interface UseAudioRecorderReturn<TOutput> {\n /** Solid accessor: latest recording (transformed if `onComplete` provided), or null. */\n recording: () => TOutput | null\n /** Solid accessor: true while actively capturing audio. */\n isRecording: () => boolean\n /** Whether the browser supports recording. */\n isSupported: boolean\n start: () => Promise<void>\n /** Stop and resolve with the completed recording (transformed if `onComplete` provided). */\n stop: () => Promise<TOutput>\n /** Discard the in-progress recording and release the mic. */\n cancel: () => void\n}\n\n/**\n * Solid hook for recording an audio message. The resolved recording carries\n * `.part` (for `useChat.sendMessage`) and `.base64` (for generation hooks).\n *\n * Errors are delivered via `onError`. `start()` and `stop()` also reject on\n * failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs\n * while a stop is in flight, e.g. on unmount) — handle one channel, not both.\n */\nexport function useAudioRecorder<\n TOnComplete extends (recording: AudioRecording) => unknown,\n>(\n options: UseAudioRecorderOptions<TOnComplete>,\n): UseAudioRecorderReturn<InferAudioRecordingOutput<TOnComplete>>\nexport function useAudioRecorder(\n options?: UseAudioRecorderOptions<undefined>,\n): UseAudioRecorderReturn<AudioRecording>\nexport function useAudioRecorder(\n options: UseAudioRecorderOptions<(recording: AudioRecording) => unknown> = {},\n): UseAudioRecorderReturn<unknown> {\n const recorder = new AudioRecorder({\n ...(options.audio !== undefined && { audio: options.audio }),\n ...(options.mimeType !== undefined && { mimeType: options.mimeType }),\n ...(options.onError !== undefined && { onError: options.onError }),\n })\n const [isRecording, setIsRecording] = createSignal(false)\n const [recording, setRecording] = createSignal<unknown>(null)\n\n const unsubscribe = recorder.subscribe((state) => {\n setIsRecording(state === 'recording')\n })\n\n onCleanup(() => {\n unsubscribe()\n recorder.cancel()\n })\n\n const stop = async (): Promise<unknown> => {\n const rawRecording = await recorder.stop()\n const transformed = await options.onComplete?.(rawRecording)\n // Only `undefined` (returning nothing) keeps the raw recording; a returned\n // null is a real value, matching the inferred output type.\n const output = transformed === undefined ? rawRecording : transformed\n // Store via updater so a function-valued transform result isn't invoked.\n setRecording(() => output)\n return output\n }\n\n return {\n recording,\n isRecording,\n isSupported: AudioRecorder.isSupported(),\n start: () => recorder.start(),\n stop,\n cancel: () => recorder.cancel(),\n }\n}\n"],"mappings":";;;;AA+CA,SAAgB,iBACd,UAA2E,EAAE,EAC5C;CACjC,MAAM,WAAW,IAAI,cAAc;EACjC,GAAI,QAAQ,UAAU,UAAa,EAAE,OAAO,QAAQ,OAAO;EAC3D,GAAI,QAAQ,aAAa,UAAa,EAAE,UAAU,QAAQ,UAAU;EACpE,GAAI,QAAQ,YAAY,UAAa,EAAE,SAAS,QAAQ,SAAS;EAClE,CAAC;CACF,MAAM,CAAC,aAAa,kBAAkB,aAAa,MAAM;CACzD,MAAM,CAAC,WAAW,gBAAgB,aAAsB,KAAK;CAE7D,MAAM,cAAc,SAAS,WAAW,UAAU;AAChD,iBAAe,UAAU,YAAY;GACrC;AAEF,iBAAgB;AACd,eAAa;AACb,WAAS,QAAQ;GACjB;CAEF,MAAM,OAAO,YAA8B;EACzC,MAAM,eAAe,MAAM,SAAS,MAAM;EAC1C,MAAM,cAAc,MAAM,QAAQ,aAAa,aAAa;EAG5D,MAAM,SAAS,gBAAgB,SAAY,eAAe;AAE1D,qBAAmB,OAAO;AAC1B,SAAO;;AAGT,QAAO;EACL;EACA;EACA,aAAa,cAAc,aAAa;EACxC,aAAa,SAAS,OAAO;EAC7B;EACA,cAAc,SAAS,QAAQ;EAChC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, AudioGenerateInput, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, AudioGenerateInput, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutputFromReturn } from "@tanstack/ai-client";
|
|
3
3
|
import { AudioGenerationResult, StreamChunk } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/use-generate-audio.d.ts
|
|
@@ -80,9 +80,9 @@ interface UseGenerateAudioReturn<TOutput = AudioGenerationResult> {
|
|
|
80
80
|
* }
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
declare function useGenerateAudio<
|
|
84
|
-
onResult?:
|
|
85
|
-
}): UseGenerateAudioReturn<
|
|
83
|
+
declare function useGenerateAudio<TTransformed = void>(options: Omit<UseGenerateAudioOptions, 'onResult'> & {
|
|
84
|
+
onResult?: (result: AudioGenerationResult) => TTransformed;
|
|
85
|
+
}): UseGenerateAudioReturn<InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>>;
|
|
86
86
|
//#endregion
|
|
87
87
|
export { UseGenerateAudioOptions, UseGenerateAudioReturn, useGenerateAudio };
|
|
88
88
|
//# sourceMappingURL=use-generate-audio.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-generate-audio.js","names":[],"sources":["../src/use-generate-audio.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { AudioGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\n AudioGenerateInput,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n
|
|
1
|
+
{"version":3,"file":"use-generate-audio.js","names":[],"sources":["../src/use-generate-audio.ts"],"sourcesContent":["import { useGeneration } from './use-generation'\nimport type { AudioGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\n AudioGenerateInput,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutputFromReturn,\n} from '@tanstack/ai-client'\nimport type { Accessor } from 'solid-js'\n\n/**\n * Options for the useGenerateAudio hook.\n *\n * @template TOutput - The transformed output type (defaults to AudioGenerationResult)\n */\nexport interface UseGenerateAudioOptions<TOutput = AudioGenerationResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for audio generation */\n fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with connect-based adapter requests */\n body?: Record<string, any>\n /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\n /**\n * Callback when audio is generated. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: AudioGenerationResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the useGenerateAudio hook.\n *\n * @template TOutput - The transformed output type (defaults to AudioGenerationResult)\n */\nexport interface UseGenerateAudioReturn<TOutput = AudioGenerationResult> {\n /** Trigger audio generation */\n generate: (input: AudioGenerateInput) => Promise<void>\n /** The generation result containing audio, or null */\n result: 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 audio (music, sound effects) using AI models.\n *\n * @example\n * ```tsx\n * import { useGenerateAudio } from '@tanstack/ai-solid'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * function AudioGenerator() {\n * const { generate, result, isLoading } = useGenerateAudio({\n * connection: fetchServerSentEvents('/api/generate/audio'),\n * })\n *\n * return (\n * <div>\n * <button onClick={() => generate({ prompt: 'An upbeat electronic track', duration: 10 })}>\n * Generate\n * </button>\n * {result()?.audio.url && <audio src={result()!.audio.url} controls />}\n * </div>\n * )\n * }\n * ```\n */\nexport function useGenerateAudio<TTransformed = void>(\n options: Omit<UseGenerateAudioOptions, 'onResult'> & {\n onResult?: (result: AudioGenerationResult) => TTransformed\n },\n): UseGenerateAudioReturn<\n InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useGenerateAudio',\n outputKind: 'audio' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<AudioGenerateInput, AudioGenerationResult, TTransformed>({\n ...options,\n devtools,\n })\n\n return {\n generate: generate as (input: AudioGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FA,SAAgB,iBACd,SAKA;CACA,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAuE;EACrE,GAAG;EACH;EACD,CAAC;AAEJ,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, ImageGenerateInput, InferGenerationOutputFromReturn } from "@tanstack/ai-client";
|
|
3
3
|
import { ImageGenerationResult, StreamChunk } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/use-generate-image.d.ts
|
|
@@ -88,9 +88,9 @@ interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {
|
|
|
88
88
|
* }
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
declare function useGenerateImage<
|
|
92
|
-
onResult?:
|
|
93
|
-
}): UseGenerateImageReturn<
|
|
91
|
+
declare function useGenerateImage<TTransformed = void>(options: Omit<UseGenerateImageOptions, 'onResult'> & {
|
|
92
|
+
onResult?: (result: ImageGenerationResult) => TTransformed;
|
|
93
|
+
}): UseGenerateImageReturn<InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>>;
|
|
94
94
|
//#endregion
|
|
95
95
|
export { UseGenerateImageOptions, UseGenerateImageReturn, useGenerateImage };
|
|
96
96
|
//# sourceMappingURL=use-generate-image.d.ts.map
|
|
@@ -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 AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n ImageGenerateInput,\n
|
|
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 AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n ImageGenerateInput,\n InferGenerationOutputFromReturn,\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 /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\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<TTransformed = void>(\n options: Omit<UseGenerateImageOptions, 'onResult'> & {\n onResult?: (result: ImageGenerationResult) => TTransformed\n },\n): UseGenerateImageReturn<\n InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useGenerateImage',\n outputKind: 'image' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<ImageGenerateInput, ImageGenerationResult, TTransformed>({\n ...options,\n devtools,\n })\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,SAAgB,iBACd,SAKA;CACA,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAuE;EACrE,GAAG;EACH;EACD,CAAC;AAEJ,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutputFromReturn, SpeechGenerateInput } from "@tanstack/ai-client";
|
|
3
3
|
import { StreamChunk, TTSResult } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/use-generate-speech.d.ts
|
|
@@ -82,9 +82,9 @@ interface UseGenerateSpeechReturn<TOutput = TTSResult> {
|
|
|
82
82
|
* }
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
|
-
declare function useGenerateSpeech<
|
|
86
|
-
onResult?:
|
|
87
|
-
}): UseGenerateSpeechReturn<
|
|
85
|
+
declare function useGenerateSpeech<TTransformed = void>(options: Omit<UseGenerateSpeechOptions, 'onResult'> & {
|
|
86
|
+
onResult?: (result: TTSResult) => TTransformed;
|
|
87
|
+
}): UseGenerateSpeechReturn<InferGenerationOutputFromReturn<TTSResult, TTransformed>>;
|
|
88
88
|
//#endregion
|
|
89
89
|
export { UseGenerateSpeechOptions, UseGenerateSpeechReturn, useGenerateSpeech };
|
|
90
90
|
//# sourceMappingURL=use-generate-speech.d.ts.map
|
|
@@ -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 AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n
|
|
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 AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutputFromReturn,\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 /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\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<TTransformed = void>(\n options: Omit<UseGenerateSpeechOptions, 'onResult'> & {\n onResult?: (result: TTSResult) => TTransformed\n },\n): UseGenerateSpeechReturn<\n InferGenerationOutputFromReturn<TTSResult, TTransformed>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useGenerateSpeech',\n outputKind: 'audio' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n useGeneration<SpeechGenerateInput, TTSResult, TTransformed>({\n ...options,\n devtools,\n })\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4FA,SAAgB,kBACd,SAKA;CACA,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAA4D;EAC1D,GAAG;EACH;EACD,CAAC;AAEJ,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutputFromReturn, 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
|
|
@@ -95,9 +95,9 @@ interface UseGenerateVideoReturn<TOutput = VideoGenerateResult> {
|
|
|
95
95
|
* }
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
|
-
declare function useGenerateVideo<
|
|
99
|
-
onResult?:
|
|
100
|
-
}): UseGenerateVideoReturn<
|
|
98
|
+
declare function useGenerateVideo<TTransformed = void>(options: Omit<UseGenerateVideoOptions, 'onResult'> & {
|
|
99
|
+
onResult?: (result: VideoGenerateResult) => TTransformed;
|
|
100
|
+
}): UseGenerateVideoReturn<InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>>;
|
|
101
101
|
//#endregion
|
|
102
102
|
export { UseGenerateVideoOptions, UseGenerateVideoReturn, useGenerateVideo };
|
|
103
103
|
//# sourceMappingURL=use-generate-video.d.ts.map
|
|
@@ -54,7 +54,7 @@ function useGenerateVideo(options) {
|
|
|
54
54
|
hookName: "useGenerateVideo",
|
|
55
55
|
outputKind: "video"
|
|
56
56
|
},
|
|
57
|
-
onResult: (r) => options.onResult?.(r),
|
|
57
|
+
onResult: ((r) => options.onResult?.(r)),
|
|
58
58
|
onError: (e) => options.onError?.(e),
|
|
59
59
|
onProgress: (p, m) => options.onProgress?.(p, m),
|
|
60
60
|
onChunk: (c) => options.onChunk?.(c),
|
|
@@ -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 { createVideoDevtoolsBridge } 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 GenerationClientState,\n GenerationFetcher,\n
|
|
1
|
+
{"version":3,"file":"use-generate-video.js","names":[],"sources":["../src/use-generate-video.ts"],"sourcesContent":["import { VideoGenerationClient } from '@tanstack/ai-client'\nimport { createVideoDevtoolsBridge } 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 GenerationClientState,\n GenerationFetcher,\n InferGenerationOutputFromReturn,\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 /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\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 */\n// `TTransformed` infers from the `onResult` return position so the callback\n// parameter is typed as `VideoGenerateResult` and `result` narrows to the\n// transform's return. See issue #848.\nexport function useGenerateVideo<TTransformed = void>(\n options: Omit<UseGenerateVideoOptions, 'onResult'> & {\n onResult?: (result: VideoGenerateResult) => TTransformed\n },\n): UseGenerateVideoReturn<\n InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>\n> {\n type TOutput = InferGenerationOutputFromReturn<\n VideoGenerateResult,\n TTransformed\n >\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 // Conditional spread on `body`: VideoGenerationClientOptions.body\n // is a strict optional; EOPT forbids passing `T | undefined`.\n const baseOptions = {\n id: clientId,\n body: options.body,\n devtoolsBridgeFactory: createVideoDevtoolsBridge,\n devtools: {\n ...options.devtools,\n framework: 'solid',\n hookName: 'useGenerateVideo',\n outputKind: 'video' as const,\n },\n // The transform's raw return type (`TTransformed`) and the stored output\n // (`TOutput`, with null/void/undefined stripped) are identical at runtime;\n // the cast bridges the relationship that the conditional type hides.\n onResult: ((r: VideoGenerateResult) => options.onResult?.(r)) as (\n result: VideoGenerateResult,\n ) => TOutput | null | void,\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({\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: 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA,SAAgB,iBACd,SAKA;CAKA,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;EAG9B,MAAM,cAAc;GAClB,IAAI;GACJ,MAAM,QAAQ;GACd,uBAAuB;GACvB,UAAU;IACR,GAAG,QAAQ;IACX,WAAW;IACX,UAAU;IACV,YAAY;IACb;GAID,YAAY,MAA2B,QAAQ,WAAW,EAAE;GAG5D,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,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,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"}
|
package/dist/use-generation.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutputFromReturn } from "@tanstack/ai-client";
|
|
3
3
|
import { StreamChunk } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/use-generation.d.ts
|
|
@@ -80,9 +80,9 @@ interface UseGenerationReturn<TOutput> {
|
|
|
80
80
|
* await generate({ prompt: 'Hello' })
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
declare function useGeneration<TInput extends Record<string, any>, TResult,
|
|
84
|
-
onResult?:
|
|
85
|
-
}): UseGenerationReturn<
|
|
83
|
+
declare function useGeneration<TInput extends Record<string, any>, TResult, TTransformed = void>(options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {
|
|
84
|
+
onResult?: (result: TResult) => TTransformed;
|
|
85
|
+
}): UseGenerationReturn<InferGenerationOutputFromReturn<TResult, TTransformed>>;
|
|
86
86
|
//#endregion
|
|
87
87
|
export { UseGenerationOptions, UseGenerationReturn, useGeneration };
|
|
88
88
|
//# sourceMappingURL=use-generation.d.ts.map
|
package/dist/use-generation.js
CHANGED
|
@@ -40,7 +40,7 @@ function useGeneration(options) {
|
|
|
40
40
|
framework: "solid",
|
|
41
41
|
hookName: "useGeneration"
|
|
42
42
|
},
|
|
43
|
-
onResult: (r) => options.onResult?.(r),
|
|
43
|
+
onResult: ((r) => options.onResult?.(r)),
|
|
44
44
|
onError: (e) => options.onError?.(e),
|
|
45
45
|
onProgress: (p, m) => options.onProgress?.(p, m),
|
|
46
46
|
onChunk: (c) => options.onChunk?.(c),
|
|
@@ -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 { 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
|
|
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 InferGenerationOutputFromReturn,\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 */\n// `TTransformed` infers from the `onResult` return position (a covariant\n// inference site that works even for an optional nested property), which types\n// the callback parameter as `TResult` and narrows `result`. Inferring the\n// whole callback as a defaulted type parameter instead collapses to the\n// default, leaving the parameter `any` — a hard error under `strict`. See\n// issue #848.\nexport function useGeneration<\n TInput extends Record<string, any>,\n TResult,\n TTransformed = void,\n>(\n options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {\n onResult?: (result: TResult) => TTransformed\n },\n): UseGenerationReturn<InferGenerationOutputFromReturn<TResult, TTransformed>> {\n type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>\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 // The transform's raw return type (`TTransformed`) and the stored output\n // (`TOutput`, with null/void/undefined stripped) are identical at runtime;\n // the cast bridges the relationship that the conditional type hides.\n onResult: ((r: TResult) => options.onResult?.(r)) as (\n result: TResult,\n ) => TOutput | null | void,\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":";;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,SAAgB,cAKd,SAG6E;CAE7E,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;GAID,YAAY,MAAe,QAAQ,WAAW,EAAE;GAGhD,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"}
|
package/dist/use-summarize.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutputFromReturn, SummarizeGenerateInput } from "@tanstack/ai-client";
|
|
3
3
|
import { StreamChunk, SummarizationResult } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/use-summarize.d.ts
|
|
@@ -85,9 +85,9 @@ interface UseSummarizeReturn<TOutput = SummarizationResult> {
|
|
|
85
85
|
* }
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
declare function useSummarize<
|
|
89
|
-
onResult?:
|
|
90
|
-
}): UseSummarizeReturn<
|
|
88
|
+
declare function useSummarize<TTransformed = void>(options: Omit<UseSummarizeOptions, 'onResult'> & {
|
|
89
|
+
onResult?: (result: SummarizationResult) => TTransformed;
|
|
90
|
+
}): UseSummarizeReturn<InferGenerationOutputFromReturn<SummarizationResult, TTransformed>>;
|
|
91
91
|
//#endregion
|
|
92
92
|
export { UseSummarizeOptions, UseSummarizeReturn, useSummarize };
|
|
93
93
|
//# sourceMappingURL=use-summarize.d.ts.map
|
|
@@ -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 AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n
|
|
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 InferGenerationOutputFromReturn,\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<TTransformed = void>(\n options: Omit<UseSummarizeOptions, 'onResult'> & {\n onResult?: (result: SummarizationResult) => TTransformed\n },\n): UseSummarizeReturn<\n InferGenerationOutputFromReturn<SummarizationResult, TTransformed>\n> {\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, TTransformed>({\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,aACd,SAKA;CACA,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAAyE;EACvE,GAAG;EACH;EACD,CAAC;AAEJ,QAAO;EACK;EACV;EACA;EACA;EACA;EACA;EACA;EACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
|
-
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher,
|
|
2
|
+
import { AIDevtoolsDisplayOptions, ConnectConnectionAdapter, GenerationClientState, GenerationFetcher, InferGenerationOutputFromReturn, TranscriptionGenerateInput } from "@tanstack/ai-client";
|
|
3
3
|
import { StreamChunk, TranscriptionResult } from "@tanstack/ai";
|
|
4
4
|
|
|
5
5
|
//#region src/use-transcription.d.ts
|
|
@@ -91,9 +91,9 @@ interface UseTranscriptionReturn<TOutput = TranscriptionResult> {
|
|
|
91
91
|
* }
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
|
-
declare function useTranscription<
|
|
95
|
-
onResult?:
|
|
96
|
-
}): UseTranscriptionReturn<
|
|
94
|
+
declare function useTranscription<TTransformed = void>(options: Omit<UseTranscriptionOptions, 'onResult'> & {
|
|
95
|
+
onResult?: (result: TranscriptionResult) => TTransformed;
|
|
96
|
+
}): UseTranscriptionReturn<InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>>;
|
|
97
97
|
//#endregion
|
|
98
98
|
export { UseTranscriptionOptions, UseTranscriptionReturn, useTranscription };
|
|
99
99
|
//# sourceMappingURL=use-transcription.d.ts.map
|
|
@@ -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 AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n
|
|
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 InferGenerationOutputFromReturn,\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<TTransformed = void>(\n options: Omit<UseTranscriptionOptions, 'onResult'> & {\n onResult?: (result: TranscriptionResult) => TTransformed\n },\n): UseTranscriptionReturn<\n InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>\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<\n TranscriptionGenerateInput,\n TranscriptionResult,\n TTransformed\n >({ ...options, devtools })\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,iBACd,SAKA;CACA,MAAM,WAAW;EACf,GAAG,QAAQ;EACX,WAAW;EACX,UAAU;EACV,YAAY;EACb;CACD,MAAM,EAAE,UAAU,QAAQ,WAAW,OAAO,QAAQ,MAAM,UACxD,cAIE;EAAE,GAAG;EAAS;EAAU,CAAC;AAE7B,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.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Solid hooks for TanStack AI streaming chat, structured outputs, and media generation.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"media-generation"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@tanstack/ai-client": "0.
|
|
48
|
+
"@tanstack/ai-client": "0.19.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"solid-js": ">=1.9.10",
|
|
52
|
-
"@tanstack/ai": "^0.
|
|
52
|
+
"@tanstack/ai": "^0.38.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@solidjs/testing-library": "^0.8.10",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"tsdown": "^0.17.0-beta.6",
|
|
62
62
|
"typescript": "5.9.3",
|
|
63
63
|
"vitest": "^4.0.14",
|
|
64
|
-
"@tanstack/ai": "0.
|
|
64
|
+
"@tanstack/ai": "0.38.0"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"clean": "premove ./build ./dist",
|
package/src/index.ts
CHANGED
|
@@ -47,6 +47,12 @@ export type {
|
|
|
47
47
|
UseGenerateVideoReturn,
|
|
48
48
|
} from './use-generate-video'
|
|
49
49
|
|
|
50
|
+
export { useAudioRecorder } from './use-audio-recorder'
|
|
51
|
+
export type {
|
|
52
|
+
UseAudioRecorderOptions,
|
|
53
|
+
UseAudioRecorderReturn,
|
|
54
|
+
} from './use-audio-recorder'
|
|
55
|
+
|
|
50
56
|
// Re-export from ai-client for convenience
|
|
51
57
|
export {
|
|
52
58
|
fetchServerSentEvents,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createSignal, onCleanup } from 'solid-js'
|
|
2
|
+
import { AudioRecorder } from '@tanstack/ai-client'
|
|
3
|
+
import type {
|
|
4
|
+
AudioRecorderOptions,
|
|
5
|
+
AudioRecording,
|
|
6
|
+
InferAudioRecordingOutput,
|
|
7
|
+
} from '@tanstack/ai-client'
|
|
8
|
+
|
|
9
|
+
export type UseAudioRecorderOptions<TOnComplete> = AudioRecorderOptions & {
|
|
10
|
+
/**
|
|
11
|
+
* Optional transform applied to the recording when `stop()` resolves. Its
|
|
12
|
+
* (awaited) return value becomes `recording` and the resolved value of
|
|
13
|
+
* `stop()`. Return nothing to keep the raw `AudioRecording`.
|
|
14
|
+
*/
|
|
15
|
+
onComplete?: TOnComplete
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface UseAudioRecorderReturn<TOutput> {
|
|
19
|
+
/** Solid accessor: latest recording (transformed if `onComplete` provided), or null. */
|
|
20
|
+
recording: () => TOutput | null
|
|
21
|
+
/** Solid accessor: true while actively capturing audio. */
|
|
22
|
+
isRecording: () => boolean
|
|
23
|
+
/** Whether the browser supports recording. */
|
|
24
|
+
isSupported: boolean
|
|
25
|
+
start: () => Promise<void>
|
|
26
|
+
/** Stop and resolve with the completed recording (transformed if `onComplete` provided). */
|
|
27
|
+
stop: () => Promise<TOutput>
|
|
28
|
+
/** Discard the in-progress recording and release the mic. */
|
|
29
|
+
cancel: () => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Solid hook for recording an audio message. The resolved recording carries
|
|
34
|
+
* `.part` (for `useChat.sendMessage`) and `.base64` (for generation hooks).
|
|
35
|
+
*
|
|
36
|
+
* Errors are delivered via `onError`. `start()` and `stop()` also reject on
|
|
37
|
+
* failure (and `stop()` rejects with `Recording cancelled` if `cancel()` runs
|
|
38
|
+
* while a stop is in flight, e.g. on unmount) — handle one channel, not both.
|
|
39
|
+
*/
|
|
40
|
+
export function useAudioRecorder<
|
|
41
|
+
TOnComplete extends (recording: AudioRecording) => unknown,
|
|
42
|
+
>(
|
|
43
|
+
options: UseAudioRecorderOptions<TOnComplete>,
|
|
44
|
+
): UseAudioRecorderReturn<InferAudioRecordingOutput<TOnComplete>>
|
|
45
|
+
export function useAudioRecorder(
|
|
46
|
+
options?: UseAudioRecorderOptions<undefined>,
|
|
47
|
+
): UseAudioRecorderReturn<AudioRecording>
|
|
48
|
+
export function useAudioRecorder(
|
|
49
|
+
options: UseAudioRecorderOptions<(recording: AudioRecording) => unknown> = {},
|
|
50
|
+
): UseAudioRecorderReturn<unknown> {
|
|
51
|
+
const recorder = new AudioRecorder({
|
|
52
|
+
...(options.audio !== undefined && { audio: options.audio }),
|
|
53
|
+
...(options.mimeType !== undefined && { mimeType: options.mimeType }),
|
|
54
|
+
...(options.onError !== undefined && { onError: options.onError }),
|
|
55
|
+
})
|
|
56
|
+
const [isRecording, setIsRecording] = createSignal(false)
|
|
57
|
+
const [recording, setRecording] = createSignal<unknown>(null)
|
|
58
|
+
|
|
59
|
+
const unsubscribe = recorder.subscribe((state) => {
|
|
60
|
+
setIsRecording(state === 'recording')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
onCleanup(() => {
|
|
64
|
+
unsubscribe()
|
|
65
|
+
recorder.cancel()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const stop = async (): Promise<unknown> => {
|
|
69
|
+
const rawRecording = await recorder.stop()
|
|
70
|
+
const transformed = await options.onComplete?.(rawRecording)
|
|
71
|
+
// Only `undefined` (returning nothing) keeps the raw recording; a returned
|
|
72
|
+
// null is a real value, matching the inferred output type.
|
|
73
|
+
const output = transformed === undefined ? rawRecording : transformed
|
|
74
|
+
// Store via updater so a function-valued transform result isn't invoked.
|
|
75
|
+
setRecording(() => output)
|
|
76
|
+
return output
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
recording,
|
|
81
|
+
isRecording,
|
|
82
|
+
isSupported: AudioRecorder.isSupported(),
|
|
83
|
+
start: () => recorder.start(),
|
|
84
|
+
stop,
|
|
85
|
+
cancel: () => recorder.cancel(),
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
ConnectConnectionAdapter,
|
|
7
7
|
GenerationClientState,
|
|
8
8
|
GenerationFetcher,
|
|
9
|
-
|
|
9
|
+
InferGenerationOutputFromReturn,
|
|
10
10
|
} from '@tanstack/ai-client'
|
|
11
11
|
import type { Accessor } from 'solid-js'
|
|
12
12
|
|
|
@@ -88,15 +88,12 @@ export interface UseGenerateAudioReturn<TOutput = AudioGenerationResult> {
|
|
|
88
88
|
* }
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
export function useGenerateAudio<
|
|
92
|
-
TOnResult extends ((result: AudioGenerationResult) => any) | undefined =
|
|
93
|
-
undefined,
|
|
94
|
-
>(
|
|
91
|
+
export function useGenerateAudio<TTransformed = void>(
|
|
95
92
|
options: Omit<UseGenerateAudioOptions, 'onResult'> & {
|
|
96
|
-
onResult?:
|
|
93
|
+
onResult?: (result: AudioGenerationResult) => TTransformed
|
|
97
94
|
},
|
|
98
95
|
): UseGenerateAudioReturn<
|
|
99
|
-
|
|
96
|
+
InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>
|
|
100
97
|
> {
|
|
101
98
|
const devtools = {
|
|
102
99
|
...options.devtools,
|
|
@@ -105,7 +102,7 @@ export function useGenerateAudio<
|
|
|
105
102
|
outputKind: 'audio' as const,
|
|
106
103
|
}
|
|
107
104
|
const { generate, result, isLoading, error, status, stop, reset } =
|
|
108
|
-
useGeneration<AudioGenerateInput, AudioGenerationResult,
|
|
105
|
+
useGeneration<AudioGenerateInput, AudioGenerationResult, TTransformed>({
|
|
109
106
|
...options,
|
|
110
107
|
devtools,
|
|
111
108
|
})
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
GenerationClientState,
|
|
7
7
|
GenerationFetcher,
|
|
8
8
|
ImageGenerateInput,
|
|
9
|
-
|
|
9
|
+
InferGenerationOutputFromReturn,
|
|
10
10
|
} from '@tanstack/ai-client'
|
|
11
11
|
import type { Accessor } from 'solid-js'
|
|
12
12
|
|
|
@@ -96,15 +96,12 @@ export interface UseGenerateImageReturn<TOutput = ImageGenerationResult> {
|
|
|
96
96
|
* }
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
|
-
export function useGenerateImage<
|
|
100
|
-
TOnResult extends ((result: ImageGenerationResult) => any) | undefined =
|
|
101
|
-
undefined,
|
|
102
|
-
>(
|
|
99
|
+
export function useGenerateImage<TTransformed = void>(
|
|
103
100
|
options: Omit<UseGenerateImageOptions, 'onResult'> & {
|
|
104
|
-
onResult?:
|
|
101
|
+
onResult?: (result: ImageGenerationResult) => TTransformed
|
|
105
102
|
},
|
|
106
103
|
): UseGenerateImageReturn<
|
|
107
|
-
|
|
104
|
+
InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>
|
|
108
105
|
> {
|
|
109
106
|
const devtools = {
|
|
110
107
|
...options.devtools,
|
|
@@ -113,7 +110,7 @@ export function useGenerateImage<
|
|
|
113
110
|
outputKind: 'image' as const,
|
|
114
111
|
}
|
|
115
112
|
const { generate, result, isLoading, error, status, stop, reset } =
|
|
116
|
-
useGeneration<ImageGenerateInput, ImageGenerationResult,
|
|
113
|
+
useGeneration<ImageGenerateInput, ImageGenerationResult, TTransformed>({
|
|
117
114
|
...options,
|
|
118
115
|
devtools,
|
|
119
116
|
})
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
ConnectConnectionAdapter,
|
|
6
6
|
GenerationClientState,
|
|
7
7
|
GenerationFetcher,
|
|
8
|
-
|
|
8
|
+
InferGenerationOutputFromReturn,
|
|
9
9
|
SpeechGenerateInput,
|
|
10
10
|
} from '@tanstack/ai-client'
|
|
11
11
|
import type { Accessor } from 'solid-js'
|
|
@@ -90,13 +90,13 @@ export interface UseGenerateSpeechReturn<TOutput = TTSResult> {
|
|
|
90
90
|
* }
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
93
|
-
export function useGenerateSpeech<
|
|
94
|
-
TOnResult extends ((result: TTSResult) => any) | undefined = undefined,
|
|
95
|
-
>(
|
|
93
|
+
export function useGenerateSpeech<TTransformed = void>(
|
|
96
94
|
options: Omit<UseGenerateSpeechOptions, 'onResult'> & {
|
|
97
|
-
onResult?:
|
|
95
|
+
onResult?: (result: TTSResult) => TTransformed
|
|
98
96
|
},
|
|
99
|
-
): UseGenerateSpeechReturn<
|
|
97
|
+
): UseGenerateSpeechReturn<
|
|
98
|
+
InferGenerationOutputFromReturn<TTSResult, TTransformed>
|
|
99
|
+
> {
|
|
100
100
|
const devtools = {
|
|
101
101
|
...options.devtools,
|
|
102
102
|
framework: 'solid',
|
|
@@ -104,7 +104,7 @@ export function useGenerateSpeech<
|
|
|
104
104
|
outputKind: 'audio' as const,
|
|
105
105
|
}
|
|
106
106
|
const { generate, result, isLoading, error, status, stop, reset } =
|
|
107
|
-
useGeneration<SpeechGenerateInput, TTSResult,
|
|
107
|
+
useGeneration<SpeechGenerateInput, TTSResult, TTransformed>({
|
|
108
108
|
...options,
|
|
109
109
|
devtools,
|
|
110
110
|
})
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
ConnectConnectionAdapter,
|
|
15
15
|
GenerationClientState,
|
|
16
16
|
GenerationFetcher,
|
|
17
|
-
|
|
17
|
+
InferGenerationOutputFromReturn,
|
|
18
18
|
VideoGenerateInput,
|
|
19
19
|
VideoGenerateResult,
|
|
20
20
|
VideoStatusInfo,
|
|
@@ -114,17 +114,20 @@ export interface UseGenerateVideoReturn<TOutput = VideoGenerateResult> {
|
|
|
114
114
|
* }
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
>(
|
|
117
|
+
// `TTransformed` infers from the `onResult` return position so the callback
|
|
118
|
+
// parameter is typed as `VideoGenerateResult` and `result` narrows to the
|
|
119
|
+
// transform's return. See issue #848.
|
|
120
|
+
export function useGenerateVideo<TTransformed = void>(
|
|
121
121
|
options: Omit<UseGenerateVideoOptions, 'onResult'> & {
|
|
122
|
-
onResult?:
|
|
122
|
+
onResult?: (result: VideoGenerateResult) => TTransformed
|
|
123
123
|
},
|
|
124
124
|
): UseGenerateVideoReturn<
|
|
125
|
-
|
|
125
|
+
InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>
|
|
126
126
|
> {
|
|
127
|
-
type TOutput =
|
|
127
|
+
type TOutput = InferGenerationOutputFromReturn<
|
|
128
|
+
VideoGenerateResult,
|
|
129
|
+
TTransformed
|
|
130
|
+
>
|
|
128
131
|
const hookId = createUniqueId()
|
|
129
132
|
const clientId = options.id || hookId
|
|
130
133
|
|
|
@@ -150,7 +153,12 @@ export function useGenerateVideo<
|
|
|
150
153
|
hookName: 'useGenerateVideo',
|
|
151
154
|
outputKind: 'video' as const,
|
|
152
155
|
},
|
|
153
|
-
|
|
156
|
+
// The transform's raw return type (`TTransformed`) and the stored output
|
|
157
|
+
// (`TOutput`, with null/void/undefined stripped) are identical at runtime;
|
|
158
|
+
// the cast bridges the relationship that the conditional type hides.
|
|
159
|
+
onResult: ((r: VideoGenerateResult) => options.onResult?.(r)) as (
|
|
160
|
+
result: VideoGenerateResult,
|
|
161
|
+
) => TOutput | null | void,
|
|
154
162
|
onError: (e: Error) => options.onError?.(e),
|
|
155
163
|
onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
|
|
156
164
|
onChunk: (c: StreamChunk) => options.onChunk?.(c),
|
package/src/use-generation.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
GenerationClientOptions,
|
|
16
16
|
GenerationClientState,
|
|
17
17
|
GenerationFetcher,
|
|
18
|
-
|
|
18
|
+
InferGenerationOutputFromReturn,
|
|
19
19
|
} from '@tanstack/ai-client'
|
|
20
20
|
import type { Accessor } from 'solid-js'
|
|
21
21
|
|
|
@@ -97,16 +97,22 @@ export interface UseGenerationReturn<TOutput> {
|
|
|
97
97
|
* await generate({ prompt: 'Hello' })
|
|
98
98
|
* ```
|
|
99
99
|
*/
|
|
100
|
+
// `TTransformed` infers from the `onResult` return position (a covariant
|
|
101
|
+
// inference site that works even for an optional nested property), which types
|
|
102
|
+
// the callback parameter as `TResult` and narrows `result`. Inferring the
|
|
103
|
+
// whole callback as a defaulted type parameter instead collapses to the
|
|
104
|
+
// default, leaving the parameter `any` — a hard error under `strict`. See
|
|
105
|
+
// issue #848.
|
|
100
106
|
export function useGeneration<
|
|
101
107
|
TInput extends Record<string, any>,
|
|
102
108
|
TResult,
|
|
103
|
-
|
|
109
|
+
TTransformed = void,
|
|
104
110
|
>(
|
|
105
111
|
options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {
|
|
106
|
-
onResult?:
|
|
112
|
+
onResult?: (result: TResult) => TTransformed
|
|
107
113
|
},
|
|
108
|
-
): UseGenerationReturn<
|
|
109
|
-
type TOutput =
|
|
114
|
+
): UseGenerationReturn<InferGenerationOutputFromReturn<TResult, TTransformed>> {
|
|
115
|
+
type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>
|
|
110
116
|
const hookId = createUniqueId()
|
|
111
117
|
const clientId = options.id || hookId
|
|
112
118
|
|
|
@@ -128,7 +134,12 @@ export function useGeneration<
|
|
|
128
134
|
framework: 'solid',
|
|
129
135
|
hookName: 'useGeneration',
|
|
130
136
|
},
|
|
131
|
-
|
|
137
|
+
// The transform's raw return type (`TTransformed`) and the stored output
|
|
138
|
+
// (`TOutput`, with null/void/undefined stripped) are identical at runtime;
|
|
139
|
+
// the cast bridges the relationship that the conditional type hides.
|
|
140
|
+
onResult: ((r: TResult) => options.onResult?.(r)) as (
|
|
141
|
+
result: TResult,
|
|
142
|
+
) => TOutput | null | void,
|
|
132
143
|
onError: (e: Error) => options.onError?.(e),
|
|
133
144
|
onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
|
|
134
145
|
onChunk: (c: StreamChunk) => options.onChunk?.(c),
|
package/src/use-summarize.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
ConnectConnectionAdapter,
|
|
6
6
|
GenerationClientState,
|
|
7
7
|
GenerationFetcher,
|
|
8
|
-
|
|
8
|
+
InferGenerationOutputFromReturn,
|
|
9
9
|
SummarizeGenerateInput,
|
|
10
10
|
} from '@tanstack/ai-client'
|
|
11
11
|
import type { Accessor } from 'solid-js'
|
|
@@ -93,14 +93,13 @@ export interface UseSummarizeReturn<TOutput = SummarizationResult> {
|
|
|
93
93
|
* }
|
|
94
94
|
* ```
|
|
95
95
|
*/
|
|
96
|
-
export function useSummarize<
|
|
97
|
-
TOnResult extends ((result: SummarizationResult) => any) | undefined =
|
|
98
|
-
undefined,
|
|
99
|
-
>(
|
|
96
|
+
export function useSummarize<TTransformed = void>(
|
|
100
97
|
options: Omit<UseSummarizeOptions, 'onResult'> & {
|
|
101
|
-
onResult?:
|
|
98
|
+
onResult?: (result: SummarizationResult) => TTransformed
|
|
102
99
|
},
|
|
103
|
-
): UseSummarizeReturn<
|
|
100
|
+
): UseSummarizeReturn<
|
|
101
|
+
InferGenerationOutputFromReturn<SummarizationResult, TTransformed>
|
|
102
|
+
> {
|
|
104
103
|
const devtools = {
|
|
105
104
|
...options.devtools,
|
|
106
105
|
framework: 'solid',
|
|
@@ -108,7 +107,7 @@ export function useSummarize<
|
|
|
108
107
|
outputKind: 'text' as const,
|
|
109
108
|
}
|
|
110
109
|
const { generate, result, isLoading, error, status, stop, reset } =
|
|
111
|
-
useGeneration<SummarizeGenerateInput, SummarizationResult,
|
|
110
|
+
useGeneration<SummarizeGenerateInput, SummarizationResult, TTransformed>({
|
|
112
111
|
...options,
|
|
113
112
|
devtools,
|
|
114
113
|
})
|
package/src/use-transcription.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
ConnectConnectionAdapter,
|
|
6
6
|
GenerationClientState,
|
|
7
7
|
GenerationFetcher,
|
|
8
|
-
|
|
8
|
+
InferGenerationOutputFromReturn,
|
|
9
9
|
TranscriptionGenerateInput,
|
|
10
10
|
} from '@tanstack/ai-client'
|
|
11
11
|
import type { Accessor } from 'solid-js'
|
|
@@ -99,15 +99,12 @@ export interface UseTranscriptionReturn<TOutput = TranscriptionResult> {
|
|
|
99
99
|
* }
|
|
100
100
|
* ```
|
|
101
101
|
*/
|
|
102
|
-
export function useTranscription<
|
|
103
|
-
TOnResult extends ((result: TranscriptionResult) => any) | undefined =
|
|
104
|
-
undefined,
|
|
105
|
-
>(
|
|
102
|
+
export function useTranscription<TTransformed = void>(
|
|
106
103
|
options: Omit<UseTranscriptionOptions, 'onResult'> & {
|
|
107
|
-
onResult?:
|
|
104
|
+
onResult?: (result: TranscriptionResult) => TTransformed
|
|
108
105
|
},
|
|
109
106
|
): UseTranscriptionReturn<
|
|
110
|
-
|
|
107
|
+
InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>
|
|
111
108
|
> {
|
|
112
109
|
const devtools = {
|
|
113
110
|
...options.devtools,
|
|
@@ -116,10 +113,11 @@ export function useTranscription<
|
|
|
116
113
|
outputKind: 'text' as const,
|
|
117
114
|
}
|
|
118
115
|
const { generate, result, isLoading, error, status, stop, reset } =
|
|
119
|
-
useGeneration<
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
useGeneration<
|
|
117
|
+
TranscriptionGenerateInput,
|
|
118
|
+
TranscriptionResult,
|
|
119
|
+
TTransformed
|
|
120
|
+
>({ ...options, devtools })
|
|
123
121
|
|
|
124
122
|
return {
|
|
125
123
|
generate: generate as (input: TranscriptionGenerateInput) => Promise<void>,
|