wi-chat 0.6.2 → 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 +12 -0
- package/dist/core/index.js +921 -342
- package/dist/core/useAnswerActions.d.ts +61 -0
- package/dist/core/useChat.d.ts +29 -3
- package/dist/core/useChatAuth.d.ts +175 -0
- package/dist/core/useChatRooms.d.ts +66 -0
- package/dist/core/useKeepAlive.d.ts +41 -0
- package/dist/core/useLlm.d.ts +73 -0
- package/dist/core/useRunningGroups.d.ts +58 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +119 -108
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +3 -3
- package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +1 -1
- package/dist/parser/answerCom/generic/parseGeneric.d.ts +52 -0
- package/dist/parser/answerCom/generic/types.d.ts +75 -0
- package/dist/parser/answerCom/outputFile/parseOutputFile.d.ts +7 -6
- package/dist/parser/answerCom/outputFile/types.d.ts +15 -5
- package/dist/parser/answerCom/presentFiles/parsePresentFiles.d.ts +58 -0
- package/dist/parser/answerCom/presentFiles/types.d.ts +27 -0
- package/dist/parser/answerMeta.d.ts +71 -0
- package/dist/parser/deepThinking/parseDeepThinking.d.ts +8 -0
- package/dist/parser/history/history.d.ts +9 -0
- package/dist/parser/history/index.d.ts +1 -1
- package/dist/parser/index.cjs +6 -2
- package/dist/parser/index.d.ts +11 -2
- package/dist/parser/index.js +591 -366
- package/dist/parser/message.d.ts +9 -0
- package/dist/parser/runTime.d.ts +29 -0
- package/dist/renderers/TextAnswer-BgKGvG_o.cjs +2 -0
- package/dist/renderers/TextAnswer-PQwV3K7v.js +5 -0
- package/dist/renderers/answerCard/AnswerCard.vue.d.ts +65 -0
- package/dist/renderers/answerCard/AnswerToolbar.vue.d.ts +42 -0
- package/dist/renderers/answerConfig.d.ts +33 -0
- package/dist/renderers/deviceLastValue/DeviceLastValue.vue.d.ts +37 -0
- package/dist/renderers/index.cjs +6 -1
- package/dist/renderers/index.d.ts +14 -0
- package/dist/renderers/index.js +1485 -574
- package/dist/renderers/media/MediaAnswer.vue.d.ts +19 -0
- package/dist/renderers/outputFile/OutputFileLink.vue.d.ts +19 -0
- package/dist/renderers/outputFile/localFile.d.ts +46 -0
- package/dist/renderers/outputFile/useOutputFile.d.ts +32 -3
- package/dist/renderers/presentFiles/PresentFiles.vue.d.ts +19 -0
- package/dist/renderers/recordset/RecordsetView.vue.d.ts +19 -0
- package/dist/renderers/sqlQuery/SqlQuery.vue.d.ts +19 -0
- package/dist/renderers/style.css +1 -1
- package/dist/renderers/text/TextAnswer.vue.d.ts +19 -0
- package/dist/request/api.d.ts +121 -1
- package/dist/request/client.d.ts +12 -0
- package/dist/request/index.cjs +4 -2
- package/dist/request/index.d.ts +6 -4
- package/dist/request/index.js +780 -179
- package/dist/request/login.d.ts +36 -0
- package/dist/request/ws.d.ts +11 -86
- package/dist/request/wsCore.d.ts +104 -0
- package/dist/request/wsSession.d.ts +353 -0
- package/dist/right-panel/RightPanelTabs.vue.d.ts +4 -0
- package/dist/right-panel/index.cjs +1 -1
- package/dist/right-panel/index.d.ts +1 -1
- package/dist/right-panel/index.js +598 -499
- package/dist/right-panel/style.css +1 -1
- package/dist/right-panel/types.d.ts +10 -0
- package/dist/tools/index.cjs +5 -5
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +323 -208
- package/dist/tools/markdown/index.d.ts +2 -0
- package/dist/tools/markdown/interactions.d.ts +39 -0
- package/dist/tools/markdown/sanitize.d.ts +6 -0
- package/dist/tools/style.css +1 -1
- package/dist/web-ui/attach/AttachmentCard.vue.d.ts +1 -1
- package/dist/web-ui/attach/AttachmentList.vue.d.ts +1 -1
- package/dist/web-ui/chat/ChatContainer.vue.d.ts +5 -5
- package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +1 -1
- package/dist/web-ui/index.cjs +1 -1
- package/dist/web-ui/index.js +1 -1
- package/dist/web-ui/inputbox/Inputbox.vue.d.ts +5 -5
- package/dist/web-ui/style.css +1 -1
- package/package.json +2 -2
package/dist/request/index.js
CHANGED
|
@@ -1,257 +1,858 @@
|
|
|
1
|
-
import
|
|
2
|
-
class
|
|
3
|
-
constructor(
|
|
4
|
-
super(
|
|
1
|
+
import ht from "axios";
|
|
2
|
+
class lt extends Error {
|
|
3
|
+
constructor(e = "登录已过期,请重新认证") {
|
|
4
|
+
super(e), this.name = "AuthExpiredError";
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
const
|
|
8
|
-
Object.entries(
|
|
9
|
-
),
|
|
10
|
-
const { baseURL:
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
headers:
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
try {
|
|
20
|
+
E = await ht.post(`${o}${w}`, L, {
|
|
21
|
+
headers: p(l)
|
|
22
|
+
});
|
|
23
|
+
} catch (u) {
|
|
24
|
+
throw ((n = u == null ? void 0 : u.response) == null ? void 0 : n.status) === 401 ? new lt() : u;
|
|
25
|
+
}
|
|
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),
|
|
31
52
|
// 浏览器下 XHR 不支持流式读取(response.data 会变成整包 String),
|
|
32
53
|
// 必须强制 fetch 适配器才能拿到 ReadableStream
|
|
33
54
|
adapter: "fetch",
|
|
34
55
|
responseType: "stream",
|
|
35
|
-
signal:
|
|
36
|
-
})
|
|
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);
|
|
37
61
|
}
|
|
62
|
+
return n.data;
|
|
38
63
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const i = await e.post("/login", n);
|
|
51
|
-
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("密码加密失败");
|
|
52
75
|
return i;
|
|
53
|
-
},
|
|
54
|
-
const
|
|
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;
|
|
94
|
+
}, ft = async (t) => {
|
|
95
|
+
const e = "name" in t && typeof t.name == "string" ? t.name : "", a = t.type || "";
|
|
55
96
|
if (typeof FileReader < "u")
|
|
56
|
-
return new Promise((
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
name:
|
|
62
|
-
"content-type":
|
|
63
|
-
data:
|
|
97
|
+
return new Promise((i, y) => {
|
|
98
|
+
const o = new FileReader();
|
|
99
|
+
o.onload = () => {
|
|
100
|
+
const s = String(o.result ?? "");
|
|
101
|
+
i({
|
|
102
|
+
name: e,
|
|
103
|
+
"content-type": a,
|
|
104
|
+
data: s.split(",")[1] ?? s
|
|
64
105
|
});
|
|
65
|
-
},
|
|
106
|
+
}, o.onerror = () => y(o.error), o.readAsDataURL(t);
|
|
66
107
|
});
|
|
67
|
-
if (typeof
|
|
68
|
-
const
|
|
108
|
+
if (typeof t.arrayBuffer == "function") {
|
|
109
|
+
const i = await t.arrayBuffer(), y = typeof Buffer < "u" ? Buffer.from(i).toString("base64") : btoa(String.fromCharCode(...new Uint8Array(i)));
|
|
69
110
|
return {
|
|
70
|
-
name:
|
|
71
|
-
"content-type":
|
|
72
|
-
data:
|
|
111
|
+
name: e,
|
|
112
|
+
"content-type": a,
|
|
113
|
+
data: y
|
|
73
114
|
};
|
|
74
115
|
}
|
|
75
116
|
return {
|
|
76
|
-
name:
|
|
77
|
-
"content-type":
|
|
117
|
+
name: e,
|
|
118
|
+
"content-type": a,
|
|
78
119
|
data: ""
|
|
79
120
|
};
|
|
80
|
-
},
|
|
81
|
-
Object.prototype.hasOwnProperty.call(
|
|
82
|
-
},
|
|
83
|
-
const
|
|
84
|
-
if (typeof FormData < "u" &&
|
|
85
|
-
for (const [
|
|
86
|
-
const
|
|
87
|
-
|
|
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) => {
|
|
124
|
+
const e = {};
|
|
125
|
+
if (typeof FormData < "u" && t instanceof FormData)
|
|
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);
|
|
88
129
|
}
|
|
89
|
-
else if (
|
|
90
|
-
for (const [
|
|
91
|
-
typeof Blob < "u" &&
|
|
92
|
-
|
|
93
|
-
async (
|
|
130
|
+
else if (t && typeof t == "object")
|
|
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
|
|
94
135
|
)
|
|
95
|
-
) :
|
|
96
|
-
return
|
|
97
|
-
},
|
|
98
|
-
const
|
|
99
|
-
return
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
e.
|
|
136
|
+
) : e[a] = i;
|
|
137
|
+
return e.files && !Array.isArray(e.files) && (e.files = [e.files]), e.type = "chat_stream", e;
|
|
138
|
+
}, Mt = (t, e) => {
|
|
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) => {
|
|
142
|
+
if (t.readyState != null && t.readyState !== 1) return !1;
|
|
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}`);
|
|
105
147
|
}
|
|
106
|
-
|
|
148
|
+
return !0;
|
|
149
|
+
}, oe = async (t) => {
|
|
107
150
|
const {
|
|
108
|
-
baseURL:
|
|
109
|
-
data:
|
|
110
|
-
sessionId:
|
|
111
|
-
signal:
|
|
112
|
-
chunkSize:
|
|
113
|
-
WebSocketClass:
|
|
114
|
-
onOpen:
|
|
115
|
-
} =
|
|
116
|
-
if (!
|
|
151
|
+
baseURL: e,
|
|
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
|
|
158
|
+
} = t;
|
|
159
|
+
if (!s)
|
|
117
160
|
throw new Error("当前运行环境不支持 WebSocket");
|
|
118
|
-
const
|
|
161
|
+
const C = await Pt(a), T = Mt(e, i), H = new TextEncoder();
|
|
119
162
|
return new ReadableStream({
|
|
120
|
-
start(
|
|
121
|
-
let
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
124
|
-
|
|
163
|
+
start(A) {
|
|
164
|
+
let w = !1, S = !1;
|
|
165
|
+
const l = new s(T), L = () => {
|
|
166
|
+
if (!w) {
|
|
167
|
+
w = !0;
|
|
125
168
|
try {
|
|
126
|
-
|
|
169
|
+
A.close();
|
|
127
170
|
} catch {
|
|
128
171
|
}
|
|
129
172
|
try {
|
|
130
|
-
|
|
173
|
+
l.close();
|
|
131
174
|
} catch {
|
|
132
175
|
}
|
|
133
176
|
}
|
|
134
|
-
},
|
|
135
|
-
if (!
|
|
136
|
-
|
|
177
|
+
}, E = (n) => {
|
|
178
|
+
if (!w) {
|
|
179
|
+
w = !0;
|
|
137
180
|
try {
|
|
138
|
-
|
|
181
|
+
A.error(n);
|
|
139
182
|
} catch {
|
|
140
183
|
}
|
|
141
184
|
try {
|
|
142
|
-
|
|
185
|
+
l.close();
|
|
143
186
|
} catch {
|
|
144
187
|
}
|
|
145
188
|
}
|
|
146
189
|
};
|
|
147
|
-
|
|
190
|
+
l.onopen = () => {
|
|
148
191
|
try {
|
|
149
|
-
|
|
150
|
-
} catch (
|
|
151
|
-
|
|
192
|
+
Q(l, JSON.stringify(C), o), p == null || p((n, u) => w || l.readyState !== 1 ? !1 : Q(l, n, u ?? o));
|
|
193
|
+
} catch (n) {
|
|
194
|
+
E(n);
|
|
152
195
|
}
|
|
153
|
-
},
|
|
196
|
+
}, l.onmessage = async (n) => {
|
|
154
197
|
try {
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
158
|
-
const
|
|
198
|
+
S = !0;
|
|
199
|
+
const u = await vt(n.data);
|
|
200
|
+
if (!u) return;
|
|
201
|
+
const P = H.encode(`data: ${u}
|
|
159
202
|
|
|
160
203
|
`);
|
|
161
|
-
|
|
204
|
+
A.enqueue(P);
|
|
162
205
|
try {
|
|
163
|
-
const
|
|
164
|
-
(
|
|
206
|
+
const x = JSON.parse(u);
|
|
207
|
+
(x == null ? void 0 : x.mode) === "finish" && L();
|
|
165
208
|
} catch {
|
|
166
209
|
}
|
|
167
|
-
} catch (
|
|
168
|
-
|
|
210
|
+
} catch (u) {
|
|
211
|
+
E(u);
|
|
169
212
|
}
|
|
170
|
-
},
|
|
171
|
-
if (!
|
|
172
|
-
|
|
213
|
+
}, l.onclose = () => {
|
|
214
|
+
if (!S) {
|
|
215
|
+
E(new Error("WebSocket 连接已断开(未收到任何回答数据)"));
|
|
173
216
|
return;
|
|
174
217
|
}
|
|
175
|
-
|
|
176
|
-
},
|
|
177
|
-
|
|
218
|
+
L();
|
|
219
|
+
}, l.onerror = (n) => {
|
|
220
|
+
E(n);
|
|
178
221
|
};
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
|
|
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);
|
|
182
225
|
};
|
|
183
|
-
|
|
226
|
+
y && (y.aborted ? h() : y.addEventListener("abort", h, { once: !0 }));
|
|
184
227
|
}
|
|
185
228
|
});
|
|
186
|
-
},
|
|
187
|
-
const
|
|
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 = () => {
|
|
230
|
+
const t = /* @__PURE__ */ new Map();
|
|
231
|
+
let e = null;
|
|
188
232
|
return {
|
|
189
|
-
|
|
190
|
-
|
|
233
|
+
getActive: () => e,
|
|
234
|
+
setActive(a) {
|
|
235
|
+
e = a;
|
|
236
|
+
},
|
|
237
|
+
get(a) {
|
|
238
|
+
return a ? t.get(a) : void 0;
|
|
239
|
+
},
|
|
240
|
+
set(a, i) {
|
|
241
|
+
a && t.set(a, i);
|
|
242
|
+
},
|
|
243
|
+
removeGroup(a) {
|
|
244
|
+
a && t.delete(a);
|
|
245
|
+
},
|
|
246
|
+
remove(a) {
|
|
247
|
+
e === a && (e = null);
|
|
248
|
+
for (const [i, y] of t)
|
|
249
|
+
y === a && t.delete(i);
|
|
250
|
+
},
|
|
251
|
+
entries() {
|
|
252
|
+
return new Map(t);
|
|
253
|
+
},
|
|
254
|
+
hasActive(a) {
|
|
255
|
+
var i;
|
|
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);
|
|
262
|
+
},
|
|
263
|
+
clear() {
|
|
264
|
+
t.clear(), e = null;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}, Nt = _e(), Lt = (t) => new Promise((e) => setTimeout(e, t)), we = (t) => {
|
|
268
|
+
var i;
|
|
269
|
+
const e = t == null ? void 0 : t.values;
|
|
270
|
+
if (!e) return !1;
|
|
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());
|
|
273
|
+
}, Se = (t) => {
|
|
274
|
+
var o, s;
|
|
275
|
+
const e = (t == null ? void 0 : t.values) ?? {}, a = e.answer ?? {}, i = e.attach ?? {}, y = e.entry ?? {};
|
|
276
|
+
return {
|
|
277
|
+
answer_type: "report_list",
|
|
278
|
+
question: e.question ?? "",
|
|
279
|
+
reports: a.reports ?? [],
|
|
280
|
+
conclusion: e.conclusion ?? [],
|
|
281
|
+
context_history: e.context_history ?? [],
|
|
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
|
|
290
|
+
};
|
|
291
|
+
}, me = (t) => (t == null ? void 0 : t.values) ?? {}, Ht = (t) => {
|
|
292
|
+
var a, i, y, o;
|
|
293
|
+
if (!t || typeof t != "object") return "";
|
|
294
|
+
const e = [
|
|
295
|
+
t.history_id,
|
|
296
|
+
t.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
|
|
301
|
+
];
|
|
302
|
+
for (const s of e)
|
|
303
|
+
if (typeof s == "string" && s) return s;
|
|
304
|
+
return t.mode === "history_id" && typeof t.value == "string" && t.value ? t.value : "";
|
|
305
|
+
}, $t = (t, e, a, i = !1) => `CONNECT:${JSON.stringify({
|
|
306
|
+
history_id: t,
|
|
307
|
+
local_sys_tool: e,
|
|
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) => {
|
|
311
|
+
const e = [t, t == null ? void 0 : t.values];
|
|
312
|
+
for (const a of e)
|
|
313
|
+
if (Array.isArray(a)) return a;
|
|
314
|
+
return [];
|
|
315
|
+
}, Ee = (t) => ({
|
|
316
|
+
getTaskList: () => t.getChatTaskList(),
|
|
317
|
+
pickTaskList: xt,
|
|
318
|
+
getHistoryAnswer: (e) => t.getHistoryAnswer(e),
|
|
319
|
+
// wi-chat core 的 useChat 直接消费新版 values(history_answer 帧)
|
|
320
|
+
answerFrameMode: "history_answer"
|
|
321
|
+
}), Ae = async (t) => {
|
|
322
|
+
const {
|
|
323
|
+
baseURL: e,
|
|
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,
|
|
334
|
+
preparePayload: w,
|
|
335
|
+
onChunk: S,
|
|
336
|
+
onOpen: l,
|
|
337
|
+
emitOpenOnReconnect: L = !1,
|
|
338
|
+
resumeTask: E = null,
|
|
339
|
+
forceConnect: h = !1,
|
|
340
|
+
logger: n = {},
|
|
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
|
|
348
|
+
} = t;
|
|
349
|
+
if (!H)
|
|
350
|
+
throw new Error("当前运行环境不支持 WebSocket");
|
|
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;
|
|
359
|
+
const ot = /* @__PURE__ */ new Map(), St = /* @__PURE__ */ new Set();
|
|
360
|
+
let k = 0, at = !!E, V = !1, it = !1, X = 0, m = null, W = null;
|
|
361
|
+
const Z = () => {
|
|
362
|
+
F != null && (clearTimeout(F), F = null);
|
|
363
|
+
}, J = () => {
|
|
364
|
+
z != null && (clearInterval(z), z = null);
|
|
365
|
+
}, kt = (r) => {
|
|
366
|
+
J(), !(!rt || rt <= 0) && (z = setInterval(() => {
|
|
367
|
+
if (!(b || r !== m || r.readyState !== 1))
|
|
368
|
+
try {
|
|
369
|
+
r.send(Ft);
|
|
370
|
+
} catch {
|
|
371
|
+
}
|
|
372
|
+
}, rt));
|
|
373
|
+
}, tt = {
|
|
374
|
+
get ws() {
|
|
375
|
+
return m;
|
|
376
|
+
},
|
|
377
|
+
get readyState() {
|
|
378
|
+
return (m == null ? void 0 : m.readyState) ?? 3;
|
|
379
|
+
},
|
|
380
|
+
get groupId() {
|
|
381
|
+
return I;
|
|
382
|
+
},
|
|
383
|
+
send(r) {
|
|
384
|
+
m && m.readyState === 1 && m.send(r);
|
|
385
|
+
},
|
|
386
|
+
close(r, c) {
|
|
387
|
+
try {
|
|
388
|
+
m == null || m.close(r, c);
|
|
389
|
+
} catch {
|
|
390
|
+
}
|
|
391
|
+
}
|
|
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) => {
|
|
397
|
+
try {
|
|
398
|
+
const c = JSON.parse(r);
|
|
399
|
+
if ((c == null ? void 0 : c.type) === "wait_reply" && c.reply_id != null) return String(c.reply_id);
|
|
400
|
+
} catch {
|
|
401
|
+
}
|
|
402
|
+
return "";
|
|
403
|
+
}, mt = (r, c) => {
|
|
404
|
+
const d = Qt(r);
|
|
405
|
+
if (!d) return;
|
|
406
|
+
const _ = ot.get(d);
|
|
407
|
+
if (_) {
|
|
408
|
+
_.lastPayload = r, _.lastSentGeneration = c;
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
ot.set(d, { lastPayload: r, lastSentGeneration: c });
|
|
412
|
+
}, ct = (r, c = p) => {
|
|
413
|
+
var d;
|
|
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;
|
|
419
|
+
}
|
|
420
|
+
return mt(r, 0), !1;
|
|
421
|
+
}, Kt = (r) => ct(typeof r == "string" ? r : JSON.stringify(r)), Yt = (r, c) => ct(r, c ?? p), j = () => ({
|
|
422
|
+
sender: Kt,
|
|
423
|
+
sendInChunks: Yt,
|
|
424
|
+
session: tt,
|
|
425
|
+
generation: k
|
|
426
|
+
}), G = (r) => {
|
|
427
|
+
var _;
|
|
428
|
+
if ((r == null ? void 0 : r.mode) !== "front_reply") {
|
|
429
|
+
S(r, j());
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const c = (r == null ? void 0 : r.reply_id) != null ? String(r.reply_id) : "";
|
|
433
|
+
if (!c) {
|
|
434
|
+
S(r, j());
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const d = ot.get(c);
|
|
438
|
+
if (d) {
|
|
439
|
+
if (d.lastSentGeneration === k) return;
|
|
440
|
+
(_ = n.warn) == null || _.call(n, `[chat ws] front_reply(${c}) 被后端重放,补发最后一次 wait_reply 而不重复执行`), ct(d.lastPayload);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
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;
|
|
447
|
+
V = !0, Z(), J();
|
|
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) ?? "");
|
|
449
|
+
(_ = n.warn) == null || _.call(
|
|
450
|
+
n,
|
|
451
|
+
`[chat ws] 收到 disconnect(value=${c || "空"},groupId=${I},historyId=${g}),不再重连,改为轮询任务 + 历史回答兜底`
|
|
452
|
+
);
|
|
453
|
+
try {
|
|
454
|
+
if (!g) {
|
|
455
|
+
(f = n.warn) == null || f.call(n, `[chat ws] disconnect 兜底缺少 history_id,直接结束(groupId=${I})`), et({ mode: "finish", type: "json", value: {} });
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
let R = !1;
|
|
459
|
+
for (let N = 0; N < nt; N += 1) {
|
|
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;
|
|
466
|
+
});
|
|
467
|
+
if (gt.length === 0 || gt.some((D) => (D == null ? void 0 : D.is_stop) === !0)) {
|
|
468
|
+
R = !0;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
N < nt - 1 && await Lt(wt);
|
|
473
|
+
}
|
|
474
|
+
if (b) return;
|
|
475
|
+
R || ($ = n.warn) == null || $.call(
|
|
476
|
+
n,
|
|
477
|
+
`[chat ws] disconnect 后任务 ${nt} 次轮询仍未收尾,继续尝试历史回答(historyId=${g})`
|
|
478
|
+
);
|
|
479
|
+
for (let N = 0; N < st; N += 1) {
|
|
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(
|
|
486
|
+
n,
|
|
487
|
+
`[chat ws] disconnect 兜底成功,已回放历史回答(第 ${N + 1} 次,groupId=${I},historyId=${g})`
|
|
488
|
+
), et(dt);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
N < st - 1 && await Lt(wt);
|
|
492
|
+
}
|
|
493
|
+
if (b) return;
|
|
494
|
+
(Ct = n.warn) == null || Ct.call(
|
|
495
|
+
n,
|
|
496
|
+
`[chat ws] disconnect 兜底重试 ${st} 次仍无历史回答,结束本次回答(groupId=${I},historyId=${g})`
|
|
497
|
+
), M(new Error("任务已结束,但历史回答尚未就绪"));
|
|
498
|
+
} catch (R) {
|
|
499
|
+
(bt = n.warn) == null || bt.call(
|
|
500
|
+
n,
|
|
501
|
+
`[chat ws] disconnect 兜底异常,结束本次回答:${R instanceof Error ? R.message : String(R)}`
|
|
502
|
+
), b || M(new Error("连接已断开,收回回答失败,请稍后重试"));
|
|
503
|
+
}
|
|
504
|
+
}, Vt = async () => {
|
|
505
|
+
var c, d;
|
|
506
|
+
if (b || it) return;
|
|
507
|
+
if (X >= o) {
|
|
508
|
+
(c = n.warn) == null || c.call(
|
|
509
|
+
n,
|
|
510
|
+
`[chat ws] 会话失效重试 ${X} 次仍未恢复,结束本次回答(groupId=${I})`
|
|
511
|
+
), M(new Error("登录状态已失效,请重新登录"));
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
X += 1, it = !0, J(), Z();
|
|
515
|
+
const r = m;
|
|
516
|
+
m = null;
|
|
517
|
+
try {
|
|
518
|
+
r == null || r.close();
|
|
519
|
+
} catch {
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
if (await (s == null ? void 0 : s()) === !1) throw new Error("宿主未能刷新登录态");
|
|
523
|
+
} catch (_) {
|
|
524
|
+
(d = n.warn) == null || d.call(
|
|
525
|
+
n,
|
|
526
|
+
`[chat ws] 会话失效后刷新登录态失败,结束本次回答(groupId=${I}):${_ instanceof Error ? _.message : String(_)}`
|
|
527
|
+
), M(new Error("登录状态已失效,请重新登录"));
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
b || (it = !1, g || (O = !1), ut());
|
|
531
|
+
}, Et = () => {
|
|
532
|
+
Z(), J(), T && W && (T.removeEventListener("abort", W), W = null);
|
|
533
|
+
const r = m;
|
|
534
|
+
m = null;
|
|
535
|
+
try {
|
|
536
|
+
r == null || r.close();
|
|
537
|
+
} catch {
|
|
538
|
+
}
|
|
539
|
+
P.remove(tt);
|
|
540
|
+
}, et = (r) => {
|
|
541
|
+
b || (b = !0, Et(), K(r));
|
|
542
|
+
}, M = (r) => {
|
|
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) {
|
|
548
|
+
(d = n.warn) == null || d.call(
|
|
549
|
+
n,
|
|
550
|
+
`[chat ws] 连接中断且尚未收到 history_id,无法 CONNECT 续传,结束本次回答(groupId=${I},已收 ${q} 帧)`
|
|
551
|
+
), M(new Error("WebSocket 连接已断开:尚未收到 history_id,无法续传"));
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
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($);
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
v += 1;
|
|
561
|
+
const c = Math.min(Bt * 2 ** (v - 1), Ot);
|
|
562
|
+
(f = n.warn) == null || f.call(
|
|
563
|
+
n,
|
|
564
|
+
`[chat ws] 连接中断,${c}ms 后第 ${v} 次重连(groupId=${I},已收 ${q} 帧,续传序号 ${Y})`
|
|
565
|
+
), F = setTimeout(() => {
|
|
566
|
+
if (F = null, !b)
|
|
567
|
+
try {
|
|
568
|
+
ut();
|
|
569
|
+
} catch ($) {
|
|
570
|
+
yt($);
|
|
571
|
+
}
|
|
572
|
+
}, c);
|
|
573
|
+
}, ut = () => {
|
|
574
|
+
if (b) return;
|
|
575
|
+
const r = new H(Wt());
|
|
576
|
+
m = r, r.onopen = () => {
|
|
577
|
+
Xt(r);
|
|
578
|
+
}, r.onmessage = (c) => {
|
|
579
|
+
Zt(r, c);
|
|
580
|
+
}, r.onclose = (c) => {
|
|
581
|
+
te(r, c);
|
|
582
|
+
}, r.onerror = (c) => {
|
|
583
|
+
ee(r, c);
|
|
584
|
+
};
|
|
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()));
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (!O) {
|
|
597
|
+
O = !0, v = 0, Gt(r, JSON.stringify(B)), c && (l == null || l(j()));
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (!g) {
|
|
601
|
+
M(new Error("WebSocket 重连失败:缺少 history_id,无法续传"));
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
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) => {
|
|
611
|
+
if (r === m)
|
|
612
|
+
try {
|
|
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;
|
|
618
|
+
try {
|
|
619
|
+
f = JSON.parse(_);
|
|
620
|
+
} catch {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (q += 1, (f == null ? void 0 : f.type) === "error" && String((f == null ? void 0 : f.value) ?? "") === y) {
|
|
624
|
+
Vt();
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if ((f == null ? void 0 : f.mode) === "disconnect" && at) {
|
|
628
|
+
if (u) {
|
|
629
|
+
zt(f);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
G(f), et(f);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
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);
|
|
638
|
+
} catch (d) {
|
|
639
|
+
M(d);
|
|
640
|
+
}
|
|
641
|
+
}, te = (r, c) => {
|
|
642
|
+
var d;
|
|
643
|
+
b || V || r === m && (J(), (d = n.close) == null || d.call(n, {
|
|
644
|
+
groupId: I,
|
|
645
|
+
code: c == null ? void 0 : c.code,
|
|
646
|
+
reason: c == null ? void 0 : c.reason,
|
|
647
|
+
wasClean: c == null ? void 0 : c.wasClean,
|
|
648
|
+
receivedChunks: q
|
|
649
|
+
}), yt(c));
|
|
650
|
+
}, ee = (r, c) => {
|
|
651
|
+
var d;
|
|
652
|
+
b || r === m && ((d = n.error) == null || d.call(n, {
|
|
653
|
+
groupId: I,
|
|
654
|
+
type: c == null ? void 0 : c.type,
|
|
655
|
+
readyState: r == null ? void 0 : r.readyState,
|
|
656
|
+
receivedChunks: q
|
|
657
|
+
}), r.readyState === 3 && yt(c));
|
|
658
|
+
};
|
|
659
|
+
if (P.setActive(tt), I && P.set(I, tt), T) {
|
|
660
|
+
if (W = () => M(T.reason ?? new Error("会话已取消")), T.aborted) {
|
|
661
|
+
W();
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
T.addEventListener("abort", W, { once: !0 });
|
|
665
|
+
}
|
|
666
|
+
try {
|
|
667
|
+
ut();
|
|
668
|
+
} catch (r) {
|
|
669
|
+
M(r);
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}, Ce = async (t) => {
|
|
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;
|
|
678
|
+
try {
|
|
679
|
+
s == null || s.close();
|
|
680
|
+
} catch {
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}, T = (A) => {
|
|
684
|
+
if (!p) {
|
|
685
|
+
p = !0;
|
|
686
|
+
try {
|
|
687
|
+
s == null || s.error(A);
|
|
688
|
+
} catch {
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}, H = new ReadableStream({
|
|
692
|
+
start(A) {
|
|
693
|
+
s = A;
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
return Ae({
|
|
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);
|
|
703
|
+
try {
|
|
704
|
+
s == null || s.enqueue(o.encode(`data: ${S}
|
|
705
|
+
|
|
706
|
+
`));
|
|
707
|
+
} catch (L) {
|
|
708
|
+
T(L);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
(l = y.onChunk) == null || l.call(y, A, w);
|
|
712
|
+
},
|
|
713
|
+
onOpen: (A) => {
|
|
714
|
+
i == null || i(A.sendInChunks);
|
|
715
|
+
}
|
|
716
|
+
}).then(() => {
|
|
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}` : "";
|
|
191
725
|
},
|
|
192
726
|
async getHistoryGroups() {
|
|
193
|
-
return
|
|
727
|
+
return t.post("/history/get_history_groups", {});
|
|
194
728
|
},
|
|
195
|
-
async createHistoryGroup(
|
|
196
|
-
return
|
|
729
|
+
async createHistoryGroup(o) {
|
|
730
|
+
return t.post("/history/create_history_group", { group_title: o });
|
|
197
731
|
},
|
|
198
|
-
async deleteHistoryGroup(
|
|
199
|
-
return
|
|
732
|
+
async deleteHistoryGroup(o) {
|
|
733
|
+
return t.post("/history/delete_history_group", { history_group_id: o });
|
|
200
734
|
},
|
|
201
|
-
async setHistoryGroupTitle(
|
|
202
|
-
return
|
|
735
|
+
async setHistoryGroupTitle(o, s) {
|
|
736
|
+
return t.post("/history/set_history_group_title", { history_group_id: o, title: s });
|
|
203
737
|
},
|
|
204
|
-
async getHistoryDetail(
|
|
205
|
-
const
|
|
206
|
-
history_group_id:
|
|
738
|
+
async getHistoryDetail(o, s = 0, p = 10) {
|
|
739
|
+
const C = await t.post("/history/query_history_detail", {
|
|
740
|
+
history_group_id: o,
|
|
207
741
|
last_end: s,
|
|
208
|
-
last_count:
|
|
742
|
+
last_count: p
|
|
209
743
|
});
|
|
210
|
-
return (
|
|
744
|
+
return (C == null ? void 0 : C.details) || [];
|
|
211
745
|
},
|
|
212
|
-
async getHistoryAnswer(
|
|
213
|
-
return
|
|
746
|
+
async getHistoryAnswer(o) {
|
|
747
|
+
return t.post("/history/get_history_answer", { history_id: o });
|
|
214
748
|
},
|
|
215
749
|
async getDefaultLlmId() {
|
|
216
|
-
return
|
|
750
|
+
return t.post("/admin/get_default_llm_id", {});
|
|
751
|
+
},
|
|
752
|
+
async getLlmInfoList() {
|
|
753
|
+
return t.post("/admin/workflow/get_llm_info_list", {});
|
|
754
|
+
},
|
|
755
|
+
async getLlmEntryListByRole(o = { entry_group: "智能助手" }) {
|
|
756
|
+
return t.post("/admin/get_llm_entry_list_by_role", o);
|
|
217
757
|
},
|
|
218
|
-
async
|
|
219
|
-
return
|
|
758
|
+
async pingLogin() {
|
|
759
|
+
return t.post("/system/ping", {});
|
|
220
760
|
},
|
|
221
|
-
async
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
761
|
+
async getChatTaskList() {
|
|
762
|
+
const o = await t.post("/chat/getChatTaskList", {});
|
|
763
|
+
return xt(o);
|
|
764
|
+
},
|
|
765
|
+
async setHistoryAnswerState(o, s) {
|
|
766
|
+
return t.post("/history/set_history_answer_state", { history_id: o, answer_state: s ?? "" });
|
|
767
|
+
},
|
|
768
|
+
async reportHistoryProblem(o, s) {
|
|
769
|
+
return t.post("/history/report_history_problem", { history_id: o, report_note: s });
|
|
770
|
+
},
|
|
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);
|
|
778
|
+
},
|
|
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;
|
|
782
|
+
},
|
|
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) ?? [] };
|
|
786
|
+
},
|
|
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
|
|
794
|
+
};
|
|
795
|
+
H && H.length > 0 && (E.files = H);
|
|
796
|
+
const h = () => {
|
|
797
|
+
var n;
|
|
798
|
+
return ((n = t.getSession) == null ? void 0 : n.call(t)) ?? (typeof localStorage < "u" ? localStorage.getItem("access-session") : null);
|
|
229
799
|
};
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
800
|
+
return e.resumable ? Ce({
|
|
801
|
+
baseURL: t.baseURL ?? "",
|
|
802
|
+
data: E,
|
|
803
|
+
// 每次(重)连都实时取 session:会话失效刷新后重连要带新值
|
|
804
|
+
getSessionId: h,
|
|
805
|
+
refreshSession: e.refreshSession,
|
|
806
|
+
signal: s,
|
|
807
|
+
onOpen: w,
|
|
808
|
+
groupId: C,
|
|
809
|
+
resumeTask: S ?? null,
|
|
810
|
+
registry: i,
|
|
811
|
+
fallback: Ee({
|
|
812
|
+
getChatTaskList: () => y.getChatTaskList(),
|
|
813
|
+
getHistoryAnswer: (n) => y.getHistoryAnswer(n)
|
|
814
|
+
})
|
|
815
|
+
}) : oe({
|
|
816
|
+
baseURL: t.baseURL,
|
|
817
|
+
data: E,
|
|
818
|
+
sessionId: h(),
|
|
236
819
|
signal: s,
|
|
237
820
|
// 传输层选项:连接就绪后向外部交出分片发送器(不混入发给后端的载荷)
|
|
238
|
-
onOpen:
|
|
821
|
+
onOpen: w
|
|
239
822
|
});
|
|
823
|
+
},
|
|
824
|
+
stopChat(o) {
|
|
825
|
+
return e.resumable ? i.sendStop(o) : !1;
|
|
240
826
|
}
|
|
241
827
|
};
|
|
828
|
+
return y;
|
|
242
829
|
};
|
|
243
830
|
export {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
$ as
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
831
|
+
lt as AuthExpiredError,
|
|
832
|
+
Mt as buildChatWsUrl,
|
|
833
|
+
$t as buildConnectFrame,
|
|
834
|
+
me as buildHistoryAnswerValues,
|
|
835
|
+
Nt as chatWsRegistry,
|
|
836
|
+
Pe as createChatApi,
|
|
837
|
+
Ee as createChatWsFallback,
|
|
838
|
+
_e as createChatWsRegistry,
|
|
839
|
+
De as createChunkSender,
|
|
840
|
+
Ie as createRequest,
|
|
841
|
+
Se as defaultBuildHistoryAnswerPayload,
|
|
842
|
+
we as defaultHasHistoryAnswerContent,
|
|
843
|
+
ft as fileToBase64,
|
|
844
|
+
Pt as formDataToJson,
|
|
845
|
+
Te as isCancelError,
|
|
846
|
+
Le as login,
|
|
847
|
+
$e as loginByEncryptKey,
|
|
848
|
+
He as makeEncryptLoginStatus,
|
|
849
|
+
oe as openChatWebSocketStream,
|
|
850
|
+
Ce as openChatWsSessionStream,
|
|
851
|
+
xt as pickChatTaskList,
|
|
852
|
+
Ht as pickHistoryId,
|
|
853
|
+
Dt as pwdEncrypt,
|
|
854
|
+
vt as resolveMessageData,
|
|
855
|
+
Q as sendPayloadInChunks,
|
|
856
|
+
Ae as startChatWsSession
|
|
256
857
|
};
|
|
257
858
|
//# sourceMappingURL=index.js.map
|