@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.
Files changed (40) hide show
  1. package/dist/index.d.ts +12 -0
  2. package/dist/index.js +12 -0
  3. package/dist/types.d.ts +139 -0
  4. package/dist/use-audio-recorder.d.ts +37 -0
  5. package/dist/use-audio-recorder.js +39 -0
  6. package/dist/use-audio-recorder.js.map +1 -0
  7. package/dist/use-chat.d.ts +9 -0
  8. package/dist/use-chat.js +162 -0
  9. package/dist/use-chat.js.map +1 -0
  10. package/dist/use-generate-audio.d.ts +88 -0
  11. package/dist/use-generate-audio.js +52 -0
  12. package/dist/use-generate-audio.js.map +1 -0
  13. package/dist/use-generate-image.d.ts +96 -0
  14. package/dist/use-generate-image.js +60 -0
  15. package/dist/use-generate-image.js.map +1 -0
  16. package/dist/use-generate-speech.d.ts +90 -0
  17. package/dist/use-generate-speech.js +54 -0
  18. package/dist/use-generate-speech.js.map +1 -0
  19. package/dist/use-generate-video.d.ts +103 -0
  20. package/dist/use-generate-video.js +114 -0
  21. package/dist/use-generate-video.js.map +1 -0
  22. package/dist/use-generation.d.ts +88 -0
  23. package/dist/use-generation.js +94 -0
  24. package/dist/use-generation.js.map +1 -0
  25. package/dist/use-summarize.d.ts +93 -0
  26. package/dist/use-summarize.js +57 -0
  27. package/dist/use-summarize.js.map +1 -0
  28. package/dist/use-transcription.d.ts +99 -0
  29. package/dist/use-transcription.js +63 -0
  30. package/dist/use-transcription.js.map +1 -0
  31. package/package.json +4 -4
  32. package/src/index.ts +6 -0
  33. package/src/use-audio-recorder.ts +87 -0
  34. package/src/use-generate-audio.ts +5 -8
  35. package/src/use-generate-image.ts +5 -8
  36. package/src/use-generate-speech.ts +7 -7
  37. package/src/use-generate-video.ts +17 -9
  38. package/src/use-generation.ts +17 -6
  39. package/src/use-summarize.ts +7 -8
  40. package/src/use-transcription.ts +9 -11
@@ -5,7 +5,7 @@ import type {
5
5
  ConnectConnectionAdapter,
6
6
  GenerationClientState,
7
7
  GenerationFetcher,
8
- InferGenerationOutput,
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?: TOnResult
95
+ onResult?: (result: TTSResult) => TTransformed
98
96
  },
99
- ): UseGenerateSpeechReturn<InferGenerationOutput<TTSResult, TOnResult>> {
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, TOnResult>({
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
- InferGenerationOutput,
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
- export function useGenerateVideo<
118
- TOnResult extends ((result: VideoGenerateResult) => any) | undefined =
119
- undefined,
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?: TOnResult
122
+ onResult?: (result: VideoGenerateResult) => TTransformed
123
123
  },
124
124
  ): UseGenerateVideoReturn<
125
- InferGenerationOutput<VideoGenerateResult, TOnResult>
125
+ InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>
126
126
  > {
127
- type TOutput = InferGenerationOutput<VideoGenerateResult, TOnResult>
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
- onResult: (r: VideoGenerateResult) => options.onResult?.(r),
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),
@@ -15,7 +15,7 @@ import type {
15
15
  GenerationClientOptions,
16
16
  GenerationClientState,
17
17
  GenerationFetcher,
18
- InferGenerationOutput,
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
- TOnResult extends ((result: TResult) => any) | undefined = undefined,
109
+ TTransformed = void,
104
110
  >(
105
111
  options: Omit<UseGenerationOptions<TInput, TResult>, 'onResult'> & {
106
- onResult?: TOnResult
112
+ onResult?: (result: TResult) => TTransformed
107
113
  },
108
- ): UseGenerationReturn<InferGenerationOutput<TResult, TOnResult>> {
109
- type TOutput = InferGenerationOutput<TResult, TOnResult>
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
- onResult: (r: TResult) => options.onResult?.(r),
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),
@@ -5,7 +5,7 @@ import type {
5
5
  ConnectConnectionAdapter,
6
6
  GenerationClientState,
7
7
  GenerationFetcher,
8
- InferGenerationOutput,
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?: TOnResult
98
+ onResult?: (result: SummarizationResult) => TTransformed
102
99
  },
103
- ): UseSummarizeReturn<InferGenerationOutput<SummarizationResult, TOnResult>> {
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, TOnResult>({
110
+ useGeneration<SummarizeGenerateInput, SummarizationResult, TTransformed>({
112
111
  ...options,
113
112
  devtools,
114
113
  })
@@ -5,7 +5,7 @@ import type {
5
5
  ConnectConnectionAdapter,
6
6
  GenerationClientState,
7
7
  GenerationFetcher,
8
- InferGenerationOutput,
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?: TOnResult
104
+ onResult?: (result: TranscriptionResult) => TTransformed
108
105
  },
109
106
  ): UseTranscriptionReturn<
110
- InferGenerationOutput<TranscriptionResult, TOnResult>
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<TranscriptionGenerateInput, TranscriptionResult, TOnResult>({
120
- ...options,
121
- devtools,
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>,