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