super-agent-sdk 1.0.5 → 1.0.6
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/README.md +22 -24
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -1
- package/dist/widget.cjs +6 -6
- package/dist/widget.d.ts +2 -2
- package/dist/widget.mjs +499 -489
- package/package.json +4 -3
package/dist/widget.mjs
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
import Y, { useState as T, useRef as
|
|
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
2
|
import { createRoot as le } from "react-dom/client";
|
|
3
3
|
import { jsx as e, jsxs as d, Fragment as q } from "react/jsx-runtime";
|
|
4
4
|
function ce(a) {
|
|
5
|
-
const { sdk: t, sessionId:
|
|
6
|
-
|
|
7
|
-
const m =
|
|
8
|
-
if (
|
|
9
|
-
|
|
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
10
|
const O = {
|
|
11
11
|
id: `user_${Date.now()}`,
|
|
12
12
|
role: "user",
|
|
13
|
-
parts: [{ type: "text", content:
|
|
13
|
+
parts: [{ type: "text", content: L }],
|
|
14
14
|
timestamp: Date.now()
|
|
15
|
-
}, y = `assistant_${Date.now()}`,
|
|
15
|
+
}, y = `assistant_${Date.now()}`, D = {
|
|
16
16
|
id: y,
|
|
17
17
|
role: "assistant",
|
|
18
18
|
parts: [],
|
|
19
19
|
timestamp: Date.now()
|
|
20
20
|
};
|
|
21
|
-
p((
|
|
22
|
-
const
|
|
21
|
+
p((M) => [...M, O, D]), u("submitted"), w(null);
|
|
22
|
+
const P = (M) => {
|
|
23
23
|
let E = "", A = "", H = [], z = !1;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const $ = () => {
|
|
25
|
+
const x = [...H];
|
|
26
26
|
if (E) {
|
|
27
|
-
const
|
|
28
|
-
|
|
27
|
+
const _ = x.findIndex((B) => B.type === "thinking");
|
|
28
|
+
_ >= 0 ? x[_] = { type: "thinking", content: E } : x.unshift({ type: "thinking", content: E });
|
|
29
29
|
}
|
|
30
30
|
if (A) {
|
|
31
|
-
const
|
|
32
|
-
|
|
31
|
+
const _ = x.findLastIndex((B) => B.type === "text");
|
|
32
|
+
_ >= 0 ? x[_] = { type: "text", content: A } : x.push({ type: "text", content: A });
|
|
33
33
|
}
|
|
34
34
|
p(
|
|
35
|
-
(
|
|
35
|
+
(_) => _.map((B) => B.id === y ? { ...B, parts: x } : B)
|
|
36
36
|
);
|
|
37
37
|
};
|
|
38
38
|
k.current = t.chat({
|
|
39
|
-
sessionId:
|
|
40
|
-
message:
|
|
39
|
+
sessionId: M,
|
|
40
|
+
message: L,
|
|
41
41
|
stream: !0,
|
|
42
|
-
onMessage: (
|
|
43
|
-
switch (z || (z = !0, u("streaming")),
|
|
42
|
+
onMessage: (x) => {
|
|
43
|
+
switch (z || (z = !0, u("streaming")), x.type) {
|
|
44
44
|
case "thinking":
|
|
45
|
-
E +=
|
|
45
|
+
E += x.content;
|
|
46
46
|
break;
|
|
47
47
|
case "ai":
|
|
48
|
-
A +=
|
|
48
|
+
A += x.content;
|
|
49
49
|
break;
|
|
50
50
|
case "tool_call":
|
|
51
51
|
H.push({
|
|
52
52
|
type: "tool_call",
|
|
53
|
-
toolName:
|
|
54
|
-
toolCallId:
|
|
55
|
-
args:
|
|
53
|
+
toolName: x.toolName,
|
|
54
|
+
toolCallId: x.toolCallId,
|
|
55
|
+
args: x.args ?? "{}"
|
|
56
56
|
});
|
|
57
57
|
break;
|
|
58
58
|
case "tool_result":
|
|
59
59
|
H.push({
|
|
60
60
|
type: "tool_result",
|
|
61
|
-
toolName:
|
|
62
|
-
toolCallId:
|
|
63
|
-
content:
|
|
64
|
-
artifacts:
|
|
65
|
-
renderMode:
|
|
66
|
-
html:
|
|
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
67
|
}), A && (H.push({ type: "text", content: A }), A = "");
|
|
68
68
|
break;
|
|
69
69
|
case "interrupt":
|
|
70
|
-
|
|
70
|
+
x.interrupt && H.push({
|
|
71
71
|
type: "interrupt",
|
|
72
|
-
interrupt:
|
|
72
|
+
interrupt: x.interrupt,
|
|
73
73
|
resolved: !1
|
|
74
74
|
});
|
|
75
75
|
break;
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
$();
|
|
78
78
|
},
|
|
79
|
-
onDone: (
|
|
80
|
-
(A || H.length > 0 || E) &&
|
|
81
|
-
(
|
|
82
|
-
),
|
|
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;
|
|
83
83
|
},
|
|
84
|
-
onError: (
|
|
85
|
-
H.push({ type: "error", content:
|
|
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;
|
|
86
86
|
}
|
|
87
|
-
}), n == null || n(
|
|
87
|
+
}), n == null || n(M);
|
|
88
88
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}).catch((
|
|
92
|
-
|
|
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;
|
|
93
93
|
});
|
|
94
|
-
}, [t,
|
|
95
|
-
var
|
|
96
|
-
(
|
|
97
|
-
}, []),
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const O = c[
|
|
102
|
-
p((y) => y.slice(0,
|
|
103
|
-
}, [c, m]),
|
|
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
104
|
p(
|
|
105
|
-
(z) => z.map((
|
|
106
|
-
|
|
107
|
-
parts:
|
|
108
|
-
(
|
|
105
|
+
(z) => z.map(($) => ({
|
|
106
|
+
...$,
|
|
107
|
+
parts: $.parts.map(
|
|
108
|
+
(x) => x.type === "interrupt" && x.interrupt.interruptId === L ? { ...x, resolved: !0, response: O } : x
|
|
109
109
|
)
|
|
110
110
|
}))
|
|
111
111
|
);
|
|
112
|
-
const y =
|
|
112
|
+
const y = v.current;
|
|
113
113
|
if (!y) return;
|
|
114
|
-
const
|
|
115
|
-
id:
|
|
114
|
+
const D = `assistant_${Date.now()}`, P = {
|
|
115
|
+
id: D,
|
|
116
116
|
role: "assistant",
|
|
117
117
|
parts: [],
|
|
118
118
|
timestamp: Date.now()
|
|
119
119
|
};
|
|
120
|
-
p((z) => [...z,
|
|
121
|
-
let
|
|
120
|
+
p((z) => [...z, P]), u("streaming");
|
|
121
|
+
let M = "", E = "", A = [];
|
|
122
122
|
const H = () => {
|
|
123
123
|
const z = [...A];
|
|
124
|
-
if (
|
|
125
|
-
const
|
|
126
|
-
|
|
124
|
+
if (M) {
|
|
125
|
+
const $ = z.findIndex((x) => x.type === "thinking");
|
|
126
|
+
$ >= 0 ? z[$] = { type: "thinking", content: M } : z.unshift({ type: "thinking", content: M });
|
|
127
127
|
}
|
|
128
128
|
if (E) {
|
|
129
|
-
const
|
|
130
|
-
|
|
129
|
+
const $ = z.findLastIndex((x) => x.type === "text");
|
|
130
|
+
$ >= 0 ? z[$] = { type: "text", content: E } : z.push({ type: "text", content: E });
|
|
131
131
|
}
|
|
132
132
|
p(
|
|
133
|
-
(
|
|
133
|
+
($) => $.map((x) => x.id === D ? { ...x, parts: z } : x)
|
|
134
134
|
);
|
|
135
135
|
};
|
|
136
136
|
t.respondInterrupt(
|
|
137
|
-
|
|
137
|
+
L,
|
|
138
138
|
y,
|
|
139
139
|
O,
|
|
140
140
|
(z) => {
|
|
141
141
|
switch (z.type) {
|
|
142
142
|
case "thinking":
|
|
143
|
-
|
|
143
|
+
M += z.content;
|
|
144
144
|
break;
|
|
145
145
|
case "ai":
|
|
146
146
|
E += z.content;
|
|
@@ -168,19 +168,21 @@ function ce(a) {
|
|
|
168
168
|
z.interrupt && A.push({ type: "interrupt", interrupt: z.interrupt, resolved: !1 });
|
|
169
169
|
break;
|
|
170
170
|
case "done":
|
|
171
|
-
|
|
171
|
+
z.messageId && p(
|
|
172
|
+
($) => $.map((x) => x.id === D ? { ...x, id: z.messageId } : x)
|
|
173
|
+
), u("ready");
|
|
172
174
|
break;
|
|
173
175
|
}
|
|
174
176
|
H();
|
|
175
177
|
},
|
|
176
178
|
(z) => {
|
|
177
|
-
A.push({ type: "error", content: z.message }), H(),
|
|
179
|
+
A.push({ type: "error", content: z.message }), H(), w(z), u("error"), i == null || i(z);
|
|
178
180
|
}
|
|
179
181
|
).catch((z) => {
|
|
180
182
|
i == null || i(z instanceof Error ? z : new Error(String(z))), u("error");
|
|
181
183
|
});
|
|
182
184
|
}, [t, i]);
|
|
183
|
-
return { messages: c, status: f, error: h, sendMessage: m, stop:
|
|
185
|
+
return { messages: c, status: f, error: h, sendMessage: m, stop: g, regenerate: N, setMessages: p, respondToInterrupt: S };
|
|
184
186
|
}
|
|
185
187
|
const X = "sa_active_conversation";
|
|
186
188
|
function J() {
|
|
@@ -197,46 +199,46 @@ function de(a) {
|
|
|
197
199
|
}
|
|
198
200
|
}
|
|
199
201
|
function pe(a) {
|
|
200
|
-
const { sdk: t, onConversationChange:
|
|
202
|
+
const { sdk: t, onConversationChange: r } = a, [s, n] = T([]), [o, i] = T(
|
|
201
203
|
() => J()
|
|
202
|
-
), [l, c] = T(!1), p =
|
|
203
|
-
|
|
204
|
+
), [l, c] = T(!1), p = F(!0);
|
|
205
|
+
R(() => () => {
|
|
204
206
|
p.current = !1;
|
|
205
207
|
}, []);
|
|
206
|
-
const f =
|
|
207
|
-
i(m), de(m), m && (
|
|
208
|
-
}, [
|
|
208
|
+
const f = I((m) => {
|
|
209
|
+
i(m), de(m), m && (r == null || r(m));
|
|
210
|
+
}, [r]), u = I(async () => {
|
|
209
211
|
c(!0);
|
|
210
212
|
try {
|
|
211
213
|
const m = await t.listConversations({ page: 1, size: 100 });
|
|
212
214
|
if (!p.current) return;
|
|
213
215
|
n(m.items);
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
+
const g = J();
|
|
217
|
+
g && !m.items.find((N) => N.sessionId === g) && f(null);
|
|
216
218
|
} catch {
|
|
217
219
|
} finally {
|
|
218
220
|
p.current && c(!1);
|
|
219
221
|
}
|
|
220
|
-
}, [t, f]), h =
|
|
222
|
+
}, [t, f]), h = I(async (m) => (f(m), await t.getMessages(m)), [t, f]), w = I(() => {
|
|
221
223
|
f(null);
|
|
222
|
-
}, [f]), k =
|
|
223
|
-
await t.deleteConversation(m), n((
|
|
224
|
-
}, [t, o, f]),
|
|
225
|
-
await t.renameConversation(m,
|
|
226
|
-
(
|
|
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)
|
|
227
229
|
);
|
|
228
|
-
}, [t]), { enabled:
|
|
229
|
-
return
|
|
230
|
-
|
|
231
|
-
}, [
|
|
232
|
-
conversations:
|
|
230
|
+
}, [t]), { enabled: v = !0 } = a;
|
|
231
|
+
return R(() => {
|
|
232
|
+
v && u();
|
|
233
|
+
}, [v, u]), {
|
|
234
|
+
conversations: s,
|
|
233
235
|
activeConversationId: o,
|
|
234
236
|
loading: l,
|
|
235
237
|
loadConversations: u,
|
|
236
238
|
switchConversation: h,
|
|
237
|
-
newConversation:
|
|
239
|
+
newConversation: w,
|
|
238
240
|
deleteConversation: k,
|
|
239
|
-
renameConversation:
|
|
241
|
+
renameConversation: b,
|
|
240
242
|
setActiveConversationId: f
|
|
241
243
|
};
|
|
242
244
|
}
|
|
@@ -249,15 +251,15 @@ function ee(a) {
|
|
|
249
251
|
function ae(a) {
|
|
250
252
|
if (!a) return [];
|
|
251
253
|
const t = [];
|
|
252
|
-
for (const
|
|
253
|
-
|
|
254
|
-
id:
|
|
255
|
-
type:
|
|
256
|
-
filename:
|
|
257
|
-
url:
|
|
258
|
-
mime:
|
|
259
|
-
size:
|
|
260
|
-
summary:
|
|
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
|
|
261
263
|
});
|
|
262
264
|
return t;
|
|
263
265
|
}
|
|
@@ -265,22 +267,22 @@ async function U(a) {
|
|
|
265
267
|
try {
|
|
266
268
|
const t = await fetch(a.url);
|
|
267
269
|
if (!t.ok) throw new Error(`HTTP ${t.status}`);
|
|
268
|
-
const
|
|
269
|
-
n.href =
|
|
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);
|
|
270
272
|
} catch {
|
|
271
273
|
const t = document.createElement("a");
|
|
272
274
|
t.href = a.url, t.download = a.filename, t.target = "_blank", document.body.appendChild(t), t.click(), t.remove();
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
const te = ie(null);
|
|
276
|
-
function
|
|
278
|
+
function W() {
|
|
277
279
|
const a = oe(te);
|
|
278
280
|
if (!a) throw new Error("useChatContext must be used within ChatProvider");
|
|
279
281
|
return a;
|
|
280
282
|
}
|
|
281
|
-
function G({ sdk: a, hooks: t, children:
|
|
282
|
-
const [
|
|
283
|
-
|
|
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(() => {
|
|
284
286
|
a.getToken().then(() => {
|
|
285
287
|
f(!0);
|
|
286
288
|
}).catch(() => {
|
|
@@ -299,45 +301,45 @@ function G({ sdk: a, hooks: t, children: s }) {
|
|
|
299
301
|
},
|
|
300
302
|
onStreamStart: t == null ? void 0 : t.onStreamStart,
|
|
301
303
|
onStreamEnd: (y) => {
|
|
302
|
-
var
|
|
303
|
-
(
|
|
304
|
+
var D;
|
|
305
|
+
(D = t == null ? void 0 : t.onStreamEnd) == null || D.call(t, y), u.loadConversations();
|
|
304
306
|
},
|
|
305
307
|
onError: t == null ? void 0 : t.onError,
|
|
306
308
|
onMessageSend: t == null ? void 0 : t.onMessageSend
|
|
307
|
-
}),
|
|
308
|
-
const
|
|
309
|
-
h.setMessages(
|
|
310
|
-
}, [u, h]), k =
|
|
309
|
+
}), w = I(async (y) => {
|
|
310
|
+
const D = await u.switchConversation(y);
|
|
311
|
+
h.setMessages(D), n(!1);
|
|
312
|
+
}, [u, h]), k = I(() => {
|
|
311
313
|
u.newConversation(), h.setMessages([]), n(!1);
|
|
312
|
-
}, [u, h]),
|
|
314
|
+
}, [u, h]), b = I(async (y) => {
|
|
313
315
|
await u.deleteConversation(y), u.activeConversationId === y && h.setMessages([]);
|
|
314
316
|
}, [u, h]);
|
|
315
|
-
|
|
317
|
+
R(() => {
|
|
316
318
|
u.activeConversationId && h.messages.length === 0 && a.getMessages(u.activeConversationId).then((y) => {
|
|
317
319
|
h.setMessages(y);
|
|
318
320
|
}).catch(() => {
|
|
319
321
|
});
|
|
320
322
|
}, []);
|
|
321
|
-
const
|
|
323
|
+
const v = I(() => {
|
|
322
324
|
n((y) => !y);
|
|
323
|
-
}, []), m =
|
|
325
|
+
}, []), m = I(() => {
|
|
324
326
|
i((y) => !y), c((y) => null);
|
|
325
|
-
}, []),
|
|
327
|
+
}, []), g = I((y) => {
|
|
326
328
|
c(y), i(!0);
|
|
327
|
-
}, []),
|
|
328
|
-
const y = /* @__PURE__ */ new Set(),
|
|
329
|
-
for (const
|
|
330
|
-
for (const
|
|
331
|
-
if (
|
|
332
|
-
for (const E of ae(
|
|
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)) {
|
|
333
335
|
const A = E.id || `${E.url}:${E.filename}`;
|
|
334
|
-
y.has(A) || (y.add(A),
|
|
336
|
+
y.has(A) || (y.add(A), D.push(E));
|
|
335
337
|
}
|
|
336
|
-
return
|
|
337
|
-
}, [h.messages]),
|
|
338
|
-
a.feedback(y,
|
|
338
|
+
return D;
|
|
339
|
+
}, [h.messages]), S = I((y, D, P) => {
|
|
340
|
+
a.feedback(y, D, P).catch(() => {
|
|
339
341
|
});
|
|
340
|
-
}, [a]),
|
|
342
|
+
}, [a]), L = I((y) => {
|
|
341
343
|
a.cancelFeedback(y).catch(() => {
|
|
342
344
|
});
|
|
343
345
|
}, [a]), O = V(() => ({
|
|
@@ -346,22 +348,22 @@ function G({ sdk: a, hooks: t, children: s }) {
|
|
|
346
348
|
messages: h.messages,
|
|
347
349
|
conversations: u.conversations,
|
|
348
350
|
activeConversationId: u.activeConversationId,
|
|
349
|
-
isThreadListOpen:
|
|
351
|
+
isThreadListOpen: s,
|
|
350
352
|
isArtifactDrawerOpen: o,
|
|
351
|
-
allArtifacts:
|
|
353
|
+
allArtifacts: N,
|
|
352
354
|
activePreviewArtifact: l,
|
|
353
355
|
sendMessage: h.sendMessage,
|
|
354
356
|
stop: h.stop,
|
|
355
357
|
regenerate: h.regenerate,
|
|
356
|
-
switchConversation:
|
|
358
|
+
switchConversation: w,
|
|
357
359
|
newConversation: k,
|
|
358
|
-
deleteConversation:
|
|
360
|
+
deleteConversation: b,
|
|
359
361
|
renameConversation: u.renameConversation,
|
|
360
|
-
toggleThreadList:
|
|
362
|
+
toggleThreadList: v,
|
|
361
363
|
toggleArtifactDrawer: m,
|
|
362
|
-
openArtifactPreview:
|
|
363
|
-
feedback:
|
|
364
|
-
cancelFeedback:
|
|
364
|
+
openArtifactPreview: g,
|
|
365
|
+
feedback: S,
|
|
366
|
+
cancelFeedback: L,
|
|
365
367
|
respondToInterrupt: h.respondToInterrupt
|
|
366
368
|
}), [
|
|
367
369
|
h.status,
|
|
@@ -374,27 +376,27 @@ function G({ sdk: a, hooks: t, children: s }) {
|
|
|
374
376
|
u.conversations,
|
|
375
377
|
u.activeConversationId,
|
|
376
378
|
u.renameConversation,
|
|
377
|
-
|
|
379
|
+
s,
|
|
378
380
|
o,
|
|
379
|
-
|
|
381
|
+
N,
|
|
380
382
|
l,
|
|
381
|
-
|
|
383
|
+
w,
|
|
382
384
|
k,
|
|
383
|
-
g,
|
|
384
385
|
b,
|
|
386
|
+
v,
|
|
385
387
|
m,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
388
|
+
g,
|
|
389
|
+
S,
|
|
390
|
+
L
|
|
389
391
|
]);
|
|
390
|
-
return /* @__PURE__ */ e(te.Provider, { value: O, children:
|
|
392
|
+
return /* @__PURE__ */ e(te.Provider, { value: O, children: r });
|
|
391
393
|
}
|
|
392
|
-
function C({ name: a, size: t = 16, color:
|
|
394
|
+
function C({ name: a, size: t = 16, color: r = "currentColor", className: s, style: n }) {
|
|
393
395
|
return /* @__PURE__ */ e(
|
|
394
396
|
"svg",
|
|
395
397
|
{
|
|
396
|
-
className:
|
|
397
|
-
style: { width: t, height: t, fill:
|
|
398
|
+
className: s,
|
|
399
|
+
style: { width: t, height: t, fill: r, verticalAlign: "middle", ...n },
|
|
398
400
|
"aria-hidden": "true",
|
|
399
401
|
children: /* @__PURE__ */ e("use", { href: `#icon-${a}` })
|
|
400
402
|
}
|
|
@@ -403,7 +405,7 @@ function C({ name: a, size: t = 16, color: s = "currentColor", className: r, sty
|
|
|
403
405
|
function fe({ isOpen: a, onClick: t }) {
|
|
404
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" }) });
|
|
405
407
|
}
|
|
406
|
-
function ue({ title: a, onClose: t, onToggleThreadList:
|
|
408
|
+
function ue({ title: a, onClose: t, onToggleThreadList: r, showClose: s = !0, artifactCount: n = 0, onToggleArtifactDrawer: o }) {
|
|
407
409
|
return /* @__PURE__ */ d("div", { className: "sa-header", children: [
|
|
408
410
|
/* @__PURE__ */ d("div", { className: "sa-header-left", children: [
|
|
409
411
|
/* @__PURE__ */ e("div", { className: "sa-header-avatar", children: "A" }),
|
|
@@ -420,16 +422,16 @@ function ue({ title: a, onClose: t, onToggleThreadList: s, showClose: r = !0, ar
|
|
|
420
422
|
] }),
|
|
421
423
|
/* @__PURE__ */ e("span", { children: "产物" })
|
|
422
424
|
] }),
|
|
423
|
-
/* @__PURE__ */ e("button", { className: "sa-header-btn", onClick:
|
|
424
|
-
|
|
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 }) })
|
|
425
427
|
] })
|
|
426
428
|
] });
|
|
427
429
|
}
|
|
428
430
|
function me(a) {
|
|
429
|
-
const t = /* @__PURE__ */ new Date(),
|
|
431
|
+
const t = /* @__PURE__ */ new Date(), r = new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime(), s = r - 6 * 864e5, n = [], o = [], i = [];
|
|
430
432
|
for (const c of a) {
|
|
431
433
|
const p = new Date(c.updateTime).getTime();
|
|
432
|
-
p >=
|
|
434
|
+
p >= r ? n.push(c) : p >= s ? o.push(c) : i.push(c);
|
|
433
435
|
}
|
|
434
436
|
const l = [];
|
|
435
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;
|
|
@@ -438,46 +440,46 @@ function he() {
|
|
|
438
440
|
const {
|
|
439
441
|
conversations: a,
|
|
440
442
|
activeConversationId: t,
|
|
441
|
-
switchConversation:
|
|
442
|
-
newConversation:
|
|
443
|
+
switchConversation: r,
|
|
444
|
+
newConversation: s,
|
|
443
445
|
deleteConversation: n,
|
|
444
446
|
renameConversation: o,
|
|
445
447
|
isThreadListOpen: i,
|
|
446
448
|
toggleThreadList: l
|
|
447
|
-
} =
|
|
448
|
-
p(
|
|
449
|
-
}, []),
|
|
450
|
-
f.trim() && o(
|
|
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);
|
|
451
453
|
}, [f, o]), k = V(() => me(a), [a]);
|
|
452
454
|
return i ? /* @__PURE__ */ d(q, { children: [
|
|
453
455
|
/* @__PURE__ */ e("div", { className: "sa-thread-list-overlay", onClick: l }),
|
|
454
456
|
/* @__PURE__ */ d("div", { className: "sa-thread-list", children: [
|
|
455
457
|
/* @__PURE__ */ d("div", { className: "sa-thread-list-header", children: [
|
|
456
458
|
/* @__PURE__ */ e("span", { className: "sa-thread-list-title", children: "会话记录" }),
|
|
457
|
-
/* @__PURE__ */ d("button", { className: "sa-thread-list-new", onClick:
|
|
459
|
+
/* @__PURE__ */ d("button", { className: "sa-thread-list-new", onClick: s, children: [
|
|
458
460
|
/* @__PURE__ */ e(C, { name: "plus", size: 14 }),
|
|
459
461
|
" 新会话"
|
|
460
462
|
] })
|
|
461
463
|
] }),
|
|
462
464
|
/* @__PURE__ */ d("div", { className: "sa-thread-list-items", children: [
|
|
463
465
|
a.length === 0 && /* @__PURE__ */ e("div", { className: "sa-thread-list-empty", children: "暂无会话" }),
|
|
464
|
-
k.map((
|
|
465
|
-
/* @__PURE__ */ e("div", { className: "sa-thread-group-label", children:
|
|
466
|
-
|
|
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(
|
|
467
469
|
"div",
|
|
468
470
|
{
|
|
469
|
-
className: `sa-thread-item ${
|
|
470
|
-
onClick: () =>
|
|
471
|
+
className: `sa-thread-item ${v.sessionId === t ? "active" : ""}`,
|
|
472
|
+
onClick: () => r(v.sessionId),
|
|
471
473
|
children: [
|
|
472
|
-
c ===
|
|
474
|
+
c === v.sessionId ? /* @__PURE__ */ e(
|
|
473
475
|
"input",
|
|
474
476
|
{
|
|
475
477
|
className: "sa-thread-item-edit",
|
|
476
478
|
value: f,
|
|
477
479
|
onChange: (m) => u(m.target.value),
|
|
478
|
-
onBlur: () => v
|
|
480
|
+
onBlur: () => w(v.sessionId),
|
|
479
481
|
onKeyDown: (m) => {
|
|
480
|
-
m.key === "Enter" && v
|
|
482
|
+
m.key === "Enter" && w(v.sessionId), m.key === "Escape" && p(null);
|
|
481
483
|
},
|
|
482
484
|
onClick: (m) => m.stopPropagation(),
|
|
483
485
|
autoFocus: !0
|
|
@@ -487,9 +489,9 @@ function he() {
|
|
|
487
489
|
{
|
|
488
490
|
className: "sa-thread-item-title",
|
|
489
491
|
onDoubleClick: (m) => {
|
|
490
|
-
m.stopPropagation(), h(
|
|
492
|
+
m.stopPropagation(), h(v.sessionId, v.title);
|
|
491
493
|
},
|
|
492
|
-
children:
|
|
494
|
+
children: v.title || "新会话"
|
|
493
495
|
}
|
|
494
496
|
),
|
|
495
497
|
/* @__PURE__ */ e(
|
|
@@ -497,7 +499,7 @@ function he() {
|
|
|
497
499
|
{
|
|
498
500
|
className: "sa-thread-item-delete",
|
|
499
501
|
onClick: (m) => {
|
|
500
|
-
m.stopPropagation(), n(
|
|
502
|
+
m.stopPropagation(), n(v.sessionId);
|
|
501
503
|
},
|
|
502
504
|
title: "删除",
|
|
503
505
|
children: /* @__PURE__ */ e(C, { name: "trash2", size: 14 })
|
|
@@ -505,33 +507,33 @@ function he() {
|
|
|
505
507
|
)
|
|
506
508
|
]
|
|
507
509
|
},
|
|
508
|
-
|
|
510
|
+
v.sessionId
|
|
509
511
|
))
|
|
510
|
-
] },
|
|
512
|
+
] }, b.label))
|
|
511
513
|
] })
|
|
512
514
|
] })
|
|
513
515
|
] }) : null;
|
|
514
516
|
}
|
|
515
517
|
function ge(a) {
|
|
516
|
-
const t =
|
|
518
|
+
const t = F(null), r = F(!1), s = F(0), n = I(() => {
|
|
517
519
|
const i = t.current;
|
|
518
520
|
if (!i) return;
|
|
519
521
|
const { scrollTop: l, scrollHeight: c, clientHeight: p } = i, f = c - l - p < 40;
|
|
520
|
-
l <
|
|
522
|
+
l < s.current && !f && (r.current = !0), f && (r.current = !1), s.current = l;
|
|
521
523
|
}, []);
|
|
522
|
-
|
|
524
|
+
R(() => {
|
|
523
525
|
const i = t.current;
|
|
524
526
|
if (i)
|
|
525
527
|
return i.addEventListener("scroll", n, { passive: !0 }), () => i.removeEventListener("scroll", n);
|
|
526
|
-
}, [n]),
|
|
527
|
-
if (
|
|
528
|
+
}, [n]), R(() => {
|
|
529
|
+
if (r.current) return;
|
|
528
530
|
const i = t.current;
|
|
529
531
|
i && requestAnimationFrame(() => {
|
|
530
532
|
i.scrollTop = i.scrollHeight;
|
|
531
533
|
});
|
|
532
534
|
}, a);
|
|
533
|
-
const o =
|
|
534
|
-
|
|
535
|
+
const o = I(() => {
|
|
536
|
+
r.current = !1;
|
|
535
537
|
const i = t.current;
|
|
536
538
|
i && (i.scrollTop = i.scrollHeight);
|
|
537
539
|
}, []);
|
|
@@ -541,8 +543,8 @@ function j(a) {
|
|
|
541
543
|
return a.value++;
|
|
542
544
|
}
|
|
543
545
|
function K(a, t) {
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
+
const r = [], s = [], n = () => {
|
|
547
|
+
s.length > 0 && (r.push(s.join("")), s.length = 0);
|
|
546
548
|
};
|
|
547
549
|
let o = 0;
|
|
548
550
|
for (; o < a.length; ) {
|
|
@@ -550,7 +552,7 @@ function K(a, t) {
|
|
|
550
552
|
if (i === "`") {
|
|
551
553
|
const l = a.indexOf("`", o + 1);
|
|
552
554
|
if (l !== -1) {
|
|
553
|
-
n(),
|
|
555
|
+
n(), r.push(
|
|
554
556
|
/* @__PURE__ */ e("code", { className: "sa-inline-code", children: a.slice(o + 1, l) }, j(t))
|
|
555
557
|
), o = l + 1;
|
|
556
558
|
continue;
|
|
@@ -558,7 +560,7 @@ function K(a, t) {
|
|
|
558
560
|
} else if (i === "*" && a[o + 1] === "*") {
|
|
559
561
|
const l = a.indexOf("**", o + 2);
|
|
560
562
|
if (l !== -1) {
|
|
561
|
-
n(),
|
|
563
|
+
n(), r.push(
|
|
562
564
|
/* @__PURE__ */ e("strong", { children: K(a.slice(o + 2, l), t) }, j(t))
|
|
563
565
|
), o = l + 2;
|
|
564
566
|
continue;
|
|
@@ -566,7 +568,7 @@ function K(a, t) {
|
|
|
566
568
|
} else if (i === "*") {
|
|
567
569
|
const l = a.indexOf("*", o + 1);
|
|
568
570
|
if (l !== -1) {
|
|
569
|
-
n(),
|
|
571
|
+
n(), r.push(
|
|
570
572
|
/* @__PURE__ */ e("em", { children: K(a.slice(o + 1, l), t) }, j(t))
|
|
571
573
|
), o = l + 1;
|
|
572
574
|
continue;
|
|
@@ -577,7 +579,7 @@ function K(a, t) {
|
|
|
577
579
|
const c = a.indexOf(")", l + 2);
|
|
578
580
|
if (c !== -1) {
|
|
579
581
|
const p = a.slice(o + 1, l), f = a.slice(l + 2, c);
|
|
580
|
-
n(),
|
|
582
|
+
n(), r.push(
|
|
581
583
|
/* @__PURE__ */ e(
|
|
582
584
|
"a",
|
|
583
585
|
{
|
|
@@ -593,17 +595,17 @@ function K(a, t) {
|
|
|
593
595
|
}
|
|
594
596
|
}
|
|
595
597
|
}
|
|
596
|
-
|
|
598
|
+
s.push(i), o++;
|
|
597
599
|
}
|
|
598
|
-
return n(),
|
|
600
|
+
return n(), r;
|
|
599
601
|
}
|
|
600
|
-
function
|
|
601
|
-
const
|
|
602
|
+
function be(a, t) {
|
|
603
|
+
const r = [], s = a.split(`
|
|
602
604
|
`);
|
|
603
605
|
let n = 0;
|
|
604
606
|
const o = (c) => c.trim() === "", i = (c) => /^#{1,6}\s+\S/.test(c.trim()), l = (c) => /^(?:[-*+]|\d+[.)])\s+\S/.test(c.trim());
|
|
605
|
-
for (; n <
|
|
606
|
-
const c =
|
|
607
|
+
for (; n < s.length; ) {
|
|
608
|
+
const c = s[n], p = c.trim();
|
|
607
609
|
if (o(c)) {
|
|
608
610
|
n++;
|
|
609
611
|
continue;
|
|
@@ -611,10 +613,10 @@ function xe(a, t) {
|
|
|
611
613
|
if (i(c)) {
|
|
612
614
|
const u = p.match(/^(#{1,6})\s+(.*)$/);
|
|
613
615
|
if (u) {
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
+
const w = `h${Math.min(u[1].length, 6)}`;
|
|
617
|
+
r.push(
|
|
616
618
|
Y.createElement(
|
|
617
|
-
|
|
619
|
+
w,
|
|
618
620
|
{ key: j(t) },
|
|
619
621
|
K(u[2], t)
|
|
620
622
|
)
|
|
@@ -625,45 +627,45 @@ function xe(a, t) {
|
|
|
625
627
|
}
|
|
626
628
|
if (l(c)) {
|
|
627
629
|
const u = /^\d+[.)]/.test(p), h = [];
|
|
628
|
-
for (; n <
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
/* @__PURE__ */ e("li", { children: K(
|
|
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))
|
|
632
634
|
), n++;
|
|
633
635
|
}
|
|
634
|
-
|
|
636
|
+
r.push(
|
|
635
637
|
u ? /* @__PURE__ */ e("ol", { className: "sa-list", children: h }, j(t)) : /* @__PURE__ */ e("ul", { className: "sa-list", children: h }, j(t))
|
|
636
638
|
);
|
|
637
639
|
continue;
|
|
638
640
|
}
|
|
639
641
|
const f = [];
|
|
640
|
-
for (; n <
|
|
641
|
-
f.push(
|
|
642
|
-
|
|
642
|
+
for (; n < s.length && !o(s[n]) && !i(s[n]) && !l(s[n]); )
|
|
643
|
+
f.push(s[n]), n++;
|
|
644
|
+
r.push(
|
|
643
645
|
/* @__PURE__ */ e("p", { className: "sa-text-paragraph", children: K(f.join(" "), t) }, j(t))
|
|
644
646
|
);
|
|
645
647
|
}
|
|
646
|
-
return
|
|
648
|
+
return r;
|
|
647
649
|
}
|
|
648
|
-
function
|
|
649
|
-
const t = { value: 0 },
|
|
650
|
-
for (let n = 0; n <
|
|
650
|
+
function xe(a) {
|
|
651
|
+
const t = { value: 0 }, r = [], s = a.split("```");
|
|
652
|
+
for (let n = 0; n < s.length; n++)
|
|
651
653
|
if (n % 2 === 0)
|
|
652
|
-
|
|
653
|
-
else if (
|
|
654
|
-
let o =
|
|
655
|
-
o = o.replace(/^[a-zA-Z0-9_+#.-]+\r?\n/, ""), o = o.replace(/\r?\n$/, ""),
|
|
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(
|
|
656
658
|
/* @__PURE__ */ e("pre", { className: "sa-code-block", children: /* @__PURE__ */ e("code", { children: o }) }, j(t))
|
|
657
659
|
);
|
|
658
660
|
}
|
|
659
|
-
return
|
|
661
|
+
return r;
|
|
660
662
|
}
|
|
661
663
|
function ve({ content: a }) {
|
|
662
|
-
return /* @__PURE__ */ e("div", { className: "sa-text-part", children:
|
|
664
|
+
return /* @__PURE__ */ e("div", { className: "sa-text-part", children: xe(a) });
|
|
663
665
|
}
|
|
664
666
|
function we({ content: a }) {
|
|
665
|
-
const [t,
|
|
666
|
-
return /* @__PURE__ */ d("div", { className: "sa-thinking-part", onClick: () =>
|
|
667
|
+
const [t, r] = T(!1);
|
|
668
|
+
return /* @__PURE__ */ d("div", { className: "sa-thinking-part", onClick: () => r(!t), children: [
|
|
667
669
|
/* @__PURE__ */ d("div", { className: "sa-thinking-header", children: [
|
|
668
670
|
/* @__PURE__ */ e("span", { className: "sa-thinking-icon", children: /* @__PURE__ */ e(C, { name: "brain", size: 14 }) }),
|
|
669
671
|
/* @__PURE__ */ e("span", { className: "sa-thinking-label", children: "思考过程" }),
|
|
@@ -672,44 +674,44 @@ function we({ content: a }) {
|
|
|
672
674
|
t && /* @__PURE__ */ e("div", { className: "sa-thinking-content", children: a })
|
|
673
675
|
] });
|
|
674
676
|
}
|
|
675
|
-
function ye({ toolName: a, toolCallId: t, args:
|
|
676
|
-
const [
|
|
677
|
-
let o =
|
|
677
|
+
function ye({ toolName: a, toolCallId: t, args: r }) {
|
|
678
|
+
const [s, n] = T(!1);
|
|
679
|
+
let o = r;
|
|
678
680
|
try {
|
|
679
|
-
o = JSON.stringify(JSON.parse(
|
|
681
|
+
o = JSON.stringify(JSON.parse(r), null, 2);
|
|
680
682
|
} catch {
|
|
681
683
|
}
|
|
682
684
|
return /* @__PURE__ */ d("div", { className: "sa-tool-call-part", children: [
|
|
683
|
-
/* @__PURE__ */ d("div", { className: "sa-tool-call-header", onClick: () => n(!
|
|
685
|
+
/* @__PURE__ */ d("div", { className: "sa-tool-call-header", onClick: () => n(!s), children: [
|
|
684
686
|
/* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(C, { name: "zap", size: 14 }) }),
|
|
685
687
|
/* @__PURE__ */ d("span", { className: "sa-tool-name", children: [
|
|
686
688
|
"调用工具: ",
|
|
687
689
|
a
|
|
688
690
|
] }),
|
|
689
|
-
/* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${
|
|
691
|
+
/* @__PURE__ */ e("span", { className: `sa-thinking-arrow ${s ? "expanded" : ""}`, children: /* @__PURE__ */ e(C, { name: "chevron-right", size: 12 }) })
|
|
690
692
|
] }),
|
|
691
|
-
|
|
693
|
+
s && /* @__PURE__ */ e("pre", { className: "sa-tool-args", children: o })
|
|
692
694
|
] });
|
|
693
695
|
}
|
|
694
696
|
function ke({ html: a }) {
|
|
695
|
-
const [t,
|
|
696
|
-
return
|
|
697
|
-
let
|
|
697
|
+
const [t, r] = T(null);
|
|
698
|
+
return R(() => {
|
|
699
|
+
let s = !1;
|
|
698
700
|
return import("./purify.es-C-6FFqDW.js").then((n) => {
|
|
699
|
-
|
|
701
|
+
s || r(n.default.sanitize(a, { FORCE_BODY: !0 }));
|
|
700
702
|
}), () => {
|
|
701
|
-
|
|
703
|
+
s = !0;
|
|
702
704
|
};
|
|
703
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 产物" }) });
|
|
704
706
|
}
|
|
705
|
-
function Ce({ toolName: a, content: t, artifacts:
|
|
706
|
-
const { openArtifactPreview: i } =
|
|
707
|
+
function Ce({ toolName: a, content: t, artifacts: r, renderMode: s, html: n, artifactPreview: o }) {
|
|
708
|
+
const { openArtifactPreview: i } = W(), l = ae(r);
|
|
707
709
|
return /* @__PURE__ */ d("div", { className: "sa-tool-result-part", children: [
|
|
708
710
|
/* @__PURE__ */ d("div", { className: "sa-tool-result-header", children: [
|
|
709
711
|
/* @__PURE__ */ e("span", { className: "sa-tool-icon", children: /* @__PURE__ */ e(C, { name: "circle-check", size: 14, color: "#10b981" }) }),
|
|
710
712
|
/* @__PURE__ */ e("span", { className: "sa-tool-result-label", children: a || "工具返回" })
|
|
711
713
|
] }),
|
|
712
|
-
|
|
714
|
+
s === "html" && n ? /* @__PURE__ */ e(ke, { html: n }) : t ? /* @__PURE__ */ e("div", { className: "sa-tool-result-content", children: t }) : null,
|
|
713
715
|
l.length > 0 && /* @__PURE__ */ e("ul", { className: "sa-artifact-file-list", role: "list", children: l.map((c, p) => /* @__PURE__ */ d(
|
|
714
716
|
"li",
|
|
715
717
|
{
|
|
@@ -757,7 +759,7 @@ function Ne({ content: a, onRetry: t }) {
|
|
|
757
759
|
}
|
|
758
760
|
function ze({ interrupt: a, onRespond: t }) {
|
|
759
761
|
var o, i;
|
|
760
|
-
const
|
|
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) || "取消";
|
|
761
763
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
|
|
762
764
|
/* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
|
|
763
765
|
/* @__PURE__ */ e(C, { name: "circle-alert", size: 16, color: "#f59e0b" }),
|
|
@@ -767,7 +769,7 @@ function ze({ interrupt: a, onRespond: t }) {
|
|
|
767
769
|
/* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", onClick: () => t({ action: "confirm" }), children: [
|
|
768
770
|
/* @__PURE__ */ e(C, { name: "check", size: 14 }),
|
|
769
771
|
" ",
|
|
770
|
-
|
|
772
|
+
s
|
|
771
773
|
] }),
|
|
772
774
|
/* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-secondary", onClick: () => t({ action: "cancel" }), children: [
|
|
773
775
|
/* @__PURE__ */ e(C, { name: "x", size: 14 }),
|
|
@@ -779,7 +781,7 @@ function ze({ interrupt: a, onRespond: t }) {
|
|
|
779
781
|
}
|
|
780
782
|
function Ie({ interrupt: a, onRespond: t }) {
|
|
781
783
|
var l, c, p, f;
|
|
782
|
-
const
|
|
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;
|
|
783
785
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
|
|
784
786
|
/* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
|
|
785
787
|
/* @__PURE__ */ e(C, { name: "circle-alert", size: 16, color: "#f59e0b" }),
|
|
@@ -789,7 +791,7 @@ function Ie({ interrupt: a, onRespond: t }) {
|
|
|
789
791
|
/* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", onClick: () => t({ action: "approve" }), children: [
|
|
790
792
|
/* @__PURE__ */ e(C, { name: "check", size: 14 }),
|
|
791
793
|
" ",
|
|
792
|
-
|
|
794
|
+
s
|
|
793
795
|
] }),
|
|
794
796
|
/* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-danger", onClick: () => t({ action: "reject" }), children: [
|
|
795
797
|
/* @__PURE__ */ e(C, { name: "x", size: 14 }),
|
|
@@ -808,32 +810,32 @@ function Te(a) {
|
|
|
808
810
|
return typeof a == "string" ? { value: a, label: a } : a;
|
|
809
811
|
}
|
|
810
812
|
function Se({ interrupt: a, onRespond: t }) {
|
|
811
|
-
const
|
|
813
|
+
const r = (a.options ?? []).map(Te);
|
|
812
814
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
|
|
813
815
|
/* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
|
|
814
816
|
/* @__PURE__ */ e(C, { name: "list", size: 16, color: "#6366f1" }),
|
|
815
817
|
/* @__PURE__ */ e("span", { children: a.content })
|
|
816
818
|
] }),
|
|
817
|
-
/* @__PURE__ */ e("div", { className: "sa-interrupt-options", children:
|
|
819
|
+
/* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((s) => /* @__PURE__ */ d(
|
|
818
820
|
"button",
|
|
819
821
|
{
|
|
820
|
-
className: `sa-interrupt-option ${
|
|
821
|
-
onClick: () => t({ action: "select", value:
|
|
822
|
+
className: `sa-interrupt-option ${s.danger ? "sa-interrupt-option-danger" : ""}`,
|
|
823
|
+
onClick: () => t({ action: "select", value: s.value }),
|
|
822
824
|
children: [
|
|
823
|
-
|
|
824
|
-
/* @__PURE__ */ e("span", { children:
|
|
825
|
-
|
|
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 })
|
|
826
828
|
]
|
|
827
829
|
},
|
|
828
|
-
|
|
830
|
+
s.value
|
|
829
831
|
)) })
|
|
830
832
|
] });
|
|
831
833
|
}
|
|
832
834
|
function Me(a) {
|
|
833
835
|
return typeof a == "string" ? { value: a, label: a } : a;
|
|
834
836
|
}
|
|
835
|
-
function
|
|
836
|
-
const
|
|
837
|
+
function Le({ interrupt: a, onRespond: t }) {
|
|
838
|
+
const r = (a.options ?? []).map(Me), [s, n] = T(/* @__PURE__ */ new Set()), o = (i) => {
|
|
837
839
|
n((l) => {
|
|
838
840
|
const c = new Set(l);
|
|
839
841
|
return c.has(i) ? c.delete(i) : c.add(i), c;
|
|
@@ -844,13 +846,13 @@ function De({ interrupt: a, onRespond: t }) {
|
|
|
844
846
|
/* @__PURE__ */ e(C, { name: "list-checks", size: 16, color: "#6366f1" }),
|
|
845
847
|
/* @__PURE__ */ e("span", { children: a.content })
|
|
846
848
|
] }),
|
|
847
|
-
/* @__PURE__ */ e("div", { className: "sa-interrupt-options", children:
|
|
849
|
+
/* @__PURE__ */ e("div", { className: "sa-interrupt-options", children: r.map((i) => /* @__PURE__ */ d(
|
|
848
850
|
"button",
|
|
849
851
|
{
|
|
850
|
-
className: `sa-interrupt-option ${
|
|
852
|
+
className: `sa-interrupt-option ${s.has(i.value) ? "sa-interrupt-option-selected" : ""}`,
|
|
851
853
|
onClick: () => o(i.value),
|
|
852
854
|
children: [
|
|
853
|
-
/* @__PURE__ */ e(C, { name:
|
|
855
|
+
/* @__PURE__ */ e(C, { name: s.has(i.value) ? "square-check" : "square", size: 14 }),
|
|
854
856
|
/* @__PURE__ */ e("span", { children: i.label })
|
|
855
857
|
]
|
|
856
858
|
},
|
|
@@ -860,21 +862,21 @@ function De({ interrupt: a, onRespond: t }) {
|
|
|
860
862
|
"button",
|
|
861
863
|
{
|
|
862
864
|
className: "sa-interrupt-btn sa-interrupt-btn-primary",
|
|
863
|
-
disabled:
|
|
864
|
-
onClick: () => t({ action: "submit", value: Array.from(
|
|
865
|
+
disabled: s.size === 0,
|
|
866
|
+
onClick: () => t({ action: "submit", value: Array.from(s) }),
|
|
865
867
|
children: [
|
|
866
868
|
/* @__PURE__ */ e(C, { name: "check", size: 14 }),
|
|
867
869
|
" 确认 (",
|
|
868
|
-
|
|
870
|
+
s.size,
|
|
869
871
|
")"
|
|
870
872
|
]
|
|
871
873
|
}
|
|
872
874
|
) })
|
|
873
875
|
] });
|
|
874
876
|
}
|
|
875
|
-
function
|
|
876
|
-
const [
|
|
877
|
-
a.required && !
|
|
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() });
|
|
878
880
|
};
|
|
879
881
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
|
|
880
882
|
/* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
|
|
@@ -885,8 +887,8 @@ function Le({ interrupt: a, onRespond: t }) {
|
|
|
885
887
|
"textarea",
|
|
886
888
|
{
|
|
887
889
|
className: "sa-interrupt-textarea",
|
|
888
|
-
value:
|
|
889
|
-
onChange: (l) =>
|
|
890
|
+
value: r,
|
|
891
|
+
onChange: (l) => s(l.target.value),
|
|
890
892
|
placeholder: a.placeholder,
|
|
891
893
|
maxLength: a.maxLength,
|
|
892
894
|
rows: 3
|
|
@@ -896,8 +898,8 @@ function Le({ interrupt: a, onRespond: t }) {
|
|
|
896
898
|
{
|
|
897
899
|
className: "sa-interrupt-input",
|
|
898
900
|
type: n,
|
|
899
|
-
value:
|
|
900
|
-
onChange: (l) =>
|
|
901
|
+
value: r,
|
|
902
|
+
onChange: (l) => s(l.target.value),
|
|
901
903
|
placeholder: a.placeholder,
|
|
902
904
|
maxLength: a.maxLength,
|
|
903
905
|
onKeyDown: (l) => l.key === "Enter" && i()
|
|
@@ -907,7 +909,7 @@ function Le({ interrupt: a, onRespond: t }) {
|
|
|
907
909
|
"button",
|
|
908
910
|
{
|
|
909
911
|
className: "sa-interrupt-btn sa-interrupt-btn-primary",
|
|
910
|
-
disabled: a.required ? !
|
|
912
|
+
disabled: a.required ? !r.trim() : !1,
|
|
911
913
|
onClick: i,
|
|
912
914
|
children: [
|
|
913
915
|
/* @__PURE__ */ e(C, { name: "check", size: 14 }),
|
|
@@ -918,27 +920,27 @@ function Le({ interrupt: a, onRespond: t }) {
|
|
|
918
920
|
] });
|
|
919
921
|
}
|
|
920
922
|
function Ee({ interrupt: a, onRespond: t }) {
|
|
921
|
-
const
|
|
923
|
+
const r = a.fields ?? [], [s, n] = T(() => {
|
|
922
924
|
const c = {};
|
|
923
|
-
for (const p of
|
|
925
|
+
for (const p of r)
|
|
924
926
|
c[p.name] = p.defaultValue ?? "";
|
|
925
927
|
return c;
|
|
926
928
|
}), o = (c, p) => {
|
|
927
929
|
n((f) => ({ ...f, [c]: p }));
|
|
928
|
-
}, i =
|
|
929
|
-
i && t({ action: "submit", value:
|
|
930
|
+
}, i = r.every((c) => !c.required || s[c.name]), l = () => {
|
|
931
|
+
i && t({ action: "submit", value: s });
|
|
930
932
|
};
|
|
931
933
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-card", children: [
|
|
932
934
|
/* @__PURE__ */ d("div", { className: "sa-interrupt-content", children: [
|
|
933
935
|
/* @__PURE__ */ e(C, { name: "file-text", size: 16, color: "#6366f1" }),
|
|
934
936
|
/* @__PURE__ */ e("span", { children: a.content })
|
|
935
937
|
] }),
|
|
936
|
-
/* @__PURE__ */ e("div", { className: "sa-interrupt-form", children:
|
|
938
|
+
/* @__PURE__ */ e("div", { className: "sa-interrupt-form", children: r.map((c) => /* @__PURE__ */ d("div", { className: "sa-interrupt-form-field", children: [
|
|
937
939
|
/* @__PURE__ */ d("label", { className: "sa-interrupt-form-label", children: [
|
|
938
940
|
c.label,
|
|
939
941
|
c.required && /* @__PURE__ */ e("span", { className: "sa-interrupt-form-required", children: "*" })
|
|
940
942
|
] }),
|
|
941
|
-
Ae(c,
|
|
943
|
+
Ae(c, s[c.name], (p) => o(c.name, p))
|
|
942
944
|
] }, c.name)) }),
|
|
943
945
|
/* @__PURE__ */ d("div", { className: "sa-interrupt-actions", children: [
|
|
944
946
|
/* @__PURE__ */ d("button", { className: "sa-interrupt-btn sa-interrupt-btn-primary", disabled: !i, onClick: l, children: [
|
|
@@ -949,38 +951,38 @@ function Ee({ interrupt: a, onRespond: t }) {
|
|
|
949
951
|
] })
|
|
950
952
|
] });
|
|
951
953
|
}
|
|
952
|
-
function Ae(a, t,
|
|
954
|
+
function Ae(a, t, r) {
|
|
953
955
|
switch (a.type) {
|
|
954
956
|
case "textarea":
|
|
955
|
-
return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: t, onChange: (
|
|
957
|
+
return /* @__PURE__ */ e("textarea", { className: "sa-interrupt-textarea", value: t, onChange: (s) => r(s.target.value), placeholder: a.placeholder, rows: 3 });
|
|
956
958
|
case "select":
|
|
957
|
-
return /* @__PURE__ */ d("select", { className: "sa-interrupt-select", value: t, onChange: (
|
|
959
|
+
return /* @__PURE__ */ d("select", { className: "sa-interrupt-select", value: t, onChange: (s) => r(s.target.value), children: [
|
|
958
960
|
/* @__PURE__ */ e("option", { value: "", children: "请选择" }),
|
|
959
|
-
(a.options ?? []).map((
|
|
961
|
+
(a.options ?? []).map((s) => /* @__PURE__ */ e("option", { value: s, children: s }, s))
|
|
960
962
|
] });
|
|
961
963
|
default:
|
|
962
|
-
return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: a.type, value: t, onChange: (
|
|
964
|
+
return /* @__PURE__ */ e("input", { className: "sa-interrupt-input", type: a.type, value: t, onChange: (s) => r(s.target.value), placeholder: a.placeholder });
|
|
963
965
|
}
|
|
964
966
|
}
|
|
965
|
-
function $e({ interrupt: a, resolved: t, response:
|
|
967
|
+
function $e({ interrupt: a, resolved: t, response: r, onRespond: s }) {
|
|
966
968
|
if (t)
|
|
967
969
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-resolved", children: [
|
|
968
970
|
/* @__PURE__ */ e(C, { name: "circle-check", size: 14, color: "#10b981" }),
|
|
969
|
-
/* @__PURE__ */ e("span", { children: Pe(a.interruptType,
|
|
971
|
+
/* @__PURE__ */ e("span", { children: Pe(a.interruptType, r) })
|
|
970
972
|
] });
|
|
971
973
|
switch (a.interruptType) {
|
|
972
974
|
case "confirm":
|
|
973
|
-
return /* @__PURE__ */ e(ze, { interrupt: a, onRespond:
|
|
975
|
+
return /* @__PURE__ */ e(ze, { interrupt: a, onRespond: s });
|
|
974
976
|
case "approve":
|
|
975
|
-
return /* @__PURE__ */ e(Ie, { interrupt: a, onRespond:
|
|
977
|
+
return /* @__PURE__ */ e(Ie, { interrupt: a, onRespond: s });
|
|
976
978
|
case "select":
|
|
977
|
-
return /* @__PURE__ */ e(Se, { interrupt: a, onRespond:
|
|
979
|
+
return /* @__PURE__ */ e(Se, { interrupt: a, onRespond: s });
|
|
978
980
|
case "multiSelect":
|
|
979
|
-
return /* @__PURE__ */ e(
|
|
981
|
+
return /* @__PURE__ */ e(Le, { interrupt: a, onRespond: s });
|
|
980
982
|
case "input":
|
|
981
|
-
return /* @__PURE__ */ e(
|
|
983
|
+
return /* @__PURE__ */ e(De, { interrupt: a, onRespond: s });
|
|
982
984
|
case "form":
|
|
983
|
-
return /* @__PURE__ */ e(Ee, { interrupt: a, onRespond:
|
|
985
|
+
return /* @__PURE__ */ e(Ee, { interrupt: a, onRespond: s });
|
|
984
986
|
default:
|
|
985
987
|
return /* @__PURE__ */ d("div", { className: "sa-interrupt-unknown", children: [
|
|
986
988
|
"未知的交互类型: ",
|
|
@@ -1017,25 +1019,37 @@ const Oe = [
|
|
|
1017
1019
|
{ value: 5, label: "冗长啰嗦" },
|
|
1018
1020
|
{ value: 6, label: "难以理解" }
|
|
1019
1021
|
];
|
|
1020
|
-
function Re({ message: a, onCopy: t, onRegenerate:
|
|
1021
|
-
const { status:
|
|
1022
|
-
if (
|
|
1023
|
-
const
|
|
1024
|
-
t(),
|
|
1025
|
-
}, [t]), k =
|
|
1026
|
-
|
|
1027
|
-
}, [
|
|
1028
|
-
|
|
1029
|
-
}, [
|
|
1030
|
-
|
|
1031
|
-
}, [a.id,
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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);
|
|
1035
|
+
}, []);
|
|
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);
|
|
1042
|
+
};
|
|
1043
|
+
return document.addEventListener("mousedown", g), document.addEventListener("keydown", N), () => {
|
|
1044
|
+
document.removeEventListener("mousedown", g), document.removeEventListener("keydown", N);
|
|
1045
|
+
};
|
|
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 }),
|
|
1035
1049
|
" ",
|
|
1036
|
-
|
|
1050
|
+
c ? "已复制" : "复制"
|
|
1037
1051
|
] }),
|
|
1038
|
-
/* @__PURE__ */ d("button", { className: "sa-action-btn", onClick:
|
|
1052
|
+
/* @__PURE__ */ d("button", { className: "sa-action-btn", onClick: r, title: "重新生成", children: [
|
|
1039
1053
|
/* @__PURE__ */ e(C, { name: "refresh-cw", size: 14 }),
|
|
1040
1054
|
" 重新生成"
|
|
1041
1055
|
] }),
|
|
@@ -1043,7 +1057,7 @@ function Re({ message: a, onCopy: t, onRegenerate: s, onFeedback: r }) {
|
|
|
1043
1057
|
/* @__PURE__ */ e(
|
|
1044
1058
|
"button",
|
|
1045
1059
|
{
|
|
1046
|
-
className: `sa-action-btn ${
|
|
1060
|
+
className: `sa-action-btn ${i === "like" ? "sa-action-btn-active" : ""}`,
|
|
1047
1061
|
onClick: k,
|
|
1048
1062
|
title: "有用",
|
|
1049
1063
|
"aria-label": "点赞",
|
|
@@ -1053,31 +1067,27 @@ function Re({ message: a, onCopy: t, onRegenerate: s, onFeedback: r }) {
|
|
|
1053
1067
|
/* @__PURE__ */ e(
|
|
1054
1068
|
"button",
|
|
1055
1069
|
{
|
|
1056
|
-
className: `sa-action-btn ${
|
|
1057
|
-
onClick:
|
|
1070
|
+
className: `sa-action-btn ${i === "dislike" ? "sa-action-btn-active" : ""}`,
|
|
1071
|
+
onClick: b,
|
|
1058
1072
|
title: "无用",
|
|
1059
1073
|
"aria-label": "踩",
|
|
1074
|
+
"aria-expanded": f,
|
|
1075
|
+
"aria-haspopup": "dialog",
|
|
1060
1076
|
children: /* @__PURE__ */ e(C, { name: "thumbs-down", size: 14 })
|
|
1061
1077
|
}
|
|
1062
1078
|
),
|
|
1063
|
-
|
|
1064
|
-
Be,
|
|
1065
|
-
{
|
|
1066
|
-
onSubmit: b,
|
|
1067
|
-
onCancel: () => h(!1)
|
|
1068
|
-
}
|
|
1069
|
-
)
|
|
1079
|
+
f && /* @__PURE__ */ e("div", { ref: h, children: /* @__PURE__ */ e(Be, { onSubmit: v, onCancel: m }) })
|
|
1070
1080
|
] });
|
|
1071
1081
|
}
|
|
1072
1082
|
function Be({ onSubmit: a, onCancel: t }) {
|
|
1073
|
-
const [
|
|
1083
|
+
const [r, s] = T(void 0), [n, o] = T("");
|
|
1074
1084
|
return /* @__PURE__ */ d("div", { className: "sa-dislike-panel", children: [
|
|
1075
1085
|
/* @__PURE__ */ e("div", { className: "sa-dislike-panel-title", children: "请选择不满意的原因(可选)" }),
|
|
1076
1086
|
/* @__PURE__ */ e("div", { className: "sa-dislike-reasons", children: Oe.map((i) => /* @__PURE__ */ e(
|
|
1077
1087
|
"button",
|
|
1078
1088
|
{
|
|
1079
|
-
className: `sa-dislike-reason-btn ${
|
|
1080
|
-
onClick: () => r
|
|
1089
|
+
className: `sa-dislike-reason-btn ${r === i.value ? "active" : ""}`,
|
|
1090
|
+
onClick: () => s(r === i.value ? void 0 : i.value),
|
|
1081
1091
|
children: i.label
|
|
1082
1092
|
},
|
|
1083
1093
|
i.value
|
|
@@ -1094,118 +1104,118 @@ function Be({ onSubmit: a, onCancel: t }) {
|
|
|
1094
1104
|
}
|
|
1095
1105
|
),
|
|
1096
1106
|
/* @__PURE__ */ d("div", { className: "sa-dislike-actions", children: [
|
|
1097
|
-
/* @__PURE__ */ e("button", { className: "sa-dislike-submit", onClick: () => a(
|
|
1107
|
+
/* @__PURE__ */ e("button", { className: "sa-dislike-submit", onClick: () => a(r, n || void 0), children: "提交" }),
|
|
1098
1108
|
/* @__PURE__ */ e("button", { className: "sa-dislike-cancel", onClick: t, children: "取消" })
|
|
1099
1109
|
] })
|
|
1100
1110
|
] });
|
|
1101
1111
|
}
|
|
1102
1112
|
function Z({ src: a, role: t }) {
|
|
1103
|
-
const
|
|
1104
|
-
return a ? a.startsWith("http") || a.startsWith("/") || a.startsWith("data:") ? /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${t}`, children: /* @__PURE__ */ e("img", { src: a, alt: t, style: { width: "100%", height: "100%", borderRadius: "inherit", objectFit: "cover" } }) }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${t}`, children: a }) : /* @__PURE__ */ e("div", { className: `sa-avatar sa-avatar-${t}`, children:
|
|
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 });
|
|
1105
1115
|
}
|
|
1106
|
-
function
|
|
1107
|
-
const { regenerate: i, feedback: l, respondToInterrupt: c } =
|
|
1108
|
-
var
|
|
1109
|
-
const
|
|
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(`
|
|
1110
1120
|
`);
|
|
1111
|
-
(
|
|
1121
|
+
(N = navigator.clipboard) == null || N.writeText(g).catch(() => {
|
|
1112
1122
|
});
|
|
1113
|
-
}, [a]), f = a.role === "user", u =
|
|
1123
|
+
}, [a]), f = a.role === "user", u = s.Message;
|
|
1114
1124
|
if (u)
|
|
1115
1125
|
return /* @__PURE__ */ e(
|
|
1116
1126
|
u,
|
|
1117
1127
|
{
|
|
1118
1128
|
message: a,
|
|
1119
1129
|
isStreaming: t,
|
|
1120
|
-
isLast:
|
|
1130
|
+
isLast: r,
|
|
1121
1131
|
avatar: n,
|
|
1122
|
-
slots:
|
|
1132
|
+
slots: s,
|
|
1123
1133
|
onCopy: p,
|
|
1124
1134
|
onRegenerate: i,
|
|
1125
1135
|
onFeedback: l
|
|
1126
1136
|
}
|
|
1127
1137
|
);
|
|
1128
|
-
const h =
|
|
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;
|
|
1129
1139
|
return /* @__PURE__ */ d("div", { className: `sa-message ${f ? "sa-message-user" : "sa-message-assistant"}`, children: [
|
|
1130
1140
|
!f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.assistant, role: "assistant" }),
|
|
1131
1141
|
/* @__PURE__ */ d("div", { className: "sa-message-body", children: [
|
|
1132
|
-
a.parts.map((
|
|
1133
|
-
switch (
|
|
1142
|
+
a.parts.map((g, N) => {
|
|
1143
|
+
switch (g.type) {
|
|
1134
1144
|
case "text":
|
|
1135
|
-
return /* @__PURE__ */ e(h, { content:
|
|
1145
|
+
return /* @__PURE__ */ e(h, { content: g.content }, N);
|
|
1136
1146
|
case "thinking":
|
|
1137
|
-
return /* @__PURE__ */ e(
|
|
1147
|
+
return /* @__PURE__ */ e(w, { content: g.content }, N);
|
|
1138
1148
|
case "tool_call":
|
|
1139
|
-
return /* @__PURE__ */ e(k, { toolName:
|
|
1149
|
+
return /* @__PURE__ */ e(k, { toolName: g.toolName, toolCallId: g.toolCallId, args: g.args }, N);
|
|
1140
1150
|
case "tool_result":
|
|
1141
|
-
return /* @__PURE__ */ e(
|
|
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);
|
|
1142
1152
|
case "error":
|
|
1143
|
-
return /* @__PURE__ */ e(
|
|
1153
|
+
return /* @__PURE__ */ e(v, { content: g.content, onRetry: i }, N);
|
|
1144
1154
|
case "interrupt":
|
|
1145
1155
|
return /* @__PURE__ */ e(
|
|
1146
1156
|
$e,
|
|
1147
1157
|
{
|
|
1148
|
-
interrupt:
|
|
1149
|
-
resolved:
|
|
1150
|
-
response:
|
|
1151
|
-
onRespond: (
|
|
1158
|
+
interrupt: g.interrupt,
|
|
1159
|
+
resolved: g.resolved ?? !1,
|
|
1160
|
+
response: g.response,
|
|
1161
|
+
onRespond: (S) => c(g.interrupt.interruptId, S)
|
|
1152
1162
|
},
|
|
1153
|
-
|
|
1163
|
+
N
|
|
1154
1164
|
);
|
|
1155
1165
|
default:
|
|
1156
1166
|
return null;
|
|
1157
1167
|
}
|
|
1158
1168
|
}),
|
|
1159
|
-
t &&
|
|
1169
|
+
t && r && !f && /* @__PURE__ */ e("span", { className: "sa-streaming-cursor", children: "|" }),
|
|
1160
1170
|
!f && !t && a.parts.length > 0 && /* @__PURE__ */ e(m, { message: a, onCopy: p, onRegenerate: i, onFeedback: l })
|
|
1161
1171
|
] }),
|
|
1162
1172
|
f && /* @__PURE__ */ e(Z, { src: n == null ? void 0 : n.user, role: "user" })
|
|
1163
1173
|
] });
|
|
1164
1174
|
}
|
|
1165
|
-
function
|
|
1175
|
+
function He({ message: a, suggestedPrompts: t, onPromptClick: r }) {
|
|
1166
1176
|
return /* @__PURE__ */ d("div", { className: "sa-welcome", children: [
|
|
1167
1177
|
/* @__PURE__ */ e("div", { className: "sa-welcome-icon", children: /* @__PURE__ */ e(C, { name: "sparkles", size: 40 }) }),
|
|
1168
1178
|
/* @__PURE__ */ e("p", { className: "sa-welcome-message", children: a || "你好!有什么可以帮你的?" }),
|
|
1169
|
-
t && t.length > 0 && /* @__PURE__ */ e("div", { className: "sa-welcome-prompts", children: t.map((
|
|
1179
|
+
t && t.length > 0 && /* @__PURE__ */ e("div", { className: "sa-welcome-prompts", children: t.map((s, n) => /* @__PURE__ */ e(
|
|
1170
1180
|
"button",
|
|
1171
1181
|
{
|
|
1172
1182
|
className: "sa-welcome-prompt",
|
|
1173
|
-
onClick: () => s
|
|
1174
|
-
children:
|
|
1183
|
+
onClick: () => r(s),
|
|
1184
|
+
children: s
|
|
1175
1185
|
},
|
|
1176
1186
|
n
|
|
1177
1187
|
)) })
|
|
1178
1188
|
] });
|
|
1179
1189
|
}
|
|
1180
|
-
function re({ slots: a, welcomeMessage: t, suggestedPrompts:
|
|
1181
|
-
const { messages: o, status: i, sendMessage: l } =
|
|
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;
|
|
1182
1192
|
return o.length === 0 ? /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: /* @__PURE__ */ e(
|
|
1183
1193
|
f,
|
|
1184
1194
|
{
|
|
1185
1195
|
message: t,
|
|
1186
|
-
suggestedPrompts:
|
|
1196
|
+
suggestedPrompts: r,
|
|
1187
1197
|
onPromptClick: l
|
|
1188
1198
|
}
|
|
1189
1199
|
) }) : /* @__PURE__ */ e("div", { className: "sa-thread", ref: c, children: o.map((u, h) => /* @__PURE__ */ e(
|
|
1190
|
-
|
|
1200
|
+
Fe,
|
|
1191
1201
|
{
|
|
1192
1202
|
message: u,
|
|
1193
1203
|
isStreaming: p,
|
|
1194
1204
|
isLast: h === o.length - 1,
|
|
1195
1205
|
slots: a,
|
|
1196
|
-
avatar:
|
|
1206
|
+
avatar: s,
|
|
1197
1207
|
artifactPreview: n
|
|
1198
1208
|
},
|
|
1199
1209
|
u.id
|
|
1200
1210
|
)) });
|
|
1201
1211
|
}
|
|
1202
1212
|
function se() {
|
|
1203
|
-
const { status: a, sendMessage: t, stop:
|
|
1204
|
-
const f =
|
|
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();
|
|
1205
1215
|
!f || i || (t(f), n(""), o.current && (o.current.style.height = "auto"));
|
|
1206
|
-
}, [
|
|
1216
|
+
}, [s, i, t]), c = I((f) => {
|
|
1207
1217
|
f.key === "Enter" && !f.shiftKey && (f.preventDefault(), l());
|
|
1208
|
-
}, [l]), p =
|
|
1218
|
+
}, [l]), p = I((f) => {
|
|
1209
1219
|
n(f.target.value);
|
|
1210
1220
|
const u = f.target;
|
|
1211
1221
|
u.style.height = "auto", u.style.height = Math.min(u.scrollHeight, 120) + "px";
|
|
@@ -1216,7 +1226,7 @@ function se() {
|
|
|
1216
1226
|
{
|
|
1217
1227
|
ref: o,
|
|
1218
1228
|
className: "sa-composer-input",
|
|
1219
|
-
value:
|
|
1229
|
+
value: s,
|
|
1220
1230
|
onChange: p,
|
|
1221
1231
|
onKeyDown: c,
|
|
1222
1232
|
placeholder: "输入消息...",
|
|
@@ -1224,23 +1234,23 @@ function se() {
|
|
|
1224
1234
|
disabled: a === "submitted"
|
|
1225
1235
|
}
|
|
1226
1236
|
),
|
|
1227
|
-
i ? /* @__PURE__ */ e("button", { className: "sa-composer-stop", onClick:
|
|
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(
|
|
1228
1238
|
"button",
|
|
1229
1239
|
{
|
|
1230
1240
|
className: "sa-composer-send",
|
|
1231
1241
|
onClick: l,
|
|
1232
|
-
disabled: !
|
|
1242
|
+
disabled: !s.trim(),
|
|
1233
1243
|
title: "发送",
|
|
1234
1244
|
children: /* @__PURE__ */ e(C, { name: "arrow-up", size: 16, color: "#fff" })
|
|
1235
1245
|
}
|
|
1236
1246
|
)
|
|
1237
1247
|
] });
|
|
1238
1248
|
}
|
|
1239
|
-
function
|
|
1240
|
-
const [t,
|
|
1249
|
+
function je({ artifact: a }) {
|
|
1250
|
+
const [t, r] = Y.useState(null), [s, n] = Y.useState(!0), [o, i] = Y.useState(null);
|
|
1241
1251
|
return Y.useEffect(() => {
|
|
1242
1252
|
let l = !1;
|
|
1243
|
-
n(!0), i(null),
|
|
1253
|
+
n(!0), i(null), r(null);
|
|
1244
1254
|
async function c() {
|
|
1245
1255
|
try {
|
|
1246
1256
|
if (a.type === "pdf") {
|
|
@@ -1251,14 +1261,14 @@ function _e({ artifact: a }) {
|
|
|
1251
1261
|
const p = await fetch(a.url);
|
|
1252
1262
|
if (!p.ok) throw new Error(`HTTP ${p.status}`);
|
|
1253
1263
|
const f = await p.text(), u = (await import("./purify.es-C-6FFqDW.js")).default;
|
|
1254
|
-
l || (
|
|
1264
|
+
l || (r(u.sanitize(f, { FORCE_BODY: !0 })), n(!1));
|
|
1255
1265
|
return;
|
|
1256
1266
|
}
|
|
1257
1267
|
if (a.type === "docx") {
|
|
1258
1268
|
const p = await fetch(a.url);
|
|
1259
1269
|
if (!p.ok) throw new Error(`HTTP ${p.status}`);
|
|
1260
|
-
const f = await p.arrayBuffer(), h = await (await import("./mammoth.browser-COPV53yV.js").then((k) => k.m)).convertToHtml({ arrayBuffer: f }),
|
|
1261
|
-
l || (
|
|
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));
|
|
1262
1272
|
return;
|
|
1263
1273
|
}
|
|
1264
1274
|
l || (n(!1), i(`不支持预览「${a.type}」类型`));
|
|
@@ -1269,54 +1279,54 @@ function _e({ artifact: a }) {
|
|
|
1269
1279
|
return c(), () => {
|
|
1270
1280
|
l = !0;
|
|
1271
1281
|
};
|
|
1272
|
-
}, [a]),
|
|
1282
|
+
}, [a]), s ? /* @__PURE__ */ e("div", { className: "sa-drawer-preview-loading", children: "加载中" }) : o ? /* @__PURE__ */ d("div", { className: "sa-drawer-preview-error", children: [
|
|
1273
1283
|
o,
|
|
1274
1284
|
/* @__PURE__ */ e("button", { className: "sa-drawer-btn-sm", onClick: () => void U(a), children: "下载查看" })
|
|
1275
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;
|
|
1276
1286
|
}
|
|
1277
|
-
function ne({ artifacts: a, initialArtifact: t, onClose:
|
|
1278
|
-
const [
|
|
1287
|
+
function ne({ artifacts: a, initialArtifact: t, onClose: r }) {
|
|
1288
|
+
const [s, n] = T(
|
|
1279
1289
|
t ? { mode: "preview", artifact: t } : { mode: "list" }
|
|
1280
|
-
), [o, i] = T(!1), l =
|
|
1281
|
-
|
|
1290
|
+
), [o, i] = T(!1), l = F(null), [c, p] = T(340), f = F(null);
|
|
1291
|
+
R(() => {
|
|
1282
1292
|
t && (l.current && (clearTimeout(l.current), l.current = null, i(!1)), n({ mode: "preview", artifact: t }));
|
|
1283
1293
|
}, [t]);
|
|
1284
|
-
const u =
|
|
1294
|
+
const u = I(() => {
|
|
1285
1295
|
i(!0), l.current = setTimeout(() => {
|
|
1286
|
-
l.current = null,
|
|
1296
|
+
l.current = null, r();
|
|
1287
1297
|
}, 240);
|
|
1288
|
-
}, [
|
|
1289
|
-
|
|
1290
|
-
var
|
|
1291
|
-
l.current && clearTimeout(l.current), (
|
|
1298
|
+
}, [r]);
|
|
1299
|
+
R(() => () => {
|
|
1300
|
+
var b;
|
|
1301
|
+
l.current && clearTimeout(l.current), (b = f.current) == null || b.call(f);
|
|
1292
1302
|
}, []);
|
|
1293
|
-
const h =
|
|
1294
|
-
n({ mode: "preview", artifact:
|
|
1295
|
-
}, []),
|
|
1303
|
+
const h = I((b) => {
|
|
1304
|
+
n({ mode: "preview", artifact: b });
|
|
1305
|
+
}, []), w = I(() => {
|
|
1296
1306
|
n({ mode: "list" });
|
|
1297
1307
|
}, []);
|
|
1298
|
-
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1308
|
+
R(() => {
|
|
1309
|
+
const b = (v) => {
|
|
1310
|
+
v.key === "Escape" && u();
|
|
1301
1311
|
};
|
|
1302
|
-
return document.addEventListener("keydown",
|
|
1312
|
+
return document.addEventListener("keydown", b), () => document.removeEventListener("keydown", b);
|
|
1303
1313
|
}, [u]);
|
|
1304
|
-
const k =
|
|
1305
|
-
|
|
1306
|
-
const
|
|
1307
|
-
const
|
|
1308
|
-
p(Math.max(240, Math.min(window.innerWidth * 0.7, m +
|
|
1309
|
-
},
|
|
1310
|
-
document.removeEventListener("mousemove",
|
|
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;
|
|
1311
1321
|
};
|
|
1312
|
-
document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove",
|
|
1322
|
+
document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", g), document.addEventListener("mouseup", N), f.current = N;
|
|
1313
1323
|
}, [c]);
|
|
1314
1324
|
return /* @__PURE__ */ d("div", { className: `sa-artifact-drawer ${o ? "sa-drawer-closing" : ""}`, style: { width: c }, children: [
|
|
1315
1325
|
/* @__PURE__ */ e("div", { className: "sa-drawer-resize-handle", onMouseDown: k }),
|
|
1316
1326
|
/* @__PURE__ */ d("div", { className: "sa-artifact-drawer-header", children: [
|
|
1317
|
-
|
|
1318
|
-
/* @__PURE__ */ e("button", { className: "sa-drawer-btn", onClick:
|
|
1319
|
-
/* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", 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 })
|
|
1320
1330
|
] }) : /* @__PURE__ */ d(q, { children: [
|
|
1321
1331
|
/* @__PURE__ */ d("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { flexShrink: 0 }, children: [
|
|
1322
1332
|
/* @__PURE__ */ e("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
|
|
@@ -1325,103 +1335,103 @@ function ne({ artifacts: a, initialArtifact: t, onClose: s }) {
|
|
|
1325
1335
|
/* @__PURE__ */ e("span", { className: "sa-artifact-drawer-title", children: "会话产物" })
|
|
1326
1336
|
] }),
|
|
1327
1337
|
/* @__PURE__ */ e("div", { style: { flex: 1 } }),
|
|
1328
|
-
|
|
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" }) }) }),
|
|
1329
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" }) }) })
|
|
1330
1340
|
] }),
|
|
1331
|
-
/* @__PURE__ */ e("div", { className: "sa-artifact-drawer-body", children:
|
|
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(
|
|
1332
1342
|
"li",
|
|
1333
1343
|
{
|
|
1334
1344
|
className: "sa-drawer-file-card",
|
|
1335
|
-
onClick: () => h(
|
|
1345
|
+
onClick: () => h(b),
|
|
1336
1346
|
onKeyDown: (m) => {
|
|
1337
|
-
(m.key === "Enter" || m.key === " ") && (m.preventDefault(), h(
|
|
1347
|
+
(m.key === "Enter" || m.key === " ") && (m.preventDefault(), h(b));
|
|
1338
1348
|
},
|
|
1339
1349
|
tabIndex: 0,
|
|
1340
1350
|
role: "button",
|
|
1341
|
-
"aria-label": `预览 ${
|
|
1351
|
+
"aria-label": `预览 ${b.filename}`,
|
|
1342
1352
|
children: [
|
|
1343
|
-
/* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(
|
|
1353
|
+
/* @__PURE__ */ e("div", { className: "sa-drawer-file-icon", children: /* @__PURE__ */ e("span", { className: "sa-artifact-chip-type", children: ee(b.type) }) }),
|
|
1344
1354
|
/* @__PURE__ */ d("div", { className: "sa-drawer-file-info", children: [
|
|
1345
|
-
/* @__PURE__ */ e("span", { className: "sa-drawer-file-name", children:
|
|
1346
|
-
/* @__PURE__ */ e("span", { className: "sa-drawer-file-size", children: Q(
|
|
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) })
|
|
1347
1357
|
] }),
|
|
1348
1358
|
/* @__PURE__ */ e(
|
|
1349
1359
|
"button",
|
|
1350
1360
|
{
|
|
1351
1361
|
className: "sa-drawer-btn",
|
|
1352
1362
|
title: "下载",
|
|
1353
|
-
"aria-label": `下载 ${
|
|
1363
|
+
"aria-label": `下载 ${b.filename}`,
|
|
1354
1364
|
onClick: (m) => {
|
|
1355
|
-
m.stopPropagation(), U(
|
|
1365
|
+
m.stopPropagation(), U(b);
|
|
1356
1366
|
},
|
|
1357
1367
|
children: /* @__PURE__ */ e("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ e("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M7 10l5 5 5-5M12 15V3" }) })
|
|
1358
1368
|
}
|
|
1359
1369
|
)
|
|
1360
1370
|
]
|
|
1361
1371
|
},
|
|
1362
|
-
|
|
1363
|
-
)) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(
|
|
1372
|
+
b.id || `artifact-${v}`
|
|
1373
|
+
)) }) : /* @__PURE__ */ e("div", { className: "sa-drawer-view-enter", children: /* @__PURE__ */ e(je, { artifact: s.artifact }) }) })
|
|
1364
1374
|
] });
|
|
1365
1375
|
}
|
|
1366
|
-
function
|
|
1367
|
-
const { status: c, sendMessage: p, stop: f, toggleThreadList: u, toggleArtifactDrawer: h, conversations:
|
|
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();
|
|
1368
1378
|
if (!a) return null;
|
|
1369
|
-
const y =
|
|
1379
|
+
const y = s.Header, D = s.Composer, P = s.ThreadList;
|
|
1370
1380
|
return /* @__PURE__ */ d("div", { className: "sa-panel", children: [
|
|
1371
|
-
y ? /* @__PURE__ */ e(y, { title:
|
|
1381
|
+
y ? /* @__PURE__ */ e(y, { title: r, onClose: t, onToggleThreadList: u }) : /* @__PURE__ */ e(
|
|
1372
1382
|
ue,
|
|
1373
1383
|
{
|
|
1374
|
-
title:
|
|
1384
|
+
title: r,
|
|
1375
1385
|
onClose: t,
|
|
1376
1386
|
onToggleThreadList: u,
|
|
1377
|
-
artifactCount: l ?
|
|
1387
|
+
artifactCount: l ? L.length : 0,
|
|
1378
1388
|
onToggleArtifactDrawer: l ? h : void 0
|
|
1379
1389
|
}
|
|
1380
1390
|
),
|
|
1381
|
-
|
|
1382
|
-
|
|
1391
|
+
P && N ? /* @__PURE__ */ e(
|
|
1392
|
+
P,
|
|
1383
1393
|
{
|
|
1384
|
-
conversations:
|
|
1394
|
+
conversations: w,
|
|
1385
1395
|
activeSessionId: k,
|
|
1386
|
-
onSwitch:
|
|
1387
|
-
onNew:
|
|
1396
|
+
onSwitch: b,
|
|
1397
|
+
onNew: v,
|
|
1388
1398
|
onDelete: m,
|
|
1389
|
-
onRename:
|
|
1399
|
+
onRename: g
|
|
1390
1400
|
}
|
|
1391
1401
|
) : /* @__PURE__ */ e(he, {}),
|
|
1392
1402
|
/* @__PURE__ */ d("div", { className: "sa-panel-content", children: [
|
|
1393
|
-
/* @__PURE__ */ e(re, { slots:
|
|
1394
|
-
l &&
|
|
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 })
|
|
1395
1405
|
] }),
|
|
1396
|
-
|
|
1406
|
+
D ? /* @__PURE__ */ e(D, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
|
|
1397
1407
|
] });
|
|
1398
1408
|
}
|
|
1399
|
-
function
|
|
1409
|
+
function We({
|
|
1400
1410
|
conversations: a,
|
|
1401
1411
|
activeSessionId: t,
|
|
1402
|
-
onSwitch:
|
|
1403
|
-
onNew:
|
|
1412
|
+
onSwitch: r,
|
|
1413
|
+
onNew: s,
|
|
1404
1414
|
onDelete: n,
|
|
1405
1415
|
isCollapsed: o,
|
|
1406
1416
|
onToggleCollapse: i
|
|
1407
1417
|
}) {
|
|
1408
|
-
const [l, c] = T(null), [p, f] = T(null), u =
|
|
1409
|
-
k.stopPropagation(), p ===
|
|
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));
|
|
1410
1420
|
}, [p, n]), h = (() => {
|
|
1411
|
-
const
|
|
1412
|
-
for (const
|
|
1413
|
-
const
|
|
1414
|
-
|
|
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);
|
|
1415
1425
|
}
|
|
1416
1426
|
const m = [];
|
|
1417
|
-
return k.length && m.push({ label: "今天", items: k }),
|
|
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;
|
|
1418
1428
|
})();
|
|
1419
1429
|
return o ? /* @__PURE__ */ d("div", { className: "sa-fp-sidebar sa-fp-sidebar-collapsed", children: [
|
|
1420
1430
|
/* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: i, title: "展开", children: /* @__PURE__ */ e(C, { name: "panel-left", size: 18 }) }),
|
|
1421
|
-
/* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick:
|
|
1431
|
+
/* @__PURE__ */ e("button", { className: "sa-fp-sidebar-toggle", onClick: s, title: "新会话", style: { marginTop: 4 }, children: /* @__PURE__ */ e(C, { name: "plus", size: 18 }) })
|
|
1422
1432
|
] }) : /* @__PURE__ */ d("div", { className: "sa-fp-sidebar", children: [
|
|
1423
1433
|
/* @__PURE__ */ d("div", { className: "sa-fp-sidebar-header", children: [
|
|
1424
|
-
/* @__PURE__ */ d("button", { className: "sa-fp-sidebar-new", onClick:
|
|
1434
|
+
/* @__PURE__ */ d("button", { className: "sa-fp-sidebar-new", onClick: s, children: [
|
|
1425
1435
|
/* @__PURE__ */ e(C, { name: "plus", size: 15 }),
|
|
1426
1436
|
" ",
|
|
1427
1437
|
/* @__PURE__ */ e("span", { children: "新会话" })
|
|
@@ -1430,24 +1440,24 @@ function Fe({
|
|
|
1430
1440
|
] }),
|
|
1431
1441
|
/* @__PURE__ */ d("div", { className: "sa-fp-sidebar-list", children: [
|
|
1432
1442
|
a.length === 0 && /* @__PURE__ */ e("div", { className: "sa-fp-sidebar-empty", children: "开始你的第一个对话" }),
|
|
1433
|
-
h.map((
|
|
1434
|
-
/* @__PURE__ */ e("div", { className: "sa-fp-sidebar-group", children:
|
|
1435
|
-
|
|
1436
|
-
const
|
|
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;
|
|
1437
1447
|
return /* @__PURE__ */ d(
|
|
1438
1448
|
"div",
|
|
1439
1449
|
{
|
|
1440
|
-
className: `sa-fp-sidebar-item ${
|
|
1441
|
-
onClick: () =>
|
|
1450
|
+
className: `sa-fp-sidebar-item ${b ? "active" : ""}`,
|
|
1451
|
+
onClick: () => r(k.sessionId),
|
|
1442
1452
|
onMouseEnter: () => c(k.sessionId),
|
|
1443
1453
|
onMouseLeave: () => c(null),
|
|
1444
1454
|
children: [
|
|
1445
1455
|
/* @__PURE__ */ e("span", { className: "sa-fp-sidebar-item-title", children: k.title || "新会话" }),
|
|
1446
|
-
|
|
1456
|
+
v && /* @__PURE__ */ e(
|
|
1447
1457
|
"button",
|
|
1448
1458
|
{
|
|
1449
1459
|
className: `sa-fp-sidebar-item-action ${m ? "danger" : ""}`,
|
|
1450
|
-
onClick: (
|
|
1460
|
+
onClick: (g) => u(k.sessionId, g),
|
|
1451
1461
|
title: m ? "确认删除" : "删除",
|
|
1452
1462
|
children: /* @__PURE__ */ e(C, { name: m ? "x" : "trash2", size: 14 })
|
|
1453
1463
|
}
|
|
@@ -1457,56 +1467,56 @@ function Fe({
|
|
|
1457
1467
|
k.sessionId
|
|
1458
1468
|
);
|
|
1459
1469
|
})
|
|
1460
|
-
] },
|
|
1470
|
+
] }, w.label))
|
|
1461
1471
|
] })
|
|
1462
1472
|
] });
|
|
1463
1473
|
}
|
|
1464
|
-
function Ye({ title: a, slots: t, welcomeMessage:
|
|
1474
|
+
function Ye({ title: a, slots: t, welcomeMessage: r, suggestedPrompts: s, sidebarDefaultOpen: n = !0, onClose: o, avatar: i, artifactPreview: l }) {
|
|
1465
1475
|
const {
|
|
1466
1476
|
status: c,
|
|
1467
1477
|
sendMessage: p,
|
|
1468
1478
|
stop: f,
|
|
1469
1479
|
conversations: u,
|
|
1470
1480
|
activeConversationId: h,
|
|
1471
|
-
switchConversation:
|
|
1481
|
+
switchConversation: w,
|
|
1472
1482
|
newConversation: k,
|
|
1473
|
-
deleteConversation:
|
|
1474
|
-
renameConversation:
|
|
1483
|
+
deleteConversation: b,
|
|
1484
|
+
renameConversation: v,
|
|
1475
1485
|
toggleArtifactDrawer: m,
|
|
1476
|
-
isArtifactDrawerOpen:
|
|
1477
|
-
allArtifacts:
|
|
1478
|
-
activePreviewArtifact:
|
|
1479
|
-
} =
|
|
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;
|
|
1480
1490
|
return /* @__PURE__ */ d("div", { className: "sa-fullpage", children: [
|
|
1481
|
-
|
|
1482
|
-
|
|
1491
|
+
D ? /* @__PURE__ */ e("div", { className: `sa-fp-sidebar-wrapper ${L ? "" : "sa-fp-sidebar-wrapper-collapsed"}`, children: /* @__PURE__ */ e(
|
|
1492
|
+
D,
|
|
1483
1493
|
{
|
|
1484
1494
|
conversations: u,
|
|
1485
1495
|
activeSessionId: h,
|
|
1486
|
-
onSwitch:
|
|
1496
|
+
onSwitch: w,
|
|
1487
1497
|
onNew: k,
|
|
1488
|
-
onDelete:
|
|
1489
|
-
onRename:
|
|
1498
|
+
onDelete: b,
|
|
1499
|
+
onRename: v
|
|
1490
1500
|
}
|
|
1491
1501
|
) }) : /* @__PURE__ */ e(
|
|
1492
|
-
|
|
1502
|
+
We,
|
|
1493
1503
|
{
|
|
1494
1504
|
conversations: u,
|
|
1495
1505
|
activeSessionId: h,
|
|
1496
|
-
onSwitch:
|
|
1506
|
+
onSwitch: w,
|
|
1497
1507
|
onNew: k,
|
|
1498
|
-
onDelete:
|
|
1499
|
-
onRename:
|
|
1500
|
-
isCollapsed: !
|
|
1508
|
+
onDelete: b,
|
|
1509
|
+
onRename: v,
|
|
1510
|
+
isCollapsed: !L,
|
|
1501
1511
|
onToggleCollapse: y
|
|
1502
1512
|
}
|
|
1503
1513
|
),
|
|
1504
1514
|
/* @__PURE__ */ d("div", { className: "sa-fp-main", children: [
|
|
1505
1515
|
/* @__PURE__ */ d("div", { className: "sa-fp-header", children: [
|
|
1506
|
-
!
|
|
1516
|
+
!L && !D && /* @__PURE__ */ e("button", { className: "sa-fp-header-btn", onClick: y, title: "展开侧边栏", children: /* @__PURE__ */ e(C, { name: "panel-left", size: 18 }) }),
|
|
1507
1517
|
/* @__PURE__ */ e("div", { className: "sa-fp-header-title", children: a }),
|
|
1508
1518
|
/* @__PURE__ */ d("div", { className: "sa-fp-header-actions", children: [
|
|
1509
|
-
l &&
|
|
1519
|
+
l && N.length > 0 && /* @__PURE__ */ d("button", { className: "sa-fp-header-btn sa-header-btn-artifact", onClick: m, title: "会话产物", children: [
|
|
1510
1520
|
/* @__PURE__ */ d("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
1511
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" }),
|
|
1512
1522
|
/* @__PURE__ */ e("polyline", { points: "14 2 14 8 20 8" })
|
|
@@ -1517,47 +1527,47 @@ function Ye({ title: a, slots: t, welcomeMessage: s, suggestedPrompts: r, sideba
|
|
|
1517
1527
|
] })
|
|
1518
1528
|
] }),
|
|
1519
1529
|
/* @__PURE__ */ d("div", { className: "sa-fp-content-row", children: [
|
|
1520
|
-
/* @__PURE__ */ e(re, { slots: t, welcomeMessage:
|
|
1521
|
-
l &&
|
|
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 })
|
|
1522
1532
|
] }),
|
|
1523
|
-
|
|
1533
|
+
P ? /* @__PURE__ */ e(P, { status: c, onSend: p, onStop: f }) : /* @__PURE__ */ e(se, {})
|
|
1524
1534
|
] })
|
|
1525
1535
|
] });
|
|
1526
1536
|
}
|
|
1527
1537
|
function Ke(a) {
|
|
1528
|
-
const { sdk: t, mode:
|
|
1529
|
-
|
|
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(() => {
|
|
1530
1540
|
k(c);
|
|
1531
1541
|
}, [c]);
|
|
1532
|
-
const
|
|
1533
|
-
var
|
|
1534
|
-
const
|
|
1535
|
-
k(
|
|
1536
|
-
}, [
|
|
1537
|
-
var
|
|
1538
|
-
k(!1), p == null || p(!1), (
|
|
1539
|
-
}, [n, p]), m =
|
|
1540
|
-
return
|
|
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(
|
|
1541
1551
|
Ye,
|
|
1542
1552
|
{
|
|
1543
1553
|
title: l,
|
|
1544
|
-
slots:
|
|
1554
|
+
slots: s,
|
|
1545
1555
|
welcomeMessage: o,
|
|
1546
1556
|
suggestedPrompts: i,
|
|
1547
1557
|
sidebarDefaultOpen: f,
|
|
1548
|
-
onClose:
|
|
1558
|
+
onClose: v,
|
|
1549
1559
|
avatar: u,
|
|
1550
1560
|
artifactPreview: h
|
|
1551
1561
|
}
|
|
1552
1562
|
) }) : null : /* @__PURE__ */ d(G, { sdk: t, hooks: n, children: [
|
|
1553
|
-
/* @__PURE__ */ e(m, { isOpen:
|
|
1563
|
+
/* @__PURE__ */ e(m, { isOpen: w, onClick: b }),
|
|
1554
1564
|
/* @__PURE__ */ e(
|
|
1555
|
-
|
|
1565
|
+
_e,
|
|
1556
1566
|
{
|
|
1557
|
-
isOpen:
|
|
1558
|
-
onClose:
|
|
1567
|
+
isOpen: w,
|
|
1568
|
+
onClose: v,
|
|
1559
1569
|
title: l,
|
|
1560
|
-
slots:
|
|
1570
|
+
slots: s,
|
|
1561
1571
|
welcomeMessage: o,
|
|
1562
1572
|
suggestedPrompts: i,
|
|
1563
1573
|
avatar: u,
|
|
@@ -2124,8 +2134,8 @@ const Ue = `
|
|
|
2124
2134
|
|
|
2125
2135
|
/* ── Dislike Panel ── */
|
|
2126
2136
|
.sa-dislike-panel {
|
|
2127
|
-
position: absolute;
|
|
2128
|
-
margin-
|
|
2137
|
+
position: absolute; top: 100%; left: 0; right: 0;
|
|
2138
|
+
margin-top: 6px; padding: 12px;
|
|
2129
2139
|
background: #fff; border: 1px solid var(--sa-border); border-radius: 10px;
|
|
2130
2140
|
box-shadow: 0 4px 16px rgba(0,0,0,0.08);
|
|
2131
2141
|
animation: sa-fade-in-up 0.2s cubic-bezier(0.16,1,0.3,1) both;
|
|
@@ -3117,17 +3127,17 @@ function qe(a) {
|
|
|
3117
3127
|
].join("; ");
|
|
3118
3128
|
}
|
|
3119
3129
|
function Ze(a, t) {
|
|
3120
|
-
const
|
|
3121
|
-
if (!
|
|
3130
|
+
const r = typeof a == "string" ? document.querySelector(a) : a;
|
|
3131
|
+
if (!r)
|
|
3122
3132
|
throw new Error(`Target element not found: ${a}`);
|
|
3123
|
-
const
|
|
3124
|
-
|
|
3133
|
+
const s = document.createElement("div");
|
|
3134
|
+
s.setAttribute("data-super-agent-widget", "");
|
|
3125
3135
|
const n = qe(t.theme ?? {});
|
|
3126
|
-
if (
|
|
3136
|
+
if (s.setAttribute("style", n), r.appendChild(s), !document.getElementById("sa-widget-styles")) {
|
|
3127
3137
|
const c = document.createElement("style");
|
|
3128
3138
|
c.id = "sa-widget-styles", c.textContent = Ue, document.head.appendChild(c);
|
|
3129
3139
|
}
|
|
3130
|
-
let o = le(
|
|
3140
|
+
let o = le(s), i = !1;
|
|
3131
3141
|
const l = (c) => {
|
|
3132
3142
|
o && o.render(
|
|
3133
3143
|
Y.createElement(Ke, {
|
|
@@ -3147,7 +3157,7 @@ function Ze(a, t) {
|
|
|
3147
3157
|
i = !1, l(!1);
|
|
3148
3158
|
},
|
|
3149
3159
|
destroy() {
|
|
3150
|
-
o && (o.unmount(), o = null),
|
|
3160
|
+
o && (o.unmount(), o = null), s.remove();
|
|
3151
3161
|
}
|
|
3152
3162
|
};
|
|
3153
3163
|
}
|
|
@@ -3161,7 +3171,7 @@ export {
|
|
|
3161
3171
|
ue as Header,
|
|
3162
3172
|
C as Icon,
|
|
3163
3173
|
$e as InterruptCard,
|
|
3164
|
-
|
|
3174
|
+
Fe as Message,
|
|
3165
3175
|
ve as TextPart,
|
|
3166
3176
|
we as ThinkingPart,
|
|
3167
3177
|
re as Thread,
|
|
@@ -3169,13 +3179,13 @@ export {
|
|
|
3169
3179
|
ye as ToolCallPart,
|
|
3170
3180
|
Ce as ToolResultPart,
|
|
3171
3181
|
fe as Trigger,
|
|
3172
|
-
|
|
3182
|
+
He as WelcomeScreen,
|
|
3173
3183
|
Ve as defaultTheme,
|
|
3174
3184
|
Ze as mount,
|
|
3175
3185
|
qe as themeToCSSVars,
|
|
3176
3186
|
ge as useAutoScroll,
|
|
3177
3187
|
ce as useChat,
|
|
3178
|
-
|
|
3188
|
+
W as useChatContext,
|
|
3179
3189
|
pe as useConversations,
|
|
3180
3190
|
Ue as widgetStyles
|
|
3181
3191
|
};
|