@bidding-group/ai-chat 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -48
- package/dist/ai-chat.css +1 -1
- package/dist/ai-chat.js +443 -398
- package/dist/ai-chat.umd.cjs +2 -2
- package/dist/api/index.d.ts +21 -0
- package/dist/components/AiChat.vue.d.ts +2 -0
- package/dist/components/AiChatDrawer.vue.d.ts +2 -0
- package/dist/components/AiChatFloat.vue.d.ts +2 -0
- package/dist/components/AiChatMessage.vue.d.ts +6 -0
- package/dist/config.d.ts +3 -0
- package/dist/index.d.ts +12 -0
- package/dist/store/ai.d.ts +295 -0
- package/dist/types/index.d.ts +59 -0
- package/package.json +10 -9
package/dist/ai-chat.js
CHANGED
|
@@ -1,53 +1,89 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { ChatDotRound as
|
|
3
|
-
import { defineStore as
|
|
4
|
-
import { ElScrollbar as
|
|
5
|
-
let
|
|
6
|
-
function
|
|
7
|
-
|
|
1
|
+
import { defineComponent as G, ref as C, computed as y, onMounted as be, onUnmounted as Ie, resolveComponent as R, openBlock as r, createElementBlock as h, normalizeStyle as Ae, normalizeClass as F, createVNode as i, withCtx as u, createElementVNode as p, unref as g, createBlock as B, Fragment as U, renderList as J, createCommentVNode as I, toDisplayString as P, watch as _e, nextTick as Se, Transition as te, withModifiers as se, createTextVNode as ne, withKeys as Be } from "vue";
|
|
2
|
+
import { ChatDotRound as Ge, Monitor as qe, User as Ke, Grid as Ye, Menu as Ze, FullScreen as Qe, Plus as et, Close as ke, Loading as tt, List as st, Promotion as nt } from "@element-plus/icons-vue";
|
|
3
|
+
import { defineStore as it } from "pinia";
|
|
4
|
+
import { ElScrollbar as we, ElMessage as z } from "element-plus";
|
|
5
|
+
let oe = null;
|
|
6
|
+
function ot(t) {
|
|
7
|
+
oe = t;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
if (!
|
|
9
|
+
function ae() {
|
|
10
|
+
if (!oe)
|
|
11
11
|
throw new Error("[@cgs/ai-chat] 插件未安装,请先调用 app.use(AiChat, options)");
|
|
12
|
-
return
|
|
12
|
+
return oe;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
function at(t) {
|
|
15
|
+
try {
|
|
16
|
+
const e = t.split(".");
|
|
17
|
+
if (e.length !== 3) return null;
|
|
18
|
+
const d = e[1].replace(/-/g, "+").replace(/_/g, "/"), o = decodeURIComponent(
|
|
19
|
+
atob(d).split("").map((l) => "%" + ("00" + l.charCodeAt(0).toString(16)).slice(-2)).join("")
|
|
20
|
+
);
|
|
21
|
+
return JSON.parse(o, (l, a) => typeof a == "number" && !Number.isSafeInteger(a) ? String(a) : a);
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function Me(t) {
|
|
27
|
+
const e = ae(), d = { ...t };
|
|
28
|
+
if (e.getToken) {
|
|
29
|
+
const o = e.getToken();
|
|
30
|
+
if (o) {
|
|
31
|
+
d["x-access-token"] = o;
|
|
32
|
+
const l = at(o);
|
|
33
|
+
l && (l.details_user_id && (d.details_user_id = String(l.details_user_id)), l.details_username && (d.details_username = String(l.details_username)), l.details_tenant_id && (d.details_tenant_id = String(l.details_tenant_id)), l.details_app_id && (d.details_app_id = String(l.details_app_id)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return d;
|
|
37
|
+
}
|
|
38
|
+
async function H(t, e, d) {
|
|
39
|
+
const o = ae(), l = Me({ "Content-Type": "application/json" });
|
|
40
|
+
let a = d;
|
|
41
|
+
d && typeof d == "object" ? (a = { ...d }, !a.tenantId && o.getTenantId && (a.tenantId = o.getTenantId()), !a.appId && o.getAppId && (a.appId = o.getAppId())) : (t === "POST" || t === "PUT") && !d && (a = {}, o.getTenantId && (a.tenantId = o.getTenantId()), o.getAppId && (a.appId = o.getAppId()));
|
|
42
|
+
const m = await fetch(`${o.baseUrl}${e}`, {
|
|
20
43
|
method: t,
|
|
21
|
-
headers:
|
|
22
|
-
body:
|
|
23
|
-
});
|
|
24
|
-
if (!
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
headers: l,
|
|
45
|
+
body: a !== void 0 ? JSON.stringify(a) : void 0
|
|
46
|
+
}), b = await m.text(), c = JSON.parse(b, (_, S) => typeof S == "number" && !Number.isSafeInteger(S) ? String(S) : S);
|
|
47
|
+
if (!m.ok) {
|
|
48
|
+
const _ = c?.msg || c?.message || c?.detail || "";
|
|
49
|
+
throw new Error(`HTTP ${m.status}: ${e}${_ ? ` — ${_}` : ""}`);
|
|
50
|
+
}
|
|
51
|
+
if (c?.code === 401)
|
|
52
|
+
throw new Error(`AUTH_EXPIRED:${c.msg || "认证失败,请重新登录"}`);
|
|
53
|
+
if (c?.code && c.code !== 200 && c.code !== 0)
|
|
54
|
+
throw new Error(`${c.msg || c.message || "请求失败"} (code: ${c.code})`);
|
|
55
|
+
return c.data;
|
|
28
56
|
}
|
|
29
|
-
const
|
|
57
|
+
const lt = () => H("POST", "/session/create"), ye = (t) => H("POST", "/session/page", t).then((e) => ({
|
|
30
58
|
list: e?.records ?? [],
|
|
31
59
|
total: e?.total ?? 0
|
|
32
|
-
})),
|
|
33
|
-
async function
|
|
34
|
-
const e = Me(),
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
e.getToken && (g["x-access-token"] = e.getToken()), e.getTenantId && (g["X-Tenant-Id"] = String(e.getTenantId()));
|
|
38
|
-
const h = await fetch(`${e.baseUrl}/chat/stream`, {
|
|
60
|
+
})), rt = (t) => H("GET", `/session/${t}/messages`), ct = (t) => H("DELETE", `/session/${t}`), dt = () => H("GET", "/usage/today");
|
|
61
|
+
async function ut(t) {
|
|
62
|
+
const e = ae(), d = Me({ "Content-Type": "application/json" }), o = { ...t };
|
|
63
|
+
!o.tenantId && e.getTenantId && (o.tenantId = e.getTenantId()), !o.appId && e.getAppId && (o.appId = e.getAppId());
|
|
64
|
+
const l = await fetch(`${e.baseUrl}/chat/stream`, {
|
|
39
65
|
method: "POST",
|
|
40
|
-
headers:
|
|
41
|
-
body: JSON.stringify(
|
|
66
|
+
headers: d,
|
|
67
|
+
body: JSON.stringify(o),
|
|
42
68
|
signal: t.signal
|
|
43
|
-
// 支持 AbortSignal
|
|
44
69
|
});
|
|
45
|
-
if (!
|
|
46
|
-
throw new Error(`流式请求失败: HTTP ${
|
|
47
|
-
|
|
70
|
+
if (!l.ok)
|
|
71
|
+
throw new Error(`流式请求失败: HTTP ${l.status}`);
|
|
72
|
+
const a = l.clone();
|
|
73
|
+
try {
|
|
74
|
+
const m = await a.json();
|
|
75
|
+
if (m?.code === 401)
|
|
76
|
+
throw new Error(`AUTH_EXPIRED:${m.msg || "认证失败,请重新登录"}`);
|
|
77
|
+
if (m?.code && m.code !== 200 && m.code !== 0)
|
|
78
|
+
throw new Error(`${m.msg || "请求失败"} (code: ${m.code})`);
|
|
79
|
+
} catch (m) {
|
|
80
|
+
if (m instanceof Error && m.message.startsWith("AUTH_EXPIRED:"))
|
|
81
|
+
throw m;
|
|
82
|
+
}
|
|
83
|
+
return l;
|
|
48
84
|
}
|
|
49
85
|
const Ce = "cgs-ai-chat-state";
|
|
50
|
-
function
|
|
86
|
+
function gt() {
|
|
51
87
|
try {
|
|
52
88
|
const t = localStorage.getItem(Ce);
|
|
53
89
|
return t ? JSON.parse(t) : {};
|
|
@@ -55,7 +91,7 @@ function dt() {
|
|
|
55
91
|
return {};
|
|
56
92
|
}
|
|
57
93
|
}
|
|
58
|
-
function
|
|
94
|
+
function mt(t) {
|
|
59
95
|
try {
|
|
60
96
|
localStorage.setItem(
|
|
61
97
|
Ce,
|
|
@@ -68,10 +104,10 @@ function ut(t) {
|
|
|
68
104
|
} catch {
|
|
69
105
|
}
|
|
70
106
|
}
|
|
71
|
-
const
|
|
107
|
+
const Te = 15, ie = gt(), Ee = it("cgs-ai-chat", {
|
|
72
108
|
state: () => ({
|
|
73
109
|
visible: !1,
|
|
74
|
-
currentSessionId:
|
|
110
|
+
currentSessionId: ie.currentSessionId ?? null,
|
|
75
111
|
sessions: [],
|
|
76
112
|
sessionPage: 1,
|
|
77
113
|
sessionTotal: 0,
|
|
@@ -79,8 +115,8 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
79
115
|
messages: [],
|
|
80
116
|
loading: !1,
|
|
81
117
|
sending: !1,
|
|
82
|
-
panelWidth:
|
|
83
|
-
isFullScreen:
|
|
118
|
+
panelWidth: ie.panelWidth ?? (typeof window < "u" ? Math.max(320, Math.round(window.innerWidth * 0.25)) : 420),
|
|
119
|
+
isFullScreen: ie.isFullScreen ?? !1,
|
|
84
120
|
tokenUsage: null
|
|
85
121
|
}),
|
|
86
122
|
actions: {
|
|
@@ -113,7 +149,7 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
113
149
|
async loadSessions() {
|
|
114
150
|
this.loading = !0, this.sessionPage = 1;
|
|
115
151
|
try {
|
|
116
|
-
const t = await ye({ pageNum: 1, pageSize:
|
|
152
|
+
const t = await ye({ pageNum: 1, pageSize: Te });
|
|
117
153
|
this.sessions = t.list, this.sessionTotal = t.total;
|
|
118
154
|
} finally {
|
|
119
155
|
this.loading = !1;
|
|
@@ -124,7 +160,7 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
124
160
|
if (!(this.sessionLoadingMore || this.sessions.length >= this.sessionTotal)) {
|
|
125
161
|
this.sessionLoadingMore = !0;
|
|
126
162
|
try {
|
|
127
|
-
const t = this.sessionPage + 1, e = await ye({ pageNum: t, pageSize:
|
|
163
|
+
const t = this.sessionPage + 1, e = await ye({ pageNum: t, pageSize: Te });
|
|
128
164
|
this.sessions = [...this.sessions, ...e.list], this.sessionTotal = e.total, this.sessionPage = t;
|
|
129
165
|
} finally {
|
|
130
166
|
this.sessionLoadingMore = !1;
|
|
@@ -134,7 +170,7 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
134
170
|
async loadMessages(t) {
|
|
135
171
|
this.loading = !0;
|
|
136
172
|
try {
|
|
137
|
-
const e = await
|
|
173
|
+
const e = await rt(t);
|
|
138
174
|
this.currentSessionId === t && (this.messages = e);
|
|
139
175
|
} finally {
|
|
140
176
|
this.loading = !1;
|
|
@@ -142,7 +178,7 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
142
178
|
},
|
|
143
179
|
async createSession() {
|
|
144
180
|
try {
|
|
145
|
-
const t = await
|
|
181
|
+
const t = await lt();
|
|
146
182
|
return await this.loadSessions(), t;
|
|
147
183
|
} catch (t) {
|
|
148
184
|
return console.error("[@cgs/ai-chat] 创建会话失败", t), null;
|
|
@@ -150,7 +186,7 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
150
186
|
},
|
|
151
187
|
async deleteSession(t) {
|
|
152
188
|
try {
|
|
153
|
-
await
|
|
189
|
+
await ct(t), await this.loadSessions(), this.currentSessionId === t && (this.currentSessionId = null, this.messages = [], this._persist());
|
|
154
190
|
} catch (e) {
|
|
155
191
|
console.error("[@cgs/ai-chat] 删除会话失败", e);
|
|
156
192
|
}
|
|
@@ -162,15 +198,15 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
162
198
|
this.messages = [];
|
|
163
199
|
},
|
|
164
200
|
setPanelWidth(t) {
|
|
165
|
-
const
|
|
166
|
-
this.panelWidth = Math.max(320, Math.min(
|
|
201
|
+
const d = Math.floor(window.innerWidth * 0.9);
|
|
202
|
+
this.panelWidth = Math.max(320, Math.min(d, t)), this.isFullScreen = !1, this._persist();
|
|
167
203
|
},
|
|
168
204
|
toggleFullScreen() {
|
|
169
205
|
this.isFullScreen = !this.isFullScreen, this._persist();
|
|
170
206
|
},
|
|
171
207
|
async loadTokenUsage() {
|
|
172
208
|
try {
|
|
173
|
-
this.tokenUsage = await
|
|
209
|
+
this.tokenUsage = await dt();
|
|
174
210
|
} catch (t) {
|
|
175
211
|
console.error("[@cgs/ai-chat] 加载 Token 用量失败", t);
|
|
176
212
|
}
|
|
@@ -183,7 +219,7 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
183
219
|
},
|
|
184
220
|
// 内部方法:持久化关键状态到 localStorage
|
|
185
221
|
_persist() {
|
|
186
|
-
|
|
222
|
+
mt(this.$state);
|
|
187
223
|
}
|
|
188
224
|
},
|
|
189
225
|
getters: {
|
|
@@ -197,46 +233,46 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
197
233
|
/** 是否还有更多会话可加载 */
|
|
198
234
|
sessionHasMore: (t) => t.sessions.length < t.sessionTotal
|
|
199
235
|
}
|
|
200
|
-
}),
|
|
236
|
+
}), ht = /* @__PURE__ */ G({
|
|
201
237
|
__name: "AiChatFloat",
|
|
202
238
|
setup(t) {
|
|
203
|
-
const e =
|
|
204
|
-
|
|
205
|
-
},
|
|
239
|
+
const e = Ee(), d = () => e.toggleVisible(), o = C(!1), l = () => {
|
|
240
|
+
o.value = window.innerWidth < 768;
|
|
241
|
+
}, a = y(() => o.value ? {
|
|
206
242
|
position: "fixed",
|
|
207
243
|
right: "50%",
|
|
208
244
|
bottom: "24px",
|
|
209
245
|
transform: "translateX(50%)",
|
|
210
|
-
zIndex: "
|
|
246
|
+
zIndex: "999"
|
|
211
247
|
} : {
|
|
212
248
|
position: "fixed",
|
|
213
249
|
right: "24px",
|
|
214
|
-
bottom: "
|
|
215
|
-
zIndex: "
|
|
250
|
+
bottom: "80px",
|
|
251
|
+
zIndex: "999"
|
|
216
252
|
});
|
|
217
|
-
return
|
|
218
|
-
|
|
219
|
-
}),
|
|
220
|
-
window.removeEventListener("resize",
|
|
221
|
-
}), (
|
|
222
|
-
const
|
|
223
|
-
return
|
|
224
|
-
class:
|
|
225
|
-
style:
|
|
226
|
-
onClick:
|
|
253
|
+
return be(() => {
|
|
254
|
+
l(), window.addEventListener("resize", l);
|
|
255
|
+
}), Ie(() => {
|
|
256
|
+
window.removeEventListener("resize", l);
|
|
257
|
+
}), (m, b) => {
|
|
258
|
+
const c = R("el-icon"), _ = R("el-tooltip");
|
|
259
|
+
return r(), h("div", {
|
|
260
|
+
class: F(["ai-chat-float", { "is-mobile": o.value }]),
|
|
261
|
+
style: Ae(a.value),
|
|
262
|
+
onClick: d
|
|
227
263
|
}, [
|
|
228
|
-
i(
|
|
264
|
+
i(_, {
|
|
229
265
|
content: "AI助手",
|
|
230
266
|
placement: "left",
|
|
231
267
|
"show-after": 300
|
|
232
268
|
}, {
|
|
233
|
-
default:
|
|
234
|
-
|
|
235
|
-
class:
|
|
269
|
+
default: u(() => [
|
|
270
|
+
p("div", {
|
|
271
|
+
class: F(["float-btn", { "is-active": g(e).visible }])
|
|
236
272
|
}, [
|
|
237
|
-
i(
|
|
238
|
-
default:
|
|
239
|
-
i(
|
|
273
|
+
i(c, { size: 24 }, {
|
|
274
|
+
default: u(() => [
|
|
275
|
+
i(g(Ge))
|
|
240
276
|
]),
|
|
241
277
|
_: 1
|
|
242
278
|
})
|
|
@@ -247,319 +283,328 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
247
283
|
], 6);
|
|
248
284
|
};
|
|
249
285
|
}
|
|
250
|
-
}),
|
|
251
|
-
const
|
|
252
|
-
for (const [
|
|
253
|
-
|
|
254
|
-
return
|
|
255
|
-
},
|
|
286
|
+
}), q = (t, e) => {
|
|
287
|
+
const d = t.__vccOpts || t;
|
|
288
|
+
for (const [o, l] of e)
|
|
289
|
+
d[o] = l;
|
|
290
|
+
return d;
|
|
291
|
+
}, $e = /* @__PURE__ */ q(ht, [["__scopeId", "data-v-fc7be81c"]]), pt = { class: "avatar" }, ft = { class: "content" }, vt = {
|
|
256
292
|
key: 0,
|
|
257
293
|
class: "message-images"
|
|
258
|
-
},
|
|
294
|
+
}, _t = ["src"], St = ["innerHTML"], kt = ["innerHTML"], wt = {
|
|
259
295
|
key: 1,
|
|
260
296
|
class: "loading-placeholder"
|
|
261
|
-
}, yt = { class: "time" },
|
|
297
|
+
}, yt = { class: "time" }, Tt = /* @__PURE__ */ G({
|
|
262
298
|
__name: "AiChatMessage",
|
|
263
299
|
props: {
|
|
264
300
|
message: {}
|
|
265
301
|
},
|
|
266
302
|
setup(t) {
|
|
267
|
-
const e = t,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
303
|
+
const e = t, d = y(() => {
|
|
304
|
+
const a = e.message.content || "";
|
|
305
|
+
if (!a) return "";
|
|
306
|
+
const m = [], b = (_) => {
|
|
307
|
+
const S = m.length;
|
|
308
|
+
return m.push(_), `\0PH${S}\0`;
|
|
309
|
+
};
|
|
310
|
+
let c = a;
|
|
311
|
+
return c = c.replace(/```(\w*)\n([\s\S]*?)```/g, (_, S, x) => b(`<pre class="code-block"><code>${o(x)}</code></pre>`)), c = c.replace(/`([^`]+)`/g, (_, S) => b(`<code class="inline-code">${o(S)}</code>`)), c = c.replace(/\*\*(.+?)\*\*/g, (_, S) => b(`<strong>${o(S)}</strong>`)), c = o(c), c = c.replace(/\n/g, "<br>"), c = c.replace(/\x00PH(\d+)\x00/g, (_, S) => m[parseInt(S)]), c;
|
|
312
|
+
});
|
|
313
|
+
function o(a) {
|
|
314
|
+
return a.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
315
|
+
}
|
|
316
|
+
const l = (a) => a ? new Date(a).toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" }) : "";
|
|
317
|
+
return (a, m) => {
|
|
318
|
+
const b = R("el-icon");
|
|
319
|
+
return r(), h("div", {
|
|
320
|
+
class: F(["message-item", [t.message.role]])
|
|
275
321
|
}, [
|
|
276
|
-
|
|
277
|
-
t.message.role === "assistant" ? (
|
|
322
|
+
p("div", pt, [
|
|
323
|
+
t.message.role === "assistant" ? (r(), B(b, {
|
|
278
324
|
key: 0,
|
|
279
325
|
size: 20
|
|
280
326
|
}, {
|
|
281
|
-
default:
|
|
282
|
-
i(
|
|
327
|
+
default: u(() => [
|
|
328
|
+
i(g(qe))
|
|
283
329
|
]),
|
|
284
330
|
_: 1
|
|
285
|
-
})) : (
|
|
331
|
+
})) : (r(), B(b, {
|
|
286
332
|
key: 1,
|
|
287
333
|
size: 20
|
|
288
334
|
}, {
|
|
289
|
-
default:
|
|
290
|
-
i(
|
|
335
|
+
default: u(() => [
|
|
336
|
+
i(g(Ke))
|
|
291
337
|
]),
|
|
292
338
|
_: 1
|
|
293
339
|
}))
|
|
294
340
|
]),
|
|
295
|
-
|
|
296
|
-
t.message.role === "user" ? (
|
|
297
|
-
t.message.images && t.message.images.length > 0 ? (
|
|
298
|
-
(
|
|
299
|
-
key:
|
|
300
|
-
src:
|
|
341
|
+
p("div", ft, [
|
|
342
|
+
t.message.role === "user" ? (r(), h(U, { key: 0 }, [
|
|
343
|
+
t.message.images && t.message.images.length > 0 ? (r(), h("div", vt, [
|
|
344
|
+
(r(!0), h(U, null, J(t.message.images, (c, _) => (r(), h("img", {
|
|
345
|
+
key: _,
|
|
346
|
+
src: c,
|
|
301
347
|
class: "message-image",
|
|
302
348
|
alt: "图片"
|
|
303
|
-
}, null, 8,
|
|
304
|
-
])) :
|
|
305
|
-
t.message.content && t.message.content !== "[图片]" ? (
|
|
349
|
+
}, null, 8, _t))), 128))
|
|
350
|
+
])) : I("", !0),
|
|
351
|
+
t.message.content && t.message.content !== "[图片]" ? (r(), h("div", {
|
|
306
352
|
key: 1,
|
|
307
353
|
class: "text",
|
|
308
|
-
innerHTML:
|
|
309
|
-
}, null, 8,
|
|
310
|
-
], 64)) : (
|
|
311
|
-
t.message.content ? (
|
|
354
|
+
innerHTML: d.value
|
|
355
|
+
}, null, 8, St)) : I("", !0)
|
|
356
|
+
], 64)) : (r(), h(U, { key: 1 }, [
|
|
357
|
+
t.message.content ? (r(), h("div", {
|
|
312
358
|
key: 0,
|
|
313
359
|
class: "text",
|
|
314
|
-
innerHTML:
|
|
315
|
-
}, null, 8,
|
|
360
|
+
innerHTML: d.value
|
|
361
|
+
}, null, 8, kt)) : (r(), h("div", wt, "正在思考..."))
|
|
316
362
|
], 64)),
|
|
317
|
-
|
|
363
|
+
p("div", yt, P(l(t.message.createTime)), 1)
|
|
318
364
|
])
|
|
319
365
|
], 2);
|
|
320
366
|
};
|
|
321
367
|
}
|
|
322
|
-
}),
|
|
368
|
+
}), bt = /* @__PURE__ */ q(Tt, [["__scopeId", "data-v-171a31c7"]]), It = {
|
|
323
369
|
key: 0,
|
|
324
370
|
class: "width-tooltip"
|
|
325
|
-
},
|
|
371
|
+
}, At = { class: "panel-container" }, Mt = { class: "panel-header" }, Ct = { class: "header-left" }, Et = {
|
|
326
372
|
key: 0,
|
|
327
373
|
class: "token-usage"
|
|
328
|
-
},
|
|
374
|
+
}, $t = {
|
|
329
375
|
key: 1,
|
|
330
376
|
class: "preset-btns"
|
|
331
|
-
},
|
|
377
|
+
}, xt = { class: "header-right" }, Lt = { class: "chat-container" }, Pt = {
|
|
332
378
|
key: 0,
|
|
333
379
|
class: "session-list"
|
|
334
|
-
},
|
|
380
|
+
}, Rt = { class: "session-header" }, Ut = ["onClick"], Wt = { class: "session-title" }, zt = { class: "session-meta" }, Ft = {
|
|
335
381
|
key: 0,
|
|
336
382
|
class: "session-load-more"
|
|
337
|
-
},
|
|
383
|
+
}, Dt = {
|
|
338
384
|
key: 1,
|
|
339
385
|
class: "session-load-more session-no-more"
|
|
340
|
-
},
|
|
386
|
+
}, Ht = { class: "messages-area" }, Ot = { class: "messages-content" }, Nt = {
|
|
341
387
|
key: 0,
|
|
342
388
|
class: "typing-indicator"
|
|
343
|
-
},
|
|
389
|
+
}, Vt = {
|
|
344
390
|
key: 0,
|
|
345
391
|
class: "pending-images"
|
|
346
|
-
},
|
|
392
|
+
}, Xt = { class: "image-index" }, jt = ["src"], Jt = { class: "input-area" }, Bt = 4, Gt = 0.25, qt = 0.38, Kt = /* @__PURE__ */ G({
|
|
347
393
|
__name: "AiChatDrawer",
|
|
348
394
|
setup(t) {
|
|
349
|
-
const e =
|
|
350
|
-
let
|
|
351
|
-
const
|
|
395
|
+
const e = Ee();
|
|
396
|
+
let d = new AbortController();
|
|
397
|
+
const o = y({
|
|
352
398
|
get: () => e.visible,
|
|
353
399
|
set: (s) => e.setVisible(s)
|
|
354
|
-
}),
|
|
355
|
-
|
|
356
|
-
},
|
|
357
|
-
const s = {
|
|
358
|
-
position: "fixed",
|
|
359
|
-
top: "0",
|
|
360
|
-
height: "100vh",
|
|
361
|
-
zIndex: "10000",
|
|
362
|
-
display: "flex",
|
|
363
|
-
flexDirection: "row"
|
|
364
|
-
};
|
|
365
|
-
return y.value ? {
|
|
366
|
-
...s,
|
|
367
|
-
left: "0",
|
|
368
|
-
right: "0",
|
|
369
|
-
width: "100%"
|
|
370
|
-
} : k.value ? { ...s, right: "0", width: "100%" } : { ...s, right: "0", width: `${a.value}px` };
|
|
371
|
-
}), j = p(() => {
|
|
400
|
+
}), l = y(() => e.panelWidth), a = y(() => e.isFullScreen), m = C(!1), b = () => {
|
|
401
|
+
m.value = window.innerWidth < 768;
|
|
402
|
+
}, c = y(() => m.value ? { width: "100%" } : a.value ? { width: "100%" } : { width: `${l.value}px` }), _ = y(() => {
|
|
372
403
|
const s = e.tokenUsage;
|
|
373
404
|
return s ? s.limitTokens === 0 ? `${s.usedTokens} tokens` : `${s.usedTokens}/${s.limitTokens}` : "";
|
|
374
|
-
}),
|
|
405
|
+
}), S = y(() => {
|
|
375
406
|
const s = e.tokenUsage;
|
|
376
407
|
return s ? s.limitTokens === 0 ? `今日已使用 ${s.usedTokens} tokens(不限制)` : s.limitReached ? "今日配额已用完,请明天再试" : `今日已使用 ${s.usedTokens}/${s.limitTokens} tokens,剩余 ${s.remainingTokens}` : "";
|
|
377
|
-
}),
|
|
378
|
-
|
|
379
|
-
},
|
|
380
|
-
let
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
},
|
|
384
|
-
s.touches.length === 1 && (
|
|
385
|
-
}, K = (s) => {
|
|
386
|
-
E.value && (_ && cancelAnimationFrame(_), _ = requestAnimationFrame(() => {
|
|
387
|
-
const n = D.value + (O.value - s.clientX), u = Math.max(320, Math.min(window.innerWidth / 2, n));
|
|
388
|
-
e.setPanelWidth(u);
|
|
389
|
-
}));
|
|
408
|
+
}), x = C(""), D = C(!1), E = C([]), O = C(), le = C(), N = C(window.innerWidth), re = () => {
|
|
409
|
+
N.value = window.innerWidth, b();
|
|
410
|
+
}, ce = y(() => m.value ? window.innerWidth : Math.max(320, Math.round(N.value * Gt))), de = y(() => m.value ? window.innerWidth : Math.max(420, Math.round(N.value * qt))), K = y(() => l.value / N.value), Le = y(() => !a.value && K.value <= 0.3), Pe = y(() => !a.value && K.value > 0.3 && K.value <= 0.45), Re = y(() => `窄 (${ce.value}px)`), Ue = y(() => `宽 (${de.value}px)`), W = C(!1), V = C(0), X = C(0);
|
|
411
|
+
let T = null;
|
|
412
|
+
const We = (s) => {
|
|
413
|
+
W.value = !0, V.value = s.clientX, X.value = l.value, document.addEventListener("mousemove", Y), document.addEventListener("mouseup", Q), document.body.style.cursor = "ew-resize", document.body.style.userSelect = "none";
|
|
414
|
+
}, ze = (s) => {
|
|
415
|
+
s.touches.length === 1 && (W.value = !0, V.value = s.touches[0].clientX, X.value = l.value, document.addEventListener("touchmove", Z), document.addEventListener("touchend", ee));
|
|
390
416
|
}, Y = (s) => {
|
|
391
|
-
|
|
392
|
-
const n =
|
|
393
|
-
e.setPanelWidth(
|
|
417
|
+
W.value && (T && cancelAnimationFrame(T), T = requestAnimationFrame(() => {
|
|
418
|
+
const n = X.value + (V.value - s.clientX), f = Math.max(320, Math.min(window.innerWidth / 2, n));
|
|
419
|
+
e.setPanelWidth(f);
|
|
420
|
+
}));
|
|
421
|
+
}, Z = (s) => {
|
|
422
|
+
!W.value || s.touches.length !== 1 || (T && cancelAnimationFrame(T), T = requestAnimationFrame(() => {
|
|
423
|
+
const n = X.value + (V.value - s.touches[0].clientX), f = Math.max(320, Math.min(window.innerWidth / 2, n));
|
|
424
|
+
e.setPanelWidth(f);
|
|
394
425
|
}));
|
|
395
|
-
}, Z = () => {
|
|
396
|
-
E.value = !1, _ && (cancelAnimationFrame(_), _ = null), document.removeEventListener("mousemove", K), document.removeEventListener("mouseup", Z), document.body.style.cursor = "", document.body.style.userSelect = "";
|
|
397
426
|
}, Q = () => {
|
|
398
|
-
|
|
399
|
-
},
|
|
427
|
+
W.value = !1, T && (cancelAnimationFrame(T), T = null), document.removeEventListener("mousemove", Y), document.removeEventListener("mouseup", Q), document.body.style.cursor = "", document.body.style.userSelect = "";
|
|
428
|
+
}, ee = () => {
|
|
429
|
+
W.value = !1, T && (cancelAnimationFrame(T), T = null), document.removeEventListener("touchmove", Z), document.removeEventListener("touchend", ee);
|
|
430
|
+
}, ue = (s) => e.setPanelWidth(s), Fe = () => e.toggleFullScreen(), ge = () => e.setVisible(!1), De = async (s) => {
|
|
400
431
|
const n = s.clipboardData?.items;
|
|
401
432
|
if (n)
|
|
402
|
-
for (let
|
|
403
|
-
const
|
|
404
|
-
if (
|
|
405
|
-
if (s.preventDefault(),
|
|
406
|
-
|
|
433
|
+
for (let f = 0; f < n.length; f++) {
|
|
434
|
+
const k = n[f];
|
|
435
|
+
if (k.type.startsWith("image/")) {
|
|
436
|
+
if (s.preventDefault(), E.value.length >= Bt) {
|
|
437
|
+
z.warning("最多只能上传4张图片");
|
|
407
438
|
return;
|
|
408
439
|
}
|
|
409
|
-
const
|
|
410
|
-
if (
|
|
411
|
-
const
|
|
412
|
-
|
|
440
|
+
const w = k.getAsFile();
|
|
441
|
+
if (w) {
|
|
442
|
+
const $ = await He(w);
|
|
443
|
+
E.value.push($);
|
|
413
444
|
}
|
|
414
445
|
}
|
|
415
446
|
}
|
|
416
|
-
},
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
}),
|
|
420
|
-
const n =
|
|
447
|
+
}, He = (s) => new Promise((n) => {
|
|
448
|
+
const f = new FileReader();
|
|
449
|
+
f.onload = (k) => n(k.target.result), f.readAsDataURL(s);
|
|
450
|
+
}), Oe = (s) => s?.length > 30 ? s.substring(0, 30) + "..." : s, Ne = ({ scrollTop: s }) => {
|
|
451
|
+
const n = le.value?.wrapRef;
|
|
421
452
|
n && s + n.clientHeight >= n.scrollHeight - 150 && e.loadMoreSessions();
|
|
422
|
-
},
|
|
423
|
-
|
|
453
|
+
}, me = () => {
|
|
454
|
+
O.value?.wrapRef && (O.value.wrapRef.scrollTop = O.value.wrapRef.scrollHeight);
|
|
424
455
|
};
|
|
425
|
-
|
|
426
|
-
s && (e.
|
|
456
|
+
_e(() => e.messages.length, () => Se(me)), _e(o, (s) => {
|
|
457
|
+
s && (e.currentSessionId || e.loadSessions(), e.loadTokenUsage());
|
|
427
458
|
});
|
|
428
459
|
const Ve = async () => {
|
|
429
460
|
const s = await e.createSession();
|
|
430
|
-
s ? (e.setCurrentSession(s, !1),
|
|
431
|
-
},
|
|
432
|
-
e.setCurrentSession(s.id),
|
|
433
|
-
},
|
|
461
|
+
s ? (e.setCurrentSession(s, !1), D.value = !1) : z.error("创建对话失败,请检查网络或重新登录");
|
|
462
|
+
}, Xe = (s) => {
|
|
463
|
+
e.setCurrentSession(s.id), D.value = !1;
|
|
464
|
+
}, je = async (s) => {
|
|
434
465
|
await e.deleteSession(s);
|
|
435
|
-
},
|
|
436
|
-
const s =
|
|
466
|
+
}, he = async () => {
|
|
467
|
+
const s = x.value.trim(), n = [...E.value];
|
|
437
468
|
if (!s && n.length === 0 || e.sending) return;
|
|
438
|
-
|
|
439
|
-
let
|
|
440
|
-
|
|
441
|
-
|
|
469
|
+
x.value = "", E.value = [], e.setSending(!0), d = new AbortController();
|
|
470
|
+
let f = e.currentSessionId;
|
|
471
|
+
if (!f) {
|
|
472
|
+
if (f = await e.createSession(), !f) {
|
|
473
|
+
e.setSending(!1), x.value = s, E.value = n, z.error("创建对话失败,请检查网络或重新登录");
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
e.setCurrentSession(f, !1);
|
|
477
|
+
}
|
|
478
|
+
const k = {
|
|
442
479
|
id: Date.now(),
|
|
443
|
-
sessionId:
|
|
480
|
+
sessionId: f,
|
|
444
481
|
role: "user",
|
|
445
482
|
content: s || "[图片]",
|
|
446
483
|
images: n.length > 0 ? n : void 0,
|
|
447
484
|
createTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
448
485
|
};
|
|
449
|
-
e.addMessage(
|
|
450
|
-
const
|
|
486
|
+
e.addMessage(k);
|
|
487
|
+
const w = {
|
|
451
488
|
id: Date.now() + 1,
|
|
452
|
-
sessionId:
|
|
489
|
+
sessionId: f,
|
|
453
490
|
role: "assistant",
|
|
454
491
|
content: "",
|
|
455
492
|
createTime: (/* @__PURE__ */ new Date()).toISOString()
|
|
456
493
|
};
|
|
457
|
-
e.addMessage(
|
|
494
|
+
e.addMessage(w);
|
|
458
495
|
try {
|
|
459
|
-
const
|
|
460
|
-
sessionId:
|
|
461
|
-
// string | undefined
|
|
496
|
+
const L = (await ut({
|
|
497
|
+
sessionId: f,
|
|
462
498
|
message: s || "[图片]",
|
|
463
499
|
images: n.length > 0 ? n : void 0,
|
|
464
|
-
signal:
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
let w = "";
|
|
500
|
+
signal: d.signal
|
|
501
|
+
})).body?.getReader(), v = new TextDecoder();
|
|
502
|
+
if (L) {
|
|
503
|
+
let A = "";
|
|
469
504
|
for (; ; ) {
|
|
470
|
-
const { done:
|
|
471
|
-
if (
|
|
472
|
-
|
|
473
|
-
const
|
|
505
|
+
const { done: pe, value: Je } = await L.read();
|
|
506
|
+
if (pe) break;
|
|
507
|
+
A += v.decode(Je, { stream: !0 });
|
|
508
|
+
const fe = A.split(`
|
|
474
509
|
`);
|
|
475
|
-
|
|
510
|
+
A = fe.pop() ?? "";
|
|
476
511
|
let ve = "";
|
|
477
|
-
for (const
|
|
478
|
-
if (
|
|
479
|
-
ve =
|
|
480
|
-
else if (
|
|
512
|
+
for (const j of fe)
|
|
513
|
+
if (j.startsWith("event:"))
|
|
514
|
+
ve = j.slice(6).trim();
|
|
515
|
+
else if (j.startsWith("data:"))
|
|
481
516
|
try {
|
|
482
|
-
const
|
|
483
|
-
if (ve === "error" ||
|
|
484
|
-
e.updateLastAssistantMessage(
|
|
517
|
+
const M = JSON.parse(j.slice(5).trim());
|
|
518
|
+
if (ve === "error" || M.error) {
|
|
519
|
+
e.updateLastAssistantMessage(M.error || "服务异常,请重试。"), z.error(M.error || "服务异常,请重试");
|
|
485
520
|
break;
|
|
486
521
|
}
|
|
487
|
-
!
|
|
522
|
+
!M.done && M.content && (e.updateLastAssistantMessage(M.content), Se(me)), M.sessionId && !e.currentSessionId && e.setCurrentSession(M.sessionId), M.done && M.usage && e.updateTokenUsage(M.usage.totalTokens);
|
|
488
523
|
} catch {
|
|
489
524
|
}
|
|
490
525
|
}
|
|
491
526
|
}
|
|
492
|
-
} catch (
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
527
|
+
} catch ($) {
|
|
528
|
+
if ($.name === "AbortError")
|
|
529
|
+
console.log("[@cgs/ai-chat] 请求已取消");
|
|
530
|
+
else if ($.message?.startsWith("AUTH_EXPIRED:")) {
|
|
531
|
+
const L = $.message.replace("AUTH_EXPIRED:", "");
|
|
532
|
+
console.error("[@cgs/ai-chat] 认证过期", L), e.updateLastAssistantMessage(`认证失败:${L}`), z.error({
|
|
533
|
+
message: L,
|
|
534
|
+
duration: 5e3,
|
|
535
|
+
showClose: !0
|
|
536
|
+
});
|
|
537
|
+
} else
|
|
538
|
+
console.error("[@cgs/ai-chat] 发送消息失败", $), e.updateLastAssistantMessage("抱歉,发生了错误,请重试。"), z.error({
|
|
539
|
+
message: "消息发送失败,请检查网络连接",
|
|
540
|
+
duration: 3e3,
|
|
541
|
+
showClose: !0
|
|
542
|
+
});
|
|
498
543
|
} finally {
|
|
499
544
|
e.setSending(!1), e.loadSessions();
|
|
500
545
|
}
|
|
501
546
|
};
|
|
502
|
-
return
|
|
503
|
-
window.addEventListener("resize",
|
|
504
|
-
}),
|
|
505
|
-
|
|
547
|
+
return be(() => {
|
|
548
|
+
window.addEventListener("resize", re), b();
|
|
549
|
+
}), Ie(() => {
|
|
550
|
+
d.abort(), window.removeEventListener("resize", re), document.removeEventListener("mousemove", Y), document.removeEventListener("mouseup", Q), document.removeEventListener("touchmove", Z), document.removeEventListener("touchend", ee), T && cancelAnimationFrame(T);
|
|
506
551
|
}), (s, n) => {
|
|
507
|
-
const
|
|
508
|
-
return
|
|
509
|
-
i(
|
|
510
|
-
default:
|
|
511
|
-
|
|
552
|
+
const f = R("el-tooltip"), k = R("el-icon"), w = R("el-button"), $ = R("el-empty"), L = R("el-input");
|
|
553
|
+
return r(), h(U, null, [
|
|
554
|
+
i(te, { name: "slide" }, {
|
|
555
|
+
default: u(() => [
|
|
556
|
+
o.value ? (r(), h("div", {
|
|
512
557
|
key: 0,
|
|
513
|
-
class:
|
|
514
|
-
style:
|
|
558
|
+
class: F(["ai-chat-panel", { "full-screen": a.value, "is-mobile": m.value }]),
|
|
559
|
+
style: Ae(c.value)
|
|
515
560
|
}, [
|
|
516
|
-
|
|
561
|
+
m.value ? I("", !0) : (r(), h("div", {
|
|
517
562
|
key: 0,
|
|
518
563
|
class: "resize-handle",
|
|
519
|
-
onMousedown:
|
|
520
|
-
onTouchstart:
|
|
564
|
+
onMousedown: We,
|
|
565
|
+
onTouchstart: se(ze, ["prevent"])
|
|
521
566
|
}, [
|
|
522
|
-
n[5] || (n[5] =
|
|
523
|
-
i(
|
|
524
|
-
default:
|
|
525
|
-
|
|
567
|
+
n[5] || (n[5] = p("div", { class: "resize-bar" }, null, -1)),
|
|
568
|
+
i(te, { name: "fade" }, {
|
|
569
|
+
default: u(() => [
|
|
570
|
+
W.value ? (r(), h("div", It, P(Math.round(l.value)) + "px ", 1)) : I("", !0)
|
|
526
571
|
]),
|
|
527
572
|
_: 1
|
|
528
573
|
})
|
|
529
574
|
], 32)),
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
n[6] || (n[6] =
|
|
534
|
-
|
|
535
|
-
i(
|
|
536
|
-
content:
|
|
575
|
+
p("div", At, [
|
|
576
|
+
p("div", Mt, [
|
|
577
|
+
p("div", Ct, [
|
|
578
|
+
n[6] || (n[6] = p("span", { class: "title" }, "AI助手", -1)),
|
|
579
|
+
g(e).tokenUsage ? (r(), h("div", Et, [
|
|
580
|
+
i(f, {
|
|
581
|
+
content: S.value,
|
|
537
582
|
placement: "bottom"
|
|
538
583
|
}, {
|
|
539
|
-
default:
|
|
540
|
-
|
|
541
|
-
class:
|
|
542
|
-
},
|
|
584
|
+
default: u(() => [
|
|
585
|
+
p("span", {
|
|
586
|
+
class: F({ "limit-warning": g(e).tokenUsage.limitReached })
|
|
587
|
+
}, P(_.value), 3)
|
|
543
588
|
]),
|
|
544
589
|
_: 1
|
|
545
590
|
}, 8, ["content"])
|
|
546
|
-
])) :
|
|
547
|
-
|
|
548
|
-
i(
|
|
549
|
-
content:
|
|
591
|
+
])) : I("", !0),
|
|
592
|
+
m.value ? I("", !0) : (r(), h("div", $t, [
|
|
593
|
+
i(f, {
|
|
594
|
+
content: Re.value,
|
|
550
595
|
placement: "bottom"
|
|
551
596
|
}, {
|
|
552
|
-
default:
|
|
553
|
-
i(
|
|
597
|
+
default: u(() => [
|
|
598
|
+
i(w, {
|
|
554
599
|
size: "small",
|
|
555
600
|
type: Le.value ? "primary" : "default",
|
|
556
601
|
link: "",
|
|
557
|
-
onClick: n[0] || (n[0] = (
|
|
602
|
+
onClick: n[0] || (n[0] = (v) => ue(ce.value))
|
|
558
603
|
}, {
|
|
559
|
-
default:
|
|
560
|
-
i(
|
|
561
|
-
default:
|
|
562
|
-
i(
|
|
604
|
+
default: u(() => [
|
|
605
|
+
i(k, null, {
|
|
606
|
+
default: u(() => [
|
|
607
|
+
i(g(Ye))
|
|
563
608
|
]),
|
|
564
609
|
_: 1
|
|
565
610
|
})
|
|
@@ -569,21 +614,21 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
569
614
|
]),
|
|
570
615
|
_: 1
|
|
571
616
|
}, 8, ["content"]),
|
|
572
|
-
i(
|
|
573
|
-
content:
|
|
617
|
+
i(f, {
|
|
618
|
+
content: Ue.value,
|
|
574
619
|
placement: "bottom"
|
|
575
620
|
}, {
|
|
576
|
-
default:
|
|
577
|
-
i(
|
|
621
|
+
default: u(() => [
|
|
622
|
+
i(w, {
|
|
578
623
|
size: "small",
|
|
579
|
-
type:
|
|
624
|
+
type: Pe.value ? "primary" : "default",
|
|
580
625
|
link: "",
|
|
581
|
-
onClick: n[1] || (n[1] = (
|
|
626
|
+
onClick: n[1] || (n[1] = (v) => ue(de.value))
|
|
582
627
|
}, {
|
|
583
|
-
default:
|
|
584
|
-
i(
|
|
585
|
-
default:
|
|
586
|
-
i(
|
|
628
|
+
default: u(() => [
|
|
629
|
+
i(k, null, {
|
|
630
|
+
default: u(() => [
|
|
631
|
+
i(g(Ze))
|
|
587
632
|
]),
|
|
588
633
|
_: 1
|
|
589
634
|
})
|
|
@@ -593,21 +638,21 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
593
638
|
]),
|
|
594
639
|
_: 1
|
|
595
640
|
}, 8, ["content"]),
|
|
596
|
-
i(
|
|
597
|
-
content:
|
|
641
|
+
i(f, {
|
|
642
|
+
content: a.value ? "退出全屏" : "全屏",
|
|
598
643
|
placement: "bottom"
|
|
599
644
|
}, {
|
|
600
|
-
default:
|
|
601
|
-
i(
|
|
645
|
+
default: u(() => [
|
|
646
|
+
i(w, {
|
|
602
647
|
size: "small",
|
|
603
|
-
type:
|
|
648
|
+
type: a.value ? "primary" : "default",
|
|
604
649
|
link: "",
|
|
605
|
-
onClick:
|
|
650
|
+
onClick: Fe
|
|
606
651
|
}, {
|
|
607
|
-
default:
|
|
608
|
-
i(
|
|
609
|
-
default:
|
|
610
|
-
i(
|
|
652
|
+
default: u(() => [
|
|
653
|
+
i(k, null, {
|
|
654
|
+
default: u(() => [
|
|
655
|
+
i(g(Qe))
|
|
611
656
|
]),
|
|
612
657
|
_: 1
|
|
613
658
|
})
|
|
@@ -619,32 +664,32 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
619
664
|
}, 8, ["content"])
|
|
620
665
|
]))
|
|
621
666
|
]),
|
|
622
|
-
|
|
623
|
-
i(
|
|
667
|
+
p("div", xt, [
|
|
668
|
+
i(w, {
|
|
624
669
|
type: "primary",
|
|
625
670
|
link: "",
|
|
626
671
|
onClick: Ve
|
|
627
672
|
}, {
|
|
628
|
-
default:
|
|
629
|
-
i(
|
|
630
|
-
default:
|
|
631
|
-
i(
|
|
673
|
+
default: u(() => [
|
|
674
|
+
i(k, null, {
|
|
675
|
+
default: u(() => [
|
|
676
|
+
i(g(et))
|
|
632
677
|
]),
|
|
633
678
|
_: 1
|
|
634
679
|
}),
|
|
635
|
-
n[7] || (n[7] =
|
|
680
|
+
n[7] || (n[7] = ne("新对话 ", -1))
|
|
636
681
|
]),
|
|
637
682
|
_: 1
|
|
638
683
|
}),
|
|
639
|
-
i(
|
|
684
|
+
i(w, {
|
|
640
685
|
type: "default",
|
|
641
686
|
link: "",
|
|
642
|
-
onClick:
|
|
687
|
+
onClick: ge
|
|
643
688
|
}, {
|
|
644
|
-
default:
|
|
645
|
-
i(
|
|
646
|
-
default:
|
|
647
|
-
i(
|
|
689
|
+
default: u(() => [
|
|
690
|
+
i(k, null, {
|
|
691
|
+
default: u(() => [
|
|
692
|
+
i(g(ke))
|
|
648
693
|
]),
|
|
649
694
|
_: 1
|
|
650
695
|
})
|
|
@@ -653,120 +698,120 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
653
698
|
})
|
|
654
699
|
])
|
|
655
700
|
]),
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
n[9] || (n[9] =
|
|
660
|
-
i(
|
|
701
|
+
p("div", Lt, [
|
|
702
|
+
D.value ? (r(), h("div", Pt, [
|
|
703
|
+
p("div", Rt, [
|
|
704
|
+
n[9] || (n[9] = p("span", null, "历史对话", -1)),
|
|
705
|
+
i(w, {
|
|
661
706
|
type: "primary",
|
|
662
707
|
link: "",
|
|
663
708
|
size: "small",
|
|
664
|
-
onClick: n[2] || (n[2] = (
|
|
709
|
+
onClick: n[2] || (n[2] = (v) => D.value = !1)
|
|
665
710
|
}, {
|
|
666
|
-
default:
|
|
667
|
-
|
|
711
|
+
default: u(() => [...n[8] || (n[8] = [
|
|
712
|
+
ne("返回聊天", -1)
|
|
668
713
|
])]),
|
|
669
714
|
_: 1
|
|
670
715
|
})
|
|
671
716
|
]),
|
|
672
|
-
i(
|
|
717
|
+
i(g(we), {
|
|
673
718
|
ref_key: "sessionScrollbarRef",
|
|
674
|
-
ref:
|
|
675
|
-
height: (
|
|
719
|
+
ref: le,
|
|
720
|
+
height: (m.value, "calc(100vh - 200px)"),
|
|
676
721
|
onScroll: Ne
|
|
677
722
|
}, {
|
|
678
|
-
default:
|
|
679
|
-
(
|
|
680
|
-
key:
|
|
681
|
-
class:
|
|
682
|
-
onClick: (
|
|
723
|
+
default: u(() => [
|
|
724
|
+
(r(!0), h(U, null, J(g(e).sessions, (v) => (r(), h("div", {
|
|
725
|
+
key: v.id,
|
|
726
|
+
class: F(["session-item", { active: v.id === g(e).currentSessionId }]),
|
|
727
|
+
onClick: (A) => Xe(v)
|
|
683
728
|
}, [
|
|
684
|
-
i(
|
|
685
|
-
content:
|
|
729
|
+
i(f, {
|
|
730
|
+
content: v.title,
|
|
686
731
|
placement: "left",
|
|
687
732
|
"show-after": 500
|
|
688
733
|
}, {
|
|
689
|
-
default:
|
|
690
|
-
|
|
734
|
+
default: u(() => [
|
|
735
|
+
p("div", Wt, P(Oe(v.title)), 1)
|
|
691
736
|
]),
|
|
692
737
|
_: 2
|
|
693
738
|
}, 1032, ["content"]),
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
i(
|
|
739
|
+
p("div", zt, [
|
|
740
|
+
p("span", null, P(v.messageCount) + "条消息", 1),
|
|
741
|
+
i(w, {
|
|
697
742
|
type: "danger",
|
|
698
743
|
link: "",
|
|
699
744
|
size: "small",
|
|
700
|
-
onClick:
|
|
745
|
+
onClick: se((A) => je(v.id), ["stop"])
|
|
701
746
|
}, {
|
|
702
|
-
default:
|
|
703
|
-
|
|
747
|
+
default: u(() => [...n[10] || (n[10] = [
|
|
748
|
+
ne("删除", -1)
|
|
704
749
|
])]),
|
|
705
750
|
_: 1
|
|
706
751
|
}, 8, ["onClick"])
|
|
707
752
|
])
|
|
708
|
-
], 10,
|
|
709
|
-
|
|
710
|
-
i(
|
|
711
|
-
default:
|
|
712
|
-
i(
|
|
753
|
+
], 10, Ut))), 128)),
|
|
754
|
+
g(e).sessionLoadingMore ? (r(), h("div", Ft, [
|
|
755
|
+
i(k, { class: "is-loading" }, {
|
|
756
|
+
default: u(() => [
|
|
757
|
+
i(g(tt))
|
|
713
758
|
]),
|
|
714
759
|
_: 1
|
|
715
760
|
}),
|
|
716
|
-
n[11] || (n[11] =
|
|
717
|
-
])) :
|
|
718
|
-
|
|
761
|
+
n[11] || (n[11] = p("span", null, "加载中...", -1))
|
|
762
|
+
])) : g(e).sessions.length > 0 && !g(e).sessionHasMore ? (r(), h("div", Dt, " 共 " + P(g(e).sessionTotal) + " 条对话 ", 1)) : I("", !0),
|
|
763
|
+
g(e).sessions.length === 0 ? (r(), B($, {
|
|
719
764
|
key: 2,
|
|
720
765
|
description: "暂无历史对话"
|
|
721
|
-
})) :
|
|
766
|
+
})) : I("", !0)
|
|
722
767
|
]),
|
|
723
768
|
_: 1
|
|
724
769
|
}, 8, ["height"])
|
|
725
|
-
])) : (
|
|
726
|
-
|
|
727
|
-
i(
|
|
770
|
+
])) : (r(), h(U, { key: 1 }, [
|
|
771
|
+
p("div", Ht, [
|
|
772
|
+
i(g(we), {
|
|
728
773
|
ref_key: "scrollbarRef",
|
|
729
|
-
ref:
|
|
774
|
+
ref: O,
|
|
730
775
|
height: "100%"
|
|
731
776
|
}, {
|
|
732
|
-
default:
|
|
733
|
-
|
|
734
|
-
(
|
|
735
|
-
key:
|
|
736
|
-
message:
|
|
777
|
+
default: u(() => [
|
|
778
|
+
p("div", Ot, [
|
|
779
|
+
(r(!0), h(U, null, J(g(e).messages, (v, A) => (r(), B(bt, {
|
|
780
|
+
key: A,
|
|
781
|
+
message: v
|
|
737
782
|
}, null, 8, ["message"]))), 128)),
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
])])) :
|
|
783
|
+
g(e).sending ? (r(), h("div", Nt, [...n[12] || (n[12] = [
|
|
784
|
+
p("span", null, null, -1),
|
|
785
|
+
p("span", null, null, -1),
|
|
786
|
+
p("span", null, null, -1)
|
|
787
|
+
])])) : I("", !0)
|
|
743
788
|
])
|
|
744
789
|
]),
|
|
745
790
|
_: 1
|
|
746
791
|
}, 512)
|
|
747
792
|
]),
|
|
748
|
-
|
|
749
|
-
(
|
|
750
|
-
key:
|
|
793
|
+
E.value.length > 0 ? (r(), h("div", Vt, [
|
|
794
|
+
(r(!0), h(U, null, J(E.value, (v, A) => (r(), h("div", {
|
|
795
|
+
key: A,
|
|
751
796
|
class: "pending-image-wrap"
|
|
752
797
|
}, [
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
src:
|
|
798
|
+
p("div", Xt, P(A + 1) + "/" + P(E.value.length), 1),
|
|
799
|
+
p("img", {
|
|
800
|
+
src: v,
|
|
756
801
|
class: "pending-image",
|
|
757
802
|
alt: "待发送图片"
|
|
758
|
-
}, null, 8,
|
|
759
|
-
i(
|
|
803
|
+
}, null, 8, jt),
|
|
804
|
+
i(w, {
|
|
760
805
|
type: "danger",
|
|
761
806
|
circle: "",
|
|
762
807
|
size: "small",
|
|
763
808
|
class: "remove-img",
|
|
764
|
-
onClick: (
|
|
809
|
+
onClick: (pe) => E.value.splice(A, 1)
|
|
765
810
|
}, {
|
|
766
|
-
default:
|
|
767
|
-
i(
|
|
768
|
-
default:
|
|
769
|
-
i(
|
|
811
|
+
default: u(() => [
|
|
812
|
+
i(k, null, {
|
|
813
|
+
default: u(() => [
|
|
814
|
+
i(g(ke))
|
|
770
815
|
]),
|
|
771
816
|
_: 1
|
|
772
817
|
})
|
|
@@ -774,83 +819,83 @@ const Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
|
|
|
774
819
|
_: 1
|
|
775
820
|
}, 8, ["onClick"])
|
|
776
821
|
]))), 128))
|
|
777
|
-
])) :
|
|
778
|
-
|
|
779
|
-
i(
|
|
822
|
+
])) : I("", !0),
|
|
823
|
+
p("div", Jt, [
|
|
824
|
+
i(w, {
|
|
780
825
|
type: "primary",
|
|
781
826
|
link: "",
|
|
782
|
-
onClick: n[3] || (n[3] = (
|
|
827
|
+
onClick: n[3] || (n[3] = (v) => D.value = !0)
|
|
783
828
|
}, {
|
|
784
|
-
default:
|
|
785
|
-
i(
|
|
786
|
-
default:
|
|
787
|
-
i(
|
|
829
|
+
default: u(() => [
|
|
830
|
+
i(k, null, {
|
|
831
|
+
default: u(() => [
|
|
832
|
+
i(g(st))
|
|
788
833
|
]),
|
|
789
834
|
_: 1
|
|
790
835
|
})
|
|
791
836
|
]),
|
|
792
837
|
_: 1
|
|
793
838
|
}),
|
|
794
|
-
i(
|
|
795
|
-
modelValue:
|
|
796
|
-
"onUpdate:modelValue": n[4] || (n[4] = (
|
|
839
|
+
i(L, {
|
|
840
|
+
modelValue: x.value,
|
|
841
|
+
"onUpdate:modelValue": n[4] || (n[4] = (v) => x.value = v),
|
|
797
842
|
type: "textarea",
|
|
798
843
|
rows: 2,
|
|
799
844
|
maxlength: "2000",
|
|
800
845
|
"show-word-limit": "",
|
|
801
846
|
placeholder: "输入消息... (Enter 发送,Shift+Enter 换行,Ctrl+V 粘贴截图)",
|
|
802
847
|
resize: "none",
|
|
803
|
-
disabled:
|
|
804
|
-
onKeydown:
|
|
805
|
-
onPaste:
|
|
848
|
+
disabled: g(e).sending || g(e).tokenUsage?.limitReached,
|
|
849
|
+
onKeydown: Be(se(he, ["exact", "prevent"]), ["enter"]),
|
|
850
|
+
onPaste: De
|
|
806
851
|
}, null, 8, ["modelValue", "disabled", "onKeydown"]),
|
|
807
|
-
i(
|
|
852
|
+
i(w, {
|
|
808
853
|
type: "primary",
|
|
809
|
-
icon:
|
|
854
|
+
icon: g(nt),
|
|
810
855
|
circle: "",
|
|
811
|
-
loading:
|
|
812
|
-
disabled: !
|
|
813
|
-
onClick:
|
|
856
|
+
loading: g(e).sending,
|
|
857
|
+
disabled: !x.value.trim() && E.value.length === 0 || g(e).sending || g(e).tokenUsage?.limitReached,
|
|
858
|
+
onClick: he
|
|
814
859
|
}, null, 8, ["icon", "loading", "disabled"])
|
|
815
860
|
]),
|
|
816
|
-
n[13] || (n[13] =
|
|
861
|
+
n[13] || (n[13] = p("div", { class: "ai-disclaimer" }, "内容由AI生成,请仔细甄别", -1))
|
|
817
862
|
], 64))
|
|
818
863
|
])
|
|
819
864
|
])
|
|
820
|
-
], 6)) :
|
|
865
|
+
], 6)) : I("", !0)
|
|
821
866
|
]),
|
|
822
867
|
_: 1
|
|
823
868
|
}),
|
|
824
|
-
i(
|
|
825
|
-
default:
|
|
826
|
-
|
|
869
|
+
i(te, { name: "fade" }, {
|
|
870
|
+
default: u(() => [
|
|
871
|
+
o.value ? (r(), h("div", {
|
|
827
872
|
key: 0,
|
|
828
873
|
class: "ai-panel-overlay",
|
|
829
|
-
onClick:
|
|
830
|
-
})) :
|
|
874
|
+
onClick: ge
|
|
875
|
+
})) : I("", !0)
|
|
831
876
|
]),
|
|
832
877
|
_: 1
|
|
833
878
|
})
|
|
834
879
|
], 64);
|
|
835
880
|
};
|
|
836
881
|
}
|
|
837
|
-
}),
|
|
882
|
+
}), xe = /* @__PURE__ */ q(Kt, [["__scopeId", "data-v-25c55a59"]]), Yt = { class: "cgs-ai-chat-root" }, Zt = /* @__PURE__ */ G({
|
|
838
883
|
__name: "AiChat",
|
|
839
884
|
setup(t) {
|
|
840
|
-
return (e,
|
|
841
|
-
i(
|
|
842
|
-
i(
|
|
885
|
+
return (e, d) => (r(), h("div", Yt, [
|
|
886
|
+
i($e),
|
|
887
|
+
i(xe)
|
|
843
888
|
]));
|
|
844
889
|
}
|
|
845
|
-
}),
|
|
890
|
+
}), Qt = /* @__PURE__ */ q(Zt, [["__scopeId", "data-v-4f2a75e5"]]), is = {
|
|
846
891
|
install(t, e) {
|
|
847
|
-
e?.baseUrl || console.warn("[@cgs/ai-chat] 警告:未提供 baseUrl,组件可能无法正常工作"),
|
|
892
|
+
e?.baseUrl || console.warn("[@cgs/ai-chat] 警告:未提供 baseUrl,组件可能无法正常工作"), ot(e), t.component("AiChat", Qt), t.component("AiChatFloat", $e), t.component("AiChatDrawer", xe);
|
|
848
893
|
}
|
|
849
894
|
};
|
|
850
895
|
export {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
896
|
+
xe as AiChatDrawer,
|
|
897
|
+
$e as AiChatFloat,
|
|
898
|
+
bt as AiChatMessage,
|
|
899
|
+
is as default,
|
|
900
|
+
Ee as useAiStore
|
|
856
901
|
};
|