@tanstack/ai-angular 0.7.4 → 0.8.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.
@@ -0,0 +1,408 @@
1
+ import * as i0 from '@angular/core';
2
+ import { signal, InjectionToken, inject, ChangeDetectionStrategy, Component, computed, Injector, input, effect, untracked, assertInInjectionContext } from '@angular/core';
3
+ import { NgComponentOutlet } from '@angular/common';
4
+ import { collectInlineToolNames, automaticPartsForMessage, selectMessageUI, selectChatUI, resolveInterruptComponent } from '@tanstack/ai-client/ui';
5
+ import { injectChat } from '@tanstack/ai-angular';
6
+
7
+ /**
8
+ * Holder for the active chat instance. Factory components inject this
9
+ * and read `host()`.
10
+ */
11
+ class ChatHostRef {
12
+ host = signal(null, ...(ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []));
13
+ }
14
+ /**
15
+ * Create isolated tokens for nested chat trees, or for widgets in other
16
+ * files that cannot import the `createChatHook` result.
17
+ */
18
+ function createChatHookContexts() {
19
+ const chatRef = new InjectionToken('ChatUIHostRef');
20
+ const part = new InjectionToken('ChatUIPart');
21
+ const interrupt = new InjectionToken('ChatUIInterrupt');
22
+ function injectChatContext() {
23
+ const ref = inject(chatRef);
24
+ const chat = ref.host();
25
+ if (!chat) {
26
+ throw new Error('`injectChatContext` must be used within `Chat` or `ChatProvider`.');
27
+ }
28
+ return chat;
29
+ }
30
+ return { chatRef, part, interrupt, injectChatContext };
31
+ }
32
+ const defaultChatUITokens = createChatHookContexts();
33
+
34
+ function createWarnOnce() {
35
+ const seen = new Set();
36
+ return (key, message) => {
37
+ if (process.env.NODE_ENV === 'production')
38
+ return;
39
+ if (seen.has(key))
40
+ return;
41
+ seen.add(key);
42
+ console.warn(message);
43
+ };
44
+ }
45
+ /**
46
+ * Bind chat options and Angular widgets once at module scope.
47
+ *
48
+ * Layout, message, input, queue, parts, tools, and interrupts are
49
+ * standalone component classes. The factory builds `Chat`, `Messages`,
50
+ * `Interrupts`, and `Queue` as Angular components that inject the active
51
+ * chat through DI.
52
+ */
53
+ function createChatUI(options, config) {
54
+ void options;
55
+ const { context: contextOption, components, partsComponents: parts, toolsComponents: tools, interruptsComponents: interrupts, } = config;
56
+ const { layout: Layout, message: MessageComponent, input: InputComponent, queue: QueueItemComponent, } = components;
57
+ const warn = createWarnOnce();
58
+ const tokens = {
59
+ chatRef: contextOption?.chatRef ?? defaultChatUITokens.chatRef,
60
+ part: contextOption?.part ?? defaultChatUITokens.part,
61
+ interrupt: contextOption?.interrupt ?? defaultChatUITokens.interrupt,
62
+ };
63
+ const inlineToolNames = collectInlineToolNames(interrupts?.tools, Object.keys(tools ?? {}));
64
+ function injectChatContext() {
65
+ const ref = inject(tokens.chatRef);
66
+ const chat = ref.host();
67
+ if (!chat) {
68
+ throw new Error('`injectChatContext` must be used within `Chat` or `ChatProvider`.');
69
+ }
70
+ return chat;
71
+ }
72
+ class MissingInput {
73
+ constructor() {
74
+ warn('input', '[tanstack-ai-ui] Rendered Input but no `input` component is registered.');
75
+ }
76
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MissingInput, deps: [], target: i0.ɵɵFactoryTarget.Component });
77
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.20", type: MissingInput, isStandalone: true, selector: "ai-chat-missing-input", ngImport: i0, template: '', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
78
+ }
79
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: MissingInput, decorators: [{
80
+ type: Component,
81
+ args: [{
82
+ selector: 'ai-chat-missing-input',
83
+ changeDetection: ChangeDetectionStrategy.OnPush,
84
+ template: '',
85
+ }]
86
+ }], ctorParameters: () => [] });
87
+ class Queue {
88
+ ref = inject(tokens.chatRef);
89
+ itemComponent = QueueItemComponent;
90
+ rows = computed(() => {
91
+ const chat = this.ref.host();
92
+ if (!chat || !QueueItemComponent)
93
+ return [];
94
+ const items = chat.queue();
95
+ return items.map((item) => ({
96
+ item: {
97
+ ...item,
98
+ cancelQueued: () => {
99
+ chat.cancelQueued(item.id);
100
+ },
101
+ },
102
+ }));
103
+ }, ...(ngDevMode ? [{ debugName: "rows" }] : /* istanbul ignore next */ []));
104
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Queue, deps: [], target: i0.ɵɵFactoryTarget.Component });
105
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.20", type: Queue, isStandalone: true, selector: "ai-chat-queue", ngImport: i0, template: `
106
+ @if (itemComponent) {
107
+ @for (row of rows(); track row.item.id) {
108
+ <ng-container
109
+ [ngComponentOutlet]="itemComponent"
110
+ [ngComponentOutletInputs]="{ item: row.item }"
111
+ />
112
+ }
113
+ }
114
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
115
+ }
116
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Queue, decorators: [{
117
+ type: Component,
118
+ args: [{
119
+ selector: 'ai-chat-queue',
120
+ changeDetection: ChangeDetectionStrategy.OnPush,
121
+ imports: [NgComponentOutlet],
122
+ template: `
123
+ @if (itemComponent) {
124
+ @for (row of rows(); track row.item.id) {
125
+ <ng-container
126
+ [ngComponentOutlet]="itemComponent"
127
+ [ngComponentOutletInputs]="{ item: row.item }"
128
+ />
129
+ }
130
+ }
131
+ `,
132
+ }]
133
+ }] });
134
+ class Parts {
135
+ injector = inject(Injector);
136
+ ref = inject(tokens.chatRef);
137
+ message = input.required(...(ngDevMode ? [{ debugName: "message" }] : /* istanbul ignore next */ []));
138
+ selectedParts = computed(() => {
139
+ const chat = this.ref.host();
140
+ return automaticPartsForMessage(selectMessageUI(this.message(), {
141
+ interrupts: (chat?.interrupts() ??
142
+ []),
143
+ inlineToolNames,
144
+ }));
145
+ }, ...(ngDevMode ? [{ debugName: "selectedParts" }] : /* istanbul ignore next */ []));
146
+ outletFor(selected) {
147
+ if (selected.key === 'toolCall') {
148
+ const name = selected.part.name;
149
+ const Tool = tools?.[name];
150
+ if (!Tool) {
151
+ warn(`tool:${name}`, `[tanstack-ai-ui] Missing tools.${name} component`);
152
+ return null;
153
+ }
154
+ return Tool;
155
+ }
156
+ const PartComponent = (parts[selected.key] ?? parts.fallback);
157
+ if (!PartComponent) {
158
+ warn(`part:${selected.key}`, `[tanstack-ai-ui] Missing parts.${selected.key} component`);
159
+ return null;
160
+ }
161
+ return PartComponent;
162
+ }
163
+ inputsFor(selected) {
164
+ if (selected.key === 'toolCall') {
165
+ return {
166
+ part: selected.part,
167
+ result: selected.result,
168
+ interrupt: selected.interrupt,
169
+ };
170
+ }
171
+ return { part: selected.part };
172
+ }
173
+ injectorFor(selected) {
174
+ return Injector.create({
175
+ parent: this.injector,
176
+ providers: [{ provide: tokens.part, useValue: selected }],
177
+ });
178
+ }
179
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Parts, deps: [], target: i0.ɵɵFactoryTarget.Component });
180
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.20", type: Parts, isStandalone: true, selector: "ai-chat-parts", inputs: { message: { classPropertyName: "message", publicName: "message", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `
181
+ @for (selected of selectedParts(); track $index) {
182
+ <ng-container
183
+ [ngComponentOutlet]="outletFor(selected)"
184
+ [ngComponentOutletInputs]="inputsFor(selected)"
185
+ [ngComponentOutletInjector]="injectorFor(selected)"
186
+ />
187
+ }
188
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
189
+ }
190
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Parts, decorators: [{
191
+ type: Component,
192
+ args: [{
193
+ selector: 'ai-chat-parts',
194
+ changeDetection: ChangeDetectionStrategy.OnPush,
195
+ imports: [NgComponentOutlet],
196
+ template: `
197
+ @for (selected of selectedParts(); track $index) {
198
+ <ng-container
199
+ [ngComponentOutlet]="outletFor(selected)"
200
+ [ngComponentOutletInputs]="inputsFor(selected)"
201
+ [ngComponentOutletInjector]="injectorFor(selected)"
202
+ />
203
+ }
204
+ `,
205
+ }]
206
+ }], propDecorators: { message: [{ type: i0.Input, args: [{ isSignal: true, alias: "message", required: true }] }] } });
207
+ class Messages {
208
+ ref = inject(tokens.chatRef);
209
+ messageComponent = MessageComponent;
210
+ Parts = Parts;
211
+ messages = computed(() => {
212
+ const chat = this.ref.host();
213
+ return (chat?.messages() ?? []);
214
+ }, ...(ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []));
215
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Messages, deps: [], target: i0.ɵɵFactoryTarget.Component });
216
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.20", type: Messages, isStandalone: true, selector: "ai-chat-messages", ngImport: i0, template: `
217
+ @for (message of messages(); track message.id) {
218
+ <ng-container
219
+ [ngComponentOutlet]="messageComponent"
220
+ [ngComponentOutletInputs]="{
221
+ message,
222
+ Parts,
223
+ }"
224
+ />
225
+ }
226
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
227
+ }
228
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Messages, decorators: [{
229
+ type: Component,
230
+ args: [{
231
+ selector: 'ai-chat-messages',
232
+ changeDetection: ChangeDetectionStrategy.OnPush,
233
+ imports: [NgComponentOutlet],
234
+ template: `
235
+ @for (message of messages(); track message.id) {
236
+ <ng-container
237
+ [ngComponentOutlet]="messageComponent"
238
+ [ngComponentOutletInputs]="{
239
+ message,
240
+ Parts,
241
+ }"
242
+ />
243
+ }
244
+ `,
245
+ }]
246
+ }] });
247
+ class Interrupts {
248
+ injector = inject(Injector);
249
+ ref = inject(tokens.chatRef);
250
+ interrupts = computed(() => {
251
+ const chat = this.ref.host();
252
+ const selected = selectChatUI({
253
+ messages: (chat?.messages() ?? []),
254
+ interrupts: (chat?.interrupts() ??
255
+ []),
256
+ inlineToolNames,
257
+ });
258
+ return selected.interrupts;
259
+ }, ...(ngDevMode ? [{ debugName: "interrupts" }] : /* istanbul ignore next */ []));
260
+ outletFor(interrupt) {
261
+ const InterruptComponent = resolveInterruptComponent(interrupt, interrupts);
262
+ if (!InterruptComponent) {
263
+ warn(`interrupt:${interrupt.id}`, `[tanstack-ai-ui] Missing interrupt component for ${interrupt.kind}`);
264
+ return null;
265
+ }
266
+ return InterruptComponent;
267
+ }
268
+ injectorFor(interrupt) {
269
+ return Injector.create({
270
+ parent: this.injector,
271
+ providers: [{ provide: tokens.interrupt, useValue: interrupt }],
272
+ });
273
+ }
274
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Interrupts, deps: [], target: i0.ɵɵFactoryTarget.Component });
275
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.20", type: Interrupts, isStandalone: true, selector: "ai-chat-interrupts", ngImport: i0, template: `
276
+ @for (interrupt of interrupts(); track interrupt.id) {
277
+ <ng-container
278
+ [ngComponentOutlet]="outletFor(interrupt)"
279
+ [ngComponentOutletInputs]="{ interrupt }"
280
+ [ngComponentOutletInjector]="injectorFor(interrupt)"
281
+ />
282
+ }
283
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
284
+ }
285
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Interrupts, decorators: [{
286
+ type: Component,
287
+ args: [{
288
+ selector: 'ai-chat-interrupts',
289
+ changeDetection: ChangeDetectionStrategy.OnPush,
290
+ imports: [NgComponentOutlet],
291
+ template: `
292
+ @for (interrupt of interrupts(); track interrupt.id) {
293
+ <ng-container
294
+ [ngComponentOutlet]="outletFor(interrupt)"
295
+ [ngComponentOutletInputs]="{ interrupt }"
296
+ [ngComponentOutletInjector]="injectorFor(interrupt)"
297
+ />
298
+ }
299
+ `,
300
+ }]
301
+ }] });
302
+ const layoutInputs = {
303
+ Messages,
304
+ Interrupts,
305
+ Queue,
306
+ Input: (InputComponent ?? MissingInput),
307
+ };
308
+ class Chat {
309
+ chat = input.required(...(ngDevMode ? [{ debugName: "chat" }] : /* istanbul ignore next */ []));
310
+ layout = Layout;
311
+ layoutInputs = layoutInputs;
312
+ ref = inject(tokens.chatRef);
313
+ constructor() {
314
+ effect(() => {
315
+ const next = this.chat();
316
+ untracked(() => this.ref.host.set(next));
317
+ });
318
+ }
319
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Chat, deps: [], target: i0.ɵɵFactoryTarget.Component });
320
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.20", type: Chat, isStandalone: true, selector: "ai-chat", inputs: { chat: { classPropertyName: "chat", publicName: "chat", isSignal: true, isRequired: true, transformFunction: null } }, providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }], ngImport: i0, template: `
321
+ <ng-container
322
+ [ngComponentOutlet]="layout"
323
+ [ngComponentOutletInputs]="layoutInputs"
324
+ />
325
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
326
+ }
327
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: Chat, decorators: [{
328
+ type: Component,
329
+ args: [{
330
+ selector: 'ai-chat',
331
+ changeDetection: ChangeDetectionStrategy.OnPush,
332
+ imports: [NgComponentOutlet],
333
+ providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }],
334
+ template: `
335
+ <ng-container
336
+ [ngComponentOutlet]="layout"
337
+ [ngComponentOutletInputs]="layoutInputs"
338
+ />
339
+ `,
340
+ }]
341
+ }], ctorParameters: () => [], propDecorators: { chat: [{ type: i0.Input, args: [{ isSignal: true, alias: "chat", required: true }] }] } });
342
+ class ChatProvider {
343
+ chat = input.required(...(ngDevMode ? [{ debugName: "chat" }] : /* istanbul ignore next */ []));
344
+ ref = inject(tokens.chatRef);
345
+ constructor() {
346
+ effect(() => {
347
+ const next = this.chat();
348
+ untracked(() => this.ref.host.set(next));
349
+ });
350
+ }
351
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ChatProvider, deps: [], target: i0.ɵɵFactoryTarget.Component });
352
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.20", type: ChatProvider, isStandalone: true, selector: "ai-chat-provider", inputs: { chat: { classPropertyName: "chat", publicName: "chat", isSignal: true, isRequired: true, transformFunction: null } }, providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }], ngImport: i0, template: `<ng-content />`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
353
+ }
354
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.20", ngImport: i0, type: ChatProvider, decorators: [{
355
+ type: Component,
356
+ args: [{
357
+ selector: 'ai-chat-provider',
358
+ changeDetection: ChangeDetectionStrategy.OnPush,
359
+ providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }],
360
+ template: `<ng-content />`,
361
+ }]
362
+ }], ctorParameters: () => [], propDecorators: { chat: [{ type: i0.Input, args: [{ isSignal: true, alias: "chat", required: true }] }] } });
363
+ return {
364
+ Chat,
365
+ ChatProvider,
366
+ Messages,
367
+ Interrupts,
368
+ Queue,
369
+ Parts,
370
+ injectChatContext,
371
+ Input: InputComponent,
372
+ };
373
+ }
374
+
375
+ /**
376
+ * Bind chat options and Angular widgets once at module scope.
377
+ *
378
+ * This matches Form `injectForm` and the React `createChatHook` factory:
379
+ * widgets register here. The returned `injectAppChat` creates a chat
380
+ * instance in an injection context. Render `<ai-chat [chat]="chat" />`
381
+ * with the factory `Chat` component.
382
+ */
383
+ function createChatHook({ options, ...chatComponents }) {
384
+ const ui = createChatUI(options, chatComponents);
385
+ function injectAppChat(overrides) {
386
+ assertInInjectionContext(injectAppChat);
387
+ const chat = (overrides
388
+ ? injectChat({
389
+ ...options,
390
+ ...overrides,
391
+ })
392
+ : injectChat(options));
393
+ return chat;
394
+ }
395
+ return {
396
+ injectAppChat,
397
+ injectChatContext: ui.injectChatContext,
398
+ Chat: ui.Chat,
399
+ ChatProvider: ui.ChatProvider,
400
+ };
401
+ }
402
+
403
+ /**
404
+ * Generated bundle index. Do not edit.
405
+ */
406
+
407
+ export { ChatHostRef, createChatHook, createChatHookContexts, createChatUI };
408
+ //# sourceMappingURL=tanstack-ai-angular-ui.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack-ai-angular-ui.mjs","sources":["../../ui/src/tokens.ts","../../ui/src/create-ui.ts","../../ui/src/create-chat-hook.ts","../../ui/src/tanstack-ai-angular-ui.ts"],"sourcesContent":["import { InjectionToken, inject, signal } from '@angular/core'\nimport type { WritableSignal } from '@angular/core'\nimport type {\n ChatUIInterrupt,\n ChatUISelectedPart,\n} from '@tanstack/ai-client/ui'\nimport type { InjectChatResult } from '@tanstack/ai-angular'\n\n/**\n * Holder for the active chat instance. Factory components inject this\n * and read `host()`.\n */\nexport class ChatHostRef {\n readonly host: WritableSignal<InjectChatResult | null> = signal(null)\n}\n\nexport interface ChatUITokens {\n chatRef: InjectionToken<ChatHostRef>\n part: InjectionToken<ChatUISelectedPart>\n interrupt: InjectionToken<ChatUIInterrupt>\n injectChatContext: () => InjectChatResult\n}\n\n/**\n * Create isolated tokens for nested chat trees, or for widgets in other\n * files that cannot import the `createChatHook` result.\n */\nexport function createChatHookContexts(): ChatUITokens {\n const chatRef = new InjectionToken<ChatHostRef>('ChatUIHostRef')\n const part = new InjectionToken<ChatUISelectedPart>('ChatUIPart')\n const interrupt = new InjectionToken<ChatUIInterrupt>('ChatUIInterrupt')\n\n function injectChatContext() {\n const ref = inject(chatRef)\n const chat = ref.host()\n if (!chat) {\n throw new Error(\n '`injectChatContext` must be used within `Chat` or `ChatProvider`.',\n )\n }\n return chat\n }\n\n return { chatRef, part, interrupt, injectChatContext }\n}\n\nexport const defaultChatUITokens = createChatHookContexts()\n","import {\n ChangeDetectionStrategy,\n Component,\n Injector,\n computed,\n effect,\n inject,\n input,\n untracked,\n} from '@angular/core'\nimport { NgComponentOutlet } from '@angular/common'\nimport type { Type } from '@angular/core'\nimport {\n automaticPartsForMessage,\n collectInlineToolNames,\n resolveInterruptComponent,\n selectChatUI,\n selectMessageUI,\n} from '@tanstack/ai-client/ui'\nimport type {\n ChatUIHasNamedInterrupts,\n ChatUIHasNamedTools,\n ChatUIInterrupt,\n ChatUIInterruptName,\n ChatUIInterruptOf,\n ChatUIInterruptsOf,\n ChatUIMessages,\n ChatUINamedInterruptId,\n ChatUIPartKey,\n ChatUIPartOf,\n ChatUISchemaOf,\n ChatUISelectedPart,\n ChatUIToolApproval,\n ChatUIToolName,\n ChatUIToolsOf,\n} from '@tanstack/ai-client/ui'\nimport type {\n InferredClientContext,\n QueuedMessage,\n ToolCallPart,\n ToolResultPart,\n} from '@tanstack/ai-client'\nimport type { InjectChatResult } from '@tanstack/ai-angular'\nimport { ChatHostRef, defaultChatUITokens } from './tokens'\nimport type { ChatUITokens } from './tokens'\n\nexport type ChatUIHost<TOptions = unknown> = InjectChatResult<\n ChatUIToolsOf<TOptions>,\n ChatUISchemaOf<TOptions>,\n ChatUIInterruptsOf<TOptions>\n>\n\nexport type ChatUIQueueItem = QueuedMessage & {\n cancelQueued: () => void\n}\n\nexport type LayoutProps<\n TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown>,\n> = {\n Messages: Type<unknown>\n Interrupts: Type<unknown>\n Queue: Type<unknown>\n readonly __ui?: TOptions\n} & (TInput extends Type<unknown> ? { Input: Type<unknown> } : {})\n\nexport type MessageProps<TOptions> = {\n message: ChatUIMessages<TOptions>[number]\n Parts: Type<unknown>\n}\n\nexport type InputProps<TOptions> = {\n readonly __ui?: TOptions\n}\n\nexport type QueueProps<TOptions> = {\n item: ChatUIQueueItem\n readonly __ui?: TOptions\n}\n\nexport type PartProps<TOptions, TKey extends ChatUIPartKey = ChatUIPartKey> = {\n part: ChatUIPartOf<TOptions, TKey>\n}\n\nexport type ToolProps<\n TOptions,\n TName extends ChatUIToolName<TOptions> = ChatUIToolName<TOptions>,\n> = {\n part: Extract<ToolCallPart<ChatUIToolsOf<TOptions>>, { name: TName }>\n result?: ToolResultPart\n interrupt?: ChatUIToolApproval<TOptions, TName>\n}\n\nexport type InterruptProps<\n TOptions,\n TName extends ChatUIInterruptName<TOptions> = never,\n> = {\n interrupt: ChatUIInterruptOf<TOptions, TName>\n readonly __ui?: TOptions\n}\n\ntype GenericInterruptComponents<TOptions> =\n ChatUIHasNamedInterrupts<TOptions> extends true\n ? {\n [K in ChatUINamedInterruptId<TOptions>]: Type<unknown>\n } & {\n fallback?: Type<unknown>\n }\n : {\n fallback?: Type<unknown>\n }\n\ntype ToolApprovalMap<TOptions> = {\n [K in ChatUIToolName<TOptions>]?: Type<unknown>\n}\n\nexport type ChatUIChromeComponents<\n TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown>,\n> = {\n layout: Type<unknown>\n message: Type<unknown>\n input?: TInput\n queue?: Type<unknown>\n readonly __ui?: TOptions\n}\n\nexport type ChatUIPartsComponents<TOptions> = {\n [K in ChatUIPartKey]?: Type<unknown>\n} & {\n fallback?: Type<unknown>\n readonly __ui?: TOptions\n}\n\nexport type ChatUIInterruptsComponents<TOptions> = {\n tools?: ToolApprovalMap<TOptions>\n generic: GenericInterruptComponents<TOptions>\n}\n\nexport type ChatUIComponents<\n TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown>,\n> = {\n components: ChatUIChromeComponents<TOptions, TInput>\n partsComponents: ChatUIPartsComponents<TOptions>\n} & (ChatUIHasNamedTools<TOptions> extends true\n ? {\n toolsComponents: {\n [K in ChatUIToolName<TOptions>]: Type<unknown>\n }\n }\n : {\n toolsComponents?: {\n [K in ChatUIToolName<TOptions>]?: Type<unknown>\n }\n }) &\n (ChatUIHasNamedInterrupts<TOptions> extends true\n ? { interruptsComponents: ChatUIInterruptsComponents<TOptions> }\n : {\n interruptsComponents?: {\n tools?: ToolApprovalMap<TOptions>\n generic?: GenericInterruptComponents<TOptions>\n }\n })\n\nexport type ChatUIContextConfig = {\n chatRef?: ChatUITokens['chatRef']\n part?: ChatUITokens['part']\n interrupt?: ChatUITokens['interrupt']\n}\n\nexport type ChatUIFactoryConfig<\n TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown>,\n> = ChatUIComponents<TOptions, TInput> & {\n context?: ChatUIContextConfig\n}\n\nfunction createWarnOnce() {\n const seen = new Set<string>()\n return (key: string, message: string) => {\n if (process.env.NODE_ENV === 'production') return\n if (seen.has(key)) return\n seen.add(key)\n console.warn(message)\n }\n}\n\n/**\n * Bind chat options and Angular widgets once at module scope.\n *\n * Layout, message, input, queue, parts, tools, and interrupts are\n * standalone component classes. The factory builds `Chat`, `Messages`,\n * `Interrupts`, and `Queue` as Angular components that inject the active\n * chat through DI.\n */\nexport function createChatUI<\n const TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown> | undefined,\n>(options: TOptions, config: ChatUIFactoryConfig<NoInfer<TOptions>, TInput>) {\n void options\n const {\n context: contextOption,\n components,\n partsComponents: parts,\n toolsComponents: tools,\n interruptsComponents: interrupts,\n } = config as ChatUIFactoryConfig<TOptions, TInput> & {\n toolsComponents?: Record<string, Type<unknown> | undefined>\n interruptsComponents?: {\n tools?: Record<string, Type<unknown> | undefined>\n generic?: Record<string, Type<unknown> | undefined>\n }\n }\n const {\n layout: Layout,\n message: MessageComponent,\n input: InputComponent,\n queue: QueueItemComponent,\n } = components\n const warn = createWarnOnce()\n const tokens = {\n chatRef: contextOption?.chatRef ?? defaultChatUITokens.chatRef,\n part: contextOption?.part ?? defaultChatUITokens.part,\n interrupt: contextOption?.interrupt ?? defaultChatUITokens.interrupt,\n }\n const inlineToolNames = collectInlineToolNames(\n interrupts?.tools as Record<string, unknown> | undefined,\n Object.keys(tools ?? {}),\n )\n\n function injectChatContext() {\n const ref = inject(tokens.chatRef)\n const chat = ref.host()\n if (!chat) {\n throw new Error(\n '`injectChatContext` must be used within `Chat` or `ChatProvider`.',\n )\n }\n return chat as ChatUIHost<TOptions>\n }\n\n @Component({\n selector: 'ai-chat-missing-input',\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: '',\n })\n class MissingInput {\n constructor() {\n warn(\n 'input',\n '[tanstack-ai-ui] Rendered Input but no `input` component is registered.',\n )\n }\n }\n\n @Component({\n selector: 'ai-chat-queue',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [NgComponentOutlet],\n template: `\n @if (itemComponent) {\n @for (row of rows(); track row.item.id) {\n <ng-container\n [ngComponentOutlet]=\"itemComponent\"\n [ngComponentOutletInputs]=\"{ item: row.item }\"\n />\n }\n }\n `,\n })\n class Queue {\n readonly ref = inject(tokens.chatRef)\n readonly itemComponent = QueueItemComponent\n readonly rows = computed(() => {\n const chat = this.ref.host()\n if (!chat || !QueueItemComponent) return []\n const items = chat.queue()\n return items.map((item) => ({\n item: {\n ...item,\n cancelQueued: () => {\n chat.cancelQueued(item.id)\n },\n },\n }))\n })\n }\n\n @Component({\n selector: 'ai-chat-parts',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [NgComponentOutlet],\n template: `\n @for (selected of selectedParts(); track $index) {\n <ng-container\n [ngComponentOutlet]=\"outletFor(selected)\"\n [ngComponentOutletInputs]=\"inputsFor(selected)\"\n [ngComponentOutletInjector]=\"injectorFor(selected)\"\n />\n }\n `,\n })\n class Parts {\n readonly injector = inject(Injector)\n readonly ref = inject(tokens.chatRef)\n message = input.required<ChatUIMessages<TOptions>[number]>()\n\n readonly selectedParts = computed(() => {\n const chat = this.ref.host()\n return automaticPartsForMessage(\n selectMessageUI(this.message(), {\n interrupts: (chat?.interrupts() ??\n []) as ReadonlyArray<ChatUIInterrupt>,\n inlineToolNames,\n }),\n )\n })\n\n outletFor(selected: ChatUISelectedPart) {\n if (selected.key === 'toolCall') {\n const name = selected.part.name\n const Tool = tools?.[name as ChatUIToolName<TOptions>]\n if (!Tool) {\n warn(\n `tool:${name}`,\n `[tanstack-ai-ui] Missing tools.${name} component`,\n )\n return null\n }\n return Tool\n }\n const PartComponent = (parts[selected.key] ?? parts.fallback) as\n | Type<unknown>\n | undefined\n if (!PartComponent) {\n warn(\n `part:${selected.key}`,\n `[tanstack-ai-ui] Missing parts.${selected.key} component`,\n )\n return null\n }\n return PartComponent\n }\n\n inputsFor(selected: ChatUISelectedPart) {\n if (selected.key === 'toolCall') {\n return {\n part: selected.part,\n result: selected.result,\n interrupt: selected.interrupt,\n }\n }\n return { part: selected.part }\n }\n\n injectorFor(selected: ChatUISelectedPart) {\n return Injector.create({\n parent: this.injector,\n providers: [{ provide: tokens.part, useValue: selected }],\n })\n }\n }\n\n @Component({\n selector: 'ai-chat-messages',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [NgComponentOutlet],\n template: `\n @for (message of messages(); track message.id) {\n <ng-container\n [ngComponentOutlet]=\"messageComponent\"\n [ngComponentOutletInputs]=\"{\n message,\n Parts,\n }\"\n />\n }\n `,\n })\n class Messages {\n readonly ref = inject(tokens.chatRef)\n readonly messageComponent = MessageComponent\n readonly Parts = Parts\n readonly messages = computed(() => {\n const chat = this.ref.host()\n return (chat?.messages() ?? []) as ChatUIMessages<TOptions>\n })\n }\n\n @Component({\n selector: 'ai-chat-interrupts',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [NgComponentOutlet],\n template: `\n @for (interrupt of interrupts(); track interrupt.id) {\n <ng-container\n [ngComponentOutlet]=\"outletFor(interrupt)\"\n [ngComponentOutletInputs]=\"{ interrupt }\"\n [ngComponentOutletInjector]=\"injectorFor(interrupt)\"\n />\n }\n `,\n })\n class Interrupts {\n readonly injector = inject(Injector)\n readonly ref = inject(tokens.chatRef)\n readonly interrupts = computed(() => {\n const chat = this.ref.host()\n const selected = selectChatUI({\n messages: (chat?.messages() ?? []) as ChatUIMessages<TOptions>,\n interrupts: (chat?.interrupts() ??\n []) as ReadonlyArray<ChatUIInterrupt>,\n inlineToolNames,\n })\n return selected.interrupts\n })\n\n outletFor(interrupt: ChatUIInterrupt) {\n const InterruptComponent = resolveInterruptComponent(\n interrupt,\n interrupts,\n ) as Type<unknown> | undefined\n if (!InterruptComponent) {\n warn(\n `interrupt:${interrupt.id}`,\n `[tanstack-ai-ui] Missing interrupt component for ${interrupt.kind}`,\n )\n return null\n }\n return InterruptComponent\n }\n\n injectorFor(interrupt: ChatUIInterrupt) {\n return Injector.create({\n parent: this.injector,\n providers: [{ provide: tokens.interrupt, useValue: interrupt }],\n })\n }\n }\n\n const layoutInputs = {\n Messages,\n Interrupts,\n Queue,\n Input: (InputComponent ?? MissingInput) as Type<unknown>,\n }\n\n @Component({\n selector: 'ai-chat',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [NgComponentOutlet],\n providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }],\n template: `\n <ng-container\n [ngComponentOutlet]=\"layout\"\n [ngComponentOutletInputs]=\"layoutInputs\"\n />\n `,\n })\n class Chat {\n chat = input.required<ChatUIHost<TOptions>>()\n readonly layout = Layout\n readonly layoutInputs = layoutInputs\n readonly ref = inject(tokens.chatRef)\n\n constructor() {\n effect(() => {\n const next = this.chat()\n untracked(() => this.ref.host.set(next as InjectChatResult))\n })\n }\n }\n\n @Component({\n selector: 'ai-chat-provider',\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }],\n template: `<ng-content />`,\n })\n class ChatProvider {\n chat = input.required<ChatUIHost<TOptions>>()\n readonly ref = inject(tokens.chatRef)\n\n constructor() {\n effect(() => {\n const next = this.chat()\n untracked(() => this.ref.host.set(next as InjectChatResult))\n })\n }\n }\n\n return {\n Chat,\n ChatProvider,\n Messages,\n Interrupts,\n Queue,\n Parts,\n injectChatContext,\n Input: InputComponent,\n } as ChatUIKit<TOptions, TInput>\n}\n\nexport type ChatUIKit<\n TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown>,\n> = {\n Chat: Type<unknown>\n ChatProvider: Type<unknown>\n Messages: Type<unknown>\n Interrupts: Type<unknown>\n Queue: Type<unknown>\n Parts: Type<unknown>\n injectChatContext: () => ChatUIHost<TOptions>\n Input: TInput\n}\n\nexport type { InferredClientContext }\n","import { assertInInjectionContext } from '@angular/core'\nimport type { Type } from '@angular/core'\nimport { injectChat } from '@tanstack/ai-angular'\nimport type { InjectChatOptions } from '@tanstack/ai-angular'\nimport { createChatUI } from './create-ui'\nimport type { ChatUIFactoryConfig, ChatUIHost, InputProps } from './create-ui'\nimport type {\n ChatUIInterruptsOf,\n ChatUISchemaOf,\n ChatUIToolsOf,\n} from '@tanstack/ai-client/ui'\nimport type { InferredClientContext } from '@tanstack/ai-client'\n\ntype HeadlessOptions<TOptions> = InjectChatOptions<\n ChatUIToolsOf<TOptions>,\n ChatUISchemaOf<TOptions>,\n InferredClientContext<ChatUIToolsOf<TOptions>>,\n ChatUIInterruptsOf<TOptions>\n>\n\ntype ChatInstanceOverrides<TOptions> = {\n threadId?: string\n live?: HeadlessOptions<TOptions>['live']\n forwardedProps?: HeadlessOptions<TOptions>['forwardedProps']\n body?: HeadlessOptions<TOptions>['body']\n initialMessages?: HeadlessOptions<TOptions>['initialMessages']\n}\n\n/**\n * Bind chat options and Angular widgets once at module scope.\n *\n * This matches Form `injectForm` and the React `createChatHook` factory:\n * widgets register here. The returned `injectAppChat` creates a chat\n * instance in an injection context. Render `<ai-chat [chat]=\"chat\" />`\n * with the factory `Chat` component.\n */\nexport function createChatHook<\n const TOptions,\n TInput extends Type<unknown> | undefined = Type<unknown> | undefined,\n>({\n options,\n ...chatComponents\n}: {\n options: TOptions\n} & ChatUIFactoryConfig<NoInfer<TOptions>, TInput>) {\n const ui = createChatUI(\n options,\n chatComponents as ChatUIFactoryConfig<NoInfer<TOptions>, TInput>,\n )\n\n function injectAppChat(overrides?: ChatInstanceOverrides<TOptions>) {\n assertInInjectionContext(injectAppChat)\n const chat = (\n overrides\n ? injectChat({\n ...(options as HeadlessOptions<TOptions>),\n ...overrides,\n })\n : injectChat(options as HeadlessOptions<TOptions>)\n ) as ChatUIHost<TOptions>\n return chat\n }\n\n return {\n injectAppChat,\n injectChatContext: ui.injectChatContext,\n Chat: ui.Chat,\n ChatProvider: ui.ChatProvider,\n } as {\n injectAppChat: (\n overrides?: ChatInstanceOverrides<TOptions>,\n ) => ChatUIHost<TOptions>\n injectChatContext: () => ChatUIHost<TOptions>\n Chat: Type<unknown>\n ChatProvider: Type<unknown>\n }\n}\n\nexport type { InputProps }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAQA;;;AAGG;MACU,WAAW,CAAA;AACb,IAAA,IAAI,GAA4C,MAAM,CAAC,IAAI,2EAAC;AACtE;AASD;;;AAGG;SACa,sBAAsB,GAAA;AACpC,IAAA,MAAM,OAAO,GAAG,IAAI,cAAc,CAAc,eAAe,CAAC;AAChE,IAAA,MAAM,IAAI,GAAG,IAAI,cAAc,CAAqB,YAAY,CAAC;AACjE,IAAA,MAAM,SAAS,GAAG,IAAI,cAAc,CAAkB,iBAAiB,CAAC;AAExE,IAAA,SAAS,iBAAiB,GAAA;AACxB,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC;AAC3B,QAAA,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE;QACvB,IAAI,CAAC,IAAI,EAAE;AACT,YAAA,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE;QACH;AACA,QAAA,OAAO,IAAI;IACb;IAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,iBAAiB,EAAE;AACxD;AAEO,MAAM,mBAAmB,GAAG,sBAAsB,EAAE;;ACoI3D,SAAS,cAAc,GAAA;AACrB,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU;AAC9B,IAAA,OAAO,CAAC,GAAW,EAAE,OAAe,KAAI;AACtC,QAAA,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YAAE;AAC3C,QAAA,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE;AACnB,QAAA,IAAI,CAAC,GAAG,CAAC,G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AgB,EAAA,QAAA,EAAA,IAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,CAAA;;gGAEtB,YAAY,EAAA,UAAA,EAAA,CAAA;sBANjB,SAAS;AAAC,gBAAA,IAAA,EAAA,CAAA;AACT,wBAAA,QAAQ,EAAE,kBAAkB;wBAC5B,eAAe,EAAE,uBAAuB,CAAC,MAAM;AAC/C,wBAAA,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAC/D,wBAAA,QAAQ,EAAE,CAAA,cAAA,CAAgB;AAC3B,qBAAA;;IAaD,OAAO;QACL,IAAI;QACJ,YAAY;QACZ,QAAQ;QACR,UAAU;QACV,KAAK;QACL,KAAK;QACL,iBAAiB;AACjB,QAAA,KAAK,EAAE,cAAc;KACS;AACjC;;AC1dD;;;;;;;AAOG;AACG,SAAU,cAAc,CAG5B,EACA,OAAO,EACP,GAAG,cAAc,EAG+B,EAAA;IAChD,MAAM,EAAE,GAAG,YAAY,CACrB,OAAO,EACP,cAAgE,CACjE;IAED,SAAS,aAAa,CAAC,SAA2C,EAAA;QAChE,wBAAwB,CAAC,aAAa,CAAC;QACvC,MAAM,IAAI,IACR;cACI,UAAU,CAAC;AACT,gBAAA,GAAI,OAAqC;AACzC,gBAAA,GAAG,SAAS;aACb;AACH,cAAE,UAAU,CAAC,OAAoC,CAAC,CAC7B;AACzB,QAAA,OAAO,IAAI;IACb;IAEA,OAAO;QACL,aAAa;QACb,iBAAiB,EAAE,EAAE,CAAC,iBAAiB;QACvC,IAAI,EAAE,EAAE,CAAC,IAAI;QACb,YAAY,EAAE,EAAE,CAAC,YAAY;KAQ9B;AACH;;AC5EA;;AAEG;;;;"}
@@ -0,0 +1,162 @@
1
+ import { WritableSignal, InjectionToken, Type } from '@angular/core';
2
+ import { ChatUISelectedPart, ChatUIInterrupt, ChatUIPartKey, ChatUIHasNamedTools, ChatUIToolName, ChatUIHasNamedInterrupts, ChatUINamedInterruptId, ChatUIToolsOf, ChatUISchemaOf, ChatUIInterruptsOf, ChatUIInterruptName, ChatUIInterruptOf, ChatUIMessages, ChatUIPartOf, ChatUIToolApproval } from '@tanstack/ai-client/ui';
3
+ import { QueuedMessage, ToolCallPart, ToolResultPart, InferredClientContext } from '@tanstack/ai-client';
4
+ import { InjectChatResult, InjectChatOptions } from '@tanstack/ai-angular';
5
+
6
+ /**
7
+ * Holder for the active chat instance. Factory components inject this
8
+ * and read `host()`.
9
+ */
10
+ declare class ChatHostRef {
11
+ readonly host: WritableSignal<InjectChatResult | null>;
12
+ }
13
+ interface ChatUITokens {
14
+ chatRef: InjectionToken<ChatHostRef>;
15
+ part: InjectionToken<ChatUISelectedPart>;
16
+ interrupt: InjectionToken<ChatUIInterrupt>;
17
+ injectChatContext: () => InjectChatResult;
18
+ }
19
+ /**
20
+ * Create isolated tokens for nested chat trees, or for widgets in other
21
+ * files that cannot import the `createChatHook` result.
22
+ */
23
+ declare function createChatHookContexts(): ChatUITokens;
24
+
25
+ type ChatUIHost<TOptions = unknown> = InjectChatResult<ChatUIToolsOf<TOptions>, ChatUISchemaOf<TOptions>, ChatUIInterruptsOf<TOptions>>;
26
+ type ChatUIQueueItem = QueuedMessage & {
27
+ cancelQueued: () => void;
28
+ };
29
+ type LayoutProps<TOptions, TInput extends Type<unknown> | undefined = Type<unknown>> = {
30
+ Messages: Type<unknown>;
31
+ Interrupts: Type<unknown>;
32
+ Queue: Type<unknown>;
33
+ readonly __ui?: TOptions;
34
+ } & (TInput extends Type<unknown> ? {
35
+ Input: Type<unknown>;
36
+ } : {});
37
+ type MessageProps<TOptions> = {
38
+ message: ChatUIMessages<TOptions>[number];
39
+ Parts: Type<unknown>;
40
+ };
41
+ type InputProps<TOptions> = {
42
+ readonly __ui?: TOptions;
43
+ };
44
+ type QueueProps<TOptions> = {
45
+ item: ChatUIQueueItem;
46
+ readonly __ui?: TOptions;
47
+ };
48
+ type PartProps<TOptions, TKey extends ChatUIPartKey = ChatUIPartKey> = {
49
+ part: ChatUIPartOf<TOptions, TKey>;
50
+ };
51
+ type ToolProps<TOptions, TName extends ChatUIToolName<TOptions> = ChatUIToolName<TOptions>> = {
52
+ part: Extract<ToolCallPart<ChatUIToolsOf<TOptions>>, {
53
+ name: TName;
54
+ }>;
55
+ result?: ToolResultPart;
56
+ interrupt?: ChatUIToolApproval<TOptions, TName>;
57
+ };
58
+ type InterruptProps<TOptions, TName extends ChatUIInterruptName<TOptions> = never> = {
59
+ interrupt: ChatUIInterruptOf<TOptions, TName>;
60
+ readonly __ui?: TOptions;
61
+ };
62
+ type GenericInterruptComponents<TOptions> = ChatUIHasNamedInterrupts<TOptions> extends true ? {
63
+ [K in ChatUINamedInterruptId<TOptions>]: Type<unknown>;
64
+ } & {
65
+ fallback?: Type<unknown>;
66
+ } : {
67
+ fallback?: Type<unknown>;
68
+ };
69
+ type ToolApprovalMap<TOptions> = {
70
+ [K in ChatUIToolName<TOptions>]?: Type<unknown>;
71
+ };
72
+ type ChatUIChromeComponents<TOptions, TInput extends Type<unknown> | undefined = Type<unknown>> = {
73
+ layout: Type<unknown>;
74
+ message: Type<unknown>;
75
+ input?: TInput;
76
+ queue?: Type<unknown>;
77
+ readonly __ui?: TOptions;
78
+ };
79
+ type ChatUIPartsComponents<TOptions> = {
80
+ [K in ChatUIPartKey]?: Type<unknown>;
81
+ } & {
82
+ fallback?: Type<unknown>;
83
+ readonly __ui?: TOptions;
84
+ };
85
+ type ChatUIInterruptsComponents<TOptions> = {
86
+ tools?: ToolApprovalMap<TOptions>;
87
+ generic: GenericInterruptComponents<TOptions>;
88
+ };
89
+ type ChatUIComponents<TOptions, TInput extends Type<unknown> | undefined = Type<unknown>> = {
90
+ components: ChatUIChromeComponents<TOptions, TInput>;
91
+ partsComponents: ChatUIPartsComponents<TOptions>;
92
+ } & (ChatUIHasNamedTools<TOptions> extends true ? {
93
+ toolsComponents: {
94
+ [K in ChatUIToolName<TOptions>]: Type<unknown>;
95
+ };
96
+ } : {
97
+ toolsComponents?: {
98
+ [K in ChatUIToolName<TOptions>]?: Type<unknown>;
99
+ };
100
+ }) & (ChatUIHasNamedInterrupts<TOptions> extends true ? {
101
+ interruptsComponents: ChatUIInterruptsComponents<TOptions>;
102
+ } : {
103
+ interruptsComponents?: {
104
+ tools?: ToolApprovalMap<TOptions>;
105
+ generic?: GenericInterruptComponents<TOptions>;
106
+ };
107
+ });
108
+ type ChatUIContextConfig = {
109
+ chatRef?: ChatUITokens['chatRef'];
110
+ part?: ChatUITokens['part'];
111
+ interrupt?: ChatUITokens['interrupt'];
112
+ };
113
+ type ChatUIFactoryConfig<TOptions, TInput extends Type<unknown> | undefined = Type<unknown>> = ChatUIComponents<TOptions, TInput> & {
114
+ context?: ChatUIContextConfig;
115
+ };
116
+ /**
117
+ * Bind chat options and Angular widgets once at module scope.
118
+ *
119
+ * Layout, message, input, queue, parts, tools, and interrupts are
120
+ * standalone component classes. The factory builds `Chat`, `Messages`,
121
+ * `Interrupts`, and `Queue` as Angular components that inject the active
122
+ * chat through DI.
123
+ */
124
+ declare function createChatUI<const TOptions, TInput extends Type<unknown> | undefined = Type<unknown> | undefined>(options: TOptions, config: ChatUIFactoryConfig<NoInfer<TOptions>, TInput>): ChatUIKit<TOptions, TInput>;
125
+ type ChatUIKit<TOptions, TInput extends Type<unknown> | undefined = Type<unknown>> = {
126
+ Chat: Type<unknown>;
127
+ ChatProvider: Type<unknown>;
128
+ Messages: Type<unknown>;
129
+ Interrupts: Type<unknown>;
130
+ Queue: Type<unknown>;
131
+ Parts: Type<unknown>;
132
+ injectChatContext: () => ChatUIHost<TOptions>;
133
+ Input: TInput;
134
+ };
135
+
136
+ type HeadlessOptions<TOptions> = InjectChatOptions<ChatUIToolsOf<TOptions>, ChatUISchemaOf<TOptions>, InferredClientContext<ChatUIToolsOf<TOptions>>, ChatUIInterruptsOf<TOptions>>;
137
+ type ChatInstanceOverrides<TOptions> = {
138
+ threadId?: string;
139
+ live?: HeadlessOptions<TOptions>['live'];
140
+ forwardedProps?: HeadlessOptions<TOptions>['forwardedProps'];
141
+ body?: HeadlessOptions<TOptions>['body'];
142
+ initialMessages?: HeadlessOptions<TOptions>['initialMessages'];
143
+ };
144
+ /**
145
+ * Bind chat options and Angular widgets once at module scope.
146
+ *
147
+ * This matches Form `injectForm` and the React `createChatHook` factory:
148
+ * widgets register here. The returned `injectAppChat` creates a chat
149
+ * instance in an injection context. Render `<ai-chat [chat]="chat" />`
150
+ * with the factory `Chat` component.
151
+ */
152
+ declare function createChatHook<const TOptions, TInput extends Type<unknown> | undefined = Type<unknown> | undefined>({ options, ...chatComponents }: {
153
+ options: TOptions;
154
+ } & ChatUIFactoryConfig<NoInfer<TOptions>, TInput>): {
155
+ injectAppChat: (overrides?: ChatInstanceOverrides<TOptions>) => ChatUIHost<TOptions>;
156
+ injectChatContext: () => ChatUIHost<TOptions>;
157
+ Chat: Type<unknown>;
158
+ ChatProvider: Type<unknown>;
159
+ };
160
+
161
+ export { ChatHostRef, createChatHook, createChatHookContexts, createChatUI };
162
+ export type { ChatUIComponents, ChatUIFactoryConfig, ChatUIHost, ChatUIKit, ChatUIQueueItem, ChatUITokens, InputProps, InterruptProps, LayoutProps, MessageProps, PartProps, QueueProps, ToolProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-angular",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "Angular signals integration for TanStack AI streaming chat, structured outputs, and media generation.",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -33,6 +33,10 @@
33
33
  },
34
34
  "./package.json": {
35
35
  "default": "./package.json"
36
+ },
37
+ "./ui": {
38
+ "types": "./dist/types/tanstack-ai-angular-ui.d.ts",
39
+ "default": "./dist/fesm2022/tanstack-ai-angular-ui.mjs"
36
40
  }
37
41
  },
38
42
  "sideEffects": false,
@@ -41,15 +45,17 @@
41
45
  },
42
46
  "files": [
43
47
  "dist",
44
- "src"
48
+ "src",
49
+ "ui"
45
50
  ],
46
51
  "dependencies": {
47
52
  "tslib": "^2.8.1",
48
- "@tanstack/ai-client": "^0.29.2"
53
+ "@tanstack/ai-client": "^0.30.0"
49
54
  },
50
55
  "peerDependencies": {
56
+ "@angular/common": ">=21.0.0",
51
57
  "@angular/core": ">=21.0.0",
52
- "@tanstack/ai": "^0.52.0"
58
+ "@tanstack/ai": "^0.52.1"
53
59
  },
54
60
  "devDependencies": {
55
61
  "@analogjs/vite-plugin-angular": "^2.6.2",
@@ -66,11 +72,11 @@
66
72
  "vitest": "^4.1.10",
67
73
  "zod": "^4.2.0",
68
74
  "zone.js": "^0.15.0",
69
- "@tanstack/ai": "0.52.0"
75
+ "@tanstack/ai": "0.52.1"
70
76
  },
71
77
  "scripts": {
72
78
  "clean": "premove ./build ./dist",
73
- "test:oxlint": "oxlint src --type-aware",
79
+ "test:oxlint": "oxlint src ui/src --type-aware",
74
80
  "test:lib": "vitest run",
75
81
  "test:lib:dev": "vitest",
76
82
  "test:types": "tsc",
@@ -0,0 +1,5 @@
1
+ {
2
+ "lib": {
3
+ "entryFile": "src/index.ts"
4
+ }
5
+ }
@@ -0,0 +1,79 @@
1
+ import { assertInInjectionContext } from '@angular/core'
2
+ import type { Type } from '@angular/core'
3
+ import { injectChat } from '@tanstack/ai-angular'
4
+ import type { InjectChatOptions } from '@tanstack/ai-angular'
5
+ import { createChatUI } from './create-ui'
6
+ import type { ChatUIFactoryConfig, ChatUIHost, InputProps } from './create-ui'
7
+ import type {
8
+ ChatUIInterruptsOf,
9
+ ChatUISchemaOf,
10
+ ChatUIToolsOf,
11
+ } from '@tanstack/ai-client/ui'
12
+ import type { InferredClientContext } from '@tanstack/ai-client'
13
+
14
+ type HeadlessOptions<TOptions> = InjectChatOptions<
15
+ ChatUIToolsOf<TOptions>,
16
+ ChatUISchemaOf<TOptions>,
17
+ InferredClientContext<ChatUIToolsOf<TOptions>>,
18
+ ChatUIInterruptsOf<TOptions>
19
+ >
20
+
21
+ type ChatInstanceOverrides<TOptions> = {
22
+ threadId?: string
23
+ live?: HeadlessOptions<TOptions>['live']
24
+ forwardedProps?: HeadlessOptions<TOptions>['forwardedProps']
25
+ body?: HeadlessOptions<TOptions>['body']
26
+ initialMessages?: HeadlessOptions<TOptions>['initialMessages']
27
+ }
28
+
29
+ /**
30
+ * Bind chat options and Angular widgets once at module scope.
31
+ *
32
+ * This matches Form `injectForm` and the React `createChatHook` factory:
33
+ * widgets register here. The returned `injectAppChat` creates a chat
34
+ * instance in an injection context. Render `<ai-chat [chat]="chat" />`
35
+ * with the factory `Chat` component.
36
+ */
37
+ export function createChatHook<
38
+ const TOptions,
39
+ TInput extends Type<unknown> | undefined = Type<unknown> | undefined,
40
+ >({
41
+ options,
42
+ ...chatComponents
43
+ }: {
44
+ options: TOptions
45
+ } & ChatUIFactoryConfig<NoInfer<TOptions>, TInput>) {
46
+ const ui = createChatUI(
47
+ options,
48
+ chatComponents as ChatUIFactoryConfig<NoInfer<TOptions>, TInput>,
49
+ )
50
+
51
+ function injectAppChat(overrides?: ChatInstanceOverrides<TOptions>) {
52
+ assertInInjectionContext(injectAppChat)
53
+ const chat = (
54
+ overrides
55
+ ? injectChat({
56
+ ...(options as HeadlessOptions<TOptions>),
57
+ ...overrides,
58
+ })
59
+ : injectChat(options as HeadlessOptions<TOptions>)
60
+ ) as ChatUIHost<TOptions>
61
+ return chat
62
+ }
63
+
64
+ return {
65
+ injectAppChat,
66
+ injectChatContext: ui.injectChatContext,
67
+ Chat: ui.Chat,
68
+ ChatProvider: ui.ChatProvider,
69
+ } as {
70
+ injectAppChat: (
71
+ overrides?: ChatInstanceOverrides<TOptions>,
72
+ ) => ChatUIHost<TOptions>
73
+ injectChatContext: () => ChatUIHost<TOptions>
74
+ Chat: Type<unknown>
75
+ ChatProvider: Type<unknown>
76
+ }
77
+ }
78
+
79
+ export type { InputProps }
@@ -0,0 +1,519 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ Injector,
5
+ computed,
6
+ effect,
7
+ inject,
8
+ input,
9
+ untracked,
10
+ } from '@angular/core'
11
+ import { NgComponentOutlet } from '@angular/common'
12
+ import type { Type } from '@angular/core'
13
+ import {
14
+ automaticPartsForMessage,
15
+ collectInlineToolNames,
16
+ resolveInterruptComponent,
17
+ selectChatUI,
18
+ selectMessageUI,
19
+ } from '@tanstack/ai-client/ui'
20
+ import type {
21
+ ChatUIHasNamedInterrupts,
22
+ ChatUIHasNamedTools,
23
+ ChatUIInterrupt,
24
+ ChatUIInterruptName,
25
+ ChatUIInterruptOf,
26
+ ChatUIInterruptsOf,
27
+ ChatUIMessages,
28
+ ChatUINamedInterruptId,
29
+ ChatUIPartKey,
30
+ ChatUIPartOf,
31
+ ChatUISchemaOf,
32
+ ChatUISelectedPart,
33
+ ChatUIToolApproval,
34
+ ChatUIToolName,
35
+ ChatUIToolsOf,
36
+ } from '@tanstack/ai-client/ui'
37
+ import type {
38
+ InferredClientContext,
39
+ QueuedMessage,
40
+ ToolCallPart,
41
+ ToolResultPart,
42
+ } from '@tanstack/ai-client'
43
+ import type { InjectChatResult } from '@tanstack/ai-angular'
44
+ import { ChatHostRef, defaultChatUITokens } from './tokens'
45
+ import type { ChatUITokens } from './tokens'
46
+
47
+ export type ChatUIHost<TOptions = unknown> = InjectChatResult<
48
+ ChatUIToolsOf<TOptions>,
49
+ ChatUISchemaOf<TOptions>,
50
+ ChatUIInterruptsOf<TOptions>
51
+ >
52
+
53
+ export type ChatUIQueueItem = QueuedMessage & {
54
+ cancelQueued: () => void
55
+ }
56
+
57
+ export type LayoutProps<
58
+ TOptions,
59
+ TInput extends Type<unknown> | undefined = Type<unknown>,
60
+ > = {
61
+ Messages: Type<unknown>
62
+ Interrupts: Type<unknown>
63
+ Queue: Type<unknown>
64
+ readonly __ui?: TOptions
65
+ } & (TInput extends Type<unknown> ? { Input: Type<unknown> } : {})
66
+
67
+ export type MessageProps<TOptions> = {
68
+ message: ChatUIMessages<TOptions>[number]
69
+ Parts: Type<unknown>
70
+ }
71
+
72
+ export type InputProps<TOptions> = {
73
+ readonly __ui?: TOptions
74
+ }
75
+
76
+ export type QueueProps<TOptions> = {
77
+ item: ChatUIQueueItem
78
+ readonly __ui?: TOptions
79
+ }
80
+
81
+ export type PartProps<TOptions, TKey extends ChatUIPartKey = ChatUIPartKey> = {
82
+ part: ChatUIPartOf<TOptions, TKey>
83
+ }
84
+
85
+ export type ToolProps<
86
+ TOptions,
87
+ TName extends ChatUIToolName<TOptions> = ChatUIToolName<TOptions>,
88
+ > = {
89
+ part: Extract<ToolCallPart<ChatUIToolsOf<TOptions>>, { name: TName }>
90
+ result?: ToolResultPart
91
+ interrupt?: ChatUIToolApproval<TOptions, TName>
92
+ }
93
+
94
+ export type InterruptProps<
95
+ TOptions,
96
+ TName extends ChatUIInterruptName<TOptions> = never,
97
+ > = {
98
+ interrupt: ChatUIInterruptOf<TOptions, TName>
99
+ readonly __ui?: TOptions
100
+ }
101
+
102
+ type GenericInterruptComponents<TOptions> =
103
+ ChatUIHasNamedInterrupts<TOptions> extends true
104
+ ? {
105
+ [K in ChatUINamedInterruptId<TOptions>]: Type<unknown>
106
+ } & {
107
+ fallback?: Type<unknown>
108
+ }
109
+ : {
110
+ fallback?: Type<unknown>
111
+ }
112
+
113
+ type ToolApprovalMap<TOptions> = {
114
+ [K in ChatUIToolName<TOptions>]?: Type<unknown>
115
+ }
116
+
117
+ export type ChatUIChromeComponents<
118
+ TOptions,
119
+ TInput extends Type<unknown> | undefined = Type<unknown>,
120
+ > = {
121
+ layout: Type<unknown>
122
+ message: Type<unknown>
123
+ input?: TInput
124
+ queue?: Type<unknown>
125
+ readonly __ui?: TOptions
126
+ }
127
+
128
+ export type ChatUIPartsComponents<TOptions> = {
129
+ [K in ChatUIPartKey]?: Type<unknown>
130
+ } & {
131
+ fallback?: Type<unknown>
132
+ readonly __ui?: TOptions
133
+ }
134
+
135
+ export type ChatUIInterruptsComponents<TOptions> = {
136
+ tools?: ToolApprovalMap<TOptions>
137
+ generic: GenericInterruptComponents<TOptions>
138
+ }
139
+
140
+ export type ChatUIComponents<
141
+ TOptions,
142
+ TInput extends Type<unknown> | undefined = Type<unknown>,
143
+ > = {
144
+ components: ChatUIChromeComponents<TOptions, TInput>
145
+ partsComponents: ChatUIPartsComponents<TOptions>
146
+ } & (ChatUIHasNamedTools<TOptions> extends true
147
+ ? {
148
+ toolsComponents: {
149
+ [K in ChatUIToolName<TOptions>]: Type<unknown>
150
+ }
151
+ }
152
+ : {
153
+ toolsComponents?: {
154
+ [K in ChatUIToolName<TOptions>]?: Type<unknown>
155
+ }
156
+ }) &
157
+ (ChatUIHasNamedInterrupts<TOptions> extends true
158
+ ? { interruptsComponents: ChatUIInterruptsComponents<TOptions> }
159
+ : {
160
+ interruptsComponents?: {
161
+ tools?: ToolApprovalMap<TOptions>
162
+ generic?: GenericInterruptComponents<TOptions>
163
+ }
164
+ })
165
+
166
+ export type ChatUIContextConfig = {
167
+ chatRef?: ChatUITokens['chatRef']
168
+ part?: ChatUITokens['part']
169
+ interrupt?: ChatUITokens['interrupt']
170
+ }
171
+
172
+ export type ChatUIFactoryConfig<
173
+ TOptions,
174
+ TInput extends Type<unknown> | undefined = Type<unknown>,
175
+ > = ChatUIComponents<TOptions, TInput> & {
176
+ context?: ChatUIContextConfig
177
+ }
178
+
179
+ function createWarnOnce() {
180
+ const seen = new Set<string>()
181
+ return (key: string, message: string) => {
182
+ if (process.env.NODE_ENV === 'production') return
183
+ if (seen.has(key)) return
184
+ seen.add(key)
185
+ console.warn(message)
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Bind chat options and Angular widgets once at module scope.
191
+ *
192
+ * Layout, message, input, queue, parts, tools, and interrupts are
193
+ * standalone component classes. The factory builds `Chat`, `Messages`,
194
+ * `Interrupts`, and `Queue` as Angular components that inject the active
195
+ * chat through DI.
196
+ */
197
+ export function createChatUI<
198
+ const TOptions,
199
+ TInput extends Type<unknown> | undefined = Type<unknown> | undefined,
200
+ >(options: TOptions, config: ChatUIFactoryConfig<NoInfer<TOptions>, TInput>) {
201
+ void options
202
+ const {
203
+ context: contextOption,
204
+ components,
205
+ partsComponents: parts,
206
+ toolsComponents: tools,
207
+ interruptsComponents: interrupts,
208
+ } = config as ChatUIFactoryConfig<TOptions, TInput> & {
209
+ toolsComponents?: Record<string, Type<unknown> | undefined>
210
+ interruptsComponents?: {
211
+ tools?: Record<string, Type<unknown> | undefined>
212
+ generic?: Record<string, Type<unknown> | undefined>
213
+ }
214
+ }
215
+ const {
216
+ layout: Layout,
217
+ message: MessageComponent,
218
+ input: InputComponent,
219
+ queue: QueueItemComponent,
220
+ } = components
221
+ const warn = createWarnOnce()
222
+ const tokens = {
223
+ chatRef: contextOption?.chatRef ?? defaultChatUITokens.chatRef,
224
+ part: contextOption?.part ?? defaultChatUITokens.part,
225
+ interrupt: contextOption?.interrupt ?? defaultChatUITokens.interrupt,
226
+ }
227
+ const inlineToolNames = collectInlineToolNames(
228
+ interrupts?.tools as Record<string, unknown> | undefined,
229
+ Object.keys(tools ?? {}),
230
+ )
231
+
232
+ function injectChatContext() {
233
+ const ref = inject(tokens.chatRef)
234
+ const chat = ref.host()
235
+ if (!chat) {
236
+ throw new Error(
237
+ '`injectChatContext` must be used within `Chat` or `ChatProvider`.',
238
+ )
239
+ }
240
+ return chat as ChatUIHost<TOptions>
241
+ }
242
+
243
+ @Component({
244
+ selector: 'ai-chat-missing-input',
245
+ changeDetection: ChangeDetectionStrategy.OnPush,
246
+ template: '',
247
+ })
248
+ class MissingInput {
249
+ constructor() {
250
+ warn(
251
+ 'input',
252
+ '[tanstack-ai-ui] Rendered Input but no `input` component is registered.',
253
+ )
254
+ }
255
+ }
256
+
257
+ @Component({
258
+ selector: 'ai-chat-queue',
259
+ changeDetection: ChangeDetectionStrategy.OnPush,
260
+ imports: [NgComponentOutlet],
261
+ template: `
262
+ @if (itemComponent) {
263
+ @for (row of rows(); track row.item.id) {
264
+ <ng-container
265
+ [ngComponentOutlet]="itemComponent"
266
+ [ngComponentOutletInputs]="{ item: row.item }"
267
+ />
268
+ }
269
+ }
270
+ `,
271
+ })
272
+ class Queue {
273
+ readonly ref = inject(tokens.chatRef)
274
+ readonly itemComponent = QueueItemComponent
275
+ readonly rows = computed(() => {
276
+ const chat = this.ref.host()
277
+ if (!chat || !QueueItemComponent) return []
278
+ const items = chat.queue()
279
+ return items.map((item) => ({
280
+ item: {
281
+ ...item,
282
+ cancelQueued: () => {
283
+ chat.cancelQueued(item.id)
284
+ },
285
+ },
286
+ }))
287
+ })
288
+ }
289
+
290
+ @Component({
291
+ selector: 'ai-chat-parts',
292
+ changeDetection: ChangeDetectionStrategy.OnPush,
293
+ imports: [NgComponentOutlet],
294
+ template: `
295
+ @for (selected of selectedParts(); track $index) {
296
+ <ng-container
297
+ [ngComponentOutlet]="outletFor(selected)"
298
+ [ngComponentOutletInputs]="inputsFor(selected)"
299
+ [ngComponentOutletInjector]="injectorFor(selected)"
300
+ />
301
+ }
302
+ `,
303
+ })
304
+ class Parts {
305
+ readonly injector = inject(Injector)
306
+ readonly ref = inject(tokens.chatRef)
307
+ message = input.required<ChatUIMessages<TOptions>[number]>()
308
+
309
+ readonly selectedParts = computed(() => {
310
+ const chat = this.ref.host()
311
+ return automaticPartsForMessage(
312
+ selectMessageUI(this.message(), {
313
+ interrupts: (chat?.interrupts() ??
314
+ []) as ReadonlyArray<ChatUIInterrupt>,
315
+ inlineToolNames,
316
+ }),
317
+ )
318
+ })
319
+
320
+ outletFor(selected: ChatUISelectedPart) {
321
+ if (selected.key === 'toolCall') {
322
+ const name = selected.part.name
323
+ const Tool = tools?.[name as ChatUIToolName<TOptions>]
324
+ if (!Tool) {
325
+ warn(
326
+ `tool:${name}`,
327
+ `[tanstack-ai-ui] Missing tools.${name} component`,
328
+ )
329
+ return null
330
+ }
331
+ return Tool
332
+ }
333
+ const PartComponent = (parts[selected.key] ?? parts.fallback) as
334
+ | Type<unknown>
335
+ | undefined
336
+ if (!PartComponent) {
337
+ warn(
338
+ `part:${selected.key}`,
339
+ `[tanstack-ai-ui] Missing parts.${selected.key} component`,
340
+ )
341
+ return null
342
+ }
343
+ return PartComponent
344
+ }
345
+
346
+ inputsFor(selected: ChatUISelectedPart) {
347
+ if (selected.key === 'toolCall') {
348
+ return {
349
+ part: selected.part,
350
+ result: selected.result,
351
+ interrupt: selected.interrupt,
352
+ }
353
+ }
354
+ return { part: selected.part }
355
+ }
356
+
357
+ injectorFor(selected: ChatUISelectedPart) {
358
+ return Injector.create({
359
+ parent: this.injector,
360
+ providers: [{ provide: tokens.part, useValue: selected }],
361
+ })
362
+ }
363
+ }
364
+
365
+ @Component({
366
+ selector: 'ai-chat-messages',
367
+ changeDetection: ChangeDetectionStrategy.OnPush,
368
+ imports: [NgComponentOutlet],
369
+ template: `
370
+ @for (message of messages(); track message.id) {
371
+ <ng-container
372
+ [ngComponentOutlet]="messageComponent"
373
+ [ngComponentOutletInputs]="{
374
+ message,
375
+ Parts,
376
+ }"
377
+ />
378
+ }
379
+ `,
380
+ })
381
+ class Messages {
382
+ readonly ref = inject(tokens.chatRef)
383
+ readonly messageComponent = MessageComponent
384
+ readonly Parts = Parts
385
+ readonly messages = computed(() => {
386
+ const chat = this.ref.host()
387
+ return (chat?.messages() ?? []) as ChatUIMessages<TOptions>
388
+ })
389
+ }
390
+
391
+ @Component({
392
+ selector: 'ai-chat-interrupts',
393
+ changeDetection: ChangeDetectionStrategy.OnPush,
394
+ imports: [NgComponentOutlet],
395
+ template: `
396
+ @for (interrupt of interrupts(); track interrupt.id) {
397
+ <ng-container
398
+ [ngComponentOutlet]="outletFor(interrupt)"
399
+ [ngComponentOutletInputs]="{ interrupt }"
400
+ [ngComponentOutletInjector]="injectorFor(interrupt)"
401
+ />
402
+ }
403
+ `,
404
+ })
405
+ class Interrupts {
406
+ readonly injector = inject(Injector)
407
+ readonly ref = inject(tokens.chatRef)
408
+ readonly interrupts = computed(() => {
409
+ const chat = this.ref.host()
410
+ const selected = selectChatUI({
411
+ messages: (chat?.messages() ?? []) as ChatUIMessages<TOptions>,
412
+ interrupts: (chat?.interrupts() ??
413
+ []) as ReadonlyArray<ChatUIInterrupt>,
414
+ inlineToolNames,
415
+ })
416
+ return selected.interrupts
417
+ })
418
+
419
+ outletFor(interrupt: ChatUIInterrupt) {
420
+ const InterruptComponent = resolveInterruptComponent(
421
+ interrupt,
422
+ interrupts,
423
+ ) as Type<unknown> | undefined
424
+ if (!InterruptComponent) {
425
+ warn(
426
+ `interrupt:${interrupt.id}`,
427
+ `[tanstack-ai-ui] Missing interrupt component for ${interrupt.kind}`,
428
+ )
429
+ return null
430
+ }
431
+ return InterruptComponent
432
+ }
433
+
434
+ injectorFor(interrupt: ChatUIInterrupt) {
435
+ return Injector.create({
436
+ parent: this.injector,
437
+ providers: [{ provide: tokens.interrupt, useValue: interrupt }],
438
+ })
439
+ }
440
+ }
441
+
442
+ const layoutInputs = {
443
+ Messages,
444
+ Interrupts,
445
+ Queue,
446
+ Input: (InputComponent ?? MissingInput) as Type<unknown>,
447
+ }
448
+
449
+ @Component({
450
+ selector: 'ai-chat',
451
+ changeDetection: ChangeDetectionStrategy.OnPush,
452
+ imports: [NgComponentOutlet],
453
+ providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }],
454
+ template: `
455
+ <ng-container
456
+ [ngComponentOutlet]="layout"
457
+ [ngComponentOutletInputs]="layoutInputs"
458
+ />
459
+ `,
460
+ })
461
+ class Chat {
462
+ chat = input.required<ChatUIHost<TOptions>>()
463
+ readonly layout = Layout
464
+ readonly layoutInputs = layoutInputs
465
+ readonly ref = inject(tokens.chatRef)
466
+
467
+ constructor() {
468
+ effect(() => {
469
+ const next = this.chat()
470
+ untracked(() => this.ref.host.set(next as InjectChatResult))
471
+ })
472
+ }
473
+ }
474
+
475
+ @Component({
476
+ selector: 'ai-chat-provider',
477
+ changeDetection: ChangeDetectionStrategy.OnPush,
478
+ providers: [{ provide: tokens.chatRef, useClass: ChatHostRef }],
479
+ template: `<ng-content />`,
480
+ })
481
+ class ChatProvider {
482
+ chat = input.required<ChatUIHost<TOptions>>()
483
+ readonly ref = inject(tokens.chatRef)
484
+
485
+ constructor() {
486
+ effect(() => {
487
+ const next = this.chat()
488
+ untracked(() => this.ref.host.set(next as InjectChatResult))
489
+ })
490
+ }
491
+ }
492
+
493
+ return {
494
+ Chat,
495
+ ChatProvider,
496
+ Messages,
497
+ Interrupts,
498
+ Queue,
499
+ Parts,
500
+ injectChatContext,
501
+ Input: InputComponent,
502
+ } as ChatUIKit<TOptions, TInput>
503
+ }
504
+
505
+ export type ChatUIKit<
506
+ TOptions,
507
+ TInput extends Type<unknown> | undefined = Type<unknown>,
508
+ > = {
509
+ Chat: Type<unknown>
510
+ ChatProvider: Type<unknown>
511
+ Messages: Type<unknown>
512
+ Interrupts: Type<unknown>
513
+ Queue: Type<unknown>
514
+ Parts: Type<unknown>
515
+ injectChatContext: () => ChatUIHost<TOptions>
516
+ Input: TInput
517
+ }
518
+
519
+ export type { InferredClientContext }
@@ -0,0 +1,21 @@
1
+ export {
2
+ createChatUI,
3
+ type ChatUIComponents,
4
+ type ChatUIFactoryConfig,
5
+ type ChatUIHost,
6
+ type ChatUIKit,
7
+ type ChatUIQueueItem,
8
+ type InputProps,
9
+ type InterruptProps,
10
+ type LayoutProps,
11
+ type MessageProps,
12
+ type PartProps,
13
+ type QueueProps,
14
+ type ToolProps,
15
+ } from './create-ui'
16
+ export { createChatHook } from './create-chat-hook'
17
+ export {
18
+ createChatHookContexts,
19
+ ChatHostRef,
20
+ type ChatUITokens,
21
+ } from './tokens'
@@ -0,0 +1,47 @@
1
+ import { InjectionToken, inject, signal } from '@angular/core'
2
+ import type { WritableSignal } from '@angular/core'
3
+ import type {
4
+ ChatUIInterrupt,
5
+ ChatUISelectedPart,
6
+ } from '@tanstack/ai-client/ui'
7
+ import type { InjectChatResult } from '@tanstack/ai-angular'
8
+
9
+ /**
10
+ * Holder for the active chat instance. Factory components inject this
11
+ * and read `host()`.
12
+ */
13
+ export class ChatHostRef {
14
+ readonly host: WritableSignal<InjectChatResult | null> = signal(null)
15
+ }
16
+
17
+ export interface ChatUITokens {
18
+ chatRef: InjectionToken<ChatHostRef>
19
+ part: InjectionToken<ChatUISelectedPart>
20
+ interrupt: InjectionToken<ChatUIInterrupt>
21
+ injectChatContext: () => InjectChatResult
22
+ }
23
+
24
+ /**
25
+ * Create isolated tokens for nested chat trees, or for widgets in other
26
+ * files that cannot import the `createChatHook` result.
27
+ */
28
+ export function createChatHookContexts(): ChatUITokens {
29
+ const chatRef = new InjectionToken<ChatHostRef>('ChatUIHostRef')
30
+ const part = new InjectionToken<ChatUISelectedPart>('ChatUIPart')
31
+ const interrupt = new InjectionToken<ChatUIInterrupt>('ChatUIInterrupt')
32
+
33
+ function injectChatContext() {
34
+ const ref = inject(chatRef)
35
+ const chat = ref.host()
36
+ if (!chat) {
37
+ throw new Error(
38
+ '`injectChatContext` must be used within `Chat` or `ChatProvider`.',
39
+ )
40
+ }
41
+ return chat
42
+ }
43
+
44
+ return { chatRef, part, interrupt, injectChatContext }
45
+ }
46
+
47
+ export const defaultChatUITokens = createChatHookContexts()