@tanstack/ai-angular 1.0.1 → 1.1.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.
@@ -1,692 +1,472 @@
1
- import { ChatClient, registerWebMCPTools, subscribeWebMCPTools, GenerationClient, reconstructImageResult, reconstructAudioResult, reconstructSpeechResult, reconstructTranscriptionResult, AudioRecorder, reconstructSummarizeResult, VideoGenerationClient } from '@tanstack/ai-client';
2
- export { AudioRecorder, BatchStrategy, ChatClient, CompositeStrategy, DurableStreamIncompleteError, GENERATION_EVENTS, GenerationClient, ImmediateStrategy, InterruptManager, PartialJSONParser, PunctuationStrategy, RealtimeClient, StorageUnavailableError, StreamProcessor, StreamReconnectLimitError, StreamTruncatedError, UnsupportedResponseStreamError, VideoGenerationClient, WordBoundaryStrategy, clientTools, convertMessagesToModelMessages, createAIDevtoolsGenerationPreview, createChatClientOptions, createMcpAppBridge, defaultJSONParser, fetchHttpStream, fetchJson, fetchServerSentEvents, generateMessageId, getWebMCPTools, indexedDBPersistence, localStoragePersistence, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, reconstructAudioResult, reconstructImageResult, reconstructSpeechResult, reconstructSummarizeResult, reconstructTranscriptionResult, registerWebMCPTools, rpcStream, sessionStoragePersistence, stream, subscribeWebMCPTools, uiMessageToModelMessages, webSocket, 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
- */
1
+ import { AudioRecorder, AudioRecorder as AudioRecorder$1, BatchStrategy, ChatClient, ChatClient as ChatClient$1, CompositeStrategy, DurableStreamIncompleteError, GENERATION_EVENTS, GenerationClient, GenerationClient as GenerationClient$1, ImmediateStrategy, InterruptManager, PartialJSONParser, PunctuationStrategy, RealtimeClient, StorageUnavailableError, StreamProcessor, StreamReconnectLimitError, StreamTruncatedError, UnsupportedResponseStreamError, VideoGenerationClient, VideoGenerationClient as VideoGenerationClient$1, WordBoundaryStrategy, clientTools, convertMessagesToModelMessages, createAIDevtoolsGenerationPreview, createChatClientOptions, createMcpAppBridge, defaultJSONParser, fetchHttpStream, fetchJson, fetchServerSentEvents, generateMessageId, getWebMCPTools, indexedDBPersistence, localStoragePersistence, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, reconstructAudioResult, reconstructAudioResult as reconstructAudioResult$1, reconstructImageResult, reconstructImageResult as reconstructImageResult$1, reconstructSpeechResult, reconstructSpeechResult as reconstructSpeechResult$1, reconstructSummarizeResult, reconstructSummarizeResult as reconstructSummarizeResult$1, reconstructTranscriptionResult, reconstructTranscriptionResult as reconstructTranscriptionResult$1, registerWebMCPTools, registerWebMCPTools as registerWebMCPTools$1, rpcStream, sessionStoragePersistence, stream, subscribeWebMCPTools, subscribeWebMCPTools as subscribeWebMCPTools$1, uiMessageToModelMessages, webSocket, xhrHttpStream, xhrServerSentEvents } from "@tanstack/ai-client";
2
+ import { createChatDevtoolsBridge, createGenerationDevtoolsBridge, createVideoDevtoolsBridge } from "@tanstack/ai-client/devtools";
3
+ import { DestroyRef, Injector, afterNextRender, assertInInjectionContext, computed, effect, inject, isSignal, signal } from "@angular/core";
13
4
  function toReactive(value) {
14
- if (isSignal(value)) {
15
- return value;
16
- }
17
- if (typeof value === 'function') {
18
- return computed(value);
19
- }
20
- return () => value;
5
+ if (isSignal(value)) return value;
6
+ if (typeof value === "function") return computed(value);
7
+ return () => value;
21
8
  }
22
-
23
9
  function injectChat(options) {
24
- assertInInjectionContext(injectChat);
25
- const destroyRef = inject(DestroyRef);
26
- const injector = inject(Injector);
27
- // Reactive option sources. Plain values become constant computeds.
28
- const forwardedPropsSource = options.forwardedProps !== undefined
29
- ? toReactive(options.forwardedProps)
30
- : undefined;
31
- const contextSource = options.context !== undefined ? toReactive(options.context) : undefined;
32
- const liveSource = options.live !== undefined ? toReactive(options.live) : undefined;
33
- const toolsSource = options.tools !== undefined ? toReactive(options.tools) : undefined;
34
- const transport = options.connection
35
- ? { connection: options.connection }
36
- : { fetcher: options.fetcher };
37
- const client = new ChatClient({
38
- devtoolsBridgeFactory: createChatDevtoolsBridge,
39
- ...transport,
40
- ...(options.initialMessages !== undefined && {
41
- initialMessages: options.initialMessages,
42
- }),
43
- threadId: options.threadId,
44
- ...(options.persistence === true
45
- ? {
46
- persistence: true,
47
- ...(options.history !== undefined && {
48
- history: options.history,
49
- }),
50
- }
51
- : { persistence: options.persistence }),
52
- ...(options.initialResumeSnapshot !== undefined && {
53
- initialResumeSnapshot: options.initialResumeSnapshot,
54
- }),
55
- ...(forwardedPropsSource !== undefined && {
56
- forwardedProps: forwardedPropsSource(),
57
- }),
58
- ...(options.byok !== undefined && { byok: options.byok }),
59
- byokProvider: () => options.byokProvider?.(),
60
- ...(contextSource !== undefined && { context: contextSource() }),
61
- devtools: {
62
- ...options.devtools,
63
- framework: 'angular',
64
- hookName: 'injectChat',
65
- outputKind: options.outputSchema ? 'structured' : 'chat',
66
- },
67
- onResponse: (response) => options.onResponse?.(response),
68
- onChunk: (chunk) => options.onChunk?.(chunk),
69
- onFinish: (message) => options.onFinish?.(message),
70
- onError: (err) => options.onError?.(err),
71
- onInterruptStateChange: (nextInterruptState, context) => {
72
- options.onInterruptStateChange?.(nextInterruptState, context);
73
- },
74
- tools: toolsSource?.(),
75
- ...(options.interrupts !== undefined && {
76
- interrupts: options.interrupts,
77
- }),
78
- onCustomEvent: (eventType, data, context) => options.onCustomEvent?.(eventType, data, context),
79
- ...(options.streamProcessor !== undefined && {
80
- streamProcessor: options.streamProcessor,
81
- }),
82
- ...(options.queue !== undefined && { queue: options.queue }),
83
- });
84
- const snapshot = signal(client.getSnapshot(), ...(ngDevMode ? [{ debugName: "snapshot" }] : /* istanbul ignore next */ []));
85
- const messages = computed(() => snapshot().messages, ...(ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []));
86
- const interruptState = computed(() => snapshot().interruptState, ...(ngDevMode ? [{ debugName: "interruptState" }] : /* istanbul ignore next */ []));
87
- const unsubscribeSnapshot = client.subscribeSnapshot(() => snapshot.set(client.getSnapshot()));
88
- // START TAILING HERE, not in the constructor. A client is idle until something
89
- // attaches it, so a client that gets built and thrown away never opens a
90
- // connection — an unreachable stream would hold one of the browser's ~6
91
- // connections per origin until the page reloaded. `inject*` runs in an injection
92
- // context tied to the consumer's lifetime, and `destroyRef.onDestroy` below is the
93
- // matching `detach`.
94
- client.attach();
95
- // Sync reactive forwardedProps / context to the client.
96
- if (forwardedPropsSource || contextSource) {
97
- effect(() => {
98
- const newForwardedProps = forwardedPropsSource?.();
99
- const newContext = contextSource?.();
100
- client.updateOptions({
101
- ...(newForwardedProps !== undefined && {
102
- forwardedProps: newForwardedProps,
103
- }),
104
- ...(newContext !== undefined && { context: newContext }),
105
- });
106
- }, { injector });
107
- }
108
- // Sync reactive tools to the client.
109
- if (toolsSource) {
110
- effect(() => client.updateOptions({ tools: toolsSource() }), { injector });
111
- }
112
- // Subscribe / unsubscribe based on reactive `live`.
113
- if (liveSource) {
114
- effect(() => {
115
- if (liveSource()) {
116
- client.subscribe();
117
- }
118
- else {
119
- client.unsubscribe();
120
- }
121
- }, { injector });
122
- }
123
- afterNextRender(() => {
124
- client.mountDevtools();
125
- // Delivery-durability resume is transparent: the resumable SSE
126
- // connection adapter reattaches via the browser's native Last-Event-ID
127
- // on reconnect. No client-side auto-resume wiring is needed.
128
- }, { injector });
129
- destroyRef.onDestroy(() => {
130
- unsubscribeSnapshot();
131
- // Release the connection first: the counterpart of the `attach` above.
132
- client.detach();
133
- if (liveSource?.()) {
134
- client.unsubscribe();
135
- }
136
- else {
137
- client.stop();
138
- }
139
- client.dispose();
140
- });
141
- // Active structured-output part = the one on the assistant message after the
142
- // latest user message. Ported from ai-vue/src/use-chat.ts.
143
- const activeStructuredPart = computed(() => {
144
- const list = messages();
145
- let lastUserIndex = -1;
146
- for (let i = list.length - 1; i >= 0; i--) {
147
- if (list[i]?.role === 'user') {
148
- lastUserIndex = i;
149
- break;
150
- }
151
- }
152
- if (lastUserIndex === -1)
153
- return null;
154
- for (let i = list.length - 1; i > lastUserIndex; i--) {
155
- const m = list[i];
156
- if (m?.role !== 'assistant')
157
- continue;
158
- const part = m.parts.find((p) => p.type === 'structured-output');
159
- if (part)
160
- return part;
161
- }
162
- return null;
163
- }, ...(ngDevMode ? [{ debugName: "activeStructuredPart" }] : /* istanbul ignore next */ []));
164
- const partial = computed(() => {
165
- const part = activeStructuredPart();
166
- if (!part)
167
- return {};
168
- const v = part.partial ?? part.data;
169
- return (v ?? {});
170
- }, ...(ngDevMode ? [{ debugName: "partial" }] : /* istanbul ignore next */ []));
171
- const final = computed(() => {
172
- const part = activeStructuredPart();
173
- if (!part || part.status !== 'complete')
174
- return null;
175
- return part.data;
176
- }, ...(ngDevMode ? [{ debugName: "final" }] : /* istanbul ignore next */ []));
177
- const sendMessage = async (content, sendOptions) => {
178
- await client.sendMessage(content, undefined, sendOptions);
179
- };
180
- const cancelQueued = (id) => client.cancelQueued(id);
181
- const append = async (message) => {
182
- await client.append(message);
183
- };
184
- const reload = async () => {
185
- await client.reload();
186
- };
187
- const loadOlderMessages = async () => {
188
- await client.loadOlderMessages();
189
- };
190
- const stop = () => client.stop();
191
- const clear = () => client.clear();
192
- const setMessages = (m) => client.setMessagesManually(m);
193
- const addToolResult = async (result) => {
194
- await client.addToolResult(result);
195
- };
196
- const interrupts = computed(() => interruptState().interrupts, ...(ngDevMode ? [{ debugName: "interrupts" }] : /* istanbul ignore next */ []));
197
- const interruptErrors = computed(() => interruptState().interruptErrors, ...(ngDevMode ? [{ debugName: "interruptErrors" }] : /* istanbul ignore next */ []));
198
- const resuming = computed(() => interruptState().resuming, ...(ngDevMode ? [{ debugName: "resuming" }] : /* istanbul ignore next */ []));
199
- const resolveInterrupts = (resolution) => {
200
- if (typeof resolution === 'boolean') {
201
- client.resolveInterrupts(resolution);
202
- }
203
- else {
204
- client.resolveInterrupts(resolution);
205
- }
206
- };
207
- const cancelInterrupts = () => client.cancelInterrupts();
208
- const retryInterrupts = () => client.retryInterrupts();
209
- const resumeInterruptsUnsafe = (resumeItems, state) => client.resumeInterruptsUnsafe(resumeItems, state);
210
- // oxlint-disable-next-line eslint-js/no-restricted-syntax -- return shape diverges from conditional InjectChatResult<TTools, TSchema>; TS can't structurally narrow the TSchema-gated partial/final signals
211
- return {
212
- messages,
213
- sendMessage,
214
- queue: computed(() => snapshot().queue),
215
- cancelQueued,
216
- append,
217
- reload,
218
- stop,
219
- isLoading: computed(() => snapshot().isLoading),
220
- hasOlderMessages: computed(() => snapshot().hasOlderMessages),
221
- loadOlderMessages,
222
- error: computed(() => snapshot().error),
223
- status: computed(() => snapshot().status),
224
- isSubscribed: computed(() => snapshot().isSubscribed),
225
- connectionStatus: computed(() => snapshot().connectionStatus),
226
- sessionGenerating: computed(() => snapshot().sessionGenerating),
227
- isHydrating: computed(() => snapshot().isHydrating),
228
- setMessages,
229
- clear,
230
- addToolResult,
231
- runId: computed(() => snapshot().runId),
232
- interrupts,
233
- interruptErrors,
234
- resuming,
235
- resolveInterrupts,
236
- cancelInterrupts,
237
- retryInterrupts,
238
- resumeInterruptsUnsafe,
239
- partial,
240
- final,
241
- };
10
+ assertInInjectionContext(injectChat);
11
+ const destroyRef = inject(DestroyRef);
12
+ const injector = inject(Injector);
13
+ const forwardedPropsSource = options.forwardedProps !== void 0 ? toReactive(options.forwardedProps) : void 0;
14
+ const contextSource = options.context !== void 0 ? toReactive(options.context) : void 0;
15
+ const liveSource = options.live !== void 0 ? toReactive(options.live) : void 0;
16
+ const toolsSource = options.tools !== void 0 ? toReactive(options.tools) : void 0;
17
+ const transport = options.connection ? { connection: options.connection } : { fetcher: options.fetcher };
18
+ const client = new ChatClient$1({
19
+ devtoolsBridgeFactory: createChatDevtoolsBridge,
20
+ ...transport,
21
+ ...options.initialMessages !== void 0 && { initialMessages: options.initialMessages },
22
+ threadId: options.threadId,
23
+ ...options.persistence === true ? {
24
+ persistence: true,
25
+ ...options.history !== void 0 && { history: options.history }
26
+ } : { persistence: options.persistence },
27
+ ...options.initialResumeSnapshot !== void 0 && { initialResumeSnapshot: options.initialResumeSnapshot },
28
+ ...forwardedPropsSource !== void 0 && { forwardedProps: forwardedPropsSource() },
29
+ ...options.byok !== void 0 && { byok: options.byok },
30
+ byokProvider: () => options.byokProvider?.(),
31
+ ...contextSource !== void 0 && { context: contextSource() },
32
+ devtools: {
33
+ ...options.devtools,
34
+ framework: "angular",
35
+ hookName: "injectChat",
36
+ outputKind: options.outputSchema ? "structured" : "chat"
37
+ },
38
+ onResponse: (response) => options.onResponse?.(response),
39
+ onChunk: (chunk) => options.onChunk?.(chunk),
40
+ onFinish: (message) => options.onFinish?.(message),
41
+ onError: (err) => options.onError?.(err),
42
+ onInterruptStateChange: (nextInterruptState, context) => {
43
+ options.onInterruptStateChange?.(nextInterruptState, context);
44
+ },
45
+ tools: toolsSource?.(),
46
+ ...options.interrupts !== void 0 && { interrupts: options.interrupts },
47
+ onCustomEvent: (eventType, data, context) => options.onCustomEvent?.(eventType, data, context),
48
+ ...options.streamProcessor !== void 0 && { streamProcessor: options.streamProcessor },
49
+ ...options.queue !== void 0 && { queue: options.queue }
50
+ });
51
+ const snapshot = signal(client.getSnapshot(), ...ngDevMode ? [{ debugName: "snapshot" }] : /* istanbul ignore next */ []);
52
+ const messages = computed(() => snapshot().messages, ...ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []);
53
+ const interruptState = computed(() => snapshot().interruptState, ...ngDevMode ? [{ debugName: "interruptState" }] : /* istanbul ignore next */ []);
54
+ const unsubscribeSnapshot = client.subscribeSnapshot(() => snapshot.set(client.getSnapshot()));
55
+ client.attach();
56
+ if (forwardedPropsSource || contextSource) effect(() => {
57
+ const newForwardedProps = forwardedPropsSource?.();
58
+ const newContext = contextSource?.();
59
+ client.updateOptions({
60
+ ...newForwardedProps !== void 0 && { forwardedProps: newForwardedProps },
61
+ ...newContext !== void 0 && { context: newContext }
62
+ });
63
+ }, { injector });
64
+ if (toolsSource) effect(() => client.updateOptions({ tools: toolsSource() }), { injector });
65
+ if (liveSource) effect(() => {
66
+ if (liveSource()) client.subscribe();
67
+ else client.unsubscribe();
68
+ }, { injector });
69
+ afterNextRender(() => {
70
+ client.mountDevtools();
71
+ }, { injector });
72
+ destroyRef.onDestroy(() => {
73
+ unsubscribeSnapshot();
74
+ client.detach();
75
+ if (liveSource?.()) client.unsubscribe();
76
+ else client.stop();
77
+ client.dispose();
78
+ });
79
+ const activeStructuredPart = computed(() => {
80
+ const list = messages();
81
+ let lastUserIndex = -1;
82
+ for (let i = list.length - 1; i >= 0; i--) if (list[i]?.role === "user") {
83
+ lastUserIndex = i;
84
+ break;
85
+ }
86
+ if (lastUserIndex === -1) return null;
87
+ for (let i = list.length - 1; i > lastUserIndex; i--) {
88
+ const m = list[i];
89
+ if (m?.role !== "assistant") continue;
90
+ const part = m.parts.find((p) => p.type === "structured-output");
91
+ if (part) return part;
92
+ }
93
+ return null;
94
+ }, ...ngDevMode ? [{ debugName: "activeStructuredPart" }] : /* istanbul ignore next */ []);
95
+ const partial = computed(() => {
96
+ const part = activeStructuredPart();
97
+ if (!part) return {};
98
+ return part.partial ?? part.data ?? {};
99
+ }, ...ngDevMode ? [{ debugName: "partial" }] : /* istanbul ignore next */ []);
100
+ const final = computed(() => {
101
+ const part = activeStructuredPart();
102
+ if (!part || part.status !== "complete") return null;
103
+ return part.data;
104
+ }, ...ngDevMode ? [{ debugName: "final" }] : /* istanbul ignore next */ []);
105
+ const sendMessage = async (content, sendOptions) => {
106
+ await client.sendMessage(content, void 0, sendOptions);
107
+ };
108
+ const cancelQueued = (id) => client.cancelQueued(id);
109
+ const append = async (message) => {
110
+ await client.append(message);
111
+ };
112
+ const reload = async () => {
113
+ await client.reload();
114
+ };
115
+ const loadOlderMessages = async () => {
116
+ await client.loadOlderMessages();
117
+ };
118
+ const stop = () => client.stop();
119
+ const clear = () => client.clear();
120
+ const setMessages = (m) => client.setMessagesManually(m);
121
+ const addToolResult = async (result) => {
122
+ await client.addToolResult(result);
123
+ };
124
+ const interrupts = computed(() => interruptState().interrupts, ...ngDevMode ? [{ debugName: "interrupts" }] : /* istanbul ignore next */ []);
125
+ const interruptErrors = computed(() => interruptState().interruptErrors, ...ngDevMode ? [{ debugName: "interruptErrors" }] : /* istanbul ignore next */ []);
126
+ const resuming = computed(() => interruptState().resuming, ...ngDevMode ? [{ debugName: "resuming" }] : /* istanbul ignore next */ []);
127
+ const resolveInterrupts = (resolution) => {
128
+ if (typeof resolution === "boolean") client.resolveInterrupts(resolution);
129
+ else client.resolveInterrupts(resolution);
130
+ };
131
+ const cancelInterrupts = () => client.cancelInterrupts();
132
+ const retryInterrupts = () => client.retryInterrupts();
133
+ const resumeInterruptsUnsafe = (resumeItems, state) => client.resumeInterruptsUnsafe(resumeItems, state);
134
+ return {
135
+ messages,
136
+ sendMessage,
137
+ queue: computed(() => snapshot().queue),
138
+ cancelQueued,
139
+ append,
140
+ reload,
141
+ stop,
142
+ isLoading: computed(() => snapshot().isLoading),
143
+ hasOlderMessages: computed(() => snapshot().hasOlderMessages),
144
+ loadOlderMessages,
145
+ error: computed(() => snapshot().error),
146
+ status: computed(() => snapshot().status),
147
+ isSubscribed: computed(() => snapshot().isSubscribed),
148
+ connectionStatus: computed(() => snapshot().connectionStatus),
149
+ sessionGenerating: computed(() => snapshot().sessionGenerating),
150
+ isHydrating: computed(() => snapshot().isHydrating),
151
+ setMessages,
152
+ clear,
153
+ addToolResult,
154
+ runId: computed(() => snapshot().runId),
155
+ interrupts,
156
+ interruptErrors,
157
+ resuming,
158
+ resolveInterrupts,
159
+ cancelInterrupts,
160
+ retryInterrupts,
161
+ resumeInterruptsUnsafe,
162
+ partial,
163
+ final
164
+ };
242
165
  }
243
-
244
166
  function injectByok(client) {
245
- assertInInjectionContext(injectByok);
246
- const destroyRef = inject(DestroyRef);
247
- const snapshot = signal(client.getSnapshot(), ...(ngDevMode ? [{ debugName: "snapshot" }] : /* istanbul ignore next */ []));
248
- const unsubscribe = client.subscribe(() => {
249
- snapshot.set(client.getSnapshot());
250
- });
251
- destroyRef.onDestroy(unsubscribe);
252
- return snapshot.asReadonly();
167
+ assertInInjectionContext(injectByok);
168
+ const destroyRef = inject(DestroyRef);
169
+ const snapshot = signal(client.getSnapshot(), ...ngDevMode ? [{ debugName: "snapshot" }] : /* istanbul ignore next */ []);
170
+ const unsubscribe = client.subscribe(() => {
171
+ snapshot.set(client.getSnapshot());
172
+ });
173
+ destroyRef.onDestroy(unsubscribe);
174
+ return snapshot.asReadonly();
253
175
  }
254
-
255
- /**
256
- * Registers executable client tools with WebMCP for the current Angular owner.
257
- *
258
- * Angular removes the registrations when it destroys the injection owner. Call
259
- * this function in an injection context, such as a component field initializer.
260
- *
261
- * @param tools - The executable client tools to expose through WebMCP.
262
- * @param options - Runtime context, per-tool options, and error handling.
263
- *
264
- * @example
265
- * ```ts
266
- * registration = injectRegisterWebMCPTools([statusTool], {
267
- * onError: (error) => console.error(error),
268
- * })
269
- * ```
270
- */
271
176
  function injectRegisterWebMCPTools(tools, ...[options]) {
272
- assertInInjectionContext(injectRegisterWebMCPTools);
273
- const destroyRef = inject(DestroyRef);
274
- const registrationController = new AbortController();
275
- const { onError, ...registrationOptions } = options ?? {};
276
- destroyRef.onDestroy(() => registrationController.abort());
277
- void registerWebMCPTools(tools, {
278
- ...registrationOptions,
279
- signal: registrationController.signal,
280
- }).catch((error) => {
281
- if (!registrationController.signal.aborted) {
282
- onError?.(error);
283
- }
284
- });
177
+ assertInInjectionContext(injectRegisterWebMCPTools);
178
+ const destroyRef = inject(DestroyRef);
179
+ const registrationController = new AbortController();
180
+ const { onError, ...registrationOptions } = options ?? {};
181
+ destroyRef.onDestroy(() => registrationController.abort());
182
+ registerWebMCPTools$1(tools, {
183
+ ...registrationOptions,
184
+ signal: registrationController.signal
185
+ }).catch((error) => {
186
+ if (!registrationController.signal.aborted) onError?.(error);
187
+ });
285
188
  }
286
- /**
287
- * Returns the WebMCP tools on the page as client tools for `injectChat`.
288
- *
289
- * The signal starts empty and updates when the page registers or removes a
290
- * tool. Angular stops the updates when it destroys the injection owner. Call
291
- * this function in an injection context.
292
- *
293
- * @param options - A filter that skips tools, and an error callback.
294
- *
295
- * @example
296
- * ```ts
297
- * pageTools = injectPageWebMCPTools({
298
- * filter: (tool) => tool.origin === location.origin,
299
- * })
300
- * chat = injectChat({ threadId: 'support-1', connection, tools: this.pageTools })
301
- * ```
302
- */
303
189
  function injectPageWebMCPTools(options) {
304
- assertInInjectionContext(injectPageWebMCPTools);
305
- const destroyRef = inject(DestroyRef);
306
- const tools = signal([], ...(ngDevMode ? [{ debugName: "tools" }] : /* istanbul ignore next */ []));
307
- const controller = new AbortController();
308
- destroyRef.onDestroy(() => controller.abort());
309
- subscribeWebMCPTools((nextTools) => tools.set(nextTools), {
310
- signal: controller.signal,
311
- filter: (tool) => options?.filter?.(tool) ?? true,
312
- onError: (error) => options?.onError?.(error),
313
- });
314
- return tools.asReadonly();
190
+ assertInInjectionContext(injectPageWebMCPTools);
191
+ const destroyRef = inject(DestroyRef);
192
+ const tools = signal([], ...ngDevMode ? [{ debugName: "tools" }] : /* istanbul ignore next */ []);
193
+ const controller = new AbortController();
194
+ destroyRef.onDestroy(() => controller.abort());
195
+ subscribeWebMCPTools$1((nextTools) => tools.set(nextTools), {
196
+ signal: controller.signal,
197
+ filter: (tool) => options?.filter?.(tool) ?? true,
198
+ onError: (error) => options?.onError?.(error)
199
+ });
200
+ return tools.asReadonly();
315
201
  }
316
-
317
- // `TTransformed` infers from the `onResult` return position (a covariant
318
- // inference site that works even for an optional nested property), which types
319
- // the callback parameter as `TResult` and narrows `result`. Inferring the
320
- // whole callback as a defaulted type parameter instead collapses to the
321
- // default, leaving the parameter `any` — a hard error under `strict`. See
322
- // issue #848.
323
202
  function injectGeneration(options) {
324
- assertInInjectionContext(injectGeneration);
325
- const destroyRef = inject(DestroyRef);
326
- const injector = inject(Injector);
327
- const result = signal(null, ...(ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []));
328
- const isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
329
- const error = signal(undefined, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
330
- const status = signal('idle', ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
331
- const runId = signal(null, ...(ngDevMode ? [{ debugName: "runId" }] : /* istanbul ignore next */ []));
332
- let disposed = false;
333
- const bodySource = options.body !== undefined ? toReactive(options.body) : undefined;
334
- const clientOptions = {
335
- persistence: options.persistence,
336
- threadId: options.threadId,
337
- ...(bodySource !== undefined && { body: bodySource() }),
338
- ...(options.hydrateGeneration !== undefined && {
339
- hydrateGeneration: options.hydrateGeneration,
340
- }),
341
- ...(options.joinRun !== undefined && { joinRun: options.joinRun }),
342
- ...(options.byok !== undefined && { byok: options.byok }),
343
- byokProvider: () => options.byokProvider?.(),
344
- ...(options.reconstructResult
345
- ? { reconstructResult: options.reconstructResult }
346
- : {}),
347
- devtoolsBridgeFactory: createGenerationDevtoolsBridge,
348
- devtools: {
349
- ...options.devtools,
350
- framework: 'angular',
351
- hookName: 'injectGeneration',
352
- },
353
- // The transform's raw return type (`TTransformed`) and the stored output
354
- // (`TOutput`, with null/void/undefined stripped) are identical at runtime;
355
- // the cast bridges the relationship that the conditional type hides.
356
- onResult: ((r) => options.onResult?.(r)),
357
- onError: (e) => {
358
- if (!disposed)
359
- options.onError?.(e);
360
- },
361
- onProgress: (p, m) => {
362
- if (!disposed)
363
- options.onProgress?.(p, m);
364
- },
365
- onChunk: (c) => {
366
- if (!disposed)
367
- options.onChunk?.(c);
368
- },
369
- };
370
- let client;
371
- if (options.connection) {
372
- client = new GenerationClient({
373
- ...clientOptions,
374
- connection: options.connection,
375
- });
376
- }
377
- else if (options.fetcher) {
378
- client = new GenerationClient({
379
- ...clientOptions,
380
- fetcher: options.fetcher,
381
- });
382
- }
383
- else {
384
- throw new Error('injectGeneration requires either a connection or fetcher option');
385
- }
386
- const applySnapshot = () => {
387
- const next = client.getSnapshot();
388
- result.set(next.result);
389
- isLoading.set(next.isLoading);
390
- error.set(next.error);
391
- status.set(next.status);
392
- runId.set(next.runId);
393
- };
394
- applySnapshot();
395
- const unsubscribeSnapshot = client.subscribe(applySnapshot);
396
- if (bodySource) {
397
- effect(() => {
398
- client.updateOptions({
399
- body: bodySource(),
400
- });
401
- }, { injector });
402
- }
403
- // Mount devtools only. Generation runs are never auto-started after render —
404
- // persisted state is read-only for display.
405
- afterNextRender(() => {
406
- client.mountDevtools();
407
- }, { injector });
408
- destroyRef.onDestroy(() => {
409
- disposed = true;
410
- unsubscribeSnapshot();
411
- client.dispose();
412
- });
413
- return {
414
- generate: (input) => client.generate(input),
415
- result: result.asReadonly(),
416
- isLoading: isLoading.asReadonly(),
417
- error: error.asReadonly(),
418
- status: status.asReadonly(),
419
- stop: () => client.stop(),
420
- reset: () => client.reset(),
421
- runId: runId.asReadonly(),
422
- };
203
+ assertInInjectionContext(injectGeneration);
204
+ const destroyRef = inject(DestroyRef);
205
+ const injector = inject(Injector);
206
+ const result = signal(null, ...ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []);
207
+ const isLoading = signal(false, ...ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []);
208
+ const error = signal(void 0, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
209
+ const status = signal("idle", ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
210
+ const runId = signal(null, ...ngDevMode ? [{ debugName: "runId" }] : /* istanbul ignore next */ []);
211
+ let disposed = false;
212
+ const bodySource = options.body !== void 0 ? toReactive(options.body) : void 0;
213
+ const clientOptions = {
214
+ persistence: options.persistence,
215
+ threadId: options.threadId,
216
+ ...bodySource !== void 0 && { body: bodySource() },
217
+ ...options.hydrateGeneration !== void 0 && { hydrateGeneration: options.hydrateGeneration },
218
+ ...options.joinRun !== void 0 && { joinRun: options.joinRun },
219
+ ...options.byok !== void 0 && { byok: options.byok },
220
+ byokProvider: () => options.byokProvider?.(),
221
+ ...options.reconstructResult ? { reconstructResult: options.reconstructResult } : {},
222
+ devtoolsBridgeFactory: createGenerationDevtoolsBridge,
223
+ devtools: {
224
+ ...options.devtools,
225
+ framework: "angular",
226
+ hookName: "injectGeneration"
227
+ },
228
+ onResult: ((r) => options.onResult?.(r)),
229
+ onError: (e) => {
230
+ if (!disposed) options.onError?.(e);
231
+ },
232
+ onProgress: (p, m) => {
233
+ if (!disposed) options.onProgress?.(p, m);
234
+ },
235
+ onChunk: (c) => {
236
+ if (!disposed) options.onChunk?.(c);
237
+ }
238
+ };
239
+ let client;
240
+ if (options.connection) client = new GenerationClient$1({
241
+ ...clientOptions,
242
+ connection: options.connection
243
+ });
244
+ else if (options.fetcher) client = new GenerationClient$1({
245
+ ...clientOptions,
246
+ fetcher: options.fetcher
247
+ });
248
+ else throw new Error("injectGeneration requires either a connection or fetcher option");
249
+ const applySnapshot = () => {
250
+ const next = client.getSnapshot();
251
+ result.set(next.result);
252
+ isLoading.set(next.isLoading);
253
+ error.set(next.error);
254
+ status.set(next.status);
255
+ runId.set(next.runId);
256
+ };
257
+ applySnapshot();
258
+ const unsubscribeSnapshot = client.subscribe(applySnapshot);
259
+ if (bodySource) effect(() => {
260
+ client.updateOptions({ body: bodySource() });
261
+ }, { injector });
262
+ afterNextRender(() => {
263
+ client.mountDevtools();
264
+ }, { injector });
265
+ destroyRef.onDestroy(() => {
266
+ disposed = true;
267
+ unsubscribeSnapshot();
268
+ client.dispose();
269
+ });
270
+ return {
271
+ generate: (input) => client.generate(input),
272
+ result: result.asReadonly(),
273
+ isLoading: isLoading.asReadonly(),
274
+ error: error.asReadonly(),
275
+ status: status.asReadonly(),
276
+ stop: () => client.stop(),
277
+ reset: () => client.reset(),
278
+ runId: runId.asReadonly()
279
+ };
423
280
  }
424
-
425
281
  function injectGenerateImage(options) {
426
- const devtools = {
427
- ...options.devtools,
428
- framework: 'angular',
429
- hookName: 'injectGenerateImage',
430
- outputKind: 'image',
431
- };
432
- const generation = injectGeneration({
433
- ...options,
434
- devtools,
435
- reconstructResult: reconstructImageResult,
436
- });
437
- return generation;
282
+ const devtools = {
283
+ ...options.devtools,
284
+ framework: "angular",
285
+ hookName: "injectGenerateImage",
286
+ outputKind: "image"
287
+ };
288
+ return injectGeneration({
289
+ ...options,
290
+ devtools,
291
+ reconstructResult: reconstructImageResult$1
292
+ });
438
293
  }
439
-
440
- /**
441
- * Angular injectable for generating audio (music, sound effects) using AI models.
442
- *
443
- * @example
444
- * ```typescript
445
- * import { Component } from '@angular/core'
446
- * import { injectGenerateAudio } from '@tanstack/ai-angular'
447
- * import { fetchServerSentEvents } from '@tanstack/ai-client'
448
- *
449
- * @Component({
450
- * selector: 'app-audio',
451
- * template: `
452
- * <button (click)="generate({ prompt: 'An upbeat electronic track', duration: 10 })">
453
- * Generate
454
- * </button>
455
- * @if (result()) {
456
- * <audio [src]="result()!.audio.url" controls></audio>
457
- * }
458
- * `,
459
- * })
460
- * export class AudioComponent {
461
- * private gen = injectGenerateAudio({
462
- * threadId: 'theme-audio',
463
- * connection: fetchServerSentEvents('/api/generate/audio'),
464
- * })
465
- *
466
- * generate = this.gen.generate
467
- * result = this.gen.result
468
- * isLoading = this.gen.isLoading
469
- * }
470
- * ```
471
- */
472
294
  function injectGenerateAudio(options) {
473
- const devtools = {
474
- ...options.devtools,
475
- framework: 'angular',
476
- hookName: 'injectGenerateAudio',
477
- outputKind: 'audio',
478
- };
479
- const generation = injectGeneration({
480
- ...options,
481
- devtools,
482
- reconstructResult: reconstructAudioResult,
483
- });
484
- return generation;
295
+ const devtools = {
296
+ ...options.devtools,
297
+ framework: "angular",
298
+ hookName: "injectGenerateAudio",
299
+ outputKind: "audio"
300
+ };
301
+ return injectGeneration({
302
+ ...options,
303
+ devtools,
304
+ reconstructResult: reconstructAudioResult$1
305
+ });
485
306
  }
486
-
487
307
  function injectGenerateSpeech(options) {
488
- const devtools = {
489
- ...options.devtools,
490
- framework: 'angular',
491
- hookName: 'injectGenerateSpeech',
492
- outputKind: 'audio',
493
- };
494
- const generation = injectGeneration({
495
- ...options,
496
- devtools,
497
- reconstructResult: reconstructSpeechResult,
498
- });
499
- return generation;
308
+ const devtools = {
309
+ ...options.devtools,
310
+ framework: "angular",
311
+ hookName: "injectGenerateSpeech",
312
+ outputKind: "audio"
313
+ };
314
+ return injectGeneration({
315
+ ...options,
316
+ devtools,
317
+ reconstructResult: reconstructSpeechResult$1
318
+ });
500
319
  }
501
-
502
320
  function injectTranscription(options) {
503
- const devtools = {
504
- ...options.devtools,
505
- framework: 'angular',
506
- hookName: 'injectTranscription',
507
- outputKind: 'text',
508
- };
509
- const generation = injectGeneration({
510
- ...options,
511
- devtools,
512
- reconstructResult: reconstructTranscriptionResult,
513
- });
514
- return generation;
321
+ const devtools = {
322
+ ...options.devtools,
323
+ framework: "angular",
324
+ hookName: "injectTranscription",
325
+ outputKind: "text"
326
+ };
327
+ return injectGeneration({
328
+ ...options,
329
+ devtools,
330
+ reconstructResult: reconstructTranscriptionResult$1
331
+ });
515
332
  }
516
-
517
333
  function injectAudioRecorder(options = {}) {
518
- assertInInjectionContext(injectAudioRecorder);
519
- const destroyRef = inject(DestroyRef);
520
- const recorder = new AudioRecorder({
521
- ...(options.audio !== undefined && { audio: options.audio }),
522
- ...(options.mimeType !== undefined && { mimeType: options.mimeType }),
523
- ...(options.onError !== undefined && { onError: options.onError }),
524
- });
525
- const isRecording = signal(false, ...(ngDevMode ? [{ debugName: "isRecording" }] : /* istanbul ignore next */ []));
526
- const recording = signal(null, ...(ngDevMode ? [{ debugName: "recording" }] : /* istanbul ignore next */ []));
527
- const unsubscribe = recorder.subscribe((state) => {
528
- isRecording.set(state === 'recording');
529
- });
530
- destroyRef.onDestroy(() => {
531
- unsubscribe();
532
- recorder.cancel();
533
- });
534
- const stop = async () => {
535
- const rawRecording = await recorder.stop();
536
- const transformed = await options.onComplete?.(rawRecording);
537
- // Only `undefined` (returning nothing) keeps the raw recording; a returned
538
- // null is a real value, matching the inferred output type.
539
- const output = transformed === undefined ? rawRecording : transformed;
540
- recording.set(output);
541
- return output;
542
- };
543
- return {
544
- recording: recording.asReadonly(),
545
- isRecording: isRecording.asReadonly(),
546
- isSupported: AudioRecorder.isSupported(),
547
- start: () => recorder.start(),
548
- stop,
549
- cancel: () => recorder.cancel(),
550
- };
334
+ assertInInjectionContext(injectAudioRecorder);
335
+ const destroyRef = inject(DestroyRef);
336
+ const recorder = new AudioRecorder$1({
337
+ ...options.audio !== void 0 && { audio: options.audio },
338
+ ...options.mimeType !== void 0 && { mimeType: options.mimeType },
339
+ ...options.onError !== void 0 && { onError: options.onError }
340
+ });
341
+ const isRecording = signal(false, ...ngDevMode ? [{ debugName: "isRecording" }] : /* istanbul ignore next */ []);
342
+ const recording = signal(null, ...ngDevMode ? [{ debugName: "recording" }] : /* istanbul ignore next */ []);
343
+ const unsubscribe = recorder.subscribe((state) => {
344
+ isRecording.set(state === "recording");
345
+ });
346
+ destroyRef.onDestroy(() => {
347
+ unsubscribe();
348
+ recorder.cancel();
349
+ });
350
+ const stop = async () => {
351
+ const rawRecording = await recorder.stop();
352
+ const transformed = await options.onComplete?.(rawRecording);
353
+ const output = transformed === void 0 ? rawRecording : transformed;
354
+ recording.set(output);
355
+ return output;
356
+ };
357
+ return {
358
+ recording: recording.asReadonly(),
359
+ isRecording: isRecording.asReadonly(),
360
+ isSupported: AudioRecorder$1.isSupported(),
361
+ start: () => recorder.start(),
362
+ stop,
363
+ cancel: () => recorder.cancel()
364
+ };
551
365
  }
552
-
553
366
  function injectSummarize(options) {
554
- const devtools = {
555
- ...options.devtools,
556
- framework: 'angular',
557
- hookName: 'injectSummarize',
558
- outputKind: 'text',
559
- };
560
- const generation = injectGeneration({
561
- ...options,
562
- devtools,
563
- reconstructResult: reconstructSummarizeResult,
564
- });
565
- return generation;
367
+ const devtools = {
368
+ ...options.devtools,
369
+ framework: "angular",
370
+ hookName: "injectSummarize",
371
+ outputKind: "text"
372
+ };
373
+ return injectGeneration({
374
+ ...options,
375
+ devtools,
376
+ reconstructResult: reconstructSummarizeResult$1
377
+ });
566
378
  }
567
-
568
- // `TTransformed` infers from the `onResult` return position so the callback
569
- // parameter is typed as `VideoGenerateResult` and `result` narrows to the
570
- // transform's return. See issue #848.
571
379
  function injectGenerateVideo(options) {
572
- assertInInjectionContext(injectGenerateVideo);
573
- const destroyRef = inject(DestroyRef);
574
- const injector = inject(Injector);
575
- const result = signal(null, ...(ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []));
576
- const jobId = signal(null, ...(ngDevMode ? [{ debugName: "jobId" }] : /* istanbul ignore next */ []));
577
- const videoStatus = signal(null, ...(ngDevMode ? [{ debugName: "videoStatus" }] : /* istanbul ignore next */ []));
578
- const isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
579
- const error = signal(undefined, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
580
- const status = signal('idle', ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
581
- const runId = signal(null, ...(ngDevMode ? [{ debugName: "runId" }] : /* istanbul ignore next */ []));
582
- let disposed = false;
583
- const bodySource = options.body !== undefined ? toReactive(options.body) : undefined;
584
- const baseOptions = {
585
- ...(bodySource !== undefined && { body: bodySource() }),
586
- persistence: options.persistence,
587
- threadId: options.threadId,
588
- ...(options.hydrateGeneration !== undefined && {
589
- hydrateGeneration: options.hydrateGeneration,
590
- }),
591
- ...(options.joinRun !== undefined && { joinRun: options.joinRun }),
592
- ...(options.byok !== undefined && { byok: options.byok }),
593
- byokProvider: () => options.byokProvider?.(),
594
- devtoolsBridgeFactory: createVideoDevtoolsBridge,
595
- devtools: {
596
- ...options.devtools,
597
- framework: 'angular',
598
- hookName: 'injectGenerateVideo',
599
- outputKind: 'video',
600
- },
601
- // The transform's raw return type (`TTransformed`) and the stored output
602
- // (`TOutput`, with null/void/undefined stripped) are identical at runtime;
603
- // the cast bridges the relationship that the conditional type hides.
604
- onResult: ((r) => options.onResult?.(r)),
605
- onError: (e) => {
606
- if (!disposed)
607
- options.onError?.(e);
608
- },
609
- onProgress: (p, m) => {
610
- if (!disposed)
611
- options.onProgress?.(p, m);
612
- },
613
- onChunk: (c) => {
614
- if (!disposed)
615
- options.onChunk?.(c);
616
- },
617
- onJobCreated: (id) => {
618
- if (!disposed)
619
- options.onJobCreated?.(id);
620
- },
621
- onStatusUpdate: (s) => {
622
- if (!disposed)
623
- options.onStatusUpdate?.(s);
624
- },
625
- };
626
- let client;
627
- if (options.connection) {
628
- client = new VideoGenerationClient({
629
- ...baseOptions,
630
- connection: options.connection,
631
- });
632
- }
633
- else if (options.fetcher) {
634
- client = new VideoGenerationClient({
635
- ...baseOptions,
636
- fetcher: options.fetcher,
637
- });
638
- }
639
- else {
640
- throw new Error('injectGenerateVideo requires either a connection or fetcher option');
641
- }
642
- const applySnapshot = () => {
643
- const next = client.getSnapshot();
644
- result.set(next.result);
645
- isLoading.set(next.isLoading);
646
- error.set(next.error);
647
- status.set(next.status);
648
- runId.set(next.runId);
649
- jobId.set(next.jobId);
650
- videoStatus.set(next.videoStatus);
651
- };
652
- applySnapshot();
653
- const unsubscribeSnapshot = client.subscribe(applySnapshot);
654
- if (bodySource) {
655
- effect(() => {
656
- client.updateOptions({
657
- body: bodySource(),
658
- });
659
- }, { injector });
660
- }
661
- // Mount devtools only. Generation runs are never auto-started after render —
662
- // persisted state is read-only for display.
663
- afterNextRender(() => {
664
- client.mountDevtools();
665
- }, { injector });
666
- destroyRef.onDestroy(() => {
667
- disposed = true;
668
- unsubscribeSnapshot();
669
- client.dispose();
670
- });
671
- return {
672
- generate: (input) => client.generate(input),
673
- result: result.asReadonly(),
674
- jobId: jobId.asReadonly(),
675
- videoStatus: videoStatus.asReadonly(),
676
- isLoading: isLoading.asReadonly(),
677
- error: error.asReadonly(),
678
- status: status.asReadonly(),
679
- stop: () => client.stop(),
680
- reset: () => client.reset(),
681
- runId: runId.asReadonly(),
682
- };
380
+ assertInInjectionContext(injectGenerateVideo);
381
+ const destroyRef = inject(DestroyRef);
382
+ const injector = inject(Injector);
383
+ const result = signal(null, ...ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []);
384
+ const jobId = signal(null, ...ngDevMode ? [{ debugName: "jobId" }] : /* istanbul ignore next */ []);
385
+ const videoStatus = signal(null, ...ngDevMode ? [{ debugName: "videoStatus" }] : /* istanbul ignore next */ []);
386
+ const isLoading = signal(false, ...ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []);
387
+ const error = signal(void 0, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
388
+ const status = signal("idle", ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
389
+ const runId = signal(null, ...ngDevMode ? [{ debugName: "runId" }] : /* istanbul ignore next */ []);
390
+ let disposed = false;
391
+ const bodySource = options.body !== void 0 ? toReactive(options.body) : void 0;
392
+ const baseOptions = {
393
+ ...bodySource !== void 0 && { body: bodySource() },
394
+ persistence: options.persistence,
395
+ threadId: options.threadId,
396
+ ...options.hydrateGeneration !== void 0 && { hydrateGeneration: options.hydrateGeneration },
397
+ ...options.joinRun !== void 0 && { joinRun: options.joinRun },
398
+ ...options.byok !== void 0 && { byok: options.byok },
399
+ byokProvider: () => options.byokProvider?.(),
400
+ devtoolsBridgeFactory: createVideoDevtoolsBridge,
401
+ devtools: {
402
+ ...options.devtools,
403
+ framework: "angular",
404
+ hookName: "injectGenerateVideo",
405
+ outputKind: "video"
406
+ },
407
+ onResult: ((r) => options.onResult?.(r)),
408
+ onError: (e) => {
409
+ if (!disposed) options.onError?.(e);
410
+ },
411
+ onProgress: (p, m) => {
412
+ if (!disposed) options.onProgress?.(p, m);
413
+ },
414
+ onChunk: (c) => {
415
+ if (!disposed) options.onChunk?.(c);
416
+ },
417
+ onJobCreated: (id) => {
418
+ if (!disposed) options.onJobCreated?.(id);
419
+ },
420
+ onStatusUpdate: (s) => {
421
+ if (!disposed) options.onStatusUpdate?.(s);
422
+ }
423
+ };
424
+ let client;
425
+ if (options.connection) client = new VideoGenerationClient$1({
426
+ ...baseOptions,
427
+ connection: options.connection
428
+ });
429
+ else if (options.fetcher) client = new VideoGenerationClient$1({
430
+ ...baseOptions,
431
+ fetcher: options.fetcher
432
+ });
433
+ else throw new Error("injectGenerateVideo requires either a connection or fetcher option");
434
+ const applySnapshot = () => {
435
+ const next = client.getSnapshot();
436
+ result.set(next.result);
437
+ isLoading.set(next.isLoading);
438
+ error.set(next.error);
439
+ status.set(next.status);
440
+ runId.set(next.runId);
441
+ jobId.set(next.jobId);
442
+ videoStatus.set(next.videoStatus);
443
+ };
444
+ applySnapshot();
445
+ const unsubscribeSnapshot = client.subscribe(applySnapshot);
446
+ if (bodySource) effect(() => {
447
+ client.updateOptions({ body: bodySource() });
448
+ }, { injector });
449
+ afterNextRender(() => {
450
+ client.mountDevtools();
451
+ }, { injector });
452
+ destroyRef.onDestroy(() => {
453
+ disposed = true;
454
+ unsubscribeSnapshot();
455
+ client.dispose();
456
+ });
457
+ return {
458
+ generate: (input) => client.generate(input),
459
+ result: result.asReadonly(),
460
+ jobId: jobId.asReadonly(),
461
+ videoStatus: videoStatus.asReadonly(),
462
+ isLoading: isLoading.asReadonly(),
463
+ error: error.asReadonly(),
464
+ status: status.asReadonly(),
465
+ stop: () => client.stop(),
466
+ reset: () => client.reset(),
467
+ runId: runId.asReadonly()
468
+ };
683
469
  }
470
+ export { AudioRecorder, BatchStrategy, ChatClient, CompositeStrategy, DurableStreamIncompleteError, GENERATION_EVENTS, GenerationClient, ImmediateStrategy, InterruptManager, PartialJSONParser, PunctuationStrategy, RealtimeClient, StorageUnavailableError, StreamProcessor, StreamReconnectLimitError, StreamTruncatedError, UnsupportedResponseStreamError, VideoGenerationClient, WordBoundaryStrategy, clientTools, convertMessagesToModelMessages, createAIDevtoolsGenerationPreview, createChatClientOptions, createMcpAppBridge, defaultJSONParser, fetchHttpStream, fetchJson, fetchServerSentEvents, generateMessageId, getWebMCPTools, indexedDBPersistence, injectAudioRecorder, injectByok, injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectPageWebMCPTools, injectRegisterWebMCPTools, injectSummarize, injectTranscription, localStoragePersistence, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, reconstructAudioResult, reconstructImageResult, reconstructSpeechResult, reconstructSummarizeResult, reconstructTranscriptionResult, registerWebMCPTools, rpcStream, sessionStoragePersistence, stream, subscribeWebMCPTools, uiMessageToModelMessages, webSocket, xhrHttpStream, xhrServerSentEvents };
684
471
 
685
- // Chat
686
-
687
- /**
688
- * Generated bundle index. Do not edit.
689
- */
690
-
691
- export { injectAudioRecorder, injectByok, injectChat, injectGenerateAudio, injectGenerateImage, injectGenerateSpeech, injectGenerateVideo, injectGeneration, injectPageWebMCPTools, injectRegisterWebMCPTools, injectSummarize, injectTranscription };
692
- //# sourceMappingURL=tanstack-ai-angular.mjs.map
472
+ //# sourceMappingURL=tanstack-ai-angular.mjs.map