@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.js CHANGED
@@ -1,100 +1,100 @@
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;
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 ae() {
10
- if (!oe)
9
+ function ce() {
10
+ if (!re)
11
11
  throw new Error("[@cgs/ai-chat] 插件未安装,请先调用 app.use(AiChat, options)");
12
- return oe;
12
+ return re;
13
13
  }
14
- function at(t) {
14
+ function ut(t) {
15
15
  try {
16
16
  const e = t.split(".");
17
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("")
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(o, (l, a) => typeof a == "number" && !Number.isSafeInteger(a) ? String(a) : a);
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 = ae(), d = { ...t };
27
+ const e = ce(), u = { ...t };
28
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)));
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 d;
36
+ return u;
37
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}`, {
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: 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}${_ ? ` — ${_}` : ""}`);
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 (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;
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 lt = () => H("POST", "/session/create"), ye = (t) => H("POST", "/session/page", t).then((e) => ({
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
- })), 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`, {
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: d,
67
- body: JSON.stringify(o),
66
+ headers: u,
67
+ body: JSON.stringify(l),
68
68
  signal: t.signal
69
69
  });
70
- if (!l.ok)
71
- throw new Error(`流式请求失败: HTTP ${l.status}`);
72
- const a = l.clone();
70
+ if (!o.ok)
71
+ throw new Error(`流式请求失败: HTTP ${o.status}`);
72
+ const m = o.clone();
73
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;
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 l;
83
+ return o;
84
84
  }
85
- const Ce = "cgs-ai-chat-state";
86
- function gt() {
85
+ const Ee = "cgs-ai-chat-state";
86
+ function vt() {
87
87
  try {
88
- const t = localStorage.getItem(Ce);
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 mt(t) {
94
+ function _t(t) {
95
95
  try {
96
96
  localStorage.setItem(
97
- Ce,
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 Te = 15, ie = gt(), Ee = it("cgs-ai-chat", {
107
+ const be = 15, le = vt(), de = ct("cgs-ai-chat", {
108
108
  state: () => ({
109
109
  visible: !1,
110
- currentSessionId: ie.currentSessionId ?? null,
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: ie.panelWidth ?? (typeof window < "u" ? Math.max(320, Math.round(window.innerWidth * 0.25)) : 420),
119
- isFullScreen: ie.isFullScreen ?? !1,
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 ye({ pageNum: 1, pageSize: Te });
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 ye({ pageNum: t, pageSize: Te });
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 rt(t);
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 lt();
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 ct(t), await this.loadSessions(), this.currentSessionId === t && (this.currentSessionId = null, this.messages = [], this._persist());
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 d = Math.floor(window.innerWidth * 0.9);
202
- this.panelWidth = Math.max(320, Math.min(d, t)), this.isFullScreen = !1, this._persist();
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 dt();
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
- mt(this.$state);
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
- }), ht = /* @__PURE__ */ G({
242
+ }), kt = /* @__PURE__ */ q({
237
243
  __name: "AiChatFloat",
238
244
  setup(t) {
239
- const e = Ee(), d = () => e.toggleVisible(), o = C(!1), l = () => {
240
- o.value = window.innerWidth < 768;
241
- }, a = y(() => o.value ? {
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 be(() => {
254
- l(), window.addEventListener("resize", l);
259
+ return Ce(() => {
260
+ o(), window.addEventListener("resize", o);
255
261
  }), 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
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: u(() => [
270
- p("div", {
271
- class: F(["float-btn", { "is-active": g(e).visible }])
275
+ default: c(() => [
276
+ g("div", {
277
+ class: N(["float-btn", { "is-active": r(e).visible }])
272
278
  }, [
273
- i(c, { size: 24 }, {
274
- default: u(() => [
275
- i(g(Ge))
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
- }), 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 = {
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
- }, _t = ["src"], St = ["innerHTML"], kt = ["innerHTML"], wt = {
295
- key: 1,
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
- }, yt = { class: "time" }, Tt = /* @__PURE__ */ G({
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, 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;
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 o(a) {
314
- return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
315
333
  }
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]])
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
- p("div", pt, [
323
- t.message.role === "assistant" ? (r(), B(b, {
340
+ g("div", wt, [
341
+ t.message.role === "assistant" ? (a(), V(C, {
324
342
  key: 0,
325
343
  size: 20
326
344
  }, {
327
- default: u(() => [
328
- i(g(qe))
345
+ default: c(() => [
346
+ i(r(Ze))
329
347
  ]),
330
348
  _: 1
331
- })) : (r(), B(b, {
349
+ })) : (a(), V(C, {
332
350
  key: 1,
333
351
  size: 20
334
352
  }, {
335
- default: u(() => [
336
- i(g(Ke))
353
+ default: c(() => [
354
+ i(r(Qe))
337
355
  ]),
338
356
  _: 1
339
357
  }))
340
358
  ]),
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,
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, _t))), 128))
350
- ])) : I("", !0),
351
- t.message.content && t.message.content !== "[图片]" ? (r(), h("div", {
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: d.value
355
- }, null, 8, St)) : I("", !0)
356
- ], 64)) : (r(), h(U, { key: 1 }, [
357
- t.message.content ? (r(), h("div", {
358
- key: 0,
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: d.value
361
- }, null, 8, kt)) : (r(), h("div", wt, "正在思考..."))
398
+ innerHTML: P.value
399
+ }, null, 8, At)) : t.message.reasoningContent ? (a(), d("div", Mt, "正在组织回答...")) : (a(), d("div", Et, "正在思考..."))
362
400
  ], 64)),
363
- p("div", yt, P(l(t.message.createTime)), 1)
401
+ g("div", $t, W(L(t.message.createTime)), 1)
364
402
  ])
365
403
  ], 2);
366
404
  };
367
405
  }
368
- }), bt = /* @__PURE__ */ q(Tt, [["__scopeId", "data-v-171a31c7"]]), It = {
406
+ }), Lt = /* @__PURE__ */ K(xt, [["__scopeId", "data-v-ee95845e"]]), Rt = {
369
407
  key: 0,
370
408
  class: "width-tooltip"
371
- }, At = { class: "panel-container" }, Mt = { class: "panel-header" }, Ct = { class: "header-left" }, Et = {
409
+ }, Pt = { class: "panel-container" }, Ut = { class: "panel-header" }, Wt = { class: "header-left" }, zt = {
372
410
  key: 0,
373
411
  class: "token-usage"
374
- }, $t = {
412
+ }, Ft = {
375
413
  key: 1,
376
414
  class: "preset-btns"
377
- }, xt = { class: "header-right" }, Lt = { class: "chat-container" }, Pt = {
415
+ }, Dt = { class: "header-right" }, Ht = { class: "chat-container" }, Ot = {
378
416
  key: 0,
379
417
  class: "session-list"
380
- }, Rt = { class: "session-header" }, Ut = ["onClick"], Wt = { class: "session-title" }, zt = { class: "session-meta" }, Ft = {
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
- }, Dt = {
421
+ }, Bt = {
384
422
  key: 1,
385
423
  class: "session-load-more session-no-more"
386
- }, Ht = { class: "messages-area" }, Ot = { class: "messages-content" }, Nt = {
424
+ }, Gt = { class: "messages-area" }, qt = { class: "messages-content" }, Kt = {
387
425
  key: 0,
388
426
  class: "typing-indicator"
389
- }, Vt = {
427
+ }, Yt = {
390
428
  key: 0,
391
429
  class: "pending-images"
392
- }, Xt = { class: "image-index" }, jt = ["src"], Jt = { class: "input-area" }, Bt = 4, Gt = 0.25, qt = 0.38, Kt = /* @__PURE__ */ G({
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 = Ee();
396
- let d = new AbortController();
397
- const o = y({
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
- }), 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(() => {
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
- }), S = y(() => {
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
- }), 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;
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
- 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";
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 && (W.value = !0, V.value = s.touches[0].clientX, X.value = l.value, document.addEventListener("touchmove", Z), document.addEventListener("touchend", ee));
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
- !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);
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
- 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) => {
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 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张图片");
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 w = k.getAsFile();
441
- if (w) {
442
- const $ = await He(w);
443
- E.value.push($);
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 f = new FileReader();
449
- f.onload = (k) => n(k.target.result), f.readAsDataURL(s);
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 = le.value?.wrapRef;
489
+ const n = $.value?.wrapRef;
452
490
  n && s + n.clientHeight >= n.scrollHeight - 150 && e.loadMoreSessions();
453
- }, me = () => {
454
- O.value?.wrapRef && (O.value.wrapRef.scrollTop = O.value.wrapRef.scrollHeight);
491
+ }, se = () => {
492
+ M.value?.wrapRef && (M.value.wrapRef.scrollTop = M.value.wrapRef.scrollHeight);
455
493
  };
456
- _e(() => e.messages.length, () => Se(me)), _e(o, (s) => {
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), D.value = !1) : z.error("创建对话失败,请检查网络或重新登录");
499
+ s ? (e.setCurrentSession(s, !1), C.value = !1) : O.error("创建对话失败,请检查网络或重新登录");
462
500
  }, Xe = (s) => {
463
- e.setCurrentSession(s.id), D.value = !1;
501
+ e.setCurrentSession(s.id), C.value = !1;
464
502
  }, je = async (s) => {
465
503
  await e.deleteSession(s);
466
- }, he = async () => {
467
- const s = x.value.trim(), n = [...E.value];
504
+ }, pe = async () => {
505
+ const s = S.value.trim(), n = [...f.value];
468
506
  if (!s && n.length === 0 || e.sending) return;
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("创建对话失败,请检查网络或重新登录");
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(f, !1);
514
+ e.setCurrentSession(p, !1);
477
515
  }
478
- const k = {
516
+ const y = {
479
517
  id: Date.now(),
480
- sessionId: f,
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(k);
487
- const w = {
524
+ e.addMessage(y);
525
+ const T = {
488
526
  id: Date.now() + 1,
489
- sessionId: f,
527
+ sessionId: p,
490
528
  role: "assistant",
491
529
  content: "",
492
530
  createTime: (/* @__PURE__ */ new Date()).toISOString()
493
531
  };
494
- e.addMessage(w);
532
+ e.addMessage(T);
495
533
  try {
496
- const L = (await ut({
497
- sessionId: f,
534
+ const U = (await pt({
535
+ sessionId: p,
498
536
  message: s || "[图片]",
499
537
  images: n.length > 0 ? n : void 0,
500
- signal: d.signal
501
- })).body?.getReader(), v = new TextDecoder();
502
- if (L) {
503
- let A = "";
538
+ signal: u.signal
539
+ })).body?.getReader(), _ = new TextDecoder();
540
+ if (U) {
541
+ let x = "";
504
542
  for (; ; ) {
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(`
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
- A = fe.pop() ?? "";
511
- let ve = "";
512
- for (const j of fe)
513
- if (j.startsWith("event:"))
514
- ve = j.slice(6).trim();
515
- else if (j.startsWith("data:"))
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 M = JSON.parse(j.slice(5).trim());
518
- if (ve === "error" || M.error) {
519
- e.updateLastAssistantMessage(M.error || "服务异常,请重试。"), z.error(M.error || "服务异常,请重试");
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
- !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);
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 ($.name === "AbortError")
565
+ } catch (R) {
566
+ if (R.name === "AbortError")
529
567
  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,
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] 发送消息失败", $), e.updateLastAssistantMessage("抱歉,发生了错误,请重试。"), z.error({
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 be(() => {
548
- window.addEventListener("resize", re), b();
585
+ return Ce(() => {
586
+ window.addEventListener("resize", ue), P();
549
587
  }), 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);
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 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", {
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: F(["ai-chat-panel", { "full-screen": a.value, "is-mobile": m.value }]),
559
- style: Ae(c.value)
596
+ class: N(["ai-chat-panel", { "full-screen": m.value, "is-mobile": h.value }]),
597
+ style: Ae(v.value)
560
598
  }, [
561
- m.value ? I("", !0) : (r(), h("div", {
599
+ h.value ? A("", !0) : (a(), d("div", {
562
600
  key: 0,
563
601
  class: "resize-handle",
564
602
  onMousedown: We,
565
- onTouchstart: se(ze, ["prevent"])
603
+ onTouchstart: oe(ze, ["prevent"])
566
604
  }, [
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)
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
- 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,
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: u(() => [
585
- p("span", {
586
- class: F({ "limit-warning": g(e).tokenUsage.limitReached })
587
- }, P(_.value), 3)
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
- ])) : I("", !0),
592
- m.value ? I("", !0) : (r(), h("div", $t, [
593
- i(f, {
594
- content: Re.value,
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: u(() => [
598
- i(w, {
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] = (v) => ue(ce.value))
640
+ onClick: n[0] || (n[0] = (_) => he(ge.value))
603
641
  }, {
604
- default: u(() => [
605
- i(k, null, {
606
- default: u(() => [
607
- i(g(Ye))
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(f, {
655
+ i(p, {
618
656
  content: Ue.value,
619
657
  placement: "bottom"
620
658
  }, {
621
- default: u(() => [
622
- i(w, {
659
+ default: c(() => [
660
+ i(T, {
623
661
  size: "small",
624
- type: Pe.value ? "primary" : "default",
662
+ type: Re.value ? "primary" : "default",
625
663
  link: "",
626
- onClick: n[1] || (n[1] = (v) => ue(de.value))
664
+ onClick: n[1] || (n[1] = (_) => he(me.value))
627
665
  }, {
628
- default: u(() => [
629
- i(k, null, {
630
- default: u(() => [
631
- i(g(Ze))
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(f, {
642
- content: a.value ? "退出全屏" : "全屏",
679
+ i(p, {
680
+ content: m.value ? "退出全屏" : "全屏",
643
681
  placement: "bottom"
644
682
  }, {
645
- default: u(() => [
646
- i(w, {
683
+ default: c(() => [
684
+ i(T, {
647
685
  size: "small",
648
- type: a.value ? "primary" : "default",
686
+ type: m.value ? "primary" : "default",
649
687
  link: "",
650
688
  onClick: Fe
651
689
  }, {
652
- default: u(() => [
653
- i(k, null, {
654
- default: u(() => [
655
- i(g(Qe))
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
- p("div", xt, [
668
- i(w, {
705
+ g("div", Dt, [
706
+ i(T, {
669
707
  type: "primary",
670
708
  link: "",
671
709
  onClick: Ve
672
710
  }, {
673
- default: u(() => [
674
- i(k, null, {
675
- default: u(() => [
676
- i(g(et))
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] = ne("新对话 ", -1))
718
+ n[7] || (n[7] = ae("新对话 ", -1))
681
719
  ]),
682
720
  _: 1
683
721
  }),
684
- i(w, {
722
+ i(T, {
685
723
  type: "default",
686
724
  link: "",
687
- onClick: ge
725
+ onClick: fe
688
726
  }, {
689
- default: u(() => [
690
- i(k, null, {
691
- default: u(() => [
692
- i(g(ke))
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
- 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, {
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] = (v) => D.value = !1)
747
+ onClick: n[2] || (n[2] = (_) => C.value = !1)
710
748
  }, {
711
- default: u(() => [...n[8] || (n[8] = [
712
- ne("返回聊天", -1)
749
+ default: c(() => [...n[8] || (n[8] = [
750
+ ae("返回聊天", -1)
713
751
  ])]),
714
752
  _: 1
715
753
  })
716
754
  ]),
717
- i(g(we), {
755
+ i(r(ye), {
718
756
  ref_key: "sessionScrollbarRef",
719
- ref: le,
720
- height: (m.value, "calc(100vh - 200px)"),
757
+ ref: $,
758
+ height: (h.value, "calc(100vh - 200px)"),
721
759
  onScroll: Ne
722
760
  }, {
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)
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(f, {
730
- content: v.title,
767
+ i(p, {
768
+ content: _.title,
731
769
  placement: "left",
732
770
  "show-after": 500
733
771
  }, {
734
- default: u(() => [
735
- p("div", Wt, P(Oe(v.title)), 1)
772
+ default: c(() => [
773
+ g("div", Xt, W(Oe(_.title)), 1)
736
774
  ]),
737
775
  _: 2
738
776
  }, 1032, ["content"]),
739
- p("div", zt, [
740
- p("span", null, P(v.messageCount) + "条消息", 1),
741
- i(w, {
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: se((A) => je(v.id), ["stop"])
783
+ onClick: oe((x) => je(_.id), ["stop"])
746
784
  }, {
747
- default: u(() => [...n[10] || (n[10] = [
748
- ne("删除", -1)
785
+ default: c(() => [...n[10] || (n[10] = [
786
+ ae("删除", -1)
749
787
  ])]),
750
788
  _: 1
751
789
  }, 8, ["onClick"])
752
790
  ])
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))
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] = 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($, {
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
- })) : I("", !0)
804
+ })) : A("", !0)
767
805
  ]),
768
806
  _: 1
769
807
  }, 8, ["height"])
770
- ])) : (r(), h(U, { key: 1 }, [
771
- p("div", Ht, [
772
- i(g(we), {
808
+ ])) : (a(), d(F, { key: 1 }, [
809
+ g("div", Gt, [
810
+ i(r(ye), {
773
811
  ref_key: "scrollbarRef",
774
- ref: O,
812
+ ref: M,
775
813
  height: "100%"
776
814
  }, {
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
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
- 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)
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
- 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,
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
- p("div", Xt, P(A + 1) + "/" + P(E.value.length), 1),
799
- p("img", {
800
- src: v,
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, jt),
804
- i(w, {
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: (pe) => E.value.splice(A, 1)
847
+ onClick: (ve) => f.value.splice(x, 1)
810
848
  }, {
811
- default: u(() => [
812
- i(k, null, {
813
- default: u(() => [
814
- i(g(ke))
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
- ])) : I("", !0),
823
- p("div", Jt, [
824
- i(w, {
860
+ ])) : A("", !0),
861
+ g("div", es, [
862
+ i(T, {
825
863
  type: "primary",
826
864
  link: "",
827
- onClick: n[3] || (n[3] = (v) => D.value = !0)
865
+ onClick: n[3] || (n[3] = (_) => C.value = !0)
828
866
  }, {
829
- default: u(() => [
830
- i(k, null, {
831
- default: u(() => [
832
- i(g(st))
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(L, {
840
- modelValue: x.value,
841
- "onUpdate:modelValue": n[4] || (n[4] = (v) => x.value = v),
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: g(e).sending || g(e).tokenUsage?.limitReached,
849
- onKeydown: Be(se(he, ["exact", "prevent"]), ["enter"]),
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(w, {
890
+ i(T, {
853
891
  type: "primary",
854
- icon: g(nt),
892
+ icon: r(rt),
855
893
  circle: "",
856
- loading: g(e).sending,
857
- disabled: !x.value.trim() && E.value.length === 0 || g(e).sending || g(e).tokenUsage?.limitReached,
858
- onClick: he
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] = p("div", { class: "ai-disclaimer" }, "内容由AI生成,请仔细甄别", -1))
899
+ n[13] || (n[13] = g("div", { class: "ai-disclaimer" }, "内容由AI生成,请仔细甄别", -1))
862
900
  ], 64))
863
901
  ])
864
902
  ])
865
- ], 6)) : I("", !0)
903
+ ], 6)) : A("", !0)
866
904
  ]),
867
905
  _: 1
868
906
  }),
869
- i(te, { name: "fade" }, {
870
- default: u(() => [
871
- o.value ? (r(), h("div", {
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: ge
875
- })) : I("", !0)
912
+ onClick: fe
913
+ })) : A("", !0)
876
914
  ]),
877
915
  _: 1
878
916
  })
879
917
  ], 64);
880
918
  };
881
919
  }
882
- }), xe = /* @__PURE__ */ q(Kt, [["__scopeId", "data-v-25c55a59"]]), Yt = { class: "cgs-ai-chat-root" }, Zt = /* @__PURE__ */ G({
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, d) => (r(), h("div", Yt, [
923
+ return (e, u) => (a(), d("div", os, [
886
924
  i($e),
887
925
  i(xe)
888
926
  ]));
889
927
  }
890
- }), Qt = /* @__PURE__ */ q(Zt, [["__scopeId", "data-v-4f2a75e5"]]), is = {
928
+ }), ls = /* @__PURE__ */ K(as, [["__scopeId", "data-v-4f2a75e5"]]), gs = {
891
929
  install(t, e) {
892
- e?.baseUrl || console.warn("[@cgs/ai-chat] 警告:未提供 baseUrl,组件可能无法正常工作"), ot(e), t.component("AiChat", Qt), t.component("AiChatFloat", $e), t.component("AiChatDrawer", xe);
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
- bt as AiChatMessage,
899
- is as default,
900
- Ee as useAiStore
936
+ Lt as AiChatMessage,
937
+ gs as default,
938
+ de as useAiStore
901
939
  };