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