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