super-agent-sdk 1.0.6 → 1.0.7

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,1017 +1,1174 @@
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";
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 = {
1
+ import Y, { useState as D, useRef as O, useCallback as N, useEffect as B, createContext as ue, useMemo as G, useContext as me } from "react";
2
+ import { createRoot as he } from "react-dom/client";
3
+ import { jsx as e, jsxs as p, Fragment as J } from "react/jsx-runtime";
4
+ function ge(t) {
5
+ const { sdk: r, sessionId: s, onSessionCreated: n, onStreamStart: a, onStreamEnd: i, onError: o, onMessageSend: l } = t, [c, f] = D([]), [u, d] = D("ready"), [m, g] = D(null), x = O(null), w = O(!1), T = O(s), L = O(!0);
6
+ T.current = s, L.current = c.length === 0;
7
+ const E = N((y) => {
8
+ if (w.current) return;
9
+ w.current = !0, l == null || l(y);
10
+ const b = {
11
11
  id: `user_${Date.now()}`,
12
12
  role: "user",
13
- parts: [{ type: "text", content: L }],
13
+ parts: [{ type: "text", content: y }],
14
14
  timestamp: Date.now()
15
- }, y = `assistant_${Date.now()}`, D = {
16
- id: y,
15
+ }, v = `assistant_${Date.now()}`, C = {
16
+ id: v,
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 });
29
- }
20
+ }, P = L.current;
21
+ f((S) => [...S, b, C]), d("submitted"), g(null);
22
+ const R = (S) => {
23
+ let A = "", j = "", I = [], _ = !1;
24
+ const H = () => {
25
+ const $ = [...I];
30
26
  if (A) {
31
- const _ = x.findLastIndex((B) => B.type === "text");
32
- _ >= 0 ? x[_] = { type: "text", content: A } : x.push({ type: "text", content: A });
27
+ const W = $.findIndex((F) => F.type === "thinking");
28
+ W >= 0 ? $[W] = { type: "thinking", content: A } : $.unshift({ type: "thinking", content: A });
29
+ }
30
+ if (j) {
31
+ const W = $.findLastIndex((F) => F.type === "text");
32
+ W >= 0 ? $[W] = { type: "text", content: j } : $.push({ type: "text", content: j });
33
33
  }
34
- p(
35
- (_) => _.map((B) => B.id === y ? { ...B, parts: x } : B)
34
+ f(
35
+ (W) => W.map((F) => F.id === v ? { ...F, parts: $ } : F)
36
36
  );
37
37
  };
38
- k.current = t.chat({
39
- sessionId: M,
40
- message: L,
38
+ x.current = r.chat({
39
+ sessionId: S,
40
+ message: y,
41
41
  stream: !0,
42
- onMessage: (x) => {
43
- switch (z || (z = !0, u("streaming")), x.type) {
42
+ onMessage: ($) => {
43
+ switch (_ || (_ = !0, d("streaming")), $.type) {
44
44
  case "thinking":
45
- E += x.content;
45
+ A += $.content;
46
46
  break;
47
47
  case "ai":
48
- A += x.content;
48
+ j += $.content;
49
49
  break;
50
50
  case "tool_call":
51
- H.push({
51
+ I.push({
52
52
  type: "tool_call",
53
- toolName: x.toolName,
54
- toolCallId: x.toolCallId,
55
- args: x.args ?? "{}"
53
+ toolName: $.toolName,
54
+ toolCallId: $.toolCallId,
55
+ args: $.args ?? "{}"
56
56
  });
57
57
  break;
58
58
  case "tool_result":
59
- H.push({
59
+ I.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: $.toolName ?? "",
62
+ toolCallId: $.toolCallId,
63
+ content: $.content,
64
+ artifacts: $.artifacts,
65
+ renderMode: $.renderMode,
66
+ html: $.html
67
+ }), j && (I.push({ type: "text", content: j }), j = "");
68
68
  break;
69
69
  case "interrupt":
70
- x.interrupt && H.push({
70
+ $.interrupt && I.push({
71
71
  type: "interrupt",
72
- interrupt: x.interrupt,
72
+ interrupt: $.interrupt,
73
73
  resolved: !1
74
74
  });
75
75
  break;
76
+ case "stop":
77
+ $.content && (j = $.content), H();
78
+ return;
76
79
  }
77
- $();
80
+ H();
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: ($) => {
83
+ (j || I.length > 0 || A) && H(), $.messageId && f(
84
+ (F) => F.map((V) => V.id === v ? { ...V, id: $.messageId } : V)
85
+ ), $.sessionId && $.sessionId !== T.current && (n == null || n($.sessionId));
86
+ const W = () => {
87
+ i == null || i($.sessionId || S), d("ready"), w.current = !1, x.current = null;
88
+ };
89
+ if (P) {
90
+ const F = y.slice(0, 30), V = $.sessionId || S;
91
+ r.renameConversation(V, F).catch(() => {
92
+ }).finally(W);
93
+ } else
94
+ W();
83
95
  },
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;
96
+ onError: ($) => {
97
+ I.push({ type: "error", content: $.message }), H(), g($), d("error"), o == null || o($), w.current = !1, x.current = null;
86
98
  }
87
- }), n == null || n(M);
99
+ }), a == null || a(S);
88
100
  };
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;
101
+ T.current ? R(T.current) : r.createSession().then((S) => {
102
+ T.current = S, n == null || n(S), R(S);
103
+ }).catch((S) => {
104
+ g(S instanceof Error ? S : new Error(String(S))), d("error"), o == null || o(S instanceof Error ? S : new Error(String(S))), w.current = !1;
93
105
  });
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
- 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
106
+ }, [r, n, a, i, o, l]), k = N(() => {
107
+ var b;
108
+ const y = T.current;
109
+ (b = x.current) == null || b.abort(), x.current = null, d("ready"), w.current = !1, y && r.stopGeneration(y).catch(() => {
110
+ });
111
+ }, [r]), h = N(() => {
112
+ if (w.current) return;
113
+ const y = c.findLastIndex((v) => v.role === "user");
114
+ if (y < 0) return;
115
+ const b = c[y].parts.filter((v) => v.type === "text").map((v) => v.content).join("");
116
+ f((v) => v.slice(0, y)), E(b);
117
+ }, [c, E]), M = N((y, b) => {
118
+ f(
119
+ (I) => I.map((_) => ({
120
+ ..._,
121
+ parts: _.parts.map(
122
+ (H) => H.type === "interrupt" && H.interrupt.interruptId === y ? { ...H, resolved: !0, response: b } : H
109
123
  )
110
124
  }))
111
125
  );
112
- const y = v.current;
113
- if (!y) return;
114
- const D = `assistant_${Date.now()}`, P = {
115
- id: D,
126
+ const v = T.current;
127
+ if (!v) return;
128
+ const C = `assistant_${Date.now()}`, P = {
129
+ id: C,
116
130
  role: "assistant",
117
131
  parts: [],
118
132
  timestamp: Date.now()
119
133
  };
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 });
134
+ f((I) => [...I, P]), d("streaming");
135
+ let R = "", S = "", A = [];
136
+ const j = () => {
137
+ const I = [...A];
138
+ if (R) {
139
+ const _ = I.findIndex((H) => H.type === "thinking");
140
+ _ >= 0 ? I[_] = { type: "thinking", content: R } : I.unshift({ type: "thinking", content: R });
127
141
  }
128
- if (E) {
129
- const $ = z.findLastIndex((x) => x.type === "text");
130
- $ >= 0 ? z[$] = { type: "text", content: E } : z.push({ type: "text", content: E });
142
+ if (S) {
143
+ const _ = I.findLastIndex((H) => H.type === "text");
144
+ _ >= 0 ? I[_] = { type: "text", content: S } : I.push({ type: "text", content: S });
131
145
  }
132
- p(
133
- ($) => $.map((x) => x.id === D ? { ...x, parts: z } : x)
146
+ f(
147
+ (_) => _.map((H) => H.id === C ? { ...H, parts: I } : H)
134
148
  );
135
149
  };
136
- t.respondInterrupt(
137
- L,
150
+ r.respondInterrupt(
138
151
  y,
139
- O,
140
- (z) => {
141
- switch (z.type) {
152
+ v,
153
+ b,
154
+ (I) => {
155
+ switch (I.type) {
142
156
  case "thinking":
143
- M += z.content;
157
+ R += I.content;
144
158
  break;
145
159
  case "ai":
146
- E += z.content;
160
+ S += I.content;
147
161
  break;
148
162
  case "tool_call":
149
163
  A.push({
150
164
  type: "tool_call",
151
- toolName: z.toolName,
152
- toolCallId: z.toolCallId,
153
- args: z.args ?? "{}"
165
+ toolName: I.toolName,
166
+ toolCallId: I.toolCallId,
167
+ args: I.args ?? "{}"
154
168
  });
155
169
  break;
156
170
  case "tool_result":
157
171
  A.push({
158
172
  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 = "");
173
+ toolName: I.toolName ?? "",
174
+ toolCallId: I.toolCallId,
175
+ content: I.content,
176
+ artifacts: I.artifacts,
177
+ renderMode: I.renderMode,
178
+ html: I.html
179
+ }), S && (A.push({ type: "text", content: S }), S = "");
166
180
  break;
167
181
  case "interrupt":
168
- z.interrupt && A.push({ type: "interrupt", interrupt: z.interrupt, resolved: !1 });
182
+ I.interrupt && A.push({ type: "interrupt", interrupt: I.interrupt, resolved: !1 });
169
183
  break;
170
184
  case "done":
171
- z.messageId && p(
172
- ($) => $.map((x) => x.id === D ? { ...x, id: z.messageId } : x)
173
- ), u("ready");
185
+ I.messageId && f(
186
+ (_) => _.map((H) => H.id === C ? { ...H, id: I.messageId } : H)
187
+ ), d("ready");
174
188
  break;
175
189
  }
176
- H();
190
+ j();
177
191
  },
178
- (z) => {
179
- A.push({ type: "error", content: z.message }), H(), w(z), u("error"), i == null || i(z);
192
+ (I) => {
193
+ A.push({ type: "error", content: I.message }), j(), g(I), d("error"), o == null || o(I);
180
194
  }
181
- ).catch((z) => {
182
- i == null || i(z instanceof Error ? z : new Error(String(z))), u("error");
195
+ ).catch((I) => {
196
+ o == null || o(I instanceof Error ? I : new Error(String(I))), d("error");
183
197
  });
184
- }, [t, i]);
185
- return { messages: c, status: f, error: h, sendMessage: m, stop: g, regenerate: N, setMessages: p, respondToInterrupt: S };
198
+ }, [r, o]);
199
+ return { messages: c, status: u, error: m, sendMessage: E, stop: k, regenerate: h, setMessages: f, respondToInterrupt: M };
186
200
  }
187
- const X = "sa_active_conversation";
188
- function J() {
201
+ const ee = "sa_active_conversation", Q = 20;
202
+ function te() {
189
203
  try {
190
- return localStorage.getItem(X);
204
+ return localStorage.getItem(ee);
191
205
  } catch {
192
206
  return null;
193
207
  }
194
208
  }
195
- function de(a) {
209
+ function xe(t) {
196
210
  try {
197
- a ? localStorage.setItem(X, a) : localStorage.removeItem(X);
211
+ t ? localStorage.setItem(ee, t) : localStorage.removeItem(ee);
198
212
  } catch {
199
213
  }
200
214
  }
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;
215
+ function be(t) {
216
+ const { sdk: r, onConversationChange: s } = t, [n, a] = D([]), [i, o] = D(
217
+ () => te()
218
+ ), [l, c] = D(!1), [f, u] = D(!0), d = O(!0), m = O(1), g = O(!1);
219
+ B(() => () => {
220
+ d.current = !1;
207
221
  }, []);
208
- const f = I((m) => {
209
- i(m), de(m), m && (r == null || r(m));
210
- }, [r]), u = I(async () => {
211
- c(!0);
222
+ const x = N((y) => {
223
+ o(y), xe(y), y && (s == null || s(y));
224
+ }, [s]), w = N(async () => {
225
+ if (!g.current) {
226
+ g.current = !0, c(!0);
227
+ try {
228
+ m.current = 1;
229
+ const y = await r.listConversations({ page: 1, size: Q });
230
+ if (!d.current) return;
231
+ a(y.items), u(y.items.length < y.total);
232
+ const b = te();
233
+ b && !y.items.find((v) => v.sessionId === b) && x(null);
234
+ } catch {
235
+ } finally {
236
+ g.current = !1, d.current && c(!1);
237
+ }
238
+ }
239
+ }, [r, x]), T = N(async () => {
240
+ if (!(g.current || !f)) {
241
+ g.current = !0, c(!0);
242
+ try {
243
+ const y = m.current + 1, b = await r.listConversations({ page: y, size: Q });
244
+ if (!d.current) return;
245
+ m.current = y, a((C) => {
246
+ const P = new Set(C.map((S) => S.sessionId)), R = b.items.filter((S) => !P.has(S.sessionId));
247
+ return [...C, ...R];
248
+ });
249
+ const v = m.current * Q;
250
+ u(v < b.total);
251
+ } catch {
252
+ } finally {
253
+ g.current = !1, d.current && c(!1);
254
+ }
255
+ }
256
+ }, [r, f]), L = N(async (y) => (x(y), await r.getMessages(y)), [r, x]), E = N(async () => {
212
257
  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);
258
+ const y = await r.createSession(), b = (/* @__PURE__ */ new Date()).toISOString();
259
+ a((v) => [
260
+ { sessionId: y, botId: 0, title: "新对话", createTime: b, updateTime: b },
261
+ ...v
262
+ ]), x(y);
218
263
  } catch {
219
- } finally {
220
- p.current && c(!1);
264
+ x(null);
221
265
  }
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)
266
+ }, [r, x]), k = N(async (y) => {
267
+ await r.deleteConversation(y), a((b) => b.filter((v) => v.sessionId !== y)), i === y && x(null);
268
+ }, [r, i, x]), h = N(async (y, b) => {
269
+ await r.renameConversation(y, b), a(
270
+ (v) => v.map((C) => C.sessionId === y ? { ...C, title: b } : C)
229
271
  );
230
- }, [t]), { enabled: v = !0 } = a;
231
- return R(() => {
232
- v && u();
233
- }, [v, u]), {
234
- conversations: s,
235
- activeConversationId: o,
272
+ }, [r]), { enabled: M = !0 } = t;
273
+ return B(() => {
274
+ M && w();
275
+ }, [M, w]), {
276
+ conversations: n,
277
+ activeConversationId: i,
236
278
  loading: l,
237
- loadConversations: u,
238
- switchConversation: h,
239
- newConversation: w,
279
+ hasMore: f,
280
+ loadConversations: w,
281
+ loadMore: T,
282
+ switchConversation: L,
283
+ newConversation: E,
240
284
  deleteConversation: k,
241
- renameConversation: b,
242
- setActiveConversationId: f
285
+ renameConversation: h,
286
+ setActiveConversationId: x
243
287
  };
244
288
  }
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`;
289
+ function ne(t) {
290
+ return !t && t !== 0 ? "" : t < 1024 ? `${t} B` : t < 1024 * 1024 ? `${(t / 1024).toFixed(1)} KB` : `${(t / 1024 / 1024).toFixed(1)} MB`;
247
291
  }
248
- function ee(a) {
249
- return a === "pdf" ? "PDF" : a === "docx" ? "DOC" : a === "html" ? "HTM" : a.slice(0, 3).toUpperCase() || "FILE";
292
+ function ie(t) {
293
+ return t === "pdf" ? "PDF" : t === "docx" ? "DOC" : t === "html" ? "HTM" : t.slice(0, 3).toUpperCase() || "FILE";
250
294
  }
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
295
+ function oe(t) {
296
+ if (!t) return [];
297
+ const r = [];
298
+ for (const s of t)
299
+ s.type === "file" && s.data && r.push({
300
+ id: s.data.id ?? "",
301
+ type: s.data.fileType ?? s.data.type ?? "",
302
+ filename: s.data.name ?? s.data.filename ?? "",
303
+ url: s.data.url ?? "",
304
+ mime: s.data.mime,
305
+ size: s.data.size,
306
+ summary: s.data.summary
263
307
  });
264
- return t;
308
+ return r;
265
309
  }
266
- async function U(a) {
310
+ async function Z(t) {
267
311
  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);
312
+ const r = await fetch(t.url);
313
+ if (!r.ok) throw new Error(`HTTP ${r.status}`);
314
+ const s = await r.blob(), n = URL.createObjectURL(s), a = document.createElement("a");
315
+ a.href = n, a.download = t.filename, document.body.appendChild(a), a.click(), a.remove(), setTimeout(() => URL.revokeObjectURL(n), 4e3);
272
316
  } 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();
317
+ const r = document.createElement("a");
318
+ r.href = t.url, r.download = t.filename, r.target = "_blank", document.body.appendChild(r), r.click(), r.remove();
275
319
  }
276
320
  }
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;
321
+ const le = ue(null);
322
+ function U() {
323
+ const t = me(le);
324
+ if (!t) throw new Error("useChatContext must be used within ChatProvider");
325
+ return t;
282
326
  }
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(() => {
287
- f(!0);
327
+ function ae({ sdk: t, hooks: r, children: s }) {
328
+ const [n, a] = D(!1), [i, o] = D(!1), [l, c] = D(null), [f, u] = D(!1);
329
+ B(() => {
330
+ t.getToken().then(() => {
331
+ u(!0);
288
332
  }).catch(() => {
289
- f(!0);
333
+ u(!0);
290
334
  });
291
- }, [a]);
292
- const u = pe({
293
- sdk: a,
294
- onConversationChange: t == null ? void 0 : t.onConversationChange,
295
- enabled: p
296
- }), h = ce({
297
- sdk: a,
298
- sessionId: u.activeConversationId,
299
- onSessionCreated: (y) => {
300
- u.setActiveConversationId(y), u.loadConversations();
335
+ }, [t]);
336
+ const d = be({
337
+ sdk: t,
338
+ onConversationChange: r == null ? void 0 : r.onConversationChange,
339
+ enabled: f
340
+ }), m = ge({
341
+ sdk: t,
342
+ sessionId: d.activeConversationId,
343
+ onSessionCreated: (b) => {
344
+ d.setActiveConversationId(b);
301
345
  },
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();
346
+ onStreamStart: r == null ? void 0 : r.onStreamStart,
347
+ onStreamEnd: (b) => {
348
+ var v;
349
+ (v = r == null ? void 0 : r.onStreamEnd) == null || v.call(r, b), d.loadConversations();
306
350
  },
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);
351
+ onError: r == null ? void 0 : r.onError,
352
+ onMessageSend: r == null ? void 0 : r.onMessageSend
353
+ }), g = N(async (b) => {
354
+ const v = await d.switchConversation(b);
355
+ m.setMessages(v), a(!1);
356
+ }, [d, m]), x = N(async () => {
357
+ m.setMessages([]), a(!1), await d.newConversation();
358
+ }, [d, m]), w = N(async (b) => {
359
+ await d.deleteConversation(b), d.activeConversationId === b && m.setMessages([]);
360
+ }, [d, m]);
361
+ B(() => {
362
+ d.activeConversationId && m.messages.length === 0 && t.getMessages(d.activeConversationId).then((b) => {
363
+ m.setMessages(b);
320
364
  }).catch(() => {
321
365
  });
322
366
  }, []);
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));
367
+ const T = N(() => {
368
+ a((b) => !b);
369
+ }, []), L = N(() => {
370
+ o((b) => !b), c((b) => null);
371
+ }, []), E = N((b) => {
372
+ c(b), o(!0);
373
+ }, []), k = G(() => {
374
+ const b = /* @__PURE__ */ new Set(), v = [];
375
+ for (const C of m.messages)
376
+ for (const P of C.parts)
377
+ if (P.type === "tool_result" && P.artifacts)
378
+ for (const R of oe(P.artifacts)) {
379
+ const S = R.id || `${R.url}:${R.filename}`;
380
+ b.has(S) || (b.add(S), v.push(R));
337
381
  }
338
- return D;
339
- }, [h.messages]), S = I((y, D, P) => {
340
- a.feedback(y, D, P).catch(() => {
382
+ return v;
383
+ }, [m.messages]), h = N((b, v, C) => {
384
+ t.feedback(b, v, C).catch(() => {
341
385
  });
342
- }, [a]), L = I((y) => {
343
- a.cancelFeedback(y).catch(() => {
386
+ }, [t]), M = N((b) => {
387
+ t.cancelFeedback(b).catch(() => {
344
388
  });
345
- }, [a]), O = V(() => ({
346
- status: h.status,
347
- error: h.error,
348
- messages: h.messages,
349
- conversations: u.conversations,
350
- activeConversationId: u.activeConversationId,
351
- isThreadListOpen: s,
352
- isArtifactDrawerOpen: o,
353
- allArtifacts: N,
389
+ }, [t]), y = G(() => ({
390
+ sdk: t,
391
+ status: m.status,
392
+ error: m.error,
393
+ messages: m.messages,
394
+ conversations: d.conversations,
395
+ activeConversationId: d.activeConversationId,
396
+ isThreadListOpen: n,
397
+ isArtifactDrawerOpen: i,
398
+ allArtifacts: k,
354
399
  activePreviewArtifact: l,
355
- sendMessage: h.sendMessage,
356
- stop: h.stop,
357
- regenerate: h.regenerate,
358
- switchConversation: w,
359
- newConversation: k,
360
- deleteConversation: b,
361
- renameConversation: u.renameConversation,
362
- toggleThreadList: v,
363
- toggleArtifactDrawer: m,
364
- openArtifactPreview: g,
365
- feedback: S,
366
- cancelFeedback: L,
367
- respondToInterrupt: h.respondToInterrupt
400
+ hasMore: d.hasMore,
401
+ sendMessage: m.sendMessage,
402
+ stop: m.stop,
403
+ regenerate: m.regenerate,
404
+ switchConversation: g,
405
+ newConversation: x,
406
+ deleteConversation: w,
407
+ renameConversation: d.renameConversation,
408
+ loadMoreConversations: d.loadMore,
409
+ toggleThreadList: T,
410
+ toggleArtifactDrawer: L,
411
+ openArtifactPreview: E,
412
+ feedback: h,
413
+ cancelFeedback: M,
414
+ respondToInterrupt: m.respondToInterrupt
368
415
  }), [
369
- h.status,
370
- h.error,
371
- h.messages,
372
- h.sendMessage,
373
- h.stop,
374
- h.regenerate,
375
- h.respondToInterrupt,
376
- u.conversations,
377
- u.activeConversationId,
378
- u.renameConversation,
379
- s,
380
- o,
381
- N,
382
- l,
383
- w,
416
+ t,
417
+ m.status,
418
+ m.error,
419
+ m.messages,
420
+ m.sendMessage,
421
+ m.stop,
422
+ m.regenerate,
423
+ m.respondToInterrupt,
424
+ d.conversations,
425
+ d.activeConversationId,
426
+ d.renameConversation,
427
+ d.hasMore,
428
+ d.loadMore,
429
+ n,
430
+ i,
384
431
  k,
385
- b,
386
- v,
387
- m,
432
+ l,
388
433
  g,
389
- S,
390
- L
434
+ x,
435
+ w,
436
+ T,
437
+ L,
438
+ E,
439
+ h,
440
+ M
391
441
  ]);
392
- return /* @__PURE__ */ e(te.Provider, { value: O, children: r });
442
+ return /* @__PURE__ */ e(le.Provider, { value: y, children: s });
393
443
  }
394
- function C({ name: a, size: t = 16, color: r = "currentColor", className: s, style: n }) {
444
+ const ve = "https://at.alicdn.com/t/c/font_5210396_pffyg5g21kn.js";
445
+ let re = !1;
446
+ function we(t = ve) {
447
+ if (re || typeof document > "u") return;
448
+ re = !0;
449
+ const r = t.split("?")[0].split("/").pop();
450
+ if (r && document.querySelector(`script[src*="${r}"]`)) return;
451
+ const s = document.createElement("script");
452
+ s.src = t, document.head.appendChild(s);
453
+ }
454
+ we();
455
+ function z({ name: t, size: r = 16, color: s = "currentColor", className: n, style: a }) {
395
456
  return /* @__PURE__ */ e(
396
457
  "svg",
397
458
  {
398
- className: s,
399
- style: { width: t, height: t, fill: r, verticalAlign: "middle", ...n },
459
+ className: n,
460
+ style: { width: r, height: r, fill: s, verticalAlign: "middle", ...a },
400
461
  "aria-hidden": "true",
401
- children: /* @__PURE__ */ e("use", { href: `#icon-${a}` })
462
+ children: /* @__PURE__ */ e("use", { href: `#icon-${t}` })
402
463
  }
403
464
  );
404
465
  }
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" }) });
466
+ function ye({ isOpen: t, onClick: r }) {
467
+ return /* @__PURE__ */ e("button", { className: `sa-trigger ${t ? "sa-trigger-open" : ""}`, onClick: r, children: t ? /* @__PURE__ */ e(z, { name: "x", size: 24, color: "#fff" }) : /* @__PURE__ */ e(z, { name: "message-square", size: 24, color: "#fff" }) });
407
468
  }
408
- function ue({ title: a, onClose: t, onToggleThreadList: r, showClose: s = !0, artifactCount: n = 0, onToggleArtifactDrawer: o }) {
409
- return /* @__PURE__ */ d("div", { className: "sa-header", children: [
410
- /* @__PURE__ */ d("div", { className: "sa-header-left", children: [
469
+ function ke({ title: t, onClose: r, onToggleThreadList: s, showClose: n = !0, artifactCount: a = 0, onToggleArtifactDrawer: i }) {
470
+ return /* @__PURE__ */ p("div", { className: "sa-header", children: [
471
+ /* @__PURE__ */ p("div", { className: "sa-header-left", children: [
411
472
  /* @__PURE__ */ e("div", { className: "sa-header-avatar", children: "A" }),
412
- /* @__PURE__ */ d("div", { className: "sa-header-info", children: [
413
- /* @__PURE__ */ e("div", { className: "sa-header-title", children: a }),
473
+ /* @__PURE__ */ p("div", { className: "sa-header-info", children: [
474
+ /* @__PURE__ */ e("div", { className: "sa-header-title", children: t }),
414
475
  /* @__PURE__ */ e("div", { className: "sa-header-status", children: "● Online" })
415
476
  ] })
416
477
  ] }),
417
- /* @__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: [
419
- /* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
478
+ /* @__PURE__ */ p("div", { className: "sa-header-actions", children: [
479
+ a > 0 && i && /* @__PURE__ */ p("button", { className: "sa-header-btn sa-header-btn-artifact", onClick: i, title: "会话产物", children: [
480
+ /* @__PURE__ */ p("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
420
481
  /* @__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
482
  /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
422
483
  ] }),
423
484
  /* @__PURE__ */ e("span", { children: "产物" })
424
485
  ] }),
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 }) })
486
+ /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: s, title: "会话列表", children: /* @__PURE__ */ e(z, { name: "menu", size: 16 }) }),
487
+ n && /* @__PURE__ */ e("button", { className: "sa-header-btn", onClick: r, title: "关闭", children: /* @__PURE__ */ e(z, { name: "x", size: 16 }) })
427
488
  ] })
428
489
  ] });
429
490
  }
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) {
433
- const p = new Date(c.updateTime).getTime();
434
- p >= r ? n.push(c) : p >= s ? o.push(c) : i.push(c);
491
+ const X = (t) => String(t).padStart(2, "0");
492
+ function ce(t) {
493
+ if (!t) return "";
494
+ const r = new Date(t);
495
+ return isNaN(r.getTime()) ? "" : `${r.getFullYear()}-${X(r.getMonth() + 1)}-${X(r.getDate())} ${X(r.getHours())}:${X(r.getMinutes())}:${X(r.getSeconds())}`;
496
+ }
497
+ function Ne(t) {
498
+ const r = /* @__PURE__ */ new Date(), s = new Date(
499
+ r.getFullYear(),
500
+ r.getMonth(),
501
+ r.getDate()
502
+ ).getTime(), n = s - 6 * 864e5, a = [], i = [], o = [];
503
+ for (const c of t) {
504
+ const f = new Date(c.updateTime).getTime();
505
+ f >= s ? a.push(c) : f >= n ? i.push(c) : o.push(c);
435
506
  }
436
507
  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;
508
+ return a.length && l.push({ label: "今天", items: a }), i.length && l.push({ label: "最近 7 天", items: i }), o.length && l.push({ label: "更早", items: o }), l;
438
509
  }
439
- function he() {
510
+ function Ce() {
440
511
  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: [
512
+ conversations: t,
513
+ activeConversationId: r,
514
+ switchConversation: s,
515
+ newConversation: n,
516
+ deleteConversation: a,
517
+ renameConversation: i,
518
+ isThreadListOpen: o,
519
+ toggleThreadList: l,
520
+ hasMore: c,
521
+ loadMoreConversations: f
522
+ } = U(), [u, d] = D(null), [m, g] = D(""), x = O(null), w = N(
523
+ (k, h) => {
524
+ d(k), g(h ?? "");
525
+ },
526
+ []
527
+ ), T = N(
528
+ (k) => {
529
+ m.trim() && i(k, m.trim()), d(null);
530
+ },
531
+ [m, i]
532
+ ), L = N(() => {
533
+ const k = x.current;
534
+ !k || !c || k.scrollHeight - k.scrollTop - k.clientHeight < 50 && f();
535
+ }, [c, f]), E = G(() => Ne(t), [t]);
536
+ return o ? /* @__PURE__ */ p(J, { children: [
455
537
  /* @__PURE__ */ e("div", { className: "sa-thread-list-overlay", onClick: l }),
456
- /* @__PURE__ */ d("div", { className: "sa-thread-list", children: [
457
- /* @__PURE__ */ d("div", { className: "sa-thread-list-header", children: [
538
+ /* @__PURE__ */ p("div", { className: "sa-thread-list", children: [
539
+ /* @__PURE__ */ p("div", { className: "sa-thread-list-header", children: [
458
540
  /* @__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 }),
541
+ /* @__PURE__ */ p("button", { className: "sa-thread-list-new", onClick: n, children: [
542
+ /* @__PURE__ */ e(z, { name: "plus", size: 14 }),
461
543
  " 新会话"
462
544
  ] })
463
545
  ] }),
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
- ] })
546
+ /* @__PURE__ */ p(
547
+ "div",
548
+ {
549
+ className: "sa-thread-list-items",
550
+ ref: x,
551
+ onScroll: L,
552
+ children: [
553
+ t.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-empty", children: "暂无会话" }),
554
+ E.map((k) => /* @__PURE__ */ p("div", { className: "sa-thread-group", children: [
555
+ /* @__PURE__ */ e("div", { className: "sa-thread-group-label", children: k.label }),
556
+ k.items.map((h) => /* @__PURE__ */ p(
557
+ "div",
558
+ {
559
+ className: `sa-thread-item ${h.sessionId === r ? "active" : ""}`,
560
+ onClick: () => {
561
+ u !== h.sessionId && s(h.sessionId);
562
+ },
563
+ children: [
564
+ u === h.sessionId ? /* @__PURE__ */ e(
565
+ "input",
566
+ {
567
+ className: "sa-thread-item-edit",
568
+ value: m,
569
+ onChange: (M) => g(M.target.value),
570
+ onBlur: () => T(h.sessionId),
571
+ onKeyDown: (M) => {
572
+ M.key === "Enter" && T(h.sessionId), M.key === "Escape" && d(null);
573
+ },
574
+ onClick: (M) => M.stopPropagation(),
575
+ autoFocus: !0
576
+ }
577
+ ) : /* @__PURE__ */ p("div", { className: "sa-thread-item-info", children: [
578
+ /* @__PURE__ */ e("span", { className: "sa-thread-item-title", children: h.title || "新会话" }),
579
+ /* @__PURE__ */ e("span", { className: "sa-thread-item-time", children: ce(h.updateTime) })
580
+ ] }),
581
+ /* @__PURE__ */ p("div", { className: "sa-thread-item-actions", children: [
582
+ /* @__PURE__ */ e(
583
+ "button",
584
+ {
585
+ className: "sa-thread-item-action-btn",
586
+ onClick: (M) => {
587
+ M.stopPropagation(), w(h.sessionId, h.title);
588
+ },
589
+ title: "重命名",
590
+ children: /* @__PURE__ */ e(z, { name: "pen", size: 13 })
591
+ }
592
+ ),
593
+ /* @__PURE__ */ e(
594
+ "button",
595
+ {
596
+ className: "sa-thread-item-action-btn",
597
+ onClick: (M) => {
598
+ M.stopPropagation(), a(h.sessionId);
599
+ },
600
+ title: "删除",
601
+ children: /* @__PURE__ */ e(z, { name: "trash2", size: 13 })
602
+ }
603
+ )
604
+ ] })
605
+ ]
606
+ },
607
+ h.sessionId
608
+ ))
609
+ ] }, k.label)),
610
+ c && /* @__PURE__ */ e("div", { className: "sa-thread-list-loading", children: "加载更多..." })
611
+ ]
612
+ }
613
+ )
514
614
  ] })
515
615
  ] }) : null;
516
616
  }
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;
617
+ function ze(t) {
618
+ const r = O(null), s = O(!1), n = O(0), a = N(() => {
619
+ const o = r.current;
620
+ if (!o) return;
621
+ const { scrollTop: l, scrollHeight: c, clientHeight: f } = o, u = c - l - f < 40;
622
+ l < n.current && !u && (s.current = !0), u && (s.current = !1), n.current = l;
523
623
  }, []);
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;
624
+ B(() => {
625
+ const o = r.current;
626
+ if (o)
627
+ return o.addEventListener("scroll", a, { passive: !0 }), () => o.removeEventListener("scroll", a);
628
+ }, [a]), B(() => {
629
+ if (s.current) return;
630
+ const o = r.current;
631
+ o && requestAnimationFrame(() => {
632
+ o.scrollTop = o.scrollHeight;
533
633
  });
534
- }, a);
535
- const o = I(() => {
536
- r.current = !1;
537
- const i = t.current;
538
- i && (i.scrollTop = i.scrollHeight);
634
+ }, t);
635
+ const i = N(() => {
636
+ s.current = !1;
637
+ const o = r.current;
638
+ o && (o.scrollTop = o.scrollHeight);
539
639
  }, []);
540
- return { containerRef: t, scrollToBottom: o };
640
+ return { containerRef: r, scrollToBottom: i };
541
641
  }
542
- function j(a) {
543
- return a.value++;
642
+ function K(t) {
643
+ return t.value++;
544
644
  }
545
- function K(a, t) {
546
- const r = [], s = [], n = () => {
547
- s.length > 0 && (r.push(s.join("")), s.length = 0);
645
+ function q(t, r) {
646
+ const s = [], n = [], a = () => {
647
+ n.length > 0 && (s.push(n.join("")), n.length = 0);
548
648
  };
549
- let o = 0;
550
- for (; o < a.length; ) {
551
- const i = a[o];
552
- if (i === "`") {
553
- const l = a.indexOf("`", o + 1);
649
+ let i = 0;
650
+ for (; i < t.length; ) {
651
+ const o = t[i];
652
+ if (o === "`") {
653
+ const l = t.indexOf("`", i + 1);
554
654
  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;
655
+ a(), s.push(
656
+ /* @__PURE__ */ e("code", { className: "sa-inline-code", children: t.slice(i + 1, l) }, K(r))
657
+ ), i = l + 1;
558
658
  continue;
559
659
  }
560
- } else if (i === "*" && a[o + 1] === "*") {
561
- const l = a.indexOf("**", o + 2);
660
+ } else if (o === "*" && t[i + 1] === "*") {
661
+ const l = t.indexOf("**", i + 2);
562
662
  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;
663
+ a(), s.push(
664
+ /* @__PURE__ */ e("strong", { children: q(t.slice(i + 2, l), r) }, K(r))
665
+ ), i = l + 2;
566
666
  continue;
567
667
  }
568
- } else if (i === "*") {
569
- const l = a.indexOf("*", o + 1);
668
+ } else if (o === "*") {
669
+ const l = t.indexOf("*", i + 1);
570
670
  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;
671
+ a(), s.push(
672
+ /* @__PURE__ */ e("em", { children: q(t.slice(i + 1, l), r) }, K(r))
673
+ ), i = l + 1;
574
674
  continue;
575
675
  }
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);
676
+ } else if (o === "[") {
677
+ const l = t.indexOf("]", i + 1);
678
+ if (l !== -1 && t[l + 1] === "(") {
679
+ const c = t.indexOf(")", l + 2);
580
680
  if (c !== -1) {
581
- const p = a.slice(o + 1, l), f = a.slice(l + 2, c);
582
- n(), r.push(
681
+ const f = t.slice(i + 1, l), u = t.slice(l + 2, c);
682
+ a(), s.push(
583
683
  /* @__PURE__ */ e(
584
684
  "a",
585
685
  {
586
- href: f,
686
+ href: u,
587
687
  target: "_blank",
588
688
  rel: "noreferrer",
589
- children: K(p, t)
689
+ children: q(f, r)
590
690
  },
591
- j(t)
691
+ K(r)
592
692
  )
593
- ), o = c + 1;
693
+ ), i = c + 1;
594
694
  continue;
595
695
  }
596
696
  }
597
697
  }
598
- s.push(i), o++;
698
+ n.push(o), i++;
599
699
  }
600
- return n(), r;
700
+ return a(), s;
601
701
  }
602
- function be(a, t) {
603
- const r = [], s = a.split(`
702
+ function Ie(t, r) {
703
+ const s = [], n = t.split(`
604
704
  `);
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++;
705
+ let a = 0;
706
+ const i = (c) => c.trim() === "", o = (c) => /^#{1,6}\s+\S/.test(c.trim()), l = (c) => /^(?:[-*+]|\d+[.)])\s+\S/.test(c.trim());
707
+ for (; a < n.length; ) {
708
+ const c = n[a], f = c.trim();
709
+ if (i(c)) {
710
+ a++;
611
711
  continue;
612
712
  }
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(
713
+ if (o(c)) {
714
+ const d = f.match(/^(#{1,6})\s+(.*)$/);
715
+ if (d) {
716
+ const g = `h${Math.min(d[1].length, 6)}`;
717
+ s.push(
618
718
  Y.createElement(
619
- w,
620
- { key: j(t) },
621
- K(u[2], t)
719
+ g,
720
+ { key: K(r) },
721
+ q(d[2], r)
622
722
  )
623
723
  );
624
724
  }
625
- n++;
725
+ a++;
626
726
  continue;
627
727
  }
628
728
  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++;
729
+ const d = /^\d+[.)]/.test(f), m = [];
730
+ for (; a < n.length && l(n[a]); ) {
731
+ const g = n[a].trim().match(/^(?:[-*+]|\d+[.)])\s+(.*)$/);
732
+ g && m.push(
733
+ /* @__PURE__ */ e("li", { children: q(g[1], r) }, K(r))
734
+ ), a++;
635
735
  }
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))
736
+ s.push(
737
+ d ? /* @__PURE__ */ e("ol", { className: "sa-list", children: m }, K(r)) : /* @__PURE__ */ e("ul", { className: "sa-list", children: m }, K(r))
638
738
  );
639
739
  continue;
640
740
  }
641
- 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))
741
+ const u = [];
742
+ for (; a < n.length && !i(n[a]) && !o(n[a]) && !l(n[a]); )
743
+ u.push(n[a]), a++;
744
+ s.push(
745
+ /* @__PURE__ */ e("p", { className: "sa-text-paragraph", children: q(u.join(" "), r) }, K(r))
646
746
  );
647
747
  }
648
- return r;
748
+ return s;
649
749
  }
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))
750
+ function Se(t) {
751
+ const r = { value: 0 }, s = [], n = t.split("```");
752
+ for (let a = 0; a < n.length; a++)
753
+ if (a % 2 === 0)
754
+ s.push(...Ie(n[a], r));
755
+ else if (n[a].trim() !== "") {
756
+ let i = n[a].replace(/^\r?\n/, "");
757
+ i = i.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/, ""), i = i.replace(/\r?\n$/, ""), s.push(
758
+ /* @__PURE__ */ e("pre", { className: "sa-code-block", children: /* @__PURE__ */ e("code", { children: i }) }, K(r))
659
759
  );
660
760
  }
661
- return r;
761
+ return s;
662
762
  }
663
- function ve({ content: a }) {
664
- return /* @__PURE__ */ e("div", { className: "sa-text-part", children: xe(a) });
763
+ function Te({ content: t }) {
764
+ return /* @__PURE__ */ e("div", { className: "sa-text-part", children: Se(t) });
665
765
  }
666
- function we({ content: a }) {
667
- const [t, r] = T(!1);
668
- return /* @__PURE__ */ d("div", { className: "sa-thinking-part", onClick: () => r(!t), children: [
669
- /* @__PURE__ */ d("div", { className: "sa-thinking-header", children: [
670
- /* @__PURE__ */ e("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ e(C, { name: "brain", size: 14 }) }),
766
+ function Me({ content: t }) {
767
+ const [r, s] = D(!1);
768
+ return /* @__PURE__ */ p("div", { className: "sa-thinking-part", onClick: () => s(!r), children: [
769
+ /* @__PURE__ */ p("div", { className: "sa-thinking-header", children: [
770
+ /* @__PURE__ */ e("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ e(z, { name: "brain", size: 14 }) }),
671
771
  /* @__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 }) })
772
+ /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${r ? "expanded" : ""}`, children: /* @__PURE__ */ e(z, { name: "chevron-right", size: 12 }) })
673
773
  ] }),
674
- t && /* @__PURE__ */ e("div", { className: "sa-thinking-content", children: a })
774
+ r && /* @__PURE__ */ e("div", { className: "sa-thinking-content", children: t })
675
775
  ] });
676
776
  }
677
- function ye({ toolName: a, toolCallId: t, args: r }) {
678
- const [s, n] = T(!1);
679
- let o = r;
777
+ function De({ toolName: t, toolCallId: r, args: s }) {
778
+ const [n, a] = D(!1);
779
+ let i = s;
680
780
  try {
681
- o = JSON.stringify(JSON.parse(r), null, 2);
781
+ i = JSON.stringify(JSON.parse(s), null, 2);
682
782
  } catch {
683
783
  }
684
- 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 }) }),
687
- /* @__PURE__ */ d("span", { className: "sa-tool-name", children: [
784
+ return /* @__PURE__ */ p("div", { className: "sa-tool-call-part", children: [
785
+ /* @__PURE__ */ p("div", { className: "sa-tool-call-header", onClick: () => a(!n), children: [
786
+ /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(z, { name: "zap", size: 14 }) }),
787
+ /* @__PURE__ */ p("span", { className: "sa-tool-name", children: [
688
788
  "调用工具: ",
689
- a
789
+ t
690
790
  ] }),
691
- /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${s ? "expanded" : ""}`, children: /* @__PURE__ */ e(C, { name: "chevron-right", size: 12 }) })
791
+ /* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${n ? "expanded" : ""}`, children: /* @__PURE__ */ e(z, { name: "chevron-right", size: 12 }) })
692
792
  ] }),
693
- s && /* @__PURE__ */ e("pre", { className: "sa-tool-args", children: o })
793
+ n && /* @__PURE__ */ e("pre", { className: "sa-tool-args", children: i })
694
794
  ] });
695
795
  }
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 }));
796
+ function $e({ html: t }) {
797
+ const [r, s] = D(null), n = Y.useRef(null);
798
+ B(() => {
799
+ let i = !1;
800
+ return import("./purify.es-C-6FFqDW.js").then((o) => {
801
+ i || s(o.default.sanitize(t, { FORCE_BODY: !0 }));
702
802
  }), () => {
703
- s = !0;
803
+ i = !0;
704
804
  };
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 产物" }) });
805
+ }, [t]);
806
+ const a = Y.useCallback(() => {
807
+ var o;
808
+ const i = n.current;
809
+ if (i)
810
+ try {
811
+ const l = i.contentDocument || ((o = i.contentWindow) == null ? void 0 : o.document);
812
+ if (!(l != null && l.body)) return;
813
+ const c = l.body.scrollHeight;
814
+ i.style.height = Math.min(c, 500) + "px";
815
+ } catch {
816
+ }
817
+ }, []);
818
+ return B(() => {
819
+ const i = n.current;
820
+ if (!(!i || r === null))
821
+ return i.addEventListener("load", a), () => i.removeEventListener("load", a);
822
+ }, [r, a]), r === null ? null : /* @__PURE__ */ e("div", { className: "sa-tool-result-html", children: /* @__PURE__ */ e(
823
+ "iframe",
824
+ {
825
+ ref: n,
826
+ srcDoc: r,
827
+ className: "sa-tool-result-html-iframe",
828
+ sandbox: "allow-same-origin",
829
+ title: "HTML 产物"
830
+ }
831
+ ) });
706
832
  }
707
- function Ce({ toolName: a, content: t, artifacts: r, renderMode: s, html: n, artifactPreview: o }) {
708
- const { openArtifactPreview: i } = W(), l = ae(r);
709
- return /* @__PURE__ */ d("div", { className: "sa-tool-result-part", children: [
710
- /* @__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 || "工具返回" })
833
+ function Ee({ toolName: t, content: r, artifacts: s, renderMode: n, html: a, artifactPreview: i }) {
834
+ const { openArtifactPreview: o } = U(), l = oe(s);
835
+ return /* @__PURE__ */ p("div", { className: "sa-tool-result-part", children: [
836
+ /* @__PURE__ */ p("div", { className: "sa-tool-result-header", children: [
837
+ /* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(z, { name: "circle-check", size: 14, color: "#10b981" }) }),
838
+ /* @__PURE__ */ e("span", { className: "sa-tool-result-label", children: t || "工具返回" })
713
839
  ] }),
714
- s === "html" && n ? /* @__PURE__ */ e(ke, { html: n }) : t ? /* @__PURE__ */ e("div", { className: "sa-tool-result-content", children: t }) : null,
715
- l.length > 0 && /* @__PURE__ */ e("ul", { className: "sa-artifact-file-list", role: "list", children: l.map((c, p) => /* @__PURE__ */ d(
840
+ n === "html" && a ? /* @__PURE__ */ e($e, { html: a }) : r ? /* @__PURE__ */ e("div", { className: "sa-tool-result-content", children: r }) : null,
841
+ l.length > 0 && /* @__PURE__ */ e("ul", { className: "sa-artifact-file-list", role: "list", children: l.map((c, f) => /* @__PURE__ */ p(
716
842
  "li",
717
843
  {
718
844
  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));
845
+ onClick: i ? () => o(c) : void 0,
846
+ onKeyDown: i ? (u) => {
847
+ (u.key === "Enter" || u.key === " ") && (u.preventDefault(), o(c));
722
848
  } : 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,
849
+ tabIndex: i ? 0 : void 0,
850
+ role: i ? "button" : void 0,
851
+ "aria-label": i ? `预览 ${c.filename}` : void 0,
852
+ style: i ? { cursor: "pointer" } : void 0,
727
853
  children: [
728
- /* @__PURE__ */ e("div", { className: "sa-artifact-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(c.type) }) }),
729
- /* @__PURE__ */ d("div", { className: "sa-artifact-file-info", children: [
854
+ /* @__PURE__ */ e("div", { className: "sa-artifact-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ie(c.type) }) }),
855
+ /* @__PURE__ */ p("div", { className: "sa-artifact-file-info", children: [
730
856
  /* @__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) })
857
+ c.size != null && /* @__PURE__ */ e("span", { className: "sa-artifact-file-size", children: ne(c.size) })
732
858
  ] }),
733
- o && /* @__PURE__ */ e(
859
+ i && /* @__PURE__ */ e(
734
860
  "button",
735
861
  {
736
862
  className: "sa-artifact-file-download",
737
863
  title: "下载",
738
864
  "aria-label": `下载 ${c.filename}`,
739
- onClick: (f) => {
740
- f.stopPropagation(), U(c);
865
+ onClick: (u) => {
866
+ u.stopPropagation(), Z(c);
741
867
  },
742
868
  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
869
  }
744
870
  )
745
871
  ]
746
872
  },
747
- c.id || `art-${p}`
873
+ c.id || `art-${f}`
748
874
  )) })
749
875
  ] });
750
876
  }
751
- function Ne({ content: a, onRetry: t }) {
752
- return /* @__PURE__ */ d("div", { className: "sa-error-part", children: [
753
- /* @__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 })
877
+ function Le({ content: t, onRetry: r }) {
878
+ return /* @__PURE__ */ p("div", { className: "sa-error-part", children: [
879
+ /* @__PURE__ */ p("div", { className: "sa-error-content", children: [
880
+ /* @__PURE__ */ e("span", { className: "sa-error-icon", children: /* @__PURE__ */ e(z, { name: "triangle-alert", size: 14 }) }),
881
+ /* @__PURE__ */ e("span", { children: t })
756
882
  ] }),
757
- t && /* @__PURE__ */ e("button", { className: "sa-error-retry", onClick: t, children: "重试" })
883
+ r && /* @__PURE__ */ e("button", { className: "sa-error-retry", onClick: r, children: "重试" })
758
884
  ] });
759
885
  }
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) || "取消";
763
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
764
- /* @__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 })
886
+ function Ae({ interrupt: t, onRespond: r, disabled: s, answeredAction: n }) {
887
+ var l, c;
888
+ const a = t.options, i = (typeof (a == null ? void 0 : a[0]) == "string" ? a[0] : (l = a == null ? void 0 : a[0]) == null ? void 0 : l.label) || "确认", o = (typeof (a == null ? void 0 : a[1]) == "string" ? a[1] : (c = a == null ? void 0 : a[1]) == null ? void 0 : c.label) || "取消";
889
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-card", children: [
890
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-content", children: [
891
+ /* @__PURE__ */ e(z, { name: "circle-alert", size: 16, color: "#f59e0b" }),
892
+ /* @__PURE__ */ e("span", { children: t.content })
767
893
  ] }),
768
- /* @__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
- ] })
894
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-actions", children: [
895
+ /* @__PURE__ */ p(
896
+ "button",
897
+ {
898
+ className: `sa-interrupt-btn sa-interrupt-btn-primary ${n === "confirm" ? "sa-interrupt-btn-answered" : ""}`,
899
+ disabled: s,
900
+ onClick: () => r({ action: "confirm" }),
901
+ children: [
902
+ /* @__PURE__ */ e(z, { name: "check", size: 14 }),
903
+ " ",
904
+ i
905
+ ]
906
+ }
907
+ ),
908
+ /* @__PURE__ */ p(
909
+ "button",
910
+ {
911
+ className: `sa-interrupt-btn sa-interrupt-btn-secondary ${n === "cancel" ? "sa-interrupt-btn-answered" : ""}`,
912
+ disabled: s,
913
+ onClick: () => r({ action: "cancel" }),
914
+ children: [
915
+ /* @__PURE__ */ e(z, { name: "x", size: 14 }),
916
+ " ",
917
+ o
918
+ ]
919
+ }
920
+ )
921
+ ] }),
922
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
780
923
  ] });
781
924
  }
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;
785
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
786
- /* @__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 })
925
+ function Re({ interrupt: t, onRespond: r, disabled: s, answeredAction: n }) {
926
+ var f, u, d, m;
927
+ const a = t.options, i = (typeof (a == null ? void 0 : a[0]) == "string" ? a[0] : (f = a == null ? void 0 : a[0]) == null ? void 0 : f.label) || "批准", o = (typeof (a == null ? void 0 : a[1]) == "string" ? a[1] : (u = a == null ? void 0 : a[1]) == null ? void 0 : u.label) || "拒绝", l = (typeof (a == null ? void 0 : a[2]) == "string" ? a[2] : (d = a == null ? void 0 : a[2]) == null ? void 0 : d.label) || "跳过", c = ((m = t.metadata) == null ? void 0 : m.showSkip) !== !1;
928
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-card", children: [
929
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-content", children: [
930
+ /* @__PURE__ */ e(z, { name: "circle-alert", size: 16, color: "#f59e0b" }),
931
+ /* @__PURE__ */ e("span", { children: t.content })
789
932
  ] }),
790
- /* @__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
- ] })
933
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-actions", children: [
934
+ /* @__PURE__ */ p(
935
+ "button",
936
+ {
937
+ className: `sa-interrupt-btn sa-interrupt-btn-primary ${n === "approve" ? "sa-interrupt-btn-answered" : ""}`,
938
+ disabled: s,
939
+ onClick: () => r({ action: "approve" }),
940
+ children: [
941
+ /* @__PURE__ */ e(z, { name: "check", size: 14 }),
942
+ " ",
943
+ i
944
+ ]
945
+ }
946
+ ),
947
+ /* @__PURE__ */ p(
948
+ "button",
949
+ {
950
+ className: `sa-interrupt-btn sa-interrupt-btn-danger ${n === "reject" ? "sa-interrupt-btn-answered" : ""}`,
951
+ disabled: s,
952
+ onClick: () => r({ action: "reject" }),
953
+ children: [
954
+ /* @__PURE__ */ e(z, { name: "x", size: 14 }),
955
+ " ",
956
+ o
957
+ ]
958
+ }
959
+ ),
960
+ c && /* @__PURE__ */ p(
961
+ "button",
962
+ {
963
+ className: `sa-interrupt-btn sa-interrupt-btn-secondary ${n === "skip" ? "sa-interrupt-btn-answered" : ""}`,
964
+ disabled: s,
965
+ onClick: () => r({ action: "skip" }),
966
+ children: [
967
+ /* @__PURE__ */ e(z, { name: "chevron-right", size: 14 }),
968
+ " ",
969
+ l
970
+ ]
971
+ }
972
+ )
973
+ ] }),
974
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
807
975
  ] });
808
976
  }
809
- function Te(a) {
810
- return typeof a == "string" ? { value: a, label: a } : a;
977
+ function Oe(t) {
978
+ return typeof t == "string" ? { value: t, label: t } : t;
811
979
  }
812
- function Se({ interrupt: a, onRespond: t }) {
813
- const r = (a.options ?? []).map(Te);
814
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
815
- /* @__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 })
980
+ function Pe({ interrupt: t, onRespond: r, disabled: s, initialValue: n }) {
981
+ const a = (t.options ?? []).map(Oe);
982
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-card", children: [
983
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-content", children: [
984
+ /* @__PURE__ */ e(z, { name: "list", size: 16, color: "#6366f1" }),
985
+ /* @__PURE__ */ e("span", { children: t.content })
818
986
  ] }),
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
- )) })
987
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: a.map((i) => {
988
+ const o = n === i.value;
989
+ return /* @__PURE__ */ p(
990
+ "button",
991
+ {
992
+ className: `sa-interrupt-option ${i.danger ? "sa-interrupt-option-danger" : ""} ${o ? "sa-interrupt-option-selected" : ""}`,
993
+ disabled: s,
994
+ onClick: () => r({ action: "select", value: i.value }),
995
+ children: [
996
+ /* @__PURE__ */ e(z, { name: o ? "circle-check" : "circle", size: 14 }),
997
+ i.icon && /* @__PURE__ */ e(z, { name: i.icon, size: 14 }),
998
+ /* @__PURE__ */ e("span", { children: i.label }),
999
+ i.description && /* @__PURE__ */ e("span", { className: "sa-interrupt-option-desc", children: i.description })
1000
+ ]
1001
+ },
1002
+ i.value
1003
+ );
1004
+ }) }),
1005
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
832
1006
  ] });
833
1007
  }
834
- function Me(a) {
835
- return typeof a == "string" ? { value: a, label: a } : a;
1008
+ function He(t) {
1009
+ return typeof t == "string" ? { value: t, label: t } : t;
836
1010
  }
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;
1011
+ function Be({ interrupt: t, onRespond: r, disabled: s, initialValue: n }) {
1012
+ const a = (t.options ?? []).map(He), [i, o] = D(
1013
+ () => new Set(Array.isArray(n) ? n : [])
1014
+ ), l = (c) => {
1015
+ s || o((f) => {
1016
+ const u = new Set(f);
1017
+ return u.has(c) ? u.delete(c) : u.add(c), u;
842
1018
  });
843
1019
  };
844
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
845
- /* @__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 })
1020
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-card", children: [
1021
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-content", children: [
1022
+ /* @__PURE__ */ e(z, { name: "list-checks", size: 16, color: "#6366f1" }),
1023
+ /* @__PURE__ */ e("span", { children: t.content })
848
1024
  ] }),
849
- /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((i) => /* @__PURE__ */ d(
1025
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: a.map((c) => /* @__PURE__ */ p(
850
1026
  "button",
851
1027
  {
852
- className: `sa-interrupt-option ${s.has(i.value) ? "sa-interrupt-option-selected" : ""}`,
853
- onClick: () => o(i.value),
1028
+ className: `sa-interrupt-option ${i.has(c.value) ? "sa-interrupt-option-selected" : ""}`,
1029
+ disabled: s,
1030
+ onClick: () => l(c.value),
854
1031
  children: [
855
- /* @__PURE__ */ e(C, { name: s.has(i.value) ? "square-check" : "square", size: 14 }),
856
- /* @__PURE__ */ e("span", { children: i.label })
1032
+ /* @__PURE__ */ e(z, { name: i.has(c.value) ? "square-check" : "square", size: 14 }),
1033
+ /* @__PURE__ */ e("span", { children: c.label })
857
1034
  ]
858
1035
  },
859
- i.value
1036
+ c.value
860
1037
  )) }),
861
- /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
1038
+ !s && /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ p(
862
1039
  "button",
863
1040
  {
864
1041
  className: "sa-interrupt-btn sa-interrupt-btn-primary",
865
- disabled: s.size === 0,
866
- onClick: () => t({ action: "submit", value: Array.from(s) }),
1042
+ disabled: i.size === 0,
1043
+ onClick: () => r({ action: "submit", value: Array.from(i) }),
867
1044
  children: [
868
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
1045
+ /* @__PURE__ */ e(z, { name: "check", size: 14 }),
869
1046
  " 确认 (",
870
- s.size,
1047
+ i.size,
871
1048
  ")"
872
1049
  ]
873
1050
  }
874
- ) })
1051
+ ) }),
1052
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
875
1053
  ] });
876
1054
  }
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() });
1055
+ function je({ interrupt: t, onRespond: r, disabled: s, initialValue: n }) {
1056
+ const [a, i] = D(n ?? ""), o = t.inputType ?? "text", l = o === "textarea", c = () => {
1057
+ s || t.required && !a.trim() || r({ action: "submit", value: a.trim() });
880
1058
  };
881
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
882
- /* @__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 })
1059
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-card", children: [
1060
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-content", children: [
1061
+ /* @__PURE__ */ e(z, { name: "text-cursor-input", size: 16, color: "#6366f1" }),
1062
+ /* @__PURE__ */ e("span", { children: t.content })
885
1063
  ] }),
886
- /* @__PURE__ */ e("div", { className: "sa-interrupt-input-area", children: o ? /* @__PURE__ */ e(
1064
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-input-area", children: l ? /* @__PURE__ */ e(
887
1065
  "textarea",
888
1066
  {
889
1067
  className: "sa-interrupt-textarea",
890
- value: r,
891
- onChange: (l) => s(l.target.value),
892
- placeholder: a.placeholder,
893
- maxLength: a.maxLength,
894
- rows: 3
1068
+ value: a,
1069
+ onChange: (f) => i(f.target.value),
1070
+ placeholder: t.placeholder,
1071
+ maxLength: t.maxLength,
1072
+ rows: 3,
1073
+ disabled: s
895
1074
  }
896
1075
  ) : /* @__PURE__ */ e(
897
1076
  "input",
898
1077
  {
899
1078
  className: "sa-interrupt-input",
900
- type: n,
901
- value: r,
902
- onChange: (l) => s(l.target.value),
903
- placeholder: a.placeholder,
904
- maxLength: a.maxLength,
905
- onKeyDown: (l) => l.key === "Enter" && i()
1079
+ type: o,
1080
+ value: a,
1081
+ onChange: (f) => i(f.target.value),
1082
+ placeholder: t.placeholder,
1083
+ maxLength: t.maxLength,
1084
+ onKeyDown: (f) => f.key === "Enter" && c(),
1085
+ disabled: s
906
1086
  }
907
1087
  ) }),
908
- /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ d(
1088
+ !s && /* @__PURE__ */ e("div", { className: "sa-interrupt-actions", children: /* @__PURE__ */ p(
909
1089
  "button",
910
1090
  {
911
1091
  className: "sa-interrupt-btn sa-interrupt-btn-primary",
912
- disabled: a.required ? !r.trim() : !1,
913
- onClick: i,
1092
+ disabled: t.required ? !a.trim() : !1,
1093
+ onClick: c,
914
1094
  children: [
915
- /* @__PURE__ */ e(C, { name: "check", size: 14 }),
1095
+ /* @__PURE__ */ e(z, { name: "check", size: 14 }),
916
1096
  " 提交"
917
1097
  ]
918
1098
  }
919
- ) })
1099
+ ) }),
1100
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
920
1101
  ] });
921
1102
  }
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 });
1103
+ function _e({ interrupt: t, onRespond: r, disabled: s, initialValue: n }) {
1104
+ const a = t.fields ?? [], [i, o] = D(() => {
1105
+ const u = {};
1106
+ for (const d of a)
1107
+ u[d.name] = (n == null ? void 0 : n[d.name]) ?? d.defaultValue ?? "";
1108
+ return u;
1109
+ }), l = (u, d) => {
1110
+ s || o((m) => ({ ...m, [u]: d }));
1111
+ }, c = !s && a.every((u) => !u.required || i[u.name]), f = () => {
1112
+ c && r({ action: "submit", value: i });
932
1113
  };
933
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
934
- /* @__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 })
1114
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-card", children: [
1115
+ /* @__PURE__ */ p("div", { className: "sa-interrupt-content", children: [
1116
+ /* @__PURE__ */ e(z, { name: "file-text", size: 16, color: "#6366f1" }),
1117
+ /* @__PURE__ */ e("span", { children: t.content })
937
1118
  ] }),
938
- /* @__PURE__ */ e("div", { className: "sa-interrupt-form", children: r.map((c) => /* @__PURE__ */ d("div", { className: "sa-interrupt-form-field", children: [
939
- /* @__PURE__ */ d("label", { className: "sa-interrupt-form-label", children: [
940
- c.label,
941
- c.required && /* @__PURE__ */ e("span", { className: "sa-interrupt-form-required", children: "*" })
1119
+ /* @__PURE__ */ e("div", { className: "sa-interrupt-form", children: a.map((u) => /* @__PURE__ */ p("div", { className: "sa-interrupt-form-field", children: [
1120
+ /* @__PURE__ */ p("label", { className: "sa-interrupt-form-label", children: [
1121
+ u.label,
1122
+ u.required && /* @__PURE__ */ e("span", { className: "sa-interrupt-form-required", children: "*" })
942
1123
  ] }),
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 }),
1124
+ Fe(u, i[u.name], (d) => l(u.name, d), s)
1125
+ ] }, u.name)) }),
1126
+ !s && /* @__PURE__ */ p("div", { className: "sa-interrupt-actions", children: [
1127
+ /* @__PURE__ */ p("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", disabled: !c, onClick: f, children: [
1128
+ /* @__PURE__ */ e(z, { name: "check", size: 14 }),
948
1129
  " 提交"
949
1130
  ] }),
950
- /* @__PURE__ */ e("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "cancel" }), children: "取消" })
951
- ] })
1131
+ /* @__PURE__ */ e("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => r({ action: "cancel" }), children: "取消" })
1132
+ ] }),
1133
+ s && /* @__PURE__ */ e("div", { className: "sa-interrupt-submitted", children: "已提交" })
952
1134
  ] });
953
1135
  }
954
- function Ae(a, t, r) {
955
- switch (a.type) {
1136
+ function Fe(t, r, s, n) {
1137
+ switch (t.type) {
956
1138
  case "textarea":
957
- return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: t, onChange: (s) => r(s.target.value), placeholder: a.placeholder, rows: 3 });
1139
+ return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: r, onChange: (a) => s(a.target.value), placeholder: t.placeholder, rows: 3, disabled: n });
958
1140
  case "select":
959
- return /* @__PURE__ */ d("select", { className: "sa-interrupt-select", value: t, onChange: (s) => r(s.target.value), children: [
1141
+ return /* @__PURE__ */ p("select", { className: "sa-interrupt-select", value: r, onChange: (a) => s(a.target.value), disabled: n, children: [
960
1142
  /* @__PURE__ */ e("option", { value: "", children: "请选择" }),
961
- (a.options ?? []).map((s) => /* @__PURE__ */ e("option", { value: s, children: s }, s))
1143
+ (t.options ?? []).map((a) => /* @__PURE__ */ e("option", { value: a, children: a }, a))
962
1144
  ] });
963
1145
  default:
964
- return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: a.type, value: t, onChange: (s) => r(s.target.value), placeholder: a.placeholder });
1146
+ return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: t.type, value: r, onChange: (a) => s(a.target.value), placeholder: t.placeholder, disabled: n });
965
1147
  }
966
1148
  }
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) {
1149
+ function We({ interrupt: t, resolved: r, response: s, onRespond: n }) {
1150
+ const a = r, i = s == null ? void 0 : s.value;
1151
+ switch (t.interruptType) {
974
1152
  case "confirm":
975
- return /* @__PURE__ */ e(ze, { interrupt: a, onRespond: s });
1153
+ return /* @__PURE__ */ e(Ae, { interrupt: t, onRespond: n, disabled: a, answeredAction: s == null ? void 0 : s.action });
976
1154
  case "approve":
977
- return /* @__PURE__ */ e(Ie, { interrupt: a, onRespond: s });
1155
+ return /* @__PURE__ */ e(Re, { interrupt: t, onRespond: n, disabled: a, answeredAction: s == null ? void 0 : s.action });
978
1156
  case "select":
979
- return /* @__PURE__ */ e(Se, { interrupt: a, onRespond: s });
1157
+ return /* @__PURE__ */ e(Pe, { interrupt: t, onRespond: n, disabled: a, initialValue: i });
980
1158
  case "multiSelect":
981
- return /* @__PURE__ */ e(Le, { interrupt: a, onRespond: s });
1159
+ return /* @__PURE__ */ e(Be, { interrupt: t, onRespond: n, disabled: a, initialValue: i });
982
1160
  case "input":
983
- return /* @__PURE__ */ e(De, { interrupt: a, onRespond: s });
1161
+ return /* @__PURE__ */ e(je, { interrupt: t, onRespond: n, disabled: a, initialValue: i });
984
1162
  case "form":
985
- return /* @__PURE__ */ e(Ee, { interrupt: a, onRespond: s });
1163
+ return /* @__PURE__ */ e(_e, { interrupt: t, onRespond: n, disabled: a, initialValue: i });
986
1164
  default:
987
- return /* @__PURE__ */ d("div", { className: "sa-interrupt-unknown", children: [
1165
+ return /* @__PURE__ */ p("div", { className: "sa-interrupt-unknown", children: [
988
1166
  "未知的交互类型: ",
989
- a.interruptType
1167
+ t.interruptType
990
1168
  ] });
991
1169
  }
992
1170
  }
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 = [
1171
+ const Ke = [
1015
1172
  { value: 1, label: "事实错误" },
1016
1173
  { value: 2, label: "逻辑问题" },
1017
1174
  { value: 3, label: "不相关" },
@@ -1019,78 +1176,78 @@ const Oe = [
1019
1176
  { value: 5, label: "冗长啰嗦" },
1020
1177
  { value: 6, label: "难以理解" }
1021
1178
  ];
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);
1179
+ function Ye({ message: t, onCopy: r, onRegenerate: s, onFeedback: n }) {
1180
+ const { status: a, cancelFeedback: i } = U(), [o, l] = D(null), [c, f] = D(!1), [u, d] = D(!1), m = O(null), g = N(() => {
1181
+ r(), f(!0), setTimeout(() => f(!1), 2e3);
1182
+ }, [r]), x = N(() => {
1183
+ o === "like" ? (l(null), i(t.id)) : (l("like"), d(!1), n == null || n(t.id, "like"));
1184
+ }, [o, t.id, n, i]), w = N(() => {
1185
+ o === "dislike" ? (l(null), d(!1), i(t.id)) : d(!0);
1186
+ }, [o, t.id, i]), T = N((E, k) => {
1187
+ l("dislike"), d(!1), n == null || n(t.id, "dislike", { reason: E, remark: (k == null ? void 0 : k.trim()) || void 0 });
1188
+ }, [t.id, n]), L = N(() => {
1189
+ d(!1);
1035
1190
  }, []);
1036
- return R(() => {
1037
- 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);
1191
+ return B(() => {
1192
+ if (!u) return;
1193
+ const E = (h) => {
1194
+ m.current && !m.current.contains(h.target) && d(!1);
1195
+ }, k = (h) => {
1196
+ h.key === "Escape" && d(!1);
1042
1197
  };
1043
- return document.addEventListener("mousedown", g), document.addEventListener("keydown", N), () => {
1044
- document.removeEventListener("mousedown", g), document.removeEventListener("keydown", N);
1198
+ return document.addEventListener("mousedown", E), document.addEventListener("keydown", k), () => {
1199
+ document.removeEventListener("mousedown", E), document.removeEventListener("keydown", k);
1045
1200
  };
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 }),
1201
+ }, [u]), a !== "ready" && a !== "error" ? null : /* @__PURE__ */ p("div", { className: "sa-action-bar", children: [
1202
+ /* @__PURE__ */ p("button", { className: "sa-action-btn", onClick: g, title: "复制", children: [
1203
+ /* @__PURE__ */ e(z, { name: c ? "circle-check" : "copy", size: 14 }),
1049
1204
  " ",
1050
1205
  c ? "已复制" : "复制"
1051
1206
  ] }),
1052
- /* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: r, title: "重新生成", children: [
1053
- /* @__PURE__ */ e(C, { name: "refresh-cw", size: 14 }),
1207
+ s && /* @__PURE__ */ p("button", { className: "sa-action-btn", onClick: s, title: "重新生成", children: [
1208
+ /* @__PURE__ */ e(z, { name: "refresh-cw", size: 14 }),
1054
1209
  " 重新生成"
1055
1210
  ] }),
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 }) })
1211
+ n && /* @__PURE__ */ p(J, { children: [
1212
+ /* @__PURE__ */ e("span", { className: "sa-action-divider" }),
1213
+ /* @__PURE__ */ e(
1214
+ "button",
1215
+ {
1216
+ className: `sa-action-btn ${o === "like" ? "sa-action-btn-active" : ""}`,
1217
+ onClick: x,
1218
+ title: "有用",
1219
+ "aria-label": "点赞",
1220
+ children: /* @__PURE__ */ e(z, { name: "thumbs-up", size: 14 })
1221
+ }
1222
+ ),
1223
+ /* @__PURE__ */ e(
1224
+ "button",
1225
+ {
1226
+ className: `sa-action-btn ${o === "dislike" ? "sa-action-btn-active" : ""}`,
1227
+ onClick: w,
1228
+ title: "无用",
1229
+ "aria-label": "踩",
1230
+ "aria-expanded": u,
1231
+ "aria-haspopup": "dialog",
1232
+ children: /* @__PURE__ */ e(z, { name: "thumbs-down", size: 14 })
1233
+ }
1234
+ )
1235
+ ] }),
1236
+ u && /* @__PURE__ */ e("div", { ref: m, children: /* @__PURE__ */ e(Ue, { onSubmit: T, onCancel: L }) })
1080
1237
  ] });
1081
1238
  }
1082
- function Be({ onSubmit: a, onCancel: t }) {
1083
- const [r, s] = T(void 0), [n, o] = T("");
1084
- return /* @__PURE__ */ d("div", { className: "sa-dislike-panel", children: [
1239
+ function Ue({ onSubmit: t, onCancel: r }) {
1240
+ const [s, n] = D(void 0), [a, i] = D("");
1241
+ return /* @__PURE__ */ p("div", { className: "sa-dislike-panel", children: [
1085
1242
  /* @__PURE__ */ e("div", { className: "sa-dislike-panel-title", children: "请选择不满意的原因(可选)" }),
1086
- /* @__PURE__ */ e("div", { className: "sa-dislike-reasons", children: Oe.map((i) => /* @__PURE__ */ e(
1243
+ /* @__PURE__ */ e("div", { className: "sa-dislike-reasons", children: Ke.map((o) => /* @__PURE__ */ e(
1087
1244
  "button",
1088
1245
  {
1089
- className: `sa-dislike-reason-btn ${r === i.value ? "active" : ""}`,
1090
- onClick: () => s(r === i.value ? void 0 : i.value),
1091
- children: i.label
1246
+ className: `sa-dislike-reason-btn ${s === o.value ? "active" : ""}`,
1247
+ onClick: () => n(s === o.value ? void 0 : o.value),
1248
+ children: o.label
1092
1249
  },
1093
- i.value
1250
+ o.value
1094
1251
  )) }),
1095
1252
  /* @__PURE__ */ e(
1096
1253
  "textarea",
@@ -1098,492 +1255,723 @@ function Be({ onSubmit: a, onCancel: t }) {
1098
1255
  className: "sa-dislike-remark",
1099
1256
  placeholder: "补充描述(选填,≤500 字)",
1100
1257
  maxLength: 500,
1101
- value: n,
1102
- onChange: (i) => o(i.target.value),
1258
+ value: a,
1259
+ onChange: (o) => i(o.target.value),
1103
1260
  rows: 2
1104
1261
  }
1105
1262
  ),
1106
- /* @__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: "取消" })
1263
+ /* @__PURE__ */ p("div", { className: "sa-dislike-actions", children: [
1264
+ /* @__PURE__ */ e("button", { className: "sa-dislike-submit", onClick: () => t(s, a || void 0), children: "提交" }),
1265
+ /* @__PURE__ */ e("button", { className: "sa-dislike-cancel", onClick: r, children: "取消" })
1109
1266
  ] })
1110
1267
  ] });
1111
1268
  }
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 });
1269
+ function se({ src: t, role: r }) {
1270
+ const s = r === "assistant" ? "A" : "U";
1271
+ return t ? t.startsWith("http") || t.startsWith("/") || t.startsWith("data:") ? /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${r}`, children: /* @__PURE__ */ e("img", { src: t, alt: r, style: { width: "100%", height: "100%", borderRadius: "inherit", objectFit: "cover" } }) }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${r}`, children: t }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${r}`, children: s });
1115
1272
  }
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(`
1273
+ function qe({ message: t, isStreaming: r, isLast: s, slots: n, avatar: a, artifactPreview: i }) {
1274
+ const { regenerate: o, feedback: l, respondToInterrupt: c } = U(), f = N(() => {
1275
+ var M;
1276
+ const h = t.parts.filter((y) => y.type === "text").map((y) => y.content).join(`
1120
1277
  `);
1121
- (N = navigator.clipboard) == null || N.writeText(g).catch(() => {
1278
+ (M = navigator.clipboard) == null || M.writeText(h).catch(() => {
1122
1279
  });
1123
- }, [a]), f = a.role === "user", u = s.Message;
1124
- if (u)
1280
+ }, [t]), u = t.role === "user", d = n.Message;
1281
+ if (d)
1125
1282
  return /* @__PURE__ */ e(
1126
- u,
1283
+ d,
1127
1284
  {
1128
- message: a,
1129
- isStreaming: t,
1130
- isLast: r,
1131
- avatar: n,
1132
- slots: s,
1133
- onCopy: p,
1134
- onRegenerate: i,
1285
+ message: t,
1286
+ isStreaming: r,
1287
+ isLast: s,
1288
+ avatar: a,
1289
+ slots: n,
1290
+ onCopy: f,
1291
+ onRegenerate: o,
1135
1292
  onFeedback: l
1136
1293
  }
1137
1294
  );
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,
1157
- {
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 })
1295
+ const m = n.TextPart ?? Te, g = n.ThinkingPart ?? Me, x = n.ToolCallPart ?? De, w = n.ToolResultPart ?? Ee, T = n.ErrorPart ?? Le, L = n.ActionBar ?? Ye, E = !u && t.parts.some((h) => h.type === "text" && h.content), k = !t.id.startsWith("assistant_") && !t.id.startsWith("user_");
1296
+ return /* @__PURE__ */ p("div", { className: `sa-message ${u ? "sa-message-user" : "sa-message-assistant"}`, children: [
1297
+ !u && /* @__PURE__ */ e(se, { src: a == null ? void 0 : a.assistant, role: "assistant" }),
1298
+ /* @__PURE__ */ p("div", { className: "sa-message-content", children: [
1299
+ /* @__PURE__ */ e("span", { className: `sa-message-time ${u ? "sa-message-time-right" : ""}`, children: ce(t.timestamp) }),
1300
+ /* @__PURE__ */ p("div", { className: "sa-message-body", children: [
1301
+ t.parts.map((h, M) => {
1302
+ switch (h.type) {
1303
+ case "text":
1304
+ return /* @__PURE__ */ e(m, { content: h.content }, M);
1305
+ case "thinking":
1306
+ return /* @__PURE__ */ e(g, { content: h.content }, M);
1307
+ case "tool_call":
1308
+ return /* @__PURE__ */ e(x, { toolName: h.toolName, toolCallId: h.toolCallId, args: h.args }, M);
1309
+ case "tool_result":
1310
+ return /* @__PURE__ */ e(w, { toolName: h.toolName, toolCallId: h.toolCallId, content: h.content, artifacts: h.artifacts, renderMode: h.renderMode, html: h.html, artifactPreview: i }, M);
1311
+ case "error":
1312
+ return /* @__PURE__ */ e(T, { content: h.content, onRetry: o }, M);
1313
+ case "interrupt":
1314
+ return /* @__PURE__ */ e(
1315
+ We,
1316
+ {
1317
+ interrupt: h.interrupt,
1318
+ resolved: h.resolved ?? !1,
1319
+ response: h.response,
1320
+ onRespond: (y) => c(h.interrupt.interruptId, y)
1321
+ },
1322
+ M
1323
+ );
1324
+ default:
1325
+ return null;
1326
+ }
1327
+ }),
1328
+ r && s && !u && /* @__PURE__ */ e("span", { className: "sa-streaming-cursor", children: "|" }),
1329
+ !u && !r && E && /* @__PURE__ */ e(L, { message: t, onCopy: f, onRegenerate: s ? o : void 0, onFeedback: k ? l : void 0 })
1330
+ ] })
1171
1331
  ] }),
1172
- f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.user, role: "user" })
1332
+ u && /* @__PURE__ */ e(se, { src: a == null ? void 0 : a.user, role: "user" })
1173
1333
  ] });
1174
1334
  }
1175
- function He({ message: a, suggestedPrompts: t, onPromptClick: r }) {
1176
- 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(
1335
+ function Ve({ message: t, suggestedPrompts: r, onPromptClick: s }) {
1336
+ return /* @__PURE__ */ p("div", { className: "sa-welcome", children: [
1337
+ /* @__PURE__ */ e("div", { className: "sa-welcome-icon", children: /* @__PURE__ */ e(z, { name: "sparkles", size: 40 }) }),
1338
+ /* @__PURE__ */ e("p", { className: "sa-welcome-message", children: t || "你好!有什么可以帮你的?" }),
1339
+ r && r.length > 0 && /* @__PURE__ */ e("div", { className: "sa-welcome-prompts", children: r.map((n, a) => /* @__PURE__ */ e(
1180
1340
  "button",
1181
1341
  {
1182
1342
  className: "sa-welcome-prompt",
1183
- onClick: () => r(s),
1184
- children: s
1343
+ onClick: () => s(n),
1344
+ children: n
1185
1345
  },
1186
- n
1346
+ a
1187
1347
  )) })
1188
1348
  ] });
1189
1349
  }
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(
1193
- f,
1350
+ function de({ slots: t, welcomeMessage: r, suggestedPrompts: s, avatar: n, artifactPreview: a }) {
1351
+ const { messages: i, status: o, sendMessage: l } = U(), { containerRef: c } = ze([i]), f = o === "streaming", u = t.WelcomeScreen ?? Ve;
1352
+ return i.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: /* @__PURE__ */ e(
1353
+ u,
1194
1354
  {
1195
- message: t,
1196
- suggestedPrompts: r,
1355
+ message: r,
1356
+ suggestedPrompts: s,
1197
1357
  onPromptClick: l
1198
1358
  }
1199
- ) }) : /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: o.map((u, h) => /* @__PURE__ */ e(
1200
- Fe,
1359
+ ) }) : /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: i.map((d, m) => /* @__PURE__ */ e(
1360
+ qe,
1201
1361
  {
1202
- message: u,
1203
- isStreaming: p,
1204
- isLast: h === o.length - 1,
1205
- slots: a,
1206
- avatar: s,
1207
- artifactPreview: n
1362
+ message: d,
1363
+ isStreaming: f,
1364
+ isLast: m === i.length - 1,
1365
+ slots: t,
1366
+ avatar: n,
1367
+ artifactPreview: a
1208
1368
  },
1209
- u.id
1369
+ d.id
1210
1370
  )) });
1211
1371
  }
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";
1372
+ function Xe({ items: t, activeIndex: r, onSelect: s }) {
1373
+ const n = O(null);
1374
+ return B(() => {
1375
+ var i;
1376
+ const a = (i = n.current) == null ? void 0 : i.children[r];
1377
+ a == null || a.scrollIntoView({ block: "nearest" });
1378
+ }, [r]), 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((a, i) => /* @__PURE__ */ p(
1379
+ "div",
1380
+ {
1381
+ className: `sa-slash-menu-item${i === r ? " sa-slash-menu-item--active" : ""}`,
1382
+ onMouseDown: (o) => {
1383
+ o.preventDefault(), s(a);
1384
+ },
1385
+ children: [
1386
+ /* @__PURE__ */ p("span", { className: "sa-slash-menu-item-name", children: [
1387
+ "/",
1388
+ a.name
1389
+ ] }),
1390
+ (a.displayName || a.description) && /* @__PURE__ */ e("span", { className: "sa-slash-menu-item-desc", children: a.displayName || a.description })
1391
+ ]
1392
+ },
1393
+ a.code
1394
+ )) });
1395
+ }
1396
+ function Ge({ sdk: t, input: r, onSelect: s }) {
1397
+ const [n, a] = D([]), [i, o] = D(!1), [l, c] = D(0), f = O(!1);
1398
+ B(() => {
1399
+ f.current || (f.current = !0, t.listSkills().then(a).catch(() => a([])));
1400
+ }, [t]);
1401
+ const u = /^\/\S*$/.test(r);
1402
+ B(() => {
1403
+ o(u);
1404
+ }, [u]), B(() => {
1405
+ u && c(0);
1406
+ }, [r, u]);
1407
+ const d = r.startsWith("/") ? r.slice(1).toLowerCase() : "", m = G(
1408
+ () => n.filter(
1409
+ (k) => !d || k.code.toLowerCase().includes(d) || k.name.toLowerCase().includes(d) || k.displayName && k.displayName.toLowerCase().includes(d)
1410
+ ),
1411
+ [n, d]
1412
+ ), g = O(i), x = O(m), w = O(l), T = O(s);
1413
+ g.current = i, x.current = m, w.current = l, T.current = s;
1414
+ const L = N((k) => {
1415
+ if (!g.current || x.current.length === 0) return !1;
1416
+ switch (k.key) {
1417
+ case "ArrowDown":
1418
+ return k.preventDefault(), c((h) => (h + 1) % x.current.length), !0;
1419
+ case "ArrowUp":
1420
+ return k.preventDefault(), c((h) => (h - 1 + x.current.length) % x.current.length), !0;
1421
+ case "Enter":
1422
+ case "Tab":
1423
+ return k.preventDefault(), T.current(x.current[w.current]), o(!1), !0;
1424
+ case "Escape":
1425
+ return k.preventDefault(), o(!1), !0;
1426
+ default:
1427
+ return !1;
1428
+ }
1429
+ }, []), E = N(() => o(!1), []);
1430
+ return { isOpen: i, items: m, activeIndex: l, handleKeyDown: L, close: E };
1431
+ }
1432
+ function pe() {
1433
+ const { status: t, sendMessage: r, stop: s, sdk: n } = U(), [a, i] = D(""), o = O(null), l = t === "streaming" || t === "submitted", c = N((g) => {
1434
+ i(`/${g.name} `), setTimeout(() => {
1435
+ const x = o.current;
1436
+ x && (x.focus(), x.selectionStart = x.selectionEnd = x.value.length);
1437
+ }, 0);
1438
+ }, []), f = Ge({
1439
+ sdk: n,
1440
+ input: a,
1441
+ onSelect: c
1442
+ }), u = N(() => {
1443
+ const g = a.trim();
1444
+ !g || l || (r(g), i(""), o.current && (o.current.style.height = "auto"));
1445
+ }, [a, l, r]), d = N((g) => {
1446
+ f.handleKeyDown(g) || g.key === "Enter" && !g.shiftKey && (g.preventDefault(), u());
1447
+ }, [u, f.handleKeyDown]), m = N((g) => {
1448
+ i(g.target.value);
1449
+ const x = g.target;
1450
+ x.style.height = "auto", x.style.height = Math.min(x.scrollHeight, 120) + "px";
1222
1451
  }, []);
1223
- return /* @__PURE__ */ d("div", { className: "sa-composer", children: [
1452
+ return /* @__PURE__ */ p("div", { className: "sa-composer", children: [
1453
+ f.isOpen && /* @__PURE__ */ e(
1454
+ Xe,
1455
+ {
1456
+ items: f.items,
1457
+ activeIndex: f.activeIndex,
1458
+ onSelect: c
1459
+ }
1460
+ ),
1224
1461
  /* @__PURE__ */ e(
1225
1462
  "textarea",
1226
1463
  {
1227
1464
  ref: o,
1228
1465
  className: "sa-composer-input",
1229
- value: s,
1230
- onChange: p,
1231
- onKeyDown: c,
1232
- placeholder: "输入消息...",
1466
+ value: a,
1467
+ onChange: m,
1468
+ onKeyDown: d,
1469
+ placeholder: "输入消息,按 / 选择技能...",
1233
1470
  rows: 1,
1234
- disabled: a === "submitted"
1471
+ disabled: t === "submitted"
1235
1472
  }
1236
1473
  ),
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(
1474
+ l ? /* @__PURE__ */ e("button", { className: "sa-composer-stop", onClick: s, title: "停止", children: /* @__PURE__ */ e(z, { name: "circle-stop", size: 16, color: "#fff" }) }) : /* @__PURE__ */ e(
1238
1475
  "button",
1239
1476
  {
1240
1477
  className: "sa-composer-send",
1241
- onClick: l,
1242
- disabled: !s.trim(),
1478
+ onClick: u,
1479
+ disabled: !a.trim(),
1243
1480
  title: "发送",
1244
- children: /* @__PURE__ */ e(C, { name: "arrow-up", size: 16, color: "#fff" })
1481
+ children: /* @__PURE__ */ e(z, { name: "arrow-up", size: 16, color: "#fff" })
1245
1482
  }
1246
1483
  )
1247
1484
  ] });
1248
1485
  }
1249
- function je({ artifact: a }) {
1250
- const [t, r] = Y.useState(null), [s, n] = Y.useState(!0), [o, i] = Y.useState(null);
1486
+ function Je({ artifact: t }) {
1487
+ const [r, s] = Y.useState(null), [n, a] = Y.useState(!0), [i, o] = Y.useState(null);
1251
1488
  return Y.useEffect(() => {
1252
1489
  let l = !1;
1253
- n(!0), i(null), r(null);
1490
+ a(!0), o(null), s(null);
1254
1491
  async function c() {
1255
1492
  try {
1256
- if (a.type === "pdf") {
1257
- l || n(!1);
1493
+ if (t.type === "pdf") {
1494
+ l || a(!1);
1258
1495
  return;
1259
1496
  }
1260
- if (a.type === "html") {
1261
- const p = await fetch(a.url);
1262
- 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));
1497
+ if (t.type === "html") {
1498
+ const f = await fetch(t.url);
1499
+ if (!f.ok) throw new Error(`HTTP ${f.status}`);
1500
+ const u = await f.text(), d = (await import("./purify.es-C-6FFqDW.js")).default;
1501
+ l || (s(d.sanitize(u, { FORCE_BODY: !0, ADD_ATTR: ["target"] })), a(!1));
1265
1502
  return;
1266
1503
  }
1267
- if (a.type === "docx") {
1268
- const p = await fetch(a.url);
1269
- 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));
1504
+ if (t.type === "docx") {
1505
+ const f = await fetch(t.url);
1506
+ if (!f.ok) throw new Error(`HTTP ${f.status}`);
1507
+ const u = await f.arrayBuffer(), m = await (await import("./mammoth.browser-COPV53yV.js").then((x) => x.m)).convertToHtml({ arrayBuffer: u }), g = (await import("./purify.es-C-6FFqDW.js")).default;
1508
+ l || (s(g.sanitize(m.value, { FORCE_BODY: !0, ADD_ATTR: ["target"] })), a(!1));
1272
1509
  return;
1273
1510
  }
1274
- l || (n(!1), i(`不支持预览「${a.type}」类型`));
1275
- } catch (p) {
1276
- l || (n(!1), i(p instanceof Error ? p.message : "加载失败"));
1511
+ l || (a(!1), o(`不支持预览「${t.type}」类型`));
1512
+ } catch (f) {
1513
+ l || (a(!1), o(f instanceof Error ? f.message : "加载失败"));
1277
1514
  }
1278
1515
  }
1279
1516
  return c(), () => {
1280
1517
  l = !0;
1281
1518
  };
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;
1519
+ }, [t]), n ? /* @__PURE__ */ e("div", { className: "sa-drawer-preview-loading", children: "加载中" }) : i ? /* @__PURE__ */ p("div", { className: "sa-drawer-preview-error", children: [
1520
+ i,
1521
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn-sm", onClick: () => void Z(t), children: "下载查看" })
1522
+ ] }) : t.type === "pdf" ? /* @__PURE__ */ e("iframe", { src: t.url, title: t.filename, className: "sa-drawer-preview-iframe", sandbox: "allow-scripts" }) : r !== null ? /* @__PURE__ */ e("iframe", { srcDoc: r, title: t.filename, className: "sa-drawer-preview-iframe", sandbox: "allow-same-origin" }) : null;
1286
1523
  }
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();
1297
- }, 240);
1524
+ function fe({ artifacts: t, initialArtifact: r, onClose: s }) {
1525
+ const [n, a] = D(
1526
+ r ? { mode: "preview", artifact: r } : { mode: "list" }
1527
+ ), [i, o] = D(!1), l = O(null), [c, f] = D(340), u = O(null);
1528
+ B(() => {
1529
+ r && (l.current && (clearTimeout(l.current), l.current = null, o(!1)), a({ mode: "preview", artifact: r }));
1298
1530
  }, [r]);
1299
- R(() => () => {
1300
- var b;
1301
- l.current && clearTimeout(l.current), (b = f.current) == null || b.call(f);
1531
+ const d = N(() => {
1532
+ o(!0), l.current = setTimeout(() => {
1533
+ l.current = null, s();
1534
+ }, 240);
1535
+ }, [s]);
1536
+ B(() => () => {
1537
+ var w;
1538
+ l.current && clearTimeout(l.current), (w = u.current) == null || w.call(u);
1302
1539
  }, []);
1303
- const h = I((b) => {
1304
- n({ mode: "preview", artifact: b });
1305
- }, []), w = I(() => {
1306
- n({ mode: "list" });
1540
+ const m = N((w) => {
1541
+ a({ mode: "preview", artifact: w });
1542
+ }, []), g = N(() => {
1543
+ a({ mode: "list" });
1307
1544
  }, []);
1308
- R(() => {
1309
- const b = (v) => {
1310
- v.key === "Escape" && u();
1545
+ B(() => {
1546
+ const w = (T) => {
1547
+ T.key === "Escape" && d();
1311
1548
  };
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;
1549
+ return document.addEventListener("keydown", w), () => document.removeEventListener("keydown", w);
1550
+ }, [d]);
1551
+ const x = N((w) => {
1552
+ w.preventDefault();
1553
+ const T = w.clientX, L = c, E = (h) => {
1554
+ const M = T - h.clientX;
1555
+ f(Math.max(240, Math.min(window.innerWidth * 0.7, L + M)));
1556
+ }, k = () => {
1557
+ document.removeEventListener("mousemove", E), document.removeEventListener("mouseup", k), document.body.style.cursor = "", document.body.style.userSelect = "", u.current = null;
1321
1558
  };
1322
- document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", g), document.addEventListener("mouseup", N), f.current = N;
1559
+ document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", E), document.addEventListener("mouseup", k), u.current = k;
1323
1560
  }, [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 }),
1326
- /* @__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 })
1330
- ] }) : /* @__PURE__ */ d(q, { children: [
1331
- /* @__PURE__ */ d("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { flexShrink: 0 }, children: [
1561
+ return /* @__PURE__ */ p("div", { className: `sa-artifact-drawer ${i ? "sa-drawer-closing" : ""}`, style: { width: c }, children: [
1562
+ /* @__PURE__ */ e("div", { className: "sa-drawer-resize-handle", onMouseDown: x }),
1563
+ /* @__PURE__ */ p("div", { className: "sa-artifact-drawer-header", children: [
1564
+ n.mode === "preview" ? /* @__PURE__ */ p(J, { children: [
1565
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: g, 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" }) }) }),
1566
+ /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: n.artifact.filename })
1567
+ ] }) : /* @__PURE__ */ p(J, { children: [
1568
+ /* @__PURE__ */ p("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { flexShrink: 0 }, children: [
1332
1569
  /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
1333
1570
  /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
1334
1571
  ] }),
1335
1572
  /* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: "会话产物" })
1336
1573
  ] }),
1337
1574
  /* @__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" }) }) })
1575
+ 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" }) }) }),
1576
+ /* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick: d, 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
1577
  ] }),
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(
1578
+ /* @__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((w, T) => /* @__PURE__ */ p(
1342
1579
  "li",
1343
1580
  {
1344
1581
  className: "sa-drawer-file-card",
1345
- onClick: () => h(b),
1346
- onKeyDown: (m) => {
1347
- (m.key === "Enter" || m.key === " ") && (m.preventDefault(), h(b));
1582
+ onClick: () => m(w),
1583
+ onKeyDown: (L) => {
1584
+ (L.key === "Enter" || L.key === " ") && (L.preventDefault(), m(w));
1348
1585
  },
1349
1586
  tabIndex: 0,
1350
1587
  role: "button",
1351
- "aria-label": `预览 ${b.filename}`,
1588
+ "aria-label": `预览 ${w.filename}`,
1352
1589
  children: [
1353
- /* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(b.type) }) }),
1354
- /* @__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) })
1590
+ /* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ie(w.type) }) }),
1591
+ /* @__PURE__ */ p("div", { className: "sa-drawer-file-info", children: [
1592
+ /* @__PURE__ */ e("span", { className: "sa-drawer-file-name", children: w.filename }),
1593
+ /* @__PURE__ */ e("span", { className: "sa-drawer-file-size", children: ne(w.size) })
1357
1594
  ] }),
1358
1595
  /* @__PURE__ */ e(
1359
1596
  "button",
1360
1597
  {
1361
1598
  className: "sa-drawer-btn",
1362
1599
  title: "下载",
1363
- "aria-label": `下载 ${b.filename}`,
1364
- onClick: (m) => {
1365
- m.stopPropagation(), U(b);
1600
+ "aria-label": `下载 ${w.filename}`,
1601
+ onClick: (L) => {
1602
+ L.stopPropagation(), Z(w);
1366
1603
  },
1367
1604
  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
1605
  }
1369
1606
  )
1370
1607
  ]
1371
1608
  },
1372
- b.id || `artifact-${v}`
1373
- )) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(je, { artifact: s.artifact }) }) })
1609
+ w.id || `artifact-${T}`
1610
+ )) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(Je, { artifact: n.artifact }) }) })
1374
1611
  ] });
1375
1612
  }
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;
1380
- return /* @__PURE__ */ d("div", { className: "sa-panel", children: [
1381
- y ? /* @__PURE__ */ e(y, { title: r, onClose: t, onToggleThreadList: u }) : /* @__PURE__ */ e(
1382
- ue,
1613
+ function Ze({ isOpen: t, onClose: r, title: s, slots: n, welcomeMessage: a, suggestedPrompts: i, avatar: o, artifactPreview: l }) {
1614
+ const { status: c, sendMessage: f, stop: u, toggleThreadList: d, toggleArtifactDrawer: m, conversations: g, activeConversationId: x, switchConversation: w, newConversation: T, deleteConversation: L, renameConversation: E, isThreadListOpen: k, isArtifactDrawerOpen: h, allArtifacts: M, activePreviewArtifact: y } = U();
1615
+ if (!t) return null;
1616
+ const b = n.Header, v = n.Composer, C = n.ThreadList;
1617
+ return /* @__PURE__ */ p("div", { className: "sa-panel", children: [
1618
+ b ? /* @__PURE__ */ e(b, { title: s, onClose: r, onToggleThreadList: d }) : /* @__PURE__ */ e(
1619
+ ke,
1383
1620
  {
1384
- title: r,
1385
- onClose: t,
1386
- onToggleThreadList: u,
1387
- artifactCount: l ? L.length : 0,
1388
- onToggleArtifactDrawer: l ? h : void 0
1621
+ title: s,
1622
+ onClose: r,
1623
+ onToggleThreadList: d,
1624
+ artifactCount: l ? M.length : 0,
1625
+ onToggleArtifactDrawer: l ? m : void 0
1389
1626
  }
1390
1627
  ),
1391
- P && N ? /* @__PURE__ */ e(
1392
- P,
1628
+ C && k ? /* @__PURE__ */ e(
1629
+ C,
1393
1630
  {
1394
- conversations: w,
1395
- activeSessionId: k,
1396
- onSwitch: b,
1397
- onNew: v,
1398
- onDelete: m,
1399
- onRename: g
1631
+ conversations: g,
1632
+ activeSessionId: x,
1633
+ onSwitch: w,
1634
+ onNew: T,
1635
+ onDelete: L,
1636
+ onRename: E
1400
1637
  }
1401
- ) : /* @__PURE__ */ e(he, {}),
1402
- /* @__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 })
1638
+ ) : /* @__PURE__ */ e(Ce, {}),
1639
+ /* @__PURE__ */ p("div", { className: "sa-panel-content", children: [
1640
+ /* @__PURE__ */ e(de, { slots: n, welcomeMessage: a, suggestedPrompts: i, avatar: o, artifactPreview: l }),
1641
+ l && h && /* @__PURE__ */ e(fe, { artifacts: M, initialArtifact: y, onClose: m })
1405
1642
  ] }),
1406
- D ? /* @__PURE__ */ e(D, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
1643
+ v ? /* @__PURE__ */ e(v, { status: c, onSend: f, onStop: u }) : /* @__PURE__ */ e(pe, {})
1407
1644
  ] });
1408
1645
  }
1409
- function We({
1410
- conversations: a,
1411
- activeSessionId: t,
1412
- onSwitch: r,
1413
- onNew: s,
1414
- onDelete: n,
1646
+ function Qe({
1647
+ conversations: t,
1648
+ activeSessionId: r,
1649
+ onSwitch: s,
1650
+ onNew: n,
1651
+ onDelete: a,
1652
+ onRename: i,
1415
1653
  isCollapsed: o,
1416
- onToggleCollapse: i
1654
+ onToggleCollapse: l,
1655
+ hasMore: c,
1656
+ onLoadMore: f
1417
1657
  }) {
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);
1658
+ const [u, d] = D(null), [m, g] = D(null), [x, w] = D(null), [T, L] = D(""), E = N(
1659
+ (v, C) => {
1660
+ C.stopPropagation(), m === v ? (a(v), g(null)) : (g(v), setTimeout(() => g(null), 3e3));
1661
+ },
1662
+ [m, a]
1663
+ ), k = N(
1664
+ (v, C, P) => {
1665
+ P.stopPropagation(), w(v), L(C ?? "");
1666
+ },
1667
+ []
1668
+ ), h = N(
1669
+ (v) => {
1670
+ T.trim() && i(v, T.trim()), w(null);
1671
+ },
1672
+ [T, i]
1673
+ ), M = O(null), y = N(() => {
1674
+ const v = M.current;
1675
+ !v || !c || !f || v.scrollHeight - v.scrollTop - v.clientHeight < 50 && f();
1676
+ }, [c, f]), b = (() => {
1677
+ const v = Date.now(), C = [], P = [], R = [];
1678
+ for (const A of t) {
1679
+ const j = v - new Date(A.updateTime).getTime();
1680
+ j < 864e5 ? C.push(A) : j < 6048e5 ? P.push(A) : R.push(A);
1425
1681
  }
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;
1682
+ const S = [];
1683
+ return C.length && S.push({ label: "今天", items: C }), P.length && S.push({ label: "最近 7 天", items: P }), R.length && S.push({ label: "更早", items: R }), S;
1428
1684
  })();
1429
- 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 }) })
1432
- ] }) : /* @__PURE__ */ d("div", { className: "sa-fp-sidebar", children: [
1433
- /* @__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 }),
1685
+ return o ? /* @__PURE__ */ p("div", { className: "sa-fp-sidebar sa-fp-sidebar-collapsed", children: [
1686
+ /* @__PURE__ */ e(
1687
+ "button",
1688
+ {
1689
+ className: "sa-fp-sidebar-toggle",
1690
+ onClick: l,
1691
+ title: "展开",
1692
+ children: /* @__PURE__ */ e(z, { name: "panel-left", size: 18 })
1693
+ }
1694
+ ),
1695
+ /* @__PURE__ */ e(
1696
+ "button",
1697
+ {
1698
+ className: "sa-fp-sidebar-toggle",
1699
+ onClick: n,
1700
+ title: "新会话",
1701
+ style: { marginTop: 4 },
1702
+ children: /* @__PURE__ */ e(z, { name: "plus", size: 18 })
1703
+ }
1704
+ )
1705
+ ] }) : /* @__PURE__ */ p("div", { className: "sa-fp-sidebar", children: [
1706
+ /* @__PURE__ */ p("div", { className: "sa-fp-sidebar-header", children: [
1707
+ /* @__PURE__ */ p("button", { className: "sa-fp-sidebar-new", onClick: n, children: [
1708
+ /* @__PURE__ */ e(z, { name: "plus", size: 15 }),
1436
1709
  " ",
1437
1710
  /* @__PURE__ */ e("span", { children: "新会话" })
1438
1711
  ] }),
1439
- /* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: i, title: "收起侧边栏", children: /* @__PURE__ */ e(C, { name: "panel-left-close", size: 18 }) })
1712
+ /* @__PURE__ */ e(
1713
+ "button",
1714
+ {
1715
+ className: "sa-fp-sidebar-toggle",
1716
+ onClick: l,
1717
+ title: "收起侧边栏",
1718
+ children: /* @__PURE__ */ e(z, { name: "panel-left-close", size: 18 })
1719
+ }
1720
+ )
1440
1721
  ] }),
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;
1447
- return /* @__PURE__ */ d(
1722
+ /* @__PURE__ */ p("div", { className: "sa-fp-sidebar-list", ref: M, onScroll: y, children: [
1723
+ t.length === 0 && /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-empty", children: "开始你的第一个对话" }),
1724
+ b.map((v) => /* @__PURE__ */ p("div", { children: [
1725
+ /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-group", children: v.label }),
1726
+ v.items.map((C) => {
1727
+ const P = C.sessionId === r, R = u === C.sessionId, S = m === C.sessionId;
1728
+ return /* @__PURE__ */ p(
1448
1729
  "div",
1449
1730
  {
1450
- className: `sa-fp-sidebar-item ${b ? "active" : ""}`,
1451
- onClick: () => r(k.sessionId),
1452
- onMouseEnter: () => c(k.sessionId),
1453
- onMouseLeave: () => c(null),
1731
+ className: `sa-fp-sidebar-item ${P ? "active" : ""}`,
1732
+ onClick: () => {
1733
+ x !== C.sessionId && s(C.sessionId);
1734
+ },
1735
+ onMouseEnter: () => d(C.sessionId),
1736
+ onMouseLeave: () => d(null),
1454
1737
  children: [
1455
- /* @__PURE__ */ e("span", { className: "sa-fp-sidebar-item-title", children: k.title || "新会话" }),
1456
- v && /* @__PURE__ */ e(
1457
- "button",
1738
+ x === C.sessionId ? /* @__PURE__ */ e(
1739
+ "input",
1740
+ {
1741
+ className: "sa-fp-sidebar-item-edit",
1742
+ value: T,
1743
+ onChange: (A) => L(A.target.value),
1744
+ onBlur: () => h(C.sessionId),
1745
+ onKeyDown: (A) => {
1746
+ A.key === "Enter" && h(C.sessionId), A.key === "Escape" && w(null);
1747
+ },
1748
+ onClick: (A) => A.stopPropagation(),
1749
+ autoFocus: !0
1750
+ }
1751
+ ) : /* @__PURE__ */ e("span", { className: "sa-fp-sidebar-item-title", children: C.title || "新会话" }),
1752
+ /* @__PURE__ */ p(
1753
+ "div",
1458
1754
  {
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 })
1755
+ className: `sa-fp-sidebar-item-actions ${R && x !== C.sessionId ? "visible" : ""}`,
1756
+ children: [
1757
+ /* @__PURE__ */ e(
1758
+ "button",
1759
+ {
1760
+ className: "sa-fp-sidebar-item-action",
1761
+ onClick: (A) => k(C.sessionId, C.title, A),
1762
+ title: "重命名",
1763
+ children: /* @__PURE__ */ e(z, { name: "pen", size: 14 })
1764
+ }
1765
+ ),
1766
+ /* @__PURE__ */ e(
1767
+ "button",
1768
+ {
1769
+ className: `sa-fp-sidebar-item-action ${S ? "danger" : ""}`,
1770
+ onClick: (A) => E(C.sessionId, A),
1771
+ title: S ? "确认删除" : "删除",
1772
+ children: /* @__PURE__ */ e(z, { name: S ? "x" : "trash2", size: 14 })
1773
+ }
1774
+ )
1775
+ ]
1463
1776
  }
1464
1777
  )
1465
1778
  ]
1466
1779
  },
1467
- k.sessionId
1780
+ C.sessionId
1468
1781
  );
1469
1782
  })
1470
- ] }, w.label))
1783
+ ] }, v.label)),
1784
+ c && /* @__PURE__ */ e("div", { className: "sa-thread-list-loading", children: "加载更多..." })
1471
1785
  ] })
1472
1786
  ] });
1473
1787
  }
1474
- function Ye({ title: a, slots: t, welcomeMessage: r, suggestedPrompts: s, sidebarDefaultOpen: n = !0, onClose: o, avatar: i, artifactPreview: l }) {
1788
+ function et({
1789
+ title: t,
1790
+ slots: r,
1791
+ welcomeMessage: s,
1792
+ suggestedPrompts: n,
1793
+ sidebarDefaultOpen: a = !0,
1794
+ onClose: i,
1795
+ avatar: o,
1796
+ artifactPreview: l
1797
+ }) {
1475
1798
  const {
1476
1799
  status: c,
1477
- sendMessage: p,
1478
- 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;
1490
- 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,
1800
+ sendMessage: f,
1801
+ stop: u,
1802
+ conversations: d,
1803
+ activeConversationId: m,
1804
+ switchConversation: g,
1805
+ newConversation: x,
1806
+ deleteConversation: w,
1807
+ renameConversation: T,
1808
+ toggleArtifactDrawer: L,
1809
+ isArtifactDrawerOpen: E,
1810
+ allArtifacts: k,
1811
+ activePreviewArtifact: h,
1812
+ hasMore: M,
1813
+ loadMoreConversations: y
1814
+ } = U(), [b, v] = D(a), C = N(() => v((S) => !S), []), P = r.ThreadList, R = r.Composer;
1815
+ return /* @__PURE__ */ p("div", { className: "sa-fullpage", children: [
1816
+ P ? /* @__PURE__ */ e(
1817
+ "div",
1493
1818
  {
1494
- conversations: u,
1495
- activeSessionId: h,
1496
- onSwitch: w,
1497
- onNew: k,
1498
- onDelete: b,
1499
- onRename: v
1819
+ className: `sa-fp-sidebar-wrapper ${b ? "" : "sa-fp-sidebar-wrapper-collapsed"}`,
1820
+ children: /* @__PURE__ */ e(
1821
+ P,
1822
+ {
1823
+ conversations: d,
1824
+ activeSessionId: m,
1825
+ onSwitch: g,
1826
+ onNew: x,
1827
+ onDelete: w,
1828
+ onRename: T,
1829
+ hasMore: M,
1830
+ onLoadMore: y
1831
+ }
1832
+ )
1500
1833
  }
1501
- ) }) : /* @__PURE__ */ e(
1502
- We,
1834
+ ) : /* @__PURE__ */ e(
1835
+ Qe,
1503
1836
  {
1504
- conversations: u,
1505
- activeSessionId: h,
1506
- onSwitch: w,
1507
- onNew: k,
1508
- onDelete: b,
1509
- onRename: v,
1510
- isCollapsed: !L,
1511
- onToggleCollapse: y
1837
+ conversations: d,
1838
+ activeSessionId: m,
1839
+ onSwitch: g,
1840
+ onNew: x,
1841
+ onDelete: w,
1842
+ onRename: T,
1843
+ isCollapsed: !b,
1844
+ onToggleCollapse: C,
1845
+ hasMore: M,
1846
+ onLoadMore: y
1512
1847
  }
1513
1848
  ),
1514
- /* @__PURE__ */ d("div", { className: "sa-fp-main", children: [
1515
- /* @__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 }),
1518
- /* @__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 }) })
1849
+ /* @__PURE__ */ p("div", { className: "sa-fp-main", children: [
1850
+ /* @__PURE__ */ p("div", { className: "sa-fp-header", children: [
1851
+ !b && !P && /* @__PURE__ */ e(
1852
+ "button",
1853
+ {
1854
+ className: "sa-fp-header-btn",
1855
+ onClick: C,
1856
+ title: "展开侧边栏",
1857
+ children: /* @__PURE__ */ e(z, { name: "panel-left", size: 18 })
1858
+ }
1859
+ ),
1860
+ /* @__PURE__ */ e("div", { className: "sa-fp-header-title", children: t }),
1861
+ /* @__PURE__ */ p("div", { className: "sa-fp-header-actions", children: [
1862
+ l && k.length > 0 && /* @__PURE__ */ p(
1863
+ "button",
1864
+ {
1865
+ className: "sa-fp-header-btn sa-header-btn-artifact",
1866
+ onClick: L,
1867
+ title: "会话产物",
1868
+ children: [
1869
+ /* @__PURE__ */ p(
1870
+ "svg",
1871
+ {
1872
+ width: "14",
1873
+ height: "14",
1874
+ viewBox: "0 0 24 24",
1875
+ fill: "none",
1876
+ stroke: "currentColor",
1877
+ strokeWidth: "2",
1878
+ children: [
1879
+ /* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
1880
+ /* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
1881
+ ]
1882
+ }
1883
+ ),
1884
+ /* @__PURE__ */ e("span", { children: "产物" })
1885
+ ]
1886
+ }
1887
+ ),
1888
+ i && /* @__PURE__ */ e(
1889
+ "button",
1890
+ {
1891
+ className: "sa-fp-header-btn",
1892
+ onClick: i,
1893
+ title: "关闭",
1894
+ children: /* @__PURE__ */ e(z, { name: "x", size: 18 })
1895
+ }
1896
+ )
1527
1897
  ] })
1528
1898
  ] }),
1529
- /* @__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 })
1899
+ /* @__PURE__ */ p("div", { className: "sa-fp-content-row", children: [
1900
+ /* @__PURE__ */ e(
1901
+ de,
1902
+ {
1903
+ slots: r,
1904
+ welcomeMessage: s,
1905
+ suggestedPrompts: n,
1906
+ avatar: o,
1907
+ artifactPreview: l
1908
+ }
1909
+ ),
1910
+ l && E && /* @__PURE__ */ e(
1911
+ fe,
1912
+ {
1913
+ artifacts: k,
1914
+ initialArtifact: h,
1915
+ onClose: L
1916
+ }
1917
+ )
1532
1918
  ] }),
1533
- P ? /* @__PURE__ */ e(P, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
1919
+ R ? /* @__PURE__ */ e(R, { status: c, onSend: f, onStop: u }) : /* @__PURE__ */ e(pe, {})
1534
1920
  ] })
1535
1921
  ] });
1536
1922
  }
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);
1923
+ function tt(t) {
1924
+ const { sdk: r, mode: s = "floating", slots: n = {}, hooks: a = {}, welcomeMessage: i, suggestedPrompts: o, title: l = "AI Assistant", initialOpen: c = !1, onOpenChange: f, sidebarDefaultOpen: u, avatar: d, artifactPreview: m } = t, [g, x] = D(c);
1925
+ B(() => {
1926
+ x(c);
1541
1927
  }, [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,
1928
+ const w = N(() => {
1929
+ var k, h;
1930
+ const E = !g;
1931
+ x(E), f == null || f(E), E ? (k = a.onOpen) == null || k.call(a) : (h = a.onClose) == null || h.call(a);
1932
+ }, [g, a, f]), T = N(() => {
1933
+ var E;
1934
+ x(!1), f == null || f(!1), (E = a.onClose) == null || E.call(a);
1935
+ }, [a, f]), L = n.Trigger ?? ye;
1936
+ return s === "fullpage" ? g ? /* @__PURE__ */ e(ae, { sdk: r, hooks: a, children: /* @__PURE__ */ e(
1937
+ et,
1552
1938
  {
1553
1939
  title: l,
1554
- slots: s,
1555
- welcomeMessage: o,
1556
- suggestedPrompts: i,
1557
- sidebarDefaultOpen: f,
1558
- onClose: v,
1559
- avatar: u,
1560
- artifactPreview: h
1940
+ slots: n,
1941
+ welcomeMessage: i,
1942
+ suggestedPrompts: o,
1943
+ sidebarDefaultOpen: u,
1944
+ onClose: T,
1945
+ avatar: d,
1946
+ artifactPreview: m
1561
1947
  }
1562
- ) }) : null : /* @__PURE__ */ d(G, { sdk: t, hooks: n, children: [
1563
- /* @__PURE__ */ e(m, { isOpen: w, onClick: b }),
1948
+ ) }) : null : /* @__PURE__ */ p(ae, { sdk: r, hooks: a, children: [
1949
+ /* @__PURE__ */ e(L, { isOpen: g, onClick: w }),
1564
1950
  /* @__PURE__ */ e(
1565
- _e,
1951
+ Ze,
1566
1952
  {
1567
- isOpen: w,
1568
- onClose: v,
1953
+ isOpen: g,
1954
+ onClose: T,
1569
1955
  title: l,
1570
- slots: s,
1571
- welcomeMessage: o,
1572
- suggestedPrompts: i,
1573
- avatar: u,
1574
- artifactPreview: h
1956
+ slots: n,
1957
+ welcomeMessage: i,
1958
+ suggestedPrompts: o,
1959
+ avatar: d,
1960
+ artifactPreview: m
1575
1961
  }
1576
1962
  )
1577
1963
  ] });
1578
1964
  }
1579
- const Ue = `
1965
+ const at = `
1580
1966
  [data-super-agent-widget] {
1581
1967
  --sa-primary-dark: color-mix(in srgb, var(--sa-primary) 82%, #000);
1582
1968
  --sa-primary-light: color-mix(in srgb, var(--sa-primary) 10%, #fff);
1583
1969
  --sa-text: #1f2937;
1584
1970
  --sa-text-muted: #6b7280;
1971
+ --sa-text-light: #9ca3af;
1585
1972
  --sa-border: #e5e7eb;
1586
1973
  --sa-surface: #f9fafb;
1974
+ --sa-hover: #f3f4f6;
1587
1975
 
1588
1976
  font-family: var(--sa-font);
1589
1977
  color: var(--sa-text);
@@ -1771,13 +2159,19 @@ const Ue = `
1771
2159
  justify-content: flex-end;
1772
2160
  }
1773
2161
 
1774
- .sa-message-body {
2162
+ .sa-message-content {
1775
2163
  max-width: 78%;
1776
2164
  display: flex;
1777
2165
  flex-direction: column;
1778
2166
  gap: 4px;
1779
2167
  }
1780
2168
 
2169
+ .sa-message-body {
2170
+ display: flex;
2171
+ flex-direction: column;
2172
+ gap: 4px;
2173
+ }
2174
+
1781
2175
  .sa-message-user .sa-message-body {
1782
2176
  padding: 10px 14px;
1783
2177
  border-radius: 16px;
@@ -1801,6 +2195,16 @@ const Ue = `
1801
2195
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
1802
2196
  }
1803
2197
 
2198
+ .sa-message-time {
2199
+ font-size: 11px;
2200
+ color: var(--sa-text-muted);
2201
+ opacity: 0.7;
2202
+ }
2203
+
2204
+ .sa-message-time-right {
2205
+ text-align: right;
2206
+ }
2207
+
1804
2208
  .sa-avatar {
1805
2209
  width: 28px;
1806
2210
  height: 28px;
@@ -2046,6 +2450,8 @@ const Ue = `
2046
2450
  }
2047
2451
 
2048
2452
  .sa-tool-result-content {
2453
+ max-height: 100px;
2454
+ overflow-y: auto;
2049
2455
  padding: 10px 12px;
2050
2456
  color: #4b5563;
2051
2457
  font-size: 13px;
@@ -2098,12 +2504,21 @@ const Ue = `
2098
2504
 
2099
2505
  .sa-action-bar {
2100
2506
  display: flex;
2507
+ align-items: center;
2508
+ flex-wrap: wrap;
2101
2509
  gap: 6px;
2102
2510
  margin-top: 6px;
2103
2511
  position: relative;
2104
2512
  }
2105
2513
 
2106
2514
  .sa-action-btn {
2515
+ display: inline-flex;
2516
+ align-items: center;
2517
+ justify-content: center;
2518
+ gap: 4px;
2519
+ flex: none;
2520
+ white-space: nowrap;
2521
+ line-height: 1;
2107
2522
  padding: 4px 10px;
2108
2523
  border: none;
2109
2524
  border-radius: 6px;
@@ -2114,6 +2529,11 @@ const Ue = `
2114
2529
  transition: color 0.15s ease, background 0.15s ease;
2115
2530
  }
2116
2531
 
2532
+ .sa-action-btn svg {
2533
+ display: block;
2534
+ flex: none;
2535
+ }
2536
+
2117
2537
  .sa-action-btn:hover {
2118
2538
  color: var(--sa-text);
2119
2539
  background: rgba(0, 0, 0, 0.05);
@@ -2173,6 +2593,7 @@ const Ue = `
2173
2593
  /* ── Composer ────────────────────────────────────────────── */
2174
2594
 
2175
2595
  .sa-composer {
2596
+ position: relative;
2176
2597
  display: flex;
2177
2598
  align-items: flex-end;
2178
2599
  gap: 10px;
@@ -2248,6 +2669,62 @@ const Ue = `
2248
2669
  transform: scale(1.05);
2249
2670
  }
2250
2671
 
2672
+ /* ── Slash Menu ─────────────────────────────────────────── */
2673
+
2674
+ .sa-slash-menu {
2675
+ position: absolute;
2676
+ bottom: 100%;
2677
+ left: 14px;
2678
+ right: 14px;
2679
+ max-width: 400px;
2680
+ max-height: 200px;
2681
+ overflow-y: auto;
2682
+ background: var(--sa-surface);
2683
+ border: 1px solid var(--sa-border);
2684
+ border-radius: 8px;
2685
+ box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
2686
+ margin-bottom: 4px;
2687
+ z-index: 10;
2688
+ }
2689
+
2690
+ .sa-slash-menu-empty {
2691
+ padding: 12px 14px;
2692
+ color: #9ca3af;
2693
+ font-size: 13px;
2694
+ text-align: center;
2695
+ }
2696
+
2697
+ .sa-slash-menu-item {
2698
+ display: flex;
2699
+ align-items: center;
2700
+ gap: 8px;
2701
+ padding: 8px 14px;
2702
+ cursor: pointer;
2703
+ transition: background 0.15s ease;
2704
+ }
2705
+
2706
+ .sa-slash-menu-item:hover,
2707
+ .sa-slash-menu-item--active {
2708
+ background: var(--sa-hover);
2709
+ }
2710
+
2711
+ .sa-slash-menu-item-name {
2712
+ font-size: 13px;
2713
+ font-weight: 500;
2714
+ color: var(--sa-text);
2715
+ white-space: nowrap;
2716
+ }
2717
+
2718
+ .sa-slash-menu-item-desc {
2719
+ font-size: 12px;
2720
+ color: #9ca3af;
2721
+ overflow: hidden;
2722
+ text-overflow: ellipsis;
2723
+ white-space: nowrap;
2724
+ flex: 1;
2725
+ min-width: 0;
2726
+ }
2727
+
2251
2728
  /* ── Thread list ─────────────────────────────────────────── */
2252
2729
 
2253
2730
  .sa-thread-list-overlay {
@@ -2318,6 +2795,13 @@ const Ue = `
2318
2795
  font-size: 14px;
2319
2796
  }
2320
2797
 
2798
+ .sa-thread-list-loading {
2799
+ padding: 12px 16px;
2800
+ text-align: center;
2801
+ color: #9ca3af;
2802
+ font-size: 13px;
2803
+ }
2804
+
2321
2805
  .sa-thread-group-label {
2322
2806
  padding: 16px 8px 6px;
2323
2807
  font-size: 12px;
@@ -2349,13 +2833,26 @@ const Ue = `
2349
2833
  font-weight: 500;
2350
2834
  }
2351
2835
 
2352
- .sa-thread-item-title {
2836
+ .sa-thread-item-info {
2353
2837
  flex: 1;
2838
+ overflow: hidden;
2839
+ display: flex;
2840
+ flex-direction: column;
2841
+ gap: 2px;
2842
+ }
2843
+
2844
+ .sa-thread-item-title {
2354
2845
  overflow: hidden;
2355
2846
  white-space: nowrap;
2356
2847
  text-overflow: ellipsis;
2357
2848
  }
2358
2849
 
2850
+ .sa-thread-item-time {
2851
+ font-size: 11px;
2852
+ color: var(--sa-text-light);
2853
+ white-space: nowrap;
2854
+ }
2855
+
2359
2856
  .sa-thread-item-edit {
2360
2857
  width: 100%;
2361
2858
  padding: 4px 8px;
@@ -2367,22 +2864,33 @@ const Ue = `
2367
2864
  color: var(--sa-text);
2368
2865
  }
2369
2866
 
2370
- .sa-thread-item-delete {
2867
+ /* 操作按钮组:始终占位(visibility 控制),hover 时显示,高度不变 */
2868
+ .sa-thread-item-actions {
2869
+ display: flex;
2870
+ gap: 2px;
2871
+ flex-shrink: 0;
2872
+ visibility: hidden;
2873
+ }
2874
+
2875
+ .sa-thread-item:hover .sa-thread-item-actions {
2876
+ visibility: visible;
2877
+ }
2878
+
2879
+ .sa-thread-item-action-btn {
2371
2880
  border: none;
2372
2881
  background: transparent;
2373
2882
  color: var(--sa-text-muted);
2374
- font-size: 14px;
2375
2883
  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;
2884
+ padding: 2px;
2885
+ border-radius: 4px;
2886
+ display: inline-flex;
2887
+ align-items: center;
2888
+ transition: color 0.15s ease, background 0.15s ease;
2382
2889
  }
2383
2890
 
2384
- .sa-thread-item-delete:hover {
2385
- color: #ef4444;
2891
+ .sa-thread-item-action-btn:hover {
2892
+ color: var(--sa-primary);
2893
+ background: rgba(99,102,241,0.08);
2386
2894
  }
2387
2895
 
2388
2896
  /* ── Welcome ─────────────────────────────────────────────── */
@@ -2618,16 +3126,34 @@ const Ue = `
2618
3126
  margin-left: 2px;
2619
3127
  }
2620
3128
 
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;
3129
+ .sa-interrupt-submitted {
3130
+ margin-top: 8px;
3131
+ font-size: 12px;
3132
+ color: #9ca3af;
3133
+ }
3134
+
3135
+ .sa-interrupt-btn-answered {
3136
+ background: var(--sa-primary) !important;
3137
+ color: #fff !important;
3138
+ opacity: 0.7;
3139
+ }
3140
+
3141
+ .sa-interrupt-btn:disabled {
3142
+ opacity: 0.5;
3143
+ cursor: not-allowed;
3144
+ }
3145
+
3146
+ .sa-interrupt-option:disabled {
3147
+ opacity: 0.6;
3148
+ cursor: not-allowed;
3149
+ }
3150
+
3151
+ .sa-interrupt-input:disabled,
3152
+ .sa-interrupt-textarea:disabled,
3153
+ .sa-interrupt-select:disabled {
3154
+ opacity: 0.6;
3155
+ cursor: not-allowed;
3156
+ background: #f9fafb;
2631
3157
  }
2632
3158
 
2633
3159
  .sa-interrupt-unknown {
@@ -2676,13 +3202,11 @@ const Ue = `
2676
3202
  /* ── Fullpage Layout (DeepSeek-style) ────────────────────────── */
2677
3203
 
2678
3204
  .sa-fullpage {
2679
- position: fixed;
2680
- inset: 0;
2681
- width: 100vw;
2682
- height: 100vh;
3205
+ position: relative;
3206
+ width: 100%;
3207
+ height: 100%;
2683
3208
  display: flex;
2684
- background: #f7f7f8;
2685
- z-index: var(--sa-z-index, 9999);
3209
+ background: var(--sa-bg, #ffffff);
2686
3210
  }
2687
3211
 
2688
3212
  /* Sidebar */
@@ -2690,7 +3214,7 @@ const Ue = `
2690
3214
  width: 260px;
2691
3215
  display: flex;
2692
3216
  flex-direction: column;
2693
- background: #f2f2f3;
3217
+ background: var(--sa-surface, #ffffff);
2694
3218
  flex-shrink: 0;
2695
3219
  transition: width 0.2s cubic-bezier(0.16,1,0.3,1);
2696
3220
  overflow: hidden;
@@ -2816,6 +3340,29 @@ const Ue = `
2816
3340
  text-overflow: ellipsis;
2817
3341
  }
2818
3342
 
3343
+ .sa-fp-sidebar-item-edit {
3344
+ flex: 1;
3345
+ min-width: 0;
3346
+ padding: 2px 6px;
3347
+ border: 1px solid var(--sa-primary, #6366f1);
3348
+ border-radius: 4px;
3349
+ font-size: 13px;
3350
+ color: #27272a;
3351
+ background: #fff;
3352
+ outline: none;
3353
+ }
3354
+
3355
+ .sa-fp-sidebar-item-actions {
3356
+ display: flex;
3357
+ gap: 2px;
3358
+ flex-shrink: 0;
3359
+ visibility: hidden;
3360
+ }
3361
+
3362
+ .sa-fp-sidebar-item-actions.visible {
3363
+ visibility: visible;
3364
+ }
3365
+
2819
3366
  .sa-fp-sidebar-item-action {
2820
3367
  width: 24px;
2821
3368
  height: 24px;
@@ -2976,7 +3523,7 @@ const Ue = `
2976
3523
 
2977
3524
  /* ── Inline HTML rendering (render_mode=html) ── */
2978
3525
  .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; }
3526
+ .sa-tool-result-html-iframe { width: 100%; height: 120px; max-height: 500px; border: none; background: #fff; }
2980
3527
 
2981
3528
  /* ── Header artifact button ── */
2982
3529
  .sa-header-btn-artifact {
@@ -3105,7 +3652,7 @@ const Ue = `
3105
3652
  from { opacity: 0; transform: translateX(12px); }
3106
3653
  to { opacity: 1; transform: translateX(0); }
3107
3654
  }
3108
- `, Ve = {
3655
+ `, rt = {
3109
3656
  primaryColor: "#6366f1",
3110
3657
  backgroundColor: "#ffffff",
3111
3658
  fontFamily: "system-ui, -apple-system, sans-serif",
@@ -3114,78 +3661,98 @@ const Ue = `
3114
3661
  panelHeight: 520,
3115
3662
  zIndex: 9999
3116
3663
  };
3117
- function qe(a) {
3118
- const t = { ...Ve, ...a };
3664
+ function st(t, r) {
3665
+ const s = parseInt(t.slice(1, 3), 16), n = parseInt(t.slice(3, 5), 16), a = parseInt(t.slice(5, 7), 16), i = 1 - r;
3666
+ return `#${Math.round(s * i).toString(16).padStart(2, "0")}${Math.round(n * i).toString(16).padStart(2, "0")}${Math.round(a * i).toString(16).padStart(2, "0")}`;
3667
+ }
3668
+ function nt(t, r) {
3669
+ const s = parseInt(t.slice(1, 3), 16), n = parseInt(t.slice(3, 5), 16), a = parseInt(t.slice(5, 7), 16);
3670
+ return `#${Math.round(s + (255 - s) * r).toString(16).padStart(2, "0")}${Math.round(n + (255 - n) * r).toString(16).padStart(2, "0")}${Math.round(a + (255 - a) * r).toString(16).padStart(2, "0")}`;
3671
+ }
3672
+ function it(t) {
3673
+ const r = { ...rt, ...t }, s = r.primaryColor, n = r.backgroundColor;
3119
3674
  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}`
3675
+ // 用户直接配置的变量
3676
+ `--sa-primary: ${s}`,
3677
+ `--sa-bg: ${n}`,
3678
+ `--sa-font: ${r.fontFamily}`,
3679
+ `--sa-radius: ${r.borderRadius}px`,
3680
+ `--sa-panel-width: ${r.panelWidth}px`,
3681
+ `--sa-panel-height: ${r.panelHeight}px`,
3682
+ `--sa-z-index: ${r.zIndex}`,
3683
+ // 从 primaryColor 自动派生
3684
+ `--sa-primary-dark: ${st(s, 0.15)}`,
3685
+ `--sa-primary-light: ${nt(s, 0.9)}`,
3686
+ // 从 backgroundColor 自动派生的语义色
3687
+ `--sa-surface: ${n}`,
3688
+ "--sa-border: #e5e7eb",
3689
+ "--sa-hover: #f4f4f5",
3690
+ "--sa-text: #374151",
3691
+ "--sa-text-muted: #9ca3af",
3692
+ "--sa-text-light: #6b7280"
3127
3693
  ].join("; ");
3128
3694
  }
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")) {
3695
+ function dt(t, r) {
3696
+ const s = typeof t == "string" ? document.querySelector(t) : t;
3697
+ if (!s)
3698
+ throw new Error(`Target element not found: ${t}`);
3699
+ const n = document.createElement("div");
3700
+ n.setAttribute("data-super-agent-widget", "");
3701
+ const a = it(r.theme ?? {});
3702
+ if (n.setAttribute("style", `${a}; height: 100%;`), s.appendChild(n), !document.getElementById("sa-widget-styles")) {
3137
3703
  const c = document.createElement("style");
3138
- c.id = "sa-widget-styles", c.textContent = Ue, document.head.appendChild(c);
3704
+ c.id = "sa-widget-styles", c.textContent = at, document.head.appendChild(c);
3139
3705
  }
3140
- let o = le(s), i = !1;
3706
+ let i = he(n), o = !1;
3141
3707
  const l = (c) => {
3142
- o && o.render(
3143
- Y.createElement(Ke, {
3144
- ...t,
3145
- initialOpen: c ?? i,
3146
- onOpenChange: (p) => {
3147
- i = p;
3708
+ i && i.render(
3709
+ Y.createElement(tt, {
3710
+ ...r,
3711
+ initialOpen: c ?? o,
3712
+ onOpenChange: (f) => {
3713
+ o = f;
3148
3714
  }
3149
3715
  })
3150
3716
  );
3151
3717
  };
3152
3718
  return l(!1), {
3153
3719
  open() {
3154
- i = !0, l(!0);
3720
+ o = !0, l(!0);
3155
3721
  },
3156
3722
  close() {
3157
- i = !1, l(!1);
3723
+ o = !1, l(!1);
3158
3724
  },
3159
3725
  destroy() {
3160
- o && (o.unmount(), o = null), s.remove();
3726
+ i && (i.unmount(), i = null), n.remove();
3161
3727
  }
3162
3728
  };
3163
3729
  }
3164
3730
  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
3731
+ Ye as ActionBar,
3732
+ ae as ChatProvider,
3733
+ tt as ChatWidget,
3734
+ pe as Composer,
3735
+ Le as ErrorPart,
3736
+ et as FullpageLayout,
3737
+ ke as Header,
3738
+ z as Icon,
3739
+ We as InterruptCard,
3740
+ qe as Message,
3741
+ Te as TextPart,
3742
+ Me as ThinkingPart,
3743
+ de as Thread,
3744
+ Ce as ThreadList,
3745
+ De as ToolCallPart,
3746
+ Ee as ToolResultPart,
3747
+ ye as Trigger,
3748
+ Ve as WelcomeScreen,
3749
+ rt as defaultTheme,
3750
+ we as ensureIconFont,
3751
+ dt as mount,
3752
+ it as themeToCSSVars,
3753
+ ze as useAutoScroll,
3754
+ ge as useChat,
3755
+ U as useChatContext,
3756
+ be as useConversations,
3757
+ at as widgetStyles
3191
3758
  };