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