@tanstack/ai-svelte 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/create-audio-recorder.svelte.d.ts +37 -0
- package/dist/create-audio-recorder.svelte.js +36 -0
- package/dist/create-chat.svelte.d.ts +34 -0
- package/dist/create-chat.svelte.js +248 -0
- package/dist/create-generate-audio.svelte.d.ts +85 -0
- package/dist/create-generate-audio.svelte.js +57 -0
- package/dist/create-generate-image.svelte.d.ts +94 -0
- package/dist/create-generate-image.svelte.js +66 -0
- package/dist/create-generate-speech.svelte.d.ts +85 -0
- package/dist/create-generate-speech.svelte.js +57 -0
- package/dist/create-generate-video.svelte.d.ts +99 -0
- package/dist/create-generate-video.svelte.js +149 -0
- package/dist/create-generation.svelte.d.ts +96 -0
- package/dist/create-generation.svelte.js +136 -0
- package/dist/create-summarize.svelte.d.ts +89 -0
- package/dist/create-summarize.svelte.js +61 -0
- package/dist/create-transcription.svelte.d.ts +94 -0
- package/dist/create-transcription.svelte.js +66 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +12 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.js +3 -0
- package/package.json +4 -4
- package/src/create-audio-recorder.svelte.ts +93 -0
- package/src/create-generate-audio.svelte.ts +5 -8
- package/src/create-generate-image.svelte.ts +5 -8
- package/src/create-generate-speech.svelte.ts +7 -7
- package/src/create-generate-video.svelte.ts +17 -9
- package/src/create-generation.svelte.ts +19 -6
- package/src/create-summarize.svelte.ts +5 -8
- package/src/create-transcription.svelte.ts +5 -8
- package/src/index.ts +6 -0
|
@@ -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
|
|
|
12
12
|
/**
|
|
@@ -100,15 +100,12 @@ export interface CreateGenerateImageReturn<TOutput = ImageGenerationResult> {
|
|
|
100
100
|
* </div>
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
|
-
export function createGenerateImage<
|
|
104
|
-
TOnResult extends ((result: ImageGenerationResult) => any) | undefined =
|
|
105
|
-
undefined,
|
|
106
|
-
>(
|
|
103
|
+
export function createGenerateImage<TTransformed = void>(
|
|
107
104
|
options: Omit<CreateGenerateImageOptions, 'onResult'> & {
|
|
108
|
-
onResult?:
|
|
105
|
+
onResult?: (result: ImageGenerationResult) => TTransformed
|
|
109
106
|
},
|
|
110
107
|
): CreateGenerateImageReturn<
|
|
111
|
-
|
|
108
|
+
InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>
|
|
112
109
|
> {
|
|
113
110
|
const devtools = {
|
|
114
111
|
...options.devtools,
|
|
@@ -119,7 +116,7 @@ export function createGenerateImage<
|
|
|
119
116
|
const gen = createGeneration<
|
|
120
117
|
ImageGenerateInput,
|
|
121
118
|
ImageGenerationResult,
|
|
122
|
-
|
|
119
|
+
TTransformed
|
|
123
120
|
>({
|
|
124
121
|
...options,
|
|
125
122
|
devtools,
|
|
@@ -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
|
|
|
@@ -91,20 +91,20 @@ export interface CreateGenerateSpeechReturn<TOutput = TTSResult> {
|
|
|
91
91
|
* </div>
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
94
|
-
export function createGenerateSpeech<
|
|
95
|
-
TOnResult extends ((result: TTSResult) => any) | undefined = undefined,
|
|
96
|
-
>(
|
|
94
|
+
export function createGenerateSpeech<TTransformed = void>(
|
|
97
95
|
options: Omit<CreateGenerateSpeechOptions, 'onResult'> & {
|
|
98
|
-
onResult?:
|
|
96
|
+
onResult?: (result: TTSResult) => TTransformed
|
|
99
97
|
},
|
|
100
|
-
): CreateGenerateSpeechReturn<
|
|
98
|
+
): CreateGenerateSpeechReturn<
|
|
99
|
+
InferGenerationOutputFromReturn<TTSResult, TTransformed>
|
|
100
|
+
> {
|
|
101
101
|
const devtools = {
|
|
102
102
|
...options.devtools,
|
|
103
103
|
framework: 'svelte',
|
|
104
104
|
hookName: 'createGenerateSpeech',
|
|
105
105
|
outputKind: 'audio' as const,
|
|
106
106
|
}
|
|
107
|
-
const gen = createGeneration<SpeechGenerateInput, TTSResult,
|
|
107
|
+
const gen = createGeneration<SpeechGenerateInput, TTSResult, TTransformed>({
|
|
108
108
|
...options,
|
|
109
109
|
devtools,
|
|
110
110
|
})
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
ConnectConnectionAdapter,
|
|
7
7
|
GenerationClientState,
|
|
8
8
|
GenerationFetcher,
|
|
9
|
-
|
|
9
|
+
InferGenerationOutputFromReturn,
|
|
10
10
|
VideoGenerateInput,
|
|
11
11
|
VideoGenerateResult,
|
|
12
12
|
VideoStatusInfo,
|
|
@@ -108,17 +108,20 @@ export interface CreateGenerateVideoReturn<TOutput = VideoGenerateResult> {
|
|
|
108
108
|
* </div>
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
>(
|
|
111
|
+
// `TTransformed` infers from the `onResult` return position so the callback
|
|
112
|
+
// parameter is typed as `VideoGenerateResult` and `result` narrows to the
|
|
113
|
+
// transform's return. See issue #848.
|
|
114
|
+
export function createGenerateVideo<TTransformed = void>(
|
|
115
115
|
options: Omit<CreateGenerateVideoOptions, 'onResult'> & {
|
|
116
|
-
onResult?:
|
|
116
|
+
onResult?: (result: VideoGenerateResult) => TTransformed
|
|
117
117
|
},
|
|
118
118
|
): CreateGenerateVideoReturn<
|
|
119
|
-
|
|
119
|
+
InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>
|
|
120
120
|
> {
|
|
121
|
-
type TOutput =
|
|
121
|
+
type TOutput = InferGenerationOutputFromReturn<
|
|
122
|
+
VideoGenerateResult,
|
|
123
|
+
TTransformed
|
|
124
|
+
>
|
|
122
125
|
const clientId =
|
|
123
126
|
options.id ||
|
|
124
127
|
`video-${Date.now()}-${Math.random().toString(36).substring(7)}`
|
|
@@ -145,7 +148,12 @@ export function createGenerateVideo<
|
|
|
145
148
|
hookName: 'createGenerateVideo',
|
|
146
149
|
outputKind: 'video' as const,
|
|
147
150
|
},
|
|
148
|
-
|
|
151
|
+
// The transform's raw return type (`TTransformed`) and the stored output
|
|
152
|
+
// (`TOutput`, with null/void/undefined stripped) are identical at runtime;
|
|
153
|
+
// the cast bridges the relationship that the conditional type hides.
|
|
154
|
+
onResult: ((r: VideoGenerateResult) => options.onResult?.(r)) as (
|
|
155
|
+
result: VideoGenerateResult,
|
|
156
|
+
) => TOutput | null | void,
|
|
149
157
|
onError: (e: Error) => options.onError?.(e),
|
|
150
158
|
onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
|
|
151
159
|
onChunk: (c: StreamChunk) => options.onChunk?.(c),
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
GenerationClientOptions,
|
|
8
8
|
GenerationClientState,
|
|
9
9
|
GenerationFetcher,
|
|
10
|
-
|
|
10
|
+
InferGenerationOutputFromReturn,
|
|
11
11
|
} from '@tanstack/ai-client'
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -103,16 +103,24 @@ export interface CreateGenerationReturn<TOutput> {
|
|
|
103
103
|
* </div>
|
|
104
104
|
* ```
|
|
105
105
|
*/
|
|
106
|
+
// `TTransformed` infers from the `onResult` return position (a covariant
|
|
107
|
+
// inference site that works even for an optional nested property), which types
|
|
108
|
+
// the callback parameter as `TResult` and narrows `result`. Inferring the
|
|
109
|
+
// whole callback as a defaulted type parameter instead collapses to the
|
|
110
|
+
// default, leaving the parameter `any` — a hard error under `strict`. See
|
|
111
|
+
// issue #848.
|
|
106
112
|
export function createGeneration<
|
|
107
113
|
TInput extends Record<string, any>,
|
|
108
114
|
TResult,
|
|
109
|
-
|
|
115
|
+
TTransformed = void,
|
|
110
116
|
>(
|
|
111
117
|
options: Omit<CreateGenerationOptions<TInput, TResult>, 'onResult'> & {
|
|
112
|
-
onResult?:
|
|
118
|
+
onResult?: (result: TResult) => TTransformed
|
|
113
119
|
},
|
|
114
|
-
): CreateGenerationReturn<
|
|
115
|
-
|
|
120
|
+
): CreateGenerationReturn<
|
|
121
|
+
InferGenerationOutputFromReturn<TResult, TTransformed>
|
|
122
|
+
> {
|
|
123
|
+
type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>
|
|
116
124
|
const clientId =
|
|
117
125
|
options.id || `gen-${Date.now()}-${Math.random().toString(36).substring(7)}`
|
|
118
126
|
|
|
@@ -136,7 +144,12 @@ export function createGeneration<
|
|
|
136
144
|
framework: 'svelte',
|
|
137
145
|
hookName: 'createGeneration',
|
|
138
146
|
},
|
|
139
|
-
|
|
147
|
+
// The transform's raw return type (`TTransformed`) and the stored output
|
|
148
|
+
// (`TOutput`, with null/void/undefined stripped) are identical at runtime;
|
|
149
|
+
// the cast bridges the relationship that the conditional type hides.
|
|
150
|
+
onResult: ((r: TResult) => options.onResult?.(r)) as (
|
|
151
|
+
result: TResult,
|
|
152
|
+
) => TOutput | null | void,
|
|
140
153
|
onError: (e: Error) => options.onError?.(e),
|
|
141
154
|
onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
|
|
142
155
|
onChunk: (c: StreamChunk) => options.onChunk?.(c),
|
|
@@ -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
|
|
|
@@ -95,15 +95,12 @@ export interface CreateSummarizeReturn<TOutput = SummarizationResult> {
|
|
|
95
95
|
* </div>
|
|
96
96
|
* ```
|
|
97
97
|
*/
|
|
98
|
-
export function createSummarize<
|
|
99
|
-
TOnResult extends ((result: SummarizationResult) => any) | undefined =
|
|
100
|
-
undefined,
|
|
101
|
-
>(
|
|
98
|
+
export function createSummarize<TTransformed = void>(
|
|
102
99
|
options: Omit<CreateSummarizeOptions, 'onResult'> & {
|
|
103
|
-
onResult?:
|
|
100
|
+
onResult?: (result: SummarizationResult) => TTransformed
|
|
104
101
|
},
|
|
105
102
|
): CreateSummarizeReturn<
|
|
106
|
-
|
|
103
|
+
InferGenerationOutputFromReturn<SummarizationResult, TTransformed>
|
|
107
104
|
> {
|
|
108
105
|
const devtools = {
|
|
109
106
|
...options.devtools,
|
|
@@ -114,7 +111,7 @@ export function createSummarize<
|
|
|
114
111
|
const gen = createGeneration<
|
|
115
112
|
SummarizeGenerateInput,
|
|
116
113
|
SummarizationResult,
|
|
117
|
-
|
|
114
|
+
TTransformed
|
|
118
115
|
>({
|
|
119
116
|
...options,
|
|
120
117
|
devtools,
|
|
@@ -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
|
|
|
@@ -100,15 +100,12 @@ export interface CreateTranscriptionReturn<TOutput = TranscriptionResult> {
|
|
|
100
100
|
* </div>
|
|
101
101
|
* ```
|
|
102
102
|
*/
|
|
103
|
-
export function createTranscription<
|
|
104
|
-
TOnResult extends ((result: TranscriptionResult) => any) | undefined =
|
|
105
|
-
undefined,
|
|
106
|
-
>(
|
|
103
|
+
export function createTranscription<TTransformed = void>(
|
|
107
104
|
options: Omit<CreateTranscriptionOptions, 'onResult'> & {
|
|
108
|
-
onResult?:
|
|
105
|
+
onResult?: (result: TranscriptionResult) => TTransformed
|
|
109
106
|
},
|
|
110
107
|
): CreateTranscriptionReturn<
|
|
111
|
-
|
|
108
|
+
InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>
|
|
112
109
|
> {
|
|
113
110
|
const devtools = {
|
|
114
111
|
...options.devtools,
|
|
@@ -119,7 +116,7 @@ export function createTranscription<
|
|
|
119
116
|
const gen = createGeneration<
|
|
120
117
|
TranscriptionGenerateInput,
|
|
121
118
|
TranscriptionResult,
|
|
122
|
-
|
|
119
|
+
TTransformed
|
|
123
120
|
>({
|
|
124
121
|
...options,
|
|
125
122
|
devtools,
|
package/src/index.ts
CHANGED
|
@@ -50,6 +50,12 @@ export type {
|
|
|
50
50
|
CreateGenerateVideoReturn,
|
|
51
51
|
} from './create-generate-video.svelte'
|
|
52
52
|
|
|
53
|
+
export { createAudioRecorder } from './create-audio-recorder.svelte'
|
|
54
|
+
export type {
|
|
55
|
+
CreateAudioRecorderOptions,
|
|
56
|
+
CreateAudioRecorderReturn,
|
|
57
|
+
} from './create-audio-recorder.svelte'
|
|
58
|
+
|
|
53
59
|
// Re-export from ai-client for convenience
|
|
54
60
|
export {
|
|
55
61
|
fetchServerSentEvents,
|