@@ -3,6 +3,7 @@ import { createGenerationDevtoolsBridge } from '@tanstack/ai-client/devtools'
33import { useCallback , useEffect , useId , useMemo , useRef , useState } from 'react'
44import type { StreamChunk } from '@tanstack/ai'
55import type {
6+ AIDevtoolsClientMetadata ,
67 AIDevtoolsDisplayOptions ,
78 ConnectConnectionAdapter ,
89 GenerationClientOptions ,
@@ -166,6 +167,34 @@ export function useGeneration<
166167) : UseGenerationReturn <
167168 InferGenerationOutputFromReturn < TResult , TTransformed > ,
168169 TInput
170+ > {
171+ return useGenerationWithDevtoolsIdentity < TInput , TResult , TTransformed > (
172+ options ,
173+ { hookName : 'useGeneration' } ,
174+ )
175+ }
176+
177+ interface GenerationDevtoolsIdentity {
178+ hookName : AIDevtoolsClientMetadata [ 'hookName' ]
179+ outputKind ?: AIDevtoolsClientMetadata [ 'outputKind' ]
180+ }
181+
182+ /** @internal */
183+ export function useGenerationWithDevtoolsIdentity <
184+ TInput extends Record < string , any > ,
185+ TResult ,
186+ TTransformed = void ,
187+ > (
188+ options : Omit <
189+ UseGenerationOptions < TInput , TResult > ,
190+ 'onResult' | 'persistence' | 'threadId' | 'id'
191+ > & {
192+ onResult ?: ( result : TResult ) => TTransformed
193+ } & GenerationPersistenceOptions ,
194+ devtoolsIdentity : GenerationDevtoolsIdentity ,
195+ ) : UseGenerationReturn <
196+ InferGenerationOutputFromReturn < TResult , TTransformed > ,
197+ TInput
169198> {
170199 type TOutput = InferGenerationOutputFromReturn < TResult , TTransformed >
171200 const hookId = useId ( )
@@ -205,9 +234,12 @@ export function useGeneration<
205234 : { } ) ,
206235 devtoolsBridgeFactory : createGenerationDevtoolsBridge ,
207236 devtools : {
208- hookName : 'useGeneration' ,
209- framework : 'react' ,
210237 ...opts . devtools ,
238+ framework : 'react' ,
239+ hookName : devtoolsIdentity . hookName ,
240+ ...( devtoolsIdentity . outputKind !== undefined && {
241+ outputKind : devtoolsIdentity . outputKind ,
242+ } ) ,
211243 } ,
212244 // The transform's raw return type (`TTransformed`) and the stored output
213245 // (`TOutput`, with null/void/undefined stripped) are identical at runtime;
0 commit comments