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