@tanstack/ai-angular 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/dist/README.md +11 -10
- package/dist/fesm2022/tanstack-ai-angular-byok.mjs +1 -6
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs +578 -326
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs.map +1 -1
- package/dist/fesm2022/tanstack-ai-angular.mjs +457 -665
- package/dist/fesm2022/tanstack-ai-angular.mjs.map +1 -1
- package/dist/types/tanstack-ai-angular-byok.d.ts +2 -1
- package/dist/types/tanstack-ai-angular-ui.d.ts +80 -95
- package/dist/types/tanstack-ai-angular.d.ts +414 -380
- package/package.json +17 -16
- package/src/index.ts +8 -0
- package/src/inject-generate-3d-model.ts +92 -0
- package/dist/fesm2022/tanstack-ai-angular-byok.mjs.map +0 -1
|
@@ -1,692 +1,484 @@
|
|
|
1
|
-
import { ChatClient,
|
|
2
|
-
|
|
3
|
-
import {
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function injectGenerate3DModel(options) {
|
|
295
|
+
const devtools = {
|
|
296
|
+
...options.devtools,
|
|
297
|
+
framework: "angular",
|
|
298
|
+
hookName: "injectGenerate3DModel"
|
|
299
|
+
};
|
|
300
|
+
return injectGeneration({
|
|
301
|
+
...options,
|
|
302
|
+
devtools,
|
|
303
|
+
persistence: false
|
|
304
|
+
});
|
|
438
305
|
}
|
|
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
306
|
function injectGenerateAudio(options) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
return generation;
|
|
307
|
+
const devtools = {
|
|
308
|
+
...options.devtools,
|
|
309
|
+
framework: "angular",
|
|
310
|
+
hookName: "injectGenerateAudio",
|
|
311
|
+
outputKind: "audio"
|
|
312
|
+
};
|
|
313
|
+
return injectGeneration({
|
|
314
|
+
...options,
|
|
315
|
+
devtools,
|
|
316
|
+
reconstructResult: reconstructAudioResult$1
|
|
317
|
+
});
|
|
485
318
|
}
|
|
486
|
-
|
|
487
319
|
function injectGenerateSpeech(options) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return generation;
|
|
320
|
+
const devtools = {
|
|
321
|
+
...options.devtools,
|
|
322
|
+
framework: "angular",
|
|
323
|
+
hookName: "injectGenerateSpeech",
|
|
324
|
+
outputKind: "audio"
|
|
325
|
+
};
|
|
326
|
+
return injectGeneration({
|
|
327
|
+
...options,
|
|
328
|
+
devtools,
|
|
329
|
+
reconstructResult: reconstructSpeechResult$1
|
|
330
|
+
});
|
|
500
331
|
}
|
|
501
|
-
|
|
502
332
|
function injectTranscription(options) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
return generation;
|
|
333
|
+
const devtools = {
|
|
334
|
+
...options.devtools,
|
|
335
|
+
framework: "angular",
|
|
336
|
+
hookName: "injectTranscription",
|
|
337
|
+
outputKind: "text"
|
|
338
|
+
};
|
|
339
|
+
return injectGeneration({
|
|
340
|
+
...options,
|
|
341
|
+
devtools,
|
|
342
|
+
reconstructResult: reconstructTranscriptionResult$1
|
|
343
|
+
});
|
|
515
344
|
}
|
|
516
|
-
|
|
517
345
|
function injectAudioRecorder(options = {}) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
cancel: () => recorder.cancel(),
|
|
550
|
-
};
|
|
346
|
+
assertInInjectionContext(injectAudioRecorder);
|
|
347
|
+
const destroyRef = inject(DestroyRef);
|
|
348
|
+
const recorder = new AudioRecorder$1({
|
|
349
|
+
...options.audio !== void 0 && { audio: options.audio },
|
|
350
|
+
...options.mimeType !== void 0 && { mimeType: options.mimeType },
|
|
351
|
+
...options.onError !== void 0 && { onError: options.onError }
|
|
352
|
+
});
|
|
353
|
+
const isRecording = signal(false, ...ngDevMode ? [{ debugName: "isRecording" }] : /* istanbul ignore next */ []);
|
|
354
|
+
const recording = signal(null, ...ngDevMode ? [{ debugName: "recording" }] : /* istanbul ignore next */ []);
|
|
355
|
+
const unsubscribe = recorder.subscribe((state) => {
|
|
356
|
+
isRecording.set(state === "recording");
|
|
357
|
+
});
|
|
358
|
+
destroyRef.onDestroy(() => {
|
|
359
|
+
unsubscribe();
|
|
360
|
+
recorder.cancel();
|
|
361
|
+
});
|
|
362
|
+
const stop = async () => {
|
|
363
|
+
const rawRecording = await recorder.stop();
|
|
364
|
+
const transformed = await options.onComplete?.(rawRecording);
|
|
365
|
+
const output = transformed === void 0 ? rawRecording : transformed;
|
|
366
|
+
recording.set(output);
|
|
367
|
+
return output;
|
|
368
|
+
};
|
|
369
|
+
return {
|
|
370
|
+
recording: recording.asReadonly(),
|
|
371
|
+
isRecording: isRecording.asReadonly(),
|
|
372
|
+
isSupported: AudioRecorder$1.isSupported(),
|
|
373
|
+
start: () => recorder.start(),
|
|
374
|
+
stop,
|
|
375
|
+
cancel: () => recorder.cancel()
|
|
376
|
+
};
|
|
551
377
|
}
|
|
552
|
-
|
|
553
378
|
function injectSummarize(options) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return generation;
|
|
379
|
+
const devtools = {
|
|
380
|
+
...options.devtools,
|
|
381
|
+
framework: "angular",
|
|
382
|
+
hookName: "injectSummarize",
|
|
383
|
+
outputKind: "text"
|
|
384
|
+
};
|
|
385
|
+
return injectGeneration({
|
|
386
|
+
...options,
|
|
387
|
+
devtools,
|
|
388
|
+
reconstructResult: reconstructSummarizeResult$1
|
|
389
|
+
});
|
|
566
390
|
}
|
|
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
391
|
function injectGenerateVideo(options) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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
|
-
};
|
|
392
|
+
assertInInjectionContext(injectGenerateVideo);
|
|
393
|
+
const destroyRef = inject(DestroyRef);
|
|
394
|
+
const injector = inject(Injector);
|
|
395
|
+
const result = signal(null, ...ngDevMode ? [{ debugName: "result" }] : /* istanbul ignore next */ []);
|
|
396
|
+
const jobId = signal(null, ...ngDevMode ? [{ debugName: "jobId" }] : /* istanbul ignore next */ []);
|
|
397
|
+
const videoStatus = signal(null, ...ngDevMode ? [{ debugName: "videoStatus" }] : /* istanbul ignore next */ []);
|
|
398
|
+
const isLoading = signal(false, ...ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []);
|
|
399
|
+
const error = signal(void 0, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
|
|
400
|
+
const status = signal("idle", ...ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []);
|
|
401
|
+
const runId = signal(null, ...ngDevMode ? [{ debugName: "runId" }] : /* istanbul ignore next */ []);
|
|
402
|
+
let disposed = false;
|
|
403
|
+
const bodySource = options.body !== void 0 ? toReactive(options.body) : void 0;
|
|
404
|
+
const baseOptions = {
|
|
405
|
+
...bodySource !== void 0 && { body: bodySource() },
|
|
406
|
+
persistence: options.persistence,
|
|
407
|
+
threadId: options.threadId,
|
|
408
|
+
...options.hydrateGeneration !== void 0 && { hydrateGeneration: options.hydrateGeneration },
|
|
409
|
+
...options.joinRun !== void 0 && { joinRun: options.joinRun },
|
|
410
|
+
...options.byok !== void 0 && { byok: options.byok },
|
|
411
|
+
byokProvider: () => options.byokProvider?.(),
|
|
412
|
+
devtoolsBridgeFactory: createVideoDevtoolsBridge,
|
|
413
|
+
devtools: {
|
|
414
|
+
...options.devtools,
|
|
415
|
+
framework: "angular",
|
|
416
|
+
hookName: "injectGenerateVideo",
|
|
417
|
+
outputKind: "video"
|
|
418
|
+
},
|
|
419
|
+
onResult: ((r) => options.onResult?.(r)),
|
|
420
|
+
onError: (e) => {
|
|
421
|
+
if (!disposed) options.onError?.(e);
|
|
422
|
+
},
|
|
423
|
+
onProgress: (p, m) => {
|
|
424
|
+
if (!disposed) options.onProgress?.(p, m);
|
|
425
|
+
},
|
|
426
|
+
onChunk: (c) => {
|
|
427
|
+
if (!disposed) options.onChunk?.(c);
|
|
428
|
+
},
|
|
429
|
+
onJobCreated: (id) => {
|
|
430
|
+
if (!disposed) options.onJobCreated?.(id);
|
|
431
|
+
},
|
|
432
|
+
onStatusUpdate: (s) => {
|
|
433
|
+
if (!disposed) options.onStatusUpdate?.(s);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
let client;
|
|
437
|
+
if (options.connection) client = new VideoGenerationClient$1({
|
|
438
|
+
...baseOptions,
|
|
439
|
+
connection: options.connection
|
|
440
|
+
});
|
|
441
|
+
else if (options.fetcher) client = new VideoGenerationClient$1({
|
|
442
|
+
...baseOptions,
|
|
443
|
+
fetcher: options.fetcher
|
|
444
|
+
});
|
|
445
|
+
else throw new Error("injectGenerateVideo requires either a connection or fetcher option");
|
|
446
|
+
const applySnapshot = () => {
|
|
447
|
+
const next = client.getSnapshot();
|
|
448
|
+
result.set(next.result);
|
|
449
|
+
isLoading.set(next.isLoading);
|
|
450
|
+
error.set(next.error);
|
|
451
|
+
status.set(next.status);
|
|
452
|
+
runId.set(next.runId);
|
|
453
|
+
jobId.set(next.jobId);
|
|
454
|
+
videoStatus.set(next.videoStatus);
|
|
455
|
+
};
|
|
456
|
+
applySnapshot();
|
|
457
|
+
const unsubscribeSnapshot = client.subscribe(applySnapshot);
|
|
458
|
+
if (bodySource) effect(() => {
|
|
459
|
+
client.updateOptions({ body: bodySource() });
|
|
460
|
+
}, { injector });
|
|
461
|
+
afterNextRender(() => {
|
|
462
|
+
client.mountDevtools();
|
|
463
|
+
}, { injector });
|
|
464
|
+
destroyRef.onDestroy(() => {
|
|
465
|
+
disposed = true;
|
|
466
|
+
unsubscribeSnapshot();
|
|
467
|
+
client.dispose();
|
|
468
|
+
});
|
|
469
|
+
return {
|
|
470
|
+
generate: (input) => client.generate(input),
|
|
471
|
+
result: result.asReadonly(),
|
|
472
|
+
jobId: jobId.asReadonly(),
|
|
473
|
+
videoStatus: videoStatus.asReadonly(),
|
|
474
|
+
isLoading: isLoading.asReadonly(),
|
|
475
|
+
error: error.asReadonly(),
|
|
476
|
+
status: status.asReadonly(),
|
|
477
|
+
stop: () => client.stop(),
|
|
478
|
+
reset: () => client.reset(),
|
|
479
|
+
runId: runId.asReadonly()
|
|
480
|
+
};
|
|
683
481
|
}
|
|
482
|
+
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, injectGenerate3DModel, 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
483
|
|
|
685
|
-
|
|
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
|
|
484
|
+
//# sourceMappingURL=tanstack-ai-angular.mjs.map
|