@mast-ai/react-ui 0.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/LICENSE +193 -0
- package/README.md +57 -0
- package/dist/approval.d.ts +82 -0
- package/dist/components/AssistantMessage.d.ts +44 -0
- package/dist/components/ChatInput.d.ts +41 -0
- package/dist/components/ConversationPanel.d.ts +43 -0
- package/dist/components/InlineApproval.d.ts +26 -0
- package/dist/components/MessageItem.d.ts +29 -0
- package/dist/components/MessageList.d.ts +38 -0
- package/dist/components/ThinkingBlock.d.ts +32 -0
- package/dist/components/ToolCallBlock.d.ts +11 -0
- package/dist/components/UserMessage.d.ts +19 -0
- package/dist/context.d.ts +113 -0
- package/dist/hooks/useAgentStream.d.ts +131 -0
- package/dist/icons.d.ts +21 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +1012 -0
- package/dist/mentions/MentionPicker.d.ts +30 -0
- package/dist/mentions/index.d.ts +6 -0
- package/dist/mentions/types.d.ts +63 -0
- package/dist/mentions/useMentions.d.ts +54 -0
- package/dist/mentions/utils.d.ts +33 -0
- package/dist/styles.css +631 -0
- package/dist/types.d.ts +162 -0
- package/package.json +71 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
import { useState as R, useRef as C, useEffect as Q, useCallback as _, createContext as nt, useMemo as J, useContext as st, lazy as pt, Fragment as rt, Suspense as ft, useId as gt } from "react";
|
|
2
|
+
import { jsx as e, jsxs as k } from "react/jsx-runtime";
|
|
3
|
+
import { AgentRunner as vt } from "@mast-ai/core";
|
|
4
|
+
import { useVirtualizer as bt } from "@tanstack/react-virtual";
|
|
5
|
+
function tt(t, n, r) {
|
|
6
|
+
return { id: crypto.randomUUID(), role: t, text: n, toolEvents: [], isStreaming: r };
|
|
7
|
+
}
|
|
8
|
+
function F(t, n, r) {
|
|
9
|
+
return t.map((s) => s.id === n ? r(s) : s);
|
|
10
|
+
}
|
|
11
|
+
function W(t, n, r, s) {
|
|
12
|
+
return F(t, n, (a) => {
|
|
13
|
+
let i = !1;
|
|
14
|
+
const l = a.toolEvents.map((o) => !i && o.name === r && o.isStreaming ? (i = !0, s(o)) : o);
|
|
15
|
+
return { ...a, toolEvents: l };
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function kt(t, n, r, s, a) {
|
|
19
|
+
return W(t, n, r, (i) => {
|
|
20
|
+
let l = !1;
|
|
21
|
+
const o = (i.nestedToolEvents ?? []).map((u) => !l && u.name === s && u.isStreaming ? (l = !0, a(u)) : u);
|
|
22
|
+
return { ...i, nestedToolEvents: o };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function xt(t, n) {
|
|
26
|
+
const [r, s] = R(() => (n == null ? void 0 : n.initialEntries) ?? []), [a, i] = R(() => [...t.history]), [l, o] = R(!1), [u, m] = R(0), y = C(null), v = C(n == null ? void 0 : n.onTurnComplete);
|
|
27
|
+
v.current = n == null ? void 0 : n.onTurnComplete, Q(() => {
|
|
28
|
+
var g;
|
|
29
|
+
u !== 0 && ((g = v.current) == null || g.call(v, r, a));
|
|
30
|
+
}, [u]);
|
|
31
|
+
const T = (g) => {
|
|
32
|
+
for (let A = g.length - 1; A >= 0; A--) {
|
|
33
|
+
const N = g[A];
|
|
34
|
+
if (N.role === "assistant" && N.isStreaming) return N.id;
|
|
35
|
+
}
|
|
36
|
+
}, M = _((g, A) => {
|
|
37
|
+
s((N) => {
|
|
38
|
+
const E = T(N);
|
|
39
|
+
return E === void 0 ? N : W(N, E, g, (I) => ({
|
|
40
|
+
...I,
|
|
41
|
+
awaitingApproval: A
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
}, []), P = _((g, A) => {
|
|
45
|
+
s((N) => {
|
|
46
|
+
const E = T(N);
|
|
47
|
+
return E === void 0 ? N : W(N, E, g, (I) => ({ ...I, status: A }));
|
|
48
|
+
});
|
|
49
|
+
}, []), S = _(
|
|
50
|
+
(g, A) => {
|
|
51
|
+
if (l) return;
|
|
52
|
+
const N = tt("user", A ?? g, !1), E = tt("assistant", "", !0), I = E.id;
|
|
53
|
+
s((b) => [...b, N, E]), o(!0);
|
|
54
|
+
const h = new AbortController();
|
|
55
|
+
y.current = h, (async () => {
|
|
56
|
+
try {
|
|
57
|
+
const b = t.runStream(
|
|
58
|
+
g,
|
|
59
|
+
h.signal,
|
|
60
|
+
(d, f) => {
|
|
61
|
+
if (f.type === "thinking")
|
|
62
|
+
s(
|
|
63
|
+
(c) => W(c, I, d, (x) => ({
|
|
64
|
+
...x,
|
|
65
|
+
subThinking: (x.subThinking ?? "") + f.delta
|
|
66
|
+
}))
|
|
67
|
+
);
|
|
68
|
+
else if (f.type === "text_delta")
|
|
69
|
+
s(
|
|
70
|
+
(c) => W(c, I, d, (x) => ({
|
|
71
|
+
...x,
|
|
72
|
+
subText: (x.subText ?? "") + f.delta
|
|
73
|
+
}))
|
|
74
|
+
);
|
|
75
|
+
else if (f.type === "tool_call_started") {
|
|
76
|
+
const c = {
|
|
77
|
+
id: crypto.randomUUID(),
|
|
78
|
+
type: "tool_call_started",
|
|
79
|
+
name: f.name,
|
|
80
|
+
args: f.args,
|
|
81
|
+
isStreaming: !0
|
|
82
|
+
};
|
|
83
|
+
s(
|
|
84
|
+
(x) => W(x, I, d, (V) => ({
|
|
85
|
+
...V,
|
|
86
|
+
nestedToolEvents: [...V.nestedToolEvents ?? [], c]
|
|
87
|
+
}))
|
|
88
|
+
);
|
|
89
|
+
} else if (f.type === "tool_call_completed") {
|
|
90
|
+
const c = f;
|
|
91
|
+
s(
|
|
92
|
+
(x) => kt(x, I, d, c.name, (V) => ({
|
|
93
|
+
...V,
|
|
94
|
+
type: "tool_call_completed",
|
|
95
|
+
result: c.result,
|
|
96
|
+
isStreaming: !1,
|
|
97
|
+
status: c.error ? "error" : "success"
|
|
98
|
+
}))
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
for await (const d of b)
|
|
104
|
+
if (d.type === "text_delta")
|
|
105
|
+
s(
|
|
106
|
+
(f) => F(f, I, (c) => ({
|
|
107
|
+
...c,
|
|
108
|
+
text: c.text + d.delta
|
|
109
|
+
}))
|
|
110
|
+
);
|
|
111
|
+
else if (d.type === "thinking")
|
|
112
|
+
s(
|
|
113
|
+
(f) => F(f, I, (c) => ({
|
|
114
|
+
...c,
|
|
115
|
+
thinking: (c.thinking ?? "") + d.delta
|
|
116
|
+
}))
|
|
117
|
+
);
|
|
118
|
+
else if (d.type === "tool_call_started") {
|
|
119
|
+
const f = {
|
|
120
|
+
id: crypto.randomUUID(),
|
|
121
|
+
type: "tool_call_started",
|
|
122
|
+
name: d.name,
|
|
123
|
+
args: d.args,
|
|
124
|
+
isStreaming: !0
|
|
125
|
+
};
|
|
126
|
+
s(
|
|
127
|
+
(c) => F(c, I, (x) => ({
|
|
128
|
+
...x,
|
|
129
|
+
toolEvents: [...x.toolEvents, f]
|
|
130
|
+
}))
|
|
131
|
+
);
|
|
132
|
+
} else if (d.type === "tool_call_completed")
|
|
133
|
+
s(
|
|
134
|
+
(f) => W(f, I, d.name, (c) => ({
|
|
135
|
+
...c,
|
|
136
|
+
type: "tool_call_completed",
|
|
137
|
+
result: d.result,
|
|
138
|
+
isStreaming: !1,
|
|
139
|
+
// Preserve a status set by the proxy (e.g. 'cancelled'); only
|
|
140
|
+
// fall back to error/success based on the runner's flag.
|
|
141
|
+
status: c.status ?? (d.error ? "error" : "success")
|
|
142
|
+
}))
|
|
143
|
+
);
|
|
144
|
+
else if (d.type === "done") {
|
|
145
|
+
const f = d.history;
|
|
146
|
+
s(
|
|
147
|
+
(c) => F(c, I, (x) => ({
|
|
148
|
+
...x,
|
|
149
|
+
text: d.output,
|
|
150
|
+
isStreaming: !1
|
|
151
|
+
}))
|
|
152
|
+
), i(f), m((c) => c + 1);
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
s(
|
|
156
|
+
(b) => F(b, I, (d) => ({ ...d, isStreaming: !1 }))
|
|
157
|
+
);
|
|
158
|
+
} finally {
|
|
159
|
+
o(!1);
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
},
|
|
163
|
+
[t, l]
|
|
164
|
+
), w = _(() => {
|
|
165
|
+
var g;
|
|
166
|
+
(g = y.current) == null || g.abort();
|
|
167
|
+
}, []), B = _(() => {
|
|
168
|
+
var g;
|
|
169
|
+
(g = y.current) == null || g.abort(), y.current = null, s([]), i([]), o(!1);
|
|
170
|
+
}, []);
|
|
171
|
+
return {
|
|
172
|
+
entries: r,
|
|
173
|
+
history: a,
|
|
174
|
+
isRunning: l,
|
|
175
|
+
sendMessage: S,
|
|
176
|
+
cancel: w,
|
|
177
|
+
reset: B,
|
|
178
|
+
setToolAwaitingApproval: M,
|
|
179
|
+
setToolStatus: P
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const K = {
|
|
183
|
+
width: 16,
|
|
184
|
+
height: 16,
|
|
185
|
+
viewBox: "0 0 24 24",
|
|
186
|
+
fill: "none",
|
|
187
|
+
stroke: "currentColor",
|
|
188
|
+
strokeWidth: 2,
|
|
189
|
+
strokeLinecap: "round",
|
|
190
|
+
strokeLinejoin: "round",
|
|
191
|
+
"aria-hidden": !0,
|
|
192
|
+
focusable: !1
|
|
193
|
+
};
|
|
194
|
+
function yt() {
|
|
195
|
+
return /* @__PURE__ */ k("svg", { ...K, children: [
|
|
196
|
+
/* @__PURE__ */ e("path", { d: "M9 3a3 3 0 0 0-3 3v.5a3 3 0 0 0-2 5.2A3 3 0 0 0 6 17v.5a3 3 0 0 0 6 0V3a3 3 0 0 0-3 0Z" }),
|
|
197
|
+
/* @__PURE__ */ e("path", { d: "M15 3a3 3 0 0 1 3 3v.5a3 3 0 0 1 2 5.2A3 3 0 0 1 18 17v.5a3 3 0 0 1-6 0V3a3 3 0 0 1 3 0Z" })
|
|
198
|
+
] });
|
|
199
|
+
}
|
|
200
|
+
function It() {
|
|
201
|
+
return /* @__PURE__ */ e("svg", { ...K, children: /* @__PURE__ */ e("path", { d: "M14.7 6.3a4 4 0 0 0-5.4 5.4L3 18l3 3 6.3-6.3a4 4 0 0 0 5.4-5.4l-2.6 2.6-2.4-2.4 2.6-2.6Z" }) });
|
|
202
|
+
}
|
|
203
|
+
function St() {
|
|
204
|
+
return /* @__PURE__ */ k("svg", { ...K, children: [
|
|
205
|
+
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "9" }),
|
|
206
|
+
/* @__PURE__ */ e("path", { d: "m8 12 3 3 5-6" })
|
|
207
|
+
] });
|
|
208
|
+
}
|
|
209
|
+
function Nt() {
|
|
210
|
+
return /* @__PURE__ */ k("svg", { ...K, children: [
|
|
211
|
+
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "9" }),
|
|
212
|
+
/* @__PURE__ */ e("path", { d: "m9 9 6 6" }),
|
|
213
|
+
/* @__PURE__ */ e("path", { d: "m15 9-6 6" })
|
|
214
|
+
] });
|
|
215
|
+
}
|
|
216
|
+
function Tt() {
|
|
217
|
+
return /* @__PURE__ */ k("svg", { ...K, children: [
|
|
218
|
+
/* @__PURE__ */ e("circle", { cx: "12", cy: "12", r: "9" }),
|
|
219
|
+
/* @__PURE__ */ e("path", { d: "M5.5 5.5 18.5 18.5" })
|
|
220
|
+
] });
|
|
221
|
+
}
|
|
222
|
+
function wt() {
|
|
223
|
+
return /* @__PURE__ */ e("svg", { ...K, className: "mast-spin", children: /* @__PURE__ */ e("path", { d: "M12 3a9 9 0 1 0 9 9" }) });
|
|
224
|
+
}
|
|
225
|
+
function At() {
|
|
226
|
+
return /* @__PURE__ */ e("svg", { ...K, fill: "currentColor", stroke: "none", children: /* @__PURE__ */ e("path", { d: "M3 3 21 12 3 21l3-9-3-9Z" }) });
|
|
227
|
+
}
|
|
228
|
+
function Et() {
|
|
229
|
+
return /* @__PURE__ */ e("svg", { ...K, fill: "currentColor", stroke: "none", children: /* @__PURE__ */ e("rect", { x: "5", y: "5", width: "14", height: "14", rx: "1" }) });
|
|
230
|
+
}
|
|
231
|
+
const L = {
|
|
232
|
+
brain: /* @__PURE__ */ e(yt, {}),
|
|
233
|
+
wrench: /* @__PURE__ */ e(It, {}),
|
|
234
|
+
check: /* @__PURE__ */ e(St, {}),
|
|
235
|
+
error: /* @__PURE__ */ e(Nt, {}),
|
|
236
|
+
cancelled: /* @__PURE__ */ e(Tt, {}),
|
|
237
|
+
loader: /* @__PURE__ */ e(wt, {}),
|
|
238
|
+
send: /* @__PURE__ */ e(At, {}),
|
|
239
|
+
stop: /* @__PURE__ */ e(Et, {})
|
|
240
|
+
}, at = nt(L);
|
|
241
|
+
function Ct({ icons: t, children: n }) {
|
|
242
|
+
const r = J(() => t ? {
|
|
243
|
+
brain: t.brain ?? L.brain,
|
|
244
|
+
wrench: t.wrench ?? L.wrench,
|
|
245
|
+
check: t.check ?? L.check,
|
|
246
|
+
error: t.error ?? L.error,
|
|
247
|
+
cancelled: t.cancelled ?? L.cancelled,
|
|
248
|
+
loader: t.loader ?? L.loader,
|
|
249
|
+
send: t.send ?? L.send,
|
|
250
|
+
stop: t.stop ?? L.stop
|
|
251
|
+
} : L, [t]);
|
|
252
|
+
return /* @__PURE__ */ e(at.Provider, { value: r, children: n });
|
|
253
|
+
}
|
|
254
|
+
function q() {
|
|
255
|
+
return st(at);
|
|
256
|
+
}
|
|
257
|
+
const Mt = Symbol.for("@mast-ai/react-ui.INLINE_APPROVAL"), Pt = "User cancelled the tool call.";
|
|
258
|
+
function _t(t, n) {
|
|
259
|
+
let r = !1, s = !1;
|
|
260
|
+
if (n)
|
|
261
|
+
for (const a of n)
|
|
262
|
+
a.startsWith("!") ? a.slice(1) === t.name && (s = !0) : a === t.name && (r = !0);
|
|
263
|
+
return (t.requiresApproval === !0 || r) && !s;
|
|
264
|
+
}
|
|
265
|
+
class Rt {
|
|
266
|
+
constructor(n, r, s) {
|
|
267
|
+
this.inner = n, this.onApprovalRequired = r, this.hooks = s;
|
|
268
|
+
}
|
|
269
|
+
definition() {
|
|
270
|
+
return this.inner.definition();
|
|
271
|
+
}
|
|
272
|
+
async call(n, r) {
|
|
273
|
+
var i, l, o, u, m, y;
|
|
274
|
+
const s = this.inner.definition();
|
|
275
|
+
(l = (i = this.hooks).notifyAwaiting) == null || l.call(i, s.name, !0);
|
|
276
|
+
let a;
|
|
277
|
+
try {
|
|
278
|
+
const v = await this.onApprovalRequired({
|
|
279
|
+
id: "",
|
|
280
|
+
type: "tool_call_started",
|
|
281
|
+
name: s.name,
|
|
282
|
+
args: n,
|
|
283
|
+
isStreaming: !0
|
|
284
|
+
});
|
|
285
|
+
v === Mt ? this.hooks.enqueueInline ? a = await this.hooks.enqueueInline(s.name, n) : a = !0 : a = v;
|
|
286
|
+
} finally {
|
|
287
|
+
(u = (o = this.hooks).notifyAwaiting) == null || u.call(o, s.name, !1);
|
|
288
|
+
}
|
|
289
|
+
return a === !1 ? ((y = (m = this.hooks).setStatus) == null || y.call(m, s.name, "cancelled"), Pt) : typeof a == "string" ? a : this.inner.call(n, r);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function Dt(t, n, r, s = {}) {
|
|
293
|
+
return {
|
|
294
|
+
getTools: () => t.getTools(),
|
|
295
|
+
getTool: (a) => {
|
|
296
|
+
const i = t.getTool(a);
|
|
297
|
+
if (!i) return;
|
|
298
|
+
const l = i.definition();
|
|
299
|
+
if (!_t(l, r())) return i;
|
|
300
|
+
const o = n();
|
|
301
|
+
return o ? new Rt(i, o, s) : i;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const it = nt(null);
|
|
306
|
+
function re({
|
|
307
|
+
runner: t,
|
|
308
|
+
agent: n,
|
|
309
|
+
children: r,
|
|
310
|
+
icons: s,
|
|
311
|
+
onApprovalRequired: a,
|
|
312
|
+
approvalOverride: i,
|
|
313
|
+
initialHistory: l,
|
|
314
|
+
initialEntries: o,
|
|
315
|
+
onConversationChange: u
|
|
316
|
+
}) {
|
|
317
|
+
const m = C(u);
|
|
318
|
+
m.current = u;
|
|
319
|
+
const y = C(l), v = C(o), T = C(a);
|
|
320
|
+
T.current = a;
|
|
321
|
+
const M = C(i);
|
|
322
|
+
M.current = i;
|
|
323
|
+
const P = C(null), S = C(null), w = C(null), B = J(() => {
|
|
324
|
+
const $ = a !== void 0, O = i !== void 0 && i.length > 0;
|
|
325
|
+
if (!$ && !O) return t;
|
|
326
|
+
const z = {
|
|
327
|
+
notifyAwaiting: (U, D) => {
|
|
328
|
+
var j;
|
|
329
|
+
return (j = P.current) == null ? void 0 : j.call(P, U, D);
|
|
330
|
+
},
|
|
331
|
+
setStatus: (U, D) => {
|
|
332
|
+
var j;
|
|
333
|
+
return (j = S.current) == null ? void 0 : j.call(S, U, D);
|
|
334
|
+
},
|
|
335
|
+
enqueueInline: (U, D) => {
|
|
336
|
+
var j;
|
|
337
|
+
return ((j = w.current) == null ? void 0 : j.call(w, U, D)) ?? Promise.resolve(!0);
|
|
338
|
+
}
|
|
339
|
+
}, H = Dt(
|
|
340
|
+
t.registry,
|
|
341
|
+
() => T.current,
|
|
342
|
+
() => M.current,
|
|
343
|
+
z
|
|
344
|
+
);
|
|
345
|
+
return new vt(t.adapter, H);
|
|
346
|
+
}, [t, a, i]), [g, A] = R(() => {
|
|
347
|
+
const $ = B.conversation(n);
|
|
348
|
+
return y.current && y.current.length > 0 && ($.history = [...y.current]), $;
|
|
349
|
+
}), N = _(
|
|
350
|
+
($, O) => {
|
|
351
|
+
var z;
|
|
352
|
+
(z = m.current) == null || z.call(m, O, $);
|
|
353
|
+
},
|
|
354
|
+
[]
|
|
355
|
+
), {
|
|
356
|
+
entries: E,
|
|
357
|
+
history: I,
|
|
358
|
+
sendMessage: h,
|
|
359
|
+
cancel: p,
|
|
360
|
+
isRunning: b,
|
|
361
|
+
reset: d,
|
|
362
|
+
setToolAwaitingApproval: f,
|
|
363
|
+
setToolStatus: c
|
|
364
|
+
} = xt(g, {
|
|
365
|
+
initialEntries: v.current,
|
|
366
|
+
onTurnComplete: N
|
|
367
|
+
});
|
|
368
|
+
P.current = f, S.current = c;
|
|
369
|
+
const [x, V] = R([]), X = C(x);
|
|
370
|
+
X.current = x;
|
|
371
|
+
const dt = _(($, O) => new Promise((z) => {
|
|
372
|
+
const H = (D) => {
|
|
373
|
+
V((j) => j.filter((ht) => ht !== U)), z(D);
|
|
374
|
+
}, U = {
|
|
375
|
+
toolName: $,
|
|
376
|
+
args: O,
|
|
377
|
+
approve: () => H(!0),
|
|
378
|
+
reject: () => H(!1),
|
|
379
|
+
respondWith: (D) => H(D)
|
|
380
|
+
};
|
|
381
|
+
V((D) => [...D, U]);
|
|
382
|
+
}), []);
|
|
383
|
+
w.current = dt;
|
|
384
|
+
const Y = _(() => {
|
|
385
|
+
X.current.forEach(($) => $.reject()), d(), A(B.conversation(n));
|
|
386
|
+
}, [d, B, n]), mt = J(
|
|
387
|
+
() => ({
|
|
388
|
+
messages: E,
|
|
389
|
+
history: I,
|
|
390
|
+
sendMessage: h,
|
|
391
|
+
cancel: p,
|
|
392
|
+
isRunning: b,
|
|
393
|
+
reset: Y,
|
|
394
|
+
pendingApprovals: x
|
|
395
|
+
}),
|
|
396
|
+
[E, I, h, p, b, Y, x]
|
|
397
|
+
);
|
|
398
|
+
return /* @__PURE__ */ e(it.Provider, { value: mt, children: /* @__PURE__ */ e(Ct, { icons: s, children: r }) });
|
|
399
|
+
}
|
|
400
|
+
function G() {
|
|
401
|
+
const t = st(it);
|
|
402
|
+
if (!t)
|
|
403
|
+
throw new Error("useAgent() must be called from a component rendered inside <AgentProvider>.");
|
|
404
|
+
return t;
|
|
405
|
+
}
|
|
406
|
+
function $t(t) {
|
|
407
|
+
if (t === void 0) return "";
|
|
408
|
+
if (typeof t == "string") return t;
|
|
409
|
+
try {
|
|
410
|
+
return JSON.stringify(t, null, 2);
|
|
411
|
+
} catch {
|
|
412
|
+
return String(t);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function jt({ entry: t, approve: n, reject: r, className: s }) {
|
|
416
|
+
const a = q(), i = ["mast-inline-approval", s].filter(Boolean).join(" "), l = $t(t.args);
|
|
417
|
+
return /* @__PURE__ */ k("div", { "data-mast-inline-approval": !0, "data-tool-name": t.name, className: i, children: [
|
|
418
|
+
/* @__PURE__ */ k("div", { className: "mast-inline-approval-header", children: [
|
|
419
|
+
/* @__PURE__ */ e("span", { className: "mast-inline-approval-icon", "aria-hidden": "true", children: a.wrench }),
|
|
420
|
+
/* @__PURE__ */ e("span", { className: "mast-inline-approval-name", children: t.name }),
|
|
421
|
+
/* @__PURE__ */ e("span", { className: "mast-inline-approval-label", children: "requires approval" })
|
|
422
|
+
] }),
|
|
423
|
+
l ? /* @__PURE__ */ e("pre", { className: "mast-inline-approval-args", children: /* @__PURE__ */ e("code", { children: l }) }) : null,
|
|
424
|
+
/* @__PURE__ */ k("div", { className: "mast-inline-approval-actions", children: [
|
|
425
|
+
/* @__PURE__ */ e(
|
|
426
|
+
"button",
|
|
427
|
+
{
|
|
428
|
+
type: "button",
|
|
429
|
+
className: "mast-inline-approval-button mast-inline-approval-approve",
|
|
430
|
+
onClick: n,
|
|
431
|
+
children: "Approve"
|
|
432
|
+
}
|
|
433
|
+
),
|
|
434
|
+
/* @__PURE__ */ e(
|
|
435
|
+
"button",
|
|
436
|
+
{
|
|
437
|
+
type: "button",
|
|
438
|
+
className: "mast-inline-approval-button mast-inline-approval-reject",
|
|
439
|
+
onClick: r,
|
|
440
|
+
children: "Reject"
|
|
441
|
+
}
|
|
442
|
+
)
|
|
443
|
+
] })
|
|
444
|
+
] });
|
|
445
|
+
}
|
|
446
|
+
function lt({
|
|
447
|
+
content: t,
|
|
448
|
+
isStreaming: n = !1,
|
|
449
|
+
className: r,
|
|
450
|
+
label: s = "Thinking Process",
|
|
451
|
+
open: a
|
|
452
|
+
}) {
|
|
453
|
+
const i = q(), l = ["mast-thinking-block", r].filter(Boolean).join(" ");
|
|
454
|
+
return /* @__PURE__ */ k(
|
|
455
|
+
"details",
|
|
456
|
+
{
|
|
457
|
+
"data-mast-thinking-block": !0,
|
|
458
|
+
"data-streaming": n ? "true" : void 0,
|
|
459
|
+
className: l,
|
|
460
|
+
open: a,
|
|
461
|
+
children: [
|
|
462
|
+
/* @__PURE__ */ k("summary", { className: "mast-thinking-block-summary", children: [
|
|
463
|
+
/* @__PURE__ */ e("span", { className: "mast-thinking-block-icon", "aria-hidden": "true", children: i.brain }),
|
|
464
|
+
/* @__PURE__ */ e("span", { className: "mast-thinking-block-label", children: s }),
|
|
465
|
+
n ? /* @__PURE__ */ e(
|
|
466
|
+
"span",
|
|
467
|
+
{
|
|
468
|
+
className: "mast-thinking-block-pulse",
|
|
469
|
+
"data-testid": "mast-thinking-pulse",
|
|
470
|
+
"aria-hidden": "true"
|
|
471
|
+
}
|
|
472
|
+
) : null
|
|
473
|
+
] }),
|
|
474
|
+
/* @__PURE__ */ e("div", { className: "mast-thinking-block-content", children: t })
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
function et(t) {
|
|
480
|
+
if (t === void 0) return "";
|
|
481
|
+
if (typeof t == "string") return t;
|
|
482
|
+
try {
|
|
483
|
+
return JSON.stringify(t, null, 2);
|
|
484
|
+
} catch {
|
|
485
|
+
return String(t);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function Lt(t, n) {
|
|
489
|
+
if (t.isStreaming) return n.loader;
|
|
490
|
+
switch (t.status) {
|
|
491
|
+
case "error":
|
|
492
|
+
return n.error;
|
|
493
|
+
case "cancelled":
|
|
494
|
+
return n.cancelled;
|
|
495
|
+
default:
|
|
496
|
+
return n.check;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function ot({ entry: t, className: n }) {
|
|
500
|
+
const r = q(), s = ["mast-tool-call-block", n].filter(Boolean).join(" "), a = t.subThinking !== void 0 || t.subText !== void 0, i = t.nestedToolEvents ?? [], l = Lt(t, r), o = et(t.args), u = et(t.result);
|
|
501
|
+
return /* @__PURE__ */ k(
|
|
502
|
+
"div",
|
|
503
|
+
{
|
|
504
|
+
"data-mast-tool-call-block": !0,
|
|
505
|
+
"data-streaming": t.isStreaming ? "true" : void 0,
|
|
506
|
+
"data-status": t.status,
|
|
507
|
+
"data-tool-name": t.name,
|
|
508
|
+
className: s,
|
|
509
|
+
children: [
|
|
510
|
+
/* @__PURE__ */ k("div", { className: "mast-tool-call-block-header", children: [
|
|
511
|
+
/* @__PURE__ */ e(
|
|
512
|
+
"span",
|
|
513
|
+
{
|
|
514
|
+
className: "mast-tool-call-block-status",
|
|
515
|
+
"data-testid": "mast-tool-call-status",
|
|
516
|
+
"aria-hidden": "true",
|
|
517
|
+
children: l
|
|
518
|
+
}
|
|
519
|
+
),
|
|
520
|
+
/* @__PURE__ */ e("span", { className: "mast-tool-call-block-wrench", "aria-hidden": "true", children: r.wrench }),
|
|
521
|
+
/* @__PURE__ */ e("span", { className: "mast-tool-call-block-name", children: t.name })
|
|
522
|
+
] }),
|
|
523
|
+
a ? /* @__PURE__ */ k("div", { className: "mast-tool-call-block-sub-output", children: [
|
|
524
|
+
t.subThinking !== void 0 ? /* @__PURE__ */ e(
|
|
525
|
+
lt,
|
|
526
|
+
{
|
|
527
|
+
content: t.subThinking,
|
|
528
|
+
isStreaming: t.isStreaming,
|
|
529
|
+
className: "mast-tool-call-block-sub-thinking",
|
|
530
|
+
open: t.isStreaming ? !0 : void 0
|
|
531
|
+
}
|
|
532
|
+
) : null,
|
|
533
|
+
t.subText !== void 0 ? /* @__PURE__ */ e("div", { className: "mast-tool-call-block-sub-text", "data-testid": "mast-tool-call-sub-text", children: t.subText }) : null
|
|
534
|
+
] }) : null,
|
|
535
|
+
i.length > 0 ? /* @__PURE__ */ e("div", { className: "mast-tool-call-block-nested", "data-testid": "mast-tool-call-nested", children: i.map((m) => /* @__PURE__ */ e(ot, { entry: m }, m.id)) }) : null,
|
|
536
|
+
o ? /* @__PURE__ */ k("details", { className: "mast-tool-call-block-args", children: [
|
|
537
|
+
/* @__PURE__ */ e("summary", { children: "Arguments" }),
|
|
538
|
+
/* @__PURE__ */ e("pre", { className: "mast-tool-call-block-pre", children: /* @__PURE__ */ e("code", { children: o }) })
|
|
539
|
+
] }) : null,
|
|
540
|
+
!t.isStreaming && u ? /* @__PURE__ */ k("details", { className: "mast-tool-call-block-result", children: [
|
|
541
|
+
/* @__PURE__ */ e("summary", { children: "Result" }),
|
|
542
|
+
/* @__PURE__ */ e("pre", { className: "mast-tool-call-block-pre", children: /* @__PURE__ */ e("code", { children: u }) })
|
|
543
|
+
] }) : null
|
|
544
|
+
]
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
function Bt({ entry: t, className: n }) {
|
|
549
|
+
const r = ["mast-user-message", n].filter(Boolean).join(" ");
|
|
550
|
+
return /* @__PURE__ */ e("div", { "data-mast-user-message": !0, className: r, children: /* @__PURE__ */ e("div", { className: "mast-user-message-bubble", children: t.text }) });
|
|
551
|
+
}
|
|
552
|
+
const Ut = pt(async () => {
|
|
553
|
+
try {
|
|
554
|
+
const [{ default: t }, { default: n }, { default: r }] = await Promise.all([
|
|
555
|
+
import("react-markdown"),
|
|
556
|
+
import("remark-gfm"),
|
|
557
|
+
import("rehype-sanitize")
|
|
558
|
+
]);
|
|
559
|
+
return {
|
|
560
|
+
default: ({ children: s }) => /* @__PURE__ */ e("div", { className: "mast-assistant-message-markdown", children: /* @__PURE__ */ e(t, { remarkPlugins: [n], rehypePlugins: [r], children: s }) })
|
|
561
|
+
};
|
|
562
|
+
} catch {
|
|
563
|
+
return {
|
|
564
|
+
default: ({ children: t }) => /* @__PURE__ */ e("p", { className: "mast-assistant-message-text", children: t })
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
function Kt({
|
|
569
|
+
entry: t,
|
|
570
|
+
className: n,
|
|
571
|
+
renderMessage: r,
|
|
572
|
+
renderToolCall: s
|
|
573
|
+
}) {
|
|
574
|
+
const a = ["mast-assistant-message", n].filter(Boolean).join(" "), { pendingApprovals: i } = G(), l = (o) => {
|
|
575
|
+
const u = o.awaitingApproval ? i.find((m) => m.toolName === o.name) : void 0;
|
|
576
|
+
return s ? s(o, u) : u ? /* @__PURE__ */ e(
|
|
577
|
+
jt,
|
|
578
|
+
{
|
|
579
|
+
entry: o,
|
|
580
|
+
approve: u.approve,
|
|
581
|
+
reject: u.reject,
|
|
582
|
+
respondWith: u.respondWith
|
|
583
|
+
}
|
|
584
|
+
) : /* @__PURE__ */ e(ot, { entry: o });
|
|
585
|
+
};
|
|
586
|
+
return /* @__PURE__ */ k(
|
|
587
|
+
"div",
|
|
588
|
+
{
|
|
589
|
+
"data-mast-assistant-message": !0,
|
|
590
|
+
"data-streaming": t.isStreaming ? "true" : void 0,
|
|
591
|
+
className: a,
|
|
592
|
+
children: [
|
|
593
|
+
t.thinking ? /* @__PURE__ */ e(lt, { content: t.thinking, isStreaming: t.isStreaming }) : null,
|
|
594
|
+
t.toolEvents.map((o, u) => /* @__PURE__ */ e(rt, { children: l(o) }, `${o.id}-${u}`)),
|
|
595
|
+
t.text ? r ? r(t.text) : /* @__PURE__ */ e(ft, { fallback: /* @__PURE__ */ e("p", { className: "mast-assistant-message-text", children: t.text }), children: /* @__PURE__ */ e(Ut, { children: t.text }) }) : null
|
|
596
|
+
]
|
|
597
|
+
}
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
function Vt({
|
|
601
|
+
items: t,
|
|
602
|
+
activeIndex: n,
|
|
603
|
+
onSelect: r,
|
|
604
|
+
idPrefix: s,
|
|
605
|
+
renderItem: a
|
|
606
|
+
}) {
|
|
607
|
+
return t.length === 0 ? null : /* @__PURE__ */ e(
|
|
608
|
+
"ul",
|
|
609
|
+
{
|
|
610
|
+
className: "mast-mention-picker",
|
|
611
|
+
id: `${s}-listbox`,
|
|
612
|
+
role: "listbox",
|
|
613
|
+
"aria-label": "Mention picker",
|
|
614
|
+
children: t.map((i, l) => {
|
|
615
|
+
const o = l === n, u = o ? "mast-mention-picker-item mast-mention-picker-active" : "mast-mention-picker-item";
|
|
616
|
+
return /* @__PURE__ */ e(
|
|
617
|
+
"li",
|
|
618
|
+
{
|
|
619
|
+
id: `${s}-${l}`,
|
|
620
|
+
role: "option",
|
|
621
|
+
"aria-selected": o,
|
|
622
|
+
className: u,
|
|
623
|
+
onMouseDown: (m) => {
|
|
624
|
+
m.preventDefault(), r(i);
|
|
625
|
+
},
|
|
626
|
+
children: a ? a(i, o) : /* @__PURE__ */ k("div", { children: [
|
|
627
|
+
/* @__PURE__ */ e("div", { className: "mast-mention-picker-item-label", children: i.label }),
|
|
628
|
+
i.description && /* @__PURE__ */ e("div", { className: "mast-mention-picker-item-description", children: i.description })
|
|
629
|
+
] })
|
|
630
|
+
},
|
|
631
|
+
i.id
|
|
632
|
+
);
|
|
633
|
+
})
|
|
634
|
+
}
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
const Z = "@";
|
|
638
|
+
function ct(t) {
|
|
639
|
+
return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
640
|
+
}
|
|
641
|
+
function Wt(t, n = Z) {
|
|
642
|
+
const r = ct(n), s = new RegExp(`${r}([^\\s${r}]*)$`), a = t.match(s);
|
|
643
|
+
return a ? a[1] : null;
|
|
644
|
+
}
|
|
645
|
+
function zt(t, n = Z) {
|
|
646
|
+
const r = ct(n), s = new RegExp(`${r}[^\\s${r}]*$`);
|
|
647
|
+
return t.replace(s, "");
|
|
648
|
+
}
|
|
649
|
+
function Ft(t, n) {
|
|
650
|
+
return t.map((r) => `${r.text}${Z}${r.item.label}`).join("") + n;
|
|
651
|
+
}
|
|
652
|
+
function Ot(t) {
|
|
653
|
+
const n = t.trigger ?? "@", [r, s] = R([]), [a, i] = R(""), [l, o] = R(null), [u, m] = R(0), [y, v] = R([]), T = C(r);
|
|
654
|
+
T.current = r;
|
|
655
|
+
const M = C(a);
|
|
656
|
+
M.current = a;
|
|
657
|
+
const P = C(0);
|
|
658
|
+
Q(() => {
|
|
659
|
+
if (l === null) {
|
|
660
|
+
v([]);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
const h = ++P.current;
|
|
664
|
+
if (t.onSearch) {
|
|
665
|
+
const p = t.onSearch(l);
|
|
666
|
+
p instanceof Promise ? p.then((b) => {
|
|
667
|
+
h === P.current && v(b);
|
|
668
|
+
}) : v(p);
|
|
669
|
+
}
|
|
670
|
+
}, [l, t.onSearch]);
|
|
671
|
+
const S = new Set(r.map((h) => h.item.id)), w = (() => {
|
|
672
|
+
if (l === null) return [];
|
|
673
|
+
if (t.onSearch)
|
|
674
|
+
return y.filter((p) => !S.has(p.id));
|
|
675
|
+
const h = l.toLowerCase();
|
|
676
|
+
return (t.items ?? []).filter(
|
|
677
|
+
(p) => !S.has(p.id) && p.label.toLowerCase().includes(h)
|
|
678
|
+
);
|
|
679
|
+
})(), B = _(
|
|
680
|
+
(h) => {
|
|
681
|
+
i(h), o(Wt(h, n)), m(0);
|
|
682
|
+
},
|
|
683
|
+
[n]
|
|
684
|
+
), g = _(
|
|
685
|
+
(h) => {
|
|
686
|
+
const p = T.current;
|
|
687
|
+
if (p.some((d) => d.item.id === h.id)) return;
|
|
688
|
+
const b = zt(M.current, n);
|
|
689
|
+
s([...p, { text: b, item: h }]), i(""), o(null), m(0);
|
|
690
|
+
},
|
|
691
|
+
[n]
|
|
692
|
+
), A = _((h) => {
|
|
693
|
+
const p = T.current, b = p.findIndex((c) => c.item.id === h);
|
|
694
|
+
if (b === -1) return;
|
|
695
|
+
const d = p[b].text, f = [...p.slice(0, b), ...p.slice(b + 1)];
|
|
696
|
+
if (b < f.length) {
|
|
697
|
+
f[b] = { ...f[b], text: d + f[b].text }, s(f);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
s(f), i(d + M.current);
|
|
701
|
+
}, []), N = _(
|
|
702
|
+
(h) => {
|
|
703
|
+
if (l === null || w.length === 0) return !1;
|
|
704
|
+
switch (h.key) {
|
|
705
|
+
case "ArrowDown":
|
|
706
|
+
return h.preventDefault(), m((p) => (p + 1) % w.length), !0;
|
|
707
|
+
case "ArrowUp":
|
|
708
|
+
return h.preventDefault(), m((p) => p === 0 ? w.length - 1 : p - 1), !0;
|
|
709
|
+
case "Enter":
|
|
710
|
+
return h.preventDefault(), g(w[u] ?? w[0]), !0;
|
|
711
|
+
case "Escape":
|
|
712
|
+
return h.preventDefault(), o(null), !0;
|
|
713
|
+
default:
|
|
714
|
+
return !1;
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
[l, w, u, g]
|
|
718
|
+
), E = _(() => {
|
|
719
|
+
const h = Ft(r, a);
|
|
720
|
+
return { prompt: t.buildPrompt ? t.buildPrompt(r, a) : h, displayText: h };
|
|
721
|
+
}, [r, a, t.buildPrompt]), I = _(() => {
|
|
722
|
+
s([]), i(""), o(null), m(0);
|
|
723
|
+
}, []);
|
|
724
|
+
return {
|
|
725
|
+
segments: r,
|
|
726
|
+
trailingInput: a,
|
|
727
|
+
mentionQuery: l,
|
|
728
|
+
filteredItems: w,
|
|
729
|
+
pickerIndex: u,
|
|
730
|
+
setTrailingInput: B,
|
|
731
|
+
handleKeyDown: N,
|
|
732
|
+
selectItem: g,
|
|
733
|
+
removeChip: A,
|
|
734
|
+
buildSubmission: E,
|
|
735
|
+
clear: I
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
const Ht = 1, qt = 8;
|
|
739
|
+
function ut(t) {
|
|
740
|
+
const n = t.split(`
|
|
741
|
+
`).length;
|
|
742
|
+
return Math.min(qt, Math.max(Ht, n));
|
|
743
|
+
}
|
|
744
|
+
function Gt({
|
|
745
|
+
className: t,
|
|
746
|
+
placeholder: n = "Type a message and press Enter.",
|
|
747
|
+
sendLabel: r,
|
|
748
|
+
cancelLabel: s,
|
|
749
|
+
mentions: a
|
|
750
|
+
}) {
|
|
751
|
+
return a ? /* @__PURE__ */ e(
|
|
752
|
+
Qt,
|
|
753
|
+
{
|
|
754
|
+
className: t,
|
|
755
|
+
placeholder: n,
|
|
756
|
+
sendLabel: r,
|
|
757
|
+
cancelLabel: s,
|
|
758
|
+
mentions: a
|
|
759
|
+
}
|
|
760
|
+
) : /* @__PURE__ */ e(
|
|
761
|
+
Jt,
|
|
762
|
+
{
|
|
763
|
+
className: t,
|
|
764
|
+
placeholder: n,
|
|
765
|
+
sendLabel: r,
|
|
766
|
+
cancelLabel: s
|
|
767
|
+
}
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
function Jt({ className: t, placeholder: n, sendLabel: r, cancelLabel: s }) {
|
|
771
|
+
const { sendMessage: a, cancel: i, isRunning: l } = G(), o = q(), [u, m] = R(""), y = ["mast-chat-input", t].filter(Boolean).join(" "), v = u.trim(), T = !l && v.length > 0, M = () => {
|
|
772
|
+
T && (a(v), m(""));
|
|
773
|
+
}, P = (S) => {
|
|
774
|
+
S.key === "Enter" && !S.shiftKey && (S.preventDefault(), M());
|
|
775
|
+
};
|
|
776
|
+
return /* @__PURE__ */ k(
|
|
777
|
+
"form",
|
|
778
|
+
{
|
|
779
|
+
"data-mast-chat-input": !0,
|
|
780
|
+
className: y,
|
|
781
|
+
onSubmit: (S) => {
|
|
782
|
+
S.preventDefault(), M();
|
|
783
|
+
},
|
|
784
|
+
children: [
|
|
785
|
+
/* @__PURE__ */ e("label", { className: "mast-chat-input-label mast-visually-hidden", htmlFor: "mast-chat-input-field", children: "Message" }),
|
|
786
|
+
/* @__PURE__ */ e(
|
|
787
|
+
"textarea",
|
|
788
|
+
{
|
|
789
|
+
id: "mast-chat-input-field",
|
|
790
|
+
className: "mast-chat-input-textarea",
|
|
791
|
+
value: u,
|
|
792
|
+
placeholder: n,
|
|
793
|
+
rows: ut(u),
|
|
794
|
+
disabled: l,
|
|
795
|
+
onChange: (S) => m(S.target.value),
|
|
796
|
+
onKeyDown: P
|
|
797
|
+
}
|
|
798
|
+
),
|
|
799
|
+
l ? /* @__PURE__ */ e(
|
|
800
|
+
"button",
|
|
801
|
+
{
|
|
802
|
+
type: "button",
|
|
803
|
+
className: "mast-chat-input-cancel",
|
|
804
|
+
"aria-label": "Cancel",
|
|
805
|
+
onClick: i,
|
|
806
|
+
children: s ?? o.stop
|
|
807
|
+
}
|
|
808
|
+
) : /* @__PURE__ */ e(
|
|
809
|
+
"button",
|
|
810
|
+
{
|
|
811
|
+
type: "submit",
|
|
812
|
+
className: "mast-chat-input-send",
|
|
813
|
+
"aria-label": "Send",
|
|
814
|
+
disabled: !T,
|
|
815
|
+
children: r ?? o.send
|
|
816
|
+
}
|
|
817
|
+
)
|
|
818
|
+
]
|
|
819
|
+
}
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
function Qt({
|
|
823
|
+
className: t,
|
|
824
|
+
placeholder: n,
|
|
825
|
+
sendLabel: r,
|
|
826
|
+
cancelLabel: s,
|
|
827
|
+
mentions: a
|
|
828
|
+
}) {
|
|
829
|
+
const { sendMessage: i, cancel: l, isRunning: o } = G(), u = q(), m = gt(), {
|
|
830
|
+
segments: y,
|
|
831
|
+
trailingInput: v,
|
|
832
|
+
mentionQuery: T,
|
|
833
|
+
filteredItems: M,
|
|
834
|
+
pickerIndex: P,
|
|
835
|
+
setTrailingInput: S,
|
|
836
|
+
handleKeyDown: w,
|
|
837
|
+
selectItem: B,
|
|
838
|
+
removeChip: g,
|
|
839
|
+
buildSubmission: A,
|
|
840
|
+
clear: N
|
|
841
|
+
} = Ot(a), E = ["mast-chat-input", "mast-mention-input", t].filter(Boolean).join(" "), I = y.length > 0 || v.trim().length > 0, h = !o && I, p = T !== null && M.length > 0, b = p ? `${m}-${P}` : void 0, d = () => {
|
|
842
|
+
if (!h) return;
|
|
843
|
+
const { prompt: c, displayText: x } = A();
|
|
844
|
+
x.trim() && (i(c, x), N());
|
|
845
|
+
}, f = (c) => {
|
|
846
|
+
w(c) || c.key === "Enter" && !c.shiftKey && (c.preventDefault(), d());
|
|
847
|
+
};
|
|
848
|
+
return /* @__PURE__ */ k(
|
|
849
|
+
"form",
|
|
850
|
+
{
|
|
851
|
+
"data-mast-chat-input": !0,
|
|
852
|
+
className: E,
|
|
853
|
+
onSubmit: (c) => {
|
|
854
|
+
c.preventDefault(), d();
|
|
855
|
+
},
|
|
856
|
+
children: [
|
|
857
|
+
/* @__PURE__ */ e("label", { className: "mast-chat-input-label mast-visually-hidden", htmlFor: "mast-chat-input-field", children: "Message" }),
|
|
858
|
+
/* @__PURE__ */ k("div", { className: "mast-mention-input-field", children: [
|
|
859
|
+
p && /* @__PURE__ */ e(
|
|
860
|
+
Vt,
|
|
861
|
+
{
|
|
862
|
+
items: M,
|
|
863
|
+
activeIndex: P,
|
|
864
|
+
onSelect: B,
|
|
865
|
+
idPrefix: m,
|
|
866
|
+
renderItem: a.renderItem
|
|
867
|
+
}
|
|
868
|
+
),
|
|
869
|
+
/* @__PURE__ */ k("div", { className: "mast-mention-input-content", children: [
|
|
870
|
+
y.map((c) => /* @__PURE__ */ k(rt, { children: [
|
|
871
|
+
c.text && /* @__PURE__ */ e("span", { className: "mast-mention-segment-text", children: c.text }),
|
|
872
|
+
a.renderChip ? a.renderChip(c.item, () => g(c.item.id)) : /* @__PURE__ */ k("span", { className: "mast-mention-chip", children: [
|
|
873
|
+
"@",
|
|
874
|
+
c.item.label,
|
|
875
|
+
/* @__PURE__ */ e(
|
|
876
|
+
"button",
|
|
877
|
+
{
|
|
878
|
+
type: "button",
|
|
879
|
+
className: "mast-mention-chip-remove",
|
|
880
|
+
"aria-label": `Remove reference to ${c.item.label}`,
|
|
881
|
+
onClick: () => g(c.item.id),
|
|
882
|
+
children: "×"
|
|
883
|
+
}
|
|
884
|
+
)
|
|
885
|
+
] })
|
|
886
|
+
] }, c.item.id)),
|
|
887
|
+
/* @__PURE__ */ e(
|
|
888
|
+
"textarea",
|
|
889
|
+
{
|
|
890
|
+
id: "mast-chat-input-field",
|
|
891
|
+
className: "mast-chat-input-textarea mast-mention-input-textarea",
|
|
892
|
+
value: v,
|
|
893
|
+
placeholder: y.length === 0 ? n : "",
|
|
894
|
+
rows: ut(v),
|
|
895
|
+
disabled: o,
|
|
896
|
+
onChange: (c) => S(c.target.value),
|
|
897
|
+
onKeyDown: f,
|
|
898
|
+
role: "combobox",
|
|
899
|
+
"aria-expanded": p,
|
|
900
|
+
"aria-controls": p ? `${m}-listbox` : void 0,
|
|
901
|
+
"aria-autocomplete": "list",
|
|
902
|
+
"aria-activedescendant": b
|
|
903
|
+
}
|
|
904
|
+
)
|
|
905
|
+
] })
|
|
906
|
+
] }),
|
|
907
|
+
o ? /* @__PURE__ */ e(
|
|
908
|
+
"button",
|
|
909
|
+
{
|
|
910
|
+
type: "button",
|
|
911
|
+
className: "mast-chat-input-cancel",
|
|
912
|
+
"aria-label": "Cancel",
|
|
913
|
+
onClick: l,
|
|
914
|
+
children: s ?? u.stop
|
|
915
|
+
}
|
|
916
|
+
) : /* @__PURE__ */ e(
|
|
917
|
+
"button",
|
|
918
|
+
{
|
|
919
|
+
type: "submit",
|
|
920
|
+
className: "mast-chat-input-send",
|
|
921
|
+
"aria-label": "Send",
|
|
922
|
+
disabled: !h,
|
|
923
|
+
children: r ?? u.send
|
|
924
|
+
}
|
|
925
|
+
)
|
|
926
|
+
]
|
|
927
|
+
}
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
function Zt({ entry: t, className: n, renderToolCall: r, renderMessage: s }) {
|
|
931
|
+
return t.role === "user" ? /* @__PURE__ */ e(Bt, { entry: t, className: n }) : /* @__PURE__ */ e(
|
|
932
|
+
Kt,
|
|
933
|
+
{
|
|
934
|
+
entry: t,
|
|
935
|
+
className: n,
|
|
936
|
+
renderToolCall: r,
|
|
937
|
+
renderMessage: s
|
|
938
|
+
}
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
const Xt = 80;
|
|
942
|
+
function Yt({ className: t, renderToolCall: n, renderMessage: r }) {
|
|
943
|
+
const { messages: s } = G(), a = C(null), i = bt({
|
|
944
|
+
count: s.length,
|
|
945
|
+
getScrollElement: () => a.current,
|
|
946
|
+
estimateSize: () => Xt,
|
|
947
|
+
overscan: 4
|
|
948
|
+
}), l = s.length > 0 ? s[s.length - 1] : void 0, o = (l == null ? void 0 : l.text.length) ?? 0;
|
|
949
|
+
Q(() => {
|
|
950
|
+
s.length !== 0 && i.scrollToIndex(s.length - 1, { align: "end" });
|
|
951
|
+
}, [s.length, o, i]);
|
|
952
|
+
const u = i.getTotalSize(), m = i.getVirtualItems(), y = ["mast-message-list", t].filter(Boolean).join(" ");
|
|
953
|
+
return /* @__PURE__ */ e("div", { ref: a, "data-mast-message-list": !0, className: y, role: "log", "aria-live": "polite", children: /* @__PURE__ */ e("div", { style: { height: `${u}px`, position: "relative", width: "100%" }, children: m.map((v) => {
|
|
954
|
+
const T = s[v.index];
|
|
955
|
+
return /* @__PURE__ */ e(
|
|
956
|
+
"div",
|
|
957
|
+
{
|
|
958
|
+
"data-index": v.index,
|
|
959
|
+
ref: i.measureElement,
|
|
960
|
+
style: {
|
|
961
|
+
position: "absolute",
|
|
962
|
+
top: 0,
|
|
963
|
+
left: 0,
|
|
964
|
+
width: "100%",
|
|
965
|
+
transform: `translateY(${v.start}px)`
|
|
966
|
+
},
|
|
967
|
+
children: /* @__PURE__ */ e(
|
|
968
|
+
Zt,
|
|
969
|
+
{
|
|
970
|
+
entry: T,
|
|
971
|
+
renderToolCall: n,
|
|
972
|
+
renderMessage: r
|
|
973
|
+
}
|
|
974
|
+
)
|
|
975
|
+
},
|
|
976
|
+
T.id
|
|
977
|
+
);
|
|
978
|
+
}) }) });
|
|
979
|
+
}
|
|
980
|
+
function ae({
|
|
981
|
+
theme: t,
|
|
982
|
+
className: n,
|
|
983
|
+
renderToolCall: r,
|
|
984
|
+
renderMessage: s,
|
|
985
|
+
inputPlaceholder: a,
|
|
986
|
+
mentions: i
|
|
987
|
+
}) {
|
|
988
|
+
const l = ["mast-conversation-panel", n].filter(Boolean).join(" ");
|
|
989
|
+
return /* @__PURE__ */ k("div", { "data-mast-root": !0, "data-mast-theme": t, className: l, children: [
|
|
990
|
+
/* @__PURE__ */ e(Yt, { renderToolCall: r, renderMessage: s }),
|
|
991
|
+
/* @__PURE__ */ e(Gt, { placeholder: a, mentions: i })
|
|
992
|
+
] });
|
|
993
|
+
}
|
|
994
|
+
export {
|
|
995
|
+
re as AgentProvider,
|
|
996
|
+
Kt as AssistantMessage,
|
|
997
|
+
Gt as ChatInput,
|
|
998
|
+
ae as ConversationPanel,
|
|
999
|
+
Mt as INLINE_APPROVAL,
|
|
1000
|
+
jt as InlineApproval,
|
|
1001
|
+
Zt as MessageItem,
|
|
1002
|
+
Yt as MessageList,
|
|
1003
|
+
lt as ThinkingBlock,
|
|
1004
|
+
ot as ToolCallBlock,
|
|
1005
|
+
Bt as UserMessage,
|
|
1006
|
+
Ft as buildInlineMentionPrompt,
|
|
1007
|
+
Wt as extractMentionQuery,
|
|
1008
|
+
zt as removeMentionTrigger,
|
|
1009
|
+
G as useAgent,
|
|
1010
|
+
xt as useAgentStream,
|
|
1011
|
+
Ot as useMentions
|
|
1012
|
+
};
|