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