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.
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +756 -580
- package/dist/core/useChatAuth.d.ts +91 -12
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +1 -1
- package/dist/request/client.d.ts +8 -2
- package/dist/request/index.cjs +3 -3
- package/dist/request/index.d.ts +2 -2
- package/dist/request/index.js +474 -453
- package/dist/request/login.d.ts +36 -0
- package/dist/web-ui/chat/ChatContainer.vue.d.ts +1 -1
- package/package.json +1 -1
package/dist/request/index.js
CHANGED
|
@@ -4,350 +4,369 @@ class lt extends Error {
|
|
|
4
4
|
super(e), this.name = "AuthExpiredError";
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
Object.entries(t).reduce((e, [
|
|
9
|
-
),
|
|
10
|
-
const { baseURL: e, getWisession:
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
return
|
|
15
|
-
},
|
|
16
|
-
var
|
|
17
|
-
const
|
|
18
|
-
let
|
|
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
|
-
|
|
21
|
-
headers:
|
|
20
|
+
E = await ht.post(`${o}${w}`, L, {
|
|
21
|
+
headers: p(l)
|
|
22
22
|
});
|
|
23
|
-
} catch (
|
|
24
|
-
throw ((
|
|
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
|
|
27
|
-
if ((
|
|
28
|
-
if ((
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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:
|
|
58
|
-
})
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 : "",
|
|
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((
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
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":
|
|
85
|
-
data:
|
|
103
|
+
"content-type": a,
|
|
104
|
+
data: s.split(",")[1] ?? s
|
|
86
105
|
});
|
|
87
|
-
},
|
|
106
|
+
}, o.onerror = () => y(o.error), o.readAsDataURL(t);
|
|
88
107
|
});
|
|
89
108
|
if (typeof t.arrayBuffer == "function") {
|
|
90
|
-
const
|
|
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":
|
|
94
|
-
data:
|
|
112
|
+
"content-type": a,
|
|
113
|
+
data: y
|
|
95
114
|
};
|
|
96
115
|
}
|
|
97
116
|
return {
|
|
98
117
|
name: e,
|
|
99
|
-
"content-type":
|
|
118
|
+
"content-type": a,
|
|
100
119
|
data: ""
|
|
101
120
|
};
|
|
102
|
-
}, se = (t, e,
|
|
103
|
-
Object.prototype.hasOwnProperty.call(t, e) ? t[e] = Array.isArray(t[e]) ? [...t[e],
|
|
104
|
-
},
|
|
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 [
|
|
108
|
-
const
|
|
109
|
-
se(e,
|
|
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 [
|
|
113
|
-
typeof Blob < "u" &&
|
|
114
|
-
|
|
115
|
-
async (
|
|
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[
|
|
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
|
|
121
|
-
return
|
|
122
|
-
},
|
|
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
|
|
125
|
-
for (let
|
|
126
|
-
const
|
|
127
|
-
t.send(`${
|
|
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:
|
|
134
|
-
sessionId:
|
|
135
|
-
signal:
|
|
136
|
-
chunkSize:
|
|
137
|
-
WebSocketClass:
|
|
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 (!
|
|
159
|
+
if (!s)
|
|
141
160
|
throw new Error("当前运行环境不支持 WebSocket");
|
|
142
|
-
const
|
|
161
|
+
const C = await Pt(a), T = Mt(e, i), H = new TextEncoder();
|
|
143
162
|
return new ReadableStream({
|
|
144
|
-
start(
|
|
145
|
-
let w = !1,
|
|
146
|
-
const
|
|
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
|
-
|
|
169
|
+
A.close();
|
|
151
170
|
} catch {
|
|
152
171
|
}
|
|
153
172
|
try {
|
|
154
|
-
|
|
173
|
+
l.close();
|
|
155
174
|
} catch {
|
|
156
175
|
}
|
|
157
176
|
}
|
|
158
|
-
},
|
|
177
|
+
}, E = (n) => {
|
|
159
178
|
if (!w) {
|
|
160
179
|
w = !0;
|
|
161
180
|
try {
|
|
162
|
-
|
|
181
|
+
A.error(n);
|
|
163
182
|
} catch {
|
|
164
183
|
}
|
|
165
184
|
try {
|
|
166
|
-
|
|
185
|
+
l.close();
|
|
167
186
|
} catch {
|
|
168
187
|
}
|
|
169
188
|
}
|
|
170
189
|
};
|
|
171
|
-
|
|
190
|
+
l.onopen = () => {
|
|
172
191
|
try {
|
|
173
|
-
Q(
|
|
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
|
-
|
|
194
|
+
E(n);
|
|
176
195
|
}
|
|
177
|
-
},
|
|
196
|
+
}, l.onmessage = async (n) => {
|
|
178
197
|
try {
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
if (!
|
|
182
|
-
const
|
|
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
|
-
|
|
204
|
+
A.enqueue(P);
|
|
186
205
|
try {
|
|
187
|
-
const
|
|
188
|
-
(
|
|
206
|
+
const x = JSON.parse(u);
|
|
207
|
+
(x == null ? void 0 : x.mode) === "finish" && L();
|
|
189
208
|
} catch {
|
|
190
209
|
}
|
|
191
|
-
} catch (
|
|
192
|
-
|
|
210
|
+
} catch (u) {
|
|
211
|
+
E(u);
|
|
193
212
|
}
|
|
194
|
-
},
|
|
195
|
-
if (!
|
|
196
|
-
|
|
213
|
+
}, l.onclose = () => {
|
|
214
|
+
if (!S) {
|
|
215
|
+
E(new Error("WebSocket 连接已断开(未收到任何回答数据)"));
|
|
197
216
|
return;
|
|
198
217
|
}
|
|
199
|
-
|
|
200
|
-
},
|
|
201
|
-
|
|
218
|
+
L();
|
|
219
|
+
}, l.onerror = (n) => {
|
|
220
|
+
E(n);
|
|
202
221
|
};
|
|
203
|
-
const
|
|
204
|
-
const n =
|
|
205
|
-
|
|
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
|
-
|
|
226
|
+
y && (y.aborted ? h() : y.addEventListener("abort", h, { once: !0 }));
|
|
208
227
|
}
|
|
209
228
|
});
|
|
210
|
-
},
|
|
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(
|
|
216
|
-
e =
|
|
234
|
+
setActive(a) {
|
|
235
|
+
e = a;
|
|
217
236
|
},
|
|
218
|
-
get(
|
|
219
|
-
return
|
|
237
|
+
get(a) {
|
|
238
|
+
return a ? t.get(a) : void 0;
|
|
220
239
|
},
|
|
221
|
-
set(
|
|
222
|
-
|
|
240
|
+
set(a, i) {
|
|
241
|
+
a && t.set(a, i);
|
|
223
242
|
},
|
|
224
|
-
removeGroup(
|
|
225
|
-
|
|
243
|
+
removeGroup(a) {
|
|
244
|
+
a && t.delete(a);
|
|
226
245
|
},
|
|
227
|
-
remove(
|
|
228
|
-
e ===
|
|
229
|
-
for (const [
|
|
230
|
-
|
|
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(
|
|
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
|
-
|
|
242
|
-
|
|
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
|
|
268
|
+
var i;
|
|
250
269
|
const e = t == null ? void 0 : t.values;
|
|
251
270
|
if (!e) return !1;
|
|
252
|
-
const
|
|
253
|
-
return !!(Array.isArray(
|
|
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
|
|
256
|
-
const e = (t == null ? void 0 : t.values) ?? {},
|
|
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:
|
|
279
|
+
reports: a.reports ?? [],
|
|
261
280
|
conclusion: e.conclusion ?? [],
|
|
262
281
|
context_history: e.context_history ?? [],
|
|
263
|
-
attach_tables:
|
|
264
|
-
attach_metrics:
|
|
265
|
-
attach_files:
|
|
266
|
-
isHaveNotify:
|
|
267
|
-
err_code: ((
|
|
268
|
-
json_msg: ((
|
|
269
|
-
entry_id:
|
|
270
|
-
entry_title:
|
|
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
|
|
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
|
-
(
|
|
279
|
-
(
|
|
280
|
-
(
|
|
281
|
-
(
|
|
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
|
|
284
|
-
if (typeof
|
|
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,
|
|
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:
|
|
290
|
-
force_connect:
|
|
291
|
-
})}`,
|
|
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
|
|
294
|
-
if (Array.isArray(
|
|
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:
|
|
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:
|
|
306
|
-
getSessionId:
|
|
307
|
-
authErrorMessage:
|
|
308
|
-
authRetryMax:
|
|
309
|
-
refreshSession:
|
|
310
|
-
chunkSize:
|
|
311
|
-
groupId:
|
|
312
|
-
signal:
|
|
313
|
-
WebSocketClass:
|
|
314
|
-
socketProtocol:
|
|
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:
|
|
317
|
-
onOpen:
|
|
318
|
-
emitOpenOnReconnect:
|
|
319
|
-
resumeTask:
|
|
320
|
-
forceConnect:
|
|
335
|
+
onChunk: S,
|
|
336
|
+
onOpen: l,
|
|
337
|
+
emitOpenOnReconnect: L = !1,
|
|
338
|
+
resumeTask: E = null,
|
|
339
|
+
forceConnect: h = !1,
|
|
321
340
|
logger: n = {},
|
|
322
|
-
fallback:
|
|
323
|
-
registry:
|
|
324
|
-
maxReconnectAttempts:
|
|
325
|
-
reconnectBaseDelay:
|
|
326
|
-
reconnectMaxDelay:
|
|
327
|
-
heartbeatInterval: rt =
|
|
328
|
-
heartbeatMessage:
|
|
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 (!
|
|
349
|
+
if (!H)
|
|
331
350
|
throw new Error("当前运行环境不支持 WebSocket");
|
|
332
|
-
const
|
|
333
|
-
await (w == null ? void 0 : w(
|
|
334
|
-
const
|
|
335
|
-
const
|
|
336
|
-
return
|
|
337
|
-
},
|
|
338
|
-
return new Promise((
|
|
339
|
-
let
|
|
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
|
|
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
|
-
},
|
|
365
|
+
}, kt = (r) => {
|
|
347
366
|
J(), !(!rt || rt <= 0) && (z = setInterval(() => {
|
|
348
|
-
if (!(
|
|
367
|
+
if (!(b || r !== m || r.readyState !== 1))
|
|
349
368
|
try {
|
|
350
|
-
r.send(
|
|
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
|
|
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
|
-
},
|
|
374
|
-
var
|
|
375
|
-
const d = Math.max(
|
|
376
|
-
(
|
|
377
|
-
},
|
|
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 =
|
|
404
|
+
const d = Qt(r);
|
|
386
405
|
if (!d) return;
|
|
387
|
-
const
|
|
388
|
-
if (
|
|
389
|
-
|
|
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 (
|
|
396
|
-
const
|
|
397
|
-
(d = n.send) == null || d.call(n, "chat_stream", r, { chunkSize: Math.max(c, 1), chunkCount:
|
|
398
|
-
const
|
|
399
|
-
return mt(r,
|
|
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
|
-
},
|
|
403
|
-
sender:
|
|
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:
|
|
407
|
-
}),
|
|
408
|
-
var
|
|
425
|
+
generation: k
|
|
426
|
+
}), G = (r) => {
|
|
427
|
+
var _;
|
|
409
428
|
if ((r == null ? void 0 : r.mode) !== "front_reply") {
|
|
410
|
-
|
|
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
|
-
|
|
434
|
+
S(r, j());
|
|
416
435
|
return;
|
|
417
436
|
}
|
|
418
437
|
const d = ot.get(c);
|
|
419
438
|
if (d) {
|
|
420
|
-
if (d.lastSentGeneration ===
|
|
421
|
-
(
|
|
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),
|
|
425
|
-
},
|
|
426
|
-
var d,
|
|
427
|
-
if (
|
|
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
|
-
(
|
|
449
|
+
(_ = n.warn) == null || _.call(
|
|
431
450
|
n,
|
|
432
|
-
`[chat ws] 收到 disconnect(value=${c || "空"},groupId=${
|
|
451
|
+
`[chat ws] 收到 disconnect(value=${c || "空"},groupId=${I},historyId=${g}),不再重连,改为轮询任务 + 历史回答兜底`
|
|
433
452
|
);
|
|
434
453
|
try {
|
|
435
|
-
if (!
|
|
436
|
-
(
|
|
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
|
|
458
|
+
let R = !1;
|
|
440
459
|
for (let N = 0; N < nt; N += 1) {
|
|
441
|
-
if (
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
const
|
|
445
|
-
const
|
|
446
|
-
return ((
|
|
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 (
|
|
449
|
-
|
|
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 (
|
|
456
|
-
|
|
474
|
+
if (b) return;
|
|
475
|
+
R || ($ = n.warn) == null || $.call(
|
|
457
476
|
n,
|
|
458
|
-
`[chat ws] disconnect 后任务 ${nt} 次轮询仍未收尾,继续尝试历史回答(historyId=${
|
|
477
|
+
`[chat ws] disconnect 后任务 ${nt} 次轮询仍未收尾,继续尝试历史回答(historyId=${g})`
|
|
459
478
|
);
|
|
460
479
|
for (let N = 0; N < st; N += 1) {
|
|
461
|
-
if (
|
|
462
|
-
const
|
|
463
|
-
if (
|
|
464
|
-
|
|
465
|
-
const
|
|
466
|
-
|
|
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=${
|
|
469
|
-
), et(
|
|
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 (
|
|
493
|
+
if (b) return;
|
|
475
494
|
(Ct = n.warn) == null || Ct.call(
|
|
476
495
|
n,
|
|
477
|
-
`[chat ws] disconnect 兜底重试 ${st} 次仍无历史回答,结束本次回答(groupId=${
|
|
496
|
+
`[chat ws] disconnect 兜底重试 ${st} 次仍无历史回答,结束本次回答(groupId=${I},historyId=${g})`
|
|
478
497
|
), M(new Error("任务已结束,但历史回答尚未就绪"));
|
|
479
|
-
} catch (
|
|
498
|
+
} catch (R) {
|
|
480
499
|
(bt = n.warn) == null || bt.call(
|
|
481
500
|
n,
|
|
482
|
-
`[chat ws] disconnect 兜底异常,结束本次回答:${
|
|
483
|
-
),
|
|
501
|
+
`[chat ws] disconnect 兜底异常,结束本次回答:${R instanceof Error ? R.message : String(R)}`
|
|
502
|
+
), b || M(new Error("连接已断开,收回回答失败,请稍后重试"));
|
|
484
503
|
}
|
|
485
|
-
},
|
|
504
|
+
}, Vt = async () => {
|
|
486
505
|
var c, d;
|
|
487
|
-
if (
|
|
488
|
-
if (X >=
|
|
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=${
|
|
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 (
|
|
504
|
-
} catch (
|
|
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=${
|
|
526
|
+
`[chat ws] 会话失效后刷新登录态失败,结束本次回答(groupId=${I}):${_ instanceof Error ? _.message : String(_)}`
|
|
508
527
|
), M(new Error("登录状态已失效,请重新登录"));
|
|
509
528
|
return;
|
|
510
529
|
}
|
|
511
|
-
|
|
530
|
+
b || (it = !1, g || (O = !1), ut());
|
|
512
531
|
}, Et = () => {
|
|
513
|
-
Z(), J(),
|
|
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
|
-
|
|
539
|
+
P.remove(tt);
|
|
521
540
|
}, et = (r) => {
|
|
522
|
-
|
|
541
|
+
b || (b = !0, Et(), K(r));
|
|
523
542
|
}, M = (r) => {
|
|
524
|
-
|
|
525
|
-
},
|
|
526
|
-
var d,
|
|
527
|
-
if (
|
|
528
|
-
if (
|
|
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=${
|
|
550
|
+
`[chat ws] 连接中断且尚未收到 history_id,无法 CONNECT 续传,结束本次回答(groupId=${I},已收 ${q} 帧)`
|
|
532
551
|
), M(new Error("WebSocket 连接已断开:尚未收到 history_id,无法续传"));
|
|
533
552
|
return;
|
|
534
553
|
}
|
|
535
|
-
if (
|
|
536
|
-
(
|
|
537
|
-
const
|
|
538
|
-
M(
|
|
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
|
-
|
|
542
|
-
const c = Math.min(
|
|
543
|
-
(
|
|
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 后第 ${
|
|
564
|
+
`[chat ws] 连接中断,${c}ms 后第 ${v} 次重连(groupId=${I},已收 ${q} 帧,续传序号 ${Y})`
|
|
546
565
|
), F = setTimeout(() => {
|
|
547
|
-
if (F = null, !
|
|
566
|
+
if (F = null, !b)
|
|
548
567
|
try {
|
|
549
|
-
|
|
550
|
-
} catch (
|
|
551
|
-
|
|
568
|
+
ut();
|
|
569
|
+
} catch ($) {
|
|
570
|
+
yt($);
|
|
552
571
|
}
|
|
553
572
|
}, c);
|
|
554
|
-
},
|
|
555
|
-
if (
|
|
556
|
-
const r = new
|
|
573
|
+
}, ut = () => {
|
|
574
|
+
if (b) return;
|
|
575
|
+
const r = new H(Wt());
|
|
557
576
|
m = r, r.onopen = () => {
|
|
558
|
-
|
|
577
|
+
Xt(r);
|
|
559
578
|
}, r.onmessage = (c) => {
|
|
560
|
-
Xt(r, c);
|
|
561
|
-
}, r.onclose = (c) => {
|
|
562
579
|
Zt(r, c);
|
|
563
|
-
}, r.
|
|
580
|
+
}, r.onclose = (c) => {
|
|
564
581
|
te(r, c);
|
|
582
|
+
}, r.onerror = (c) => {
|
|
583
|
+
ee(r, c);
|
|
565
584
|
};
|
|
566
|
-
},
|
|
567
|
-
var
|
|
568
|
-
if (
|
|
569
|
-
Z(),
|
|
570
|
-
const c =
|
|
571
|
-
if (
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
(
|
|
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 (!
|
|
578
|
-
|
|
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 (!
|
|
600
|
+
if (!g) {
|
|
582
601
|
M(new Error("WebSocket 重连失败:缺少 history_id,无法续传"));
|
|
583
602
|
return;
|
|
584
603
|
}
|
|
585
|
-
const d = $t(
|
|
586
|
-
(
|
|
587
|
-
historyId:
|
|
588
|
-
startHistoryIndex:
|
|
589
|
-
forceConnect:
|
|
590
|
-
}), at = !0, r.send(d), c && (
|
|
591
|
-
},
|
|
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
|
|
595
|
-
if (
|
|
596
|
-
const
|
|
597
|
-
if (!
|
|
598
|
-
let
|
|
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
|
-
|
|
619
|
+
f = JSON.parse(_);
|
|
601
620
|
} catch {
|
|
602
621
|
return;
|
|
603
622
|
}
|
|
604
|
-
if (
|
|
605
|
-
|
|
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 ((
|
|
609
|
-
if (
|
|
610
|
-
|
|
627
|
+
if ((f == null ? void 0 : f.mode) === "disconnect" && at) {
|
|
628
|
+
if (u) {
|
|
629
|
+
zt(f);
|
|
611
630
|
return;
|
|
612
631
|
}
|
|
613
|
-
|
|
632
|
+
G(f), et(f);
|
|
614
633
|
return;
|
|
615
634
|
}
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
|
|
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
|
-
},
|
|
641
|
+
}, te = (r, c) => {
|
|
623
642
|
var d;
|
|
624
|
-
|
|
625
|
-
groupId:
|
|
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:
|
|
630
|
-
}),
|
|
631
|
-
},
|
|
648
|
+
receivedChunks: q
|
|
649
|
+
}), yt(c));
|
|
650
|
+
}, ee = (r, c) => {
|
|
632
651
|
var d;
|
|
633
|
-
|
|
634
|
-
groupId:
|
|
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:
|
|
638
|
-
}), r.readyState === 3 &&
|
|
656
|
+
receivedChunks: q
|
|
657
|
+
}), r.readyState === 3 && yt(c));
|
|
639
658
|
};
|
|
640
|
-
if (
|
|
641
|
-
if (
|
|
642
|
-
|
|
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
|
-
|
|
664
|
+
T.addEventListener("abort", W, { once: !0 });
|
|
646
665
|
}
|
|
647
666
|
try {
|
|
648
|
-
|
|
667
|
+
ut();
|
|
649
668
|
} catch (r) {
|
|
650
669
|
M(r);
|
|
651
670
|
}
|
|
652
671
|
});
|
|
653
672
|
}, Ce = async (t) => {
|
|
654
|
-
const { sessionId: e, getSessionId:
|
|
655
|
-
let
|
|
656
|
-
const
|
|
657
|
-
if (!
|
|
658
|
-
|
|
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
|
-
|
|
679
|
+
s == null || s.close();
|
|
661
680
|
} catch {
|
|
662
681
|
}
|
|
663
682
|
}
|
|
664
|
-
},
|
|
665
|
-
if (!
|
|
666
|
-
|
|
683
|
+
}, T = (A) => {
|
|
684
|
+
if (!p) {
|
|
685
|
+
p = !0;
|
|
667
686
|
try {
|
|
668
|
-
|
|
687
|
+
s == null || s.error(A);
|
|
669
688
|
} catch {
|
|
670
689
|
}
|
|
671
690
|
}
|
|
672
|
-
},
|
|
673
|
-
start(
|
|
674
|
-
|
|
691
|
+
}, H = new ReadableStream({
|
|
692
|
+
start(A) {
|
|
693
|
+
s = A;
|
|
675
694
|
}
|
|
676
695
|
});
|
|
677
696
|
return Ae({
|
|
678
|
-
...
|
|
679
|
-
getSessionId:
|
|
680
|
-
onChunk: (
|
|
681
|
-
var
|
|
682
|
-
if (
|
|
683
|
-
const
|
|
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
|
-
|
|
704
|
+
s == null || s.enqueue(o.encode(`data: ${S}
|
|
686
705
|
|
|
687
706
|
`));
|
|
688
|
-
} catch (
|
|
689
|
-
|
|
707
|
+
} catch (L) {
|
|
708
|
+
T(L);
|
|
690
709
|
return;
|
|
691
710
|
}
|
|
692
|
-
(
|
|
711
|
+
(l = y.onChunk) == null || l.call(y, A, w);
|
|
693
712
|
},
|
|
694
|
-
onOpen: (
|
|
695
|
-
|
|
713
|
+
onOpen: (A) => {
|
|
714
|
+
i == null || i(A.sendInChunks);
|
|
696
715
|
}
|
|
697
716
|
}).then(() => {
|
|
698
|
-
|
|
699
|
-
}).catch((
|
|
700
|
-
|
|
701
|
-
}),
|
|
702
|
-
},
|
|
703
|
-
const
|
|
704
|
-
getFileUrl(
|
|
705
|
-
return
|
|
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(
|
|
711
|
-
return t.post("/history/create_history_group", { group_title:
|
|
729
|
+
async createHistoryGroup(o) {
|
|
730
|
+
return t.post("/history/create_history_group", { group_title: o });
|
|
712
731
|
},
|
|
713
|
-
async deleteHistoryGroup(
|
|
714
|
-
return t.post("/history/delete_history_group", { history_group_id:
|
|
732
|
+
async deleteHistoryGroup(o) {
|
|
733
|
+
return t.post("/history/delete_history_group", { history_group_id: o });
|
|
715
734
|
},
|
|
716
|
-
async setHistoryGroupTitle(
|
|
717
|
-
return t.post("/history/set_history_group_title", { history_group_id:
|
|
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(
|
|
720
|
-
const
|
|
721
|
-
history_group_id:
|
|
722
|
-
last_end:
|
|
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 (
|
|
744
|
+
return (C == null ? void 0 : C.details) || [];
|
|
726
745
|
},
|
|
727
|
-
async getHistoryAnswer(
|
|
728
|
-
return t.post("/history/get_history_answer", { history_id:
|
|
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(
|
|
737
|
-
return t.post("/admin/get_llm_entry_list_by_role",
|
|
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
|
|
744
|
-
return
|
|
762
|
+
const o = await t.post("/chat/getChatTaskList", {});
|
|
763
|
+
return xt(o);
|
|
745
764
|
},
|
|
746
|
-
async setHistoryAnswerState(
|
|
747
|
-
return t.post("/history/set_history_answer_state", { history_id:
|
|
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(
|
|
750
|
-
return t.post("/history/report_history_problem", { history_id:
|
|
768
|
+
async reportHistoryProblem(o, s) {
|
|
769
|
+
return t.post("/history/report_history_problem", { history_id: o, report_note: s });
|
|
751
770
|
},
|
|
752
|
-
async shareChatHistory(
|
|
753
|
-
const
|
|
754
|
-
history_ids:
|
|
755
|
-
share_days:
|
|
756
|
-
}),
|
|
757
|
-
if (!
|
|
758
|
-
return String(
|
|
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(
|
|
761
|
-
const
|
|
762
|
-
return (
|
|
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(
|
|
765
|
-
const
|
|
766
|
-
return { columns: (
|
|
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(
|
|
769
|
-
const { question:
|
|
770
|
-
question:
|
|
771
|
-
history_group_id:
|
|
772
|
-
entry_id:
|
|
773
|
-
inc_prev_question:
|
|
774
|
-
...
|
|
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
|
-
|
|
777
|
-
const
|
|
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:
|
|
802
|
+
data: E,
|
|
784
803
|
// 每次(重)连都实时取 session:会话失效刷新后重连要带新值
|
|
785
|
-
getSessionId:
|
|
804
|
+
getSessionId: h,
|
|
786
805
|
refreshSession: e.refreshSession,
|
|
787
|
-
signal:
|
|
806
|
+
signal: s,
|
|
788
807
|
onOpen: w,
|
|
789
|
-
groupId:
|
|
790
|
-
resumeTask:
|
|
791
|
-
registry:
|
|
808
|
+
groupId: C,
|
|
809
|
+
resumeTask: S ?? null,
|
|
810
|
+
registry: i,
|
|
792
811
|
fallback: Ee({
|
|
793
|
-
getChatTaskList: () =>
|
|
794
|
-
getHistoryAnswer: (n) =>
|
|
812
|
+
getChatTaskList: () => y.getChatTaskList(),
|
|
813
|
+
getHistoryAnswer: (n) => y.getHistoryAnswer(n)
|
|
795
814
|
})
|
|
796
815
|
}) : oe({
|
|
797
816
|
baseURL: t.baseURL,
|
|
798
|
-
data:
|
|
799
|
-
sessionId:
|
|
800
|
-
signal:
|
|
817
|
+
data: E,
|
|
818
|
+
sessionId: h(),
|
|
819
|
+
signal: s,
|
|
801
820
|
// 传输层选项:连接就绪后向外部交出分片发送器(不混入发给后端的载荷)
|
|
802
821
|
onOpen: w
|
|
803
822
|
});
|
|
804
823
|
},
|
|
805
|
-
stopChat(
|
|
806
|
-
return e.resumable ?
|
|
824
|
+
stopChat(o) {
|
|
825
|
+
return e.resumable ? i.sendStop(o) : !1;
|
|
807
826
|
}
|
|
808
827
|
};
|
|
809
|
-
return
|
|
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
|
-
|
|
836
|
+
Pe as createChatApi,
|
|
818
837
|
Ee as createChatWsFallback,
|
|
819
838
|
_e as createChatWsRegistry,
|
|
820
|
-
|
|
821
|
-
|
|
839
|
+
De as createChunkSender,
|
|
840
|
+
Ie as createRequest,
|
|
822
841
|
Se as defaultBuildHistoryAnswerPayload,
|
|
823
842
|
we as defaultHasHistoryAnswerContent,
|
|
824
843
|
ft as fileToBase64,
|
|
825
|
-
|
|
826
|
-
|
|
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
|
-
|
|
851
|
+
xt as pickChatTaskList,
|
|
831
852
|
Ht as pickHistoryId,
|
|
832
|
-
|
|
833
|
-
|
|
853
|
+
Dt as pwdEncrypt,
|
|
854
|
+
vt as resolveMessageData,
|
|
834
855
|
Q as sendPayloadInChunks,
|
|
835
856
|
Ae as startChatWsSession
|
|
836
857
|
};
|