@mast-ai/react-ui 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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 v } from "react/jsx-runtime";
3
- import { AgentRunner as bt } from "@mast-ai/core";
4
- import { useVirtualizer as vt } 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
- const l = a.toolEvents.map((c) => !i && c.name === r && c.isStreaming ? (i = !0, s(c)) : c);
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 c = (i.nestedToolEvents ?? []).map((u) => !l && u.name === s && u.isStreaming ? (l = !0, a(u)) : u);
22
- return { ...i, nestedToolEvents: c };
21
+ const o = (i.nestedToolEvents ?? []).map((c) => !l && c.name === s && c.isStreaming ? (l = !0, a(c)) : c);
22
+ return { ...i, nestedToolEvents: o };
23
23
  });
24
24
  }
25
- function xt(t, n) {
26
- const [r, s] = R(() => (n == null ? void 0 : n.initialEntries) ?? []), [a, i] = R(() => [...t.history]), [l, c] = R(!1), [u, m] = R(0), k = C(null), g = C(n == null ? void 0 : n.onTurnComplete);
27
- g.current = n == null ? void 0 : n.onTurnComplete, Q(() => {
25
+ function wt(t, n) {
26
+ const [r, s] = j(() => (n == null ? void 0 : n.initialEntries) ?? []), [a, i] = j(
27
+ () => t ? [...t.history] : []
28
+ ), [l, o] = j(!1);
29
+ G(() => {
30
+ t && i([...t.history]);
31
+ }, [t]);
32
+ const [c, u] = j(0), m = R(null), g = R(n == null ? void 0 : n.onTurnComplete);
33
+ g.current = n == null ? void 0 : n.onTurnComplete, G(() => {
28
34
  var b;
29
- u !== 0 && ((b = g.current) == null || b.call(g, r, a));
30
- }, [u]);
31
- const T = (b) => {
32
- for (let A = b.length - 1; A >= 0; A--) {
33
- const N = b[A];
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 = _((b, A) => {
42
+ }, T = _((b, y) => {
37
43
  s((N) => {
38
- const E = T(N);
39
- return E === void 0 ? N : W(N, E, b, (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 = _((b, A) => {
50
+ }, []), A = _((b, y) => {
45
51
  s((N) => {
46
- const E = T(N);
47
- return E === void 0 ? N : W(N, E, b, (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
- (b, A) => {
55
+ }, []), D = _(
56
+ (b, y) => {
51
57
  if (l) return;
52
- const N = tt("user", A ?? b, !1), E = tt("assistant", "", !0), I = E.id;
53
- s((x) => [...x, N, E]), c(!0);
54
- const h = new AbortController();
55
- k.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 x = t.runStream(
69
+ const S = t.runStream(
58
70
  b,
59
- h.signal,
60
- (d, f) => {
61
- if (f.type === "thinking")
71
+ f.signal,
72
+ (d, p) => {
73
+ if (p.type === "thinking")
62
74
  s(
63
- (o) => W(o, I, d, (y) => ({
64
- ...y,
65
- subThinking: (y.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
- (o) => W(o, I, d, (y) => ({
71
- ...y,
72
- subText: (y.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 o = {
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
- (y) => W(y, I, d, (V) => ({
85
- ...V,
86
- nestedToolEvents: [...V.nestedToolEvents ?? [], o]
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 o = f;
101
+ } else if (p.type === "tool_call_completed") {
102
+ const h = p;
91
103
  s(
92
- (y) => kt(y, I, d, o.name, (V) => ({
93
- ...V,
104
+ (M) => Nt(M, w, d, h.name, (k) => ({
105
+ ...k,
94
106
  type: "tool_call_completed",
95
- result: o.result,
107
+ result: h.result,
96
108
  isStreaming: !1,
97
- status: o.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 x)
115
+ for await (const d of S)
104
116
  if (d.type === "text_delta")
105
117
  s(
106
- (f) => F(f, I, (o) => ({
107
- ...o,
108
- text: o.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, (o) => ({
114
- ...o,
115
- thinking: (o.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,62 +136,62 @@ function xt(t, n) {
124
136
  isStreaming: !0
125
137
  };
126
138
  s(
127
- (o) => F(o, I, (y) => ({
128
- ...y,
129
- toolEvents: [...y.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, (o) => ({
135
- ...o,
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: o.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
- (o) => F(o, I, (y) => ({
148
- ...y,
159
+ (h) => O(h, w, (M) => ({
160
+ ...M,
149
161
  text: d.output,
150
162
  isStreaming: !1
151
163
  }))
152
- ), i(f), m((o) => o + 1);
164
+ ), i(p), u((h) => h + 1);
153
165
  }
154
166
  } catch {
155
167
  s(
156
- (x) => F(x, I, (d) => ({ ...d, isStreaming: !1 }))
168
+ (S) => O(S, w, (d) => ({ ...d, isStreaming: !1 }))
157
169
  );
158
170
  } finally {
159
- c(!1);
171
+ o(!1);
160
172
  }
161
173
  })();
162
174
  },
163
175
  [t, l]
164
- ), w = _(() => {
176
+ ), C = _(() => {
165
177
  var b;
166
- (b = k.current) == null || b.abort();
167
- }, []), B = _(() => {
178
+ (b = m.current) == null || b.abort();
179
+ }, []), E = _(() => {
168
180
  var b;
169
- (b = k.current) == null || b.abort(), k.current = null, s([]), i([]), c(!1);
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__ */ v("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__ */ v("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__ */ v("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__ */ v("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,7 +282,7 @@ class Rt {
270
282
  return this.inner.definition();
271
283
  }
272
284
  async call(n, r) {
273
- var i, l, c, u, m, k;
285
+ var i, l, o, c, u, m;
274
286
  const s = this.inner.definition();
275
287
  (l = (i = this.hooks).notifyAwaiting) == null || l.call(i, s.name, !0);
276
288
  let a;
@@ -282,28 +294,28 @@ class Rt {
282
294
  args: n,
283
295
  isStreaming: !0
284
296
  });
285
- g === Mt ? this.hooks.enqueueInline ? a = await this.hooks.enqueueInline(s.name, n) : a = !0 : a = g;
297
+ g === $t ? this.hooks.enqueueInline ? a = await this.hooks.enqueueInline(s.name, n) : a = !0 : a = g;
286
298
  } finally {
287
- (u = (c = this.hooks).notifyAwaiting) == null || u.call(c, s.name, !1);
299
+ (c = (o = this.hooks).notifyAwaiting) == null || c.call(o, s.name, !1);
288
300
  }
289
- return a === !1 ? ((k = (m = this.hooks).setStatus) == null || k.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;
300
- const c = n();
301
- return c ? new Rt(i, c, s) : i;
311
+ if (!Lt(l, r())) return i;
312
+ const o = n();
313
+ return o ? new Bt(i, o, s) : i;
302
314
  }
303
315
  };
304
316
  }
305
- const it = nt(null);
306
- function ae({
317
+ const ct = X(null);
318
+ function ue({
307
319
  runner: t,
308
320
  agent: n,
309
321
  children: r,
@@ -311,99 +323,111 @@ function ae({
311
323
  onApprovalRequired: a,
312
324
  approvalOverride: i,
313
325
  initialHistory: l,
314
- initialEntries: c,
315
- onConversationChange: u
326
+ initialEntries: o,
327
+ onConversationChange: c,
328
+ theme: u,
329
+ disableRoot: m
316
330
  }) {
317
- const m = C(u);
318
- m.current = u;
319
- const k = C(l), g = C(c), 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 bt(t.adapter, H);
346
- }, [t, a, i]), [b, A] = R(() => {
347
- const $ = B.conversation(n);
348
- return k.current && k.current.length > 0 && ($.history = [...k.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: x,
361
- reset: d,
362
- setToolAwaitingApproval: f,
363
- setToolStatus: o
364
- } = xt(b, {
365
- initialEntries: g.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 = o;
369
- const [y, V] = R([]), X = C(y);
370
- X.current = y;
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: x,
393
- reset: Y,
394
- pendingApprovals: y
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, x, Y, y]
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__ */ v("div", { "data-mast-inline-approval": !0, "data-tool-name": t.name, className: i, children: [
418
- /* @__PURE__ */ v("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__ */ v("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__ */ v(
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__ */ v("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,22 +521,27 @@ function Lt(t, n) {
496
521
  return n.check;
497
522
  }
498
523
  }
499
- function Bt(t, n) {
524
+ function zt(t, n) {
500
525
  return t === "streaming" ? n ? !0 : void 0 : t;
501
526
  }
502
- function ot({ entry: t, className: n, defaultOpen: r = "streaming" }) {
503
- const s = q(), a = ["mast-tool-call-block", n].filter(Boolean).join(" "), i = t.subThinking !== void 0 || t.subText !== void 0, l = t.nestedToolEvents ?? [], c = Lt(t, s), u = et(t.args), m = et(t.result), k = Bt(r, t.isStreaming);
504
- return /* @__PURE__ */ v(
527
+ function mt({
528
+ entry: t,
529
+ className: n,
530
+ defaultOpen: r = "streaming",
531
+ label: s
532
+ }) {
533
+ const a = J(), i = Y(dt), l = ["mast-tool-call-block", n].filter(Boolean).join(" "), o = t.subThinking !== void 0 || t.subText !== void 0, c = t.nestedToolEvents ?? [], u = Wt(t, a), m = it(t.args), g = it(t.result), x = zt(r, t.isStreaming), T = s ?? (i == null ? void 0 : i(t)) ?? t.name;
534
+ return /* @__PURE__ */ I(
505
535
  "details",
506
536
  {
507
537
  "data-mast-tool-call-block": !0,
508
538
  "data-streaming": t.isStreaming ? "true" : void 0,
509
539
  "data-status": t.status,
510
540
  "data-tool-name": t.name,
511
- className: a,
512
- open: k,
541
+ className: l,
542
+ open: x,
513
543
  children: [
514
- /* @__PURE__ */ v("summary", { className: "mast-tool-call-block-header", children: [
544
+ /* @__PURE__ */ I("summary", { className: "mast-tool-call-block-header", children: [
515
545
  /* @__PURE__ */ e("span", { className: "mast-tool-call-block-chevron", "aria-hidden": "true", children: "▸" }),
516
546
  /* @__PURE__ */ e(
517
547
  "span",
@@ -519,16 +549,16 @@ function ot({ entry: t, className: n, defaultOpen: r = "streaming" }) {
519
549
  className: "mast-tool-call-block-status",
520
550
  "data-testid": "mast-tool-call-status",
521
551
  "aria-hidden": "true",
522
- children: c
552
+ children: u
523
553
  }
524
554
  ),
525
- /* @__PURE__ */ e("span", { className: "mast-tool-call-block-wrench", "aria-hidden": "true", children: s.wrench }),
526
- /* @__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 })
527
557
  ] }),
528
- /* @__PURE__ */ v("div", { className: "mast-tool-call-block-body", children: [
529
- i ? /* @__PURE__ */ v("div", { className: "mast-tool-call-block-sub-output", children: [
558
+ /* @__PURE__ */ I("div", { className: "mast-tool-call-block-body", children: [
559
+ o ? /* @__PURE__ */ I("div", { className: "mast-tool-call-block-sub-output", children: [
530
560
  t.subThinking !== void 0 ? /* @__PURE__ */ e(
531
- lt,
561
+ ut,
532
562
  {
533
563
  content: t.subThinking,
534
564
  isStreaming: t.isStreaming,
@@ -538,25 +568,25 @@ function ot({ entry: t, className: n, defaultOpen: r = "streaming" }) {
538
568
  ) : null,
539
569
  t.subText !== void 0 ? /* @__PURE__ */ e("div", { className: "mast-tool-call-block-sub-text", "data-testid": "mast-tool-call-sub-text", children: t.subText }) : null
540
570
  ] }) : null,
541
- l.length > 0 ? /* @__PURE__ */ e("div", { className: "mast-tool-call-block-nested", "data-testid": "mast-tool-call-nested", children: l.map((g) => /* @__PURE__ */ e(ot, { entry: g }, g.id)) }) : null,
542
- u ? /* @__PURE__ */ v("details", { className: "mast-tool-call-block-args", children: [
571
+ c.length > 0 ? /* @__PURE__ */ e("div", { className: "mast-tool-call-block-nested", "data-testid": "mast-tool-call-nested", children: c.map((A) => /* @__PURE__ */ e(mt, { entry: A }, A.id)) }) : null,
572
+ m ? /* @__PURE__ */ I("details", { className: "mast-tool-call-block-args", children: [
543
573
  /* @__PURE__ */ e("summary", { children: "Arguments" }),
544
- /* @__PURE__ */ e("pre", { className: "mast-tool-call-block-pre", children: /* @__PURE__ */ e("code", { children: u }) })
574
+ /* @__PURE__ */ e("pre", { className: "mast-tool-call-block-pre", children: /* @__PURE__ */ e("code", { children: m }) })
545
575
  ] }) : null,
546
- !t.isStreaming && m ? /* @__PURE__ */ v("details", { className: "mast-tool-call-block-result", children: [
576
+ !t.isStreaming && g ? /* @__PURE__ */ I("details", { className: "mast-tool-call-block-result", children: [
547
577
  /* @__PURE__ */ e("summary", { children: "Result" }),
548
- /* @__PURE__ */ e("pre", { className: "mast-tool-call-block-pre", children: /* @__PURE__ */ e("code", { children: m }) })
578
+ /* @__PURE__ */ e("pre", { className: "mast-tool-call-block-pre", children: /* @__PURE__ */ e("code", { children: g }) })
549
579
  ] }) : null
550
580
  ] })
551
581
  ]
552
582
  }
553
583
  );
554
584
  }
555
- function Ut({ entry: t, className: n }) {
585
+ function Ft({ entry: t, className: n }) {
556
586
  const r = ["mast-user-message", n].filter(Boolean).join(" ");
557
587
  return /* @__PURE__ */ e("div", { "data-mast-user-message": !0, className: r, children: /* @__PURE__ */ e("div", { className: "mast-user-message-bubble", children: t.text }) });
558
588
  }
559
- const Kt = pt(async () => {
589
+ const Ot = kt(async () => {
560
590
  try {
561
591
  const [{ default: t }, { default: n }, { default: r }] = await Promise.all([
562
592
  import("react-markdown"),
@@ -572,39 +602,41 @@ const Kt = pt(async () => {
572
602
  };
573
603
  }
574
604
  });
575
- function Vt({
605
+ function Ht({
576
606
  entry: t,
577
607
  className: n,
578
608
  renderMessage: r,
579
- renderToolCall: s
609
+ renderToolCall: s,
610
+ renderApproval: a,
611
+ getToolLabel: i
580
612
  }) {
581
- const a = ["mast-assistant-message", n].filter(Boolean).join(" "), { pendingApprovals: i } = G(), l = (c) => {
582
- const u = c.awaitingApproval ? i.find((m) => m.toolName === c.name) : void 0;
583
- return s ? s(c, u) : u ? /* @__PURE__ */ e(
584
- 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,
585
617
  {
586
- entry: c,
587
- approve: u.approve,
588
- reject: u.reject,
589
- respondWith: u.respondWith
618
+ entry: u,
619
+ approve: m.approve,
620
+ reject: m.reject,
621
+ respondWith: m.respondWith
590
622
  }
591
- ) : /* @__PURE__ */ e(ot, { entry: c });
623
+ ) : /* @__PURE__ */ e(mt, { entry: u });
592
624
  };
593
- return /* @__PURE__ */ v(
625
+ return /* @__PURE__ */ e(dt.Provider, { value: i, children: /* @__PURE__ */ I(
594
626
  "div",
595
627
  {
596
628
  "data-mast-assistant-message": !0,
597
629
  "data-streaming": t.isStreaming ? "true" : void 0,
598
- className: a,
630
+ className: l,
599
631
  children: [
600
- t.thinking ? /* @__PURE__ */ e(lt, { content: t.thinking, isStreaming: t.isStreaming }) : null,
601
- t.toolEvents.map((c, u) => /* @__PURE__ */ e(rt, { children: l(c) }, `${c.id}-${u}`)),
602
- t.text ? r ? r(t.text) : /* @__PURE__ */ e(ft, { fallback: /* @__PURE__ */ e("p", { className: "mast-assistant-message-text", children: t.text }), children: /* @__PURE__ */ e(Kt, { 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
603
635
  ]
604
636
  }
605
- );
637
+ ) });
606
638
  }
607
- function Wt({
639
+ function qt({
608
640
  items: t,
609
641
  activeIndex: n,
610
642
  onSelect: r,
@@ -619,18 +651,18 @@ function Wt({
619
651
  role: "listbox",
620
652
  "aria-label": "Mention picker",
621
653
  children: t.map((i, l) => {
622
- const c = l === n, u = c ? "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";
623
655
  return /* @__PURE__ */ e(
624
656
  "li",
625
657
  {
626
658
  id: `${s}-${l}`,
627
659
  role: "option",
628
- "aria-selected": c,
629
- className: u,
630
- onMouseDown: (m) => {
631
- m.preventDefault(), r(i);
660
+ "aria-selected": o,
661
+ className: c,
662
+ onMouseDown: (u) => {
663
+ u.preventDefault(), r(i);
632
664
  },
633
- children: a ? a(i, c) : /* @__PURE__ */ v("div", { children: [
665
+ children: a ? a(i, o) : /* @__PURE__ */ I("div", { children: [
634
666
  /* @__PURE__ */ e("div", { className: "mast-mention-picker-item-label", children: i.label }),
635
667
  i.description && /* @__PURE__ */ e("div", { className: "mast-mention-picker-item-description", children: i.description })
636
668
  ] })
@@ -641,114 +673,114 @@ function Wt({
641
673
  }
642
674
  );
643
675
  }
644
- const Z = "@";
645
- function ct(t) {
676
+ const tt = "@";
677
+ function ht(t) {
646
678
  return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
647
679
  }
648
- function zt(t, n = Z) {
649
- 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);
650
682
  return a ? a[1] : null;
651
683
  }
652
- function Ft(t, n = Z) {
653
- 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}]*$`);
654
686
  return t.replace(s, "");
655
687
  }
656
- function Ot(t, n) {
657
- 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;
658
690
  }
659
- function Ht(t) {
660
- const n = t.trigger ?? "@", [r, s] = R([]), [a, i] = R(""), [l, c] = R(null), [u, m] = R(0), [k, g] = R([]), T = C(r);
661
- T.current = r;
662
- const M = C(a);
663
- M.current = a;
664
- const P = C(0);
665
- 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(() => {
666
698
  if (l === null) {
667
699
  g([]);
668
700
  return;
669
701
  }
670
- const h = ++P.current;
702
+ const f = ++A.current;
671
703
  if (t.onSearch) {
672
- const p = t.onSearch(l);
673
- p instanceof Promise ? p.then((x) => {
674
- h === P.current && g(x);
675
- }) : g(p);
704
+ const v = t.onSearch(l);
705
+ v instanceof Promise ? v.then((S) => {
706
+ f === A.current && g(S);
707
+ }) : g(v);
676
708
  }
677
709
  }, [l, t.onSearch]);
678
- const S = new Set(r.map((h) => h.item.id)), w = (() => {
710
+ const D = new Set(r.map((f) => f.item.id)), C = (() => {
679
711
  if (l === null) return [];
680
712
  if (t.onSearch)
681
- return k.filter((p) => !S.has(p.id));
682
- const h = l.toLowerCase();
713
+ return m.filter((v) => !D.has(v.id));
714
+ const f = l.toLowerCase();
683
715
  return (t.items ?? []).filter(
684
- (p) => !S.has(p.id) && p.label.toLowerCase().includes(h)
716
+ (v) => !D.has(v.id) && v.label.toLowerCase().includes(f)
685
717
  );
686
- })(), B = _(
687
- (h) => {
688
- i(h), c(zt(h, n)), m(0);
718
+ })(), E = _(
719
+ (f) => {
720
+ i(f), o(Gt(f, n)), u(0);
689
721
  },
690
722
  [n]
691
723
  ), b = _(
692
- (h) => {
693
- const p = T.current;
694
- if (p.some((d) => d.item.id === h.id)) return;
695
- const x = Ft(M.current, n);
696
- s([...p, { text: x, item: h }]), i(""), c(null), m(0);
724
+ (f) => {
725
+ const v = x.current;
726
+ if (v.some((d) => d.item.id === f.id)) return;
727
+ const S = Jt(T.current, n);
728
+ s([...v, { text: S, item: f }]), i(""), o(null), u(0);
697
729
  },
698
730
  [n]
699
- ), A = _((h) => {
700
- const p = T.current, x = p.findIndex((o) => o.item.id === h);
701
- if (x === -1) return;
702
- const d = p[x].text, f = [...p.slice(0, x), ...p.slice(x + 1)];
703
- if (x < f.length) {
704
- f[x] = { ...f[x], text: d + f[x].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);
705
737
  return;
706
738
  }
707
- s(f), i(d + M.current);
739
+ s(p), i(d + T.current);
708
740
  }, []), N = _(
709
- (h) => {
710
- if (l === null || w.length === 0) return !1;
711
- switch (h.key) {
741
+ (f) => {
742
+ if (l === null || C.length === 0) return !1;
743
+ switch (f.key) {
712
744
  case "ArrowDown":
713
- return h.preventDefault(), m((p) => (p + 1) % w.length), !0;
745
+ return f.preventDefault(), u((v) => (v + 1) % C.length), !0;
714
746
  case "ArrowUp":
715
- 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;
716
748
  case "Enter":
717
- return h.preventDefault(), b(w[u] ?? w[0]), !0;
749
+ return f.preventDefault(), b(C[c] ?? C[0]), !0;
718
750
  case "Escape":
719
- return h.preventDefault(), c(null), !0;
751
+ return f.preventDefault(), o(null), !0;
720
752
  default:
721
753
  return !1;
722
754
  }
723
755
  },
724
- [l, w, u, b]
725
- ), E = _(() => {
726
- const h = Ot(r, a);
727
- return { prompt: t.buildPrompt ? t.buildPrompt(r, a) : h, displayText: h };
728
- }, [r, a, t.buildPrompt]), I = _(() => {
729
- s([]), i(""), c(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);
730
762
  }, []);
731
763
  return {
732
764
  segments: r,
733
765
  trailingInput: a,
734
766
  mentionQuery: l,
735
- filteredItems: w,
736
- pickerIndex: u,
737
- setTrailingInput: B,
767
+ filteredItems: C,
768
+ pickerIndex: c,
769
+ setTrailingInput: E,
738
770
  handleKeyDown: N,
739
771
  selectItem: b,
740
- removeChip: A,
741
- buildSubmission: E,
742
- clear: I
772
+ removeChip: y,
773
+ buildSubmission: P,
774
+ clear: w
743
775
  };
744
776
  }
745
- const qt = 1, Gt = 8;
746
- function ut(t) {
777
+ const Xt = 1, Yt = 8;
778
+ function pt(t) {
747
779
  const n = t.split(`
748
780
  `).length;
749
- return Math.min(Gt, Math.max(qt, n));
781
+ return Math.min(Yt, Math.max(Xt, n));
750
782
  }
751
- function Jt({
783
+ function te({
752
784
  className: t,
753
785
  placeholder: n = "Type a message and press Enter.",
754
786
  sendLabel: r,
@@ -756,7 +788,7 @@ function Jt({
756
788
  mentions: a
757
789
  }) {
758
790
  return a ? /* @__PURE__ */ e(
759
- Zt,
791
+ ne,
760
792
  {
761
793
  className: t,
762
794
  placeholder: n,
@@ -765,7 +797,7 @@ function Jt({
765
797
  mentions: a
766
798
  }
767
799
  ) : /* @__PURE__ */ e(
768
- Qt,
800
+ ee,
769
801
  {
770
802
  className: t,
771
803
  placeholder: n,
@@ -774,19 +806,19 @@ function Jt({
774
806
  }
775
807
  );
776
808
  }
777
- function Qt({ className: t, placeholder: n, sendLabel: r, cancelLabel: s }) {
778
- const { sendMessage: a, cancel: i, isRunning: l } = G(), c = q(), [u, m] = R(""), k = ["mast-chat-input", t].filter(Boolean).join(" "), g = u.trim(), T = !l && g.length > 0, M = () => {
779
- T && (a(g), m(""));
780
- }, P = (S) => {
781
- 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());
782
814
  };
783
- return /* @__PURE__ */ v(
815
+ return /* @__PURE__ */ I(
784
816
  "form",
785
817
  {
786
818
  "data-mast-chat-input": !0,
787
- className: k,
788
- onSubmit: (S) => {
789
- S.preventDefault(), M();
819
+ className: g,
820
+ onSubmit: (E) => {
821
+ E.preventDefault(), D();
790
822
  },
791
823
  children: [
792
824
  /* @__PURE__ */ e("label", { className: "mast-chat-input-label mast-visually-hidden", htmlFor: "mast-chat-input-field", children: "Message" }),
@@ -797,10 +829,10 @@ function Qt({ className: t, placeholder: n, sendLabel: r, cancelLabel: s }) {
797
829
  className: "mast-chat-input-textarea",
798
830
  value: u,
799
831
  placeholder: n,
800
- rows: ut(u),
801
- disabled: l,
802
- onChange: (S) => m(S.target.value),
803
- onKeyDown: P
832
+ rows: pt(u),
833
+ disabled: A,
834
+ onChange: (E) => m(E.target.value),
835
+ onKeyDown: C
804
836
  }
805
837
  ),
806
838
  l ? /* @__PURE__ */ e(
@@ -826,92 +858,92 @@ function Qt({ className: t, placeholder: n, sendLabel: r, cancelLabel: s }) {
826
858
  }
827
859
  );
828
860
  }
829
- function Zt({
861
+ function ne({
830
862
  className: t,
831
863
  placeholder: n,
832
864
  sendLabel: r,
833
865
  cancelLabel: s,
834
866
  mentions: a
835
867
  }) {
836
- const { sendMessage: i, cancel: l, isRunning: c } = G(), u = q(), m = gt(), {
837
- segments: k,
838
- trailingInput: g,
868
+ const { sendMessage: i, cancel: l, isRunning: o, isReady: c } = Q(), u = J(), m = yt(), {
869
+ segments: g,
870
+ trailingInput: x,
839
871
  mentionQuery: T,
840
- filteredItems: M,
841
- pickerIndex: P,
842
- setTrailingInput: S,
843
- handleKeyDown: w,
844
- selectItem: B,
845
- removeChip: b,
846
- buildSubmission: A,
847
- clear: N
848
- } = Ht(a), E = ["mast-chat-input", "mast-mention-input", t].filter(Boolean).join(" "), I = k.length > 0 || g.trim().length > 0, h = !c && I, p = T !== null && M.length > 0, x = p ? `${m}-${P}` : void 0, d = () => {
849
- if (!h) return;
850
- const { prompt: o, displayText: y } = A();
851
- y.trim() && (i(o, y), N());
852
- }, f = (o) => {
853
- w(o) || o.key === "Enter" && !o.shiftKey && (o.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());
854
886
  };
855
- return /* @__PURE__ */ v(
887
+ return /* @__PURE__ */ I(
856
888
  "form",
857
889
  {
858
890
  "data-mast-chat-input": !0,
859
- className: E,
860
- onSubmit: (o) => {
861
- o.preventDefault(), d();
891
+ className: w,
892
+ onSubmit: (k) => {
893
+ k.preventDefault(), h();
862
894
  },
863
895
  children: [
864
896
  /* @__PURE__ */ e("label", { className: "mast-chat-input-label mast-visually-hidden", htmlFor: "mast-chat-input-field", children: "Message" }),
865
- /* @__PURE__ */ v("div", { className: "mast-mention-input-field", children: [
866
- p && /* @__PURE__ */ e(
867
- Wt,
897
+ /* @__PURE__ */ I("div", { className: "mast-mention-input-field", children: [
898
+ d && /* @__PURE__ */ e(
899
+ qt,
868
900
  {
869
- items: M,
870
- activeIndex: P,
871
- onSelect: B,
901
+ items: A,
902
+ activeIndex: D,
903
+ onSelect: b,
872
904
  idPrefix: m,
873
905
  renderItem: a.renderItem
874
906
  }
875
907
  ),
876
- /* @__PURE__ */ v("div", { className: "mast-mention-input-content", children: [
877
- k.map((o) => /* @__PURE__ */ v(rt, { children: [
878
- o.text && /* @__PURE__ */ e("span", { className: "mast-mention-segment-text", children: o.text }),
879
- a.renderChip ? a.renderChip(o.item, () => b(o.item.id)) : /* @__PURE__ */ v("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: [
880
912
  "@",
881
- o.item.label,
913
+ k.item.label,
882
914
  /* @__PURE__ */ e(
883
915
  "button",
884
916
  {
885
917
  type: "button",
886
918
  className: "mast-mention-chip-remove",
887
- "aria-label": `Remove reference to ${o.item.label}`,
888
- onClick: () => b(o.item.id),
919
+ "aria-label": `Remove reference to ${k.item.label}`,
920
+ onClick: () => y(k.item.id),
889
921
  children: "×"
890
922
  }
891
923
  )
892
924
  ] })
893
- ] }, o.item.id)),
925
+ ] }, k.item.id)),
894
926
  /* @__PURE__ */ e(
895
927
  "textarea",
896
928
  {
897
929
  id: "mast-chat-input-field",
898
930
  className: "mast-chat-input-textarea mast-mention-input-textarea",
899
- value: g,
900
- placeholder: k.length === 0 ? n : "",
901
- rows: ut(g),
902
- disabled: c,
903
- onChange: (o) => S(o.target.value),
904
- 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,
905
937
  role: "combobox",
906
- "aria-expanded": p,
907
- "aria-controls": p ? `${m}-listbox` : void 0,
938
+ "aria-expanded": d,
939
+ "aria-controls": d ? `${m}-listbox` : void 0,
908
940
  "aria-autocomplete": "list",
909
- "aria-activedescendant": x
941
+ "aria-activedescendant": p
910
942
  }
911
943
  )
912
944
  ] })
913
945
  ] }),
914
- c ? /* @__PURE__ */ e(
946
+ o ? /* @__PURE__ */ e(
915
947
  "button",
916
948
  {
917
949
  type: "button",
@@ -926,7 +958,7 @@ function Zt({
926
958
  type: "submit",
927
959
  className: "mast-chat-input-send",
928
960
  "aria-label": "Send",
929
- disabled: !h,
961
+ disabled: !v,
930
962
  children: r ?? u.send
931
963
  }
932
964
  )
@@ -934,86 +966,113 @@ function Zt({
934
966
  }
935
967
  );
936
968
  }
937
- function Xt({ entry: t, className: n, renderToolCall: r, renderMessage: s }) {
938
- return t.role === "user" ? /* @__PURE__ */ e(Ut, { entry: t, className: n }) : /* @__PURE__ */ e(
939
- Vt,
969
+ function se({
970
+ entry: t,
971
+ className: n,
972
+ renderToolCall: r,
973
+ renderApproval: s,
974
+ renderMessage: a,
975
+ getToolLabel: i
976
+ }) {
977
+ return t.role === "user" ? /* @__PURE__ */ e(Ft, { entry: t, className: n }) : /* @__PURE__ */ e(
978
+ Ht,
940
979
  {
941
980
  entry: t,
942
981
  className: n,
943
982
  renderToolCall: r,
944
- renderMessage: s
983
+ renderApproval: s,
984
+ renderMessage: a,
985
+ getToolLabel: i
945
986
  }
946
987
  );
947
988
  }
948
- const Yt = 80;
949
- function te({ className: t, renderToolCall: n, renderMessage: r }) {
950
- const { messages: s } = G(), a = C(null), i = vt({
951
- count: s.length,
952
- getScrollElement: () => a.current,
953
- estimateSize: () => Yt,
989
+ const re = 80;
990
+ function ae({
991
+ className: t,
992
+ renderToolCall: n,
993
+ renderApproval: r,
994
+ renderMessage: s,
995
+ getToolLabel: a
996
+ }) {
997
+ const { messages: i } = Q(), l = R(null), o = St({
998
+ count: i.length,
999
+ getScrollElement: () => l.current,
1000
+ estimateSize: () => re,
954
1001
  overscan: 4
955
- }), l = s.length > 0 ? s[s.length - 1] : void 0, c = (l == null ? void 0 : l.text.length) ?? 0;
956
- Q(() => {
957
- s.length !== 0 && i.scrollToIndex(s.length - 1, { align: "end" });
958
- }, [s.length, c, i]);
959
- const u = i.getTotalSize(), m = i.getVirtualItems(), k = ["mast-message-list", t].filter(Boolean).join(" ");
960
- return /* @__PURE__ */ e("div", { ref: a, "data-mast-message-list": !0, className: k, role: "log", "aria-live": "polite", children: /* @__PURE__ */ e("div", { style: { height: `${u}px`, position: "relative", width: "100%" }, children: m.map((g) => {
961
- const T = s[g.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];
962
1009
  return /* @__PURE__ */ e(
963
1010
  "div",
964
1011
  {
965
- "data-index": g.index,
966
- ref: i.measureElement,
1012
+ "data-index": T.index,
1013
+ ref: o.measureElement,
967
1014
  style: {
968
1015
  position: "absolute",
969
1016
  top: 0,
970
1017
  left: 0,
971
1018
  width: "100%",
972
- transform: `translateY(${g.start}px)`
1019
+ transform: `translateY(${T.start}px)`
973
1020
  },
974
1021
  children: /* @__PURE__ */ e(
975
- Xt,
1022
+ se,
976
1023
  {
977
- entry: T,
1024
+ entry: A,
978
1025
  renderToolCall: n,
979
- renderMessage: r
1026
+ renderApproval: r,
1027
+ renderMessage: s,
1028
+ getToolLabel: a
980
1029
  }
981
1030
  )
982
1031
  },
983
- T.id
1032
+ A.id
984
1033
  );
985
1034
  }) }) });
986
1035
  }
987
- function ie({
1036
+ function de({
988
1037
  theme: t,
989
1038
  className: n,
990
1039
  renderToolCall: r,
991
- renderMessage: s,
992
- inputPlaceholder: a,
993
- mentions: i
1040
+ renderApproval: s,
1041
+ renderMessage: a,
1042
+ getToolLabel: i,
1043
+ inputPlaceholder: l,
1044
+ mentions: o
994
1045
  }) {
995
- const l = ["mast-conversation-panel", n].filter(Boolean).join(" ");
996
- return /* @__PURE__ */ v("div", { "data-mast-root": !0, "data-mast-theme": t, className: l, children: [
997
- /* @__PURE__ */ e(te, { renderToolCall: r, renderMessage: s }),
998
- /* @__PURE__ */ e(Jt, { 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 })
999
1058
  ] });
1000
1059
  }
1001
1060
  export {
1002
- ae as AgentProvider,
1003
- Vt as AssistantMessage,
1004
- Jt as ChatInput,
1005
- ie as ConversationPanel,
1006
- Mt as INLINE_APPROVAL,
1007
- jt as InlineApproval,
1008
- Xt as MessageItem,
1009
- te as MessageList,
1010
- lt as ThinkingBlock,
1011
- ot as ToolCallBlock,
1012
- Ut as UserMessage,
1013
- Ot as buildInlineMentionPrompt,
1014
- zt as extractMentionQuery,
1015
- Ft as removeMentionTrigger,
1016
- G as useAgent,
1017
- xt as useAgentStream,
1018
- Ht 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
1019
1078
  };