@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.
- package/dist/fesm2022/tanstack-ai-angular-byok.mjs +2 -6
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs +578 -326
- package/dist/fesm2022/tanstack-ai-angular-ui.mjs.map +1 -1
- package/dist/fesm2022/tanstack-ai-angular.mjs +445 -665
- package/dist/fesm2022/tanstack-ai-angular.mjs.map +1 -1
- package/dist/types/tanstack-ai-angular-byok.d.ts +2 -1
- package/dist/types/tanstack-ai-angular-ui.d.ts +80 -95
- package/dist/types/tanstack-ai-angular.d.ts +362 -380
- package/package.json +16 -15
- package/dist/fesm2022/tanstack-ai-angular-byok.mjs.map +0 -1
|
@@ -1,108 +1,119 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import { NgComponentOutlet } from
|
|
4
|
-
import {
|
|
5
|
-
import { injectChat } from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
`,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
`,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
`,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
`,
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
`,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
657
|
+
|
|
658
|
+
//# sourceMappingURL=tanstack-ai-angular-ui.mjs.map
|