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