wi-chat 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,29 @@
1
- import { ref as b, getCurrentInstance as te, onBeforeUnmount as we, computed as X, getCurrentScope as pe, onScopeDispose as me, reactive as V, onMounted as Fe, shallowReactive as Pe, effectScope as Qe, watch as ue } from "vue";
2
- import { createEmptyAnswerValues as ce, nextLocalMessageId as fe, buildChatTitle as De, createHistoryGroup as Se, loadGroupMessagesByStep as de, clearPendingClarifications as He, consumeStream as Ne, parseServerStartTime as Je, normalizeAnswer as ke, collectThinkingSteps as ve, applyAnswerChunk as je, expirePendingClarificationsForReply as We, mergeAnswerMeta as ze, readAnswerMeta as Ae, loadGroupMessages as Be, deleteHistoryGroup as Ve, setHistoryGroupTitle as $e, getHistoryGroups as Ye, resolveRemoteFileUrl as Xe, collectAnswerMarkdown as ye, markdownToPlainText as Ze } from "wi-chat/parser";
3
- import { AuthExpiredError as et, createRequest as $, createChatApi as _e, login as Y, isCancelError as tt } from "wi-chat/request";
4
- const nt = (e) => {
5
- const { api: r, interval: g = 5 * 60 * 1e3, renew: f, onExpired: l, immediate: h = !0 } = e, c = b(!1), o = b(0);
6
- let x = null, L = null;
7
- const p = async () => {
8
- const d = f ? await f().catch(() => !1) : !1;
1
+ import { ref as G, getCurrentInstance as we, onBeforeUnmount as Ee, computed as de, getCurrentScope as Ue, onScopeDispose as Me, reactive as ue, onMounted as Pe, shallowReactive as je, effectScope as De, watch as ke } from "vue";
2
+ import { createEmptyAnswerValues as be, nextLocalMessageId as Re, buildChatTitle as Qe, createHistoryGroup as Te, loadGroupMessagesByStep as Le, clearPendingClarifications as Ne, consumeStream as He, parseServerStartTime as Je, normalizeAnswer as Be, collectThinkingSteps as xe, applyAnswerChunk as We, expirePendingClarificationsForReply as $e, mergeAnswerMeta as Ve, readAnswerMeta as Ke, loadGroupMessages as ze, deleteHistoryGroup as Ye, setHistoryGroupTitle as Xe, getHistoryGroups as Ze, resolveRemoteFileUrl as et, collectAnswerMarkdown as Ge, markdownToPlainText as tt } from "wi-chat/parser";
3
+ import { AuthExpiredError as ce, createRequest as se, createChatApi as Oe, login as fe, makeEncryptLoginStatus as rt, pwdEncrypt as nt, loginByEncryptKey as st, isCancelError as at } from "wi-chat/request";
4
+ const ot = (e) => {
5
+ const { api: t, interval: y = 5 * 60 * 1e3, renew: h, onExpired: l, immediate: A = !0 } = e, w = G(!1), u = G(0);
6
+ let R = null, x = null;
7
+ const m = async () => {
8
+ const d = h ? await h().catch(() => !1) : !1;
9
9
  return d || l == null || l(), d;
10
- }, i = () => L || (L = (async () => {
11
- if (!r.pingLogin) return !0;
10
+ }, c = () => x || (x = (async () => {
11
+ if (!t.pingLogin) return !0;
12
12
  try {
13
- const d = await r.pingLogin();
14
- return o.value = Date.now(), (d == null ? void 0 : d.is_login) === !1 ? p() : !0;
13
+ const d = await t.pingLogin();
14
+ return u.value = Date.now(), (d == null ? void 0 : d.is_login) === !1 ? m() : !0;
15
15
  } catch (d) {
16
- return d instanceof et ? p() : !0;
16
+ return d instanceof ce ? m() : !0;
17
17
  } finally {
18
- L = null;
18
+ x = null;
19
19
  }
20
- })(), L), t = () => {
21
- x || (c.value = !0, x = setInterval(() => void i(), g));
22
- }, s = () => {
23
- x && clearInterval(x), x = null, c.value = !1;
20
+ })(), x), n = () => {
21
+ R || (w.value = !0, R = setInterval(() => void c(), y));
22
+ }, f = () => {
23
+ R && clearInterval(R), R = null, w.value = !1;
24
24
  };
25
- return h && t(), te() && we(s), { active: c, lastPingAt: o, start: t, stop: s, pingNow: i };
26
- }, H = {
25
+ return A && n(), we() && Ee(f), { active: w, lastPingAt: u, start: n, stop: f, pingNow: c };
26
+ }, F = {
27
27
  get(e) {
28
28
  try {
29
29
  return typeof localStorage < "u" ? localStorage.getItem(e) : null;
@@ -31,9 +31,9 @@ const nt = (e) => {
31
31
  return null;
32
32
  }
33
33
  },
34
- set(e, r) {
34
+ set(e, t) {
35
35
  try {
36
- typeof localStorage < "u" && localStorage.setItem(e, r);
36
+ typeof localStorage < "u" && localStorage.setItem(e, t);
37
37
  } catch {
38
38
  }
39
39
  },
@@ -43,833 +43,1009 @@ const nt = (e) => {
43
43
  } catch {
44
44
  }
45
45
  }
46
- }, rt = (e) => btoa(unescape(encodeURIComponent(e))), at = (e) => decodeURIComponent(escape(atob(e))), be = (e) => {
47
- let r = null;
48
- return () => (r || (r = Promise.resolve().then(e).catch(() => !1).finally(() => {
49
- setTimeout(() => r = null, 0);
50
- })), r);
51
- }, st = (e) => ({
46
+ }, it = (e) => btoa(unescape(encodeURIComponent(e))), lt = (e) => decodeURIComponent(escape(atob(e))), ge = 24 * 60 * 60 * 1e3, ut = 15 * 1e3, ct = (e) => {
47
+ let t = null;
48
+ return () => (t || (t = Promise.resolve().then(e).catch(() => !1).finally(() => {
49
+ setTimeout(() => t = null, 0);
50
+ })), t);
51
+ }, he = (e) => {
52
+ if (!e || typeof e != "object") return !1;
53
+ const t = e;
54
+ return t.err_code === "AUTH" || t.error_code === "AUTH" || t.err_no_login === !0;
55
+ }, ft = (e) => ({
52
56
  get() {
53
- const r = H.get(e);
54
- if (!r) return null;
57
+ const t = F.get(e);
58
+ if (!t) return null;
55
59
  try {
56
- const g = JSON.parse(at(r));
57
- return g != null && g.user && (g != null && g.pass) ? g : null;
60
+ const y = JSON.parse(t);
61
+ return y != null && y.encryptKey ? y : null;
58
62
  } catch {
59
63
  return null;
60
64
  }
61
65
  },
62
- set(r) {
63
- H.set(e, rt(JSON.stringify(r)));
66
+ set(t) {
67
+ F.set(e, JSON.stringify(t));
64
68
  },
65
69
  clear() {
66
- H.remove(e);
70
+ F.remove(e);
67
71
  }
68
- }), wt = (e) => {
69
- const r = e.sessionKey === void 0 ? "wi-chat-session" : e.sessionKey, g = e.remember ?? !1;
70
- let f = null;
71
- const l = e.credentialStore ?? (g && r ? st(`${r}-account`) : {
72
- get: () => f,
73
- set: (A) => {
74
- f = A;
72
+ }), dt = (e) => ({
73
+ get() {
74
+ const t = F.get(e);
75
+ if (!t) return null;
76
+ try {
77
+ const y = JSON.parse(lt(t));
78
+ return y != null && y.user && (y != null && y.pass) ? y : null;
79
+ } catch {
80
+ return null;
81
+ }
82
+ },
83
+ set(t) {
84
+ F.set(e, it(JSON.stringify(t)));
85
+ },
86
+ clear() {
87
+ F.remove(e);
88
+ }
89
+ }), yt = () => {
90
+ let e = null;
91
+ return {
92
+ get: () => e,
93
+ set: (t) => {
94
+ e = t;
95
+ },
96
+ clear: () => {
97
+ e = null;
98
+ }
99
+ };
100
+ }, vt = () => {
101
+ let e = null;
102
+ return {
103
+ get: () => e,
104
+ set: (t) => {
105
+ e = t;
75
106
  },
76
107
  clear: () => {
77
- f = null;
108
+ e = null;
78
109
  }
79
- }), h = r ? `${r}-user` : null, c = b(r ? H.get(r) ?? "" : ""), o = b(null);
80
- if (h)
110
+ };
111
+ }, gt = (e, t) => {
112
+ if (!Number.isFinite(e) || e <= 0 || !Number.isFinite(t) || t <= e)
113
+ throw new Error("登录密钥有效期必须大于保持登录窗口,且两者必须为正数");
114
+ return { rememberDays: e, encryptKeyDays: t };
115
+ }, xt = (e) => {
116
+ const t = e.sessionKey === void 0 ? "wi-chat-session" : e.sessionKey, y = e.remember ?? !1, { rememberDays: h, encryptKeyDays: l } = gt(
117
+ e.rememberDays ?? 7,
118
+ e.encryptKeyDays ?? 10
119
+ ), A = e.touchInterval ?? 30 * 60 * 1e3, w = e.touchMinInterval ?? 6 * 60 * 60 * 1e3, u = e.keyStore ?? (y && t ? ft(`${t}-encrypt-key`) : yt()), R = e.credentialStore ?? (y && t ? dt(`${t}-account`) : vt()), x = t ? `${t}-user` : null, m = y && t ? `${t}-signed-out` : null, c = () => !!(m && F.get(m)), n = () => {
120
+ m && F.set(m, "1");
121
+ }, f = () => {
122
+ m && F.remove(m);
123
+ }, d = G(t ? F.get(t) ?? "" : ""), s = G(null);
124
+ if (x)
81
125
  try {
82
- o.value = JSON.parse(H.get(h) || "null");
126
+ s.value = JSON.parse(F.get(x) || "null");
83
127
  } catch {
84
- o.value = null;
85
- }
86
- const x = X(() => !!c.value), L = (A) => {
87
- c.value = A.wisession || "", o.value = A, r && H.set(r, c.value), h && H.set(h, JSON.stringify(A));
88
- }, p = () => {
89
- c.value = "", o.value = null, r && H.remove(r), h && H.remove(h);
90
- }, i = $({ baseURL: e.baseURL });
91
- let t = 0;
92
- const s = be(async () => {
93
- const A = t;
128
+ s.value = null;
129
+ }
130
+ const v = de(() => !!d.value), p = (o) => {
131
+ d.value = o.wisession || "", s.value = o, t && F.set(t, d.value), x && F.set(x, JSON.stringify(o)), f();
132
+ }, I = () => {
133
+ d.value = "", s.value = null, t && F.remove(t), x && F.remove(x);
134
+ }, E = se({ baseURL: e.baseURL }), T = (o) => se({ baseURL: e.baseURL, getWisession: () => o });
135
+ let C = 0, q = null, P = 0;
136
+ const O = async ({
137
+ session: o,
138
+ userId: a
139
+ }) => {
140
+ if (!o) return { ok: !1, reason: "missing" };
141
+ const b = C;
142
+ P = Date.now();
94
143
  try {
95
- const q = await l.get();
96
- if (!q) return !1;
97
- const T = await Y(i, { ...q, client: e.client });
98
- return A !== t ? !1 : (L(T), !0);
99
- } catch {
100
- return !1;
144
+ const i = await rt(T(o), l);
145
+ if (b !== C) return { ok: !1, reason: "superseded" };
146
+ const g = i == null ? void 0 : i.encrypt_key;
147
+ if (i != null && i.json_ok && g) {
148
+ const N = await u.get(), H = await nt(String(g));
149
+ if (b !== C) return { ok: !1, reason: "superseded" };
150
+ const B = Date.now();
151
+ return await u.set({
152
+ encryptKey: H,
153
+ userId: a != null ? String(a) : (N == null ? void 0 : N.userId) || "",
154
+ createdAt: B,
155
+ expiresAt: Math.min(B + h * ge, B + l * ge),
156
+ keyExpiresAt: B + l * ge
157
+ }), q = null, await R.clear(), { ok: !0, reason: "ok", session: o };
158
+ }
159
+ const X = he(i);
160
+ return q && await R.set(q), console.warn("[wi-chat auth] 签发登录密钥失败,回退账号密码兜底:", (i == null ? void 0 : i.json_msg) || (i == null ? void 0 : i.err_code) || ""), { ok: !1, reason: X ? "credential_rejected" : "login_failed", session: o };
161
+ } catch (i) {
162
+ return b !== C ? { ok: !1, reason: "superseded" } : i instanceof ce ? (q && await R.set(q), console.warn("[wi-chat auth] 签发登录密钥被后端拒绝(无权限),回退账号密码兜底"), { ok: !1, reason: "credential_rejected", session: o }) : (console.warn("[wi-chat auth] 签发登录密钥网络异常,保留原有凭据:", i), { ok: !1, reason: "network_error", session: o });
101
163
  }
102
- }), d = $({
103
- baseURL: e.baseURL,
104
- getWisession: () => c.value,
105
- onAuthExpired: async () => {
106
- const A = await s();
107
- return A || y(), A;
164
+ }, V = async (o) => {
165
+ var b;
166
+ const a = C;
167
+ try {
168
+ const i = await st(E, {
169
+ encrypt_key: o.encryptKey,
170
+ client: e.client
171
+ });
172
+ return a !== C ? { ok: !1, reason: "superseded" } : { ok: !0, reason: "ok", session: i.wisession, userInfo: i };
173
+ } catch (i) {
174
+ return a !== C ? { ok: !1, reason: "superseded" } : i instanceof ce || he((b = i == null ? void 0 : i.response) == null ? void 0 : b.data) ? { ok: !1, reason: "credential_rejected" } : (console.warn("[wi-chat auth] 用登录密钥续期失败(保留凭据):", i), { ok: !1, reason: "network_error" });
108
175
  }
109
- }), a = _e(d, {
110
- resumable: e.resumable ?? !0,
111
- // 对话 WS 收到 user not login:用记住的账号静默重登,失败则按彻底失效处理
112
- refreshSession: async () => {
113
- const A = await s();
114
- return A || y(), A;
176
+ }, j = async (o) => {
177
+ var b;
178
+ const a = C;
179
+ try {
180
+ const i = await fe(E, {
181
+ user: o.user,
182
+ pass: o.pass,
183
+ client: e.client
184
+ });
185
+ return a !== C ? { ok: !1, reason: "superseded" } : { ok: !0, reason: "ok", session: i.wisession, userInfo: i };
186
+ } catch (i) {
187
+ return a !== C ? { ok: !1, reason: "superseded" } : i instanceof ce || he((b = i == null ? void 0 : i.response) == null ? void 0 : b.data) ? { ok: !1, reason: "credential_rejected" } : (console.warn("[wi-chat auth] 用账号密码续期失败(保留凭据):", i), { ok: !1, reason: "network_error" });
188
+ }
189
+ };
190
+ let S = null, k = 0;
191
+ const D = async () => {
192
+ var b, i;
193
+ const o = await u.get();
194
+ if (o != null && o.encryptKey) {
195
+ const g = await V(o);
196
+ if (g.ok)
197
+ return p({
198
+ ...g.userInfo || {},
199
+ wisession: g.session
200
+ }), O({ session: g.session || "", userId: (b = g.userInfo) == null ? void 0 : b.id }), g;
201
+ if (g.reason === "superseded" || g.reason === "network_error") return g;
115
202
  }
116
- }), u = nt({
117
- api: a,
203
+ const a = await R.get() ?? q;
204
+ if (a != null && a.user && (a != null && a.pass)) {
205
+ const g = await j(a);
206
+ return g.ok && (p({
207
+ ...g.userInfo || {},
208
+ wisession: g.session
209
+ }), O({ session: g.session || "", userId: (i = g.userInfo) == null ? void 0 : i.id })), g;
210
+ }
211
+ return { ok: !1, reason: "missing" };
212
+ };
213
+ let U = null, Q = -1;
214
+ const J = (o) => {
215
+ if (!y)
216
+ return Promise.resolve(
217
+ d.value ? { ok: !1, reason: "credential_rejected" } : { ok: !1, reason: "missing" }
218
+ );
219
+ if (c())
220
+ return Promise.resolve({ ok: !1, reason: "missing" });
221
+ const a = String(o || "");
222
+ if (a && (S != null && S.ok) && S.session === a && (S = null, k = 0), S && Date.now() - k < ut)
223
+ return Promise.resolve(S);
224
+ if (U && Q === C) return U;
225
+ const b = C, i = D().finally(() => {
226
+ U === i && (U = null, Q = -1);
227
+ }).then((g) => (g.reason === "superseded" || g.ok && (S = g, k = Date.now()), g));
228
+ return U = i, Q = b, i;
229
+ }, Z = (o) => o === "missing" || o === "credential_rejected", ee = () => {
230
+ var o;
231
+ d.value && (I(), W.stop(), le(), (o = e.onExpired) == null || o.call(e));
232
+ }, ae = async (o) => {
233
+ const a = await J(o);
234
+ return a.ok ? !0 : (Z(a.reason) && ee(), !1);
235
+ }, te = se({
236
+ baseURL: e.baseURL,
237
+ getWisession: () => d.value,
238
+ // client 层拿到新 session 后会用新 session 自动重试一次原请求
239
+ onAuthExpired: (o) => ae(o == null ? void 0 : o.rejectedSession)
240
+ }), oe = Oe(te, {
241
+ resumable: e.resumable ?? !0,
242
+ // 对话 WS 收到 user not login:用保存的凭据静默重登,失败则按彻底失效处理
243
+ refreshSession: () => ae()
244
+ }), W = ot({
245
+ api: oe,
118
246
  interval: e.pingInterval || 5 * 60 * 1e3,
119
- // ping 的请求拦截器已先行续期并(失败时)清过登录态,这里不重复登录
120
- renew: async () => c.value ? s() : !1,
121
- onExpired: () => y(),
247
+ // ping 的请求拦截器已先行续期;这里兜住「is_login === false 但非 AUTH 错误」的情况。
248
+ // 临时失败(network_error / login_failed)返回 true:保留登录态,等下一次心跳再试,绝不在此清登录态
249
+ renew: async () => {
250
+ if (!d.value) return !1;
251
+ const o = await J(d.value);
252
+ return o.ok || !Z(o.reason);
253
+ },
254
+ onExpired: () => ee(),
122
255
  immediate: !1
123
- }), y = () => {
124
- var A;
125
- c.value && (p(), u.stop(), (A = e.onExpired) == null || A.call(e));
126
- }, G = () => {
127
- e.pingInterval !== 0 && u.start();
128
- }, E = async (A, q, T = {}) => {
129
- const k = { ...T, user: A, pass: q, client: e.client }, O = await Y(i, k);
130
- return L(O), await l.set({ user: A, pass: q }), G(), O;
131
- }, I = async () => {
132
- const A = await s();
133
- return A && G(), A;
134
- }, P = async (A = !0) => {
135
- t += 1, p(), u.stop(), A && await l.clear();
256
+ }), ie = async () => await u.get() || await R.get() ? !0 : !!q, z = async (o = w) => {
257
+ var g;
258
+ const a = d.value;
259
+ if (!a)
260
+ return await ie() ? J() : { ok: !1, reason: "missing" };
261
+ if (!y) return { ok: !0, reason: "ok", session: a };
262
+ if (c()) return { ok: !1, reason: "missing" };
263
+ const b = await u.get();
264
+ if (b) {
265
+ if (o > 0 && Date.now() - b.createdAt < o)
266
+ return { ok: !0, reason: "ok", session: a };
267
+ } else if (o > 0 && Date.now() - P < o)
268
+ return { ok: !0, reason: "ok", session: a };
269
+ const i = await O({ session: a, userId: (g = s.value) == null ? void 0 : g.id });
270
+ return i.ok ? (S = { ok: !0, reason: "ok", session: a }, k = Date.now(), i) : i.reason === "credential_rejected" ? await ie() ? { ok: !0, reason: "ok", session: a } : J(a) : i;
271
+ };
272
+ let Y = null, re = !1;
273
+ const ye = async () => {
274
+ if (!(re || !d.value)) {
275
+ re = !0;
276
+ try {
277
+ const o = await z();
278
+ !o.ok && Z(o.reason) && ee();
279
+ } finally {
280
+ re = !1;
281
+ }
282
+ }
283
+ }, ne = () => {
284
+ !y || A <= 0 || Y || (Y = setInterval(() => void ye(), A));
285
+ }, le = () => {
286
+ Y && clearInterval(Y), Y = null;
287
+ }, r = () => {
288
+ e.pingInterval !== 0 && W.start();
289
+ }, L = async (o, a, b = {}) => {
290
+ const i = { ...b, user: o, pass: a, client: e.client }, g = await fe(E, i);
291
+ return p(g), y ? (q = { user: o, pass: a }, await O({ session: g.wisession || "", userId: g.id }), r(), ne(), g) : (r(), g);
292
+ }, _ = async () => {
293
+ if (!y) return !1;
294
+ const o = await J();
295
+ return o.ok && (r(), ne(), z()), o.ok;
296
+ }, M = async (o = !0) => {
297
+ n(), C += 1, I(), W.stop(), le(), S = null, k = 0, U = null, Q = -1, o && (q = null, await u.clear(), await R.clear());
298
+ };
299
+ return d.value && (r(), ne(), W.pingNow()), {
300
+ session: d,
301
+ userInfo: s,
302
+ isLoggedIn: v,
303
+ request: te,
304
+ api: oe,
305
+ keepAlive: W,
306
+ login: L,
307
+ autoLogin: _,
308
+ renew: async () => (await J()).ok,
309
+ restore: J,
310
+ touch: z,
311
+ logout: M
136
312
  };
137
- return c.value && (G(), u.pingNow()), { session: c, userInfo: o, isLoggedIn: x, request: d, api: a, keepAlive: u, login: E, autoLogin: I, renew: s, logout: P };
138
- }, lt = (e) => {
139
- const r = {
313
+ }, ht = (e) => {
314
+ const t = {
140
315
  requestId: e,
141
316
  sender: null,
142
317
  queue: [],
143
318
  closed: !1,
144
- reply: (g) => xe(r, g)
319
+ reply: (y) => qe(t, y)
145
320
  };
146
- return r;
147
- }, xe = (e, r, g) => {
321
+ return t;
322
+ }, qe = (e, t, y) => {
148
323
  if (e.closed) return !1;
149
- const f = typeof r == "string" ? r : JSON.stringify(r) ?? "";
150
- return e.sender ? e.sender(f, g) !== !1 : (e.queue.push({ payloadText: f, chunkSize: g }), !0);
151
- }, ge = (e) => {
152
- e.closed || (e.closed = !0, e.queue.length = 0, e.sender = null, We(e.reply));
153
- }, Le = (e) => {
154
- const r = e.login, g = e.defaultGroupTitle ?? "新对话", f = e.lastCount ?? 10, l = e.autoSetGroupTitleOnFirstQuestion ?? !0, h = {
324
+ const h = typeof t == "string" ? t : JSON.stringify(t) ?? "";
325
+ return e.sender ? e.sender(h, y) !== !1 : (e.queue.push({ payloadText: h, chunkSize: y }), !0);
326
+ }, Ie = (e) => {
327
+ e.closed || (e.closed = !0, e.queue.length = 0, e.sender = null, $e(e.reply));
328
+ }, Fe = (e) => {
329
+ const t = e.login, y = e.defaultGroupTitle ?? "新对话", h = e.lastCount ?? 10, l = e.autoSetGroupTitleOnFirstQuestion ?? !0, A = {
155
330
  beforeKnowledgeRender: e.beforeKnowledgeRender,
156
331
  parsers: e.parsers,
157
332
  actionExecute: {
158
333
  ...e.actionExecute,
159
334
  reply: () => !1
160
335
  }
161
- }, c = b(""), o = b([]), x = b(""), L = b(e.incPrevQuestion ?? "Y"), p = b(!1), i = b(!1), t = b(""), s = b(!1), d = b(""), a = b(!0), u = b(!1), y = b(0), G = e.api ? null : $({
336
+ }, w = G(""), u = G([]), R = G(""), x = G(e.incPrevQuestion ?? "Y"), m = G(!1), c = G(!1), n = G(""), f = G(!1), d = G(""), s = G(!0), v = G(!1), p = G(0), I = e.api ? null : se({
162
337
  baseURL: e.baseURL ?? "",
163
- getWisession: () => c.value,
164
- onAuthExpired: () => P()
165
- }), E = e.api ?? _e(G, { resumable: e.resumable, refreshSession: () => P() }), I = G ? $({ baseURL: e.baseURL ?? "" }) : null, P = be(async () => {
338
+ getWisession: () => w.value,
339
+ onAuthExpired: () => C()
340
+ }), E = e.api ?? Oe(I, { resumable: e.resumable, refreshSession: () => C() }), T = I ? se({ baseURL: e.baseURL ?? "" }) : null, C = ct(async () => {
166
341
  if (e.onAuthExpired) return e.onAuthExpired();
167
- if (!G || !r || !I) return !1;
168
- const n = await Y(I, r);
169
- return c.value = n.wisession || "", !!c.value;
170
- }), A = (n, _) => {
171
- var w;
172
- n && ((w = e.onRunningChange) == null || w.call(e, n, _));
342
+ if (!I || !t || !T) return !1;
343
+ const r = await fe(T, t);
344
+ return w.value = r.wisession || "", !!w.value;
345
+ }), q = (r, L) => {
346
+ var _;
347
+ r && ((_ = e.onRunningChange) == null || _.call(e, r, L));
173
348
  };
174
- let q = null, T = null, k = 0, O = 0, m = 0, S = null;
349
+ let P = null, O = null, V = 0, j = 0, S = 0, k = null;
175
350
  const D = async () => {
176
- if (d.value = "", !G || !r) {
177
- s.value = !0;
351
+ if (d.value = "", !I || !t) {
352
+ f.value = !0;
178
353
  return;
179
354
  }
180
355
  try {
181
- const n = await Y(I ?? G, r);
182
- return c.value = n.wisession || "", s.value = !0, n;
183
- } catch (n) {
184
- throw d.value = n instanceof Error ? n.message : String(n), n;
356
+ const r = await fe(T ?? I, t);
357
+ return w.value = r.wisession || "", f.value = !0, r;
358
+ } catch (r) {
359
+ throw d.value = r instanceof Error ? r.message : String(r), r;
185
360
  }
186
- }, K = (n) => n === k, W = (n) => {
187
- typeof URL > "u" || typeof URL.revokeObjectURL != "function" || n.forEach((_) => {
188
- _.role !== "user" || !_.attachments || _.attachments.forEach((w) => {
189
- var R;
190
- const M = (R = w.attachContent) == null ? void 0 : R.url;
361
+ }, U = (r) => r === V, Q = (r) => {
362
+ typeof URL > "u" || typeof URL.revokeObjectURL != "function" || r.forEach((L) => {
363
+ L.role !== "user" || !L.attachments || L.attachments.forEach((_) => {
364
+ var o;
365
+ const M = (o = _.attachContent) == null ? void 0 : o.url;
191
366
  M && M.startsWith("blob:") && URL.revokeObjectURL(M);
192
367
  });
193
368
  });
194
- }, Ge = (n) => ({
369
+ }, J = (r) => ({
195
370
  beforeKnowledgeRender: e.beforeKnowledgeRender,
196
371
  parsers: e.parsers,
197
372
  actionExecute: {
198
373
  ...e.actionExecute,
199
- reply: n.reply
200
- }
201
- }), Re = async (n) => {
202
- const _ = ++O;
203
- m += 1, p.value = !0, W(o.value), S && He(S.reply), o.value = [], t.value = n, a.value = !0, u.value = !1, y.value = 0;
204
- const w = [], M = () => {
205
- const v = [];
206
- w.forEach((F) => {
207
- v.push(F.user), F.assistant && v.push(F.assistant);
208
- }), _ === O && (o.value = v);
209
- }, R = (v) => {
210
- _ === O && (v.type === "users" ? (w.length = 0, v.users.forEach((F) => w.push({ user: F }))) : w[v.index] && (v.user && (w[v.index].user = v.user), w[v.index].assistant = v.assistant), M());
374
+ reply: r.reply
375
+ }
376
+ }), Z = async (r) => {
377
+ const L = ++j;
378
+ S += 1, m.value = !0, Q(u.value), k && Ne(k.reply), u.value = [], n.value = r, s.value = !0, v.value = !1, p.value = 0;
379
+ const _ = [], M = () => {
380
+ const a = [];
381
+ _.forEach((b) => {
382
+ a.push(b.user), b.assistant && a.push(b.assistant);
383
+ }), L === j && (u.value = a);
384
+ }, o = (a) => {
385
+ L === j && (a.type === "users" ? (_.length = 0, a.users.forEach((b) => _.push({ user: b }))) : _[a.index] && (a.user && (_[a.index].user = a.user), _[a.index].assistant = a.assistant), M());
211
386
  };
212
387
  try {
213
- await de(E, n, f, R, 0, h), M(), _ === O && (y.value = w.length, w.length < f && (a.value = !1));
388
+ await Le(E, r, h, o, 0, A), M(), L === j && (p.value = _.length, _.length < h && (s.value = !1));
214
389
  } finally {
215
- m -= 1, m <= 0 && (m = 0, p.value = !1);
390
+ S -= 1, S <= 0 && (S = 0, m.value = !1);
216
391
  }
217
- }, Ce = async () => {
218
- if (!t.value || p.value || !a.value || u.value) return;
219
- const n = t.value, _ = O, w = y.value;
220
- u.value = !0;
392
+ }, ee = async () => {
393
+ if (!n.value || m.value || !s.value || v.value) return;
394
+ const r = n.value, L = j, _ = p.value;
395
+ v.value = !0;
221
396
  try {
222
- const M = await de(E, n, f, void 0, w, h), R = M.filter((v) => v.role === "user").length;
223
- if (R < f && (a.value = !1), _ === O && t.value === n) {
224
- const v = /* @__PURE__ */ new Set();
225
- o.value.forEach((C) => {
226
- C.historyId && v.add(C.historyId), C.id && v.add(C.id);
397
+ const M = await Le(E, r, h, void 0, _, A), o = M.filter((a) => a.role === "user").length;
398
+ if (o < h && (s.value = !1), L === j && n.value === r) {
399
+ const a = /* @__PURE__ */ new Set();
400
+ u.value.forEach((i) => {
401
+ i.historyId && a.add(i.historyId), i.id && a.add(i.id);
227
402
  });
228
- const F = M.filter((C) => !(C.historyId && v.has(C.historyId) || C.id && v.has(C.id)));
229
- o.value = [...F, ...o.value], y.value += R;
403
+ const b = M.filter((i) => !(i.historyId && a.has(i.historyId) || i.id && a.has(i.id)));
404
+ u.value = [...b, ...u.value], p.value += o;
230
405
  }
231
406
  } finally {
232
- u.value = !1;
407
+ v.value = !1;
233
408
  }
234
- }, Ee = async (n = g) => {
235
- const _ = await Se(E, n);
236
- return t.value = _, _;
237
- }, ne = (n = !0) => {
238
- var _;
239
- n !== !1 && i.value && t.value && ((_ = E.stopChat) == null || _.call(E, t.value)), k += 1, O += 1, T && (T.stopped = !0, T.thinking.expanded = !1, Z(T)), q == null || q.abort(), q = null, S && ge(S), S = null, T = null, i.value = !1;
240
- }, Ie = () => {
241
- T && (T.error = !0, T.thinking.expanded = !1, Z(T));
242
- }, re = async (n, _, w, M) => {
243
- const R = k + 1;
244
- k = R, O += 1;
245
- const v = lt(R);
246
- S = v;
247
- const F = Ge(v), C = M || t.value;
248
- T = n, i.value = !0, A(C, !0);
249
- let Q = !1;
409
+ }, ae = async (r = y) => {
410
+ const L = await Te(E, r);
411
+ return n.value = L, L;
412
+ }, te = (r = !0) => {
413
+ var L;
414
+ r !== !1 && c.value && n.value && ((L = E.stopChat) == null || L.call(E, n.value)), V += 1, j += 1, O && (O.stopped = !0, O.thinking.expanded = !1, z(O)), P == null || P.abort(), P = null, k && Ie(k), k = null, O = null, c.value = !1;
415
+ }, oe = () => {
416
+ O && (O.error = !0, O.thinking.expanded = !1, z(O));
417
+ }, W = async (r, L, _, M) => {
418
+ const o = V + 1;
419
+ V = o, j += 1;
420
+ const a = ht(o);
421
+ k = a;
422
+ const b = J(a), i = M || n.value;
423
+ O = r, c.value = !0, q(i, !0);
424
+ let g = !1;
250
425
  try {
251
- q = new AbortController();
252
- const z = await w((j) => {
253
- if (!K(R) || v.closed) return;
254
- v.sender = j;
255
- const N = v.queue;
256
- v.queue = [], N.forEach(({ payloadText: B, chunkSize: ee }) => j(B, ee));
257
- }, q.signal);
258
- await Ne(z, (j) => {
259
- var N;
260
- K(R) && (Me(n, _, j, F), (N = e.onChunk) == null || N.call(e, j));
261
- }), K(R) && (Q = !0, n.thinking.expanded = !1, Z(n));
262
- } catch (z) {
263
- K(R) && !tt(z) && Ie();
426
+ P = new AbortController();
427
+ const X = await _((N) => {
428
+ if (!U(o) || a.closed) return;
429
+ a.sender = N;
430
+ const H = a.queue;
431
+ a.queue = [], H.forEach(({ payloadText: B, chunkSize: ve }) => N(B, ve));
432
+ }, P.signal);
433
+ await He(X, (N) => {
434
+ var H;
435
+ U(o) && (ie(r, L, N, b), (H = e.onChunk) == null || H.call(e, N));
436
+ }), U(o) && (g = !0, r.thinking.expanded = !1, z(r));
437
+ } catch (X) {
438
+ U(o) && !at(X) && oe();
264
439
  } finally {
265
- ge(v), S === v && (S = null), A(C, !1), K(R) && (i.value = !1, q = null, T = null);
440
+ Ie(a), k === a && (k = null), q(i, !1), U(o) && (c.value = !1, P = null, O = null);
266
441
  }
267
- return Q && Ue(n), Q;
268
- }, Me = (n, _, w, M) => {
269
- if (w.mode === "history_id") {
270
- const v = typeof w.value == "object" && w.value !== null ? w.value.history_id : w.value;
271
- v && (_ && (_.historyId = String(v)), n.historyId = String(v), n.answer.id = String(v));
442
+ return g && Y(r), g;
443
+ }, ie = (r, L, _, M) => {
444
+ if (_.mode === "history_id") {
445
+ const a = typeof _.value == "object" && _.value !== null ? _.value.history_id : _.value;
446
+ a && (L && (L.historyId = String(a)), r.historyId = String(a), r.answer.id = String(a));
272
447
  return;
273
448
  }
274
- if (w.mode === "start") {
275
- const v = Je(w.value ?? w.time, n.runStartAt);
276
- v != null && n.runStartAt != null && (n.runStartAt = v);
449
+ if (_.mode === "start") {
450
+ const a = Je(_.value ?? _.time, r.runStartAt);
451
+ a != null && r.runStartAt != null && (r.runStartAt = a);
277
452
  return;
278
453
  }
279
- if (w.mode === "history_answer") {
280
- const v = ke(w.value, n.historyId ?? "", n.answer.question ?? "", h);
281
- n.answer = v, n.thinking.steps = ve(v);
454
+ if (_.mode === "history_answer") {
455
+ const a = Be(_.value, r.historyId ?? "", r.answer.question ?? "", A);
456
+ r.answer = a, r.thinking.steps = xe(a);
282
457
  return;
283
458
  }
284
- je(n.answer, w, M).includes("deep_thinking") && (n.thinking.steps = ve(n.answer)), w.mode === "finish" && (n.thinking.expanded = !1);
285
- }, Z = (n) => {
286
- !n || n.runStartAt == null || (n.runMs = Math.max(0, Date.now() - n.runStartAt), delete n.runStartAt);
287
- }, Ue = async (n) => {
288
- if (!(!e.syncMetaOnFinish || !n.historyId))
459
+ We(r.answer, _, M).includes("deep_thinking") && (r.thinking.steps = xe(r.answer)), _.mode === "finish" && (r.thinking.expanded = !1);
460
+ }, z = (r) => {
461
+ !r || r.runStartAt == null || (r.runMs = Math.max(0, Date.now() - r.runStartAt), delete r.runStartAt);
462
+ }, Y = async (r) => {
463
+ if (!(!e.syncMetaOnFinish || !r.historyId))
289
464
  try {
290
- const _ = await E.getHistoryAnswer(n.historyId);
291
- ze(n.answer, _);
292
- const w = Ae(n.answer).runMs;
293
- w != null && (n.runMs = w);
465
+ const L = await E.getHistoryAnswer(r.historyId);
466
+ Ve(r.answer, L);
467
+ const _ = Ke(r.answer).runMs;
468
+ _ != null && (r.runMs = _);
294
469
  } catch {
295
470
  }
296
- }, qe = async (n) => {
297
- var le, oe;
298
- const _ = typeof n == "string" ? { text: n } : n || {}, { text: w, entryId: M, files: R, attachments: v, extArgs: F, ...C } = _, Q = (w !== void 0 ? w : x.value).trim(), z = F ?? e.extArgs ?? {}, j = R && R.length > 0 ? R : (v ?? []).map((U) => {
299
- var J;
300
- return (J = U.attachContent) == null ? void 0 : J.raw;
301
- }).filter((U) => !!U);
302
- if (!Q || i.value || !t.value) return;
303
- const N = t.value, B = v || (R || []).map((U) => {
304
- var ie;
305
- const J = U.name.includes(".") && ((ie = U.name.split(".").pop()) == null ? void 0 : ie.toLowerCase()) || "";
471
+ }, re = async (r) => {
472
+ var Se, _e;
473
+ const L = typeof r == "string" ? { text: r } : r || {}, { text: _, entryId: M, files: o, attachments: a, extArgs: b, ...i } = L, g = (_ !== void 0 ? _ : R.value).trim(), X = b ?? e.extArgs ?? {}, N = o && o.length > 0 ? o : (a ?? []).map((K) => {
474
+ var $;
475
+ return ($ = K.attachContent) == null ? void 0 : $.raw;
476
+ }).filter((K) => !!K);
477
+ if (!g || c.value || !n.value) return;
478
+ const H = n.value, B = a || (o || []).map((K) => {
479
+ var Ae;
480
+ const $ = K.name.includes(".") && ((Ae = K.name.split(".").pop()) == null ? void 0 : Ae.toLowerCase()) || "";
306
481
  return {
307
482
  type: "file",
308
- name: U.name,
309
- description: J ? J.toUpperCase() : "",
310
- attachContent: { file_name: U.name, size: U.size, suffix: J, raw: U }
483
+ name: K.name,
484
+ description: $ ? $.toUpperCase() : "",
485
+ attachContent: { file_name: K.name, size: K.size, suffix: $, raw: K }
311
486
  };
312
- }), ee = y.value === 0 && !o.value.some((U) => U.role === "user"), ae = V({
313
- id: fe("user"),
487
+ }), ve = p.value === 0 && !u.value.some((K) => K.role === "user"), pe = ue({
488
+ id: Re("user"),
314
489
  role: "user",
315
- content: Q,
490
+ content: g,
316
491
  attachments: B.length > 0 ? B : void 0
317
492
  });
318
- o.value.push(ae);
319
- const se = V({
320
- id: fe("answer"),
493
+ u.value.push(pe);
494
+ const me = ue({
495
+ id: Re("answer"),
321
496
  role: "assistant",
322
- answer: ce("", Q),
497
+ answer: be("", g),
323
498
  error: !1,
324
499
  stopped: !1,
325
500
  runStartAt: Date.now(),
326
501
  thinking: { steps: [], expanded: !0 }
327
502
  });
328
- if (o.value.push(se), x.value = "", (le = e.onSubmitQuestion) == null || le.call(e, Q), ee) {
329
- const U = De(Q);
330
- e.onFirstQuestion ? e.onFirstQuestion({ question: U, groupId: N }) : l && U && E.setHistoryGroupTitle(N, U).catch(() => {
503
+ if (u.value.push(me), R.value = "", (Se = e.onSubmitQuestion) == null || Se.call(e, g), ve) {
504
+ const K = Qe(g);
505
+ e.onFirstQuestion ? e.onFirstQuestion({ question: K, groupId: H }) : l && K && E.setHistoryGroupTitle(H, K).catch(() => {
331
506
  });
332
507
  }
333
- y.value += 1, await re(
334
- se,
335
- ae,
336
- (U, J) => E.questionStream(
508
+ p.value += 1, await W(
509
+ me,
510
+ pe,
511
+ (K, $) => E.questionStream(
337
512
  {
338
513
  // 先铺开外部透传的额外字段,已知字段随后覆盖,避免同名额外字段篡改核心参数
339
- ...C,
340
- question: Q,
341
- historyGroupId: N,
514
+ ...i,
515
+ question: g,
516
+ historyGroupId: H,
342
517
  entryId: M,
343
- files: j,
344
- ext_args: JSON.stringify(z),
345
- incPrevQuestion: L.value,
346
- onOpen: U
518
+ files: N,
519
+ ext_args: JSON.stringify(X),
520
+ incPrevQuestion: x.value,
521
+ onOpen: K
347
522
  },
348
- J
523
+ $
349
524
  )
350
- ) && ((oe = e.onFinish) == null || oe.call(e));
351
- }, Te = async (n) => {
352
- var F;
353
- if (i.value || !(n != null && n.history_id) || t.value && n.history_group_id && n.history_group_id !== t.value) return !1;
354
- !t.value && n.history_group_id && (t.value = n.history_group_id);
355
- const _ = o.value.find((C) => C.role === "user" && C.historyId === n.history_id);
356
- o.value = o.value.filter((C) => !(C.role === "assistant" && C.historyId === n.history_id));
357
- let w = _ ?? null;
358
- w || (w = V({
359
- id: n.history_id,
360
- historyId: n.history_id,
525
+ ) && ((_e = e.onFinish) == null || _e.call(e));
526
+ }, ye = async (r) => {
527
+ var b;
528
+ if (c.value || !(r != null && r.history_id) || n.value && r.history_group_id && r.history_group_id !== n.value) return !1;
529
+ !n.value && r.history_group_id && (n.value = r.history_group_id);
530
+ const L = u.value.find((i) => i.role === "user" && i.historyId === r.history_id);
531
+ u.value = u.value.filter((i) => !(i.role === "assistant" && i.historyId === r.history_id));
532
+ let _ = L ?? null;
533
+ _ || (_ = ue({
534
+ id: r.history_id,
535
+ historyId: r.history_id,
361
536
  role: "user",
362
- content: n.question ?? ""
363
- }), o.value.push(w), y.value += 1);
364
- const M = V({
365
- id: `${n.history_id}-answer`,
366
- historyId: n.history_id,
537
+ content: r.question ?? ""
538
+ }), u.value.push(_), p.value += 1);
539
+ const M = ue({
540
+ id: `${r.history_id}-answer`,
541
+ historyId: r.history_id,
367
542
  role: "assistant",
368
- answer: ce(n.history_id, n.question ?? ""),
543
+ answer: be(r.history_id, r.question ?? ""),
369
544
  error: !1,
370
545
  stopped: !1,
371
546
  runStartAt: Date.now(),
372
547
  thinking: { steps: [], expanded: !0 }
373
- }), R = o.value.indexOf(w);
374
- o.value.splice(R + 1, 0, M);
375
- const v = await re(
548
+ }), o = u.value.indexOf(_);
549
+ u.value.splice(o + 1, 0, M);
550
+ const a = await W(
376
551
  M,
377
- w,
378
- (C, Q) => E.questionStream(
552
+ _,
553
+ (i, g) => E.questionStream(
379
554
  {
380
- question: n.question ?? "",
381
- historyGroupId: n.history_group_id || t.value,
382
- resumeTask: n,
383
- onOpen: C
555
+ question: r.question ?? "",
556
+ historyGroupId: r.history_group_id || n.value,
557
+ resumeTask: r,
558
+ onOpen: i
384
559
  },
385
- Q
560
+ g
386
561
  ),
387
- n.history_group_id || t.value
562
+ r.history_group_id || n.value
388
563
  );
389
- return v && ((F = e.onFinish) == null || F.call(e)), v;
390
- }, Oe = (n, _) => !i.value || !S ? !1 : xe(S, n, _), Ke = e.autoLogin !== !1 ? D().then(() => {
564
+ return a && ((b = e.onFinish) == null || b.call(e)), a;
565
+ }, ne = (r, L) => !c.value || !k ? !1 : qe(k, r, L), le = e.autoLogin !== !1 ? D().then(() => {
391
566
  }).catch(() => {
392
567
  }) : Promise.resolve();
393
- return pe() && me(() => {
394
- ne(!1), W(o.value);
568
+ return Ue() && Me(() => {
569
+ te(!1), Q(u.value);
395
570
  }), {
396
571
  /** 当前分组的消息列表(user / assistant 交错;loadGroup / loadOlder / submitQuestion 会更新) */
397
- messages: o,
572
+ messages: u,
398
573
  /** 输入框内容(v-model 绑定;submitQuestion 成功后清空) */
399
- question: x,
574
+ question: R,
400
575
  /**
401
576
  * 提问是否携带之前对话上下文(inc_prev_question:'Y' 不忽略 / 'N' 忽略,默认 'Y')。
402
577
  * submitQuestion 提交时读取当前值发送;可在外部随时修改(如绑定输入框组件的勾选开关)。
403
578
  */
404
- incPrevQuestion: L,
579
+ incPrevQuestion: x,
405
580
  /** 会话发送 / 流式回答进行中(true 时 submitQuestion 不再受理新提问) */
406
- talking: i,
581
+ talking: c,
407
582
  /** 历史加载中(首屏 loadGroup 及并发加载全部完成后结束) */
408
- loading: p,
583
+ loading: m,
409
584
  /** 当前会话 token(自动登录写入;未自动登录时可自行赋值) */
410
- session: c,
585
+ session: w,
411
586
  /** 自动登录流程已结束(成功 / 失败 / 跳过均置 true;UI 可等待它再渲染登录状态) */
412
- autoLoginDone: s,
587
+ autoLoginDone: f,
413
588
  /** 最近一次自动登录的错误信息(UI 可据此提示重试) */
414
589
  autoLoginError: d,
415
590
  /** 自动登录完成时机(无论成败都会 resolve;宿主用它编排"登录后才能发"的请求,如加载历史分组) */
416
- loginDone: Ke,
591
+ loginDone: le,
417
592
  /** 当前会话所在的历史分组 id */
418
- historyGroupId: t,
593
+ historyGroupId: n,
419
594
  /** 内部自建的 request 客户端(注入 api 时为 null,无使用价值) */
420
- selfRequest: G,
595
+ selfRequest: I,
421
596
  /** 实际使用的业务 API(外部注入的实例或内部自建) */
422
597
  api: E,
423
598
  /** 手动触发一次自动登录(成功返回登录结果;失败抛错并记录到 autoLoginError) */
424
599
  doAutoLogin: D,
425
600
  /** 按分组加载消息(插空式渐进渲染;并发调用时仅最新一次生效) */
426
- loadGroup: Re,
601
+ loadGroup: Z,
427
602
  /** 加载更早一页历史(向上翻页),前插到消息列表顶部 */
428
- loadOlder: Ce,
603
+ loadOlder: ee,
429
604
  /** 是否仍可能有更早历史(向上翻页) */
430
- hasMore: a,
605
+ hasMore: s,
431
606
  /** 向上翻页加载中(触顶防重) */
432
- loadMoreLoading: u,
607
+ loadMoreLoading: v,
433
608
  /** 新建历史分组并选中(返回分组 id) */
434
- createGroup: Ee,
609
+ createGroup: ae,
435
610
  /** 提交问题并走 SSE 流式问答(支持传参 entryId、files 与文本;无文本 / 发送中 / 无分组时不发送) */
436
- submitQuestion: qe,
611
+ submitQuestion: re,
437
612
  /**
438
613
  * 向当前提问的 WebSocket 连接追发自定义消息(B/M/E 分帧):
439
614
  * 连接就绪立即发出、未就绪入队待连接建立后按序补发;仅在 talking 期间受理,
440
615
  * 无在途会话返回 false。见 sendWsMessage 的 JSDoc。
441
616
  */
442
- sendWsMessage: Oe,
617
+ sendWsMessage: ne,
443
618
  /** 停止在途会话:向后端发 STOP(可续传模式)、中断流、把当前回答标记为 stopped,并复位 talking */
444
- stopQuestion: ne,
619
+ stopQuestion: te,
445
620
  /** 接管当前分组正在进行的任务(刷新 / 切回房间后 CONNECT 重放),需 resumable */
446
- resumeTask: Te,
621
+ resumeTask: ye,
447
622
  /** 手动触发一次登录态续期(并发调用合并为一次) */
448
- renewSession: P
623
+ renewSession: C
449
624
  };
450
- }, ot = "wi-chat-history-groups", it = (e) => {
451
- var O;
625
+ }, wt = "wi-chat-history-groups", pt = (e) => {
626
+ var j;
452
627
  const {
453
- api: r,
454
- defaultGroupTitle: g = "新对话",
455
- lastCount: f = 10,
628
+ api: t,
629
+ defaultGroupTitle: y = "新对话",
630
+ lastCount: h = 10,
456
631
  ensureGroup: l = !0,
457
- autoSelectFirst: h = !0,
458
- autoLoadMessages: c = !0
459
- } = e, o = e.persistGroups ?? !1, x = e.storageKey ?? ot, L = e.beforeKnowledgeRender || (O = e.parsers) != null && O.length ? { beforeKnowledgeRender: e.beforeKnowledgeRender, parsers: e.parsers } : void 0, p = b([]), i = b(""), t = b([]), s = b(!1);
460
- let d = !1, a = null;
461
- const u = () => {
462
- if (a === !1) return null;
463
- let m;
632
+ autoSelectFirst: A = !0,
633
+ autoLoadMessages: w = !0
634
+ } = e, u = e.persistGroups ?? !1, R = e.storageKey ?? wt, x = e.beforeKnowledgeRender || (j = e.parsers) != null && j.length ? { beforeKnowledgeRender: e.beforeKnowledgeRender, parsers: e.parsers } : void 0, m = G([]), c = G(""), n = G([]), f = G(!1);
635
+ let d = !1, s = null;
636
+ const v = () => {
637
+ if (s === !1) return null;
638
+ let S;
464
639
  try {
465
- m = localStorage.getItem(x);
640
+ S = localStorage.getItem(R);
466
641
  } catch {
467
- return a = !1, null;
642
+ return s = !1, null;
468
643
  }
469
- if (m === null) return [];
644
+ if (S === null) return [];
470
645
  try {
471
- const S = JSON.parse(m);
472
- return Array.isArray(S) ? S : [];
646
+ const k = JSON.parse(S);
647
+ return Array.isArray(k) ? k : [];
473
648
  } catch {
474
649
  return [];
475
650
  }
476
- }, y = (m) => {
477
- if (a !== !1)
651
+ }, p = (S) => {
652
+ if (s !== !1)
478
653
  try {
479
- localStorage.setItem(x, JSON.stringify(m));
654
+ localStorage.setItem(R, JSON.stringify(S));
480
655
  } catch {
481
- a = !1;
656
+ s = !1;
482
657
  }
483
- }, G = (m) => {
484
- const S = u();
485
- S !== null && y([...S, m]);
486
- }, E = async (m, S = f) => {
487
- s.value = !0;
658
+ }, I = (S) => {
659
+ const k = v();
660
+ k !== null && p([...k, S]);
661
+ }, E = async (S, k = h) => {
662
+ f.value = !0;
488
663
  try {
489
- t.value = m ? await Be(r, m, S, 0, L) : [];
664
+ n.value = S ? await ze(t, S, k, 0, x) : [];
490
665
  } finally {
491
- s.value = !1;
666
+ f.value = !1;
492
667
  }
493
- }, I = async (m) => {
494
- i.value = m, c && await E(m);
495
- }, P = async () => {
668
+ }, T = async (S) => {
669
+ c.value = S, w && await E(S);
670
+ }, C = async () => {
496
671
  if (!d) {
497
672
  d = !0;
498
673
  try {
499
- p.value.length === 0 ? l && await q(g) : !i.value && h && await I(p.value[0].group_id);
674
+ m.value.length === 0 ? l && await P(y) : !c.value && A && await T(m.value[0].group_id);
500
675
  } finally {
501
676
  d = !1;
502
677
  }
503
678
  }
504
- }, A = async () => {
505
- s.value = !0;
679
+ }, q = async () => {
680
+ f.value = !0;
506
681
  try {
507
- const m = await Ye(r);
508
- if (o) {
509
- const S = u();
510
- if (S === null)
511
- p.value = m;
682
+ const S = await Ze(t);
683
+ if (u) {
684
+ const k = v();
685
+ if (k === null)
686
+ m.value = S;
512
687
  else {
513
- const D = new Set(S.map((W) => W.group_id)), K = m.filter((W) => D.has(W.group_id));
514
- y(K), p.value = K;
688
+ const D = new Set(k.map((Q) => Q.group_id)), U = S.filter((Q) => D.has(Q.group_id));
689
+ p(U), m.value = U;
515
690
  }
516
691
  } else
517
- p.value = m;
518
- await P();
692
+ m.value = S;
693
+ await C();
519
694
  } finally {
520
- s.value = !1;
695
+ f.value = !1;
521
696
  }
522
- }, q = async (m = g) => {
523
- const S = await Se(r, m);
524
- return o && G({ group_id: S, group_title: m }), await A(), i.value !== S && await I(S), S;
697
+ }, P = async (S = y) => {
698
+ const k = await Te(t, S);
699
+ return u && I({ group_id: k, group_title: S }), await q(), c.value !== k && await T(k), k;
525
700
  };
526
701
  return {
527
- groups: p,
528
- activeGroupId: i,
529
- messages: t,
530
- loading: s,
531
- loadGroups: A,
532
- createGroup: q,
533
- renameGroup: async (m, S) => {
534
- await $e(r, m, S);
535
- const D = p.value.find((K) => K.group_id === m);
536
- D && (D.group_title = S), o && y(p.value);
702
+ groups: m,
703
+ activeGroupId: c,
704
+ messages: n,
705
+ loading: f,
706
+ loadGroups: q,
707
+ createGroup: P,
708
+ renameGroup: async (S, k) => {
709
+ await Xe(t, S, k);
710
+ const D = m.value.find((U) => U.group_id === S);
711
+ D && (D.group_title = k), u && p(m.value);
537
712
  },
538
- deleteGroup: async (m) => {
539
- const S = p.value.findIndex((K) => K.group_id === m);
540
- if (await Ve(r, m), p.value = p.value.filter((K) => K.group_id !== m), o && y(p.value), i.value !== m) return;
541
- const D = p.value[S] ?? p.value[p.value.length - 1];
713
+ deleteGroup: async (S) => {
714
+ const k = m.value.findIndex((U) => U.group_id === S);
715
+ if (await Ye(t, S), m.value = m.value.filter((U) => U.group_id !== S), u && p(m.value), c.value !== S) return;
716
+ const D = m.value[k] ?? m.value[m.value.length - 1];
542
717
  if (D) {
543
- await I(D.group_id);
718
+ await T(D.group_id);
544
719
  return;
545
720
  }
546
- l ? await q(g) : (i.value = "", t.value = []);
721
+ l ? await P(y) : (c.value = "", n.value = []);
547
722
  },
548
- selectGroup: I,
723
+ selectGroup: T,
549
724
  loadMessages: E
550
725
  };
551
- }, ut = (e) => {
552
- const { api: r, defaultEntryId: g, entryGroup: f = "智能助手", autoLoad: l = !0 } = e, h = b([]), c = b(null), o = b(!1), x = (i) => i ? typeof r.getFileUrl == "function" ? r.getFileUrl(i) : Xe(i, "", "/algorithm/get_file_data") : "", L = (i) => {
553
- c.value = i;
554
- }, p = async () => {
555
- var i;
556
- o.value = !0;
726
+ }, mt = (e) => {
727
+ const { api: t, defaultEntryId: y, entryGroup: h = "智能助手", autoLoad: l = !0 } = e, A = G([]), w = G(null), u = G(!1), R = (c) => c ? typeof t.getFileUrl == "function" ? t.getFileUrl(c) : et(c, "", "/algorithm/get_file_data") : "", x = (c) => {
728
+ w.value = c;
729
+ }, m = async () => {
730
+ var c;
731
+ u.value = !0;
557
732
  try {
558
- let t = g || ((i = c.value) == null ? void 0 : i.entry_id);
559
- if (!t)
733
+ let n = y || ((c = w.value) == null ? void 0 : c.entry_id);
734
+ if (!n)
560
735
  try {
561
- const u = await r.getDefaultLlmId();
562
- t = u == null ? void 0 : u.default_entry_id;
563
- } catch (u) {
564
- console.warn("[useAgent] 获取默认智能体 ID 失败:", u);
736
+ const v = await t.getDefaultLlmId();
737
+ n = v == null ? void 0 : v.default_entry_id;
738
+ } catch (v) {
739
+ console.warn("[useAgent] 获取默认智能体 ID 失败:", v);
565
740
  }
566
- const s = await r.getLlmEntryListByRole({ entry_group: f }), a = ((s == null ? void 0 : s.values) || []).filter((u) => u.entry_enable !== !1);
567
- if (h.value = a, t) {
568
- const u = a.find((y) => y.entry_id === t);
569
- u ? c.value = u : a.length > 0 && (c.value = a[0]);
570
- } else a.length > 0 && !c.value && (c.value = a[0]);
741
+ const f = await t.getLlmEntryListByRole({ entry_group: h }), s = ((f == null ? void 0 : f.values) || []).filter((v) => v.entry_enable !== !1);
742
+ if (A.value = s, n) {
743
+ const v = s.find((p) => p.entry_id === n);
744
+ v ? w.value = v : s.length > 0 && (w.value = s[0]);
745
+ } else s.length > 0 && !w.value && (w.value = s[0]);
571
746
  } finally {
572
- o.value = !1;
747
+ u.value = !1;
573
748
  }
574
749
  };
575
- return l && (te() ? Fe(() => {
576
- p();
577
- }) : p()), {
578
- agentList: h,
579
- currentAgent: c,
580
- loading: o,
581
- getFileUrl: x,
582
- loadAgents: p,
583
- selectAgent: L
750
+ return l && (we() ? Pe(() => {
751
+ m();
752
+ }) : m()), {
753
+ agentList: A,
754
+ currentAgent: w,
755
+ loading: u,
756
+ getFileUrl: R,
757
+ loadAgents: m,
758
+ selectAgent: x
584
759
  };
585
- }, ct = (e) => {
586
- const { api: r, interval: g = 5e3, immediate: f = !1 } = e, l = b([]), h = b(/* @__PURE__ */ new Set());
587
- let c = null, o = null;
588
- const x = X(() => {
589
- const a = new Set(h.value);
590
- return l.value.forEach((u) => u.history_group && a.add(String(u.history_group))), a;
591
- }), L = (a) => !!a && x.value.has(a), p = (a, u) => {
592
- if (!a) return;
593
- const y = new Set(h.value);
594
- if (u ? y.add(a) : y.delete(a), h.value = y, !u) {
595
- const G = o;
596
- (async () => (G && await G, await t()))();
597
- }
598
- }, i = (a) => l.value.find(
599
- (u) => String(u.history_group) === a && u.is_connected !== !0 && !h.value.has(a)
600
- ), t = () => o || (o = (async () => {
601
- if (!r.getChatTaskList) return l.value;
760
+ }, St = (e) => {
761
+ const { api: t, interval: y = 5e3, immediate: h = !1 } = e, l = G([]), A = G(/* @__PURE__ */ new Set());
762
+ let w = null, u = null;
763
+ const R = de(() => {
764
+ const s = new Set(A.value);
765
+ return l.value.forEach((v) => v.history_group && s.add(String(v.history_group))), s;
766
+ }), x = (s) => !!s && R.value.has(s), m = (s, v) => {
767
+ if (!s) return;
768
+ const p = new Set(A.value);
769
+ if (v ? p.add(s) : p.delete(s), A.value = p, !v) {
770
+ const I = u;
771
+ (async () => (I && await I, await n()))();
772
+ }
773
+ }, c = (s) => l.value.find(
774
+ (v) => String(v.history_group) === s && v.is_connected !== !0 && !A.value.has(s)
775
+ ), n = () => u || (u = (async () => {
776
+ if (!t.getChatTaskList) return l.value;
602
777
  try {
603
- const a = (await r.getChatTaskList()).filter((u) => u && u.is_stop !== !0);
604
- if (l.value = a, e.onUnknownGroups && e.isKnownGroup) {
605
- const u = a.map((y) => String(y.history_group)).filter((y) => y && !e.isKnownGroup(y));
606
- u.length && e.onUnknownGroups(u);
778
+ const s = (await t.getChatTaskList()).filter((v) => v && v.is_stop !== !0);
779
+ if (l.value = s, e.onUnknownGroups && e.isKnownGroup) {
780
+ const v = s.map((p) => String(p.history_group)).filter((p) => p && !e.isKnownGroup(p));
781
+ v.length && e.onUnknownGroups(v);
607
782
  }
608
783
  } catch {
609
784
  } finally {
610
- o = null;
785
+ u = null;
611
786
  }
612
787
  return l.value;
613
- })(), o), s = () => {
614
- c || !g || (t(), c = setInterval(() => void t(), g));
788
+ })(), u), f = () => {
789
+ w || !y || (n(), w = setInterval(() => void n(), y));
615
790
  }, d = () => {
616
- c && clearInterval(c), c = null, l.value = [];
791
+ w && clearInterval(w), w = null, l.value = [];
617
792
  };
618
- return f && s(), te() && we(d), { tasks: l, runningIds: x, isRunning: L, setLocalRunning: p, findResumableTask: i, refresh: t, start: s, stop: d };
619
- }, pt = (e) => {
620
- const { api: r, maxRooms: g = 10 } = e, f = Pe(/* @__PURE__ */ new Map()), l = b(""), h = ct({
621
- api: r,
793
+ return h && f(), we() && Ee(d), { tasks: l, runningIds: R, isRunning: x, setLocalRunning: m, findResumableTask: c, refresh: n, start: f, stop: d };
794
+ }, Gt = (e) => {
795
+ const { api: t, maxRooms: y = 10 } = e, h = je(/* @__PURE__ */ new Map()), l = G(""), A = St({
796
+ api: t,
622
797
  interval: e.taskPollInterval ?? 5e3,
623
798
  onUnknownGroups: e.onUnknownGroups,
624
799
  isKnownGroup: e.isKnownGroup
625
- }), c = (t) => {
626
- if (f.size <= g) return;
627
- const s = [...f.entries()].filter(([d, a]) => d !== l.value && d !== t && !a.chat.talking.value).sort((d, a) => d[1].touchedAt - a[1].touchedAt);
628
- for (; f.size > g && s.length; ) {
629
- const [d] = s.shift();
630
- L(d);
631
- }
632
- }, o = (t) => {
633
- const s = f.get(t);
634
- if (s)
635
- return s.touchedAt = Date.now(), s.chat;
636
- const d = Qe(!0), a = d.run(
800
+ }), w = (n) => {
801
+ if (h.size <= y) return;
802
+ const f = [...h.entries()].filter(([d, s]) => d !== l.value && d !== n && !s.chat.talking.value).sort((d, s) => d[1].touchedAt - s[1].touchedAt);
803
+ for (; h.size > y && f.length; ) {
804
+ const [d] = f.shift();
805
+ x(d);
806
+ }
807
+ }, u = (n) => {
808
+ const f = h.get(n);
809
+ if (f)
810
+ return f.touchedAt = Date.now(), f.chat;
811
+ const d = De(!0), s = d.run(
637
812
  () => {
638
- var y;
639
- return Le({
640
- ...(y = e.roomOptions) == null ? void 0 : y.call(e, t),
641
- api: r,
813
+ var p;
814
+ return Fe({
815
+ ...(p = e.roomOptions) == null ? void 0 : p.call(e, n),
816
+ api: t,
642
817
  autoLogin: !1,
643
818
  parsers: e.parsers,
644
819
  beforeKnowledgeRender: e.beforeKnowledgeRender,
645
820
  actionExecute: e.actionExecute,
646
821
  lastCount: e.lastCount,
647
822
  syncMetaOnFinish: !0,
648
- onRunningChange: h.setLocalRunning
823
+ onRunningChange: A.setLocalRunning
649
824
  });
650
825
  }
651
- ), u = { chat: a, scope: d, loaded: a.loadGroup(t).catch(() => {
826
+ ), v = { chat: s, scope: d, loaded: s.loadGroup(n).catch(() => {
652
827
  }), touchedAt: Date.now() };
653
- return f.set(t, u), c(t), a;
654
- }, x = async (t) => {
655
- var a;
656
- if (l.value = t, !t) return;
657
- const s = o(t);
658
- if (await ((a = f.get(t)) == null ? void 0 : a.loaded), s.talking.value) return;
659
- await h.refresh();
660
- const d = h.findResumableTask(t);
661
- d && l.value === t && s.resumeTask({ history_id: d.history_id, history_group_id: String(d.history_group), question: d.question });
662
- }, L = (t) => {
663
- const s = f.get(t);
664
- s && (s.chat.stopQuestion(!1), s.scope.stop(), f.delete(t), l.value === t && (l.value = ""));
665
- }, p = () => {
666
- [...f.keys()].forEach(L), h.stop();
667
- }, i = X(() => {
668
- var t;
669
- return l.value ? ((t = f.get(l.value)) == null ? void 0 : t.chat) ?? null : null;
828
+ return h.set(n, v), w(n), s;
829
+ }, R = async (n) => {
830
+ var s;
831
+ if (l.value = n, !n) return;
832
+ const f = u(n);
833
+ if (await ((s = h.get(n)) == null ? void 0 : s.loaded), f.talking.value) return;
834
+ await A.refresh();
835
+ const d = A.findResumableTask(n);
836
+ d && l.value === n && f.resumeTask({ history_id: d.history_id, history_group_id: String(d.history_group), question: d.question });
837
+ }, x = (n) => {
838
+ const f = h.get(n);
839
+ f && (f.chat.stopQuestion(!1), f.scope.stop(), h.delete(n), l.value === n && (l.value = ""));
840
+ }, m = () => {
841
+ [...h.keys()].forEach(x), A.stop();
842
+ }, c = de(() => {
843
+ var n;
844
+ return l.value ? ((n = h.get(l.value)) == null ? void 0 : n.chat) ?? null : null;
670
845
  });
671
- return pe() && me(p), { activeId: l, active: i, running: h, getRoom: o, open: x, dispose: L, disposeAll: p };
672
- }, ft = (e) => {
846
+ return Ue() && Me(m), { activeId: l, active: c, running: A, getRoom: u, open: R, dispose: x, disposeAll: m };
847
+ }, _t = (e) => {
673
848
  if (!e || typeof localStorage > "u") return {};
674
849
  try {
675
- const r = JSON.parse(localStorage.getItem(e) || "{}");
676
- return r && typeof r == "object" ? r : {};
850
+ const t = JSON.parse(localStorage.getItem(e) || "{}");
851
+ return t && typeof t == "object" ? t : {};
677
852
  } catch {
678
853
  return {};
679
854
  }
680
- }, dt = (e, r) => {
855
+ }, At = (e, t) => {
681
856
  if (!(!e || typeof localStorage > "u"))
682
857
  try {
683
- localStorage.setItem(e, JSON.stringify(r));
858
+ localStorage.setItem(e, JSON.stringify(t));
684
859
  } catch {
685
860
  }
686
- }, mt = (e) => {
687
- const r = e.storageKey === void 0 ? "wi-chat-room-llm" : e.storageKey, g = b([]), f = b(!1), l = b(ft(r)), h = X(() => new Set(g.value.flatMap((a) => (a.children ?? []).map((u) => u.id)))), c = (a) => {
688
- l.value = a, dt(r, a);
861
+ }, It = (e) => {
862
+ const t = e.storageKey === void 0 ? "wi-chat-room-llm" : e.storageKey, y = G([]), h = G(!1), l = G(_t(t)), A = de(() => new Set(y.value.flatMap((s) => (s.children ?? []).map((v) => v.id)))), w = (s) => {
863
+ l.value = s, At(t, s);
689
864
  };
690
- let o = null;
691
- const x = () => f.value ? Promise.resolve() : o || (o = (async () => {
692
- var a, u;
865
+ let u = null;
866
+ const R = () => h.value ? Promise.resolve() : u || (u = (async () => {
867
+ var s, v;
693
868
  try {
694
- const y = await ((u = (a = e.api).getLlmInfoList) == null ? void 0 : u.call(a));
695
- if (!y) return;
696
- const G = y.connections ?? [];
697
- g.value = (y.factorys ?? []).map((I) => ({
698
- id: I.factory_id,
699
- name: I.factory_title,
869
+ const p = await ((v = (s = e.api).getLlmInfoList) == null ? void 0 : v.call(s));
870
+ if (!p) return;
871
+ const I = p.connections ?? [];
872
+ y.value = (p.factorys ?? []).map((T) => ({
873
+ id: T.factory_id,
874
+ name: T.factory_title,
700
875
  type: "factory",
701
- children: G.filter((P) => P.factory_id === I.factory_id).map((P) => ({ id: P.connect_id, name: P.connect_title, type: "connection" }))
702
- })).filter((I) => I.children.length > 0), f.value = !0;
703
- const E = Object.entries(l.value).filter(([, I]) => h.value.has(I));
704
- E.length !== Object.keys(l.value).length && c(Object.fromEntries(E));
876
+ children: I.filter((C) => C.factory_id === T.factory_id).map((C) => ({ id: C.connect_id, name: C.connect_title, type: "connection" }))
877
+ })).filter((T) => T.children.length > 0), h.value = !0;
878
+ const E = Object.entries(l.value).filter(([, T]) => A.value.has(T));
879
+ E.length !== Object.keys(l.value).length && w(Object.fromEntries(E));
705
880
  } catch {
706
881
  } finally {
707
- o = null;
708
- }
709
- })(), o), L = (a) => !!a && (!f.value || h.value.has(a));
710
- return { llmTree: g, loaded: f, roomLlmMap: l, validIds: h, load: x, resolve: (a, u) => {
711
- const y = a ? l.value[a] : "";
712
- return y && L(y) ? y : u || "";
713
- }, select: (a, u, y) => {
714
- if (!a) return;
715
- const G = { ...l.value };
716
- u && u !== y ? G[a] = u : delete G[a], c(G);
717
- }, migrate: (a, u) => {
718
- const y = l.value[a];
719
- if (!y || a === u) return;
720
- const G = { ...l.value, [u]: y };
721
- delete G[a], c(G);
722
- }, nameOf: (a) => {
723
- var u;
724
- if (!a) return "";
725
- for (const y of g.value) {
726
- const G = (u = y.children) == null ? void 0 : u.find((E) => E.id === a);
727
- if (G) return G.name;
882
+ u = null;
883
+ }
884
+ })(), u), x = (s) => !!s && (!h.value || A.value.has(s));
885
+ return { llmTree: y, loaded: h, roomLlmMap: l, validIds: A, load: R, resolve: (s, v) => {
886
+ const p = s ? l.value[s] : "";
887
+ return p && x(p) ? p : v || "";
888
+ }, select: (s, v, p) => {
889
+ if (!s) return;
890
+ const I = { ...l.value };
891
+ v && v !== p ? I[s] = v : delete I[s], w(I);
892
+ }, migrate: (s, v) => {
893
+ const p = l.value[s];
894
+ if (!p || s === v) return;
895
+ const I = { ...l.value, [v]: p };
896
+ delete I[s], w(I);
897
+ }, nameOf: (s) => {
898
+ var v;
899
+ if (!s) return "";
900
+ for (const p of y.value) {
901
+ const I = (v = p.children) == null ? void 0 : v.find((E) => E.id === s);
902
+ if (I) return I.name;
728
903
  }
729
904
  return "";
730
- }, isUnavailable: (a) => !!a && f.value && !h.value.has(a) };
731
- }, he = async (e) => {
732
- var f;
733
- if (typeof navigator < "u" && ((f = navigator.clipboard) != null && f.writeText))
905
+ }, isUnavailable: (s) => !!s && h.value && !A.value.has(s) };
906
+ }, Ce = async (e) => {
907
+ var h;
908
+ if (typeof navigator < "u" && ((h = navigator.clipboard) != null && h.writeText))
734
909
  try {
735
910
  await navigator.clipboard.writeText(e);
736
911
  return;
737
912
  } catch {
738
913
  }
739
914
  if (typeof document > "u") throw new Error("当前环境不支持剪贴板");
740
- const r = document.createElement("textarea");
741
- r.value = e, r.style.position = "fixed", r.style.opacity = "0", document.body.appendChild(r), r.select();
742
- const g = document.execCommand("copy");
743
- if (document.body.removeChild(r), !g) throw new Error("复制失败");
744
- }, St = (e) => {
745
- const { api: r, buildShareUrl: g, shareDays: f = 1 } = e, l = (i) => !!ye(i.answer), h = async (i, t = !1) => {
746
- const s = ye(i.answer);
747
- if (!s) return !1;
915
+ const t = document.createElement("textarea");
916
+ t.value = e, t.style.position = "fixed", t.style.opacity = "0", document.body.appendChild(t), t.select();
917
+ const y = document.execCommand("copy");
918
+ if (document.body.removeChild(t), !y) throw new Error("复制失败");
919
+ }, Ct = (e) => {
920
+ const { api: t, buildShareUrl: y, shareDays: h = 1 } = e, l = (c) => !!Ge(c.answer), A = async (c, n = !1) => {
921
+ const f = Ge(c.answer);
922
+ if (!f) return !1;
748
923
  try {
749
- return await he(t ? s : Ze(s)), !0;
924
+ return await Ce(n ? f : tt(f)), !0;
750
925
  } catch {
751
926
  return !1;
752
927
  }
753
- }, c = (i) => Ae(i.answer).state, o = /* @__PURE__ */ new WeakSet();
754
- return { canCopy: l, copy: h, stateOf: c, toggleState: async (i, t) => {
755
- if (!(!i.historyId || !r.setHistoryAnswerState || o.has(i))) {
756
- o.add(i);
928
+ }, w = (c) => Ke(c.answer).state, u = /* @__PURE__ */ new WeakSet();
929
+ return { canCopy: l, copy: A, stateOf: w, toggleState: async (c, n) => {
930
+ if (!(!c.historyId || !t.setHistoryAnswerState || u.has(c))) {
931
+ u.add(c);
757
932
  try {
758
- const s = c(i) === t ? null : t;
759
- await r.setHistoryAnswerState(i.historyId, s), i.answer.answer || (i.answer.answer = { reports: [] }), i.answer.answer.state = s;
933
+ const f = w(c) === n ? null : n;
934
+ await t.setHistoryAnswerState(c.historyId, f), c.answer.answer || (c.answer.answer = { reports: [] }), c.answer.answer.state = f;
760
935
  } finally {
761
- o.delete(i);
936
+ u.delete(c);
762
937
  }
763
938
  }
764
- }, feedback: async (i, t) => {
765
- !i.historyId || !t.trim() || !r.reportHistoryProblem || await r.reportHistoryProblem(i.historyId, t.trim());
766
- }, share: async (i) => {
767
- if (!i.historyId || !r.shareChatHistory) throw new Error("当前回答暂不支持分享");
768
- const t = await r.shareChatHistory([i.historyId], f), s = g(t);
769
- return await he(s), s;
939
+ }, feedback: async (c, n) => {
940
+ !c.historyId || !n.trim() || !t.reportHistoryProblem || await t.reportHistoryProblem(c.historyId, n.trim());
941
+ }, share: async (c) => {
942
+ if (!c.historyId || !t.shareChatHistory) throw new Error("当前回答暂不支持分享");
943
+ const n = await t.shareChatHistory([c.historyId], h), f = y(n);
944
+ return await Ce(f), f;
770
945
  } };
771
- }, At = (e = {}) => {
772
- const r = e.parsers ?? [];
773
- let g = null, f;
774
- const l = Le({
946
+ }, Et = (e = {}) => {
947
+ const t = e.parsers ?? [];
948
+ let y = null, h;
949
+ const l = Fe({
775
950
  ...e.chat,
776
- parsers: r,
777
- onFirstQuestion: ({ question: t, groupId: s }) => {
778
- f == null || f(s, t);
951
+ parsers: t,
952
+ onFirstQuestion: ({ question: n, groupId: f }) => {
953
+ h == null || h(f, n);
779
954
  }
780
- }), h = it({
955
+ }), A = pt({
781
956
  ...e.history,
782
957
  api: l.api,
783
958
  autoLoadMessages: !1,
784
- parsers: r
959
+ parsers: t
785
960
  });
786
- f = (t, s) => {
787
- g = h.renameGroup(t, s).catch((d) => {
788
- var a;
789
- (a = e.onError) == null || a.call(e, d, "groups");
961
+ h = (n, f) => {
962
+ y = A.renameGroup(n, f).catch((d) => {
963
+ var s;
964
+ (s = e.onError) == null || s.call(e, d, "groups");
790
965
  });
791
966
  };
792
- const c = ut({
967
+ const w = mt({
793
968
  ...e.agent,
794
969
  api: l.api,
795
970
  autoLoad: !1
796
- }), o = (t, s) => {
971
+ }), u = (n, f) => {
797
972
  var d;
798
- (d = e.onError) == null || d.call(e, t, s);
799
- }, x = async () => {
973
+ (d = e.onError) == null || d.call(e, n, f);
974
+ }, R = async () => {
800
975
  try {
801
- await h.loadGroups();
802
- } catch (t) {
803
- o(t, "groups");
976
+ await A.loadGroups();
977
+ } catch (n) {
978
+ u(n, "groups");
804
979
  }
805
- }, L = async (t) => {
980
+ }, x = async (n) => {
806
981
  try {
807
- await l.loadGroup(t);
808
- } catch (s) {
809
- o(s, "messages");
982
+ await l.loadGroup(n);
983
+ } catch (f) {
984
+ u(f, "messages");
810
985
  }
811
- }, p = async () => {
986
+ }, m = async () => {
812
987
  try {
813
- await c.loadAgents();
814
- } catch (t) {
815
- o(t, "agents");
988
+ await w.loadAgents();
989
+ } catch (n) {
990
+ u(n, "agents");
816
991
  }
817
- }, i = async (t) => {
818
- var a;
819
- const s = typeof t == "string" ? { text: t } : t;
992
+ }, c = async (n) => {
993
+ var s;
994
+ const f = typeof n == "string" ? { text: n } : n;
820
995
  await l.submitQuestion({
821
- ...s,
822
- entryId: (s == null ? void 0 : s.entryId) ?? ((a = c.currentAgent.value) == null ? void 0 : a.entry_id)
996
+ ...f,
997
+ entryId: (f == null ? void 0 : f.entryId) ?? ((s = w.currentAgent.value) == null ? void 0 : s.entry_id)
823
998
  });
824
- const d = g;
825
- g = null, d && await d, await x();
999
+ const d = y;
1000
+ y = null, d && await d, await R();
826
1001
  };
827
- return ue(l.session, (t) => {
828
- t && (x(), p());
829
- }), ue(h.activeGroupId, (t) => {
830
- t && L(t);
1002
+ return ke(l.session, (n) => {
1003
+ n && (R(), m());
1004
+ }), ke(A.activeGroupId, (n) => {
1005
+ n && x(n);
831
1006
  }), {
832
1007
  chat: l,
833
- history: h,
834
- agent: c,
835
- parsers: r,
1008
+ history: A,
1009
+ agent: w,
1010
+ parsers: t,
836
1011
  messages: l.messages,
837
1012
  question: l.question,
838
1013
  incPrevQuestion: l.incPrevQuestion,
839
1014
  talking: l.talking,
840
1015
  loading: l.loading,
841
1016
  session: l.session,
842
- groups: h.groups,
843
- activeGroupId: h.activeGroupId,
844
- historyLoading: h.loading,
845
- agentList: c.agentList,
846
- currentAgent: c.currentAgent,
847
- agentLoading: c.loading,
1017
+ groups: A.groups,
1018
+ activeGroupId: A.activeGroupId,
1019
+ historyLoading: A.loading,
1020
+ agentList: w.agentList,
1021
+ currentAgent: w.currentAgent,
1022
+ agentLoading: w.loading,
848
1023
  hasMore: l.hasMore,
849
1024
  loadMoreLoading: l.loadMoreLoading,
850
- loadGroup: L,
1025
+ loadGroup: x,
851
1026
  loadOlder: l.loadOlder,
852
- refreshGroups: x,
853
- loadAgents: p,
854
- selectAgent: c.selectAgent,
855
- getFileUrl: c.getFileUrl,
856
- submitQuestion: i,
1027
+ refreshGroups: R,
1028
+ loadAgents: m,
1029
+ selectAgent: w.selectAgent,
1030
+ getFileUrl: w.getFileUrl,
1031
+ submitQuestion: c,
857
1032
  sendWsMessage: l.sendWsMessage,
858
1033
  stopQuestion: l.stopQuestion
859
1034
  };
860
1035
  };
861
1036
  export {
862
- st as createLocalCredentialStore,
863
- be as createRenewer,
864
- ut as useAgent,
865
- St as useAnswerActions,
866
- Le as useChat,
867
- wt as useChatAuth,
868
- pt as useChatRooms,
869
- At as useChatSession,
870
- it as useHistory,
871
- nt as useKeepAlive,
872
- mt as useLlm,
873
- ct as useRunningGroups
1037
+ dt as createLocalCredentialStore,
1038
+ ft as createLocalKeyCredentialStore,
1039
+ ct as createRenewer,
1040
+ mt as useAgent,
1041
+ Ct as useAnswerActions,
1042
+ Fe as useChat,
1043
+ xt as useChatAuth,
1044
+ Gt as useChatRooms,
1045
+ Et as useChatSession,
1046
+ pt as useHistory,
1047
+ ot as useKeepAlive,
1048
+ It as useLlm,
1049
+ St as useRunningGroups
874
1050
  };
875
1051
  //# sourceMappingURL=index.js.map