@tanstack/ai-solid 0.16.3 → 0.18.1
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/README.md +2 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/types.d.ts +9 -9
- package/dist/use-chat.d.ts +2 -2
- package/dist/use-chat.js +7 -4
- package/dist/use-chat.js.map +1 -1
- package/dist/use-generate-audio.d.ts +1 -5
- package/dist/use-generate-audio.js.map +1 -1
- package/dist/use-generate-image.d.ts +1 -5
- package/dist/use-generate-image.js.map +1 -1
- package/dist/use-generate-speech.d.ts +1 -5
- package/dist/use-generate-speech.js.map +1 -1
- package/dist/use-generate-video.d.ts +3 -7
- package/dist/use-generate-video.js +5 -4
- package/dist/use-generate-video.js.map +1 -1
- package/dist/use-generation.d.ts +3 -7
- package/dist/use-generation.js +7 -4
- package/dist/use-generation.js.map +1 -1
- package/dist/use-summarize.d.ts +1 -5
- package/dist/use-summarize.js.map +1 -1
- package/dist/use-transcription.d.ts +1 -5
- package/dist/use-transcription.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +2 -0
- package/src/types.ts +21 -11
- package/src/use-chat.ts +36 -19
- package/src/use-generate-audio.ts +1 -5
- package/src/use-generate-image.ts +1 -5
- package/src/use-generate-speech.ts +1 -5
- package/src/use-generate-video.ts +13 -17
- package/src/use-generation.ts +21 -17
- package/src/use-summarize.ts +1 -5
- package/src/use-transcription.ts +1 -5
package/src/use-generation.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { createGenerationDevtoolsBridge } from '@tanstack/ai-client/devtools'
|
|
|
3
3
|
import {
|
|
4
4
|
createEffect,
|
|
5
5
|
createSignal,
|
|
6
|
-
createUniqueId,
|
|
7
6
|
onCleanup,
|
|
8
7
|
onMount,
|
|
9
8
|
untrack,
|
|
@@ -35,10 +34,6 @@ export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
|
35
34
|
connection?: ConnectConnectionAdapter
|
|
36
35
|
/** Direct async function for one-shot generation (no streaming protocol needed) */
|
|
37
36
|
fetcher?: GenerationFetcher<TInput, TResult>
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Prefer `threadId`. Only allowed when `threadId` is omitted (see `GenerationPersistenceOptions`).
|
|
40
|
-
*/
|
|
41
|
-
id?: string
|
|
42
37
|
/** Additional body parameters to send with connect-based adapter requests */
|
|
43
38
|
body?: Record<string, any>
|
|
44
39
|
/** Display options for TanStack AI Devtools. */
|
|
@@ -62,8 +57,8 @@ export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
|
62
57
|
* id on the wire, which the protocol requires.
|
|
63
58
|
*
|
|
64
59
|
* **Required whenever `persistence` is set** — an app that cannot name the
|
|
65
|
-
* scope has nothing to restore to. Optional for ephemeral generations
|
|
66
|
-
*
|
|
60
|
+
* scope has nothing to restore to. Optional for ephemeral generations. If
|
|
61
|
+
* omitted, the client mints a wire id after mount.
|
|
67
62
|
*/
|
|
68
63
|
threadId?: string
|
|
69
64
|
/**
|
|
@@ -168,7 +163,7 @@ export function useGeneration<
|
|
|
168
163
|
>(
|
|
169
164
|
options: Omit<
|
|
170
165
|
UseGenerationOptions<TInput, TResult>,
|
|
171
|
-
'onResult' | 'persistence' | 'threadId'
|
|
166
|
+
'onResult' | 'persistence' | 'threadId'
|
|
172
167
|
> & {
|
|
173
168
|
onResult?: (result: TResult) => TTransformed
|
|
174
169
|
} & GenerationPersistenceOptions,
|
|
@@ -177,7 +172,6 @@ export function useGeneration<
|
|
|
177
172
|
TInput
|
|
178
173
|
> {
|
|
179
174
|
type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>
|
|
180
|
-
const hookId = createUniqueId()
|
|
181
175
|
|
|
182
176
|
const [result, setResult] = createSignal<TOutput | null>(null)
|
|
183
177
|
const [isLoading, setIsLoading] = createSignal(false)
|
|
@@ -195,15 +189,11 @@ export function useGeneration<
|
|
|
195
189
|
// Conditional spread on `body`: `GenerationClientOptions.body` is a
|
|
196
190
|
// strict optional (`body?: Record<string, any>`) and EOPT forbids
|
|
197
191
|
// assigning the source `T | undefined` directly.
|
|
198
|
-
const clientOptions:
|
|
192
|
+
const clientOptions: Omit<
|
|
193
|
+
GenerationClientOptions<TInput, TResult, TOutput>,
|
|
194
|
+
'persistence' | 'threadId'
|
|
195
|
+
> = {
|
|
199
196
|
body: options.body,
|
|
200
|
-
// Identity: pass `threadId` alone when set (never also pass deprecated `id`).
|
|
201
|
-
...(options.threadId !== undefined
|
|
202
|
-
? { threadId: options.threadId }
|
|
203
|
-
: { id: options.id ?? hookId }),
|
|
204
|
-
...(options.persistence !== undefined && {
|
|
205
|
-
persistence: options.persistence,
|
|
206
|
-
}),
|
|
207
197
|
...(options.hydrateGeneration !== undefined && {
|
|
208
198
|
hydrateGeneration: options.hydrateGeneration,
|
|
209
199
|
}),
|
|
@@ -249,9 +239,22 @@ export function useGeneration<
|
|
|
249
239
|
},
|
|
250
240
|
}
|
|
251
241
|
|
|
242
|
+
const persistenceProps =
|
|
243
|
+
typeof options.threadId === 'string' && options.persistence
|
|
244
|
+
? {
|
|
245
|
+
persistence: options.persistence,
|
|
246
|
+
threadId: options.threadId,
|
|
247
|
+
}
|
|
248
|
+
: {
|
|
249
|
+
...(options.threadId !== undefined && {
|
|
250
|
+
threadId: options.threadId,
|
|
251
|
+
}),
|
|
252
|
+
}
|
|
253
|
+
|
|
252
254
|
if (options.connection) {
|
|
253
255
|
return new GenerationClient<TInput, TResult, TOutput>({
|
|
254
256
|
...clientOptions,
|
|
257
|
+
...persistenceProps,
|
|
255
258
|
connection: options.connection,
|
|
256
259
|
})
|
|
257
260
|
}
|
|
@@ -259,6 +262,7 @@ export function useGeneration<
|
|
|
259
262
|
if (options.fetcher) {
|
|
260
263
|
return new GenerationClient<TInput, TResult, TOutput>({
|
|
261
264
|
...clientOptions,
|
|
265
|
+
...persistenceProps,
|
|
262
266
|
fetcher: options.fetcher,
|
|
263
267
|
})
|
|
264
268
|
}
|
package/src/use-summarize.ts
CHANGED
|
@@ -31,10 +31,6 @@ export interface UseSummarizeOptions<
|
|
|
31
31
|
connection?: ConnectConnectionAdapter
|
|
32
32
|
/** Direct async function for summarization */
|
|
33
33
|
fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>
|
|
34
|
-
/**
|
|
35
|
-
* @deprecated Prefer `threadId`. Only allowed when `threadId` is omitted (see `GenerationPersistenceOptions`).
|
|
36
|
-
*/
|
|
37
|
-
id?: string
|
|
38
34
|
/** Additional body parameters to send with connect-based adapter requests */
|
|
39
35
|
body?: Record<string, any>
|
|
40
36
|
/** Display options for TanStack AI Devtools. */
|
|
@@ -108,7 +104,7 @@ export interface UseSummarizeReturn<TOutput = SummarizationResult> extends Omit<
|
|
|
108
104
|
export function useSummarize<TTransformed = void>(
|
|
109
105
|
options: Omit<
|
|
110
106
|
UseSummarizeOptions,
|
|
111
|
-
'onResult' | 'persistence' | 'threadId'
|
|
107
|
+
'onResult' | 'persistence' | 'threadId'
|
|
112
108
|
> & {
|
|
113
109
|
onResult?: (result: SummarizationResult) => TTransformed
|
|
114
110
|
} & GenerationPersistenceOptions,
|
package/src/use-transcription.ts
CHANGED
|
@@ -35,10 +35,6 @@ export interface UseTranscriptionOptions<
|
|
|
35
35
|
connection?: ConnectConnectionAdapter
|
|
36
36
|
/** Direct async function for transcription */
|
|
37
37
|
fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Prefer `threadId`. Only allowed when `threadId` is omitted (see `GenerationPersistenceOptions`).
|
|
40
|
-
*/
|
|
41
|
-
id?: string
|
|
42
38
|
/** Additional body parameters to send with connect-based adapter requests */
|
|
43
39
|
body?: Record<string, any>
|
|
44
40
|
/** Display options for TanStack AI Devtools. */
|
|
@@ -117,7 +113,7 @@ export interface UseTranscriptionReturn<
|
|
|
117
113
|
export function useTranscription<TTransformed = void>(
|
|
118
114
|
options: Omit<
|
|
119
115
|
UseTranscriptionOptions,
|
|
120
|
-
'onResult' | 'persistence' | 'threadId'
|
|
116
|
+
'onResult' | 'persistence' | 'threadId'
|
|
121
117
|
> & {
|
|
122
118
|
onResult?: (result: TranscriptionResult) => TTransformed
|
|
123
119
|
} & GenerationPersistenceOptions,
|