@tanstack/ai-angular 0.1.10 → 0.1.11

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.
package/dist/README.md ADDED
@@ -0,0 +1,158 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/TanStack/ai/main/media/header_ai.png" alt="TanStack AI" />
3
+ </div>
4
+
5
+ <br />
6
+
7
+ <div align="center">
8
+ <a href="https://npmjs.com/package/@tanstack/ai-angular" target="_parent">
9
+ <img alt="NPM downloads" src="https://img.shields.io/npm/dm/@tanstack/ai-angular.svg" />
10
+ </a>
11
+ <a href="https://github.com/TanStack/ai" target="_parent">
12
+ <img alt="GitHub stars" src="https://img.shields.io/github/stars/TanStack/ai.svg?style=social&label=Star" />
13
+ </a>
14
+ <a href="https://github.com/TanStack/ai/releases" target="_parent">
15
+ <img alt="Release" src="https://img.shields.io/github/v/release/tanstack/ai" />
16
+ </a>
17
+ <a href="https://bundlephobia.com/result?p=@tanstack/ai-angular@latest" target="_parent">
18
+ <img alt="Bundle size" src="https://badgen.net/bundlephobia/minzip/@tanstack/ai-angular@latest" />
19
+ </a>
20
+ <a href="https://twitter.com/tan_stack">
21
+ <img alt="Follow @TanStack" src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" />
22
+ </a>
23
+ </div>
24
+
25
+ # TanStack AI — Angular
26
+
27
+ Angular signal-based bindings for TanStack AI — streaming chat, tool-calling agents, and media generation built on Angular's native reactivity model.
28
+
29
+ ## <a href="https://tanstack.com/ai">Read the docs -></a>
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ pnpm add @tanstack/ai-angular @tanstack/ai
35
+ ```
36
+
37
+ ```bash
38
+ npm install @tanstack/ai-angular @tanstack/ai
39
+ ```
40
+
41
+ ## Minimal Usage
42
+
43
+ > **Important:** All `inject*` functions use Angular's dependency injection system and **must** be called within an Angular injection context — a component or directive class field initializer, the constructor, or inside `runInInjectionContext`. Calling them outside an injection context will throw a runtime error.
44
+
45
+ The example below shows a standalone component that streams chat messages from a server endpoint via SSE:
46
+
47
+ ```typescript
48
+ import { Component } from '@angular/core'
49
+ import { CommonModule } from '@angular/common'
50
+ import { injectChat } from '@tanstack/ai-angular'
51
+ import { fetchServerSentEvents } from '@tanstack/ai-client'
52
+
53
+ @Component({
54
+ selector: 'app-chat',
55
+ standalone: true,
56
+ imports: [CommonModule],
57
+ template: `
58
+ <ul>
59
+ @for (message of chat.messages(); track message.id) {
60
+ <li>{{ message.role }}: {{ message.content }}</li>
61
+ }
62
+ </ul>
63
+ <input #input placeholder="Type a message..." />
64
+ <button (click)="chat.sendMessage(input.value); input.value = ''">
65
+ Send
66
+ </button>
67
+ @if (chat.isLoading()) {
68
+ <p>Thinking...</p>
69
+ }
70
+ `,
71
+ })
72
+ export class ChatComponent {
73
+ // injectChat is called in a field initializer — this is a valid injection context.
74
+ chat = injectChat({
75
+ connection: fetchServerSentEvents('/api/chat'),
76
+ })
77
+ }
78
+ ```
79
+
80
+ All state is exposed as Angular `Signal`s. Read them by calling them as functions:
81
+
82
+ | Signal | Type | Description |
83
+ | ------------------------- | -------------------- | ------------------------------------------- |
84
+ | `chat.messages()` | `UIMessage[]` | Current message list |
85
+ | `chat.isLoading()` | `boolean` | Whether a response is streaming |
86
+ | `chat.error()` | `Error \| undefined` | Last error, if any |
87
+ | `chat.status()` | `ChatClientState` | `'ready'`, `'streaming'`, `'error'`, ... |
88
+ | `chat.isSubscribed()` | `boolean` | Whether a live (SSE push) session is active |
89
+ | `chat.connectionStatus()` | `ConnectionStatus` | Transport connection status |
90
+
91
+ Available methods on the return value: `sendMessage`, `append`, `reload`, `stop`, `clear`, `setMessages`, `addToolResult`, `addToolApprovalResponse`.
92
+
93
+ ## Server endpoint
94
+
95
+ The client pairs with any endpoint that returns a TanStack AI SSE stream:
96
+
97
+ ```typescript
98
+ import { chat, toServerSentEventsResponse } from '@tanstack/ai'
99
+ import { openaiText } from '@tanstack/ai-openai'
100
+
101
+ export async function POST(request: Request) {
102
+ const body = await request.json()
103
+
104
+ const stream = chat({
105
+ adapter: openaiText('gpt-5.5'),
106
+ messages: body.messages,
107
+ })
108
+
109
+ return toServerSentEventsResponse(stream)
110
+ }
111
+ ```
112
+
113
+ ## Available Functions
114
+
115
+ | Function | Description |
116
+ | ---------------------- | ---------------------------------------------------------------- |
117
+ | `injectChat` | Streaming chat with messages, tool calls, and structured outputs |
118
+ | `injectGeneration` | Generic generation client (streaming or one-shot) |
119
+ | `injectGenerateImage` | Image generation |
120
+ | `injectGenerateAudio` | Audio generation |
121
+ | `injectGenerateVideo` | Video generation |
122
+ | `injectGenerateSpeech` | Text-to-speech |
123
+ | `injectSummarize` | Summarization |
124
+ | `injectTranscription` | Audio transcription |
125
+
126
+ All generation functions return signals (`result`, `isLoading`, `error`, `status`) and methods (`generate`, `stop`, `reset`).
127
+
128
+ ## Injection Context
129
+
130
+ Angular's DI system requires that `inject()` is called during component construction. Every `inject*` function in this package calls `inject()` internally. Valid call sites:
131
+
132
+ ```typescript
133
+ // Field initializer (recommended)
134
+ export class MyComponent {
135
+ chat = injectChat({ connection: fetchServerSentEvents('/api/chat') })
136
+ }
137
+
138
+ // Constructor
139
+ export class MyComponent {
140
+ chat: ReturnType<typeof injectChat>
141
+ constructor() {
142
+ this.chat = injectChat({ connection: fetchServerSentEvents('/api/chat') })
143
+ }
144
+ }
145
+
146
+ // Inside runInInjectionContext
147
+ const chat = runInInjectionContext(injector, () =>
148
+ injectChat({ connection: fetchServerSentEvents('/api/chat') }),
149
+ )
150
+ ```
151
+
152
+ ## Get Involved
153
+
154
+ - Read the [docs](https://tanstack.com/ai).
155
+ - Participate in [GitHub discussions](https://github.com/TanStack/ai/discussions).
156
+ - Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ).
157
+ - See [CONTRIBUTING.md](https://github.com/TanStack/ai/blob/main/CONTRIBUTING.md) for setup instructions.
158
+ - [Become a sponsor](https://github.com/sponsors/tannerlinsley/).
@@ -0,0 +1,481 @@
1
+ import { ChatClient, GenerationClient, VideoGenerationClient } from '@tanstack/ai-client';
2
+ export { createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, xhrHttpStream, xhrServerSentEvents } from '@tanstack/ai-client';
3
+ import { createChatDevtoolsBridge, createGenerationDevtoolsBridge, createVideoDevtoolsBridge } from '@tanstack/ai-client/devtools';
4
+ import { isSignal, computed, assertInInjectionContext, inject, DestroyRef, Injector, signal, effect, afterNextRender } from '@angular/core';
5
+
6
+ /**
7
+ * Normalize a {@link ReactiveOption} into a `Signal`-like getter `() => T`.
8
+ *
9
+ * - A `Signal` is returned as-is (already a getter that tracks reads).
10
+ * - A zero-arg function is wrapped in `computed` so reads inside it are tracked.
11
+ * - A plain value becomes a constant non-reactive fn (never re-fires).
12
+ */
13
+ function toReactive(value) {
14
+ if (isSignal(value)) {
15
+ return value;
16
+ }
17
+ if (typeof value === 'function') {
18
+ return computed(value);
19
+ }
20
+ return () => value;
21
+ }
22
+
23
+ let nextId$2 = 0;
24
+ function injectChat(options = {}) {
25
+ assertInInjectionContext(injectChat);
26
+ const destroyRef = inject(DestroyRef);
27
+ const injector = inject(Injector);
28
+ const clientId = options.id || `injectChat-${nextId$2++}`;
29
+ const messages = signal(options.initialMessages || [], ...(ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []));
30
+ const isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
31
+ const error = signal(undefined, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
32
+ const status = signal('ready', ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
33
+ const isSubscribed = signal(false, ...(ngDevMode ? [{ debugName: "isSubscribed" }] : /* istanbul ignore next */ []));
34
+ const connectionStatus = signal('disconnected', ...(ngDevMode ? [{ debugName: "connectionStatus" }] : /* istanbul ignore next */ []));
35
+ const sessionGenerating = signal(false, ...(ngDevMode ? [{ debugName: "sessionGenerating" }] : /* istanbul ignore next */ []));
36
+ // Reactive option sources. Plain values become constant computeds.
37
+ const bodySource = options.body !== undefined ? toReactive(options.body) : undefined;
38
+ const forwardedPropsSource = options.forwardedProps !== undefined
39
+ ? toReactive(options.forwardedProps)
40
+ : undefined;
41
+ const contextSource = options.context !== undefined ? toReactive(options.context) : undefined;
42
+ const liveSource = options.live !== undefined ? toReactive(options.live) : undefined;
43
+ const transport = options.connection
44
+ ? { connection: options.connection }
45
+ : { fetcher: options.fetcher };
46
+ const client = new ChatClient({
47
+ devtoolsBridgeFactory: createChatDevtoolsBridge,
48
+ ...transport,
49
+ id: clientId,
50
+ ...(options.initialMessages !== undefined && {
51
+ initialMessages: options.initialMessages,
52
+ }),
53
+ ...(options.persistence !== undefined && {
54
+ persistence: options.persistence,
55
+ }),
56
+ ...(bodySource !== undefined && { body: bodySource() }),
57
+ ...(options.threadId !== undefined && { threadId: options.threadId }),
58
+ ...(forwardedPropsSource !== undefined && {
59
+ forwardedProps: forwardedPropsSource(),
60
+ }),
61
+ ...(contextSource !== undefined && { context: contextSource() }),
62
+ devtools: {
63
+ ...options.devtools,
64
+ framework: 'angular',
65
+ hookName: 'injectChat',
66
+ outputKind: options.outputSchema ? 'structured' : 'chat',
67
+ },
68
+ onResponse: (response) => options.onResponse?.(response),
69
+ onChunk: (chunk) => options.onChunk?.(chunk),
70
+ onFinish: (message) => options.onFinish?.(message),
71
+ onError: (err) => options.onError?.(err),
72
+ tools: options.tools,
73
+ onCustomEvent: (eventType, data, context) => options.onCustomEvent?.(eventType, data, context),
74
+ ...(options.streamProcessor !== undefined && {
75
+ streamProcessor: options.streamProcessor,
76
+ }),
77
+ onMessagesChange: (m) => messages.set(m),
78
+ onLoadingChange: (v) => isLoading.set(v),
79
+ onStatusChange: (v) => status.set(v),
80
+ onErrorChange: (v) => error.set(v),
81
+ onSubscriptionChange: (v) => isSubscribed.set(v),
82
+ onConnectionStatusChange: (v) => connectionStatus.set(v),
83
+ onSessionGeneratingChange: (v) => sessionGenerating.set(v),
84
+ });
85
+ messages.set(client.getMessages());
86
+ // Sync reactive body / forwardedProps / context to the client.
87
+ if (bodySource || forwardedPropsSource || contextSource) {
88
+ effect(() => {
89
+ const newBody = bodySource?.();
90
+ const newForwardedProps = forwardedPropsSource?.();
91
+ const newContext = contextSource?.();
92
+ client.updateOptions({
93
+ ...(newBody !== undefined && { body: newBody }),
94
+ ...(newForwardedProps !== undefined && {
95
+ forwardedProps: newForwardedProps,
96
+ }),
97
+ ...(newContext !== undefined && { context: newContext }),
98
+ });
99
+ }, { injector });
100
+ }
101
+ // Subscribe / unsubscribe based on reactive `live`.
102
+ if (liveSource) {
103
+ effect(() => {
104
+ if (liveSource()) {
105
+ client.subscribe();
106
+ }
107
+ else {
108
+ client.unsubscribe();
109
+ }
110
+ }, { injector });
111
+ }
112
+ afterNextRender(() => client.mountDevtools(), { injector });
113
+ destroyRef.onDestroy(() => {
114
+ if (liveSource?.()) {
115
+ client.unsubscribe();
116
+ }
117
+ else {
118
+ client.stop();
119
+ }
120
+ client.dispose();
121
+ });
122
+ // Active structured-output part = the one on the assistant message after the
123
+ // latest user message. Ported from ai-vue/src/use-chat.ts.
124
+ const activeStructuredPart = computed(() => {
125
+ const list = messages();
126
+ let lastUserIndex = -1;
127
+ for (let i = list.length - 1; i >= 0; i--) {
128
+ if (list[i]?.role === 'user') {
129
+ lastUserIndex = i;
130
+ break;
131
+ }
132
+ }
133
+ if (lastUserIndex === -1)
134
+ return null;
135
+ for (let i = list.length - 1; i > lastUserIndex; i--) {
136
+ const m = list[i];
137
+ if (m?.role !== 'assistant')
138
+ continue;
139
+ const part = m.parts.find((p) => p.type === 'structured-output');
140
+ if (part)
141
+ return part;
142
+ }
143
+ return null;
144
+ }, ...(ngDevMode ? [{ debugName: "activeStructuredPart" }] : /* istanbul ignore next */ []));
145
+ const partial = computed(() => {
146
+ const part = activeStructuredPart();
147
+ if (!part)
148
+ return {};
149
+ const v = part.partial ?? part.data;
150
+ return (v ?? {});
151
+ }, ...(ngDevMode ? [{ debugName: "partial" }] : /* istanbul ignore next */ []));
152
+ const final = computed(() => {
153
+ const part = activeStructuredPart();
154
+ if (!part || part.status !== 'complete')
155
+ return null;
156
+ return part.data;
157
+ }, ...(ngDevMode ? [{ debugName: "final" }] : /* istanbul ignore next */ []));
158
+ const sendMessage = async (content) => {
159
+ await client.sendMessage(content);
160
+ };
161
+ const append = async (message) => {
162
+ await client.append(message);
163
+ };
164
+ const reload = async () => {
165
+ await client.reload();
166
+ };
167
+ const stop = () => client.stop();
168
+ const clear = () => client.clear();
169
+ const setMessages = (m) => client.setMessagesManually(m);
170
+ const addToolResult = async (result) => {
171
+ await client.addToolResult(result);
172
+ };
173
+ const addToolApprovalResponse = async (response) => {
174
+ await client.addToolApprovalResponse(response);
175
+ };
176
+ // eslint-disable-next-line no-restricted-syntax -- return shape diverges from conditional InjectChatResult<TTools, TSchema>; TS can't structurally narrow the TSchema-gated partial/final signals
177
+ return {
178
+ messages: messages.asReadonly(),
179
+ sendMessage,
180
+ append,
181
+ reload,
182
+ stop,
183
+ isLoading: isLoading.asReadonly(),
184
+ error: error.asReadonly(),
185
+ status: status.asReadonly(),
186
+ isSubscribed: isSubscribed.asReadonly(),
187
+ connectionStatus: connectionStatus.asReadonly(),
188
+ sessionGenerating: sessionGenerating.asReadonly(),
189
+ setMessages,
190
+ clear,
191
+ addToolResult,
192
+ addToolApprovalResponse,
193
+ partial,
194
+ final,
195
+ };
196
+ }
197
+
198
+ let nextId$1 = 0;
199
+ function injectGeneration(options) {
200
+ assertInInjectionContext(injectGeneration);
201
+ const destroyRef = inject(DestroyRef);
202
+ const injector = inject(Injector);
203
+ const clientId = options.id || `injectGeneration-${nextId$1++}`;
204
+ const result = signal(null, ...(ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []));
205
+ const isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
206
+ const error = signal(undefined, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
207
+ const status = signal('idle', ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
208
+ const bodySource = options.body !== undefined ? toReactive(options.body) : undefined;
209
+ const clientOptions = {
210
+ id: clientId,
211
+ ...(bodySource !== undefined && { body: bodySource() }),
212
+ devtoolsBridgeFactory: createGenerationDevtoolsBridge,
213
+ devtools: {
214
+ ...options.devtools,
215
+ framework: 'angular',
216
+ hookName: 'injectGeneration',
217
+ },
218
+ onResult: (r) => options.onResult?.(r),
219
+ onError: (e) => options.onError?.(e),
220
+ onProgress: (p, m) => options.onProgress?.(p, m),
221
+ onChunk: (c) => options.onChunk?.(c),
222
+ onResultChange: (r) => result.set(r),
223
+ onLoadingChange: (l) => isLoading.set(l),
224
+ onErrorChange: (e) => error.set(e),
225
+ onStatusChange: (s) => status.set(s),
226
+ };
227
+ let client;
228
+ if (options.connection) {
229
+ client = new GenerationClient({
230
+ ...clientOptions,
231
+ connection: options.connection,
232
+ });
233
+ }
234
+ else if (options.fetcher) {
235
+ client = new GenerationClient({
236
+ ...clientOptions,
237
+ fetcher: options.fetcher,
238
+ });
239
+ }
240
+ else {
241
+ throw new Error('injectGeneration requires either a connection or fetcher option');
242
+ }
243
+ if (bodySource) {
244
+ effect(() => {
245
+ client.updateOptions({ body: bodySource() });
246
+ }, { injector });
247
+ }
248
+ afterNextRender(() => client.mountDevtools(), { injector });
249
+ destroyRef.onDestroy(() => client.dispose());
250
+ return {
251
+ generate: ((input) => client.generate(input)),
252
+ result: result.asReadonly(),
253
+ isLoading: isLoading.asReadonly(),
254
+ error: error.asReadonly(),
255
+ status: status.asReadonly(),
256
+ stop: () => client.stop(),
257
+ reset: () => client.reset(),
258
+ };
259
+ }
260
+
261
+ function injectGenerateImage(options) {
262
+ const devtools = {
263
+ ...options.devtools,
264
+ framework: 'angular',
265
+ hookName: 'injectGenerateImage',
266
+ outputKind: 'image',
267
+ };
268
+ const { generate, result, isLoading, error, status, stop, reset } = injectGeneration({
269
+ ...options,
270
+ devtools,
271
+ });
272
+ return {
273
+ generate: generate,
274
+ result,
275
+ isLoading,
276
+ error,
277
+ status,
278
+ stop,
279
+ reset,
280
+ };
281
+ }
282
+
283
+ /**
284
+ * Angular injectable for generating audio (music, sound effects) using AI models.
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * import { Component } from '@angular/core'
289
+ * import { injectGenerateAudio } from '@tanstack/ai-angular'
290
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
291
+ *
292
+ * @Component({
293
+ * selector: 'app-audio',
294
+ * template: `
295
+ * <button (click)="generate({ prompt: 'An upbeat electronic track', duration: 10 })">
296
+ * Generate
297
+ * </button>
298
+ * @if (result()) {
299
+ * <audio [src]="result()!.audio.url" controls></audio>
300
+ * }
301
+ * `,
302
+ * })
303
+ * export class AudioComponent {
304
+ * private gen = injectGenerateAudio({
305
+ * connection: fetchServerSentEvents('/api/generate/audio'),
306
+ * })
307
+ *
308
+ * generate = this.gen.generate
309
+ * result = this.gen.result
310
+ * isLoading = this.gen.isLoading
311
+ * }
312
+ * ```
313
+ */
314
+ function injectGenerateAudio(options) {
315
+ const devtools = {
316
+ ...options.devtools,
317
+ framework: 'angular',
318
+ hookName: 'injectGenerateAudio',
319
+ outputKind: 'audio',
320
+ };
321
+ const { generate, result, isLoading, error, status, stop, reset } = injectGeneration({
322
+ ...options,
323
+ devtools,
324
+ });
325
+ return {
326
+ generate: generate,
327
+ result,
328
+ isLoading,
329
+ error,
330
+ status,
331
+ stop,
332
+ reset,
333
+ };
334
+ }
335
+
336
+ function injectGenerateSpeech(options) {
337
+ const devtools = {
338
+ ...options.devtools,
339
+ framework: 'angular',
340
+ hookName: 'injectGenerateSpeech',
341
+ outputKind: 'audio',
342
+ };
343
+ const { generate, result, isLoading, error, status, stop, reset } = injectGeneration({
344
+ ...options,
345
+ devtools,
346
+ });
347
+ return {
348
+ generate: generate,
349
+ result,
350
+ isLoading,
351
+ error,
352
+ status,
353
+ stop,
354
+ reset,
355
+ };
356
+ }
357
+
358
+ function injectTranscription(options) {
359
+ const devtools = {
360
+ ...options.devtools,
361
+ framework: 'angular',
362
+ hookName: 'injectTranscription',
363
+ outputKind: 'text',
364
+ };
365
+ const { generate, result, isLoading, error, status, stop, reset } = injectGeneration({
366
+ ...options,
367
+ devtools,
368
+ });
369
+ return {
370
+ generate: generate,
371
+ result,
372
+ isLoading,
373
+ error,
374
+ status,
375
+ stop,
376
+ reset,
377
+ };
378
+ }
379
+
380
+ function injectSummarize(options) {
381
+ const devtools = {
382
+ ...options.devtools,
383
+ framework: 'angular',
384
+ hookName: 'injectSummarize',
385
+ outputKind: 'text',
386
+ };
387
+ const { generate, result, isLoading, error, status, stop, reset } = injectGeneration({
388
+ ...options,
389
+ devtools,
390
+ });
391
+ return {
392
+ generate: generate,
393
+ result,
394
+ isLoading,
395
+ error,
396
+ status,
397
+ stop,
398
+ reset,
399
+ };
400
+ }
401
+
402
+ let nextId = 0;
403
+ function injectGenerateVideo(options) {
404
+ assertInInjectionContext(injectGenerateVideo);
405
+ const destroyRef = inject(DestroyRef);
406
+ const injector = inject(Injector);
407
+ const clientId = options.id || `injectGenerateVideo-${nextId++}`;
408
+ const result = signal(null, ...(ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []));
409
+ const jobId = signal(null, ...(ngDevMode ? [{ debugName: "jobId" }] : /* istanbul ignore next */ []));
410
+ const videoStatus = signal(null, ...(ngDevMode ? [{ debugName: "videoStatus" }] : /* istanbul ignore next */ []));
411
+ const isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
412
+ const error = signal(undefined, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
413
+ const status = signal('idle', ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
414
+ const bodySource = options.body !== undefined ? toReactive(options.body) : undefined;
415
+ const baseOptions = {
416
+ id: clientId,
417
+ ...(bodySource !== undefined && { body: bodySource() }),
418
+ devtoolsBridgeFactory: createVideoDevtoolsBridge,
419
+ devtools: {
420
+ ...options.devtools,
421
+ framework: 'angular',
422
+ hookName: 'injectGenerateVideo',
423
+ outputKind: 'video',
424
+ },
425
+ onResult: (r) => options.onResult?.(r),
426
+ onError: (e) => options.onError?.(e),
427
+ onProgress: (p, m) => options.onProgress?.(p, m),
428
+ onChunk: (c) => options.onChunk?.(c),
429
+ onJobCreated: (id) => options.onJobCreated?.(id),
430
+ onStatusUpdate: (s) => options.onStatusUpdate?.(s),
431
+ onResultChange: (r) => result.set(r),
432
+ onLoadingChange: (l) => isLoading.set(l),
433
+ onErrorChange: (e) => error.set(e),
434
+ onStatusChange: (s) => status.set(s),
435
+ onJobIdChange: (id) => jobId.set(id),
436
+ onVideoStatusChange: (s) => videoStatus.set(s),
437
+ };
438
+ let client;
439
+ if (options.connection) {
440
+ client = new VideoGenerationClient({
441
+ ...baseOptions,
442
+ connection: options.connection,
443
+ });
444
+ }
445
+ else if (options.fetcher) {
446
+ client = new VideoGenerationClient({
447
+ ...baseOptions,
448
+ fetcher: options.fetcher,
449
+ });
450
+ }
451
+ else {
452
+ throw new Error('injectGenerateVideo requires either a connection or fetcher option');
453
+ }
454
+ if (bodySource) {
455
+ effect(() => {
456
+ client.updateOptions({ body: bodySource() });
457
+ }, { injector });
458
+ }
459
+ afterNextRender(() => client.mountDevtools(), { injector });
460
+ destroyRef.onDestroy(() => client.dispose());
461
+ return {
462
+ generate: (input) => client.generate(input),
463
+ result: result.asReadonly(),
464
+ jobId: jobId.asReadonly(),
465
+ videoStatus: videoStatus.asReadonly(),
466
+ isLoading: isLoading.asReadonly(),
467
+ error: error.asReadonly(),
468
+ status: status.asReadonly(),
469
+ stop: () => client.stop(),
470
+ reset: () => client.reset(),
471
+ };
472
+ }
473
+
474
+ // Chat
475
+
476
+ /**
477
+ * Generated bundle index. Do not edit.
478
+ */
479
+
480
+ export { injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectSummarize, injectTranscription };
481
+ //# sourceMappingURL=tanstack-ai-angular.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack-ai-angular.mjs","sources":["../../src/internal/to-reactive.ts","../../src/inject-chat.ts","../../src/inject-generation.ts","../../src/inject-generate-image.ts","../../src/inject-generate-audio.ts","../../src/inject-generate-speech.ts","../../src/inject-transcription.ts","../../src/inject-summarize.ts","../../src/inject-generate-video.ts","../../src/index.ts","../../src/tanstack-ai-angular.ts"],"sourcesContent":["import { computed, isSignal } from '@angular/core'\nimport type { Signal } from '@angular/core'\n\n/**\n * A value that may be supplied to `injectChat` either as a static value, an\n * Angular `Signal`, or a zero-arg getter. The getter form lets callers read\n * other signals so the option stays reactive.\n */\nexport type ReactiveOption<T> = T | Signal<T> | (() => T)\n\n/**\n * Normalize a {@link ReactiveOption} into a `Signal`-like getter `() => T`.\n *\n * - A `Signal` is returned as-is (already a getter that tracks reads).\n * - A zero-arg function is wrapped in `computed` so reads inside it are tracked.\n * - A plain value becomes a constant non-reactive fn (never re-fires).\n */\nexport function toReactive<T>(value: ReactiveOption<T>): () => T {\n if (isSignal(value)) {\n return value\n }\n if (typeof value === 'function') {\n return computed(value as () => T)\n }\n return () => value\n}\n","import { ChatClient } from '@tanstack/ai-client'\nimport { createChatDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n DestroyRef,\n Injector,\n afterNextRender,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport { toReactive } from './internal/to-reactive'\nimport type {\n AnyClientTool,\n InferSchemaType,\n ModelMessage,\n SchemaInput,\n StreamChunk,\n} from '@tanstack/ai'\nimport type {\n ChatClientState,\n ConnectionStatus,\n InferredClientContext,\n StructuredOutputPart,\n} from '@tanstack/ai-client'\nimport type {\n DeepPartial,\n InjectChatOptions,\n InjectChatResult,\n MultimodalContent,\n UIMessage,\n} from './types'\n\nlet nextId = 0\n\nexport function injectChat<\n TTools extends ReadonlyArray<AnyClientTool> = any,\n TSchema extends SchemaInput | undefined = undefined,\n TContext = InferredClientContext<TTools>,\n>(\n options: InjectChatOptions<\n TTools,\n TSchema,\n TContext\n > = {} as InjectChatOptions<TTools, TSchema, TContext>,\n): InjectChatResult<TTools, TSchema> {\n assertInInjectionContext(injectChat)\n\n type Partial = DeepPartial<InferSchemaType<NonNullable<TSchema>>>\n type Final = InferSchemaType<NonNullable<TSchema>>\n\n const destroyRef = inject(DestroyRef)\n const injector = inject(Injector)\n const clientId = options.id || `injectChat-${nextId++}`\n\n const messages = signal<Array<UIMessage<TTools>>>(\n options.initialMessages || [],\n )\n const isLoading = signal(false)\n const error = signal<Error | undefined>(undefined)\n const status = signal<ChatClientState>('ready')\n const isSubscribed = signal(false)\n const connectionStatus = signal<ConnectionStatus>('disconnected')\n const sessionGenerating = signal(false)\n\n // Reactive option sources. Plain values become constant computeds.\n const bodySource =\n options.body !== undefined ? toReactive(options.body) : undefined\n const forwardedPropsSource =\n options.forwardedProps !== undefined\n ? toReactive(options.forwardedProps)\n : undefined\n const contextSource =\n options.context !== undefined ? toReactive(options.context) : undefined\n const liveSource =\n options.live !== undefined ? toReactive(options.live) : undefined\n\n const transport = options.connection\n ? { connection: options.connection }\n : { fetcher: options.fetcher }\n\n const client = new ChatClient<TTools, TContext>({\n devtoolsBridgeFactory: createChatDevtoolsBridge,\n ...transport,\n id: clientId,\n ...(options.initialMessages !== undefined && {\n initialMessages: options.initialMessages,\n }),\n ...(options.persistence !== undefined && {\n persistence: options.persistence,\n }),\n ...(bodySource !== undefined && { body: bodySource() }),\n ...(options.threadId !== undefined && { threadId: options.threadId }),\n ...(forwardedPropsSource !== undefined && {\n forwardedProps: forwardedPropsSource(),\n }),\n ...(contextSource !== undefined && { context: contextSource() }),\n devtools: {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectChat',\n outputKind: options.outputSchema ? 'structured' : 'chat',\n },\n onResponse: (response) => options.onResponse?.(response),\n onChunk: (chunk: StreamChunk) => options.onChunk?.(chunk),\n onFinish: (message) => options.onFinish?.(message),\n onError: (err) => options.onError?.(err),\n tools: options.tools,\n onCustomEvent: (eventType, data, context) =>\n options.onCustomEvent?.(eventType, data, context),\n ...(options.streamProcessor !== undefined && {\n streamProcessor: options.streamProcessor,\n }),\n onMessagesChange: (m: Array<UIMessage<TTools>>) => messages.set(m),\n onLoadingChange: (v: boolean) => isLoading.set(v),\n onStatusChange: (v: ChatClientState) => status.set(v),\n onErrorChange: (v: Error | undefined) => error.set(v),\n onSubscriptionChange: (v: boolean) => isSubscribed.set(v),\n onConnectionStatusChange: (v: ConnectionStatus) => connectionStatus.set(v),\n onSessionGeneratingChange: (v: boolean) => sessionGenerating.set(v),\n })\n\n messages.set(client.getMessages())\n\n // Sync reactive body / forwardedProps / context to the client.\n if (bodySource || forwardedPropsSource || contextSource) {\n effect(\n () => {\n const newBody = bodySource?.()\n const newForwardedProps = forwardedPropsSource?.()\n const newContext = contextSource?.()\n client.updateOptions({\n ...(newBody !== undefined && { body: newBody }),\n ...(newForwardedProps !== undefined && {\n forwardedProps: newForwardedProps,\n }),\n ...(newContext !== undefined && { context: newContext }),\n })\n },\n { injector },\n )\n }\n\n // Subscribe / unsubscribe based on reactive `live`.\n if (liveSource) {\n effect(\n () => {\n if (liveSource()) {\n client.subscribe()\n } else {\n client.unsubscribe()\n }\n },\n { injector },\n )\n }\n\n afterNextRender(() => client.mountDevtools(), { injector })\n\n destroyRef.onDestroy(() => {\n if (liveSource?.()) {\n client.unsubscribe()\n } else {\n client.stop()\n }\n client.dispose()\n })\n\n // Active structured-output part = the one on the assistant message after the\n // latest user message. Ported from ai-vue/src/use-chat.ts.\n const activeStructuredPart = computed<StructuredOutputPart | null>(() => {\n const list = messages()\n let lastUserIndex = -1\n for (let i = list.length - 1; i >= 0; i--) {\n if (list[i]?.role === 'user') {\n lastUserIndex = i\n break\n }\n }\n if (lastUserIndex === -1) return null\n for (let i = list.length - 1; i > lastUserIndex; i--) {\n const m = list[i]\n if (m?.role !== 'assistant') continue\n const part = m.parts.find(\n (p): p is StructuredOutputPart => p.type === 'structured-output',\n )\n if (part) return part\n }\n return null\n })\n\n const partial = computed<Partial>(() => {\n const part = activeStructuredPart()\n if (!part) return {} as Partial\n const v = part.partial ?? part.data\n return (v ?? {}) as Partial\n })\n\n const final = computed<Final | null>(() => {\n const part = activeStructuredPart()\n if (!part || part.status !== 'complete') return null\n return part.data as Final\n })\n\n const sendMessage = async (content: string | MultimodalContent) => {\n await client.sendMessage(content)\n }\n const append = async (message: ModelMessage | UIMessage<TTools>) => {\n await client.append(message)\n }\n const reload = async () => {\n await client.reload()\n }\n const stop = () => client.stop()\n const clear = () => client.clear()\n const setMessages = (m: Array<UIMessage<TTools>>) =>\n client.setMessagesManually(m)\n const addToolResult = async (result: {\n toolCallId: string\n tool: string\n output: any\n state?: 'output-available' | 'output-error'\n errorText?: string\n }) => {\n await client.addToolResult(result)\n }\n const addToolApprovalResponse = async (response: {\n id: string\n approved: boolean\n }) => {\n await client.addToolApprovalResponse(response)\n }\n\n // eslint-disable-next-line no-restricted-syntax -- return shape diverges from conditional InjectChatResult<TTools, TSchema>; TS can't structurally narrow the TSchema-gated partial/final signals\n return {\n messages: messages.asReadonly(),\n sendMessage,\n append,\n reload,\n stop,\n isLoading: isLoading.asReadonly(),\n error: error.asReadonly(),\n status: status.asReadonly(),\n isSubscribed: isSubscribed.asReadonly(),\n connectionStatus: connectionStatus.asReadonly(),\n sessionGenerating: sessionGenerating.asReadonly(),\n setMessages,\n clear,\n addToolResult,\n addToolApprovalResponse,\n partial,\n final,\n } as unknown as InjectChatResult<TTools, TSchema>\n}\n","import { GenerationClient } from '@tanstack/ai-client'\nimport { createGenerationDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n DestroyRef,\n Injector,\n afterNextRender,\n assertInInjectionContext,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport { toReactive } from './internal/to-reactive'\nimport type { Signal } from '@angular/core'\nimport type { StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientOptions,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { ReactiveOption } from './internal/to-reactive'\n\nlet nextId = 0\n\nexport interface InjectGenerationOptions<TInput, TResult, TOutput = TResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for one-shot generation (no streaming protocol needed) */\n fetcher?: GenerationFetcher<TInput, TResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional request body params. Reactive. */\n body?: ReactiveOption<Record<string, any>>\n /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\n /**\n * Callback when a result is received. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: TResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\nexport interface InjectGenerationResult<TOutput> {\n /** Trigger a generation request */\n generate: (input: Record<string, any>) => Promise<void>\n /** The generation result, or null if not yet generated */\n result: Signal<TOutput | null>\n /** Whether a generation is currently in progress */\n isLoading: Signal<boolean>\n /** Current error, if any */\n error: Signal<Error | undefined>\n /** Current state of the generation client */\n status: Signal<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\nexport function injectGeneration<\n TInput extends Record<string, any>,\n TResult,\n TOnResult extends ((result: TResult) => any) | undefined = undefined,\n>(\n options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectGenerationResult<InferGenerationOutput<TResult, TOnResult>> {\n assertInInjectionContext(injectGeneration)\n\n type TOutput = InferGenerationOutput<TResult, TOnResult>\n\n const destroyRef = inject(DestroyRef)\n const injector = inject(Injector)\n const clientId = options.id || `injectGeneration-${nextId++}`\n\n const result = signal<TOutput | null>(null)\n const isLoading = signal(false)\n const error = signal<Error | undefined>(undefined)\n const status = signal<GenerationClientState>('idle')\n\n const bodySource =\n options.body !== undefined ? toReactive(options.body) : undefined\n\n const clientOptions: GenerationClientOptions<TInput, TResult, TOutput> = {\n id: clientId,\n ...(bodySource !== undefined && { body: bodySource() }),\n devtoolsBridgeFactory: createGenerationDevtoolsBridge,\n devtools: {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectGeneration',\n },\n onResult: (r: TResult) => options.onResult?.(r),\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onResultChange: (r: TOutput | null) => result.set(r),\n onLoadingChange: (l: boolean) => isLoading.set(l),\n onErrorChange: (e: Error | undefined) => error.set(e),\n onStatusChange: (s: GenerationClientState) => status.set(s),\n }\n\n let client: GenerationClient<TInput, TResult, TOutput>\n if (options.connection) {\n client = new GenerationClient({\n ...clientOptions,\n connection: options.connection,\n })\n } else if (options.fetcher) {\n client = new GenerationClient({\n ...clientOptions,\n fetcher: options.fetcher,\n })\n } else {\n throw new Error(\n 'injectGeneration requires either a connection or fetcher option',\n )\n }\n\n if (bodySource) {\n effect(\n () => {\n client.updateOptions({ body: bodySource() })\n },\n { injector },\n )\n }\n\n afterNextRender(() => client.mountDevtools(), { injector })\n destroyRef.onDestroy(() => client.dispose())\n\n return {\n generate: ((input: TInput) => client.generate(input)) as (\n input: Record<string, any>,\n ) => Promise<void>,\n result: result.asReadonly(),\n isLoading: isLoading.asReadonly(),\n error: error.asReadonly(),\n status: status.asReadonly(),\n stop: () => client.stop(),\n reset: () => client.reset(),\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { ImageGenerationResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n ImageGenerateInput,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectGenerateImageOptions<TOutput = ImageGenerationResult> = Omit<\n InjectGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>,\n 'onResult'\n> & {\n onResult?: (result: ImageGenerationResult) => TOutput | null | void\n}\n\nexport interface InjectGenerateImageResult<TOutput = ImageGenerationResult> {\n generate: (input: ImageGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectGenerateImage<\n TOnResult extends ((result: ImageGenerationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<InjectGenerateImageOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectGenerateImageResult<\n InferGenerationOutput<ImageGenerationResult, TOnResult>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectGenerateImage',\n outputKind: 'image' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<ImageGenerateInput, ImageGenerationResult, TOnResult>({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: ImageGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { AudioGenerationResult, StreamChunk } from '@tanstack/ai'\nimport type {\n AIDevtoolsDisplayOptions,\n AudioGenerateInput,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n} from '@tanstack/ai-client'\nimport type { Signal } from '@angular/core'\nimport type { ReactiveOption } from './internal/to-reactive'\n\n/**\n * Options for the injectGenerateAudio injectable.\n *\n * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)\n */\nexport interface InjectGenerateAudioOptions<TOutput = AudioGenerationResult> {\n /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */\n connection?: ConnectConnectionAdapter\n /** Direct async function for audio generation */\n fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>\n /** Unique identifier for this generation instance */\n id?: string\n /** Additional body parameters to send with connect-based adapter requests. Reactive. */\n body?: ReactiveOption<Record<string, any>>\n /** Display options for TanStack AI Devtools. */\n devtools?: AIDevtoolsDisplayOptions\n /**\n * Callback when audio is generated. Can optionally return a transformed value.\n *\n * - Return a non-null value to transform and store it as the result\n * - Return `null` to keep the previous result unchanged\n * - Return nothing (`void`) to store the raw result as-is\n */\n onResult?: (result: AudioGenerationResult) => TOutput | null | void\n /** Callback when an error occurs */\n onError?: (error: Error) => void\n /** Callback when progress is reported (0-100) */\n onProgress?: (progress: number, message?: string) => void\n /** Callback for each stream chunk (connect-based adapter mode only) */\n onChunk?: (chunk: StreamChunk) => void\n}\n\n/**\n * Return type for the injectGenerateAudio injectable.\n *\n * @template TOutput - The output type (after optional transform)\n */\nexport interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> {\n /** Trigger audio generation */\n generate: (input: AudioGenerateInput) => Promise<void>\n /** The generation result containing audio, or null */\n result: Signal<TOutput | null>\n /** Whether generation is in progress */\n isLoading: Signal<boolean>\n /** Current error, if any */\n error: Signal<Error | undefined>\n /** Current state of the generation */\n status: Signal<GenerationClientState>\n /** Abort the current generation */\n stop: () => void\n /** Clear result, error, and return to idle */\n reset: () => void\n}\n\n/**\n * Angular injectable for generating audio (music, sound effects) using AI models.\n *\n * @example\n * ```typescript\n * import { Component } from '@angular/core'\n * import { injectGenerateAudio } from '@tanstack/ai-angular'\n * import { fetchServerSentEvents } from '@tanstack/ai-client'\n *\n * @Component({\n * selector: 'app-audio',\n * template: `\n * <button (click)=\"generate({ prompt: 'An upbeat electronic track', duration: 10 })\">\n * Generate\n * </button>\n * @if (result()) {\n * <audio [src]=\"result()!.audio.url\" controls></audio>\n * }\n * `,\n * })\n * export class AudioComponent {\n * private gen = injectGenerateAudio({\n * connection: fetchServerSentEvents('/api/generate/audio'),\n * })\n *\n * generate = this.gen.generate\n * result = this.gen.result\n * isLoading = this.gen.isLoading\n * }\n * ```\n */\nexport function injectGenerateAudio<\n TOnResult extends ((result: AudioGenerationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<InjectGenerateAudioOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectGenerateAudioResult<\n InferGenerationOutput<AudioGenerationResult, TOnResult>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectGenerateAudio',\n outputKind: 'audio' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<AudioGenerateInput, AudioGenerationResult, TOnResult>({\n ...options,\n devtools,\n })\n\n return {\n generate: generate as (input: AudioGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { TTSResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n InferGenerationOutput,\n SpeechGenerateInput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectGenerateSpeechOptions<TOutput = TTSResult> = Omit<\n InjectGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>,\n 'onResult'\n> & {\n onResult?: (result: TTSResult) => TOutput | null | void\n}\n\nexport interface InjectGenerateSpeechResult<TOutput = TTSResult> {\n generate: (input: SpeechGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectGenerateSpeech<\n TOnResult extends ((result: TTSResult) => any) | undefined = undefined,\n>(\n options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectGenerateSpeechResult<InferGenerationOutput<TTSResult, TOnResult>> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectGenerateSpeech',\n outputKind: 'audio' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<SpeechGenerateInput, TTSResult, TOnResult>({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: SpeechGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { TranscriptionResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n InferGenerationOutput,\n TranscriptionGenerateInput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectTranscriptionOptions<TOutput = TranscriptionResult> = Omit<\n InjectGenerationOptions<\n TranscriptionGenerateInput,\n TranscriptionResult,\n TOutput\n >,\n 'onResult'\n> & {\n onResult?: (result: TranscriptionResult) => TOutput | null | void\n}\n\nexport interface InjectTranscriptionResult<TOutput = TranscriptionResult> {\n generate: (input: TranscriptionGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectTranscription<\n TOnResult extends ((result: TranscriptionResult) => any) | undefined =\n undefined,\n>(\n options: Omit<InjectTranscriptionOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectTranscriptionResult<\n InferGenerationOutput<TranscriptionResult, TOnResult>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectTranscription',\n outputKind: 'text' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<\n TranscriptionGenerateInput,\n TranscriptionResult,\n TOnResult\n >({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: TranscriptionGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { injectGeneration } from './inject-generation'\nimport type { Signal } from '@angular/core'\nimport type { SummarizationResult } from '@tanstack/ai'\nimport type {\n GenerationClientState,\n InferGenerationOutput,\n SummarizeGenerateInput,\n} from '@tanstack/ai-client'\nimport type { InjectGenerationOptions } from './inject-generation'\n\nexport type InjectSummarizeOptions<TOutput = SummarizationResult> = Omit<\n InjectGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>,\n 'onResult'\n> & {\n onResult?: (result: SummarizationResult) => TOutput | null | void\n}\n\nexport interface InjectSummarizeResult<TOutput = SummarizationResult> {\n generate: (input: SummarizeGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectSummarize<\n TOnResult extends ((result: SummarizationResult) => any) | undefined =\n undefined,\n>(\n options: Omit<InjectSummarizeOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectSummarizeResult<\n InferGenerationOutput<SummarizationResult, TOnResult>\n> {\n const devtools = {\n ...options.devtools,\n framework: 'angular' as const,\n hookName: 'injectSummarize',\n outputKind: 'text' as const,\n }\n const { generate, result, isLoading, error, status, stop, reset } =\n injectGeneration<SummarizeGenerateInput, SummarizationResult, TOnResult>({\n ...options,\n devtools,\n })\n return {\n generate: generate as (input: SummarizeGenerateInput) => Promise<void>,\n result,\n isLoading,\n error,\n status,\n stop,\n reset,\n }\n}\n","import { VideoGenerationClient } from '@tanstack/ai-client'\nimport { createVideoDevtoolsBridge } from '@tanstack/ai-client/devtools'\nimport {\n DestroyRef,\n Injector,\n afterNextRender,\n assertInInjectionContext,\n effect,\n inject,\n signal,\n} from '@angular/core'\nimport { toReactive } from './internal/to-reactive'\nimport type { Signal } from '@angular/core'\nimport type { ReactiveOption } from './internal/to-reactive'\nimport type {\n AIDevtoolsDisplayOptions,\n ConnectConnectionAdapter,\n GenerationClientState,\n GenerationFetcher,\n InferGenerationOutput,\n VideoGenerateInput,\n VideoGenerateResult,\n VideoStatusInfo,\n} from '@tanstack/ai-client'\nimport type { StreamChunk } from '@tanstack/ai'\n\nlet nextId = 0\n\nexport interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {\n connection?: ConnectConnectionAdapter\n fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>\n id?: string\n body?: ReactiveOption<Record<string, any>>\n devtools?: AIDevtoolsDisplayOptions\n onResult?: (result: VideoGenerateResult) => TOutput | null | void\n onError?: (error: Error) => void\n onProgress?: (progress: number, message?: string) => void\n onJobCreated?: (jobId: string) => void\n onStatusUpdate?: (status: VideoStatusInfo) => void\n onChunk?: (chunk: StreamChunk) => void\n}\n\nexport interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {\n generate: (input: VideoGenerateInput) => Promise<void>\n result: Signal<TOutput | null>\n jobId: Signal<string | null>\n videoStatus: Signal<VideoStatusInfo | null>\n isLoading: Signal<boolean>\n error: Signal<Error | undefined>\n status: Signal<GenerationClientState>\n stop: () => void\n reset: () => void\n}\n\nexport function injectGenerateVideo<\n TOnResult extends ((result: VideoGenerateResult) => any) | undefined =\n undefined,\n>(\n options: Omit<InjectGenerateVideoOptions, 'onResult'> & {\n onResult?: TOnResult\n },\n): InjectGenerateVideoResult<\n InferGenerationOutput<VideoGenerateResult, TOnResult>\n> {\n assertInInjectionContext(injectGenerateVideo)\n\n type TOutput = InferGenerationOutput<VideoGenerateResult, TOnResult>\n\n const destroyRef = inject(DestroyRef)\n const injector = inject(Injector)\n const clientId = options.id || `injectGenerateVideo-${nextId++}`\n\n const result = signal<TOutput | null>(null)\n const jobId = signal<string | null>(null)\n const videoStatus = signal<VideoStatusInfo | null>(null)\n const isLoading = signal(false)\n const error = signal<Error | undefined>(undefined)\n const status = signal<GenerationClientState>('idle')\n\n const bodySource =\n options.body !== undefined ? toReactive(options.body) : undefined\n\n const baseOptions = {\n id: clientId,\n ...(bodySource !== undefined && { body: bodySource() }),\n devtoolsBridgeFactory: createVideoDevtoolsBridge,\n devtools: {\n ...options.devtools,\n framework: 'angular',\n hookName: 'injectGenerateVideo',\n outputKind: 'video' as const,\n },\n onResult: (r: VideoGenerateResult) => options.onResult?.(r),\n onError: (e: Error) => options.onError?.(e),\n onProgress: (p: number, m?: string) => options.onProgress?.(p, m),\n onChunk: (c: StreamChunk) => options.onChunk?.(c),\n onJobCreated: (id: string) => options.onJobCreated?.(id),\n onStatusUpdate: (s: VideoStatusInfo) => options.onStatusUpdate?.(s),\n onResultChange: (r: TOutput | null) => result.set(r),\n onLoadingChange: (l: boolean) => isLoading.set(l),\n onErrorChange: (e: Error | undefined) => error.set(e),\n onStatusChange: (s: GenerationClientState) => status.set(s),\n onJobIdChange: (id: string | null) => jobId.set(id),\n onVideoStatusChange: (s: VideoStatusInfo | null) => videoStatus.set(s),\n }\n\n let client: VideoGenerationClient<TOutput>\n if (options.connection) {\n client = new VideoGenerationClient({\n ...baseOptions,\n connection: options.connection,\n })\n } else if (options.fetcher) {\n client = new VideoGenerationClient({\n ...baseOptions,\n fetcher: options.fetcher,\n })\n } else {\n throw new Error(\n 'injectGenerateVideo requires either a connection or fetcher option',\n )\n }\n\n if (bodySource) {\n effect(\n () => {\n client.updateOptions({ body: bodySource() })\n },\n { injector },\n )\n }\n\n afterNextRender(() => client.mountDevtools(), { injector })\n destroyRef.onDestroy(() => client.dispose())\n\n return {\n generate: (input: VideoGenerateInput) => client.generate(input),\n result: result.asReadonly(),\n jobId: jobId.asReadonly(),\n videoStatus: videoStatus.asReadonly(),\n isLoading: isLoading.asReadonly(),\n error: error.asReadonly(),\n status: status.asReadonly(),\n stop: () => client.stop(),\n reset: () => client.reset(),\n }\n}\n","// Chat\nexport { injectChat } from './inject-chat'\n\n// Generation\nexport { injectGeneration } from './inject-generation'\nexport type {\n InjectGenerationOptions,\n InjectGenerationResult,\n} from './inject-generation'\n\n// Generate Image\nexport { injectGenerateImage } from './inject-generate-image'\nexport type {\n InjectGenerateImageOptions,\n InjectGenerateImageResult,\n} from './inject-generate-image'\n\n// Generate Audio\nexport { injectGenerateAudio } from './inject-generate-audio'\nexport type {\n InjectGenerateAudioOptions,\n InjectGenerateAudioResult,\n} from './inject-generate-audio'\n\n// Generate Speech\nexport { injectGenerateSpeech } from './inject-generate-speech'\nexport type {\n InjectGenerateSpeechOptions,\n InjectGenerateSpeechResult,\n} from './inject-generate-speech'\n\n// Transcription\nexport { injectTranscription } from './inject-transcription'\nexport type {\n InjectTranscriptionOptions,\n InjectTranscriptionResult,\n} from './inject-transcription'\n\n// Summarize\nexport { injectSummarize } from './inject-summarize'\nexport type {\n InjectSummarizeOptions,\n InjectSummarizeResult,\n} from './inject-summarize'\n\n// Generate Video\nexport { injectGenerateVideo } from './inject-generate-video'\nexport type {\n InjectGenerateVideoOptions,\n InjectGenerateVideoResult,\n} from './inject-generate-video'\n\n// Types from ./types\nexport type {\n DeepPartial,\n InjectChatOptions,\n InjectChatResult,\n UIMessage,\n ChatRequestBody,\n MultimodalContent,\n ReactiveOption,\n} from './types'\n\n// Re-export from @tanstack/ai-client for convenience\nexport {\n fetchServerSentEvents,\n fetchHttpStream,\n xhrServerSentEvents,\n xhrHttpStream,\n stream,\n rpcStream,\n createChatClientOptions,\n type ConnectionAdapter,\n type ConnectConnectionAdapter,\n type SubscribeConnectionAdapter,\n type RunAgentInputContext,\n type FetchConnectionOptions,\n type XhrConnectionOptions,\n type InferChatMessages,\n type GenerationClientState,\n type ImageGenerateInput,\n type AudioGenerateInput,\n type SpeechGenerateInput,\n type TranscriptionGenerateInput,\n type SummarizeGenerateInput,\n type VideoGenerateInput,\n type VideoGenerateResult,\n type VideoStatusInfo,\n} from '@tanstack/ai-client'\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["nextId"],"mappings":";;;;;AAUA;;;;;;AAMG;AACG,SAAU,UAAU,CAAI,KAAwB,EAAA;AACpD,IAAA,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;AACnB,QAAA,OAAO,KAAK;IACd;AACA,IAAA,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;AAC/B,QAAA,OAAO,QAAQ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ult, TTSResult, TranscriptionResult, SummarizationResult } from '@tanstack/ai';
2
+ import { InferredClientContext, DistributedOmit, ChatClientOptions, AIDevtoolsDisplayOptions, ClientContextOptionFromTools, UIMessage, MultimodalContent, ChatClientState, ConnectionStatus, ConnectConnectionAdapter, GenerationFetcher, GenerationClientState, InferGenerationOutput, ImageGenerateInput, AudioGenerateInput, SpeechGenerateInput, TranscriptionGenerateInput, SummarizeGenerateInput, VideoGenerateResult, VideoGenerateInput, VideoStatusInfo } from '@tanstack/ai-client';
3
+ export { AudioGenerateInput, ChatRequestBody, ConnectConnectionAdapter, ConnectionAdapter, FetchConnectionOptions, GenerationClientState, ImageGenerateInput, InferChatMessages, MultimodalContent, RunAgentInputContext, SpeechGenerateInput, SubscribeConnectionAdapter, SummarizeGenerateInput, TranscriptionGenerateInput, UIMessage, VideoGenerateInput, VideoGenerateResult, VideoStatusInfo, XhrConnectionOptions, createChatClientOptions, fetchHttpStream, fetchServerSentEvents, rpcStream, stream, xhrHttpStream, xhrServerSentEvents } from '@tanstack/ai-client';
4
+ import { Signal } from '@angular/core';
5
+
6
+ /**
7
+ * A value that may be supplied to `injectChat` either as a static value, an
8
+ * Angular `Signal`, or a zero-arg getter. The getter form lets callers read
9
+ * other signals so the option stays reactive.
10
+ */
11
+ type ReactiveOption<T> = T | Signal<T> | (() => T);
12
+
13
+ /**
14
+ * Recursive partial — every property and every nested array element is optional.
15
+ * Used to type the in-flight `partial` value while a structured-output stream
16
+ * is still arriving.
17
+ */
18
+ type DeepPartial<T> = T extends ReadonlyArray<infer U> ? Array<DeepPartial<U>> : T extends object ? {
19
+ [K in keyof T]?: DeepPartial<T[K]>;
20
+ } : T;
21
+ /**
22
+ * Options for {@link injectChat}.
23
+ *
24
+ * Mirrors the Vue `useChat` options, except:
25
+ * - State-change callbacks are managed internally and exposed as signals.
26
+ * - `body`, `forwardedProps`, and `live` accept a {@link ReactiveOption} so
27
+ * they can be a static value, a `Signal`, or a getter and stay reactive.
28
+ */
29
+ type InjectChatOptions<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>> = DistributedOmit<ChatClientOptions<TTools, TContext>, 'onMessagesChange' | 'onLoadingChange' | 'onErrorChange' | 'onStatusChange' | 'onSubscriptionChange' | 'onConnectionStatusChange' | 'onSessionGeneratingChange' | 'context' | 'devtools' | 'body' | 'forwardedProps'> & {
30
+ /** Display options for TanStack AI Devtools. */
31
+ devtools?: AIDevtoolsDisplayOptions;
32
+ /** Additional request body params. Reactive. */
33
+ body?: ReactiveOption<Record<string, any>>;
34
+ /** Forwarded request props (preferred over `body`). Reactive. */
35
+ forwardedProps?: ReactiveOption<Record<string, any>>;
36
+ /** Whether to keep a live subscription open. Reactive. */
37
+ live?: ReactiveOption<boolean>;
38
+ /**
39
+ * Standard-schema-compatible schema (Zod, Valibot, ArkType, or JSON Schema).
40
+ * Used to infer the shape of `partial` and `final`.
41
+ */
42
+ outputSchema?: TSchema;
43
+ } & ClientContextOptionFromTools<TTools, ReactiveOption<TContext>>;
44
+ /**
45
+ * Return shape of {@link injectChat}. When `outputSchema` is supplied, adds
46
+ * typed `partial` / `final` signals; otherwise the return is unchanged.
47
+ */
48
+ type InjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined> = BaseInjectChatResult<TTools, TSchema extends SchemaInput ? InferSchemaType<TSchema> : unknown> & (TSchema extends SchemaInput ? {
49
+ /** Live progressively-parsed structured output. */
50
+ partial: Signal<DeepPartial<InferSchemaType<TSchema>>>;
51
+ /** Final, schema-validated structured output. `null` until complete. */
52
+ final: Signal<InferSchemaType<TSchema> | null>;
53
+ } : Record<never, never>);
54
+ interface BaseInjectChatResult<TTools extends ReadonlyArray<AnyClientTool> = any, TData = unknown> {
55
+ /** Current messages in the conversation. */
56
+ messages: Signal<Array<UIMessage<TTools, TData>>>;
57
+ /** Send a message (string or multimodal content). */
58
+ sendMessage: (content: string | MultimodalContent) => Promise<void>;
59
+ /** Append a message to the conversation. */
60
+ append: (message: ModelMessage | UIMessage<TTools, TData>) => Promise<void>;
61
+ /** Add the result of a client-side tool execution. */
62
+ addToolResult: (result: {
63
+ toolCallId: string;
64
+ tool: string;
65
+ output: any;
66
+ state?: 'output-available' | 'output-error';
67
+ errorText?: string;
68
+ }) => Promise<void>;
69
+ /** Respond to a tool approval request. */
70
+ addToolApprovalResponse: (response: {
71
+ id: string;
72
+ approved: boolean;
73
+ }) => Promise<void>;
74
+ /** Reload the last assistant message. */
75
+ reload: () => Promise<void>;
76
+ /** Stop the current response generation. */
77
+ stop: () => void;
78
+ /** Whether a response is currently being generated. */
79
+ isLoading: Signal<boolean>;
80
+ /** Current error, if any. */
81
+ error: Signal<Error | undefined>;
82
+ /** Set messages manually. */
83
+ setMessages: (messages: Array<UIMessage<TTools, TData>>) => void;
84
+ /** Clear all messages. */
85
+ clear: () => void;
86
+ /** Current generation status. */
87
+ status: Signal<ChatClientState>;
88
+ /** Whether the subscription loop is active. */
89
+ isSubscribed: Signal<boolean>;
90
+ /** Current connection lifecycle status. */
91
+ connectionStatus: Signal<ConnectionStatus>;
92
+ /** Whether the shared session is actively generating. */
93
+ sessionGenerating: Signal<boolean>;
94
+ }
95
+
96
+ declare function injectChat<TTools extends ReadonlyArray<AnyClientTool> = any, TSchema extends SchemaInput | undefined = undefined, TContext = InferredClientContext<TTools>>(options?: InjectChatOptions<TTools, TSchema, TContext>): InjectChatResult<TTools, TSchema>;
97
+
98
+ interface InjectGenerationOptions<TInput, TResult, TOutput = TResult> {
99
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
100
+ connection?: ConnectConnectionAdapter;
101
+ /** Direct async function for one-shot generation (no streaming protocol needed) */
102
+ fetcher?: GenerationFetcher<TInput, TResult>;
103
+ /** Unique identifier for this generation instance */
104
+ id?: string;
105
+ /** Additional request body params. Reactive. */
106
+ body?: ReactiveOption<Record<string, any>>;
107
+ /** Display options for TanStack AI Devtools. */
108
+ devtools?: AIDevtoolsDisplayOptions;
109
+ /**
110
+ * Callback when a result is received. Can optionally return a transformed value.
111
+ *
112
+ * - Return a non-null value to transform and store it as the result
113
+ * - Return `null` to keep the previous result unchanged
114
+ * - Return nothing (`void`) to store the raw result as-is
115
+ */
116
+ onResult?: (result: TResult) => TOutput | null | void;
117
+ /** Callback when an error occurs */
118
+ onError?: (error: Error) => void;
119
+ /** Callback when progress is reported (0-100) */
120
+ onProgress?: (progress: number, message?: string) => void;
121
+ /** Callback for each stream chunk (connect-based adapter mode only) */
122
+ onChunk?: (chunk: StreamChunk) => void;
123
+ }
124
+ interface InjectGenerationResult<TOutput> {
125
+ /** Trigger a generation request */
126
+ generate: (input: Record<string, any>) => Promise<void>;
127
+ /** The generation result, or null if not yet generated */
128
+ result: Signal<TOutput | null>;
129
+ /** Whether a generation is currently in progress */
130
+ isLoading: Signal<boolean>;
131
+ /** Current error, if any */
132
+ error: Signal<Error | undefined>;
133
+ /** Current state of the generation client */
134
+ status: Signal<GenerationClientState>;
135
+ /** Abort the current generation */
136
+ stop: () => void;
137
+ /** Clear result, error, and return to idle */
138
+ reset: () => void;
139
+ }
140
+ declare function injectGeneration<TInput extends Record<string, any>, TResult, TOnResult extends ((result: TResult) => any) | undefined = undefined>(options: Omit<InjectGenerationOptions<TInput, TResult>, 'onResult'> & {
141
+ onResult?: TOnResult;
142
+ }): InjectGenerationResult<InferGenerationOutput<TResult, TOnResult>>;
143
+
144
+ type InjectGenerateImageOptions<TOutput = ImageGenerationResult> = Omit<InjectGenerationOptions<ImageGenerateInput, ImageGenerationResult, TOutput>, 'onResult'> & {
145
+ onResult?: (result: ImageGenerationResult) => TOutput | null | void;
146
+ };
147
+ interface InjectGenerateImageResult<TOutput = ImageGenerationResult> {
148
+ generate: (input: ImageGenerateInput) => Promise<void>;
149
+ result: Signal<TOutput | null>;
150
+ isLoading: Signal<boolean>;
151
+ error: Signal<Error | undefined>;
152
+ status: Signal<GenerationClientState>;
153
+ stop: () => void;
154
+ reset: () => void;
155
+ }
156
+ declare function injectGenerateImage<TOnResult extends ((result: ImageGenerationResult) => any) | undefined = undefined>(options: Omit<InjectGenerateImageOptions, 'onResult'> & {
157
+ onResult?: TOnResult;
158
+ }): InjectGenerateImageResult<InferGenerationOutput<ImageGenerationResult, TOnResult>>;
159
+
160
+ /**
161
+ * Options for the injectGenerateAudio injectable.
162
+ *
163
+ * @template TOutput - The output type after optional transform (defaults to AudioGenerationResult)
164
+ */
165
+ interface InjectGenerateAudioOptions<TOutput = AudioGenerationResult> {
166
+ /** Connect-based adapter for streaming transport (SSE, HTTP stream, custom) */
167
+ connection?: ConnectConnectionAdapter;
168
+ /** Direct async function for audio generation */
169
+ fetcher?: GenerationFetcher<AudioGenerateInput, AudioGenerationResult>;
170
+ /** Unique identifier for this generation instance */
171
+ id?: string;
172
+ /** Additional body parameters to send with connect-based adapter requests. Reactive. */
173
+ body?: ReactiveOption<Record<string, any>>;
174
+ /** Display options for TanStack AI Devtools. */
175
+ devtools?: AIDevtoolsDisplayOptions;
176
+ /**
177
+ * Callback when audio is generated. Can optionally return a transformed value.
178
+ *
179
+ * - Return a non-null value to transform and store it as the result
180
+ * - Return `null` to keep the previous result unchanged
181
+ * - Return nothing (`void`) to store the raw result as-is
182
+ */
183
+ onResult?: (result: AudioGenerationResult) => TOutput | null | void;
184
+ /** Callback when an error occurs */
185
+ onError?: (error: Error) => void;
186
+ /** Callback when progress is reported (0-100) */
187
+ onProgress?: (progress: number, message?: string) => void;
188
+ /** Callback for each stream chunk (connect-based adapter mode only) */
189
+ onChunk?: (chunk: StreamChunk) => void;
190
+ }
191
+ /**
192
+ * Return type for the injectGenerateAudio injectable.
193
+ *
194
+ * @template TOutput - The output type (after optional transform)
195
+ */
196
+ interface InjectGenerateAudioResult<TOutput = AudioGenerationResult> {
197
+ /** Trigger audio generation */
198
+ generate: (input: AudioGenerateInput) => Promise<void>;
199
+ /** The generation result containing audio, or null */
200
+ result: Signal<TOutput | null>;
201
+ /** Whether generation is in progress */
202
+ isLoading: Signal<boolean>;
203
+ /** Current error, if any */
204
+ error: Signal<Error | undefined>;
205
+ /** Current state of the generation */
206
+ status: Signal<GenerationClientState>;
207
+ /** Abort the current generation */
208
+ stop: () => void;
209
+ /** Clear result, error, and return to idle */
210
+ reset: () => void;
211
+ }
212
+ /**
213
+ * Angular injectable for generating audio (music, sound effects) using AI models.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * import { Component } from '@angular/core'
218
+ * import { injectGenerateAudio } from '@tanstack/ai-angular'
219
+ * import { fetchServerSentEvents } from '@tanstack/ai-client'
220
+ *
221
+ * @Component({
222
+ * selector: 'app-audio',
223
+ * template: `
224
+ * <button (click)="generate({ prompt: 'An upbeat electronic track', duration: 10 })">
225
+ * Generate
226
+ * </button>
227
+ * @if (result()) {
228
+ * <audio [src]="result()!.audio.url" controls></audio>
229
+ * }
230
+ * `,
231
+ * })
232
+ * export class AudioComponent {
233
+ * private gen = injectGenerateAudio({
234
+ * connection: fetchServerSentEvents('/api/generate/audio'),
235
+ * })
236
+ *
237
+ * generate = this.gen.generate
238
+ * result = this.gen.result
239
+ * isLoading = this.gen.isLoading
240
+ * }
241
+ * ```
242
+ */
243
+ declare function injectGenerateAudio<TOnResult extends ((result: AudioGenerationResult) => any) | undefined = undefined>(options: Omit<InjectGenerateAudioOptions, 'onResult'> & {
244
+ onResult?: TOnResult;
245
+ }): InjectGenerateAudioResult<InferGenerationOutput<AudioGenerationResult, TOnResult>>;
246
+
247
+ type InjectGenerateSpeechOptions<TOutput = TTSResult> = Omit<InjectGenerationOptions<SpeechGenerateInput, TTSResult, TOutput>, 'onResult'> & {
248
+ onResult?: (result: TTSResult) => TOutput | null | void;
249
+ };
250
+ interface InjectGenerateSpeechResult<TOutput = TTSResult> {
251
+ generate: (input: SpeechGenerateInput) => Promise<void>;
252
+ result: Signal<TOutput | null>;
253
+ isLoading: Signal<boolean>;
254
+ error: Signal<Error | undefined>;
255
+ status: Signal<GenerationClientState>;
256
+ stop: () => void;
257
+ reset: () => void;
258
+ }
259
+ declare function injectGenerateSpeech<TOnResult extends ((result: TTSResult) => any) | undefined = undefined>(options: Omit<InjectGenerateSpeechOptions, 'onResult'> & {
260
+ onResult?: TOnResult;
261
+ }): InjectGenerateSpeechResult<InferGenerationOutput<TTSResult, TOnResult>>;
262
+
263
+ type InjectTranscriptionOptions<TOutput = TranscriptionResult> = Omit<InjectGenerationOptions<TranscriptionGenerateInput, TranscriptionResult, TOutput>, 'onResult'> & {
264
+ onResult?: (result: TranscriptionResult) => TOutput | null | void;
265
+ };
266
+ interface InjectTranscriptionResult<TOutput = TranscriptionResult> {
267
+ generate: (input: TranscriptionGenerateInput) => Promise<void>;
268
+ result: Signal<TOutput | null>;
269
+ isLoading: Signal<boolean>;
270
+ error: Signal<Error | undefined>;
271
+ status: Signal<GenerationClientState>;
272
+ stop: () => void;
273
+ reset: () => void;
274
+ }
275
+ declare function injectTranscription<TOnResult extends ((result: TranscriptionResult) => any) | undefined = undefined>(options: Omit<InjectTranscriptionOptions, 'onResult'> & {
276
+ onResult?: TOnResult;
277
+ }): InjectTranscriptionResult<InferGenerationOutput<TranscriptionResult, TOnResult>>;
278
+
279
+ type InjectSummarizeOptions<TOutput = SummarizationResult> = Omit<InjectGenerationOptions<SummarizeGenerateInput, SummarizationResult, TOutput>, 'onResult'> & {
280
+ onResult?: (result: SummarizationResult) => TOutput | null | void;
281
+ };
282
+ interface InjectSummarizeResult<TOutput = SummarizationResult> {
283
+ generate: (input: SummarizeGenerateInput) => Promise<void>;
284
+ result: Signal<TOutput | null>;
285
+ isLoading: Signal<boolean>;
286
+ error: Signal<Error | undefined>;
287
+ status: Signal<GenerationClientState>;
288
+ stop: () => void;
289
+ reset: () => void;
290
+ }
291
+ declare function injectSummarize<TOnResult extends ((result: SummarizationResult) => any) | undefined = undefined>(options: Omit<InjectSummarizeOptions, 'onResult'> & {
292
+ onResult?: TOnResult;
293
+ }): InjectSummarizeResult<InferGenerationOutput<SummarizationResult, TOnResult>>;
294
+
295
+ interface InjectGenerateVideoOptions<TOutput = VideoGenerateResult> {
296
+ connection?: ConnectConnectionAdapter;
297
+ fetcher?: GenerationFetcher<VideoGenerateInput, VideoGenerateResult>;
298
+ id?: string;
299
+ body?: ReactiveOption<Record<string, any>>;
300
+ devtools?: AIDevtoolsDisplayOptions;
301
+ onResult?: (result: VideoGenerateResult) => TOutput | null | void;
302
+ onError?: (error: Error) => void;
303
+ onProgress?: (progress: number, message?: string) => void;
304
+ onJobCreated?: (jobId: string) => void;
305
+ onStatusUpdate?: (status: VideoStatusInfo) => void;
306
+ onChunk?: (chunk: StreamChunk) => void;
307
+ }
308
+ interface InjectGenerateVideoResult<TOutput = VideoGenerateResult> {
309
+ generate: (input: VideoGenerateInput) => Promise<void>;
310
+ result: Signal<TOutput | null>;
311
+ jobId: Signal<string | null>;
312
+ videoStatus: Signal<VideoStatusInfo | null>;
313
+ isLoading: Signal<boolean>;
314
+ error: Signal<Error | undefined>;
315
+ status: Signal<GenerationClientState>;
316
+ stop: () => void;
317
+ reset: () => void;
318
+ }
319
+ declare function injectGenerateVideo<TOnResult extends ((result: VideoGenerateResult) => any) | undefined = undefined>(options: Omit<InjectGenerateVideoOptions, 'onResult'> & {
320
+ onResult?: TOnResult;
321
+ }): InjectGenerateVideoResult<InferGenerationOutput<VideoGenerateResult, TOnResult>>;
322
+
323
+ export { injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectSummarize, injectTranscription };
324
+ export type { DeepPartial, InjectChatOptions, InjectChatResult, InjectGenerateAudioOptions, InjectGenerateAudioResult, InjectGenerateImageOptions, InjectGenerateImageResult, InjectGenerateSpeechOptions, InjectGenerateSpeechResult, InjectGenerateVideoOptions, InjectGenerateVideoResult, InjectGenerationOptions, InjectGenerationResult, InjectSummarizeOptions, InjectSummarizeResult, InjectTranscriptionOptions, InjectTranscriptionResult, ReactiveOption };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-angular",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Angular signals integration for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -45,11 +45,11 @@
45
45
  ],
46
46
  "dependencies": {
47
47
  "tslib": "^2.8.1",
48
- "@tanstack/ai-client": "0.18.5"
48
+ "@tanstack/ai-client": "0.18.6"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@angular/core": ">=21.0.0",
52
- "@tanstack/ai": "^0.36.0"
52
+ "@tanstack/ai": "^0.37.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@analogjs/vite-plugin-angular": "^1.10.0",
@@ -66,7 +66,7 @@
66
66
  "vitest": "^4.0.14",
67
67
  "zod": "^4.2.0",
68
68
  "zone.js": "^0.15.0",
69
- "@tanstack/ai": "0.36.0"
69
+ "@tanstack/ai": "0.37.0"
70
70
  },
71
71
  "scripts": {
72
72
  "clean": "premove ./build ./dist",