Open History to see the last commit
1import { injectGeneration } from './inject-generation'
2import { reconstructImageResult } from '@tanstack/ai-client'
3import type { Signal } from '@angular/core'
4import type { ImageGenerationResult } from '@tanstack/ai'
5import type {
6 GenerationClientState,
7 GenerationPersistenceOptions,
8 ImageGenerateInput,
9 InferGenerationOutputFromReturn,
10} from '@tanstack/ai-client'
11import type {
12 InjectGenerationOptions,
13 InjectGenerationResult,
14} from './inject-generation'
15
16export type InjectGenerateImageOptions<TOutput = ImageGenerationResult> = Omit<
17 InjectGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>,
18 'onResult' | 'reconstructResult'
19> & {
20 onResult?: (result: ImageGenerationResult) => TOutput | null | void
21}
22
23export interface InjectGenerateImageResult<
24 TOutput = ImageGenerationResult,
25> extends Omit<InjectGenerationResult<TOutput>, 'generate'> {
26 generate: (input: ImageGenerateInput) => Promise<void>
27 result: Signal<TOutput | null>
28 isLoading: Signal<boolean>
29 error: Signal<Error | undefined>
30 status: Signal<GenerationClientState>
31}
32
33export function injectGenerateImage<TTransformed = void>(
34 options: Omit<
35 InjectGenerateImageOptions,
36 'onResult' | 'persistence' | 'threadId'
37 > & {
38 onResult?: (result: ImageGenerationResult) => TTransformed
39 } & GenerationPersistenceOptions,
40): InjectGenerateImageResult<
41 InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>
42> {
43 const devtools = {
44 ...options.devtools,
45 framework: 'angular' as const,
46 hookName: 'injectGenerateImage',
47 outputKind: 'image' as const,
48 }
49 const generation = injectGeneration<
50 ImageGenerateInput,
51 ImageGenerationResult,
52 TTransformed
53 >({
54 ...options,
55 devtools,
56 reconstructResult: reconstructImageResult,
57 })
58 return generation
59}