@tanstack/ai-angular 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,108 +1,119 @@
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
- */
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, InjectionToken, Injector, assertInInjectionContext, computed, effect, inject, input, signal, untracked } from "@angular/core";
3
+ import { NgComponentOutlet } from "@angular/common";
4
+ import { automaticPartsForMessage, collectInlineToolNames, resolveInterruptComponent, selectChatUI, selectMessageUI } from "@tanstack/ai-client/ui";
5
+ import { injectChat } from "@tanstack/ai-angular";
6
+ var ChatHostRef = class {
7
+ host = signal(null, ...ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []);
8
+ };
18
9
  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 };
10
+ const chatRef = new InjectionToken("ChatUIHostRef");
11
+ const part = new InjectionToken("ChatUIPart");
12
+ const interrupt = new InjectionToken("ChatUIInterrupt");
13
+ function injectChatContext() {
14
+ const chat = inject(chatRef).host();
15
+ if (!chat) throw new Error("`injectChatContext` must be used within `Chat` or `ChatProvider`.");
16
+ return chat;
17
+ }
18
+ return {
19
+ chatRef,
20
+ part,
21
+ interrupt,
22
+ injectChatContext
23
+ };
31
24
  }
32
25
  const defaultChatUITokens = createChatHookContexts();
33
-
34
26
  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
- };
27
+ const seen = /* @__PURE__ */ new Set();
28
+ return (key, message) => {
29
+ if (seen.has(key)) return;
30
+ seen.add(key);
31
+ console.warn(message);
32
+ };
44
33
  }
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
34
  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: `
35
+ const { context: contextOption, components, partsComponents: parts, toolsComponents: tools, interruptsComponents: interrupts } = config;
36
+ const { layout: Layout, message: MessageComponent, input: InputComponent, queue: QueueItemComponent } = components;
37
+ const warn = createWarnOnce();
38
+ const tokens = {
39
+ chatRef: contextOption?.chatRef ?? defaultChatUITokens.chatRef,
40
+ part: contextOption?.part ?? defaultChatUITokens.part,
41
+ interrupt: contextOption?.interrupt ?? defaultChatUITokens.interrupt
42
+ };
43
+ const inlineToolNames = collectInlineToolNames(interrupts?.tools, Object.keys(tools ?? {}));
44
+ function injectChatContext() {
45
+ const chat = inject(tokens.chatRef).host();
46
+ if (!chat) throw new Error("`injectChatContext` must be used within `Chat` or `ChatProvider`.");
47
+ return chat;
48
+ }
49
+ class MissingInput {
50
+ constructor() {
51
+ warn("input", "[tanstack-ai-ui] Rendered Input but no `input` component is registered.");
52
+ }
53
+ static ɵfac = i0.ɵɵngDeclareFactory({
54
+ minVersion: "12.0.0",
55
+ version: "22.2.4",
56
+ ngImport: i0,
57
+ type: MissingInput,
58
+ deps: [],
59
+ target: i0.ɵɵFactoryTarget.Component
60
+ });
61
+ static ɵcmp = i0.ɵɵngDeclareComponent({
62
+ minVersion: "14.0.0",
63
+ version: "22.2.4",
64
+ type: MissingInput,
65
+ isStandalone: true,
66
+ selector: "ai-chat-missing-input",
67
+ ngImport: i0,
68
+ template: "",
69
+ isInline: true,
70
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
71
+ });
72
+ }
73
+ i0.ɵɵngDeclareClassMetadata({
74
+ minVersion: "12.0.0",
75
+ version: "22.2.4",
76
+ ngImport: i0,
77
+ type: MissingInput,
78
+ decorators: [{
79
+ type: Component,
80
+ args: [{
81
+ selector: "ai-chat-missing-input",
82
+ changeDetection: ChangeDetectionStrategy.OnPush,
83
+ template: ""
84
+ }]
85
+ }],
86
+ ctorParameters: () => []
87
+ });
88
+ class Queue {
89
+ ref = inject(tokens.chatRef);
90
+ itemComponent = QueueItemComponent;
91
+ rows = computed(() => {
92
+ const chat = this.ref.host();
93
+ if (!chat || !QueueItemComponent) return [];
94
+ return chat.queue().map((item) => ({ item: {
95
+ ...item,
96
+ cancelQueued: () => {
97
+ chat.cancelQueued(item.id);
98
+ }
99
+ } }));
100
+ }, ...ngDevMode ? [{ debugName: "rows" }] : /* istanbul ignore next */ []);
101
+ static ɵfac = i0.ɵɵngDeclareFactory({
102
+ minVersion: "12.0.0",
103
+ version: "22.2.4",
104
+ ngImport: i0,
105
+ type: Queue,
106
+ deps: [],
107
+ target: i0.ɵɵFactoryTarget.Component
108
+ });
109
+ static ɵcmp = i0.ɵɵngDeclareComponent({
110
+ minVersion: "17.0.0",
111
+ version: "22.2.4",
112
+ type: Queue,
113
+ isStandalone: true,
114
+ selector: "ai-chat-queue",
115
+ ngImport: i0,
116
+ template: `
106
117
  @if (itemComponent) {
107
118
  @for (row of rows(); track row.item.id) {
108
119
  <ng-container
@@ -111,15 +122,37 @@ function createChatUI(options, config) {
111
122
  />
112
123
  }
113
124
  }
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: `
125
+ `,
126
+ isInline: true,
127
+ dependencies: [{
128
+ kind: "directive",
129
+ type: NgComponentOutlet,
130
+ selector: "[ngComponentOutlet]",
131
+ inputs: [
132
+ "ngComponentOutlet",
133
+ "ngComponentOutletInputs",
134
+ "ngComponentOutletInjector",
135
+ "ngComponentOutletEnvironmentInjector",
136
+ "ngComponentOutletContent",
137
+ "ngComponentOutletNgModule"
138
+ ],
139
+ exportAs: ["ngComponentOutlet"]
140
+ }],
141
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
142
+ });
143
+ }
144
+ i0.ɵɵngDeclareClassMetadata({
145
+ minVersion: "12.0.0",
146
+ version: "22.2.4",
147
+ ngImport: i0,
148
+ type: Queue,
149
+ decorators: [{
150
+ type: Component,
151
+ args: [{
152
+ selector: "ai-chat-queue",
153
+ changeDetection: ChangeDetectionStrategy.OnPush,
154
+ imports: [NgComponentOutlet],
155
+ template: `
123
156
  @if (itemComponent) {
124
157
  @for (row of rows(); track row.item.id) {
125
158
  <ng-container
@@ -128,56 +161,78 @@ function createChatUI(options, config) {
128
161
  />
129
162
  }
130
163
  }
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: `
164
+ `
165
+ }]
166
+ }]
167
+ });
168
+ class Parts {
169
+ injector = inject(Injector);
170
+ ref = inject(tokens.chatRef);
171
+ message = input.required(...ngDevMode ? [{ debugName: "message" }] : /* istanbul ignore next */ []);
172
+ selectedParts = computed(() => {
173
+ const chat = this.ref.host();
174
+ return automaticPartsForMessage(selectMessageUI(this.message(), {
175
+ interrupts: chat?.interrupts() ?? [],
176
+ inlineToolNames
177
+ }));
178
+ }, ...ngDevMode ? [{ debugName: "selectedParts" }] : /* istanbul ignore next */ []);
179
+ outletFor(selected) {
180
+ if (selected.key === "toolCall") {
181
+ const name = selected.part.name;
182
+ const Tool = tools?.[name];
183
+ if (!Tool) {
184
+ warn(`tool:${name}`, `[tanstack-ai-ui] Missing tools.${name} component`);
185
+ return null;
186
+ }
187
+ return Tool;
188
+ }
189
+ const PartComponent = parts[selected.key] ?? parts.fallback;
190
+ if (!PartComponent) {
191
+ warn(`part:${selected.key}`, `[tanstack-ai-ui] Missing parts.${selected.key} component`);
192
+ return null;
193
+ }
194
+ return PartComponent;
195
+ }
196
+ inputsFor(selected) {
197
+ if (selected.key === "toolCall") return {
198
+ part: selected.part,
199
+ result: selected.result,
200
+ interrupt: selected.interrupt
201
+ };
202
+ return { part: selected.part };
203
+ }
204
+ injectorFor(selected) {
205
+ return Injector.create({
206
+ parent: this.injector,
207
+ providers: [{
208
+ provide: tokens.part,
209
+ useValue: selected
210
+ }]
211
+ });
212
+ }
213
+ static ɵfac = i0.ɵɵngDeclareFactory({
214
+ minVersion: "12.0.0",
215
+ version: "22.2.4",
216
+ ngImport: i0,
217
+ type: Parts,
218
+ deps: [],
219
+ target: i0.ɵɵFactoryTarget.Component
220
+ });
221
+ static ɵcmp = i0.ɵɵngDeclareComponent({
222
+ minVersion: "17.0.0",
223
+ version: "22.2.4",
224
+ type: Parts,
225
+ isStandalone: true,
226
+ selector: "ai-chat-parts",
227
+ inputs: { message: {
228
+ classPropertyName: "message",
229
+ publicName: "message",
230
+ isSignal: true,
231
+ isRequired: true,
232
+ transformFunction: null
233
+ } },
234
+ ngImport: i0,
235
+ template: `
181
236
  @for (selected of selectedParts(); track $index) {
182
237
  <ng-container
183
238
  [ngComponentOutlet]="outletFor(selected)"
@@ -185,15 +240,37 @@ function createChatUI(options, config) {
185
240
  [ngComponentOutletInjector]="injectorFor(selected)"
186
241
  />
187
242
  }
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: `
243
+ `,
244
+ isInline: true,
245
+ dependencies: [{
246
+ kind: "directive",
247
+ type: NgComponentOutlet,
248
+ selector: "[ngComponentOutlet]",
249
+ inputs: [
250
+ "ngComponentOutlet",
251
+ "ngComponentOutletInputs",
252
+ "ngComponentOutletInjector",
253
+ "ngComponentOutletEnvironmentInjector",
254
+ "ngComponentOutletContent",
255
+ "ngComponentOutletNgModule"
256
+ ],
257
+ exportAs: ["ngComponentOutlet"]
258
+ }],
259
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
260
+ });
261
+ }
262
+ i0.ɵɵngDeclareClassMetadata({
263
+ minVersion: "12.0.0",
264
+ version: "22.2.4",
265
+ ngImport: i0,
266
+ type: Parts,
267
+ decorators: [{
268
+ type: Component,
269
+ args: [{
270
+ selector: "ai-chat-parts",
271
+ changeDetection: ChangeDetectionStrategy.OnPush,
272
+ imports: [NgComponentOutlet],
273
+ template: `
197
274
  @for (selected of selectedParts(); track $index) {
198
275
  <ng-container
199
276
  [ngComponentOutlet]="outletFor(selected)"
@@ -201,19 +278,41 @@ function createChatUI(options, config) {
201
278
  [ngComponentOutletInjector]="injectorFor(selected)"
202
279
  />
203
280
  }
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: `
281
+ `
282
+ }]
283
+ }],
284
+ propDecorators: { message: [{
285
+ type: i0.Input,
286
+ args: [{
287
+ isSignal: true,
288
+ alias: "message",
289
+ required: true
290
+ }]
291
+ }] }
292
+ });
293
+ class Messages {
294
+ ref = inject(tokens.chatRef);
295
+ messageComponent = MessageComponent;
296
+ Parts = Parts;
297
+ messages = computed(() => {
298
+ return this.ref.host()?.messages() ?? [];
299
+ }, ...ngDevMode ? [{ debugName: "messages" }] : /* istanbul ignore next */ []);
300
+ static ɵfac = i0.ɵɵngDeclareFactory({
301
+ minVersion: "12.0.0",
302
+ version: "22.2.4",
303
+ ngImport: i0,
304
+ type: Messages,
305
+ deps: [],
306
+ target: i0.ɵɵFactoryTarget.Component
307
+ });
308
+ static ɵcmp = i0.ɵɵngDeclareComponent({
309
+ minVersion: "17.0.0",
310
+ version: "22.2.4",
311
+ type: Messages,
312
+ isStandalone: true,
313
+ selector: "ai-chat-messages",
314
+ ngImport: i0,
315
+ template: `
217
316
  @for (message of messages(); track message.id) {
218
317
  <ng-container
219
318
  [ngComponentOutlet]="messageComponent"
@@ -223,15 +322,37 @@ function createChatUI(options, config) {
223
322
  }"
224
323
  />
225
324
  }
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: `
325
+ `,
326
+ isInline: true,
327
+ dependencies: [{
328
+ kind: "directive",
329
+ type: NgComponentOutlet,
330
+ selector: "[ngComponentOutlet]",
331
+ inputs: [
332
+ "ngComponentOutlet",
333
+ "ngComponentOutletInputs",
334
+ "ngComponentOutletInjector",
335
+ "ngComponentOutletEnvironmentInjector",
336
+ "ngComponentOutletContent",
337
+ "ngComponentOutletNgModule"
338
+ ],
339
+ exportAs: ["ngComponentOutlet"]
340
+ }],
341
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
342
+ });
343
+ }
344
+ i0.ɵɵngDeclareClassMetadata({
345
+ minVersion: "12.0.0",
346
+ version: "22.2.4",
347
+ ngImport: i0,
348
+ type: Messages,
349
+ decorators: [{
350
+ type: Component,
351
+ args: [{
352
+ selector: "ai-chat-messages",
353
+ changeDetection: ChangeDetectionStrategy.OnPush,
354
+ imports: [NgComponentOutlet],
355
+ template: `
235
356
  @for (message of messages(); track message.id) {
236
357
  <ng-container
237
358
  [ngComponentOutlet]="messageComponent"
@@ -241,38 +362,54 @@ function createChatUI(options, config) {
241
362
  }"
242
363
  />
243
364
  }
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: `
365
+ `
366
+ }]
367
+ }]
368
+ });
369
+ class Interrupts {
370
+ injector = inject(Injector);
371
+ ref = inject(tokens.chatRef);
372
+ interrupts = computed(() => {
373
+ const chat = this.ref.host();
374
+ return selectChatUI({
375
+ messages: chat?.messages() ?? [],
376
+ interrupts: chat?.interrupts() ?? [],
377
+ inlineToolNames
378
+ }).interrupts;
379
+ }, ...ngDevMode ? [{ debugName: "interrupts" }] : /* istanbul ignore next */ []);
380
+ outletFor(interrupt) {
381
+ const InterruptComponent = resolveInterruptComponent(interrupt, interrupts);
382
+ if (!InterruptComponent) {
383
+ warn(`interrupt:${interrupt.id}`, `[tanstack-ai-ui] Missing interrupt component for ${interrupt.kind}`);
384
+ return null;
385
+ }
386
+ return InterruptComponent;
387
+ }
388
+ injectorFor(interrupt) {
389
+ return Injector.create({
390
+ parent: this.injector,
391
+ providers: [{
392
+ provide: tokens.interrupt,
393
+ useValue: interrupt
394
+ }]
395
+ });
396
+ }
397
+ static ɵfac = i0.ɵɵngDeclareFactory({
398
+ minVersion: "12.0.0",
399
+ version: "22.2.4",
400
+ ngImport: i0,
401
+ type: Interrupts,
402
+ deps: [],
403
+ target: i0.ɵɵFactoryTarget.Component
404
+ });
405
+ static ɵcmp = i0.ɵɵngDeclareComponent({
406
+ minVersion: "17.0.0",
407
+ version: "22.2.4",
408
+ type: Interrupts,
409
+ isStandalone: true,
410
+ selector: "ai-chat-interrupts",
411
+ ngImport: i0,
412
+ template: `
276
413
  @for (interrupt of interrupts(); track interrupt.id) {
277
414
  <ng-container
278
415
  [ngComponentOutlet]="outletFor(interrupt)"
@@ -280,15 +417,37 @@ function createChatUI(options, config) {
280
417
  [ngComponentOutletInjector]="injectorFor(interrupt)"
281
418
  />
282
419
  }
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: `
420
+ `,
421
+ isInline: true,
422
+ dependencies: [{
423
+ kind: "directive",
424
+ type: NgComponentOutlet,
425
+ selector: "[ngComponentOutlet]",
426
+ inputs: [
427
+ "ngComponentOutlet",
428
+ "ngComponentOutletInputs",
429
+ "ngComponentOutletInjector",
430
+ "ngComponentOutletEnvironmentInjector",
431
+ "ngComponentOutletContent",
432
+ "ngComponentOutletNgModule"
433
+ ],
434
+ exportAs: ["ngComponentOutlet"]
435
+ }],
436
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
437
+ });
438
+ }
439
+ i0.ɵɵngDeclareClassMetadata({
440
+ minVersion: "12.0.0",
441
+ version: "22.2.4",
442
+ ngImport: i0,
443
+ type: Interrupts,
444
+ decorators: [{
445
+ type: Component,
446
+ args: [{
447
+ selector: "ai-chat-interrupts",
448
+ changeDetection: ChangeDetectionStrategy.OnPush,
449
+ imports: [NgComponentOutlet],
450
+ template: `
292
451
  @for (interrupt of interrupts(); track interrupt.id) {
293
452
  <ng-container
294
453
  [ngComponentOutlet]="outletFor(interrupt)"
@@ -296,111 +455,204 @@ function createChatUI(options, config) {
296
455
  [ngComponentOutletInjector]="injectorFor(interrupt)"
297
456
  />
298
457
  }
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: `
458
+ `
459
+ }]
460
+ }]
461
+ });
462
+ const layoutInputs = {
463
+ Messages,
464
+ Interrupts,
465
+ Queue,
466
+ Input: InputComponent ?? MissingInput
467
+ };
468
+ class Chat {
469
+ chat = input.required(...ngDevMode ? [{ debugName: "chat" }] : /* istanbul ignore next */ []);
470
+ layout = Layout;
471
+ layoutInputs = layoutInputs;
472
+ ref = inject(tokens.chatRef);
473
+ constructor() {
474
+ effect(() => {
475
+ const next = this.chat();
476
+ untracked(() => this.ref.host.set(next));
477
+ });
478
+ }
479
+ static ɵfac = i0.ɵɵngDeclareFactory({
480
+ minVersion: "12.0.0",
481
+ version: "22.2.4",
482
+ ngImport: i0,
483
+ type: Chat,
484
+ deps: [],
485
+ target: i0.ɵɵFactoryTarget.Component
486
+ });
487
+ static ɵcmp = i0.ɵɵngDeclareComponent({
488
+ minVersion: "17.1.0",
489
+ version: "22.2.4",
490
+ type: Chat,
491
+ isStandalone: true,
492
+ selector: "ai-chat",
493
+ inputs: { chat: {
494
+ classPropertyName: "chat",
495
+ publicName: "chat",
496
+ isSignal: true,
497
+ isRequired: true,
498
+ transformFunction: null
499
+ } },
500
+ providers: [{
501
+ provide: tokens.chatRef,
502
+ useClass: ChatHostRef
503
+ }],
504
+ ngImport: i0,
505
+ template: `
321
506
  <ng-container
322
507
  [ngComponentOutlet]="layout"
323
508
  [ngComponentOutletInputs]="layoutInputs"
324
509
  />
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: `
510
+ `,
511
+ isInline: true,
512
+ dependencies: [{
513
+ kind: "directive",
514
+ type: NgComponentOutlet,
515
+ selector: "[ngComponentOutlet]",
516
+ inputs: [
517
+ "ngComponentOutlet",
518
+ "ngComponentOutletInputs",
519
+ "ngComponentOutletInjector",
520
+ "ngComponentOutletEnvironmentInjector",
521
+ "ngComponentOutletContent",
522
+ "ngComponentOutletNgModule"
523
+ ],
524
+ exportAs: ["ngComponentOutlet"]
525
+ }],
526
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
527
+ });
528
+ }
529
+ i0.ɵɵngDeclareClassMetadata({
530
+ minVersion: "12.0.0",
531
+ version: "22.2.4",
532
+ ngImport: i0,
533
+ type: Chat,
534
+ decorators: [{
535
+ type: Component,
536
+ args: [{
537
+ selector: "ai-chat",
538
+ changeDetection: ChangeDetectionStrategy.OnPush,
539
+ imports: [NgComponentOutlet],
540
+ providers: [{
541
+ provide: tokens.chatRef,
542
+ useClass: ChatHostRef
543
+ }],
544
+ template: `
335
545
  <ng-container
336
546
  [ngComponentOutlet]="layout"
337
547
  [ngComponentOutletInputs]="layoutInputs"
338
548
  />
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
- };
549
+ `
550
+ }]
551
+ }],
552
+ ctorParameters: () => [],
553
+ propDecorators: { chat: [{
554
+ type: i0.Input,
555
+ args: [{
556
+ isSignal: true,
557
+ alias: "chat",
558
+ required: true
559
+ }]
560
+ }] }
561
+ });
562
+ class ChatProvider {
563
+ chat = input.required(...ngDevMode ? [{ debugName: "chat" }] : /* istanbul ignore next */ []);
564
+ ref = inject(tokens.chatRef);
565
+ constructor() {
566
+ effect(() => {
567
+ const next = this.chat();
568
+ untracked(() => this.ref.host.set(next));
569
+ });
570
+ }
571
+ static ɵfac = i0.ɵɵngDeclareFactory({
572
+ minVersion: "12.0.0",
573
+ version: "22.2.4",
574
+ ngImport: i0,
575
+ type: ChatProvider,
576
+ deps: [],
577
+ target: i0.ɵɵFactoryTarget.Component
578
+ });
579
+ static ɵcmp = i0.ɵɵngDeclareComponent({
580
+ minVersion: "17.1.0",
581
+ version: "22.2.4",
582
+ type: ChatProvider,
583
+ isStandalone: true,
584
+ selector: "ai-chat-provider",
585
+ inputs: { chat: {
586
+ classPropertyName: "chat",
587
+ publicName: "chat",
588
+ isSignal: true,
589
+ isRequired: true,
590
+ transformFunction: null
591
+ } },
592
+ providers: [{
593
+ provide: tokens.chatRef,
594
+ useClass: ChatHostRef
595
+ }],
596
+ ngImport: i0,
597
+ template: `<ng-content />`,
598
+ isInline: true,
599
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
600
+ });
601
+ }
602
+ i0.ɵɵngDeclareClassMetadata({
603
+ minVersion: "12.0.0",
604
+ version: "22.2.4",
605
+ ngImport: i0,
606
+ type: ChatProvider,
607
+ decorators: [{
608
+ type: Component,
609
+ args: [{
610
+ selector: "ai-chat-provider",
611
+ changeDetection: ChangeDetectionStrategy.OnPush,
612
+ providers: [{
613
+ provide: tokens.chatRef,
614
+ useClass: ChatHostRef
615
+ }],
616
+ template: `<ng-content />`
617
+ }]
618
+ }],
619
+ ctorParameters: () => [],
620
+ propDecorators: { chat: [{
621
+ type: i0.Input,
622
+ args: [{
623
+ isSignal: true,
624
+ alias: "chat",
625
+ required: true
626
+ }]
627
+ }] }
628
+ });
629
+ return {
630
+ Chat,
631
+ ChatProvider,
632
+ Messages,
633
+ Interrupts,
634
+ Queue,
635
+ Parts,
636
+ injectChatContext,
637
+ Input: InputComponent
638
+ };
373
639
  }
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
640
  function createChatHook({ options, ...chatComponents }) {
384
- const ui = createChatUI(options, chatComponents);
385
- function injectAppChat(overrides) {
386
- assertInInjectionContext(injectAppChat);
387
- const chat = injectChat({
388
- ...options,
389
- ...overrides,
390
- });
391
- return chat;
392
- }
393
- return {
394
- injectAppChat,
395
- injectChatContext: ui.injectChatContext,
396
- Chat: ui.Chat,
397
- ChatProvider: ui.ChatProvider,
398
- };
641
+ const ui = createChatUI(options, chatComponents);
642
+ function injectAppChat(overrides) {
643
+ assertInInjectionContext(injectAppChat);
644
+ return injectChat({
645
+ ...options,
646
+ ...overrides
647
+ });
648
+ }
649
+ return {
650
+ injectAppChat,
651
+ injectChatContext: ui.injectChatContext,
652
+ Chat: ui.Chat,
653
+ ChatProvider: ui.ChatProvider
654
+ };
399
655
  }
400
-
401
- /**
402
- * Generated bundle index. Do not edit.
403
- */
404
-
405
656
  export { ChatHostRef, createChatHook, createChatHookContexts, createChatUI };
406
- //# sourceMappingURL=tanstack-ai-angular-ui.mjs.map
657
+
658
+ //# sourceMappingURL=tanstack-ai-angular-ui.mjs.map