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