@tanstack/ai-react 0.19.3 → 0.20.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.
@@ -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, where
58
- * it falls back to `id` purely to satisfy the wire.
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' | 'id'
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
- // Single identity: prefer `threadId`; deprecated `id` only when no threadId.
173
- const clientIdentity = options.threadId ?? options.id ?? hookId
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
- // Identity: pass `threadId` alone when set (never also pass deprecated `id`).
193
- const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {
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
  }
@@ -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, where
52
- * it falls back to `id` purely to satisfy the wire.
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' | 'id'
142
+ 'onResult' | 'persistence' | 'threadId'
147
143
  > & {
148
144
  onResult?: (result: SummarizationResult) => TTransformed
149
145
  } & GenerationPersistenceOptions,
@@ -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, where
52
- * it falls back to `id` purely to satisfy the wire.
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' | 'id'
147
+ 'onResult' | 'persistence' | 'threadId'
152
148
  > & {
153
149
  onResult?: (result: TranscriptionResult) => TTransformed
154
150
  } & GenerationPersistenceOptions,