wi-chat 0.6.1 → 0.7.0
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 +737 -322
- package/dist/core/useAnswerActions.d.ts +61 -0
- package/dist/core/useChat.d.ts +90 -15
- package/dist/core/useChatAuth.d.ts +96 -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 +4 -2
- package/dist/index.js +119 -108
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +8 -8
- package/dist/mobile-ui/chat/ChatMessagesView.vue.d.ts +6 -6
- package/dist/mobile-ui/index.cjs +1 -1
- package/dist/mobile-ui/index.js +104 -104
- package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +6 -6
- package/dist/page-context/index.js +2 -4
- package/dist/parser/answerCom/actionExecute/actionProtocol.d.ts +1 -7
- package/dist/parser/answerCom/actionExecute/clarification.d.ts +15 -3
- package/dist/parser/answerCom/actionExecute/constants.d.ts +10 -0
- package/dist/parser/answerCom/actionExecute/parseCollectClarifications.d.ts +3 -2
- package/dist/parser/answerCom/actionExecute/parseHostAction.d.ts +3 -2
- package/dist/parser/answerCom/actionExecute/types.d.ts +3 -3
- 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 +13 -4
- package/dist/parser/index.js +640 -457
- package/dist/parser/message.d.ts +9 -0
- package/dist/parser/registry.d.ts +1 -1
- 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/aiAnswer/AiAnswerBubble.vue.d.ts +4 -4
- 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/clarification/ClarificationCard.vue.d.ts +3 -3
- package/dist/renderers/deepThinking/DeepThinkingSteps.vue.d.ts +4 -4
- package/dist/renderers/deviceLastValue/DeviceLastValue.vue.d.ts +37 -0
- package/dist/renderers/hostAction/HostActionStatus.vue.d.ts +3 -3
- package/dist/renderers/iframePage/IframePage.vue.d.ts +3 -3
- package/dist/renderers/index.cjs +6 -1
- package/dist/renderers/index.d.ts +14 -0
- package/dist/renderers/index.js +1504 -607
- package/dist/renderers/knowledgeStream/KnowledgeStreamResult.vue.d.ts +3 -3
- package/dist/renderers/media/MediaAnswer.vue.d.ts +19 -0
- package/dist/renderers/outputFile/OutputFile.vue.d.ts +3 -3
- 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 +6 -0
- package/dist/request/index.cjs +4 -2
- package/dist/request/index.d.ts +4 -2
- package/dist/request/index.js +754 -181
- 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/RightPanel.vue.d.ts +6 -6
- package/dist/right-panel/RightPanelIcon.vue.d.ts +4 -4
- package/dist/right-panel/RightPanelTabs.vue.d.ts +9 -5
- package/dist/right-panel/index.cjs +1 -1
- package/dist/right-panel/index.d.ts +1 -1
- package/dist/right-panel/index.js +617 -537
- package/dist/right-panel/panels/newtab/NewTabPanel.vue.d.ts +4 -4
- package/dist/right-panel/panels/web/WebPanel.vue.d.ts +3 -3
- package/dist/right-panel/shared/BrowserToolbar.vue.d.ts +3 -3
- package/dist/right-panel/shared/RightPanelToolList.vue.d.ts +5 -5
- package/dist/right-panel/style.css +1 -1
- package/dist/right-panel/types.d.ts +10 -0
- package/dist/theme/index.js +2 -4
- package/dist/tools/index.cjs +5 -5
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +323 -217
- package/dist/tools/markdown/MarkdownContent.vue.d.ts +5 -5
- 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/tools/useAutoScroll.d.ts +3 -3
- package/dist/web-ui/attach/AttachmentCard.vue.d.ts +6 -6
- package/dist/web-ui/attach/AttachmentList.vue.d.ts +6 -6
- package/dist/web-ui/chat/ChatContainer.vue.d.ts +10 -10
- package/dist/web-ui/chat/ChatMessagesView.vue.d.ts +6 -6
- package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +6 -6
- package/dist/web-ui/index.cjs +1 -1
- package/dist/web-ui/index.js +630 -635
- package/dist/web-ui/inputbox/Inputbox.vue.d.ts +11 -11
- package/dist/web-ui/recordset/RecordsetTable.vue.d.ts +4 -4
- package/dist/web-ui/style.css +1 -1
- package/package.json +2 -1
package/dist/request/index.js
CHANGED
|
@@ -1,264 +1,837 @@
|
|
|
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
|
|
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;
|
|
19
|
+
try {
|
|
20
|
+
g = await ht.post(`${s}${p}`, f, {
|
|
21
|
+
headers: _(E)
|
|
22
|
+
});
|
|
23
|
+
} catch (n) {
|
|
24
|
+
throw ((L = n == null ? void 0 : n.response) == null ? void 0 : L.status) === 401 ? new lt() : n;
|
|
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;
|
|
15
30
|
};
|
|
16
31
|
return {
|
|
17
|
-
baseURL:
|
|
18
|
-
getSession:
|
|
19
|
-
post: async (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
}
|
|
28
48
|
},
|
|
29
|
-
stream: async (
|
|
30
|
-
const
|
|
31
|
-
return (await
|
|
32
|
-
headers:
|
|
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),
|
|
33
53
|
// 浏览器下 XHR 不支持流式读取(response.data 会变成整包 String),
|
|
34
54
|
// 必须强制 fetch 适配器才能拿到 ReadableStream
|
|
35
55
|
adapter: "fetch",
|
|
36
56
|
responseType: "stream",
|
|
37
|
-
signal:
|
|
57
|
+
signal: E
|
|
38
58
|
})).data;
|
|
39
59
|
}
|
|
40
60
|
};
|
|
41
|
-
},
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!i.wisession)
|
|
55
|
-
throw new Error("登录失败:未返回 wisession");
|
|
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");
|
|
56
74
|
return i;
|
|
57
|
-
},
|
|
58
|
-
const
|
|
75
|
+
}, ft = async (t) => {
|
|
76
|
+
const e = "name" in t && typeof t.name == "string" ? t.name : "", o = t.type || "";
|
|
59
77
|
if (typeof FileReader < "u")
|
|
60
|
-
return new Promise((
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const i = String(
|
|
64
|
-
|
|
65
|
-
name:
|
|
66
|
-
"content-type":
|
|
78
|
+
return new Promise((a, u) => {
|
|
79
|
+
const s = new FileReader();
|
|
80
|
+
s.onload = () => {
|
|
81
|
+
const i = String(s.result ?? "");
|
|
82
|
+
a({
|
|
83
|
+
name: e,
|
|
84
|
+
"content-type": o,
|
|
67
85
|
data: i.split(",")[1] ?? i
|
|
68
86
|
});
|
|
69
|
-
},
|
|
87
|
+
}, s.onerror = () => u(s.error), s.readAsDataURL(t);
|
|
70
88
|
});
|
|
71
|
-
if (typeof
|
|
72
|
-
const
|
|
89
|
+
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)));
|
|
73
91
|
return {
|
|
74
|
-
name:
|
|
75
|
-
"content-type":
|
|
76
|
-
data:
|
|
92
|
+
name: e,
|
|
93
|
+
"content-type": o,
|
|
94
|
+
data: u
|
|
77
95
|
};
|
|
78
96
|
}
|
|
79
97
|
return {
|
|
80
|
-
name:
|
|
81
|
-
"content-type":
|
|
98
|
+
name: e,
|
|
99
|
+
"content-type": o,
|
|
82
100
|
data: ""
|
|
83
101
|
};
|
|
84
|
-
},
|
|
85
|
-
Object.prototype.hasOwnProperty.call(
|
|
86
|
-
},
|
|
87
|
-
const
|
|
88
|
-
if (typeof FormData < "u" &&
|
|
89
|
-
for (const [
|
|
90
|
-
const
|
|
91
|
-
|
|
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) => {
|
|
105
|
+
const e = {};
|
|
106
|
+
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);
|
|
92
110
|
}
|
|
93
|
-
else if (
|
|
94
|
-
for (const [
|
|
95
|
-
typeof Blob < "u" &&
|
|
96
|
-
|
|
97
|
-
async (
|
|
111
|
+
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
|
|
98
116
|
)
|
|
99
|
-
) : o
|
|
100
|
-
return
|
|
101
|
-
},
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
e.
|
|
117
|
+
) : e[o] = a;
|
|
118
|
+
return e.files && !Array.isArray(e.files) && (e.files = [e.files]), e.type = "chat_stream", e;
|
|
119
|
+
}, 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) => {
|
|
123
|
+
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}`);
|
|
109
128
|
}
|
|
110
|
-
|
|
129
|
+
return !0;
|
|
130
|
+
}, oe = async (t) => {
|
|
111
131
|
const {
|
|
112
|
-
baseURL:
|
|
113
|
-
data:
|
|
114
|
-
sessionId:
|
|
115
|
-
signal:
|
|
116
|
-
chunkSize:
|
|
132
|
+
baseURL: e,
|
|
133
|
+
data: o,
|
|
134
|
+
sessionId: a,
|
|
135
|
+
signal: u,
|
|
136
|
+
chunkSize: s = 8e3,
|
|
117
137
|
WebSocketClass: i = typeof WebSocket < "u" ? WebSocket : void 0,
|
|
118
|
-
onOpen:
|
|
119
|
-
} =
|
|
138
|
+
onOpen: _
|
|
139
|
+
} = t;
|
|
120
140
|
if (!i)
|
|
121
141
|
throw new Error("当前运行环境不支持 WebSocket");
|
|
122
|
-
const
|
|
142
|
+
const A = await Dt(o), I = Mt(e, a), D = new TextEncoder();
|
|
123
143
|
return new ReadableStream({
|
|
124
|
-
start(
|
|
125
|
-
let
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
128
|
-
|
|
144
|
+
start(p) {
|
|
145
|
+
let w = !1, E = !1;
|
|
146
|
+
const f = new i(I), g = () => {
|
|
147
|
+
if (!w) {
|
|
148
|
+
w = !0;
|
|
129
149
|
try {
|
|
130
|
-
|
|
150
|
+
p.close();
|
|
131
151
|
} catch {
|
|
132
152
|
}
|
|
133
153
|
try {
|
|
134
|
-
|
|
154
|
+
f.close();
|
|
135
155
|
} catch {
|
|
136
156
|
}
|
|
137
157
|
}
|
|
138
|
-
},
|
|
139
|
-
if (!
|
|
140
|
-
|
|
158
|
+
}, y = (n) => {
|
|
159
|
+
if (!w) {
|
|
160
|
+
w = !0;
|
|
141
161
|
try {
|
|
142
|
-
|
|
162
|
+
p.error(n);
|
|
143
163
|
} catch {
|
|
144
164
|
}
|
|
145
165
|
try {
|
|
146
|
-
|
|
166
|
+
f.close();
|
|
147
167
|
} catch {
|
|
148
168
|
}
|
|
149
169
|
}
|
|
150
170
|
};
|
|
151
|
-
|
|
171
|
+
f.onopen = () => {
|
|
152
172
|
try {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} catch (f) {
|
|
157
|
-
m(f);
|
|
173
|
+
Q(f, JSON.stringify(A), s), _ == null || _((n, h) => w || f.readyState !== 1 ? !1 : Q(f, n, h ?? s));
|
|
174
|
+
} catch (n) {
|
|
175
|
+
y(n);
|
|
158
176
|
}
|
|
159
|
-
},
|
|
177
|
+
}, f.onmessage = async (n) => {
|
|
160
178
|
try {
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
if (!
|
|
164
|
-
|
|
165
|
-
const D = c.encode(`data: ${l}
|
|
179
|
+
E = !0;
|
|
180
|
+
const h = await Pt(n.data);
|
|
181
|
+
if (!h) return;
|
|
182
|
+
const j = D.encode(`data: ${h}
|
|
166
183
|
|
|
167
184
|
`);
|
|
168
|
-
|
|
185
|
+
p.enqueue(j);
|
|
169
186
|
try {
|
|
170
|
-
const
|
|
171
|
-
(
|
|
187
|
+
const G = JSON.parse(h);
|
|
188
|
+
(G == null ? void 0 : G.mode) === "finish" && g();
|
|
172
189
|
} catch {
|
|
173
190
|
}
|
|
174
|
-
} catch (
|
|
175
|
-
|
|
191
|
+
} catch (h) {
|
|
192
|
+
y(h);
|
|
176
193
|
}
|
|
177
|
-
},
|
|
178
|
-
if (!
|
|
179
|
-
|
|
194
|
+
}, f.onclose = () => {
|
|
195
|
+
if (!E) {
|
|
196
|
+
y(new Error("WebSocket 连接已断开(未收到任何回答数据)"));
|
|
180
197
|
return;
|
|
181
198
|
}
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
|
|
199
|
+
g();
|
|
200
|
+
}, f.onerror = (n) => {
|
|
201
|
+
y(n);
|
|
185
202
|
};
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
|
|
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);
|
|
189
206
|
};
|
|
190
|
-
|
|
207
|
+
u && (u.aborted ? L() : u.addEventListener("abort", L, { once: !0 }));
|
|
191
208
|
}
|
|
192
209
|
});
|
|
193
|
-
},
|
|
194
|
-
const
|
|
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 = () => {
|
|
211
|
+
const t = /* @__PURE__ */ new Map();
|
|
212
|
+
let e = null;
|
|
195
213
|
return {
|
|
196
|
-
|
|
197
|
-
|
|
214
|
+
getActive: () => e,
|
|
215
|
+
setActive(o) {
|
|
216
|
+
e = o;
|
|
217
|
+
},
|
|
218
|
+
get(o) {
|
|
219
|
+
return o ? t.get(o) : void 0;
|
|
220
|
+
},
|
|
221
|
+
set(o, a) {
|
|
222
|
+
o && t.set(o, a);
|
|
223
|
+
},
|
|
224
|
+
removeGroup(o) {
|
|
225
|
+
o && t.delete(o);
|
|
226
|
+
},
|
|
227
|
+
remove(o) {
|
|
228
|
+
e === o && (e = null);
|
|
229
|
+
for (const [a, u] of t)
|
|
230
|
+
u === o && t.delete(a);
|
|
231
|
+
},
|
|
232
|
+
entries() {
|
|
233
|
+
return new Map(t);
|
|
234
|
+
},
|
|
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) {
|
|
240
|
+
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);
|
|
243
|
+
},
|
|
244
|
+
clear() {
|
|
245
|
+
t.clear(), e = null;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}, Nt = _e(), Lt = (t) => new Promise((e) => setTimeout(e, t)), we = (t) => {
|
|
249
|
+
var a;
|
|
250
|
+
const e = t == null ? void 0 : t.values;
|
|
251
|
+
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());
|
|
254
|
+
}, Se = (t) => {
|
|
255
|
+
var s, i;
|
|
256
|
+
const e = (t == null ? void 0 : t.values) ?? {}, o = e.answer ?? {}, a = e.attach ?? {}, u = e.entry ?? {};
|
|
257
|
+
return {
|
|
258
|
+
answer_type: "report_list",
|
|
259
|
+
question: e.question ?? "",
|
|
260
|
+
reports: o.reports ?? [],
|
|
261
|
+
conclusion: e.conclusion ?? [],
|
|
262
|
+
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
|
|
271
|
+
};
|
|
272
|
+
}, me = (t) => (t == null ? void 0 : t.values) ?? {}, Ht = (t) => {
|
|
273
|
+
var o, a, u, s;
|
|
274
|
+
if (!t || typeof t != "object") return "";
|
|
275
|
+
const e = [
|
|
276
|
+
t.history_id,
|
|
277
|
+
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
|
|
282
|
+
];
|
|
283
|
+
for (const i of e)
|
|
284
|
+
if (typeof i == "string" && i) return i;
|
|
285
|
+
return t.mode === "history_id" && typeof t.value == "string" && t.value ? t.value : "";
|
|
286
|
+
}, $t = (t, e, o, a = !1) => `CONNECT:${JSON.stringify({
|
|
287
|
+
history_id: t,
|
|
288
|
+
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) => {
|
|
292
|
+
const e = [t, t == null ? void 0 : t.values];
|
|
293
|
+
for (const o of e)
|
|
294
|
+
if (Array.isArray(o)) return o;
|
|
295
|
+
return [];
|
|
296
|
+
}, Ee = (t) => ({
|
|
297
|
+
getTaskList: () => t.getChatTaskList(),
|
|
298
|
+
pickTaskList: Ut,
|
|
299
|
+
getHistoryAnswer: (e) => t.getHistoryAnswer(e),
|
|
300
|
+
// wi-chat core 的 useChat 直接消费新版 values(history_answer 帧)
|
|
301
|
+
answerFrameMode: "history_answer"
|
|
302
|
+
}), Ae = async (t) => {
|
|
303
|
+
const {
|
|
304
|
+
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,
|
|
315
|
+
preparePayload: w,
|
|
316
|
+
onChunk: E,
|
|
317
|
+
onOpen: f,
|
|
318
|
+
emitOpenOnReconnect: g = !1,
|
|
319
|
+
resumeTask: y = null,
|
|
320
|
+
forceConnect: L = !1,
|
|
321
|
+
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
|
|
329
|
+
} = t;
|
|
330
|
+
if (!D)
|
|
331
|
+
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;
|
|
340
|
+
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;
|
|
342
|
+
const Z = () => {
|
|
343
|
+
F != null && (clearTimeout(F), F = null);
|
|
344
|
+
}, J = () => {
|
|
345
|
+
z != null && (clearInterval(z), z = null);
|
|
346
|
+
}, Rt = (r) => {
|
|
347
|
+
J(), !(!rt || rt <= 0) && (z = setInterval(() => {
|
|
348
|
+
if (!(C || r !== m || r.readyState !== 1))
|
|
349
|
+
try {
|
|
350
|
+
r.send(Ot);
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
}, rt));
|
|
354
|
+
}, tt = {
|
|
355
|
+
get ws() {
|
|
356
|
+
return m;
|
|
357
|
+
},
|
|
358
|
+
get readyState() {
|
|
359
|
+
return (m == null ? void 0 : m.readyState) ?? 3;
|
|
360
|
+
},
|
|
361
|
+
get groupId() {
|
|
362
|
+
return T;
|
|
363
|
+
},
|
|
364
|
+
send(r) {
|
|
365
|
+
m && m.readyState === 1 && m.send(r);
|
|
366
|
+
},
|
|
367
|
+
close(r, c) {
|
|
368
|
+
try {
|
|
369
|
+
m == null || m.close(r, c);
|
|
370
|
+
} catch {
|
|
371
|
+
}
|
|
372
|
+
}
|
|
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) => {
|
|
378
|
+
try {
|
|
379
|
+
const c = JSON.parse(r);
|
|
380
|
+
if ((c == null ? void 0 : c.type) === "wait_reply" && c.reply_id != null) return String(c.reply_id);
|
|
381
|
+
} catch {
|
|
382
|
+
}
|
|
383
|
+
return "";
|
|
384
|
+
}, mt = (r, c) => {
|
|
385
|
+
const d = kt(r);
|
|
386
|
+
if (!d) return;
|
|
387
|
+
const S = ot.get(d);
|
|
388
|
+
if (S) {
|
|
389
|
+
S.lastPayload = r, S.lastSentGeneration = c;
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
ot.set(d, { lastPayload: r, lastSentGeneration: c });
|
|
393
|
+
}, ct = (r, c = _) => {
|
|
394
|
+
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;
|
|
400
|
+
}
|
|
401
|
+
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,
|
|
404
|
+
sendInChunks: Yt,
|
|
405
|
+
session: tt,
|
|
406
|
+
generation: q
|
|
407
|
+
}), k = (r) => {
|
|
408
|
+
var S;
|
|
409
|
+
if ((r == null ? void 0 : r.mode) !== "front_reply") {
|
|
410
|
+
E(r, B());
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const c = (r == null ? void 0 : r.reply_id) != null ? String(r.reply_id) : "";
|
|
414
|
+
if (!c) {
|
|
415
|
+
E(r, B());
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const d = ot.get(c);
|
|
419
|
+
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);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
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;
|
|
428
|
+
V = !0, Z(), J();
|
|
429
|
+
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(
|
|
431
|
+
n,
|
|
432
|
+
`[chat ws] 收到 disconnect(value=${c || "空"},groupId=${T},historyId=${b}),不再重连,改为轮询任务 + 历史回答兜底`
|
|
433
|
+
);
|
|
434
|
+
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: {} });
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
let W = !1;
|
|
440
|
+
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;
|
|
447
|
+
});
|
|
448
|
+
if (Tt.length === 0 || Tt.some(($) => ($ == null ? void 0 : $.is_stop) === !0)) {
|
|
449
|
+
W = !0;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
N < nt - 1 && await Lt(wt);
|
|
454
|
+
}
|
|
455
|
+
if (C) return;
|
|
456
|
+
W || (H = n.warn) == null || H.call(
|
|
457
|
+
n,
|
|
458
|
+
`[chat ws] disconnect 后任务 ${nt} 次轮询仍未收尾,继续尝试历史回答(historyId=${b})`
|
|
459
|
+
);
|
|
460
|
+
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(
|
|
467
|
+
n,
|
|
468
|
+
`[chat ws] disconnect 兜底成功,已回放历史回答(第 ${N + 1} 次,groupId=${T},historyId=${b})`
|
|
469
|
+
), et(yt);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
N < st - 1 && await Lt(wt);
|
|
473
|
+
}
|
|
474
|
+
if (C) return;
|
|
475
|
+
(Ct = n.warn) == null || Ct.call(
|
|
476
|
+
n,
|
|
477
|
+
`[chat ws] disconnect 兜底重试 ${st} 次仍无历史回答,结束本次回答(groupId=${T},historyId=${b})`
|
|
478
|
+
), M(new Error("任务已结束,但历史回答尚未就绪"));
|
|
479
|
+
} catch (W) {
|
|
480
|
+
(bt = n.warn) == null || bt.call(
|
|
481
|
+
n,
|
|
482
|
+
`[chat ws] disconnect 兜底异常,结束本次回答:${W instanceof Error ? W.message : String(W)}`
|
|
483
|
+
), C || M(new Error("连接已断开,收回回答失败,请稍后重试"));
|
|
484
|
+
}
|
|
485
|
+
}, zt = async () => {
|
|
486
|
+
var c, d;
|
|
487
|
+
if (C || it) return;
|
|
488
|
+
if (X >= s) {
|
|
489
|
+
(c = n.warn) == null || c.call(
|
|
490
|
+
n,
|
|
491
|
+
`[chat ws] 会话失效重试 ${X} 次仍未恢复,结束本次回答(groupId=${T})`
|
|
492
|
+
), M(new Error("登录状态已失效,请重新登录"));
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
X += 1, it = !0, J(), Z();
|
|
496
|
+
const r = m;
|
|
497
|
+
m = null;
|
|
498
|
+
try {
|
|
499
|
+
r == null || r.close();
|
|
500
|
+
} catch {
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
if (await (i == null ? void 0 : i()) === !1) throw new Error("宿主未能刷新登录态");
|
|
504
|
+
} catch (S) {
|
|
505
|
+
(d = n.warn) == null || d.call(
|
|
506
|
+
n,
|
|
507
|
+
`[chat ws] 会话失效后刷新登录态失败,结束本次回答(groupId=${T}):${S instanceof Error ? S.message : String(S)}`
|
|
508
|
+
), M(new Error("登录状态已失效,请重新登录"));
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
C || (it = !1, b || (x = !1), dt());
|
|
512
|
+
}, Et = () => {
|
|
513
|
+
Z(), J(), I && O && (I.removeEventListener("abort", O), O = null);
|
|
514
|
+
const r = m;
|
|
515
|
+
m = null;
|
|
516
|
+
try {
|
|
517
|
+
r == null || r.close();
|
|
518
|
+
} catch {
|
|
519
|
+
}
|
|
520
|
+
j.remove(tt);
|
|
521
|
+
}, et = (r) => {
|
|
522
|
+
C || (C = !0, Et(), Y(r));
|
|
523
|
+
}, 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) {
|
|
529
|
+
(d = n.warn) == null || d.call(
|
|
530
|
+
n,
|
|
531
|
+
`[chat ws] 连接中断且尚未收到 history_id,无法 CONNECT 续传,结束本次回答(groupId=${T},已收 ${R} 帧)`
|
|
532
|
+
), M(new Error("WebSocket 连接已断开:尚未收到 history_id,无法续传"));
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
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);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
P += 1;
|
|
542
|
+
const c = Math.min(xt * 2 ** (P - 1), Ft);
|
|
543
|
+
(l = n.warn) == null || l.call(
|
|
544
|
+
n,
|
|
545
|
+
`[chat ws] 连接中断,${c}ms 后第 ${P} 次重连(groupId=${T},已收 ${R} 帧,续传序号 ${K})`
|
|
546
|
+
), F = setTimeout(() => {
|
|
547
|
+
if (F = null, !C)
|
|
548
|
+
try {
|
|
549
|
+
dt();
|
|
550
|
+
} catch (H) {
|
|
551
|
+
ut(H);
|
|
552
|
+
}
|
|
553
|
+
}, c);
|
|
554
|
+
}, dt = () => {
|
|
555
|
+
if (C) return;
|
|
556
|
+
const r = new D(Bt());
|
|
557
|
+
m = r, r.onopen = () => {
|
|
558
|
+
Vt(r);
|
|
559
|
+
}, r.onmessage = (c) => {
|
|
560
|
+
Xt(r, c);
|
|
561
|
+
}, r.onclose = (c) => {
|
|
562
|
+
Zt(r, c);
|
|
563
|
+
}, r.onerror = (c) => {
|
|
564
|
+
te(r, c);
|
|
565
|
+
};
|
|
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()));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (!x) {
|
|
578
|
+
x = !0, P = 0, Jt(r, JSON.stringify(U)), c && (f == null || f(B()));
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
if (!b) {
|
|
582
|
+
M(new Error("WebSocket 重连失败:缺少 history_id,无法续传"));
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
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) => {
|
|
592
|
+
if (r === m)
|
|
593
|
+
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;
|
|
599
|
+
try {
|
|
600
|
+
l = JSON.parse(S);
|
|
601
|
+
} catch {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (R += 1, (l == null ? void 0 : l.type) === "error" && String((l == null ? void 0 : l.value) ?? "") === u) {
|
|
605
|
+
zt();
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
if ((l == null ? void 0 : l.mode) === "disconnect" && at) {
|
|
609
|
+
if (h) {
|
|
610
|
+
Kt(l);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
k(l), et(l);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
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);
|
|
619
|
+
} catch (d) {
|
|
620
|
+
M(d);
|
|
621
|
+
}
|
|
622
|
+
}, Zt = (r, c) => {
|
|
623
|
+
var d;
|
|
624
|
+
C || V || r === m && (J(), (d = n.close) == null || d.call(n, {
|
|
625
|
+
groupId: T,
|
|
626
|
+
code: c == null ? void 0 : c.code,
|
|
627
|
+
reason: c == null ? void 0 : c.reason,
|
|
628
|
+
wasClean: c == null ? void 0 : c.wasClean,
|
|
629
|
+
receivedChunks: R
|
|
630
|
+
}), ut(c));
|
|
631
|
+
}, te = (r, c) => {
|
|
632
|
+
var d;
|
|
633
|
+
C || r === m && ((d = n.error) == null || d.call(n, {
|
|
634
|
+
groupId: T,
|
|
635
|
+
type: c == null ? void 0 : c.type,
|
|
636
|
+
readyState: r == null ? void 0 : r.readyState,
|
|
637
|
+
receivedChunks: R
|
|
638
|
+
}), r.readyState === 3 && ut(c));
|
|
639
|
+
};
|
|
640
|
+
if (j.setActive(tt), T && j.set(T, tt), I) {
|
|
641
|
+
if (O = () => M(I.reason ?? new Error("会话已取消")), I.aborted) {
|
|
642
|
+
O();
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
I.addEventListener("abort", O, { once: !0 });
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
dt();
|
|
649
|
+
} catch (r) {
|
|
650
|
+
M(r);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}, 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;
|
|
659
|
+
try {
|
|
660
|
+
i == null || i.close();
|
|
661
|
+
} catch {
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}, I = (p) => {
|
|
665
|
+
if (!_) {
|
|
666
|
+
_ = !0;
|
|
667
|
+
try {
|
|
668
|
+
i == null || i.error(p);
|
|
669
|
+
} catch {
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}, D = new ReadableStream({
|
|
673
|
+
start(p) {
|
|
674
|
+
i = p;
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
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);
|
|
684
|
+
try {
|
|
685
|
+
i == null || i.enqueue(s.encode(`data: ${E}
|
|
686
|
+
|
|
687
|
+
`));
|
|
688
|
+
} catch (g) {
|
|
689
|
+
I(g);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
(f = u.onChunk) == null || f.call(u, p, w);
|
|
693
|
+
},
|
|
694
|
+
onOpen: (p) => {
|
|
695
|
+
a == null || a(p.sendInChunks);
|
|
696
|
+
}
|
|
697
|
+
}).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}` : "";
|
|
198
706
|
},
|
|
199
707
|
async getHistoryGroups() {
|
|
200
|
-
return
|
|
708
|
+
return t.post("/history/get_history_groups", {});
|
|
201
709
|
},
|
|
202
|
-
async createHistoryGroup(
|
|
203
|
-
return
|
|
710
|
+
async createHistoryGroup(s) {
|
|
711
|
+
return t.post("/history/create_history_group", { group_title: s });
|
|
204
712
|
},
|
|
205
|
-
async deleteHistoryGroup(
|
|
206
|
-
return
|
|
713
|
+
async deleteHistoryGroup(s) {
|
|
714
|
+
return t.post("/history/delete_history_group", { history_group_id: s });
|
|
207
715
|
},
|
|
208
|
-
async setHistoryGroupTitle(
|
|
209
|
-
return
|
|
716
|
+
async setHistoryGroupTitle(s, i) {
|
|
717
|
+
return t.post("/history/set_history_group_title", { history_group_id: s, title: i });
|
|
210
718
|
},
|
|
211
|
-
async getHistoryDetail(
|
|
212
|
-
const
|
|
213
|
-
history_group_id:
|
|
214
|
-
last_end:
|
|
215
|
-
last_count:
|
|
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: _
|
|
216
724
|
});
|
|
217
|
-
return (
|
|
725
|
+
return (A == null ? void 0 : A.details) || [];
|
|
218
726
|
},
|
|
219
|
-
async getHistoryAnswer(
|
|
220
|
-
return
|
|
727
|
+
async getHistoryAnswer(s) {
|
|
728
|
+
return t.post("/history/get_history_answer", { history_id: s });
|
|
221
729
|
},
|
|
222
730
|
async getDefaultLlmId() {
|
|
223
|
-
return
|
|
731
|
+
return t.post("/admin/get_default_llm_id", {});
|
|
224
732
|
},
|
|
225
|
-
async
|
|
226
|
-
return
|
|
733
|
+
async getLlmInfoList() {
|
|
734
|
+
return t.post("/admin/workflow/get_llm_info_list", {});
|
|
227
735
|
},
|
|
228
|
-
async
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
736
|
+
async getLlmEntryListByRole(s = { entry_group: "智能助手" }) {
|
|
737
|
+
return t.post("/admin/get_llm_entry_list_by_role", s);
|
|
738
|
+
},
|
|
739
|
+
async pingLogin() {
|
|
740
|
+
return t.post("/system/ping", {});
|
|
741
|
+
},
|
|
742
|
+
async getChatTaskList() {
|
|
743
|
+
const s = await t.post("/chat/getChatTaskList", {});
|
|
744
|
+
return Ut(s);
|
|
745
|
+
},
|
|
746
|
+
async setHistoryAnswerState(s, i) {
|
|
747
|
+
return t.post("/history/set_history_answer_state", { history_id: s, answer_state: i ?? "" });
|
|
748
|
+
},
|
|
749
|
+
async reportHistoryProblem(s, i) {
|
|
750
|
+
return t.post("/history/report_history_problem", { history_id: s, report_note: i });
|
|
751
|
+
},
|
|
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);
|
|
759
|
+
},
|
|
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;
|
|
763
|
+
},
|
|
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) ?? [] };
|
|
767
|
+
},
|
|
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
|
|
236
775
|
};
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
776
|
+
D && D.length > 0 && (y.files = D);
|
|
777
|
+
const L = () => {
|
|
778
|
+
var n;
|
|
779
|
+
return ((n = t.getSession) == null ? void 0 : n.call(t)) ?? (typeof localStorage < "u" ? localStorage.getItem("access-session") : null);
|
|
780
|
+
};
|
|
781
|
+
return e.resumable ? Ce({
|
|
782
|
+
baseURL: t.baseURL ?? "",
|
|
783
|
+
data: y,
|
|
784
|
+
// 每次(重)连都实时取 session:会话失效刷新后重连要带新值
|
|
785
|
+
getSessionId: L,
|
|
786
|
+
refreshSession: e.refreshSession,
|
|
787
|
+
signal: i,
|
|
788
|
+
onOpen: w,
|
|
789
|
+
groupId: A,
|
|
790
|
+
resumeTask: E ?? null,
|
|
791
|
+
registry: a,
|
|
792
|
+
fallback: Ee({
|
|
793
|
+
getChatTaskList: () => u.getChatTaskList(),
|
|
794
|
+
getHistoryAnswer: (n) => u.getHistoryAnswer(n)
|
|
795
|
+
})
|
|
796
|
+
}) : oe({
|
|
797
|
+
baseURL: t.baseURL,
|
|
798
|
+
data: y,
|
|
799
|
+
sessionId: L(),
|
|
800
|
+
signal: i,
|
|
244
801
|
// 传输层选项:连接就绪后向外部交出分片发送器(不混入发给后端的载荷)
|
|
245
|
-
onOpen:
|
|
802
|
+
onOpen: w
|
|
246
803
|
});
|
|
804
|
+
},
|
|
805
|
+
stopChat(s) {
|
|
806
|
+
return e.resumable ? a.sendStop(s) : !1;
|
|
247
807
|
}
|
|
248
808
|
};
|
|
809
|
+
return u;
|
|
249
810
|
};
|
|
250
811
|
export {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
$ as
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
812
|
+
lt as AuthExpiredError,
|
|
813
|
+
Mt as buildChatWsUrl,
|
|
814
|
+
$t as buildConnectFrame,
|
|
815
|
+
me as buildHistoryAnswerValues,
|
|
816
|
+
Nt as chatWsRegistry,
|
|
817
|
+
$e as createChatApi,
|
|
818
|
+
Ee as createChatWsFallback,
|
|
819
|
+
_e as createChatWsRegistry,
|
|
820
|
+
He as createChunkSender,
|
|
821
|
+
ge as createRequest,
|
|
822
|
+
Se as defaultBuildHistoryAnswerPayload,
|
|
823
|
+
we as defaultHasHistoryAnswerContent,
|
|
824
|
+
ft as fileToBase64,
|
|
825
|
+
Dt as formDataToJson,
|
|
826
|
+
Ie as isCancelError,
|
|
827
|
+
Le as login,
|
|
828
|
+
oe as openChatWebSocketStream,
|
|
829
|
+
Ce as openChatWsSessionStream,
|
|
830
|
+
Ut as pickChatTaskList,
|
|
831
|
+
Ht as pickHistoryId,
|
|
832
|
+
ne as pwdEncrypt,
|
|
833
|
+
Pt as resolveMessageData,
|
|
834
|
+
Q as sendPayloadInChunks,
|
|
835
|
+
Ae as startChatWsSession
|
|
263
836
|
};
|
|
264
837
|
//# sourceMappingURL=index.js.map
|