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