@somecat/ai-assist-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,962 @@
1
+ import { defineComponent as gt, ref as y, reactive as nt, computed as ht, watch as Ht, nextTick as St, onUnmounted as bt, onMounted as J, openBlock as l, createElementBlock as v, createElementVNode as e, toDisplayString as P, unref as R, Fragment as st, renderList as ut, createCommentVNode as W, normalizeClass as ot, createStaticVNode as Yt, withDirectives as Tt, withKeys as jt, vModelText as Pt, withModifiers as Mt, createBlock as ft, Teleport as Vt, vShow as xt, normalizeStyle as Jt, createApp as Zt } from "vue";
2
+ import { g as mt, f as It, c as te, r as Nt, p as Dt, s as ee, u as se, a as ne, b as oe, d as ae, e as ie, h as le, i as ce, j as re, k as ue, l as Lt } from "../chunks/index-CGfAEdrA.mjs";
3
+ import { r as Ct, s as ve, a as de, b as pe, f as he, c as fe, d as ge, h as me, e as ye, g as _e, i as ke, j as we } from "../chunks/index-Dlj6re41.mjs";
4
+ const Ce = { class: "container" }, Se = { class: "message ai-message greet-message" }, be = { class: "ai-greet" }, Te = {
5
+ key: 0,
6
+ class: "message ai-message recommend-message"
7
+ }, $e = { class: "ai-recommend" }, Ae = { class: "recommend-header" }, Ee = ["src"], Re = ["onClick"], Me = {
8
+ key: 0,
9
+ class: "message-content ba-markdown"
10
+ }, Ne = {
11
+ key: 0,
12
+ class: "agent-thought"
13
+ }, De = { class: "agent-thought__text" }, He = ["onClick"], Pe = { class: "thinking-block__title" }, Le = {
14
+ key: 0,
15
+ class: "thinking-block__content"
16
+ }, Oe = { key: 2 }, We = ["innerHTML"], Ge = {
17
+ key: 0,
18
+ class: "streaming-cursor"
19
+ }, Be = ["innerHTML"], Xe = {
20
+ key: 0,
21
+ class: "streaming-cursor"
22
+ }, Ke = {
23
+ key: 3,
24
+ class: "message-error"
25
+ }, qe = {
26
+ key: 4,
27
+ class: "message-cost"
28
+ }, Qe = { class: "status-indicator" }, Ue = ["onClick"], Fe = {
29
+ key: 1,
30
+ class: "message-content"
31
+ }, ze = { class: "input-container" }, Ye = {
32
+ key: 0,
33
+ class: "tooltip-enhanced",
34
+ "data-tooltip": "重新回答"
35
+ }, je = ["src"], Ve = ["src"], xe = ["disabled"], Je = {
36
+ key: 2,
37
+ class: "tooltip-enhanced stop",
38
+ "data-tooltip": "停止回答"
39
+ }, Ze = ["src"], Ie = {
40
+ key: 3,
41
+ class: "tooltip-enhanced send",
42
+ "data-tooltip": "开始回答"
43
+ }, ts = ["src"], es = {
44
+ key: 4,
45
+ class: "moveTB"
46
+ }, ss = ["src"], ns = /* @__PURE__ */ gt({
47
+ __name: "Answer",
48
+ props: {
49
+ defaultSayhello: {},
50
+ defaultRecommend: {}
51
+ },
52
+ setup(G, { expose: L }) {
53
+ const a = {
54
+ THINKING: "thinking",
55
+ RETHINKING: "rethinking",
56
+ ANSWERING: "answering",
57
+ PAUSED: "paused",
58
+ COMPLETED: "completed",
59
+ STOP: "stop",
60
+ ERROR: "error"
61
+ }, B = G, _ = mt(), g = _.apis, i = y([]), X = y(""), N = y(!1), k = y(""), A = y(!0), S = y(!1), E = nt({ text1: "", text2: "" }), Q = y([]), Z = y(0), O = y(null), $ = y(/* @__PURE__ */ new Map()), K = y(/* @__PURE__ */ new Map()), at = y(/* @__PURE__ */ new Map()), dt = y(/* @__PURE__ */ new Map()), it = y(/* @__PURE__ */ new Map()), U = nt({
62
+ first: new AbortController(),
63
+ again: new AbortController()
64
+ }), z = y(!1), V = y(""), I = nt(/* @__PURE__ */ new Map()), lt = nt(/* @__PURE__ */ new Map()), Y = y(/* @__PURE__ */ new Map());
65
+ let q = 0, ct = 0;
66
+ function yt() {
67
+ if (q) return;
68
+ const s = 16, n = 1, t = 40, o = (C) => {
69
+ if (C - ct >= s) {
70
+ ct = C;
71
+ let H = !1;
72
+ if (i.value.forEach((f, M) => {
73
+ if (f.type !== "ai" || f.status !== a.ANSWERING) return;
74
+ const p = f.content, u = Y.value.get(M) ?? 0, d = p.length - u;
75
+ if (d > 0) {
76
+ H = !0;
77
+ const m = d > 15 ? Math.min(Math.ceil(d * 0.3), t) : n, w = Math.min(u + m, p.length);
78
+ Y.value.set(M, w), lt.set(M, p.slice(0, w));
79
+ }
80
+ }), H && tt(), !i.value.some((f) => f.type === "ai" && f.status === a.ANSWERING)) {
81
+ q = 0;
82
+ return;
83
+ }
84
+ }
85
+ q = requestAnimationFrame(o);
86
+ };
87
+ q = requestAnimationFrame(o);
88
+ }
89
+ function _t(s, n, t, o) {
90
+ if (t.type !== "answer" || o.status !== a.ANSWERING) return t.content;
91
+ const C = o.segments || [];
92
+ if (C.slice(n + 1).some((p) => p.type === "answer")) return t.content;
93
+ const h = Y.value.get(s);
94
+ if (h == null) return t.content;
95
+ let f = 0;
96
+ for (let p = 0; p < n; p++)
97
+ C[p].type === "answer" && (f += C[p].content.length);
98
+ const M = f + t.content.length;
99
+ return h >= M ? t.content : h <= f ? "" : t.content.slice(0, h - f);
100
+ }
101
+ let F = null, j = 0;
102
+ function c(s) {
103
+ F = s(F || [...i.value]), j || (j = requestAnimationFrame(() => {
104
+ j = 0, F && (i.value = F, F = null);
105
+ }));
106
+ }
107
+ function r() {
108
+ j && (cancelAnimationFrame(j), j = 0), F && (i.value = F, F = null);
109
+ }
110
+ const D = ht(
111
+ () => Q.value[Z.value % (Q.value.length || 1)]
112
+ );
113
+ function x() {
114
+ return g.queryAgainStreamApi || g.queryAgainApi || g.chatQueryStreamApi || g.chatQueryApi;
115
+ }
116
+ function tt() {
117
+ St(() => {
118
+ O.value && (O.value.scrollTop = O.value.scrollHeight);
119
+ });
120
+ }
121
+ function kt() {
122
+ if (!O.value) return;
123
+ const s = O.value, n = s.scrollTop + s.clientHeight >= s.scrollHeight - 1, t = s.scrollHeight > s.clientHeight;
124
+ A.value = n, S.value = t;
125
+ }
126
+ function wt() {
127
+ Z.value++;
128
+ }
129
+ function Wt(s) {
130
+ X.value = s;
131
+ }
132
+ function Gt(s) {
133
+ try {
134
+ const { copy: n } = se();
135
+ n(s.content);
136
+ } catch {
137
+ }
138
+ }
139
+ function $t(s, n) {
140
+ s ? it.value.set(n, s) : it.value.delete(n);
141
+ }
142
+ function Bt(s) {
143
+ s.querySelectorAll("pre").forEach((t) => {
144
+ if (t.querySelector(".copy-button")) return;
145
+ const o = t.querySelector("code");
146
+ if (!o) return;
147
+ const H = (Array.from(o.classList).find((f) => f.startsWith("language-")) || "").replace("language-", "");
148
+ if (H) {
149
+ const f = document.createElement("span");
150
+ f.className = "code-lang", f.textContent = H, t.appendChild(f);
151
+ }
152
+ const h = document.createElement("button");
153
+ h.className = "copy-button", h.textContent = "复制", h.onclick = () => {
154
+ navigator.clipboard.writeText(o.textContent || "").then(() => {
155
+ h.textContent = "已复制", setTimeout(() => {
156
+ h.textContent = "复制";
157
+ }, 2e3);
158
+ });
159
+ }, t.appendChild(h);
160
+ });
161
+ }
162
+ function Xt(s) {
163
+ var n;
164
+ if (typeof s == "string") {
165
+ const t = ie(s);
166
+ return le(t) || s;
167
+ }
168
+ return (s == null ? void 0 : s.answer) || ((n = s == null ? void 0 : s.data) == null ? void 0 : n.answer) || String(s || "");
169
+ }
170
+ function Kt(s) {
171
+ const n = [];
172
+ s.inputTokens > 0 && n.push(`输入 ${s.inputTokens} tokens`), s.outputTokens > 0 && n.push(`输出 ${s.outputTokens} tokens`);
173
+ const t = s.latency >= 1 ? `${s.latency.toFixed(1)}s` : `${Math.round(s.latency * 1e3)}ms`;
174
+ return n.push(`耗时 ${t}`), n.join(" · ");
175
+ }
176
+ function qt(s, n) {
177
+ const t = `${s}-${n}`;
178
+ I.set(t, I.get(t) !== !0);
179
+ }
180
+ function At(s) {
181
+ const n = $.value.get(s) || [];
182
+ c((t) => {
183
+ if (t[s]) {
184
+ const o = [...t];
185
+ return o[s] = { ...o[s], segments: n.map((C) => ({ ...C })) }, o;
186
+ }
187
+ return t;
188
+ });
189
+ }
190
+ async function Et(s, n, t, o, C = !1) {
191
+ z.value = !1, $.value.set(t, []), N.value = !0;
192
+ try {
193
+ const H = _.baseUrl.replace(/\/+$/, "") + "/" + s.replace(/^\/+/, "");
194
+ await he(H, {
195
+ method: "POST",
196
+ headers: { "Content-Type": "application/json" },
197
+ body: JSON.stringify({ app: _.app ?? 1, data: n }),
198
+ signal: o,
199
+ openWhenHidden: !0,
200
+ async onopen(h) {
201
+ },
202
+ onmessage(h) {
203
+ var f;
204
+ try {
205
+ let M = h.data || "";
206
+ if (M.startsWith("data:") && (M = M.replace(/^data:\s*/, "")), !M) return;
207
+ let p;
208
+ try {
209
+ p = JSON.parse(M);
210
+ } catch {
211
+ return;
212
+ }
213
+ switch (p.event) {
214
+ case "message_start":
215
+ C || (k.value = p.id), K.value.set(t, "answer");
216
+ break;
217
+ case "think_message_output_start": {
218
+ at.value.set(t, Date.now()), K.value.set(t, "thinking");
219
+ const u = $.value.get(t) || [];
220
+ $.value.set(t, [...u, { type: "thinking", content: "" }]), At(t);
221
+ break;
222
+ }
223
+ case "agent_thought": {
224
+ const u = p.thought || p.thinking || "", d = $.value.get(t) || [], m = d[d.length - 1];
225
+ m && m.type === "agent_thought" ? m.content += u : (K.value.set(t, "agent_thought"), d.push({ type: "agent_thought", content: u }), dt.value.set(t, Date.now())), $.value.set(t, d), c((w) => {
226
+ if (w[t]) {
227
+ const b = [...w];
228
+ return b[t] = {
229
+ ...b[t],
230
+ segments: d.map((T) => ({ ...T })),
231
+ thinkingContent: (b[t].thinkingContent || "") + u,
232
+ status: a.THINKING
233
+ }, b;
234
+ }
235
+ return w;
236
+ });
237
+ break;
238
+ }
239
+ case "think_message": {
240
+ const u = p.thinking || p.answer || p.text || "", d = $.value.get(t) || [], m = d[d.length - 1];
241
+ m && m.type === "thinking" ? m.content += u : (d.push({ type: "thinking", content: u }), at.value.set(t, Date.now())), $.value.set(t, d), c((w) => {
242
+ if (w[t]) {
243
+ const b = [...w];
244
+ return b[t] = {
245
+ ...b[t],
246
+ segments: d.map((T) => ({ ...T })),
247
+ thinkingContent: (b[t].thinkingContent || "") + u,
248
+ status: a.THINKING
249
+ }, b;
250
+ }
251
+ return w;
252
+ });
253
+ break;
254
+ }
255
+ case "agent_thought_end": {
256
+ const u = dt.value.get(t), d = u ? Math.round((Date.now() - u) / 1e3 * 10) / 10 : 0, m = $.value.get(t) || [], w = m[m.length - 1];
257
+ w && w.type === "agent_thought" && (w.duration = d), $.value.set(t, m), c((b) => {
258
+ if (b[t]) {
259
+ const T = [...b];
260
+ return T[t] = {
261
+ ...T[t],
262
+ segments: m.map((et) => ({ ...et })),
263
+ thinkingDuration: (T[t].thinkingDuration || 0) + d
264
+ }, T;
265
+ }
266
+ return b;
267
+ });
268
+ break;
269
+ }
270
+ case "think_message_output_end": {
271
+ const u = at.value.get(t), d = u ? Math.round((Date.now() - u) / 1e3 * 10) / 10 : 0, m = $.value.get(t) || [], w = m[m.length - 1];
272
+ w && w.type === "thinking" && (w.duration = d), $.value.set(t, m), c((b) => {
273
+ if (b[t]) {
274
+ const T = [...b];
275
+ return T[t] = {
276
+ ...T[t],
277
+ segments: m.map((et) => ({ ...et })),
278
+ thinkingDuration: (T[t].thinkingDuration || 0) + d
279
+ }, T;
280
+ }
281
+ return b;
282
+ });
283
+ break;
284
+ }
285
+ case "tool_message": {
286
+ const u = p.answer || p.text || p.content || "";
287
+ if (!u) break;
288
+ const d = $.value.get(t) || [];
289
+ d.push({ type: "answer", content: u }), $.value.set(t, d), At(t);
290
+ break;
291
+ }
292
+ case "message_output_start":
293
+ K.value.set(t, "answer");
294
+ break;
295
+ case "message": {
296
+ const u = p.answer || "", d = K.value.get(t), m = $.value.get(t) || [], w = m[m.length - 1];
297
+ d === "answer" && w && w.type === "answer" ? w.content += u : (K.value.set(t, "answer"), m.push({ type: "answer", content: u })), $.value.set(t, m);
298
+ const b = m.filter((T) => T.type === "answer").map((T) => T.content).join("");
299
+ c((T) => {
300
+ if (T[t]) {
301
+ const et = [...T];
302
+ return et[t] = {
303
+ ...et[t],
304
+ segments: m.map((zt) => ({ ...zt })),
305
+ content: b,
306
+ status: z.value ? a.STOP : a.ANSWERING
307
+ }, et;
308
+ }
309
+ return T;
310
+ });
311
+ break;
312
+ }
313
+ case "message_end": {
314
+ r();
315
+ const u = [...i.value];
316
+ u[t] && (u[t] = { ...u[t], status: z.value ? a.STOP : a.COMPLETED }), i.value = u, N.value = !1;
317
+ break;
318
+ }
319
+ case "agent_error":
320
+ case "message_failed": {
321
+ r();
322
+ const u = [...i.value];
323
+ u[t] && (u[t] = {
324
+ ...u[t],
325
+ status: a.ERROR,
326
+ content: p.error_msg || p.message || "请求失败",
327
+ errorMessage: p.error_msg || p.message || "请求失败"
328
+ }, i.value = u), N.value = !1;
329
+ break;
330
+ }
331
+ case "message_replace": {
332
+ const u = p.answer || "", d = $.value.get(t) || [], m = (f = d.map((w, b) => ({ s: w, i: b })).reverse().find((w) => w.s.type === "answer")) == null ? void 0 : f.i;
333
+ m != null ? d[m] = { ...d[m], content: u } : d.push({ type: "answer", content: u }), $.value.set(t, d), c((w) => {
334
+ if (w[t]) {
335
+ const b = [...w];
336
+ return b[t] = {
337
+ ...b[t],
338
+ segments: d.map((T) => ({ ...T })),
339
+ content: u
340
+ }, b;
341
+ }
342
+ return w;
343
+ });
344
+ break;
345
+ }
346
+ case "message_cost": {
347
+ const u = {
348
+ inputTokens: p.input_tokens || 0,
349
+ outputTokens: p.output_tokens || 0,
350
+ latency: p.latency || 0,
351
+ latencyFirstResp: p.latency_first_resp
352
+ };
353
+ c((d) => {
354
+ if (d[t]) {
355
+ const m = [...d];
356
+ return m[t] = { ...m[t], cost: u }, m;
357
+ }
358
+ return d;
359
+ });
360
+ break;
361
+ }
362
+ default:
363
+ }
364
+ } catch (M) {
365
+ console.error("[ai-assist-sdk] onmessage 解析失败:", M);
366
+ }
367
+ },
368
+ onclose() {
369
+ r();
370
+ const f = ($.value.get(t) || []).filter((p) => p.type === "answer").map((p) => p.content).join(""), M = [...i.value];
371
+ M[t] && M[t].status !== a.ERROR && (M[t] = {
372
+ ...M[t],
373
+ content: z.value && !f ? "已停止回答" : f,
374
+ status: z.value ? a.STOP : a.COMPLETED
375
+ }), i.value = M, N.value = !1;
376
+ },
377
+ onerror(h) {
378
+ console.error("[ai-assist-sdk] ❌ 连接错误:", h), r();
379
+ const f = [...i.value];
380
+ f[t] && (f[t] = { ...f[t], content: `
381
+ ⚠️ 请求异常,已终止`, status: a.ERROR }), i.value = f, N.value = !1;
382
+ }
383
+ });
384
+ } catch (H) {
385
+ if (console.error("[ai-assist-sdk] doStreamRequest error:", H), !z.value) {
386
+ r();
387
+ const h = [...i.value];
388
+ h[t] && (h[t] = { ...h[t], content: "服务连接失败,请稍后重试", status: a.ERROR }), i.value = h, N.value = !1;
389
+ }
390
+ }
391
+ }
392
+ async function Rt() {
393
+ const s = X.value.trim();
394
+ if (!s || N.value) return;
395
+ const n = [
396
+ ...i.value,
397
+ { type: "user", content: s },
398
+ { type: "ai", content: "", status: a.THINKING }
399
+ ];
400
+ i.value = n, X.value = "", tt();
401
+ const t = n.length - 1;
402
+ if (g.chatQueryStreamApi) {
403
+ console.log("[ai-assist-sdk] ✅ 使用流式 SSE:", g.chatQueryStreamApi), await Et(g.chatQueryStreamApi, {
404
+ Query: s,
405
+ AppConversationID: V.value,
406
+ ResponseMode: "streaming"
407
+ }, t, U.first.signal);
408
+ return;
409
+ }
410
+ console.warn("[ai-assist-sdk] ⚠️ 未配置 chatQueryStreamApi,降级为非流式请求");
411
+ try {
412
+ const C = await ne().post(g.chatQueryApi, {
413
+ app: _.app ?? 1,
414
+ data: { Query: s, AppConversationID: V.value }
415
+ }), H = Xt(C.data);
416
+ i.value = [...i.value.slice(0, -1), { type: "ai", content: H, status: a.COMPLETED }];
417
+ } catch {
418
+ i.value = [...i.value.slice(0, -1), { type: "ai", content: "服务连接失败,请稍后重试", status: a.ERROR }];
419
+ }
420
+ }
421
+ async function Qt() {
422
+ if (!k.value || N.value) return;
423
+ const s = [...i.value];
424
+ s.length > 0 && s[s.length - 1].type === "ai" && s.pop(), s.push({ type: "ai", content: "", status: a.RETHINKING }), i.value = s, tt();
425
+ const n = i.value.length;
426
+ await Et(x(), {
427
+ MessageID: k.value,
428
+ AppConversationID: V.value,
429
+ ResponseMode: "streaming"
430
+ }, n, U.again.signal, !0);
431
+ }
432
+ async function Ut() {
433
+ if (!g.stopMessageApi || !N.value) return;
434
+ const s = i.value.length - 1;
435
+ try {
436
+ await oe(g, k.value);
437
+ const n = [...i.value];
438
+ n[s] && (n[s] = { ...n[s], content: n[s].content || "已停止回答", status: a.STOP }), i.value = n, N.value = !1, U.first.abort(), U.first = new AbortController(), U.again.abort(), U.again = new AbortController(), z.value = !0;
439
+ } catch {
440
+ const n = [...i.value];
441
+ n[s] && (n[s] = { ...n[s], content: "系统繁忙,请稍后再试", status: a.ERROR }), i.value = n;
442
+ }
443
+ }
444
+ async function Ft(s) {
445
+ var o, C, H;
446
+ V.value = s;
447
+ const n = await ae(g, s), t = (H = (C = (o = n == null ? void 0 : n.messages) == null ? void 0 : o[0]) == null ? void 0 : C.answerInfo) == null ? void 0 : H.answer;
448
+ t && (i.value = [...i.value, { type: "ai", content: t, status: a.COMPLETED }]);
449
+ }
450
+ L({ goHistoryMessage: Ft }), Ht(i, () => {
451
+ St(() => {
452
+ i.value.forEach((s, n) => {
453
+ s.type === "ai" && s.status !== a.ANSWERING && (lt.set(n, s.content), Y.value.set(n, s.content.length));
454
+ }), yt(), it.value.forEach((s) => {
455
+ Bt(s);
456
+ });
457
+ });
458
+ }, { deep: !0 }), bt(() => {
459
+ q && (cancelAnimationFrame(q), q = 0), O.value && pt && O.value.removeEventListener("scroll", pt);
460
+ }), J(() => {
461
+ B.defaultSayhello && (E.text1 = B.defaultSayhello.text1, E.text2 = B.defaultSayhello.text2), B.defaultRecommend && (Q.value = It(B.defaultRecommend));
462
+ }), J(async () => {
463
+ var n;
464
+ const s = await te(g);
465
+ (n = s == null ? void 0 : s.conversation) != null && n.appConversationID && (V.value = s.conversation.appConversationID);
466
+ });
467
+ let pt = null;
468
+ return J(() => {
469
+ O.value && (pt = () => kt(), O.value.addEventListener("scroll", pt));
470
+ }), (s, n) => {
471
+ var t;
472
+ return l(), v("div", Ce, [
473
+ e("div", {
474
+ class: "chat-box scrollWrap",
475
+ ref_key: "chatBoxRef",
476
+ ref: O
477
+ }, [
478
+ e("div", Se, [
479
+ e("div", be, [
480
+ e("h1", null, P(E.text1), 1),
481
+ e("p", null, P(E.text2), 1)
482
+ ])
483
+ ]),
484
+ (t = D.value) != null && t.length ? (l(), v("div", Te, [
485
+ e("div", $e, [
486
+ e("div", Ae, [
487
+ n[2] || (n[2] = e("span", null, "你可以尝试这样问我:", -1)),
488
+ e("p", {
489
+ class: "refresh-btn",
490
+ onClick: wt
491
+ }, [
492
+ e("img", { src: R(Ct) }, null, 8, Ee),
493
+ n[1] || (n[1] = e("span", null, "换一换", -1))
494
+ ])
495
+ ]),
496
+ e("ul", null, [
497
+ (l(!0), v(st, null, ut(D.value, (o, C) => (l(), v("li", {
498
+ key: C,
499
+ onClick: (H) => Wt(o)
500
+ }, P(o), 9, Re))), 128))
501
+ ])
502
+ ])
503
+ ])) : W("", !0),
504
+ (l(!0), v(st, null, ut(i.value, (o, C) => {
505
+ var H;
506
+ return l(), v("div", {
507
+ key: C,
508
+ class: ot(["message", `${o.type}-message`])
509
+ }, [
510
+ o.type === "ai" ? (l(), v(st, { key: 0 }, [
511
+ (o.status === a.THINKING || o.status === a.RETHINKING) && !o.thinkingContent && !o.content ? (l(), v("div", Me, [...n[3] || (n[3] = [
512
+ Yt('<div class="scale-animation-container"><span class="scale-dot"></span><span class="scale-dot"></span><span class="scale-dot"></span><span class="scale-dot"></span></div>', 1)
513
+ ])])) : W("", !0),
514
+ o.segments && o.segments.length ? (l(), v("div", {
515
+ key: 1,
516
+ class: "message-content ba-markdown",
517
+ ref_for: !0,
518
+ ref: (h) => $t(h, C)
519
+ }, [
520
+ (l(!0), v(st, null, ut(o.segments, (h, f) => (l(), v(st, { key: f }, [
521
+ h.type === "agent_thought" ? (l(), v("div", Ne, [
522
+ n[4] || (n[4] = e("svg", {
523
+ class: "agent-thought__icon",
524
+ viewBox: "0 0 24 24",
525
+ width: "14",
526
+ height: "14",
527
+ fill: "none",
528
+ stroke: "currentColor",
529
+ "stroke-width": "2"
530
+ }, [
531
+ e("circle", {
532
+ cx: "11",
533
+ cy: "11",
534
+ r: "7"
535
+ }),
536
+ e("line", {
537
+ x1: "16.5",
538
+ y1: "16.5",
539
+ x2: "21",
540
+ y2: "21"
541
+ })
542
+ ], -1)),
543
+ e("span", De, P(h.duration != null ? "搜索信息完成" : "搜索信息中…"), 1)
544
+ ])) : h.type === "thinking" ? (l(), v("div", {
545
+ key: 1,
546
+ class: ot(["thinking-block", { "thinking-block--expanded": I.get(`${C}-${f}`) === !0 }])
547
+ }, [
548
+ e("div", {
549
+ class: "thinking-block__header",
550
+ onClick: (M) => qt(C, f)
551
+ }, [
552
+ e("span", Pe, P(h.duration != null ? "深度思考" : "深度思考中"), 1),
553
+ (l(), v("svg", {
554
+ class: ot(["thinking-block__arrow", { "thinking-block__arrow--down": I.get(`${C}-${f}`) === !0 }]),
555
+ viewBox: "0 0 24 24",
556
+ width: "14",
557
+ height: "14",
558
+ fill: "none",
559
+ stroke: "currentColor",
560
+ "stroke-width": "2"
561
+ }, [...n[5] || (n[5] = [
562
+ e("polyline", { points: "6 9 12 15 18 9" }, null, -1)
563
+ ])], 2))
564
+ ], 8, He),
565
+ I.get(`${C}-${f}`) === !0 ? (l(), v("div", Le, P(h.content), 1)) : W("", !0)
566
+ ], 2)) : (l(), v("div", Oe, [
567
+ e("div", {
568
+ innerHTML: R(Nt)(R(Dt)(_t(C, f, h, o)))
569
+ }, null, 8, We)
570
+ ]))
571
+ ], 64))), 128)),
572
+ o.status === a.ANSWERING ? (l(), v("span", Ge)) : W("", !0)
573
+ ], 512)) : W("", !0),
574
+ !((H = o.segments) != null && H.length) && o.content ? (l(), v("div", {
575
+ key: 2,
576
+ class: "message-content ba-markdown",
577
+ ref_for: !0,
578
+ ref: (h) => $t(h, C)
579
+ }, [
580
+ e("div", {
581
+ innerHTML: R(Nt)(R(Dt)(lt.get(C) ?? o.content))
582
+ }, null, 8, Be),
583
+ o.status === a.ANSWERING ? (l(), v("span", Xe)) : W("", !0)
584
+ ], 512)) : W("", !0),
585
+ o.errorMessage ? (l(), v("div", Ke, [
586
+ n[6] || (n[6] = e("span", { class: "message-error__icon" }, "⚠️", -1)),
587
+ e("span", null, P(o.errorMessage), 1)
588
+ ])) : W("", !0),
589
+ o.cost && o.status !== a.ANSWERING && o.status !== a.THINKING ? (l(), v("div", qe, P(Kt(o.cost)), 1)) : W("", !0),
590
+ e("div", Qe, [
591
+ e("span", {
592
+ onClick: (h) => Gt(o)
593
+ }, P(R(ee)(o.status)), 9, Ue)
594
+ ])
595
+ ], 64)) : (l(), v("div", Fe, P(o.content), 1))
596
+ ], 2);
597
+ }), 128))
598
+ ], 512),
599
+ e("div", ze, [
600
+ k.value ? (l(), v("div", Ye, [
601
+ e("img", {
602
+ class: "refresh",
603
+ onClick: Qt,
604
+ src: R(Ct)
605
+ }, null, 8, je)
606
+ ])) : (l(), v("img", {
607
+ key: 1,
608
+ class: "refresh",
609
+ src: R(Ct)
610
+ }, null, 8, Ve)),
611
+ Tt(e("input", {
612
+ "onUpdate:modelValue": n[0] || (n[0] = (o) => X.value = o),
613
+ type: "text",
614
+ placeholder: "输入消息...",
615
+ onKeyup: jt(Rt, ["enter"]),
616
+ disabled: N.value
617
+ }, null, 40, xe), [
618
+ [Pt, X.value]
619
+ ]),
620
+ N.value && k.value ? (l(), v("div", Je, [
621
+ e("img", {
622
+ src: R(ve),
623
+ onClick: Ut
624
+ }, null, 8, Ze)
625
+ ])) : (l(), v("div", Ie, [
626
+ e("img", {
627
+ src: R(de),
628
+ onClick: Rt
629
+ }, null, 8, ts)
630
+ ])),
631
+ S.value && !A.value ? (l(), v("div", es, [
632
+ e("img", {
633
+ onClick: tt,
634
+ src: R(pe)
635
+ }, null, 8, ss)
636
+ ])) : W("", !0)
637
+ ])
638
+ ]);
639
+ };
640
+ }
641
+ }), os = { class: "ai-history" }, as = { class: "content" }, is = { key: 0 }, ls = ["onClick"], cs = { class: "info-pic" }, rs = { class: "info-content" }, us = { class: "info-content-title" }, vs = { class: "info-content-time" }, ds = ["onClick"], ps = ["src"], hs = { class: "ai-modal" }, fs = { class: "ai-modal-footer" }, gs = /* @__PURE__ */ gt({
642
+ __name: "History",
643
+ emits: ["history-detail", "new-answer"],
644
+ setup(G, { emit: L }) {
645
+ const B = mt().apis, _ = y([]), g = y(!1), i = y("");
646
+ async function X() {
647
+ const A = await ce(B);
648
+ A != null && A.conversationList && (_.value = A.conversationList.filter((S) => S !== null).map((S) => ({ ...S, selected: !1 })));
649
+ }
650
+ function N(A) {
651
+ i.value = A, g.value = !0;
652
+ }
653
+ async function k() {
654
+ g.value = !1, await re(B, i.value), await X();
655
+ }
656
+ return J(() => {
657
+ X();
658
+ }), (A, S) => (l(), v("div", os, [
659
+ e("div", as, [
660
+ _.value.length > 0 ? (l(), v("div", is, [
661
+ (l(!0), v(st, null, ut(_.value, (E) => (l(), v("div", {
662
+ key: E.appConversationID,
663
+ class: "info",
664
+ onClick: (Q) => A.$emit("history-detail", E.appConversationID)
665
+ }, [
666
+ e("div", cs, P(E.conversationName.slice(0, 1)), 1),
667
+ e("div", rs, [
668
+ e("div", us, P(E.conversationName), 1),
669
+ e("div", vs, P(E.createTime), 1)
670
+ ]),
671
+ e("div", {
672
+ class: "clear-history",
673
+ onClick: Mt((Q) => N(E.appConversationID), ["stop"])
674
+ }, "删除", 8, ds)
675
+ ], 8, ls))), 128))
676
+ ])) : W("", !0)
677
+ ]),
678
+ e("div", {
679
+ class: "ai-add",
680
+ onClick: S[0] || (S[0] = (E) => A.$emit("new-answer"))
681
+ }, [
682
+ e("img", { src: R(fe) }, null, 8, ps),
683
+ S[3] || (S[3] = e("span", { style: { color: "#333333" } }, "新建AI对话", -1))
684
+ ]),
685
+ (l(), ft(Vt, { to: "body" }, [
686
+ g.value ? (l(), v("div", {
687
+ key: 0,
688
+ class: "ai-modal-overlay",
689
+ onClick: S[2] || (S[2] = Mt((E) => g.value = !1, ["self"]))
690
+ }, [
691
+ e("div", hs, [
692
+ S[4] || (S[4] = e("div", { class: "ai-modal-header" }, "确定要删除该历史记录吗?", -1)),
693
+ S[5] || (S[5] = e("div", { class: "ai-modal-body" }, "一旦删除,数据将无法恢复。", -1)),
694
+ e("div", fs, [
695
+ e("button", {
696
+ class: "ai-modal-btn cancel",
697
+ onClick: S[1] || (S[1] = (E) => g.value = !1)
698
+ }, "取消"),
699
+ e("button", {
700
+ class: "ai-modal-btn confirm",
701
+ onClick: k
702
+ }, "确定")
703
+ ])
704
+ ])
705
+ ])) : W("", !0)
706
+ ]))
707
+ ]));
708
+ }
709
+ }), ms = (G, L) => {
710
+ const a = G.__vccOpts || G;
711
+ for (const [B, _] of L)
712
+ a[B] = _;
713
+ return a;
714
+ }, ys = /* @__PURE__ */ ms(gs, [["__scopeId", "data-v-d145ed86"]]), _s = { class: "container info" }, ks = { class: "info-item" }, ws = { class: "basic-content" }, Cs = { class: "basic-content-text" }, Ss = { class: "basic-content" }, bs = { class: "basic-content-text" }, Ts = { class: "info-item" }, $s = { class: "permission-content" }, As = { class: "info-item" }, Es = { class: "basic-content" }, Rs = { class: "basic-content-text" }, Ms = { class: "basic-content" }, Ns = { class: "basic-content-text" }, Ds = /* @__PURE__ */ gt({
715
+ __name: "Info",
716
+ setup(G) {
717
+ const L = mt(), a = y(null);
718
+ return J(async () => {
719
+ a.value = await ue(L.apis);
720
+ }), (B, _) => {
721
+ var g, i, X, N, k;
722
+ return l(), v("div", _s, [
723
+ e("div", ks, [
724
+ _[2] || (_[2] = e("div", { class: "heading" }, [
725
+ e("div", { class: "heading-column" }),
726
+ e("div", { class: "heading-title" }, "基本信息")
727
+ ], -1)),
728
+ e("div", ws, [
729
+ _[0] || (_[0] = e("div", { class: "basic-content-text basic-content-key" }, "姓名", -1)),
730
+ e("div", Cs, P(((g = a.value) == null ? void 0 : g.name) || ""), 1)
731
+ ]),
732
+ e("div", Ss, [
733
+ _[1] || (_[1] = e("div", { class: "basic-content-text basic-content-key" }, "用户名", -1)),
734
+ e("div", bs, P(((i = a.value) == null ? void 0 : i.userName) || ""), 1)
735
+ ])
736
+ ]),
737
+ e("div", Ts, [
738
+ _[3] || (_[3] = e("div", { class: "heading" }, [
739
+ e("div", { class: "heading-column" }),
740
+ e("div", { class: "heading-title" }, "数据权限")
741
+ ], -1)),
742
+ e("div", $s, [
743
+ (l(!0), v(st, null, ut((X = a.value) == null ? void 0 : X.ptnameList, (A, S) => (l(), v("div", {
744
+ key: S,
745
+ class: "permission-content-text"
746
+ }, P(A), 1))), 128))
747
+ ])
748
+ ]),
749
+ e("div", As, [
750
+ _[6] || (_[6] = e("div", { class: "heading" }, [
751
+ e("div", { class: "heading-column" }),
752
+ e("div", { class: "heading-title" }, "帮助信息")
753
+ ], -1)),
754
+ e("div", Es, [
755
+ _[4] || (_[4] = e("div", { class: "basic-content-text basic-content-key" }, "部门", -1)),
756
+ e("div", Rs, P(((N = a.value) == null ? void 0 : N.dept) || ""), 1)
757
+ ]),
758
+ e("div", Ms, [
759
+ _[5] || (_[5] = e("div", { class: "basic-content-text basic-content-key" }, "邮箱", -1)),
760
+ e("div", Ns, P(((k = a.value) == null ? void 0 : k.email) || ""), 1)
761
+ ])
762
+ ])
763
+ ]);
764
+ };
765
+ }
766
+ }), Hs = { class: "header" }, Ps = ["src"], Ls = { class: "header-title" }, Os = ["src"], Ws = ["src"], Gs = ["src"], Bs = { class: "setTitle" }, Xs = { class: "content" }, Ks = { class: "main" }, qs = { class: "btn" }, Qs = ["src"], Us = 117, rt = 118, Ot = /* @__PURE__ */ gt({
767
+ __name: "AiAssist",
768
+ setup(G) {
769
+ const L = Us / 2, a = mt(), B = y(!1), _ = y(!1), g = y("answer"), i = y(!1), X = y(""), N = y(""), k = nt({
770
+ x: window.innerWidth - L,
771
+ y: window.innerHeight / 2 - rt / 2
772
+ }), A = y(!1), S = y(!1), E = y("right"), Q = y("left"), Z = nt({ x: 0, y: 0 }), O = y(!1), $ = y(null);
773
+ let K = null;
774
+ const at = ht(() => {
775
+ const c = window.innerWidth / 2;
776
+ return k.x + L < c ? 5 : -5;
777
+ }), dt = ht(() => _.value ? "" : `panel-${E.value}`), it = ht(() => ({
778
+ left: `${k.x}px`,
779
+ top: `${k.y}px`,
780
+ transition: A.value ? "none" : "all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1)",
781
+ "--direction": String(at.value)
782
+ }));
783
+ function U() {
784
+ const c = window.innerWidth / 2;
785
+ k.x + L < c ? (E.value = "left", Q.value = "right") : (E.value = "right", Q.value = "left");
786
+ }
787
+ function z() {
788
+ const c = window.innerWidth, r = Math.max(0, Math.min(k.y, window.innerHeight - rt));
789
+ return { x: k.x + L >= c / 2 ? c - L : -L, y: r };
790
+ }
791
+ function V() {
792
+ S.value = !0;
793
+ const c = z();
794
+ k.x = c.x, k.y = c.y, setTimeout(() => {
795
+ S.value = !1, U(), I();
796
+ }, 400);
797
+ }
798
+ function I() {
799
+ try {
800
+ localStorage.setItem("characterPosition", JSON.stringify({ x: k.x, y: k.y })), localStorage.setItem("panelPosition", E.value), localStorage.setItem("backPosition", Q.value);
801
+ } catch {
802
+ }
803
+ }
804
+ function lt() {
805
+ const c = localStorage.getItem("characterPosition");
806
+ if (c) {
807
+ const x = JSON.parse(c);
808
+ k.x = x.x, k.y = Math.min(Math.max(x.y, 0), window.innerHeight - rt);
809
+ } else
810
+ k.x = window.innerWidth - L, k.y = window.innerHeight / 2 - rt / 2;
811
+ const r = localStorage.getItem("panelPosition"), D = localStorage.getItem("backPosition");
812
+ r && (E.value = r), D && (Q.value = D);
813
+ }
814
+ function Y(c) {
815
+ if (!A.value) return;
816
+ const r = "touches" in c ? c.touches[0].clientX : c.clientX, D = "touches" in c ? c.touches[0].clientY : c.clientY, x = r - Z.x, tt = Math.max(0, Math.min(D - Z.y, window.innerHeight - rt)), kt = Math.abs(x - k.x), wt = Math.abs(tt - k.y);
817
+ kt + wt > 5 && (O.value = !0), k.x = x, k.y = tt;
818
+ }
819
+ function q() {
820
+ A.value && (A.value = !1, O.value && (V(), O.value = !1));
821
+ }
822
+ function ct(c) {
823
+ S.value = !1, A.value = !0, O.value = !1;
824
+ const r = "touches" in c ? c.touches[0].clientX : c.clientX, D = "touches" in c ? c.touches[0].clientY : c.clientY;
825
+ Z.x = r - k.x, Z.y = D - k.y;
826
+ }
827
+ function yt() {
828
+ !O.value && !S.value ? (U(), B.value = !0) : O.value = !1;
829
+ }
830
+ function _t(c) {
831
+ g.value = "answer", St(() => {
832
+ var r;
833
+ (r = $.value) == null || r.goHistoryMessage(c);
834
+ });
835
+ }
836
+ function F() {
837
+ N.value = X.value, i.value = !1;
838
+ }
839
+ Ht(_, (c) => {
840
+ c ? E.value = "center" : U();
841
+ }), J(() => {
842
+ lt();
843
+ });
844
+ function j() {
845
+ K && clearTimeout(K), K = setTimeout(() => V(), 100);
846
+ }
847
+ return J(() => {
848
+ window.addEventListener("resize", j);
849
+ }), bt(() => {
850
+ window.removeEventListener("resize", j), K && clearTimeout(K);
851
+ }), J(() => {
852
+ document.addEventListener("mousemove", Y), document.addEventListener("touchmove", Y, { passive: !0 }), document.addEventListener("mouseup", q), document.addEventListener("touchend", q);
853
+ }), bt(() => {
854
+ document.removeEventListener("mousemove", Y), document.removeEventListener("touchmove", Y), document.removeEventListener("mouseup", q), document.removeEventListener("touchend", q);
855
+ }), (c, r) => (l(), v("div", null, [
856
+ B.value ? (l(), v("div", {
857
+ key: 0,
858
+ class: ot(["ai-panel", _.value ? "maxWrap" : "minWrap", dt.value])
859
+ }, [
860
+ e("div", Hs, [
861
+ e("p", null, [
862
+ g.value === "info" || g.value === "history" ? (l(), v("span", {
863
+ key: 0,
864
+ class: ot(["back", Q.value]),
865
+ onClick: r[0] || (r[0] = (D) => g.value = "answer")
866
+ }, [...r[8] || (r[8] = [
867
+ e("span", { style: { "font-size": "18px" } }, "←", -1)
868
+ ])], 2)) : (l(), v("img", {
869
+ key: 1,
870
+ src: R(ge),
871
+ onClick: r[1] || (r[1] = (D) => g.value = "info")
872
+ }, null, 8, Ps))
873
+ ]),
874
+ e("div", Ls, [
875
+ e("span", null, P(g.value === "info" ? "个人信息" : g.value === "history" ? "历史信息" : R(a).name), 1)
876
+ ]),
877
+ e("p", null, [
878
+ e("img", {
879
+ src: R(me),
880
+ class: "mute",
881
+ onClick: r[2] || (r[2] = (D) => g.value = "history")
882
+ }, null, 8, Os),
883
+ e("img", {
884
+ onClick: r[3] || (r[3] = (D) => _.value = !_.value),
885
+ src: _.value ? R(ye) : R(_e)
886
+ }, null, 8, Ws),
887
+ e("img", {
888
+ onClick: r[4] || (r[4] = (D) => B.value = !1),
889
+ src: R(ke)
890
+ }, null, 8, Gs)
891
+ ])
892
+ ]),
893
+ g.value === "answer" ? (l(), ft(ns, {
894
+ key: 0,
895
+ ref_key: "answerRef",
896
+ ref: $,
897
+ defaultSayhello: R(a).defaultSayhello,
898
+ defaultRecommend: R(a).defaultRecommend
899
+ }, null, 8, ["defaultSayhello", "defaultRecommend"])) : W("", !0),
900
+ g.value === "history" ? (l(), ft(ys, {
901
+ key: 1,
902
+ onHistoryDetail: _t,
903
+ onNewAnswer: r[5] || (r[5] = (D) => g.value = "answer")
904
+ })) : W("", !0),
905
+ g.value === "info" ? (l(), ft(Ds, { key: 2 })) : W("", !0),
906
+ Tt(e("div", Bs, [
907
+ e("div", Xs, [
908
+ e("div", Ks, [
909
+ r[9] || (r[9] = e("p", { class: "title" }, "修改标题", -1)),
910
+ Tt(e("textarea", {
911
+ "onUpdate:modelValue": r[6] || (r[6] = (D) => X.value = D),
912
+ placeholder: "请输入新标题"
913
+ }, null, 512), [
914
+ [Pt, X.value]
915
+ ]),
916
+ e("p", qs, [
917
+ e("span", {
918
+ onClick: r[7] || (r[7] = (D) => i.value = !1)
919
+ }, "取消"),
920
+ e("span", { onClick: F }, "确定")
921
+ ])
922
+ ])
923
+ ])
924
+ ], 512), [
925
+ [xt, i.value]
926
+ ])
927
+ ], 2)) : W("", !0),
928
+ B.value ? W("", !0) : (l(), v("div", {
929
+ key: 1,
930
+ class: ot(["character", { dragging: A.value, recycling: S.value }]),
931
+ style: Jt(it.value),
932
+ onMousedown: ct,
933
+ onTouchstart: ct,
934
+ onClick: yt
935
+ }, [
936
+ e("img", { src: R(we) }, null, 8, Qs)
937
+ ], 38))
938
+ ]));
939
+ }
940
+ });
941
+ let vt = null;
942
+ const js = (G) => {
943
+ Lt(G);
944
+ }, Vs = (G) => {
945
+ const L = G || document.body, a = document.createElement("div");
946
+ a.id = "ai-assist-root", L.appendChild(a), vt = Zt(Ot), vt.mount(a);
947
+ }, xs = () => {
948
+ vt && (vt.unmount(), vt = null);
949
+ const G = document.getElementById("ai-assist-root");
950
+ G && G.remove();
951
+ }, Js = {
952
+ install(G, L) {
953
+ Lt(L), G.component("AiAssist", Ot);
954
+ }
955
+ };
956
+ export {
957
+ Ot as AiAssist,
958
+ Js as default,
959
+ js as initAiAssist,
960
+ Vs as mountAiAssist,
961
+ xs as unmountAiAssist
962
+ };