@tanstack/ai-angular 0.1.10 → 0.2.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.
@@ -6,7 +6,7 @@ import type {
6
6
  ConnectConnectionAdapter,
7
7
  GenerationClientState,
8
8
  GenerationFetcher,
9
- InferGenerationOutput,
9
+ InferGenerationOutputFromReturn,
10
10
  } from '@tanstack/ai-client'
11
11
  import type { Signal } from '@angular/core'
12
12
  import type { ReactiveOption } from './internal/to-reactive'
@@ -96,15 +96,12 @@ export interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> {
96
96
  * }
97
97
  * ```
98
98
  */
99
- export function injectGenerateAudio<
100
- TOnResult extends ((result: AudioGenerationResult) => any) | undefined =
101
- undefined,
102
- >(
99
+ export function injectGenerateAudio<TTransformed = void>(
103
100
  options: Omit<InjectGenerateAudioOptions, 'onResult'> & {
104
- onResult?: TOnResult
101
+ onResult?: (result: AudioGenerationResult) => TTransformed
105
102
  },
106
103
  ): InjectGenerateAudioResult<
107
- InferGenerationOutput<AudioGenerationResult, TOnResult>
104
+ InferGenerationOutputFromReturn<AudioGenerationResult, TTransformed>
108
105
  > {
109
106
  const devtools = {
110
107
  ...options.devtools,
@@ -113,7 +110,7 @@ export function injectGenerateAudio<
113
110
  outputKind: 'audio' as const,
114
111
  }
115
112
  const { generate, result, isLoading, error, status, stop, reset } =
116
- injectGeneration<AudioGenerateInput, AudioGenerationResult, TOnResult>({
113
+ injectGeneration<AudioGenerateInput, AudioGenerationResult, TTransformed>({
117
114
  ...options,
118
115
  devtools,
119
116
  })
@@ -4,7 +4,7 @@ import type { ImageGenerationResult } from '@tanstack/ai'
4
4
  import type {
5
5
  GenerationClientState,
6
6
  ImageGenerateInput,
7
- InferGenerationOutput,
7
+ InferGenerationOutputFromReturn,
8
8
  } from '@tanstack/ai-client'
9
9
  import type { InjectGenerationOptions } from './inject-generation'
10
10
 
@@ -25,15 +25,12 @@ export interface InjectGenerateImageResult<TOutput = ImageGenerationResult> {
25
25
  reset: () => void
26
26
  }
27
27
 
28
- export function injectGenerateImage<
29
- TOnResult extends ((result: ImageGenerationResult) => any) | undefined =
30
- undefined,
31
- >(
28
+ export function injectGenerateImage<TTransformed = void>(
32
29
  options: Omit<InjectGenerateImageOptions, 'onResult'> & {
33
- onResult?: TOnResult
30
+ onResult?: (result: ImageGenerationResult) => TTransformed
34
31
  },
35
32
  ): InjectGenerateImageResult<
36
- InferGenerationOutput<ImageGenerationResult, TOnResult>
33
+ InferGenerationOutputFromReturn<ImageGenerationResult, TTransformed>
37
34
  > {
38
35
  const devtools = {
39
36
  ...options.devtools,
@@ -42,7 +39,7 @@ export function injectGenerateImage<
42
39
  outputKind: 'image' as const,
43
40
  }
44
41
  const { generate, result, isLoading, error, status, stop, reset } =
45
- injectGeneration<ImageGenerateInput, ImageGenerationResult, TOnResult>({
42
+ injectGeneration<ImageGenerateInput, ImageGenerationResult, TTransformed>({
46
43
  ...options,
47
44
  devtools,
48
45
  })
@@ -3,7 +3,7 @@ import type { Signal } from '@angular/core'
3
3
  import type { TTSResult } from '@tanstack/ai'
4
4
  import type {
5
5
  GenerationClientState,
6
- InferGenerationOutput,
6
+ InferGenerationOutputFromReturn,
7
7
  SpeechGenerateInput,
8
8
  } from '@tanstack/ai-client'
9
9
  import type { InjectGenerationOptions } from './inject-generation'
@@ -25,13 +25,13 @@ export interface InjectGenerateSpeechResult<TOutput = TTSResult> {
25
25
  reset: () => void
26
26
  }
27
27
 
28
- export function injectGenerateSpeech<
29
- TOnResult extends ((result: TTSResult) => any) | undefined = undefined,
30
- >(
28
+ export function injectGenerateSpeech<TTransformed = void>(
31
29
  options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {
32
- onResult?: TOnResult
30
+ onResult?: (result: TTSResult) => TTransformed
33
31
  },
34
- ): InjectGenerateSpeechResult<InferGenerationOutput<TTSResult, TOnResult>> {
32
+ ): InjectGenerateSpeechResult<
33
+ InferGenerationOutputFromReturn<TTSResult, TTransformed>
34
+ > {
35
35
  const devtools = {
36
36
  ...options.devtools,
37
37
  framework: 'angular' as const,
@@ -39,7 +39,7 @@ export function injectGenerateSpeech<
39
39
  outputKind: 'audio' as const,
40
40
  }
41
41
  const { generate, result, isLoading, error, status, stop, reset } =
42
- injectGeneration<SpeechGenerateInput, TTSResult, TOnResult>({
42
+ injectGeneration<SpeechGenerateInput, TTSResult, TTransformed>({
43
43
  ...options,
44
44
  devtools,
45
45
  })
@@ -17,7 +17,7 @@ import type {
17
17
  ConnectConnectionAdapter,
18
18
  GenerationClientState,
19
19
  GenerationFetcher,
20
- InferGenerationOutput,
20
+ InferGenerationOutputFromReturn,
21
21
  VideoGenerateInput,
22
22
  VideoGenerateResult,
23
23
  VideoStatusInfo,
@@ -52,19 +52,22 @@ export interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {
52
52
  reset: () => void
53
53
  }
54
54
 
55
- export function injectGenerateVideo<
56
- TOnResult extends ((result: VideoGenerateResult) => any) | undefined =
57
- undefined,
58
- >(
55
+ // `TTransformed` infers from the `onResult` return position so the callback
56
+ // parameter is typed as `VideoGenerateResult` and `result` narrows to the
57
+ // transform's return. See issue #848.
58
+ export function injectGenerateVideo<TTransformed = void>(
59
59
  options: Omit<InjectGenerateVideoOptions, 'onResult'> & {
60
- onResult?: TOnResult
60
+ onResult?: (result: VideoGenerateResult) => TTransformed
61
61
  },
62
62
  ): InjectGenerateVideoResult<
63
- InferGenerationOutput<VideoGenerateResult, TOnResult>
63
+ InferGenerationOutputFromReturn<VideoGenerateResult, TTransformed>
64
64
  > {
65
65
  assertInInjectionContext(injectGenerateVideo)
66
66
 
67
- type TOutput = InferGenerationOutput<VideoGenerateResult, TOnResult>
67
+ type TOutput = InferGenerationOutputFromReturn<
68
+ VideoGenerateResult,
69
+ TTransformed
70
+ >
68
71
 
69
72
  const destroyRef = inject(DestroyRef)
70
73
  const injector = inject(Injector)
@@ -90,7 +93,12 @@ export function injectGenerateVideo<
90
93
  hookName: 'injectGenerateVideo',
91
94
  outputKind: 'video' as const,
92
95
  },
93
- onResult: (r: VideoGenerateResult) => options.onResult?.(r),
96
+ // The transform's raw return type (`TTransformed`) and the stored output
97
+ // (`TOutput`, with null/void/undefined stripped) are identical at runtime;
98
+ // the cast bridges the relationship that the conditional type hides.
99
+ onResult: ((r: VideoGenerateResult) => options.onResult?.(r)) as (
100
+ result: VideoGenerateResult,
101
+ ) => TOutput | null | void,
94
102
  onError: (e: Error) => options.onError?.(e),
95
103
  onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
96
104
  onChunk: (c: StreamChunk) => options.onChunk?.(c),
@@ -18,7 +18,7 @@ import type {
18
18
  GenerationClientOptions,
19
19
  GenerationClientState,
20
20
  GenerationFetcher,
21
- InferGenerationOutput,
21
+ InferGenerationOutputFromReturn,
22
22
  } from '@tanstack/ai-client'
23
23
  import type { ReactiveOption } from './internal/to-reactive'
24
24
 
@@ -68,18 +68,26 @@ export interface InjectGenerationResult<TOutput> {
68
68
  reset: () => void
69
69
  }
70
70
 
71
+ // `TTransformed` infers from the `onResult` return position (a covariant
72
+ // inference site that works even for an optional nested property), which types
73
+ // the callback parameter as `TResult` and narrows `result`. Inferring the
74
+ // whole callback as a defaulted type parameter instead collapses to the
75
+ // default, leaving the parameter `any` — a hard error under `strict`. See
76
+ // issue #848.
71
77
  export function injectGeneration<
72
78
  TInput extends Record<string, any>,
73
79
  TResult,
74
- TOnResult extends ((result: TResult) => any) | undefined = undefined,
80
+ TTransformed = void,
75
81
  >(
76
82
  options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {
77
- onResult?: TOnResult
83
+ onResult?: (result: TResult) => TTransformed
78
84
  },
79
- ): InjectGenerationResult<InferGenerationOutput<TResult, TOnResult>> {
85
+ ): InjectGenerationResult<
86
+ InferGenerationOutputFromReturn<TResult, TTransformed>
87
+ > {
80
88
  assertInInjectionContext(injectGeneration)
81
89
 
82
- type TOutput = InferGenerationOutput<TResult, TOnResult>
90
+ type TOutput = InferGenerationOutputFromReturn<TResult, TTransformed>
83
91
 
84
92
  const destroyRef = inject(DestroyRef)
85
93
  const injector = inject(Injector)
@@ -102,7 +110,12 @@ export function injectGeneration<
102
110
  framework: 'angular',
103
111
  hookName: 'injectGeneration',
104
112
  },
105
- onResult: (r: TResult) => options.onResult?.(r),
113
+ // The transform's raw return type (`TTransformed`) and the stored output
114
+ // (`TOutput`, with null/void/undefined stripped) are identical at runtime;
115
+ // the cast bridges the relationship that the conditional type hides.
116
+ onResult: ((r: TResult) => options.onResult?.(r)) as (
117
+ result: TResult,
118
+ ) => TOutput | null | void,
106
119
  onError: (e: Error) => options.onError?.(e),
107
120
  onProgress: (p: number, m?: string) => options.onProgress?.(p, m),
108
121
  onChunk: (c: StreamChunk) => options.onChunk?.(c),
@@ -3,7 +3,7 @@ import type { Signal } from '@angular/core'
3
3
  import type { SummarizationResult } from '@tanstack/ai'
4
4
  import type {
5
5
  GenerationClientState,
6
- InferGenerationOutput,
6
+ InferGenerationOutputFromReturn,
7
7
  SummarizeGenerateInput,
8
8
  } from '@tanstack/ai-client'
9
9
  import type { InjectGenerationOptions } from './inject-generation'
@@ -25,15 +25,12 @@ export interface InjectSummarizeResult<TOutput = SummarizationResult> {
25
25
  reset: () => void
26
26
  }
27
27
 
28
- export function injectSummarize<
29
- TOnResult extends ((result: SummarizationResult) => any) | undefined =
30
- undefined,
31
- >(
28
+ export function injectSummarize<TTransformed = void>(
32
29
  options: Omit<InjectSummarizeOptions, 'onResult'> & {
33
- onResult?: TOnResult
30
+ onResult?: (result: SummarizationResult) => TTransformed
34
31
  },
35
32
  ): InjectSummarizeResult<
36
- InferGenerationOutput<SummarizationResult, TOnResult>
33
+ InferGenerationOutputFromReturn<SummarizationResult, TTransformed>
37
34
  > {
38
35
  const devtools = {
39
36
  ...options.devtools,
@@ -42,10 +39,12 @@ export function injectSummarize<
42
39
  outputKind: 'text' as const,
43
40
  }
44
41
  const { generate, result, isLoading, error, status, stop, reset } =
45
- injectGeneration<SummarizeGenerateInput, SummarizationResult, TOnResult>({
46
- ...options,
47
- devtools,
48
- })
42
+ injectGeneration<SummarizeGenerateInput, SummarizationResult, TTransformed>(
43
+ {
44
+ ...options,
45
+ devtools,
46
+ },
47
+ )
49
48
  return {
50
49
  generate: generate as (input: SummarizeGenerateInput) => Promise<void>,
51
50
  result,
@@ -3,7 +3,7 @@ import type { Signal } from '@angular/core'
3
3
  import type { TranscriptionResult } from '@tanstack/ai'
4
4
  import type {
5
5
  GenerationClientState,
6
- InferGenerationOutput,
6
+ InferGenerationOutputFromReturn,
7
7
  TranscriptionGenerateInput,
8
8
  } from '@tanstack/ai-client'
9
9
  import type { InjectGenerationOptions } from './inject-generation'
@@ -29,15 +29,12 @@ export interface InjectTranscriptionResult<TOutput = TranscriptionResult> {
29
29
  reset: () => void
30
30
  }
31
31
 
32
- export function injectTranscription<
33
- TOnResult extends ((result: TranscriptionResult) => any) | undefined =
34
- undefined,
35
- >(
32
+ export function injectTranscription<TTransformed = void>(
36
33
  options: Omit<InjectTranscriptionOptions, 'onResult'> & {
37
- onResult?: TOnResult
34
+ onResult?: (result: TranscriptionResult) => TTransformed
38
35
  },
39
36
  ): InjectTranscriptionResult<
40
- InferGenerationOutput<TranscriptionResult, TOnResult>
37
+ InferGenerationOutputFromReturn<TranscriptionResult, TTransformed>
41
38
  > {
42
39
  const devtools = {
43
40
  ...options.devtools,
@@ -49,7 +46,7 @@ export function injectTranscription<
49
46
  injectGeneration<
50
47
  TranscriptionGenerateInput,
51
48
  TranscriptionResult,
52
- TOnResult
49
+ TTransformed
53
50
  >({
54
51
  ...options,
55
52
  devtools,