wi-chat 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.js +273 -261
- package/dist/core/useChat.d.ts +61 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -33
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +6 -6
- 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 +5 -5
- 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/index.cjs +2 -2
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/index.js +216 -258
- package/dist/parser/registry.d.ts +1 -1
- package/dist/renderers/aiAnswer/AiAnswerBubble.vue.d.ts +4 -4
- package/dist/renderers/clarification/ClarificationCard.vue.d.ts +3 -3
- package/dist/renderers/deepThinking/DeepThinkingSteps.vue.d.ts +4 -4
- 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 +1 -1
- package/dist/renderers/index.js +484 -498
- package/dist/renderers/knowledgeStream/KnowledgeStreamResult.vue.d.ts +3 -3
- package/dist/renderers/outputFile/OutputFile.vue.d.ts +3 -3
- package/dist/renderers/style.css +1 -1
- package/dist/request/index.cjs +2 -2
- package/dist/request/index.js +6 -13
- package/dist/request/ws.d.ts +3 -3
- 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 +5 -5
- package/dist/right-panel/index.cjs +1 -1
- package/dist/right-panel/index.js +397 -416
- 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/theme/index.js +2 -4
- package/dist/tools/index.cjs +2 -2
- package/dist/tools/index.js +10 -19
- package/dist/tools/markdown/MarkdownContent.vue.d.ts +5 -5
- 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 +6 -6
- package/dist/web-ui/chat/ChatMessagesView.vue.d.ts +6 -6
- package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +5 -5
- 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 +7 -7
- package/dist/web-ui/recordset/RecordsetTable.vue.d.ts +4 -4
- package/package.json +2 -1
package/dist/core/index.js
CHANGED
|
@@ -1,95 +1,118 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import { clearPendingClarifications as
|
|
3
|
-
import { createRequest as
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
import { ref as p, getCurrentInstance as oe, onBeforeUnmount as Le, reactive as se, onMounted as xe, watch as re } from "vue";
|
|
2
|
+
import { clearPendingClarifications as Ae, loadGroupMessagesByStep as ne, createHistoryGroup as ie, nextLocalMessageId as le, createEmptyAnswerValues as Ce, buildChatTitle as Ie, consumeStream as _e, applyAnswerChunk as be, collectThinkingSteps as Re, expirePendingClarificationsForReply as Ee, loadGroupMessages as Se, deleteHistoryGroup as qe, setHistoryGroupTitle as Fe, getHistoryGroups as Me, resolveRemoteFileUrl as Qe } from "wi-chat/parser";
|
|
3
|
+
import { createRequest as Ue, createChatApi as Pe, login as Oe, isCancelError as Te } from "wi-chat/request";
|
|
4
|
+
const Ke = (e) => {
|
|
5
|
+
const l = {
|
|
6
|
+
requestId: e,
|
|
7
|
+
sender: null,
|
|
8
|
+
queue: [],
|
|
9
|
+
closed: !1,
|
|
10
|
+
reply: (h) => ce(l, h)
|
|
11
|
+
};
|
|
12
|
+
return l;
|
|
13
|
+
}, ce = (e, l, h) => {
|
|
14
|
+
if (e.closed) return !1;
|
|
15
|
+
const w = typeof l == "string" ? l : JSON.stringify(l) ?? "";
|
|
16
|
+
return e.sender ? e.sender(w, h) !== !1 : (e.queue.push({ payloadText: w, chunkSize: h }), !0);
|
|
17
|
+
}, ue = (e) => {
|
|
18
|
+
e.closed || (e.closed = !0, e.queue.length = 0, e.sender = null, Ee(e.reply));
|
|
19
|
+
}, ke = (e) => {
|
|
20
|
+
const l = e.login, h = e.defaultGroupTitle ?? "新对话", w = e.lastCount ?? 10, u = e.autoSetGroupTitleOnFirstQuestion ?? !0, L = {
|
|
6
21
|
beforeKnowledgeRender: e.beforeKnowledgeRender,
|
|
7
22
|
parsers: e.parsers,
|
|
8
23
|
actionExecute: {
|
|
9
24
|
...e.actionExecute,
|
|
10
|
-
reply: (
|
|
25
|
+
reply: () => !1
|
|
11
26
|
}
|
|
12
|
-
},
|
|
27
|
+
}, v = p(""), o = p([]), C = p(""), Q = p(e.incPrevQuestion ?? "Y"), s = p(!1), i = p(!1), t = p(""), n = p(!1), m = p(""), d = p(!0), y = p(!1), A = p(0), W = e.api ? null : Ue({
|
|
13
28
|
baseURL: e.baseURL ?? "",
|
|
14
|
-
getWisession: () =>
|
|
15
|
-
}),
|
|
16
|
-
let I = null,
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
29
|
+
getWisession: () => v.value
|
|
30
|
+
}), U = e.api ?? Pe(W);
|
|
31
|
+
let I = null, R = null, D = 0, _ = 0, j = 0, E = null;
|
|
32
|
+
const V = async () => {
|
|
33
|
+
if (m.value = "", !W || !l) {
|
|
34
|
+
n.value = !0;
|
|
20
35
|
return;
|
|
21
36
|
}
|
|
22
37
|
try {
|
|
23
|
-
const
|
|
24
|
-
return
|
|
25
|
-
} catch (
|
|
26
|
-
throw
|
|
38
|
+
const r = await Oe(W, l);
|
|
39
|
+
return v.value = r.wisession || "", n.value = !0, r;
|
|
40
|
+
} catch (r) {
|
|
41
|
+
throw m.value = r instanceof Error ? r.message : String(r), r;
|
|
27
42
|
}
|
|
28
|
-
},
|
|
29
|
-
typeof URL > "u" || typeof URL.revokeObjectURL != "function" ||
|
|
30
|
-
|
|
43
|
+
}, a = (r) => r === D, f = (r) => {
|
|
44
|
+
typeof URL > "u" || typeof URL.revokeObjectURL != "function" || r.forEach((G) => {
|
|
45
|
+
G.role !== "user" || !G.attachments || G.attachments.forEach((x) => {
|
|
31
46
|
var b;
|
|
32
|
-
const
|
|
33
|
-
|
|
47
|
+
const S = (b = x.attachContent) == null ? void 0 : b.url;
|
|
48
|
+
S && S.startsWith("blob:") && URL.revokeObjectURL(S);
|
|
34
49
|
});
|
|
35
50
|
});
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
}, P = (r) => ({
|
|
52
|
+
beforeKnowledgeRender: e.beforeKnowledgeRender,
|
|
53
|
+
parsers: e.parsers,
|
|
54
|
+
actionExecute: {
|
|
55
|
+
...e.actionExecute,
|
|
56
|
+
reply: r.reply
|
|
57
|
+
}
|
|
58
|
+
}), F = async (r) => {
|
|
59
|
+
const G = ++_;
|
|
60
|
+
j += 1, s.value = !0, f(o.value), E && Ae(E.reply), o.value = [], t.value = r, d.value = !0, y.value = !1, A.value = 0;
|
|
61
|
+
const x = [], S = () => {
|
|
62
|
+
const g = [];
|
|
63
|
+
x.forEach((O) => {
|
|
64
|
+
g.push(O.user), O.assistant && g.push(O.assistant);
|
|
65
|
+
}), G === _ && (o.value = g);
|
|
66
|
+
}, b = (g) => {
|
|
67
|
+
G === _ && (g.type === "users" ? (x.length = 0, g.users.forEach((O) => x.push({ user: O }))) : x[g.index] && (g.user && (x[g.index].user = g.user), x[g.index].assistant = g.assistant), S());
|
|
46
68
|
};
|
|
47
69
|
try {
|
|
48
|
-
await
|
|
70
|
+
await ne(U, r, w, b, 0, L), S(), G === _ && (A.value = x.length, x.length < w && (d.value = !1));
|
|
49
71
|
} finally {
|
|
50
|
-
j -= 1, j <= 0 && (j = 0,
|
|
72
|
+
j -= 1, j <= 0 && (j = 0, s.value = !1);
|
|
51
73
|
}
|
|
52
|
-
},
|
|
53
|
-
if (!t.value ||
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
v.value = !0;
|
|
74
|
+
}, Y = async () => {
|
|
75
|
+
if (!t.value || s.value || !d.value || y.value) return;
|
|
76
|
+
const r = t.value, G = _, x = A.value;
|
|
77
|
+
y.value = !0;
|
|
57
78
|
try {
|
|
58
|
-
const
|
|
59
|
-
if (b <
|
|
60
|
-
const
|
|
61
|
-
o.value.forEach((
|
|
62
|
-
|
|
79
|
+
const S = await ne(U, r, w, void 0, x, L), b = S.filter((g) => g.role === "user").length;
|
|
80
|
+
if (b < w && (d.value = !1), G === _ && t.value === r) {
|
|
81
|
+
const g = /* @__PURE__ */ new Set();
|
|
82
|
+
o.value.forEach((q) => {
|
|
83
|
+
q.historyId && g.add(q.historyId), q.id && g.add(q.id);
|
|
63
84
|
});
|
|
64
|
-
const
|
|
65
|
-
o.value = [...
|
|
85
|
+
const O = S.filter((q) => !(q.historyId && g.has(q.historyId) || q.id && g.has(q.id)));
|
|
86
|
+
o.value = [...O, ...o.value], A.value += b;
|
|
66
87
|
}
|
|
67
88
|
} finally {
|
|
68
|
-
|
|
89
|
+
y.value = !1;
|
|
69
90
|
}
|
|
70
|
-
},
|
|
71
|
-
const
|
|
72
|
-
return t.value =
|
|
73
|
-
},
|
|
74
|
-
|
|
91
|
+
}, de = async (r = h) => {
|
|
92
|
+
const G = await ie(U, r);
|
|
93
|
+
return t.value = G, G;
|
|
94
|
+
}, Z = () => {
|
|
95
|
+
D += 1, _ += 1, R && (R.stopped = !0, R.thinking.expanded = !1), I == null || I.abort(), I = null, E && ue(E), E = null, R = null, i.value = !1;
|
|
75
96
|
}, fe = () => {
|
|
76
|
-
|
|
77
|
-
},
|
|
97
|
+
R && (R.error = !0, R.thinking.expanded = !1);
|
|
98
|
+
}, ge = async (r) => {
|
|
78
99
|
var ee, te;
|
|
79
|
-
const
|
|
80
|
-
var
|
|
81
|
-
return (
|
|
82
|
-
}).filter((
|
|
83
|
-
if (!B || i.value || !t.value)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
const G = typeof r == "string" ? { text: r } : r || {}, { text: x, entryId: S, files: b, attachments: g, extArgs: O, ...q } = G, B = (x !== void 0 ? x : C.value).trim(), pe = O ?? e.extArgs ?? {}, he = b && b.length > 0 ? b : (g ?? []).map((k) => {
|
|
101
|
+
var z;
|
|
102
|
+
return (z = k.attachContent) == null ? void 0 : z.raw;
|
|
103
|
+
}).filter((k) => !!k);
|
|
104
|
+
if (!B || i.value || !t.value) return;
|
|
105
|
+
const T = D + 1;
|
|
106
|
+
D = T, _ += 1;
|
|
107
|
+
const K = Ke(T);
|
|
108
|
+
E = K;
|
|
109
|
+
const we = P(K);
|
|
87
110
|
let $ = !1;
|
|
88
111
|
try {
|
|
89
112
|
i.value = !0;
|
|
90
|
-
const
|
|
91
|
-
var
|
|
92
|
-
const J = c.name.includes(".") && ((
|
|
113
|
+
const k = t.value, z = g || (b || []).map((c) => {
|
|
114
|
+
var H;
|
|
115
|
+
const J = c.name.includes(".") && ((H = c.name.split(".").pop()) == null ? void 0 : H.toLowerCase()) || "";
|
|
93
116
|
return {
|
|
94
117
|
type: "file",
|
|
95
118
|
name: c.name,
|
|
@@ -101,360 +124,349 @@ const Ue = (e) => {
|
|
|
101
124
|
raw: c
|
|
102
125
|
}
|
|
103
126
|
};
|
|
104
|
-
}),
|
|
105
|
-
id:
|
|
127
|
+
}), me = A.value === 0 && !o.value.some((c) => c.role === "user"), X = k, ae = se({
|
|
128
|
+
id: le("user"),
|
|
106
129
|
role: "user",
|
|
107
130
|
content: B,
|
|
108
|
-
attachments:
|
|
131
|
+
attachments: z.length > 0 ? z : void 0
|
|
109
132
|
});
|
|
110
133
|
o.value.push(ae);
|
|
111
|
-
const
|
|
112
|
-
id:
|
|
134
|
+
const M = se({
|
|
135
|
+
id: le("answer"),
|
|
113
136
|
role: "assistant",
|
|
114
|
-
answer:
|
|
137
|
+
answer: Ce("", B),
|
|
115
138
|
error: !1,
|
|
116
139
|
stopped: !1,
|
|
117
140
|
thinking: { steps: [], expanded: !0 }
|
|
118
141
|
});
|
|
119
|
-
if (
|
|
120
|
-
const c =
|
|
121
|
-
e.onFirstQuestion ? e.onFirstQuestion({ question: c, groupId:
|
|
142
|
+
if (R = M, o.value.push(M), C.value = "", (ee = e.onSubmitQuestion) == null || ee.call(e, B), me && X) {
|
|
143
|
+
const c = Ie(B);
|
|
144
|
+
e.onFirstQuestion ? e.onFirstQuestion({ question: c, groupId: X }) : u && c && U.setHistoryGroupTitle(X, c).catch(() => {
|
|
122
145
|
});
|
|
123
146
|
}
|
|
124
147
|
I = new AbortController();
|
|
125
|
-
const
|
|
148
|
+
const Ge = await U.questionStream(
|
|
126
149
|
{
|
|
127
150
|
// 先铺开外部透传的额外字段(raw_mode / tables / metrics / group_type 等),
|
|
128
151
|
// 已知字段随后覆盖,避免同名额外字段篡改核心参数
|
|
129
|
-
...
|
|
152
|
+
...q,
|
|
130
153
|
question: B,
|
|
131
|
-
historyGroupId:
|
|
132
|
-
entryId:
|
|
133
|
-
files:
|
|
134
|
-
ext_args: JSON.stringify(
|
|
135
|
-
incPrevQuestion:
|
|
154
|
+
historyGroupId: k,
|
|
155
|
+
entryId: S,
|
|
156
|
+
files: he,
|
|
157
|
+
ext_args: JSON.stringify(pe),
|
|
158
|
+
incPrevQuestion: Q.value,
|
|
136
159
|
// 连接建立且首包发完后接收分片发送器,并按序补发连接建立前入队的追发消息
|
|
137
|
-
// (sendWsMessage 在连接未就绪时调用会先入队,见
|
|
160
|
+
// (sendWsMessage / wait_reply 在连接未就绪时调用会先入队,见 sendViaChannel)
|
|
138
161
|
onOpen: (c) => {
|
|
139
|
-
if (!
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
O = [], J.forEach(({ payloadText: W, chunkSize: N }) => c(W, N));
|
|
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));
|
|
144
166
|
}
|
|
145
167
|
},
|
|
146
168
|
I.signal
|
|
147
169
|
);
|
|
148
|
-
A.value += 1, await
|
|
149
|
-
var
|
|
150
|
-
if (!
|
|
151
|
-
return;
|
|
170
|
+
A.value += 1, await _e(Ge, (c) => {
|
|
171
|
+
var H;
|
|
172
|
+
if (!a(T)) return;
|
|
152
173
|
if (c.mode === "history_id") {
|
|
153
174
|
const N = typeof c.value == "object" && c.value !== null ? c.value.history_id : c.value;
|
|
154
|
-
N && (ae.historyId = String(N),
|
|
175
|
+
N && (ae.historyId = String(N), M.historyId = String(N), M.answer && (M.answer.id = String(N)));
|
|
155
176
|
}
|
|
156
|
-
|
|
157
|
-
}),
|
|
158
|
-
} catch (
|
|
159
|
-
|
|
177
|
+
be(M.answer, c, we).includes("deep_thinking") && (M.thinking.steps = Re(M.answer)), c.mode === "finish" && (M.thinking.expanded = !1), (H = e.onChunk) == null || H.call(e, c);
|
|
178
|
+
}), a(T) && (M.thinking.expanded = !1), a(T) && ($ = !0);
|
|
179
|
+
} catch (k) {
|
|
180
|
+
a(T) && !Te(k) && fe();
|
|
160
181
|
} finally {
|
|
161
|
-
|
|
182
|
+
ue(K), E === K && (E = null), a(T) && (i.value = !1, I = null, R = null);
|
|
162
183
|
}
|
|
163
184
|
$ && ((te = e.onFinish) == null || te.call(e));
|
|
164
|
-
},
|
|
165
|
-
if (!i.value)
|
|
166
|
-
return !1;
|
|
167
|
-
const h = typeof s == "string" ? s : JSON.stringify(s) ?? "";
|
|
168
|
-
return H ? H(h, w) : O.push({ payloadText: h, chunkSize: w }), !0;
|
|
169
|
-
}, ge = e.autoLogin !== !1 ? a().then(() => {
|
|
185
|
+
}, ve = (r, G) => !i.value || !E ? !1 : ce(E, r, G), ye = e.autoLogin !== !1 ? V().then(() => {
|
|
170
186
|
}).catch(() => {
|
|
171
187
|
}) : Promise.resolve();
|
|
172
|
-
return oe() &&
|
|
173
|
-
|
|
188
|
+
return oe() && Le(() => {
|
|
189
|
+
Z(), f(o.value);
|
|
174
190
|
}), {
|
|
175
191
|
/** 当前分组的消息列表(user / assistant 交错;loadGroup / loadOlder / submitQuestion 会更新) */
|
|
176
192
|
messages: o,
|
|
177
193
|
/** 输入框内容(v-model 绑定;submitQuestion 成功后清空) */
|
|
178
|
-
question:
|
|
194
|
+
question: C,
|
|
179
195
|
/**
|
|
180
196
|
* 提问是否携带之前对话上下文(inc_prev_question:'Y' 不忽略 / 'N' 忽略,默认 'Y')。
|
|
181
197
|
* submitQuestion 提交时读取当前值发送;可在外部随时修改(如绑定输入框组件的勾选开关)。
|
|
182
198
|
*/
|
|
183
|
-
incPrevQuestion:
|
|
199
|
+
incPrevQuestion: Q,
|
|
184
200
|
/** 会话发送 / 流式回答进行中(true 时 submitQuestion 不再受理新提问) */
|
|
185
201
|
talking: i,
|
|
186
202
|
/** 历史加载中(首屏 loadGroup 及并发加载全部完成后结束) */
|
|
187
|
-
loading:
|
|
203
|
+
loading: s,
|
|
188
204
|
/** 当前会话 token(自动登录写入;未自动登录时可自行赋值) */
|
|
189
|
-
session:
|
|
205
|
+
session: v,
|
|
190
206
|
/** 自动登录流程已结束(成功 / 失败 / 跳过均置 true;UI 可等待它再渲染登录状态) */
|
|
191
|
-
autoLoginDone:
|
|
207
|
+
autoLoginDone: n,
|
|
192
208
|
/** 最近一次自动登录的错误信息(UI 可据此提示重试) */
|
|
193
|
-
autoLoginError:
|
|
209
|
+
autoLoginError: m,
|
|
194
210
|
/** 自动登录完成时机(无论成败都会 resolve;宿主用它编排"登录后才能发"的请求,如加载历史分组) */
|
|
195
|
-
loginDone:
|
|
211
|
+
loginDone: ye,
|
|
196
212
|
/** 当前会话所在的历史分组 id */
|
|
197
213
|
historyGroupId: t,
|
|
198
214
|
/** 内部自建的 request 客户端(注入 api 时为 null,无使用价值) */
|
|
199
|
-
selfRequest:
|
|
215
|
+
selfRequest: W,
|
|
200
216
|
/** 实际使用的业务 API(外部注入的实例或内部自建) */
|
|
201
|
-
api:
|
|
217
|
+
api: U,
|
|
202
218
|
/** 手动触发一次自动登录(成功返回登录结果;失败抛错并记录到 autoLoginError) */
|
|
203
|
-
doAutoLogin:
|
|
219
|
+
doAutoLogin: V,
|
|
204
220
|
/** 按分组加载消息(插空式渐进渲染;并发调用时仅最新一次生效) */
|
|
205
|
-
loadGroup:
|
|
221
|
+
loadGroup: F,
|
|
206
222
|
/** 加载更早一页历史(向上翻页),前插到消息列表顶部 */
|
|
207
|
-
loadOlder:
|
|
223
|
+
loadOlder: Y,
|
|
208
224
|
/** 是否仍可能有更早历史(向上翻页) */
|
|
209
|
-
hasMore:
|
|
225
|
+
hasMore: d,
|
|
210
226
|
/** 向上翻页加载中(触顶防重) */
|
|
211
|
-
loadMoreLoading:
|
|
227
|
+
loadMoreLoading: y,
|
|
212
228
|
/** 新建历史分组并选中(返回分组 id) */
|
|
213
|
-
createGroup:
|
|
229
|
+
createGroup: de,
|
|
214
230
|
/** 提交问题并走 SSE 流式问答(支持传参 entryId、files 与文本;无文本 / 发送中 / 无分组时不发送) */
|
|
215
|
-
submitQuestion:
|
|
231
|
+
submitQuestion: ge,
|
|
216
232
|
/**
|
|
217
233
|
* 向当前提问的 WebSocket 连接追发自定义消息(B/M/E 分帧):
|
|
218
234
|
* 连接就绪立即发出、未就绪入队待连接建立后按序补发;仅在 talking 期间受理,
|
|
219
235
|
* 无在途会话返回 false。见 sendWsMessage 的 JSDoc。
|
|
220
236
|
*/
|
|
221
|
-
sendWsMessage:
|
|
237
|
+
sendWsMessage: ve,
|
|
222
238
|
/** 停止在途会话:中断流、把当前回答标记为 stopped,并复位 talking */
|
|
223
|
-
stopQuestion:
|
|
239
|
+
stopQuestion: Z
|
|
224
240
|
};
|
|
225
|
-
},
|
|
226
|
-
var
|
|
241
|
+
}, De = "wi-chat-history-groups", He = (e) => {
|
|
242
|
+
var V;
|
|
227
243
|
const {
|
|
228
|
-
api:
|
|
229
|
-
defaultGroupTitle:
|
|
230
|
-
lastCount:
|
|
244
|
+
api: l,
|
|
245
|
+
defaultGroupTitle: h = "新对话",
|
|
246
|
+
lastCount: w = 10,
|
|
231
247
|
ensureGroup: u = !0,
|
|
232
|
-
autoSelectFirst:
|
|
233
|
-
autoLoadMessages:
|
|
234
|
-
} = e, o = e.persistGroups ?? !1,
|
|
235
|
-
let
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
238
|
-
return null;
|
|
248
|
+
autoSelectFirst: L = !0,
|
|
249
|
+
autoLoadMessages: v = !0
|
|
250
|
+
} = e, o = e.persistGroups ?? !1, C = e.storageKey ?? De, Q = e.beforeKnowledgeRender || (V = e.parsers) != null && V.length ? { beforeKnowledgeRender: e.beforeKnowledgeRender, parsers: e.parsers } : void 0, s = p([]), i = p(""), t = p([]), n = p(!1);
|
|
251
|
+
let m = !1, d = null;
|
|
252
|
+
const y = () => {
|
|
253
|
+
if (d === !1) return null;
|
|
239
254
|
let a;
|
|
240
255
|
try {
|
|
241
|
-
a = localStorage.getItem(
|
|
256
|
+
a = localStorage.getItem(C);
|
|
242
257
|
} catch {
|
|
243
|
-
return
|
|
258
|
+
return d = !1, null;
|
|
244
259
|
}
|
|
245
|
-
if (a === null)
|
|
246
|
-
return [];
|
|
260
|
+
if (a === null) return [];
|
|
247
261
|
try {
|
|
248
|
-
const
|
|
249
|
-
return Array.isArray(
|
|
262
|
+
const f = JSON.parse(a);
|
|
263
|
+
return Array.isArray(f) ? f : [];
|
|
250
264
|
} catch {
|
|
251
265
|
return [];
|
|
252
266
|
}
|
|
253
267
|
}, A = (a) => {
|
|
254
|
-
if (
|
|
268
|
+
if (d !== !1)
|
|
255
269
|
try {
|
|
256
|
-
localStorage.setItem(
|
|
270
|
+
localStorage.setItem(C, JSON.stringify(a));
|
|
257
271
|
} catch {
|
|
258
|
-
|
|
272
|
+
d = !1;
|
|
259
273
|
}
|
|
260
|
-
},
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
},
|
|
264
|
-
|
|
274
|
+
}, W = (a) => {
|
|
275
|
+
const f = y();
|
|
276
|
+
f !== null && A([...f, a]);
|
|
277
|
+
}, U = async (a, f = w) => {
|
|
278
|
+
n.value = !0;
|
|
265
279
|
try {
|
|
266
|
-
t.value = a ? await
|
|
280
|
+
t.value = a ? await Se(l, a, f, 0, Q) : [];
|
|
267
281
|
} finally {
|
|
268
|
-
|
|
282
|
+
n.value = !1;
|
|
269
283
|
}
|
|
270
284
|
}, I = async (a) => {
|
|
271
|
-
i.value = a,
|
|
272
|
-
},
|
|
273
|
-
if (!
|
|
274
|
-
|
|
285
|
+
i.value = a, v && await U(a);
|
|
286
|
+
}, R = async () => {
|
|
287
|
+
if (!m) {
|
|
288
|
+
m = !0;
|
|
275
289
|
try {
|
|
276
|
-
|
|
290
|
+
s.value.length === 0 ? u && await _(h) : !i.value && L && await I(s.value[0].group_id);
|
|
277
291
|
} finally {
|
|
278
|
-
|
|
292
|
+
m = !1;
|
|
279
293
|
}
|
|
280
294
|
}
|
|
281
|
-
},
|
|
282
|
-
|
|
295
|
+
}, D = async () => {
|
|
296
|
+
n.value = !0;
|
|
283
297
|
try {
|
|
284
|
-
const a = await
|
|
298
|
+
const a = await Me(l);
|
|
285
299
|
if (o) {
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
|
|
300
|
+
const f = y();
|
|
301
|
+
if (f === null)
|
|
302
|
+
s.value = a;
|
|
289
303
|
else {
|
|
290
|
-
const
|
|
291
|
-
A(
|
|
304
|
+
const P = new Set(f.map((Y) => Y.group_id)), F = a.filter((Y) => P.has(Y.group_id));
|
|
305
|
+
A(F), s.value = F;
|
|
292
306
|
}
|
|
293
307
|
} else
|
|
294
|
-
|
|
295
|
-
await
|
|
308
|
+
s.value = a;
|
|
309
|
+
await R();
|
|
296
310
|
} finally {
|
|
297
|
-
|
|
311
|
+
n.value = !1;
|
|
298
312
|
}
|
|
299
|
-
}, _ = async (a =
|
|
300
|
-
const
|
|
301
|
-
return o &&
|
|
313
|
+
}, _ = async (a = h) => {
|
|
314
|
+
const f = await ie(l, a);
|
|
315
|
+
return o && W({ group_id: f, group_title: a }), await D(), i.value !== f && await I(f), f;
|
|
302
316
|
};
|
|
303
317
|
return {
|
|
304
|
-
groups:
|
|
318
|
+
groups: s,
|
|
305
319
|
activeGroupId: i,
|
|
306
320
|
messages: t,
|
|
307
|
-
loading:
|
|
308
|
-
loadGroups:
|
|
321
|
+
loading: n,
|
|
322
|
+
loadGroups: D,
|
|
309
323
|
createGroup: _,
|
|
310
|
-
renameGroup: async (a,
|
|
311
|
-
await
|
|
312
|
-
const
|
|
313
|
-
|
|
324
|
+
renameGroup: async (a, f) => {
|
|
325
|
+
await Fe(l, a, f);
|
|
326
|
+
const P = s.value.find((F) => F.group_id === a);
|
|
327
|
+
P && (P.group_title = f), o && A(s.value);
|
|
314
328
|
},
|
|
315
329
|
deleteGroup: async (a) => {
|
|
316
|
-
const
|
|
317
|
-
if (await
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
await I(Q.group_id);
|
|
330
|
+
const f = s.value.findIndex((F) => F.group_id === a);
|
|
331
|
+
if (await qe(l, a), s.value = s.value.filter((F) => F.group_id !== a), o && A(s.value), i.value !== a) return;
|
|
332
|
+
const P = s.value[f] ?? s.value[s.value.length - 1];
|
|
333
|
+
if (P) {
|
|
334
|
+
await I(P.group_id);
|
|
322
335
|
return;
|
|
323
336
|
}
|
|
324
|
-
u ? await _(
|
|
337
|
+
u ? await _(h) : (i.value = "", t.value = []);
|
|
325
338
|
},
|
|
326
339
|
selectGroup: I,
|
|
327
|
-
loadMessages:
|
|
340
|
+
loadMessages: U
|
|
328
341
|
};
|
|
329
|
-
},
|
|
330
|
-
const { api:
|
|
331
|
-
|
|
332
|
-
},
|
|
342
|
+
}, We = (e) => {
|
|
343
|
+
const { api: l, defaultEntryId: h, entryGroup: w = "智能助手", autoLoad: u = !0 } = e, L = p([]), v = p(null), o = p(!1), C = (i) => i ? typeof l.getFileUrl == "function" ? l.getFileUrl(i) : Qe(i, "", "/algorithm/get_file_data") : "", Q = (i) => {
|
|
344
|
+
v.value = i;
|
|
345
|
+
}, s = async () => {
|
|
333
346
|
var i;
|
|
334
347
|
o.value = !0;
|
|
335
348
|
try {
|
|
336
|
-
let t =
|
|
349
|
+
let t = h || ((i = v.value) == null ? void 0 : i.entry_id);
|
|
337
350
|
if (!t)
|
|
338
351
|
try {
|
|
339
|
-
const
|
|
340
|
-
t =
|
|
341
|
-
} catch (
|
|
342
|
-
console.warn("[useAgent] 获取默认智能体 ID 失败:",
|
|
352
|
+
const y = await l.getDefaultLlmId();
|
|
353
|
+
t = y == null ? void 0 : y.default_entry_id;
|
|
354
|
+
} catch (y) {
|
|
355
|
+
console.warn("[useAgent] 获取默认智能体 ID 失败:", y);
|
|
343
356
|
}
|
|
344
|
-
const
|
|
345
|
-
if (
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
} else
|
|
349
|
-
f.length > 0 && !g.value && (g.value = f[0]);
|
|
357
|
+
const n = await l.getLlmEntryListByRole({ entry_group: w }), d = ((n == null ? void 0 : n.values) || []).filter((y) => y.entry_enable !== !1);
|
|
358
|
+
if (L.value = d, t) {
|
|
359
|
+
const y = d.find((A) => A.entry_id === t);
|
|
360
|
+
y ? v.value = y : d.length > 0 && (v.value = d[0]);
|
|
361
|
+
} else d.length > 0 && !v.value && (v.value = d[0]);
|
|
350
362
|
} finally {
|
|
351
363
|
o.value = !1;
|
|
352
364
|
}
|
|
353
365
|
};
|
|
354
|
-
return u && (oe() ?
|
|
355
|
-
|
|
356
|
-
}) :
|
|
357
|
-
agentList:
|
|
358
|
-
currentAgent:
|
|
366
|
+
return u && (oe() ? xe(() => {
|
|
367
|
+
s();
|
|
368
|
+
}) : s()), {
|
|
369
|
+
agentList: L,
|
|
370
|
+
currentAgent: v,
|
|
359
371
|
loading: o,
|
|
360
|
-
getFileUrl:
|
|
361
|
-
loadAgents:
|
|
362
|
-
selectAgent:
|
|
372
|
+
getFileUrl: C,
|
|
373
|
+
loadAgents: s,
|
|
374
|
+
selectAgent: Q
|
|
363
375
|
};
|
|
364
|
-
},
|
|
365
|
-
const
|
|
366
|
-
let
|
|
367
|
-
const u =
|
|
376
|
+
}, je = (e = {}) => {
|
|
377
|
+
const l = e.parsers ?? [];
|
|
378
|
+
let h = null, w;
|
|
379
|
+
const u = ke({
|
|
368
380
|
...e.chat,
|
|
369
|
-
parsers:
|
|
370
|
-
onFirstQuestion: ({ question: t, groupId:
|
|
371
|
-
|
|
381
|
+
parsers: l,
|
|
382
|
+
onFirstQuestion: ({ question: t, groupId: n }) => {
|
|
383
|
+
w == null || w(n, t);
|
|
372
384
|
}
|
|
373
|
-
}),
|
|
385
|
+
}), L = He({
|
|
374
386
|
...e.history,
|
|
375
387
|
api: u.api,
|
|
376
388
|
autoLoadMessages: !1,
|
|
377
|
-
parsers:
|
|
389
|
+
parsers: l
|
|
378
390
|
});
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
var
|
|
382
|
-
(
|
|
391
|
+
w = (t, n) => {
|
|
392
|
+
h = L.renameGroup(t, n).catch((m) => {
|
|
393
|
+
var d;
|
|
394
|
+
(d = e.onError) == null || d.call(e, m, "groups");
|
|
383
395
|
});
|
|
384
396
|
};
|
|
385
|
-
const
|
|
397
|
+
const v = We({
|
|
386
398
|
...e.agent,
|
|
387
399
|
api: u.api,
|
|
388
400
|
autoLoad: !1
|
|
389
|
-
}), o = (t,
|
|
390
|
-
var
|
|
391
|
-
(
|
|
392
|
-
},
|
|
401
|
+
}), o = (t, n) => {
|
|
402
|
+
var m;
|
|
403
|
+
(m = e.onError) == null || m.call(e, t, n);
|
|
404
|
+
}, C = async () => {
|
|
393
405
|
try {
|
|
394
|
-
await
|
|
406
|
+
await L.loadGroups();
|
|
395
407
|
} catch (t) {
|
|
396
408
|
o(t, "groups");
|
|
397
409
|
}
|
|
398
|
-
},
|
|
410
|
+
}, Q = async (t) => {
|
|
399
411
|
try {
|
|
400
412
|
await u.loadGroup(t);
|
|
401
|
-
} catch (
|
|
402
|
-
o(
|
|
413
|
+
} catch (n) {
|
|
414
|
+
o(n, "messages");
|
|
403
415
|
}
|
|
404
|
-
},
|
|
416
|
+
}, s = async () => {
|
|
405
417
|
try {
|
|
406
|
-
await
|
|
418
|
+
await v.loadAgents();
|
|
407
419
|
} catch (t) {
|
|
408
420
|
o(t, "agents");
|
|
409
421
|
}
|
|
410
422
|
}, i = async (t) => {
|
|
411
|
-
var
|
|
412
|
-
const
|
|
423
|
+
var d;
|
|
424
|
+
const n = typeof t == "string" ? { text: t } : t;
|
|
413
425
|
await u.submitQuestion({
|
|
414
|
-
...
|
|
415
|
-
entryId: (
|
|
426
|
+
...n,
|
|
427
|
+
entryId: (n == null ? void 0 : n.entryId) ?? ((d = v.currentAgent.value) == null ? void 0 : d.entry_id)
|
|
416
428
|
});
|
|
417
|
-
const
|
|
418
|
-
|
|
429
|
+
const m = h;
|
|
430
|
+
h = null, m && await m, await C();
|
|
419
431
|
};
|
|
420
|
-
return
|
|
421
|
-
t && (
|
|
422
|
-
}),
|
|
423
|
-
t &&
|
|
432
|
+
return re(u.session, (t) => {
|
|
433
|
+
t && (C(), s());
|
|
434
|
+
}), re(L.activeGroupId, (t) => {
|
|
435
|
+
t && Q(t);
|
|
424
436
|
}), {
|
|
425
437
|
chat: u,
|
|
426
|
-
history:
|
|
427
|
-
agent:
|
|
428
|
-
parsers:
|
|
438
|
+
history: L,
|
|
439
|
+
agent: v,
|
|
440
|
+
parsers: l,
|
|
429
441
|
messages: u.messages,
|
|
430
442
|
question: u.question,
|
|
431
443
|
incPrevQuestion: u.incPrevQuestion,
|
|
432
444
|
talking: u.talking,
|
|
433
445
|
loading: u.loading,
|
|
434
446
|
session: u.session,
|
|
435
|
-
groups:
|
|
436
|
-
activeGroupId:
|
|
437
|
-
historyLoading:
|
|
438
|
-
agentList:
|
|
439
|
-
currentAgent:
|
|
440
|
-
agentLoading:
|
|
447
|
+
groups: L.groups,
|
|
448
|
+
activeGroupId: L.activeGroupId,
|
|
449
|
+
historyLoading: L.loading,
|
|
450
|
+
agentList: v.agentList,
|
|
451
|
+
currentAgent: v.currentAgent,
|
|
452
|
+
agentLoading: v.loading,
|
|
441
453
|
hasMore: u.hasMore,
|
|
442
454
|
loadMoreLoading: u.loadMoreLoading,
|
|
443
|
-
loadGroup:
|
|
455
|
+
loadGroup: Q,
|
|
444
456
|
loadOlder: u.loadOlder,
|
|
445
|
-
refreshGroups:
|
|
446
|
-
loadAgents:
|
|
447
|
-
selectAgent:
|
|
448
|
-
getFileUrl:
|
|
457
|
+
refreshGroups: C,
|
|
458
|
+
loadAgents: s,
|
|
459
|
+
selectAgent: v.selectAgent,
|
|
460
|
+
getFileUrl: v.getFileUrl,
|
|
449
461
|
submitQuestion: i,
|
|
450
462
|
sendWsMessage: u.sendWsMessage,
|
|
451
463
|
stopQuestion: u.stopQuestion
|
|
452
464
|
};
|
|
453
465
|
};
|
|
454
466
|
export {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
467
|
+
We as useAgent,
|
|
468
|
+
ke as useChat,
|
|
469
|
+
je as useChatSession,
|
|
470
|
+
He as useHistory
|
|
459
471
|
};
|
|
460
472
|
//# sourceMappingURL=index.js.map
|