wi-chat 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,350 +4,369 @@ class lt extends Error {
4
4
  super(e), this.name = "AuthExpiredError";
5
5
  }
6
6
  }
7
- const Ie = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortError" || t.name === "CanceledError"), It = (t) => new URLSearchParams(
8
- Object.entries(t).reduce((e, [o, a]) => (e[o] = String(a), e), {})
9
- ), gt = {}, ge = (t) => {
10
- const { baseURL: e, getWisession: o, getSession: a, onAuthExpired: u } = t, s = e.replace(/\/$/, ""), i = a ?? o, _ = (p = !1) => {
11
- const w = {};
12
- p || (w["Content-Type"] = "application/x-www-form-urlencoded");
13
- const E = i == null ? void 0 : i();
14
- return E && (w.wisession = E), w;
15
- }, A = async (p, w) => {
16
- var L;
17
- const E = typeof FormData < "u" && w instanceof FormData, f = E ? w : It(w);
18
- let g;
7
+ const Te = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortError" || t.name === "CanceledError"), Tt = (t) => new URLSearchParams(
8
+ Object.entries(t).reduce((e, [a, i]) => (e[a] = String(i), e), {})
9
+ ), It = {}, Ie = (t) => {
10
+ const { baseURL: e, getWisession: a, getSession: i, onAuthExpired: y } = t, o = e.replace(/\/$/, ""), s = i ?? a, p = (w = !1) => {
11
+ const S = {};
12
+ w || (S["Content-Type"] = "application/x-www-form-urlencoded");
13
+ const l = s == null ? void 0 : s();
14
+ return l && (S.wisession = l), S;
15
+ }, C = async (w, S) => {
16
+ var n;
17
+ const l = typeof FormData < "u" && S instanceof FormData, L = l ? S : Tt(S);
18
+ let E;
19
19
  try {
20
- g = await ht.post(`${s}${p}`, f, {
21
- headers: _(E)
20
+ E = await ht.post(`${o}${w}`, L, {
21
+ headers: p(l)
22
22
  });
23
- } catch (n) {
24
- throw ((L = n == null ? void 0 : n.response) == null ? void 0 : L.status) === 401 ? new lt() : n;
23
+ } catch (u) {
24
+ throw ((n = u == null ? void 0 : u.response) == null ? void 0 : n.status) === 401 ? new lt() : u;
25
25
  }
26
- const y = g.data;
27
- if ((y == null ? void 0 : y.err_code) === "AUTH") throw new lt();
28
- if ((y == null ? void 0 : y.json_ok) === !1) throw new Error((y == null ? void 0 : y.json_msg) || (y == null ? void 0 : y.message) || (y == null ? void 0 : y.err_msg) || "请求失败");
29
- return y;
30
- };
31
- return {
32
- baseURL: s,
33
- getSession: i,
34
- post: async (p, w = gt) => {
35
- try {
36
- return await A(p, w);
37
- } catch (E) {
38
- if (!(E instanceof lt) || !u) throw E;
39
- let f = !1;
40
- try {
41
- f = await u();
42
- } catch {
43
- f = !1;
44
- }
45
- if (!f) throw E;
46
- return A(p, w);
47
- }
48
- },
49
- stream: async (p, w = gt, E) => {
50
- const f = typeof FormData < "u" && w instanceof FormData, g = f ? w : It(w);
51
- return (await ht.post(`${s}${p}`, g, {
52
- headers: _(f),
26
+ const h = E.data;
27
+ if ((h == null ? void 0 : h.err_code) === "AUTH" || (h == null ? void 0 : h.error_code) === "AUTH" || (h == null ? void 0 : h.err_no_login) === !0) throw new lt();
28
+ if ((h == null ? void 0 : h.json_ok) === !1) throw new Error((h == null ? void 0 : h.json_msg) || (h == null ? void 0 : h.message) || (h == null ? void 0 : h.err_msg) || "请求失败");
29
+ return h;
30
+ }, T = async (w) => {
31
+ if (!y) return !1;
32
+ try {
33
+ return await y({ rejectedSession: w });
34
+ } catch {
35
+ return !1;
36
+ }
37
+ }, H = async (w, S = It) => {
38
+ const l = (s == null ? void 0 : s()) ?? void 0;
39
+ try {
40
+ return await C(w, S);
41
+ } catch (L) {
42
+ if (!(L instanceof lt) || !(!!(s != null && s() && (s == null ? void 0 : s()) !== l) || await T(l))) throw L;
43
+ return C(w, S);
44
+ }
45
+ }, A = async (w, S = It, l, L = !1) => {
46
+ var u;
47
+ const E = typeof FormData < "u" && S instanceof FormData, h = E ? S : Tt(S);
48
+ let n;
49
+ try {
50
+ n = await ht.post(`${o}${w}`, h, {
51
+ headers: p(E),
53
52
  // 浏览器下 XHR 不支持流式读取(response.data 会变成整包 String),
54
53
  // 必须强制 fetch 适配器才能拿到 ReadableStream
55
54
  adapter: "fetch",
56
55
  responseType: "stream",
57
- signal: E
58
- })).data;
56
+ signal: l
57
+ });
58
+ } catch (P) {
59
+ if (((u = P == null ? void 0 : P.response) == null ? void 0 : u.status) !== 401 || L || !await T((s == null ? void 0 : s()) ?? void 0)) throw P;
60
+ return A(w, S, l, !0);
59
61
  }
62
+ return n.data;
60
63
  };
61
- }, re = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8Qa+e4QjNlfSR55RGHeltMDqYJR1UCCpWzqY0xV9rgcGKXB3PzvBwn5PUUzPehGHHDXrpU4/gmcDZCjJly9hoI9NPKtjhi3bRFV7aHX0B4ms0S2ImYKtdRR7uSQfJPQFwr6fVOCs2bcPcJMYmSuJZXRKO/Fr7ZD5Uhlkcg5KGzQIDAQAB", ne = async (t) => {
62
- const e = (await import("jsencrypt")).default, o = new e({});
63
- o.setPublicKey(re);
64
- const a = o.encrypt(t);
65
- if (a === !1) throw new Error("密码加密失败");
66
- return a;
67
- }, Le = async (t, e) => {
68
- const { user: o, pass: a, ...u } = e, s = {};
69
- Object.entries(u).forEach(([_, A]) => {
70
- A !== void 0 && (s[_] = A);
71
- }), s.user = o, s.pass = await ne(a);
72
- const i = await t.post("/login", s);
73
- if (!i.wisession) throw new Error("登录失败:未返回 wisession");
64
+ return {
65
+ baseURL: o,
66
+ getSession: s,
67
+ post: H,
68
+ stream: A
69
+ };
70
+ }, ne = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8Qa+e4QjNlfSR55RGHeltMDqYJR1UCCpWzqY0xV9rgcGKXB3PzvBwn5PUUzPehGHHDXrpU4/gmcDZCjJly9hoI9NPKtjhi3bRFV7aHX0B4ms0S2ImYKtdRR7uSQfJPQFwr6fVOCs2bcPcJMYmSuJZXRKO/Fr7ZD5Uhlkcg5KGzQIDAQAB", Dt = async (t) => {
71
+ const e = (await import("jsencrypt")).default, a = new e({});
72
+ a.setPublicKey(ne);
73
+ const i = a.encrypt(t);
74
+ if (i === !1) throw new Error("密码加密失败");
74
75
  return i;
76
+ }, Le = async (t, e) => {
77
+ const { user: a, pass: i, ...y } = e, o = {};
78
+ Object.entries(y).forEach(([p, C]) => {
79
+ C !== void 0 && (o[p] = C);
80
+ }), o.user = a, o.pass = await Dt(i);
81
+ const s = await t.post("/login", o);
82
+ if (!s.wisession) throw new Error("登录失败:未返回 wisession");
83
+ return s;
84
+ }, He = async (t, e) => await t.post("/make_encrypt_login_status", {
85
+ expire_time: await Dt(String(e))
86
+ }), $e = async (t, e) => {
87
+ const { encrypt_key: a, ...i } = e, y = {};
88
+ Object.entries(i).forEach(([s, p]) => {
89
+ p !== void 0 && (y[s] = p);
90
+ }), y.encrypt_key = a;
91
+ const o = await t.post("/login", y);
92
+ if (!o.wisession) throw new Error("登录失败:未返回 wisession");
93
+ return o;
75
94
  }, ft = async (t) => {
76
- const e = "name" in t && typeof t.name == "string" ? t.name : "", o = t.type || "";
95
+ const e = "name" in t && typeof t.name == "string" ? t.name : "", a = t.type || "";
77
96
  if (typeof FileReader < "u")
78
- return new Promise((a, u) => {
79
- const s = new FileReader();
80
- s.onload = () => {
81
- const i = String(s.result ?? "");
82
- a({
97
+ return new Promise((i, y) => {
98
+ const o = new FileReader();
99
+ o.onload = () => {
100
+ const s = String(o.result ?? "");
101
+ i({
83
102
  name: e,
84
- "content-type": o,
85
- data: i.split(",")[1] ?? i
103
+ "content-type": a,
104
+ data: s.split(",")[1] ?? s
86
105
  });
87
- }, s.onerror = () => u(s.error), s.readAsDataURL(t);
106
+ }, o.onerror = () => y(o.error), o.readAsDataURL(t);
88
107
  });
89
108
  if (typeof t.arrayBuffer == "function") {
90
- const a = await t.arrayBuffer(), u = typeof Buffer < "u" ? Buffer.from(a).toString("base64") : btoa(String.fromCharCode(...new Uint8Array(a)));
109
+ const i = await t.arrayBuffer(), y = typeof Buffer < "u" ? Buffer.from(i).toString("base64") : btoa(String.fromCharCode(...new Uint8Array(i)));
91
110
  return {
92
111
  name: e,
93
- "content-type": o,
94
- data: u
112
+ "content-type": a,
113
+ data: y
95
114
  };
96
115
  }
97
116
  return {
98
117
  name: e,
99
- "content-type": o,
118
+ "content-type": a,
100
119
  data: ""
101
120
  };
102
- }, se = (t, e, o) => {
103
- Object.prototype.hasOwnProperty.call(t, e) ? t[e] = Array.isArray(t[e]) ? [...t[e], o] : [t[e], o] : t[e] = o;
104
- }, Dt = async (t) => {
121
+ }, se = (t, e, a) => {
122
+ Object.prototype.hasOwnProperty.call(t, e) ? t[e] = Array.isArray(t[e]) ? [...t[e], a] : [t[e], a] : t[e] = a;
123
+ }, Pt = async (t) => {
105
124
  const e = {};
106
125
  if (typeof FormData < "u" && t instanceof FormData)
107
- for (const [o, a] of t.entries()) {
108
- const u = typeof Blob < "u" && a instanceof Blob ? await ft(a) : a;
109
- se(e, o, u);
126
+ for (const [a, i] of t.entries()) {
127
+ const y = typeof Blob < "u" && i instanceof Blob ? await ft(i) : i;
128
+ se(e, a, y);
110
129
  }
111
130
  else if (t && typeof t == "object")
112
- for (const [o, a] of Object.entries(t))
113
- typeof Blob < "u" && a instanceof Blob ? e[o] = await ft(a) : Array.isArray(a) ? e[o] = await Promise.all(
114
- a.map(
115
- async (u) => typeof Blob < "u" && u instanceof Blob ? await ft(u) : u
131
+ for (const [a, i] of Object.entries(t))
132
+ typeof Blob < "u" && i instanceof Blob ? e[a] = await ft(i) : Array.isArray(i) ? e[a] = await Promise.all(
133
+ i.map(
134
+ async (y) => typeof Blob < "u" && y instanceof Blob ? await ft(y) : y
116
135
  )
117
- ) : e[o] = a;
136
+ ) : e[a] = i;
118
137
  return e.files && !Array.isArray(e.files) && (e.files = [e.files]), e.type = "chat_stream", e;
119
138
  }, Mt = (t, e) => {
120
- const o = t ? t.endsWith("/") ? t : `${t}/` : "/", a = typeof window < "u" && window.location ? window.location.origin : "http://localhost", u = new URL("chat/ws", new URL(o, a));
121
- return u.protocol === "http:" ? u.protocol = "ws:" : u.protocol === "https:" ? u.protocol = "wss:" : typeof window < "u" && window.location ? u.protocol = window.location.protocol === "https:" ? "wss:" : "ws:" : u.protocol.startsWith("ws") || (u.protocol = "ws:"), e != null && u.searchParams.set("session_id", String(e)), u.toString();
122
- }, Pt = async (t) => typeof t == "string" ? t : typeof Blob < "u" && t instanceof Blob ? t.text() : t instanceof ArrayBuffer ? new TextDecoder().decode(t) : String(t ?? ""), Q = (t, e, o = 8e3) => {
139
+ const a = t ? t.endsWith("/") ? t : `${t}/` : "/", i = typeof window < "u" && window.location ? window.location.origin : "http://localhost", y = new URL("chat/ws", new URL(a, i));
140
+ return y.protocol === "http:" ? y.protocol = "ws:" : y.protocol === "https:" ? y.protocol = "wss:" : typeof window < "u" && window.location ? y.protocol = window.location.protocol === "https:" ? "wss:" : "ws:" : y.protocol.startsWith("ws") || (y.protocol = "ws:"), e != null && y.searchParams.set("session_id", String(e)), y.toString();
141
+ }, vt = async (t) => typeof t == "string" ? t : typeof Blob < "u" && t instanceof Blob ? t.text() : t instanceof ArrayBuffer ? new TextDecoder().decode(t) : String(t ?? ""), Q = (t, e, a = 8e3) => {
123
142
  if (t.readyState != null && t.readyState !== 1) return !1;
124
- const a = Math.max(o, 1), u = Math.ceil(e.length / a) || 1;
125
- for (let s = 0; s < u; s++) {
126
- const i = e.slice(s * a, (s + 1) * a), _ = s === u - 1 ? "E" : s === 0 ? "B" : "M";
127
- t.send(`${_}${i}`);
143
+ const i = Math.max(a, 1), y = Math.ceil(e.length / i) || 1;
144
+ for (let o = 0; o < y; o++) {
145
+ const s = e.slice(o * i, (o + 1) * i), p = o === y - 1 ? "E" : o === 0 ? "B" : "M";
146
+ t.send(`${p}${s}`);
128
147
  }
129
148
  return !0;
130
149
  }, oe = async (t) => {
131
150
  const {
132
151
  baseURL: e,
133
- data: o,
134
- sessionId: a,
135
- signal: u,
136
- chunkSize: s = 8e3,
137
- WebSocketClass: i = typeof WebSocket < "u" ? WebSocket : void 0,
138
- onOpen: _
152
+ data: a,
153
+ sessionId: i,
154
+ signal: y,
155
+ chunkSize: o = 8e3,
156
+ WebSocketClass: s = typeof WebSocket < "u" ? WebSocket : void 0,
157
+ onOpen: p
139
158
  } = t;
140
- if (!i)
159
+ if (!s)
141
160
  throw new Error("当前运行环境不支持 WebSocket");
142
- const A = await Dt(o), I = Mt(e, a), D = new TextEncoder();
161
+ const C = await Pt(a), T = Mt(e, i), H = new TextEncoder();
143
162
  return new ReadableStream({
144
- start(p) {
145
- let w = !1, E = !1;
146
- const f = new i(I), g = () => {
163
+ start(A) {
164
+ let w = !1, S = !1;
165
+ const l = new s(T), L = () => {
147
166
  if (!w) {
148
167
  w = !0;
149
168
  try {
150
- p.close();
169
+ A.close();
151
170
  } catch {
152
171
  }
153
172
  try {
154
- f.close();
173
+ l.close();
155
174
  } catch {
156
175
  }
157
176
  }
158
- }, y = (n) => {
177
+ }, E = (n) => {
159
178
  if (!w) {
160
179
  w = !0;
161
180
  try {
162
- p.error(n);
181
+ A.error(n);
163
182
  } catch {
164
183
  }
165
184
  try {
166
- f.close();
185
+ l.close();
167
186
  } catch {
168
187
  }
169
188
  }
170
189
  };
171
- f.onopen = () => {
190
+ l.onopen = () => {
172
191
  try {
173
- Q(f, JSON.stringify(A), s), _ == null || _((n, h) => w || f.readyState !== 1 ? !1 : Q(f, n, h ?? s));
192
+ Q(l, JSON.stringify(C), o), p == null || p((n, u) => w || l.readyState !== 1 ? !1 : Q(l, n, u ?? o));
174
193
  } catch (n) {
175
- y(n);
194
+ E(n);
176
195
  }
177
- }, f.onmessage = async (n) => {
196
+ }, l.onmessage = async (n) => {
178
197
  try {
179
- E = !0;
180
- const h = await Pt(n.data);
181
- if (!h) return;
182
- const j = D.encode(`data: ${h}
198
+ S = !0;
199
+ const u = await vt(n.data);
200
+ if (!u) return;
201
+ const P = H.encode(`data: ${u}
183
202
 
184
203
  `);
185
- p.enqueue(j);
204
+ A.enqueue(P);
186
205
  try {
187
- const G = JSON.parse(h);
188
- (G == null ? void 0 : G.mode) === "finish" && g();
206
+ const x = JSON.parse(u);
207
+ (x == null ? void 0 : x.mode) === "finish" && L();
189
208
  } catch {
190
209
  }
191
- } catch (h) {
192
- y(h);
210
+ } catch (u) {
211
+ E(u);
193
212
  }
194
- }, f.onclose = () => {
195
- if (!E) {
196
- y(new Error("WebSocket 连接已断开(未收到任何回答数据)"));
213
+ }, l.onclose = () => {
214
+ if (!S) {
215
+ E(new Error("WebSocket 连接已断开(未收到任何回答数据)"));
197
216
  return;
198
217
  }
199
- g();
200
- }, f.onerror = (n) => {
201
- y(n);
218
+ L();
219
+ }, l.onerror = (n) => {
220
+ E(n);
202
221
  };
203
- const L = () => {
204
- const n = u == null ? void 0 : u.reason, h = n instanceof Error ? n : new DOMException(typeof n == "string" ? n : "The user aborted a request.", "AbortError");
205
- y(h);
222
+ const h = () => {
223
+ const n = y == null ? void 0 : y.reason, u = n instanceof Error ? n : new DOMException(typeof n == "string" ? n : "The user aborted a request.", "AbortError");
224
+ E(u);
206
225
  };
207
- u && (u.aborted ? L() : u.addEventListener("abort", L, { once: !0 }));
226
+ y && (y.aborted ? h() : y.addEventListener("abort", h, { once: !0 }));
208
227
  }
209
228
  });
210
- }, vt = 8e3, ae = 6, ie = 1e3, ce = 15e3, ue = 25e3, de = "PING", ye = 6, le = 6, fe = 2e3, he = "user not login", pe = 1, _e = () => {
229
+ }, Ut = 8e3, ae = 6, ie = 1e3, ce = 15e3, ye = 25e3, ue = "PING", de = 6, le = 6, fe = 2e3, he = "user not login", pe = 1, _e = () => {
211
230
  const t = /* @__PURE__ */ new Map();
212
231
  let e = null;
213
232
  return {
214
233
  getActive: () => e,
215
- setActive(o) {
216
- e = o;
234
+ setActive(a) {
235
+ e = a;
217
236
  },
218
- get(o) {
219
- return o ? t.get(o) : void 0;
237
+ get(a) {
238
+ return a ? t.get(a) : void 0;
220
239
  },
221
- set(o, a) {
222
- o && t.set(o, a);
240
+ set(a, i) {
241
+ a && t.set(a, i);
223
242
  },
224
- removeGroup(o) {
225
- o && t.delete(o);
243
+ removeGroup(a) {
244
+ a && t.delete(a);
226
245
  },
227
- remove(o) {
228
- e === o && (e = null);
229
- for (const [a, u] of t)
230
- u === o && t.delete(a);
246
+ remove(a) {
247
+ e === a && (e = null);
248
+ for (const [i, y] of t)
249
+ y === a && t.delete(i);
231
250
  },
232
251
  entries() {
233
252
  return new Map(t);
234
253
  },
235
- hasActive(o) {
236
- var a;
237
- return o ? ((a = t.get(o)) == null ? void 0 : a.readyState) === 1 : !1;
238
- },
239
- sendStop(o, a) {
254
+ hasActive(a) {
240
255
  var i;
241
- const u = o != null ? String(o) : "", s = u ? t.get(u) : e;
242
- return !s || s.readyState !== 1 ? !1 : ((i = a == null ? void 0 : a.send) == null || i.call(a, "chat_stop", "STOP", { groupId: u || void 0 }), s.send("STOP"), !0);
256
+ return a ? ((i = t.get(a)) == null ? void 0 : i.readyState) === 1 : !1;
257
+ },
258
+ sendStop(a, i) {
259
+ var s;
260
+ const y = a != null ? String(a) : "", o = y ? t.get(y) : e;
261
+ return !o || o.readyState !== 1 ? !1 : ((s = i == null ? void 0 : i.send) == null || s.call(i, "chat_stop", "STOP", { groupId: y || void 0 }), o.send("STOP"), !0);
243
262
  },
244
263
  clear() {
245
264
  t.clear(), e = null;
246
265
  }
247
266
  };
248
267
  }, Nt = _e(), Lt = (t) => new Promise((e) => setTimeout(e, t)), we = (t) => {
249
- var a;
268
+ var i;
250
269
  const e = t == null ? void 0 : t.values;
251
270
  if (!e) return !1;
252
- const o = (a = e == null ? void 0 : e.answer) == null ? void 0 : a.reports;
253
- return !!(Array.isArray(o) && o.length > 0 || Array.isArray(e == null ? void 0 : e.conclusion) && e.conclusion.length > 0 || Array.isArray(e == null ? void 0 : e.context_history) && e.context_history.length > 0 || typeof (e == null ? void 0 : e.answer) == "string" && e.answer.trim());
271
+ const a = (i = e == null ? void 0 : e.answer) == null ? void 0 : i.reports;
272
+ return !!(Array.isArray(a) && a.length > 0 || Array.isArray(e == null ? void 0 : e.conclusion) && e.conclusion.length > 0 || Array.isArray(e == null ? void 0 : e.context_history) && e.context_history.length > 0 || typeof (e == null ? void 0 : e.answer) == "string" && e.answer.trim());
254
273
  }, Se = (t) => {
255
- var s, i;
256
- const e = (t == null ? void 0 : t.values) ?? {}, o = e.answer ?? {}, a = e.attach ?? {}, u = e.entry ?? {};
274
+ var o, s;
275
+ const e = (t == null ? void 0 : t.values) ?? {}, a = e.answer ?? {}, i = e.attach ?? {}, y = e.entry ?? {};
257
276
  return {
258
277
  answer_type: "report_list",
259
278
  question: e.question ?? "",
260
- reports: o.reports ?? [],
279
+ reports: a.reports ?? [],
261
280
  conclusion: e.conclusion ?? [],
262
281
  context_history: e.context_history ?? [],
263
- attach_tables: a.tables ?? [],
264
- attach_metrics: a.metrics ?? [],
265
- attach_files: a.files ?? [],
266
- isHaveNotify: o.is_have_notify ?? !1,
267
- err_code: ((s = e.err) == null ? void 0 : s.code) ?? null,
268
- json_msg: ((i = e.err) == null ? void 0 : i.msg) ?? null,
269
- entry_id: u.id ?? null,
270
- entry_title: u.title ?? null
282
+ attach_tables: i.tables ?? [],
283
+ attach_metrics: i.metrics ?? [],
284
+ attach_files: i.files ?? [],
285
+ isHaveNotify: a.is_have_notify ?? !1,
286
+ err_code: ((o = e.err) == null ? void 0 : o.code) ?? null,
287
+ json_msg: ((s = e.err) == null ? void 0 : s.msg) ?? null,
288
+ entry_id: y.id ?? null,
289
+ entry_title: y.title ?? null
271
290
  };
272
291
  }, me = (t) => (t == null ? void 0 : t.values) ?? {}, Ht = (t) => {
273
- var o, a, u, s;
292
+ var a, i, y, o;
274
293
  if (!t || typeof t != "object") return "";
275
294
  const e = [
276
295
  t.history_id,
277
296
  t.historyId,
278
- (o = t.value) == null ? void 0 : o.history_id,
279
- (a = t.value) == null ? void 0 : a.historyId,
280
- (u = t.values) == null ? void 0 : u.history_id,
281
- (s = t.values) == null ? void 0 : s.historyId
297
+ (a = t.value) == null ? void 0 : a.history_id,
298
+ (i = t.value) == null ? void 0 : i.historyId,
299
+ (y = t.values) == null ? void 0 : y.history_id,
300
+ (o = t.values) == null ? void 0 : o.historyId
282
301
  ];
283
- for (const i of e)
284
- if (typeof i == "string" && i) return i;
302
+ for (const s of e)
303
+ if (typeof s == "string" && s) return s;
285
304
  return t.mode === "history_id" && typeof t.value == "string" && t.value ? t.value : "";
286
- }, $t = (t, e, o, a = !1) => `CONNECT:${JSON.stringify({
305
+ }, $t = (t, e, a, i = !1) => `CONNECT:${JSON.stringify({
287
306
  history_id: t,
288
307
  local_sys_tool: e,
289
- start_history_index: o,
290
- force_connect: a
291
- })}`, He = (t, e = vt) => (o) => Q(t, typeof o == "string" ? o : JSON.stringify(o), e), Ut = (t) => {
308
+ start_history_index: a,
309
+ force_connect: i
310
+ })}`, De = (t, e = Ut) => (a) => Q(t, typeof a == "string" ? a : JSON.stringify(a), e), xt = (t) => {
292
311
  const e = [t, t == null ? void 0 : t.values];
293
- for (const o of e)
294
- if (Array.isArray(o)) return o;
312
+ for (const a of e)
313
+ if (Array.isArray(a)) return a;
295
314
  return [];
296
315
  }, Ee = (t) => ({
297
316
  getTaskList: () => t.getChatTaskList(),
298
- pickTaskList: Ut,
317
+ pickTaskList: xt,
299
318
  getHistoryAnswer: (e) => t.getHistoryAnswer(e),
300
319
  // wi-chat core 的 useChat 直接消费新版 values(history_answer 帧)
301
320
  answerFrameMode: "history_answer"
302
321
  }), Ae = async (t) => {
303
322
  const {
304
323
  baseURL: e,
305
- data: o,
306
- getSessionId: a,
307
- authErrorMessage: u = he,
308
- authRetryMax: s = pe,
309
- refreshSession: i,
310
- chunkSize: _ = vt,
311
- groupId: A,
312
- signal: I,
313
- WebSocketClass: D = typeof WebSocket < "u" ? WebSocket : void 0,
314
- socketProtocol: p,
324
+ data: a,
325
+ getSessionId: i,
326
+ authErrorMessage: y = he,
327
+ authRetryMax: o = pe,
328
+ refreshSession: s,
329
+ chunkSize: p = Ut,
330
+ groupId: C,
331
+ signal: T,
332
+ WebSocketClass: H = typeof WebSocket < "u" ? WebSocket : void 0,
333
+ socketProtocol: A,
315
334
  preparePayload: w,
316
- onChunk: E,
317
- onOpen: f,
318
- emitOpenOnReconnect: g = !1,
319
- resumeTask: y = null,
320
- forceConnect: L = !1,
335
+ onChunk: S,
336
+ onOpen: l,
337
+ emitOpenOnReconnect: L = !1,
338
+ resumeTask: E = null,
339
+ forceConnect: h = !1,
321
340
  logger: n = {},
322
- fallback: h,
323
- registry: j = Nt,
324
- maxReconnectAttempts: G = ae,
325
- reconnectBaseDelay: xt = ie,
326
- reconnectMaxDelay: Ft = ce,
327
- heartbeatInterval: rt = ue,
328
- heartbeatMessage: Ot = de
341
+ fallback: u,
342
+ registry: P = Nt,
343
+ maxReconnectAttempts: x = ae,
344
+ reconnectBaseDelay: Bt = ie,
345
+ reconnectMaxDelay: Ot = ce,
346
+ heartbeatInterval: rt = ye,
347
+ heartbeatMessage: Ft = ue
329
348
  } = t;
330
- if (!D)
349
+ if (!H)
331
350
  throw new Error("当前运行环境不支持 WebSocket");
332
- const U = await Dt(o);
333
- await (w == null ? void 0 : w(U));
334
- const Bt = () => {
335
- const Y = new URL(Mt(e, (a == null ? void 0 : a()) ?? null));
336
- return p && (Y.protocol = p), Y.toString();
337
- }, T = String(A || U.history_group_id || (y == null ? void 0 : y.history_group_id) || ""), pt = U.local_sys_tool === "true" || U.local_sys_tool === !0, Wt = (h == null ? void 0 : h.hasAnswerContent) ?? we, _t = (h == null ? void 0 : h.answerFrameMode) ?? "result", jt = (h == null ? void 0 : h.buildAnswerPayload) ?? (_t === "history_answer" ? me : Se), nt = (h == null ? void 0 : h.taskPollMax) ?? ye, st = (h == null ? void 0 : h.historyRetryMax) ?? le, wt = (h == null ? void 0 : h.intervalMs) ?? fe;
338
- return new Promise((Y, Gt) => {
339
- let C = !1, R = 0, K = 0, b = (y == null ? void 0 : y.history_id) || Ht(U), x = !1, P = 0, F = null, z = null;
351
+ const B = await Pt(a);
352
+ await (w == null ? void 0 : w(B));
353
+ const Wt = () => {
354
+ const K = new URL(Mt(e, (i == null ? void 0 : i()) ?? null));
355
+ return A && (K.protocol = A), K.toString();
356
+ }, I = String(C || B.history_group_id || (E == null ? void 0 : E.history_group_id) || ""), pt = B.local_sys_tool === "true" || B.local_sys_tool === !0, jt = (u == null ? void 0 : u.hasAnswerContent) ?? we, _t = (u == null ? void 0 : u.answerFrameMode) ?? "result", Rt = (u == null ? void 0 : u.buildAnswerPayload) ?? (_t === "history_answer" ? me : Se), nt = (u == null ? void 0 : u.taskPollMax) ?? de, st = (u == null ? void 0 : u.historyRetryMax) ?? le, wt = (u == null ? void 0 : u.intervalMs) ?? fe;
357
+ return new Promise((K, qt) => {
358
+ let b = !1, q = 0, Y = 0, g = (E == null ? void 0 : E.history_id) || Ht(B), O = !1, v = 0, F = null, z = null;
340
359
  const ot = /* @__PURE__ */ new Map(), St = /* @__PURE__ */ new Set();
341
- let q = 0, at = !!y, V = !1, it = !1, X = 0, m = null, O = null;
360
+ let k = 0, at = !!E, V = !1, it = !1, X = 0, m = null, W = null;
342
361
  const Z = () => {
343
362
  F != null && (clearTimeout(F), F = null);
344
363
  }, J = () => {
345
364
  z != null && (clearInterval(z), z = null);
346
- }, Rt = (r) => {
365
+ }, kt = (r) => {
347
366
  J(), !(!rt || rt <= 0) && (z = setInterval(() => {
348
- if (!(C || r !== m || r.readyState !== 1))
367
+ if (!(b || r !== m || r.readyState !== 1))
349
368
  try {
350
- r.send(Ot);
369
+ r.send(Ft);
351
370
  } catch {
352
371
  }
353
372
  }, rt));
@@ -359,7 +378,7 @@ const Ie = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortErro
359
378
  return (m == null ? void 0 : m.readyState) ?? 3;
360
379
  },
361
380
  get groupId() {
362
- return T;
381
+ return I;
363
382
  },
364
383
  send(r) {
365
384
  m && m.readyState === 1 && m.send(r);
@@ -370,11 +389,11 @@ const Ie = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortErro
370
389
  } catch {
371
390
  }
372
391
  }
373
- }, qt = () => (m == null ? void 0 : m.readyState) === 1, Jt = (r, c) => {
374
- var l;
375
- const d = Math.max(_, 1), S = Math.ceil(c.length / d) || 1;
376
- (l = n.send) == null || l.call(n, "chat_stream", c, { chunkSize: d, chunkCount: S }), Q(r, c, d);
377
- }, kt = (r) => {
392
+ }, Jt = () => (m == null ? void 0 : m.readyState) === 1, Gt = (r, c) => {
393
+ var f;
394
+ const d = Math.max(p, 1), _ = Math.ceil(c.length / d) || 1;
395
+ (f = n.send) == null || f.call(n, "chat_stream", c, { chunkSize: d, chunkCount: _ }), Q(r, c, d);
396
+ }, Qt = (r) => {
378
397
  try {
379
398
  const c = JSON.parse(r);
380
399
  if ((c == null ? void 0 : c.type) === "wait_reply" && c.reply_id != null) return String(c.reply_id);
@@ -382,113 +401,113 @@ const Ie = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortErro
382
401
  }
383
402
  return "";
384
403
  }, mt = (r, c) => {
385
- const d = kt(r);
404
+ const d = Qt(r);
386
405
  if (!d) return;
387
- const S = ot.get(d);
388
- if (S) {
389
- S.lastPayload = r, S.lastSentGeneration = c;
406
+ const _ = ot.get(d);
407
+ if (_) {
408
+ _.lastPayload = r, _.lastSentGeneration = c;
390
409
  return;
391
410
  }
392
411
  ot.set(d, { lastPayload: r, lastSentGeneration: c });
393
- }, ct = (r, c = _) => {
412
+ }, ct = (r, c = p) => {
394
413
  var d;
395
- if (qt() && m) {
396
- const S = Math.ceil(r.length / Math.max(c, 1)) || 1;
397
- (d = n.send) == null || d.call(n, "chat_stream", r, { chunkSize: Math.max(c, 1), chunkCount: S });
398
- const l = Q(m, r, c);
399
- return mt(r, q), l;
414
+ if (Jt() && m) {
415
+ const _ = Math.ceil(r.length / Math.max(c, 1)) || 1;
416
+ (d = n.send) == null || d.call(n, "chat_stream", r, { chunkSize: Math.max(c, 1), chunkCount: _ });
417
+ const f = Q(m, r, c);
418
+ return mt(r, k), f;
400
419
  }
401
420
  return mt(r, 0), !1;
402
- }, Qt = (r) => ct(typeof r == "string" ? r : JSON.stringify(r)), Yt = (r, c) => ct(r, c ?? _), B = () => ({
403
- sender: Qt,
421
+ }, Kt = (r) => ct(typeof r == "string" ? r : JSON.stringify(r)), Yt = (r, c) => ct(r, c ?? p), j = () => ({
422
+ sender: Kt,
404
423
  sendInChunks: Yt,
405
424
  session: tt,
406
- generation: q
407
- }), k = (r) => {
408
- var S;
425
+ generation: k
426
+ }), G = (r) => {
427
+ var _;
409
428
  if ((r == null ? void 0 : r.mode) !== "front_reply") {
410
- E(r, B());
429
+ S(r, j());
411
430
  return;
412
431
  }
413
432
  const c = (r == null ? void 0 : r.reply_id) != null ? String(r.reply_id) : "";
414
433
  if (!c) {
415
- E(r, B());
434
+ S(r, j());
416
435
  return;
417
436
  }
418
437
  const d = ot.get(c);
419
438
  if (d) {
420
- if (d.lastSentGeneration === q) return;
421
- (S = n.warn) == null || S.call(n, `[chat ws] front_reply(${c}) 被后端重放,补发最后一次 wait_reply 而不重复执行`), ct(d.lastPayload);
439
+ if (d.lastSentGeneration === k) return;
440
+ (_ = n.warn) == null || _.call(n, `[chat ws] front_reply(${c}) 被后端重放,补发最后一次 wait_reply 而不重复执行`), ct(d.lastPayload);
422
441
  return;
423
442
  }
424
- St.has(c) || (St.add(c), E(r, B()));
425
- }, Kt = async (r) => {
426
- var d, S, l, H, At, Ct, bt;
427
- if (C || V) return;
443
+ St.has(c) || (St.add(c), S(r, j()));
444
+ }, zt = async (r) => {
445
+ var d, _, f, $, At, Ct, bt;
446
+ if (b || V) return;
428
447
  V = !0, Z(), J();
429
448
  const c = typeof (r == null ? void 0 : r.value) == "string" ? r.value : String(((d = r == null ? void 0 : r.value) == null ? void 0 : d.value) ?? "");
430
- (S = n.warn) == null || S.call(
449
+ (_ = n.warn) == null || _.call(
431
450
  n,
432
- `[chat ws] 收到 disconnect(value=${c || "空"},groupId=${T},historyId=${b}),不再重连,改为轮询任务 + 历史回答兜底`
451
+ `[chat ws] 收到 disconnect(value=${c || "空"},groupId=${I},historyId=${g}),不再重连,改为轮询任务 + 历史回答兜底`
433
452
  );
434
453
  try {
435
- if (!b) {
436
- (l = n.warn) == null || l.call(n, `[chat ws] disconnect 兜底缺少 history_id,直接结束(groupId=${T})`), et({ mode: "finish", type: "json", value: {} });
454
+ if (!g) {
455
+ (f = n.warn) == null || f.call(n, `[chat ws] disconnect 兜底缺少 history_id,直接结束(groupId=${I})`), et({ mode: "finish", type: "json", value: {} });
437
456
  return;
438
457
  }
439
- let W = !1;
458
+ let R = !1;
440
459
  for (let N = 0; N < nt; N += 1) {
441
- if (C) return;
442
- const v = await h.getTaskList();
443
- if (v && v.json_ok !== !1) {
444
- const Tt = h.pickTaskList(v).filter(($) => {
445
- const ee = ($ == null ? void 0 : $.history_group) != null ? String($.history_group) : "";
446
- return (($ == null ? void 0 : $.history_id) != null ? String($.history_id) : "") === b || !!T && ee === T;
460
+ if (b) return;
461
+ const U = await u.getTaskList();
462
+ if (U && U.json_ok !== !1) {
463
+ const gt = u.pickTaskList(U).filter((D) => {
464
+ const re = (D == null ? void 0 : D.history_group) != null ? String(D.history_group) : "";
465
+ return ((D == null ? void 0 : D.history_id) != null ? String(D.history_id) : "") === g || !!I && re === I;
447
466
  });
448
- if (Tt.length === 0 || Tt.some(($) => ($ == null ? void 0 : $.is_stop) === !0)) {
449
- W = !0;
467
+ if (gt.length === 0 || gt.some((D) => (D == null ? void 0 : D.is_stop) === !0)) {
468
+ R = !0;
450
469
  break;
451
470
  }
452
471
  }
453
472
  N < nt - 1 && await Lt(wt);
454
473
  }
455
- if (C) return;
456
- W || (H = n.warn) == null || H.call(
474
+ if (b) return;
475
+ R || ($ = n.warn) == null || $.call(
457
476
  n,
458
- `[chat ws] disconnect 后任务 ${nt} 次轮询仍未收尾,继续尝试历史回答(historyId=${b})`
477
+ `[chat ws] disconnect 后任务 ${nt} 次轮询仍未收尾,继续尝试历史回答(historyId=${g})`
459
478
  );
460
479
  for (let N = 0; N < st; N += 1) {
461
- if (C) return;
462
- const v = await h.getHistoryAnswer(b);
463
- if (v != null && v.json_ok && Wt(v)) {
464
- k({ mode: "history_id", type: "json", value: { history_id: b } }), k({ mode: _t, type: "json", value: jt(v) });
465
- const yt = { mode: "finish", type: "json", value: { history_id: b } };
466
- k(yt), (At = n.info) == null || At.call(
480
+ if (b) return;
481
+ const U = await u.getHistoryAnswer(g);
482
+ if (U != null && U.json_ok && jt(U)) {
483
+ G({ mode: "history_id", type: "json", value: { history_id: g } }), G({ mode: _t, type: "json", value: Rt(U) });
484
+ const dt = { mode: "finish", type: "json", value: { history_id: g } };
485
+ G(dt), (At = n.info) == null || At.call(
467
486
  n,
468
- `[chat ws] disconnect 兜底成功,已回放历史回答(第 ${N + 1} 次,groupId=${T},historyId=${b})`
469
- ), et(yt);
487
+ `[chat ws] disconnect 兜底成功,已回放历史回答(第 ${N + 1} 次,groupId=${I},historyId=${g})`
488
+ ), et(dt);
470
489
  return;
471
490
  }
472
491
  N < st - 1 && await Lt(wt);
473
492
  }
474
- if (C) return;
493
+ if (b) return;
475
494
  (Ct = n.warn) == null || Ct.call(
476
495
  n,
477
- `[chat ws] disconnect 兜底重试 ${st} 次仍无历史回答,结束本次回答(groupId=${T},historyId=${b})`
496
+ `[chat ws] disconnect 兜底重试 ${st} 次仍无历史回答,结束本次回答(groupId=${I},historyId=${g})`
478
497
  ), M(new Error("任务已结束,但历史回答尚未就绪"));
479
- } catch (W) {
498
+ } catch (R) {
480
499
  (bt = n.warn) == null || bt.call(
481
500
  n,
482
- `[chat ws] disconnect 兜底异常,结束本次回答:${W instanceof Error ? W.message : String(W)}`
483
- ), C || M(new Error("连接已断开,收回回答失败,请稍后重试"));
501
+ `[chat ws] disconnect 兜底异常,结束本次回答:${R instanceof Error ? R.message : String(R)}`
502
+ ), b || M(new Error("连接已断开,收回回答失败,请稍后重试"));
484
503
  }
485
- }, zt = async () => {
504
+ }, Vt = async () => {
486
505
  var c, d;
487
- if (C || it) return;
488
- if (X >= s) {
506
+ if (b || it) return;
507
+ if (X >= o) {
489
508
  (c = n.warn) == null || c.call(
490
509
  n,
491
- `[chat ws] 会话失效重试 ${X} 次仍未恢复,结束本次回答(groupId=${T})`
510
+ `[chat ws] 会话失效重试 ${X} 次仍未恢复,结束本次回答(groupId=${I})`
492
511
  ), M(new Error("登录状态已失效,请重新登录"));
493
512
  return;
494
513
  }
@@ -500,232 +519,232 @@ const Ie = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortErro
500
519
  } catch {
501
520
  }
502
521
  try {
503
- if (await (i == null ? void 0 : i()) === !1) throw new Error("宿主未能刷新登录态");
504
- } catch (S) {
522
+ if (await (s == null ? void 0 : s()) === !1) throw new Error("宿主未能刷新登录态");
523
+ } catch (_) {
505
524
  (d = n.warn) == null || d.call(
506
525
  n,
507
- `[chat ws] 会话失效后刷新登录态失败,结束本次回答(groupId=${T}):${S instanceof Error ? S.message : String(S)}`
526
+ `[chat ws] 会话失效后刷新登录态失败,结束本次回答(groupId=${I}):${_ instanceof Error ? _.message : String(_)}`
508
527
  ), M(new Error("登录状态已失效,请重新登录"));
509
528
  return;
510
529
  }
511
- C || (it = !1, b || (x = !1), dt());
530
+ b || (it = !1, g || (O = !1), ut());
512
531
  }, Et = () => {
513
- Z(), J(), I && O && (I.removeEventListener("abort", O), O = null);
532
+ Z(), J(), T && W && (T.removeEventListener("abort", W), W = null);
514
533
  const r = m;
515
534
  m = null;
516
535
  try {
517
536
  r == null || r.close();
518
537
  } catch {
519
538
  }
520
- j.remove(tt);
539
+ P.remove(tt);
521
540
  }, et = (r) => {
522
- C || (C = !0, Et(), Y(r));
541
+ b || (b = !0, Et(), K(r));
523
542
  }, M = (r) => {
524
- C || (C = !0, Et(), Gt(r));
525
- }, ut = (r) => {
526
- var d, S, l;
527
- if (C || V || F != null) return;
528
- if (x && !b) {
543
+ b || (b = !0, Et(), qt(r));
544
+ }, yt = (r) => {
545
+ var d, _, f;
546
+ if (b || V || F != null) return;
547
+ if (O && !g) {
529
548
  (d = n.warn) == null || d.call(
530
549
  n,
531
- `[chat ws] 连接中断且尚未收到 history_id,无法 CONNECT 续传,结束本次回答(groupId=${T},已收 ${R} 帧)`
550
+ `[chat ws] 连接中断且尚未收到 history_id,无法 CONNECT 续传,结束本次回答(groupId=${I},已收 ${q} 帧)`
532
551
  ), M(new Error("WebSocket 连接已断开:尚未收到 history_id,无法续传"));
533
552
  return;
534
553
  }
535
- if (P >= G) {
536
- (S = n.warn) == null || S.call(n, `[chat ws] 重连 ${P} 次仍失败,结束本次回答(groupId=${T})`);
537
- const H = r instanceof Error ? r : new Error(`WebSocket 连接已断开(重连 ${P} 次仍失败)`);
538
- M(H);
554
+ if (v >= x) {
555
+ (_ = n.warn) == null || _.call(n, `[chat ws] 重连 ${v} 次仍失败,结束本次回答(groupId=${I})`);
556
+ const $ = r instanceof Error ? r : new Error(`WebSocket 连接已断开(重连 ${v} 次仍失败)`);
557
+ M($);
539
558
  return;
540
559
  }
541
- P += 1;
542
- const c = Math.min(xt * 2 ** (P - 1), Ft);
543
- (l = n.warn) == null || l.call(
560
+ v += 1;
561
+ const c = Math.min(Bt * 2 ** (v - 1), Ot);
562
+ (f = n.warn) == null || f.call(
544
563
  n,
545
- `[chat ws] 连接中断,${c}ms 后第 ${P} 次重连(groupId=${T},已收 ${R} 帧,续传序号 ${K})`
564
+ `[chat ws] 连接中断,${c}ms 后第 ${v} 次重连(groupId=${I},已收 ${q} 帧,续传序号 ${Y})`
546
565
  ), F = setTimeout(() => {
547
- if (F = null, !C)
566
+ if (F = null, !b)
548
567
  try {
549
- dt();
550
- } catch (H) {
551
- ut(H);
568
+ ut();
569
+ } catch ($) {
570
+ yt($);
552
571
  }
553
572
  }, c);
554
- }, dt = () => {
555
- if (C) return;
556
- const r = new D(Bt());
573
+ }, ut = () => {
574
+ if (b) return;
575
+ const r = new H(Wt());
557
576
  m = r, r.onopen = () => {
558
- Vt(r);
577
+ Xt(r);
559
578
  }, r.onmessage = (c) => {
560
- Xt(r, c);
561
- }, r.onclose = (c) => {
562
579
  Zt(r, c);
563
- }, r.onerror = (c) => {
580
+ }, r.onclose = (c) => {
564
581
  te(r, c);
582
+ }, r.onerror = (c) => {
583
+ ee(r, c);
565
584
  };
566
- }, Vt = (r) => {
567
- var S, l;
568
- if (C || r !== m) return;
569
- Z(), q += 1, Rt(r);
570
- const c = q === 1 || g;
571
- if (y && !x) {
572
- x = !0, P = 0;
573
- const H = $t(b, pt, 0, L === !0);
574
- (S = n.send) == null || S.call(n, "chat_connect", H, { historyId: b, startHistoryIndex: 0, resume: !0 }), at = !0, r.send(H), c && (f == null || f(B()));
585
+ }, Xt = (r) => {
586
+ var _, f;
587
+ if (b || r !== m) return;
588
+ Z(), k += 1, kt(r);
589
+ const c = k === 1 || L;
590
+ if (E && !O) {
591
+ O = !0, v = 0;
592
+ const $ = $t(g, pt, 0, h === !0);
593
+ (_ = n.send) == null || _.call(n, "chat_connect", $, { historyId: g, startHistoryIndex: 0, resume: !0 }), at = !0, r.send($), c && (l == null || l(j()));
575
594
  return;
576
595
  }
577
- if (!x) {
578
- x = !0, P = 0, Jt(r, JSON.stringify(U)), c && (f == null || f(B()));
596
+ if (!O) {
597
+ O = !0, v = 0, Gt(r, JSON.stringify(B)), c && (l == null || l(j()));
579
598
  return;
580
599
  }
581
- if (!b) {
600
+ if (!g) {
582
601
  M(new Error("WebSocket 重连失败:缺少 history_id,无法续传"));
583
602
  return;
584
603
  }
585
- const d = $t(b, pt, K, L === !0);
586
- (l = n.send) == null || l.call(n, "chat_connect", d, {
587
- historyId: b,
588
- startHistoryIndex: K,
589
- forceConnect: L === !0
590
- }), at = !0, r.send(d), c && (f == null || f(B()));
591
- }, Xt = async (r, c) => {
604
+ const d = $t(g, pt, Y, h === !0);
605
+ (f = n.send) == null || f.call(n, "chat_connect", d, {
606
+ historyId: g,
607
+ startHistoryIndex: Y,
608
+ forceConnect: h === !0
609
+ }), at = !0, r.send(d), c && (l == null || l(j()));
610
+ }, Zt = async (r, c) => {
592
611
  if (r === m)
593
612
  try {
594
- const d = await Pt(c.data);
595
- if (C || r !== m) return;
596
- const S = d == null ? void 0 : d.trim();
597
- if (!S) return;
598
- let l;
613
+ const d = await vt(c.data);
614
+ if (b || r !== m) return;
615
+ const _ = d == null ? void 0 : d.trim();
616
+ if (!_) return;
617
+ let f;
599
618
  try {
600
- l = JSON.parse(S);
619
+ f = JSON.parse(_);
601
620
  } catch {
602
621
  return;
603
622
  }
604
- if (R += 1, (l == null ? void 0 : l.type) === "error" && String((l == null ? void 0 : l.value) ?? "") === u) {
605
- zt();
623
+ if (q += 1, (f == null ? void 0 : f.type) === "error" && String((f == null ? void 0 : f.value) ?? "") === y) {
624
+ Vt();
606
625
  return;
607
626
  }
608
- if ((l == null ? void 0 : l.mode) === "disconnect" && at) {
609
- if (h) {
610
- Kt(l);
627
+ if ((f == null ? void 0 : f.mode) === "disconnect" && at) {
628
+ if (u) {
629
+ zt(f);
611
630
  return;
612
631
  }
613
- k(l), et(l);
632
+ G(f), et(f);
614
633
  return;
615
634
  }
616
- P = 0, X = 0;
617
- const H = Ht(l);
618
- H && (b = H), (l == null ? void 0 : l.mode) !== "front_reply" && (K += 1), k(l), (l == null ? void 0 : l.mode) === "finish" && et(l);
635
+ v = 0, X = 0;
636
+ const $ = Ht(f);
637
+ $ && (g = $), (f == null ? void 0 : f.mode) !== "front_reply" && (Y += 1), G(f), (f == null ? void 0 : f.mode) === "finish" && et(f);
619
638
  } catch (d) {
620
639
  M(d);
621
640
  }
622
- }, Zt = (r, c) => {
641
+ }, te = (r, c) => {
623
642
  var d;
624
- C || V || r === m && (J(), (d = n.close) == null || d.call(n, {
625
- groupId: T,
643
+ b || V || r === m && (J(), (d = n.close) == null || d.call(n, {
644
+ groupId: I,
626
645
  code: c == null ? void 0 : c.code,
627
646
  reason: c == null ? void 0 : c.reason,
628
647
  wasClean: c == null ? void 0 : c.wasClean,
629
- receivedChunks: R
630
- }), ut(c));
631
- }, te = (r, c) => {
648
+ receivedChunks: q
649
+ }), yt(c));
650
+ }, ee = (r, c) => {
632
651
  var d;
633
- C || r === m && ((d = n.error) == null || d.call(n, {
634
- groupId: T,
652
+ b || r === m && ((d = n.error) == null || d.call(n, {
653
+ groupId: I,
635
654
  type: c == null ? void 0 : c.type,
636
655
  readyState: r == null ? void 0 : r.readyState,
637
- receivedChunks: R
638
- }), r.readyState === 3 && ut(c));
656
+ receivedChunks: q
657
+ }), r.readyState === 3 && yt(c));
639
658
  };
640
- if (j.setActive(tt), T && j.set(T, tt), I) {
641
- if (O = () => M(I.reason ?? new Error("会话已取消")), I.aborted) {
642
- O();
659
+ if (P.setActive(tt), I && P.set(I, tt), T) {
660
+ if (W = () => M(T.reason ?? new Error("会话已取消")), T.aborted) {
661
+ W();
643
662
  return;
644
663
  }
645
- I.addEventListener("abort", O, { once: !0 });
664
+ T.addEventListener("abort", W, { once: !0 });
646
665
  }
647
666
  try {
648
- dt();
667
+ ut();
649
668
  } catch (r) {
650
669
  M(r);
651
670
  }
652
671
  });
653
672
  }, Ce = async (t) => {
654
- const { sessionId: e, getSessionId: o, onOpen: a, ...u } = t, s = new TextEncoder();
655
- let i = null, _ = !1;
656
- const A = () => {
657
- if (!_) {
658
- _ = !0;
673
+ const { sessionId: e, getSessionId: a, onOpen: i, ...y } = t, o = new TextEncoder();
674
+ let s = null, p = !1;
675
+ const C = () => {
676
+ if (!p) {
677
+ p = !0;
659
678
  try {
660
- i == null || i.close();
679
+ s == null || s.close();
661
680
  } catch {
662
681
  }
663
682
  }
664
- }, I = (p) => {
665
- if (!_) {
666
- _ = !0;
683
+ }, T = (A) => {
684
+ if (!p) {
685
+ p = !0;
667
686
  try {
668
- i == null || i.error(p);
687
+ s == null || s.error(A);
669
688
  } catch {
670
689
  }
671
690
  }
672
- }, D = new ReadableStream({
673
- start(p) {
674
- i = p;
691
+ }, H = new ReadableStream({
692
+ start(A) {
693
+ s = A;
675
694
  }
676
695
  });
677
696
  return Ae({
678
- ...u,
679
- getSessionId: o ?? (() => e),
680
- onChunk: (p, w) => {
681
- var f;
682
- if (_) return;
683
- const E = typeof p == "string" ? p : JSON.stringify(p);
697
+ ...y,
698
+ getSessionId: a ?? (() => e),
699
+ onChunk: (A, w) => {
700
+ var l;
701
+ if (p) return;
702
+ const S = typeof A == "string" ? A : JSON.stringify(A);
684
703
  try {
685
- i == null || i.enqueue(s.encode(`data: ${E}
704
+ s == null || s.enqueue(o.encode(`data: ${S}
686
705
 
687
706
  `));
688
- } catch (g) {
689
- I(g);
707
+ } catch (L) {
708
+ T(L);
690
709
  return;
691
710
  }
692
- (f = u.onChunk) == null || f.call(u, p, w);
711
+ (l = y.onChunk) == null || l.call(y, A, w);
693
712
  },
694
- onOpen: (p) => {
695
- a == null || a(p.sendInChunks);
713
+ onOpen: (A) => {
714
+ i == null || i(A.sendInChunks);
696
715
  }
697
716
  }).then(() => {
698
- A();
699
- }).catch((p) => {
700
- I(p);
701
- }), D;
702
- }, $e = (t, e = {}) => {
703
- const o = (t.baseURL || "").replace(/\/$/, ""), a = e.registry ?? Nt, u = {
704
- getFileUrl(s) {
705
- return s ? s.startsWith("http://") || s.startsWith("https://") || s.startsWith("/") ? s : `${o}/algorithm/get_file_data?file_id=${s}` : "";
717
+ C();
718
+ }).catch((A) => {
719
+ T(A);
720
+ }), H;
721
+ }, Pe = (t, e = {}) => {
722
+ const a = (t.baseURL || "").replace(/\/$/, ""), i = e.registry ?? Nt, y = {
723
+ getFileUrl(o) {
724
+ return o ? o.startsWith("http://") || o.startsWith("https://") || o.startsWith("/") ? o : `${a}/algorithm/get_file_data?file_id=${o}` : "";
706
725
  },
707
726
  async getHistoryGroups() {
708
727
  return t.post("/history/get_history_groups", {});
709
728
  },
710
- async createHistoryGroup(s) {
711
- return t.post("/history/create_history_group", { group_title: s });
729
+ async createHistoryGroup(o) {
730
+ return t.post("/history/create_history_group", { group_title: o });
712
731
  },
713
- async deleteHistoryGroup(s) {
714
- return t.post("/history/delete_history_group", { history_group_id: s });
732
+ async deleteHistoryGroup(o) {
733
+ return t.post("/history/delete_history_group", { history_group_id: o });
715
734
  },
716
- async setHistoryGroupTitle(s, i) {
717
- return t.post("/history/set_history_group_title", { history_group_id: s, title: i });
735
+ async setHistoryGroupTitle(o, s) {
736
+ return t.post("/history/set_history_group_title", { history_group_id: o, title: s });
718
737
  },
719
- async getHistoryDetail(s, i = 0, _ = 10) {
720
- const A = await t.post("/history/query_history_detail", {
721
- history_group_id: s,
722
- last_end: i,
723
- last_count: _
738
+ async getHistoryDetail(o, s = 0, p = 10) {
739
+ const C = await t.post("/history/query_history_detail", {
740
+ history_group_id: o,
741
+ last_end: s,
742
+ last_count: p
724
743
  });
725
- return (A == null ? void 0 : A.details) || [];
744
+ return (C == null ? void 0 : C.details) || [];
726
745
  },
727
- async getHistoryAnswer(s) {
728
- return t.post("/history/get_history_answer", { history_id: s });
746
+ async getHistoryAnswer(o) {
747
+ return t.post("/history/get_history_answer", { history_id: o });
729
748
  },
730
749
  async getDefaultLlmId() {
731
750
  return t.post("/admin/get_default_llm_id", {});
@@ -733,80 +752,80 @@ const Ie = (t) => ht.isCancel(t) || t instanceof Error && (t.name === "AbortErro
733
752
  async getLlmInfoList() {
734
753
  return t.post("/admin/workflow/get_llm_info_list", {});
735
754
  },
736
- async getLlmEntryListByRole(s = { entry_group: "智能助手" }) {
737
- return t.post("/admin/get_llm_entry_list_by_role", s);
755
+ async getLlmEntryListByRole(o = { entry_group: "智能助手" }) {
756
+ return t.post("/admin/get_llm_entry_list_by_role", o);
738
757
  },
739
758
  async pingLogin() {
740
759
  return t.post("/system/ping", {});
741
760
  },
742
761
  async getChatTaskList() {
743
- const s = await t.post("/chat/getChatTaskList", {});
744
- return Ut(s);
762
+ const o = await t.post("/chat/getChatTaskList", {});
763
+ return xt(o);
745
764
  },
746
- async setHistoryAnswerState(s, i) {
747
- return t.post("/history/set_history_answer_state", { history_id: s, answer_state: i ?? "" });
765
+ async setHistoryAnswerState(o, s) {
766
+ return t.post("/history/set_history_answer_state", { history_id: o, answer_state: s ?? "" });
748
767
  },
749
- async reportHistoryProblem(s, i) {
750
- return t.post("/history/report_history_problem", { history_id: s, report_note: i });
768
+ async reportHistoryProblem(o, s) {
769
+ return t.post("/history/report_history_problem", { history_id: o, report_note: s });
751
770
  },
752
- async shareChatHistory(s, i = 1) {
753
- const _ = await t.post("/chat/share_chat_history", {
754
- history_ids: s.join(","),
755
- share_days: i
756
- }), A = _ != null && _.values ? Object.values(_.values)[0] : "";
757
- if (!A) throw new Error("生成分享链接失败");
758
- return String(A);
771
+ async shareChatHistory(o, s = 1) {
772
+ const p = await t.post("/chat/share_chat_history", {
773
+ history_ids: o.join(","),
774
+ share_days: s
775
+ }), C = p != null && p.values ? Object.values(p.values)[0] : "";
776
+ if (!C) throw new Error("生成分享链接失败");
777
+ return String(C);
759
778
  },
760
- async getShareChatJson(s) {
761
- const i = await t.post("/chat/get_share_chat_json", { share_id: s });
762
- return (i == null ? void 0 : i.values) ?? null;
779
+ async getShareChatJson(o) {
780
+ const s = await t.post("/chat/get_share_chat_json", { share_id: o });
781
+ return (s == null ? void 0 : s.values) ?? null;
763
782
  },
764
- async queryChatSql(s) {
765
- const i = await t.post("/chat/query_chat_sql", { ds_id: s.ds_id ?? "", sql: s.sql });
766
- return { columns: (i == null ? void 0 : i.columns) ?? [], values: (i == null ? void 0 : i.values) ?? [] };
783
+ async queryChatSql(o) {
784
+ const s = await t.post("/chat/query_chat_sql", { ds_id: o.ds_id ?? "", sql: o.sql });
785
+ return { columns: (s == null ? void 0 : s.columns) ?? [], values: (s == null ? void 0 : s.values) ?? [] };
767
786
  },
768
- async questionStream(s, i) {
769
- const { question: _, historyGroupId: A, entryId: I, files: D, incPrevQuestion: p, onOpen: w, resumeTask: E, ...f } = s, y = {
770
- question: _,
771
- history_group_id: A,
772
- entry_id: I ?? "",
773
- inc_prev_question: p ?? "Y",
774
- ...f
787
+ async questionStream(o, s) {
788
+ const { question: p, historyGroupId: C, entryId: T, files: H, incPrevQuestion: A, onOpen: w, resumeTask: S, ...l } = o, E = {
789
+ question: p,
790
+ history_group_id: C,
791
+ entry_id: T ?? "",
792
+ inc_prev_question: A ?? "Y",
793
+ ...l
775
794
  };
776
- D && D.length > 0 && (y.files = D);
777
- const L = () => {
795
+ H && H.length > 0 && (E.files = H);
796
+ const h = () => {
778
797
  var n;
779
798
  return ((n = t.getSession) == null ? void 0 : n.call(t)) ?? (typeof localStorage < "u" ? localStorage.getItem("access-session") : null);
780
799
  };
781
800
  return e.resumable ? Ce({
782
801
  baseURL: t.baseURL ?? "",
783
- data: y,
802
+ data: E,
784
803
  // 每次(重)连都实时取 session:会话失效刷新后重连要带新值
785
- getSessionId: L,
804
+ getSessionId: h,
786
805
  refreshSession: e.refreshSession,
787
- signal: i,
806
+ signal: s,
788
807
  onOpen: w,
789
- groupId: A,
790
- resumeTask: E ?? null,
791
- registry: a,
808
+ groupId: C,
809
+ resumeTask: S ?? null,
810
+ registry: i,
792
811
  fallback: Ee({
793
- getChatTaskList: () => u.getChatTaskList(),
794
- getHistoryAnswer: (n) => u.getHistoryAnswer(n)
812
+ getChatTaskList: () => y.getChatTaskList(),
813
+ getHistoryAnswer: (n) => y.getHistoryAnswer(n)
795
814
  })
796
815
  }) : oe({
797
816
  baseURL: t.baseURL,
798
- data: y,
799
- sessionId: L(),
800
- signal: i,
817
+ data: E,
818
+ sessionId: h(),
819
+ signal: s,
801
820
  // 传输层选项:连接就绪后向外部交出分片发送器(不混入发给后端的载荷)
802
821
  onOpen: w
803
822
  });
804
823
  },
805
- stopChat(s) {
806
- return e.resumable ? a.sendStop(s) : !1;
824
+ stopChat(o) {
825
+ return e.resumable ? i.sendStop(o) : !1;
807
826
  }
808
827
  };
809
- return u;
828
+ return y;
810
829
  };
811
830
  export {
812
831
  lt as AuthExpiredError,
@@ -814,23 +833,25 @@ export {
814
833
  $t as buildConnectFrame,
815
834
  me as buildHistoryAnswerValues,
816
835
  Nt as chatWsRegistry,
817
- $e as createChatApi,
836
+ Pe as createChatApi,
818
837
  Ee as createChatWsFallback,
819
838
  _e as createChatWsRegistry,
820
- He as createChunkSender,
821
- ge as createRequest,
839
+ De as createChunkSender,
840
+ Ie as createRequest,
822
841
  Se as defaultBuildHistoryAnswerPayload,
823
842
  we as defaultHasHistoryAnswerContent,
824
843
  ft as fileToBase64,
825
- Dt as formDataToJson,
826
- Ie as isCancelError,
844
+ Pt as formDataToJson,
845
+ Te as isCancelError,
827
846
  Le as login,
847
+ $e as loginByEncryptKey,
848
+ He as makeEncryptLoginStatus,
828
849
  oe as openChatWebSocketStream,
829
850
  Ce as openChatWsSessionStream,
830
- Ut as pickChatTaskList,
851
+ xt as pickChatTaskList,
831
852
  Ht as pickHistoryId,
832
- ne as pwdEncrypt,
833
- Pt as resolveMessageData,
853
+ Dt as pwdEncrypt,
854
+ vt as resolveMessageData,
834
855
  Q as sendPayloadInChunks,
835
856
  Ae as startChatWsSession
836
857
  };