@ibiz-template-plugin/ibiz-mob-ai-chat 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/dist/assets/gif/halo.gif +0 -0
  4. package/dist/assets/svg/AIChat.svg +1 -0
  5. package/dist/index.es.js +4425 -0
  6. package/dist/index.legacy.js +1 -0
  7. package/dist/polyfills.legacy.js +1 -0
  8. package/dist/style.css +1 -0
  9. package/dist/types/components/back-bottom/back-bottom.d.ts +57 -0
  10. package/dist/types/components/chart-material/chart-material-item/chart-material-item.d.ts +36 -0
  11. package/dist/types/components/chart-material/chart-material.d.ts +32 -0
  12. package/dist/types/components/chart-suggestion/chart-suggestion.d.ts +22 -0
  13. package/dist/types/components/chart-thought-chain/chart-thought-chain.d.ts +21 -0
  14. package/dist/types/components/chart-tool-call/chart-tool-call-item/chart-tool-call-item.d.ts +21 -0
  15. package/dist/types/components/chart-tool-call/chart-tool-call.d.ts +21 -0
  16. package/dist/types/components/chat-container/chat-container.d.ts +91 -0
  17. package/dist/types/components/chat-input/chat-input.d.ts +37 -0
  18. package/dist/types/components/chat-messages/chat-message-hook.d.ts +14 -0
  19. package/dist/types/components/chat-messages/chat-messages.d.ts +45 -0
  20. package/dist/types/components/chat-messages/common/error-message/error-message.d.ts +17 -0
  21. package/dist/types/components/chat-messages/common/index.d.ts +4 -0
  22. package/dist/types/components/chat-messages/common/markdown-message/markdown-message.d.ts +27 -0
  23. package/dist/types/components/chat-messages/common/unknown-message/unknown-message.d.ts +17 -0
  24. package/dist/types/components/chat-messages/common/user-message/user-message.d.ts +33 -0
  25. package/dist/types/components/chat-toolbar/chat-input-toolbar/chat-input-toolbar.d.ts +36 -0
  26. package/dist/types/components/chat-toolbar/chat-message-toolbar/chat-message-toolbar.d.ts +77 -0
  27. package/dist/types/components/chat-toolbar/chat-toolbar-hook.d.ts +14 -0
  28. package/dist/types/components/chat-toolbar/chat-toolbar-item/chat-toolbar-item.d.ts +44 -0
  29. package/dist/types/components/chat-toolbar/index.d.ts +3 -0
  30. package/dist/types/components/custom-modal/custom-modal.d.ts +10 -0
  31. package/dist/types/components/index.d.ts +3 -0
  32. package/dist/types/constants/index.d.ts +14 -0
  33. package/dist/types/controller/ai-chat/ai-chat.controller.d.ts +372 -0
  34. package/dist/types/controller/ai-material/ai-material-factory.d.ts +7 -0
  35. package/dist/types/controller/ai-material/common-helper.d.ts +13 -0
  36. package/dist/types/controller/ai-material/file-helper.d.ts +22 -0
  37. package/dist/types/controller/ai-material/material-helper.d.ts +16 -0
  38. package/dist/types/controller/ai-topic/ai-topic.controller.d.ts +165 -0
  39. package/dist/types/controller/chat/chat.controller.d.ts +138 -0
  40. package/dist/types/controller/index.d.ts +4 -0
  41. package/dist/types/entity/ai-agent/ai-agent.d.ts +12 -0
  42. package/dist/types/entity/chart-material/chart-material.d.ts +10 -0
  43. package/dist/types/entity/chart-topic/chart-topic.d.ts +28 -0
  44. package/dist/types/entity/chat-message/chat-message.d.ts +64 -0
  45. package/dist/types/entity/chat-suggestion/chat-suggestion.d.ts +9 -0
  46. package/dist/types/entity/index.d.ts +5 -0
  47. package/dist/types/global.d.ts +3 -0
  48. package/dist/types/icon/index.d.ts +1 -0
  49. package/dist/types/icon/svg.d.ts +101 -0
  50. package/dist/types/index.d.ts +1 -0
  51. package/dist/types/interface/i-ai-agent/i-ai-agent.d.ts +21 -0
  52. package/dist/types/interface/i-chat-container/i-chat-container.d.ts +107 -0
  53. package/dist/types/interface/i-chat-message/i-chat-message.d.ts +150 -0
  54. package/dist/types/interface/i-chat-options/i-chat-options.d.ts +263 -0
  55. package/dist/types/interface/i-chat-suggestion/i-chat-suggestion.d.ts +26 -0
  56. package/dist/types/interface/i-chat-tool-call/i-chat-tool-call.d.ts +39 -0
  57. package/dist/types/interface/i-chat-toolbar-item/i-chat-toolbar-item.d.ts +75 -0
  58. package/dist/types/interface/i-config-service/i-config-service.d.ts +27 -0
  59. package/dist/types/interface/i-container-options/i-container-options.d.ts +51 -0
  60. package/dist/types/interface/i-file-uploader-options/i-file-uploader-options.d.ts +27 -0
  61. package/dist/types/interface/i-material/i-material.d.ts +34 -0
  62. package/dist/types/interface/i-message-item-provider/i-message-item-provider.d.ts +18 -0
  63. package/dist/types/interface/i-portal-async-action/i-portal-async-action.d.ts +90 -0
  64. package/dist/types/interface/i-remote-resource/i-remote-resource.d.ts +68 -0
  65. package/dist/types/interface/i-resource-options/i-resource-options.d.ts +61 -0
  66. package/dist/types/interface/i-topic-options/i-topic-options.d.ts +147 -0
  67. package/dist/types/interface/index.d.ts +15 -0
  68. package/dist/types/utils/index.d.ts +10 -0
  69. package/dist/types/utils/plugin-static-resource/plugin-static-resource.d.ts +63 -0
  70. package/dist/types/utils/util/chat-suggestion-parser.d.ts +67 -0
  71. package/dist/types/utils/util/chat-tool-call-parser.d.ts +17 -0
  72. package/dist/types/utils/util/drag-util.d.ts +28 -0
  73. package/dist/types/utils/util/file-uploader.d.ts +37 -0
  74. package/dist/types/utils/util/indexdb-util.d.ts +91 -0
  75. package/dist/types/utils/util/material-resource-parser.d.ts +67 -0
  76. package/dist/types/utils/util/remote-resource-util.d.ts +26 -0
  77. package/dist/types/utils/util/text-hash-util.d.ts +8 -0
  78. package/dist/types/utils/util/util.d.ts +50 -0
  79. package/package.json +89 -0
@@ -0,0 +1,4425 @@
1
+ import './style.css';
2
+ var de = Object.defineProperty;
3
+ var pe = (a, e, t) => e in a ? de(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
4
+ var v = (a, e, t) => (pe(a, typeof e != "symbol" ? e + "" : e, t), t);
5
+ import { ref as w, createVNode as r, defineComponent as T, computed as k, onMounted as z, createTextVNode as H, watch as P, nextTick as _, onUnmounted as ge, resolveComponent as me, withDirectives as fe, vModelText as ve, createApp as V } from "vue";
6
+ import { QXEvent as Ce, createUUID as B, isString as X } from "qx-util";
7
+ import be from "vant";
8
+ import W from "cherry-markdown";
9
+ const we = "ibiz", ye = "is-";
10
+ function O(a, e, t, s, i) {
11
+ let o = "".concat(a, "-").concat(e);
12
+ return t && (o += "-".concat(t)), s && (o += "__".concat(s)), i && (o += "--".concat(i)), o;
13
+ }
14
+ class A {
15
+ /**
16
+ * Creates an instance of Namespace.
17
+ *
18
+ * @author chitanda
19
+ * @date 2022-09-06 12:09:12
20
+ * @param {string} block 当前命名空间的根模块,例如组件的名称
21
+ * @param {string} [namespace] 指定命名空间,未指定使用默认值 ibiz
22
+ */
23
+ constructor(e, t) {
24
+ /**
25
+ * 命名空间
26
+ *
27
+ * @author chitanda
28
+ * @date 2023-11-03 10:11:31
29
+ * @type {string}
30
+ */
31
+ v(this, "namespace");
32
+ this.block = e, this.namespace = t || we;
33
+ }
34
+ /**
35
+ * namespace-block
36
+ * namespace-block-blockSuffix
37
+ *
38
+ * @author chitanda
39
+ * @date 2022-09-06 12:09:08
40
+ * @param {string} [blockSuffix='']
41
+ * @return {*} {string}
42
+ */
43
+ b(e = "") {
44
+ return O(this.namespace, this.block, e, "", "");
45
+ }
46
+ /**
47
+ * namespace-block__element
48
+ *
49
+ * @author chitanda
50
+ * @date 2022-09-06 12:09:48
51
+ * @param {string} [element]
52
+ * @return {*} {string}
53
+ */
54
+ e(e) {
55
+ return e ? O(this.namespace, this.block, "", e, "") : "";
56
+ }
57
+ /**
58
+ * namespace-block--modifier
59
+ *
60
+ * @author chitanda
61
+ * @date 2022-09-06 12:09:37
62
+ * @param {string} [modifier]
63
+ * @return {*} {string}
64
+ */
65
+ m(e) {
66
+ return e ? O(this.namespace, this.block, "", "", e) : "";
67
+ }
68
+ /**
69
+ * namespace-block-blockSuffix__element
70
+ *
71
+ * @author chitanda
72
+ * @date 2022-09-06 12:09:52
73
+ * @param {string} [blockSuffix]
74
+ * @param {string} [element]
75
+ * @return {*} {string}
76
+ */
77
+ be(e, t) {
78
+ return e && t ? O(this.namespace, this.block, e, t, "") : "";
79
+ }
80
+ /**
81
+ * namespace-block__element--modifier
82
+ *
83
+ * @author chitanda
84
+ * @date 2022-09-06 12:09:19
85
+ * @param {string} [element]
86
+ * @param {string} [modifier]
87
+ * @return {*} {string}
88
+ */
89
+ em(e, t) {
90
+ return e && t ? O(this.namespace, this.block, "", e, t) : "";
91
+ }
92
+ /**
93
+ * namespace-block-blockSuffix--modifier
94
+ *
95
+ * @author chitanda
96
+ * @date 2022-09-06 12:09:59
97
+ * @param {string} [blockSuffix]
98
+ * @param {string} [modifier]
99
+ * @return {*} {string}
100
+ */
101
+ bm(e, t) {
102
+ return e && t ? O(this.namespace, this.block, e, "", t) : "";
103
+ }
104
+ /**
105
+ * namespace-block-blockSuffix__element--modifier
106
+ *
107
+ * @author chitanda
108
+ * @date 2022-09-06 12:09:37
109
+ * @param {string} [blockSuffix]
110
+ * @param {string} [element]
111
+ * @param {string} [modifier]
112
+ * @return {*} {string}
113
+ */
114
+ bem(e, t, s) {
115
+ return e && t && s ? O(this.namespace, this.block, e, t, s) : "";
116
+ }
117
+ /**
118
+ * 返回状态 class
119
+ *
120
+ * is('loading', false) => '';
121
+ * is('loading', true) => 'is-loading';
122
+ *
123
+ * @author chitanda
124
+ * @date 2022-09-06 12:09:57
125
+ * @param {string} name
126
+ * @param {boolean} [state]
127
+ * @return {*} {string}
128
+ */
129
+ is(e, t) {
130
+ return e && t ? "".concat(ye).concat(e) : "";
131
+ }
132
+ /**
133
+ * 生成使用到的 css 变量 style 对象
134
+ *
135
+ * @author chitanda
136
+ * @date 2022-09-06 15:09:41
137
+ * @param {Record<string, string>} object
138
+ * @return {*} {Record<string, string>}
139
+ */
140
+ cssVar(e) {
141
+ const t = {};
142
+ for (const s in e)
143
+ e[s] && (t[this.cssVarName(s)] = e[s]);
144
+ return t;
145
+ }
146
+ /**
147
+ * 生成使用到的 css block 变量 style 对象
148
+ *
149
+ * @author chitanda
150
+ * @date 2022-09-06 15:09:03
151
+ * @param {Record<string, string>} object
152
+ * @return {*} {Record<string, string>}
153
+ */
154
+ cssVarBlock(e) {
155
+ const t = {};
156
+ for (const s in e)
157
+ e[s] && (t[this.cssVarBlockName(s)] = e[s]);
158
+ return t;
159
+ }
160
+ /**
161
+ * 生成 css var 变量名称
162
+ *
163
+ * @author chitanda
164
+ * @date 2022-09-06 15:09:21
165
+ * @param {string} name
166
+ * @return {*} {string}
167
+ */
168
+ cssVarName(e) {
169
+ return "--".concat(this.namespace, "-").concat(e);
170
+ }
171
+ /**
172
+ * 生成块 css var 变量名称
173
+ *
174
+ * @author chitanda
175
+ * @date 2022-09-06 15:09:35
176
+ * @param {string} name
177
+ * @return {*} {string}
178
+ */
179
+ cssVarBlockName(e) {
180
+ return "--".concat(this.namespace, "-").concat(this.block, "-").concat(e);
181
+ }
182
+ }
183
+ function M(a) {
184
+ if (typeof a != "string")
185
+ throw new TypeError("Path must be a string. Received " + JSON.stringify(a));
186
+ }
187
+ function J(a, e) {
188
+ for (var t = "", s = 0, i = -1, o = 0, n, l = 0; l <= a.length; ++l) {
189
+ if (l < a.length)
190
+ n = a.charCodeAt(l);
191
+ else {
192
+ if (n === 47)
193
+ break;
194
+ n = 47;
195
+ }
196
+ if (n === 47) {
197
+ if (!(i === l - 1 || o === 1))
198
+ if (i !== l - 1 && o === 2) {
199
+ if (t.length < 2 || s !== 2 || t.charCodeAt(t.length - 1) !== 46 || t.charCodeAt(t.length - 2) !== 46) {
200
+ if (t.length > 2) {
201
+ var h = t.lastIndexOf("/");
202
+ if (h !== t.length - 1) {
203
+ h === -1 ? (t = "", s = 0) : (t = t.slice(0, h), s = t.length - 1 - t.lastIndexOf("/")), i = l, o = 0;
204
+ continue;
205
+ }
206
+ } else if (t.length === 2 || t.length === 1) {
207
+ t = "", s = 0, i = l, o = 0;
208
+ continue;
209
+ }
210
+ }
211
+ e && (t.length > 0 ? t += "/.." : t = "..", s = 2);
212
+ } else
213
+ t.length > 0 ? t += "/" + a.slice(i + 1, l) : t = a.slice(i + 1, l), s = l - i - 1;
214
+ i = l, o = 0;
215
+ } else
216
+ n === 46 && o !== -1 ? ++o : o = -1;
217
+ }
218
+ return t;
219
+ }
220
+ function Te(a, e) {
221
+ var t = e.dir || e.root, s = e.base || (e.name || "") + (e.ext || "");
222
+ return t ? t === e.root ? t + s : t + a + s : s;
223
+ }
224
+ var R = {
225
+ // path.resolve([from ...], to)
226
+ resolve: function() {
227
+ for (var e = "", t = !1, s, i = arguments.length - 1; i >= -1 && !t; i--) {
228
+ var o;
229
+ i >= 0 ? o = arguments[i] : (s === void 0 && (s = process.cwd()), o = s), M(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
230
+ }
231
+ return e = J(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
232
+ },
233
+ normalize: function(e) {
234
+ if (M(e), e.length === 0)
235
+ return ".";
236
+ var t = e.charCodeAt(0) === 47, s = e.charCodeAt(e.length - 1) === 47;
237
+ return e = J(e, !t), e.length === 0 && !t && (e = "."), e.length > 0 && s && (e += "/"), t ? "/" + e : e;
238
+ },
239
+ isAbsolute: function(e) {
240
+ return M(e), e.length > 0 && e.charCodeAt(0) === 47;
241
+ },
242
+ join: function() {
243
+ if (arguments.length === 0)
244
+ return ".";
245
+ for (var e, t = 0; t < arguments.length; ++t) {
246
+ var s = arguments[t];
247
+ M(s), s.length > 0 && (e === void 0 ? e = s : e += "/" + s);
248
+ }
249
+ return e === void 0 ? "." : R.normalize(e);
250
+ },
251
+ relative: function(e, t) {
252
+ if (M(e), M(t), e === t || (e = R.resolve(e), t = R.resolve(t), e === t))
253
+ return "";
254
+ for (var s = 1; s < e.length && e.charCodeAt(s) === 47; ++s)
255
+ ;
256
+ for (var i = e.length, o = i - s, n = 1; n < t.length && t.charCodeAt(n) === 47; ++n)
257
+ ;
258
+ for (var l = t.length, h = l - n, c = o < h ? o : h, u = -1, d = 0; d <= c; ++d) {
259
+ if (d === c) {
260
+ if (h > c) {
261
+ if (t.charCodeAt(n + d) === 47)
262
+ return t.slice(n + d + 1);
263
+ if (d === 0)
264
+ return t.slice(n + d);
265
+ } else
266
+ o > c && (e.charCodeAt(s + d) === 47 ? u = d : d === 0 && (u = 0));
267
+ break;
268
+ }
269
+ var p = e.charCodeAt(s + d), f = t.charCodeAt(n + d);
270
+ if (p !== f)
271
+ break;
272
+ p === 47 && (u = d);
273
+ }
274
+ var m = "";
275
+ for (d = s + u + 1; d <= i; ++d)
276
+ (d === i || e.charCodeAt(d) === 47) && (m.length === 0 ? m += ".." : m += "/..");
277
+ return m.length > 0 ? m + t.slice(n + u) : (n += u, t.charCodeAt(n) === 47 && ++n, t.slice(n));
278
+ },
279
+ _makeLong: function(e) {
280
+ return e;
281
+ },
282
+ dirname: function(e) {
283
+ if (M(e), e.length === 0)
284
+ return ".";
285
+ for (var t = e.charCodeAt(0), s = t === 47, i = -1, o = !0, n = e.length - 1; n >= 1; --n)
286
+ if (t = e.charCodeAt(n), t === 47) {
287
+ if (!o) {
288
+ i = n;
289
+ break;
290
+ }
291
+ } else
292
+ o = !1;
293
+ return i === -1 ? s ? "/" : "." : s && i === 1 ? "//" : e.slice(0, i);
294
+ },
295
+ basename: function(e, t) {
296
+ if (t !== void 0 && typeof t != "string")
297
+ throw new TypeError('"ext" argument must be a string');
298
+ M(e);
299
+ var s = 0, i = -1, o = !0, n;
300
+ if (t !== void 0 && t.length > 0 && t.length <= e.length) {
301
+ if (t.length === e.length && t === e)
302
+ return "";
303
+ var l = t.length - 1, h = -1;
304
+ for (n = e.length - 1; n >= 0; --n) {
305
+ var c = e.charCodeAt(n);
306
+ if (c === 47) {
307
+ if (!o) {
308
+ s = n + 1;
309
+ break;
310
+ }
311
+ } else
312
+ h === -1 && (o = !1, h = n + 1), l >= 0 && (c === t.charCodeAt(l) ? --l === -1 && (i = n) : (l = -1, i = h));
313
+ }
314
+ return s === i ? i = h : i === -1 && (i = e.length), e.slice(s, i);
315
+ } else {
316
+ for (n = e.length - 1; n >= 0; --n)
317
+ if (e.charCodeAt(n) === 47) {
318
+ if (!o) {
319
+ s = n + 1;
320
+ break;
321
+ }
322
+ } else
323
+ i === -1 && (o = !1, i = n + 1);
324
+ return i === -1 ? "" : e.slice(s, i);
325
+ }
326
+ },
327
+ extname: function(e) {
328
+ M(e);
329
+ for (var t = -1, s = 0, i = -1, o = !0, n = 0, l = e.length - 1; l >= 0; --l) {
330
+ var h = e.charCodeAt(l);
331
+ if (h === 47) {
332
+ if (!o) {
333
+ s = l + 1;
334
+ break;
335
+ }
336
+ continue;
337
+ }
338
+ i === -1 && (o = !1, i = l + 1), h === 46 ? t === -1 ? t = l : n !== 1 && (n = 1) : t !== -1 && (n = -1);
339
+ }
340
+ return t === -1 || i === -1 || // We saw a non-dot character immediately before the dot
341
+ n === 0 || // The (right-most) trimmed path component is exactly '..'
342
+ n === 1 && t === i - 1 && t === s + 1 ? "" : e.slice(t, i);
343
+ },
344
+ format: function(e) {
345
+ if (e === null || typeof e != "object")
346
+ throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof e);
347
+ return Te("/", e);
348
+ },
349
+ parse: function(e) {
350
+ M(e);
351
+ var t = { root: "", dir: "", base: "", ext: "", name: "" };
352
+ if (e.length === 0)
353
+ return t;
354
+ var s = e.charCodeAt(0), i = s === 47, o;
355
+ i ? (t.root = "/", o = 1) : o = 0;
356
+ for (var n = -1, l = 0, h = -1, c = !0, u = e.length - 1, d = 0; u >= o; --u) {
357
+ if (s = e.charCodeAt(u), s === 47) {
358
+ if (!c) {
359
+ l = u + 1;
360
+ break;
361
+ }
362
+ continue;
363
+ }
364
+ h === -1 && (c = !1, h = u + 1), s === 46 ? n === -1 ? n = u : d !== 1 && (d = 1) : n !== -1 && (d = -1);
365
+ }
366
+ return n === -1 || h === -1 || // We saw a non-dot character immediately before the dot
367
+ d === 0 || // The (right-most) trimmed path component is exactly '..'
368
+ d === 1 && n === h - 1 && n === l + 1 ? h !== -1 && (l === 0 && i ? t.base = t.name = e.slice(1, h) : t.base = t.name = e.slice(l, h)) : (l === 0 && i ? (t.name = e.slice(1, n), t.base = e.slice(1, h)) : (t.name = e.slice(l, n), t.base = e.slice(l, h)), t.ext = e.slice(n, h)), l > 0 ? t.dir = e.slice(0, l - 1) : i && (t.dir = "/"), t;
369
+ },
370
+ sep: "/",
371
+ delimiter: ":",
372
+ win32: null,
373
+ posix: null
374
+ };
375
+ R.posix = R;
376
+ function D() {
377
+ return ((1 + Math.random()) * 65536 | 0).toString(16).substring(1);
378
+ }
379
+ function Ae() {
380
+ return "".concat(D() + D(), "-").concat(D(), "-").concat(D(), "-").concat(D(), "-").concat(D()).concat(D()).concat(D());
381
+ }
382
+ function G(a) {
383
+ const e = a.lastIndexOf("@");
384
+ return e === -1 ? a : a.substring(0, e);
385
+ }
386
+ const Ie = /<svg\b[^>]*>[\s\S]*?<\/svg>/;
387
+ function Me(a) {
388
+ return Ie.test(a);
389
+ }
390
+ const ke = "topic", xe = "inline", Se = "temp", Ee = "unknow";
391
+ function De(a, e) {
392
+ let t = "";
393
+ switch (a) {
394
+ case "TOPIC":
395
+ t += ke;
396
+ break;
397
+ case "INLINE":
398
+ t += xe;
399
+ break;
400
+ case "TEMP":
401
+ t += Se;
402
+ break;
403
+ default:
404
+ t += Ee;
405
+ break;
406
+ }
407
+ return t += "@".concat(e || Ae(), "@").concat((/* @__PURE__ */ new Date()).getTime()), t;
408
+ }
409
+ class Z {
410
+ /**
411
+ * 拷贝文本
412
+ *
413
+ * @author zhanghengfeng
414
+ * @date 2023-08-31 11:08:51
415
+ * @param {string} value
416
+ * @return {*} {boolean}
417
+ */
418
+ static copy(e) {
419
+ return this.inputElement || (this.inputElement = document.createElement("input"), this.inputElement.style.position = "absolute", this.inputElement.style.left = "-9999px", document.body.appendChild(this.inputElement)), this.inputElement.value = e, this.inputElement.select(), document.execCommand("copy");
420
+ }
421
+ }
422
+ /**
423
+ * input元素,用于存储拷贝的文本
424
+ *
425
+ * @author zhanghengfeng
426
+ * @date 2023-08-31 20:08:06
427
+ * @private
428
+ * @type {(HTMLInputElement | null)}
429
+ */
430
+ v(Z, "inputElement", null);
431
+ const g = class g {
432
+ /**
433
+ * 检查数据库是否存在
434
+ *
435
+ * @param {string} storeName
436
+ * @return {*} {Promise<boolean>}
437
+ * @memberof IndexedDBUtil
438
+ */
439
+ static async checkDataBaseExists(e) {
440
+ try {
441
+ return (await indexedDB.databases()).some((s) => s.name === e);
442
+ } catch (t) {
443
+ return console.error("检查数据库是否存在时出错:", t), !1;
444
+ }
445
+ }
446
+ /**
447
+ * 删除数据库
448
+ *
449
+ * @return {*} {Promise<void>}
450
+ * @memberof IndexedDBUtil
451
+ */
452
+ static async deleteDatabase(e) {
453
+ var t, s;
454
+ return g.lastLink && ((s = (t = g.lastLink).close) == null || s.call(t)), new Promise((i, o) => {
455
+ const n = indexedDB.deleteDatabase(e);
456
+ n.onsuccess = () => {
457
+ i(!0);
458
+ }, n.onerror = () => {
459
+ i(!1);
460
+ }, n.onblocked = () => {
461
+ console.warn(
462
+ "删除数据库 ".concat(e, " 被阻塞,可能有其他连接正在使用该数据库。")
463
+ ), o(new Error("删除数据库 ".concat(e, " 被阻塞")));
464
+ };
465
+ });
466
+ }
467
+ /**
468
+ * 检查是否存在某个库以及库内是否存在某个表
469
+ *
470
+ * @param {string} storeName
471
+ * @param {string} tableName
472
+ * @return {*}
473
+ * @memberof IndexedDBUtil
474
+ */
475
+ static async checkTableExists(e, t) {
476
+ return await g.checkDataBaseExists(e) ? new Promise((i, o) => {
477
+ const n = indexedDB.open(e);
478
+ n.onupgradeneeded = (l) => {
479
+ g.db = l.target.result, g.version = g.db.version;
480
+ }, n.onsuccess = (l) => {
481
+ g.db = l.target.result, g.lastLink = n.result;
482
+ const h = g.db.objectStoreNames.contains(t);
483
+ n.result.close(), i(h);
484
+ }, n.onerror = (l) => {
485
+ o(l.target.error);
486
+ };
487
+ }) : !1;
488
+ }
489
+ /**
490
+ * 创建表
491
+ *
492
+ * @param {string} storeName 库名称
493
+ * @param {(string | null)} keyPath 表主键
494
+ * @param {boolean} [useAutoIncrement=false] 是否使用自增
495
+ * @return {*} {Promise<void>}
496
+ * @memberof IndexedDBUtil
497
+ */
498
+ static async createTable(e, t, s, i = !1) {
499
+ return new Promise((o) => {
500
+ var l, h;
501
+ g.version += 1, g.lastLink && ((h = (l = g.lastLink).close) == null || h.call(l));
502
+ const n = indexedDB.open(e, g.version);
503
+ n.onupgradeneeded = (c) => {
504
+ if (g.db = c.target.result, !g.db.objectStoreNames.contains(t)) {
505
+ const u = {};
506
+ s ? u.keyPath = s : i && (u.autoIncrement = !0), g.db.createObjectStore(t, u);
507
+ }
508
+ }, n.onsuccess = () => {
509
+ g.lastLink = n.result, n.result.close(), o(!0);
510
+ }, n.onerror = () => {
511
+ o(!1);
512
+ };
513
+ });
514
+ }
515
+ /**
516
+ * 删除表
517
+ *
518
+ * @param {string} storeName 表名称
519
+ * @return {*} {Promise<void>}
520
+ * @memberof IndexedDBUtil
521
+ */
522
+ static async deleteTable(e, t) {
523
+ return new Promise((s) => {
524
+ var o, n;
525
+ g.version += 1, g.lastLink && ((n = (o = g.lastLink).close) == null || n.call(o));
526
+ const i = indexedDB.open(e, g.version);
527
+ i.onupgradeneeded = (l) => {
528
+ g.db = l.target.result, g.lastLink = i.result, g.db.objectStoreNames.contains(t) && g.db.deleteObjectStore(t);
529
+ }, i.onsuccess = (l) => {
530
+ g.db = l.target.result, g.lastLink = i.result, i.result.close(), s(!0);
531
+ }, i.onerror = () => {
532
+ i.result.close(), s(!1);
533
+ };
534
+ });
535
+ }
536
+ /**
537
+ * 新增数据
538
+ *
539
+ * @param {string} storeName 表名称
540
+ * @param {*} data 新增数据
541
+ * @return {*} {Promise<void>}
542
+ * @memberof IndexedDBUtil
543
+ */
544
+ static async addData(e, t, s) {
545
+ return new Promise((i, o) => {
546
+ const n = indexedDB.open(e);
547
+ n.onsuccess = (l) => {
548
+ if (g.db = l.target.result, g.lastLink = n.result, g.db.objectStoreNames.contains(t)) {
549
+ const u = g.db.transaction(
550
+ [t],
551
+ "readwrite"
552
+ ).objectStore(t).add(s);
553
+ u.onsuccess = (d) => {
554
+ i(s);
555
+ }, u.onerror = () => {
556
+ i(null);
557
+ };
558
+ }
559
+ n.result.close();
560
+ }, n.onerror = () => {
561
+ n.result.close(), o();
562
+ };
563
+ });
564
+ }
565
+ /**
566
+ * 删除数据
567
+ *
568
+ * @param {string} storeName 表名称
569
+ * @param {IDBValidKey} key 数据键
570
+ * @return {*} {Promise<void>}
571
+ * @memberof IndexedDBUtil
572
+ */
573
+ static async deleteData(e, t, s) {
574
+ return new Promise((i, o) => {
575
+ const n = indexedDB.open(e);
576
+ n.onsuccess = (l) => {
577
+ if (g.db = l.target.result, g.lastLink = n.result, g.db.objectStoreNames.contains(t)) {
578
+ const u = g.db.transaction(
579
+ [t],
580
+ "readwrite"
581
+ ).objectStore(t).delete(s);
582
+ u.onsuccess = (d) => {
583
+ i(!0);
584
+ }, u.onerror = () => {
585
+ i(!1);
586
+ };
587
+ }
588
+ n.result.close();
589
+ }, n.onerror = () => {
590
+ n.result.close(), o();
591
+ };
592
+ });
593
+ }
594
+ /**
595
+ * 修改数据
596
+ *
597
+ * @param {string} storeName 表名称
598
+ * @param {*} data 需要修改的数据
599
+ * @return {*} {Promise<void>}
600
+ * @memberof IndexedDBUtil
601
+ */
602
+ static async updateData(e, t, s) {
603
+ return new Promise((i, o) => {
604
+ const n = indexedDB.open(e);
605
+ n.onsuccess = (l) => {
606
+ if (g.db = l.target.result, g.lastLink = n.result, g.db.objectStoreNames.contains(t)) {
607
+ const u = g.db.transaction(
608
+ [t],
609
+ "readwrite"
610
+ ).objectStore(t).put(s);
611
+ u.onsuccess = (d) => {
612
+ i(s);
613
+ }, u.onerror = () => {
614
+ i(s);
615
+ };
616
+ }
617
+ n.result.close();
618
+ }, n.onerror = () => {
619
+ n.result.close(), o();
620
+ };
621
+ });
622
+ }
623
+ /**
624
+ * 读取单条数据
625
+ *
626
+ * @param {string} storeName 表名称
627
+ * @param {IDBValidKey} key 数据主键
628
+ * @return {*} {Promise<any>}
629
+ * @memberof IndexedDBUtil
630
+ */
631
+ static async getData(e, t, s) {
632
+ return new Promise((i, o) => {
633
+ const n = indexedDB.open(e);
634
+ n.onsuccess = (l) => {
635
+ if (g.db = l.target.result, g.lastLink = n.result, g.db.objectStoreNames.contains(t)) {
636
+ const u = g.db.transaction(
637
+ [t],
638
+ "readonly"
639
+ ).objectStore(t).get(s);
640
+ u.onsuccess = (d) => {
641
+ i(u.result);
642
+ }, u.onerror = () => {
643
+ o(new Error("未找到数据".concat(s)));
644
+ };
645
+ }
646
+ n.result.close();
647
+ }, n.onerror = () => {
648
+ n.result.close(), o();
649
+ };
650
+ });
651
+ }
652
+ /**
653
+ * 读取所有数据
654
+ *
655
+ * @param {string} storeName 表名称
656
+ * @return {*} {Promise<any[]>}
657
+ * @memberof IndexedDBUtil
658
+ */
659
+ static async getAllData(e, t) {
660
+ return new Promise((s, i) => {
661
+ const o = indexedDB.open(e);
662
+ o.onsuccess = (n) => {
663
+ if (g.db = n.target.result, g.lastLink = o.result, g.db.objectStoreNames.contains(t)) {
664
+ const c = g.db.transaction(
665
+ [t],
666
+ "readonly"
667
+ ).objectStore(t).getAll();
668
+ c.onsuccess = (u) => {
669
+ s(c.result);
670
+ }, c.onerror = () => {
671
+ s([]);
672
+ };
673
+ }
674
+ o.result.close();
675
+ }, o.onerror = () => {
676
+ o.result.close(), i();
677
+ };
678
+ });
679
+ }
680
+ };
681
+ // 数据库版本
682
+ v(g, "version", 1), // 数据库连接句柄
683
+ v(g, "db", null), // 上一个连接
684
+ v(g, "lastLink");
685
+ let x = g;
686
+ class Oe {
687
+ /**
688
+ * Creates an instance of FileUploader.
689
+ * @author tony001
690
+ * @date 2025-02-28 15:02:15
691
+ * @param {FileUploaderOptions<T>} options
692
+ */
693
+ constructor(e) {
694
+ v(this, "options");
695
+ this.options = {
696
+ multiple: !0,
697
+ accept: "*/*",
698
+ maxSize: 5 * 1024 * 1024,
699
+ ...e
700
+ };
701
+ }
702
+ /**
703
+ * 打开文件选择对话框
704
+ */
705
+ openFilePicker() {
706
+ const e = document.createElement("input");
707
+ e.type = "file", e.multiple = this.options.multiple, e.accept = this.options.accept || "", e.onchange = (t) => {
708
+ const s = Array.from(t.target.files || []);
709
+ this.handleFiles(s);
710
+ }, e.click();
711
+ }
712
+ /**
713
+ * 处理选择的文件
714
+ */
715
+ async handleFiles(e) {
716
+ var s, i;
717
+ if (e.length === 0)
718
+ return;
719
+ const t = e.filter((o) => {
720
+ var n, l;
721
+ return this.options.maxSize && o.size > this.options.maxSize ? ((l = (n = this.options).onError) == null || l.call(
722
+ n,
723
+ new Error(
724
+ "文件大小超过限制 (".concat(this.formatSize(
725
+ o.size
726
+ ), " > ").concat(this.formatSize(this.options.maxSize), ")")
727
+ ),
728
+ o
729
+ ), !1) : !0;
730
+ });
731
+ (i = (s = this.options).onSelect) == null || i.call(s, t), await Promise.all(t.map((o) => this.processFile(o)));
732
+ }
733
+ /**
734
+ * 处理单个文件上传
735
+ */
736
+ async processFile(e) {
737
+ var t, s, i, o, n, l;
738
+ try {
739
+ const h = (u) => {
740
+ var d, p;
741
+ (p = (d = this.options).onProgress) == null || p.call(d, e, u);
742
+ }, c = await this.options.onUpload(e, h);
743
+ (s = (t = this.options).onProgress) == null || s.call(t, e, 100), (o = (i = this.options).onSuccess) == null || o.call(i, c, e);
744
+ } catch (h) {
745
+ (l = (n = this.options).onError) == null || l.call(
746
+ n,
747
+ h instanceof Error ? h : new Error("上传失败"),
748
+ e
749
+ );
750
+ }
751
+ }
752
+ /**
753
+ * 格式化文件大小
754
+ */
755
+ formatSize(e) {
756
+ if (e === 0)
757
+ return "0 B";
758
+ const t = ["B", "KB", "MB", "GB"], s = Math.floor(Math.log(e) / Math.log(1024));
759
+ return "".concat((e / 1024 ** s).toFixed(2), " ").concat(t[s]);
760
+ }
761
+ }
762
+ class j {
763
+ /**
764
+ * 从XML元素中提取CDATA内容
765
+ *
766
+ * @author tony001
767
+ * @date 2025-03-03 15:03:43
768
+ * @private
769
+ * @static
770
+ * @param {(Element | null)} element
771
+ * @return {*} {(string | null)}
772
+ */
773
+ static getCdataContent(e) {
774
+ if (!e)
775
+ return null;
776
+ const t = Array.from(e.childNodes).find(
777
+ (s) => s.nodeType === s.CDATA_SECTION_NODE
778
+ );
779
+ return (t == null ? void 0 : t.nodeValue) || e.textContent;
780
+ }
781
+ /**
782
+ * XML 字符串转数据对象
783
+ *
784
+ * @author tony001
785
+ * @date 2025-03-03 11:03:17
786
+ * @static
787
+ * @param {string} xmlString
788
+ * @return {*} {IMaterial[]}
789
+ */
790
+ static parse(e) {
791
+ const s = new DOMParser().parseFromString(e, "text/xml");
792
+ return Array.from(s.querySelectorAll("resource")).map((o) => {
793
+ const n = o.getAttribute("type") || "", l = o.querySelector("data"), h = o.querySelector("metadata");
794
+ try {
795
+ const c = this.getCdataContent(l), u = this.getCdataContent(h), d = c ? JSON.parse(c) : {}, p = u ? JSON.parse(u) : {};
796
+ return { id: d.id, type: n, data: d, metadata: p };
797
+ } catch (c) {
798
+ throw new Error("XML 解析错误: ".concat(c.message));
799
+ }
800
+ });
801
+ }
802
+ /**
803
+ * 混合内容解析
804
+ *
805
+ * @author tony001
806
+ * @date 2025-03-03 13:03:35
807
+ * @static
808
+ * @param {string} input 包含 XML 和其他文本的混合字符串
809
+ * @return {*} {{
810
+ * resources: IMaterial[];
811
+ * remainingText: string;
812
+ * hasResources: boolean;
813
+ * error?: string;
814
+ * }}
815
+ */
816
+ static parseMixedContent(e) {
817
+ const s = /<resources\b[^>]*>[\s\S]*?<\/resources>/i.exec(e);
818
+ if (!s)
819
+ return {
820
+ resources: [],
821
+ remainingText: e,
822
+ hasResources: !1
823
+ };
824
+ const [i] = s, o = s.index, n = o + i.length, l = (e.slice(0, o) + e.slice(n)).replace(/\n/g, "").replace(/(!\[[^\]]*\]\([^)]+\))/g, "\n$1\n").replace(/\n+/g, "\n").replace(/^\n|\n$/g, "");
825
+ try {
826
+ return {
827
+ resources: this.parse(i),
828
+ remainingText: l,
829
+ hasResources: !0
830
+ };
831
+ } catch (h) {
832
+ return {
833
+ resources: [],
834
+ remainingText: l,
835
+ hasResources: !0,
836
+ error: "资源解析失败: ".concat(h.message)
837
+ };
838
+ }
839
+ }
840
+ /**
841
+ * 数据对象转 XML 字符串
842
+ *
843
+ * @author tony001
844
+ * @date 2025-03-03 11:03:51
845
+ * @static
846
+ * @param {IMaterial[]} resources
847
+ * @return {*} {string}
848
+ */
849
+ static stringify(e) {
850
+ const t = document.implementation.createDocument(null, null, null), s = t.createElement("resources");
851
+ s.setAttribute("version", "1.0");
852
+ const i = (n) => "\n".concat(" ".repeat(n)), o = 1;
853
+ return e.forEach((n) => {
854
+ s.appendChild(t.createTextNode(i(o)));
855
+ const l = t.createElement("resource");
856
+ l.setAttribute("type", n.type), l.setAttribute("version", "1.0");
857
+ const h = (c, u) => {
858
+ const d = t.createElement(c);
859
+ d.appendChild(t.createTextNode(i(o + 1)));
860
+ const p = t.createCDATASection(JSON.stringify(u));
861
+ return d.appendChild(p), d.appendChild(t.createTextNode(i(o))), d;
862
+ };
863
+ l.appendChild(
864
+ t.createTextNode(i(o + 1))
865
+ ), l.appendChild(h("data", n.data)), l.appendChild(
866
+ t.createTextNode(i(o + 1))
867
+ ), l.appendChild(h("metadata", n.metadata)), l.appendChild(t.createTextNode(i(o))), s.appendChild(l);
868
+ }), s.appendChild(t.createTextNode("\n")), t.appendChild(s), new XMLSerializer().serializeToString(t).replace(/></g, ">\n<");
869
+ }
870
+ }
871
+ class Le {
872
+ /**
873
+ * 从XML元素中提取CDATA内容
874
+ *
875
+ * @author tony001
876
+ * @date 2025-03-03 15:03:43
877
+ * @private
878
+ * @static
879
+ * @param {(Element | null)} element
880
+ * @return {*} {(string | null)}
881
+ */
882
+ static getCdataContent(e) {
883
+ if (!e)
884
+ return null;
885
+ const t = Array.from(e.childNodes).find(
886
+ (s) => s.nodeType === s.CDATA_SECTION_NODE
887
+ );
888
+ return (t == null ? void 0 : t.nodeValue) || e.textContent;
889
+ }
890
+ /**
891
+ * XML 字符串转数据对象
892
+ *
893
+ * @author tony001
894
+ * @date 2025-03-03 11:03:17
895
+ * @static
896
+ * @param {string} xmlString
897
+ * @return {*} {IChatSuggestion[]}
898
+ */
899
+ static parse(e) {
900
+ const s = new DOMParser().parseFromString(e, "text/xml");
901
+ return Array.from(s.querySelectorAll("suggestion")).map((o) => {
902
+ const n = o.getAttribute("type") || "", l = o.querySelector("data"), h = o.querySelector("metadata");
903
+ try {
904
+ const c = this.getCdataContent(l), u = this.getCdataContent(h), d = c ? JSON.parse(c) : {}, p = u ? JSON.parse(u) : {};
905
+ return { type: n, data: d, metadata: p };
906
+ } catch (c) {
907
+ throw new Error("XML 解析错误: ".concat(c.message));
908
+ }
909
+ });
910
+ }
911
+ /**
912
+ * 混合内容解析
913
+ *
914
+ * @author tony001
915
+ * @date 2025-03-03 13:03:35
916
+ * @static
917
+ * @param {string} input 包含 XML 和其他文本的混合字符串
918
+ * @return {*} {{
919
+ * suggestions: IChatSuggestion[];
920
+ * remainingText: string;
921
+ * hasSuggestions: boolean;
922
+ * error?: string;
923
+ * }}
924
+ */
925
+ static parseMixedContent(e) {
926
+ const s = /<suggestions\b[^>]*>[\s\S]*?<\/suggestions>/i.exec(e);
927
+ if (!s)
928
+ return {
929
+ suggestions: [],
930
+ remainingText: e,
931
+ hasSuggestions: !1
932
+ };
933
+ const [i] = s, o = s.index, n = o + i.length, l = (e.slice(0, o) + e.slice(n)).replace(/\n/g, "");
934
+ try {
935
+ return {
936
+ suggestions: this.parse(i),
937
+ remainingText: l,
938
+ hasSuggestions: !0
939
+ };
940
+ } catch (h) {
941
+ return {
942
+ suggestions: [],
943
+ remainingText: l,
944
+ hasSuggestions: !0,
945
+ error: "资源解析失败: ".concat(h.message)
946
+ };
947
+ }
948
+ }
949
+ /**
950
+ * 数据对象转 XML 字符串
951
+ *
952
+ * @author tony001
953
+ * @date 2025-03-03 11:03:51
954
+ * @static
955
+ * @param {IChatSuggestion[]} suggestions
956
+ * @return {*} {string}
957
+ */
958
+ static stringify(e) {
959
+ const t = document.implementation.createDocument(null, null, null), s = t.createElement("suggestions");
960
+ s.setAttribute("version", "1.0");
961
+ const i = (n) => "\n".concat(" ".repeat(n)), o = 1;
962
+ return e.forEach((n) => {
963
+ s.appendChild(t.createTextNode(i(o)));
964
+ const l = t.createElement("suggestion");
965
+ l.setAttribute("type", n.type), l.setAttribute("version", "1.0");
966
+ const h = (c, u) => {
967
+ const d = t.createElement(c);
968
+ d.appendChild(t.createTextNode(i(o + 1)));
969
+ const p = t.createCDATASection(JSON.stringify(u));
970
+ return d.appendChild(p), d.appendChild(t.createTextNode(i(o))), d;
971
+ };
972
+ l.appendChild(
973
+ t.createTextNode(i(o + 1))
974
+ ), l.appendChild(h("data", n.data)), l.appendChild(
975
+ t.createTextNode(i(o + 1))
976
+ ), l.appendChild(
977
+ h("metadata", n.metadata)
978
+ ), l.appendChild(t.createTextNode(i(o))), s.appendChild(l);
979
+ }), s.appendChild(t.createTextNode("\n")), t.appendChild(s), new XMLSerializer().serializeToString(t).replace(/></g, ">\n<");
980
+ }
981
+ }
982
+ class Be {
983
+ /**
984
+ * @description 解析工具调用
985
+ * @static
986
+ * @param {string} toolCallString
987
+ * @returns {*} {IChatToolCall[]}
988
+ * @memberof ChatToolCallParser
989
+ */
990
+ static parse(e) {
991
+ const t = new RegExp(
992
+ "<tool_call>\\s*({[\\s\\S]*?})\\s*</tool_call>",
993
+ "g"
994
+ ), s = e.matchAll(t), i = [];
995
+ for (const o of s)
996
+ try {
997
+ const n = JSON.parse(o[1]), l = {
998
+ name: n.name,
999
+ parameters: n.parameters,
1000
+ error: n.error || !1
1001
+ };
1002
+ n.result && Object.assign(l, {
1003
+ result: n.result
1004
+ }), i.push(l);
1005
+ } catch (n) {
1006
+ console.error("解析工具调用失败:", n);
1007
+ }
1008
+ return i;
1009
+ }
1010
+ }
1011
+ class L {
1012
+ constructor(e) {
1013
+ v(this, "toolcalls", []);
1014
+ /**
1015
+ * @description 消息的所有原始内容
1016
+ * - 用于维护工具调用消息数据
1017
+ * @type {string}
1018
+ * @memberof ChatMessage
1019
+ */
1020
+ v(this, "allcontent", "");
1021
+ this.msg = e, this.toolcalls = e.toolcalls || [], this.allcontent = e.content;
1022
+ }
1023
+ get messageid() {
1024
+ return this.msg.messageid;
1025
+ }
1026
+ get state() {
1027
+ return this.msg.state;
1028
+ }
1029
+ get role() {
1030
+ return this.msg.role;
1031
+ }
1032
+ get type() {
1033
+ return this.msg.type;
1034
+ }
1035
+ get status() {
1036
+ return this.msg.status;
1037
+ }
1038
+ get realcontent() {
1039
+ let e = this.msg.content;
1040
+ if (e.indexOf("<think>") !== -1 && e.indexOf("</think>") === -1 || (e = e.replace(new RegExp("\\<think\\>[^]*?\\<\\/think\\>", "gs"), "").trim(), e.indexOf("<tool_call>") !== -1 && e.indexOf("</tool_call>") === -1) || (e = e.replace(new RegExp("\\<tool_call\\>[^]*?\\<\\/tool_call\\>", "gs"), "").trim(), e.indexOf("<resources>") !== -1 && e.indexOf("</resources>") === -1))
1041
+ return "";
1042
+ e = e.replace(new RegExp("\\<resources\\>[^]*?\\<\\/resources\\>", "gs"), "").trim();
1043
+ const t = e.indexOf("<suggestions>");
1044
+ return t !== -1 && (e = e.substring(0, t).trim()), e;
1045
+ }
1046
+ get content() {
1047
+ return this.msg.content;
1048
+ }
1049
+ get completed() {
1050
+ return this.msg.completed;
1051
+ }
1052
+ get suggestions() {
1053
+ return this.msg.suggestions;
1054
+ }
1055
+ get _origin() {
1056
+ return this.msg;
1057
+ }
1058
+ get islike() {
1059
+ return this.msg.islike;
1060
+ }
1061
+ get isdislike() {
1062
+ return this.msg.isdislike;
1063
+ }
1064
+ get feedbackcontent() {
1065
+ return this.msg.feedbackcontent;
1066
+ }
1067
+ get realmessageid() {
1068
+ return this.msg.realmessageid;
1069
+ }
1070
+ /**
1071
+ * 更新消息
1072
+ *
1073
+ * @author chitanda
1074
+ * @date 2023-10-10 17:10:07
1075
+ * @param {IChatMessage} msg
1076
+ */
1077
+ update(e) {
1078
+ e.content || (e.content = ""), this.allcontent += e.content, e.content.indexOf("<think>") !== -1 && this.msg.content && (this.msg.content = ""), this.msg.content += e.content, this.computeToolCalls();
1079
+ }
1080
+ /**
1081
+ * @description 替换消息
1082
+ * @param {IChatMessage} msg
1083
+ * @memberof ChatMessage
1084
+ */
1085
+ replace(e) {
1086
+ this.msg = e;
1087
+ }
1088
+ /**
1089
+ * 更新消息完成状态
1090
+ *
1091
+ * @author tony001
1092
+ * @date 2025-02-25 17:02:31
1093
+ * @param {boolean} completed
1094
+ */
1095
+ updateCompleted(e) {
1096
+ this.msg.completed = e;
1097
+ }
1098
+ /**
1099
+ * @description 计算工具调用
1100
+ * @memberof ChatMessage
1101
+ */
1102
+ computeToolCalls() {
1103
+ this.toolcalls = Be.parse(this.allcontent);
1104
+ }
1105
+ }
1106
+ class $ {
1107
+ constructor(e) {
1108
+ this.data = e;
1109
+ }
1110
+ get appid() {
1111
+ return this.data.appid;
1112
+ }
1113
+ get id() {
1114
+ return this.data.id;
1115
+ }
1116
+ get type() {
1117
+ return this.data.type;
1118
+ }
1119
+ get caption() {
1120
+ return this.data.caption;
1121
+ }
1122
+ get sourceCaption() {
1123
+ return this.data.sourceCaption;
1124
+ }
1125
+ get url() {
1126
+ return this.data.url;
1127
+ }
1128
+ get aiChat() {
1129
+ return this.data.aiChat;
1130
+ }
1131
+ get captionMode() {
1132
+ return this.data.captionMode;
1133
+ }
1134
+ get captionFilled() {
1135
+ return this.data.captionFilled;
1136
+ }
1137
+ get realid() {
1138
+ return this.data.realid;
1139
+ }
1140
+ get sequence() {
1141
+ return this.data.sequence;
1142
+ }
1143
+ get isTop() {
1144
+ return this.data.isTop;
1145
+ }
1146
+ get disableStorage() {
1147
+ return this.data.disableStorage || !1;
1148
+ }
1149
+ }
1150
+ class F {
1151
+ constructor(e) {
1152
+ this.material = e;
1153
+ }
1154
+ get id() {
1155
+ return this.material.id;
1156
+ }
1157
+ get type() {
1158
+ return this.material.type;
1159
+ }
1160
+ get metadata() {
1161
+ return this.material.metadata;
1162
+ }
1163
+ get data() {
1164
+ return this.material.data;
1165
+ }
1166
+ }
1167
+ class $e {
1168
+ constructor(e) {
1169
+ this.agent = e;
1170
+ }
1171
+ get id() {
1172
+ return this.agent.id;
1173
+ }
1174
+ get caption() {
1175
+ return this.agent.caption;
1176
+ }
1177
+ get default() {
1178
+ return this.agent.default;
1179
+ }
1180
+ get order() {
1181
+ return this.agent.order;
1182
+ }
1183
+ get value() {
1184
+ return this.agent.id;
1185
+ }
1186
+ get label() {
1187
+ return this.agent.caption;
1188
+ }
1189
+ }
1190
+ var I = /* @__PURE__ */ ((a) => (a.DATA_BASE_NAME = "ibiz-chat", a.DATA_TABLE_NAME = "history-message", a.DATA_TABLE_KEY_NAME = "id", a))(I || {});
1191
+ function Re(a) {
1192
+ switch (a) {
1193
+ case "user":
1194
+ return "USER";
1195
+ case "agent":
1196
+ return "ASSISTANT";
1197
+ case "system":
1198
+ return "SYSTEM";
1199
+ default:
1200
+ return "USER";
1201
+ }
1202
+ }
1203
+ function ze(a) {
1204
+ switch (a) {
1205
+ case "pending":
1206
+ return 20;
1207
+ case "sent":
1208
+ return 30;
1209
+ case "failed":
1210
+ return 40;
1211
+ case "canceled":
1212
+ return 30;
1213
+ default:
1214
+ return 30;
1215
+ }
1216
+ }
1217
+ function qe(a) {
1218
+ switch (a) {
1219
+ case "pending":
1220
+ case "sent":
1221
+ case "canceled":
1222
+ return "DEFAULT";
1223
+ case "failed":
1224
+ return "ERROR";
1225
+ default:
1226
+ return "DEFAULT";
1227
+ }
1228
+ }
1229
+ function Fe(a) {
1230
+ return {
1231
+ messageid: a.id,
1232
+ state: ze(a.status),
1233
+ type: qe(a.status),
1234
+ role: Re(a.sender_type),
1235
+ content: a.content,
1236
+ completed: !0,
1237
+ islike: a.is_like,
1238
+ isdislike: a.is_dislike,
1239
+ feedbackcontent: a.feedback_content,
1240
+ realmessageid: a.id,
1241
+ status: a.status
1242
+ };
1243
+ }
1244
+ class Y {
1245
+ /**
1246
+ * Creates an instance of AiChatController.
1247
+ *
1248
+ * @author chitanda
1249
+ * @date 2023-10-15 19:10:34
1250
+ * @param {IChatOptions} opts 聊天配置
1251
+ * @param {IChatOptions} resourceOptions 资源配置
1252
+ */
1253
+ constructor(e, t) {
1254
+ /**
1255
+ * 事件触发器
1256
+ * @type {EventBase}
1257
+ */
1258
+ v(this, "evt", new Ce());
1259
+ /**
1260
+ * 聊天记录
1261
+ *
1262
+ * @author chitanda
1263
+ * @date 2023-10-16 16:10:29
1264
+ * @type {Signal<ChatMessage[]>}
1265
+ */
1266
+ v(this, "messages", w([]));
1267
+ /**
1268
+ * 素材列表
1269
+ *
1270
+ * @author tony001
1271
+ * @date 2025-02-27 18:02:46
1272
+ * @type {Signal<IMaterial[]>}
1273
+ */
1274
+ v(this, "materials", w([]));
1275
+ /**
1276
+ * 聊天框输入值
1277
+ *
1278
+ * @author chitanda
1279
+ * @date 2023-10-16 15:10:43
1280
+ * @type {Signal<string>}
1281
+ */
1282
+ v(this, "input", w(""));
1283
+ /**
1284
+ * 是否加载中
1285
+ *
1286
+ * @author tony001
1287
+ * @date 2025-03-10 18:03:42
1288
+ * @type {Signal<boolean>}
1289
+ */
1290
+ v(this, "isLoading", w(!1));
1291
+ /**
1292
+ * 是否允许切换AI代理
1293
+ */
1294
+ v(this, "enableAIAgentChange", !0);
1295
+ /**
1296
+ * 激活AI代理标识
1297
+ *
1298
+ * @type {(string | undefined)}
1299
+ */
1300
+ v(this, "activeAIAgentID");
1301
+ /**
1302
+ * AI代理列表
1303
+ *
1304
+ * @type {Signal<AIAgent[]>}
1305
+ */
1306
+ v(this, "agentList", w([]));
1307
+ /**
1308
+ * 视图参数
1309
+ *
1310
+ * @author tony001
1311
+ * @date 2025-02-24 14:02:23
1312
+ * @type {object}
1313
+ */
1314
+ v(this, "context");
1315
+ /**
1316
+ * 视图参数
1317
+ *
1318
+ * @author tony001
1319
+ * @date 2025-02-24 14:02:32
1320
+ * @type {object}
1321
+ */
1322
+ v(this, "params");
1323
+ /**
1324
+ * 应用实体标记
1325
+ *
1326
+ * @author tony001
1327
+ * @date 2025-02-24 14:02:10
1328
+ * @type {string}
1329
+ */
1330
+ v(this, "appDataEntityId");
1331
+ /**
1332
+ * 话题标识
1333
+ *
1334
+ * @author tony001
1335
+ * @date 2025-02-24 18:02:02
1336
+ * @type {(string | undefined)}
1337
+ */
1338
+ v(this, "topicId");
1339
+ /**
1340
+ * 话题数据
1341
+ *
1342
+ * @author tony001
1343
+ * @date 2025-03-10 16:03:26
1344
+ * @type {(ITopic | undefined)}
1345
+ */
1346
+ v(this, "topic");
1347
+ /**
1348
+ * 话题控制器
1349
+ */
1350
+ v(this, "aiTopic");
1351
+ /**
1352
+ * @description 聊天sessionid
1353
+ * @type {string}
1354
+ * @memberof AiChatController
1355
+ */
1356
+ v(this, "chatSessionid", "");
1357
+ /**
1358
+ * 模式参数,用于业务区分
1359
+ */
1360
+ v(this, "chatMode");
1361
+ this.opts = e, this.resourceOptions = t, this.context = e.context, this.params = e.params, this.appDataEntityId = e.appDataEntityId, this.aiTopic = e.aiTopic, this.topicId = e.topicId, this.topic = e.topic, this.activeAIAgentID = e.activeAIAgentID, this.enableAIAgentChange = !!e.enableAIAgentChange, this.chatMode = e.srfMode, this.chatSessionid = e.sessionid, this.initAIChat();
1362
+ }
1363
+ /**
1364
+ * AI资源模式
1365
+ */
1366
+ get resourceMode() {
1367
+ var e;
1368
+ return ((e = this.resourceOptions) == null ? void 0 : e.resourceMode) || "LOCAL";
1369
+ }
1370
+ /**
1371
+ * 当前话题是否禁止存储
1372
+ */
1373
+ get currentTopicDisableStorage() {
1374
+ if (this.topicId && this.aiTopic) {
1375
+ const e = this.aiTopic.getCurrentTopicByID(this.topicId);
1376
+ if (e && e.disableStorage)
1377
+ return !0;
1378
+ }
1379
+ return !1;
1380
+ }
1381
+ /**
1382
+ * 初始化
1383
+ */
1384
+ async initAIChat() {
1385
+ this.messages.value = [], await this.initAIChatAgent(), await this.fecthHistory();
1386
+ }
1387
+ /**
1388
+ * 初始化AI代理列表
1389
+ */
1390
+ async initAIChatAgent() {
1391
+ this.opts.aiAgentlist && this.opts.aiAgentlist.length > 0 && this.opts.aiAgentlist.forEach((e) => {
1392
+ this.agentList.value = [...this.agentList.value, new $e(e)];
1393
+ });
1394
+ }
1395
+ /**
1396
+ * 获取历史记录存储key(用于适配不同智能体存在不同的历史记录)
1397
+ * @param topicId 话题标识
1398
+ * @returns 历史存储key
1399
+ */
1400
+ getHistoryStoreKey(e) {
1401
+ return "".concat(e);
1402
+ }
1403
+ /**
1404
+ * 获取历史记录
1405
+ *
1406
+ * @author tony001
1407
+ * @date 2025-02-24 13:02:52
1408
+ * @return {*} {Promise<boolean>}
1409
+ */
1410
+ async fecthHistory() {
1411
+ if (this.topicId) {
1412
+ let t = {};
1413
+ if (this.currentTopicDisableStorage)
1414
+ t.data = [];
1415
+ else if (this.resourceMode === "LOCAL")
1416
+ t = await x.getData(
1417
+ I.DATA_BASE_NAME,
1418
+ I.DATA_TABLE_NAME,
1419
+ this.getHistoryStoreKey(this.topicId)
1420
+ );
1421
+ else if (this.resourceMode === "REMOTE" && this.resourceOptions) {
1422
+ const s = await this.resourceOptions.getMessages({
1423
+ n_session_id_eq: this.chatSessionid
1424
+ });
1425
+ if (s && s.length > 0) {
1426
+ const i = [];
1427
+ s.forEach((o) => {
1428
+ i.push(Fe(o));
1429
+ }), t.data = i;
1430
+ }
1431
+ }
1432
+ if (t && t.data && t.data.length > 0)
1433
+ return t.data.forEach((s) => {
1434
+ const i = {
1435
+ messageid: s.messageid,
1436
+ state: s.state,
1437
+ type: s.type,
1438
+ role: s.role,
1439
+ islike: s.islike,
1440
+ isdislike: s.isdislike,
1441
+ feedbackcontent: s.feedbackcontent,
1442
+ content: s.content,
1443
+ suggestions: s.suggestions,
1444
+ completed: !0,
1445
+ toolcalls: s.toolcalls,
1446
+ realmessageid: s.realmessageid,
1447
+ status: s.status
1448
+ };
1449
+ this.addMessage(i);
1450
+ }), await this.afterFecthHistory(), !0;
1451
+ }
1452
+ return await this.opts.history(this.context, this.params, {
1453
+ appDataEntityId: this.appDataEntityId,
1454
+ appendCurData: this.opts.appendCurData,
1455
+ sessionid: this.chatSessionid,
1456
+ srfaiagent: this.activeAIAgentID,
1457
+ srfmode: this.chatMode
1458
+ }) && await this.afterFecthHistory(), !0;
1459
+ }
1460
+ /**
1461
+ * 获取历史记录后续处理
1462
+ */
1463
+ async afterFecthHistory() {
1464
+ if (this.opts.appendCurContent && this.addMessage({
1465
+ state: 30,
1466
+ messageid: B(),
1467
+ role: "USER",
1468
+ type: "DEFAULT",
1469
+ content: this.opts.appendCurContent,
1470
+ completed: !0,
1471
+ status: "sent"
1472
+ }), this.opts.appendCurResource) {
1473
+ const { hasResources: e, resources: t } = j.parseMixedContent(this.opts.appendCurResource);
1474
+ e && t && t.length > 0 && t.forEach((s) => {
1475
+ this.replaceMaterial(s.id, s);
1476
+ });
1477
+ }
1478
+ if (this.opts.autoQuestion !== !1) {
1479
+ const e = this.messages.value.length - 1, t = this.messages.value[e];
1480
+ if (t && t.role === "USER") {
1481
+ const s = this.stringlyMaterialResource(!1);
1482
+ if (s) {
1483
+ const i = s + t.content, o = {
1484
+ ...t._origin,
1485
+ messageid: B(),
1486
+ content: i
1487
+ };
1488
+ this.messages.value[e] = new L(o), this.messages.value = [...this.messages.value];
1489
+ }
1490
+ try {
1491
+ this.isLoading.value = !0, await this.opts.question(
1492
+ this,
1493
+ this.context,
1494
+ this.params,
1495
+ { appDataEntityId: this.appDataEntityId },
1496
+ this.getMessages(),
1497
+ this.chatSessionid,
1498
+ this.activeAIAgentID,
1499
+ this.chatMode
1500
+ ), this.opts.action && await this.opts.action("question", t.content);
1501
+ } finally {
1502
+ this.isLoading.value = !1;
1503
+ }
1504
+ }
1505
+ }
1506
+ await this.updateTopicCaption();
1507
+ }
1508
+ /**
1509
+ * 更新数据到indexdb
1510
+ *
1511
+ * @author tony001
1512
+ * @date 2025-02-24 18:02:41
1513
+ * @return {*} {Promise<void>}
1514
+ */
1515
+ async asyncToIndexDB() {
1516
+ if (!this.topicId || this.resourceMode !== "LOCAL" || this.currentTopicDisableStorage)
1517
+ return;
1518
+ const e = {
1519
+ id: this.getHistoryStoreKey(this.topicId),
1520
+ data: this.messages.value.map((t) => ({
1521
+ ...t._origin,
1522
+ toolcalls: t.toolcalls ? [...t.toolcalls] : []
1523
+ })),
1524
+ timestamp: (/* @__PURE__ */ new Date()).getTime()
1525
+ };
1526
+ await x.updateData(
1527
+ I.DATA_BASE_NAME,
1528
+ I.DATA_TABLE_NAME,
1529
+ e
1530
+ );
1531
+ }
1532
+ /**
1533
+ * 设置聊天框值
1534
+ *
1535
+ * @author chitanda
1536
+ * @date 2023-10-16 16:10:21
1537
+ * @param {string} input
1538
+ */
1539
+ setInput(e) {
1540
+ this.input.value = e || "";
1541
+ }
1542
+ /**
1543
+ * 新增聊天记录
1544
+ *
1545
+ * @author chitanda
1546
+ * @date 2023-10-09 15:10:15
1547
+ * @param {IMessage} data
1548
+ */
1549
+ addMessage(e) {
1550
+ const t = this.messages.value.find(
1551
+ (s) => s.messageid === e.messageid
1552
+ );
1553
+ t ? (t.update(e), this.messages.value = [...this.messages.value]) : this.messages.value = [...this.messages.value, new L(e)], this.asyncToIndexDB();
1554
+ }
1555
+ /**
1556
+ * 更新消息完成状态
1557
+ *
1558
+ * @author tony001
1559
+ * @date 2025-02-25 17:02:19
1560
+ * @param {string} id
1561
+ * @param {boolean} completed
1562
+ */
1563
+ async completeMessage(e, t) {
1564
+ const s = this.messages.value.find((i) => i.messageid === e);
1565
+ if (s && (s.updateCompleted(t), this.messages.value = [...this.messages.value], await this.asyncToIndexDB()), this.opts.autoFill === !0) {
1566
+ const i = s || this.messages.value[this.messages.value.length - 1];
1567
+ i.role === "ASSISTANT" && i.state === 30 && this.backfill(i);
1568
+ }
1569
+ this.evt.emit("onCompleteMessage", {
1570
+ messageid: e,
1571
+ completed: t
1572
+ });
1573
+ }
1574
+ /**
1575
+ * 替换已经存在的聊天消息
1576
+ *
1577
+ * @author chitanda
1578
+ * @date 2023-10-16 22:10:49
1579
+ * @param {IChatMessage} data
1580
+ */
1581
+ replaceMessage(e, t = !0) {
1582
+ const s = this.messages.value.findIndex(
1583
+ (i) => i.messageid === e.messageid
1584
+ );
1585
+ s !== -1 ? (this.messages.value[s].replace(e), this.messages.value = [...this.messages.value]) : this.messages.value = [...this.messages.value, new L(e)], this.asyncToIndexDB(), e.type === "DEFAULT" && this.opts.recommendPrompt && t && this.opts.recommendPrompt(this.context, this.params, {
1586
+ appDataEntityId: this.appDataEntityId,
1587
+ message: {
1588
+ messages: [e],
1589
+ sessionid: this.chatSessionid,
1590
+ srfaiagent: this.activeAIAgentID
1591
+ }
1592
+ }).then((i) => {
1593
+ i && i.content && this.updateRecommendPrompt(e, i.content);
1594
+ });
1595
+ }
1596
+ /**
1597
+ * 终止消息
1598
+ *
1599
+ * @author tony001
1600
+ * @date 2025-03-10 14:03:17
1601
+ * @param {IChatMessage} data
1602
+ */
1603
+ async stopMessage(e) {
1604
+ const t = this.messages.value.findIndex(
1605
+ (s) => s.messageid === e.messageid
1606
+ );
1607
+ e.content = e.content || "用户中断", t !== -1 ? (this.messages.value[t].replace(e), this.messages.value = [...this.messages.value]) : this.messages.value = [...this.messages.value, new L(e)], await this.asyncToIndexDB();
1608
+ }
1609
+ /**
1610
+ * 数据对象转 XML 字符串
1611
+ *
1612
+ * @author tony001
1613
+ * @date 2025-03-03 11:03:55
1614
+ * @return {*} {string}
1615
+ */
1616
+ stringlyMaterialResource(e = !0) {
1617
+ let t = "";
1618
+ const s = [];
1619
+ return this.materials.value && this.materials.value.length > 0 && (this.materials.value.forEach((i) => {
1620
+ if (i.type === "ossfile") {
1621
+ const o = i.metadata;
1622
+ o.state && o.state === "successed" && s.push(i);
1623
+ } else
1624
+ s.push(i);
1625
+ }), e && (this.materials.value = [])), s && s.length > 0 && (t = j.stringify(s)), t;
1626
+ }
1627
+ /**
1628
+ * @description 获取当前会话的消息集合
1629
+ * @private
1630
+ * @returns {*} {IChatMessage[]}
1631
+ * @memberof AiChatController
1632
+ */
1633
+ getMessages() {
1634
+ const e = this.messages.value.filter((t) => t.type !== "ERROR" && t.status !== "canceled").map((t) => t._origin);
1635
+ return e.forEach((t) => {
1636
+ t.content = t.content.replace(new RegExp("\\<tool_call\\>[^]*?\\<\\/tool_call\\>", "gs"), "").trim();
1637
+ }), e;
1638
+ }
1639
+ /**
1640
+ * 获取完整消息集合
1641
+ * @returns
1642
+ */
1643
+ getAllMessages() {
1644
+ return this.messages.value.map((e) => e._origin);
1645
+ }
1646
+ /**
1647
+ * 提问
1648
+ *
1649
+ * @author chitanda
1650
+ * @date 2023-10-09 20:10:43
1651
+ * @return {*} {Promise<void>}
1652
+ */
1653
+ async question(e) {
1654
+ try {
1655
+ this.isLoading.value = !0, this.messages.value.forEach((s, i) => {
1656
+ const o = s._origin;
1657
+ o.suggestions && (o.suggestions = void 0, this.messages.value[i].replace(o));
1658
+ }), this.messages.value = [...this.messages.value], this.asyncToIndexDB();
1659
+ let t = this.stringlyMaterialResource(!1);
1660
+ t ? t += "\n".concat(e) : t = e, this.addMessage({
1661
+ state: 30,
1662
+ messageid: B(),
1663
+ role: "USER",
1664
+ type: "DEFAULT",
1665
+ content: t,
1666
+ status: "sent"
1667
+ }), await this.opts.question(
1668
+ this,
1669
+ this.context,
1670
+ this.params,
1671
+ { appDataEntityId: this.appDataEntityId },
1672
+ this.getMessages(),
1673
+ this.chatSessionid,
1674
+ this.activeAIAgentID,
1675
+ this.chatMode
1676
+ ), await this.updateTopicCaption(), this.opts.action && this.opts.action("question", e), this.isLoading.value = !1;
1677
+ } finally {
1678
+ this.isLoading.value = !1;
1679
+ }
1680
+ }
1681
+ /**
1682
+ * 中断请求
1683
+ *
1684
+ * @author tony001
1685
+ * @date 2025-03-10 14:03:48
1686
+ */
1687
+ async abortQuestion() {
1688
+ try {
1689
+ await this.opts.abortQuestion(this, this.context, this.params, {
1690
+ appDataEntityId: this.appDataEntityId,
1691
+ sessionid: this.chatSessionid,
1692
+ srfaiagent: this.activeAIAgentID,
1693
+ srfmode: this.chatMode
1694
+ });
1695
+ } finally {
1696
+ this.isLoading.value = !1;
1697
+ }
1698
+ }
1699
+ /**
1700
+ * 回填选中的消息
1701
+ *
1702
+ * @author chitanda
1703
+ * @date 2023-10-16 18:10:19
1704
+ * @param {IChatMessage} message
1705
+ */
1706
+ backfill(e) {
1707
+ this.opts.action && this.opts.action("backfill", e);
1708
+ }
1709
+ /**
1710
+ *
1711
+ * 删除指定消息,如果是用户提问的刷新调用的删除,则需要删除从问题开始到最后的所有记录
1712
+ * @param {IChatMessage} message
1713
+ * @param {boolean} [isuser=false]
1714
+ * @memberof AiChatController
1715
+ */
1716
+ async deleteMessage(e) {
1717
+ const t = this.messages.value.findIndex(
1718
+ (s) => s.messageid === e.messageid
1719
+ );
1720
+ t !== -1 && (this.messages.value.splice(t, 1), this.messages.value = [...this.messages.value]), this.asyncToIndexDB(), this.resourceMode === "REMOTE" && this.resourceOptions && e.realmessageid && await this.resourceOptions.deleteMessage(e.realmessageid), this.opts.action && this.opts.action("deletemsg", e);
1721
+ }
1722
+ /**
1723
+ * 刷新当前消息
1724
+ *
1725
+ * @memberof AiChatController
1726
+ */
1727
+ async refreshMessage(e, t = !1) {
1728
+ this.isLoading.value = !0;
1729
+ try {
1730
+ const s = this.messages.value.findIndex(
1731
+ (i) => i.messageid === e.messageid
1732
+ );
1733
+ if (t)
1734
+ this.messages.value.splice(s + 1, this.messages.value.length - s - 1), this.messages.value = [...this.messages.value], await this.opts.question(
1735
+ this,
1736
+ this.context,
1737
+ this.params,
1738
+ { appDataEntityId: this.appDataEntityId },
1739
+ this.getMessages(),
1740
+ this.chatSessionid,
1741
+ this.activeAIAgentID,
1742
+ this.chatMode
1743
+ );
1744
+ else if (s === this.messages.value.length - 1)
1745
+ this.messages.value.pop(), this.messages.value = [...this.messages.value], await this.opts.question(
1746
+ this,
1747
+ this.context,
1748
+ this.params,
1749
+ { appDataEntityId: this.appDataEntityId },
1750
+ this.getMessages(),
1751
+ this.chatSessionid,
1752
+ this.activeAIAgentID,
1753
+ this.chatMode
1754
+ );
1755
+ else {
1756
+ const i = this.messages.value[s - 1].content;
1757
+ this.messages.value.splice(s - 1, 2), this.question(i);
1758
+ }
1759
+ this.asyncToIndexDB(), this.opts.action && this.opts.action("refreshmsg", e);
1760
+ } finally {
1761
+ this.isLoading.value = !1;
1762
+ }
1763
+ }
1764
+ /**
1765
+ * 复制消息
1766
+ *
1767
+ * @param {IChatMessage} message
1768
+ * @memberof AiChatController
1769
+ */
1770
+ copyMessage(e) {
1771
+ const t = e.realcontent;
1772
+ Z.copy(t), this.opts.action && this.opts.action("copymsg", e);
1773
+ }
1774
+ /**
1775
+ * 重置对话(清空当前对话、查询历史)
1776
+ * @returns
1777
+ */
1778
+ async resetTopic() {
1779
+ let e = !0;
1780
+ return e = await this.clearTopic(), e && (await this.fecthHistory(), e);
1781
+ }
1782
+ /**
1783
+ * 清空对话
1784
+ * @returns
1785
+ */
1786
+ async clearTopic() {
1787
+ let e = !0;
1788
+ if (await this.abortQuestion(), this.topicId)
1789
+ this.topicId && this.aiTopic && (this.currentTopicDisableStorage ? e = !0 : this.resourceMode === "LOCAL" ? e = await x.deleteData(
1790
+ I.DATA_BASE_NAME,
1791
+ I.DATA_TABLE_NAME,
1792
+ this.getHistoryStoreKey(this.topicId)
1793
+ ) : this.resourceMode === "REMOTE" && (e = await this.aiTopic.clearMessagesByTopicId(this.topicId)));
1794
+ else if (this.resourceMode === "REMOTE" && this.resourceOptions) {
1795
+ const t = await this.resourceOptions.getSessionList({
1796
+ n_session_id_eq: this.chatSessionid
1797
+ });
1798
+ t && t.length > 0 && (e = await this.resourceOptions.clearAllMessageBySessionId(
1799
+ t[0].realid
1800
+ ));
1801
+ }
1802
+ return e && (this.messages.value = [], e);
1803
+ }
1804
+ /**
1805
+ * 新建话题
1806
+ */
1807
+ async newTopic() {
1808
+ this.topicId && this.aiTopic && this.aiTopic.newTopic(this.topicId, {
1809
+ activeAIAgentID: this.activeAIAgentID,
1810
+ sessionid: "".concat(G(this.chatSessionid), "@").concat((/* @__PURE__ */ new Date()).getTime())
1811
+ });
1812
+ }
1813
+ /**
1814
+ * 新增素材资源
1815
+ *
1816
+ * @author tony001
1817
+ * @date 2025-02-27 18:02:00
1818
+ * @param {IMaterial} data
1819
+ */
1820
+ addMaterial(e) {
1821
+ this.materials.value.find((s) => s.id === e.id) ? this.materials.value = [...this.materials.value] : this.materials.value = [...this.materials.value, new F(e)];
1822
+ }
1823
+ /**
1824
+ * 替换素材资源
1825
+ *
1826
+ * @author tony001
1827
+ * @date 2025-02-28 15:02:24
1828
+ * @param {string} id
1829
+ * @param {IMaterial} data
1830
+ */
1831
+ replaceMaterial(e, t) {
1832
+ const s = this.materials.value.findIndex((i) => i.id === e);
1833
+ s !== -1 ? (this.materials.value[s] = new F(t), this.materials.value = [...this.materials.value]) : this.materials.value = [...this.materials.value, new F(t)];
1834
+ }
1835
+ /**
1836
+ * 删除指定素材资源
1837
+ *
1838
+ * @author tony001
1839
+ * @date 2025-02-27 18:02:33
1840
+ * @param {IMaterial} data
1841
+ */
1842
+ deleteMaterial(e) {
1843
+ const t = this.materials.value.findIndex((s) => s.id === e.id);
1844
+ t !== -1 && (this.materials.value.splice(t, 1), this.materials.value = [...this.materials.value]);
1845
+ }
1846
+ /**
1847
+ * 更新指定消息推荐提示
1848
+ *
1849
+ * @author tony001
1850
+ * @date 2025-03-19 11:03:47
1851
+ * @param {IChatMessage} data
1852
+ * @param {string} suggestionStr
1853
+ */
1854
+ updateRecommendPrompt(e, t) {
1855
+ if (!t)
1856
+ return;
1857
+ const s = this.messages.value.findIndex(
1858
+ (o) => o.messageid === e.messageid
1859
+ ), { suggestions: i } = Le.parseMixedContent(t);
1860
+ i && i.length > 0 && (e.suggestions = i, s !== -1 ? (this.messages.value[s] = new L(e), this.messages.value = [...this.messages.value]) : this.messages.value = [...this.messages.value, new L(e)], this.asyncToIndexDB());
1861
+ }
1862
+ /**
1863
+ * 处理建议点击
1864
+ *
1865
+ * @author tony001
1866
+ * @date 2025-03-19 12:03:25
1867
+ * @param {IChatMessage} message
1868
+ * @param {IChatSuggestion} suggestion
1869
+ * @param {MouseEvent} event
1870
+ * @return {*} {Promise<void>}
1871
+ */
1872
+ async handleSuggestionClick(e, t, s) {
1873
+ var l;
1874
+ const i = this.messages.value.findIndex(
1875
+ (h) => h.messageid === e.messageid
1876
+ );
1877
+ if (i !== -1) {
1878
+ const h = this.messages.value[i]._origin;
1879
+ h.suggestions = void 0, this.messages.value[i].replace(h), this.messages.value = [...this.messages.value];
1880
+ }
1881
+ this.asyncToIndexDB();
1882
+ const { type: o, metadata: n } = t;
1883
+ switch (o) {
1884
+ case "action":
1885
+ if (this.opts.extendToolbarClick) {
1886
+ const h = t.data.actionid, c = t.data.appid;
1887
+ if (!h)
1888
+ throw new Error("actionid不能为空");
1889
+ this.addMessage({
1890
+ messageid: B(),
1891
+ state: 30,
1892
+ type: "DEFAULT",
1893
+ role: "USER",
1894
+ content: n.content_name,
1895
+ status: "sent"
1896
+ });
1897
+ const u = { ...e };
1898
+ Object.assign(u, { topic: this.topic }), u.msg.realcontent = e.realcontent;
1899
+ const d = await this.opts.extendToolbarClick(
1900
+ s,
1901
+ {
1902
+ id: h,
1903
+ // 是否是插件应用(建议里面定义appid认为是插件应用的界面行为)
1904
+ isPluginApp: !!c,
1905
+ appId: c || this.context.srfappid
1906
+ },
1907
+ this.context,
1908
+ this.params,
1909
+ u
1910
+ ), p = (l = d == null ? void 0 : d.data) == null ? void 0 : l[0];
1911
+ p.content && this.addMessage({
1912
+ messageid: B(),
1913
+ state: 30,
1914
+ type: p.type || "DEFAULT",
1915
+ role: p.role || "ASSISTANT",
1916
+ content: p.content,
1917
+ status: "sent"
1918
+ });
1919
+ }
1920
+ break;
1921
+ case "raw":
1922
+ await this.question(t.data.content);
1923
+ break;
1924
+ default:
1925
+ throw new Error("不支持".concat(o, "推荐类型"));
1926
+ }
1927
+ }
1928
+ /**
1929
+ * 设置当前激活的AI助手ID
1930
+ * @param agentID
1931
+ */
1932
+ async setActiveAIAgentID(e) {
1933
+ this.activeAIAgentID = e, this.topicId && this.aiTopic && this.aiTopic.updateTopicChatByID(this.topicId, {
1934
+ activeAIAgentID: e
1935
+ });
1936
+ }
1937
+ /**
1938
+ * 更新当前话题标题
1939
+ */
1940
+ async updateTopicCaption() {
1941
+ const e = this.messages.value.find((t) => t.role === "USER");
1942
+ if (e) {
1943
+ if (this.topicId && this.aiTopic)
1944
+ this.aiTopic.updateTopicCaption(this.topicId, e.content);
1945
+ else if (this.resourceMode === "REMOTE" && this.resourceOptions) {
1946
+ const t = await this.resourceOptions.getSessionList({
1947
+ n_session_id_eq: this.chatSessionid
1948
+ });
1949
+ if (t && t.length > 0) {
1950
+ const s = e.content.substring(0, 15) || this.opts.caption;
1951
+ if (t[0].caption === s)
1952
+ return;
1953
+ await this.resourceOptions.updateSession(t[0].realid, {
1954
+ caption: s
1955
+ });
1956
+ }
1957
+ }
1958
+ }
1959
+ }
1960
+ /**
1961
+ * @description 消息点赞
1962
+ * @param {IChatMessage} message
1963
+ * @returns {*} {Promise<void>}
1964
+ * @memberof AiChatController
1965
+ */
1966
+ async messageLike(e) {
1967
+ const t = e.islike === "1", s = e.realmessageid;
1968
+ if (!s || !this.resourceOptions)
1969
+ return;
1970
+ (t ? await this.resourceOptions.cancelFeedback(s) : await this.resourceOptions.likeMessage(s)) && (e.islike = t ? "0" : "1", !t && e.isdislike === "1" && (e.isdislike = "0"), this.replaceMessage(e, !1));
1971
+ }
1972
+ /**
1973
+ * @description 消息点踩
1974
+ * @param {IChatMessage} message
1975
+ * @returns {*} {Promise<void>}
1976
+ * @memberof AiChatController
1977
+ */
1978
+ async messageDisLike(e) {
1979
+ const t = e.isdislike === "1", s = e.realmessageid, i = e.feedbackcontent;
1980
+ if (!s || !this.resourceOptions)
1981
+ return;
1982
+ (t ? await this.resourceOptions.cancelFeedback(s) : await this.resourceOptions.dislikeMessage(s, i)) && (e.isdislike = t ? "0" : "1", !t && e.islike === "1" && (e.islike = "0"), this.replaceMessage(e, !1));
1983
+ }
1984
+ /**
1985
+ * 销毁
1986
+ *
1987
+ * @return {*} {Promise<void>}
1988
+ * @memberof AiChatController
1989
+ */
1990
+ async destroyed() {
1991
+ await this.abortQuestion(), this.evt.reset();
1992
+ }
1993
+ }
1994
+ class _e {
1995
+ /**
1996
+ * Creates an instance of AiTopicController.
1997
+ * @author tony001
1998
+ * @date 2025-02-24 11:02:26
1999
+ * @param {ChatController} chat
2000
+ */
2001
+ constructor(e) {
2002
+ /**
2003
+ * 话题清单
2004
+ *
2005
+ * @author tony001
2006
+ * @date 2025-02-20 16:02:38
2007
+ * @type {Signal<ChatTopic[]>}
2008
+ */
2009
+ v(this, "topics", w([]));
2010
+ /**
2011
+ * 激活话题
2012
+ *
2013
+ * @author tony001
2014
+ * @date 2025-02-24 16:02:44
2015
+ * @type {(Signal<ITopic | undefined>)}
2016
+ */
2017
+ v(this, "activedTopic", w(void 0));
2018
+ /**
2019
+ * 当前话题配置备份
2020
+ *
2021
+ * @author tony001
2022
+ * @date 2025-02-24 16:02:28
2023
+ * @public
2024
+ * @type {(ITopicOptions | undefined)}
2025
+ */
2026
+ v(this, "backupOptions");
2027
+ /**
2028
+ * 远程会话列表
2029
+ */
2030
+ v(this, "remoteSessionList", []);
2031
+ /**
2032
+ * 资源模式
2033
+ */
2034
+ v(this, "resourceMode", "LOCAL");
2035
+ /**
2036
+ * 资源选项
2037
+ */
2038
+ v(this, "resourceOptions");
2039
+ this.chat = e;
2040
+ }
2041
+ /**
2042
+ * 注入资源选项
2043
+ * @param resourceOptions
2044
+ */
2045
+ injectResourceOptions(e) {
2046
+ this.resourceMode = (e == null ? void 0 : e.resourceMode) || "LOCAL", this.resourceOptions = e;
2047
+ }
2048
+ /**
2049
+ * 获取历史话题
2050
+ *
2051
+ * @author tony001
2052
+ * @date 2025-02-23 16:02:37
2053
+ * @return {*} {Promise<void>}
2054
+ */
2055
+ async fetchHistory(e) {
2056
+ this.topics.value = [];
2057
+ const s = await e.configService(
2058
+ e.appid,
2059
+ "aitopics",
2060
+ e.type
2061
+ ).load();
2062
+ s && s.length > 0 && (this.resourceMode === "REMOTE" && this.resourceOptions ? (this.remoteSessionList = await this.resourceOptions.getSessionList(), await this.asyncRemoteSession(s)) : s.forEach((i, o) => {
2063
+ Object.prototype.hasOwnProperty.call(i, "sequence") || (i.sequence = o), Object.prototype.hasOwnProperty.call(i, "isTop") || (i.isTop = 0), this.topics.value = [...this.topics.value, new $(i)];
2064
+ }));
2065
+ }
2066
+ /**
2067
+ * 同步远程会话
2068
+ * @param configList config存储数据
2069
+ */
2070
+ async asyncRemoteSession(e) {
2071
+ !this.remoteSessionList || this.remoteSessionList.length === 0 || !e || e.length === 0 || this.remoteSessionList.forEach((t) => {
2072
+ const s = e.find((i) => {
2073
+ var o;
2074
+ return ((o = i.aiChat) == null ? void 0 : o.sessionid) === t.session_id;
2075
+ });
2076
+ s && (s.realid = t.realid, s.sequence = t.sequence, s.isTop = t.is_top ? t.is_top : 0, t.caption && (s.caption = t.caption), this.topics.value = [...this.topics.value, new $(s)]);
2077
+ });
2078
+ }
2079
+ /**
2080
+ * 同步当前话题
2081
+ *
2082
+ * @author tony001
2083
+ * @date 2025-02-23 17:02:43
2084
+ * @param {ITopicOptions} options
2085
+ * @return {*} {Promise<void>}
2086
+ */
2087
+ async asyncTopic(e) {
2088
+ this.backupOptions = e;
2089
+ const t = this.topics.value.findIndex(
2090
+ (i) => i.id === e.id
2091
+ ), s = new $(e);
2092
+ t !== -1 ? this.topics.value.splice(t, 1, s) : this.topics.value = [...this.topics.value, s], await this.updateTopic(e), this.activedTopic.value = s;
2093
+ }
2094
+ /**
2095
+ * 获取指定标识话题
2096
+ * @param topicid
2097
+ * @returns
2098
+ */
2099
+ getCurrentTopicByID(e) {
2100
+ const t = this.topics.value.find((s) => s.id === e);
2101
+ return t && t.data ? new $({ ...t.data }) : void 0;
2102
+ }
2103
+ /**
2104
+ * 基于话题标识更新当前话题
2105
+ * @param topicid 话题标识
2106
+ */
2107
+ async updateTopicChatByID(e, t) {
2108
+ if (!e || !t || !this.backupOptions)
2109
+ return;
2110
+ const s = this.topics.value.findIndex(
2111
+ (i) => i.id === e
2112
+ );
2113
+ s === -1 || !this.topics.value[s].data.aiChat || (this.topics.value[s].data.aiChat = {
2114
+ ...this.topics.value[s].data.aiChat,
2115
+ ...t
2116
+ }, await this.updateTopic(this.backupOptions));
2117
+ }
2118
+ /**
2119
+ * 删除话题
2120
+ *
2121
+ * @author tony001
2122
+ * @date 2025-02-24 16:02:03
2123
+ * @param {ITopicOptions} options
2124
+ * @param {object} context
2125
+ * @param {object} params
2126
+ * @param {ITopic} data
2127
+ * @param {MouseEvent} event
2128
+ * @return {*} {Promise<void>}
2129
+ */
2130
+ async removeTopic(e, t, s, i, o) {
2131
+ var c;
2132
+ let n = !0;
2133
+ if (e.beforeDelete && (n = await e.beforeDelete(t, s, i, o)), !n)
2134
+ return;
2135
+ let l = !1;
2136
+ if (i && i.disableStorage)
2137
+ l = !0;
2138
+ else if (this.resourceMode === "LOCAL")
2139
+ l = await x.deleteData(
2140
+ I.DATA_BASE_NAME,
2141
+ I.DATA_TABLE_NAME,
2142
+ i.id
2143
+ );
2144
+ else if (this.resourceMode === "REMOTE" && this.resourceOptions) {
2145
+ if (i.realid)
2146
+ l = await this.resourceOptions.deleteSession(i.realid);
2147
+ else if (i.aiChat && i.aiChat.sessionid) {
2148
+ const u = await this.resourceOptions.getSessionList({
2149
+ n_session_id_eq: i.aiChat.sessionid
2150
+ });
2151
+ u && u.length > 0 ? l = await this.resourceOptions.deleteSession(
2152
+ u[0].realid
2153
+ ) : l = !0;
2154
+ }
2155
+ }
2156
+ if (!l)
2157
+ return;
2158
+ const h = this.topics.value.findIndex(
2159
+ (u) => u.id === i.id
2160
+ );
2161
+ h !== -1 && (this.topics.value.splice(h, 1), this.topics.value = [...this.topics.value]), await this.updateTopic(e), this.topics.value.length > 0 && i.id === ((c = this.activedTopic.value) == null ? void 0 : c.id) && this.handleTopicChange(this.topics.value[0]);
2162
+ }
2163
+ /**
2164
+ * 处理选中变化
2165
+ *
2166
+ * @author tony001
2167
+ * @date 2025-02-20 19:02:27
2168
+ * @param {ChatTopic} item
2169
+ */
2170
+ handleTopicChange(e) {
2171
+ var t;
2172
+ ((t = this.activedTopic.value) == null ? void 0 : t.id) !== e.id && (this.activedTopic.value = e, this.chat.switchAiChatController(e));
2173
+ }
2174
+ /**
2175
+ * 处理话题行为
2176
+ *
2177
+ * @author tony001
2178
+ * @date 2025-02-24 16:02:58
2179
+ * @param {string} action
2180
+ * @param {ChatTopic} topic
2181
+ * @param {MouseEvent} event
2182
+ * @return {*} {Promise<void>}
2183
+ */
2184
+ async handleTopicAction(e, t, s) {
2185
+ var o, n;
2186
+ const i = this.topics.value.find((l) => l.id === t.id);
2187
+ if (this.backupOptions && i && i.aiChat) {
2188
+ const { context: l, params: h } = i.aiChat;
2189
+ switch (e) {
2190
+ case "DELETE":
2191
+ await this.removeTopic(
2192
+ this.backupOptions,
2193
+ l,
2194
+ h,
2195
+ i,
2196
+ s
2197
+ );
2198
+ break;
2199
+ case "RENAME":
2200
+ case "PINNED":
2201
+ if (e === "PINNED" && (t.data.isTop = t.data.isTop === 0 ? 1 : 0, this.topics.value = [...this.topics.value]), t && !t.disableStorage && (await this.updateTopic(this.backupOptions), t && this.resourceMode === "REMOTE" && this.resourceOptions)) {
2202
+ if (t.realid)
2203
+ await this.resourceOptions.updateSession(t.realid, {
2204
+ caption: t.caption,
2205
+ is_top: t.isTop
2206
+ });
2207
+ else if (t.aiChat && t.aiChat.sessionid) {
2208
+ const c = await this.resourceOptions.getSessionList({
2209
+ n_session_id_eq: t.aiChat.sessionid
2210
+ });
2211
+ c && c.length > 0 && await this.resourceOptions.updateSession(
2212
+ c[0].realid,
2213
+ {
2214
+ caption: t.caption,
2215
+ is_top: t.isTop
2216
+ }
2217
+ );
2218
+ }
2219
+ }
2220
+ break;
2221
+ }
2222
+ (n = (o = this.backupOptions).action) == null || n.call(o, e, l, h, t, s);
2223
+ }
2224
+ }
2225
+ /**
2226
+ * 清空指定话题的消息
2227
+ * @param topicID
2228
+ * @returns
2229
+ */
2230
+ async clearMessagesByTopicId(e) {
2231
+ let t = !0;
2232
+ if (!e || !this.backupOptions)
2233
+ return t;
2234
+ const s = this.topics.value.findIndex(
2235
+ (o) => o.id === e
2236
+ );
2237
+ if (s === -1 || !this.topics.value[s].data)
2238
+ return t;
2239
+ const i = this.topics.value[s];
2240
+ if (!i || i.disableStorage)
2241
+ return t;
2242
+ if (this.resourceMode === "REMOTE" && this.resourceOptions) {
2243
+ if (i.realid)
2244
+ t = await this.resourceOptions.clearAllMessageBySessionId(
2245
+ i.realid
2246
+ );
2247
+ else if (i.aiChat && i.aiChat.sessionid) {
2248
+ const o = await this.resourceOptions.getSessionList({
2249
+ n_session_id_eq: i.aiChat.sessionid
2250
+ });
2251
+ o && o.length > 0 && (t = await this.resourceOptions.clearAllMessageBySessionId(
2252
+ o[0].realid
2253
+ ));
2254
+ }
2255
+ if (!t)
2256
+ return t;
2257
+ }
2258
+ return t;
2259
+ }
2260
+ /**
2261
+ * 新建对话
2262
+ *
2263
+ * @author tony001
2264
+ * @date 2025-03-18 18:03:49
2265
+ * @return {*} {Promise<void>}
2266
+ */
2267
+ async newTopic(e, t) {
2268
+ var u;
2269
+ if (!e)
2270
+ return;
2271
+ const s = this.getCurrentTopicByID(e);
2272
+ if (!s)
2273
+ return;
2274
+ const i = G(s.id), o = this.topics.value.filter((d) => d.id.startsWith(i));
2275
+ t && s.aiChat && (s.data.aiChat = {
2276
+ ...s.aiChat,
2277
+ ...t
2278
+ });
2279
+ let n = "";
2280
+ s.captionMode === "default" ? n = "".concat((u = s.sourceCaption) == null ? void 0 : u.split("_")[0], "_").concat(o.length) : n = "新会话";
2281
+ const l = Math.max(
2282
+ ...this.topics.value.map((d) => d.sequence)
2283
+ ), h = {
2284
+ appid: s.appid,
2285
+ // 源头数据id@当前时间戳
2286
+ id: "".concat(i, "@").concat(Date.now()),
2287
+ type: s.type,
2288
+ captionMode: s.captionMode,
2289
+ captionFilled: !1,
2290
+ caption: n,
2291
+ sourceCaption: s.sourceCaption,
2292
+ url: s.url,
2293
+ aiChat: s.aiChat,
2294
+ sequence: l + 1,
2295
+ isTop: 0,
2296
+ disableStorage: s.disableStorage
2297
+ }, c = new $(h);
2298
+ this.topics.value = [...this.topics.value, c], this.backupOptions && await this.updateTopic(this.backupOptions), this.handleTopicChange(c);
2299
+ }
2300
+ /**
2301
+ * 清空话题
2302
+ * - 当前激活项不清空
2303
+ * @return {*} {Promise<void>}
2304
+ * @memberof AiTopicController
2305
+ */
2306
+ async clearTopic() {
2307
+ var i;
2308
+ const e = this.topics.value.find(
2309
+ (o) => {
2310
+ var n;
2311
+ return o.id === ((n = this.activedTopic.value) == null ? void 0 : n.id);
2312
+ }
2313
+ );
2314
+ if (!this.backupOptions || !e)
2315
+ return;
2316
+ let t = !0;
2317
+ if (this.backupOptions.beforeDelete && (t = await this.backupOptions.beforeDelete(
2318
+ e.aiChat.context,
2319
+ e.aiChat.params,
2320
+ e,
2321
+ void 0,
2322
+ !0
2323
+ )), !t)
2324
+ return;
2325
+ let s = !1;
2326
+ if (this.resourceMode === "LOCAL")
2327
+ await Promise.all(
2328
+ this.topics.value.map((o) => {
2329
+ if (o.id !== (e == null ? void 0 : e.id) && !o.disableStorage)
2330
+ return x.deleteData(
2331
+ I.DATA_BASE_NAME,
2332
+ I.DATA_TABLE_NAME,
2333
+ o.id
2334
+ );
2335
+ })
2336
+ ), s = !0;
2337
+ else if (this.resourceMode === "REMOTE")
2338
+ if (e && this.resourceOptions) {
2339
+ const o = (i = e.aiChat) == null ? void 0 : i.sessionid;
2340
+ o ? s = await this.resourceOptions.clearAllSession(o) : s = !0;
2341
+ } else
2342
+ s = !0;
2343
+ s && (this.topics.value = e ? [e] : [], await this.updateTopic(this.backupOptions));
2344
+ }
2345
+ /**
2346
+ * 更新话题标题
2347
+ * @param topicId
2348
+ * @param message
2349
+ */
2350
+ async updateTopicCaption(e, t) {
2351
+ const s = this.topics.value.find((i) => i.id === e);
2352
+ if (s && !s.captionFilled) {
2353
+ if (s.captionMode !== "default") {
2354
+ switch (s.captionMode) {
2355
+ case "snippet":
2356
+ s.data.caption = t.substring(0, 15);
2357
+ break;
2358
+ }
2359
+ this.topics.value = [...this.topics.value], this.backupOptions && await this.updateTopic(this.backupOptions);
2360
+ }
2361
+ if (s.disableStorage)
2362
+ return;
2363
+ if (this.resourceMode === "REMOTE" && this.resourceOptions) {
2364
+ if (s.realid)
2365
+ await this.resourceOptions.updateSession(s.realid, {
2366
+ caption: s.caption
2367
+ });
2368
+ else if (s.aiChat && s.aiChat.sessionid) {
2369
+ const i = await this.resourceOptions.getSessionList({
2370
+ n_session_id_eq: s.aiChat.sessionid
2371
+ });
2372
+ if (i && i.length > 0) {
2373
+ if (i[0].caption === s.caption)
2374
+ return;
2375
+ await this.resourceOptions.updateSession(i[0].realid, {
2376
+ caption: s.caption
2377
+ });
2378
+ }
2379
+ }
2380
+ }
2381
+ s.data.captionFilled = !0;
2382
+ }
2383
+ }
2384
+ /**
2385
+ * 更新话题数据
2386
+ *
2387
+ * @param {ITopicOptions} options 话题配置
2388
+ * @return {*} {Promise<void>}
2389
+ * @memberof AiTopicController
2390
+ */
2391
+ async updateTopic(e) {
2392
+ if (!e)
2393
+ return;
2394
+ const t = [];
2395
+ this.topics.value.forEach((i) => {
2396
+ i.disableStorage || t.push({
2397
+ appid: i.appid,
2398
+ id: i.id,
2399
+ type: i.type,
2400
+ captionMode: i.captionMode,
2401
+ captionFilled: i.captionFilled,
2402
+ caption: i.caption || i.sourceCaption,
2403
+ sourceCaption: i.sourceCaption,
2404
+ url: i.url,
2405
+ aiChat: i.aiChat,
2406
+ isTop: i.isTop,
2407
+ sequence: i.sequence
2408
+ });
2409
+ });
2410
+ const s = e.configService(
2411
+ e.appid,
2412
+ "aitopics",
2413
+ e.type
2414
+ );
2415
+ await (s == null ? void 0 : s.save(t));
2416
+ }
2417
+ }
2418
+ class ee {
2419
+ constructor(e) {
2420
+ this.aiChat = e;
2421
+ }
2422
+ }
2423
+ class je extends ee {
2424
+ /**
2425
+ * 执行操作
2426
+ *
2427
+ * @author tony001
2428
+ * @date 2025-02-28 15:02:48
2429
+ * @return {*} {Promise<void>}
2430
+ */
2431
+ async excuteAction(e, t) {
2432
+ let s;
2433
+ if (t && t.onClick && typeof t.onClick == "function")
2434
+ s = await t.onClick(
2435
+ e,
2436
+ t,
2437
+ this.aiChat.context,
2438
+ this.aiChat.params
2439
+ );
2440
+ else {
2441
+ const i = this.aiChat.opts.extendToolbarClick;
2442
+ i ? s = await i(
2443
+ e,
2444
+ t,
2445
+ this.aiChat.context,
2446
+ this.aiChat.params,
2447
+ {}
2448
+ ) : console.error("未找到扩展工具栏点击事件");
2449
+ }
2450
+ if (s && s.data && s.data.length > 0) {
2451
+ const i = s.data[0], o = {
2452
+ id: i.id,
2453
+ type: i.type,
2454
+ data: i.data || {},
2455
+ metadata: i.metadata || {}
2456
+ };
2457
+ t.id && Object.assign(o.metadata, { actionId: t.id }), this.aiChat.addMaterial(o);
2458
+ }
2459
+ }
2460
+ }
2461
+ class Ne extends ee {
2462
+ /**
2463
+ * 执行操作
2464
+ *
2465
+ * @author tony001
2466
+ * @date 2025-02-28 15:02:27
2467
+ * @return {*} {Promise<void>}
2468
+ */
2469
+ async excuteAction(e, t) {
2470
+ const s = this.aiChat.opts.uploader, {
2471
+ multiple: i,
2472
+ accept: o,
2473
+ maxSize: n,
2474
+ onSelect: l,
2475
+ onUpload: h,
2476
+ onSuccess: c,
2477
+ onError: u,
2478
+ onProgress: d
2479
+ } = s, p = {
2480
+ multiple: i || !0,
2481
+ accept: o || "*/*",
2482
+ maxSize: n || 5 * 1024 * 1024,
2483
+ onSelect: (m) => {
2484
+ l == null || l(m), m.length > 0 && m.forEach((b) => {
2485
+ const y = this.buildMaterialObject(b);
2486
+ Object.assign(y.metadata, { state: "uploading" }), this.aiChat.addMaterial(y);
2487
+ });
2488
+ },
2489
+ onUpload: async (m, b) => h(m, b, {
2490
+ context: this.aiChat.context,
2491
+ params: this.aiChat.params
2492
+ }),
2493
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2494
+ onSuccess: (m, b) => {
2495
+ const y = {
2496
+ id: m.id,
2497
+ type: "ossfile",
2498
+ data: {
2499
+ id: m.id,
2500
+ name: m.name
2501
+ },
2502
+ metadata: {
2503
+ ext: m.ext,
2504
+ fileext: m.fileext,
2505
+ fileid: m.fileid,
2506
+ filename: m.filename,
2507
+ size: m.size,
2508
+ filesize: m.filesize,
2509
+ state: "successed"
2510
+ }
2511
+ };
2512
+ this.aiChat.replaceMaterial(b.name, y), c == null || c(m, b);
2513
+ },
2514
+ onError: (m, b) => {
2515
+ const y = this.buildMaterialObject(b);
2516
+ Object.assign(y.metadata, { state: "failed" }), this.aiChat.replaceMaterial(b.name, y), u == null || u(m, b);
2517
+ },
2518
+ onProgress: (m, b) => {
2519
+ d == null || d(m, b);
2520
+ }
2521
+ };
2522
+ new Oe(p).openFilePicker();
2523
+ }
2524
+ /**
2525
+ * 构建素材对象
2526
+ *
2527
+ * @author tony001
2528
+ * @date 2025-02-28 15:02:12
2529
+ * @param {File} file
2530
+ * @return {*} {IMaterial}
2531
+ */
2532
+ buildMaterialObject(e) {
2533
+ return {
2534
+ id: e.name,
2535
+ type: "ossfile",
2536
+ data: {
2537
+ name: e.name,
2538
+ id: e.name
2539
+ },
2540
+ metadata: {
2541
+ size: e.size,
2542
+ type: e.type,
2543
+ lastModified: e.lastModified
2544
+ }
2545
+ };
2546
+ }
2547
+ }
2548
+ class He {
2549
+ static getMaterialHelper(e, t) {
2550
+ switch (e) {
2551
+ case "ossfile":
2552
+ return new Ne(t);
2553
+ default:
2554
+ return new je(t);
2555
+ }
2556
+ }
2557
+ }
2558
+ const Pe = r("svg", {
2559
+ xmlns: "http://www.w3.org/2000/svg",
2560
+ width: "24",
2561
+ height: "24",
2562
+ viewBox: "0 0 24 24",
2563
+ fill: "none",
2564
+ stroke: "currentColor",
2565
+ "stroke-width": "2",
2566
+ "stroke-linecap": "round",
2567
+ "stroke-linejoin": "round",
2568
+ "aria-hidden": "true"
2569
+ }, [r("path", {
2570
+ d: "M12 19v3"
2571
+ }, null), r("path", {
2572
+ d: "M19 10v2a7 7 0 0 1-14 0v-2"
2573
+ }, null), r("rect", {
2574
+ x: "9",
2575
+ y: "2",
2576
+ width: "6",
2577
+ height: "13",
2578
+ rx: "3"
2579
+ }, null)]), Ue = r("svg", {
2580
+ xmlns: "http://www.w3.org/2000/svg",
2581
+ width: "24",
2582
+ height: "24",
2583
+ viewBox: "0 0 24 24",
2584
+ fill: "none",
2585
+ stroke: "currentColor",
2586
+ "stroke-width": "2",
2587
+ "stroke-linecap": "round",
2588
+ "stroke-linejoin": "round",
2589
+ "aria-hidden": "true"
2590
+ }, [r("path", {
2591
+ d: "M12 19v3"
2592
+ }, null), r("path", {
2593
+ d: "M15 9.34V5a3 3 0 0 0-5.68-1.33"
2594
+ }, null), r("path", {
2595
+ d: "M16.95 16.95A7 7 0 0 1 5 12v-2"
2596
+ }, null), r("path", {
2597
+ d: "M18.89 13.23A7 7 0 0 0 19 12v-2"
2598
+ }, null), r("path", {
2599
+ d: "m2 2 20 20"
2600
+ }, null), r("path", {
2601
+ d: "M9 9v3a3 3 0 0 0 5.12 2.12"
2602
+ }, null)]), Ve = r("svg", {
2603
+ xmlns: "http://www.w3.org/2000/svg",
2604
+ width: "24",
2605
+ height: "24",
2606
+ viewBox: "0 0 24 24",
2607
+ fill: "none",
2608
+ stroke: "currentColor",
2609
+ "stroke-width": "2",
2610
+ "stroke-linecap": "round",
2611
+ "stroke-linejoin": "round",
2612
+ "aria-hidden": "true"
2613
+ }, [r("path", {
2614
+ d: "M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"
2615
+ }, null), r("path", {
2616
+ d: "m21.854 2.147-10.94 10.939"
2617
+ }, null)]), Xe = r("svg", {
2618
+ viewBox: "0 0 1024 1024",
2619
+ version: "1.1",
2620
+ xmlns: "http://www.w3.org/2000/svg",
2621
+ "p-id": "4696",
2622
+ width: "24",
2623
+ height: "24",
2624
+ fill: "currentColor"
2625
+ }, [r("path", {
2626
+ d: "M512 960.2c-246 0-447.35-201.73-447.35-448.28S265.94 63.63 512 63.63s447.33 201.73 447.33 448.29S758 960.2 512 960.2z m144.3-104.38A377.09 377.09 0 0 0 855 656.7a371.79 371.79 0 0 0 0-289.57A377.09 377.09 0 0 0 656.3 168a369.15 369.15 0 0 0-288.64 0A377.18 377.18 0 0 0 169 367.13a371.79 371.79 0 0 0 0 289.57 377.18 377.18 0 0 0 198.66 199.12 369.15 369.15 0 0 0 288.64 0z",
2627
+ "p-id": "4697"
2628
+ }, null), r("path", {
2629
+ d: "M378.19 349.54h265.46a30.66 30.66 0 0 1 30.63 30.69v266a30.66 30.66 0 0 1-30.63 30.69H378.19a30.66 30.66 0 0 1-30.63-30.69v-266a30.66 30.66 0 0 1 30.63-30.69z",
2630
+ "p-id": "4698"
2631
+ }, null)]), q = r("svg", {
2632
+ viewBox: "0 0 1024 1024",
2633
+ version: "1.1",
2634
+ xmlns: "http://www.w3.org/2000/svg",
2635
+ "p-id": "9261",
2636
+ width: "24",
2637
+ height: "24",
2638
+ fill: "currentColor"
2639
+ }, [r("path", {
2640
+ d: "M512 20.48c271.36 0 491.52 220.16 491.52 491.52S783.36 1003.52 512 1003.52 20.48 783.36 20.48 512 240.64 20.48 512 20.48m0-20.48C229.376 0 0 229.376 0 512s229.376 512 512 512 512-229.376 512-512S794.624 0 512 0z",
2641
+ "p-id": "9262"
2642
+ }, null), r("path", {
2643
+ d: "M512 226.304l-283.648 143.36v284.672l283.648 143.36L795.648 655.36V369.664L512 226.304z m54.272 370.688h-32.768l-5.12-3.072-20.48-49.152h-95.232l-20.48 49.152-4.096 3.072h-32.768l-4.096-7.168 86.016-198.656 4.096-3.072h37.888l4.096 3.072 86.016 198.656-3.072 7.168z m88.064-5.12l-5.12 5.12h-29.696l-5.12-5.12V394.24l5.12-5.12h29.696l5.12 5.12v197.632z",
2644
+ "p-id": "9263"
2645
+ }, null), r("path", {
2646
+ d: "M427.008 512h67.584L460.8 427.008z",
2647
+ "p-id": "9264"
2648
+ }, null)]), Je = r("svg", {
2649
+ fill: "currentColor",
2650
+ viewBox: "0 0 24 24"
2651
+ }, [r("path", {
2652
+ d: "M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"
2653
+ }, null)]), Ye = r("svg", {
2654
+ width: "16",
2655
+ height: "16",
2656
+ viewBox: "0 0 50 50",
2657
+ xmlns: "http://www.w3.org/2000/svg"
2658
+ }, [r("circle", {
2659
+ cx: "25",
2660
+ cy: "25",
2661
+ r: "20",
2662
+ fill: "none",
2663
+ stroke: "currentColor",
2664
+ "stroke-width": "5",
2665
+ "stroke-dasharray": "31.415, 31.415",
2666
+ "stroke-linecap": "round"
2667
+ }, [r("animateTransform", {
2668
+ attributeName: "transform",
2669
+ type: "rotate",
2670
+ from: "0 25 25",
2671
+ to: "360 25 25",
2672
+ dur: "1s",
2673
+ repeatCount: "indefinite"
2674
+ }, null)])]), Ke = r("svg", {
2675
+ viewBox: "0 0 16 16",
2676
+ xmlns: "http://www.w3.org/2000/svg",
2677
+ width: "16",
2678
+ height: "16",
2679
+ fill: "currentColor",
2680
+ preserveAspectRatio: "xMidYMid meet",
2681
+ focusable: "false"
2682
+ }, [r("g", {
2683
+ id: "agptips/check-circle",
2684
+ "stroke-width": "1",
2685
+ "fill-rule": "evenodd"
2686
+ }, [r("path", {
2687
+ d: "M8 16A8 8 0 118 0a8 8 0 010 16zm0-1.2A6.8 6.8 0 108 1.2a6.8 6.8 0 000 13.6zM5.666 7.207l1.8 1.845 3.482-3.554.857.84-4.34 4.43-2.658-2.723.86-.838z",
2688
+ id: "agp形状结合"
2689
+ }, null)])]), Qe = r("svg", {
2690
+ viewBox: "0 0 16 16",
2691
+ xmlns: "http://www.w3.org/2000/svg",
2692
+ width: "16",
2693
+ height: "16",
2694
+ fill: "currentColor",
2695
+ preserveAspectRatio: "xMidYMid meet",
2696
+ focusable: "false",
2697
+ style: "transform: rotate(-90deg);"
2698
+ }, [r("g", {
2699
+ id: "abfnavigation/angle-right",
2700
+ "stroke-width": "1",
2701
+ "fill-rule": "evenodd"
2702
+ }, [r("path", {
2703
+ d: "M7.978 11.498l-.005.005L2.3 5.831 3.13 5l4.848 4.848L12.826 5l.83.831-5.673 5.672-.005-.005z",
2704
+ id: "abf形状结合",
2705
+ transform: "rotate(-90 7.978 8.252)"
2706
+ }, null)])]), te = r("svg", {
2707
+ viewBox: "0 0 16 16",
2708
+ xmlns: "http://www.w3.org/2000/svg",
2709
+ width: "16",
2710
+ height: "16",
2711
+ fill: "currentColor",
2712
+ preserveAspectRatio: "xMidYMid meet",
2713
+ focusable: "false",
2714
+ style: "transform: rotate(90deg);"
2715
+ }, [r("g", {
2716
+ id: "abfnavigation/angle-right",
2717
+ "stroke-width": "1",
2718
+ "fill-rule": "evenodd"
2719
+ }, [r("path", {
2720
+ d: "M7.978 11.498l-.005.005L2.3 5.831 3.13 5l4.848 4.848L12.826 5l.83.831-5.673 5.672-.005-.005z",
2721
+ id: "abf形状结合",
2722
+ transform: "rotate(-90 7.978 8.252)"
2723
+ }, null)])]), se = r("svg", {
2724
+ viewBox: "0 0 1024 1024",
2725
+ version: "1.1",
2726
+ xmlns: "http://www.w3.org/2000/svg",
2727
+ "p-id": "4832",
2728
+ width: "16",
2729
+ height: "16",
2730
+ fill: "currentColor"
2731
+ }, [r("path", {
2732
+ d: "M707.61856 495.14624l-357.5296-357.5296c-9.30816-9.30688-24.40064-9.30688-33.70752 0-9.30816 9.30816-9.30816 24.40064 0 33.7088L657.056 512 316.38144 852.67456c-9.30816 9.30688-9.30816 24.40064 0 33.7088 4.65408 4.65536 10.75328 6.98112 16.85376 6.98112 6.10048 0 12.19968-2.32576 16.85376-6.98112l357.5296-357.5296C716.92672 519.5456 716.92672 504.4544 707.61856 495.14624z",
2733
+ "p-id": "4833"
2734
+ }, null)]), We = r("svg", {
2735
+ xmlns: "http://www.w3.org/2000/svg",
2736
+ width: "16",
2737
+ height: "16",
2738
+ viewBox: "0 0 24 24",
2739
+ fill: "none",
2740
+ stroke: "red",
2741
+ "stroke-width": "2",
2742
+ "stroke-linecap": "round",
2743
+ "stroke-linejoin": "round",
2744
+ "aria-hidden": "true"
2745
+ }, [r("path", {
2746
+ d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"
2747
+ }, null), r("path", {
2748
+ d: "M12 9v4"
2749
+ }, null), r("path", {
2750
+ d: "M12 17h.01"
2751
+ }, null)]), ie = r("svg", {
2752
+ xmlns: "http://www.w3.org/2000/svg",
2753
+ width: "16",
2754
+ height: "16",
2755
+ viewBox: "0 0 24 24",
2756
+ fill: "none",
2757
+ stroke: "currentColor",
2758
+ "stroke-width": "2",
2759
+ "stroke-linecap": "round",
2760
+ "stroke-linejoin": "round",
2761
+ "aria-hidden": "true"
2762
+ }, [r("rect", {
2763
+ width: "14",
2764
+ height: "14",
2765
+ x: "8",
2766
+ y: "8",
2767
+ rx: "2",
2768
+ ry: "2"
2769
+ }, null), r("path", {
2770
+ d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"
2771
+ }, null)]), Ge = r("svg", {
2772
+ xmlns: "http://www.w3.org/2000/svg",
2773
+ viewBox: "0 0 512 512"
2774
+ }, [r("path", {
2775
+ fill: "none",
2776
+ stroke: "currentColor",
2777
+ "stroke-linecap": "round",
2778
+ "stroke-linejoin": "round",
2779
+ "stroke-width": "48",
2780
+ d: "M112 268l144 144 144-144M256 392V100"
2781
+ }, null)]), Ze = r("svg", {
2782
+ viewBox: "0 0 1024 1024",
2783
+ version: "1.1",
2784
+ xmlns: "http://www.w3.org/2000/svg",
2785
+ width: "24",
2786
+ height: "24",
2787
+ fill: "currentColor"
2788
+ }, [r("path", {
2789
+ d: "M938.2 671.3c-13.8 0-25 11.2-25 25v83.1c0 63.3-52.6 114.7-117.3 114.7H230.2c-64.7 0-117.3-51.5-117.3-114.7v-83.1c0-13.8-11.2-25-25-25s-25 11.2-25 25v83.1c0 90.8 75.1 164.7 167.3 164.7h565.7c92.3 0 167.3-73.9 167.3-164.7v-83.1c0-13.8-11.2-25-25-25z",
2790
+ "p-id": "7618"
2791
+ }, null), r("path", {
2792
+ d: "M494.4 80.8c4.7-4.7 11.1-7.4 17.7-7.4h0.1c6.7 0 13 2.7 17.7 7.4l189.7 192c9.7 9.8 9.6 25.7-0.2 35.4-9.8 9.7-25.7 9.6-35.4-0.2L538.8 161v513.7c0 13.8-11.2 25-25 25s-25-11.2-25-25V157.3L338.5 308.1c-9.7 9.8-25.6 9.8-35.4 0.1-9.8-9.7-9.8-25.6-0.1-35.4l191.4-192z",
2793
+ "p-id": "7619"
2794
+ }, null)]), et = r("svg", {
2795
+ viewBox: "0 0 1024 1024",
2796
+ version: "1.1",
2797
+ xmlns: "http://www.w3.org/2000/svg",
2798
+ width: "24",
2799
+ height: "24",
2800
+ fill: "currentColor"
2801
+ }, [r("path", {
2802
+ d: "M842.666667 285.866667l-187.733334-187.733334c-14.933333-14.933333-32-21.333333-53.333333-21.333333H234.666667C194.133333 74.666667 160 108.8 160 149.333333v725.333334c0 40.533333 34.133333 74.666667 74.666667 74.666666h554.666666c40.533333 0 74.666667-34.133333 74.666667-74.666666V337.066667c0-19.2-8.533333-38.4-21.333333-51.2z m-44.8 44.8c-2.133333 2.133333-4.266667 0-8.533334 0h-170.666666c-6.4 0-10.666667-4.266667-10.666667-10.666667V149.333333c0-2.133333 0-6.4-2.133333-8.533333 0 0 2.133333 0 2.133333 2.133333l189.866667 187.733334z m-8.533334 554.666666H234.666667c-6.4 0-10.666667-4.266667-10.666667-10.666666V149.333333c0-6.4 4.266667-10.666667 10.666667-10.666666h311.466666c-2.133333 4.266667-2.133333 6.4-2.133333 10.666666v170.666667c0 40.533333 34.133333 74.666667 74.666667 74.666667h170.666666c4.266667 0 6.4 0 10.666667-2.133334V874.666667c0 6.4-4.266667 10.666667-10.666667 10.666666z"
2803
+ }, null), r("path", {
2804
+ d: "M640 693.333333H341.333333c-17.066667 0-32 14.933333-32 32s14.933333 32 32 32h298.666667c17.066667 0 32-14.933333 32-32s-14.933333-32-32-32zM640 522.666667H341.333333c-17.066667 0-32 14.933333-32 32s14.933333 32 32 32h298.666667c17.066667 0 32-14.933333 32-32s-14.933333-32-32-32zM341.333333 416h85.333334c17.066667 0 32-14.933333 32-32s-14.933333-32-32-32h-85.333334c-17.066667 0-32 14.933333-32 32s14.933333 32 32 32z"
2805
+ }, null)]), ae = r("svg", {
2806
+ viewBox: "0 0 1024 1024",
2807
+ version: "1.1",
2808
+ xmlns: "http://www.w3.org/2000/svg",
2809
+ width: "24",
2810
+ height: "24",
2811
+ fill: "currentColor"
2812
+ }, [r("path", {
2813
+ d: "M557.248 511.68l135.776-135.744-45.248-45.28L512 466.432l-135.776-135.776-45.248 45.28 135.776 135.744-135.776 135.776 45.248 45.248L512 556.928l135.776 135.776 45.248-45.248-135.776-135.776zM512 64c247.136 0 448 200.864 448 448s-200.864 448-448 448S64 759.136 64 512 264.864 64 512 64z"
2814
+ }, null)]), K = r("svg", {
2815
+ viewBox: "0 0 1024 1024",
2816
+ version: "1.1",
2817
+ xmlns: "http://www.w3.org/2000/svg",
2818
+ fill: "currentcolor"
2819
+ }, [r("path", {
2820
+ d: "M511.582491 63.413262C265.134543 63.413262 64.62588 263.921925 64.62588 510.369873s200.508663 446.957635 446.957635 446.957635 446.957635-200.508663 446.957635-446.957635S758.031463 63.413262 511.582491 63.413262zM509.001713 751.859903c-98.517781 0-182.467775-62.623269-214.771505-150.056598l0.327458-0.134053c-2.007727-4.036943-3.38305-8.422833-3.38305-13.237489 0-16.647145 13.494339-30.142507 30.142507-30.142507 13.389962 0 24.358781 8.877181 28.2893 20.955264l0.422625-0.172939c23.269983 65.442478 85.645612 112.503307 158.972665 112.503307 93.106538 0 168.845523-75.738985 168.845523-168.845523s-75.738985-168.845523-168.845523-168.845523c-20.432355 0-39.874149 3.980661-58.013275 10.66899l21.248953 40.742936c2.486634 2.677992 4.0175 6.2831 4.0175 10.243295 0 8.417717-8.404414 14.921851-15.365966 15.07023-0.102331 0-0.206708 0-0.309038 0-0.220011 0-0.427742 0-0.647753-0.013303l-150.579507-6.463202c-5.372358-0.234337-10.229992-3.310396-12.716626-8.093329-2.486634-4.76963-2.236947-10.509355 0.647753-15.055904l80.890308-127.179564c2.8847-4.533246 8.006348-7.151887 13.365402-6.960529 5.372358 0.234337 10.227945 3.312442 12.71458 8.095375l18.580171 35.625382c26.629497-10.855232 55.683207-16.963347 86.168522-16.963347 126.338407 0 229.130537 102.791108 229.130537 229.130537S635.340119 751.859903 509.001713 751.859903z"
2821
+ }, null)]), tt = r("svg", {
2822
+ viewBox: "0 0 1024 1024",
2823
+ version: "1.1",
2824
+ xmlns: "http://www.w3.org/2000/svg",
2825
+ fill: "currentcolor"
2826
+ }, [r("path", {
2827
+ d: "M190.193225 471.411583c14.446014 0 26.139334-11.718903 26.139334-26.13831 0-14.44499-11.69332-26.164916-26.139334-26.164916-0.271176 0-0.490164 0.149403-0.73678 0.149403l-62.496379 0.146333c-1.425466-0.195451-2.90005-0.295735-4.373611-0.295735-19.677155 0-35.621289 16.141632-35.621289 36.114522L86.622358 888.550075c0 19.949354 15.96767 35.597753 35.670407 35.597753 1.916653 0 3.808746 0.292666 5.649674 0l61.022819 0.022513c0.099261 0 0.148379 0.048095 0.24764 0.048095 0.097214 0 0.146333-0.048095 0.24457-0.048095l0.73678 0 0-0.148379c13.413498-0.540306 24.174586-11.422144 24.174586-24.960485 0-13.55983-10.760065-24.441669-24.174586-24.981974l0-0.393973-50.949392 0 1.450025-402.275993L190.193225 471.409536z"
2828
+ }, null), r("path", {
2829
+ d: "M926.52241 433.948343c-19.283182-31.445176-47.339168-44.172035-81.289398-45.546336-1.77032-0.246617-3.536546-0.39295-5.380544-0.39295l-205.447139-0.688685c13.462616-39.059598 22.698978-85.58933 22.698978-129.317251 0-28.349675-3.193739-55.962569-9.041934-82.542948l-0.490164 0.049119c-10.638291-46.578852-51.736315-81.31498-100.966553-81.31498-57.264215 0-95.466282 48.15065-95.466282 106.126063 0 3.241834-0.294712 6.387477 0 9.532097-2.996241 108.386546-91.240027 195.548698-196.23636 207.513194l0 54.881958-0.785899 222.227314 0 229.744521 10.709923 0 500.025271 0.222057 8.746198-0.243547c19.35686 0.049119 30.239721-4.817726 47.803749-16.116049 16.682961-10.761088 29.236881-25.50079 37.490869-42.156122 2.260483-3.341095 4.028757-7.075139 5.106298-11.20111l77.018118-344.324116c1.056052-4.053316 1.348718-8.181333 1.056052-12.160971C943.643346 476.446249 938.781618 453.944769 926.52241 433.948343zM893.82573 486.837924l-82.983993 367.783411-0.099261-0.049119c-2.555196 6.141884-6.879688 11.596106-12.872169 15.427364-4.177136 2.727111-8.773827 4.351098-13.414521 4.964058-1.49812-0.195451-3.046383 0-4.620227 0l-477.028511-0.540306-0.171915-407.408897c89.323375-40.266076 154.841577-79.670527 188.596356-173.661202 0.072655 0.024559 0.124843 0.049119 0.195451 0.072655 2.99931-9.137101 6.313799-20.73423 8.697079-33.164331 5.551436-29.185716 5.258771-58.123792 5.258771-58.123792-4.937452-37.98001 25.940812-52.965306 44.364417-52.965306 25.304316 0.860601 50.263777 33.656541 50.263777 52.326762 0 0 5.600555 27.563776 5.649674 57.190537 0.048095 37.366026-4.6673 56.847729-4.6673 56.847729l-0.466628 0c-5.872754 30.879288-16.214287 60.138682-30.464849 86.964654l0.36839 0.342808c-2.358721 4.815679-3.709485 10.220782-3.709485 15.943111 0 19.922748 19.088754 21.742187 38.765909 21.742187l238.761895 0.270153c0 0 14.666024 0.465604 14.690584 0.465604l0 0.100284c12.132318-0.638543 24.221658 5.207605 31.100322 16.409738 5.504364 9.016351 6.437619 19.6045 3.486404 28.988218L893.82573 486.837924z"
2830
+ }, null), r("path", {
2831
+ d: "M264.827039 924.31872c0.319272 0.024559 0.441045 0.024559 0.295735-0.024559 0.243547-0.048095 0.367367-0.074701-0.295735-0.074701s-0.539282 0.026606-0.271176 0.074701C264.43409 924.343279 264.532327 924.343279 264.827039 924.31872z"
2832
+ }, null)]), st = r("svg", {
2833
+ viewBox: "0 0 1024 1024",
2834
+ version: "1.1",
2835
+ xmlns: "http://www.w3.org/2000/svg",
2836
+ fill: "currentcolor"
2837
+ }, [r("path", {
2838
+ d: "M190.208 552.576a26.176 26.176 0 0 1 0 52.288L189.44 604.8l-62.464-0.128a35.84 35.84 0 0 1-40-35.84l-0.384-433.28c0-19.968 16-35.648 35.712-35.648 1.92 0 3.84-0.256 5.632 0h62.272v0.128c13.44 0.576 24.192 11.456 24.192 24.96a25.024 25.024 0 0 1-24.192 24.96v0.448h-50.944l1.408 402.24h49.536z m736.32 37.504c-19.264 31.36-47.36 44.16-81.28 45.504a38.656 38.656 0 0 1-5.376 0.384l-205.44 0.704c13.44 39.04 22.656 85.568 22.656 129.28 0 28.416-3.2 56-9.024 82.56h-0.512a103.936 103.936 0 0 1-100.928 81.28c-57.28 0-95.488-48.128-95.488-106.112 0-3.2-0.32-6.4 0-9.536-3.008-108.352-91.264-195.52-196.224-207.488V551.68L254.08 329.6v-229.76h10.688l500.032-0.192 8.704 0.192c19.392 0 30.272 4.864 47.808 16.128 16.704 10.752 29.248 25.536 37.504 42.176 2.304 3.328 4.032 7.04 5.12 11.2l76.992 344.32a37.568 37.568 0 0 1 1.088 12.16c1.536 21.76-3.328 44.288-15.552 64.32z m-32.704-52.928l-83.008-367.744h-0.064a33.408 33.408 0 0 0-26.24-20.352c-1.536 0.192-3.072 0-4.672 0l-477.056 0.512-0.128 407.424c89.28 40.32 154.88 79.68 188.544 173.632h0.256c2.944 9.088 6.272 20.672 8.64 33.088 5.568 29.184 5.312 58.176 5.312 58.176-4.992 37.952 25.92 52.928 44.352 52.928 25.28-0.832 50.24-33.664 50.24-52.288 0 0 5.632-27.584 5.632-57.216 0.064-37.376-4.608-56.832-4.608-56.832h-0.512a307.84 307.84 0 0 0-30.464-87.04l0.384-0.256a36.16 36.16 0 0 1-3.712-16c0-19.84 19.072-21.76 38.784-21.76l238.72-0.192 14.72-0.512v-0.064c12.16 0.64 24.192-5.248 31.104-16.448a35.2 35.2 0 0 0 3.456-28.992h0.32zM267.52 96.768c2.048-0.192 2.816-0.192 1.92 0.128 1.536 0.32 2.304 0.512-1.92 0.512s-3.456-0.192-1.728-0.512c-0.768-0.32-0.192-0.32 1.728-0.128z"
2839
+ }, null)]), it = r("svg", {
2840
+ viewBox: "0 0 1024 1024",
2841
+ version: "1.1",
2842
+ xmlns: "http://www.w3.org/2000/svg",
2843
+ fill: "currentcolor"
2844
+ }, [r("path", {
2845
+ d: "M900.64 379.808l-263.072-256.032c-36.448-35.328-105.76-35.392-142.304 0.096l-327.04 319.904c-56.416 54.72-70.72 76.704-70.72 150.976l0 143.936c0 132.768 26.976 192 186.912 192l131.872 0c81.12 0 128.448-46.656 193.952-111.264l290.016-297.696c18.592-17.984 29.248-43.968 29.248-71.264C929.504 423.36 918.976 397.6 900.64 379.808zM323.008 786.752c-52.928 0-96-43.072-96-96s43.072-96 96-96 96 43.072 96 96S375.936 786.752 323.008 786.752z"
2846
+ }, null)]), at = r("svg", {
2847
+ viewBox: "0 0 1024 1024",
2848
+ version: "1.1",
2849
+ xmlns: "http://www.w3.org/2000/svg",
2850
+ fill: "currentcolor"
2851
+ }, [r("path", {
2852
+ d: "M843.251 424.407l43.828-74.898c10.194-17.946 32.596-22.158 48.956-11.598 16.298 10.499 23.44 32.658 14.223 49.566l-113.11 195.212-61.164-40.044-126.418-82.285c-16.115-11.598-20.632-34.428-10.194-51.702 9.705-17.397 31.009-23.501 47.857-13.734l89.67 59.028C748.576 295.547 615.81 180.667 461.008 180.667c-177.387 0-320.042 148.758-320.042 331.335 0 183.613 143.692 331.334 319.981 331.334 107.861 0.184 208.58-56.158 268.034-149.858 1.099-1.038 1.099-2.075 2.075-2.075 6.348-9.949 17.092-15.871 28.568-15.81 19.35 0 35.648 16.848 35.648 36.93 0 7.508-2.137 14.833-6.104 21.059-72.823 114.698-196.066 183.675-328.099 183.614-216.088 0-391.4-181.478-391.4-405.195 0-223.718 175.312-405.195 391.339-405.195 183.125-0.427 342.016 131.606 382.243 317.601z"
2853
+ }, null)]), nt = r("svg", {
2854
+ viewBox: "0 0 1024 1024",
2855
+ version: "1.1",
2856
+ xmlns: "http://www.w3.org/2000/svg",
2857
+ fill: "currentcolor"
2858
+ }, [r("path", {
2859
+ d: "M394.688 126.208a32 32 0 0 1 32-32h170.688a32 32 0 0 1 32 32v138.624h288a32 32 0 0 1 32 32v170.688a32 32 0 0 1-32 32H106.688a32 32 0 0 1-32-32V296.832a32 32 0 0 1 32-32h288V126.208z m64 32v138.624a32 32 0 0 1-32 32h-288v106.688h746.688V328.832h-288a32 32 0 0 1-32-32V158.208H458.688z"
2860
+ }, null), r("path", {
2861
+ d: "M138.688 469.376a32 32 0 0 1 32-32h682.688a32 32 0 0 1 32 32v384a32 32 0 0 1-32 32H170.688a32 32 0 0 1-32-32v-384z m64 32v320h618.688v-320H202.688z"
2862
+ }, null), r("path", {
2863
+ d: "M341.376 691.52a32 32 0 0 1 32 32V851.2a32 32 0 1 1-64 0v-127.68a32 32 0 0 1 32-32zM512 691.2a32 32 0 0 1 32 32v128a32 32 0 0 1-64 0v-128a32 32 0 0 1 32-32zM682.688 691.52a32 32 0 0 1 32 32V851.2a32 32 0 1 1-64 0v-127.68a32 32 0 0 1 32-32z"
2864
+ }, null)]);
2865
+ r("svg", {
2866
+ viewBox: "0 0 18 18",
2867
+ fill: "currentcolor",
2868
+ xmlns: "http://www.w3.org/2000/svg"
2869
+ }, [r("path", {
2870
+ d: "M5.856 17.121a.979.979 0 0 1-.327-.06.839.839 0 0 1-.283-.177.739.739 0 0 1-.187-.255.724.724 0 0 1-.07-.303l-.02-1.609a4.663 4.663 0 0 1-1.446-.455 4.252 4.252 0 0 1-.637-.401c-.199-.146-.385-.31-.553-.492a4.442 4.442 0 0 1-.45-.577 4.303 4.303 0 0 1-.327-.637 3.823 3.823 0 0 1-.206-.686 3.729 3.729 0 0 1-.064-.704V6.478c0-.261.025-.516.077-.771a4.43 4.43 0 0 1 .244-.747 4.062 4.062 0 0 1 .932-1.28c.2-.183.418-.347.65-.493.23-.145.482-.267.739-.364a4.21 4.21 0 0 1 .81-.225c.27-.054.553-.078.835-.078H8.55c.103 0 .2.018.29.054a.7.7 0 0 1 .411.376.667.667 0 0 1-.161.766.736.736 0 0 1-.25.151.764.764 0 0 1-.29.055H5.573c-.186 0-.366.012-.54.049-.18.03-.353.079-.52.145-.167.061-.328.14-.482.237-.148.091-.29.2-.418.316a2.897 2.897 0 0 0-.347.388c-.097.14-.187.286-.257.444a2.473 2.473 0 0 0-.206.977v4.287c0 .17.013.333.051.503a2.549 2.549 0 0 0 .772 1.33 2.721 2.721 0 0 0 .913.559c.167.066.347.115.527.152.18.03.36.048.546.048a.904.904 0 0 1 .61.23.848.848 0 0 1 .194.262.84.84 0 0 1 .07.303l.007.99 1.915-1.293a2.877 2.877 0 0 1 1.64-.492h2.372c.186 0 .366-.018.54-.048.18-.03.353-.08.52-.146.168-.067.329-.146.483-.237.148-.091.29-.2.418-.316.128-.121.244-.249.347-.388a2.8 2.8 0 0 0 .257-.444 2.47 2.47 0 0 0 .206-.977V8.585a.646.646 0 0 1 .225-.492.679.679 0 0 1 .244-.152.814.814 0 0 1 .585 0c.09.03.174.085.244.152a.657.657 0 0 1 .225.492V10.8c0 .261-.032.516-.083.771a4.192 4.192 0 0 1-.245.74c-.109.244-.244.468-.398.687a3.735 3.735 0 0 1-.534.6c-.2.183-.418.347-.65.493a4.134 4.134 0 0 1-.738.364 4.7 4.7 0 0 1-.81.225c-.27.054-.553.079-.836.079h-1.877c-.604 0-1.144.164-1.633.491l-2.54 1.713a.913.913 0 0 1-.514.157z",
2871
+ fill: "currentColor"
2872
+ }, null), r("path", {
2873
+ d: "M15.866 4.125h-4.174c-.41 0-.741.313-.741.7 0 .387.332.7.741.7h4.174c.41 0 .742-.313.742-.7 0-.387-.332-.7-.742-.7z",
2874
+ fill: "currentColor"
2875
+ }, null), r("path", {
2876
+ d: "M14.537 2.932c0-.396-.34-.717-.759-.717s-.758.32-.758.717v3.786c0 .396.34.717.758.717.42 0 .76-.321.76-.717V2.932z",
2877
+ fill: "currentColor"
2878
+ }, null)]);
2879
+ const ot = r("svg", {
2880
+ viewBox: "0 0 1024 1024",
2881
+ version: "1.1",
2882
+ xmlns: "http://www.w3.org/2000/svg",
2883
+ "p-id": "15393",
2884
+ width: "24",
2885
+ height: "24",
2886
+ fill: "currentColor"
2887
+ }, [r("path", {
2888
+ d: "M896 921.6H128c-70.656 0-128-57.344-128-128V230.4c0-70.656 57.344-128 128-128h768c70.656 0 128 57.344 128 128v563.2c0 70.656-57.344 128-128 128zM128 153.6c-42.496 0-76.8 34.304-76.8 76.8v563.2c0 42.496 34.304 76.8 76.8 76.8h768c42.496 0 76.8-34.304 76.8-76.8V230.4c0-42.496-34.304-76.8-76.8-76.8H128z",
2889
+ "p-id": "15394"
2890
+ }, null), r("path", {
2891
+ d: "M256 486.4c-70.656 0-128-57.344-128-128s57.344-128 128-128 128 57.344 128 128-57.344 128-128 128z m0-204.8c-42.496 0-76.8 34.304-76.8 76.8s34.304 76.8 76.8 76.8 76.8-34.304 76.8-76.8-34.304-76.8-76.8-76.8zM204.8 742.4c-7.68 0-15.36-3.584-20.48-10.24-8.704-11.264-6.144-27.136 5.12-35.84l181.76-136.192c21.504-15.872 49.664-19.968 74.752-9.728l198.144 79.36c9.728 3.584 20.48 1.536 27.648-5.632l129.536-129.536c10.24-10.24 26.112-10.24 36.352 0s10.24 26.112 0 36.352L708.096 660.48c-21.504 21.504-54.272 28.672-82.944 16.896l-198.144-79.36c-8.192-3.072-17.92-2.048-25.088 3.072L220.16 737.28c-4.608 3.584-10.24 5.12-15.36 5.12z",
2892
+ "p-id": "15395"
2893
+ }, null)]), rt = r("svg", {
2894
+ viewBox: "0 0 1024 1024",
2895
+ version: "1.1",
2896
+ xmlns: "http://www.w3.org/2000/svg",
2897
+ "p-id": "4645",
2898
+ width: "24",
2899
+ height: "24",
2900
+ fill: "currentColor"
2901
+ }, [r("path", {
2902
+ d: "M192.608008 1023.936a192 192 0 0 1-192-192v-640a192 192 0 0 1 192-192h383.296a64 64 0 0 1 0 128H192.608008a64 64 0 0 0-64 64v640a64 64 0 0 0 64 64h383.296a64 64 0 0 1 0 128z m544.896-289.6a64 64 0 0 1 0-90.432L805.280008 576H384.352008a64 64 0 1 1 0-128h420.928l-82.688-82.816a64 64 0 0 1 90.368-90.496l192 192a64.576 64.576 0 0 1 13.76 69.824 65.6 65.6 0 0 1-13.76 20.672l-176.896 177.152a64 64 0 0 1-90.368 0z",
2903
+ "p-id": "4646"
2904
+ }, null)]);
2905
+ const lt = /* @__PURE__ */ T({
2906
+ props: {
2907
+ message: {
2908
+ type: Object,
2909
+ required: !0
2910
+ }
2911
+ },
2912
+ setup(a) {
2913
+ return {
2914
+ ns: new A("ai-error-message")
2915
+ };
2916
+ },
2917
+ render() {
2918
+ var a, e;
2919
+ return r("div", {
2920
+ class: this.ns.b()
2921
+ }, [r("div", {
2922
+ class: this.ns.e("icon")
2923
+ }, [q]), r("div", {
2924
+ class: this.ns.e("right")
2925
+ }, [r("div", {
2926
+ class: this.ns.em("right", "header")
2927
+ }, [(e = (a = this.$slots).header) == null ? void 0 : e.call(a)]), r("div", {
2928
+ class: [this.ns.em("right", "content"), "pre-wrap-container"]
2929
+ }, [r("p", {
2930
+ class: this.ns.e("message")
2931
+ }, [this.message.content])])])]);
2932
+ }
2933
+ });
2934
+ const ct = /* @__PURE__ */ T({
2935
+ props: {
2936
+ message: {
2937
+ type: Object,
2938
+ required: !0
2939
+ }
2940
+ },
2941
+ setup(a) {
2942
+ const e = new A("chart-thought-chain"), t = w(!1), s = k(() => {
2943
+ const n = a.message.content, l = n.indexOf("<think>");
2944
+ if (l === -1)
2945
+ return;
2946
+ const h = n.indexOf("</think>");
2947
+ return h === -1 ? n.slice(l + 7) : n.slice(l + 7, h);
2948
+ }), i = k(() => a.message.content.indexOf("</think>") === -1);
2949
+ return {
2950
+ ns: e,
2951
+ think: s,
2952
+ isLoading: i,
2953
+ isCollapse: t,
2954
+ onCollapseChange: () => {
2955
+ t.value = !t.value;
2956
+ }
2957
+ };
2958
+ },
2959
+ render() {
2960
+ if (this.think)
2961
+ return r("div", {
2962
+ class: this.ns.b()
2963
+ }, [r("div", {
2964
+ class: this.ns.e("header"),
2965
+ onClick: this.onCollapseChange
2966
+ }, [r("div", {
2967
+ class: this.ns.em("header", "left")
2968
+ }, [r("div", {
2969
+ class: [this.ns.em("header", "state-icon"), this.ns.is("loading", this.isLoading)]
2970
+ }, [this.isLoading ? Ye : Ke]), r("div", {
2971
+ class: this.ns.em("header", "title")
2972
+ }, [this.isLoading ? "思考中..." : "思考完成"])]), r("div", {
2973
+ class: this.ns.em("header", "right")
2974
+ }, [r("div", {
2975
+ class: this.ns.em("header", "collapse-icon")
2976
+ }, [this.isCollapse ? te : Qe])])]), !this.isCollapse && r("div", {
2977
+ class: this.ns.e("content")
2978
+ }, [this.think])]);
2979
+ }
2980
+ });
2981
+ const ht = /* @__PURE__ */ T({
2982
+ props: {
2983
+ toolCall: {
2984
+ type: Object,
2985
+ required: !0
2986
+ }
2987
+ },
2988
+ setup(a) {
2989
+ const e = new A("chart-tool-call-item"), t = w(!1), s = () => {
2990
+ t.value = !t.value;
2991
+ }, i = (c) => {
2992
+ c.stopPropagation(), window.ibiz.util.text.copy(JSON.stringify(a.toolCall, void 0, 2)), window.message.success("拷贝成功");
2993
+ }, o = (c) => typeof c == "string" ? c.includes("Failed") || c.includes("Error") || c.includes("ERR_") ? '<span class="'.concat(e.e("error"), '">"').concat(c, '"</span>') : '<span class="'.concat(e.e("string"), '">"').concat(c, '"</span>') : typeof c == "number" ? '<span class="'.concat(e.e("number"), '">').concat(c, "</span>") : typeof c == "boolean" ? '<span class="'.concat(e.e("boolean"), '">').concat(c, "</span>") : c === null ? '<span class="'.concat(e.e("null"), '">null</span>') : "", n = (c, u = 0) => {
2994
+ const d = " ".repeat(u), p = [];
2995
+ if (Array.isArray(c)) {
2996
+ if (c.length === 0)
2997
+ return ["".concat(d, '<span class="').concat(e.e("array"), '">[]</span>')];
2998
+ p.push("".concat(d, '<span class="').concat(e.e("array"), '">[</span>')), c.forEach((f, m) => {
2999
+ const b = n(f, u + 1), y = m < c.length - 1 ? "," : "";
3000
+ typeof f == "object" && f !== null ? (p.push(...b.slice(0, -1)), p.push("".concat(b[b.length - 1]).concat(y))) : p.push("".concat(b[0]).concat(y));
3001
+ }), p.push("".concat(d, '<span class="').concat(e.e("array"), '">]</span>'));
3002
+ } else if (typeof c == "object" && c !== null) {
3003
+ const f = Object.keys(c);
3004
+ if (f.length === 0)
3005
+ return ["".concat(d, '<span class="').concat(e.e("property"), '">{}</span>')];
3006
+ p.push("".concat(d, '<span class="').concat(e.e("property"), '">{</span>')), f.forEach((m, b) => {
3007
+ const y = c[m], S = b < f.length - 1 ? "," : "", E = '<span class="'.concat(e.e("json-key"), '">"').concat(m, '":</span>');
3008
+ if (typeof y == "object" && y !== null) {
3009
+ const C = n(y, u + 1);
3010
+ p.push("".concat(d, " ").concat(E, " ").concat(C[0].trim())), C.length > 1 && (p.push(...C.slice(1, -1)), p.push("".concat(C[C.length - 1]).concat(S)));
3011
+ } else {
3012
+ const C = o(y);
3013
+ p.push("".concat(d, " ").concat(E, " ").concat(C).concat(S));
3014
+ }
3015
+ }), p.push("".concat(d, '<span class="').concat(e.e("property"), '">}</span>'));
3016
+ } else
3017
+ p.push("".concat(d).concat(o(c)));
3018
+ return p;
3019
+ }, l = w([]), h = () => {
3020
+ const c = n(a.toolCall, 0);
3021
+ l.value = c.map((u, d) => '<span class="'.concat(e.em("code-line", "line-number"), '">').concat(d + 1, "</span>").concat(u));
3022
+ };
3023
+ return z(() => {
3024
+ h();
3025
+ }), {
3026
+ ns: e,
3027
+ lines: l,
3028
+ isExpanded: t,
3029
+ onCopy: i,
3030
+ handleExpandChange: s
3031
+ };
3032
+ },
3033
+ render() {
3034
+ var a;
3035
+ return r("div", {
3036
+ class: this.ns.b()
3037
+ }, [r("div", {
3038
+ class: this.ns.e("header"),
3039
+ onClick: this.handleExpandChange
3040
+ }, [r("div", {
3041
+ class: this.ns.e("header-left")
3042
+ }, [r("div", {
3043
+ class: this.ns.em("header-left", "caption")
3044
+ }, [this.toolCall.name]), r("div", {
3045
+ class: this.ns.em("header-left", "desc")
3046
+ }, [(a = this.toolCall.parameters) == null ? void 0 : a.desc])]), r("div", {
3047
+ class: this.ns.e("header-right")
3048
+ }, [this.toolCall.error && r("div", {
3049
+ class: this.ns.em("header-right", "error")
3050
+ }, [r("span", {
3051
+ class: this.ns.em("header-right", "error-text")
3052
+ }, [H("发生错误")]), r("div", {
3053
+ class: this.ns.em("header-right", "icon")
3054
+ }, [We])]), r("div", {
3055
+ onClick: this.onCopy,
3056
+ class: this.ns.em("header-right", "icon")
3057
+ }, [ie]), r("div", {
3058
+ class: this.ns.em("header-right", "icon")
3059
+ }, [this.isExpanded ? te : se])])]), this.isExpanded && r("div", {
3060
+ class: this.ns.e("content")
3061
+ }, [this.lines.map((e) => r("div", {
3062
+ class: this.ns.e("code-line"),
3063
+ innerHTML: e
3064
+ }, null))])]);
3065
+ }
3066
+ });
3067
+ const ut = /* @__PURE__ */ T({
3068
+ props: {
3069
+ toolCalls: {
3070
+ type: Array,
3071
+ required: !0
3072
+ }
3073
+ },
3074
+ setup(a) {
3075
+ const e = new A("chart-tool-call"), t = w(!1), s = k(() => a.toolCalls.length > 4), i = k(() => s.value && !t.value ? a.toolCalls.slice(0, 4) : a.toolCalls);
3076
+ return {
3077
+ ns: e,
3078
+ items: i,
3079
+ showToggle: s,
3080
+ isExpanded: t,
3081
+ handleToggle: () => {
3082
+ t.value = !t.value;
3083
+ }
3084
+ };
3085
+ },
3086
+ render() {
3087
+ if (this.toolCalls.length)
3088
+ return r("div", {
3089
+ class: this.ns.b()
3090
+ }, [this.items.map((a) => r(ht, {
3091
+ toolCall: a
3092
+ }, null)), this.showToggle && r("div", {
3093
+ class: this.ns.e("toggle"),
3094
+ onClick: this.handleToggle
3095
+ }, [this.isExpanded ? "收起工具调用" : "展开全部 ".concat(this.toolCalls.length, " 个工具调用")])]);
3096
+ }
3097
+ });
3098
+ const dt = /* @__PURE__ */ T({
3099
+ props: {
3100
+ suggestions: {
3101
+ type: Array,
3102
+ required: !0
3103
+ }
3104
+ },
3105
+ emits: {
3106
+ itemClick: (a, e) => !0
3107
+ },
3108
+ setup(a, {
3109
+ emit: e
3110
+ }) {
3111
+ return {
3112
+ ns: new A("chart-suggestion"),
3113
+ onItemClick: (i, o) => {
3114
+ e("itemClick", i, o);
3115
+ }
3116
+ };
3117
+ },
3118
+ render() {
3119
+ return r("div", {
3120
+ class: this.ns.b()
3121
+ }, [this.suggestions.map((a) => r("div", {
3122
+ onClick: (e) => this.onItemClick(a, e),
3123
+ class: [this.ns.e("item"), this.ns.em("item", a.type)]
3124
+ }, [a.metadata.content_name, se]))]);
3125
+ }
3126
+ });
3127
+ const pt = /* @__PURE__ */ T({
3128
+ props: {
3129
+ controller: {
3130
+ type: Object,
3131
+ required: !0
3132
+ },
3133
+ message: {
3134
+ type: Object,
3135
+ required: !0
3136
+ }
3137
+ },
3138
+ setup(a) {
3139
+ const e = new A("ai-markdown-message"), t = B(), s = w(null), i = (n) => {
3140
+ let l = "", h;
3141
+ if (!n)
3142
+ return {
3143
+ content: l,
3144
+ think: h
3145
+ };
3146
+ const c = n.indexOf("<think>"), u = n.indexOf("</think>");
3147
+ return c !== -1 ? (h = u === -1 ? n.slice(c + 7) : n.slice(c + 7, u), l = u === -1 ? "" : n.slice(u + 8)) : l = n.replace(new RegExp("\\<tool_call\\>[^]*?\\<\\/tool_call\\>", "gs"), "").trim(), {
3148
+ think: h,
3149
+ content: l
3150
+ };
3151
+ };
3152
+ P(() => a.message.content, () => {
3153
+ var l;
3154
+ const {
3155
+ content: n
3156
+ } = i(a.message.content);
3157
+ (l = s.value) == null || l.setMarkdown(n);
3158
+ }, {
3159
+ immediate: !0
3160
+ });
3161
+ const o = () => {
3162
+ const {
3163
+ content: n
3164
+ } = i(a.message.content);
3165
+ s.value = new W({
3166
+ id: t,
3167
+ value: n,
3168
+ editor: {
3169
+ defaultModel: "previewOnly"
3170
+ },
3171
+ previewer: {
3172
+ enablePreviewerBubble: !1
3173
+ },
3174
+ engine: {
3175
+ syntax: {
3176
+ table: {
3177
+ enableChart: !1,
3178
+ externals: ["echarts"]
3179
+ }
3180
+ }
3181
+ }
3182
+ });
3183
+ };
3184
+ return z(() => {
3185
+ o();
3186
+ }), {
3187
+ ns: e,
3188
+ UUID: t
3189
+ };
3190
+ },
3191
+ render() {
3192
+ var a, e;
3193
+ return r("div", {
3194
+ class: this.ns.b()
3195
+ }, [r("div", {
3196
+ class: this.ns.e("icon")
3197
+ }, [q]), r("div", {
3198
+ class: this.ns.e("right")
3199
+ }, [r("div", {
3200
+ class: this.ns.em("right", "header")
3201
+ }, [(e = (a = this.$slots).header) == null ? void 0 : e.call(a)]), r("div", {
3202
+ class: [this.ns.em("right", "content"), "pre-wrap-container"]
3203
+ }, [this.message.toolcalls && r(ut, {
3204
+ class: this.ns.e("tool-call"),
3205
+ toolCalls: this.message.toolcalls
3206
+ }, null), r(ct, {
3207
+ message: this.message,
3208
+ class: this.ns.e("thought")
3209
+ }, null), r("div", {
3210
+ class: this.ns.e("message"),
3211
+ id: this.UUID
3212
+ }, null)]), r("div", {
3213
+ class: this.ns.em("right", "footer")
3214
+ }, [this.message.suggestions && r(dt, {
3215
+ suggestions: this.message.suggestions,
3216
+ onItemClick: (t, s) => {
3217
+ this.controller.handleSuggestionClick(this.message, t, s);
3218
+ }
3219
+ }, null)])])]);
3220
+ }
3221
+ });
3222
+ const gt = /* @__PURE__ */ T({
3223
+ props: {
3224
+ message: {
3225
+ type: Object,
3226
+ required: !0
3227
+ }
3228
+ },
3229
+ setup() {
3230
+ return {
3231
+ ns: new A("ai-unknown-message")
3232
+ };
3233
+ },
3234
+ render() {
3235
+ var a, e;
3236
+ return r("div", {
3237
+ class: this.ns.b()
3238
+ }, [r("div", {
3239
+ class: this.ns.e("icon")
3240
+ }, [q]), r("div", {
3241
+ class: this.ns.e("right")
3242
+ }, [r("div", {
3243
+ class: this.ns.em("right", "header")
3244
+ }, [(e = (a = this.$slots).header) == null ? void 0 : e.call(a)]), r("div", {
3245
+ class: [this.ns.em("right", "content"), "pre-wrap-container"]
3246
+ }, [r("p", {
3247
+ class: this.ns.e("message")
3248
+ }, [H("暂未支持的消息类型: "), this.message.type])])])]);
3249
+ }
3250
+ });
3251
+ const mt = /* @__PURE__ */ T({
3252
+ props: {
3253
+ material: {
3254
+ type: Object,
3255
+ required: !0
3256
+ },
3257
+ readonly: {
3258
+ type: Boolean,
3259
+ default: !1
3260
+ }
3261
+ },
3262
+ emits: {
3263
+ remove: () => !0
3264
+ },
3265
+ setup(a, {
3266
+ emit: e
3267
+ }) {
3268
+ const t = new A("chart-material-item"), s = () => {
3269
+ e("remove");
3270
+ }, i = k(() => {
3271
+ const o = a.material.metadata.state, n = {
3272
+ color: "#ff4d4f",
3273
+ label: "未知状态"
3274
+ };
3275
+ switch (o) {
3276
+ case "successed":
3277
+ Object.assign(n, {
3278
+ color: "#1890ff",
3279
+ label: "上传成功"
3280
+ });
3281
+ break;
3282
+ case "uploading":
3283
+ Object.assign(n, {
3284
+ color: "#52c41a",
3285
+ label: "上传中"
3286
+ });
3287
+ break;
3288
+ case "failed":
3289
+ Object.assign(n, {
3290
+ color: "#ff4d4f",
3291
+ label: "上传失败"
3292
+ });
3293
+ break;
3294
+ }
3295
+ return n;
3296
+ });
3297
+ return {
3298
+ ns: t,
3299
+ state: i,
3300
+ onRemove: s
3301
+ };
3302
+ },
3303
+ render() {
3304
+ return r("div", {
3305
+ class: this.ns.b()
3306
+ }, [!this.readonly && r("div", {
3307
+ class: this.ns.e("icon"),
3308
+ onClick: this.onRemove
3309
+ }, [ae]), r("div", {
3310
+ class: this.ns.e("left")
3311
+ }, [et]), r("div", {
3312
+ class: this.ns.e("right")
3313
+ }, [r("div", {
3314
+ class: this.ns.e("caption")
3315
+ }, [this.material.data.name]), r("div", {
3316
+ class: this.ns.e("metadata")
3317
+ }, [r("div", {
3318
+ class: this.ns.em("metadata", "size")
3319
+ }, [this.material.metadata.size, H("B")]), r("div", {
3320
+ class: this.ns.em("metadata", "state"),
3321
+ style: {
3322
+ color: this.state.color
3323
+ }
3324
+ }, [this.state.label])])])]);
3325
+ }
3326
+ });
3327
+ const ne = /* @__PURE__ */ T({
3328
+ props: {
3329
+ materials: {
3330
+ type: Array,
3331
+ required: !0
3332
+ },
3333
+ readonly: {
3334
+ type: Boolean,
3335
+ default: !1
3336
+ }
3337
+ },
3338
+ emits: {
3339
+ remove: (a) => !0
3340
+ },
3341
+ setup(a, {
3342
+ emit: e
3343
+ }) {
3344
+ return {
3345
+ ns: new A("chart-material"),
3346
+ onRemove: (i) => {
3347
+ e("remove", i);
3348
+ }
3349
+ };
3350
+ },
3351
+ render() {
3352
+ if (this.materials.length)
3353
+ return r("div", {
3354
+ class: this.ns.b()
3355
+ }, [this.materials.map((a) => r(mt, {
3356
+ material: a,
3357
+ readonly: this.readonly,
3358
+ onRemove: () => this.onRemove(a)
3359
+ }, null))]);
3360
+ }
3361
+ });
3362
+ const ft = /* @__PURE__ */ T({
3363
+ props: {
3364
+ controller: {
3365
+ type: Object,
3366
+ required: !0
3367
+ },
3368
+ message: {
3369
+ type: Object,
3370
+ required: !0
3371
+ }
3372
+ },
3373
+ setup(a) {
3374
+ const e = new A("ai-user-message"), t = B(), s = w(null), i = j.parseMixedContent(a.message.content), o = () => {
3375
+ s.value = new W({
3376
+ id: t,
3377
+ value: i.remainingText,
3378
+ editor: {
3379
+ defaultModel: "previewOnly"
3380
+ },
3381
+ previewer: {
3382
+ enablePreviewerBubble: !1
3383
+ },
3384
+ engine: {
3385
+ syntax: {
3386
+ table: {
3387
+ enableChart: !1,
3388
+ externals: ["echarts"]
3389
+ }
3390
+ }
3391
+ }
3392
+ });
3393
+ };
3394
+ return z(() => {
3395
+ o();
3396
+ }), {
3397
+ ns: e,
3398
+ UUID: t,
3399
+ material: i
3400
+ };
3401
+ },
3402
+ render() {
3403
+ var a, e;
3404
+ return r("div", {
3405
+ class: this.ns.b()
3406
+ }, [r("div", {
3407
+ class: this.ns.e("icon")
3408
+ }, [Je]), r("div", {
3409
+ class: this.ns.e("right")
3410
+ }, [r("div", {
3411
+ class: this.ns.em("right", "header")
3412
+ }, [(e = (a = this.$slots).header) == null ? void 0 : e.call(a)]), r("div", {
3413
+ class: [this.ns.em("right", "content"), "pre-wrap-container"]
3414
+ }, [this.material.hasResources && r(ne, {
3415
+ readonly: !0,
3416
+ class: this.ns.e("material"),
3417
+ materials: this.material.resources
3418
+ }, null), r("div", {
3419
+ class: this.ns.e("message"),
3420
+ id: this.UUID
3421
+ }, null)])])]);
3422
+ }
3423
+ });
3424
+ const vt = /* @__PURE__ */ T({
3425
+ props: {
3426
+ // 滚动目标:选择器 | DOM 元素
3427
+ target: {
3428
+ type: [String, HTMLElement],
3429
+ default: ""
3430
+ },
3431
+ // 右侧距离
3432
+ right: {
3433
+ type: [Number, String],
3434
+ default: "1rem"
3435
+ },
3436
+ // 底部距离
3437
+ bottom: {
3438
+ type: [Number, String],
3439
+ default: "1rem"
3440
+ },
3441
+ // 显示阈值(滚动高度超过该值才显示)
3442
+ offset: {
3443
+ type: Number,
3444
+ default: 200
3445
+ }
3446
+ },
3447
+ setup(a) {
3448
+ const e = new A("back-bottom"), t = w(!1), s = w(), i = w(), o = () => {
3449
+ var c;
3450
+ if (a.target) {
3451
+ if (typeof a.target == "string") {
3452
+ const u = document.querySelector(a.target);
3453
+ if (u)
3454
+ return u;
3455
+ } else if (a.target instanceof HTMLElement)
3456
+ return a.target;
3457
+ }
3458
+ return (c = i.value) == null ? void 0 : c.parentElement;
3459
+ }, n = k(() => ({
3460
+ right: X(a.right) ? a.right : "".concat(a.right, "px"),
3461
+ bottom: X(a.bottom) ? a.bottom : "".concat(a.bottom, "px")
3462
+ })), l = () => {
3463
+ const c = s.value;
3464
+ c && setTimeout(() => {
3465
+ const {
3466
+ scrollTop: u,
3467
+ scrollHeight: d,
3468
+ clientHeight: p
3469
+ } = c, f = d - (u + p) > a.offset;
3470
+ t.value = f;
3471
+ }, 1e3);
3472
+ }, h = () => {
3473
+ if (!s.value)
3474
+ return;
3475
+ const c = s.value;
3476
+ c == null || c.scrollTo({
3477
+ top: c.scrollHeight,
3478
+ behavior: "smooth"
3479
+ });
3480
+ };
3481
+ return z(async () => {
3482
+ var c;
3483
+ await _(), s.value = o(), (c = s.value) == null || c.addEventListener("scroll", l), l();
3484
+ }), P(() => a.target, async () => {
3485
+ await _(), s.value = o();
3486
+ }), ge(() => {
3487
+ var c;
3488
+ (c = s.value) == null || c.removeEventListener("scroll", l);
3489
+ }), {
3490
+ ns: e,
3491
+ btnRef: i,
3492
+ isShow: t,
3493
+ buttonStyle: n,
3494
+ scrollToBottom: h
3495
+ };
3496
+ },
3497
+ render() {
3498
+ return r("div", {
3499
+ ref: "btnRef",
3500
+ class: [this.ns.b(), this.ns.is("visible", this.isShow)],
3501
+ style: this.buttonStyle,
3502
+ onClick: this.scrollToBottom
3503
+ }, [Ge]);
3504
+ }
3505
+ });
3506
+ function oe(a) {
3507
+ return { handleItemClick: (t, s) => {
3508
+ const i = {
3509
+ ...a.data
3510
+ };
3511
+ if (a.data instanceof L ? (Object.assign(i, { topic: a.controller.topic }), i.msg.realcontent = a.data.realcontent) : (i.data || (i.data = {}), Object.assign(i.data, {
3512
+ messages: a.controller.messages.value
3513
+ })), s.onClick && typeof s.onClick == "function")
3514
+ s.onClick(
3515
+ t,
3516
+ s,
3517
+ a.controller.context,
3518
+ a.controller.params,
3519
+ i
3520
+ );
3521
+ else {
3522
+ const { extendToolbarClick: o } = a.controller.opts;
3523
+ o && typeof o == "function" && o(
3524
+ t,
3525
+ s,
3526
+ a.controller.context,
3527
+ a.controller.params,
3528
+ i
3529
+ );
3530
+ }
3531
+ } };
3532
+ }
3533
+ const N = /* @__PURE__ */ T({
3534
+ props: {
3535
+ model: {
3536
+ type: Object,
3537
+ required: !0
3538
+ },
3539
+ data: {
3540
+ type: Object,
3541
+ default: () => ({})
3542
+ },
3543
+ disabled: {
3544
+ type: Boolean,
3545
+ default: !1
3546
+ }
3547
+ },
3548
+ emits: {
3549
+ click: (a, e) => !0
3550
+ },
3551
+ setup(a, {
3552
+ emit: e
3553
+ }) {
3554
+ const t = new A("chat-toolbar-item"), s = (l) => typeof l.hidden == "function" ? l.hidden(a.data) : l.hidden === !0, i = (l) => a.disabled ? !0 : typeof l.disabled == "function" ? l.disabled(a.data) : l.disabled === !0;
3555
+ return {
3556
+ ns: t,
3557
+ isHidden: s,
3558
+ isDisabled: i,
3559
+ handleItemClick: (l, h) => {
3560
+ i(h) || e("click", l, h);
3561
+ },
3562
+ renderIcon: (l) => {
3563
+ var h, c, u, d;
3564
+ return typeof l.icon == "function" ? l.icon() : (h = l.icon) != null && h.showIcon && ((c = l.icon) != null && c.cssClass) ? r("i", {
3565
+ class: l.icon.cssClass
3566
+ }, null) : (u = l.icon) != null && u.showIcon && ((d = l.icon) != null && d.imagePath) ? Me(l.icon.imagePath) ? r("div", {
3567
+ innerHTML: l.icon.imagePath
3568
+ }, null) : r("img", {
3569
+ src: l.icon.imagePath
3570
+ }, null) : null;
3571
+ }
3572
+ };
3573
+ },
3574
+ render() {
3575
+ return this.isHidden(this.model) ? null : r("div", {
3576
+ class: [this.ns.b(), this.ns.is("disabled", this.isDisabled(this.model)), "".concat(this.model.customClass || "")]
3577
+ }, [r("div", {
3578
+ title: this.model.title,
3579
+ class: this.ns.e("content"),
3580
+ onClick: (a) => this.handleItemClick(a, this.model)
3581
+ }, [r("div", {
3582
+ class: this.ns.em("content", "icon")
3583
+ }, [this.renderIcon(this.model)]), r("div", {
3584
+ class: this.ns.em("content", "label")
3585
+ }, [this.model.label])])]);
3586
+ }
3587
+ });
3588
+ const Ct = /* @__PURE__ */ T({
3589
+ props: {
3590
+ controller: {
3591
+ type: Object,
3592
+ required: !0
3593
+ },
3594
+ data: {
3595
+ type: Object
3596
+ },
3597
+ items: {
3598
+ type: Array,
3599
+ default: () => []
3600
+ }
3601
+ },
3602
+ setup(a) {
3603
+ const e = new A("chat-input-toolbar"), {
3604
+ handleItemClick: t
3605
+ } = oe(a), s = [{
3606
+ label: "重置对话",
3607
+ title: "重置对话",
3608
+ icon: () => at,
3609
+ onClick: () => {
3610
+ a.controller.resetTopic();
3611
+ }
3612
+ }, {
3613
+ label: "清空对话",
3614
+ title: "清空对话",
3615
+ icon: () => nt,
3616
+ onClick: () => {
3617
+ a.controller.clearTopic();
3618
+ }
3619
+ }];
3620
+ return (() => {
3621
+ s.push(...a.items);
3622
+ })(), {
3623
+ ns: e,
3624
+ toolbarItems: s,
3625
+ handleItemClick: t
3626
+ };
3627
+ },
3628
+ render() {
3629
+ return r("div", {
3630
+ class: this.ns.b()
3631
+ }, [r("div", {
3632
+ class: this.ns.e("wrapper")
3633
+ }, [this.toolbarItems.map((a) => r(N, {
3634
+ data: this.data,
3635
+ model: a,
3636
+ disabled: !1,
3637
+ onClick: this.handleItemClick
3638
+ }, null))])]);
3639
+ }
3640
+ });
3641
+ const bt = /* @__PURE__ */ T({
3642
+ props: {
3643
+ controller: {
3644
+ type: Object,
3645
+ required: !0
3646
+ },
3647
+ data: {
3648
+ type: Object,
3649
+ required: !0
3650
+ },
3651
+ items: {
3652
+ type: Array,
3653
+ default: () => []
3654
+ },
3655
+ enableBackFill: {
3656
+ type: Boolean,
3657
+ default: !0
3658
+ }
3659
+ },
3660
+ setup(a) {
3661
+ const e = new A("chat-message-toolbar"), {
3662
+ handleItemClick: t
3663
+ } = oe(a), s = w([]), i = w([]), o = [{
3664
+ label: "刷新",
3665
+ title: "刷新",
3666
+ icon: () => K,
3667
+ onClick: () => {
3668
+ a.controller.refreshMessage(a.data);
3669
+ }
3670
+ }, {
3671
+ label: "删除",
3672
+ title: "删除",
3673
+ hidden: () => {
3674
+ var d;
3675
+ return !((d = a.data) != null && d.realmessageid);
3676
+ },
3677
+ icon: () => ae,
3678
+ onClick: () => {
3679
+ a.controller.deleteMessage(a.data);
3680
+ }
3681
+ }, {
3682
+ label: "复制",
3683
+ title: "复制",
3684
+ icon: () => ie,
3685
+ onClick: () => {
3686
+ a.controller.copyMessage(a.data);
3687
+ }
3688
+ }];
3689
+ a.enableBackFill && o.unshift({
3690
+ label: "回填",
3691
+ title: "回填",
3692
+ icon: () => it,
3693
+ onClick: () => {
3694
+ a.controller.backfill(a.data);
3695
+ }
3696
+ });
3697
+ const n = [{
3698
+ label: "刷新",
3699
+ title: "刷新",
3700
+ icon: () => K,
3701
+ onClick: () => {
3702
+ a.controller.refreshMessage(a.data, !0);
3703
+ }
3704
+ }], l = () => a.data.state === 20 && a.data.completed !== !0 || a.controller.resourceMode !== "REMOTE" || !a.data.realmessageid || a.controller.currentTopicDisableStorage, h = [{
3705
+ id: "islike",
3706
+ label: "点赞",
3707
+ title: "点赞",
3708
+ icon: () => tt,
3709
+ onClick: () => {
3710
+ a.controller.messageLike(a.data._origin);
3711
+ },
3712
+ hidden: () => l()
3713
+ }, {
3714
+ id: "isdislike",
3715
+ label: "点踩",
3716
+ title: "点踩",
3717
+ icon: () => st,
3718
+ onClick: () => {
3719
+ a.controller.messageDisLike(a.data._origin);
3720
+ },
3721
+ hidden: () => l()
3722
+ }];
3723
+ (() => {
3724
+ switch (a.data.type) {
3725
+ case "DEFAULT":
3726
+ a.data.role === "ASSISTANT" ? (s.value = [...h], i.value = [...o, ...a.items]) : i.value = [...n];
3727
+ break;
3728
+ case "ERROR":
3729
+ i.value = [...o, ...a.items];
3730
+ break;
3731
+ }
3732
+ })();
3733
+ const u = k(() => {
3734
+ var d, p;
3735
+ return ((d = a.data) == null ? void 0 : d.state) === 20 && ((p = a.data) == null ? void 0 : p.completed) !== !0;
3736
+ });
3737
+ return {
3738
+ ns: e,
3739
+ isLoadding: u,
3740
+ topItems: s,
3741
+ centerItems: i,
3742
+ handleItemClick: t
3743
+ };
3744
+ },
3745
+ render() {
3746
+ return r("div", {
3747
+ ref: "btnRef",
3748
+ class: this.ns.b()
3749
+ }, [this.topItems.length ? r("div", {
3750
+ class: this.ns.e("top")
3751
+ }, [this.topItems.map((a) => {
3752
+ const e = a.id === "islike" && this.data.islike === "1" || a.id === "isdislike" && this.data.isdislike === "1";
3753
+ return r(N, {
3754
+ data: this.data,
3755
+ model: a,
3756
+ disabled: this.isLoadding,
3757
+ class: [this.ns.em("top", "item"), this.ns.is("actived", !!e)],
3758
+ onClick: this.handleItemClick
3759
+ }, null);
3760
+ })]) : null, this.centerItems.length ? r("div", {
3761
+ class: this.ns.e("center")
3762
+ }, [this.centerItems.map((a) => r(N, {
3763
+ data: this.data,
3764
+ model: a,
3765
+ disabled: this.isLoadding,
3766
+ onClick: this.handleItemClick
3767
+ }, null))]) : null]);
3768
+ }
3769
+ });
3770
+ const wt = /* @__PURE__ */ T({
3771
+ emits: {
3772
+ close: () => !0
3773
+ },
3774
+ setup(a, {
3775
+ emit: e
3776
+ }) {
3777
+ return {
3778
+ ns: new A("custom-modal"),
3779
+ handleMaskClick: () => {
3780
+ e("close");
3781
+ }
3782
+ };
3783
+ },
3784
+ render() {
3785
+ var a, e;
3786
+ return r("div", {
3787
+ class: this.ns.b(),
3788
+ onClick: this.handleMaskClick
3789
+ }, [r("div", {
3790
+ class: this.ns.e("mask")
3791
+ }, null), r("div", {
3792
+ id: "modal-wrapper",
3793
+ class: this.ns.e("wrapper")
3794
+ }, [(e = (a = this.$slots).default) == null ? void 0 : e.call(a)])]);
3795
+ }
3796
+ });
3797
+ function yt(a) {
3798
+ const e = w();
3799
+ let t;
3800
+ const s = (l) => {
3801
+ if (!a.value || !a.value.$el)
3802
+ return;
3803
+ const h = 6;
3804
+ let c, u;
3805
+ l.touches && l.touches[0] ? (c = l.touches[0].clientX, u = l.touches[0].clientY) : (c = l.clientX, u = l.clientY);
3806
+ let d = c + h, p = u + h;
3807
+ const f = a.value.$el.querySelector("#modal-wrapper");
3808
+ if (!f)
3809
+ return;
3810
+ const m = f.getBoundingClientRect(), b = m.width, y = m.height, S = window.innerWidth, E = window.innerHeight, C = 8;
3811
+ d + b + C > S ? d = c - b - h : d < C && (d = C), p + y + C > E ? p = u - y - h : p < C && (p = C), f.style.top = "".concat(p, "px"), f.style.left = "".concat(d, "px"), f.style.visibility = "visible";
3812
+ };
3813
+ return { message: e, handleTouchStart: (l, h) => {
3814
+ clearTimeout(t), t = setTimeout(() => {
3815
+ e.value = h, _(() => s(l));
3816
+ }, 500);
3817
+ }, handleTouchEnd: () => {
3818
+ clearTimeout(t);
3819
+ }, closeToolbar: () => {
3820
+ e.value = void 0;
3821
+ } };
3822
+ }
3823
+ const Tt = /* @__PURE__ */ T({
3824
+ props: {
3825
+ controller: {
3826
+ type: Object,
3827
+ required: !0
3828
+ },
3829
+ toolbarItems: {
3830
+ type: Array
3831
+ },
3832
+ enableBackFill: {
3833
+ type: Boolean,
3834
+ default: !0
3835
+ }
3836
+ },
3837
+ setup(a) {
3838
+ const e = new A("chat-messages"), t = w(), s = w(), {
3839
+ message: i,
3840
+ handleTouchStart: o,
3841
+ handleTouchEnd: n,
3842
+ closeToolbar: l
3843
+ } = yt(s), h = 5, c = w(h), u = w(!1), d = w(!0), p = w(!1), {
3844
+ messages: f
3845
+ } = a.controller, m = k(() => {
3846
+ const C = Math.max(0, f.value.length - c.value);
3847
+ return f.value.slice(C);
3848
+ }), b = k(() => c.value < f.value.length), y = () => {
3849
+ const C = t.value;
3850
+ C && (p.value = !0, setTimeout(() => {
3851
+ C.scrollTo({
3852
+ top: C.scrollHeight,
3853
+ behavior: "auto"
3854
+ }), p.value = !1;
3855
+ }, 500));
3856
+ };
3857
+ return P(() => f.value, () => {
3858
+ d.value && y();
3859
+ }), {
3860
+ ns: e,
3861
+ message: i,
3862
+ messages: f,
3863
+ modalRef: s,
3864
+ containerRef: t,
3865
+ visibleMessages: m,
3866
+ handleScroll: () => {
3867
+ if (p.value)
3868
+ return;
3869
+ const C = t.value;
3870
+ if (!C)
3871
+ return;
3872
+ const {
3873
+ scrollTop: U,
3874
+ scrollHeight: re,
3875
+ clientHeight: le
3876
+ } = C;
3877
+ U < 100 && !u.value && b.value && (u.value = !0, setTimeout(() => {
3878
+ c.value = Math.min(c.value + h, f.value.length);
3879
+ const he = C.scrollHeight;
3880
+ setTimeout(() => {
3881
+ const ue = C.scrollHeight;
3882
+ C.scrollTop = ue - he + C.scrollTop, u.value = !1;
3883
+ }, 0);
3884
+ }, 300));
3885
+ const ce = re - (U + le) < 50;
3886
+ d.value = ce;
3887
+ },
3888
+ closeToolbar: l,
3889
+ renderMessage: (C) => {
3890
+ switch (C.type) {
3891
+ case "DEFAULT":
3892
+ return C.role === "ASSISTANT" ? r(pt, {
3893
+ message: C,
3894
+ controller: a.controller
3895
+ }, null) : r(ft, {
3896
+ message: C,
3897
+ controller: a.controller
3898
+ }, null);
3899
+ case "ERROR":
3900
+ return r(lt, {
3901
+ message: C
3902
+ }, null);
3903
+ default:
3904
+ return r(gt, {
3905
+ message: C
3906
+ }, null);
3907
+ }
3908
+ },
3909
+ handleTouchStart: o,
3910
+ handleTouchEnd: n
3911
+ };
3912
+ },
3913
+ render() {
3914
+ return r("div", {
3915
+ ref: "containerRef",
3916
+ class: this.ns.b(),
3917
+ onScroll: this.handleScroll
3918
+ }, [this.visibleMessages.map((a) => r("div", {
3919
+ key: a.messageid,
3920
+ class: this.ns.e("item"),
3921
+ onMouseup: this.handleTouchEnd,
3922
+ onTouchend: this.handleTouchEnd,
3923
+ onMousedown: (e) => this.handleTouchStart(e, a),
3924
+ onTouchstart: (e) => this.handleTouchStart(e, a)
3925
+ }, [this.renderMessage(a)])), r(vt, null, null), this.message && r(wt, {
3926
+ ref: "modalRef",
3927
+ onClose: this.closeToolbar
3928
+ }, {
3929
+ default: () => [r(bt, {
3930
+ data: this.message,
3931
+ items: this.toolbarItems,
3932
+ controller: this.controller,
3933
+ enableBackFill: this.enableBackFill
3934
+ }, null)]
3935
+ })]);
3936
+ }
3937
+ });
3938
+ const At = /* @__PURE__ */ T({
3939
+ props: {
3940
+ controller: {
3941
+ type: Object,
3942
+ required: !0
3943
+ },
3944
+ toolbarItems: {
3945
+ type: Array
3946
+ }
3947
+ },
3948
+ setup(a) {
3949
+ const e = new A("chat-input"), t = w([]), s = w(""), i = w(!1), o = w(), n = k(() => a.controller.isLoading.value), l = () => {
3950
+ const f = window.SpeechRecognition || window.webkitSpeechRecognition;
3951
+ f && (o.value = new f(), o.value.onstart = () => {
3952
+ i.value = !0;
3953
+ }, o.value.onend = () => {
3954
+ i.value = !1;
3955
+ }, o.value.onresult = (m) => {
3956
+ var y, S, E;
3957
+ const b = (E = (S = (y = m.results) == null ? void 0 : y[0]) == null ? void 0 : S[0]) == null ? void 0 : E.transcript;
3958
+ b && (s.value += "".concat(b));
3959
+ });
3960
+ };
3961
+ return z(() => {
3962
+ l();
3963
+ }), {
3964
+ ns: e,
3965
+ message: s,
3966
+ isLoading: n,
3967
+ recording: i,
3968
+ imageList: t,
3969
+ uploadImage: async () => {
3970
+ const f = await window.ibiz.util.file.chooseFileAndUpload(a.controller.context, a.controller.params, {}, {
3971
+ multiple: !0,
3972
+ accept: "image/*",
3973
+ extraParams: {
3974
+ enableNoAccess: !0
3975
+ }
3976
+ });
3977
+ if (!f || !Array.isArray(f))
3978
+ return;
3979
+ const {
3980
+ downloadUrl: m
3981
+ } = window.ibiz.util.file.calcFileUpDownUrl(a.controller.context, a.controller.params, {}, {
3982
+ enableNoAccess: !0
3983
+ });
3984
+ f.forEach((b) => {
3985
+ t.value.push({
3986
+ isImage: !0,
3987
+ name: b.name,
3988
+ url: m.replace("%fileId%", b.fileid)
3989
+ });
3990
+ });
3991
+ },
3992
+ onSendMessage: async () => {
3993
+ if (n.value)
3994
+ await a.controller.abortQuestion();
3995
+ else {
3996
+ const f = t.value.map((b) => "![".concat(b.name, "](").concat(b.url, ")")).join("\n"), m = "".concat(f, "\n").concat(s.value);
3997
+ s.value = "", t.value = [], await a.controller.question(m);
3998
+ }
3999
+ },
4000
+ uploadMaterial: async (f) => {
4001
+ await He.getMaterialHelper("ossfile", a.controller).excuteAction(f);
4002
+ },
4003
+ onRemoveMaterial: (f) => {
4004
+ a.controller.deleteMaterial(f);
4005
+ },
4006
+ onSpeechRecognition: () => {
4007
+ o.value && (i.value ? o.value.end() : o.value.start());
4008
+ }
4009
+ };
4010
+ },
4011
+ render() {
4012
+ return r("div", {
4013
+ class: this.ns.b()
4014
+ }, [r(ne, {
4015
+ class: this.ns.e("material"),
4016
+ materials: this.controller.materials.value,
4017
+ onRemove: this.onRemoveMaterial
4018
+ }, null), r(me("van-uploader"), {
4019
+ previewSize: "4rem",
4020
+ showUpload: !1,
4021
+ modelValue: this.imageList,
4022
+ "onUpdate:modelValue": (a) => this.imageList = a,
4023
+ class: this.ns.e("image")
4024
+ }, null), r("div", {
4025
+ class: this.ns.e("content")
4026
+ }, [r("div", {
4027
+ class: [this.ns.e("icon"), this.ns.em("icon", "voice"), this.ns.is("recording", this.recording)],
4028
+ onClick: this.onSpeechRecognition
4029
+ }, [this.recording ? Ue : Pe]), fe(r("textarea", {
4030
+ rows: 1,
4031
+ "onUpdate:modelValue": (a) => this.message = a,
4032
+ placeholder: "输入消息...",
4033
+ class: this.ns.e("input")
4034
+ }, null), [[ve, this.message]]), r("div", {
4035
+ class: [this.ns.e("icon"), this.ns.em("icon", "image")],
4036
+ onClick: this.uploadImage
4037
+ }, [ot]), r("div", {
4038
+ class: [this.ns.e("icon"), this.ns.em("icon", "upload")],
4039
+ onClick: this.uploadMaterial
4040
+ }, [Ze]), r("div", {
4041
+ class: [this.ns.e("icon"), this.ns.em("icon", "send"), this.ns.is("disabled", !this.message && !this.isLoading)],
4042
+ onClick: this.onSendMessage
4043
+ }, [this.isLoading ? Xe : Ve])])]);
4044
+ }
4045
+ });
4046
+ const Q = /* @__PURE__ */ T({
4047
+ props: {
4048
+ enableBackFill: {
4049
+ type: Boolean,
4050
+ default: !0
4051
+ },
4052
+ aiTopic: {
4053
+ type: Object,
4054
+ required: !0
4055
+ },
4056
+ aiChat: {
4057
+ type: Object,
4058
+ required: !0
4059
+ },
4060
+ openMode: {
4061
+ type: String,
4062
+ default: "default"
4063
+ },
4064
+ caption: {
4065
+ type: String,
4066
+ default: "AI助手"
4067
+ },
4068
+ contentToolbarItems: {
4069
+ type: Array
4070
+ },
4071
+ footerToolbarItems: {
4072
+ type: Array
4073
+ },
4074
+ questionToolbarItems: {
4075
+ type: Array
4076
+ },
4077
+ containerOptions: {
4078
+ type: Object
4079
+ },
4080
+ autoClose: {
4081
+ type: Object
4082
+ }
4083
+ },
4084
+ emits: {
4085
+ close: () => !0
4086
+ },
4087
+ setup(a, {
4088
+ emit: e
4089
+ }) {
4090
+ var n;
4091
+ const t = new A("chat-container"), s = ((n = a.containerOptions) == null ? void 0 : n.zIndex) || 10, i = () => {
4092
+ e("close");
4093
+ };
4094
+ return a.aiChat.evt.on("onCompleteMessage", () => {
4095
+ if (a.autoClose) {
4096
+ const {
4097
+ mode: l,
4098
+ duration: h = 3
4099
+ } = a.autoClose;
4100
+ switch (l) {
4101
+ case "close":
4102
+ i();
4103
+ break;
4104
+ case "closetime":
4105
+ setTimeout(() => {
4106
+ i();
4107
+ }, h * 1e3);
4108
+ break;
4109
+ }
4110
+ }
4111
+ }), {
4112
+ ns: t,
4113
+ zIndex: s,
4114
+ onClose: i,
4115
+ onClickOverlay: () => {
4116
+ a.openMode !== "default" && i();
4117
+ }
4118
+ };
4119
+ },
4120
+ render() {
4121
+ return r("div", {
4122
+ style: {
4123
+ zIndex: this.zIndex
4124
+ },
4125
+ class: [this.ns.b(), this.ns.e("overlay")],
4126
+ onClick: this.onClickOverlay
4127
+ }, [r("div", {
4128
+ class: [this.ns.e("dialog"), this.ns.em("dialog", this.openMode)],
4129
+ onClick: (a) => a.stopPropagation()
4130
+ }, [r("div", {
4131
+ class: this.ns.e("header")
4132
+ }, [r("div", {
4133
+ class: this.ns.em("header", "left")
4134
+ }, [r("div", {
4135
+ class: this.ns.em("header", "icon")
4136
+ }, [q]), r("div", {
4137
+ class: this.ns.em("header", "caption")
4138
+ }, [this.caption])]), r("div", {
4139
+ class: this.ns.em("header", "reght")
4140
+ }, [r("div", {
4141
+ class: this.ns.e("icon"),
4142
+ onClick: this.onClose
4143
+ }, [rt])])]), r("div", {
4144
+ class: this.ns.e("content")
4145
+ }, [r(Tt, {
4146
+ controller: this.aiChat,
4147
+ toolbarItems: this.contentToolbarItems,
4148
+ enableBackFill: this.enableBackFill
4149
+ }, null)]), r("div", {
4150
+ class: this.ns.e("footer")
4151
+ }, [r(Ct, {
4152
+ data: this.aiTopic.activedTopic.value,
4153
+ controller: this.aiChat,
4154
+ items: this.footerToolbarItems
4155
+ }, null), r(At, {
4156
+ controller: this.aiChat,
4157
+ toolbarItems: this.questionToolbarItems
4158
+ }, null)])])]);
4159
+ }
4160
+ });
4161
+ class It {
4162
+ /**
4163
+ * Creates an instance of ChatController.
4164
+ * @author tony001
4165
+ * @date 2025-02-24 11:02:20
4166
+ */
4167
+ constructor() {
4168
+ /**
4169
+ * @description 应用
4170
+ * @private
4171
+ * @type {(App | null)}
4172
+ * @memberof ChatController
4173
+ */
4174
+ v(this, "App", null);
4175
+ /**
4176
+ * 聊天框容器
4177
+ *
4178
+ * @author chitanda
4179
+ * @date 2023-10-13 17:10:03
4180
+ * @protected
4181
+ * @type {HTMLDivElement}
4182
+ */
4183
+ v(this, "container");
4184
+ /**
4185
+ * 默认模式(聊天框)和话题模式(支持多话题切换),聊天框为默认模式
4186
+ *
4187
+ * @author tony001
4188
+ * @date 2025-02-20 16:02:50
4189
+ * @protected
4190
+ * @type {('DEFAULT' | 'TOPIC')}
4191
+ */
4192
+ v(this, "mode", "DEFAULT");
4193
+ /**
4194
+ * 资源配置数据
4195
+ */
4196
+ v(this, "resourceOptions");
4197
+ /**
4198
+ * 容器配置备份
4199
+ *
4200
+ * @author tony001
4201
+ * @date 2025-02-24 11:02:49
4202
+ * @protected
4203
+ * @type {(IContainerOptions | undefined)}
4204
+ */
4205
+ v(this, "backupChatOptions");
4206
+ /**
4207
+ * 话题控制器
4208
+ *
4209
+ * @author tony001
4210
+ * @date 2025-02-23 16:02:56
4211
+ * @public
4212
+ * @type {AITopicController}
4213
+ */
4214
+ v(this, "aiTopic");
4215
+ /**
4216
+ * 话题map
4217
+ *
4218
+ * @private
4219
+ * @type {Map<string, AIChatController>}
4220
+ * @memberof ChatController
4221
+ */
4222
+ v(this, "aiTopicMap", /* @__PURE__ */ new Map());
4223
+ this.aiTopic = new _e(this);
4224
+ }
4225
+ /**
4226
+ * 聊天控制器
4227
+ *
4228
+ * @readonly
4229
+ * @type {(AIChatController | undefined)}
4230
+ * @memberof ChatController
4231
+ */
4232
+ get aiChat() {
4233
+ var e;
4234
+ return this.aiTopicMap.get("".concat((e = this.aiTopic.activedTopic.value) == null ? void 0 : e.id));
4235
+ }
4236
+ /**
4237
+ * 初始化IndexDB
4238
+ *
4239
+ * @author tony001
4240
+ * @date 2025-02-24 18:02:50
4241
+ * @return {*} {Promise<void>}
4242
+ */
4243
+ async initIndexDB() {
4244
+ await x.checkTableExists(
4245
+ I.DATA_BASE_NAME,
4246
+ I.DATA_TABLE_NAME
4247
+ ) || await x.createTable(
4248
+ I.DATA_BASE_NAME,
4249
+ I.DATA_TABLE_NAME,
4250
+ I.DATA_TABLE_KEY_NAME,
4251
+ !1
4252
+ );
4253
+ }
4254
+ /**
4255
+ * 创建聊天窗口(会同时显示出来)
4256
+ *
4257
+ * @author tony001
4258
+ * @date 2025-02-24 12:02:58
4259
+ * @param {IContainerOptions} opts
4260
+ * @return {*} {Promise<AIChatController>}
4261
+ */
4262
+ async create(e) {
4263
+ var n, l, h, c;
4264
+ this.resourceOptions = e.resourceOptions, (((n = e.resourceOptions) == null ? void 0 : n.resourceMode) || "LOCAL") === "LOCAL" && await this.initIndexDB(), this.backupChatOptions = e, await this.close(), this.container = document.createElement("div"), this.container.classList.add("ibiz-ai-chat"), document.body.appendChild(this.container);
4265
+ const s = e.chatOptions;
4266
+ let i;
4267
+ e.mode && e.mode === "TOPIC" ? (this.aiTopic.injectResourceOptions(e.resourceOptions), await this.aiTopic.fetchHistory(e.topicOptions), i = e.topicOptions, Object.assign(i, {
4268
+ aiChat: {
4269
+ caption: s.caption,
4270
+ context: s.context,
4271
+ params: s.params,
4272
+ appDataEntityId: s.appDataEntityId,
4273
+ sessionid: s.sessionid,
4274
+ contentToolbarItems: s.contentToolbarItems,
4275
+ footerToolbarItems: s.footerToolbarItems,
4276
+ questionToolbarItems: s.questionToolbarItems,
4277
+ otherToolbarItems: s.otherToolbarItems,
4278
+ appendCurData: s.appendCurData,
4279
+ appendCurContent: s.appendCurContent,
4280
+ enableAIAgentChange: s.enableAIAgentChange,
4281
+ activeAIAgentID: s.activeAIAgentID,
4282
+ aiAgentlist: s.aiAgentlist,
4283
+ srfMode: s.srfMode,
4284
+ appendCurResource: s.appendCurResource
4285
+ }
4286
+ }), this.syncHistoryOptions(i, s, e.resourceOptions), await this.aiTopic.asyncTopic(i)) : this.aiTopic.activedTopic.value = void 0, Object.assign(s, {
4287
+ topicId: i == null ? void 0 : i.id,
4288
+ topic: i,
4289
+ aiTopic: this.aiTopic
4290
+ });
4291
+ const o = new Y(s, this.resourceOptions);
4292
+ return this.aiTopicMap.set("".concat(i == null ? void 0 : i.id), o), this.App = V(Q, {
4293
+ aiChat: o,
4294
+ aiTopic: this.aiTopic,
4295
+ mode: e.mode ? e.mode : "DEFAULT",
4296
+ containerOptions: e.containerOptions,
4297
+ caption: e.mode && e.mode === "TOPIC" ? "AI助手" : s.caption,
4298
+ autoClose: (l = e.containerOptions) == null ? void 0 : l.autoClose,
4299
+ enableBackFill: (h = e.containerOptions) == null ? void 0 : h.enableBackFill,
4300
+ contentToolbarItems: s.contentToolbarItems,
4301
+ footerToolbarItems: s.footerToolbarItems,
4302
+ questionToolbarItems: s.questionToolbarItems,
4303
+ openMode: (c = e.containerOptions) == null ? void 0 : c.openMode,
4304
+ onClose: async () => {
4305
+ await this.close(), s.closed && s.closed(
4306
+ s.context,
4307
+ s.params,
4308
+ o.getAllMessages()
4309
+ );
4310
+ }
4311
+ }), this.App.use(be), this.App.mount(this.container), o;
4312
+ }
4313
+ /**
4314
+ * 同步历史参数(历史激活标识、历史会话标识)
4315
+ * @param topicOptions
4316
+ * @param chatOptions
4317
+ */
4318
+ syncHistoryOptions(e, t, s) {
4319
+ if (e.disableStorage) {
4320
+ const n = De("TEMP");
4321
+ t.sessionid = n, e.aiChat.sessionid = n, e.caption = "临时会话", e.sourceCaption = "临时会话", e.captionFilled = !0;
4322
+ return;
4323
+ }
4324
+ const i = this.aiTopic.getCurrentTopicByID(
4325
+ e.id
4326
+ );
4327
+ if (i && (e.sequence = i.sequence, e.isTop = i.isTop), i && i.aiChat && i.aiChat.activeAIAgentID)
4328
+ t.activeAIAgentID = i.aiChat.activeAIAgentID, e.aiChat.activeAIAgentID = i.aiChat.activeAIAgentID;
4329
+ else if (t.aiAgentlist && t.aiAgentlist.length > 0 && !t.activeAIAgentID) {
4330
+ const n = t.aiAgentlist.find(
4331
+ (l) => l.default === 1
4332
+ );
4333
+ n ? (t.activeAIAgentID = n.id, e.aiChat.activeAIAgentID = n.id) : (t.activeAIAgentID = t.aiAgentlist[0].id, e.aiChat.activeAIAgentID = t.aiAgentlist[0].id);
4334
+ }
4335
+ i && i.aiChat && i.aiChat.sessionid && (t.sessionid = i.aiChat.sessionid, e.aiChat.sessionid = i.aiChat.sessionid);
4336
+ const o = s.resourceMode;
4337
+ o === "LOCAL" ? e.captionMode !== "default" ? (e.sourceCaption = "新会话", i && i.captionFilled && i.caption ? (e.captionFilled = i.captionFilled, e.caption = i.caption) : e.caption = "新会话") : (e.sourceCaption = e.caption, e.captionFilled = !0) : o === "REMOTE" && (e.sourceCaption = e.caption, i && i.caption && (e.caption = i.caption), e.captionFilled = !1), o === "REMOTE" && i && i.realid && (e.realid = i.realid);
4338
+ }
4339
+ /**
4340
+ * 切换聊天控制器
4341
+ *
4342
+ * @author tony001
4343
+ * @date 2025-02-24 11:02:24
4344
+ * @param {ChatTopic} topic
4345
+ */
4346
+ switchAiChatController(e) {
4347
+ var i, o, n, l, h, c, u, d, p;
4348
+ const t = {
4349
+ ...this.backupChatOptions.chatOptions
4350
+ };
4351
+ e.aiChat && Object.assign(t, {
4352
+ caption: e.aiChat.caption,
4353
+ context: e.aiChat.context,
4354
+ params: e.aiChat.params,
4355
+ sessionid: e.aiChat.sessionid,
4356
+ contentToolbarItems: e.aiChat.contentToolbarItems,
4357
+ footerToolbarItems: e.aiChat.footerToolbarItems,
4358
+ questionToolbarItems: e.aiChat.questionToolbarItems,
4359
+ otherToolbarItems: e.aiChat.otherToolbarItems,
4360
+ appendCurData: e.aiChat.appendCurData,
4361
+ appendCurContent: e.aiChat.appendCurContent,
4362
+ aiAgentlist: e.aiChat.aiAgentlist,
4363
+ activeAIAgentID: e.aiChat.activeAIAgentID,
4364
+ enableAIAgentChange: e.aiChat.enableAIAgentChange,
4365
+ srfMode: e.aiChat.srfMode,
4366
+ appendCurResource: e.aiChat.appendCurResource,
4367
+ appDataEntityId: e.aiChat.appDataEntityId,
4368
+ topicId: e.id,
4369
+ topic: e,
4370
+ aiTopic: this.aiTopic,
4371
+ extendToolbarClick: this.backupChatOptions.chatOptions.extendToolbarClick,
4372
+ recommendPrompt: this.backupChatOptions.chatOptions.recommendPrompt
4373
+ });
4374
+ let s;
4375
+ this.aiTopicMap.has("".concat(e.id)) ? s = this.aiTopicMap.get("".concat(e.id)) : (s = new Y(t, this.resourceOptions), this.aiTopicMap.set("".concat(e.id), s)), this.container && this.App && (this.App.unmount(), this.App = V(Q, {
4376
+ aiChat: s,
4377
+ aiTopic: this.aiTopic,
4378
+ mode: (i = this.backupChatOptions) != null && i.mode ? this.backupChatOptions.mode : "DEFAULT",
4379
+ containerOptions: (o = this.backupChatOptions) == null ? void 0 : o.containerOptions,
4380
+ caption: (n = this.backupChatOptions) != null && n.mode && this.backupChatOptions.mode === "TOPIC" ? "AI助手" : t.caption,
4381
+ enableBackFill: (h = (l = this.backupChatOptions) == null ? void 0 : l.containerOptions) == null ? void 0 : h.enableBackFill,
4382
+ autoClose: (u = (c = this.backupChatOptions) == null ? void 0 : c.containerOptions) == null ? void 0 : u.autoClose,
4383
+ contentToolbarItems: t.contentToolbarItems,
4384
+ footerToolbarItems: t.footerToolbarItems,
4385
+ questionToolbarItems: t.questionToolbarItems,
4386
+ openMode: (p = (d = this.backupChatOptions) == null ? void 0 : d.containerOptions) == null ? void 0 : p.openMode,
4387
+ onClose: async () => {
4388
+ await this.close(), t.closed && t.closed(t.context, t.params, s.getAllMessages());
4389
+ }
4390
+ }), this.App.mount(this.container));
4391
+ }
4392
+ /**
4393
+ * 隐藏聊天窗口(必须先创建)
4394
+ *
4395
+ * @author chitanda
4396
+ * @date 2023-10-13 17:10:55
4397
+ */
4398
+ hidden() {
4399
+ this.container && (this.container.style.display = "none");
4400
+ }
4401
+ /**
4402
+ * 显示聊天窗窗口(必须先创建)
4403
+ *
4404
+ * @author chitanda
4405
+ * @date 2023-10-13 17:10:29
4406
+ */
4407
+ show() {
4408
+ this.container && (this.container.style.display = "flex");
4409
+ }
4410
+ /**
4411
+ * 关闭聊天窗口
4412
+ *
4413
+ * @author chitanda
4414
+ * @date 2023-10-13 17:10:10
4415
+ */
4416
+ async close() {
4417
+ await Promise.all(
4418
+ Array.from(this.aiTopicMap).map((e) => e[1].destroyed())
4419
+ ), this.App && this.container && (this.App.unmount(), this.App = null), this.container && document.body.contains(this.container) && (document.body.removeChild(this.container), this.container = void 0);
4420
+ }
4421
+ }
4422
+ const Dt = new It();
4423
+ export {
4424
+ Dt as chat
4425
+ };