@tanstack/ai-react 0.19.3 → 0.21.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 +14 -5
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/types.d.ts +9 -9
- package/dist/esm/use-chat.d.ts +2 -2
- package/dist/esm/use-chat.js +92 -55
- package/dist/esm/use-chat.js.map +1 -1
- package/dist/esm/use-generate-audio.d.ts +3 -7
- package/dist/esm/use-generate-audio.js.map +1 -1
- package/dist/esm/use-generate-image.d.ts +3 -7
- package/dist/esm/use-generate-image.js.map +1 -1
- package/dist/esm/use-generate-speech.d.ts +3 -7
- package/dist/esm/use-generate-speech.js.map +1 -1
- package/dist/esm/use-generate-video.d.ts +3 -7
- package/dist/esm/use-generate-video.js +7 -3
- package/dist/esm/use-generate-video.js.map +1 -1
- package/dist/esm/use-generation.d.ts +3 -7
- package/dist/esm/use-generation.js +7 -3
- package/dist/esm/use-generation.js.map +1 -1
- package/dist/esm/use-summarize.d.ts +3 -7
- package/dist/esm/use-summarize.js.map +1 -1
- package/dist/esm/use-transcription.d.ts +3 -7
- package/dist/esm/use-transcription.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +4 -0
- package/src/types.ts +19 -11
- package/src/use-chat.ts +132 -72
- package/src/use-generate-audio.ts +3 -7
- package/src/use-generate-image.ts +3 -7
- package/src/use-generate-speech.ts +3 -7
- package/src/use-generate-video.ts +22 -15
- package/src/use-generation.ts +21 -15
- package/src/use-summarize.ts +3 -7
- package/src/use-transcription.ts +3 -7
package/src/use-generation.ts
CHANGED
|
@@ -27,10 +27,6 @@ export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
|
27
27
|
connection?: ConnectConnectionAdapter
|
|
28
28
|
/** Direct async function for one-shot generation (no streaming protocol needed) */
|
|
29
29
|
fetcher?: GenerationFetcher<TInput, TResult>
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated Prefer `threadId`. Only allowed when `threadId` is omitted (see `GenerationPersistenceOptions`).
|
|
32
|
-
*/
|
|
33
|
-
id?: string
|
|
34
30
|
/** Additional body parameters to send with connect-based adapter requests */
|
|
35
31
|
body?: Record<string, any>
|
|
36
32
|
/** Display options for TanStack AI Devtools. */
|
|
@@ -54,8 +50,8 @@ export interface UseGenerationOptions<TInput, TResult, TOutput = TResult> {
|
|
|
54
50
|
* id on the wire, which the protocol requires.
|
|
55
51
|
*
|
|
56
52
|
* **Required whenever `persistence` is set** — an app that cannot name the
|
|
57
|
-
* scope has nothing to restore to. Optional for ephemeral generations
|
|
58
|
-
*
|
|
53
|
+
* scope has nothing to restore to. Optional for ephemeral generations. If
|
|
54
|
+
* omitted, the client mints a wire id after mount.
|
|
59
55
|
*/
|
|
60
56
|
threadId?: string
|
|
61
57
|
/**
|
|
@@ -159,7 +155,7 @@ export function useGeneration<
|
|
|
159
155
|
>(
|
|
160
156
|
options: Omit<
|
|
161
157
|
UseGenerationOptions<TInput, TResult>,
|
|
162
|
-
'onResult' | 'persistence' | 'threadId'
|
|
158
|
+
'onResult' | 'persistence' | 'threadId'
|
|
163
159
|
> & {
|
|
164
160
|
onResult?: (result: TResult) => TTransformed
|
|
165
161
|
} & GenerationPersistenceOptions,
|
|
@@ -169,8 +165,8 @@ export function useGeneration<
|
|
|
169
165
|
> {
|
|
170
166
|
type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>
|
|
171
167
|
const hookId = useId()
|
|
172
|
-
//
|
|
173
|
-
const clientIdentity = options.threadId ??
|
|
168
|
+
// The hook identity is `threadId`. `hookId` is only a React recreation key.
|
|
169
|
+
const clientIdentity = options.threadId ?? hookId
|
|
174
170
|
|
|
175
171
|
const [result, setResult] = useState<TOutput | null>(null)
|
|
176
172
|
const [isLoading, setIsLoading] = useState(false)
|
|
@@ -189,13 +185,11 @@ export function useGeneration<
|
|
|
189
185
|
// local source is `Record<string, any> | undefined`). Callbacks
|
|
190
186
|
// wrap optional ones in non-returning bodies so `?.()`'s
|
|
191
187
|
// implicit `undefined` doesn't pollute the function return type.
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
const clientOptions: Omit<
|
|
189
|
+
GenerationClientOptions<TInput, TResult, TOutput>,
|
|
190
|
+
'persistence' | 'threadId'
|
|
191
|
+
> = {
|
|
194
192
|
body: opts.body,
|
|
195
|
-
...(opts.threadId !== undefined
|
|
196
|
-
? { threadId: opts.threadId }
|
|
197
|
-
: { id: opts.id ?? hookId }),
|
|
198
|
-
...(opts.persistence !== undefined && { persistence: opts.persistence }),
|
|
199
193
|
...(opts.hydrateGeneration !== undefined && {
|
|
200
194
|
hydrateGeneration: opts.hydrateGeneration,
|
|
201
195
|
}),
|
|
@@ -241,9 +235,20 @@ export function useGeneration<
|
|
|
241
235
|
},
|
|
242
236
|
}
|
|
243
237
|
|
|
238
|
+
const persistenceProps =
|
|
239
|
+
typeof opts.threadId === 'string' && opts.persistence
|
|
240
|
+
? {
|
|
241
|
+
persistence: opts.persistence,
|
|
242
|
+
threadId: opts.threadId,
|
|
243
|
+
}
|
|
244
|
+
: {
|
|
245
|
+
...(opts.threadId !== undefined && { threadId: opts.threadId }),
|
|
246
|
+
}
|
|
247
|
+
|
|
244
248
|
if (opts.connection) {
|
|
245
249
|
return new GenerationClient<TInput, TResult, TOutput>({
|
|
246
250
|
...clientOptions,
|
|
251
|
+
...persistenceProps,
|
|
247
252
|
connection: opts.connection,
|
|
248
253
|
})
|
|
249
254
|
}
|
|
@@ -251,6 +256,7 @@ export function useGeneration<
|
|
|
251
256
|
if (opts.fetcher) {
|
|
252
257
|
return new GenerationClient<TInput, TResult, TOutput>({
|
|
253
258
|
...clientOptions,
|
|
259
|
+
...persistenceProps,
|
|
254
260
|
fetcher: opts.fetcher,
|
|
255
261
|
})
|
|
256
262
|
}
|
package/src/use-summarize.ts
CHANGED
|
@@ -21,10 +21,6 @@ export interface UseSummarizeOptions<TOutput = SummarizationResult> {
|
|
|
21
21
|
connection?: ConnectConnectionAdapter
|
|
22
22
|
/** Direct async function for summarization */
|
|
23
23
|
fetcher?: GenerationFetcher<SummarizeGenerateInput, SummarizationResult>
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Prefer `threadId`. Only allowed when `threadId` is omitted (see `GenerationPersistenceOptions`).
|
|
26
|
-
*/
|
|
27
|
-
id?: string
|
|
28
24
|
/** Additional body parameters to send with connect-based adapter requests */
|
|
29
25
|
body?: Record<string, any>
|
|
30
26
|
/** Display options for TanStack AI Devtools. */
|
|
@@ -48,8 +44,8 @@ export interface UseSummarizeOptions<TOutput = SummarizationResult> {
|
|
|
48
44
|
* id on the wire, which the protocol requires.
|
|
49
45
|
*
|
|
50
46
|
* **Required whenever `persistence` is set** — an app that cannot name the
|
|
51
|
-
* scope has nothing to restore to. Optional for ephemeral generations
|
|
52
|
-
*
|
|
47
|
+
* scope has nothing to restore to. Optional for ephemeral generations. If
|
|
48
|
+
* omitted, the client mints a wire id after mount.
|
|
53
49
|
*/
|
|
54
50
|
threadId?: string
|
|
55
51
|
/**
|
|
@@ -143,7 +139,7 @@ export interface UseSummarizeReturn<TOutput = SummarizationResult> {
|
|
|
143
139
|
export function useSummarize<TTransformed = void>(
|
|
144
140
|
options: Omit<
|
|
145
141
|
UseSummarizeOptions,
|
|
146
|
-
'onResult' | 'persistence' | 'threadId'
|
|
142
|
+
'onResult' | 'persistence' | 'threadId'
|
|
147
143
|
> & {
|
|
148
144
|
onResult?: (result: SummarizationResult) => TTransformed
|
|
149
145
|
} & GenerationPersistenceOptions,
|
package/src/use-transcription.ts
CHANGED
|
@@ -21,10 +21,6 @@ export interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
|
|
|
21
21
|
connection?: ConnectConnectionAdapter
|
|
22
22
|
/** Direct async function for transcription */
|
|
23
23
|
fetcher?: GenerationFetcher<TranscriptionGenerateInput, TranscriptionResult>
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Prefer `threadId`. Only allowed when `threadId` is omitted (see `GenerationPersistenceOptions`).
|
|
26
|
-
*/
|
|
27
|
-
id?: string
|
|
28
24
|
/** Additional body parameters to send with connect-based adapter requests */
|
|
29
25
|
body?: Record<string, any>
|
|
30
26
|
/** Display options for TanStack AI Devtools. */
|
|
@@ -48,8 +44,8 @@ export interface UseTranscriptionOptions<TOutput = TranscriptionResult> {
|
|
|
48
44
|
* id on the wire, which the protocol requires.
|
|
49
45
|
*
|
|
50
46
|
* **Required whenever `persistence` is set** — an app that cannot name the
|
|
51
|
-
* scope has nothing to restore to. Optional for ephemeral generations
|
|
52
|
-
*
|
|
47
|
+
* scope has nothing to restore to. Optional for ephemeral generations. If
|
|
48
|
+
* omitted, the client mints a wire id after mount.
|
|
53
49
|
*/
|
|
54
50
|
threadId?: string
|
|
55
51
|
/**
|
|
@@ -148,7 +144,7 @@ export interface UseTranscriptionReturn<TOutput = TranscriptionResult> {
|
|
|
148
144
|
export function useTranscription<TTransformed = void>(
|
|
149
145
|
options: Omit<
|
|
150
146
|
UseTranscriptionOptions,
|
|
151
|
-
'onResult' | 'persistence' | 'threadId'
|
|
147
|
+
'onResult' | 'persistence' | 'threadId'
|
|
152
148
|
> & {
|
|
153
149
|
onResult?: (result: TranscriptionResult) => TTransformed
|
|
154
150
|
} & GenerationPersistenceOptions,
|