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