rt-chat-messages 1.0.4 → 1.0.5

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.
@@ -1,8 +1,9 @@
1
- import { defineComponent as Q, ref as b, onMounted as De, computed as X, createBlock as G, createCommentVNode as D, openBlock as o, Teleport as st, createElementBlock as u, withModifiers as Z, normalizeClass as le, createElementVNode as a, normalizeStyle as ve, renderSlot as be, h as Se, watch as J, nextTick as de, onUnmounted as Re, createVNode as f, withCtx as H, unref as I, createTextVNode as ze, toDisplayString as F, Fragment as ue, renderList as me, resolveDynamicComponent as Pe, withDirectives as at, vShow as nt } from "vue";
2
- import lt from "markdown-it";
3
- import ot from "@vscode/markdown-it-katex";
4
- import Le from "mermaid";
5
- const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
1
+ import { defineComponent as be, ref as w, onMounted as Ve, computed as Q, createBlock as oe, createCommentVNode as z, openBlock as u, Teleport as st, createElementBlock as f, withModifiers as fe, normalizeClass as he, createElementVNode as o, normalizeStyle as Ie, renderSlot as Oe, h as Fe, watch as ge, nextTick as ne, onUnmounted as Ue, createVNode as k, withCtx as R, unref as E, createTextVNode as We, toDisplayString as K, Fragment as Ee, renderList as Te, resolveDynamicComponent as Ke, withDirectives as nt, vShow as ot, createStaticVNode as lt, Transition as rt, getCurrentInstance as it } from "vue";
2
+ import { useMessageProcessor as ct, A2UISurface as ut, useA2UIConfig as dt, provideA2UI as mt, defaultTheme as vt, DEFAULT_CATALOG as ft } from "a2ui-vue";
3
+ import gt from "markdown-it";
4
+ import ht from "@vscode/markdown-it-katex";
5
+ import je from "mermaid";
6
+ const pt = { class: "cm-dialog__body" }, yt = /* @__PURE__ */ be({
6
7
  __name: "Dialog",
7
8
  props: {
8
9
  visible: { type: Boolean, default: !1 },
@@ -13,63 +14,63 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
13
14
  appendToBody: { type: Boolean, default: !0 }
14
15
  },
15
16
  emits: ["update:visible", "close"],
16
- setup(n, { emit: p }) {
17
- const k = n, i = p, z = b(!1);
18
- De(() => {
19
- z.value = !0;
17
+ setup(r, { emit: h }) {
18
+ const b = r, p = h, d = w(!1);
19
+ Ve(() => {
20
+ d.value = !0;
20
21
  });
21
- const $ = X(() => k.fullscreen ? { width: "100%", height: "100%", margin: 0 } : { width: k.width }), E = () => {
22
- i("update:visible", !1), i("close");
23
- }, x = () => {
24
- k.closeOnClickModal && E();
22
+ const S = Q(() => b.fullscreen ? { width: "100%", height: "100%", margin: 0 } : { width: b.width }), C = () => {
23
+ p("update:visible", !1), p("close");
24
+ }, A = () => {
25
+ b.closeOnClickModal && C();
25
26
  };
26
- return (T, _) => z.value ? (o(), G(st, {
27
+ return (x, _) => d.value ? (u(), oe(st, {
27
28
  key: 0,
28
29
  to: "body"
29
30
  }, [
30
- n.visible ? (o(), u("div", {
31
+ r.visible ? (u(), f("div", {
31
32
  key: 0,
32
- class: le(["cm-dialog-overlay", { "is-fullscreen": n.fullscreen }]),
33
- onClick: Z(x, ["self"])
33
+ class: he(["cm-dialog-overlay", { "is-fullscreen": r.fullscreen }]),
34
+ onClick: fe(A, ["self"])
34
35
  }, [
35
- a("div", {
36
+ o("div", {
36
37
  class: "cm-dialog",
37
- style: ve($.value),
38
+ style: Ie(S.value),
38
39
  role: "dialog",
39
40
  "aria-modal": "true"
40
41
  }, [
41
- a("div", it, [
42
- be(T.$slots, "default", {}, void 0, !0)
42
+ o("div", pt, [
43
+ Oe(x.$slots, "default", {}, void 0, !0)
43
44
  ]),
44
- n.showClose ? (o(), u("button", {
45
+ r.showClose ? (u(), f("button", {
45
46
  key: 0,
46
47
  class: "cm-dialog__close",
47
- onClick: E
48
+ onClick: C
48
49
  }, [..._[0] || (_[0] = [
49
- a("svg", {
50
+ o("svg", {
50
51
  viewBox: "0 0 1024 1024",
51
52
  width: "16",
52
53
  height: "16"
53
54
  }, [
54
- a("path", {
55
+ o("path", {
55
56
  fill: "currentColor",
56
57
  d: "M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"
57
58
  })
58
59
  ], -1)
59
- ])])) : D("", !0)
60
+ ])])) : z("", !0)
60
61
  ], 4)
61
- ], 2)) : D("", !0)
62
- ])) : D("", !0);
62
+ ], 2)) : z("", !0)
63
+ ])) : z("", !0);
63
64
  }
64
- }), oe = (n, p) => {
65
- const k = n.__vccOpts || n;
66
- for (const [i, z] of p)
67
- k[i] = z;
68
- return k;
69
- }, Me = /* @__PURE__ */ oe(rt, [["__scopeId", "data-v-efdf0259"]]), ct = ["disabled"], dt = {
65
+ }), _e = (r, h) => {
66
+ const b = r.__vccOpts || r;
67
+ for (const [p, d] of h)
68
+ b[p] = d;
69
+ return b;
70
+ }, Pe = /* @__PURE__ */ _e(yt, [["__scopeId", "data-v-efdf0259"]]), wt = ["disabled"], kt = {
70
71
  key: 0,
71
72
  class: "cm-icon-loading"
72
- }, ut = /* @__PURE__ */ Q({
73
+ }, bt = /* @__PURE__ */ be({
73
74
  __name: "Button",
74
75
  props: {
75
76
  type: { default: "default" },
@@ -79,37 +80,37 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
79
80
  loading: { type: Boolean, default: !1 }
80
81
  },
81
82
  emits: ["click"],
82
- setup(n, { emit: p }) {
83
- const k = n, i = p, z = ($) => {
84
- k.disabled || k.loading || i("click", $);
83
+ setup(r, { emit: h }) {
84
+ const b = r, p = h, d = (S) => {
85
+ b.disabled || b.loading || p("click", S);
85
86
  };
86
- return ($, E) => (o(), u("button", {
87
- class: le(["cm-button", [
88
- `cm-button--${n.type}`,
89
- `cm-button--${n.size}`,
90
- { "is-circle": n.circle, "is-disabled": n.disabled, "is-loading": n.loading }
87
+ return (S, C) => (u(), f("button", {
88
+ class: he(["cm-button", [
89
+ `cm-button--${r.type}`,
90
+ `cm-button--${r.size}`,
91
+ { "is-circle": r.circle, "is-disabled": r.disabled, "is-loading": r.loading }
91
92
  ]]),
92
- disabled: n.disabled || n.loading,
93
- onClick: z
93
+ disabled: r.disabled || r.loading,
94
+ onClick: d
94
95
  }, [
95
- n.loading ? (o(), u("span", dt, [...E[0] || (E[0] = [
96
- a("svg", {
96
+ r.loading ? (u(), f("span", kt, [...C[0] || (C[0] = [
97
+ o("svg", {
97
98
  viewBox: "0 0 1024 1024",
98
99
  width: "1em",
99
100
  height: "1em"
100
101
  }, [
101
- a("path", {
102
+ o("path", {
102
103
  fill: "currentColor",
103
104
  d: "M512 64a448 448 0 0 1 448 448 32 32 0 1 1-64 0 416 416 0 0 0-416-416 416 416 0 0 0-416 416 32 32 0 1 1-64 0 448 448 0 0 1 448-448z"
104
105
  })
105
106
  ], -1)
106
- ])])) : be($.$slots, "default", { key: 1 }, void 0, !0)
107
- ], 10, ct));
107
+ ])])) : Oe(S.$slots, "default", { key: 1 }, void 0, !0)
108
+ ], 10, wt));
108
109
  }
109
- }), N = /* @__PURE__ */ oe(ut, [["__scopeId", "data-v-bab126c7"]]), U = (n, p) => Q({
110
- name: n,
110
+ }), Y = /* @__PURE__ */ _e(bt, [["__scopeId", "data-v-bab126c7"]]), X = (r, h) => be({
111
+ name: r,
111
112
  render() {
112
- return Se(
113
+ return Fe(
113
114
  "svg",
114
115
  {
115
116
  xmlns: "http://www.w3.org/2000/svg",
@@ -119,76 +120,76 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
119
120
  fill: "currentColor",
120
121
  style: "vertical-align: middle"
121
122
  },
122
- [Se("path", { d: p })]
123
+ [Fe("path", { d: h })]
123
124
  );
124
125
  }
125
- }), fe = U(
126
+ }), He = X(
126
127
  "Close",
127
128
  "M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"
128
- ), Ee = U(
129
+ ), Ye = X(
129
130
  "ZoomIn",
130
131
  "M637.696 587.392a316.032 316.032 0 1 0-45.44 49.344l191.232 191.296a32 32 0 0 0 45.312-45.184L637.696 587.392zM73.152 357.696a284.48 284.48 0 1 1 284.48 284.48A284.672 284.672 0 0 1 73.152 357.568zm268.48-154.56a32 32 0 0 0-32 32v90.496h-90.56a32 32 0 0 0 0 64h90.56v90.56a32 32 0 0 0 64 0v-90.496h90.496a32 32 0 0 0 0-64H373.632v-90.56a32 32 0 0 0-32-32z"
131
- ), Ie = U(
132
+ ), Ne = X(
132
133
  "ZoomOut",
133
134
  "M637.696 587.392a316.032 316.032 0 1 0-45.44 49.344l191.232 191.296a32 32 0 0 0 45.312-45.184L637.696 587.392zM73.152 357.696a284.48 284.48 0 1 1 284.48 284.48A284.672 284.672 0 0 1 73.152 357.568zm145.92-58.56a32 32 0 0 0 0 64h245.12a32 32 0 0 0 0-64H219.072z"
134
- ), Be = U(
135
+ ), Mt = X(
135
136
  "Document",
136
137
  "M854.6 288.7c0.4 0 0.7 0 1 0v431.5c0 17.6-14.4 32-32 32H200.4c-17.6 0-32-14.4-32-32l0-575.2c0-17.6 14.4-32 32-32h391.5c0 0.3 0 0.7 0 1l0 142.1c0 17.6 14.4 32.1 32 32.1h142.6c0-0.4 0-0.7 0-1.1L854.6 288.7zM790.2 220.2L668 97.9v122.3h122.2zM240 448h544a32 32 0 0 0 0-64H240a32 32 0 0 0 0 64zm0 128h544a32 32 0 0 0 0-64H240a32 32 0 0 0 0 64zm0 128h384a32 32 0 0 0 0-64H240a32 32 0 0 0 0 64z"
137
- ), Ae = U(
138
+ ), Xe = X(
138
139
  "Download",
139
140
  "M505.7 661a8 8 0 0 0 12.6 0l112-141.7c4.1-5.2 0.4-12.9-6.3-12.9h-74.1V168c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v338.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.8zM878 626h-60c-4.4 0-8 3.6-8 8v154H214V634c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v198c0 17.7 14.3 32 32 32h684c17.7 0 32-14.3 32-32V634c0-4.4-3.6-8-8-8z"
140
- ), mt = U(
141
+ ), St = X(
141
142
  "VideoPlay",
142
143
  "M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 832a384 384 0 1 0 0-768 384 384 0 0 0 0 768zm-48-247.616L668.608 512 464 375.616v272.768zm10.656-340.32a32 32 0 0 1 32 32V673.92a32 32 0 0 1-50.208 26.24l-236.8-161.92a32 32 0 0 1 0-52.48l236.8-161.92a32 32 0 0 1 18.208-5.632z"
143
- ), vt = U(
144
+ ), Ct = X(
144
145
  "VideoPause",
145
146
  "M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 832a384 384 0 1 0 0-768 384 384 0 0 0 0 768zm-96-544a32 32 0 0 1 32 32v256a32 32 0 0 1-64 0V384a32 32 0 0 1 32-32zm192 0a32 32 0 0 1 32 32v256a32 32 0 0 1-64 0V384a32 32 0 0 1 32-32z"
146
- ), gt = U(
147
+ ), At = X(
147
148
  "ArrowLeft",
148
149
  "M609.408 149.376 277.76 489.6a32 32 0 0 0 0 44.672l331.648 340.352a29.12 29.12 0 0 0 41.728 0 30.592 30.592 0 0 0 0-42.752L339.264 511.936l311.872-319.872a30.592 30.592 0 0 0 0-42.688 29.12 29.12 0 0 0-41.728 0z"
149
- ), ht = U(
150
+ ), $t = X(
150
151
  "ArrowRight",
151
152
  "M340.864 149.312a29.12 29.12 0 0 0-41.728 0 30.592 30.592 0 0 0 0 42.752L611.072 511.936 299.136 831.872a30.592 30.592 0 0 0 0 42.752 29.12 29.12 0 0 0 41.728 0L672.448 534.272a32 32 0 0 0 0-44.672L340.864 149.312z"
152
- ), Te = U(
153
+ ), qe = X(
153
154
  "Spinner",
154
155
  "M512 64a448 448 0 0 1 448 448 32 32 0 1 1-64 0 416 416 0 0 0-416-416 416 416 0 0 0-416 416 32 32 0 1 1-64 0 448 448 0 0 1 448-448z"
155
- ), He = U(
156
+ ), Ze = X(
156
157
  "Check",
157
158
  "M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1 0.4-12.8-6.3-12.8z"
158
- ), ft = U(
159
+ ), It = X(
159
160
  "ChevronUp",
160
161
  "M854.6 642.5l-320-320c-12.5-12.5-32.8-12.5-45.3 0l-320 320c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L512 390.6l297.4 297.4c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3z"
161
- ), pt = U(
162
+ ), _t = X(
162
163
  "ChevronDown",
163
164
  "M854.6 381.5l-320 320c-12.5 12.5-32.8 12.5-45.3 0l-320-320c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L512 633.4l297.4-297.4c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3z"
164
- ), yt = ["src", "alt"], wt = { class: "preview-controls" }, kt = { class: "cm-button-group" }, Mt = {
165
+ ), xt = ["src", "alt"], Lt = { class: "preview-controls" }, zt = { class: "cm-button-group" }, Et = {
165
166
  key: 0,
166
167
  class: "mobile-close-hint"
167
- }, Ct = ["innerHTML"], bt = { class: "preview-controls" }, _t = { class: "cm-button-group" }, $t = {
168
+ }, Tt = ["innerHTML"], Bt = { class: "preview-controls" }, Ut = { class: "cm-button-group" }, Ht = {
168
169
  key: 0,
169
170
  class: "mobile-close-hint"
170
- }, xt = /* @__PURE__ */ Q({
171
+ }, Dt = /* @__PURE__ */ be({
171
172
  __name: "MarkdownMessage",
172
173
  props: {
173
174
  content: {},
174
175
  isStreaming: { type: Boolean, default: !1 }
175
176
  },
176
- setup(n) {
177
- const p = n, k = b(), i = b(), z = b(!1), $ = b(""), E = b(""), x = b(!1), T = b(""), _ = b(!1), c = b(1), d = b({ x: 0, y: 0 }), M = b(!1), L = b({ x: 0, y: 0 }), S = b(1), C = b({ x: 0, y: 0 }), ee = b(!1), te = b({ x: 0, y: 0 }), se = b(""), q = b(/* @__PURE__ */ new Map());
178
- let ae = 0;
179
- Le.initialize({
177
+ setup(r) {
178
+ const h = r, b = w(), p = w(), d = w(!1), S = w(""), C = w(""), A = w(!1), x = w(""), _ = w(!1), m = w(1), V = w({ x: 0, y: 0 }), L = w(!1), P = w({ x: 0, y: 0 }), T = w(1), W = w({ x: 0, y: 0 }), B = w(!1), pe = w({ x: 0, y: 0 }), I = w(""), te = w(/* @__PURE__ */ new Map()), le = w(!1);
179
+ let ye = 0;
180
+ je.initialize({
180
181
  startOnLoad: !1,
181
182
  theme: "default",
182
183
  securityLevel: "loose",
183
184
  fontFamily: "inherit"
184
185
  });
185
- const ge = (e) => {
186
- const t = e.renderer.rules.fence;
187
- e.renderer.rules.fence = (l, g, r, s, v) => {
188
- const w = l[g], P = w.content.trim();
189
- return (w.info ? w.info.trim() : "") === "mermaid" ? (ae++, `<div class="mermaid-container"><pre class="mermaid" data-mermaid-id="${`mermaid-${Date.now()}-${ae}`}">${P}</pre></div>`) : t(l, g, r, s, v);
186
+ const xe = (e) => {
187
+ const a = e.renderer.rules.fence;
188
+ e.renderer.rules.fence = (s, n, c, l, y) => {
189
+ const M = s[n], j = M.content.trim();
190
+ return (M.info ? M.info.trim() : "") === "mermaid" ? (ye++, `<div class="mermaid-container"><pre class="mermaid" data-mermaid-id="${`mermaid-${Date.now()}-${ye}`}">${j}</pre></div>`) : a(s, n, c, l, y);
190
191
  };
191
- }, j = new lt({
192
+ }, N = new gt({
192
193
  html: !0,
193
194
  // 允许HTML标签,以便markdown渲染的标签能正常显示
194
195
  xhtmlOut: !1,
@@ -202,685 +203,737 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
202
203
  // 启用一些语言中性的替换 + 引号美化
203
204
  quotes: `""''`,
204
205
  // 双引号和单引号的替换对,中文环境
205
- highlight: function(e, t) {
206
- return t && t.trim() ? `<pre class="hljs language-${t}"><code>${((g) => g.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"))(e)}</code></pre>` : `<pre class="hljs"><code>${e}</code></pre>`;
206
+ highlight: function(e, a) {
207
+ return a && a.trim() ? `<pre class="hljs language-${a}"><code>${((n) => n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"))(e)}</code></pre>` : `<pre class="hljs"><code>${e}</code></pre>`;
207
208
  }
208
- }), ie = j.renderer.rules.image || function(e, t, l, g, r) {
209
- return r.renderToken(e, t, l);
209
+ }), U = N.renderer.rules.image || function(e, a, s, n, c) {
210
+ return c.renderToken(e, a, s);
210
211
  };
211
- j.renderer.rules.image = function(e, t, l, g, r) {
212
- const s = e[t], v = s.attrIndex("src");
213
- if (v >= 0) {
214
- const w = s.attrs[v][1], A = "img-" + ((W) => {
215
- let R = 0;
216
- for (let Y = 0; Y < W.length; Y++) {
217
- const V = W.charCodeAt(Y);
218
- R = (R << 5) - R + V, R = R & R;
212
+ N.renderer.rules.image = function(e, a, s, n, c) {
213
+ const l = e[a], y = l.attrIndex("src");
214
+ if (y >= 0) {
215
+ const M = l.attrs[y][1], D = "img-" + ((G) => {
216
+ let F = 0;
217
+ for (let Z = 0; Z < G.length; Z++) {
218
+ const ve = G.charCodeAt(Z);
219
+ F = (F << 5) - F + ve, F = F & F;
219
220
  }
220
- return Math.abs(R).toString(36);
221
- })(w);
222
- s.attrSet("id", A), s.attrSet("data-image-id", A), s.attrSet("key", A), s.attrSet("loading", "eager"), s.attrSet("decoding", "async"), s.attrSet("fetchpriority", "high"), s.attrSet("data-src", w), s.attrSet("data-cached", "true");
221
+ return Math.abs(F).toString(36);
222
+ })(M);
223
+ l.attrSet("id", D), l.attrSet("data-image-id", D), l.attrSet("key", D), l.attrSet("loading", "eager"), l.attrSet("decoding", "async"), l.attrSet("fetchpriority", "high"), l.attrSet("data-src", M), l.attrSet("data-cached", "true");
223
224
  }
224
- return ie(e, t, l, g, r);
225
- }, j.use(ot, {
225
+ return U(e, a, s, n, c);
226
+ }, N.use(ht, {
226
227
  throwOnError: !1,
227
228
  errorColor: "#cc0000"
228
- }), j.use(ge);
229
- const pe = (e) => {
230
- const t = e.match(/```[\w]*\n/g), l = e.match(/\n```/g), g = (t == null ? void 0 : t.length) || 0, r = (l == null ? void 0 : l.length) || 0;
231
- return g > r && (e += "\n```"), e;
232
- }, he = (e) => {
229
+ }), N.use(xe);
230
+ const Me = (e) => {
231
+ const a = e.match(/```[\w]*\n/g), s = e.match(/\n```/g), n = (a == null ? void 0 : a.length) || 0, c = (s == null ? void 0 : s.length) || 0;
232
+ return n > c && (e += "\n```"), e;
233
+ }, we = (e) => {
233
234
  if (!e) return "";
234
235
  e = e.replace(/;;\s*$/g, ""), e = e.replace(/;;\s*$/g, "");
235
- const t = /^```(?:markdown|md)\s*\n([\s\S]*?)\n```$/, l = e.match(t);
236
- if (l)
237
- e = l[1];
236
+ const a = /^```(?:markdown|md)\s*\n([\s\S]*?)\n```$/, s = e.match(a);
237
+ if (s)
238
+ e = s[1];
238
239
  else {
239
- const g = /^```\s*\n([\s\S]*?)\n```$/, r = e.match(g);
240
- if (r) {
241
- const s = r[1];
242
- (/^#{1,6}\s/.test(s) || /^\*{1,2}[^*]+\*{1,2}/.test(s) || /^[-*+]\s/.test(s) || /^\d+\.\s/.test(s) || /!\[.*?\]\(.*?\)/.test(s) || /\[.*?\]\(.*?\)/.test(s) || /^\|.+\|/.test(s) || /^\|[\s-:]+\|/m.test(s)) && (e = s);
240
+ const n = /^```\s*\n([\s\S]*?)\n```$/, c = e.match(n);
241
+ if (c) {
242
+ const l = c[1];
243
+ (/^#{1,6}\s/.test(l) || /^\*{1,2}[^*]+\*{1,2}/.test(l) || /^[-*+]\s/.test(l) || /^\d+\.\s/.test(l) || /!\[.*?\]\(.*?\)/.test(l) || /\[.*?\]\(.*?\)/.test(l) || /^\|.+\|/.test(l) || /^\|[\s-:]+\|/m.test(l)) && (e = l);
243
244
  }
244
245
  }
245
- if (p.isStreaming) {
246
- const g = /^```(?:markdown|md)?\s*\n/;
247
- if (g.test(e)) {
248
- const s = e.replace(g, "");
249
- (/^#{1,6}\s/.test(s) || /^\|.+\|/.test(s) || /^\|[\s-:]+\|/m.test(s) || /!\[.*?\]\(.*?\)/.test(s) || /\[.*?\]\(.*?\)/.test(s)) && (e = e.replace(g, ""));
246
+ if (h.isStreaming) {
247
+ const n = /^```(?:markdown|md)?\s*\n/;
248
+ if (n.test(e)) {
249
+ const l = e.replace(n, "");
250
+ (/^#{1,6}\s/.test(l) || /^\|.+\|/.test(l) || /^\|[\s-:]+\|/m.test(l) || /!\[.*?\]\(.*?\)/.test(l) || /\[.*?\]\(.*?\)/.test(l)) && (e = e.replace(n, ""));
250
251
  }
251
- if (/^```(?:markdown|md)?\s*\n/.test(p.content)) {
252
- const s = /\n```\s*$/;
253
- s.test(e) && (e = e.replace(s, ""));
252
+ if (/^```(?:markdown|md)?\s*\n/.test(h.content)) {
253
+ const l = /\n```\s*$/;
254
+ l.test(e) && (e = e.replace(l, ""));
254
255
  }
255
256
  }
256
257
  return e = e.replace(
257
258
  /```(?:markdown|md)\s*\n([\s\S]*?)\n```/g,
258
- (g, r) => r
259
- ), p.isStreaming && (e = pe(e)), e;
260
- }, ye = (e) => {
259
+ (n, c) => c
260
+ ), h.isStreaming && (e = Me(e)), e;
261
+ }, re = (e) => {
261
262
  if (!e.includes("<img"))
262
263
  return e;
263
- const t = /<img[^>]*?src="([^"]*)"[^>]*?>/g;
264
- let l, g = e;
265
- const r = [];
266
- for (; (l = t.exec(e)) !== null; ) {
267
- const s = l[0], v = l[1];
268
- if (q.value.has(v)) {
269
- const w = q.value.get(v);
270
- s !== w && r.push({ original: s, cached: w });
264
+ const a = /<img[^>]*?src="([^"]*)"[^>]*?>/g;
265
+ let s, n = e;
266
+ const c = [];
267
+ for (; (s = a.exec(e)) !== null; ) {
268
+ const l = s[0], y = s[1];
269
+ if (te.value.has(y)) {
270
+ const M = te.value.get(y);
271
+ l !== M && c.push({ original: l, cached: M });
271
272
  } else
272
- q.value.set(v, s);
273
+ te.value.set(y, l);
273
274
  }
274
- for (const { original: s, cached: v } of r)
275
- g = g.replace(s, v);
276
- return g;
277
- }, we = (e) => {
278
- if (!i.value)
275
+ for (const { original: l, cached: y } of c)
276
+ n = n.replace(l, y);
277
+ return n;
278
+ }, ie = (e) => {
279
+ if (!p.value)
279
280
  return;
280
- const t = i.value;
281
- if (!p.isStreaming || t.children.length === 0) {
282
- t.innerHTML = e, p.isStreaming || de(() => {
283
- xe(), y();
281
+ const a = p.value, s = /* @__PURE__ */ new Map();
282
+ if (h.isStreaming && a.children.length > 0 && a.querySelectorAll("img[data-image-id]").forEach((n) => {
283
+ const c = n.getAttribute("data-image-id");
284
+ c && s.set(c, n);
285
+ }), a.innerHTML = e, !h.isStreaming) {
286
+ ne(() => {
287
+ t(), g();
284
288
  });
285
289
  return;
286
290
  }
287
- const l = document.createElement("div");
288
- l.innerHTML = e;
289
- const g = /* @__PURE__ */ new Map();
290
- t.querySelectorAll("img[data-image-id]").forEach((s) => {
291
- const v = s.getAttribute("data-image-id");
292
- v && g.set(v, s);
293
- }), l.querySelectorAll("img[data-image-id]").forEach((s) => {
294
- const v = s.getAttribute("data-image-id");
295
- if (v && g.has(v)) {
296
- const w = g.get(v);
297
- s.parentNode && s.parentNode.replaceChild(w, s);
291
+ s.size > 0 && a.querySelectorAll("img[data-image-id]").forEach((n) => {
292
+ const c = n.getAttribute("data-image-id");
293
+ if (c && s.has(c)) {
294
+ const l = s.get(c);
295
+ n.parentNode && l !== n && n.parentNode.replaceChild(l, n);
298
296
  }
299
297
  });
300
- const r = document.createDocumentFragment();
301
- for (; l.firstChild; )
302
- r.appendChild(l.firstChild);
303
- t.innerHTML = "", t.appendChild(r);
304
- }, K = () => {
298
+ }, J = () => {
305
299
  try {
306
- if (!p.content) {
307
- se.value = "", i.value && (i.value.innerHTML = ""), p.isStreaming || q.value.clear();
300
+ if (!h.content) {
301
+ I.value = "", p.value && (p.value.innerHTML = ""), h.isStreaming || te.value.clear();
308
302
  return;
309
303
  }
310
- const e = he(p.content);
311
- let t = j.render(e);
312
- p.isStreaming && t.includes("<img") && (t = ye(t)), t !== se.value && (se.value = t, we(t)), p.isStreaming || q.value.clear();
304
+ if (document.hidden && h.isStreaming) {
305
+ le.value = !0;
306
+ return;
307
+ }
308
+ const e = we(h.content);
309
+ let a = N.render(e);
310
+ h.isStreaming && a.includes("<img") && (a = re(a)), a !== I.value && (I.value = a, ie(a)), h.isStreaming || te.value.clear();
313
311
  } catch (e) {
314
- console.error("Markdown rendering error:", e), i.value && (i.value.innerHTML = `<pre style="white-space: pre-wrap; word-wrap: break-word;">${p.content}</pre>`);
312
+ console.error("Markdown rendering error:", e), p.value && (p.value.innerHTML = `<pre style="white-space: pre-wrap; word-wrap: break-word;">${h.content}</pre>`);
315
313
  }
316
314
  };
317
- J(() => p.content, K), J(
318
- () => p.isStreaming,
319
- (e, t) => {
320
- t && !e && de(() => {
321
- K();
315
+ ge(() => h.content, J), ge(
316
+ () => h.isStreaming,
317
+ (e, a) => {
318
+ a && !e && ne(() => {
319
+ J();
322
320
  });
323
321
  }
324
322
  );
325
- const m = () => {
323
+ const ce = () => {
324
+ !document.hidden && le.value && (le.value = !1, ne(() => {
325
+ J();
326
+ }));
327
+ };
328
+ document.addEventListener("visibilitychange", ce), Ue(() => {
329
+ document.removeEventListener("visibilitychange", ce);
330
+ });
331
+ const i = () => {
326
332
  _.value = window.innerWidth < 768;
327
- }, h = (e) => {
328
- let t = e;
329
- return t = t.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1"), [
333
+ }, v = (e) => {
334
+ let a = e;
335
+ return a = a.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1"), [
330
336
  /([A-Za-z0-9_]+)\[([^\]]*[\u4e00-\u9fa5]+[^\]]*)\]/g,
331
337
  /([A-Za-z0-9_]+)\(([^)]*[\u4e00-\u9fa5]+[^)]*)\)/g,
332
338
  /([A-Za-z0-9_]+)\{([^}]*[\u4e00-\u9fa5]+[^}]*)\}/g
333
- ].forEach((g) => {
334
- t = t.replace(g, (r, s, v) => {
335
- if (v.startsWith('"') && v.endsWith('"'))
336
- return r;
337
- let w = v.replace(/^["']+|["']+$/g, "").replace(/["]/g, '\\"');
338
- return r.includes("[") ? `${s}["${w}"]` : r.includes("(") ? `${s}("${w}")` : r.includes("{") ? `${s}{"${w}"}` : r;
339
+ ].forEach((n) => {
340
+ a = a.replace(n, (c, l, y) => {
341
+ if (y.startsWith('"') && y.endsWith('"'))
342
+ return c;
343
+ let M = y.replace(/^["']+|["']+$/g, "").replace(/["]/g, '\\"');
344
+ return c.includes("[") ? `${l}["${M}"]` : c.includes("(") ? `${l}("${M}")` : c.includes("{") ? `${l}{"${M}"}` : c;
339
345
  });
340
- }), t;
341
- }, y = async () => {
342
- var t, l;
343
- if (p.isStreaming || (await de(), !k.value)) return;
344
- const e = k.value.querySelectorAll(".mermaid");
346
+ }), a;
347
+ }, g = async () => {
348
+ var a, s;
349
+ if (h.isStreaming || (await ne(), !b.value)) return;
350
+ const e = b.value.querySelectorAll(".mermaid");
345
351
  if (e.length !== 0)
346
- for (const g of Array.from(e)) {
347
- const r = g;
348
- let s = (t = r.textContent) == null ? void 0 : t.trim();
349
- if (s && r.getAttribute("data-processed") !== "true")
352
+ for (const n of Array.from(e)) {
353
+ const c = n;
354
+ let l = (a = c.textContent) == null ? void 0 : a.trim();
355
+ if (l && c.getAttribute("data-processed") !== "true")
350
356
  try {
351
- r.setAttribute("data-processed", "true"), s = h(s);
352
- const v = r.getAttribute("data-mermaid-id") || `mermaid-${Date.now()}-${Math.random()}`, { svg: w } = await Le.render(v, s), P = r.parentElement;
353
- if (P) {
354
- const A = document.createElement("div");
355
- A.className = "mermaid-svg", A.innerHTML = w, A.setAttribute("data-mermaid-svg", "true"), A.style.cursor = "pointer", A.title = "Click to zoom", A.addEventListener("click", (W) => {
356
- W.preventDefault(), W.stopPropagation(), T.value = w, S.value = 1, C.value = { x: 0, y: 0 }, x.value = !0;
357
- }), P.replaceChild(A, r);
357
+ c.setAttribute("data-processed", "true"), l = v(l);
358
+ const y = c.getAttribute("data-mermaid-id") || `mermaid-${Date.now()}-${Math.random()}`, { svg: M } = await je.render(y, l), j = c.parentElement;
359
+ if (j) {
360
+ const D = document.createElement("div");
361
+ D.className = "mermaid-svg", D.innerHTML = M, D.setAttribute("data-mermaid-svg", "true"), D.style.cursor = "pointer", D.title = "Click to zoom", D.addEventListener("click", (G) => {
362
+ G.preventDefault(), G.stopPropagation(), x.value = M, T.value = 1, W.value = { x: 0, y: 0 }, A.value = !0;
363
+ }), j.replaceChild(D, c);
358
364
  }
359
- } catch (v) {
360
- console.error("Mermaid render failure:", v);
361
- const w = document.createElement("div");
362
- w.className = "mermaid-error", w.textContent = `Mermaid render error: ${v}`, (l = r.parentElement) == null || l.replaceChild(w, r);
365
+ } catch (y) {
366
+ console.error("Mermaid render failure:", y);
367
+ const M = document.createElement("div");
368
+ M.className = "mermaid-error", M.textContent = `Mermaid render error: ${y}`, (s = c.parentElement) == null || s.replaceChild(M, c);
363
369
  }
364
370
  }
365
- }, B = (e) => {
371
+ }, $ = (e) => {
366
372
  e.preventDefault(), e.stopPropagation();
367
- const t = e.target;
368
- $.value = t.src, E.value = t.alt || "Image Preview", c.value = 1, d.value = { x: 0, y: 0 }, z.value = !0;
369
- }, O = () => {
370
- c.value <= 1 && (d.value = { x: 0, y: 0 });
371
- }, Ue = () => {
372
- c.value = Math.min(c.value + 1, 10), O();
373
- }, Ye = () => {
374
- c.value = Math.max(c.value - 1, 0.5), O();
375
- }, _e = () => {
376
- c.value = 1, d.value = { x: 0, y: 0 };
377
- }, We = () => {
378
- c.value <= 1 && (z.value = !1);
379
- }, Oe = (e) => {
373
+ const a = e.target;
374
+ S.value = a.src, C.value = a.alt || "Image Preview", m.value = 1, V.value = { x: 0, y: 0 }, d.value = !0;
375
+ }, H = () => {
376
+ m.value <= 1 && (V.value = { x: 0, y: 0 });
377
+ }, ue = () => {
378
+ m.value = Math.min(m.value + 1, 10), H();
379
+ }, ae = () => {
380
+ m.value = Math.max(m.value - 1, 0.5), H();
381
+ }, de = () => {
382
+ m.value = 1, V.value = { x: 0, y: 0 };
383
+ }, Se = () => {
384
+ m.value <= 1 && (d.value = !1);
385
+ }, me = (e) => {
380
386
  e.preventDefault();
381
- const t = e.deltaY > 0 ? -0.5 : 0.5, l = Math.max(0.5, Math.min(10, c.value + t));
382
- c.value = l, O();
383
- }, Xe = (e) => {
384
- var s;
385
- if (c.value <= 1) return;
386
- e.preventDefault(), M.value = !0, L.value = {
387
- x: e.clientX - d.value.x,
388
- y: e.clientY - d.value.y
387
+ const a = e.deltaY > 0 ? -0.5 : 0.5, s = Math.max(0.5, Math.min(10, m.value + a));
388
+ m.value = s, H();
389
+ }, ee = (e) => {
390
+ var l;
391
+ if (m.value <= 1) return;
392
+ e.preventDefault(), L.value = !0, P.value = {
393
+ x: e.clientX - V.value.x,
394
+ y: e.clientY - V.value.y
389
395
  };
390
- const t = e.target, l = (s = t.parentElement) == null ? void 0 : s.getBoundingClientRect(), g = (v) => {
391
- if (!M.value || !l) return;
392
- let w = v.clientX - L.value.x, P = v.clientY - L.value.y;
393
- const A = t.offsetWidth, W = t.offsetHeight, R = A * c.value, Y = W * c.value, V = 0.3, ke = l.width * (1 - V - 0.5) - R / 2, re = R / 2 - l.width * (1 - V - 0.5), ce = l.height * (1 - V - 0.5) - Y / 2, ne = Y / 2 - l.height * (1 - V - 0.5);
394
- R > l.width ? w = Math.max(ke, Math.min(re, w)) : w = 0, Y > l.height ? P = Math.max(ce, Math.min(ne, P)) : P = 0, d.value = { x: w, y: P };
395
- }, r = () => {
396
- M.value = !1, document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", r);
396
+ const a = e.target, s = (l = a.parentElement) == null ? void 0 : l.getBoundingClientRect(), n = (y) => {
397
+ if (!L.value || !s) return;
398
+ let M = y.clientX - P.value.x, j = y.clientY - P.value.y;
399
+ const D = a.offsetWidth, G = a.offsetHeight, F = D * m.value, Z = G * m.value, ve = 0.3, De = s.width * (1 - ve - 0.5) - F / 2, Le = F / 2 - s.width * (1 - ve - 0.5), ze = s.height * (1 - ve - 0.5) - Z / 2, $e = Z / 2 - s.height * (1 - ve - 0.5);
400
+ F > s.width ? M = Math.max(De, Math.min(Le, M)) : M = 0, Z > s.height ? j = Math.max(ze, Math.min($e, j)) : j = 0, V.value = { x: M, y: j };
401
+ }, c = () => {
402
+ L.value = !1, document.removeEventListener("mousemove", n), document.removeEventListener("mouseup", c);
397
403
  };
398
- document.addEventListener("mousemove", g), document.addEventListener("mouseup", r);
399
- }, Ve = (e) => {
400
- var P;
404
+ document.addEventListener("mousemove", n), document.addEventListener("mouseup", c);
405
+ }, O = (e) => {
406
+ var j;
401
407
  if (e.touches.length !== 1) return;
402
- const t = e.touches[0], l = t.clientX, g = t.clientY;
403
- if (c.value <= 1) return;
404
- M.value = !0, L.value = {
405
- x: l - d.value.x,
406
- y: g - d.value.y
408
+ const a = e.touches[0], s = a.clientX, n = a.clientY;
409
+ if (m.value <= 1) return;
410
+ L.value = !0, P.value = {
411
+ x: s - V.value.x,
412
+ y: n - V.value.y
407
413
  };
408
- const r = e.target, s = (P = r.parentElement) == null ? void 0 : P.getBoundingClientRect(), v = (A) => {
409
- if (!M.value || A.touches.length !== 1 || !s)
414
+ const c = e.target, l = (j = c.parentElement) == null ? void 0 : j.getBoundingClientRect(), y = (D) => {
415
+ if (!L.value || D.touches.length !== 1 || !l)
410
416
  return;
411
- const W = A.touches[0];
412
- let R = W.clientX - L.value.x, Y = W.clientY - L.value.y;
413
- const V = r.offsetWidth, ke = r.offsetHeight, re = V * c.value, ce = ke * c.value, ne = 0.3, Je = s.width * (1 - ne - 0.5) - re / 2, Qe = re / 2 - s.width * (1 - ne - 0.5), et = s.height * (1 - ne - 0.5) - ce / 2, tt = ce / 2 - s.height * (1 - ne - 0.5);
414
- re > s.width ? R = Math.max(Je, Math.min(Qe, R)) : R = 0, ce > s.height ? Y = Math.max(et, Math.min(tt, Y)) : Y = 0, d.value = { x: R, y: Y };
415
- }, w = () => {
416
- M.value = !1, document.removeEventListener("touchmove", v), document.removeEventListener("touchend", w);
417
+ const G = D.touches[0];
418
+ let F = G.clientX - P.value.x, Z = G.clientY - P.value.y;
419
+ const ve = c.offsetWidth, De = c.offsetHeight, Le = ve * m.value, ze = De * m.value, $e = 0.3, Qe = l.width * (1 - $e - 0.5) - Le / 2, et = Le / 2 - l.width * (1 - $e - 0.5), tt = l.height * (1 - $e - 0.5) - ze / 2, at = ze / 2 - l.height * (1 - $e - 0.5);
420
+ Le > l.width ? F = Math.max(Qe, Math.min(et, F)) : F = 0, ze > l.height ? Z = Math.max(tt, Math.min(at, Z)) : Z = 0, V.value = { x: F, y: Z };
421
+ }, M = () => {
422
+ L.value = !1, document.removeEventListener("touchmove", y), document.removeEventListener("touchend", M);
417
423
  };
418
- document.addEventListener("touchmove", v, { passive: !1 }), document.addEventListener("touchend", w);
419
- }, Ze = () => {
420
- S.value = Math.min(S.value + 1, 10);
421
- }, qe = () => {
422
- S.value = Math.max(S.value - 1, 0.5);
423
- }, $e = () => {
424
- S.value = 1, C.value = { x: 0, y: 0 };
425
- }, je = (e) => {
424
+ document.addEventListener("touchmove", y, { passive: !1 }), document.addEventListener("touchend", M);
425
+ }, q = () => {
426
+ T.value = Math.min(T.value + 1, 10);
427
+ }, ke = () => {
428
+ T.value = Math.max(T.value - 1, 0.5);
429
+ }, se = () => {
430
+ T.value = 1, W.value = { x: 0, y: 0 };
431
+ }, Ce = (e) => {
426
432
  e.preventDefault();
427
- const t = e.deltaY > 0 ? -0.5 : 0.5;
428
- S.value = Math.max(0.5, Math.min(10, S.value + t));
429
- }, Ke = (e) => {
430
- var s, v;
431
- if (S.value <= 1) return;
432
- e.preventDefault(), ee.value = !0, te.value = {
433
- x: e.clientX - C.value.x,
434
- y: e.clientY - C.value.y
433
+ const a = e.deltaY > 0 ? -0.5 : 0.5;
434
+ T.value = Math.max(0.5, Math.min(10, T.value + a));
435
+ }, Be = (e) => {
436
+ var l, y;
437
+ if (T.value <= 1) return;
438
+ e.preventDefault(), B.value = !0, pe.value = {
439
+ x: e.clientX - W.value.x,
440
+ y: e.clientY - W.value.y
435
441
  };
436
- const l = (v = (s = e.target.closest(".mermaid-preview-content")) == null ? void 0 : s.parentElement) == null ? void 0 : v.getBoundingClientRect(), g = (w) => {
437
- if (!ee.value || !l) return;
438
- let P = w.clientX - te.value.x, A = w.clientY - te.value.y;
439
- C.value = { x: P, y: A };
440
- }, r = () => {
441
- ee.value = !1, document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", r);
442
+ const s = (y = (l = e.target.closest(".mermaid-preview-content")) == null ? void 0 : l.parentElement) == null ? void 0 : y.getBoundingClientRect(), n = (M) => {
443
+ if (!B.value || !s) return;
444
+ let j = M.clientX - pe.value.x, D = M.clientY - pe.value.y;
445
+ W.value = { x: j, y: D };
446
+ }, c = () => {
447
+ B.value = !1, document.removeEventListener("mousemove", n), document.removeEventListener("mouseup", c);
442
448
  };
443
- document.addEventListener("mousemove", g), document.addEventListener("mouseup", r);
444
- }, Ge = (e) => {
445
- }, xe = () => {
446
- p.isStreaming || de(() => {
447
- if (!k.value) return;
448
- k.value.querySelectorAll(
449
+ document.addEventListener("mousemove", n), document.addEventListener("mouseup", c);
450
+ }, Ae = (e) => {
451
+ }, t = () => {
452
+ h.isStreaming || ne(() => {
453
+ if (!b.value) return;
454
+ b.value.querySelectorAll(
449
455
  ".markdown-content img"
450
- ).forEach((t) => {
451
- const l = t;
452
- l.getAttribute("data-processed") !== "true" && (l.setAttribute("data-processed", "true"), l.style.cursor = "pointer", l.addEventListener("click", B));
456
+ ).forEach((a) => {
457
+ const s = a;
458
+ s.getAttribute("data-processed") !== "true" && (s.setAttribute("data-processed", "true"), s.style.cursor = "pointer", s.addEventListener("click", $));
453
459
  });
454
460
  });
455
461
  };
456
- return De(() => {
457
- m(), window.addEventListener("resize", m), K(), xe(), y();
458
- }), Re(() => {
459
- k.value && k.value.querySelectorAll(
462
+ return Ve(() => {
463
+ i(), window.addEventListener("resize", i), J(), t(), g();
464
+ }), Ue(() => {
465
+ b.value && b.value.querySelectorAll(
460
466
  ".markdown-content img"
461
- ).forEach((t) => {
462
- t.removeEventListener("click", B);
467
+ ).forEach((a) => {
468
+ a.removeEventListener("click", $);
463
469
  });
464
- }), (e, t) => (o(), u("div", {
470
+ }), (e, a) => (u(), f("div", {
465
471
  class: "markdown-message",
466
472
  ref_key: "markdownContainer",
467
- ref: k
473
+ ref: b
468
474
  }, [
469
- a("div", {
475
+ o("div", {
470
476
  ref_key: "markdownContent",
471
- ref: i,
477
+ ref: p,
472
478
  class: "markdown-content"
473
479
  }, null, 512),
474
- f(Me, {
475
- visible: z.value,
476
- "onUpdate:visible": t[2] || (t[2] = (l) => z.value = l),
480
+ k(Pe, {
481
+ visible: d.value,
482
+ "onUpdate:visible": a[2] || (a[2] = (s) => d.value = s),
477
483
  width: _.value ? "95vw" : "80vw",
478
484
  fullscreen: _.value,
479
485
  class: "image-preview-dialog",
480
486
  "close-on-click-modal": !1,
481
487
  "append-to-body": ""
482
488
  }, {
483
- default: H(() => [
484
- a("div", {
489
+ default: R(() => [
490
+ o("div", {
485
491
  class: "image-preview-container",
486
- onClick: t[1] || (t[1] = Z((l) => z.value = !1, ["self"]))
492
+ onClick: a[1] || (a[1] = fe((s) => d.value = !1, ["self"]))
487
493
  }, [
488
- a("img", {
489
- src: $.value,
490
- alt: E.value,
494
+ o("img", {
495
+ src: S.value,
496
+ alt: C.value,
491
497
  class: "preview-image",
492
- style: ve({
493
- transform: `translate(${d.value.x}px, ${d.value.y}px) scale(${c.value})`
498
+ style: Ie({
499
+ transform: `translate(${V.value.x}px, ${V.value.y}px) scale(${m.value})`
494
500
  }),
495
- onWheel: Z(Oe, ["prevent"]),
496
- onDblclick: _e,
497
- onMousedown: Xe,
498
- onTouchstart: Z(Ve, ["prevent"]),
499
- onClick: We
500
- }, null, 44, yt),
501
- a("div", wt, [
502
- a("div", kt, [
503
- f(N, {
501
+ onWheel: fe(me, ["prevent"]),
502
+ onDblclick: de,
503
+ onMousedown: ee,
504
+ onTouchstart: fe(O, ["prevent"]),
505
+ onClick: Se
506
+ }, null, 44, xt),
507
+ o("div", Lt, [
508
+ o("div", zt, [
509
+ k(Y, {
504
510
  size: "small",
505
- onClick: Ye,
506
- disabled: c.value <= 0.5
511
+ onClick: ae,
512
+ disabled: m.value <= 0.5
507
513
  }, {
508
- default: H(() => [
509
- f(I(Ie))
514
+ default: R(() => [
515
+ k(E(Ne))
510
516
  ]),
511
517
  _: 1
512
518
  }, 8, ["disabled"]),
513
- f(N, {
519
+ k(Y, {
514
520
  size: "small",
515
- onClick: _e
521
+ onClick: de
516
522
  }, {
517
- default: H(() => [
518
- ze(F(Math.round(c.value * 100)) + "% ", 1)
523
+ default: R(() => [
524
+ We(K(Math.round(m.value * 100)) + "% ", 1)
519
525
  ]),
520
526
  _: 1
521
527
  }),
522
- f(N, {
528
+ k(Y, {
523
529
  size: "small",
524
- onClick: Ue,
525
- disabled: c.value >= 10
530
+ onClick: ue,
531
+ disabled: m.value >= 10
526
532
  }, {
527
- default: H(() => [
528
- f(I(Ee))
533
+ default: R(() => [
534
+ k(E(Ye))
529
535
  ]),
530
536
  _: 1
531
537
  }, 8, ["disabled"])
532
538
  ]),
533
- f(N, {
539
+ k(Y, {
534
540
  size: "small",
535
- onClick: t[0] || (t[0] = (l) => z.value = !1),
541
+ onClick: a[0] || (a[0] = (s) => d.value = !1),
536
542
  type: "danger"
537
543
  }, {
538
- default: H(() => [
539
- f(I(fe))
544
+ default: R(() => [
545
+ k(E(He))
540
546
  ]),
541
547
  _: 1
542
548
  })
543
549
  ]),
544
- _.value ? (o(), u("div", Mt, "双击重置 · 轻触关闭")) : D("", !0)
550
+ _.value ? (u(), f("div", Et, "双击重置 · 轻触关闭")) : z("", !0)
545
551
  ])
546
552
  ]),
547
553
  _: 1
548
554
  }, 8, ["visible", "width", "fullscreen"]),
549
- f(Me, {
550
- visible: x.value,
551
- "onUpdate:visible": t[5] || (t[5] = (l) => x.value = l),
555
+ k(Pe, {
556
+ visible: A.value,
557
+ "onUpdate:visible": a[5] || (a[5] = (s) => A.value = s),
552
558
  width: _.value ? "95vw" : "90vw",
553
559
  fullscreen: _.value,
554
560
  class: "mermaid-preview-dialog",
555
561
  "close-on-click-modal": !1,
556
562
  "append-to-body": ""
557
563
  }, {
558
- default: H(() => [
559
- a("div", {
564
+ default: R(() => [
565
+ o("div", {
560
566
  class: "mermaid-preview-container",
561
- onClick: t[4] || (t[4] = Z((l) => x.value = !1, ["self"]))
567
+ onClick: a[4] || (a[4] = fe((s) => A.value = !1, ["self"]))
562
568
  }, [
563
- a("div", {
569
+ o("div", {
564
570
  class: "mermaid-preview-content",
565
- innerHTML: T.value,
566
- style: ve({
567
- transform: `translate(${C.value.x}px, ${C.value.y}px) scale(${S.value})`
571
+ innerHTML: x.value,
572
+ style: Ie({
573
+ transform: `translate(${W.value.x}px, ${W.value.y}px) scale(${T.value})`
568
574
  }),
569
- onWheel: Z(je, ["prevent"]),
570
- onDblclick: $e,
571
- onMousedown: Ke,
572
- onTouchstart: Z(Ge, ["prevent"])
573
- }, null, 44, Ct),
574
- a("div", bt, [
575
- a("div", _t, [
576
- f(N, {
575
+ onWheel: fe(Ce, ["prevent"]),
576
+ onDblclick: se,
577
+ onMousedown: Be,
578
+ onTouchstart: fe(Ae, ["prevent"])
579
+ }, null, 44, Tt),
580
+ o("div", Bt, [
581
+ o("div", Ut, [
582
+ k(Y, {
577
583
  size: "small",
578
- onClick: qe,
579
- disabled: S.value <= 0.5
584
+ onClick: ke,
585
+ disabled: T.value <= 0.5
580
586
  }, {
581
- default: H(() => [
582
- f(I(Ie))
587
+ default: R(() => [
588
+ k(E(Ne))
583
589
  ]),
584
590
  _: 1
585
591
  }, 8, ["disabled"]),
586
- f(N, {
592
+ k(Y, {
587
593
  size: "small",
588
- onClick: $e
594
+ onClick: se
589
595
  }, {
590
- default: H(() => [
591
- ze(F(Math.round(S.value * 100)) + "% ", 1)
596
+ default: R(() => [
597
+ We(K(Math.round(T.value * 100)) + "% ", 1)
592
598
  ]),
593
599
  _: 1
594
600
  }),
595
- f(N, {
601
+ k(Y, {
596
602
  size: "small",
597
- onClick: Ze,
598
- disabled: S.value >= 10
603
+ onClick: q,
604
+ disabled: T.value >= 10
599
605
  }, {
600
- default: H(() => [
601
- f(I(Ee))
606
+ default: R(() => [
607
+ k(E(Ye))
602
608
  ]),
603
609
  _: 1
604
610
  }, 8, ["disabled"])
605
611
  ]),
606
- f(N, {
612
+ k(Y, {
607
613
  size: "small",
608
- onClick: t[3] || (t[3] = (l) => x.value = !1),
614
+ onClick: a[3] || (a[3] = (s) => A.value = !1),
609
615
  type: "danger"
610
616
  }, {
611
- default: H(() => [
612
- f(I(fe))
617
+ default: R(() => [
618
+ k(E(He))
613
619
  ]),
614
620
  _: 1
615
621
  })
616
622
  ]),
617
- _.value ? (o(), u("div", $t, "双击重置 · 轻触关闭")) : D("", !0)
623
+ _.value ? (u(), f("div", Ht, "双击重置 · 轻触关闭")) : z("", !0)
618
624
  ])
619
625
  ]),
620
626
  _: 1
621
627
  }, 8, ["visible", "width", "fullscreen"])
622
628
  ], 512));
623
629
  }
624
- }), Fe = /* @__PURE__ */ oe(xt, [["__scopeId", "data-v-e47faf67"]]), St = {
630
+ }), Je = /* @__PURE__ */ _e(Dt, [["__scopeId", "data-v-6028683a"]]), Pt = {
625
631
  key: 0,
626
632
  class: "text-content"
627
- }, zt = {
633
+ }, Rt = {
628
634
  key: 1,
629
635
  class: "images-content"
630
- }, Lt = ["onClick"], Et = ["src", "alt", "onError"], It = {
636
+ }, Vt = ["onClick"], Ot = ["src", "alt", "onError"], Ft = {
631
637
  key: 0,
632
638
  class: "more-images"
633
- }, Bt = {
639
+ }, Wt = {
634
640
  key: 2,
635
- class: "attachments-content"
636
- }, At = { class: "file-icon-wrapper" }, Tt = { class: "attachment-info" }, Ht = { class: "attachment-name" }, Dt = { class: "attachment-size" }, Rt = {
637
- key: 3,
638
641
  class: "files-content"
639
- }, Pt = ["onClick"], Ft = { class: "file-icon-wrapper-small" }, Nt = { class: "file-info" }, Ut = { class: "file-name" }, Yt = { class: "file-type" }, Wt = { class: "file-actions" }, Ot = {
640
- key: 4,
642
+ }, jt = ["onClick"], Yt = { class: "file-icon-wrapper-small" }, Nt = ["title"], Xt = { class: "file-name" }, qt = { class: "file-type" }, Zt = { class: "file-actions" }, Kt = {
643
+ key: 3,
641
644
  class: "audio-content"
642
- }, Xt = { class: "audio-player" }, Vt = { class: "audio-info" }, Zt = { class: "audio-progress" }, qt = { class: "progress-bar" }, jt = { class: "audio-time" }, Kt = { class: "image-preview-container" }, Gt = ["src"], Jt = {
645
+ }, Jt = { class: "audio-player" }, Gt = { class: "audio-info" }, Qt = { class: "audio-progress" }, ea = { class: "progress-bar" }, ta = { class: "audio-time" }, aa = { class: "image-preview-container" }, sa = ["src"], na = {
643
646
  key: 0,
644
647
  class: "image-nav"
645
- }, Qt = { class: "image-counter" }, es = /* @__PURE__ */ Q({
648
+ }, oa = { class: "image-counter" }, la = /* @__PURE__ */ be({
646
649
  __name: "MultimodalMessage",
647
650
  props: {
648
651
  message: {},
649
652
  isUser: { type: Boolean, default: !1 },
650
- isStreaming: { type: Boolean, default: !1 }
653
+ isStreaming: { type: Boolean, default: !1 },
654
+ apiBaseUrl: { default: "" },
655
+ onDownload: {}
651
656
  },
652
- setup(n) {
653
- const p = n, k = X(() => {
657
+ setup(r) {
658
+ const h = r, b = Q(() => {
654
659
  try {
655
- return p.message.metadata ? JSON.parse(p.message.metadata) : {};
660
+ return h.message.metadata ? JSON.parse(h.message.metadata) : {};
656
661
  } catch {
657
662
  return {};
658
663
  }
659
- }), i = X(
660
- () => k.value.imageUrls || []
661
- ), z = X(() => k.value.fileUrls || []), $ = X(() => k.value.audioUrl), E = X(() => p.message.attachments && p.message.attachments.length > 0 ? p.message.attachments : k.value.attachments && Array.isArray(k.value.attachments) ? k.value.attachments : []), x = b(!1), T = b(""), _ = b(0), c = b(!1), d = b(!1), M = b(0), L = b(0), S = X(() => L.value > 0 ? M.value / L.value * 100 : 0);
662
- let C = null;
663
- const ee = (m, h) => {
664
- T.value = m, _.value = h, x.value = !0;
665
- }, te = () => {
666
- _.value > 0 && (_.value--, T.value = i.value[_.value]);
667
- }, se = () => {
668
- _.value < i.value.length - 1 && (_.value++, T.value = i.value[_.value]);
669
- }, q = (m, h) => {
670
- console.error("Image load failed:", h);
671
- const y = m.target;
672
- y.style.display = "none";
673
- }, ae = (m) => {
664
+ }), p = Q(
665
+ () => b.value.imageUrls || []
666
+ ), d = Q(() => b.value.audioUrl), S = w(/* @__PURE__ */ new Set()), C = Q(
667
+ () => b.value.fileUrls || []
668
+ ), A = Q(() => C.value), x = Q(() => h.message.attachments && h.message.attachments.length > 0 ? h.message.attachments : b.value.attachments && Array.isArray(b.value.attachments) ? b.value.attachments : []), _ = Q(() => {
669
+ const i = [];
670
+ return x.value && x.value.length > 0 ? x.value.forEach((v) => {
671
+ var $, H;
672
+ (($ = v.type) == null ? void 0 : $.startsWith("image/")) || ((H = v.name) == null ? void 0 : H.match(/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i)) || i.push({
673
+ url: v.url || v.download_url || v.file_url || "",
674
+ name: v.original_name || v.name || "Unknown File",
675
+ type: U(v.original_name || v.name || "Unknown File")
676
+ });
677
+ }) : A.value && A.value.length > 0 && A.value.forEach((v) => {
678
+ i.push({
679
+ url: v,
680
+ name: N(v),
681
+ type: U(v)
682
+ });
683
+ }), i;
684
+ }), m = w(!1), V = w(""), L = w(0), P = w(!1), T = w(!1), W = w(0), B = w(0), pe = Q(() => B.value > 0 ? W.value / B.value * 100 : 0);
685
+ let I = null;
686
+ const te = (i, v) => {
687
+ V.value = i, L.value = v, m.value = !0;
688
+ }, le = () => {
689
+ L.value > 0 && (L.value--, V.value = p.value[L.value]);
690
+ }, ye = () => {
691
+ L.value < p.value.length - 1 && (L.value++, V.value = p.value[L.value]);
692
+ }, xe = (i, v) => {
693
+ console.error("Image load failed:", v);
694
+ const g = i.target;
695
+ g.style.display = "none";
696
+ }, N = (i) => {
697
+ if (!i) return "Unknown File";
698
+ if (!i.includes("/"))
699
+ return decodeURIComponent(i) || "Unknown File";
674
700
  try {
675
- const y = new URL(m).pathname, B = y.substring(y.lastIndexOf("/") + 1);
676
- return decodeURIComponent(B) || "Unknown File";
701
+ const v = i.lastIndexOf("/"), g = v >= 0 ? i.substring(v + 1) : i;
702
+ return decodeURIComponent(g) || "Unknown File";
677
703
  } catch {
678
704
  return "Unknown File";
679
705
  }
680
- }, ge = (m) => {
681
- var B;
682
- return ((B = ae(m).split(".").pop()) == null ? void 0 : B.toUpperCase()) || "FILE";
683
- }, j = (m) => {
684
- const h = ge(m).toLowerCase();
685
- ["jpg", "jpeg", "png", "gif", "webp", "pdf"].includes(h) ? window.open(m, "_blank") : ie(m);
686
- }, ie = (m) => {
706
+ }, U = (i) => {
707
+ var $;
708
+ return (($ = N(i).split(".").pop()) == null ? void 0 : $.toUpperCase()) || "FILE";
709
+ }, Me = (i, v) => {
710
+ re(i, v);
711
+ }, we = (i) => !i || i.startsWith("http://") || i.startsWith("https://") || i.startsWith("blob:") ? i : (h.apiBaseUrl ? h.apiBaseUrl.replace(/\/$/, "") : "") + (i.startsWith("/") ? i : "/" + i), re = async (i, v) => {
687
712
  try {
688
- const h = document.createElement("a");
689
- h.href = m, h.download = ae(m), h.target = "_blank", document.body.appendChild(h), h.click(), document.body.removeChild(h);
690
- } catch (h) {
691
- console.error("Download failed:", h), alert("下载失败");
713
+ const g = we(i);
714
+ if (console.log("正在下载文件...", g), h.onDownload && (S.value = /* @__PURE__ */ new Set([...S.value, i]), await h.onDownload(i, v) !== !1)) {
715
+ const q = new Set(S.value);
716
+ q.delete(i), S.value = q;
717
+ return;
718
+ }
719
+ S.value = /* @__PURE__ */ new Set([...S.value, i]);
720
+ const $ = localStorage.getItem("token"), H = {};
721
+ if ($ && (H.Authorization = $.startsWith("Bearer ") ? $ : `Bearer ${$}`), typeof window < "u" && typeof window.plus < "u") {
722
+ const O = window.plus, q = O.downloader.createDownload(
723
+ g,
724
+ {
725
+ method: "GET",
726
+ filename: "_downloads/" + (v || N(i))
727
+ },
728
+ (ke, se) => {
729
+ const Ce = new Set(S.value);
730
+ Ce.delete(i), S.value = Ce, se === 200 || se === 206 ? O.runtime.openFile(ke.filename) : console.error("App 环境原生下载失败, status:", se);
731
+ }
732
+ );
733
+ H.Authorization && q.setRequestHeader(
734
+ "Authorization",
735
+ H.Authorization
736
+ ), q.start();
737
+ return;
738
+ }
739
+ const ue = await fetch(g, { headers: H });
740
+ if (!ue.ok)
741
+ throw new Error(`下载失败: ${ue.status}`);
742
+ let ae = v;
743
+ const de = ue.headers.get("Content-Disposition");
744
+ if (de) {
745
+ const O = de.match(/filename\*=UTF-8''(.+)/i);
746
+ if (O)
747
+ ae = decodeURIComponent(O[1]);
748
+ else {
749
+ const q = de.match(/filename="?([^";\n]+)"?/i);
750
+ q && (ae = q[1]);
751
+ }
752
+ }
753
+ const Se = await ue.blob(), me = URL.createObjectURL(Se), ee = document.createElement("a");
754
+ ee.href = me, ee.download = ae || v || N(i), document.body.appendChild(ee), ee.click(), document.body.removeChild(ee), URL.revokeObjectURL(me);
755
+ } catch (g) {
756
+ console.error("下载文件失败:", g);
757
+ } finally {
758
+ const g = new Set(S.value);
759
+ g.delete(i), S.value = g;
692
760
  }
693
- }, pe = async () => {
694
- if ($.value)
761
+ }, ie = async () => {
762
+ if (d.value)
695
763
  try {
696
- C || (C = new Audio(), C.src = $.value, C.addEventListener("loadedmetadata", () => {
697
- L.value = (C == null ? void 0 : C.duration) || 0;
698
- }), C.addEventListener("timeupdate", () => {
699
- M.value = (C == null ? void 0 : C.currentTime) || 0;
700
- }), C.addEventListener("ended", () => {
701
- c.value = !1, M.value = 0;
702
- }), C.addEventListener("error", (m) => {
703
- console.error("Audio playback error:", m), d.value = !1, c.value = !1;
704
- })), c.value ? (C.pause(), c.value = !1) : (d.value = !0, await C.play(), c.value = !0, d.value = !1);
705
- } catch (m) {
706
- console.error("Audio playback failed:", m), d.value = !1, c.value = !1;
764
+ I || (I = new Audio(), I.src = we(d.value), I.addEventListener("loadedmetadata", () => {
765
+ B.value = (I == null ? void 0 : I.duration) || 0;
766
+ }), I.addEventListener("timeupdate", () => {
767
+ W.value = (I == null ? void 0 : I.currentTime) || 0;
768
+ }), I.addEventListener("ended", () => {
769
+ P.value = !1, W.value = 0;
770
+ }), I.addEventListener("error", (i) => {
771
+ console.error("Audio playback error:", i), T.value = !1, P.value = !1;
772
+ })), P.value ? (I.pause(), P.value = !1) : (T.value = !0, await I.play(), P.value = !0, T.value = !1);
773
+ } catch (i) {
774
+ console.error("Audio playback failed:", i), T.value = !1, P.value = !1;
707
775
  }
708
- }, he = (m) => {
709
- const h = Math.floor(m / 60), y = Math.floor(m % 60);
710
- return `${h}:${y.toString().padStart(2, "0")}`;
711
- }, ye = (m) => {
712
- if (m === 0) return "0 B";
713
- const h = 1024, y = ["B", "KB", "MB", "GB"], B = Math.floor(Math.log(m) / Math.log(h));
714
- return (m / Math.pow(h, B)).toFixed(2) + y[B];
715
- }, we = (m) => {
716
- var y;
717
- return ((y = m.split(".").pop()) == null ? void 0 : y.toUpperCase()) || "FILE";
718
- }, K = (m) => {
719
- x.value && (m.key === "ArrowLeft" ? te() : m.key === "ArrowRight" ? se() : m.key === "Escape" && (x.value = !1));
776
+ }, J = (i) => {
777
+ const v = Math.floor(i / 60), g = Math.floor(i % 60);
778
+ return `${v}:${g.toString().padStart(2, "0")}`;
779
+ }, ce = (i) => {
780
+ m.value && (i.key === "ArrowLeft" ? le() : i.key === "ArrowRight" ? ye() : i.key === "Escape" && (m.value = !1));
720
781
  };
721
- return J(x, (m) => {
722
- m ? document.addEventListener("keydown", K) : document.removeEventListener("keydown", K);
723
- }), Re(() => {
724
- C && (C.pause(), C = null), document.removeEventListener("keydown", K);
725
- }), (m, h) => (o(), u("div", {
726
- class: le(["multimodal-message", { "is-user": n.isUser, "is-assistant": !n.isUser }])
782
+ return ge(m, (i) => {
783
+ i ? document.addEventListener("keydown", ce) : document.removeEventListener("keydown", ce);
784
+ }), Ue(() => {
785
+ I && (I.pause(), I = null), document.removeEventListener("keydown", ce);
786
+ }), (i, v) => (u(), f("div", {
787
+ class: he(["multimodal-message", { "is-user": r.isUser, "is-assistant": !r.isUser }])
727
788
  }, [
728
- n.message.content ? (o(), u("div", St, [
729
- f(Fe, {
730
- content: n.message.content,
731
- "is-streaming": n.isStreaming
789
+ r.message.content ? (u(), f("div", Pt, [
790
+ k(Je, {
791
+ content: r.message.content,
792
+ "is-streaming": r.isStreaming
732
793
  }, null, 8, ["content", "is-streaming"])
733
- ])) : D("", !0),
734
- i.value && i.value.length > 0 ? (o(), u("div", zt, [
735
- a("div", {
736
- class: le(["images-grid", `grid-${Math.min(i.value.length, 4)}`])
794
+ ])) : z("", !0),
795
+ p.value && p.value.length > 0 ? (u(), f("div", Rt, [
796
+ o("div", {
797
+ class: he(["images-grid", `grid-${Math.min(p.value.length, 4)}`])
737
798
  }, [
738
- (o(!0), u(ue, null, me(i.value.slice(0, 4), (y, B) => (o(), u("div", {
739
- key: B,
799
+ (u(!0), f(Ee, null, Te(p.value.slice(0, 4), (g, $) => (u(), f("div", {
800
+ key: $,
740
801
  class: "image-item",
741
- onClick: (O) => ee(y, B)
802
+ onClick: (H) => te(g, $)
742
803
  }, [
743
- a("img", {
744
- src: y,
745
- alt: `图片 ${B + 1}`,
746
- onError: (O) => q(O, y),
804
+ o("img", {
805
+ src: g,
806
+ alt: `图片 ${$ + 1}`,
807
+ onError: (H) => xe(H, g),
747
808
  loading: "lazy"
748
- }, null, 40, Et),
749
- B === 3 && i.value.length > 4 ? (o(), u("div", It, " +" + F(i.value.length - 4), 1)) : D("", !0)
750
- ], 8, Lt))), 128))
809
+ }, null, 40, Ot),
810
+ $ === 3 && p.value.length > 4 ? (u(), f("div", Ft, " +" + K(p.value.length - 4), 1)) : z("", !0)
811
+ ], 8, Vt))), 128))
751
812
  ], 2)
752
- ])) : D("", !0),
753
- E.value && E.value.length > 0 ? (o(), u("div", Bt, [
754
- (o(!0), u(ue, null, me(E.value, (y, B) => (o(), u("div", {
755
- key: B,
756
- class: "attachment-item"
757
- }, [
758
- a("div", At, [
759
- f(I(Be), { class: "file-icon" })
760
- ]),
761
- a("div", Tt, [
762
- a("span", Ht, F(y.name), 1),
763
- a("span", Dt, F(we(y.name)) + "   " + F(ye(y.size)), 1)
764
- ])
765
- ]))), 128))
766
- ])) : D("", !0),
767
- z.value && z.value.length > 0 ? (o(), u("div", Rt, [
768
- (o(!0), u(ue, null, me(z.value, (y, B) => (o(), u("div", {
769
- key: B,
813
+ ])) : z("", !0),
814
+ _.value && _.value.length > 0 ? (u(), f("div", Wt, [
815
+ (u(!0), f(Ee, null, Te(_.value, (g, $) => (u(), f("div", {
816
+ key: $,
770
817
  class: "file-item",
771
- onClick: (O) => j(y)
818
+ onClick: (H) => Me(g.url, g.name)
772
819
  }, [
773
- a("div", Ft, [
774
- f(I(Be), { class: "file-icon" })
820
+ o("div", Yt, [
821
+ k(E(Mt), { class: "file-icon" })
775
822
  ]),
776
- a("div", Nt, [
777
- a("span", Ut, F(ae(y)), 1),
778
- a("span", Yt, F(ge(y)), 1)
779
- ]),
780
- a("div", Wt, [
781
- f(N, {
823
+ o("div", {
824
+ class: "file-info",
825
+ title: g.name
826
+ }, [
827
+ o("span", Xt, K(g.name), 1),
828
+ o("span", qt, K(g.type), 1)
829
+ ], 8, Nt),
830
+ o("div", Zt, [
831
+ k(Y, {
782
832
  size: "small",
783
833
  type: "text",
784
- onClick: Z((O) => ie(y), ["stop"])
834
+ disabled: S.value.has(g.url),
835
+ onClick: fe((H) => re(g.url, g.name), ["stop"])
785
836
  }, {
786
- default: H(() => [
787
- f(I(Ae))
837
+ default: R(() => [
838
+ k(E(Xe), {
839
+ class: he({ "icon-spin": S.value.has(g.url) })
840
+ }, null, 8, ["class"])
788
841
  ]),
789
- _: 1
790
- }, 8, ["onClick"])
842
+ _: 2
843
+ }, 1032, ["disabled", "onClick"])
791
844
  ])
792
- ], 8, Pt))), 128))
793
- ])) : D("", !0),
794
- $.value ? (o(), u("div", Ot, [
795
- a("div", Xt, [
796
- f(N, {
797
- onClick: pe,
798
- loading: d.value,
845
+ ], 8, jt))), 128))
846
+ ])) : z("", !0),
847
+ d.value ? (u(), f("div", Kt, [
848
+ o("div", Jt, [
849
+ k(Y, {
850
+ onClick: ie,
851
+ loading: T.value,
799
852
  circle: "",
800
853
  size: "small",
801
854
  class: "play-btn"
802
855
  }, {
803
- default: H(() => [
804
- (o(), G(Pe(c.value ? I(vt) : I(mt))))
856
+ default: R(() => [
857
+ (u(), oe(Ke(P.value ? E(Ct) : E(St))))
805
858
  ]),
806
859
  _: 1
807
860
  }, 8, ["loading"]),
808
- a("div", Vt, [
809
- a("div", Zt, [
810
- a("div", qt, [
811
- a("div", {
861
+ o("div", Gt, [
862
+ o("div", Qt, [
863
+ o("div", ea, [
864
+ o("div", {
812
865
  class: "progress-fill",
813
- style: ve({ width: S.value + "%" })
866
+ style: Ie({ width: pe.value + "%" })
814
867
  }, null, 4)
815
868
  ])
816
869
  ]),
817
- a("div", jt, [
818
- a("span", null, F(he(M.value)), 1),
819
- h[4] || (h[4] = a("span", null, "/", -1)),
820
- a("span", null, F(he(L.value)), 1)
870
+ o("div", ta, [
871
+ o("span", null, K(J(W.value)), 1),
872
+ v[4] || (v[4] = o("span", null, "/", -1)),
873
+ o("span", null, K(J(B.value)), 1)
821
874
  ])
822
875
  ]),
823
- f(N, {
824
- onClick: h[0] || (h[0] = (y) => ie($.value)),
876
+ k(Y, {
877
+ onClick: v[0] || (v[0] = (g) => re(d.value)),
825
878
  size: "small",
826
879
  type: "text",
827
880
  class: "download-btn"
828
881
  }, {
829
- default: H(() => [
830
- f(I(Ae))
882
+ default: R(() => [
883
+ k(E(Xe))
831
884
  ]),
832
885
  _: 1
833
886
  })
834
887
  ])
835
- ])) : D("", !0),
836
- f(Me, {
837
- visible: x.value,
838
- "onUpdate:visible": h[3] || (h[3] = (y) => x.value = y),
888
+ ])) : z("", !0),
889
+ k(Pe, {
890
+ visible: m.value,
891
+ "onUpdate:visible": v[3] || (v[3] = (g) => m.value = g),
839
892
  width: "90%",
840
893
  "show-close": !1,
841
894
  "append-to-body": "",
842
895
  class: "image-preview-dialog-wrapper"
843
896
  }, {
844
- default: H(() => [
845
- a("div", Kt, [
846
- a("img", {
847
- src: T.value,
897
+ default: R(() => [
898
+ o("div", aa, [
899
+ o("img", {
900
+ src: V.value,
848
901
  alt: "预览图片",
849
902
  class: "preview-image",
850
- onClick: h[1] || (h[1] = (y) => x.value = !1)
851
- }, null, 8, Gt),
852
- i.value && i.value.length > 1 ? (o(), u("div", Jt, [
853
- f(N, {
854
- onClick: te,
855
- disabled: _.value === 0,
903
+ onClick: v[1] || (v[1] = (g) => m.value = !1)
904
+ }, null, 8, sa),
905
+ p.value && p.value.length > 1 ? (u(), f("div", na, [
906
+ k(Y, {
907
+ onClick: le,
908
+ disabled: L.value === 0,
856
909
  circle: "",
857
910
  class: "nav-btn"
858
911
  }, {
859
- default: H(() => [
860
- f(I(gt))
912
+ default: R(() => [
913
+ k(E(At))
861
914
  ]),
862
915
  _: 1
863
916
  }, 8, ["disabled"]),
864
- a("span", Qt, F(_.value + 1) + " / " + F(i.value.length), 1),
865
- f(N, {
866
- onClick: se,
867
- disabled: _.value === i.value.length - 1,
917
+ o("span", oa, K(L.value + 1) + " / " + K(p.value.length), 1),
918
+ k(Y, {
919
+ onClick: ye,
920
+ disabled: L.value === p.value.length - 1,
868
921
  circle: "",
869
922
  class: "nav-btn"
870
923
  }, {
871
- default: H(() => [
872
- f(I(ht))
924
+ default: R(() => [
925
+ k(E($t))
873
926
  ]),
874
927
  _: 1
875
928
  }, 8, ["disabled"])
876
- ])) : D("", !0),
877
- f(N, {
878
- onClick: h[2] || (h[2] = (y) => x.value = !1),
929
+ ])) : z("", !0),
930
+ k(Y, {
931
+ onClick: v[2] || (v[2] = (g) => m.value = !1),
879
932
  class: "close-btn",
880
933
  circle: ""
881
934
  }, {
882
- default: H(() => [
883
- f(I(fe))
935
+ default: R(() => [
936
+ k(E(He))
884
937
  ]),
885
938
  _: 1
886
939
  })
@@ -890,104 +943,115 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
890
943
  }, 8, ["visible"])
891
944
  ], 2));
892
945
  }
893
- }), Ce = /* @__PURE__ */ oe(es, [["__scopeId", "data-v-7795fedb"]]), ts = {
946
+ }), Re = /* @__PURE__ */ _e(la, [["__scopeId", "data-v-3f270644"]]), ra = {
894
947
  key: 0,
895
948
  class: "agent-steps"
896
- }, ss = { class: "steps-indicator" }, as = {
949
+ }, ia = { class: "steps-indicator" }, ca = {
897
950
  key: 0,
898
951
  class: "icon-running"
899
- }, ns = {
952
+ }, ua = {
900
953
  key: 1,
901
954
  class: "icon-completed"
902
- }, ls = { class: "steps-summary" }, os = { class: "icon-chevron" }, is = { class: "steps-list" }, rs = { class: "step-icon" }, cs = {
955
+ }, da = { class: "steps-summary" }, ma = { class: "icon-chevron" }, va = { class: "steps-list" }, fa = { class: "step-icon" }, ga = {
903
956
  key: 3,
904
957
  class: "icon-dot"
905
- }, ds = { class: "step-name" }, us = /* @__PURE__ */ Q({
958
+ }, ha = { class: "step-name" }, pa = /* @__PURE__ */ be({
906
959
  __name: "AgentSteps",
907
960
  props: {
908
961
  steps: {}
909
962
  },
910
963
  emits: ["resize"],
911
- setup(n, { emit: p }) {
912
- const k = n, i = b(!0), z = p, $ = () => {
913
- i.value = !i.value, setTimeout(() => {
914
- z("resize");
964
+ setup(r, { emit: h }) {
965
+ const b = r, p = w(!0), d = h, S = () => {
966
+ p.value = !p.value, setTimeout(() => {
967
+ d("resize");
915
968
  }, 300);
916
- }, E = X(
917
- () => k.steps.some((T) => T.status === "running")
918
- ), x = X(() => {
919
- const T = k.steps.find((c) => c.status === "running");
920
- if (T)
921
- return `正在${T.displayName}...`;
922
- const _ = k.steps.filter(
923
- (c) => c.status === "completed"
969
+ }, C = Q(
970
+ () => b.steps.some((x) => x.status === "running")
971
+ ), A = Q(() => {
972
+ const x = b.steps.find((m) => m.status === "running");
973
+ if (x)
974
+ return `正在${x.displayName}...`;
975
+ const _ = b.steps.filter(
976
+ (m) => m.status === "completed"
924
977
  ).length;
925
- return _ === k.steps.length ? "处理完成" : `已完成 ${_}/${k.steps.length} 个步骤`;
978
+ return _ === b.steps.length ? "处理完成" : `已完成 ${_}/${b.steps.length} 个步骤`;
926
979
  });
927
- return (T, _) => n.steps.length > 0 ? (o(), u("div", ts, [
928
- a("div", {
980
+ return (x, _) => r.steps.length > 0 ? (u(), f("div", ra, [
981
+ o("div", {
929
982
  class: "steps-header",
930
- onClick: $
983
+ onClick: S
931
984
  }, [
932
- a("div", ss, [
933
- E.value ? (o(), u("div", as, [
934
- f(I(Te))
935
- ])) : (o(), u("div", ns, [
936
- f(I(He))
985
+ o("div", ia, [
986
+ C.value ? (u(), f("div", ca, [
987
+ k(E(qe))
988
+ ])) : (u(), f("div", ua, [
989
+ k(E(Ze))
937
990
  ]))
938
991
  ]),
939
- a("span", ls, F(x.value), 1),
940
- a("div", os, [
941
- (o(), G(Pe(i.value ? I(ft) : I(pt))))
992
+ o("span", da, K(A.value), 1),
993
+ o("div", ma, [
994
+ (u(), oe(Ke(p.value ? E(It) : E(_t))))
942
995
  ])
943
996
  ]),
944
- at(a("div", is, [
945
- (o(!0), u(ue, null, me(n.steps, (c) => (o(), u("div", {
946
- key: c.name,
947
- class: le(["step-item", {
948
- "is-running": c.status === "running",
949
- "is-completed": c.status === "completed",
950
- "is-error": c.status === "error"
997
+ nt(o("div", va, [
998
+ (u(!0), f(Ee, null, Te(r.steps, (m) => (u(), f("div", {
999
+ key: m.name,
1000
+ class: he(["step-item", {
1001
+ "is-running": m.status === "running",
1002
+ "is-completed": m.status === "completed",
1003
+ "is-error": m.status === "error"
951
1004
  }])
952
1005
  }, [
953
- a("div", rs, [
954
- c.status === "running" ? (o(), G(I(Te), {
1006
+ o("div", fa, [
1007
+ m.status === "running" ? (u(), oe(E(qe), {
955
1008
  key: 0,
956
1009
  class: "icon-spin"
957
- })) : c.status === "completed" ? (o(), G(I(He), { key: 1 })) : c.status === "error" ? (o(), G(I(fe), { key: 2 })) : (o(), u("div", cs))
1010
+ })) : m.status === "completed" ? (u(), oe(E(Ze), { key: 1 })) : m.status === "error" ? (u(), oe(E(He), { key: 2 })) : (u(), f("div", ga))
958
1011
  ]),
959
- a("span", ds, F(c.displayName), 1)
1012
+ o("span", ha, K(m.displayName), 1)
960
1013
  ], 2))), 128))
961
1014
  ], 512), [
962
- [nt, i.value]
1015
+ [ot, p.value]
963
1016
  ])
964
- ])) : D("", !0);
1017
+ ])) : z("", !0);
965
1018
  }
966
- }), Ne = /* @__PURE__ */ oe(us, [["__scopeId", "data-v-181f5844"]]), ms = { class: "chat-message-list-root" }, vs = {
1019
+ }), Ge = /* @__PURE__ */ _e(pa, [["__scopeId", "data-v-181f5844"]]), ya = { class: "chat-message-list-root" }, wa = {
967
1020
  key: 0,
968
1021
  class: "bg-grid"
969
- }, gs = {
1022
+ }, ka = {
970
1023
  key: 0,
971
1024
  class: "welcome-screen"
972
- }, hs = { class: "welcome-content" }, fs = { class: "welcome-logo" }, ps = ["src"], ys = {
1025
+ }, ba = { class: "welcome-content" }, Ma = { class: "welcome-logo" }, Sa = ["src"], Ca = {
973
1026
  key: 1,
974
1027
  class: "default-logo"
975
- }, ws = { class: "welcome-title" }, ks = {
1028
+ }, Aa = { class: "welcome-title" }, $a = {
976
1029
  key: 1,
977
1030
  class: "messages-container"
978
- }, Ms = {
1031
+ }, Ia = {
979
1032
  key: 0,
980
- class: "message-bubble user-bubble"
981
- }, Cs = {
1033
+ class: "user-message-wrapper"
1034
+ }, _a = { class: "message-bubble user-bubble" }, xa = {
1035
+ key: 0,
1036
+ class: "message-actions user-actions"
1037
+ }, La = ["onClick"], za = {
982
1038
  key: 1,
983
1039
  class: "message-content assistant-content"
984
- }, bs = { class: "message-bubble assistant-bubble" }, _s = {
1040
+ }, Ea = { class: "message-bubble assistant-bubble" }, Ta = {
1041
+ key: 1,
1042
+ class: "a2ui-card-skeleton",
1043
+ "aria-hidden": "true"
1044
+ }, Ba = {
985
1045
  key: 1,
986
1046
  class: "message-actions"
987
- }, $s = ["onClick"], xs = {
1047
+ }, Ua = ["onClick"], Ha = {
988
1048
  key: 0,
989
1049
  class: "message-row message-assistant"
990
- }, Ss = /* @__PURE__ */ Q({
1050
+ }, Da = {
1051
+ key: 0,
1052
+ class: "loading-ring",
1053
+ viewBox: "0 0 36 36"
1054
+ }, Pa = /* @__PURE__ */ be({
991
1055
  __name: "ChatMessageList",
992
1056
  props: {
993
1057
  messages: { default: () => [] },
@@ -1001,173 +1065,441 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
1001
1065
  autoScroll: { type: Boolean, default: !0 },
1002
1066
  contentPaddingTop: { default: "80px" },
1003
1067
  contentPaddingBottom: { default: "140px" },
1004
- showBackground: { type: Boolean, default: !0 }
1068
+ showBackground: { type: Boolean, default: !0 },
1069
+ apiBaseUrl: { default: "" },
1070
+ enableA2UI: { type: Boolean, default: !0 },
1071
+ autoProvideA2UI: { type: Boolean, default: !0 },
1072
+ hideA2UIRawContent: { type: Boolean, default: !0 },
1073
+ showA2UISkeleton: { type: Boolean, default: !0 },
1074
+ a2uiActionHandler: {}
1005
1075
  },
1006
- emits: ["copy", "scroll", "scroll-bottom"],
1007
- setup(n, { expose: p, emit: k }) {
1008
- const i = n, z = k, $ = b(null), E = b(!1), x = async (d = "smooth") => {
1009
- await de(), $.value && $.value.scrollTo({
1010
- top: $.value.scrollHeight,
1011
- behavior: d
1012
- });
1013
- }, T = (d) => {
1014
- z("scroll", d);
1015
- const M = d.target;
1016
- if (!M) return;
1017
- const { scrollTop: L, scrollHeight: S, clientHeight: C } = M;
1018
- S - L - C < 50 ? (E.value = !1, z("scroll-bottom")) : E.value = !0;
1076
+ emits: [
1077
+ "copy",
1078
+ "scroll",
1079
+ "scroll-bottom",
1080
+ "a2ui-action",
1081
+ "a2ui-error"
1082
+ ],
1083
+ setup(r, { expose: h, emit: b }) {
1084
+ const p = /* @__PURE__ */ new WeakSet(), d = r, S = b, C = w(null), A = w(!1), x = w(!0), _ = w({}), m = w({});
1085
+ (() => {
1086
+ var e;
1087
+ if (!d.autoProvideA2UI) return;
1088
+ try {
1089
+ dt();
1090
+ return;
1091
+ } catch {
1092
+ }
1093
+ const t = (e = it()) == null ? void 0 : e.appContext.app;
1094
+ !t || p.has(t) || (mt({
1095
+ app: t,
1096
+ catalog: ft,
1097
+ theme: vt
1098
+ }), p.add(t));
1099
+ })();
1100
+ const L = ct(), P = () => {
1101
+ if (!C.value) return !0;
1102
+ const { scrollTop: t, scrollHeight: e, clientHeight: a } = C.value;
1103
+ return e - t - a < 50;
1104
+ }, T = () => {
1105
+ x.value = P();
1106
+ }, W = (t) => {
1107
+ var a, s;
1108
+ return !t || typeof t != "object" || t.version !== "v0.9" || [
1109
+ t.createSurface,
1110
+ t.updateComponents,
1111
+ t.updateDataModel,
1112
+ t.deleteSurface
1113
+ ].filter(Boolean).length !== 1 ? !1 : t.createSurface ? pe(t.createSurface) : t.updateComponents ? xe(t.updateComponents) : t.updateDataModel ? typeof ((a = B(t.updateDataModel)) == null ? void 0 : a.surfaceId) == "string" : t.deleteSurface ? typeof ((s = B(t.deleteSurface)) == null ? void 0 : s.surfaceId) == "string" : !1;
1114
+ }, B = (t) => t && typeof t == "object" && !Array.isArray(t) ? t : null, pe = (t) => {
1115
+ const e = B(t);
1116
+ if (!e) return !1;
1117
+ const a = Object.keys(e);
1118
+ return typeof e.surfaceId == "string" && typeof e.catalogId == "string" && a.every((s) => s === "surfaceId" || s === "catalogId");
1119
+ }, I = (t) => Array.isArray(t) ? t.every((e) => {
1120
+ const a = B(e);
1121
+ return !!(a && typeof a.label == "string" && typeof a.value == "string");
1122
+ }) : !1, te = (t) => Array.isArray(t) && t.every((e) => typeof e == "string"), le = (t) => Array.isArray(t) ? t.every((e) => {
1123
+ const a = B(e);
1124
+ return !!(a && typeof a.label == "string" && typeof a.value == "string");
1125
+ }) : !1, ye = (t) => {
1126
+ const e = B(t);
1127
+ return !(!e || typeof e.id != "string" || typeof e.component != "string" || Object.prototype.hasOwnProperty.call(e, "props") || Object.prototype.hasOwnProperty.call(e, "componentType") || Object.prototype.hasOwnProperty.call(e, "component_type") || e.facts !== void 0 && !I(e.facts) || e.tags !== void 0 && !te(e.tags) || ["policyOptions", "audienceOptions", "detailOptions"].some(
1128
+ (s) => e[s] !== void 0 && !le(e[s])
1129
+ ));
1130
+ }, xe = (t) => {
1131
+ const e = B(t);
1132
+ return !e || typeof e.surfaceId != "string" || !Array.isArray(e.components) || e.components.length === 0 ? !1 : e.components.every(ye);
1133
+ }, N = (t) => {
1134
+ const e = t.trim();
1135
+ if (!e) return null;
1136
+ const a = e.match(/^```(?:json|a2ui|agui|ag-ui)?\s*([\s\S]*?)\s*```$/i), s = a ? a[1].trim() : e;
1137
+ if (!s.startsWith("{") && !s.startsWith("[")) return null;
1138
+ try {
1139
+ return JSON.parse(s);
1140
+ } catch {
1141
+ return null;
1142
+ }
1143
+ }, U = (t) => {
1144
+ if (!t) return [];
1145
+ if (typeof t == "string") {
1146
+ const s = N(t);
1147
+ return s ? U(s) : Array.from(
1148
+ t.matchAll(/```(?:agui|ag-ui|a2ui|json)\s*\n([\s\S]*?)\n```/gi)
1149
+ ).flatMap((n) => {
1150
+ const c = N(n[1]);
1151
+ return c ? U(c) : [];
1152
+ });
1153
+ }
1154
+ if (Array.isArray(t)) {
1155
+ const s = t.map((n) => B(n)).filter((n) => !!n);
1156
+ return s.length === t.length && s.every(W) ? s : [];
1157
+ }
1158
+ if (typeof t != "object") return [];
1159
+ const e = t;
1160
+ if (W(e)) return [e];
1161
+ const a = Me(e);
1162
+ return a.length > 0 ? a : [];
1163
+ }, Me = (t) => {
1164
+ if (!t || typeof t != "object") return [];
1165
+ if (Array.isArray(t)) {
1166
+ const a = t.map((s) => B(s)).filter((s) => !!s);
1167
+ return a.length !== t.length || !a.every(we) ? [] : a.flatMap(re);
1168
+ }
1169
+ const e = t;
1170
+ return e.protocol === "ag-ui" ? Me(e.aguiEvents || e.agui_events) : we(e) ? re(e) : [];
1171
+ }, we = (t) => {
1172
+ const e = String(t.type || "").toUpperCase();
1173
+ return e ? e === "STATE_SNAPSHOT" ? ie(t.state).length > 0 : e === "STATE_DELTA" ? ie(t.delta).length > 0 : !0 : !1;
1174
+ }, re = (t) => {
1175
+ const e = String(t.type || "").toUpperCase();
1176
+ return e === "STATE_SNAPSHOT" ? ie(t.state) : e === "STATE_DELTA" ? ie(t.delta) : [];
1177
+ }, ie = (t) => {
1178
+ const e = B(t);
1179
+ return e ? U(e.a2uiMessages) : [];
1180
+ }, J = (t) => [
1181
+ ...U(t.a2ui),
1182
+ ...U(t.a2uiMessage),
1183
+ ...U(t.a2uiMessages),
1184
+ ...U(t.a2ui_message),
1185
+ ...U(t.a2ui_messages),
1186
+ ...U(t.agui),
1187
+ ...U(t.aguiEvents),
1188
+ ...U(t.agui_events),
1189
+ ...U(t.metadata),
1190
+ ...U(t.content)
1191
+ ], ce = (t) => {
1192
+ var e, a, s, n;
1193
+ return ((e = t == null ? void 0 : t.createSurface) == null ? void 0 : e.surfaceId) || ((a = t == null ? void 0 : t.updateComponents) == null ? void 0 : a.surfaceId) || ((s = t == null ? void 0 : t.updateDataModel) == null ? void 0 : s.surfaceId) || ((n = t == null ? void 0 : t.deleteSurface) == null ? void 0 : n.surfaceId) || null;
1194
+ }, i = (t, e) => String(t.id || `index-${e}`), v = (t, e, a = !1) => {
1195
+ const s = { ...m.value }, n = { ..._.value }, c = a ? new Set(n[t] || []) : /* @__PURE__ */ new Set();
1196
+ for (const l of e) {
1197
+ const y = ce(l);
1198
+ y && (s[y] = t, c.add(y));
1199
+ }
1200
+ n[t] = Array.from(c), m.value = s, _.value = n;
1201
+ }, g = () => {
1202
+ if (L.clearSurfaces(), _.value = {}, m.value = {}, !d.enableA2UI) return;
1203
+ const t = [];
1204
+ if (d.messages.forEach((e, a) => {
1205
+ const s = J(e);
1206
+ if (s.length === 0) return;
1207
+ const n = i(e, a);
1208
+ v(n, s), t.push(...s);
1209
+ }), t.length !== 0)
1210
+ try {
1211
+ L.processMessages(t);
1212
+ } catch (e) {
1213
+ console.warn("[rt-chat-messages] A2UI payload render failed", e), S("a2ui-error", e);
1214
+ }
1215
+ }, $ = (t, e) => {
1216
+ if (!d.enableA2UI) return [];
1217
+ const a = i(t, e);
1218
+ return (_.value[a] || []).filter(
1219
+ (s) => m.value[s] === a
1220
+ );
1221
+ }, H = (t) => {
1222
+ const e = typeof t.content == "string" ? t.content.trimStart() : "";
1223
+ if (!e || J(t).length > 0) return !1;
1224
+ const a = e.match(/^```([^\s\n`]*)?/);
1225
+ if (!a) return !1;
1226
+ const s = (a[1] || "").toLowerCase();
1227
+ return s ? ["a", "ag", "agu", "agui", "ag-", "ag-u", "ag-ui", "a2", "a2u", "a2ui"].includes(s) : !1;
1228
+ }, ue = (t, e) => !!(d.enableA2UI && d.showA2UISkeleton && d.isStreaming && e === d.messages.length - 1 && $(t, e).length === 0 && H(t)), ae = (t) => !d.hideA2UIRawContent || t.attachments && t.attachments.length > 0 ? !0 : H(t) || !t.content ? !1 : J(t).length === 0, de = async (t) => {
1229
+ var a;
1230
+ const e = (a = t == null ? void 0 : t.message) == null ? void 0 : a.action;
1231
+ S("a2ui-action", e, t);
1232
+ try {
1233
+ const s = d.a2uiActionHandler ? await d.a2uiActionHandler(t) : [], n = U(s);
1234
+ if (n.length > 0) {
1235
+ const c = m.value[e == null ? void 0 : e.surfaceId];
1236
+ c && v(c, n, !0), L.processMessages(n), d.autoScroll && !A.value && (await ne(), O("smooth"));
1237
+ }
1238
+ t.resolve(n);
1239
+ } catch (s) {
1240
+ S("a2ui-error", s), t.reject(s instanceof Error ? s : new Error(String(s)));
1241
+ }
1019
1242
  };
1020
- J(
1021
- () => i.messages.length,
1022
- async (d, M) => {
1023
- d > (M || 0) && (E.value = !1), i.autoScroll && !E.value && x();
1243
+ let Se = 0, me = !1;
1244
+ const ee = () => {
1245
+ P() || (x.value = !1, A.value = !0);
1246
+ }, O = async (t = "smooth", e = !1) => {
1247
+ if (await ne(), C.value) {
1248
+ if (e && (A.value = !1), A.value) return;
1249
+ x.value = !0, me = !0, C.value.scrollTo({
1250
+ top: C.value.scrollHeight,
1251
+ behavior: t
1252
+ }), setTimeout(() => {
1253
+ me = !1;
1254
+ }, 50);
1024
1255
  }
1025
- ), J(
1026
- () => {
1027
- var d;
1028
- return (d = i.messages[i.messages.length - 1]) == null ? void 0 : d.content;
1029
- },
1030
- async (d, M) => {
1031
- if (i.isStreaming && i.autoScroll && !E.value) {
1032
- const L = (d == null ? void 0 : d.length) || 0, S = (M == null ? void 0 : M.length) || 0;
1033
- L > S && $.value && $.value.scrollTo({
1034
- top: $.value.scrollHeight,
1256
+ }, q = (t) => {
1257
+ if (S("scroll", t), !C.value) return;
1258
+ const e = C.value.scrollTop, a = e < Se;
1259
+ Se = e, !me && a && (A.value = !0, x.value = !1), P() && (x.value = !0, A.value = !1, S("scroll-bottom"));
1260
+ };
1261
+ ge(
1262
+ () => d.messages.length,
1263
+ async (t, e) => {
1264
+ t > (e || 0) && (A.value = !1, d.autoScroll && O("instant"));
1265
+ }
1266
+ ), ge(
1267
+ () => [d.messages, d.enableA2UI],
1268
+ g,
1269
+ { deep: !0, immediate: !0 }
1270
+ );
1271
+ let ke = null;
1272
+ ge(
1273
+ () => d.messages,
1274
+ async () => {
1275
+ if (!d.isStreaming || !d.autoScroll || A.value || document.hidden)
1276
+ return;
1277
+ const t = d.messages[d.messages.length - 1];
1278
+ !t || t.role !== "assistant" || (ke && cancelAnimationFrame(ke), ke = requestAnimationFrame(async () => {
1279
+ await ne(), C.value && !A.value && C.value.scrollTo({
1280
+ top: C.value.scrollHeight,
1035
1281
  behavior: "instant"
1036
1282
  });
1037
- }
1038
- }
1039
- ), J(
1040
- () => i.isTyping,
1041
- (d) => {
1042
- d && i.autoScroll && x();
1283
+ }));
1284
+ },
1285
+ { deep: !0 }
1286
+ ), ge(
1287
+ () => d.isTyping,
1288
+ (t) => {
1289
+ t && d.autoScroll && O("instant");
1043
1290
  }
1044
1291
  );
1045
- const _ = (d) => {
1046
- z("copy", d), navigator.clipboard && d.content && navigator.clipboard.writeText(d.content);
1292
+ const se = (t) => {
1293
+ S("copy", t), navigator.clipboard && t.content && navigator.clipboard.writeText(t.content);
1047
1294
  };
1048
- J(
1049
- () => i.agentSteps,
1295
+ ge(
1296
+ () => d.agentSteps,
1050
1297
  () => {
1051
- i.autoScroll && !E.value && x();
1298
+ d.autoScroll && !A.value && O();
1052
1299
  },
1053
1300
  { deep: !0 }
1054
1301
  );
1055
- const c = () => {
1056
- i.autoScroll && !E.value && x();
1302
+ const Ce = () => {
1303
+ d.autoScroll && !A.value && O();
1304
+ }, Be = () => {
1305
+ !document.hidden && d.isStreaming && d.autoScroll && !A.value && ne(() => {
1306
+ C.value && (C.value.scrollTo({
1307
+ top: C.value.scrollHeight,
1308
+ behavior: "instant"
1309
+ }), x.value = !0);
1310
+ });
1057
1311
  };
1058
- return p({
1059
- scrollToBottom: x,
1060
- containerRef: $
1061
- }), (d, M) => (o(), u("div", ms, [
1062
- n.showBackground ? (o(), u("div", vs)) : D("", !0),
1063
- a("div", {
1312
+ let Ae;
1313
+ return Ve(() => {
1314
+ T(), Ae = L.onEvent(de), document.addEventListener("visibilitychange", Be);
1315
+ }), Ue(() => {
1316
+ Ae == null || Ae(), document.removeEventListener("visibilitychange", Be);
1317
+ }), h({
1318
+ scrollToBottom: O,
1319
+ containerRef: C
1320
+ }), (t, e) => (u(), f("div", ya, [
1321
+ r.showBackground ? (u(), f("div", wa)) : z("", !0),
1322
+ o("div", {
1064
1323
  class: "chat-message-list",
1065
1324
  ref_key: "containerRef",
1066
- ref: $,
1067
- onScroll: T,
1068
- style: ve({
1069
- paddingTop: n.contentPaddingTop,
1070
- paddingBottom: n.contentPaddingBottom
1325
+ ref: C,
1326
+ onScroll: q,
1327
+ onWheel: ee,
1328
+ onTouchmove: ee,
1329
+ style: Ie({
1330
+ paddingTop: r.contentPaddingTop,
1331
+ paddingBottom: r.contentPaddingBottom
1071
1332
  })
1072
1333
  }, [
1073
- n.showWelcome && n.messages.length === 0 ? (o(), u("div", gs, [
1074
- be(d.$slots, "welcome", {}, () => [
1075
- a("div", hs, [
1076
- a("div", fs, [
1077
- n.appLogo ? (o(), u("img", {
1334
+ r.showWelcome && r.messages.length === 0 ? (u(), f("div", ka, [
1335
+ Oe(t.$slots, "welcome", {}, () => [
1336
+ o("div", ba, [
1337
+ o("div", Ma, [
1338
+ r.appLogo ? (u(), f("img", {
1078
1339
  key: 0,
1079
- src: n.appLogo,
1340
+ src: r.appLogo,
1080
1341
  alt: "Logo"
1081
- }, null, 8, ps)) : (o(), u("div", ys, [...M[0] || (M[0] = [
1082
- a("svg", {
1342
+ }, null, 8, Sa)) : (u(), f("div", Ca, [...e[1] || (e[1] = [
1343
+ o("svg", {
1083
1344
  viewBox: "0 0 1024 1024",
1084
1345
  width: "32",
1085
1346
  height: "32"
1086
1347
  }, [
1087
- a("path", {
1348
+ o("path", {
1088
1349
  fill: "currentColor",
1089
1350
  d: "M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"
1090
1351
  })
1091
1352
  ], -1)
1092
1353
  ])]))
1093
1354
  ]),
1094
- a("h2", ws, F(n.appName), 1),
1095
- M[1] || (M[1] = a("p", { class: "welcome-desc" }, "今天有什么可以帮您?", -1))
1355
+ o("h2", Aa, K(r.appName), 1),
1356
+ e[2] || (e[2] = o("p", { class: "welcome-desc" }, "今天有什么可以帮您?", -1))
1096
1357
  ])
1097
1358
  ], !0)
1098
- ])) : (o(), u("div", ks, [
1099
- (o(!0), u(ue, null, me(n.messages, (L, S) => (o(), u("div", {
1100
- key: L.id || S,
1101
- class: le([
1359
+ ])) : (u(), f("div", $a, [
1360
+ (u(!0), f(Ee, null, Te(r.messages, (a, s) => (u(), f("div", {
1361
+ key: a.id || s,
1362
+ class: he([
1102
1363
  "message-row",
1103
- L.role === "user" ? "message-user" : "message-assistant"
1364
+ a.role === "user" ? "message-user" : "message-assistant"
1104
1365
  ])
1105
1366
  }, [
1106
- L.role === "user" ? (o(), u("div", Ms, [
1107
- f(Ce, {
1108
- message: L,
1109
- "is-user": !0
1110
- }, null, 8, ["message"])
1111
- ])) : (o(), u("div", Cs, [
1112
- n.showAgentSteps && S === n.messages.length - 1 && n.agentSteps && n.agentSteps.length > 0 ? (o(), G(Ne, {
1367
+ a.role === "user" ? (u(), f("div", Ia, [
1368
+ o("div", _a, [
1369
+ k(Re, {
1370
+ message: a,
1371
+ "is-user": !0,
1372
+ "api-base-url": r.apiBaseUrl
1373
+ }, null, 8, ["message", "api-base-url"])
1374
+ ]),
1375
+ a.content ? (u(), f("div", xa, [
1376
+ o("button", {
1377
+ class: "action-btn",
1378
+ onClick: (n) => se(a),
1379
+ title: "复制"
1380
+ }, [...e[3] || (e[3] = [
1381
+ o("svg", {
1382
+ viewBox: "0 0 1024 1024",
1383
+ width: "12",
1384
+ height: "12"
1385
+ }, [
1386
+ o("path", {
1387
+ fill: "currentColor",
1388
+ d: "M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c6 6 14.1 9.4 22.6 9.4H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM352 853.3V704h149.3l-149.3 149.3zM224 256h448v640H416V672c0-17.7-14.3-32-32-32H224V256z"
1389
+ })
1390
+ ], -1),
1391
+ o("span", null, "复制", -1)
1392
+ ])], 8, La)
1393
+ ])) : z("", !0)
1394
+ ])) : (u(), f("div", za, [
1395
+ r.showAgentSteps && s === r.messages.length - 1 && r.agentSteps && r.agentSteps.length > 0 ? (u(), oe(Ge, {
1113
1396
  key: 0,
1114
- steps: n.agentSteps,
1115
- onResize: c
1116
- }, null, 8, ["steps"])) : D("", !0),
1117
- a("div", bs, [
1118
- f(Ce, {
1119
- message: L,
1397
+ steps: r.agentSteps,
1398
+ onResize: Ce
1399
+ }, null, 8, ["steps"])) : z("", !0),
1400
+ o("div", Ea, [
1401
+ $(a, s).length > 0 ? (u(), f("div", {
1402
+ key: 0,
1403
+ class: he(["a2ui-surfaces", { "a2ui-surfaces-with-content": ae(a) }])
1404
+ }, [
1405
+ (u(!0), f(Ee, null, Te($(a, s), (n) => (u(), oe(E(ut), {
1406
+ key: n,
1407
+ "surface-id": n
1408
+ }, null, 8, ["surface-id"]))), 128))
1409
+ ], 2)) : z("", !0),
1410
+ ue(a, s) ? (u(), f("div", Ta, [...e[4] || (e[4] = [
1411
+ lt('<div class="skeleton-header" data-v-a459a823><div class="skeleton-avatar skeleton-shimmer" data-v-a459a823></div><div class="skeleton-title-group" data-v-a459a823><div class="skeleton-line skeleton-title skeleton-shimmer" data-v-a459a823></div><div class="skeleton-line skeleton-subtitle skeleton-shimmer" data-v-a459a823></div></div></div><div class="skeleton-line skeleton-summary skeleton-shimmer" data-v-a459a823></div><div class="skeleton-line skeleton-summary short skeleton-shimmer" data-v-a459a823></div><div class="skeleton-facts" data-v-a459a823><div class="skeleton-fact skeleton-shimmer" data-v-a459a823></div><div class="skeleton-fact skeleton-shimmer" data-v-a459a823></div><div class="skeleton-fact skeleton-shimmer" data-v-a459a823></div></div>', 4)
1412
+ ])])) : z("", !0),
1413
+ ae(a) ? (u(), oe(Re, {
1414
+ key: 2,
1415
+ message: a,
1120
1416
  "is-user": !1,
1121
- "is-streaming": n.isStreaming && S === n.messages.length - 1
1122
- }, null, 8, ["message", "is-streaming"])
1417
+ "api-base-url": r.apiBaseUrl,
1418
+ "is-streaming": r.isStreaming && s === r.messages.length - 1
1419
+ }, null, 8, ["message", "api-base-url", "is-streaming"])) : z("", !0)
1123
1420
  ]),
1124
- L.content && !(n.isStreaming && S === n.messages.length - 1) ? (o(), u("div", _s, [
1125
- a("button", {
1421
+ ae(a) && a.content && !(r.isStreaming && s === r.messages.length - 1) ? (u(), f("div", Ba, [
1422
+ o("button", {
1126
1423
  class: "action-btn",
1127
- onClick: (C) => _(L),
1424
+ onClick: (n) => se(a),
1128
1425
  title: "复制"
1129
- }, [...M[2] || (M[2] = [
1130
- a("svg", {
1426
+ }, [...e[5] || (e[5] = [
1427
+ o("svg", {
1131
1428
  viewBox: "0 0 1024 1024",
1132
1429
  width: "12",
1133
1430
  height: "12"
1134
1431
  }, [
1135
- a("path", {
1432
+ o("path", {
1136
1433
  fill: "currentColor",
1137
1434
  d: "M832 64H296c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h496v688c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8V96c0-17.7-14.3-32-32-32zM704 192H192c-17.7 0-32 14.3-32 32v530.7c0 8.5 3.4 16.6 9.4 22.6l173.3 173.3c6 6 14.1 9.4 22.6 9.4H704c17.7 0 32-14.3 32-32V224c0-17.7-14.3-32-32-32zM352 853.3V704h149.3l-149.3 149.3zM224 256h448v640H416V672c0-17.7-14.3-32-32-32H224V256z"
1138
1435
  })
1139
1436
  ], -1),
1140
- a("span", null, "复制", -1)
1141
- ])], 8, $s)
1142
- ])) : D("", !0)
1437
+ o("span", null, "复制", -1)
1438
+ ])], 8, Ua)
1439
+ ])) : z("", !0)
1143
1440
  ]))
1144
1441
  ], 2))), 128)),
1145
- n.isTyping ? (o(), u("div", xs, [...M[3] || (M[3] = [
1146
- a("div", { class: "typing-indicator" }, [
1147
- a("div", { class: "typing-dot" }),
1148
- a("div", {
1442
+ r.isTyping ? (u(), f("div", Ha, [...e[6] || (e[6] = [
1443
+ o("div", { class: "typing-indicator" }, [
1444
+ o("div", { class: "typing-dot" }),
1445
+ o("div", {
1149
1446
  class: "typing-dot",
1150
1447
  style: { "animation-delay": "0.2s" }
1151
1448
  }),
1152
- a("div", {
1449
+ o("div", {
1153
1450
  class: "typing-dot",
1154
1451
  style: { "animation-delay": "0.4s" }
1155
1452
  })
1156
1453
  ], -1)
1157
- ])])) : D("", !0)
1454
+ ])])) : z("", !0)
1158
1455
  ]))
1159
- ], 36)
1456
+ ], 36),
1457
+ k(rt, { name: "fade-slide" }, {
1458
+ default: R(() => [
1459
+ x.value ? z("", !0) : (u(), f("button", {
1460
+ key: 0,
1461
+ class: "scroll-to-bottom-btn",
1462
+ style: Ie({ bottom: `calc(${r.contentPaddingBottom || "140px"} + 20px)` }),
1463
+ onClick: e[0] || (e[0] = (a) => O("smooth", !0))
1464
+ }, [
1465
+ e[8] || (e[8] = o("div", { class: "btn-inner" }, [
1466
+ o("svg", {
1467
+ class: "arrow-icon",
1468
+ viewBox: "0 0 24 24",
1469
+ fill: "none",
1470
+ stroke: "currentColor"
1471
+ }, [
1472
+ o("path", {
1473
+ "stroke-linecap": "round",
1474
+ "stroke-linejoin": "round",
1475
+ "stroke-width": "2.5",
1476
+ d: "M19 9l-7 7-7-7"
1477
+ })
1478
+ ])
1479
+ ], -1)),
1480
+ r.isStreaming ? (u(), f("svg", Da, [...e[7] || (e[7] = [
1481
+ o("circle", {
1482
+ class: "loading-circle",
1483
+ cx: "18",
1484
+ cy: "18",
1485
+ r: "16"
1486
+ }, null, -1)
1487
+ ])])) : z("", !0)
1488
+ ], 4))
1489
+ ]),
1490
+ _: 1
1491
+ })
1160
1492
  ]));
1161
1493
  }
1162
- }), zs = /* @__PURE__ */ oe(Ss, [["__scopeId", "data-v-02d657d5"]]), As = {
1163
- install(n) {
1164
- n.component("ChatMessageList", zs), n.component("MultimodalMessage", Ce), n.component("MarkdownMessage", Fe), n.component("AgentSteps", Ne);
1494
+ }), Ra = /* @__PURE__ */ _e(Pa, [["__scopeId", "data-v-a459a823"]]), Ya = {
1495
+ install(r) {
1496
+ r.component("ChatMessageList", Ra), r.component("MultimodalMessage", Re), r.component("MarkdownMessage", Je), r.component("AgentSteps", Ge);
1165
1497
  }
1166
1498
  };
1167
1499
  export {
1168
- Ne as AgentSteps,
1169
- zs as ChatMessageList,
1170
- Fe as MarkdownMessage,
1171
- Ce as MultimodalMessage,
1172
- As as default
1500
+ Ge as AgentSteps,
1501
+ Ra as ChatMessageList,
1502
+ Je as MarkdownMessage,
1503
+ Re as MultimodalMessage,
1504
+ Ya as default
1173
1505
  };