@tanstack/ai-solid 0.13.14 → 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 +12 -0
- package/dist/index.js +12 -0
- package/dist/types.d.ts +139 -0
- 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-chat.d.ts +9 -0
- package/dist/use-chat.js +162 -0
- package/dist/use-chat.js.map +1 -0
- package/dist/use-generate-audio.d.ts +88 -0
- package/dist/use-generate-audio.js +52 -0
- package/dist/use-generate-audio.js.map +1 -0
- package/dist/use-generate-image.d.ts +96 -0
- package/dist/use-generate-image.js +60 -0
- package/dist/use-generate-image.js.map +1 -0
- package/dist/use-generate-speech.d.ts +90 -0
- package/dist/use-generate-speech.js +54 -0
- package/dist/use-generate-speech.js.map +1 -0
- package/dist/use-generate-video.d.ts +103 -0
- package/dist/use-generate-video.js +114 -0
- package/dist/use-generate-video.js.map +1 -0
- package/dist/use-generation.d.ts +88 -0
- package/dist/use-generation.js +94 -0
- package/dist/use-generation.js.map +1 -0
- package/dist/use-summarize.d.ts +93 -0
- package/dist/use-summarize.js +57 -0
- package/dist/use-summarize.js.map +1 -0
- package/dist/use-transcription.d.ts +99 -0
- package/dist/use-transcription.js +63 -0
- package/dist/use-transcription.js.map +1 -0
- 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
|
@@ -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>,
|