@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/dist/ai-chat.js CHANGED
@@ -1,53 +1,89 @@
1
- import { defineComponent as J, ref as b, computed as p, onMounted as we, onUnmounted as Te, resolveComponent as x, openBlock as o, createElementBlock as c, normalizeStyle as be, normalizeClass as W, createVNode as i, withCtx as l, createElementVNode as d, unref as r, createBlock as G, Fragment as A, renderList as X, createCommentVNode as S, toDisplayString as C, watch as fe, nextTick as pe, Transition as ee, withModifiers as te, createTextVNode as se, withKeys as Je } from "vue";
2
- import { ChatDotRound as Be, Monitor as je, User as qe, Grid as Ke, Menu as Ye, FullScreen as Ze, Plus as Qe, Close as _e, Loading as et, List as tt, Promotion as st } from "@element-plus/icons-vue";
3
- import { defineStore as nt } from "pinia";
4
- import { ElScrollbar as ke, ElMessage as H } from "element-plus";
5
- let ie = null;
6
- function it(t) {
7
- ie = t;
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 Me() {
10
- if (!ie)
9
+ function ae() {
10
+ if (!oe)
11
11
  throw new Error("[@cgs/ai-chat] 插件未安装,请先调用 app.use(AiChat, options)");
12
- return ie;
12
+ return oe;
13
13
  }
14
- async function U(t, e, g) {
15
- const h = Me(), a = {
16
- "Content-Type": "application/json"
17
- };
18
- h.getToken && (a["x-access-token"] = h.getToken()), h.getTenantId && (a["X-Tenant-Id"] = String(h.getTenantId()));
19
- const k = await fetch(`${h.baseUrl}${e}`, {
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: a,
22
- body: g !== void 0 ? JSON.stringify(g) : void 0
23
- });
24
- if (!k.ok)
25
- throw new Error(`HTTP ${k.status}: ${e}`);
26
- const I = (await k.text()).replace(/:\s*(\d{16,})/g, ':"$1"');
27
- return JSON.parse(I).data;
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 ot = () => U("POST", "/session/create"), ye = (t) => U("POST", "/session/page", t).then((e) => ({
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
- })), at = (t) => U("GET", `/session/${t}/messages`), lt = (t) => U("DELETE", `/session/${t}`), rt = () => U("GET", "/usage/today");
33
- async function ct(t) {
34
- const e = Me(), g = {
35
- "Content-Type": "application/json"
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: g,
41
- body: JSON.stringify(t),
66
+ headers: d,
67
+ body: JSON.stringify(o),
42
68
  signal: t.signal
43
- // 支持 AbortSignal
44
69
  });
45
- if (!h.ok)
46
- throw new Error(`流式请求失败: HTTP ${h.status}`);
47
- return h;
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 dt() {
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 ut(t) {
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 Se = 15, ne = dt(), xe = nt("cgs-ai-chat", {
107
+ const Te = 15, ie = gt(), Ee = it("cgs-ai-chat", {
72
108
  state: () => ({
73
109
  visible: !1,
74
- currentSessionId: ne.currentSessionId ?? null,
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: ne.panelWidth ?? (typeof window < "u" ? Math.max(320, Math.round(window.innerWidth * 0.25)) : 420),
83
- isFullScreen: ne.isFullScreen ?? !1,
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: Se });
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: Se });
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 at(t);
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 ot();
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 lt(t), await this.loadSessions(), this.currentSessionId === t && (this.currentSessionId = null, this.messages = [], this._persist());
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 g = Math.floor(window.innerWidth * 0.9);
166
- this.panelWidth = Math.max(320, Math.min(g, t)), this.isFullScreen = !1, this._persist();
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 rt();
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
- ut(this.$state);
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
- }), gt = /* @__PURE__ */ J({
236
+ }), ht = /* @__PURE__ */ G({
201
237
  __name: "AiChatFloat",
202
238
  setup(t) {
203
- const e = xe(), g = () => e.toggleVisible(), h = b(!1), a = () => {
204
- h.value = window.innerWidth < 768;
205
- }, k = p(() => h.value ? {
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: "1000"
246
+ zIndex: "999"
211
247
  } : {
212
248
  position: "fixed",
213
249
  right: "24px",
214
- bottom: "120px",
215
- zIndex: "9990"
250
+ bottom: "80px",
251
+ zIndex: "999"
216
252
  });
217
- return we(() => {
218
- a(), window.addEventListener("resize", a);
219
- }), Te(() => {
220
- window.removeEventListener("resize", a);
221
- }), (y, I) => {
222
- const $ = x("el-icon"), j = x("el-tooltip");
223
- return o(), c("div", {
224
- class: W(["ai-chat-float", { "is-mobile": h.value }]),
225
- style: be(k.value),
226
- onClick: g
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(j, {
264
+ i(_, {
229
265
  content: "AI助手",
230
266
  placement: "left",
231
267
  "show-after": 300
232
268
  }, {
233
- default: l(() => [
234
- d("div", {
235
- class: W(["float-btn", { "is-active": r(e).visible }])
269
+ default: u(() => [
270
+ p("div", {
271
+ class: F(["float-btn", { "is-active": g(e).visible }])
236
272
  }, [
237
- i($, { size: 24 }, {
238
- default: l(() => [
239
- i(r(Be))
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
- }), B = (t, e) => {
251
- const g = t.__vccOpts || t;
252
- for (const [h, a] of e)
253
- g[h] = a;
254
- return g;
255
- }, Ae = /* @__PURE__ */ B(gt, [["__scopeId", "data-v-b3f66cd5"]]), ht = { class: "avatar" }, mt = { class: "content" }, vt = {
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
- }, ft = ["src"], pt = ["innerHTML"], _t = ["innerHTML"], kt = {
294
+ }, _t = ["src"], St = ["innerHTML"], kt = ["innerHTML"], wt = {
259
295
  key: 1,
260
296
  class: "loading-placeholder"
261
- }, yt = { class: "time" }, St = /* @__PURE__ */ J({
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, g = p(() => {
268
- let a = e.message.content || "";
269
- return a = a.replace(/</g, "&lt;").replace(/>/g, "&gt;"), a = a.replace(/```(\w*)\n([\s\S]*?)```/g, '<pre class="code-block"><code>$2</code></pre>'), a = a.replace(/`([^`]+)`/g, '<code class="inline-code">$1</code>'), a = a.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), a = a.replace(/\n/g, "<br>"), a;
270
- }), h = (a) => a ? new Date(a).toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" }) : "";
271
- return (a, k) => {
272
- const y = x("el-icon");
273
- return o(), c("div", {
274
- class: W(["message-item", [t.message.role]])
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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
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
- d("div", ht, [
277
- t.message.role === "assistant" ? (o(), G(y, {
322
+ p("div", pt, [
323
+ t.message.role === "assistant" ? (r(), B(b, {
278
324
  key: 0,
279
325
  size: 20
280
326
  }, {
281
- default: l(() => [
282
- i(r(je))
327
+ default: u(() => [
328
+ i(g(qe))
283
329
  ]),
284
330
  _: 1
285
- })) : (o(), G(y, {
331
+ })) : (r(), B(b, {
286
332
  key: 1,
287
333
  size: 20
288
334
  }, {
289
- default: l(() => [
290
- i(r(qe))
335
+ default: u(() => [
336
+ i(g(Ke))
291
337
  ]),
292
338
  _: 1
293
339
  }))
294
340
  ]),
295
- d("div", mt, [
296
- t.message.role === "user" ? (o(), c(A, { key: 0 }, [
297
- t.message.images && t.message.images.length > 0 ? (o(), c("div", vt, [
298
- (o(!0), c(A, null, X(t.message.images, (I, $) => (o(), c("img", {
299
- key: $,
300
- src: I,
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, ft))), 128))
304
- ])) : S("", !0),
305
- t.message.content && t.message.content !== "[图片]" ? (o(), c("div", {
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: g.value
309
- }, null, 8, pt)) : S("", !0)
310
- ], 64)) : (o(), c(A, { key: 1 }, [
311
- t.message.content ? (o(), c("div", {
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: g.value
315
- }, null, 8, _t)) : (o(), c("div", kt, "正在思考..."))
360
+ innerHTML: d.value
361
+ }, null, 8, kt)) : (r(), h("div", wt, "正在思考..."))
316
362
  ], 64)),
317
- d("div", yt, C(h(t.message.createTime)), 1)
363
+ p("div", yt, P(l(t.message.createTime)), 1)
318
364
  ])
319
365
  ], 2);
320
366
  };
321
367
  }
322
- }), wt = /* @__PURE__ */ B(St, [["__scopeId", "data-v-5ed8bd4d"]]), Tt = {
368
+ }), bt = /* @__PURE__ */ q(Tt, [["__scopeId", "data-v-171a31c7"]]), It = {
323
369
  key: 0,
324
370
  class: "width-tooltip"
325
- }, bt = { class: "panel-container" }, Mt = { class: "panel-header" }, Ct = { class: "header-left" }, xt = {
371
+ }, At = { class: "panel-container" }, Mt = { class: "panel-header" }, Ct = { class: "header-left" }, Et = {
326
372
  key: 0,
327
373
  class: "token-usage"
328
- }, At = {
374
+ }, $t = {
329
375
  key: 1,
330
376
  class: "preset-btns"
331
- }, It = { class: "header-right" }, Et = { class: "chat-container" }, Lt = {
377
+ }, xt = { class: "header-right" }, Lt = { class: "chat-container" }, Pt = {
332
378
  key: 0,
333
379
  class: "session-list"
334
- }, $t = { class: "session-header" }, Wt = ["onClick"], zt = { class: "session-title" }, Rt = { class: "session-meta" }, Ut = {
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
- }, Pt = {
383
+ }, Dt = {
338
384
  key: 1,
339
385
  class: "session-load-more session-no-more"
340
- }, Ft = { class: "messages-area" }, Ot = { class: "messages-content" }, Dt = {
386
+ }, Ht = { class: "messages-area" }, Ot = { class: "messages-content" }, Nt = {
341
387
  key: 0,
342
388
  class: "typing-indicator"
343
- }, Nt = {
389
+ }, Vt = {
344
390
  key: 0,
345
391
  class: "pending-images"
346
- }, Vt = { class: "image-index" }, Ht = ["src"], Xt = { class: "input-area" }, Gt = 4, Jt = 0.25, Bt = 0.38, jt = /* @__PURE__ */ J({
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 = xe();
350
- let g = new AbortController();
351
- const h = p({
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
- }), a = p(() => e.panelWidth), k = p(() => e.isFullScreen), y = b(!1), I = () => {
355
- y.value = window.innerWidth < 768;
356
- }, $ = p(() => {
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
- }), Ee = p(() => {
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
- }), z = b(""), R = b(!1), M = b([]), P = b(), oe = b(), F = b(window.innerWidth), ae = () => {
378
- F.value = window.innerWidth, I();
379
- }, le = p(() => y.value ? window.innerWidth : Math.max(320, Math.round(F.value * Jt))), re = p(() => y.value ? window.innerWidth : Math.max(420, Math.round(F.value * Bt))), q = p(() => a.value / F.value), Le = p(() => !k.value && q.value <= 0.3), $e = p(() => !k.value && q.value > 0.3 && q.value <= 0.45), We = p(() => `窄 (${le.value}px)`), ze = p(() => `宽 (${re.value}px)`), E = b(!1), O = b(0), D = b(0);
380
- let _ = null;
381
- const Re = (s) => {
382
- E.value = !0, O.value = s.clientX, D.value = a.value, document.addEventListener("mousemove", K), document.addEventListener("mouseup", Z), document.body.style.cursor = "ew-resize", document.body.style.userSelect = "none";
383
- }, Ue = (s) => {
384
- s.touches.length === 1 && (E.value = !0, O.value = s.touches[0].clientX, D.value = a.value, document.addEventListener("touchmove", Y), document.addEventListener("touchend", Q));
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
- !E.value || s.touches.length !== 1 || (_ && cancelAnimationFrame(_), _ = requestAnimationFrame(() => {
392
- const n = D.value + (O.value - s.touches[0].clientX), u = Math.max(320, Math.min(window.innerWidth / 2, n));
393
- e.setPanelWidth(u);
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
- E.value = !1, _ && (cancelAnimationFrame(_), _ = null), document.removeEventListener("touchmove", Y), document.removeEventListener("touchend", Q);
399
- }, ce = (s) => e.setPanelWidth(s), Pe = () => e.toggleFullScreen(), de = () => e.setVisible(!1), Fe = async (s) => {
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 u = 0; u < n.length; u++) {
403
- const v = n[u];
404
- if (v.type.startsWith("image/")) {
405
- if (s.preventDefault(), M.value.length >= Gt) {
406
- H.warning("最多只能上传4张图片");
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 f = v.getAsFile();
410
- if (f) {
411
- const L = await Oe(f);
412
- M.value.push(L);
440
+ const w = k.getAsFile();
441
+ if (w) {
442
+ const $ = await He(w);
443
+ E.value.push($);
413
444
  }
414
445
  }
415
446
  }
416
- }, Oe = (s) => new Promise((n) => {
417
- const u = new FileReader();
418
- u.onload = (v) => n(v.target.result), u.readAsDataURL(s);
419
- }), De = (s) => s?.length > 30 ? s.substring(0, 30) + "..." : s, Ne = ({ scrollTop: s }) => {
420
- const n = oe.value?.wrapRef;
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
- }, ue = () => {
423
- P.value?.wrapRef && (P.value.wrapRef.scrollTop = P.value.wrapRef.scrollHeight);
453
+ }, me = () => {
454
+ O.value?.wrapRef && (O.value.wrapRef.scrollTop = O.value.wrapRef.scrollHeight);
424
455
  };
425
- fe(() => e.messages.length, () => pe(ue)), fe(h, (s) => {
426
- s && (e.setCurrentSession(null), e.loadSessions(), e.loadTokenUsage());
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), R.value = !1) : H.error("创建对话失败,请检查网络或重新登录");
431
- }, He = (s) => {
432
- e.setCurrentSession(s.id), R.value = !1;
433
- }, Xe = async (s) => {
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
- }, ge = async () => {
436
- const s = z.value.trim(), n = [...M.value];
466
+ }, he = async () => {
467
+ const s = x.value.trim(), n = [...E.value];
437
468
  if (!s && n.length === 0 || e.sending) return;
438
- z.value = "", M.value = [], e.setSending(!0), g = new AbortController();
439
- let u = e.currentSessionId;
440
- u || (u = await e.createSession(), u && e.setCurrentSession(u, !1));
441
- const v = {
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: u ?? "",
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(v);
450
- const f = {
486
+ e.addMessage(k);
487
+ const w = {
451
488
  id: Date.now() + 1,
452
- sessionId: u ?? "",
489
+ sessionId: f,
453
490
  role: "assistant",
454
491
  content: "",
455
492
  createTime: (/* @__PURE__ */ new Date()).toISOString()
456
493
  };
457
- e.addMessage(f);
494
+ e.addMessage(w);
458
495
  try {
459
- const N = (await ct({
460
- sessionId: u ?? void 0,
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: g.signal
465
- // 传递 signal 以支持取消
466
- })).body?.getReader(), m = new TextDecoder();
467
- if (N) {
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: he, value: Ge } = await N.read();
471
- if (he) break;
472
- w += m.decode(Ge, { stream: !0 });
473
- const me = w.split(`
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
- w = me.pop() ?? "";
510
+ A = fe.pop() ?? "";
476
511
  let ve = "";
477
- for (const V of me)
478
- if (V.startsWith("event:"))
479
- ve = V.slice(6).trim();
480
- else if (V.startsWith("data:"))
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 T = JSON.parse(V.slice(5).trim());
483
- if (ve === "error" || T.error) {
484
- e.updateLastAssistantMessage(T.error || "服务异常,请重试。"), H.error(T.error || "服务异常,请重试");
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
- !T.done && T.content && (e.updateLastAssistantMessage(T.content), pe(ue)), T.sessionId && !e.currentSessionId && e.setCurrentSession(T.sessionId), T.done && T.usage && e.updateTokenUsage(T.usage.totalTokens);
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 (L) {
493
- L.name === "AbortError" ? console.log("[@cgs/ai-chat] 请求已取消") : (console.error("[@cgs/ai-chat] 发送消息失败", L), e.updateLastAssistantMessage("抱歉,发生了错误,请重试。"), H.error({
494
- message: "消息发送失败,请检查网络连接",
495
- duration: 3e3,
496
- showClose: !0
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 we(() => {
503
- window.addEventListener("resize", ae), I();
504
- }), Te(() => {
505
- g.abort(), window.removeEventListener("resize", ae), document.removeEventListener("mousemove", K), document.removeEventListener("mouseup", Z), document.removeEventListener("touchmove", Y), document.removeEventListener("touchend", Q), _ && cancelAnimationFrame(_);
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 u = x("el-tooltip"), v = x("el-icon"), f = x("el-button"), L = x("el-empty"), N = x("el-input");
508
- return o(), c(A, null, [
509
- i(ee, { name: "slide" }, {
510
- default: l(() => [
511
- h.value ? (o(), c("div", {
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: W(["ai-chat-panel", { "full-screen": k.value, "is-mobile": y.value }]),
514
- style: be($.value)
558
+ class: F(["ai-chat-panel", { "full-screen": a.value, "is-mobile": m.value }]),
559
+ style: Ae(c.value)
515
560
  }, [
516
- y.value ? S("", !0) : (o(), c("div", {
561
+ m.value ? I("", !0) : (r(), h("div", {
517
562
  key: 0,
518
563
  class: "resize-handle",
519
- onMousedown: Re,
520
- onTouchstart: te(Ue, ["prevent"])
564
+ onMousedown: We,
565
+ onTouchstart: se(ze, ["prevent"])
521
566
  }, [
522
- n[5] || (n[5] = d("div", { class: "resize-bar" }, null, -1)),
523
- i(ee, { name: "fade" }, {
524
- default: l(() => [
525
- E.value ? (o(), c("div", Tt, C(Math.round(a.value)) + "px ", 1)) : S("", !0)
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
- d("div", bt, [
531
- d("div", Mt, [
532
- d("div", Ct, [
533
- n[6] || (n[6] = d("span", { class: "title" }, "AI助手", -1)),
534
- r(e).tokenUsage ? (o(), c("div", xt, [
535
- i(u, {
536
- content: Ee.value,
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: l(() => [
540
- d("span", {
541
- class: W({ "limit-warning": r(e).tokenUsage.limitReached })
542
- }, C(j.value), 3)
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
- ])) : S("", !0),
547
- y.value ? S("", !0) : (o(), c("div", At, [
548
- i(u, {
549
- content: We.value,
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: l(() => [
553
- i(f, {
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] = (m) => ce(le.value))
602
+ onClick: n[0] || (n[0] = (v) => ue(ce.value))
558
603
  }, {
559
- default: l(() => [
560
- i(v, null, {
561
- default: l(() => [
562
- i(r(Ke))
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(u, {
573
- content: ze.value,
617
+ i(f, {
618
+ content: Ue.value,
574
619
  placement: "bottom"
575
620
  }, {
576
- default: l(() => [
577
- i(f, {
621
+ default: u(() => [
622
+ i(w, {
578
623
  size: "small",
579
- type: $e.value ? "primary" : "default",
624
+ type: Pe.value ? "primary" : "default",
580
625
  link: "",
581
- onClick: n[1] || (n[1] = (m) => ce(re.value))
626
+ onClick: n[1] || (n[1] = (v) => ue(de.value))
582
627
  }, {
583
- default: l(() => [
584
- i(v, null, {
585
- default: l(() => [
586
- i(r(Ye))
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(u, {
597
- content: k.value ? "退出全屏" : "全屏",
641
+ i(f, {
642
+ content: a.value ? "退出全屏" : "全屏",
598
643
  placement: "bottom"
599
644
  }, {
600
- default: l(() => [
601
- i(f, {
645
+ default: u(() => [
646
+ i(w, {
602
647
  size: "small",
603
- type: k.value ? "primary" : "default",
648
+ type: a.value ? "primary" : "default",
604
649
  link: "",
605
- onClick: Pe
650
+ onClick: Fe
606
651
  }, {
607
- default: l(() => [
608
- i(v, null, {
609
- default: l(() => [
610
- i(r(Ze))
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
- d("div", It, [
623
- i(f, {
667
+ p("div", xt, [
668
+ i(w, {
624
669
  type: "primary",
625
670
  link: "",
626
671
  onClick: Ve
627
672
  }, {
628
- default: l(() => [
629
- i(v, null, {
630
- default: l(() => [
631
- i(r(Qe))
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] = se("新对话 ", -1))
680
+ n[7] || (n[7] = ne("新对话 ", -1))
636
681
  ]),
637
682
  _: 1
638
683
  }),
639
- i(f, {
684
+ i(w, {
640
685
  type: "default",
641
686
  link: "",
642
- onClick: de
687
+ onClick: ge
643
688
  }, {
644
- default: l(() => [
645
- i(v, null, {
646
- default: l(() => [
647
- i(r(_e))
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
- d("div", Et, [
657
- R.value ? (o(), c("div", Lt, [
658
- d("div", $t, [
659
- n[9] || (n[9] = d("span", null, "历史对话", -1)),
660
- i(f, {
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] = (m) => R.value = !1)
709
+ onClick: n[2] || (n[2] = (v) => D.value = !1)
665
710
  }, {
666
- default: l(() => [...n[8] || (n[8] = [
667
- se("返回聊天", -1)
711
+ default: u(() => [...n[8] || (n[8] = [
712
+ ne("返回聊天", -1)
668
713
  ])]),
669
714
  _: 1
670
715
  })
671
716
  ]),
672
- i(r(ke), {
717
+ i(g(we), {
673
718
  ref_key: "sessionScrollbarRef",
674
- ref: oe,
675
- height: (y.value, "calc(100vh - 200px)"),
719
+ ref: le,
720
+ height: (m.value, "calc(100vh - 200px)"),
676
721
  onScroll: Ne
677
722
  }, {
678
- default: l(() => [
679
- (o(!0), c(A, null, X(r(e).sessions, (m) => (o(), c("div", {
680
- key: m.id,
681
- class: W(["session-item", { active: m.id === r(e).currentSessionId }]),
682
- onClick: (w) => He(m)
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(u, {
685
- content: m.title,
729
+ i(f, {
730
+ content: v.title,
686
731
  placement: "left",
687
732
  "show-after": 500
688
733
  }, {
689
- default: l(() => [
690
- d("div", zt, C(De(m.title)), 1)
734
+ default: u(() => [
735
+ p("div", Wt, P(Oe(v.title)), 1)
691
736
  ]),
692
737
  _: 2
693
738
  }, 1032, ["content"]),
694
- d("div", Rt, [
695
- d("span", null, C(m.messageCount) + "条消息", 1),
696
- i(f, {
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: te((w) => Xe(m.id), ["stop"])
745
+ onClick: se((A) => je(v.id), ["stop"])
701
746
  }, {
702
- default: l(() => [...n[10] || (n[10] = [
703
- se("删除", -1)
747
+ default: u(() => [...n[10] || (n[10] = [
748
+ ne("删除", -1)
704
749
  ])]),
705
750
  _: 1
706
751
  }, 8, ["onClick"])
707
752
  ])
708
- ], 10, Wt))), 128)),
709
- r(e).sessionLoadingMore ? (o(), c("div", Ut, [
710
- i(v, { class: "is-loading" }, {
711
- default: l(() => [
712
- i(r(et))
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] = d("span", null, "加载中...", -1))
717
- ])) : r(e).sessions.length > 0 && !r(e).sessionHasMore ? (o(), c("div", Pt, " 共 " + C(r(e).sessionTotal) + " 条对话 ", 1)) : S("", !0),
718
- r(e).sessions.length === 0 ? (o(), G(L, {
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
- })) : S("", !0)
766
+ })) : I("", !0)
722
767
  ]),
723
768
  _: 1
724
769
  }, 8, ["height"])
725
- ])) : (o(), c(A, { key: 1 }, [
726
- d("div", Ft, [
727
- i(r(ke), {
770
+ ])) : (r(), h(U, { key: 1 }, [
771
+ p("div", Ht, [
772
+ i(g(we), {
728
773
  ref_key: "scrollbarRef",
729
- ref: P,
774
+ ref: O,
730
775
  height: "100%"
731
776
  }, {
732
- default: l(() => [
733
- d("div", Ot, [
734
- (o(!0), c(A, null, X(r(e).messages, (m, w) => (o(), G(wt, {
735
- key: w,
736
- message: m
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
- r(e).sending ? (o(), c("div", Dt, [...n[12] || (n[12] = [
739
- d("span", null, null, -1),
740
- d("span", null, null, -1),
741
- d("span", null, null, -1)
742
- ])])) : S("", !0)
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
- M.value.length > 0 ? (o(), c("div", Nt, [
749
- (o(!0), c(A, null, X(M.value, (m, w) => (o(), c("div", {
750
- key: w,
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
- d("div", Vt, C(w + 1) + "/" + C(M.value.length), 1),
754
- d("img", {
755
- src: m,
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, Ht),
759
- i(f, {
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: (he) => M.value.splice(w, 1)
809
+ onClick: (pe) => E.value.splice(A, 1)
765
810
  }, {
766
- default: l(() => [
767
- i(v, null, {
768
- default: l(() => [
769
- i(r(_e))
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
- ])) : S("", !0),
778
- d("div", Xt, [
779
- i(f, {
822
+ ])) : I("", !0),
823
+ p("div", Jt, [
824
+ i(w, {
780
825
  type: "primary",
781
826
  link: "",
782
- onClick: n[3] || (n[3] = (m) => R.value = !0)
827
+ onClick: n[3] || (n[3] = (v) => D.value = !0)
783
828
  }, {
784
- default: l(() => [
785
- i(v, null, {
786
- default: l(() => [
787
- i(r(tt))
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(N, {
795
- modelValue: z.value,
796
- "onUpdate:modelValue": n[4] || (n[4] = (m) => z.value = m),
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: r(e).sending || r(e).tokenUsage?.limitReached,
804
- onKeydown: Je(te(ge, ["exact", "prevent"]), ["enter"]),
805
- onPaste: Fe
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(f, {
852
+ i(w, {
808
853
  type: "primary",
809
- icon: r(st),
854
+ icon: g(nt),
810
855
  circle: "",
811
- loading: r(e).sending,
812
- disabled: !z.value.trim() && M.value.length === 0 || r(e).sending || r(e).tokenUsage?.limitReached,
813
- onClick: ge
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] = d("div", { class: "ai-disclaimer" }, "内容由AI生成,请仔细甄别", -1))
861
+ n[13] || (n[13] = p("div", { class: "ai-disclaimer" }, "内容由AI生成,请仔细甄别", -1))
817
862
  ], 64))
818
863
  ])
819
864
  ])
820
- ], 6)) : S("", !0)
865
+ ], 6)) : I("", !0)
821
866
  ]),
822
867
  _: 1
823
868
  }),
824
- i(ee, { name: "fade" }, {
825
- default: l(() => [
826
- h.value ? (o(), c("div", {
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: de
830
- })) : S("", !0)
874
+ onClick: ge
875
+ })) : I("", !0)
831
876
  ]),
832
877
  _: 1
833
878
  })
834
879
  ], 64);
835
880
  };
836
881
  }
837
- }), Ie = /* @__PURE__ */ B(jt, [["__scopeId", "data-v-95d944a2"]]), qt = { class: "cgs-ai-chat-root" }, Kt = /* @__PURE__ */ J({
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, g) => (o(), c("div", qt, [
841
- i(Ae),
842
- i(Ie)
885
+ return (e, d) => (r(), h("div", Yt, [
886
+ i($e),
887
+ i(xe)
843
888
  ]));
844
889
  }
845
- }), Yt = /* @__PURE__ */ B(Kt, [["__scopeId", "data-v-e2e91206"]]), ss = {
890
+ }), Qt = /* @__PURE__ */ q(Zt, [["__scopeId", "data-v-4f2a75e5"]]), is = {
846
891
  install(t, e) {
847
- e?.baseUrl || console.warn("[@cgs/ai-chat] 警告:未提供 baseUrl,组件可能无法正常工作"), it(e), t.component("AiChat", Yt), t.component("AiChatFloat", Ae), t.component("AiChatDrawer", Ie);
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
- Ie as AiChatDrawer,
852
- Ae as AiChatFloat,
853
- wt as AiChatMessage,
854
- ss as default,
855
- xe as useAiStore
896
+ xe as AiChatDrawer,
897
+ $e as AiChatFloat,
898
+ bt as AiChatMessage,
899
+ is as default,
900
+ Ee as useAiStore
856
901
  };