super-agent-sdk 1.0.3 → 1.0.5

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/widget.mjs CHANGED
@@ -1,875 +1,1572 @@
1
- import q, { useState as I, useRef as R, useCallback as y, useEffect as A, createContext as Z, useContext as Q, useMemo as ee } from "react";
2
- import { createRoot as ae } from "react-dom/client";
3
- import { jsx as a, jsxs as x, Fragment as te } from "react/jsx-runtime";
4
- function se(t) {
5
- const { sdk: e, sessionId: l, onSessionCreated: r, onStreamStart: s, onStreamEnd: i, onError: c, onMessageSend: n } = t, [o, f] = I([]), [p, m] = I("ready"), [v, b] = I(null), h = R(null), g = R(!1), u = R(l);
6
- u.current = l;
7
- const d = y((z) => {
1
+ import Y, { useState as T, useRef as _, useCallback as N, useEffect as B, createContext as ie, useMemo as V, useContext as oe } from "react";
2
+ import { createRoot as le } from "react-dom/client";
3
+ import { jsx as e, jsxs as d, Fragment as q } from "react/jsx-runtime";
4
+ function ce(a) {
5
+ const { sdk: t, sessionId: s, onSessionCreated: r, onStreamStart: n, onStreamEnd: o, onError: i, onMessageSend: l } = a, [c, p] = T([]), [f, u] = T("ready"), [h, v] = T(null), k = _(null), g = _(!1), b = _(s);
6
+ b.current = s;
7
+ const m = N((M) => {
8
8
  if (g.current) return;
9
- g.current = !0, n == null || n(z);
9
+ g.current = !0, l == null || l(M);
10
10
  const O = {
11
11
  id: `user_${Date.now()}`,
12
12
  role: "user",
13
- parts: [{ type: "text", content: z }],
13
+ parts: [{ type: "text", content: M }],
14
14
  timestamp: Date.now()
15
- }, S = `assistant_${Date.now()}`, G = {
16
- id: S,
15
+ }, y = `assistant_${Date.now()}`, L = {
16
+ id: y,
17
17
  role: "assistant",
18
18
  parts: [],
19
19
  timestamp: Date.now()
20
20
  };
21
- f((T) => [...T, O, G]), m("submitted"), b(null);
22
- const F = (T) => {
23
- let H = "", E = "", D = [], W = !1;
24
- const B = () => {
25
- const k = [...D];
26
- if (H) {
27
- const $ = k.findIndex((L) => L.type === "thinking");
28
- $ >= 0 ? k[$] = { type: "thinking", content: H } : k.unshift({ type: "thinking", content: H });
29
- }
21
+ p((S) => [...S, O, L]), u("submitted"), v(null);
22
+ const $ = (S) => {
23
+ let E = "", A = "", H = [], z = !1;
24
+ const P = () => {
25
+ const w = [...H];
30
26
  if (E) {
31
- const $ = k.findLastIndex((L) => L.type === "text");
32
- $ >= 0 ? k[$] = { type: "text", content: E } : k.push({ type: "text", content: E });
27
+ const W = w.findIndex((R) => R.type === "thinking");
28
+ W >= 0 ? w[W] = { type: "thinking", content: E } : w.unshift({ type: "thinking", content: E });
29
+ }
30
+ if (A) {
31
+ const W = w.findLastIndex((R) => R.type === "text");
32
+ W >= 0 ? w[W] = { type: "text", content: A } : w.push({ type: "text", content: A });
33
33
  }
34
- f(
35
- ($) => $.map((L) => L.id === S ? { ...L, parts: k } : L)
34
+ p(
35
+ (W) => W.map((R) => R.id === y ? { ...R, parts: w } : R)
36
36
  );
37
37
  };
38
- h.current = e.chat({
39
- sessionId: T,
40
- message: z,
38
+ k.current = t.chat({
39
+ sessionId: S,
40
+ message: M,
41
41
  stream: !0,
42
- onMessage: (k) => {
43
- switch (W || (W = !0, m("streaming")), k.type) {
42
+ onMessage: (w) => {
43
+ switch (z || (z = !0, u("streaming")), w.type) {
44
44
  case "thinking":
45
- H += k.content;
45
+ E += w.content;
46
46
  break;
47
47
  case "ai":
48
- E += k.content;
48
+ A += w.content;
49
49
  break;
50
50
  case "tool_call":
51
- D.push({
51
+ H.push({
52
52
  type: "tool_call",
53
- toolName: k.toolName,
54
- toolCallId: k.toolCallId,
55
- args: k.args ?? "{}"
53
+ toolName: w.toolName,
54
+ toolCallId: w.toolCallId,
55
+ args: w.args ?? "{}"
56
56
  });
57
57
  break;
58
58
  case "tool_result":
59
- D.push({
59
+ H.push({
60
60
  type: "tool_result",
61
- toolName: k.toolName ?? "",
62
- toolCallId: k.toolCallId,
63
- content: k.content
64
- }), E && (D.push({ type: "text", content: E }), E = "");
61
+ toolName: w.toolName ?? "",
62
+ toolCallId: w.toolCallId,
63
+ content: w.content,
64
+ artifacts: w.artifacts,
65
+ renderMode: w.renderMode,
66
+ html: w.html
67
+ }), A && (H.push({ type: "text", content: A }), A = "");
68
+ break;
69
+ case "interrupt":
70
+ w.interrupt && H.push({
71
+ type: "interrupt",
72
+ interrupt: w.interrupt,
73
+ resolved: !1
74
+ });
65
75
  break;
66
76
  }
67
- B();
77
+ P();
68
78
  },
69
- onDone: (k) => {
70
- (E || D.length > 0 || H) && B(), k.sessionId && k.sessionId !== u.current && (r == null || r(k.sessionId)), i == null || i(k.sessionId || T), m("ready"), g.current = !1, h.current = null;
79
+ onDone: (w) => {
80
+ (A || H.length > 0 || E) && P(), w.messageId && p(
81
+ (W) => W.map((R) => R.id === y ? { ...R, id: w.messageId } : R)
82
+ ), w.sessionId && w.sessionId !== b.current && (r == null || r(w.sessionId)), o == null || o(w.sessionId || S), u("ready"), g.current = !1, k.current = null;
71
83
  },
72
- onError: (k) => {
73
- D.push({ type: "error", content: k.message }), B(), b(k), m("error"), c == null || c(k), g.current = !1, h.current = null;
84
+ onError: (w) => {
85
+ H.push({ type: "error", content: w.message }), P(), v(w), u("error"), i == null || i(w), g.current = !1, k.current = null;
74
86
  }
75
- }), s == null || s(T);
87
+ }), n == null || n(S);
76
88
  };
77
- u.current ? F(u.current) : e.createSession().then((T) => {
78
- u.current = T, r == null || r(T), F(T);
79
- }).catch((T) => {
80
- b(T instanceof Error ? T : new Error(String(T))), m("error"), c == null || c(T instanceof Error ? T : new Error(String(T))), g.current = !1;
89
+ b.current ? $(b.current) : t.createSession().then((S) => {
90
+ b.current = S, r == null || r(S), $(S);
91
+ }).catch((S) => {
92
+ v(S instanceof Error ? S : new Error(String(S))), u("error"), i == null || i(S instanceof Error ? S : new Error(String(S))), g.current = !1;
81
93
  });
82
- }, [e, r, s, i, c, n]), w = y(() => {
83
- var z;
84
- (z = h.current) == null || z.abort(), h.current = null, m("ready"), g.current = !1;
85
- }, []), N = y(() => {
94
+ }, [t, r, n, o, i, l]), x = N(() => {
95
+ var M;
96
+ (M = k.current) == null || M.abort(), k.current = null, u("ready"), g.current = !1;
97
+ }, []), I = N(() => {
86
98
  if (g.current) return;
87
- const z = o.findLastIndex((S) => S.role === "user");
88
- if (z < 0) return;
89
- const O = o[z].parts.filter((S) => S.type === "text").map((S) => S.content).join("");
90
- f((S) => S.slice(0, z)), d(O);
91
- }, [o, d]);
92
- return { messages: o, status: p, error: v, sendMessage: d, stop: w, regenerate: N, setMessages: f };
99
+ const M = c.findLastIndex((y) => y.role === "user");
100
+ if (M < 0) return;
101
+ const O = c[M].parts.filter((y) => y.type === "text").map((y) => y.content).join("");
102
+ p((y) => y.slice(0, M)), m(O);
103
+ }, [c, m]), D = N((M, O) => {
104
+ p(
105
+ (z) => z.map((P) => ({
106
+ ...P,
107
+ parts: P.parts.map(
108
+ (w) => w.type === "interrupt" && w.interrupt.interruptId === M ? { ...w, resolved: !0, response: O } : w
109
+ )
110
+ }))
111
+ );
112
+ const y = b.current;
113
+ if (!y) return;
114
+ const L = `assistant_${Date.now()}`, $ = {
115
+ id: L,
116
+ role: "assistant",
117
+ parts: [],
118
+ timestamp: Date.now()
119
+ };
120
+ p((z) => [...z, $]), u("streaming");
121
+ let S = "", E = "", A = [];
122
+ const H = () => {
123
+ const z = [...A];
124
+ if (S) {
125
+ const P = z.findIndex((w) => w.type === "thinking");
126
+ P >= 0 ? z[P] = { type: "thinking", content: S } : z.unshift({ type: "thinking", content: S });
127
+ }
128
+ if (E) {
129
+ const P = z.findLastIndex((w) => w.type === "text");
130
+ P >= 0 ? z[P] = { type: "text", content: E } : z.push({ type: "text", content: E });
131
+ }
132
+ p(
133
+ (P) => P.map((w) => w.id === L ? { ...w, parts: z } : w)
134
+ );
135
+ };
136
+ t.respondInterrupt(
137
+ M,
138
+ y,
139
+ O,
140
+ (z) => {
141
+ switch (z.type) {
142
+ case "thinking":
143
+ S += z.content;
144
+ break;
145
+ case "ai":
146
+ E += z.content;
147
+ break;
148
+ case "tool_call":
149
+ A.push({
150
+ type: "tool_call",
151
+ toolName: z.toolName,
152
+ toolCallId: z.toolCallId,
153
+ args: z.args ?? "{}"
154
+ });
155
+ break;
156
+ case "tool_result":
157
+ A.push({
158
+ type: "tool_result",
159
+ toolName: z.toolName ?? "",
160
+ toolCallId: z.toolCallId,
161
+ content: z.content,
162
+ artifacts: z.artifacts,
163
+ renderMode: z.renderMode,
164
+ html: z.html
165
+ }), E && (A.push({ type: "text", content: E }), E = "");
166
+ break;
167
+ case "interrupt":
168
+ z.interrupt && A.push({ type: "interrupt", interrupt: z.interrupt, resolved: !1 });
169
+ break;
170
+ case "done":
171
+ u("ready");
172
+ break;
173
+ }
174
+ H();
175
+ },
176
+ (z) => {
177
+ A.push({ type: "error", content: z.message }), H(), v(z), u("error"), i == null || i(z);
178
+ }
179
+ ).catch((z) => {
180
+ i == null || i(z instanceof Error ? z : new Error(String(z))), u("error");
181
+ });
182
+ }, [t, i]);
183
+ return { messages: c, status: f, error: h, sendMessage: m, stop: x, regenerate: I, setMessages: p, respondToInterrupt: D };
93
184
  }
94
- const _ = "sa_active_conversation";
95
- function K() {
185
+ const X = "sa_active_conversation";
186
+ function J() {
96
187
  try {
97
- return localStorage.getItem(_);
188
+ return localStorage.getItem(X);
98
189
  } catch {
99
190
  return null;
100
191
  }
101
192
  }
102
- function re(t) {
193
+ function de(a) {
103
194
  try {
104
- t ? localStorage.setItem(_, t) : localStorage.removeItem(_);
195
+ a ? localStorage.setItem(X, a) : localStorage.removeItem(X);
105
196
  } catch {
106
197
  }
107
198
  }
108
- function ne(t) {
109
- const { sdk: e, onConversationChange: l } = t, [r, s] = I([]), [i, c] = I(
110
- () => K()
111
- ), [n, o] = I(!1), f = R(!0);
112
- A(() => () => {
113
- f.current = !1;
199
+ function pe(a) {
200
+ const { sdk: t, onConversationChange: s } = a, [r, n] = T([]), [o, i] = T(
201
+ () => J()
202
+ ), [l, c] = T(!1), p = _(!0);
203
+ B(() => () => {
204
+ p.current = !1;
114
205
  }, []);
115
- const p = y((d) => {
116
- c(d), re(d), d && (l == null || l(d));
117
- }, [l]), m = y(async () => {
118
- o(!0);
206
+ const f = N((m) => {
207
+ i(m), de(m), m && (s == null || s(m));
208
+ }, [s]), u = N(async () => {
209
+ c(!0);
119
210
  try {
120
- const d = await e.listConversations({ page: 1, size: 100 });
121
- if (!f.current) return;
122
- s(d.items);
123
- const w = K();
124
- w && !d.items.find((N) => N.sessionId === w) && p(null);
211
+ const m = await t.listConversations({ page: 1, size: 100 });
212
+ if (!p.current) return;
213
+ n(m.items);
214
+ const x = J();
215
+ x && !m.items.find((I) => I.sessionId === x) && f(null);
125
216
  } catch {
126
217
  } finally {
127
- f.current && o(!1);
218
+ p.current && c(!1);
128
219
  }
129
- }, [e, p]), v = y(async (d) => (p(d), await e.getMessages(d)), [e, p]), b = y(() => {
130
- p(null);
131
- }, [p]), h = y(async (d) => {
132
- await e.deleteConversation(d), s((w) => w.filter((N) => N.sessionId !== d)), i === d && p(null);
133
- }, [e, i, p]), g = y(async (d, w) => {
134
- await e.renameConversation(d, w), s(
135
- (N) => N.map((z) => z.sessionId === d ? { ...z, title: w } : z)
220
+ }, [t, f]), h = N(async (m) => (f(m), await t.getMessages(m)), [t, f]), v = N(() => {
221
+ f(null);
222
+ }, [f]), k = N(async (m) => {
223
+ await t.deleteConversation(m), n((x) => x.filter((I) => I.sessionId !== m)), o === m && f(null);
224
+ }, [t, o, f]), g = N(async (m, x) => {
225
+ await t.renameConversation(m, x), n(
226
+ (I) => I.map((D) => D.sessionId === m ? { ...D, title: x } : D)
136
227
  );
137
- }, [e]), { enabled: u = !0 } = t;
138
- return A(() => {
139
- u && m();
140
- }, [u, m]), {
228
+ }, [t]), { enabled: b = !0 } = a;
229
+ return B(() => {
230
+ b && u();
231
+ }, [b, u]), {
141
232
  conversations: r,
142
- activeConversationId: i,
143
- loading: n,
144
- loadConversations: m,
145
- switchConversation: v,
146
- newConversation: b,
147
- deleteConversation: h,
233
+ activeConversationId: o,
234
+ loading: l,
235
+ loadConversations: u,
236
+ switchConversation: h,
237
+ newConversation: v,
238
+ deleteConversation: k,
148
239
  renameConversation: g,
149
- setActiveConversationId: p
240
+ setActiveConversationId: f
150
241
  };
151
242
  }
152
- const V = Z(null);
153
- function P() {
154
- const t = Q(V);
155
- if (!t) throw new Error("useChatContext must be used within ChatProvider");
243
+ function Q(a) {
244
+ return !a && a !== 0 ? "" : a < 1024 ? `${a} B` : a < 1024 * 1024 ? `${(a / 1024).toFixed(1)} KB` : `${(a / 1024 / 1024).toFixed(1)} MB`;
245
+ }
246
+ function ee(a) {
247
+ return a === "pdf" ? "PDF" : a === "docx" ? "DOC" : a === "html" ? "HTM" : a.slice(0, 3).toUpperCase() || "FILE";
248
+ }
249
+ function ae(a) {
250
+ if (!a) return [];
251
+ const t = [];
252
+ for (const s of a)
253
+ s.type === "file" && s.data && t.push({
254
+ id: s.data.id ?? "",
255
+ type: s.data.fileType ?? s.data.type ?? "",
256
+ filename: s.data.name ?? s.data.filename ?? "",
257
+ url: s.data.url ?? "",
258
+ mime: s.data.mime,
259
+ size: s.data.size,
260
+ summary: s.data.summary
261
+ });
156
262
  return t;
157
263
  }
158
- function U({ sdk: t, hooks: e, children: l }) {
159
- const [r, s] = I(!1), [i, c] = I(!1);
160
- A(() => {
161
- t.getToken().then(() => {
162
- c(!0);
264
+ async function U(a) {
265
+ try {
266
+ const t = await fetch(a.url);
267
+ if (!t.ok) throw new Error(`HTTP ${t.status}`);
268
+ const s = await t.blob(), r = URL.createObjectURL(s), n = document.createElement("a");
269
+ n.href = r, n.download = a.filename, document.body.appendChild(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(r), 4e3);
270
+ } catch {
271
+ const t = document.createElement("a");
272
+ t.href = a.url, t.download = a.filename, t.target = "_blank", document.body.appendChild(t), t.click(), t.remove();
273
+ }
274
+ }
275
+ const te = ie(null);
276
+ function F() {
277
+ const a = oe(te);
278
+ if (!a) throw new Error("useChatContext must be used within ChatProvider");
279
+ return a;
280
+ }
281
+ function G({ sdk: a, hooks: t, children: s }) {
282
+ const [r, n] = T(!1), [o, i] = T(!1), [l, c] = T(null), [p, f] = T(!1);
283
+ B(() => {
284
+ a.getToken().then(() => {
285
+ f(!0);
163
286
  }).catch(() => {
164
- c(!0);
287
+ f(!0);
165
288
  });
166
- }, [t]);
167
- const n = ne({
168
- sdk: t,
169
- onConversationChange: e == null ? void 0 : e.onConversationChange,
170
- enabled: i
171
- }), o = se({
172
- sdk: t,
173
- sessionId: n.activeConversationId,
174
- onSessionCreated: (h) => {
175
- n.setActiveConversationId(h), n.loadConversations();
289
+ }, [a]);
290
+ const u = pe({
291
+ sdk: a,
292
+ onConversationChange: t == null ? void 0 : t.onConversationChange,
293
+ enabled: p
294
+ }), h = ce({
295
+ sdk: a,
296
+ sessionId: u.activeConversationId,
297
+ onSessionCreated: (y) => {
298
+ u.setActiveConversationId(y), u.loadConversations();
176
299
  },
177
- onStreamStart: e == null ? void 0 : e.onStreamStart,
178
- onStreamEnd: (h) => {
179
- var g;
180
- (g = e == null ? void 0 : e.onStreamEnd) == null || g.call(e, h), n.loadConversations();
300
+ onStreamStart: t == null ? void 0 : t.onStreamStart,
301
+ onStreamEnd: (y) => {
302
+ var L;
303
+ (L = t == null ? void 0 : t.onStreamEnd) == null || L.call(t, y), u.loadConversations();
181
304
  },
182
- onError: e == null ? void 0 : e.onError,
183
- onMessageSend: e == null ? void 0 : e.onMessageSend
184
- }), f = y(async (h) => {
185
- const g = await n.switchConversation(h);
186
- o.setMessages(g), s(!1);
187
- }, [n, o]), p = y(() => {
188
- n.newConversation(), o.setMessages([]), s(!1);
189
- }, [n, o]), m = y(async (h) => {
190
- await n.deleteConversation(h), n.activeConversationId === h && o.setMessages([]);
191
- }, [n, o]);
192
- A(() => {
193
- n.activeConversationId && o.messages.length === 0 && t.getMessages(n.activeConversationId).then((h) => {
194
- o.setMessages(h);
305
+ onError: t == null ? void 0 : t.onError,
306
+ onMessageSend: t == null ? void 0 : t.onMessageSend
307
+ }), v = N(async (y) => {
308
+ const L = await u.switchConversation(y);
309
+ h.setMessages(L), n(!1);
310
+ }, [u, h]), k = N(() => {
311
+ u.newConversation(), h.setMessages([]), n(!1);
312
+ }, [u, h]), g = N(async (y) => {
313
+ await u.deleteConversation(y), u.activeConversationId === y && h.setMessages([]);
314
+ }, [u, h]);
315
+ B(() => {
316
+ u.activeConversationId && h.messages.length === 0 && a.getMessages(u.activeConversationId).then((y) => {
317
+ h.setMessages(y);
195
318
  }).catch(() => {
196
319
  });
197
320
  }, []);
198
- const v = y(() => {
199
- s((h) => !h);
200
- }, []), b = {
201
- status: o.status,
202
- error: o.error,
203
- messages: o.messages,
204
- conversations: n.conversations,
205
- activeConversationId: n.activeConversationId,
321
+ const b = N(() => {
322
+ n((y) => !y);
323
+ }, []), m = N(() => {
324
+ i((y) => !y), c((y) => null);
325
+ }, []), x = N((y) => {
326
+ c(y), i(!0);
327
+ }, []), I = V(() => {
328
+ const y = /* @__PURE__ */ new Set(), L = [];
329
+ for (const $ of h.messages)
330
+ for (const S of $.parts)
331
+ if (S.type === "tool_result" && S.artifacts)
332
+ for (const E of ae(S.artifacts)) {
333
+ const A = E.id || `${E.url}:${E.filename}`;
334
+ y.has(A) || (y.add(A), L.push(E));
335
+ }
336
+ return L;
337
+ }, [h.messages]), D = N((y, L, $) => {
338
+ a.feedback(y, L, $).catch(() => {
339
+ });
340
+ }, [a]), M = N((y) => {
341
+ a.cancelFeedback(y).catch(() => {
342
+ });
343
+ }, [a]), O = V(() => ({
344
+ status: h.status,
345
+ error: h.error,
346
+ messages: h.messages,
347
+ conversations: u.conversations,
348
+ activeConversationId: u.activeConversationId,
206
349
  isThreadListOpen: r,
207
- sendMessage: o.sendMessage,
208
- stop: o.stop,
209
- regenerate: o.regenerate,
210
- switchConversation: f,
211
- newConversation: p,
212
- deleteConversation: m,
213
- renameConversation: n.renameConversation,
214
- toggleThreadList: v,
215
- feedback: (h, g) => {
216
- t.feedback(h, g);
217
- }
218
- };
219
- return /* @__PURE__ */ a(V.Provider, { value: b, children: l });
350
+ isArtifactDrawerOpen: o,
351
+ allArtifacts: I,
352
+ activePreviewArtifact: l,
353
+ sendMessage: h.sendMessage,
354
+ stop: h.stop,
355
+ regenerate: h.regenerate,
356
+ switchConversation: v,
357
+ newConversation: k,
358
+ deleteConversation: g,
359
+ renameConversation: u.renameConversation,
360
+ toggleThreadList: b,
361
+ toggleArtifactDrawer: m,
362
+ openArtifactPreview: x,
363
+ feedback: D,
364
+ cancelFeedback: M,
365
+ respondToInterrupt: h.respondToInterrupt
366
+ }), [
367
+ h.status,
368
+ h.error,
369
+ h.messages,
370
+ h.sendMessage,
371
+ h.stop,
372
+ h.regenerate,
373
+ h.respondToInterrupt,
374
+ u.conversations,
375
+ u.activeConversationId,
376
+ u.renameConversation,
377
+ r,
378
+ o,
379
+ I,
380
+ l,
381
+ v,
382
+ k,
383
+ g,
384
+ b,
385
+ m,
386
+ x,
387
+ D,
388
+ M
389
+ ]);
390
+ return /* @__PURE__ */ e(te.Provider, { value: O, children: s });
220
391
  }
221
- function C({ name: t, size: e = 16, color: l = "currentColor", className: r, style: s }) {
222
- return /* @__PURE__ */ a(
392
+ function C({ name: a, size: t = 16, color: s = "currentColor", className: r, style: n }) {
393
+ return /* @__PURE__ */ e(
223
394
  "svg",
224
395
  {
225
396
  className: r,
226
- style: { width: e, height: e, fill: l, verticalAlign: "middle", ...s },
397
+ style: { width: t, height: t, fill: s, verticalAlign: "middle", ...n },
227
398
  "aria-hidden": "true",
228
- children: /* @__PURE__ */ a("use", { href: `#icon-${t}` })
399
+ children: /* @__PURE__ */ e("use", { href: `#icon-${a}` })
229
400
  }
230
401
  );
231
402
  }
232
- function ie({ isOpen: t, onClick: e }) {
233
- return /* @__PURE__ */ a("button", { className: `sa-trigger ${t ? "sa-trigger-open" : ""}`, onClick: e, children: t ? /* @__PURE__ */ a(C, { name: "x", size: 24, color: "#fff" }) : /* @__PURE__ */ a(C, { name: "message-square", size: 24, color: "#fff" }) });
403
+ function fe({ isOpen: a, onClick: t }) {
404
+ return /* @__PURE__ */ e("button", { className: `sa-trigger ${a ? "sa-trigger-open" : ""}`, onClick: t, children: a ? /* @__PURE__ */ e(C, { name: "x", size: 24, color: "#fff" }) : /* @__PURE__ */ e(C, { name: "message-square", size: 24, color: "#fff" }) });
234
405
  }
235
- function oe({ title: t, onClose: e, onToggleThreadList: l, showClose: r = !0 }) {
236
- return /* @__PURE__ */ x("div", { className: "sa-header", children: [
237
- /* @__PURE__ */ x("div", { className: "sa-header-left", children: [
238
- /* @__PURE__ */ a("div", { className: "sa-header-avatar", children: "A" }),
239
- /* @__PURE__ */ x("div", { className: "sa-header-info", children: [
240
- /* @__PURE__ */ a("div", { className: "sa-header-title", children: t }),
241
- /* @__PURE__ */ a("div", { className: "sa-header-status", children: "● Online" })
406
+ function ue({ title: a, onClose: t, onToggleThreadList: s, showClose: r = !0, artifactCount: n = 0, onToggleArtifactDrawer: o }) {
407
+ return /* @__PURE__ */ d("div", { className: "sa-header", children: [
408
+ /* @__PURE__ */ d("div", { className: "sa-header-left", children: [
409
+ /* @__PURE__ */ e("div", { className: "sa-header-avatar", children: "A" }),
410
+ /* @__PURE__ */ d("div", { className: "sa-header-info", children: [
411
+ /* @__PURE__ */ e("div", { className: "sa-header-title", children: a }),
412
+ /* @__PURE__ */ e("div", { className: "sa-header-status", children: "● Online" })
242
413
  ] })
243
414
  ] }),
244
- /* @__PURE__ */ x("div", { className: "sa-header-actions", children: [
245
- /* @__PURE__ */ a("button", { className: "sa-header-btn", onClick: l, title: "会话列表", children: /* @__PURE__ */ a(C, { name: "menu", size: 16 }) }),
246
- r && /* @__PURE__ */ a("button", { className: "sa-header-btn", onClick: e, title: "关闭", children: /* @__PURE__ */ a(C, { name: "x", size: 16 }) })
415
+ /* @__PURE__ */ d("div", { className: "sa-header-actions", children: [
416
+ n > 0 && o && /* @__PURE__ */ d("button", { className: "sa-header-btn sa-header-btn-artifact", onClick: o, title: "会话产物", children: [
417
+ /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
418
+ /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
419
+ /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
420
+ ] }),
421
+ /* @__PURE__ */ e("span", { children: "产物" })
422
+ ] }),
423
+ /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: s, title: "会话列表", children: /* @__PURE__ */ e(C, { name: "menu", size: 16 }) }),
424
+ r && /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: t, title: "关闭", children: /* @__PURE__ */ e(C, { name: "x", size: 16 }) })
247
425
  ] })
248
426
  ] });
249
427
  }
250
- function le(t) {
251
- const e = /* @__PURE__ */ new Date(), l = new Date(e.getFullYear(), e.getMonth(), e.getDate()).getTime(), r = l - 6 * 864e5, s = [], i = [], c = [];
252
- for (const o of t) {
253
- const f = new Date(o.updateTime).getTime();
254
- f >= l ? s.push(o) : f >= r ? i.push(o) : c.push(o);
255
- }
256
- const n = [];
257
- return s.length && n.push({ label: "今天", items: s }), i.length && n.push({ label: "最近 7 天", items: i }), c.length && n.push({ label: "更早", items: c }), n;
428
+ function me(a) {
429
+ const t = /* @__PURE__ */ new Date(), s = new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime(), r = s - 6 * 864e5, n = [], o = [], i = [];
430
+ for (const c of a) {
431
+ const p = new Date(c.updateTime).getTime();
432
+ p >= s ? n.push(c) : p >= r ? o.push(c) : i.push(c);
433
+ }
434
+ const l = [];
435
+ return n.length && l.push({ label: "今天", items: n }), o.length && l.push({ label: "最近 7 天", items: o }), i.length && l.push({ label: "更早", items: i }), l;
258
436
  }
259
- function ce() {
437
+ function he() {
260
438
  const {
261
- conversations: t,
262
- activeConversationId: e,
263
- switchConversation: l,
439
+ conversations: a,
440
+ activeConversationId: t,
441
+ switchConversation: s,
264
442
  newConversation: r,
265
- deleteConversation: s,
266
- renameConversation: i,
267
- isThreadListOpen: c,
268
- toggleThreadList: n
269
- } = P(), [o, f] = I(null), [p, m] = I(""), v = y((g, u) => {
270
- f(g), m(u ?? "");
271
- }, []), b = y((g) => {
272
- p.trim() && i(g, p.trim()), f(null);
273
- }, [p, i]), h = ee(() => le(t), [t]);
274
- return c ? /* @__PURE__ */ x(te, { children: [
275
- /* @__PURE__ */ a("div", { className: "sa-thread-list-overlay", onClick: n }),
276
- /* @__PURE__ */ x("div", { className: "sa-thread-list", children: [
277
- /* @__PURE__ */ x("div", { className: "sa-thread-list-header", children: [
278
- /* @__PURE__ */ a("span", { className: "sa-thread-list-title", children: "会话记录" }),
279
- /* @__PURE__ */ x("button", { className: "sa-thread-list-new", onClick: r, children: [
280
- /* @__PURE__ */ a(C, { name: "plus", size: 14 }),
443
+ deleteConversation: n,
444
+ renameConversation: o,
445
+ isThreadListOpen: i,
446
+ toggleThreadList: l
447
+ } = F(), [c, p] = T(null), [f, u] = T(""), h = N((g, b) => {
448
+ p(g), u(b ?? "");
449
+ }, []), v = N((g) => {
450
+ f.trim() && o(g, f.trim()), p(null);
451
+ }, [f, o]), k = V(() => me(a), [a]);
452
+ return i ? /* @__PURE__ */ d(q, { children: [
453
+ /* @__PURE__ */ e("div", { className: "sa-thread-list-overlay", onClick: l }),
454
+ /* @__PURE__ */ d("div", { className: "sa-thread-list", children: [
455
+ /* @__PURE__ */ d("div", { className: "sa-thread-list-header", children: [
456
+ /* @__PURE__ */ e("span", { className: "sa-thread-list-title", children: "会话记录" }),
457
+ /* @__PURE__ */ d("button", { className: "sa-thread-list-new", onClick: r, children: [
458
+ /* @__PURE__ */ e(C, { name: "plus", size: 14 }),
281
459
  " 新会话"
282
460
  ] })
283
461
  ] }),
284
- /* @__PURE__ */ x("div", { className: "sa-thread-list-items", children: [
285
- t.length === 0 && /* @__PURE__ */ a("div", { className: "sa-thread-list-empty", children: "暂无会话" }),
286
- h.map((g) => /* @__PURE__ */ x("div", { className: "sa-thread-group", children: [
287
- /* @__PURE__ */ a("div", { className: "sa-thread-group-label", children: g.label }),
288
- g.items.map((u) => /* @__PURE__ */ x(
462
+ /* @__PURE__ */ d("div", { className: "sa-thread-list-items", children: [
463
+ a.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-empty", children: "暂无会话" }),
464
+ k.map((g) => /* @__PURE__ */ d("div", { className: "sa-thread-group", children: [
465
+ /* @__PURE__ */ e("div", { className: "sa-thread-group-label", children: g.label }),
466
+ g.items.map((b) => /* @__PURE__ */ d(
289
467
  "div",
290
468
  {
291
- className: `sa-thread-item ${u.sessionId === e ? "active" : ""}`,
292
- onClick: () => l(u.sessionId),
469
+ className: `sa-thread-item ${b.sessionId === t ? "active" : ""}`,
470
+ onClick: () => s(b.sessionId),
293
471
  children: [
294
- o === u.sessionId ? /* @__PURE__ */ a(
472
+ c === b.sessionId ? /* @__PURE__ */ e(
295
473
  "input",
296
474
  {
297
475
  className: "sa-thread-item-edit",
298
- value: p,
299
- onChange: (d) => m(d.target.value),
300
- onBlur: () => b(u.sessionId),
301
- onKeyDown: (d) => {
302
- d.key === "Enter" && b(u.sessionId), d.key === "Escape" && f(null);
476
+ value: f,
477
+ onChange: (m) => u(m.target.value),
478
+ onBlur: () => v(b.sessionId),
479
+ onKeyDown: (m) => {
480
+ m.key === "Enter" && v(b.sessionId), m.key === "Escape" && p(null);
303
481
  },
304
- onClick: (d) => d.stopPropagation(),
482
+ onClick: (m) => m.stopPropagation(),
305
483
  autoFocus: !0
306
484
  }
307
- ) : /* @__PURE__ */ a(
485
+ ) : /* @__PURE__ */ e(
308
486
  "span",
309
487
  {
310
488
  className: "sa-thread-item-title",
311
- onDoubleClick: (d) => {
312
- d.stopPropagation(), v(u.sessionId, u.title);
489
+ onDoubleClick: (m) => {
490
+ m.stopPropagation(), h(b.sessionId, b.title);
313
491
  },
314
- children: u.title || "新会话"
492
+ children: b.title || "新会话"
315
493
  }
316
494
  ),
317
- /* @__PURE__ */ a(
495
+ /* @__PURE__ */ e(
318
496
  "button",
319
497
  {
320
498
  className: "sa-thread-item-delete",
321
- onClick: (d) => {
322
- d.stopPropagation(), s(u.sessionId);
499
+ onClick: (m) => {
500
+ m.stopPropagation(), n(b.sessionId);
323
501
  },
324
502
  title: "删除",
325
- children: /* @__PURE__ */ a(C, { name: "trash2", size: 14 })
503
+ children: /* @__PURE__ */ e(C, { name: "trash2", size: 14 })
326
504
  }
327
505
  )
328
506
  ]
329
507
  },
330
- u.sessionId
508
+ b.sessionId
331
509
  ))
332
510
  ] }, g.label))
333
511
  ] })
334
512
  ] })
335
513
  ] }) : null;
336
514
  }
337
- function de(t) {
338
- const e = R(null), l = R(!1), r = R(0), s = y(() => {
339
- const c = e.current;
340
- if (!c) return;
341
- const { scrollTop: n, scrollHeight: o, clientHeight: f } = c, p = o - n - f < 40;
342
- n < r.current && !p && (l.current = !0), p && (l.current = !1), r.current = n;
515
+ function ge(a) {
516
+ const t = _(null), s = _(!1), r = _(0), n = N(() => {
517
+ const i = t.current;
518
+ if (!i) return;
519
+ const { scrollTop: l, scrollHeight: c, clientHeight: p } = i, f = c - l - p < 40;
520
+ l < r.current && !f && (s.current = !0), f && (s.current = !1), r.current = l;
343
521
  }, []);
344
- A(() => {
345
- const c = e.current;
346
- if (c)
347
- return c.addEventListener("scroll", s, { passive: !0 }), () => c.removeEventListener("scroll", s);
348
- }, [s]), A(() => {
349
- if (l.current) return;
350
- const c = e.current;
351
- c && requestAnimationFrame(() => {
352
- c.scrollTop = c.scrollHeight;
522
+ B(() => {
523
+ const i = t.current;
524
+ if (i)
525
+ return i.addEventListener("scroll", n, { passive: !0 }), () => i.removeEventListener("scroll", n);
526
+ }, [n]), B(() => {
527
+ if (s.current) return;
528
+ const i = t.current;
529
+ i && requestAnimationFrame(() => {
530
+ i.scrollTop = i.scrollHeight;
353
531
  });
354
- }, t);
355
- const i = y(() => {
356
- l.current = !1;
357
- const c = e.current;
358
- c && (c.scrollTop = c.scrollHeight);
532
+ }, a);
533
+ const o = N(() => {
534
+ s.current = !1;
535
+ const i = t.current;
536
+ i && (i.scrollTop = i.scrollHeight);
359
537
  }, []);
360
- return { containerRef: e, scrollToBottom: i };
538
+ return { containerRef: t, scrollToBottom: o };
361
539
  }
362
- function M(t) {
363
- return t.value++;
540
+ function j(a) {
541
+ return a.value++;
364
542
  }
365
- function j(t, e) {
366
- const l = [], r = [], s = () => {
367
- r.length > 0 && (l.push(r.join("")), r.length = 0);
543
+ function K(a, t) {
544
+ const s = [], r = [], n = () => {
545
+ r.length > 0 && (s.push(r.join("")), r.length = 0);
368
546
  };
369
- let i = 0;
370
- for (; i < t.length; ) {
371
- const c = t[i];
372
- if (c === "`") {
373
- const n = t.indexOf("`", i + 1);
374
- if (n !== -1) {
375
- s(), l.push(
376
- /* @__PURE__ */ a("code", { className: "sa-inline-code", children: t.slice(i + 1, n) }, M(e))
377
- ), i = n + 1;
547
+ let o = 0;
548
+ for (; o < a.length; ) {
549
+ const i = a[o];
550
+ if (i === "`") {
551
+ const l = a.indexOf("`", o + 1);
552
+ if (l !== -1) {
553
+ n(), s.push(
554
+ /* @__PURE__ */ e("code", { className: "sa-inline-code", children: a.slice(o + 1, l) }, j(t))
555
+ ), o = l + 1;
378
556
  continue;
379
557
  }
380
- } else if (c === "*" && t[i + 1] === "*") {
381
- const n = t.indexOf("**", i + 2);
382
- if (n !== -1) {
383
- s(), l.push(
384
- /* @__PURE__ */ a("strong", { children: j(t.slice(i + 2, n), e) }, M(e))
385
- ), i = n + 2;
558
+ } else if (i === "*" && a[o + 1] === "*") {
559
+ const l = a.indexOf("**", o + 2);
560
+ if (l !== -1) {
561
+ n(), s.push(
562
+ /* @__PURE__ */ e("strong", { children: K(a.slice(o + 2, l), t) }, j(t))
563
+ ), o = l + 2;
386
564
  continue;
387
565
  }
388
- } else if (c === "*") {
389
- const n = t.indexOf("*", i + 1);
390
- if (n !== -1) {
391
- s(), l.push(
392
- /* @__PURE__ */ a("em", { children: j(t.slice(i + 1, n), e) }, M(e))
393
- ), i = n + 1;
566
+ } else if (i === "*") {
567
+ const l = a.indexOf("*", o + 1);
568
+ if (l !== -1) {
569
+ n(), s.push(
570
+ /* @__PURE__ */ e("em", { children: K(a.slice(o + 1, l), t) }, j(t))
571
+ ), o = l + 1;
394
572
  continue;
395
573
  }
396
- } else if (c === "[") {
397
- const n = t.indexOf("]", i + 1);
398
- if (n !== -1 && t[n + 1] === "(") {
399
- const o = t.indexOf(")", n + 2);
400
- if (o !== -1) {
401
- const f = t.slice(i + 1, n), p = t.slice(n + 2, o);
402
- s(), l.push(
403
- /* @__PURE__ */ a(
574
+ } else if (i === "[") {
575
+ const l = a.indexOf("]", o + 1);
576
+ if (l !== -1 && a[l + 1] === "(") {
577
+ const c = a.indexOf(")", l + 2);
578
+ if (c !== -1) {
579
+ const p = a.slice(o + 1, l), f = a.slice(l + 2, c);
580
+ n(), s.push(
581
+ /* @__PURE__ */ e(
404
582
  "a",
405
583
  {
406
- href: p,
584
+ href: f,
407
585
  target: "_blank",
408
586
  rel: "noreferrer",
409
- children: j(f, e)
587
+ children: K(p, t)
410
588
  },
411
- M(e)
589
+ j(t)
412
590
  )
413
- ), i = o + 1;
591
+ ), o = c + 1;
414
592
  continue;
415
593
  }
416
594
  }
417
595
  }
418
- r.push(c), i++;
596
+ r.push(i), o++;
419
597
  }
420
- return s(), l;
598
+ return n(), s;
421
599
  }
422
- function pe(t, e) {
423
- const l = [], r = t.split(`
600
+ function xe(a, t) {
601
+ const s = [], r = a.split(`
424
602
  `);
425
- let s = 0;
426
- const i = (o) => o.trim() === "", c = (o) => /^#{1,6}\s+\S/.test(o.trim()), n = (o) => /^(?:[-*+]|\d+[.)])\s+\S/.test(o.trim());
427
- for (; s < r.length; ) {
428
- const o = r[s], f = o.trim();
429
- if (i(o)) {
430
- s++;
603
+ let n = 0;
604
+ const o = (c) => c.trim() === "", i = (c) => /^#{1,6}\s+\S/.test(c.trim()), l = (c) => /^(?:[-*+]|\d+[.)])\s+\S/.test(c.trim());
605
+ for (; n < r.length; ) {
606
+ const c = r[n], p = c.trim();
607
+ if (o(c)) {
608
+ n++;
431
609
  continue;
432
610
  }
433
- if (c(o)) {
434
- const m = f.match(/^(#{1,6})\s+(.*)$/);
435
- if (m) {
436
- const b = `h${Math.min(m[1].length, 6)}`;
437
- l.push(
438
- q.createElement(
439
- b,
440
- { key: M(e) },
441
- j(m[2], e)
611
+ if (i(c)) {
612
+ const u = p.match(/^(#{1,6})\s+(.*)$/);
613
+ if (u) {
614
+ const v = `h${Math.min(u[1].length, 6)}`;
615
+ s.push(
616
+ Y.createElement(
617
+ v,
618
+ { key: j(t) },
619
+ K(u[2], t)
442
620
  )
443
621
  );
444
622
  }
445
- s++;
623
+ n++;
446
624
  continue;
447
625
  }
448
- if (n(o)) {
449
- const m = /^\d+[.)]/.test(f), v = [];
450
- for (; s < r.length && n(r[s]); ) {
451
- const b = r[s].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);
452
- b && v.push(
453
- /* @__PURE__ */ a("li", { children: j(b[1], e) }, M(e))
454
- ), s++;
626
+ if (l(c)) {
627
+ const u = /^\d+[.)]/.test(p), h = [];
628
+ for (; n < r.length && l(r[n]); ) {
629
+ const v = r[n].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);
630
+ v && h.push(
631
+ /* @__PURE__ */ e("li", { children: K(v[1], t) }, j(t))
632
+ ), n++;
455
633
  }
456
- l.push(
457
- m ? /* @__PURE__ */ a("ol", { className: "sa-list", children: v }, M(e)) : /* @__PURE__ */ a("ul", { className: "sa-list", children: v }, M(e))
634
+ s.push(
635
+ u ? /* @__PURE__ */ e("ol", { className: "sa-list", children: h }, j(t)) : /* @__PURE__ */ e("ul", { className: "sa-list", children: h }, j(t))
458
636
  );
459
637
  continue;
460
638
  }
461
- const p = [];
462
- for (; s < r.length && !i(r[s]) && !c(r[s]) && !n(r[s]); )
463
- p.push(r[s]), s++;
464
- l.push(
465
- /* @__PURE__ */ a("p", { className: "sa-text-paragraph", children: j(p.join(" "), e) }, M(e))
639
+ const f = [];
640
+ for (; n < r.length && !o(r[n]) && !i(r[n]) && !l(r[n]); )
641
+ f.push(r[n]), n++;
642
+ s.push(
643
+ /* @__PURE__ */ e("p", { className: "sa-text-paragraph", children: K(f.join(" "), t) }, j(t))
466
644
  );
467
645
  }
468
- return l;
646
+ return s;
469
647
  }
470
- function fe(t) {
471
- const e = { value: 0 }, l = [], r = t.split("```");
472
- for (let s = 0; s < r.length; s++)
473
- if (s % 2 === 0)
474
- l.push(...pe(r[s], e));
475
- else if (r[s].trim() !== "") {
476
- let i = r[s].replace(/^\r?\n/, "");
477
- i = i.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/, ""), i = i.replace(/\r?\n$/, ""), l.push(
478
- /* @__PURE__ */ a("pre", { className: "sa-code-block", children: /* @__PURE__ */ a("code", { children: i }) }, M(e))
648
+ function be(a) {
649
+ const t = { value: 0 }, s = [], r = a.split("```");
650
+ for (let n = 0; n < r.length; n++)
651
+ if (n % 2 === 0)
652
+ s.push(...xe(r[n], t));
653
+ else if (r[n].trim() !== "") {
654
+ let o = r[n].replace(/^\r?\n/, "");
655
+ o = o.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/, ""), o = o.replace(/\r?\n$/, ""), s.push(
656
+ /* @__PURE__ */ e("pre", { className: "sa-code-block", children: /* @__PURE__ */ e("code", { children: o }) }, j(t))
479
657
  );
480
658
  }
481
- return l;
659
+ return s;
482
660
  }
483
- function he({ content: t }) {
484
- return /* @__PURE__ */ a("div", { className: "sa-text-part", children: fe(t) });
661
+ function ve({ content: a }) {
662
+ return /* @__PURE__ */ e("div", { className: "sa-text-part", children: be(a) });
485
663
  }
486
- function ue({ content: t }) {
487
- const [e, l] = I(!1);
488
- return /* @__PURE__ */ x("div", { className: "sa-thinking-part", onClick: () => l(!e), children: [
489
- /* @__PURE__ */ x("div", { className: "sa-thinking-header", children: [
490
- /* @__PURE__ */ a("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ a(C, { name: "brain", size: 14 }) }),
491
- /* @__PURE__ */ a("span", { className: "sa-thinking-label", children: "思考过程" }),
492
- /* @__PURE__ */ a("span", { className: `sa-thinking-arrow ${e ? "expanded" : ""}`, children: /* @__PURE__ */ a(C, { name: "chevron-right", size: 12 }) })
664
+ function we({ content: a }) {
665
+ const [t, s] = T(!1);
666
+ return /* @__PURE__ */ d("div", { className: "sa-thinking-part", onClick: () => s(!t), children: [
667
+ /* @__PURE__ */ d("div", { className: "sa-thinking-header", children: [
668
+ /* @__PURE__ */ e("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ e(C, { name: "brain", size: 14 }) }),
669
+ /* @__PURE__ */ e("span", { className: "sa-thinking-label", children: "思考过程" }),
670
+ /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${t ? "expanded" : ""}`, children: /* @__PURE__ */ e(C, { name: "chevron-right", size: 12 }) })
493
671
  ] }),
494
- e && /* @__PURE__ */ a("div", { className: "sa-thinking-content", children: t })
672
+ t && /* @__PURE__ */ e("div", { className: "sa-thinking-content", children: a })
495
673
  ] });
496
674
  }
497
- function me({ toolName: t, toolCallId: e, args: l }) {
498
- const [r, s] = I(!1);
499
- let i = l;
675
+ function ye({ toolName: a, toolCallId: t, args: s }) {
676
+ const [r, n] = T(!1);
677
+ let o = s;
500
678
  try {
501
- i = JSON.stringify(JSON.parse(l), null, 2);
679
+ o = JSON.stringify(JSON.parse(s), null, 2);
502
680
  } catch {
503
681
  }
504
- return /* @__PURE__ */ x("div", { className: "sa-tool-call-part", children: [
505
- /* @__PURE__ */ x("div", { className: "sa-tool-call-header", onClick: () => s(!r), children: [
506
- /* @__PURE__ */ a("span", { className: "sa-tool-icon", children: /* @__PURE__ */ a(C, { name: "zap", size: 14 }) }),
507
- /* @__PURE__ */ x("span", { className: "sa-tool-name", children: [
682
+ return /* @__PURE__ */ d("div", { className: "sa-tool-call-part", children: [
683
+ /* @__PURE__ */ d("div", { className: "sa-tool-call-header", onClick: () => n(!r), children: [
684
+ /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(C, { name: "zap", size: 14 }) }),
685
+ /* @__PURE__ */ d("span", { className: "sa-tool-name", children: [
508
686
  "调用工具: ",
509
- t
687
+ a
510
688
  ] }),
511
- /* @__PURE__ */ a("span", { className: `sa-thinking-arrow ${r ? "expanded" : ""}`, children: /* @__PURE__ */ a(C, { name: "chevron-right", size: 12 }) })
689
+ /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${r ? "expanded" : ""}`, children: /* @__PURE__ */ e(C, { name: "chevron-right", size: 12 }) })
690
+ ] }),
691
+ r && /* @__PURE__ */ e("pre", { className: "sa-tool-args", children: o })
692
+ ] });
693
+ }
694
+ function ke({ html: a }) {
695
+ const [t, s] = T(null);
696
+ return B(() => {
697
+ let r = !1;
698
+ return import("./purify.es-C-6FFqDW.js").then((n) => {
699
+ r || s(n.default.sanitize(a, { FORCE_BODY: !0 }));
700
+ }), () => {
701
+ r = !0;
702
+ };
703
+ }, [a]), t === null ? null : /* @__PURE__ */ e("div", { className: "sa-tool-result-html", children: /* @__PURE__ */ e("iframe", { srcDoc: t, className: "sa-tool-result-html-iframe", sandbox: "", title: "HTML 产物" }) });
704
+ }
705
+ function Ce({ toolName: a, content: t, artifacts: s, renderMode: r, html: n, artifactPreview: o }) {
706
+ const { openArtifactPreview: i } = F(), l = ae(s);
707
+ return /* @__PURE__ */ d("div", { className: "sa-tool-result-part", children: [
708
+ /* @__PURE__ */ d("div", { className: "sa-tool-result-header", children: [
709
+ /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(C, { name: "circle-check", size: 14, color: "#10b981" }) }),
710
+ /* @__PURE__ */ e("span", { className: "sa-tool-result-label", children: a || "工具返回" })
711
+ ] }),
712
+ r === "html" && n ? /* @__PURE__ */ e(ke, { html: n }) : t ? /* @__PURE__ */ e("div", { className: "sa-tool-result-content", children: t }) : null,
713
+ l.length > 0 && /* @__PURE__ */ e("ul", { className: "sa-artifact-file-list", role: "list", children: l.map((c, p) => /* @__PURE__ */ d(
714
+ "li",
715
+ {
716
+ className: "sa-artifact-file-card",
717
+ onClick: o ? () => i(c) : void 0,
718
+ onKeyDown: o ? (f) => {
719
+ (f.key === "Enter" || f.key === " ") && (f.preventDefault(), i(c));
720
+ } : void 0,
721
+ tabIndex: o ? 0 : void 0,
722
+ role: o ? "button" : void 0,
723
+ "aria-label": o ? `预览 ${c.filename}` : void 0,
724
+ style: o ? { cursor: "pointer" } : void 0,
725
+ children: [
726
+ /* @__PURE__ */ e("div", { className: "sa-artifact-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(c.type) }) }),
727
+ /* @__PURE__ */ d("div", { className: "sa-artifact-file-info", children: [
728
+ /* @__PURE__ */ e("span", { className: "sa-artifact-file-name", children: c.filename }),
729
+ c.size != null && /* @__PURE__ */ e("span", { className: "sa-artifact-file-size", children: Q(c.size) })
730
+ ] }),
731
+ o && /* @__PURE__ */ e(
732
+ "button",
733
+ {
734
+ className: "sa-artifact-file-download",
735
+ title: "下载",
736
+ "aria-label": `下载 ${c.filename}`,
737
+ onClick: (f) => {
738
+ f.stopPropagation(), U(c);
739
+ },
740
+ children: /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ e("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3" }) })
741
+ }
742
+ )
743
+ ]
744
+ },
745
+ c.id || `art-${p}`
746
+ )) })
747
+ ] });
748
+ }
749
+ function Ne({ content: a, onRetry: t }) {
750
+ return /* @__PURE__ */ d("div", { className: "sa-error-part", children: [
751
+ /* @__PURE__ */ d("div", { className: "sa-error-content", children: [
752
+ /* @__PURE__ */ e("span", { className: "sa-error-icon", children: /* @__PURE__ */ e(C, { name: "triangle-alert", size: 14 }) }),
753
+ /* @__PURE__ */ e("span", { children: a })
754
+ ] }),
755
+ t && /* @__PURE__ */ e("button", { className: "sa-error-retry", onClick: t, children: "重试" })
756
+ ] });
757
+ }
758
+ function ze({ interrupt: a, onRespond: t }) {
759
+ var o, i;
760
+ const s = a.options, r = (typeof (s == null ? void 0 : s[0]) == "string" ? s[0] : (o = s == null ? void 0 : s[0]) == null ? void 0 : o.label) || "确认", n = (typeof (s == null ? void 0 : s[1]) == "string" ? s[1] : (i = s == null ? void 0 : s[1]) == null ? void 0 : i.label) || "取消";
761
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
762
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
763
+ /* @__PURE__ */ e(C, { name: "circle-alert", size: 16, color: "#f59e0b" }),
764
+ /* @__PURE__ */ e("span", { children: a.content })
765
+ ] }),
766
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
767
+ /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", onClick: () => t({ action: "confirm" }), children: [
768
+ /* @__PURE__ */ e(C, { name: "check", size: 14 }),
769
+ " ",
770
+ r
771
+ ] }),
772
+ /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "cancel" }), children: [
773
+ /* @__PURE__ */ e(C, { name: "x", size: 14 }),
774
+ " ",
775
+ n
776
+ ] })
777
+ ] })
778
+ ] });
779
+ }
780
+ function Ie({ interrupt: a, onRespond: t }) {
781
+ var l, c, p, f;
782
+ const s = a.options, r = (typeof (s == null ? void 0 : s[0]) == "string" ? s[0] : (l = s == null ? void 0 : s[0]) == null ? void 0 : l.label) || "批准", n = (typeof (s == null ? void 0 : s[1]) == "string" ? s[1] : (c = s == null ? void 0 : s[1]) == null ? void 0 : c.label) || "拒绝", o = (typeof (s == null ? void 0 : s[2]) == "string" ? s[2] : (p = s == null ? void 0 : s[2]) == null ? void 0 : p.label) || "跳过", i = ((f = a.metadata) == null ? void 0 : f.showSkip) !== !1;
783
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
784
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
785
+ /* @__PURE__ */ e(C, { name: "circle-alert", size: 16, color: "#f59e0b" }),
786
+ /* @__PURE__ */ e("span", { children: a.content })
787
+ ] }),
788
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
789
+ /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", onClick: () => t({ action: "approve" }), children: [
790
+ /* @__PURE__ */ e(C, { name: "check", size: 14 }),
791
+ " ",
792
+ r
793
+ ] }),
794
+ /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-danger", onClick: () => t({ action: "reject" }), children: [
795
+ /* @__PURE__ */ e(C, { name: "x", size: 14 }),
796
+ " ",
797
+ n
798
+ ] }),
799
+ i && /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "skip" }), children: [
800
+ /* @__PURE__ */ e(C, { name: "chevron-right", size: 14 }),
801
+ " ",
802
+ o
803
+ ] })
804
+ ] })
805
+ ] });
806
+ }
807
+ function Te(a) {
808
+ return typeof a == "string" ? { value: a, label: a } : a;
809
+ }
810
+ function Se({ interrupt: a, onRespond: t }) {
811
+ const s = (a.options ?? []).map(Te);
812
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
813
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
814
+ /* @__PURE__ */ e(C, { name: "list", size: 16, color: "#6366f1" }),
815
+ /* @__PURE__ */ e("span", { children: a.content })
816
+ ] }),
817
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: s.map((r) => /* @__PURE__ */ d(
818
+ "button",
819
+ {
820
+ className: `sa-interrupt-option ${r.danger ? "sa-interrupt-option-danger" : ""}`,
821
+ onClick: () => t({ action: "select", value: r.value }),
822
+ children: [
823
+ r.icon && /* @__PURE__ */ e(C, { name: r.icon, size: 14 }),
824
+ /* @__PURE__ */ e("span", { children: r.label }),
825
+ r.description && /* @__PURE__ */ e("span", { className: "sa-interrupt-option-desc", children: r.description })
826
+ ]
827
+ },
828
+ r.value
829
+ )) })
830
+ ] });
831
+ }
832
+ function Me(a) {
833
+ return typeof a == "string" ? { value: a, label: a } : a;
834
+ }
835
+ function De({ interrupt: a, onRespond: t }) {
836
+ const s = (a.options ?? []).map(Me), [r, n] = T(/* @__PURE__ */ new Set()), o = (i) => {
837
+ n((l) => {
838
+ const c = new Set(l);
839
+ return c.has(i) ? c.delete(i) : c.add(i), c;
840
+ });
841
+ };
842
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
843
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
844
+ /* @__PURE__ */ e(C, { name: "list-checks", size: 16, color: "#6366f1" }),
845
+ /* @__PURE__ */ e("span", { children: a.content })
512
846
  ] }),
513
- r && /* @__PURE__ */ a("pre", { className: "sa-tool-args", children: i })
847
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: s.map((i) => /* @__PURE__ */ d(
848
+ "button",
849
+ {
850
+ className: `sa-interrupt-option ${r.has(i.value) ? "sa-interrupt-option-selected" : ""}`,
851
+ onClick: () => o(i.value),
852
+ children: [
853
+ /* @__PURE__ */ e(C, { name: r.has(i.value) ? "square-check" : "square", size: 14 }),
854
+ /* @__PURE__ */ e("span", { children: i.label })
855
+ ]
856
+ },
857
+ i.value
858
+ )) }),
859
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
860
+ "button",
861
+ {
862
+ className: "sa-interrupt-btn sa-interrupt-btn-primary",
863
+ disabled: r.size === 0,
864
+ onClick: () => t({ action: "submit", value: Array.from(r) }),
865
+ children: [
866
+ /* @__PURE__ */ e(C, { name: "check", size: 14 }),
867
+ " 确认 (",
868
+ r.size,
869
+ ")"
870
+ ]
871
+ }
872
+ ) })
514
873
  ] });
515
874
  }
516
- function ge({ toolName: t, toolCallId: e, content: l }) {
517
- return /* @__PURE__ */ x("div", { className: "sa-tool-result-part", children: [
518
- /* @__PURE__ */ x("div", { className: "sa-tool-result-header", children: [
519
- /* @__PURE__ */ a("span", { className: "sa-tool-icon", children: /* @__PURE__ */ a(C, { name: "circle-check", size: 14, color: "#10b981" }) }),
520
- /* @__PURE__ */ a("span", { className: "sa-tool-result-label", children: t || "工具返回" })
875
+ function Le({ interrupt: a, onRespond: t }) {
876
+ const [s, r] = T(""), n = a.inputType ?? "text", o = n === "textarea", i = () => {
877
+ a.required && !s.trim() || t({ action: "submit", value: s.trim() });
878
+ };
879
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
880
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
881
+ /* @__PURE__ */ e(C, { name: "text-cursor-input", size: 16, color: "#6366f1" }),
882
+ /* @__PURE__ */ e("span", { children: a.content })
521
883
  ] }),
522
- /* @__PURE__ */ a("div", { className: "sa-tool-result-content", children: l })
884
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-input-area", children: o ? /* @__PURE__ */ e(
885
+ "textarea",
886
+ {
887
+ className: "sa-interrupt-textarea",
888
+ value: s,
889
+ onChange: (l) => r(l.target.value),
890
+ placeholder: a.placeholder,
891
+ maxLength: a.maxLength,
892
+ rows: 3
893
+ }
894
+ ) : /* @__PURE__ */ e(
895
+ "input",
896
+ {
897
+ className: "sa-interrupt-input",
898
+ type: n,
899
+ value: s,
900
+ onChange: (l) => r(l.target.value),
901
+ placeholder: a.placeholder,
902
+ maxLength: a.maxLength,
903
+ onKeyDown: (l) => l.key === "Enter" && i()
904
+ }
905
+ ) }),
906
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
907
+ "button",
908
+ {
909
+ className: "sa-interrupt-btn sa-interrupt-btn-primary",
910
+ disabled: a.required ? !s.trim() : !1,
911
+ onClick: i,
912
+ children: [
913
+ /* @__PURE__ */ e(C, { name: "check", size: 14 }),
914
+ " 提交"
915
+ ]
916
+ }
917
+ ) })
523
918
  ] });
524
919
  }
525
- function xe({ content: t, onRetry: e }) {
526
- return /* @__PURE__ */ x("div", { className: "sa-error-part", children: [
527
- /* @__PURE__ */ x("div", { className: "sa-error-content", children: [
528
- /* @__PURE__ */ a("span", { className: "sa-error-icon", children: /* @__PURE__ */ a(C, { name: "triangle-alert", size: 14 }) }),
529
- /* @__PURE__ */ a("span", { children: t })
920
+ function Ee({ interrupt: a, onRespond: t }) {
921
+ const s = a.fields ?? [], [r, n] = T(() => {
922
+ const c = {};
923
+ for (const p of s)
924
+ c[p.name] = p.defaultValue ?? "";
925
+ return c;
926
+ }), o = (c, p) => {
927
+ n((f) => ({ ...f, [c]: p }));
928
+ }, i = s.every((c) => !c.required || r[c.name]), l = () => {
929
+ i && t({ action: "submit", value: r });
930
+ };
931
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
932
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
933
+ /* @__PURE__ */ e(C, { name: "file-text", size: 16, color: "#6366f1" }),
934
+ /* @__PURE__ */ e("span", { children: a.content })
530
935
  ] }),
531
- e && /* @__PURE__ */ a("button", { className: "sa-error-retry", onClick: e, children: "重试" })
936
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-form", children: s.map((c) => /* @__PURE__ */ d("div", { className: "sa-interrupt-form-field", children: [
937
+ /* @__PURE__ */ d("label", { className: "sa-interrupt-form-label", children: [
938
+ c.label,
939
+ c.required && /* @__PURE__ */ e("span", { className: "sa-interrupt-form-required", children: "*" })
940
+ ] }),
941
+ Ae(c, r[c.name], (p) => o(c.name, p))
942
+ ] }, c.name)) }),
943
+ /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
944
+ /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", disabled: !i, onClick: l, children: [
945
+ /* @__PURE__ */ e(C, { name: "check", size: 14 }),
946
+ " 提交"
947
+ ] }),
948
+ /* @__PURE__ */ e("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "cancel" }), children: "取消" })
949
+ ] })
532
950
  ] });
533
951
  }
534
- function be({ message: t, onCopy: e, onRegenerate: l, onFeedback: r }) {
535
- const { status: s } = P(), [i, c] = I(null), [n, o] = I(!1);
536
- if (s !== "ready" && s !== "error") return null;
537
- const f = y(() => {
538
- e(), o(!0), setTimeout(() => o(!1), 2e3);
539
- }, [e]), p = y((m) => {
540
- const v = i === m ? null : m;
541
- c(v), v && (r == null || r(t.id, v));
542
- }, [i, t.id, r]);
543
- return /* @__PURE__ */ x("div", { className: "sa-action-bar", children: [
544
- /* @__PURE__ */ x("button", { className: "sa-action-btn", onClick: f, title: "复制", children: [
545
- /* @__PURE__ */ a(C, { name: n ? "circle-check" : "copy", size: 14 }),
952
+ function Ae(a, t, s) {
953
+ switch (a.type) {
954
+ case "textarea":
955
+ return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: t, onChange: (r) => s(r.target.value), placeholder: a.placeholder, rows: 3 });
956
+ case "select":
957
+ return /* @__PURE__ */ d("select", { className: "sa-interrupt-select", value: t, onChange: (r) => s(r.target.value), children: [
958
+ /* @__PURE__ */ e("option", { value: "", children: "请选择" }),
959
+ (a.options ?? []).map((r) => /* @__PURE__ */ e("option", { value: r, children: r }, r))
960
+ ] });
961
+ default:
962
+ return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: a.type, value: t, onChange: (r) => s(r.target.value), placeholder: a.placeholder });
963
+ }
964
+ }
965
+ function $e({ interrupt: a, resolved: t, response: s, onRespond: r }) {
966
+ if (t)
967
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-resolved", children: [
968
+ /* @__PURE__ */ e(C, { name: "circle-check", size: 14, color: "#10b981" }),
969
+ /* @__PURE__ */ e("span", { children: Pe(a.interruptType, s) })
970
+ ] });
971
+ switch (a.interruptType) {
972
+ case "confirm":
973
+ return /* @__PURE__ */ e(ze, { interrupt: a, onRespond: r });
974
+ case "approve":
975
+ return /* @__PURE__ */ e(Ie, { interrupt: a, onRespond: r });
976
+ case "select":
977
+ return /* @__PURE__ */ e(Se, { interrupt: a, onRespond: r });
978
+ case "multiSelect":
979
+ return /* @__PURE__ */ e(De, { interrupt: a, onRespond: r });
980
+ case "input":
981
+ return /* @__PURE__ */ e(Le, { interrupt: a, onRespond: r });
982
+ case "form":
983
+ return /* @__PURE__ */ e(Ee, { interrupt: a, onRespond: r });
984
+ default:
985
+ return /* @__PURE__ */ d("div", { className: "sa-interrupt-unknown", children: [
986
+ "未知的交互类型: ",
987
+ a.interruptType
988
+ ] });
989
+ }
990
+ }
991
+ function Pe(a, t) {
992
+ if (!t) return "已完成";
993
+ switch (t.action) {
994
+ case "confirm":
995
+ return "已确认";
996
+ case "cancel":
997
+ return "已取消";
998
+ case "select":
999
+ return `已选择: ${t.value}`;
1000
+ case "submit":
1001
+ return "已提交";
1002
+ case "approve":
1003
+ return "已批准";
1004
+ case "reject":
1005
+ return "已拒绝";
1006
+ case "skip":
1007
+ return "已跳过";
1008
+ default:
1009
+ return "已完成";
1010
+ }
1011
+ }
1012
+ const Oe = [
1013
+ { value: 1, label: "事实错误" },
1014
+ { value: 2, label: "逻辑问题" },
1015
+ { value: 3, label: "不相关" },
1016
+ { value: 4, label: "信息过时" },
1017
+ { value: 5, label: "冗长啰嗦" },
1018
+ { value: 6, label: "难以理解" }
1019
+ ];
1020
+ function Re({ message: a, onCopy: t, onRegenerate: s, onFeedback: r }) {
1021
+ const { status: n, feedback: o, cancelFeedback: i } = F(), [l, c] = T(null), [p, f] = T(!1), [u, h] = T(!1);
1022
+ if (n !== "ready" && n !== "error") return null;
1023
+ const v = N(() => {
1024
+ t(), f(!0), setTimeout(() => f(!1), 2e3);
1025
+ }, [t]), k = N(() => {
1026
+ l === "like" ? (c(null), i(a.id)) : (c("like"), h(!1), o(a.id, "like"), r == null || r(a.id, "like"));
1027
+ }, [l, a.id, o, i, r]), g = N(() => {
1028
+ l === "dislike" ? (c(null), h(!1), i(a.id)) : h(!0);
1029
+ }, [l, a.id, i]), b = N((m, x) => {
1030
+ c("dislike"), h(!1), o(a.id, "dislike", { reason: m, remark: x }), r == null || r(a.id, "dislike");
1031
+ }, [a.id, o, r]);
1032
+ return /* @__PURE__ */ d("div", { className: "sa-action-bar", children: [
1033
+ /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: v, title: "复制", children: [
1034
+ /* @__PURE__ */ e(C, { name: p ? "circle-check" : "copy", size: 14 }),
546
1035
  " ",
547
- n ? "已复制" : "复制"
1036
+ p ? "已复制" : "复制"
548
1037
  ] }),
549
- /* @__PURE__ */ x("button", { className: "sa-action-btn", onClick: l, title: "重新生成", children: [
550
- /* @__PURE__ */ a(C, { name: "refresh-cw", size: 14 }),
1038
+ /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: s, title: "重新生成", children: [
1039
+ /* @__PURE__ */ e(C, { name: "refresh-cw", size: 14 }),
551
1040
  " 重新生成"
552
1041
  ] }),
553
- /* @__PURE__ */ a("span", { className: "sa-action-divider" }),
554
- /* @__PURE__ */ a(
1042
+ /* @__PURE__ */ e("span", { className: "sa-action-divider" }),
1043
+ /* @__PURE__ */ e(
555
1044
  "button",
556
1045
  {
557
- className: `sa-action-btn ${i === "like" ? "sa-action-btn-active" : ""}`,
558
- onClick: () => p("like"),
1046
+ className: `sa-action-btn ${l === "like" ? "sa-action-btn-active" : ""}`,
1047
+ onClick: k,
559
1048
  title: "有用",
560
- children: /* @__PURE__ */ a(C, { name: "thumbs-up", size: 14 })
1049
+ "aria-label": "点赞",
1050
+ children: /* @__PURE__ */ e(C, { name: "thumbs-up", size: 14 })
561
1051
  }
562
1052
  ),
563
- /* @__PURE__ */ a(
1053
+ /* @__PURE__ */ e(
564
1054
  "button",
565
1055
  {
566
- className: `sa-action-btn ${i === "dislike" ? "sa-action-btn-active" : ""}`,
567
- onClick: () => p("dislike"),
1056
+ className: `sa-action-btn ${l === "dislike" ? "sa-action-btn-active" : ""}`,
1057
+ onClick: g,
568
1058
  title: "无用",
569
- children: /* @__PURE__ */ a(C, { name: "thumbs-down", size: 14 })
1059
+ "aria-label": "",
1060
+ children: /* @__PURE__ */ e(C, { name: "thumbs-down", size: 14 })
1061
+ }
1062
+ ),
1063
+ u && /* @__PURE__ */ e(
1064
+ Be,
1065
+ {
1066
+ onSubmit: b,
1067
+ onCancel: () => h(!1)
570
1068
  }
571
1069
  )
572
1070
  ] });
573
1071
  }
574
- function Y({ src: t, role: e }) {
575
- const l = e === "assistant" ? "A" : "U";
576
- return t ? t.startsWith("http") || t.startsWith("/") || t.startsWith("data:") ? /* @__PURE__ */ a("div", { className: `sa-avatar sa-avatar-${e}`, children: /* @__PURE__ */ a("img", { src: t, alt: e, style: { width: "100%", height: "100%", borderRadius: "inherit", objectFit: "cover" } }) }) : /* @__PURE__ */ a("div", { className: `sa-avatar sa-avatar-${e}`, children: t }) : /* @__PURE__ */ a("div", { className: `sa-avatar sa-avatar-${e}`, children: l });
1072
+ function Be({ onSubmit: a, onCancel: t }) {
1073
+ const [s, r] = T(void 0), [n, o] = T("");
1074
+ return /* @__PURE__ */ d("div", { className: "sa-dislike-panel", children: [
1075
+ /* @__PURE__ */ e("div", { className: "sa-dislike-panel-title", children: "请选择不满意的原因(可选)" }),
1076
+ /* @__PURE__ */ e("div", { className: "sa-dislike-reasons", children: Oe.map((i) => /* @__PURE__ */ e(
1077
+ "button",
1078
+ {
1079
+ className: `sa-dislike-reason-btn ${s === i.value ? "active" : ""}`,
1080
+ onClick: () => r(s === i.value ? void 0 : i.value),
1081
+ children: i.label
1082
+ },
1083
+ i.value
1084
+ )) }),
1085
+ /* @__PURE__ */ e(
1086
+ "textarea",
1087
+ {
1088
+ className: "sa-dislike-remark",
1089
+ placeholder: "补充描述(选填,≤500 字)",
1090
+ maxLength: 500,
1091
+ value: n,
1092
+ onChange: (i) => o(i.target.value),
1093
+ rows: 2
1094
+ }
1095
+ ),
1096
+ /* @__PURE__ */ d("div", { className: "sa-dislike-actions", children: [
1097
+ /* @__PURE__ */ e("button", { className: "sa-dislike-submit", onClick: () => a(s, n || void 0), children: "提交" }),
1098
+ /* @__PURE__ */ e("button", { className: "sa-dislike-cancel", onClick: t, children: "取消" })
1099
+ ] })
1100
+ ] });
1101
+ }
1102
+ function Z({ src: a, role: t }) {
1103
+ const s = t === "assistant" ? "A" : "U";
1104
+ return a ? a.startsWith("http") || a.startsWith("/") || a.startsWith("data:") ? /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${t}`, children: /* @__PURE__ */ e("img", { src: a, alt: t, style: { width: "100%", height: "100%", borderRadius: "inherit", objectFit: "cover" } }) }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${t}`, children: a }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${t}`, children: s });
577
1105
  }
578
- function ve({ message: t, isStreaming: e, isLast: l, slots: r, avatar: s }) {
579
- const { regenerate: i, feedback: c } = P(), n = y(() => {
580
- var d;
581
- const u = t.parts.filter((w) => w.type === "text").map((w) => w.content).join(`
1106
+ function He({ message: a, isStreaming: t, isLast: s, slots: r, avatar: n, artifactPreview: o }) {
1107
+ const { regenerate: i, feedback: l, respondToInterrupt: c } = F(), p = N(() => {
1108
+ var I;
1109
+ const x = a.parts.filter((D) => D.type === "text").map((D) => D.content).join(`
582
1110
  `);
583
- (d = navigator.clipboard) == null || d.writeText(u).catch(() => {
1111
+ (I = navigator.clipboard) == null || I.writeText(x).catch(() => {
584
1112
  });
585
- }, [t]), o = t.role === "user", f = r.Message;
586
- if (f)
587
- return /* @__PURE__ */ a(
588
- f,
1113
+ }, [a]), f = a.role === "user", u = r.Message;
1114
+ if (u)
1115
+ return /* @__PURE__ */ e(
1116
+ u,
589
1117
  {
590
- message: t,
591
- isStreaming: e,
592
- isLast: l,
593
- avatar: s,
1118
+ message: a,
1119
+ isStreaming: t,
1120
+ isLast: s,
1121
+ avatar: n,
594
1122
  slots: r,
595
- onCopy: n,
1123
+ onCopy: p,
596
1124
  onRegenerate: i,
597
- onFeedback: c
1125
+ onFeedback: l
598
1126
  }
599
1127
  );
600
- const p = r.TextPart ?? he, m = r.ThinkingPart ?? ue, v = r.ToolCallPart ?? me, b = r.ToolResultPart ?? ge, h = r.ErrorPart ?? xe, g = r.ActionBar ?? be;
601
- return /* @__PURE__ */ x("div", { className: `sa-message ${o ? "sa-message-user" : "sa-message-assistant"}`, children: [
602
- !o && /* @__PURE__ */ a(Y, { src: s == null ? void 0 : s.assistant, role: "assistant" }),
603
- /* @__PURE__ */ x("div", { className: "sa-message-body", children: [
604
- t.parts.map((u, d) => {
605
- switch (u.type) {
1128
+ const h = r.TextPart ?? ve, v = r.ThinkingPart ?? we, k = r.ToolCallPart ?? ye, g = r.ToolResultPart ?? Ce, b = r.ErrorPart ?? Ne, m = r.ActionBar ?? Re;
1129
+ return /* @__PURE__ */ d("div", { className: `sa-message ${f ? "sa-message-user" : "sa-message-assistant"}`, children: [
1130
+ !f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.assistant, role: "assistant" }),
1131
+ /* @__PURE__ */ d("div", { className: "sa-message-body", children: [
1132
+ a.parts.map((x, I) => {
1133
+ switch (x.type) {
606
1134
  case "text":
607
- return /* @__PURE__ */ a(p, { content: u.content }, d);
1135
+ return /* @__PURE__ */ e(h, { content: x.content }, I);
608
1136
  case "thinking":
609
- return /* @__PURE__ */ a(m, { content: u.content }, d);
1137
+ return /* @__PURE__ */ e(v, { content: x.content }, I);
610
1138
  case "tool_call":
611
- return /* @__PURE__ */ a(v, { toolName: u.toolName, toolCallId: u.toolCallId, args: u.args }, d);
1139
+ return /* @__PURE__ */ e(k, { toolName: x.toolName, toolCallId: x.toolCallId, args: x.args }, I);
612
1140
  case "tool_result":
613
- return /* @__PURE__ */ a(b, { toolName: u.toolName, toolCallId: u.toolCallId, content: u.content }, d);
1141
+ return /* @__PURE__ */ e(g, { toolName: x.toolName, toolCallId: x.toolCallId, content: x.content, artifacts: x.artifacts, renderMode: x.renderMode, html: x.html, artifactPreview: o }, I);
614
1142
  case "error":
615
- return /* @__PURE__ */ a(h, { content: u.content, onRetry: i }, d);
1143
+ return /* @__PURE__ */ e(b, { content: x.content, onRetry: i }, I);
1144
+ case "interrupt":
1145
+ return /* @__PURE__ */ e(
1146
+ $e,
1147
+ {
1148
+ interrupt: x.interrupt,
1149
+ resolved: x.resolved ?? !1,
1150
+ response: x.response,
1151
+ onRespond: (D) => c(x.interrupt.interruptId, D)
1152
+ },
1153
+ I
1154
+ );
616
1155
  default:
617
1156
  return null;
618
1157
  }
619
1158
  }),
620
- e && l && !o && /* @__PURE__ */ a("span", { className: "sa-streaming-cursor", children: "|" }),
621
- !o && !e && t.parts.length > 0 && /* @__PURE__ */ a(g, { message: t, onCopy: n, onRegenerate: i, onFeedback: c })
1159
+ t && s && !f && /* @__PURE__ */ e("span", { className: "sa-streaming-cursor", children: "|" }),
1160
+ !f && !t && a.parts.length > 0 && /* @__PURE__ */ e(m, { message: a, onCopy: p, onRegenerate: i, onFeedback: l })
622
1161
  ] }),
623
- o && /* @__PURE__ */ a(Y, { src: s == null ? void 0 : s.user, role: "user" })
1162
+ f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.user, role: "user" })
624
1163
  ] });
625
1164
  }
626
- function we({ message: t, suggestedPrompts: e, onPromptClick: l }) {
627
- return /* @__PURE__ */ x("div", { className: "sa-welcome", children: [
628
- /* @__PURE__ */ a("div", { className: "sa-welcome-icon", children: /* @__PURE__ */ a(C, { name: "sparkles", size: 40 }) }),
629
- /* @__PURE__ */ a("p", { className: "sa-welcome-message", children: t || "你好!有什么可以帮你的?" }),
630
- e && e.length > 0 && /* @__PURE__ */ a("div", { className: "sa-welcome-prompts", children: e.map((r, s) => /* @__PURE__ */ a(
1165
+ function je({ message: a, suggestedPrompts: t, onPromptClick: s }) {
1166
+ return /* @__PURE__ */ d("div", { className: "sa-welcome", children: [
1167
+ /* @__PURE__ */ e("div", { className: "sa-welcome-icon", children: /* @__PURE__ */ e(C, { name: "sparkles", size: 40 }) }),
1168
+ /* @__PURE__ */ e("p", { className: "sa-welcome-message", children: a || "你好!有什么可以帮你的?" }),
1169
+ t && t.length > 0 && /* @__PURE__ */ e("div", { className: "sa-welcome-prompts", children: t.map((r, n) => /* @__PURE__ */ e(
631
1170
  "button",
632
1171
  {
633
1172
  className: "sa-welcome-prompt",
634
- onClick: () => l(r),
1173
+ onClick: () => s(r),
635
1174
  children: r
636
1175
  },
637
- s
1176
+ n
638
1177
  )) })
639
1178
  ] });
640
1179
  }
641
- function J({ slots: t, welcomeMessage: e, suggestedPrompts: l, avatar: r }) {
642
- const { messages: s, status: i, sendMessage: c } = P(), { containerRef: n } = de([s]), o = i === "streaming", f = t.WelcomeScreen ?? we;
643
- return s.length === 0 ? /* @__PURE__ */ a("div", { className: "sa-thread", ref: n, children: /* @__PURE__ */ a(
1180
+ function re({ slots: a, welcomeMessage: t, suggestedPrompts: s, avatar: r, artifactPreview: n }) {
1181
+ const { messages: o, status: i, sendMessage: l } = F(), { containerRef: c } = ge([o]), p = i === "streaming", f = a.WelcomeScreen ?? je;
1182
+ return o.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: /* @__PURE__ */ e(
644
1183
  f,
645
1184
  {
646
- message: e,
647
- suggestedPrompts: l,
648
- onPromptClick: c
1185
+ message: t,
1186
+ suggestedPrompts: s,
1187
+ onPromptClick: l
649
1188
  }
650
- ) }) : /* @__PURE__ */ a("div", { className: "sa-thread", ref: n, children: s.map((p, m) => /* @__PURE__ */ a(
651
- ve,
1189
+ ) }) : /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: o.map((u, h) => /* @__PURE__ */ e(
1190
+ He,
652
1191
  {
653
- message: p,
654
- isStreaming: o,
655
- isLast: m === s.length - 1,
656
- slots: t,
657
- avatar: r
1192
+ message: u,
1193
+ isStreaming: p,
1194
+ isLast: h === o.length - 1,
1195
+ slots: a,
1196
+ avatar: r,
1197
+ artifactPreview: n
658
1198
  },
659
- p.id
1199
+ u.id
660
1200
  )) });
661
1201
  }
662
- function X() {
663
- const { status: t, sendMessage: e, stop: l } = P(), [r, s] = I(""), i = R(null), c = t === "streaming" || t === "submitted", n = y(() => {
664
- const p = r.trim();
665
- !p || c || (e(p), s(""), i.current && (i.current.style.height = "auto"));
666
- }, [r, c, e]), o = y((p) => {
667
- p.key === "Enter" && !p.shiftKey && (p.preventDefault(), n());
668
- }, [n]), f = y((p) => {
669
- s(p.target.value);
670
- const m = p.target;
671
- m.style.height = "auto", m.style.height = Math.min(m.scrollHeight, 120) + "px";
1202
+ function se() {
1203
+ const { status: a, sendMessage: t, stop: s } = F(), [r, n] = T(""), o = _(null), i = a === "streaming" || a === "submitted", l = N(() => {
1204
+ const f = r.trim();
1205
+ !f || i || (t(f), n(""), o.current && (o.current.style.height = "auto"));
1206
+ }, [r, i, t]), c = N((f) => {
1207
+ f.key === "Enter" && !f.shiftKey && (f.preventDefault(), l());
1208
+ }, [l]), p = N((f) => {
1209
+ n(f.target.value);
1210
+ const u = f.target;
1211
+ u.style.height = "auto", u.style.height = Math.min(u.scrollHeight, 120) + "px";
672
1212
  }, []);
673
- return /* @__PURE__ */ x("div", { className: "sa-composer", children: [
674
- /* @__PURE__ */ a(
1213
+ return /* @__PURE__ */ d("div", { className: "sa-composer", children: [
1214
+ /* @__PURE__ */ e(
675
1215
  "textarea",
676
1216
  {
677
- ref: i,
1217
+ ref: o,
678
1218
  className: "sa-composer-input",
679
1219
  value: r,
680
- onChange: f,
681
- onKeyDown: o,
1220
+ onChange: p,
1221
+ onKeyDown: c,
682
1222
  placeholder: "输入消息...",
683
1223
  rows: 1,
684
- disabled: t === "submitted"
1224
+ disabled: a === "submitted"
685
1225
  }
686
1226
  ),
687
- c ? /* @__PURE__ */ a("button", { className: "sa-composer-stop", onClick: l, title: "停止", children: /* @__PURE__ */ a(C, { name: "circle-stop", size: 16, color: "#fff" }) }) : /* @__PURE__ */ a(
1227
+ i ? /* @__PURE__ */ e("button", { className: "sa-composer-stop", onClick: s, title: "停止", children: /* @__PURE__ */ e(C, { name: "circle-stop", size: 16, color: "#fff" }) }) : /* @__PURE__ */ e(
688
1228
  "button",
689
1229
  {
690
1230
  className: "sa-composer-send",
691
- onClick: n,
1231
+ onClick: l,
692
1232
  disabled: !r.trim(),
693
1233
  title: "发送",
694
- children: /* @__PURE__ */ a(C, { name: "arrow-up", size: 16, color: "#fff" })
1234
+ children: /* @__PURE__ */ e(C, { name: "arrow-up", size: 16, color: "#fff" })
695
1235
  }
696
1236
  )
697
1237
  ] });
698
1238
  }
699
- function ye({ isOpen: t, onClose: e, title: l, slots: r, welcomeMessage: s, suggestedPrompts: i, avatar: c }) {
700
- const { status: n, sendMessage: o, stop: f, toggleThreadList: p, conversations: m, activeConversationId: v, switchConversation: b, newConversation: h, deleteConversation: g, renameConversation: u, isThreadListOpen: d } = P();
701
- if (!t) return null;
702
- const w = r.Header, N = r.Composer, z = r.ThreadList;
703
- return /* @__PURE__ */ x("div", { className: "sa-panel", children: [
704
- w ? /* @__PURE__ */ a(w, { title: l, onClose: e, onToggleThreadList: p }) : /* @__PURE__ */ a(oe, { title: l, onClose: e, onToggleThreadList: p }),
705
- z && d ? /* @__PURE__ */ a(
706
- z,
1239
+ function _e({ artifact: a }) {
1240
+ const [t, s] = Y.useState(null), [r, n] = Y.useState(!0), [o, i] = Y.useState(null);
1241
+ return Y.useEffect(() => {
1242
+ let l = !1;
1243
+ n(!0), i(null), s(null);
1244
+ async function c() {
1245
+ try {
1246
+ if (a.type === "pdf") {
1247
+ l || n(!1);
1248
+ return;
1249
+ }
1250
+ if (a.type === "html") {
1251
+ const p = await fetch(a.url);
1252
+ if (!p.ok) throw new Error(`HTTP ${p.status}`);
1253
+ const f = await p.text(), u = (await import("./purify.es-C-6FFqDW.js")).default;
1254
+ l || (s(u.sanitize(f, { FORCE_BODY: !0 })), n(!1));
1255
+ return;
1256
+ }
1257
+ if (a.type === "docx") {
1258
+ const p = await fetch(a.url);
1259
+ if (!p.ok) throw new Error(`HTTP ${p.status}`);
1260
+ const f = await p.arrayBuffer(), h = await (await import("./mammoth.browser-COPV53yV.js").then((k) => k.m)).convertToHtml({ arrayBuffer: f }), v = (await import("./purify.es-C-6FFqDW.js")).default;
1261
+ l || (s(v.sanitize(h.value, { FORCE_BODY: !0 })), n(!1));
1262
+ return;
1263
+ }
1264
+ l || (n(!1), i(`不支持预览「${a.type}」类型`));
1265
+ } catch (p) {
1266
+ l || (n(!1), i(p instanceof Error ? p.message : "加载失败"));
1267
+ }
1268
+ }
1269
+ return c(), () => {
1270
+ l = !0;
1271
+ };
1272
+ }, [a]), r ? /* @__PURE__ */ e("div", { className: "sa-drawer-preview-loading", children: "加载中" }) : o ? /* @__PURE__ */ d("div", { className: "sa-drawer-preview-error", children: [
1273
+ o,
1274
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn-sm", onClick: () => void U(a), children: "下载查看" })
1275
+ ] }) : a.type === "pdf" ? /* @__PURE__ */ e("iframe", { src: a.url, title: a.filename, className: "sa-drawer-preview-iframe", sandbox: "allow-scripts" }) : t !== null ? /* @__PURE__ */ e("iframe", { srcDoc: t, title: a.filename, className: "sa-drawer-preview-iframe", sandbox: "allow-same-origin" }) : null;
1276
+ }
1277
+ function ne({ artifacts: a, initialArtifact: t, onClose: s }) {
1278
+ const [r, n] = T(
1279
+ t ? { mode: "preview", artifact: t } : { mode: "list" }
1280
+ ), [o, i] = T(!1), l = _(null), [c, p] = T(340), f = _(null);
1281
+ B(() => {
1282
+ t && (l.current && (clearTimeout(l.current), l.current = null, i(!1)), n({ mode: "preview", artifact: t }));
1283
+ }, [t]);
1284
+ const u = N(() => {
1285
+ i(!0), l.current = setTimeout(() => {
1286
+ l.current = null, s();
1287
+ }, 240);
1288
+ }, [s]);
1289
+ B(() => () => {
1290
+ var g;
1291
+ l.current && clearTimeout(l.current), (g = f.current) == null || g.call(f);
1292
+ }, []);
1293
+ const h = N((g) => {
1294
+ n({ mode: "preview", artifact: g });
1295
+ }, []), v = N(() => {
1296
+ n({ mode: "list" });
1297
+ }, []);
1298
+ B(() => {
1299
+ const g = (b) => {
1300
+ b.key === "Escape" && u();
1301
+ };
1302
+ return document.addEventListener("keydown", g), () => document.removeEventListener("keydown", g);
1303
+ }, [u]);
1304
+ const k = N((g) => {
1305
+ g.preventDefault();
1306
+ const b = g.clientX, m = c, x = (D) => {
1307
+ const M = b - D.clientX;
1308
+ p(Math.max(240, Math.min(window.innerWidth * 0.7, m + M)));
1309
+ }, I = () => {
1310
+ document.removeEventListener("mousemove", x), document.removeEventListener("mouseup", I), document.body.style.cursor = "", document.body.style.userSelect = "", f.current = null;
1311
+ };
1312
+ document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", x), document.addEventListener("mouseup", I), f.current = I;
1313
+ }, [c]);
1314
+ return /* @__PURE__ */ d("div", { className: `sa-artifact-drawer ${o ? "sa-drawer-closing" : ""}`, style: { width: c }, children: [
1315
+ /* @__PURE__ */ e("div", { className: "sa-drawer-resize-handle", onMouseDown: k }),
1316
+ /* @__PURE__ */ d("div", { className: "sa-artifact-drawer-header", children: [
1317
+ r.mode === "preview" ? /* @__PURE__ */ d(q, { children: [
1318
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: v, title: "返回列表", "aria-label": "返回列表", children: /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ e("path", { d: "M15 18l-6-6 6-6" }) }) }),
1319
+ /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: r.artifact.filename })
1320
+ ] }) : /* @__PURE__ */ d(q, { children: [
1321
+ /* @__PURE__ */ d("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { flexShrink: 0 }, children: [
1322
+ /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
1323
+ /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
1324
+ ] }),
1325
+ /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: "会话产物" })
1326
+ ] }),
1327
+ /* @__PURE__ */ e("div", { style: { flex: 1 } }),
1328
+ r.mode === "preview" && /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: () => void U(r.artifact), title: "下载", "aria-label": "下载", children: /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ e("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3" }) }) }),
1329
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: u, title: "关闭", "aria-label": "关闭", children: /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ e("path", { d: "M18 6L6 18M6 6l12 12" }) }) })
1330
+ ] }),
1331
+ /* @__PURE__ */ e("div", { className: "sa-artifact-drawer-body", children: r.mode === "list" ? a.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-drawer-empty", children: "暂无产物" }) : /* @__PURE__ */ e("ul", { className: "sa-drawer-file-list", role: "list", children: a.map((g, b) => /* @__PURE__ */ d(
1332
+ "li",
707
1333
  {
708
- conversations: m,
709
- activeSessionId: v,
710
- onSwitch: b,
711
- onNew: h,
712
- onDelete: g,
713
- onRename: u
1334
+ className: "sa-drawer-file-card",
1335
+ onClick: () => h(g),
1336
+ onKeyDown: (m) => {
1337
+ (m.key === "Enter" || m.key === " ") && (m.preventDefault(), h(g));
1338
+ },
1339
+ tabIndex: 0,
1340
+ role: "button",
1341
+ "aria-label": `预览 ${g.filename}`,
1342
+ children: [
1343
+ /* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(g.type) }) }),
1344
+ /* @__PURE__ */ d("div", { className: "sa-drawer-file-info", children: [
1345
+ /* @__PURE__ */ e("span", { className: "sa-drawer-file-name", children: g.filename }),
1346
+ /* @__PURE__ */ e("span", { className: "sa-drawer-file-size", children: Q(g.size) })
1347
+ ] }),
1348
+ /* @__PURE__ */ e(
1349
+ "button",
1350
+ {
1351
+ className: "sa-drawer-btn",
1352
+ title: "下载",
1353
+ "aria-label": `下载 ${g.filename}`,
1354
+ onClick: (m) => {
1355
+ m.stopPropagation(), U(g);
1356
+ },
1357
+ children: /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ e("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3" }) })
1358
+ }
1359
+ )
1360
+ ]
1361
+ },
1362
+ g.id || `artifact-${b}`
1363
+ )) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(_e, { artifact: r.artifact }) }) })
1364
+ ] });
1365
+ }
1366
+ function We({ isOpen: a, onClose: t, title: s, slots: r, welcomeMessage: n, suggestedPrompts: o, avatar: i, artifactPreview: l }) {
1367
+ const { status: c, sendMessage: p, stop: f, toggleThreadList: u, toggleArtifactDrawer: h, conversations: v, activeConversationId: k, switchConversation: g, newConversation: b, deleteConversation: m, renameConversation: x, isThreadListOpen: I, isArtifactDrawerOpen: D, allArtifacts: M, activePreviewArtifact: O } = F();
1368
+ if (!a) return null;
1369
+ const y = r.Header, L = r.Composer, $ = r.ThreadList;
1370
+ return /* @__PURE__ */ d("div", { className: "sa-panel", children: [
1371
+ y ? /* @__PURE__ */ e(y, { title: s, onClose: t, onToggleThreadList: u }) : /* @__PURE__ */ e(
1372
+ ue,
1373
+ {
1374
+ title: s,
1375
+ onClose: t,
1376
+ onToggleThreadList: u,
1377
+ artifactCount: l ? M.length : 0,
1378
+ onToggleArtifactDrawer: l ? h : void 0
1379
+ }
1380
+ ),
1381
+ $ && I ? /* @__PURE__ */ e(
1382
+ $,
1383
+ {
1384
+ conversations: v,
1385
+ activeSessionId: k,
1386
+ onSwitch: g,
1387
+ onNew: b,
1388
+ onDelete: m,
1389
+ onRename: x
714
1390
  }
715
- ) : /* @__PURE__ */ a(ce, {}),
716
- /* @__PURE__ */ a(J, { slots: r, welcomeMessage: s, suggestedPrompts: i, avatar: c }),
717
- N ? /* @__PURE__ */ a(N, { status: n, onSend: o, onStop: f }) : /* @__PURE__ */ a(X, {})
1391
+ ) : /* @__PURE__ */ e(he, {}),
1392
+ /* @__PURE__ */ d("div", { className: "sa-panel-content", children: [
1393
+ /* @__PURE__ */ e(re, { slots: r, welcomeMessage: n, suggestedPrompts: o, avatar: i, artifactPreview: l }),
1394
+ l && D && /* @__PURE__ */ e(ne, { artifacts: M, initialArtifact: O, onClose: h })
1395
+ ] }),
1396
+ L ? /* @__PURE__ */ e(L, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
718
1397
  ] });
719
1398
  }
720
- function ke({
721
- conversations: t,
722
- activeSessionId: e,
723
- onSwitch: l,
1399
+ function Fe({
1400
+ conversations: a,
1401
+ activeSessionId: t,
1402
+ onSwitch: s,
724
1403
  onNew: r,
725
- onDelete: s,
726
- isCollapsed: i,
727
- onToggleCollapse: c
1404
+ onDelete: n,
1405
+ isCollapsed: o,
1406
+ onToggleCollapse: i
728
1407
  }) {
729
- const [n, o] = I(null), [f, p] = I(null), m = y((b, h) => {
730
- h.stopPropagation(), f === b ? (s(b), p(null)) : (p(b), setTimeout(() => p(null), 3e3));
731
- }, [f, s]), v = (() => {
732
- const b = Date.now(), h = [], g = [], u = [];
733
- for (const w of t) {
734
- const N = b - new Date(w.updateTime).getTime();
735
- N < 864e5 ? h.push(w) : N < 6048e5 ? g.push(w) : u.push(w);
1408
+ const [l, c] = T(null), [p, f] = T(null), u = N((v, k) => {
1409
+ k.stopPropagation(), p === v ? (n(v), f(null)) : (f(v), setTimeout(() => f(null), 3e3));
1410
+ }, [p, n]), h = (() => {
1411
+ const v = Date.now(), k = [], g = [], b = [];
1412
+ for (const x of a) {
1413
+ const I = v - new Date(x.updateTime).getTime();
1414
+ I < 864e5 ? k.push(x) : I < 6048e5 ? g.push(x) : b.push(x);
736
1415
  }
737
- const d = [];
738
- return h.length && d.push({ label: "今天", items: h }), g.length && d.push({ label: "最近 7 天", items: g }), u.length && d.push({ label: "更早", items: u }), d;
1416
+ const m = [];
1417
+ return k.length && m.push({ label: "今天", items: k }), g.length && m.push({ label: "最近 7 天", items: g }), b.length && m.push({ label: "更早", items: b }), m;
739
1418
  })();
740
- return i ? /* @__PURE__ */ x("div", { className: "sa-fp-sidebar sa-fp-sidebar-collapsed", children: [
741
- /* @__PURE__ */ a("button", { className: "sa-fp-sidebar-toggle", onClick: c, title: "展开", children: /* @__PURE__ */ a(C, { name: "panel-left", size: 18 }) }),
742
- /* @__PURE__ */ a("button", { className: "sa-fp-sidebar-toggle", onClick: r, title: "新会话", style: { marginTop: 4 }, children: /* @__PURE__ */ a(C, { name: "plus", size: 18 }) })
743
- ] }) : /* @__PURE__ */ x("div", { className: "sa-fp-sidebar", children: [
744
- /* @__PURE__ */ x("div", { className: "sa-fp-sidebar-header", children: [
745
- /* @__PURE__ */ x("button", { className: "sa-fp-sidebar-new", onClick: r, children: [
746
- /* @__PURE__ */ a(C, { name: "plus", size: 15 }),
1419
+ return o ? /* @__PURE__ */ d("div", { className: "sa-fp-sidebar sa-fp-sidebar-collapsed", children: [
1420
+ /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: i, title: "展开", children: /* @__PURE__ */ e(C, { name: "panel-left", size: 18 }) }),
1421
+ /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: r, title: "新会话", style: { marginTop: 4 }, children: /* @__PURE__ */ e(C, { name: "plus", size: 18 }) })
1422
+ ] }) : /* @__PURE__ */ d("div", { className: "sa-fp-sidebar", children: [
1423
+ /* @__PURE__ */ d("div", { className: "sa-fp-sidebar-header", children: [
1424
+ /* @__PURE__ */ d("button", { className: "sa-fp-sidebar-new", onClick: r, children: [
1425
+ /* @__PURE__ */ e(C, { name: "plus", size: 15 }),
747
1426
  " ",
748
- /* @__PURE__ */ a("span", { children: "新会话" })
1427
+ /* @__PURE__ */ e("span", { children: "新会话" })
749
1428
  ] }),
750
- /* @__PURE__ */ a("button", { className: "sa-fp-sidebar-toggle", onClick: c, title: "收起侧边栏", children: /* @__PURE__ */ a(C, { name: "panel-left-close", size: 18 }) })
1429
+ /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: i, title: "收起侧边栏", children: /* @__PURE__ */ e(C, { name: "panel-left-close", size: 18 }) })
751
1430
  ] }),
752
- /* @__PURE__ */ x("div", { className: "sa-fp-sidebar-list", children: [
753
- t.length === 0 && /* @__PURE__ */ a("div", { className: "sa-fp-sidebar-empty", children: "开始你的第一个对话" }),
754
- v.map((b) => /* @__PURE__ */ x("div", { children: [
755
- /* @__PURE__ */ a("div", { className: "sa-fp-sidebar-group", children: b.label }),
756
- b.items.map((h) => {
757
- const g = h.sessionId === e, u = n === h.sessionId, d = f === h.sessionId;
758
- return /* @__PURE__ */ x(
1431
+ /* @__PURE__ */ d("div", { className: "sa-fp-sidebar-list", children: [
1432
+ a.length === 0 && /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-empty", children: "开始你的第一个对话" }),
1433
+ h.map((v) => /* @__PURE__ */ d("div", { children: [
1434
+ /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-group", children: v.label }),
1435
+ v.items.map((k) => {
1436
+ const g = k.sessionId === t, b = l === k.sessionId, m = p === k.sessionId;
1437
+ return /* @__PURE__ */ d(
759
1438
  "div",
760
1439
  {
761
1440
  className: `sa-fp-sidebar-item ${g ? "active" : ""}`,
762
- onClick: () => l(h.sessionId),
763
- onMouseEnter: () => o(h.sessionId),
764
- onMouseLeave: () => o(null),
1441
+ onClick: () => s(k.sessionId),
1442
+ onMouseEnter: () => c(k.sessionId),
1443
+ onMouseLeave: () => c(null),
765
1444
  children: [
766
- /* @__PURE__ */ a("span", { className: "sa-fp-sidebar-item-title", children: h.title || "新会话" }),
767
- u && /* @__PURE__ */ a(
1445
+ /* @__PURE__ */ e("span", { className: "sa-fp-sidebar-item-title", children: k.title || "新会话" }),
1446
+ b && /* @__PURE__ */ e(
768
1447
  "button",
769
1448
  {
770
- className: `sa-fp-sidebar-item-action ${d ? "danger" : ""}`,
771
- onClick: (w) => m(h.sessionId, w),
772
- title: d ? "确认删除" : "删除",
773
- children: /* @__PURE__ */ a(C, { name: d ? "x" : "trash2", size: 14 })
1449
+ className: `sa-fp-sidebar-item-action ${m ? "danger" : ""}`,
1450
+ onClick: (x) => u(k.sessionId, x),
1451
+ title: m ? "确认删除" : "删除",
1452
+ children: /* @__PURE__ */ e(C, { name: m ? "x" : "trash2", size: 14 })
774
1453
  }
775
1454
  )
776
1455
  ]
777
1456
  },
778
- h.sessionId
1457
+ k.sessionId
779
1458
  );
780
1459
  })
781
- ] }, b.label))
1460
+ ] }, v.label))
782
1461
  ] })
783
1462
  ] });
784
1463
  }
785
- function Ce({ title: t, slots: e, welcomeMessage: l, suggestedPrompts: r, sidebarDefaultOpen: s = !0, onClose: i, avatar: c }) {
1464
+ function Ye({ title: a, slots: t, welcomeMessage: s, suggestedPrompts: r, sidebarDefaultOpen: n = !0, onClose: o, avatar: i, artifactPreview: l }) {
786
1465
  const {
787
- status: n,
788
- sendMessage: o,
1466
+ status: c,
1467
+ sendMessage: p,
789
1468
  stop: f,
790
- conversations: p,
791
- activeConversationId: m,
1469
+ conversations: u,
1470
+ activeConversationId: h,
792
1471
  switchConversation: v,
793
- newConversation: b,
794
- deleteConversation: h,
795
- renameConversation: g
796
- } = P(), [u, d] = I(s), w = y(() => d((O) => !O), []), N = e.ThreadList, z = e.Composer;
797
- return /* @__PURE__ */ x("div", { className: "sa-fullpage", children: [
798
- N ? /* @__PURE__ */ a("div", { className: `sa-fp-sidebar-wrapper ${u ? "" : "sa-fp-sidebar-wrapper-collapsed"}`, children: /* @__PURE__ */ a(
799
- N,
1472
+ newConversation: k,
1473
+ deleteConversation: g,
1474
+ renameConversation: b,
1475
+ toggleArtifactDrawer: m,
1476
+ isArtifactDrawerOpen: x,
1477
+ allArtifacts: I,
1478
+ activePreviewArtifact: D
1479
+ } = F(), [M, O] = T(n), y = N(() => O((S) => !S), []), L = t.ThreadList, $ = t.Composer;
1480
+ return /* @__PURE__ */ d("div", { className: "sa-fullpage", children: [
1481
+ L ? /* @__PURE__ */ e("div", { className: `sa-fp-sidebar-wrapper ${M ? "" : "sa-fp-sidebar-wrapper-collapsed"}`, children: /* @__PURE__ */ e(
1482
+ L,
800
1483
  {
801
- conversations: p,
802
- activeSessionId: m,
1484
+ conversations: u,
1485
+ activeSessionId: h,
803
1486
  onSwitch: v,
804
- onNew: b,
805
- onDelete: h,
806
- onRename: g
1487
+ onNew: k,
1488
+ onDelete: g,
1489
+ onRename: b
807
1490
  }
808
- ) }) : /* @__PURE__ */ a(
809
- ke,
1491
+ ) }) : /* @__PURE__ */ e(
1492
+ Fe,
810
1493
  {
811
- conversations: p,
812
- activeSessionId: m,
1494
+ conversations: u,
1495
+ activeSessionId: h,
813
1496
  onSwitch: v,
814
- onNew: b,
815
- onDelete: h,
816
- onRename: g,
817
- isCollapsed: !u,
818
- onToggleCollapse: w
1497
+ onNew: k,
1498
+ onDelete: g,
1499
+ onRename: b,
1500
+ isCollapsed: !M,
1501
+ onToggleCollapse: y
819
1502
  }
820
1503
  ),
821
- /* @__PURE__ */ x("div", { className: "sa-fp-main", children: [
822
- /* @__PURE__ */ x("div", { className: "sa-fp-header", children: [
823
- !u && !N && /* @__PURE__ */ a("button", { className: "sa-fp-header-btn", onClick: w, title: "展开侧边栏", children: /* @__PURE__ */ a(C, { name: "panel-left", size: 18 }) }),
824
- /* @__PURE__ */ a("div", { className: "sa-fp-header-title", children: t }),
825
- /* @__PURE__ */ a("div", { className: "sa-fp-header-actions", children: i && /* @__PURE__ */ a("button", { className: "sa-fp-header-btn", onClick: i, title: "关闭", children: /* @__PURE__ */ a(C, { name: "x", size: 18 }) }) })
1504
+ /* @__PURE__ */ d("div", { className: "sa-fp-main", children: [
1505
+ /* @__PURE__ */ d("div", { className: "sa-fp-header", children: [
1506
+ !M && !L && /* @__PURE__ */ e("button", { className: "sa-fp-header-btn", onClick: y, title: "展开侧边栏", children: /* @__PURE__ */ e(C, { name: "panel-left", size: 18 }) }),
1507
+ /* @__PURE__ */ e("div", { className: "sa-fp-header-title", children: a }),
1508
+ /* @__PURE__ */ d("div", { className: "sa-fp-header-actions", children: [
1509
+ l && I.length > 0 && /* @__PURE__ */ d("button", { className: "sa-fp-header-btn sa-header-btn-artifact", onClick: m, title: "会话产物", children: [
1510
+ /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1511
+ /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
1512
+ /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
1513
+ ] }),
1514
+ /* @__PURE__ */ e("span", { children: "产物" })
1515
+ ] }),
1516
+ o && /* @__PURE__ */ e("button", { className: "sa-fp-header-btn", onClick: o, title: "关闭", children: /* @__PURE__ */ e(C, { name: "x", size: 18 }) })
1517
+ ] })
1518
+ ] }),
1519
+ /* @__PURE__ */ d("div", { className: "sa-fp-content-row", children: [
1520
+ /* @__PURE__ */ e(re, { slots: t, welcomeMessage: s, suggestedPrompts: r, avatar: i, artifactPreview: l }),
1521
+ l && x && /* @__PURE__ */ e(ne, { artifacts: I, initialArtifact: D, onClose: m })
826
1522
  ] }),
827
- /* @__PURE__ */ a(J, { slots: e, welcomeMessage: l, suggestedPrompts: r, avatar: c }),
828
- z ? /* @__PURE__ */ a(z, { status: n, onSend: o, onStop: f }) : /* @__PURE__ */ a(X, {})
1523
+ $ ? /* @__PURE__ */ e($, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
829
1524
  ] })
830
1525
  ] });
831
1526
  }
832
- function Ne(t) {
833
- const { sdk: e, mode: l = "floating", slots: r = {}, hooks: s = {}, welcomeMessage: i, suggestedPrompts: c, title: n = "AI Assistant", initialOpen: o = !1, onOpenChange: f, sidebarDefaultOpen: p, avatar: m } = t, [v, b] = I(o);
834
- A(() => {
835
- b(o);
836
- }, [o]);
837
- const h = y(() => {
838
- var w, N;
839
- const d = !v;
840
- b(d), f == null || f(d), d ? (w = s.onOpen) == null || w.call(s) : (N = s.onClose) == null || N.call(s);
841
- }, [v, s, f]), g = y(() => {
842
- var d;
843
- b(!1), f == null || f(!1), (d = s.onClose) == null || d.call(s);
844
- }, [s, f]), u = r.Trigger ?? ie;
845
- return l === "fullpage" ? v ? /* @__PURE__ */ a(U, { sdk: e, hooks: s, children: /* @__PURE__ */ a(
846
- Ce,
1527
+ function Ke(a) {
1528
+ const { sdk: t, mode: s = "floating", slots: r = {}, hooks: n = {}, welcomeMessage: o, suggestedPrompts: i, title: l = "AI Assistant", initialOpen: c = !1, onOpenChange: p, sidebarDefaultOpen: f, avatar: u, artifactPreview: h } = a, [v, k] = T(c);
1529
+ B(() => {
1530
+ k(c);
1531
+ }, [c]);
1532
+ const g = N(() => {
1533
+ var I, D;
1534
+ const x = !v;
1535
+ k(x), p == null || p(x), x ? (I = n.onOpen) == null || I.call(n) : (D = n.onClose) == null || D.call(n);
1536
+ }, [v, n, p]), b = N(() => {
1537
+ var x;
1538
+ k(!1), p == null || p(!1), (x = n.onClose) == null || x.call(n);
1539
+ }, [n, p]), m = r.Trigger ?? fe;
1540
+ return s === "fullpage" ? v ? /* @__PURE__ */ e(G, { sdk: t, hooks: n, children: /* @__PURE__ */ e(
1541
+ Ye,
847
1542
  {
848
- title: n,
1543
+ title: l,
849
1544
  slots: r,
850
- welcomeMessage: i,
851
- suggestedPrompts: c,
852
- sidebarDefaultOpen: p,
853
- onClose: g,
854
- avatar: m
1545
+ welcomeMessage: o,
1546
+ suggestedPrompts: i,
1547
+ sidebarDefaultOpen: f,
1548
+ onClose: b,
1549
+ avatar: u,
1550
+ artifactPreview: h
855
1551
  }
856
- ) }) : null : /* @__PURE__ */ x(U, { sdk: e, hooks: s, children: [
857
- /* @__PURE__ */ a(u, { isOpen: v, onClick: h }),
858
- /* @__PURE__ */ a(
859
- ye,
1552
+ ) }) : null : /* @__PURE__ */ d(G, { sdk: t, hooks: n, children: [
1553
+ /* @__PURE__ */ e(m, { isOpen: v, onClick: g }),
1554
+ /* @__PURE__ */ e(
1555
+ We,
860
1556
  {
861
1557
  isOpen: v,
862
- onClose: g,
863
- title: n,
1558
+ onClose: b,
1559
+ title: l,
864
1560
  slots: r,
865
- welcomeMessage: i,
866
- suggestedPrompts: c,
867
- avatar: m
1561
+ welcomeMessage: o,
1562
+ suggestedPrompts: i,
1563
+ avatar: u,
1564
+ artifactPreview: h
868
1565
  }
869
1566
  )
870
1567
  ] });
871
1568
  }
872
- const ze = `
1569
+ const Ue = `
873
1570
  [data-super-agent-widget] {
874
1571
  --sa-primary-dark: color-mix(in srgb, var(--sa-primary) 82%, #000);
875
1572
  --sa-primary-light: color-mix(in srgb, var(--sa-primary) 10%, #fff);
@@ -1393,6 +2090,7 @@ const ze = `
1393
2090
  display: flex;
1394
2091
  gap: 6px;
1395
2092
  margin-top: 6px;
2093
+ position: relative;
1396
2094
  }
1397
2095
 
1398
2096
  .sa-action-btn {
@@ -1424,6 +2122,44 @@ const ze = `
1424
2122
  align-self: center;
1425
2123
  }
1426
2124
 
2125
+ /* ── Dislike Panel ── */
2126
+ .sa-dislike-panel {
2127
+ position: absolute; bottom: 100%; left: 0; right: 0;
2128
+ margin-bottom: 6px; padding: 12px;
2129
+ background: #fff; border: 1px solid var(--sa-border); border-radius: 10px;
2130
+ box-shadow: 0 4px 16px rgba(0,0,0,0.08);
2131
+ animation: sa-fade-in-up 0.2s cubic-bezier(0.16,1,0.3,1) both;
2132
+ z-index: 10;
2133
+ }
2134
+ .sa-dislike-panel-title { font-size: 13px; font-weight: 500; color: var(--sa-text); margin-bottom: 8px; }
2135
+ .sa-dislike-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
2136
+ .sa-dislike-reason-btn {
2137
+ padding: 4px 10px; border: 1px solid var(--sa-border); border-radius: 6px;
2138
+ background: #fff; color: var(--sa-text); font-size: 12px; cursor: pointer;
2139
+ transition: border-color 0.15s, background 0.15s, color 0.15s;
2140
+ }
2141
+ .sa-dislike-reason-btn:hover { border-color: var(--sa-primary); color: var(--sa-primary); }
2142
+ .sa-dislike-reason-btn.active { background: var(--sa-primary); color: #fff; border-color: var(--sa-primary); }
2143
+ .sa-dislike-remark {
2144
+ width: 100%; padding: 8px 10px; border: 1px solid var(--sa-border); border-radius: 8px;
2145
+ font-size: 13px; color: var(--sa-text); resize: none; outline: none;
2146
+ transition: border-color 0.15s;
2147
+ }
2148
+ .sa-dislike-remark:focus { border-color: var(--sa-primary); }
2149
+ .sa-dislike-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
2150
+ .sa-dislike-submit {
2151
+ padding: 5px 14px; border: none; border-radius: 6px;
2152
+ background: var(--sa-primary); color: #fff; font-size: 13px; font-weight: 500; cursor: pointer;
2153
+ transition: opacity 0.15s;
2154
+ }
2155
+ .sa-dislike-submit:hover { opacity: 0.9; }
2156
+ .sa-dislike-cancel {
2157
+ padding: 5px 14px; border: 1px solid var(--sa-border); border-radius: 6px;
2158
+ background: #fff; color: var(--sa-text-muted); font-size: 13px; cursor: pointer;
2159
+ transition: background 0.15s;
2160
+ }
2161
+ .sa-dislike-cancel:hover { background: var(--sa-surface); }
2162
+
1427
2163
  /* ── Composer ────────────────────────────────────────────── */
1428
2164
 
1429
2165
  .sa-composer {
@@ -1699,6 +2435,200 @@ const ze = `
1699
2435
  animation: sa-blink 1s steps(2, start) infinite;
1700
2436
  }
1701
2437
 
2438
+ /* ── Interrupt cards ──────────────────────────────────────── */
2439
+
2440
+ .sa-interrupt-card {
2441
+ margin: 8px 0;
2442
+ padding: 14px;
2443
+ border: 1px solid #e0e7ff;
2444
+ border-radius: 10px;
2445
+ background: #f8faff;
2446
+ }
2447
+
2448
+ .sa-interrupt-content {
2449
+ display: flex;
2450
+ align-items: flex-start;
2451
+ gap: 8px;
2452
+ font-size: 13px;
2453
+ line-height: 1.6;
2454
+ color: var(--sa-text);
2455
+ margin-bottom: 12px;
2456
+ }
2457
+
2458
+ .sa-interrupt-actions {
2459
+ display: flex;
2460
+ gap: 8px;
2461
+ margin-top: 10px;
2462
+ }
2463
+
2464
+ .sa-interrupt-btn {
2465
+ display: inline-flex;
2466
+ align-items: center;
2467
+ gap: 5px;
2468
+ padding: 6px 14px;
2469
+ border: none;
2470
+ border-radius: 8px;
2471
+ font-size: 13px;
2472
+ font-weight: 500;
2473
+ cursor: pointer;
2474
+ transition: background 0.15s, opacity 0.15s;
2475
+ }
2476
+
2477
+ .sa-interrupt-btn:disabled {
2478
+ opacity: 0.5;
2479
+ cursor: not-allowed;
2480
+ }
2481
+
2482
+ .sa-interrupt-btn-primary {
2483
+ background: var(--sa-primary);
2484
+ color: #fff;
2485
+ }
2486
+
2487
+ .sa-interrupt-btn-primary:hover:not(:disabled) {
2488
+ opacity: 0.9;
2489
+ }
2490
+
2491
+ .sa-interrupt-btn-secondary {
2492
+ background: #f3f4f6;
2493
+ color: #374151;
2494
+ }
2495
+
2496
+ .sa-interrupt-btn-secondary:hover:not(:disabled) {
2497
+ background: #e5e7eb;
2498
+ }
2499
+
2500
+ .sa-interrupt-btn-danger {
2501
+ background: #fef2f2;
2502
+ color: #dc2626;
2503
+ }
2504
+
2505
+ .sa-interrupt-btn-danger:hover:not(:disabled) {
2506
+ background: #fee2e2;
2507
+ }
2508
+
2509
+ .sa-interrupt-options {
2510
+ display: flex;
2511
+ flex-direction: column;
2512
+ gap: 6px;
2513
+ }
2514
+
2515
+ .sa-interrupt-option {
2516
+ display: flex;
2517
+ align-items: center;
2518
+ gap: 8px;
2519
+ padding: 8px 12px;
2520
+ border: 1px solid var(--sa-border);
2521
+ border-radius: 8px;
2522
+ background: #fff;
2523
+ color: var(--sa-text);
2524
+ font-size: 13px;
2525
+ cursor: pointer;
2526
+ text-align: left;
2527
+ transition: border-color 0.12s, background 0.12s;
2528
+ }
2529
+
2530
+ .sa-interrupt-option:hover {
2531
+ border-color: var(--sa-primary);
2532
+ background: #f5f3ff;
2533
+ }
2534
+
2535
+ .sa-interrupt-option-selected {
2536
+ border-color: var(--sa-primary);
2537
+ background: #ede9fe;
2538
+ color: var(--sa-primary);
2539
+ font-weight: 500;
2540
+ }
2541
+
2542
+ .sa-interrupt-option-danger {
2543
+ color: #ef4444;
2544
+ }
2545
+
2546
+ .sa-interrupt-option-danger:hover {
2547
+ border-color: #ef4444;
2548
+ background: #fef2f2;
2549
+ }
2550
+
2551
+ .sa-interrupt-option-desc {
2552
+ font-size: 11px;
2553
+ color: var(--sa-text-muted);
2554
+ margin-left: auto;
2555
+ }
2556
+
2557
+ .sa-interrupt-input-area {
2558
+ margin-top: 4px;
2559
+ }
2560
+
2561
+ .sa-interrupt-input,
2562
+ .sa-interrupt-textarea,
2563
+ .sa-interrupt-select {
2564
+ width: 100%;
2565
+ padding: 8px 12px;
2566
+ border: 1px solid var(--sa-border);
2567
+ border-radius: 8px;
2568
+ background: #fff;
2569
+ color: var(--sa-text);
2570
+ font-size: 13px;
2571
+ font-family: inherit;
2572
+ outline: none;
2573
+ transition: border-color 0.15s;
2574
+ }
2575
+
2576
+ .sa-interrupt-input:focus,
2577
+ .sa-interrupt-textarea:focus,
2578
+ .sa-interrupt-select:focus {
2579
+ border-color: var(--sa-primary);
2580
+ }
2581
+
2582
+ .sa-interrupt-textarea {
2583
+ resize: vertical;
2584
+ min-height: 60px;
2585
+ }
2586
+
2587
+ .sa-interrupt-form {
2588
+ display: flex;
2589
+ flex-direction: column;
2590
+ gap: 10px;
2591
+ margin-top: 4px;
2592
+ }
2593
+
2594
+ .sa-interrupt-form-field {
2595
+ display: flex;
2596
+ flex-direction: column;
2597
+ gap: 4px;
2598
+ }
2599
+
2600
+ .sa-interrupt-form-label {
2601
+ font-size: 12px;
2602
+ font-weight: 500;
2603
+ color: var(--sa-text);
2604
+ }
2605
+
2606
+ .sa-interrupt-form-required {
2607
+ color: #ef4444;
2608
+ margin-left: 2px;
2609
+ }
2610
+
2611
+ .sa-interrupt-resolved {
2612
+ display: flex;
2613
+ align-items: center;
2614
+ gap: 6px;
2615
+ padding: 8px 12px;
2616
+ border-radius: 8px;
2617
+ background: #ecfdf5;
2618
+ color: #065f46;
2619
+ font-size: 13px;
2620
+ margin: 6px 0;
2621
+ }
2622
+
2623
+ .sa-interrupt-unknown {
2624
+ padding: 8px 12px;
2625
+ border-radius: 8px;
2626
+ background: #fef3c7;
2627
+ color: #92400e;
2628
+ font-size: 13px;
2629
+ margin: 6px 0;
2630
+ }
2631
+
1702
2632
  /* ── Animations ──────────────────────────────────────────── */
1703
2633
 
1704
2634
  @keyframes sa-slide-up {
@@ -1960,7 +2890,7 @@ const ze = `
1960
2890
  }
1961
2891
 
1962
2892
  .sa-fp-header-btn {
1963
- width: 34px;
2893
+ min-width: 34px;
1964
2894
  height: 34px;
1965
2895
  border: none;
1966
2896
  border-radius: 8px;
@@ -2004,7 +2934,168 @@ const ze = `
2004
2934
  border-color: #d4d4d8;
2005
2935
  box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
2006
2936
  }
2007
- `, Ie = {
2937
+
2938
+ /* ── Artifact file cards (in ToolResultPart) ── */
2939
+ .sa-artifact-file-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
2940
+ .sa-artifact-file-card {
2941
+ display: flex; align-items: center; gap: 10px; padding: 8px 10px;
2942
+ border: 1px solid var(--sa-border); border-radius: 10px; background: var(--sa-surface);
2943
+ font-size: 13px; color: var(--sa-text);
2944
+ transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
2945
+ animation: sa-fade-in-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
2946
+ }
2947
+ .sa-artifact-file-card:hover { border-color: var(--sa-primary); background: #fff; box-shadow: 0 2px 8px rgba(99,102,241,0.1); transform: translateY(-1px); }
2948
+ .sa-artifact-file-card:active { transform: translateY(0) scale(0.99); }
2949
+ .sa-artifact-file-icon { flex-shrink: 0; }
2950
+ .sa-artifact-chip-type {
2951
+ display: inline-flex; align-items: center; justify-content: center;
2952
+ min-width: 36px; padding: 2px 6px; border-radius: 5px;
2953
+ background: var(--sa-primary); color: #fff;
2954
+ font-size: 10px; font-weight: 700; letter-spacing: 0.3px; line-height: 1.4;
2955
+ }
2956
+ .sa-artifact-file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
2957
+ .sa-artifact-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
2958
+ .sa-artifact-file-size { color: var(--sa-text-muted); font-size: 12px; }
2959
+ .sa-artifact-file-download {
2960
+ border: none; background: none; cursor: pointer; color: var(--sa-text-muted);
2961
+ padding: 6px; border-radius: 6px; display: inline-flex;
2962
+ transition: color 0.15s ease, background 0.15s ease, transform 0.1s ease;
2963
+ }
2964
+ .sa-artifact-file-download:hover { color: var(--sa-primary); background: rgba(99,102,241,0.08); }
2965
+ .sa-artifact-file-download:active { transform: scale(0.9); }
2966
+
2967
+ /* ── Inline HTML rendering (render_mode=html) ── */
2968
+ .sa-tool-result-html { margin-top: 8px; border: 1px solid var(--sa-border); border-radius: 8px; overflow: hidden; }
2969
+ .sa-tool-result-html-iframe { width: 100%; min-height: 120px; max-height: 400px; border: none; background: #fff; }
2970
+
2971
+ /* ── Header artifact button ── */
2972
+ .sa-header-btn-artifact {
2973
+ display: inline-flex; align-items: center; gap: 4px;
2974
+ padding: 4px 12px !important; border-radius: 8px;
2975
+ background: var(--sa-primary) !important; color: #fff !important;
2976
+ font-size: 12px; font-weight: 600;
2977
+ transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease;
2978
+ box-shadow: 0 1px 4px rgba(99,102,241,0.25);
2979
+ }
2980
+ .sa-header-btn-artifact:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(99,102,241,0.3); }
2981
+ .sa-header-btn-artifact:active { transform: translateY(0) scale(0.97); }
2982
+ .sa-header-btn-artifact svg { stroke: #fff; }
2983
+ .sa-header-btn-artifact.sa-artifact-pulse { animation: sa-artifact-pulse 2s ease-in-out 3; }
2984
+
2985
+ /* ── Artifact drawer (right side panel) ── */
2986
+ .sa-artifact-drawer {
2987
+ display: flex; flex-direction: column; min-width: 240px; max-width: 70%;
2988
+ border-left: 1px solid var(--sa-border); background: #fff; flex-shrink: 0; overflow: hidden;
2989
+ animation: sa-slide-in-right 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
2990
+ position: relative;
2991
+ }
2992
+ .sa-artifact-drawer.sa-drawer-closing {
2993
+ animation: sa-slide-out-right 0.25s cubic-bezier(0.4, 0, 1, 1) both;
2994
+ }
2995
+ .sa-drawer-resize-handle {
2996
+ position: absolute; left: -3px; top: 0; bottom: 0; width: 6px;
2997
+ cursor: col-resize; z-index: 2;
2998
+ transition: background 0.15s ease;
2999
+ }
3000
+ .sa-drawer-resize-handle:hover, .sa-drawer-resize-handle:active {
3001
+ background: var(--sa-primary); opacity: 0.3; border-radius: 3px;
3002
+ }
3003
+ .sa-artifact-drawer-header {
3004
+ display: flex; align-items: center; gap: 8px; padding: 12px 14px;
3005
+ border-bottom: 1px solid var(--sa-border); font-weight: 600; font-size: 15px; color: var(--sa-text);
3006
+ background: var(--sa-surface);
3007
+ }
3008
+ .sa-artifact-drawer-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
3009
+ .sa-drawer-btn {
3010
+ border: none; background: none; cursor: pointer; color: var(--sa-text-muted);
3011
+ padding: 6px; border-radius: 6px; display: inline-flex; align-items: center;
3012
+ transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
3013
+ }
3014
+ .sa-drawer-btn:hover { background: var(--sa-border); color: var(--sa-text); }
3015
+ .sa-drawer-btn:active { transform: scale(0.92); }
3016
+ .sa-drawer-btn-sm {
3017
+ border: 1px solid var(--sa-border); background: #fff; cursor: pointer; color: var(--sa-primary);
3018
+ padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
3019
+ transition: background 0.15s ease, border-color 0.15s ease;
3020
+ }
3021
+ .sa-drawer-btn-sm:hover { background: var(--sa-surface); border-color: var(--sa-primary); }
3022
+ .sa-artifact-drawer-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
3023
+ .sa-drawer-empty { padding: 48px 24px; text-align: center; color: var(--sa-text-muted); font-size: 14px; }
3024
+ .sa-drawer-file-list { list-style: none; margin: 0; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
3025
+ .sa-drawer-file-card {
3026
+ display: flex; align-items: center; gap: 10px; padding: 12px 14px;
3027
+ border: 1px solid var(--sa-border); border-radius: 10px; cursor: pointer; background: #fff;
3028
+ transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
3029
+ animation: sa-fade-in-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
3030
+ }
3031
+ .sa-drawer-file-card:nth-child(1) { animation-delay: 0s; }
3032
+ .sa-drawer-file-card:nth-child(2) { animation-delay: 0.04s; }
3033
+ .sa-drawer-file-card:nth-child(3) { animation-delay: 0.08s; }
3034
+ .sa-drawer-file-card:nth-child(4) { animation-delay: 0.12s; }
3035
+ .sa-drawer-file-card:nth-child(5) { animation-delay: 0.16s; }
3036
+ .sa-drawer-file-card:hover { border-color: var(--sa-primary); background: var(--sa-surface); box-shadow: 0 2px 8px rgba(99,102,241,0.08); transform: translateY(-1px); }
3037
+ .sa-drawer-file-card:active { transform: translateY(0) scale(0.98); }
3038
+ .sa-drawer-file-icon { flex-shrink: 0; }
3039
+ .sa-drawer-file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
3040
+ .sa-drawer-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 14px; color: var(--sa-text); }
3041
+ .sa-drawer-file-size { color: var(--sa-text-muted); font-size: 12px; }
3042
+
3043
+ /* ── Drawer preview ── */
3044
+ .sa-drawer-preview-iframe { width: 100%; height: 100%; border: none; background: #fff; animation: sa-fade-in 0.3s ease both; }
3045
+ .sa-drawer-preview-loading {
3046
+ display: flex; flex-direction: column; align-items: center; justify-content: center;
3047
+ height: 100%; gap: 12px; color: var(--sa-text-muted); font-size: 14px;
3048
+ }
3049
+ .sa-drawer-preview-loading::before {
3050
+ content: ''; width: 28px; height: 28px; border-radius: 50%;
3051
+ border: 3px solid var(--sa-border); border-top-color: var(--sa-primary);
3052
+ animation: sa-spinner 0.7s linear infinite;
3053
+ }
3054
+ .sa-drawer-preview-error {
3055
+ display: flex; flex-direction: column; align-items: center; justify-content: center;
3056
+ gap: 14px; height: 100%; color: var(--sa-text-muted); font-size: 14px;
3057
+ animation: sa-fade-in 0.2s ease both;
3058
+ }
3059
+
3060
+ /* ── Drawer view transition ── */
3061
+ .sa-drawer-view-enter { animation: sa-drawer-view-in 0.25s cubic-bezier(0.16, 1, 0.3, 1) both; }
3062
+
3063
+ /* ── Layout helpers for drawer alongside thread ── */
3064
+ .sa-panel-content { display: flex; flex: 1; min-height: 0; overflow: hidden; }
3065
+ .sa-panel-content .sa-thread { flex: 1; min-width: 120px; transition: flex 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
3066
+ .sa-panel-content .sa-artifact-drawer { max-width: 60%; }
3067
+ .sa-fp-content-row { display: flex; flex: 1; min-height: 0; overflow: hidden; }
3068
+ .sa-fp-content-row .sa-thread { flex: 1; min-width: 0; transition: flex 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
3069
+
3070
+ /* ── Artifact keyframes ── */
3071
+ @keyframes sa-slide-in-right {
3072
+ from { opacity: 0; transform: translateX(100%); }
3073
+ to { opacity: 1; transform: translateX(0); }
3074
+ }
3075
+ @keyframes sa-slide-out-right {
3076
+ from { opacity: 1; transform: translateX(0); }
3077
+ to { opacity: 0; transform: translateX(100%); }
3078
+ }
3079
+ @keyframes sa-fade-in-up {
3080
+ from { opacity: 0; transform: translateY(8px); }
3081
+ to { opacity: 1; transform: translateY(0); }
3082
+ }
3083
+ @keyframes sa-fade-in {
3084
+ from { opacity: 0; }
3085
+ to { opacity: 1; }
3086
+ }
3087
+ @keyframes sa-spinner {
3088
+ to { transform: rotate(360deg); }
3089
+ }
3090
+ @keyframes sa-artifact-pulse {
3091
+ 0%, 100% { box-shadow: 0 1px 4px rgba(99,102,241,0.25); }
3092
+ 50% { box-shadow: 0 2px 12px rgba(99,102,241,0.5); }
3093
+ }
3094
+ @keyframes sa-drawer-view-in {
3095
+ from { opacity: 0; transform: translateX(12px); }
3096
+ to { opacity: 1; transform: translateX(0); }
3097
+ }
3098
+ `, Ve = {
2008
3099
  primaryColor: "#6366f1",
2009
3100
  backgroundColor: "#ffffff",
2010
3101
  fontFamily: "system-ui, -apple-system, sans-serif",
@@ -2013,77 +3104,78 @@ const ze = `
2013
3104
  panelHeight: 520,
2014
3105
  zIndex: 9999
2015
3106
  };
2016
- function Te(t) {
2017
- const e = { ...Ie, ...t };
3107
+ function qe(a) {
3108
+ const t = { ...Ve, ...a };
2018
3109
  return [
2019
- `--sa-primary: ${e.primaryColor}`,
2020
- `--sa-bg: ${e.backgroundColor}`,
2021
- `--sa-font: ${e.fontFamily}`,
2022
- `--sa-radius: ${e.borderRadius}px`,
2023
- `--sa-panel-width: ${e.panelWidth}px`,
2024
- `--sa-panel-height: ${e.panelHeight}px`,
2025
- `--sa-z-index: ${e.zIndex}`
3110
+ `--sa-primary: ${t.primaryColor}`,
3111
+ `--sa-bg: ${t.backgroundColor}`,
3112
+ `--sa-font: ${t.fontFamily}`,
3113
+ `--sa-radius: ${t.borderRadius}px`,
3114
+ `--sa-panel-width: ${t.panelWidth}px`,
3115
+ `--sa-panel-height: ${t.panelHeight}px`,
3116
+ `--sa-z-index: ${t.zIndex}`
2026
3117
  ].join("; ");
2027
3118
  }
2028
- function Re(t, e) {
2029
- const l = typeof t == "string" ? document.querySelector(t) : t;
2030
- if (!l)
2031
- throw new Error(`Target element not found: ${t}`);
3119
+ function Ze(a, t) {
3120
+ const s = typeof a == "string" ? document.querySelector(a) : a;
3121
+ if (!s)
3122
+ throw new Error(`Target element not found: ${a}`);
2032
3123
  const r = document.createElement("div");
2033
3124
  r.setAttribute("data-super-agent-widget", "");
2034
- const s = Te(e.theme ?? {});
2035
- if (r.setAttribute("style", s), l.appendChild(r), !document.getElementById("sa-widget-styles")) {
2036
- const o = document.createElement("style");
2037
- o.id = "sa-widget-styles", o.textContent = ze, document.head.appendChild(o);
2038
- }
2039
- let i = ae(r), c = !1;
2040
- const n = (o) => {
2041
- i && i.render(
2042
- q.createElement(Ne, {
2043
- ...e,
2044
- initialOpen: o ?? c,
2045
- onOpenChange: (f) => {
2046
- c = f;
3125
+ const n = qe(t.theme ?? {});
3126
+ if (r.setAttribute("style", n), s.appendChild(r), !document.getElementById("sa-widget-styles")) {
3127
+ const c = document.createElement("style");
3128
+ c.id = "sa-widget-styles", c.textContent = Ue, document.head.appendChild(c);
3129
+ }
3130
+ let o = le(r), i = !1;
3131
+ const l = (c) => {
3132
+ o && o.render(
3133
+ Y.createElement(Ke, {
3134
+ ...t,
3135
+ initialOpen: c ?? i,
3136
+ onOpenChange: (p) => {
3137
+ i = p;
2047
3138
  }
2048
3139
  })
2049
3140
  );
2050
3141
  };
2051
- return n(!1), {
3142
+ return l(!1), {
2052
3143
  open() {
2053
- c = !0, n(!0);
3144
+ i = !0, l(!0);
2054
3145
  },
2055
3146
  close() {
2056
- c = !1, n(!1);
3147
+ i = !1, l(!1);
2057
3148
  },
2058
3149
  destroy() {
2059
- i && (i.unmount(), i = null), r.remove();
3150
+ o && (o.unmount(), o = null), r.remove();
2060
3151
  }
2061
3152
  };
2062
3153
  }
2063
3154
  export {
2064
- be as ActionBar,
2065
- U as ChatProvider,
2066
- Ne as ChatWidget,
2067
- X as Composer,
2068
- xe as ErrorPart,
2069
- Ce as FullpageLayout,
2070
- oe as Header,
3155
+ Re as ActionBar,
3156
+ G as ChatProvider,
3157
+ Ke as ChatWidget,
3158
+ se as Composer,
3159
+ Ne as ErrorPart,
3160
+ Ye as FullpageLayout,
3161
+ ue as Header,
2071
3162
  C as Icon,
2072
- ve as Message,
2073
- he as TextPart,
2074
- ue as ThinkingPart,
2075
- J as Thread,
2076
- ce as ThreadList,
2077
- me as ToolCallPart,
2078
- ge as ToolResultPart,
2079
- ie as Trigger,
2080
- we as WelcomeScreen,
2081
- Ie as defaultTheme,
2082
- Re as mount,
2083
- Te as themeToCSSVars,
2084
- de as useAutoScroll,
2085
- se as useChat,
2086
- P as useChatContext,
2087
- ne as useConversations,
2088
- ze as widgetStyles
3163
+ $e as InterruptCard,
3164
+ He as Message,
3165
+ ve as TextPart,
3166
+ we as ThinkingPart,
3167
+ re as Thread,
3168
+ he as ThreadList,
3169
+ ye as ToolCallPart,
3170
+ Ce as ToolResultPart,
3171
+ fe as Trigger,
3172
+ je as WelcomeScreen,
3173
+ Ve as defaultTheme,
3174
+ Ze as mount,
3175
+ qe as themeToCSSVars,
3176
+ ge as useAutoScroll,
3177
+ ce as useChat,
3178
+ F as useChatContext,
3179
+ pe as useConversations,
3180
+ Ue as widgetStyles
2089
3181
  };