super-agent-sdk 1.0.6 → 1.0.8

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,743 +1,915 @@
1
- import Y, { useState as T, useRef as F, useCallback as I, useEffect as R, createContext as ie, useMemo as V, useContext as oe } from "react";
2
- import { createRoot as le } from "react-dom/client";
1
+ import V, { useState as M, useRef as _, useCallback as C, useEffect as B, createContext as ge, useMemo as J, useContext as xe } from "react";
2
+ import { createRoot as be } from "react-dom/client";
3
3
  import { jsx as e, jsxs as d, Fragment as q } from "react/jsx-runtime";
4
- function ce(a) {
5
- const { sdk: t, sessionId: r, onSessionCreated: s, onStreamStart: n, onStreamEnd: o, onError: i, onMessageSend: l } = a, [c, p] = T([]), [f, u] = T("ready"), [h, w] = T(null), k = F(null), b = F(!1), v = F(r);
6
- v.current = r;
7
- const m = I((L) => {
8
- if (b.current) return;
9
- b.current = !0, l == null || l(L);
10
- const O = {
4
+ function ve(t) {
5
+ const { sdk: a, sessionId: s, onSessionCreated: n, onStreamStart: r, onStreamEnd: i, onError: o, onMessageSend: l } = t, [c, p] = M([]), [f, h] = M("ready"), [w, u] = M(null), m = _(null), v = _(!1), S = _(null), T = _(s), A = _(!0);
6
+ T.current = s, A.current = c.length === 0;
7
+ const x = C((N) => {
8
+ if (v.current) return;
9
+ v.current = !0, l == null || l(N);
10
+ const R = {
11
11
  id: `user_${Date.now()}`,
12
12
  role: "user",
13
- parts: [{ type: "text", content: L }],
13
+ parts: [{ type: "text", content: N }],
14
14
  timestamp: Date.now()
15
- }, y = `assistant_${Date.now()}`, D = {
15
+ }, y = `assistant_${Date.now()}`, g = {
16
16
  id: y,
17
17
  role: "assistant",
18
18
  parts: [],
19
19
  timestamp: Date.now()
20
- };
21
- p((M) => [...M, O, D]), u("submitted"), w(null);
22
- const P = (M) => {
23
- let E = "", A = "", H = [], z = !1;
24
- const $ = () => {
25
- const x = [...H];
26
- if (E) {
27
- const _ = x.findIndex((B) => B.type === "thinking");
28
- _ >= 0 ? x[_] = { type: "thinking", content: E } : x.unshift({ type: "thinking", content: E });
20
+ }, E = A.current;
21
+ p((k) => [...k, R, g]), h("submitted"), u(null);
22
+ const L = (k) => {
23
+ let O = "", b = "", H = [], j = !1;
24
+ const W = () => {
25
+ const D = [...H];
26
+ if (O) {
27
+ const F = D.findIndex((U) => U.type === "thinking");
28
+ F >= 0 ? D[F] = { type: "thinking", content: O } : D.unshift({ type: "thinking", content: O });
29
29
  }
30
- if (A) {
31
- const _ = x.findLastIndex((B) => B.type === "text");
32
- _ >= 0 ? x[_] = { type: "text", content: A } : x.push({ type: "text", content: A });
30
+ if (b) {
31
+ const F = D[D.length - 1];
32
+ (F == null ? void 0 : F.type) === "text" ? D[D.length - 1] = { type: "text", content: b } : D.push({ type: "text", content: b });
33
33
  }
34
34
  p(
35
- (_) => _.map((B) => B.id === y ? { ...B, parts: x } : B)
35
+ (F) => F.map((U) => U.id === y ? { ...U, parts: D } : U)
36
36
  );
37
37
  };
38
- k.current = t.chat({
39
- sessionId: M,
40
- message: L,
38
+ m.current = a.chat({
39
+ sessionId: k,
40
+ message: N,
41
41
  stream: !0,
42
- onMessage: (x) => {
43
- switch (z || (z = !0, u("streaming")), x.type) {
42
+ onMessage: (D) => {
43
+ switch (j || (j = !0, h("streaming")), D.type) {
44
44
  case "thinking":
45
- E += x.content;
45
+ O += D.content;
46
46
  break;
47
47
  case "ai":
48
- A += x.content;
48
+ b += D.content;
49
49
  break;
50
50
  case "tool_call":
51
- H.push({
51
+ b && (H.push({ type: "text", content: b }), b = ""), H.push({
52
52
  type: "tool_call",
53
- toolName: x.toolName,
54
- toolCallId: x.toolCallId,
55
- args: x.args ?? "{}"
53
+ toolName: D.toolName,
54
+ toolCallId: D.toolCallId,
55
+ args: D.args ?? "{}"
56
56
  });
57
57
  break;
58
58
  case "tool_result":
59
- H.push({
59
+ b && (H.push({ type: "text", content: b }), b = ""), H.push({
60
60
  type: "tool_result",
61
- toolName: x.toolName ?? "",
62
- toolCallId: x.toolCallId,
63
- content: x.content,
64
- artifacts: x.artifacts,
65
- renderMode: x.renderMode,
66
- html: x.html
67
- }), A && (H.push({ type: "text", content: A }), A = "");
61
+ toolName: D.toolName ?? "",
62
+ toolCallId: D.toolCallId,
63
+ content: D.content,
64
+ artifacts: D.artifacts,
65
+ renderMode: D.renderMode,
66
+ html: D.html
67
+ });
68
68
  break;
69
69
  case "interrupt":
70
- x.interrupt && H.push({
70
+ b && (H.push({ type: "text", content: b }), b = ""), D.interrupt && H.push({
71
71
  type: "interrupt",
72
- interrupt: x.interrupt,
72
+ interrupt: D.interrupt,
73
73
  resolved: !1
74
74
  });
75
75
  break;
76
+ case "stop":
77
+ D.content && (b = D.content), W();
78
+ return;
76
79
  }
77
- $();
80
+ W();
78
81
  },
79
- onDone: (x) => {
80
- (A || H.length > 0 || E) && $(), x.messageId && p(
81
- (_) => _.map((B) => B.id === y ? { ...B, id: x.messageId } : B)
82
- ), x.sessionId && x.sessionId !== v.current && (s == null || s(x.sessionId)), o == null || o(x.sessionId || M), u("ready"), b.current = !1, k.current = null;
82
+ onDone: (D) => {
83
+ (b || H.length > 0 || O) && W(), D.sessionId && D.sessionId !== T.current && (n == null || n(D.sessionId));
84
+ const F = () => {
85
+ S.current && (clearTimeout(S.current), S.current = null), i == null || i(D.sessionId || k), h("ready"), v.current = !1, m.current = null;
86
+ };
87
+ if (E) {
88
+ const U = N.slice(0, 30), he = D.sessionId || k;
89
+ a.renameConversation(he, U).catch(() => {
90
+ }).finally(F);
91
+ } else
92
+ F();
83
93
  },
84
- onError: (x) => {
85
- H.push({ type: "error", content: x.message }), $(), w(x), u("error"), i == null || i(x), b.current = !1, k.current = null;
94
+ onError: (D) => {
95
+ H.push({ type: "error", content: D.message }), W(), S.current && (clearTimeout(S.current), S.current = null), u(D), h("error"), o == null || o(D), v.current = !1, m.current = null;
86
96
  }
87
- }), n == null || n(M);
97
+ }), r == null || r(k);
88
98
  };
89
- v.current ? P(v.current) : t.createSession().then((M) => {
90
- v.current = M, s == null || s(M), P(M);
91
- }).catch((M) => {
92
- w(M instanceof Error ? M : new Error(String(M))), u("error"), i == null || i(M instanceof Error ? M : new Error(String(M))), b.current = !1;
99
+ T.current ? L(T.current) : a.createSession().then((k) => {
100
+ T.current = k, n == null || n(k), L(k);
101
+ }).catch((k) => {
102
+ u(k instanceof Error ? k : new Error(String(k))), h("error"), o == null || o(k instanceof Error ? k : new Error(String(k))), v.current = !1;
93
103
  });
94
- }, [t, s, n, o, i, l]), g = I(() => {
95
- var L;
96
- (L = k.current) == null || L.abort(), k.current = null, u("ready"), b.current = !1;
97
- }, []), N = I(() => {
98
- if (b.current) return;
99
- const L = c.findLastIndex((y) => y.role === "user");
100
- if (L < 0) return;
101
- const O = c[L].parts.filter((y) => y.type === "text").map((y) => y.content).join("");
102
- p((y) => y.slice(0, L)), m(O);
103
- }, [c, m]), S = I((L, O) => {
104
+ }, [a, n, r, i, o, l]), z = C(() => {
105
+ const N = T.current;
106
+ N && (S.current && clearTimeout(S.current), S.current = setTimeout(() => {
107
+ var R;
108
+ S.current = null, (R = m.current) == null || R.abort(), m.current = null, v.current = !1, h("ready");
109
+ }, 8e3), a.stopGeneration(N).catch(() => {
110
+ }));
111
+ }, [a]), $ = C(() => {
112
+ if (v.current) return;
113
+ const N = c.findLastIndex((y) => y.role === "user");
114
+ if (N < 0) return;
115
+ const R = c[N].parts.filter((y) => y.type === "text").map((y) => y.content).join("");
116
+ p((y) => y.slice(0, N)), x(R);
117
+ }, [c, x]), P = C((N, R) => {
104
118
  p(
105
- (z) => z.map(($) => ({
106
- ...$,
107
- parts: $.parts.map(
108
- (x) => x.type === "interrupt" && x.interrupt.interruptId === L ? { ...x, resolved: !0, response: O } : x
119
+ (b) => b.map((H) => ({
120
+ ...H,
121
+ parts: H.parts.map(
122
+ (j) => j.type === "interrupt" && j.interrupt.interruptId === N ? { ...j, resolved: !0, response: R } : j
109
123
  )
110
124
  }))
111
125
  );
112
- const y = v.current;
126
+ const y = T.current;
113
127
  if (!y) return;
114
- const D = `assistant_${Date.now()}`, P = {
115
- id: D,
116
- role: "assistant",
117
- parts: [],
118
- timestamp: Date.now()
119
- };
120
- p((z) => [...z, P]), u("streaming");
121
- let M = "", E = "", A = [];
122
- const H = () => {
123
- const z = [...A];
124
- if (M) {
125
- const $ = z.findIndex((x) => x.type === "thinking");
126
- $ >= 0 ? z[$] = { type: "thinking", content: M } : z.unshift({ type: "thinking", content: M });
127
- }
128
+ let g = 0;
129
+ p((b) => b.length > 0 && b[b.length - 1].role === "assistant" ? (g = b[b.length - 1].parts.length, b) : (g = 0, [...b, { id: `assistant_${Date.now()}`, role: "assistant", parts: [], timestamp: Date.now() }])), h("streaming");
130
+ let E = "", L = "", k = [];
131
+ const O = () => {
132
+ const b = [...k];
128
133
  if (E) {
129
- const $ = z.findLastIndex((x) => x.type === "text");
130
- $ >= 0 ? z[$] = { type: "text", content: E } : z.push({ type: "text", content: E });
134
+ const H = b.findIndex((j) => j.type === "thinking");
135
+ H >= 0 ? b[H] = { type: "thinking", content: E } : b.unshift({ type: "thinking", content: E });
131
136
  }
132
- p(
133
- ($) => $.map((x) => x.id === D ? { ...x, parts: z } : x)
134
- );
137
+ if (L) {
138
+ const H = b[b.length - 1];
139
+ (H == null ? void 0 : H.type) === "text" ? b[b.length - 1] = { type: "text", content: L } : b.push({ type: "text", content: L });
140
+ }
141
+ p((H) => {
142
+ const j = H.findLastIndex((W) => W.role === "assistant");
143
+ return j < 0 ? H : H.map(
144
+ (W, D) => D === j ? { ...W, parts: [...W.parts.slice(0, g), ...b] } : W
145
+ );
146
+ });
135
147
  };
136
- t.respondInterrupt(
137
- L,
148
+ a.respondInterrupt(
149
+ N,
138
150
  y,
139
- O,
140
- (z) => {
141
- switch (z.type) {
151
+ R,
152
+ (b) => {
153
+ switch (b.type) {
142
154
  case "thinking":
143
- M += z.content;
155
+ E += b.content;
144
156
  break;
145
157
  case "ai":
146
- E += z.content;
158
+ L += b.content;
147
159
  break;
148
160
  case "tool_call":
149
- A.push({
161
+ L && (k.push({ type: "text", content: L }), L = ""), k.push({
150
162
  type: "tool_call",
151
- toolName: z.toolName,
152
- toolCallId: z.toolCallId,
153
- args: z.args ?? "{}"
163
+ toolName: b.toolName,
164
+ toolCallId: b.toolCallId,
165
+ args: b.args ?? "{}"
154
166
  });
155
167
  break;
156
168
  case "tool_result":
157
- A.push({
169
+ L && (k.push({ type: "text", content: L }), L = ""), k.push({
158
170
  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 = "");
171
+ toolName: b.toolName ?? "",
172
+ toolCallId: b.toolCallId,
173
+ content: b.content,
174
+ artifacts: b.artifacts,
175
+ renderMode: b.renderMode,
176
+ html: b.html
177
+ });
166
178
  break;
167
179
  case "interrupt":
168
- z.interrupt && A.push({ type: "interrupt", interrupt: z.interrupt, resolved: !1 });
180
+ L && (k.push({ type: "text", content: L }), L = ""), b.interrupt && k.push({ type: "interrupt", interrupt: b.interrupt, resolved: !1 });
169
181
  break;
170
182
  case "done":
171
- z.messageId && p(
172
- ($) => $.map((x) => x.id === D ? { ...x, id: z.messageId } : x)
173
- ), u("ready");
183
+ i == null || i(y), h("ready");
174
184
  break;
175
185
  }
176
- H();
186
+ O();
177
187
  },
178
- (z) => {
179
- A.push({ type: "error", content: z.message }), H(), w(z), u("error"), i == null || i(z);
188
+ (b) => {
189
+ k.push({ type: "error", content: b.message }), O(), u(b), h("error"), o == null || o(b);
180
190
  }
181
- ).catch((z) => {
182
- i == null || i(z instanceof Error ? z : new Error(String(z))), u("error");
191
+ ).catch((b) => {
192
+ o == null || o(b instanceof Error ? b : new Error(String(b))), h("error");
183
193
  });
184
- }, [t, i]);
185
- return { messages: c, status: f, error: h, sendMessage: m, stop: g, regenerate: N, setMessages: p, respondToInterrupt: S };
194
+ }, [a, o, i]);
195
+ return { messages: c, status: f, error: w, sendMessage: x, stop: z, regenerate: $, setMessages: p, respondToInterrupt: P };
186
196
  }
187
- const X = "sa_active_conversation";
188
- function J() {
197
+ const ie = "sa_active_conversation", Q = 20;
198
+ function ee(t) {
189
199
  try {
190
- return localStorage.getItem(X);
200
+ return localStorage.getItem(`${ie}_${t}`);
191
201
  } catch {
192
202
  return null;
193
203
  }
194
204
  }
195
- function de(a) {
205
+ function we(t, a) {
196
206
  try {
197
- a ? localStorage.setItem(X, a) : localStorage.removeItem(X);
207
+ const s = `${ie}_${t}`;
208
+ a ? localStorage.setItem(s, a) : localStorage.removeItem(s);
198
209
  } catch {
199
210
  }
200
211
  }
201
- function pe(a) {
202
- const { sdk: t, onConversationChange: r } = a, [s, n] = T([]), [o, i] = T(
203
- () => J()
204
- ), [l, c] = T(!1), p = F(!0);
205
- R(() => () => {
206
- p.current = !1;
212
+ function ye(t) {
213
+ const { sdk: a, onConversationChange: s } = t, n = a.botId, [r, i] = M([]), [o, l] = M(
214
+ () => ee(n)
215
+ ), [c, p] = M(!1), [f, h] = M(!0), w = _(!0), u = _(1), m = _(!1);
216
+ B(() => () => {
217
+ w.current = !1;
207
218
  }, []);
208
- const f = I((m) => {
209
- i(m), de(m), m && (r == null || r(m));
210
- }, [r]), u = I(async () => {
211
- c(!0);
219
+ const v = C((N) => {
220
+ l(N), we(n, N), N && (s == null || s(N));
221
+ }, [n, s]), S = C(async () => {
222
+ if (!m.current) {
223
+ m.current = !0, p(!0);
224
+ try {
225
+ u.current = 1;
226
+ const N = await a.listConversations({ page: 1, size: Q });
227
+ if (!w.current) return;
228
+ i(N.items), h(N.items.length < N.total);
229
+ const R = ee(n);
230
+ R && !N.items.find((y) => y.sessionId === R) && v(null);
231
+ } catch {
232
+ } finally {
233
+ m.current = !1, w.current && p(!1);
234
+ }
235
+ }
236
+ }, [a, v]), T = C(async () => {
237
+ if (!(m.current || !f)) {
238
+ m.current = !0, p(!0);
239
+ try {
240
+ const N = u.current + 1, R = await a.listConversations({ page: N, size: Q });
241
+ if (!w.current) return;
242
+ u.current = N, i((g) => {
243
+ const E = new Set(g.map((k) => k.sessionId)), L = R.items.filter((k) => !E.has(k.sessionId));
244
+ return [...g, ...L];
245
+ });
246
+ const y = u.current * Q;
247
+ h(y < R.total);
248
+ } catch {
249
+ } finally {
250
+ m.current = !1, w.current && p(!1);
251
+ }
252
+ }
253
+ }, [a, f]), A = C(async (N) => (v(N), await a.getMessages(N)), [a, v]), x = C(async () => {
212
254
  try {
213
- const m = await t.listConversations({ page: 1, size: 100 });
214
- if (!p.current) return;
215
- n(m.items);
216
- const g = J();
217
- g && !m.items.find((N) => N.sessionId === g) && f(null);
255
+ const N = await a.createSession(), R = (/* @__PURE__ */ new Date()).toISOString();
256
+ i((y) => [
257
+ { sessionId: N, botId: 0, title: "新对话", createTime: R, updateTime: R },
258
+ ...y
259
+ ]), v(N);
260
+ } catch {
261
+ v(null);
262
+ }
263
+ }, [a, v]), z = C(async (N) => {
264
+ i((R) => R.filter((y) => y.sessionId !== N)), o === N && v(null);
265
+ try {
266
+ await a.deleteConversation(N);
218
267
  } catch {
219
- } finally {
220
- p.current && c(!1);
221
268
  }
222
- }, [t, f]), h = I(async (m) => (f(m), await t.getMessages(m)), [t, f]), w = I(() => {
223
- f(null);
224
- }, [f]), k = I(async (m) => {
225
- await t.deleteConversation(m), n((g) => g.filter((N) => N.sessionId !== m)), o === m && f(null);
226
- }, [t, o, f]), b = I(async (m, g) => {
227
- await t.renameConversation(m, g), n(
228
- (N) => N.map((S) => S.sessionId === m ? { ...S, title: g } : S)
269
+ }, [a, o, v]), $ = C(async (N, R) => {
270
+ await a.renameConversation(N, R), i(
271
+ (y) => y.map((g) => g.sessionId === N ? { ...g, title: R } : g)
229
272
  );
230
- }, [t]), { enabled: v = !0 } = a;
231
- return R(() => {
232
- v && u();
233
- }, [v, u]), {
234
- conversations: s,
273
+ }, [a]), { enabled: P = !0 } = t;
274
+ return B(() => {
275
+ P && S();
276
+ }, [P, S]), {
277
+ conversations: r,
235
278
  activeConversationId: o,
236
- loading: l,
237
- loadConversations: u,
238
- switchConversation: h,
239
- newConversation: w,
240
- deleteConversation: k,
241
- renameConversation: b,
242
- setActiveConversationId: f
279
+ loading: c,
280
+ hasMore: f,
281
+ loadConversations: S,
282
+ loadMore: T,
283
+ switchConversation: A,
284
+ newConversation: x,
285
+ deleteConversation: z,
286
+ renameConversation: $,
287
+ setActiveConversationId: v
243
288
  };
244
289
  }
245
- function Q(a) {
246
- return !a && a !== 0 ? "" : a < 1024 ? `${a} B` : a < 1024 * 1024 ? `${(a / 1024).toFixed(1)} KB` : `${(a / 1024 / 1024).toFixed(1)} MB`;
290
+ function oe(t) {
291
+ return !t && t !== 0 ? "" : t < 1024 ? `${t} B` : t < 1024 * 1024 ? `${(t / 1024).toFixed(1)} KB` : `${(t / 1024 / 1024).toFixed(1)} MB`;
247
292
  }
248
- function ee(a) {
249
- return a === "pdf" ? "PDF" : a === "docx" ? "DOC" : a === "html" ? "HTM" : a.slice(0, 3).toUpperCase() || "FILE";
293
+ function le(t) {
294
+ return t === "pdf" ? "PDF" : t === "docx" ? "DOC" : t === "html" ? "HTM" : t.slice(0, 3).toUpperCase() || "FILE";
250
295
  }
251
- function ae(a) {
252
- if (!a) return [];
253
- const t = [];
254
- for (const r of a)
255
- r.type === "file" && r.data && t.push({
256
- id: r.data.id ?? "",
257
- type: r.data.fileType ?? r.data.type ?? "",
258
- filename: r.data.name ?? r.data.filename ?? "",
259
- url: r.data.url ?? "",
260
- mime: r.data.mime,
261
- size: r.data.size,
262
- summary: r.data.summary
296
+ function ce(t) {
297
+ if (!t) return [];
298
+ const a = [];
299
+ for (const s of t)
300
+ s.type === "file" && s.data && a.push({
301
+ id: s.data.id ?? "",
302
+ type: s.data.fileType ?? s.data.type ?? "",
303
+ filename: s.data.name ?? s.data.filename ?? "",
304
+ url: s.data.url ?? "",
305
+ mime: s.data.mime,
306
+ size: s.data.size,
307
+ summary: s.data.summary
263
308
  });
264
- return t;
309
+ return a;
265
310
  }
266
- async function U(a) {
311
+ async function Z(t) {
267
312
  try {
268
- const t = await fetch(a.url);
269
- if (!t.ok) throw new Error(`HTTP ${t.status}`);
270
- const r = await t.blob(), s = URL.createObjectURL(r), n = document.createElement("a");
271
- n.href = s, n.download = a.filename, document.body.appendChild(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(s), 4e3);
313
+ const a = await fetch(t.url);
314
+ if (!a.ok) throw new Error(`HTTP ${a.status}`);
315
+ const s = await a.blob(), n = URL.createObjectURL(s), r = document.createElement("a");
316
+ r.href = n, r.download = t.filename, document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(n), 4e3);
272
317
  } catch {
273
- const t = document.createElement("a");
274
- t.href = a.url, t.download = a.filename, t.target = "_blank", document.body.appendChild(t), t.click(), t.remove();
318
+ const a = document.createElement("a");
319
+ a.href = t.url, a.download = t.filename, a.target = "_blank", document.body.appendChild(a), a.click(), a.remove();
275
320
  }
276
321
  }
277
- const te = ie(null);
278
- function W() {
279
- const a = oe(te);
280
- if (!a) throw new Error("useChatContext must be used within ChatProvider");
281
- return a;
322
+ const de = ge(null);
323
+ function Y() {
324
+ const t = xe(de);
325
+ if (!t) throw new Error("useChatContext must be used within ChatProvider");
326
+ return t;
282
327
  }
283
- function G({ sdk: a, hooks: t, children: r }) {
284
- const [s, n] = T(!1), [o, i] = T(!1), [l, c] = T(null), [p, f] = T(!1);
285
- R(() => {
286
- a.getToken().then(() => {
328
+ function te({ sdk: t, hooks: a, children: s }) {
329
+ const [n, r] = M(!1), [i, o] = M(!1), [l, c] = M(null), [p, f] = M(!1), [h, w] = M(!1);
330
+ B(() => {
331
+ t.getToken().then(() => {
287
332
  f(!0);
288
333
  }).catch(() => {
289
334
  f(!0);
290
335
  });
291
- }, [a]);
292
- const u = pe({
293
- sdk: a,
294
- onConversationChange: t == null ? void 0 : t.onConversationChange,
336
+ }, [t]);
337
+ const u = ye({
338
+ sdk: t,
339
+ onConversationChange: a == null ? void 0 : a.onConversationChange,
295
340
  enabled: p
296
- }), h = ce({
297
- sdk: a,
341
+ }), m = ve({
342
+ sdk: t,
298
343
  sessionId: u.activeConversationId,
299
- onSessionCreated: (y) => {
300
- u.setActiveConversationId(y), u.loadConversations();
344
+ onSessionCreated: (g) => {
345
+ u.setActiveConversationId(g);
301
346
  },
302
- onStreamStart: t == null ? void 0 : t.onStreamStart,
303
- onStreamEnd: (y) => {
304
- var D;
305
- (D = t == null ? void 0 : t.onStreamEnd) == null || D.call(t, y), u.loadConversations();
347
+ onStreamStart: a == null ? void 0 : a.onStreamStart,
348
+ onStreamEnd: (g) => {
349
+ var E;
350
+ (E = a == null ? void 0 : a.onStreamEnd) == null || E.call(a, g), u.loadConversations();
306
351
  },
307
- onError: t == null ? void 0 : t.onError,
308
- onMessageSend: t == null ? void 0 : t.onMessageSend
309
- }), w = I(async (y) => {
310
- const D = await u.switchConversation(y);
311
- h.setMessages(D), n(!1);
312
- }, [u, h]), k = I(() => {
313
- u.newConversation(), h.setMessages([]), n(!1);
314
- }, [u, h]), b = I(async (y) => {
315
- await u.deleteConversation(y), u.activeConversationId === y && h.setMessages([]);
316
- }, [u, h]);
317
- R(() => {
318
- u.activeConversationId && h.messages.length === 0 && a.getMessages(u.activeConversationId).then((y) => {
319
- h.setMessages(y);
352
+ onError: a == null ? void 0 : a.onError,
353
+ onMessageSend: a == null ? void 0 : a.onMessageSend
354
+ }), v = C(async (g) => {
355
+ w(!0);
356
+ try {
357
+ const E = await u.switchConversation(g);
358
+ m.setMessages(E), r(!1);
359
+ } finally {
360
+ w(!1);
361
+ }
362
+ }, [u, m]), S = C(async () => {
363
+ m.setMessages([]), r(!1), await u.newConversation();
364
+ }, [u, m]), T = C(async (g) => {
365
+ u.activeConversationId === g && m.setMessages([]), await u.deleteConversation(g);
366
+ }, [u, m]);
367
+ B(() => {
368
+ u.activeConversationId && m.messages.length === 0 && (w(!0), t.getMessages(u.activeConversationId).then((g) => {
369
+ m.setMessages(g);
320
370
  }).catch(() => {
321
- });
371
+ }).finally(() => w(!1)));
322
372
  }, []);
323
- const v = I(() => {
324
- n((y) => !y);
325
- }, []), m = I(() => {
326
- i((y) => !y), c((y) => null);
327
- }, []), g = I((y) => {
328
- c(y), i(!0);
329
- }, []), N = V(() => {
330
- const y = /* @__PURE__ */ new Set(), D = [];
331
- for (const P of h.messages)
332
- for (const M of P.parts)
333
- if (M.type === "tool_result" && M.artifacts)
334
- for (const E of ae(M.artifacts)) {
335
- const A = E.id || `${E.url}:${E.filename}`;
336
- y.has(A) || (y.add(A), D.push(E));
373
+ const A = C(() => {
374
+ r((g) => !g);
375
+ }, []), x = C(() => {
376
+ o((g) => !g), c((g) => null);
377
+ }, []), z = C((g) => {
378
+ c(g), o(!0);
379
+ }, []), $ = J(() => {
380
+ const g = /* @__PURE__ */ new Set(), E = [];
381
+ for (const L of m.messages)
382
+ for (const k of L.parts)
383
+ if (k.type === "tool_result" && k.artifacts)
384
+ for (const O of ce(k.artifacts)) {
385
+ const b = O.id || `${O.url}:${O.filename}`;
386
+ g.has(b) || (g.add(b), E.push(O));
337
387
  }
338
- return D;
339
- }, [h.messages]), S = I((y, D, P) => {
340
- a.feedback(y, D, P).catch(() => {
388
+ return E;
389
+ }, [m.messages]), P = C(async () => {
390
+ const g = u.activeConversationId;
391
+ if (!g) return null;
392
+ try {
393
+ const E = await t.getMessages(g);
394
+ m.setMessages(E);
395
+ const L = E.findLast((k) => k.role === "assistant");
396
+ return (L == null ? void 0 : L.id) ?? null;
397
+ } catch {
398
+ return null;
399
+ }
400
+ }, [t, u.activeConversationId, m]), N = C((g, E, L) => {
401
+ if (/^\d+$/.test(g)) {
402
+ t.feedback(g, E, L).catch(() => {
403
+ });
404
+ return;
405
+ }
406
+ P().then((k) => {
407
+ k && t.feedback(k, E, L).catch(() => {
408
+ });
341
409
  });
342
- }, [a]), L = I((y) => {
343
- a.cancelFeedback(y).catch(() => {
410
+ }, [t, P]), R = C((g) => {
411
+ if (/^\d+$/.test(g)) {
412
+ t.cancelFeedback(g).catch(() => {
413
+ });
414
+ return;
415
+ }
416
+ P().then((E) => {
417
+ E && t.cancelFeedback(E).catch(() => {
418
+ });
344
419
  });
345
- }, [a]), O = V(() => ({
346
- status: h.status,
347
- error: h.error,
348
- messages: h.messages,
420
+ }, [t, P]), y = J(() => ({
421
+ sdk: t,
422
+ status: m.status,
423
+ error: m.error,
424
+ messages: m.messages,
349
425
  conversations: u.conversations,
350
426
  activeConversationId: u.activeConversationId,
351
- isThreadListOpen: s,
352
- isArtifactDrawerOpen: o,
353
- allArtifacts: N,
427
+ isThreadListOpen: n,
428
+ isArtifactDrawerOpen: i,
429
+ allArtifacts: $,
354
430
  activePreviewArtifact: l,
355
- sendMessage: h.sendMessage,
356
- stop: h.stop,
357
- regenerate: h.regenerate,
358
- switchConversation: w,
359
- newConversation: k,
360
- deleteConversation: b,
431
+ hasMore: u.hasMore,
432
+ conversationsLoading: u.loading,
433
+ messagesLoading: h,
434
+ sendMessage: m.sendMessage,
435
+ stop: m.stop,
436
+ regenerate: m.regenerate,
437
+ switchConversation: v,
438
+ newConversation: S,
439
+ deleteConversation: T,
361
440
  renameConversation: u.renameConversation,
362
- toggleThreadList: v,
363
- toggleArtifactDrawer: m,
364
- openArtifactPreview: g,
365
- feedback: S,
366
- cancelFeedback: L,
367
- respondToInterrupt: h.respondToInterrupt
441
+ loadMoreConversations: u.loadMore,
442
+ toggleThreadList: A,
443
+ toggleArtifactDrawer: x,
444
+ openArtifactPreview: z,
445
+ feedback: N,
446
+ cancelFeedback: R,
447
+ respondToInterrupt: m.respondToInterrupt
368
448
  }), [
369
- h.status,
370
- h.error,
371
- h.messages,
372
- h.sendMessage,
373
- h.stop,
374
- h.regenerate,
375
- h.respondToInterrupt,
449
+ t,
450
+ m.status,
451
+ m.error,
452
+ m.messages,
453
+ m.sendMessage,
454
+ m.stop,
455
+ m.regenerate,
456
+ m.respondToInterrupt,
376
457
  u.conversations,
377
458
  u.activeConversationId,
378
459
  u.renameConversation,
379
- s,
380
- o,
381
- N,
460
+ u.hasMore,
461
+ u.loadMore,
462
+ u.loading,
463
+ n,
464
+ i,
465
+ $,
382
466
  l,
383
- w,
384
- k,
385
- b,
467
+ h,
386
468
  v,
387
- m,
388
- g,
389
469
  S,
390
- L
470
+ T,
471
+ A,
472
+ x,
473
+ z,
474
+ N,
475
+ R
391
476
  ]);
392
- return /* @__PURE__ */ e(te.Provider, { value: O, children: r });
477
+ return /* @__PURE__ */ e(de.Provider, { value: y, children: s });
478
+ }
479
+ const ke = "https://at.alicdn.com/t/c/font_5210396_pffyg5g21kn.js";
480
+ let ae = !1;
481
+ function Ne(t = ke) {
482
+ if (ae || typeof document > "u") return;
483
+ ae = !0;
484
+ const a = t.split("?")[0].split("/").pop();
485
+ if (a && document.querySelector(`script[src*="${a}"]`)) return;
486
+ const s = document.createElement("script");
487
+ s.src = t, document.head.appendChild(s);
393
488
  }
394
- function C({ name: a, size: t = 16, color: r = "currentColor", className: s, style: n }) {
489
+ Ne();
490
+ function I({ name: t, size: a = 16, color: s = "currentColor", className: n, style: r }) {
395
491
  return /* @__PURE__ */ e(
396
492
  "svg",
397
493
  {
398
- className: s,
399
- style: { width: t, height: t, fill: r, verticalAlign: "middle", ...n },
494
+ className: n,
495
+ style: { width: a, height: a, fill: s, verticalAlign: "middle", ...r },
400
496
  "aria-hidden": "true",
401
- children: /* @__PURE__ */ e("use", { href: `#icon-${a}` })
497
+ children: /* @__PURE__ */ e("use", { href: `#icon-${t}` })
402
498
  }
403
499
  );
404
500
  }
405
- function fe({ isOpen: a, onClick: t }) {
406
- 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" }) });
501
+ function Ce({ isOpen: t, onClick: a }) {
502
+ return /* @__PURE__ */ e("button", { className: `sa-trigger ${t ? "sa-trigger-open" : ""}`, onClick: a, children: t ? /* @__PURE__ */ e(I, { name: "x", size: 24, color: "#fff" }) : /* @__PURE__ */ e(I, { name: "message-square", size: 24, color: "#fff" }) });
407
503
  }
408
- function ue({ title: a, onClose: t, onToggleThreadList: r, showClose: s = !0, artifactCount: n = 0, onToggleArtifactDrawer: o }) {
504
+ function ze({ title: t, onClose: a, onToggleThreadList: s, showClose: n = !0, artifactCount: r = 0, onToggleArtifactDrawer: i }) {
409
505
  return /* @__PURE__ */ d("div", { className: "sa-header", children: [
410
506
  /* @__PURE__ */ d("div", { className: "sa-header-left", children: [
411
507
  /* @__PURE__ */ e("div", { className: "sa-header-avatar", children: "A" }),
412
508
  /* @__PURE__ */ d("div", { className: "sa-header-info", children: [
413
- /* @__PURE__ */ e("div", { className: "sa-header-title", children: a }),
509
+ /* @__PURE__ */ e("div", { className: "sa-header-title", children: t }),
414
510
  /* @__PURE__ */ e("div", { className: "sa-header-status", children: "● Online" })
415
511
  ] })
416
512
  ] }),
417
513
  /* @__PURE__ */ d("div", { className: "sa-header-actions", children: [
418
- n > 0 && o && /* @__PURE__ */ d("button", { className: "sa-header-btn sa-header-btn-artifact", onClick: o, title: "会话产物", children: [
514
+ r > 0 && i && /* @__PURE__ */ d("button", { className: "sa-header-btn sa-header-btn-artifact", onClick: i, title: "会话产物", children: [
419
515
  /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
420
516
  /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
421
517
  /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
422
518
  ] }),
423
519
  /* @__PURE__ */ e("span", { children: "产物" })
424
520
  ] }),
425
- /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: r, title: "会话列表", children: /* @__PURE__ */ e(C, { name: "menu", size: 16 }) }),
426
- s && /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: t, title: "关闭", children: /* @__PURE__ */ e(C, { name: "x", size: 16 }) })
521
+ /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: s, title: "会话列表", children: /* @__PURE__ */ e(I, { name: "menu", size: 16 }) }),
522
+ n && /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: a, title: "关闭", children: /* @__PURE__ */ e(I, { name: "x", size: 16 }) })
427
523
  ] })
428
524
  ] });
429
525
  }
430
- function me(a) {
431
- const t = /* @__PURE__ */ new Date(), r = new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime(), s = r - 6 * 864e5, n = [], o = [], i = [];
432
- for (const c of a) {
526
+ const G = (t) => String(t).padStart(2, "0");
527
+ function pe(t) {
528
+ if (!t) return "";
529
+ const a = new Date(t);
530
+ return isNaN(a.getTime()) ? "" : `${a.getFullYear()}-${G(a.getMonth() + 1)}-${G(a.getDate())} ${G(a.getHours())}:${G(a.getMinutes())}:${G(a.getSeconds())}`;
531
+ }
532
+ function Ie(t) {
533
+ const a = /* @__PURE__ */ new Date(), s = new Date(
534
+ a.getFullYear(),
535
+ a.getMonth(),
536
+ a.getDate()
537
+ ).getTime(), n = s - 6 * 864e5, r = [], i = [], o = [];
538
+ for (const c of t) {
433
539
  const p = new Date(c.updateTime).getTime();
434
- p >= r ? n.push(c) : p >= s ? o.push(c) : i.push(c);
540
+ p >= s ? r.push(c) : p >= n ? i.push(c) : o.push(c);
435
541
  }
436
542
  const l = [];
437
- return n.length && l.push({ label: "今天", items: n }), o.length && l.push({ label: "最近 7 天", items: o }), i.length && l.push({ label: "更早", items: i }), l;
543
+ return r.length && l.push({ label: "今天", items: r }), i.length && l.push({ label: "最近 7 天", items: i }), o.length && l.push({ label: "更早", items: o }), l;
438
544
  }
439
- function he() {
545
+ function Se() {
440
546
  const {
441
- conversations: a,
442
- activeConversationId: t,
443
- switchConversation: r,
444
- newConversation: s,
445
- deleteConversation: n,
446
- renameConversation: o,
447
- isThreadListOpen: i,
448
- toggleThreadList: l
449
- } = W(), [c, p] = T(null), [f, u] = T(""), h = I((b, v) => {
450
- p(b), u(v ?? "");
451
- }, []), w = I((b) => {
452
- f.trim() && o(b, f.trim()), p(null);
453
- }, [f, o]), k = V(() => me(a), [a]);
454
- return i ? /* @__PURE__ */ d(q, { children: [
547
+ conversations: t,
548
+ activeConversationId: a,
549
+ switchConversation: s,
550
+ newConversation: n,
551
+ deleteConversation: r,
552
+ renameConversation: i,
553
+ isThreadListOpen: o,
554
+ toggleThreadList: l,
555
+ hasMore: c,
556
+ loadMoreConversations: p,
557
+ conversationsLoading: f
558
+ } = Y(), [h, w] = M(null), [u, m] = M(""), v = _(null), S = C(
559
+ (z, $) => {
560
+ w(z), m($ ?? "");
561
+ },
562
+ []
563
+ ), T = C(
564
+ (z) => {
565
+ u.trim() && i(z, u.trim()), w(null);
566
+ },
567
+ [u, i]
568
+ ), A = C(() => {
569
+ const z = v.current;
570
+ !z || !c || z.scrollHeight - z.scrollTop - z.clientHeight < 50 && p();
571
+ }, [c, p]), x = J(() => Ie(t), [t]);
572
+ return o ? /* @__PURE__ */ d(q, { children: [
455
573
  /* @__PURE__ */ e("div", { className: "sa-thread-list-overlay", onClick: l }),
456
574
  /* @__PURE__ */ d("div", { className: "sa-thread-list", children: [
457
575
  /* @__PURE__ */ d("div", { className: "sa-thread-list-header", children: [
458
576
  /* @__PURE__ */ e("span", { className: "sa-thread-list-title", children: "会话记录" }),
459
- /* @__PURE__ */ d("button", { className: "sa-thread-list-new", onClick: s, children: [
460
- /* @__PURE__ */ e(C, { name: "plus", size: 14 }),
577
+ /* @__PURE__ */ d("button", { className: "sa-thread-list-new", onClick: n, children: [
578
+ /* @__PURE__ */ e(I, { name: "plus", size: 14 }),
461
579
  " 新会话"
462
580
  ] })
463
581
  ] }),
464
- /* @__PURE__ */ d("div", { className: "sa-thread-list-items", children: [
465
- a.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-empty", children: "暂无会话" }),
466
- k.map((b) => /* @__PURE__ */ d("div", { className: "sa-thread-group", children: [
467
- /* @__PURE__ */ e("div", { className: "sa-thread-group-label", children: b.label }),
468
- b.items.map((v) => /* @__PURE__ */ d(
469
- "div",
470
- {
471
- className: `sa-thread-item ${v.sessionId === t ? "active" : ""}`,
472
- onClick: () => r(v.sessionId),
473
- children: [
474
- c === v.sessionId ? /* @__PURE__ */ e(
475
- "input",
476
- {
477
- className: "sa-thread-item-edit",
478
- value: f,
479
- onChange: (m) => u(m.target.value),
480
- onBlur: () => w(v.sessionId),
481
- onKeyDown: (m) => {
482
- m.key === "Enter" && w(v.sessionId), m.key === "Escape" && p(null);
483
- },
484
- onClick: (m) => m.stopPropagation(),
485
- autoFocus: !0
486
- }
487
- ) : /* @__PURE__ */ e(
488
- "span",
489
- {
490
- className: "sa-thread-item-title",
491
- onDoubleClick: (m) => {
492
- m.stopPropagation(), h(v.sessionId, v.title);
493
- },
494
- children: v.title || "新会话"
495
- }
496
- ),
497
- /* @__PURE__ */ e(
498
- "button",
499
- {
500
- className: "sa-thread-item-delete",
501
- onClick: (m) => {
502
- m.stopPropagation(), n(v.sessionId);
503
- },
504
- title: "删除",
505
- children: /* @__PURE__ */ e(C, { name: "trash2", size: 14 })
506
- }
507
- )
508
- ]
509
- },
510
- v.sessionId
511
- ))
512
- ] }, b.label))
513
- ] })
582
+ /* @__PURE__ */ d(
583
+ "div",
584
+ {
585
+ className: "sa-thread-list-items",
586
+ ref: v,
587
+ onScroll: A,
588
+ children: [
589
+ f && t.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-loading", children: "加载中..." }),
590
+ !f && t.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-empty", children: "暂无会话" }),
591
+ x.map((z) => /* @__PURE__ */ d("div", { className: "sa-thread-group", children: [
592
+ /* @__PURE__ */ e("div", { className: "sa-thread-group-label", children: z.label }),
593
+ z.items.map(($) => /* @__PURE__ */ d(
594
+ "div",
595
+ {
596
+ className: `sa-thread-item ${$.sessionId === a ? "active" : ""}`,
597
+ onClick: () => {
598
+ h !== $.sessionId && s($.sessionId);
599
+ },
600
+ children: [
601
+ h === $.sessionId ? /* @__PURE__ */ e(
602
+ "input",
603
+ {
604
+ className: "sa-thread-item-edit",
605
+ value: u,
606
+ onChange: (P) => m(P.target.value),
607
+ onBlur: () => T($.sessionId),
608
+ onKeyDown: (P) => {
609
+ P.key === "Enter" && T($.sessionId), P.key === "Escape" && w(null);
610
+ },
611
+ onClick: (P) => P.stopPropagation(),
612
+ autoFocus: !0
613
+ }
614
+ ) : /* @__PURE__ */ d("div", { className: "sa-thread-item-info", children: [
615
+ /* @__PURE__ */ e("span", { className: "sa-thread-item-title", children: $.title || "新会话" }),
616
+ /* @__PURE__ */ e("span", { className: "sa-thread-item-time", children: pe($.updateTime) })
617
+ ] }),
618
+ /* @__PURE__ */ d("div", { className: "sa-thread-item-actions", children: [
619
+ /* @__PURE__ */ e(
620
+ "button",
621
+ {
622
+ className: "sa-thread-item-action-btn",
623
+ onClick: (P) => {
624
+ P.stopPropagation(), S($.sessionId, $.title);
625
+ },
626
+ title: "重命名",
627
+ children: /* @__PURE__ */ e(I, { name: "pen", size: 13 })
628
+ }
629
+ ),
630
+ /* @__PURE__ */ e(
631
+ "button",
632
+ {
633
+ className: "sa-thread-item-action-btn",
634
+ onClick: (P) => {
635
+ P.stopPropagation(), r($.sessionId);
636
+ },
637
+ title: "删除",
638
+ children: /* @__PURE__ */ e(I, { name: "trash2", size: 13 })
639
+ }
640
+ )
641
+ ] })
642
+ ]
643
+ },
644
+ $.sessionId
645
+ ))
646
+ ] }, z.label)),
647
+ f && t.length > 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-loading", children: c ? "加载更多..." : "加载中..." }),
648
+ !f && c && /* @__PURE__ */ e("div", { className: "sa-thread-list-hint", children: "向下滚动加载更多" })
649
+ ]
650
+ }
651
+ )
514
652
  ] })
515
653
  ] }) : null;
516
654
  }
517
- function ge(a) {
518
- const t = F(null), r = F(!1), s = F(0), n = I(() => {
519
- const i = t.current;
520
- if (!i) return;
521
- const { scrollTop: l, scrollHeight: c, clientHeight: p } = i, f = c - l - p < 40;
522
- l < s.current && !f && (r.current = !0), f && (r.current = !1), s.current = l;
655
+ function Te(t) {
656
+ const a = _(null), s = _(!1), n = _(0), r = C(() => {
657
+ const o = a.current;
658
+ if (!o) return;
659
+ const { scrollTop: l, scrollHeight: c, clientHeight: p } = o, f = c - l - p < 40;
660
+ l < n.current && !f && (s.current = !0), f && (s.current = !1), n.current = l;
523
661
  }, []);
524
- R(() => {
525
- const i = t.current;
526
- if (i)
527
- return i.addEventListener("scroll", n, { passive: !0 }), () => i.removeEventListener("scroll", n);
528
- }, [n]), R(() => {
529
- if (r.current) return;
530
- const i = t.current;
531
- i && requestAnimationFrame(() => {
532
- i.scrollTop = i.scrollHeight;
662
+ B(() => {
663
+ const o = a.current;
664
+ if (o)
665
+ return o.addEventListener("scroll", r, { passive: !0 }), () => o.removeEventListener("scroll", r);
666
+ }, [r]), B(() => {
667
+ if (s.current) return;
668
+ const o = a.current;
669
+ o && requestAnimationFrame(() => {
670
+ o.scrollTop = o.scrollHeight;
533
671
  });
534
- }, a);
535
- const o = I(() => {
536
- r.current = !1;
537
- const i = t.current;
538
- i && (i.scrollTop = i.scrollHeight);
672
+ }, t);
673
+ const i = C(() => {
674
+ s.current = !1;
675
+ const o = a.current;
676
+ o && (o.scrollTop = o.scrollHeight);
539
677
  }, []);
540
- return { containerRef: t, scrollToBottom: o };
678
+ return { containerRef: a, scrollToBottom: i };
541
679
  }
542
- function j(a) {
543
- return a.value++;
680
+ function K(t) {
681
+ return t.value++;
544
682
  }
545
- function K(a, t) {
546
- const r = [], s = [], n = () => {
547
- s.length > 0 && (r.push(s.join("")), s.length = 0);
683
+ function X(t, a) {
684
+ const s = [], n = [], r = () => {
685
+ n.length > 0 && (s.push(n.join("")), n.length = 0);
548
686
  };
549
- let o = 0;
550
- for (; o < a.length; ) {
551
- const i = a[o];
552
- if (i === "`") {
553
- const l = a.indexOf("`", o + 1);
687
+ let i = 0;
688
+ for (; i < t.length; ) {
689
+ const o = t[i];
690
+ if (o === "`") {
691
+ const l = t.indexOf("`", i + 1);
554
692
  if (l !== -1) {
555
- n(), r.push(
556
- /* @__PURE__ */ e("code", { className: "sa-inline-code", children: a.slice(o + 1, l) }, j(t))
557
- ), o = l + 1;
693
+ r(), s.push(
694
+ /* @__PURE__ */ e("code", { className: "sa-inline-code", children: t.slice(i + 1, l) }, K(a))
695
+ ), i = l + 1;
558
696
  continue;
559
697
  }
560
- } else if (i === "*" && a[o + 1] === "*") {
561
- const l = a.indexOf("**", o + 2);
698
+ } else if (o === "*" && t[i + 1] === "*") {
699
+ const l = t.indexOf("**", i + 2);
562
700
  if (l !== -1) {
563
- n(), r.push(
564
- /* @__PURE__ */ e("strong", { children: K(a.slice(o + 2, l), t) }, j(t))
565
- ), o = l + 2;
701
+ r(), s.push(
702
+ /* @__PURE__ */ e("strong", { children: X(t.slice(i + 2, l), a) }, K(a))
703
+ ), i = l + 2;
566
704
  continue;
567
705
  }
568
- } else if (i === "*") {
569
- const l = a.indexOf("*", o + 1);
706
+ } else if (o === "*") {
707
+ const l = t.indexOf("*", i + 1);
570
708
  if (l !== -1) {
571
- n(), r.push(
572
- /* @__PURE__ */ e("em", { children: K(a.slice(o + 1, l), t) }, j(t))
573
- ), o = l + 1;
709
+ r(), s.push(
710
+ /* @__PURE__ */ e("em", { children: X(t.slice(i + 1, l), a) }, K(a))
711
+ ), i = l + 1;
574
712
  continue;
575
713
  }
576
- } else if (i === "[") {
577
- const l = a.indexOf("]", o + 1);
578
- if (l !== -1 && a[l + 1] === "(") {
579
- const c = a.indexOf(")", l + 2);
714
+ } else if (o === "[") {
715
+ const l = t.indexOf("]", i + 1);
716
+ if (l !== -1 && t[l + 1] === "(") {
717
+ const c = t.indexOf(")", l + 2);
580
718
  if (c !== -1) {
581
- const p = a.slice(o + 1, l), f = a.slice(l + 2, c);
582
- n(), r.push(
719
+ const p = t.slice(i + 1, l), f = t.slice(l + 2, c);
720
+ r(), s.push(
583
721
  /* @__PURE__ */ e(
584
722
  "a",
585
723
  {
586
724
  href: f,
587
725
  target: "_blank",
588
726
  rel: "noreferrer",
589
- children: K(p, t)
727
+ children: X(p, a)
590
728
  },
591
- j(t)
729
+ K(a)
592
730
  )
593
- ), o = c + 1;
731
+ ), i = c + 1;
594
732
  continue;
595
733
  }
596
734
  }
597
735
  }
598
- s.push(i), o++;
736
+ n.push(o), i++;
599
737
  }
600
- return n(), r;
738
+ return r(), s;
601
739
  }
602
- function be(a, t) {
603
- const r = [], s = a.split(`
740
+ function Me(t, a) {
741
+ const s = [], n = t.split(`
604
742
  `);
605
- let n = 0;
606
- const o = (c) => c.trim() === "", i = (c) => /^#{1,6}\s+\S/.test(c.trim()), l = (c) => /^(?:[-*+]|\d+[.)])\s+\S/.test(c.trim());
607
- for (; n < s.length; ) {
608
- const c = s[n], p = c.trim();
609
- if (o(c)) {
610
- n++;
743
+ let r = 0;
744
+ const i = (c) => c.trim() === "", o = (c) => /^#{1,6}\s+\S/.test(c.trim()), l = (c) => /^(?:[-*+]|\d+[.)])\s+\S/.test(c.trim());
745
+ for (; r < n.length; ) {
746
+ const c = n[r], p = c.trim();
747
+ if (i(c)) {
748
+ r++;
611
749
  continue;
612
750
  }
613
- if (i(c)) {
614
- const u = p.match(/^(#{1,6})\s+(.*)$/);
615
- if (u) {
616
- const w = `h${Math.min(u[1].length, 6)}`;
617
- r.push(
618
- Y.createElement(
619
- w,
620
- { key: j(t) },
621
- K(u[2], t)
751
+ if (o(c)) {
752
+ const h = p.match(/^(#{1,6})\s+(.*)$/);
753
+ if (h) {
754
+ const u = `h${Math.min(h[1].length, 6)}`;
755
+ s.push(
756
+ V.createElement(
757
+ u,
758
+ { key: K(a) },
759
+ X(h[2], a)
622
760
  )
623
761
  );
624
762
  }
625
- n++;
763
+ r++;
626
764
  continue;
627
765
  }
628
766
  if (l(c)) {
629
- const u = /^\d+[.)]/.test(p), h = [];
630
- for (; n < s.length && l(s[n]); ) {
631
- const w = s[n].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);
632
- w && h.push(
633
- /* @__PURE__ */ e("li", { children: K(w[1], t) }, j(t))
634
- ), n++;
767
+ const h = /^\d+[.)]/.test(p), w = [];
768
+ for (; r < n.length && l(n[r]); ) {
769
+ const u = n[r].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);
770
+ u && w.push(
771
+ /* @__PURE__ */ e("li", { children: X(u[1], a) }, K(a))
772
+ ), r++;
635
773
  }
636
- r.push(
637
- u ? /* @__PURE__ */ e("ol", { className: "sa-list", children: h }, j(t)) : /* @__PURE__ */ e("ul", { className: "sa-list", children: h }, j(t))
774
+ s.push(
775
+ h ? /* @__PURE__ */ e("ol", { className: "sa-list", children: w }, K(a)) : /* @__PURE__ */ e("ul", { className: "sa-list", children: w }, K(a))
638
776
  );
639
777
  continue;
640
778
  }
641
779
  const f = [];
642
- for (; n < s.length && !o(s[n]) && !i(s[n]) && !l(s[n]); )
643
- f.push(s[n]), n++;
644
- r.push(
645
- /* @__PURE__ */ e("p", { className: "sa-text-paragraph", children: K(f.join(" "), t) }, j(t))
780
+ for (; r < n.length && !i(n[r]) && !o(n[r]) && !l(n[r]); )
781
+ f.push(n[r]), r++;
782
+ s.push(
783
+ /* @__PURE__ */ e("p", { className: "sa-text-paragraph", children: X(f.join(" "), a) }, K(a))
646
784
  );
647
785
  }
648
- return r;
786
+ return s;
649
787
  }
650
- function xe(a) {
651
- const t = { value: 0 }, r = [], s = a.split("```");
652
- for (let n = 0; n < s.length; n++)
653
- if (n % 2 === 0)
654
- r.push(...be(s[n], t));
655
- else if (s[n].trim() !== "") {
656
- let o = s[n].replace(/^\r?\n/, "");
657
- o = o.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/, ""), o = o.replace(/\r?\n$/, ""), r.push(
658
- /* @__PURE__ */ e("pre", { className: "sa-code-block", children: /* @__PURE__ */ e("code", { children: o }) }, j(t))
788
+ function $e(t) {
789
+ const a = { value: 0 }, s = [], n = t.split("```");
790
+ for (let r = 0; r < n.length; r++)
791
+ if (r % 2 === 0)
792
+ s.push(...Me(n[r], a));
793
+ else if (n[r].trim() !== "") {
794
+ let i = n[r].replace(/^\r?\n/, "");
795
+ i = i.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/, ""), i = i.replace(/\r?\n$/, ""), s.push(
796
+ /* @__PURE__ */ e("pre", { className: "sa-code-block", children: /* @__PURE__ */ e("code", { children: i }) }, K(a))
659
797
  );
660
798
  }
661
- return r;
799
+ return s;
662
800
  }
663
- function ve({ content: a }) {
664
- return /* @__PURE__ */ e("div", { className: "sa-text-part", children: xe(a) });
801
+ function De({ content: t }) {
802
+ return /* @__PURE__ */ e("div", { className: "sa-text-part", children: $e(t) });
665
803
  }
666
- function we({ content: a }) {
667
- const [t, r] = T(!1);
668
- return /* @__PURE__ */ d("div", { className: "sa-thinking-part", onClick: () => r(!t), children: [
804
+ function Le({ content: t }) {
805
+ const [a, s] = M(!1);
806
+ return /* @__PURE__ */ d("div", { className: "sa-thinking-part", onClick: () => s(!a), children: [
669
807
  /* @__PURE__ */ d("div", { className: "sa-thinking-header", children: [
670
- /* @__PURE__ */ e("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ e(C, { name: "brain", size: 14 }) }),
808
+ /* @__PURE__ */ e("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ e(I, { name: "brain", size: 14 }) }),
671
809
  /* @__PURE__ */ e("span", { className: "sa-thinking-label", children: "思考过程" }),
672
- /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${t ? "expanded" : ""}`, children: /* @__PURE__ */ e(C, { name: "chevron-right", size: 12 }) })
810
+ /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${a ? "expanded" : ""}`, children: /* @__PURE__ */ e(I, { name: "chevron-right", size: 12 }) })
673
811
  ] }),
674
- t && /* @__PURE__ */ e("div", { className: "sa-thinking-content", children: a })
812
+ a && /* @__PURE__ */ e("div", { className: "sa-thinking-content", children: t })
675
813
  ] });
676
814
  }
677
- function ye({ toolName: a, toolCallId: t, args: r }) {
678
- const [s, n] = T(!1);
679
- let o = r;
815
+ function Ee({ toolName: t, toolCallId: a, args: s }) {
816
+ const [n, r] = M(!1), [i, o] = M(!1);
817
+ let l = s;
680
818
  try {
681
- o = JSON.stringify(JSON.parse(r), null, 2);
819
+ l = JSON.stringify(JSON.parse(s), null, 2);
682
820
  } catch {
683
821
  }
822
+ const c = C(() => {
823
+ var p;
824
+ (p = navigator.clipboard) == null || p.writeText(l).then(() => {
825
+ o(!0), setTimeout(() => o(!1), 2e3);
826
+ }).catch(() => {
827
+ });
828
+ }, [l]);
684
829
  return /* @__PURE__ */ d("div", { className: "sa-tool-call-part", children: [
685
- /* @__PURE__ */ d("div", { className: "sa-tool-call-header", onClick: () => n(!s), children: [
686
- /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(C, { name: "zap", size: 14 }) }),
830
+ /* @__PURE__ */ d("div", { className: "sa-tool-call-header", onClick: () => r(!n), children: [
831
+ /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(I, { name: "zap", size: 14 }) }),
687
832
  /* @__PURE__ */ d("span", { className: "sa-tool-name", children: [
688
833
  "调用工具: ",
689
- a
834
+ t
690
835
  ] }),
691
- /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${s ? "expanded" : ""}`, children: /* @__PURE__ */ e(C, { name: "chevron-right", size: 12 }) })
836
+ /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${n ? "expanded" : ""}`, children: /* @__PURE__ */ e(I, { name: "chevron-right", size: 12 }) })
692
837
  ] }),
693
- s && /* @__PURE__ */ e("pre", { className: "sa-tool-args", children: o })
838
+ n && /* @__PURE__ */ d(q, { children: [
839
+ /* @__PURE__ */ e("pre", { className: "sa-tool-args", children: l }),
840
+ /* @__PURE__ */ e("div", { className: "sa-tool-result-actions", children: /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: c, title: "复制", children: [
841
+ /* @__PURE__ */ e(I, { name: i ? "circle-check" : "copy", size: 14 }),
842
+ " ",
843
+ i ? "已复制" : "复制"
844
+ ] }) })
845
+ ] })
846
+ ] });
847
+ }
848
+ function re({ text: t }) {
849
+ const [a, s] = M(!1);
850
+ return /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: () => {
851
+ var r;
852
+ (r = navigator.clipboard) == null || r.writeText(t).then(() => {
853
+ s(!0), setTimeout(() => s(!1), 2e3);
854
+ }).catch(() => {
855
+ });
856
+ }, title: "复制", children: [
857
+ /* @__PURE__ */ e(I, { name: a ? "circle-check" : "copy", size: 14 }),
858
+ " ",
859
+ a ? "已复制" : "复制"
694
860
  ] });
695
861
  }
696
- function ke({ html: a }) {
697
- const [t, r] = T(null);
698
- return R(() => {
699
- let s = !1;
700
- return import("./purify.es-C-6FFqDW.js").then((n) => {
701
- s || r(n.default.sanitize(a, { FORCE_BODY: !0 }));
862
+ function Ae({ html: t }) {
863
+ const [a, s] = M(null);
864
+ return B(() => {
865
+ let n = !1;
866
+ return import("./purify.es-C-6FFqDW.js").then((r) => {
867
+ n || s(r.default.sanitize(t, { FORCE_BODY: !0, ADD_ATTR: ["target"] }));
702
868
  }), () => {
703
- s = !0;
869
+ n = !0;
704
870
  };
705
- }, [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 产物" }) });
871
+ }, [t]), a === null ? null : /* @__PURE__ */ e("div", { className: "sa-tool-result-html-scroll", children: /* @__PURE__ */ e("div", { className: "sa-tool-result-html sa-text-part", dangerouslySetInnerHTML: { __html: a } }) });
706
872
  }
707
- function Ce({ toolName: a, content: t, artifacts: r, renderMode: s, html: n, artifactPreview: o }) {
708
- const { openArtifactPreview: i } = W(), l = ae(r);
873
+ function Re({ toolName: t, content: a, artifacts: s, renderMode: n, html: r, artifactPreview: i }) {
874
+ const { openArtifactPreview: o } = Y(), l = ce(s);
709
875
  return /* @__PURE__ */ d("div", { className: "sa-tool-result-part", children: [
710
876
  /* @__PURE__ */ d("div", { className: "sa-tool-result-header", children: [
711
- /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(C, { name: "circle-check", size: 14, color: "#10b981" }) }),
712
- /* @__PURE__ */ e("span", { className: "sa-tool-result-label", children: a || "工具返回" })
877
+ /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(I, { name: "circle-check", size: 14, color: "#10b981" }) }),
878
+ /* @__PURE__ */ e("span", { className: "sa-tool-result-label", children: t || "工具返回" })
713
879
  ] }),
714
- s === "html" && n ? /* @__PURE__ */ e(ke, { html: n }) : t ? /* @__PURE__ */ e("div", { className: "sa-tool-result-content", children: t }) : null,
880
+ n === "html" && r ? /* @__PURE__ */ d(q, { children: [
881
+ /* @__PURE__ */ e(Ae, { html: r }),
882
+ /* @__PURE__ */ e("div", { className: "sa-tool-result-actions", children: /* @__PURE__ */ e(re, { text: r }) })
883
+ ] }) : a ? /* @__PURE__ */ d(q, { children: [
884
+ /* @__PURE__ */ e("pre", { className: "sa-tool-result-content", children: a }),
885
+ /* @__PURE__ */ e("div", { className: "sa-tool-result-actions", children: /* @__PURE__ */ e(re, { text: a }) })
886
+ ] }) : /* @__PURE__ */ e("pre", { className: "sa-tool-result-content", children: "—" }),
715
887
  l.length > 0 && /* @__PURE__ */ e("ul", { className: "sa-artifact-file-list", role: "list", children: l.map((c, p) => /* @__PURE__ */ d(
716
888
  "li",
717
889
  {
718
890
  className: "sa-artifact-file-card",
719
- onClick: o ? () => i(c) : void 0,
720
- onKeyDown: o ? (f) => {
721
- (f.key === "Enter" || f.key === " ") && (f.preventDefault(), i(c));
891
+ onClick: i ? () => o(c) : void 0,
892
+ onKeyDown: i ? (f) => {
893
+ (f.key === "Enter" || f.key === " ") && (f.preventDefault(), o(c));
722
894
  } : void 0,
723
- tabIndex: o ? 0 : void 0,
724
- role: o ? "button" : void 0,
725
- "aria-label": o ? `预览 ${c.filename}` : void 0,
726
- style: o ? { cursor: "pointer" } : void 0,
895
+ tabIndex: i ? 0 : void 0,
896
+ role: i ? "button" : void 0,
897
+ "aria-label": i ? `预览 ${c.filename}` : void 0,
898
+ style: i ? { cursor: "pointer" } : void 0,
727
899
  children: [
728
- /* @__PURE__ */ e("div", { className: "sa-artifact-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(c.type) }) }),
900
+ /* @__PURE__ */ e("div", { className: "sa-artifact-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: le(c.type) }) }),
729
901
  /* @__PURE__ */ d("div", { className: "sa-artifact-file-info", children: [
730
902
  /* @__PURE__ */ e("span", { className: "sa-artifact-file-name", children: c.filename }),
731
- c.size != null && /* @__PURE__ */ e("span", { className: "sa-artifact-file-size", children: Q(c.size) })
903
+ c.size != null && /* @__PURE__ */ e("span", { className: "sa-artifact-file-size", children: oe(c.size) })
732
904
  ] }),
733
- o && /* @__PURE__ */ e(
905
+ i && /* @__PURE__ */ e(
734
906
  "button",
735
907
  {
736
908
  className: "sa-artifact-file-download",
737
909
  title: "下载",
738
910
  "aria-label": `下载 ${c.filename}`,
739
911
  onClick: (f) => {
740
- f.stopPropagation(), U(c);
912
+ f.stopPropagation(), Z(c);
741
913
  },
742
914
  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" }) })
743
915
  }
@@ -748,270 +920,324 @@ function Ce({ toolName: a, content: t, artifacts: r, renderMode: s, html: n, art
748
920
  )) })
749
921
  ] });
750
922
  }
751
- function Ne({ content: a, onRetry: t }) {
923
+ function Oe({ content: t, onRetry: a }) {
752
924
  return /* @__PURE__ */ d("div", { className: "sa-error-part", children: [
753
925
  /* @__PURE__ */ d("div", { className: "sa-error-content", children: [
754
- /* @__PURE__ */ e("span", { className: "sa-error-icon", children: /* @__PURE__ */ e(C, { name: "triangle-alert", size: 14 }) }),
755
- /* @__PURE__ */ e("span", { children: a })
926
+ /* @__PURE__ */ e("span", { className: "sa-error-icon", children: /* @__PURE__ */ e(I, { name: "triangle-alert", size: 14 }) }),
927
+ /* @__PURE__ */ e("span", { children: t })
756
928
  ] }),
757
- t && /* @__PURE__ */ e("button", { className: "sa-error-retry", onClick: t, children: "重试" })
929
+ a && /* @__PURE__ */ e("button", { className: "sa-error-retry", onClick: a, children: "重试" })
758
930
  ] });
759
931
  }
760
- function ze({ interrupt: a, onRespond: t }) {
761
- var o, i;
762
- const r = a.options, s = (typeof (r == null ? void 0 : r[0]) == "string" ? r[0] : (o = r == null ? void 0 : r[0]) == null ? void 0 : o.label) || "确认", n = (typeof (r == null ? void 0 : r[1]) == "string" ? r[1] : (i = r == null ? void 0 : r[1]) == null ? void 0 : i.label) || "取消";
932
+ function Pe({ interrupt: t, onRespond: a, disabled: s, answeredAction: n }) {
933
+ var l, c;
934
+ const r = t.options, i = (typeof (r == null ? void 0 : r[0]) == "string" ? r[0] : (l = r == null ? void 0 : r[0]) == null ? void 0 : l.label) || "确认", o = (typeof (r == null ? void 0 : r[1]) == "string" ? r[1] : (c = r == null ? void 0 : r[1]) == null ? void 0 : c.label) || "取消";
763
935
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
764
936
  /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
765
- /* @__PURE__ */ e(C, { name: "circle-alert", size: 16, color: "#f59e0b" }),
766
- /* @__PURE__ */ e("span", { children: a.content })
937
+ /* @__PURE__ */ e(I, { name: "circle-alert", size: 16, color: "#f59e0b" }),
938
+ /* @__PURE__ */ e("span", { children: t.content })
767
939
  ] }),
768
940
  /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
769
- /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", onClick: () => t({ action: "confirm" }), children: [
770
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
771
- " ",
772
- s
773
- ] }),
774
- /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "cancel" }), children: [
775
- /* @__PURE__ */ e(C, { name: "x", size: 14 }),
776
- " ",
777
- n
778
- ] })
779
- ] })
941
+ /* @__PURE__ */ d(
942
+ "button",
943
+ {
944
+ className: `sa-interrupt-btn sa-interrupt-btn-primary ${n === "confirm" ? "sa-interrupt-btn-answered" : ""}`,
945
+ disabled: s,
946
+ onClick: () => a({ action: "confirm" }),
947
+ children: [
948
+ /* @__PURE__ */ e(I, { name: "check", size: 14 }),
949
+ " ",
950
+ i
951
+ ]
952
+ }
953
+ ),
954
+ /* @__PURE__ */ d(
955
+ "button",
956
+ {
957
+ className: `sa-interrupt-btn sa-interrupt-btn-secondary ${n === "cancel" ? "sa-interrupt-btn-answered" : ""}`,
958
+ disabled: s,
959
+ onClick: () => a({ action: "cancel" }),
960
+ children: [
961
+ /* @__PURE__ */ e(I, { name: "x", size: 14 }),
962
+ " ",
963
+ o
964
+ ]
965
+ }
966
+ )
967
+ ] }),
968
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
780
969
  ] });
781
970
  }
782
- function Ie({ interrupt: a, onRespond: t }) {
783
- var l, c, p, f;
784
- const r = a.options, s = (typeof (r == null ? void 0 : r[0]) == "string" ? r[0] : (l = r == null ? void 0 : r[0]) == null ? void 0 : l.label) || "批准", n = (typeof (r == null ? void 0 : r[1]) == "string" ? r[1] : (c = r == null ? void 0 : r[1]) == null ? void 0 : c.label) || "拒绝", o = (typeof (r == null ? void 0 : r[2]) == "string" ? r[2] : (p = r == null ? void 0 : r[2]) == null ? void 0 : p.label) || "跳过", i = ((f = a.metadata) == null ? void 0 : f.showSkip) !== !1;
971
+ function He({ interrupt: t, onRespond: a, disabled: s, answeredAction: n }) {
972
+ var p, f, h, w;
973
+ const r = t.options, i = (typeof (r == null ? void 0 : r[0]) == "string" ? r[0] : (p = r == null ? void 0 : r[0]) == null ? void 0 : p.label) || "批准", o = (typeof (r == null ? void 0 : r[1]) == "string" ? r[1] : (f = r == null ? void 0 : r[1]) == null ? void 0 : f.label) || "拒绝", l = (typeof (r == null ? void 0 : r[2]) == "string" ? r[2] : (h = r == null ? void 0 : r[2]) == null ? void 0 : h.label) || "跳过", c = ((w = t.metadata) == null ? void 0 : w.showSkip) !== !1;
785
974
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
786
975
  /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
787
- /* @__PURE__ */ e(C, { name: "circle-alert", size: 16, color: "#f59e0b" }),
788
- /* @__PURE__ */ e("span", { children: a.content })
976
+ /* @__PURE__ */ e(I, { name: "circle-alert", size: 16, color: "#f59e0b" }),
977
+ /* @__PURE__ */ e("span", { children: t.content })
789
978
  ] }),
790
979
  /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
791
- /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", onClick: () => t({ action: "approve" }), children: [
792
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
793
- " ",
794
- s
795
- ] }),
796
- /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-danger", onClick: () => t({ action: "reject" }), children: [
797
- /* @__PURE__ */ e(C, { name: "x", size: 14 }),
798
- " ",
799
- n
800
- ] }),
801
- i && /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "skip" }), children: [
802
- /* @__PURE__ */ e(C, { name: "chevron-right", size: 14 }),
803
- " ",
804
- o
805
- ] })
806
- ] })
980
+ /* @__PURE__ */ d(
981
+ "button",
982
+ {
983
+ className: `sa-interrupt-btn sa-interrupt-btn-primary ${n === "approve" ? "sa-interrupt-btn-answered" : ""}`,
984
+ disabled: s,
985
+ onClick: () => a({ action: "approve" }),
986
+ children: [
987
+ /* @__PURE__ */ e(I, { name: "check", size: 14 }),
988
+ " ",
989
+ i
990
+ ]
991
+ }
992
+ ),
993
+ /* @__PURE__ */ d(
994
+ "button",
995
+ {
996
+ className: `sa-interrupt-btn sa-interrupt-btn-danger ${n === "reject" ? "sa-interrupt-btn-answered" : ""}`,
997
+ disabled: s,
998
+ onClick: () => a({ action: "reject" }),
999
+ children: [
1000
+ /* @__PURE__ */ e(I, { name: "x", size: 14 }),
1001
+ " ",
1002
+ o
1003
+ ]
1004
+ }
1005
+ ),
1006
+ c && /* @__PURE__ */ d(
1007
+ "button",
1008
+ {
1009
+ className: `sa-interrupt-btn sa-interrupt-btn-secondary ${n === "skip" ? "sa-interrupt-btn-answered" : ""}`,
1010
+ disabled: s,
1011
+ onClick: () => a({ action: "skip" }),
1012
+ children: [
1013
+ /* @__PURE__ */ e(I, { name: "chevron-right", size: 14 }),
1014
+ " ",
1015
+ l
1016
+ ]
1017
+ }
1018
+ )
1019
+ ] }),
1020
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
807
1021
  ] });
808
1022
  }
809
- function Te(a) {
810
- return typeof a == "string" ? { value: a, label: a } : a;
1023
+ function _e(t) {
1024
+ return typeof t == "string" ? { value: t, label: t } : t;
811
1025
  }
812
- function Se({ interrupt: a, onRespond: t }) {
813
- const r = (a.options ?? []).map(Te);
1026
+ function Be({ interrupt: t, onRespond: a, disabled: s, initialValue: n }) {
1027
+ const r = (t.options ?? []).map(_e);
814
1028
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
815
1029
  /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
816
- /* @__PURE__ */ e(C, { name: "list", size: 16, color: "#6366f1" }),
817
- /* @__PURE__ */ e("span", { children: a.content })
1030
+ /* @__PURE__ */ e(I, { name: "list", size: 16, color: "#6366f1" }),
1031
+ /* @__PURE__ */ e("span", { children: t.content })
818
1032
  ] }),
819
- /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((s) => /* @__PURE__ */ d(
820
- "button",
821
- {
822
- className: `sa-interrupt-option ${s.danger ? "sa-interrupt-option-danger" : ""}`,
823
- onClick: () => t({ action: "select", value: s.value }),
824
- children: [
825
- s.icon && /* @__PURE__ */ e(C, { name: s.icon, size: 14 }),
826
- /* @__PURE__ */ e("span", { children: s.label }),
827
- s.description && /* @__PURE__ */ e("span", { className: "sa-interrupt-option-desc", children: s.description })
828
- ]
829
- },
830
- s.value
831
- )) })
1033
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((i) => {
1034
+ const o = n === i.value;
1035
+ return /* @__PURE__ */ d(
1036
+ "button",
1037
+ {
1038
+ className: `sa-interrupt-option ${i.danger ? "sa-interrupt-option-danger" : ""} ${o ? "sa-interrupt-option-selected" : ""}`,
1039
+ disabled: s,
1040
+ onClick: () => a({ action: "select", value: i.value }),
1041
+ children: [
1042
+ /* @__PURE__ */ e(I, { name: o ? "circle-check" : "circle", size: 14 }),
1043
+ i.icon && /* @__PURE__ */ e(I, { name: i.icon, size: 14 }),
1044
+ /* @__PURE__ */ e("span", { children: i.label }),
1045
+ i.description && /* @__PURE__ */ e("span", { className: "sa-interrupt-option-desc", children: i.description })
1046
+ ]
1047
+ },
1048
+ i.value
1049
+ );
1050
+ }) }),
1051
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
832
1052
  ] });
833
1053
  }
834
- function Me(a) {
835
- return typeof a == "string" ? { value: a, label: a } : a;
1054
+ function je(t) {
1055
+ return typeof t == "string" ? { value: t, label: t } : t;
836
1056
  }
837
- function Le({ interrupt: a, onRespond: t }) {
838
- const r = (a.options ?? []).map(Me), [s, n] = T(/* @__PURE__ */ new Set()), o = (i) => {
839
- n((l) => {
840
- const c = new Set(l);
841
- return c.has(i) ? c.delete(i) : c.add(i), c;
1057
+ function Fe({ interrupt: t, onRespond: a, disabled: s, initialValue: n }) {
1058
+ const r = (t.options ?? []).map(je), [i, o] = M(
1059
+ () => new Set(Array.isArray(n) ? n : [])
1060
+ ), l = (c) => {
1061
+ s || o((p) => {
1062
+ const f = new Set(p);
1063
+ return f.has(c) ? f.delete(c) : f.add(c), f;
842
1064
  });
843
1065
  };
844
1066
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
845
1067
  /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
846
- /* @__PURE__ */ e(C, { name: "list-checks", size: 16, color: "#6366f1" }),
847
- /* @__PURE__ */ e("span", { children: a.content })
1068
+ /* @__PURE__ */ e(I, { name: "list-checks", size: 16, color: "#6366f1" }),
1069
+ /* @__PURE__ */ e("span", { children: t.content })
848
1070
  ] }),
849
- /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((i) => /* @__PURE__ */ d(
1071
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((c) => /* @__PURE__ */ d(
850
1072
  "button",
851
1073
  {
852
- className: `sa-interrupt-option ${s.has(i.value) ? "sa-interrupt-option-selected" : ""}`,
853
- onClick: () => o(i.value),
1074
+ className: `sa-interrupt-option ${i.has(c.value) ? "sa-interrupt-option-selected" : ""}`,
1075
+ disabled: s,
1076
+ onClick: () => l(c.value),
854
1077
  children: [
855
- /* @__PURE__ */ e(C, { name: s.has(i.value) ? "square-check" : "square", size: 14 }),
856
- /* @__PURE__ */ e("span", { children: i.label })
1078
+ /* @__PURE__ */ e(I, { name: i.has(c.value) ? "square-check" : "square", size: 14 }),
1079
+ /* @__PURE__ */ e("span", { children: c.label })
857
1080
  ]
858
1081
  },
859
- i.value
1082
+ c.value
860
1083
  )) }),
861
- /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
1084
+ !s && /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
862
1085
  "button",
863
1086
  {
864
1087
  className: "sa-interrupt-btn sa-interrupt-btn-primary",
865
- disabled: s.size === 0,
866
- onClick: () => t({ action: "submit", value: Array.from(s) }),
1088
+ disabled: i.size === 0,
1089
+ onClick: () => a({ action: "submit", value: Array.from(i) }),
867
1090
  children: [
868
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
1091
+ /* @__PURE__ */ e(I, { name: "check", size: 14 }),
869
1092
  " 确认 (",
870
- s.size,
1093
+ i.size,
871
1094
  ")"
872
1095
  ]
873
1096
  }
874
- ) })
1097
+ ) }),
1098
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
875
1099
  ] });
876
1100
  }
877
- function De({ interrupt: a, onRespond: t }) {
878
- const [r, s] = T(""), n = a.inputType ?? "text", o = n === "textarea", i = () => {
879
- a.required && !r.trim() || t({ action: "submit", value: r.trim() });
1101
+ function We({ interrupt: t, onRespond: a, disabled: s, initialValue: n }) {
1102
+ const [r, i] = M(n ?? ""), o = t.inputType ?? "text", l = o === "textarea", c = () => {
1103
+ s || t.required && !r.trim() || a({ action: "submit", value: r.trim() });
880
1104
  };
881
1105
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
882
1106
  /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
883
- /* @__PURE__ */ e(C, { name: "text-cursor-input", size: 16, color: "#6366f1" }),
884
- /* @__PURE__ */ e("span", { children: a.content })
1107
+ /* @__PURE__ */ e(I, { name: "text-cursor-input", size: 16, color: "#6366f1" }),
1108
+ /* @__PURE__ */ e("span", { children: t.content })
885
1109
  ] }),
886
- /* @__PURE__ */ e("div", { className: "sa-interrupt-input-area", children: o ? /* @__PURE__ */ e(
1110
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-input-area", children: l ? /* @__PURE__ */ e(
887
1111
  "textarea",
888
1112
  {
889
1113
  className: "sa-interrupt-textarea",
890
1114
  value: r,
891
- onChange: (l) => s(l.target.value),
892
- placeholder: a.placeholder,
893
- maxLength: a.maxLength,
894
- rows: 3
1115
+ onChange: (p) => i(p.target.value),
1116
+ placeholder: t.placeholder,
1117
+ maxLength: t.maxLength,
1118
+ rows: 3,
1119
+ disabled: s
895
1120
  }
896
1121
  ) : /* @__PURE__ */ e(
897
1122
  "input",
898
1123
  {
899
1124
  className: "sa-interrupt-input",
900
- type: n,
1125
+ type: o,
901
1126
  value: r,
902
- onChange: (l) => s(l.target.value),
903
- placeholder: a.placeholder,
904
- maxLength: a.maxLength,
905
- onKeyDown: (l) => l.key === "Enter" && i()
1127
+ onChange: (p) => i(p.target.value),
1128
+ placeholder: t.placeholder,
1129
+ maxLength: t.maxLength,
1130
+ onKeyDown: (p) => p.key === "Enter" && c(),
1131
+ disabled: s
906
1132
  }
907
1133
  ) }),
908
- /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
1134
+ !s && /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
909
1135
  "button",
910
1136
  {
911
1137
  className: "sa-interrupt-btn sa-interrupt-btn-primary",
912
- disabled: a.required ? !r.trim() : !1,
913
- onClick: i,
1138
+ disabled: t.required ? !r.trim() : !1,
1139
+ onClick: c,
914
1140
  children: [
915
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
1141
+ /* @__PURE__ */ e(I, { name: "check", size: 14 }),
916
1142
  " 提交"
917
1143
  ]
918
1144
  }
919
- ) })
1145
+ ) }),
1146
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
920
1147
  ] });
921
1148
  }
922
- function Ee({ interrupt: a, onRespond: t }) {
923
- const r = a.fields ?? [], [s, n] = T(() => {
924
- const c = {};
925
- for (const p of r)
926
- c[p.name] = p.defaultValue ?? "";
927
- return c;
928
- }), o = (c, p) => {
929
- n((f) => ({ ...f, [c]: p }));
930
- }, i = r.every((c) => !c.required || s[c.name]), l = () => {
931
- i && t({ action: "submit", value: s });
1149
+ function Ke({ interrupt: t, onRespond: a, disabled: s, initialValue: n }) {
1150
+ const r = t.fields ?? [], [i, o] = M(() => {
1151
+ const f = {};
1152
+ for (const h of r)
1153
+ f[h.name] = (n == null ? void 0 : n[h.name]) ?? h.defaultValue ?? "";
1154
+ return f;
1155
+ }), l = (f, h) => {
1156
+ s || o((w) => ({ ...w, [f]: h }));
1157
+ }, c = !s && r.every((f) => !f.required || i[f.name]), p = () => {
1158
+ c && a({ action: "submit", value: i });
932
1159
  };
933
1160
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
934
1161
  /* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
935
- /* @__PURE__ */ e(C, { name: "file-text", size: 16, color: "#6366f1" }),
936
- /* @__PURE__ */ e("span", { children: a.content })
1162
+ /* @__PURE__ */ e(I, { name: "file-text", size: 16, color: "#6366f1" }),
1163
+ /* @__PURE__ */ e("span", { children: t.content })
937
1164
  ] }),
938
- /* @__PURE__ */ e("div", { className: "sa-interrupt-form", children: r.map((c) => /* @__PURE__ */ d("div", { className: "sa-interrupt-form-field", children: [
1165
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-form", children: r.map((f) => /* @__PURE__ */ d("div", { className: "sa-interrupt-form-field", children: [
939
1166
  /* @__PURE__ */ d("label", { className: "sa-interrupt-form-label", children: [
940
- c.label,
941
- c.required && /* @__PURE__ */ e("span", { className: "sa-interrupt-form-required", children: "*" })
1167
+ f.label,
1168
+ f.required && /* @__PURE__ */ e("span", { className: "sa-interrupt-form-required", children: "*" })
942
1169
  ] }),
943
- Ae(c, s[c.name], (p) => o(c.name, p))
944
- ] }, c.name)) }),
945
- /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
946
- /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", disabled: !i, onClick: l, children: [
947
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
1170
+ Ye(f, i[f.name], (h) => l(f.name, h), s)
1171
+ ] }, f.name)) }),
1172
+ !s && /* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
1173
+ /* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", disabled: !c, onClick: p, children: [
1174
+ /* @__PURE__ */ e(I, { name: "check", size: 14 }),
948
1175
  " 提交"
949
1176
  ] }),
950
- /* @__PURE__ */ e("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "cancel" }), children: "取消" })
951
- ] })
1177
+ /* @__PURE__ */ e("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => a({ action: "cancel" }), children: "取消" })
1178
+ ] }),
1179
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
952
1180
  ] });
953
1181
  }
954
- function Ae(a, t, r) {
955
- switch (a.type) {
1182
+ function se(t) {
1183
+ return typeof t == "string" ? { value: t, label: t } : t;
1184
+ }
1185
+ function Ye(t, a, s, n) {
1186
+ switch (t.type) {
956
1187
  case "textarea":
957
- return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: t, onChange: (s) => r(s.target.value), placeholder: a.placeholder, rows: 3 });
958
- case "select":
959
- return /* @__PURE__ */ d("select", { className: "sa-interrupt-select", value: t, onChange: (s) => r(s.target.value), children: [
1188
+ return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: a, onChange: (r) => s(r.target.value), placeholder: t.placeholder, rows: 3, disabled: n });
1189
+ case "select": {
1190
+ const r = (t.options ?? []).map(se);
1191
+ return /* @__PURE__ */ d("select", { className: "sa-interrupt-select", value: a, onChange: (i) => s(i.target.value), disabled: n, children: [
960
1192
  /* @__PURE__ */ e("option", { value: "", children: "请选择" }),
961
- (a.options ?? []).map((s) => /* @__PURE__ */ e("option", { value: s, children: s }, s))
1193
+ r.map((i) => /* @__PURE__ */ e("option", { value: i.value, children: i.label }, i.value))
962
1194
  ] });
1195
+ }
1196
+ case "multiSelect": {
1197
+ const r = (t.options ?? []).map(se), i = Array.isArray(a) ? a : [], o = (l) => {
1198
+ n || s(i.includes(l) ? i.filter((c) => c !== l) : [...i, l]);
1199
+ };
1200
+ return /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((l) => /* @__PURE__ */ e(
1201
+ "button",
1202
+ {
1203
+ type: "button",
1204
+ className: `sa-interrupt-option ${i.includes(l.value) ? "sa-interrupt-option-selected" : ""}`,
1205
+ disabled: n,
1206
+ onClick: () => o(l.value),
1207
+ children: l.label
1208
+ },
1209
+ l.value
1210
+ )) });
1211
+ }
1212
+ case "password":
1213
+ return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: "password", value: a, onChange: (r) => s(r.target.value), placeholder: t.placeholder, disabled: n });
963
1214
  default:
964
- return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: a.type, value: t, onChange: (s) => r(s.target.value), placeholder: a.placeholder });
1215
+ return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: t.type === "number" ? "number" : t.type === "date" ? "date" : "text", value: a, onChange: (r) => s(r.target.value), placeholder: t.placeholder, disabled: n });
965
1216
  }
966
1217
  }
967
- function $e({ interrupt: a, resolved: t, response: r, onRespond: s }) {
968
- if (t)
969
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-resolved", children: [
970
- /* @__PURE__ */ e(C, { name: "circle-check", size: 14, color: "#10b981" }),
971
- /* @__PURE__ */ e("span", { children: Pe(a.interruptType, r) })
972
- ] });
973
- switch (a.interruptType) {
1218
+ function Ue({ interrupt: t, resolved: a, response: s, onRespond: n }) {
1219
+ const r = a, i = s == null ? void 0 : s.value;
1220
+ switch (t.interruptType) {
974
1221
  case "confirm":
975
- return /* @__PURE__ */ e(ze, { interrupt: a, onRespond: s });
1222
+ return /* @__PURE__ */ e(Pe, { interrupt: t, onRespond: n, disabled: r, answeredAction: s == null ? void 0 : s.action });
976
1223
  case "approve":
977
- return /* @__PURE__ */ e(Ie, { interrupt: a, onRespond: s });
1224
+ return /* @__PURE__ */ e(He, { interrupt: t, onRespond: n, disabled: r, answeredAction: s == null ? void 0 : s.action });
978
1225
  case "select":
979
- return /* @__PURE__ */ e(Se, { interrupt: a, onRespond: s });
1226
+ return /* @__PURE__ */ e(Be, { interrupt: t, onRespond: n, disabled: r, initialValue: i });
980
1227
  case "multiSelect":
981
- return /* @__PURE__ */ e(Le, { interrupt: a, onRespond: s });
1228
+ return /* @__PURE__ */ e(Fe, { interrupt: t, onRespond: n, disabled: r, initialValue: i });
982
1229
  case "input":
983
- return /* @__PURE__ */ e(De, { interrupt: a, onRespond: s });
1230
+ return /* @__PURE__ */ e(We, { interrupt: t, onRespond: n, disabled: r, initialValue: i });
984
1231
  case "form":
985
- return /* @__PURE__ */ e(Ee, { interrupt: a, onRespond: s });
1232
+ return /* @__PURE__ */ e(Ke, { interrupt: t, onRespond: n, disabled: r, initialValue: i });
986
1233
  default:
987
1234
  return /* @__PURE__ */ d("div", { className: "sa-interrupt-unknown", children: [
988
1235
  "未知的交互类型: ",
989
- a.interruptType
1236
+ t.interruptType
990
1237
  ] });
991
1238
  }
992
1239
  }
993
- function Pe(a, t) {
994
- if (!t) return "已完成";
995
- switch (t.action) {
996
- case "confirm":
997
- return "已确认";
998
- case "cancel":
999
- return "已取消";
1000
- case "select":
1001
- return `已选择: ${t.value}`;
1002
- case "submit":
1003
- return "已提交";
1004
- case "approve":
1005
- return "已批准";
1006
- case "reject":
1007
- return "已拒绝";
1008
- case "skip":
1009
- return "已跳过";
1010
- default:
1011
- return "已完成";
1012
- }
1013
- }
1014
- const Oe = [
1240
+ const qe = [
1015
1241
  { value: 1, label: "事实错误" },
1016
1242
  { value: 2, label: "逻辑问题" },
1017
1243
  { value: 3, label: "不相关" },
@@ -1019,78 +1245,78 @@ const Oe = [
1019
1245
  { value: 5, label: "冗长啰嗦" },
1020
1246
  { value: 6, label: "难以理解" }
1021
1247
  ];
1022
- function Re({ message: a, onCopy: t, onRegenerate: r }) {
1023
- const { status: s, feedback: n, cancelFeedback: o } = W(), [i, l] = T(null), [c, p] = T(!1), [f, u] = T(!1), h = F(null);
1024
- if (s !== "ready" && s !== "error") return null;
1025
- const w = I(() => {
1026
- t(), p(!0), setTimeout(() => p(!1), 2e3);
1027
- }, [t]), k = I(() => {
1028
- i === "like" ? (l(null), o(a.id)) : (l("like"), u(!1), n(a.id, "like"));
1029
- }, [i, a.id, n, o]), b = I(() => {
1030
- i === "dislike" ? (l(null), u(!1), o(a.id)) : u(!0);
1031
- }, [i, a.id, o]), v = I((g, N) => {
1032
- l("dislike"), u(!1), n(a.id, "dislike", { reason: g, remark: (N == null ? void 0 : N.trim()) || void 0 });
1033
- }, [a.id, n]), m = I(() => {
1034
- u(!1);
1248
+ function Ve({ message: t, onCopy: a, onRegenerate: s, onFeedback: n }) {
1249
+ const { status: r, cancelFeedback: i } = Y(), [o, l] = M(null), [c, p] = M(!1), [f, h] = M(!1), w = _(null), u = C(() => {
1250
+ a(), p(!0), setTimeout(() => p(!1), 2e3);
1251
+ }, [a]), m = C(() => {
1252
+ o === "like" ? (l(null), i(t.id)) : (l("like"), h(!1), n == null || n(t.id, "like"));
1253
+ }, [o, t.id, n, i]), v = C(() => {
1254
+ o === "dislike" ? (l(null), h(!1), i(t.id)) : h(!0);
1255
+ }, [o, t.id, i]), S = C((A, x) => {
1256
+ l("dislike"), h(!1), n == null || n(t.id, "dislike", { reason: A, remark: (x == null ? void 0 : x.trim()) || void 0 });
1257
+ }, [t.id, n]), T = C(() => {
1258
+ h(!1);
1035
1259
  }, []);
1036
- return R(() => {
1260
+ return B(() => {
1037
1261
  if (!f) return;
1038
- const g = (S) => {
1039
- h.current && !h.current.contains(S.target) && u(!1);
1040
- }, N = (S) => {
1041
- S.key === "Escape" && u(!1);
1262
+ const A = (z) => {
1263
+ w.current && !w.current.contains(z.target) && h(!1);
1264
+ }, x = (z) => {
1265
+ z.key === "Escape" && h(!1);
1042
1266
  };
1043
- return document.addEventListener("mousedown", g), document.addEventListener("keydown", N), () => {
1044
- document.removeEventListener("mousedown", g), document.removeEventListener("keydown", N);
1267
+ return document.addEventListener("mousedown", A), document.addEventListener("keydown", x), () => {
1268
+ document.removeEventListener("mousedown", A), document.removeEventListener("keydown", x);
1045
1269
  };
1046
- }, [f]), /* @__PURE__ */ d("div", { className: "sa-action-bar", children: [
1047
- /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: w, title: "复制", children: [
1048
- /* @__PURE__ */ e(C, { name: c ? "circle-check" : "copy", size: 14 }),
1270
+ }, [f]), r !== "ready" && r !== "error" ? null : /* @__PURE__ */ d("div", { className: "sa-action-bar", children: [
1271
+ /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: u, title: "复制", children: [
1272
+ /* @__PURE__ */ e(I, { name: c ? "circle-check" : "copy", size: 14 }),
1049
1273
  " ",
1050
1274
  c ? "已复制" : "复制"
1051
1275
  ] }),
1052
- /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: r, title: "重新生成", children: [
1053
- /* @__PURE__ */ e(C, { name: "refresh-cw", size: 14 }),
1276
+ s && /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: s, title: "重新生成", children: [
1277
+ /* @__PURE__ */ e(I, { name: "refresh-cw", size: 14 }),
1054
1278
  " 重新生成"
1055
1279
  ] }),
1056
- /* @__PURE__ */ e("span", { className: "sa-action-divider" }),
1057
- /* @__PURE__ */ e(
1058
- "button",
1059
- {
1060
- className: `sa-action-btn ${i === "like" ? "sa-action-btn-active" : ""}`,
1061
- onClick: k,
1062
- title: "有用",
1063
- "aria-label": "点赞",
1064
- children: /* @__PURE__ */ e(C, { name: "thumbs-up", size: 14 })
1065
- }
1066
- ),
1067
- /* @__PURE__ */ e(
1068
- "button",
1069
- {
1070
- className: `sa-action-btn ${i === "dislike" ? "sa-action-btn-active" : ""}`,
1071
- onClick: b,
1072
- title: "无用",
1073
- "aria-label": "",
1074
- "aria-expanded": f,
1075
- "aria-haspopup": "dialog",
1076
- children: /* @__PURE__ */ e(C, { name: "thumbs-down", size: 14 })
1077
- }
1078
- ),
1079
- f && /* @__PURE__ */ e("div", { ref: h, children: /* @__PURE__ */ e(Be, { onSubmit: v, onCancel: m }) })
1280
+ n && /* @__PURE__ */ d(q, { children: [
1281
+ /* @__PURE__ */ e("span", { className: "sa-action-divider" }),
1282
+ /* @__PURE__ */ e(
1283
+ "button",
1284
+ {
1285
+ className: `sa-action-btn ${o === "like" ? "sa-action-btn-active" : ""}`,
1286
+ onClick: m,
1287
+ title: "有用",
1288
+ "aria-label": "点赞",
1289
+ children: /* @__PURE__ */ e(I, { name: "thumbs-up", size: 14 })
1290
+ }
1291
+ ),
1292
+ /* @__PURE__ */ e(
1293
+ "button",
1294
+ {
1295
+ className: `sa-action-btn ${o === "dislike" ? "sa-action-btn-active" : ""}`,
1296
+ onClick: v,
1297
+ title: "无用",
1298
+ "aria-label": "踩",
1299
+ "aria-expanded": f,
1300
+ "aria-haspopup": "dialog",
1301
+ children: /* @__PURE__ */ e(I, { name: "thumbs-down", size: 14 })
1302
+ }
1303
+ )
1304
+ ] }),
1305
+ f && /* @__PURE__ */ e("div", { ref: w, children: /* @__PURE__ */ e(Xe, { onSubmit: S, onCancel: T }) })
1080
1306
  ] });
1081
1307
  }
1082
- function Be({ onSubmit: a, onCancel: t }) {
1083
- const [r, s] = T(void 0), [n, o] = T("");
1308
+ function Xe({ onSubmit: t, onCancel: a }) {
1309
+ const [s, n] = M(void 0), [r, i] = M("");
1084
1310
  return /* @__PURE__ */ d("div", { className: "sa-dislike-panel", children: [
1085
1311
  /* @__PURE__ */ e("div", { className: "sa-dislike-panel-title", children: "请选择不满意的原因(可选)" }),
1086
- /* @__PURE__ */ e("div", { className: "sa-dislike-reasons", children: Oe.map((i) => /* @__PURE__ */ e(
1312
+ /* @__PURE__ */ e("div", { className: "sa-dislike-reasons", children: qe.map((o) => /* @__PURE__ */ e(
1087
1313
  "button",
1088
1314
  {
1089
- className: `sa-dislike-reason-btn ${r === i.value ? "active" : ""}`,
1090
- onClick: () => s(r === i.value ? void 0 : i.value),
1091
- children: i.label
1315
+ className: `sa-dislike-reason-btn ${s === o.value ? "active" : ""}`,
1316
+ onClick: () => n(s === o.value ? void 0 : o.value),
1317
+ children: o.label
1092
1318
  },
1093
- i.value
1319
+ o.value
1094
1320
  )) }),
1095
1321
  /* @__PURE__ */ e(
1096
1322
  "textarea",
@@ -1098,235 +1324,381 @@ function Be({ onSubmit: a, onCancel: t }) {
1098
1324
  className: "sa-dislike-remark",
1099
1325
  placeholder: "补充描述(选填,≤500 字)",
1100
1326
  maxLength: 500,
1101
- value: n,
1102
- onChange: (i) => o(i.target.value),
1327
+ value: r,
1328
+ onChange: (o) => i(o.target.value),
1103
1329
  rows: 2
1104
1330
  }
1105
1331
  ),
1106
1332
  /* @__PURE__ */ d("div", { className: "sa-dislike-actions", children: [
1107
- /* @__PURE__ */ e("button", { className: "sa-dislike-submit", onClick: () => a(r, n || void 0), children: "提交" }),
1108
- /* @__PURE__ */ e("button", { className: "sa-dislike-cancel", onClick: t, children: "取消" })
1333
+ /* @__PURE__ */ e("button", { className: "sa-dislike-submit", onClick: () => t(s, r || void 0), children: "提交" }),
1334
+ /* @__PURE__ */ e("button", { className: "sa-dislike-cancel", onClick: a, children: "取消" })
1109
1335
  ] })
1110
1336
  ] });
1111
1337
  }
1112
- function Z({ src: a, role: t }) {
1113
- const r = t === "assistant" ? "A" : "U";
1114
- 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: r });
1338
+ function ne({ src: t, role: a }) {
1339
+ const s = a === "assistant" ? "A" : "U";
1340
+ return t ? t.startsWith("http") || t.startsWith("/") || t.startsWith("data:") ? /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${a}`, children: /* @__PURE__ */ e(
1341
+ "img",
1342
+ {
1343
+ src: t,
1344
+ alt: a,
1345
+ style: {
1346
+ width: "100%",
1347
+ height: "100%",
1348
+ borderRadius: "inherit",
1349
+ objectFit: "cover"
1350
+ }
1351
+ }
1352
+ ) }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${a}`, children: t }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${a}`, children: s });
1115
1353
  }
1116
- function Fe({ message: a, isStreaming: t, isLast: r, slots: s, avatar: n, artifactPreview: o }) {
1117
- const { regenerate: i, feedback: l, respondToInterrupt: c } = W(), p = I(() => {
1118
- var N;
1119
- const g = a.parts.filter((S) => S.type === "text").map((S) => S.content).join(`
1354
+ function Ge({
1355
+ message: t,
1356
+ isStreaming: a,
1357
+ isLast: s,
1358
+ slots: n,
1359
+ avatar: r,
1360
+ artifactPreview: i
1361
+ }) {
1362
+ const { regenerate: o, feedback: l, respondToInterrupt: c } = Y(), p = C(() => {
1363
+ var z;
1364
+ const x = t.parts.filter(($) => $.type === "text").map(($) => $.content).join(`
1120
1365
  `);
1121
- (N = navigator.clipboard) == null || N.writeText(g).catch(() => {
1366
+ (z = navigator.clipboard) == null || z.writeText(x).catch(() => {
1122
1367
  });
1123
- }, [a]), f = a.role === "user", u = s.Message;
1124
- if (u)
1368
+ }, [t]), f = t.role === "user", h = n.Message;
1369
+ if (h)
1125
1370
  return /* @__PURE__ */ e(
1126
- u,
1371
+ h,
1127
1372
  {
1128
- message: a,
1129
- isStreaming: t,
1130
- isLast: r,
1131
- avatar: n,
1132
- slots: s,
1373
+ message: t,
1374
+ isStreaming: a,
1375
+ isLast: s,
1376
+ avatar: r,
1377
+ slots: n,
1133
1378
  onCopy: p,
1134
- onRegenerate: i,
1379
+ onRegenerate: o,
1135
1380
  onFeedback: l
1136
1381
  }
1137
1382
  );
1138
- const h = s.TextPart ?? ve, w = s.ThinkingPart ?? we, k = s.ToolCallPart ?? ye, b = s.ToolResultPart ?? Ce, v = s.ErrorPart ?? Ne, m = s.ActionBar ?? Re;
1139
- return /* @__PURE__ */ d("div", { className: `sa-message ${f ? "sa-message-user" : "sa-message-assistant"}`, children: [
1140
- !f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.assistant, role: "assistant" }),
1141
- /* @__PURE__ */ d("div", { className: "sa-message-body", children: [
1142
- a.parts.map((g, N) => {
1143
- switch (g.type) {
1144
- case "text":
1145
- return /* @__PURE__ */ e(h, { content: g.content }, N);
1146
- case "thinking":
1147
- return /* @__PURE__ */ e(w, { content: g.content }, N);
1148
- case "tool_call":
1149
- return /* @__PURE__ */ e(k, { toolName: g.toolName, toolCallId: g.toolCallId, args: g.args }, N);
1150
- case "tool_result":
1151
- return /* @__PURE__ */ e(b, { toolName: g.toolName, toolCallId: g.toolCallId, content: g.content, artifacts: g.artifacts, renderMode: g.renderMode, html: g.html, artifactPreview: o }, N);
1152
- case "error":
1153
- return /* @__PURE__ */ e(v, { content: g.content, onRetry: i }, N);
1154
- case "interrupt":
1155
- return /* @__PURE__ */ e(
1156
- $e,
1383
+ const w = n.TextPart ?? De, u = n.ThinkingPart ?? Le, m = n.ToolCallPart ?? Ee, v = n.ToolResultPart ?? Re, S = n.ErrorPart ?? Oe, T = n.ActionBar ?? Ve, A = !f && t.parts.some((x) => x.type === "text" && x.content);
1384
+ return /* @__PURE__ */ d(
1385
+ "div",
1386
+ {
1387
+ className: `sa-message ${f ? "sa-message-user" : "sa-message-assistant"}`,
1388
+ children: [
1389
+ !f && /* @__PURE__ */ e(ne, { src: r == null ? void 0 : r.assistant, role: "assistant" }),
1390
+ /* @__PURE__ */ d("div", { className: "sa-message-content", children: [
1391
+ /* @__PURE__ */ e(
1392
+ "span",
1393
+ {
1394
+ className: `sa-message-time ${f ? "sa-message-time-right" : ""}`,
1395
+ children: pe(t.timestamp)
1396
+ }
1397
+ ),
1398
+ /* @__PURE__ */ d("div", { className: "sa-message-body", children: [
1399
+ t.parts.map((x, z) => {
1400
+ switch (x.type) {
1401
+ case "text":
1402
+ return /* @__PURE__ */ e(w, { content: x.content }, z);
1403
+ case "thinking":
1404
+ return /* @__PURE__ */ e(u, { content: x.content }, z);
1405
+ case "tool_call":
1406
+ return /* @__PURE__ */ e(
1407
+ m,
1408
+ {
1409
+ toolName: x.toolName,
1410
+ toolCallId: x.toolCallId,
1411
+ args: x.args
1412
+ },
1413
+ z
1414
+ );
1415
+ case "tool_result":
1416
+ return /* @__PURE__ */ e(
1417
+ v,
1418
+ {
1419
+ toolName: x.toolName,
1420
+ toolCallId: x.toolCallId,
1421
+ content: x.content,
1422
+ artifacts: x.artifacts,
1423
+ renderMode: x.renderMode,
1424
+ html: x.html,
1425
+ artifactPreview: i
1426
+ },
1427
+ z
1428
+ );
1429
+ case "error":
1430
+ return /* @__PURE__ */ e(
1431
+ S,
1432
+ {
1433
+ content: x.content,
1434
+ onRetry: o
1435
+ },
1436
+ z
1437
+ );
1438
+ case "interrupt":
1439
+ return /* @__PURE__ */ e(
1440
+ Ue,
1441
+ {
1442
+ interrupt: x.interrupt,
1443
+ resolved: x.resolved ?? !1,
1444
+ response: x.response,
1445
+ onRespond: ($) => c(x.interrupt.interruptId, $)
1446
+ },
1447
+ z
1448
+ );
1449
+ default:
1450
+ return null;
1451
+ }
1452
+ }),
1453
+ a && s && !f && /* @__PURE__ */ e("span", { className: "sa-streaming-cursor", children: "|" }),
1454
+ !f && !a && A && /* @__PURE__ */ e(
1455
+ T,
1157
1456
  {
1158
- interrupt: g.interrupt,
1159
- resolved: g.resolved ?? !1,
1160
- response: g.response,
1161
- onRespond: (S) => c(g.interrupt.interruptId, S)
1162
- },
1163
- N
1164
- );
1165
- default:
1166
- return null;
1167
- }
1168
- }),
1169
- t && r && !f && /* @__PURE__ */ e("span", { className: "sa-streaming-cursor", children: "|" }),
1170
- !f && !t && a.parts.length > 0 && /* @__PURE__ */ e(m, { message: a, onCopy: p, onRegenerate: i, onFeedback: l })
1171
- ] }),
1172
- f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.user, role: "user" })
1173
- ] });
1457
+ message: t,
1458
+ onCopy: p,
1459
+ onRegenerate: s ? o : void 0,
1460
+ onFeedback: l
1461
+ }
1462
+ )
1463
+ ] })
1464
+ ] }),
1465
+ f && /* @__PURE__ */ e(ne, { src: r == null ? void 0 : r.user, role: "user" })
1466
+ ]
1467
+ }
1468
+ );
1174
1469
  }
1175
- function He({ message: a, suggestedPrompts: t, onPromptClick: r }) {
1470
+ function Je({ message: t, suggestedPrompts: a, onPromptClick: s }) {
1176
1471
  return /* @__PURE__ */ d("div", { className: "sa-welcome", children: [
1177
- /* @__PURE__ */ e("div", { className: "sa-welcome-icon", children: /* @__PURE__ */ e(C, { name: "sparkles", size: 40 }) }),
1178
- /* @__PURE__ */ e("p", { className: "sa-welcome-message", children: a || "你好!有什么可以帮你的?" }),
1179
- t && t.length > 0 && /* @__PURE__ */ e("div", { className: "sa-welcome-prompts", children: t.map((s, n) => /* @__PURE__ */ e(
1472
+ /* @__PURE__ */ e("div", { className: "sa-welcome-icon", children: /* @__PURE__ */ e(I, { name: "sparkles", size: 40 }) }),
1473
+ /* @__PURE__ */ e("p", { className: "sa-welcome-message", children: t || "你好!有什么可以帮你的?" }),
1474
+ a && a.length > 0 && /* @__PURE__ */ e("div", { className: "sa-welcome-prompts", children: a.map((n, r) => /* @__PURE__ */ e(
1180
1475
  "button",
1181
1476
  {
1182
1477
  className: "sa-welcome-prompt",
1183
- onClick: () => r(s),
1184
- children: s
1478
+ onClick: () => s(n),
1479
+ children: n
1185
1480
  },
1186
- n
1481
+ r
1187
1482
  )) })
1188
1483
  ] });
1189
1484
  }
1190
- function re({ slots: a, welcomeMessage: t, suggestedPrompts: r, avatar: s, artifactPreview: n }) {
1191
- const { messages: o, status: i, sendMessage: l } = W(), { containerRef: c } = ge([o]), p = i === "streaming", f = a.WelcomeScreen ?? He;
1192
- return o.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: /* @__PURE__ */ e(
1485
+ function fe({ slots: t, welcomeMessage: a, suggestedPrompts: s, avatar: n, artifactPreview: r }) {
1486
+ const { messages: i, status: o, sendMessage: l } = Y(), { containerRef: c } = Te([i]), p = o === "streaming", f = t.WelcomeScreen ?? Je;
1487
+ return i.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: /* @__PURE__ */ e(
1193
1488
  f,
1194
1489
  {
1195
- message: t,
1196
- suggestedPrompts: r,
1490
+ message: a,
1491
+ suggestedPrompts: s,
1197
1492
  onPromptClick: l
1198
1493
  }
1199
- ) }) : /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: o.map((u, h) => /* @__PURE__ */ e(
1200
- Fe,
1494
+ ) }) : /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: i.map((h, w) => /* @__PURE__ */ e(
1495
+ Ge,
1201
1496
  {
1202
- message: u,
1497
+ message: h,
1203
1498
  isStreaming: p,
1204
- isLast: h === o.length - 1,
1205
- slots: a,
1206
- avatar: s,
1207
- artifactPreview: n
1499
+ isLast: w === i.length - 1,
1500
+ slots: t,
1501
+ avatar: n,
1502
+ artifactPreview: r
1503
+ },
1504
+ h.id
1505
+ )) });
1506
+ }
1507
+ function Ze({ items: t, activeIndex: a, onSelect: s }) {
1508
+ const n = _(null);
1509
+ return B(() => {
1510
+ var i;
1511
+ const r = (i = n.current) == null ? void 0 : i.children[a];
1512
+ r == null || r.scrollIntoView({ block: "nearest" });
1513
+ }, [a]), t.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-slash-menu", children: /* @__PURE__ */ e("div", { className: "sa-slash-menu-empty", children: "没有匹配的技能" }) }) : /* @__PURE__ */ e("div", { className: "sa-slash-menu", ref: n, children: t.map((r, i) => /* @__PURE__ */ d(
1514
+ "div",
1515
+ {
1516
+ className: `sa-slash-menu-item${i === a ? " sa-slash-menu-item--active" : ""}`,
1517
+ onMouseDown: (o) => {
1518
+ o.preventDefault(), s(r);
1519
+ },
1520
+ children: [
1521
+ /* @__PURE__ */ d("span", { className: "sa-slash-menu-item-name", children: [
1522
+ "/",
1523
+ r.name
1524
+ ] }),
1525
+ (r.displayName || r.description) && /* @__PURE__ */ e("span", { className: "sa-slash-menu-item-desc", children: r.displayName || r.description })
1526
+ ]
1208
1527
  },
1209
- u.id
1528
+ r.code
1210
1529
  )) });
1211
1530
  }
1212
- function se() {
1213
- const { status: a, sendMessage: t, stop: r } = W(), [s, n] = T(""), o = F(null), i = a === "streaming" || a === "submitted", l = I(() => {
1214
- const f = s.trim();
1215
- !f || i || (t(f), n(""), o.current && (o.current.style.height = "auto"));
1216
- }, [s, i, t]), c = I((f) => {
1217
- f.key === "Enter" && !f.shiftKey && (f.preventDefault(), l());
1218
- }, [l]), p = I((f) => {
1219
- n(f.target.value);
1220
- const u = f.target;
1221
- u.style.height = "auto", u.style.height = Math.min(u.scrollHeight, 120) + "px";
1531
+ function Qe({ sdk: t, input: a, onSelect: s }) {
1532
+ const [n, r] = M([]), [i, o] = M(!1), [l, c] = M(0), p = _(!1);
1533
+ B(() => {
1534
+ p.current || (p.current = !0, t.listSkills().then(r).catch(() => r([])));
1535
+ }, [t]);
1536
+ const f = /^\/\S*$/.test(a);
1537
+ B(() => {
1538
+ o(f);
1539
+ }, [f]), B(() => {
1540
+ f && c(0);
1541
+ }, [a, f]);
1542
+ const h = a.startsWith("/") ? a.slice(1).toLowerCase() : "", w = J(
1543
+ () => n.filter(
1544
+ (x) => !h || x.code.toLowerCase().includes(h) || x.name.toLowerCase().includes(h) || x.displayName && x.displayName.toLowerCase().includes(h)
1545
+ ),
1546
+ [n, h]
1547
+ ), u = _(i), m = _(w), v = _(l), S = _(s);
1548
+ u.current = i, m.current = w, v.current = l, S.current = s;
1549
+ const T = C((x) => {
1550
+ if (!u.current || m.current.length === 0) return !1;
1551
+ switch (x.key) {
1552
+ case "ArrowDown":
1553
+ return x.preventDefault(), c((z) => (z + 1) % m.current.length), !0;
1554
+ case "ArrowUp":
1555
+ return x.preventDefault(), c((z) => (z - 1 + m.current.length) % m.current.length), !0;
1556
+ case "Enter":
1557
+ case "Tab":
1558
+ return x.preventDefault(), S.current(m.current[v.current]), o(!1), !0;
1559
+ case "Escape":
1560
+ return x.preventDefault(), o(!1), !0;
1561
+ default:
1562
+ return !1;
1563
+ }
1564
+ }, []), A = C(() => o(!1), []);
1565
+ return { isOpen: i, items: w, activeIndex: l, handleKeyDown: T, close: A };
1566
+ }
1567
+ function ue() {
1568
+ const { status: t, sendMessage: a, stop: s, sdk: n } = Y(), [r, i] = M(""), o = _(null), l = t === "streaming" || t === "submitted", c = C((u) => {
1569
+ i(`/${u.name} `), setTimeout(() => {
1570
+ const m = o.current;
1571
+ m && (m.focus(), m.selectionStart = m.selectionEnd = m.value.length);
1572
+ }, 0);
1573
+ }, []), p = Qe({
1574
+ sdk: n,
1575
+ input: r,
1576
+ onSelect: c
1577
+ }), f = C(() => {
1578
+ const u = r.trim();
1579
+ !u || l || (a(u), i(""), o.current && (o.current.style.height = "auto"));
1580
+ }, [r, l, a]), h = C((u) => {
1581
+ p.handleKeyDown(u) || u.key === "Enter" && !u.shiftKey && (u.preventDefault(), f());
1582
+ }, [f, p.handleKeyDown]), w = C((u) => {
1583
+ i(u.target.value);
1584
+ const m = u.target;
1585
+ m.style.height = "auto", m.style.height = Math.min(m.scrollHeight, 120) + "px";
1222
1586
  }, []);
1223
1587
  return /* @__PURE__ */ d("div", { className: "sa-composer", children: [
1588
+ p.isOpen && /* @__PURE__ */ e(
1589
+ Ze,
1590
+ {
1591
+ items: p.items,
1592
+ activeIndex: p.activeIndex,
1593
+ onSelect: c
1594
+ }
1595
+ ),
1224
1596
  /* @__PURE__ */ e(
1225
1597
  "textarea",
1226
1598
  {
1227
1599
  ref: o,
1228
1600
  className: "sa-composer-input",
1229
- value: s,
1230
- onChange: p,
1231
- onKeyDown: c,
1232
- placeholder: "输入消息...",
1601
+ value: r,
1602
+ onChange: w,
1603
+ onKeyDown: h,
1604
+ placeholder: l ? "回答生成中..." : "输入消息,按 / 选择技能...",
1233
1605
  rows: 1,
1234
- disabled: a === "submitted"
1606
+ disabled: l
1235
1607
  }
1236
1608
  ),
1237
- i ? /* @__PURE__ */ e("button", { className: "sa-composer-stop", onClick: r, title: "停止", children: /* @__PURE__ */ e(C, { name: "circle-stop", size: 16, color: "#fff" }) }) : /* @__PURE__ */ e(
1609
+ l ? /* @__PURE__ */ e("button", { className: "sa-composer-stop", onClick: s, title: "停止", children: /* @__PURE__ */ e(I, { name: "circle-stop", size: 16, color: "#fff" }) }) : /* @__PURE__ */ e(
1238
1610
  "button",
1239
1611
  {
1240
1612
  className: "sa-composer-send",
1241
- onClick: l,
1242
- disabled: !s.trim(),
1613
+ onClick: f,
1614
+ disabled: !r.trim(),
1243
1615
  title: "发送",
1244
- children: /* @__PURE__ */ e(C, { name: "arrow-up", size: 16, color: "#fff" })
1616
+ children: /* @__PURE__ */ e(I, { name: "arrow-up", size: 16, color: "#fff" })
1245
1617
  }
1246
1618
  )
1247
1619
  ] });
1248
1620
  }
1249
- function je({ artifact: a }) {
1250
- const [t, r] = Y.useState(null), [s, n] = Y.useState(!0), [o, i] = Y.useState(null);
1251
- return Y.useEffect(() => {
1621
+ function et({ artifact: t }) {
1622
+ const [a, s] = V.useState(null), [n, r] = V.useState(!0), [i, o] = V.useState(null);
1623
+ return V.useEffect(() => {
1252
1624
  let l = !1;
1253
- n(!0), i(null), r(null);
1625
+ r(!0), o(null), s(null);
1254
1626
  async function c() {
1255
1627
  try {
1256
- if (a.type === "pdf") {
1257
- l || n(!1);
1628
+ if (t.type === "pdf") {
1629
+ l || r(!1);
1258
1630
  return;
1259
1631
  }
1260
- if (a.type === "html") {
1261
- const p = await fetch(a.url);
1632
+ if (t.type === "html") {
1633
+ const p = await fetch(t.url);
1262
1634
  if (!p.ok) throw new Error(`HTTP ${p.status}`);
1263
- const f = await p.text(), u = (await import("./purify.es-C-6FFqDW.js")).default;
1264
- l || (r(u.sanitize(f, { FORCE_BODY: !0 })), n(!1));
1635
+ const f = await p.text(), h = (await import("./purify.es-C-6FFqDW.js")).default;
1636
+ l || (s(h.sanitize(f, { FORCE_BODY: !0, ADD_ATTR: ["target"] })), r(!1));
1265
1637
  return;
1266
1638
  }
1267
- if (a.type === "docx") {
1268
- const p = await fetch(a.url);
1639
+ if (t.type === "docx") {
1640
+ const p = await fetch(t.url);
1269
1641
  if (!p.ok) throw new Error(`HTTP ${p.status}`);
1270
- const f = await p.arrayBuffer(), h = await (await import("./mammoth.browser-COPV53yV.js").then((k) => k.m)).convertToHtml({ arrayBuffer: f }), w = (await import("./purify.es-C-6FFqDW.js")).default;
1271
- l || (r(w.sanitize(h.value, { FORCE_BODY: !0 })), n(!1));
1642
+ const f = await p.arrayBuffer(), w = await (await import("./mammoth.browser-COPV53yV.js").then((m) => m.m)).convertToHtml({ arrayBuffer: f }), u = (await import("./purify.es-C-6FFqDW.js")).default;
1643
+ l || (s(u.sanitize(w.value, { FORCE_BODY: !0, ADD_ATTR: ["target"] })), r(!1));
1272
1644
  return;
1273
1645
  }
1274
- l || (n(!1), i(`不支持预览「${a.type}」类型`));
1646
+ l || (r(!1), o(`不支持预览「${t.type}」类型`));
1275
1647
  } catch (p) {
1276
- l || (n(!1), i(p instanceof Error ? p.message : "加载失败"));
1648
+ l || (r(!1), o(p instanceof Error ? p.message : "加载失败"));
1277
1649
  }
1278
1650
  }
1279
1651
  return c(), () => {
1280
1652
  l = !0;
1281
1653
  };
1282
- }, [a]), s ? /* @__PURE__ */ e("div", { className: "sa-drawer-preview-loading", children: "加载中" }) : o ? /* @__PURE__ */ d("div", { className: "sa-drawer-preview-error", children: [
1283
- o,
1284
- /* @__PURE__ */ e("button", { className: "sa-drawer-btn-sm", onClick: () => void U(a), children: "下载查看" })
1285
- ] }) : 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;
1654
+ }, [t]), n ? /* @__PURE__ */ e("div", { className: "sa-drawer-preview-loading", children: "加载中" }) : i ? /* @__PURE__ */ d("div", { className: "sa-drawer-preview-error", children: [
1655
+ i,
1656
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn-sm", onClick: () => void Z(t), children: "下载查看" })
1657
+ ] }) : t.type === "pdf" ? /* @__PURE__ */ e("iframe", { src: t.url, title: t.filename, className: "sa-drawer-preview-iframe", sandbox: "allow-scripts" }) : a !== null ? /* @__PURE__ */ e("iframe", { srcDoc: a, title: t.filename, className: "sa-drawer-preview-iframe", sandbox: "allow-same-origin" }) : null;
1286
1658
  }
1287
- function ne({ artifacts: a, initialArtifact: t, onClose: r }) {
1288
- const [s, n] = T(
1289
- t ? { mode: "preview", artifact: t } : { mode: "list" }
1290
- ), [o, i] = T(!1), l = F(null), [c, p] = T(340), f = F(null);
1291
- R(() => {
1292
- t && (l.current && (clearTimeout(l.current), l.current = null, i(!1)), n({ mode: "preview", artifact: t }));
1293
- }, [t]);
1294
- const u = I(() => {
1295
- i(!0), l.current = setTimeout(() => {
1296
- l.current = null, r();
1659
+ function me({ artifacts: t, initialArtifact: a, onClose: s }) {
1660
+ const [n, r] = M(
1661
+ a ? { mode: "preview", artifact: a } : { mode: "list" }
1662
+ ), [i, o] = M(!1), l = _(null), [c, p] = M(340), f = _(null);
1663
+ B(() => {
1664
+ a && (l.current && (clearTimeout(l.current), l.current = null, o(!1)), r({ mode: "preview", artifact: a }));
1665
+ }, [a]);
1666
+ const h = C(() => {
1667
+ o(!0), l.current = setTimeout(() => {
1668
+ l.current = null, s();
1297
1669
  }, 240);
1298
- }, [r]);
1299
- R(() => () => {
1300
- var b;
1301
- l.current && clearTimeout(l.current), (b = f.current) == null || b.call(f);
1670
+ }, [s]);
1671
+ B(() => () => {
1672
+ var v;
1673
+ l.current && clearTimeout(l.current), (v = f.current) == null || v.call(f);
1302
1674
  }, []);
1303
- const h = I((b) => {
1304
- n({ mode: "preview", artifact: b });
1305
- }, []), w = I(() => {
1306
- n({ mode: "list" });
1675
+ const w = C((v) => {
1676
+ r({ mode: "preview", artifact: v });
1677
+ }, []), u = C(() => {
1678
+ r({ mode: "list" });
1307
1679
  }, []);
1308
- R(() => {
1309
- const b = (v) => {
1310
- v.key === "Escape" && u();
1680
+ B(() => {
1681
+ const v = (S) => {
1682
+ S.key === "Escape" && h();
1311
1683
  };
1312
- return document.addEventListener("keydown", b), () => document.removeEventListener("keydown", b);
1313
- }, [u]);
1314
- const k = I((b) => {
1315
- b.preventDefault();
1316
- const v = b.clientX, m = c, g = (S) => {
1317
- const L = v - S.clientX;
1318
- p(Math.max(240, Math.min(window.innerWidth * 0.7, m + L)));
1319
- }, N = () => {
1320
- document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", N), document.body.style.cursor = "", document.body.style.userSelect = "", f.current = null;
1684
+ return document.addEventListener("keydown", v), () => document.removeEventListener("keydown", v);
1685
+ }, [h]);
1686
+ const m = C((v) => {
1687
+ v.preventDefault();
1688
+ const S = v.clientX, T = c, A = (z) => {
1689
+ const $ = S - z.clientX;
1690
+ p(Math.max(240, Math.min(window.innerWidth * 0.7, T + $)));
1691
+ }, x = () => {
1692
+ document.removeEventListener("mousemove", A), document.removeEventListener("mouseup", x), document.body.style.cursor = "", document.body.style.userSelect = "", f.current = null;
1321
1693
  };
1322
- document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", g), document.addEventListener("mouseup", N), f.current = N;
1694
+ document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", A), document.addEventListener("mouseup", x), f.current = x;
1323
1695
  }, [c]);
1324
- return /* @__PURE__ */ d("div", { className: `sa-artifact-drawer ${o ? "sa-drawer-closing" : ""}`, style: { width: c }, children: [
1325
- /* @__PURE__ */ e("div", { className: "sa-drawer-resize-handle", onMouseDown: k }),
1696
+ return /* @__PURE__ */ d("div", { className: `sa-artifact-drawer ${i ? "sa-drawer-closing" : ""}`, style: { width: c }, children: [
1697
+ /* @__PURE__ */ e("div", { className: "sa-drawer-resize-handle", onMouseDown: m }),
1326
1698
  /* @__PURE__ */ d("div", { className: "sa-artifact-drawer-header", children: [
1327
- s.mode === "preview" ? /* @__PURE__ */ d(q, { children: [
1328
- /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: w, 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" }) }) }),
1329
- /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: s.artifact.filename })
1699
+ n.mode === "preview" ? /* @__PURE__ */ d(q, { children: [
1700
+ /* @__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: "M15 18l-6-6 6-6" }) }) }),
1701
+ /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: n.artifact.filename })
1330
1702
  ] }) : /* @__PURE__ */ d(q, { children: [
1331
1703
  /* @__PURE__ */ d("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { flexShrink: 0 }, children: [
1332
1704
  /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
@@ -1335,255 +1707,419 @@ function ne({ artifacts: a, initialArtifact: t, onClose: r }) {
1335
1707
  /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: "会话产物" })
1336
1708
  ] }),
1337
1709
  /* @__PURE__ */ e("div", { style: { flex: 1 } }),
1338
- s.mode === "preview" && /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: () => void U(s.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" }) }) }),
1339
- /* @__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" }) }) })
1710
+ n.mode === "preview" && /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: () => void Z(n.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" }) }) }),
1711
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: h, 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" }) }) })
1340
1712
  ] }),
1341
- /* @__PURE__ */ e("div", { className: "sa-artifact-drawer-body", children: s.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((b, v) => /* @__PURE__ */ d(
1713
+ /* @__PURE__ */ e("div", { className: "sa-artifact-drawer-body", children: n.mode === "list" ? t.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-drawer-empty", children: "暂无产物" }) : /* @__PURE__ */ e("ul", { className: "sa-drawer-file-list", role: "list", children: t.map((v, S) => /* @__PURE__ */ d(
1342
1714
  "li",
1343
1715
  {
1344
1716
  className: "sa-drawer-file-card",
1345
- onClick: () => h(b),
1346
- onKeyDown: (m) => {
1347
- (m.key === "Enter" || m.key === " ") && (m.preventDefault(), h(b));
1717
+ onClick: () => w(v),
1718
+ onKeyDown: (T) => {
1719
+ (T.key === "Enter" || T.key === " ") && (T.preventDefault(), w(v));
1348
1720
  },
1349
1721
  tabIndex: 0,
1350
1722
  role: "button",
1351
- "aria-label": `预览 ${b.filename}`,
1723
+ "aria-label": `预览 ${v.filename}`,
1352
1724
  children: [
1353
- /* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(b.type) }) }),
1725
+ /* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: le(v.type) }) }),
1354
1726
  /* @__PURE__ */ d("div", { className: "sa-drawer-file-info", children: [
1355
- /* @__PURE__ */ e("span", { className: "sa-drawer-file-name", children: b.filename }),
1356
- /* @__PURE__ */ e("span", { className: "sa-drawer-file-size", children: Q(b.size) })
1727
+ /* @__PURE__ */ e("span", { className: "sa-drawer-file-name", children: v.filename }),
1728
+ /* @__PURE__ */ e("span", { className: "sa-drawer-file-size", children: oe(v.size) })
1357
1729
  ] }),
1358
1730
  /* @__PURE__ */ e(
1359
1731
  "button",
1360
1732
  {
1361
1733
  className: "sa-drawer-btn",
1362
1734
  title: "下载",
1363
- "aria-label": `下载 ${b.filename}`,
1364
- onClick: (m) => {
1365
- m.stopPropagation(), U(b);
1735
+ "aria-label": `下载 ${v.filename}`,
1736
+ onClick: (T) => {
1737
+ T.stopPropagation(), Z(v);
1366
1738
  },
1367
1739
  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" }) })
1368
1740
  }
1369
1741
  )
1370
1742
  ]
1371
1743
  },
1372
- b.id || `artifact-${v}`
1373
- )) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(je, { artifact: s.artifact }) }) })
1744
+ v.id || `artifact-${S}`
1745
+ )) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(et, { artifact: n.artifact }) }) })
1374
1746
  ] });
1375
1747
  }
1376
- function _e({ isOpen: a, onClose: t, title: r, slots: s, welcomeMessage: n, suggestedPrompts: o, avatar: i, artifactPreview: l }) {
1377
- const { status: c, sendMessage: p, stop: f, toggleThreadList: u, toggleArtifactDrawer: h, conversations: w, activeConversationId: k, switchConversation: b, newConversation: v, deleteConversation: m, renameConversation: g, isThreadListOpen: N, isArtifactDrawerOpen: S, allArtifacts: L, activePreviewArtifact: O } = W();
1378
- if (!a) return null;
1379
- const y = s.Header, D = s.Composer, P = s.ThreadList;
1748
+ function tt({ isOpen: t, onClose: a, title: s, slots: n, welcomeMessage: r, suggestedPrompts: i, avatar: o, artifactPreview: l }) {
1749
+ const { status: c, sendMessage: p, stop: f, toggleThreadList: h, toggleArtifactDrawer: w, conversations: u, activeConversationId: m, switchConversation: v, newConversation: S, deleteConversation: T, renameConversation: A, isThreadListOpen: x, isArtifactDrawerOpen: z, allArtifacts: $, activePreviewArtifact: P, messagesLoading: N } = Y();
1750
+ if (!t) return null;
1751
+ const R = n.Header, y = n.Composer, g = n.ThreadList;
1380
1752
  return /* @__PURE__ */ d("div", { className: "sa-panel", children: [
1381
- y ? /* @__PURE__ */ e(y, { title: r, onClose: t, onToggleThreadList: u }) : /* @__PURE__ */ e(
1382
- ue,
1753
+ R ? /* @__PURE__ */ e(R, { title: s, onClose: a, onToggleThreadList: h }) : /* @__PURE__ */ e(
1754
+ ze,
1383
1755
  {
1384
- title: r,
1385
- onClose: t,
1386
- onToggleThreadList: u,
1387
- artifactCount: l ? L.length : 0,
1388
- onToggleArtifactDrawer: l ? h : void 0
1756
+ title: s,
1757
+ onClose: a,
1758
+ onToggleThreadList: h,
1759
+ artifactCount: l ? $.length : 0,
1760
+ onToggleArtifactDrawer: l ? w : void 0
1389
1761
  }
1390
1762
  ),
1391
- P && N ? /* @__PURE__ */ e(
1392
- P,
1763
+ g && x ? /* @__PURE__ */ e(
1764
+ g,
1393
1765
  {
1394
- conversations: w,
1395
- activeSessionId: k,
1396
- onSwitch: b,
1397
- onNew: v,
1398
- onDelete: m,
1399
- onRename: g
1766
+ conversations: u,
1767
+ activeSessionId: m,
1768
+ onSwitch: v,
1769
+ onNew: S,
1770
+ onDelete: T,
1771
+ onRename: A
1400
1772
  }
1401
- ) : /* @__PURE__ */ e(he, {}),
1773
+ ) : /* @__PURE__ */ e(Se, {}),
1402
1774
  /* @__PURE__ */ d("div", { className: "sa-panel-content", children: [
1403
- /* @__PURE__ */ e(re, { slots: s, welcomeMessage: n, suggestedPrompts: o, avatar: i, artifactPreview: l }),
1404
- l && S && /* @__PURE__ */ e(ne, { artifacts: L, initialArtifact: O, onClose: h })
1775
+ N ? /* @__PURE__ */ d("div", { className: "sa-messages-loading", children: [
1776
+ /* @__PURE__ */ e("span", { className: "sa-loading-spinner" }),
1777
+ "加载对话..."
1778
+ ] }) : /* @__PURE__ */ e(fe, { slots: n, welcomeMessage: r, suggestedPrompts: i, avatar: o, artifactPreview: l }),
1779
+ l && z && /* @__PURE__ */ e(me, { artifacts: $, initialArtifact: P, onClose: w })
1405
1780
  ] }),
1406
- D ? /* @__PURE__ */ e(D, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
1781
+ y ? /* @__PURE__ */ e(y, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(ue, {})
1407
1782
  ] });
1408
1783
  }
1409
- function We({
1410
- conversations: a,
1411
- activeSessionId: t,
1412
- onSwitch: r,
1413
- onNew: s,
1414
- onDelete: n,
1784
+ function at({
1785
+ conversations: t,
1786
+ activeSessionId: a,
1787
+ onSwitch: s,
1788
+ onNew: n,
1789
+ onDelete: r,
1790
+ onRename: i,
1415
1791
  isCollapsed: o,
1416
- onToggleCollapse: i
1792
+ onToggleCollapse: l,
1793
+ hasMore: c,
1794
+ onLoadMore: p,
1795
+ conversationsLoading: f
1417
1796
  }) {
1418
- const [l, c] = T(null), [p, f] = T(null), u = I((w, k) => {
1419
- k.stopPropagation(), p === w ? (n(w), f(null)) : (f(w), setTimeout(() => f(null), 3e3));
1420
- }, [p, n]), h = (() => {
1421
- const w = Date.now(), k = [], b = [], v = [];
1422
- for (const g of a) {
1423
- const N = w - new Date(g.updateTime).getTime();
1424
- N < 864e5 ? k.push(g) : N < 6048e5 ? b.push(g) : v.push(g);
1797
+ const [h, w] = M(null), [u, m] = M(null), [v, S] = M(null), [T, A] = M(""), x = C(
1798
+ (y, g) => {
1799
+ g.stopPropagation(), u === y ? (r(y), m(null)) : (m(y), setTimeout(() => m(null), 3e3));
1800
+ },
1801
+ [u, r]
1802
+ ), z = C(
1803
+ (y, g, E) => {
1804
+ E.stopPropagation(), S(y), A(g ?? "");
1805
+ },
1806
+ []
1807
+ ), $ = C(
1808
+ (y) => {
1809
+ T.trim() && i(y, T.trim()), S(null);
1810
+ },
1811
+ [T, i]
1812
+ ), P = _(null), N = C(() => {
1813
+ const y = P.current;
1814
+ !y || !c || !p || y.scrollHeight - y.scrollTop - y.clientHeight < 50 && p();
1815
+ }, [c, p]), R = (() => {
1816
+ const y = Date.now(), g = [], E = [], L = [];
1817
+ for (const O of t) {
1818
+ const b = y - new Date(O.updateTime).getTime();
1819
+ b < 864e5 ? g.push(O) : b < 6048e5 ? E.push(O) : L.push(O);
1425
1820
  }
1426
- const m = [];
1427
- return k.length && m.push({ label: "今天", items: k }), b.length && m.push({ label: "最近 7 天", items: b }), v.length && m.push({ label: "更早", items: v }), m;
1821
+ const k = [];
1822
+ return g.length && k.push({ label: "今天", items: g }), E.length && k.push({ label: "最近 7 天", items: E }), L.length && k.push({ label: "更早", items: L }), k;
1428
1823
  })();
1429
1824
  return o ? /* @__PURE__ */ d("div", { className: "sa-fp-sidebar sa-fp-sidebar-collapsed", children: [
1430
- /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: i, title: "展开", children: /* @__PURE__ */ e(C, { name: "panel-left", size: 18 }) }),
1431
- /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: s, title: "新会话", style: { marginTop: 4 }, children: /* @__PURE__ */ e(C, { name: "plus", size: 18 }) })
1825
+ /* @__PURE__ */ e(
1826
+ "button",
1827
+ {
1828
+ className: "sa-fp-sidebar-toggle",
1829
+ onClick: l,
1830
+ title: "展开",
1831
+ children: /* @__PURE__ */ e(I, { name: "panel-left", size: 18 })
1832
+ }
1833
+ ),
1834
+ /* @__PURE__ */ e(
1835
+ "button",
1836
+ {
1837
+ className: "sa-fp-sidebar-toggle",
1838
+ onClick: () => {
1839
+ n(), l();
1840
+ },
1841
+ title: "新会话",
1842
+ style: { marginTop: 4 },
1843
+ children: /* @__PURE__ */ e(I, { name: "plus", size: 18 })
1844
+ }
1845
+ )
1432
1846
  ] }) : /* @__PURE__ */ d("div", { className: "sa-fp-sidebar", children: [
1433
1847
  /* @__PURE__ */ d("div", { className: "sa-fp-sidebar-header", children: [
1434
- /* @__PURE__ */ d("button", { className: "sa-fp-sidebar-new", onClick: s, children: [
1435
- /* @__PURE__ */ e(C, { name: "plus", size: 15 }),
1848
+ /* @__PURE__ */ d("button", { className: "sa-fp-sidebar-new", onClick: n, children: [
1849
+ /* @__PURE__ */ e(I, { name: "plus", size: 15 }),
1436
1850
  " ",
1437
1851
  /* @__PURE__ */ e("span", { children: "新会话" })
1438
1852
  ] }),
1439
- /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: i, title: "收起侧边栏", children: /* @__PURE__ */ e(C, { name: "panel-left-close", size: 18 }) })
1853
+ /* @__PURE__ */ e(
1854
+ "button",
1855
+ {
1856
+ className: "sa-fp-sidebar-toggle",
1857
+ onClick: l,
1858
+ title: "收起侧边栏",
1859
+ children: /* @__PURE__ */ e(I, { name: "panel-left-close", size: 18 })
1860
+ }
1861
+ )
1440
1862
  ] }),
1441
- /* @__PURE__ */ d("div", { className: "sa-fp-sidebar-list", children: [
1442
- a.length === 0 && /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-empty", children: "开始你的第一个对话" }),
1443
- h.map((w) => /* @__PURE__ */ d("div", { children: [
1444
- /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-group", children: w.label }),
1445
- w.items.map((k) => {
1446
- const b = k.sessionId === t, v = l === k.sessionId, m = p === k.sessionId;
1863
+ /* @__PURE__ */ d("div", { className: "sa-fp-sidebar-list", ref: P, onScroll: N, children: [
1864
+ f && t.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-loading", children: "加载中..." }),
1865
+ !f && t.length === 0 && /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-empty", children: "开始你的第一个对话" }),
1866
+ R.map((y) => /* @__PURE__ */ d("div", { children: [
1867
+ /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-group", children: y.label }),
1868
+ y.items.map((g) => {
1869
+ const E = g.sessionId === a, L = h === g.sessionId, k = u === g.sessionId;
1447
1870
  return /* @__PURE__ */ d(
1448
1871
  "div",
1449
1872
  {
1450
- className: `sa-fp-sidebar-item ${b ? "active" : ""}`,
1451
- onClick: () => r(k.sessionId),
1452
- onMouseEnter: () => c(k.sessionId),
1453
- onMouseLeave: () => c(null),
1873
+ className: `sa-fp-sidebar-item ${E ? "active" : ""}`,
1874
+ onClick: () => {
1875
+ v !== g.sessionId && s(g.sessionId);
1876
+ },
1877
+ onMouseEnter: () => w(g.sessionId),
1878
+ onMouseLeave: () => w(null),
1454
1879
  children: [
1455
- /* @__PURE__ */ e("span", { className: "sa-fp-sidebar-item-title", children: k.title || "新会话" }),
1456
- v && /* @__PURE__ */ e(
1457
- "button",
1880
+ v === g.sessionId ? /* @__PURE__ */ e(
1881
+ "input",
1458
1882
  {
1459
- className: `sa-fp-sidebar-item-action ${m ? "danger" : ""}`,
1460
- onClick: (g) => u(k.sessionId, g),
1461
- title: m ? "确认删除" : "删除",
1462
- children: /* @__PURE__ */ e(C, { name: m ? "x" : "trash2", size: 14 })
1883
+ className: "sa-fp-sidebar-item-edit",
1884
+ value: T,
1885
+ onChange: (O) => A(O.target.value),
1886
+ onBlur: () => $(g.sessionId),
1887
+ onKeyDown: (O) => {
1888
+ O.key === "Enter" && $(g.sessionId), O.key === "Escape" && S(null);
1889
+ },
1890
+ onClick: (O) => O.stopPropagation(),
1891
+ autoFocus: !0
1892
+ }
1893
+ ) : /* @__PURE__ */ e("span", { className: "sa-fp-sidebar-item-title", children: g.title || "新会话" }),
1894
+ /* @__PURE__ */ d(
1895
+ "div",
1896
+ {
1897
+ className: `sa-fp-sidebar-item-actions ${L && v !== g.sessionId ? "visible" : ""}`,
1898
+ children: [
1899
+ /* @__PURE__ */ e(
1900
+ "button",
1901
+ {
1902
+ className: "sa-fp-sidebar-item-action",
1903
+ onClick: (O) => z(g.sessionId, g.title, O),
1904
+ title: "重命名",
1905
+ children: /* @__PURE__ */ e(I, { name: "pen", size: 14 })
1906
+ }
1907
+ ),
1908
+ /* @__PURE__ */ e(
1909
+ "button",
1910
+ {
1911
+ className: `sa-fp-sidebar-item-action ${k ? "danger" : ""}`,
1912
+ onClick: (O) => x(g.sessionId, O),
1913
+ title: k ? "确认删除" : "删除",
1914
+ children: /* @__PURE__ */ e(I, { name: k ? "x" : "trash2", size: 14 })
1915
+ }
1916
+ )
1917
+ ]
1463
1918
  }
1464
1919
  )
1465
1920
  ]
1466
1921
  },
1467
- k.sessionId
1922
+ g.sessionId
1468
1923
  );
1469
1924
  })
1470
- ] }, w.label))
1925
+ ] }, y.label)),
1926
+ c && /* @__PURE__ */ e("div", { className: "sa-thread-list-loading", children: "加载更多..." })
1471
1927
  ] })
1472
1928
  ] });
1473
1929
  }
1474
- function Ye({ title: a, slots: t, welcomeMessage: r, suggestedPrompts: s, sidebarDefaultOpen: n = !0, onClose: o, avatar: i, artifactPreview: l }) {
1930
+ function rt({
1931
+ title: t,
1932
+ slots: a,
1933
+ welcomeMessage: s,
1934
+ suggestedPrompts: n,
1935
+ sidebarDefaultOpen: r = !0,
1936
+ onClose: i,
1937
+ avatar: o,
1938
+ artifactPreview: l
1939
+ }) {
1475
1940
  const {
1476
1941
  status: c,
1477
1942
  sendMessage: p,
1478
1943
  stop: f,
1479
- conversations: u,
1480
- activeConversationId: h,
1481
- switchConversation: w,
1482
- newConversation: k,
1483
- deleteConversation: b,
1484
- renameConversation: v,
1485
- toggleArtifactDrawer: m,
1486
- isArtifactDrawerOpen: g,
1487
- allArtifacts: N,
1488
- activePreviewArtifact: S
1489
- } = W(), [L, O] = T(n), y = I(() => O((M) => !M), []), D = t.ThreadList, P = t.Composer;
1944
+ conversations: h,
1945
+ activeConversationId: w,
1946
+ switchConversation: u,
1947
+ newConversation: m,
1948
+ deleteConversation: v,
1949
+ renameConversation: S,
1950
+ toggleArtifactDrawer: T,
1951
+ isArtifactDrawerOpen: A,
1952
+ allArtifacts: x,
1953
+ activePreviewArtifact: z,
1954
+ hasMore: $,
1955
+ loadMoreConversations: P,
1956
+ conversationsLoading: N,
1957
+ messagesLoading: R
1958
+ } = Y(), [y, g] = M(r), E = C(() => g((O) => !O), []), L = a.ThreadList, k = a.Composer;
1490
1959
  return /* @__PURE__ */ d("div", { className: "sa-fullpage", children: [
1491
- D ? /* @__PURE__ */ e("div", { className: `sa-fp-sidebar-wrapper ${L ? "" : "sa-fp-sidebar-wrapper-collapsed"}`, children: /* @__PURE__ */ e(
1492
- D,
1960
+ L ? /* @__PURE__ */ e(
1961
+ "div",
1493
1962
  {
1494
- conversations: u,
1495
- activeSessionId: h,
1496
- onSwitch: w,
1497
- onNew: k,
1498
- onDelete: b,
1499
- onRename: v
1963
+ className: `sa-fp-sidebar-wrapper ${y ? "" : "sa-fp-sidebar-wrapper-collapsed"}`,
1964
+ children: /* @__PURE__ */ e(
1965
+ L,
1966
+ {
1967
+ conversations: h,
1968
+ activeSessionId: w,
1969
+ onSwitch: u,
1970
+ onNew: m,
1971
+ onDelete: v,
1972
+ onRename: S,
1973
+ hasMore: $,
1974
+ onLoadMore: P
1975
+ }
1976
+ )
1500
1977
  }
1501
- ) }) : /* @__PURE__ */ e(
1502
- We,
1978
+ ) : /* @__PURE__ */ e(
1979
+ at,
1503
1980
  {
1504
- conversations: u,
1505
- activeSessionId: h,
1506
- onSwitch: w,
1507
- onNew: k,
1508
- onDelete: b,
1509
- onRename: v,
1510
- isCollapsed: !L,
1511
- onToggleCollapse: y
1981
+ conversations: h,
1982
+ activeSessionId: w,
1983
+ onSwitch: u,
1984
+ onNew: m,
1985
+ onDelete: v,
1986
+ onRename: S,
1987
+ isCollapsed: !y,
1988
+ onToggleCollapse: E,
1989
+ hasMore: $,
1990
+ onLoadMore: P,
1991
+ conversationsLoading: N
1512
1992
  }
1513
1993
  ),
1514
1994
  /* @__PURE__ */ d("div", { className: "sa-fp-main", children: [
1515
1995
  /* @__PURE__ */ d("div", { className: "sa-fp-header", children: [
1516
- !L && !D && /* @__PURE__ */ e("button", { className: "sa-fp-header-btn", onClick: y, title: "展开侧边栏", children: /* @__PURE__ */ e(C, { name: "panel-left", size: 18 }) }),
1517
- /* @__PURE__ */ e("div", { className: "sa-fp-header-title", children: a }),
1996
+ !y && !L && /* @__PURE__ */ e(
1997
+ "button",
1998
+ {
1999
+ className: "sa-fp-header-btn",
2000
+ onClick: E,
2001
+ title: "展开侧边栏",
2002
+ children: /* @__PURE__ */ e(I, { name: "panel-left", size: 18 })
2003
+ }
2004
+ ),
2005
+ /* @__PURE__ */ e("div", { className: "sa-fp-header-title", children: t }),
1518
2006
  /* @__PURE__ */ d("div", { className: "sa-fp-header-actions", children: [
1519
- l && N.length > 0 && /* @__PURE__ */ d("button", { className: "sa-fp-header-btn sa-header-btn-artifact", onClick: m, title: "会话产物", children: [
1520
- /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1521
- /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
1522
- /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
1523
- ] }),
1524
- /* @__PURE__ */ e("span", { children: "产物" })
1525
- ] }),
1526
- o && /* @__PURE__ */ e("button", { className: "sa-fp-header-btn", onClick: o, title: "关闭", children: /* @__PURE__ */ e(C, { name: "x", size: 18 }) })
2007
+ l && x.length > 0 && /* @__PURE__ */ d(
2008
+ "button",
2009
+ {
2010
+ className: "sa-fp-header-btn sa-header-btn-artifact",
2011
+ onClick: T,
2012
+ title: "会话产物",
2013
+ children: [
2014
+ /* @__PURE__ */ d(
2015
+ "svg",
2016
+ {
2017
+ width: "14",
2018
+ height: "14",
2019
+ viewBox: "0 0 24 24",
2020
+ fill: "none",
2021
+ stroke: "currentColor",
2022
+ strokeWidth: "2",
2023
+ children: [
2024
+ /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
2025
+ /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
2026
+ ]
2027
+ }
2028
+ ),
2029
+ /* @__PURE__ */ e("span", { children: "产物" })
2030
+ ]
2031
+ }
2032
+ ),
2033
+ i && /* @__PURE__ */ e(
2034
+ "button",
2035
+ {
2036
+ className: "sa-fp-header-btn",
2037
+ onClick: i,
2038
+ title: "关闭",
2039
+ children: /* @__PURE__ */ e(I, { name: "x", size: 18 })
2040
+ }
2041
+ )
1527
2042
  ] })
1528
2043
  ] }),
1529
2044
  /* @__PURE__ */ d("div", { className: "sa-fp-content-row", children: [
1530
- /* @__PURE__ */ e(re, { slots: t, welcomeMessage: r, suggestedPrompts: s, avatar: i, artifactPreview: l }),
1531
- l && g && /* @__PURE__ */ e(ne, { artifacts: N, initialArtifact: S, onClose: m })
2045
+ R ? /* @__PURE__ */ d("div", { className: "sa-messages-loading", children: [
2046
+ /* @__PURE__ */ e("span", { className: "sa-loading-spinner" }),
2047
+ "加载对话..."
2048
+ ] }) : /* @__PURE__ */ e(
2049
+ fe,
2050
+ {
2051
+ slots: a,
2052
+ welcomeMessage: s,
2053
+ suggestedPrompts: n,
2054
+ avatar: o,
2055
+ artifactPreview: l
2056
+ }
2057
+ ),
2058
+ l && A && /* @__PURE__ */ e(
2059
+ me,
2060
+ {
2061
+ artifacts: x,
2062
+ initialArtifact: z,
2063
+ onClose: T
2064
+ }
2065
+ )
1532
2066
  ] }),
1533
- P ? /* @__PURE__ */ e(P, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
2067
+ k ? /* @__PURE__ */ e(k, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(ue, {})
1534
2068
  ] })
1535
2069
  ] });
1536
2070
  }
1537
- function Ke(a) {
1538
- const { sdk: t, mode: r = "floating", slots: s = {}, hooks: n = {}, welcomeMessage: o, suggestedPrompts: i, title: l = "AI Assistant", initialOpen: c = !1, onOpenChange: p, sidebarDefaultOpen: f, avatar: u, artifactPreview: h } = a, [w, k] = T(c);
1539
- R(() => {
1540
- k(c);
2071
+ function st(t) {
2072
+ const { sdk: a, mode: s = "floating", slots: n = {}, hooks: r = {}, welcomeMessage: i, suggestedPrompts: o, title: l = "AI Assistant", initialOpen: c = !1, onOpenChange: p, sidebarDefaultOpen: f, avatar: h, artifactPreview: w } = t, [u, m] = M(c);
2073
+ B(() => {
2074
+ m(c);
1541
2075
  }, [c]);
1542
- const b = I(() => {
1543
- var N, S;
1544
- const g = !w;
1545
- k(g), p == null || p(g), g ? (N = n.onOpen) == null || N.call(n) : (S = n.onClose) == null || S.call(n);
1546
- }, [w, n, p]), v = I(() => {
1547
- var g;
1548
- k(!1), p == null || p(!1), (g = n.onClose) == null || g.call(n);
1549
- }, [n, p]), m = s.Trigger ?? fe;
1550
- return r === "fullpage" ? w ? /* @__PURE__ */ e(G, { sdk: t, hooks: n, children: /* @__PURE__ */ e(
1551
- Ye,
2076
+ const v = C(() => {
2077
+ var x, z;
2078
+ const A = !u;
2079
+ m(A), p == null || p(A), A ? (x = r.onOpen) == null || x.call(r) : (z = r.onClose) == null || z.call(r);
2080
+ }, [u, r, p]), S = C(() => {
2081
+ var A;
2082
+ m(!1), p == null || p(!1), (A = r.onClose) == null || A.call(r);
2083
+ }, [r, p]), T = n.Trigger ?? Ce;
2084
+ return s === "fullpage" ? u ? /* @__PURE__ */ e(te, { sdk: a, hooks: r, children: /* @__PURE__ */ e(
2085
+ rt,
1552
2086
  {
1553
2087
  title: l,
1554
- slots: s,
1555
- welcomeMessage: o,
1556
- suggestedPrompts: i,
2088
+ slots: n,
2089
+ welcomeMessage: i,
2090
+ suggestedPrompts: o,
1557
2091
  sidebarDefaultOpen: f,
1558
- onClose: v,
1559
- avatar: u,
1560
- artifactPreview: h
2092
+ onClose: S,
2093
+ avatar: h,
2094
+ artifactPreview: w
1561
2095
  }
1562
- ) }) : null : /* @__PURE__ */ d(G, { sdk: t, hooks: n, children: [
1563
- /* @__PURE__ */ e(m, { isOpen: w, onClick: b }),
2096
+ ) }) : null : /* @__PURE__ */ d(te, { sdk: a, hooks: r, children: [
2097
+ /* @__PURE__ */ e(T, { isOpen: u, onClick: v }),
1564
2098
  /* @__PURE__ */ e(
1565
- _e,
2099
+ tt,
1566
2100
  {
1567
- isOpen: w,
1568
- onClose: v,
2101
+ isOpen: u,
2102
+ onClose: S,
1569
2103
  title: l,
1570
- slots: s,
1571
- welcomeMessage: o,
1572
- suggestedPrompts: i,
1573
- avatar: u,
1574
- artifactPreview: h
2104
+ slots: n,
2105
+ welcomeMessage: i,
2106
+ suggestedPrompts: o,
2107
+ avatar: h,
2108
+ artifactPreview: w
1575
2109
  }
1576
2110
  )
1577
2111
  ] });
1578
2112
  }
1579
- const Ue = `
2113
+ const nt = `
1580
2114
  [data-super-agent-widget] {
1581
2115
  --sa-primary-dark: color-mix(in srgb, var(--sa-primary) 82%, #000);
1582
2116
  --sa-primary-light: color-mix(in srgb, var(--sa-primary) 10%, #fff);
1583
2117
  --sa-text: #1f2937;
1584
2118
  --sa-text-muted: #6b7280;
2119
+ --sa-text-light: #9ca3af;
1585
2120
  --sa-border: #e5e7eb;
1586
2121
  --sa-surface: #f9fafb;
2122
+ --sa-hover: #f3f4f6;
1587
2123
 
1588
2124
  font-family: var(--sa-font);
1589
2125
  color: var(--sa-text);
@@ -1771,13 +2307,19 @@ const Ue = `
1771
2307
  justify-content: flex-end;
1772
2308
  }
1773
2309
 
1774
- .sa-message-body {
2310
+ .sa-message-content {
1775
2311
  max-width: 78%;
1776
2312
  display: flex;
1777
2313
  flex-direction: column;
1778
2314
  gap: 4px;
1779
2315
  }
1780
2316
 
2317
+ .sa-message-body {
2318
+ display: flex;
2319
+ flex-direction: column;
2320
+ gap: 4px;
2321
+ }
2322
+
1781
2323
  .sa-message-user .sa-message-body {
1782
2324
  padding: 10px 14px;
1783
2325
  border-radius: 16px;
@@ -1801,6 +2343,16 @@ const Ue = `
1801
2343
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
1802
2344
  }
1803
2345
 
2346
+ .sa-message-time {
2347
+ font-size: 11px;
2348
+ color: var(--sa-text-muted);
2349
+ opacity: 0.7;
2350
+ }
2351
+
2352
+ .sa-message-time-right {
2353
+ text-align: right;
2354
+ }
2355
+
1804
2356
  .sa-avatar {
1805
2357
  width: 28px;
1806
2358
  height: 28px;
@@ -2046,12 +2598,24 @@ const Ue = `
2046
2598
  }
2047
2599
 
2048
2600
  .sa-tool-result-content {
2601
+ max-height: 256px;
2602
+ overflow: auto;
2603
+ margin: 8px 0 0;
2049
2604
  padding: 10px 12px;
2050
2605
  color: #4b5563;
2051
2606
  font-size: 13px;
2052
2607
  line-height: 1.55;
2053
2608
  white-space: pre-wrap;
2054
2609
  word-break: break-word;
2610
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
2611
+ background: #f9fafb;
2612
+ border-radius: 8px;
2613
+ }
2614
+
2615
+ .sa-tool-result-actions {
2616
+ display: flex;
2617
+ gap: 8px;
2618
+ margin: 4px 0;
2055
2619
  }
2056
2620
 
2057
2621
  /* ── Error part ──────────────────────────────────────────── */
@@ -2098,12 +2662,21 @@ const Ue = `
2098
2662
 
2099
2663
  .sa-action-bar {
2100
2664
  display: flex;
2665
+ align-items: center;
2666
+ flex-wrap: wrap;
2101
2667
  gap: 6px;
2102
2668
  margin-top: 6px;
2103
2669
  position: relative;
2104
2670
  }
2105
2671
 
2106
2672
  .sa-action-btn {
2673
+ display: inline-flex;
2674
+ align-items: center;
2675
+ justify-content: center;
2676
+ gap: 4px;
2677
+ flex: none;
2678
+ white-space: nowrap;
2679
+ line-height: 1;
2107
2680
  padding: 4px 10px;
2108
2681
  border: none;
2109
2682
  border-radius: 6px;
@@ -2114,6 +2687,11 @@ const Ue = `
2114
2687
  transition: color 0.15s ease, background 0.15s ease;
2115
2688
  }
2116
2689
 
2690
+ .sa-action-btn svg {
2691
+ display: block;
2692
+ flex: none;
2693
+ }
2694
+
2117
2695
  .sa-action-btn:hover {
2118
2696
  color: var(--sa-text);
2119
2697
  background: rgba(0, 0, 0, 0.05);
@@ -2173,6 +2751,7 @@ const Ue = `
2173
2751
  /* ── Composer ────────────────────────────────────────────── */
2174
2752
 
2175
2753
  .sa-composer {
2754
+ position: relative;
2176
2755
  display: flex;
2177
2756
  align-items: flex-end;
2178
2757
  gap: 10px;
@@ -2248,6 +2827,62 @@ const Ue = `
2248
2827
  transform: scale(1.05);
2249
2828
  }
2250
2829
 
2830
+ /* ── Slash Menu ─────────────────────────────────────────── */
2831
+
2832
+ .sa-slash-menu {
2833
+ position: absolute;
2834
+ bottom: 100%;
2835
+ left: 14px;
2836
+ right: 14px;
2837
+ max-width: 400px;
2838
+ max-height: 200px;
2839
+ overflow-y: auto;
2840
+ background: var(--sa-surface);
2841
+ border: 1px solid var(--sa-border);
2842
+ border-radius: 8px;
2843
+ box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
2844
+ margin-bottom: 4px;
2845
+ z-index: 10;
2846
+ }
2847
+
2848
+ .sa-slash-menu-empty {
2849
+ padding: 12px 14px;
2850
+ color: #9ca3af;
2851
+ font-size: 13px;
2852
+ text-align: center;
2853
+ }
2854
+
2855
+ .sa-slash-menu-item {
2856
+ display: flex;
2857
+ align-items: center;
2858
+ gap: 8px;
2859
+ padding: 8px 14px;
2860
+ cursor: pointer;
2861
+ transition: background 0.15s ease;
2862
+ }
2863
+
2864
+ .sa-slash-menu-item:hover,
2865
+ .sa-slash-menu-item--active {
2866
+ background: var(--sa-hover);
2867
+ }
2868
+
2869
+ .sa-slash-menu-item-name {
2870
+ font-size: 13px;
2871
+ font-weight: 500;
2872
+ color: var(--sa-text);
2873
+ white-space: nowrap;
2874
+ }
2875
+
2876
+ .sa-slash-menu-item-desc {
2877
+ font-size: 12px;
2878
+ color: #9ca3af;
2879
+ overflow: hidden;
2880
+ text-overflow: ellipsis;
2881
+ white-space: nowrap;
2882
+ flex: 1;
2883
+ min-width: 0;
2884
+ }
2885
+
2251
2886
  /* ── Thread list ─────────────────────────────────────────── */
2252
2887
 
2253
2888
  .sa-thread-list-overlay {
@@ -2318,6 +2953,45 @@ const Ue = `
2318
2953
  font-size: 14px;
2319
2954
  }
2320
2955
 
2956
+ .sa-thread-list-loading {
2957
+ padding: 12px 16px;
2958
+ text-align: center;
2959
+ color: #9ca3af;
2960
+ font-size: 13px;
2961
+ }
2962
+
2963
+ .sa-thread-list-hint {
2964
+ padding: 8px 16px 12px;
2965
+ text-align: center;
2966
+ color: #d1d5db;
2967
+ font-size: 12px;
2968
+ }
2969
+
2970
+ /* 消息区加载态 */
2971
+ .sa-messages-loading {
2972
+ flex: 1;
2973
+ display: flex;
2974
+ align-items: center;
2975
+ justify-content: center;
2976
+ gap: 8px;
2977
+ color: #9ca3af;
2978
+ font-size: 14px;
2979
+ }
2980
+
2981
+ .sa-loading-spinner {
2982
+ width: 16px;
2983
+ height: 16px;
2984
+ border: 2px solid var(--sa-border, #e5e7eb);
2985
+ border-top-color: var(--sa-primary, #6366f1);
2986
+ border-radius: 50%;
2987
+ animation: sa-spin 0.8s linear infinite;
2988
+ flex-shrink: 0;
2989
+ }
2990
+
2991
+ @keyframes sa-spin {
2992
+ to { transform: rotate(360deg); }
2993
+ }
2994
+
2321
2995
  .sa-thread-group-label {
2322
2996
  padding: 16px 8px 6px;
2323
2997
  font-size: 12px;
@@ -2349,13 +3023,26 @@ const Ue = `
2349
3023
  font-weight: 500;
2350
3024
  }
2351
3025
 
2352
- .sa-thread-item-title {
3026
+ .sa-thread-item-info {
2353
3027
  flex: 1;
3028
+ overflow: hidden;
3029
+ display: flex;
3030
+ flex-direction: column;
3031
+ gap: 2px;
3032
+ }
3033
+
3034
+ .sa-thread-item-title {
2354
3035
  overflow: hidden;
2355
3036
  white-space: nowrap;
2356
3037
  text-overflow: ellipsis;
2357
3038
  }
2358
3039
 
3040
+ .sa-thread-item-time {
3041
+ font-size: 11px;
3042
+ color: var(--sa-text-light);
3043
+ white-space: nowrap;
3044
+ }
3045
+
2359
3046
  .sa-thread-item-edit {
2360
3047
  width: 100%;
2361
3048
  padding: 4px 8px;
@@ -2367,22 +3054,33 @@ const Ue = `
2367
3054
  color: var(--sa-text);
2368
3055
  }
2369
3056
 
2370
- .sa-thread-item-delete {
3057
+ /* 操作按钮组:始终占位(visibility 控制),hover 时显示,高度不变 */
3058
+ .sa-thread-item-actions {
3059
+ display: flex;
3060
+ gap: 2px;
3061
+ flex-shrink: 0;
3062
+ visibility: hidden;
3063
+ }
3064
+
3065
+ .sa-thread-item:hover .sa-thread-item-actions {
3066
+ visibility: visible;
3067
+ }
3068
+
3069
+ .sa-thread-item-action-btn {
2371
3070
  border: none;
2372
3071
  background: transparent;
2373
3072
  color: var(--sa-text-muted);
2374
- font-size: 14px;
2375
3073
  cursor: pointer;
2376
- opacity: 0;
2377
- transition: opacity 0.15s ease, color 0.15s ease;
2378
- }
2379
-
2380
- .sa-thread-item:hover .sa-thread-item-delete {
2381
- opacity: 1;
3074
+ padding: 2px;
3075
+ border-radius: 4px;
3076
+ display: inline-flex;
3077
+ align-items: center;
3078
+ transition: color 0.15s ease, background 0.15s ease;
2382
3079
  }
2383
3080
 
2384
- .sa-thread-item-delete:hover {
2385
- color: #ef4444;
3081
+ .sa-thread-item-action-btn:hover {
3082
+ color: var(--sa-primary);
3083
+ background: rgba(99,102,241,0.08);
2386
3084
  }
2387
3085
 
2388
3086
  /* ── Welcome ─────────────────────────────────────────────── */
@@ -2618,16 +3316,34 @@ const Ue = `
2618
3316
  margin-left: 2px;
2619
3317
  }
2620
3318
 
2621
- .sa-interrupt-resolved {
2622
- display: flex;
2623
- align-items: center;
2624
- gap: 6px;
2625
- padding: 8px 12px;
2626
- border-radius: 8px;
2627
- background: #ecfdf5;
2628
- color: #065f46;
2629
- font-size: 13px;
2630
- margin: 6px 0;
3319
+ .sa-interrupt-submitted {
3320
+ margin-top: 8px;
3321
+ font-size: 12px;
3322
+ color: #9ca3af;
3323
+ }
3324
+
3325
+ .sa-interrupt-btn-answered {
3326
+ background: var(--sa-primary) !important;
3327
+ color: #fff !important;
3328
+ opacity: 0.7;
3329
+ }
3330
+
3331
+ .sa-interrupt-btn:disabled {
3332
+ opacity: 0.5;
3333
+ cursor: not-allowed;
3334
+ }
3335
+
3336
+ .sa-interrupt-option:disabled {
3337
+ opacity: 0.6;
3338
+ cursor: not-allowed;
3339
+ }
3340
+
3341
+ .sa-interrupt-input:disabled,
3342
+ .sa-interrupt-textarea:disabled,
3343
+ .sa-interrupt-select:disabled {
3344
+ opacity: 0.6;
3345
+ cursor: not-allowed;
3346
+ background: #f9fafb;
2631
3347
  }
2632
3348
 
2633
3349
  .sa-interrupt-unknown {
@@ -2676,13 +3392,11 @@ const Ue = `
2676
3392
  /* ── Fullpage Layout (DeepSeek-style) ────────────────────────── */
2677
3393
 
2678
3394
  .sa-fullpage {
2679
- position: fixed;
2680
- inset: 0;
2681
- width: 100vw;
2682
- height: 100vh;
3395
+ position: relative;
3396
+ width: 100%;
3397
+ height: 100%;
2683
3398
  display: flex;
2684
- background: #f7f7f8;
2685
- z-index: var(--sa-z-index, 9999);
3399
+ background: var(--sa-bg, #ffffff);
2686
3400
  }
2687
3401
 
2688
3402
  /* Sidebar */
@@ -2690,7 +3404,7 @@ const Ue = `
2690
3404
  width: 260px;
2691
3405
  display: flex;
2692
3406
  flex-direction: column;
2693
- background: #f2f2f3;
3407
+ background: var(--sa-surface, #ffffff);
2694
3408
  flex-shrink: 0;
2695
3409
  transition: width 0.2s cubic-bezier(0.16,1,0.3,1);
2696
3410
  overflow: hidden;
@@ -2816,6 +3530,29 @@ const Ue = `
2816
3530
  text-overflow: ellipsis;
2817
3531
  }
2818
3532
 
3533
+ .sa-fp-sidebar-item-edit {
3534
+ flex: 1;
3535
+ min-width: 0;
3536
+ padding: 2px 6px;
3537
+ border: 1px solid var(--sa-primary, #6366f1);
3538
+ border-radius: 4px;
3539
+ font-size: 13px;
3540
+ color: #27272a;
3541
+ background: #fff;
3542
+ outline: none;
3543
+ }
3544
+
3545
+ .sa-fp-sidebar-item-actions {
3546
+ display: flex;
3547
+ gap: 2px;
3548
+ flex-shrink: 0;
3549
+ visibility: hidden;
3550
+ }
3551
+
3552
+ .sa-fp-sidebar-item-actions.visible {
3553
+ visibility: visible;
3554
+ }
3555
+
2819
3556
  .sa-fp-sidebar-item-action {
2820
3557
  width: 24px;
2821
3558
  height: 24px;
@@ -2975,8 +3712,9 @@ const Ue = `
2975
3712
  .sa-artifact-file-download:active { transform: scale(0.9); }
2976
3713
 
2977
3714
  /* ── Inline HTML rendering (render_mode=html) ── */
2978
- .sa-tool-result-html { margin-top: 8px; border: 1px solid var(--sa-border); border-radius: 8px; overflow: hidden; }
2979
- .sa-tool-result-html-iframe { width: 100%; min-height: 120px; max-height: 400px; border: none; background: #fff; }
3715
+ /* HTML 工具结果:外层滚动容器 + 内层内容层(与 Playground 一致,无 iframe) */
3716
+ .sa-tool-result-html-scroll { margin-top: 8px; max-height: 60vh; overflow: auto; border: 1px solid var(--sa-border); border-radius: 8px; }
3717
+ .sa-tool-result-html { padding: 12px; background: #fff; min-width: 100%; width: max-content; }
2980
3718
 
2981
3719
  /* ── Header artifact button ── */
2982
3720
  .sa-header-btn-artifact {
@@ -3105,7 +3843,7 @@ const Ue = `
3105
3843
  from { opacity: 0; transform: translateX(12px); }
3106
3844
  to { opacity: 1; transform: translateX(0); }
3107
3845
  }
3108
- `, Ve = {
3846
+ `, it = {
3109
3847
  primaryColor: "#6366f1",
3110
3848
  backgroundColor: "#ffffff",
3111
3849
  fontFamily: "system-ui, -apple-system, sans-serif",
@@ -3114,78 +3852,98 @@ const Ue = `
3114
3852
  panelHeight: 520,
3115
3853
  zIndex: 9999
3116
3854
  };
3117
- function qe(a) {
3118
- const t = { ...Ve, ...a };
3855
+ function ot(t, a) {
3856
+ const s = parseInt(t.slice(1, 3), 16), n = parseInt(t.slice(3, 5), 16), r = parseInt(t.slice(5, 7), 16), i = 1 - a;
3857
+ return `#${Math.round(s * i).toString(16).padStart(2, "0")}${Math.round(n * i).toString(16).padStart(2, "0")}${Math.round(r * i).toString(16).padStart(2, "0")}`;
3858
+ }
3859
+ function lt(t, a) {
3860
+ const s = parseInt(t.slice(1, 3), 16), n = parseInt(t.slice(3, 5), 16), r = parseInt(t.slice(5, 7), 16);
3861
+ return `#${Math.round(s + (255 - s) * a).toString(16).padStart(2, "0")}${Math.round(n + (255 - n) * a).toString(16).padStart(2, "0")}${Math.round(r + (255 - r) * a).toString(16).padStart(2, "0")}`;
3862
+ }
3863
+ function ct(t) {
3864
+ const a = { ...it, ...t }, s = a.primaryColor, n = a.backgroundColor;
3119
3865
  return [
3120
- `--sa-primary: ${t.primaryColor}`,
3121
- `--sa-bg: ${t.backgroundColor}`,
3122
- `--sa-font: ${t.fontFamily}`,
3123
- `--sa-radius: ${t.borderRadius}px`,
3124
- `--sa-panel-width: ${t.panelWidth}px`,
3125
- `--sa-panel-height: ${t.panelHeight}px`,
3126
- `--sa-z-index: ${t.zIndex}`
3866
+ // 用户直接配置的变量
3867
+ `--sa-primary: ${s}`,
3868
+ `--sa-bg: ${n}`,
3869
+ `--sa-font: ${a.fontFamily}`,
3870
+ `--sa-radius: ${a.borderRadius}px`,
3871
+ `--sa-panel-width: ${a.panelWidth}px`,
3872
+ `--sa-panel-height: ${a.panelHeight}px`,
3873
+ `--sa-z-index: ${a.zIndex}`,
3874
+ // 从 primaryColor 自动派生
3875
+ `--sa-primary-dark: ${ot(s, 0.15)}`,
3876
+ `--sa-primary-light: ${lt(s, 0.9)}`,
3877
+ // 从 backgroundColor 自动派生的语义色
3878
+ `--sa-surface: ${n}`,
3879
+ "--sa-border: #e5e7eb",
3880
+ "--sa-hover: #f4f4f5",
3881
+ "--sa-text: #374151",
3882
+ "--sa-text-muted: #9ca3af",
3883
+ "--sa-text-light: #6b7280"
3127
3884
  ].join("; ");
3128
3885
  }
3129
- function Ze(a, t) {
3130
- const r = typeof a == "string" ? document.querySelector(a) : a;
3131
- if (!r)
3132
- throw new Error(`Target element not found: ${a}`);
3133
- const s = document.createElement("div");
3134
- s.setAttribute("data-super-agent-widget", "");
3135
- const n = qe(t.theme ?? {});
3136
- if (s.setAttribute("style", n), r.appendChild(s), !document.getElementById("sa-widget-styles")) {
3886
+ function ut(t, a) {
3887
+ const s = typeof t == "string" ? document.querySelector(t) : t;
3888
+ if (!s)
3889
+ throw new Error(`Target element not found: ${t}`);
3890
+ const n = document.createElement("div");
3891
+ n.setAttribute("data-super-agent-widget", "");
3892
+ const r = ct(a.theme ?? {});
3893
+ if (n.setAttribute("style", `${r}; height: 100%;`), s.appendChild(n), !document.getElementById("sa-widget-styles")) {
3137
3894
  const c = document.createElement("style");
3138
- c.id = "sa-widget-styles", c.textContent = Ue, document.head.appendChild(c);
3895
+ c.id = "sa-widget-styles", c.textContent = nt, document.head.appendChild(c);
3139
3896
  }
3140
- let o = le(s), i = !1;
3897
+ let i = be(n), o = !1;
3141
3898
  const l = (c) => {
3142
- o && o.render(
3143
- Y.createElement(Ke, {
3144
- ...t,
3145
- initialOpen: c ?? i,
3899
+ i && i.render(
3900
+ V.createElement(st, {
3901
+ ...a,
3902
+ initialOpen: c ?? o,
3146
3903
  onOpenChange: (p) => {
3147
- i = p;
3904
+ o = p;
3148
3905
  }
3149
3906
  })
3150
3907
  );
3151
3908
  };
3152
3909
  return l(!1), {
3153
3910
  open() {
3154
- i = !0, l(!0);
3911
+ o = !0, l(!0);
3155
3912
  },
3156
3913
  close() {
3157
- i = !1, l(!1);
3914
+ o = !1, l(!1);
3158
3915
  },
3159
3916
  destroy() {
3160
- o && (o.unmount(), o = null), s.remove();
3917
+ i && (i.unmount(), i = null), n.remove();
3161
3918
  }
3162
3919
  };
3163
3920
  }
3164
3921
  export {
3165
- Re as ActionBar,
3166
- G as ChatProvider,
3167
- Ke as ChatWidget,
3168
- se as Composer,
3169
- Ne as ErrorPart,
3170
- Ye as FullpageLayout,
3171
- ue as Header,
3172
- C as Icon,
3173
- $e as InterruptCard,
3174
- Fe as Message,
3175
- ve as TextPart,
3176
- we as ThinkingPart,
3177
- re as Thread,
3178
- he as ThreadList,
3179
- ye as ToolCallPart,
3180
- Ce as ToolResultPart,
3181
- fe as Trigger,
3182
- He as WelcomeScreen,
3183
- Ve as defaultTheme,
3184
- Ze as mount,
3185
- qe as themeToCSSVars,
3186
- ge as useAutoScroll,
3187
- ce as useChat,
3188
- W as useChatContext,
3189
- pe as useConversations,
3190
- Ue as widgetStyles
3922
+ Ve as ActionBar,
3923
+ te as ChatProvider,
3924
+ st as ChatWidget,
3925
+ ue as Composer,
3926
+ Oe as ErrorPart,
3927
+ rt as FullpageLayout,
3928
+ ze as Header,
3929
+ I as Icon,
3930
+ Ue as InterruptCard,
3931
+ Ge as Message,
3932
+ De as TextPart,
3933
+ Le as ThinkingPart,
3934
+ fe as Thread,
3935
+ Se as ThreadList,
3936
+ Ee as ToolCallPart,
3937
+ Re as ToolResultPart,
3938
+ Ce as Trigger,
3939
+ Je as WelcomeScreen,
3940
+ it as defaultTheme,
3941
+ Ne as ensureIconFont,
3942
+ ut as mount,
3943
+ ct as themeToCSSVars,
3944
+ Te as useAutoScroll,
3945
+ ve as useChat,
3946
+ Y as useChatContext,
3947
+ ye as useConversations,
3948
+ nt as widgetStyles
3191
3949
  };