rt-chat-messages 1.0.4 → 1.0.6

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 Me, ref as C, onMounted as Ve, computed as Y, createBlock as de, createCommentVNode as B, openBlock as d, Teleport as at, createElementBlock as p, withModifiers as he, normalizeClass as le, createElementVNode as l, normalizeStyle as be, renderSlot as Fe, h as Oe, watch as ye, nextTick as oe, onUnmounted as He, createVNode as M, withCtx as W, unref as U, createTextVNode as We, toDisplayString as N, Fragment as ze, renderList as Ee, 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, DEFAULT_CATALOG as mt, provideA2UI as vt, defaultTheme as ft } from "a2ui-vue";
3
+ import gt from "markdown-it";
4
+ import pt from "@vscode/markdown-it-katex";
5
+ import je from "mermaid";
6
+ const ht = { class: "cm-dialog__body" }, yt = /* @__PURE__ */ Me({
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: y }) {
18
+ const b = r, w = y, m = C(!1);
19
+ Ve(() => {
20
+ m.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");
22
+ const A = Y(() => b.fullscreen ? { width: "100%", height: "100%", margin: 0 } : { width: b.width }), $ = () => {
23
+ w("update:visible", !1), w("close");
23
24
  }, x = () => {
24
- k.closeOnClickModal && E();
25
+ b.closeOnClickModal && $();
25
26
  };
26
- return (T, _) => z.value ? (o(), G(st, {
27
+ return (H, D) => m.value ? (d(), de(at, {
27
28
  key: 0,
28
29
  to: "body"
29
30
  }, [
30
- n.visible ? (o(), u("div", {
31
+ r.visible ? (d(), p("div", {
31
32
  key: 0,
32
- class: le(["cm-dialog-overlay", { "is-fullscreen": n.fullscreen }]),
33
- onClick: Z(x, ["self"])
33
+ class: le(["cm-dialog-overlay", { "is-fullscreen": r.fullscreen }]),
34
+ onClick: he(x, ["self"])
34
35
  }, [
35
- a("div", {
36
+ l("div", {
36
37
  class: "cm-dialog",
37
- style: ve($.value),
38
+ style: be(A.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
+ l("div", ht, [
43
+ Fe(H.$slots, "default", {}, void 0, !0)
43
44
  ]),
44
- n.showClose ? (o(), u("button", {
45
+ r.showClose ? (d(), p("button", {
45
46
  key: 0,
46
47
  class: "cm-dialog__close",
47
- onClick: E
48
- }, [..._[0] || (_[0] = [
49
- a("svg", {
48
+ onClick: $
49
+ }, [...D[0] || (D[0] = [
50
+ l("svg", {
50
51
  viewBox: "0 0 1024 1024",
51
52
  width: "16",
52
53
  height: "16"
53
54
  }, [
54
- a("path", {
55
+ l("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
+ ])])) : B("", !0)
60
61
  ], 4)
61
- ], 2)) : D("", !0)
62
- ])) : D("", !0);
62
+ ], 2)) : B("", !0)
63
+ ])) : B("", !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
+ }), Ce = (r, y) => {
66
+ const b = r.__vccOpts || r;
67
+ for (const [w, m] of y)
68
+ b[w] = m;
69
+ return b;
70
+ }, Pe = /* @__PURE__ */ Ce(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__ */ Me({
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: y }) {
84
+ const b = r, w = y, m = (A) => {
85
+ b.disabled || b.loading || w("click", A);
85
86
  };
86
- return ($, E) => (o(), u("button", {
87
+ return (A, $) => (d(), p("button", {
87
88
  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 }
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: m
94
95
  }, [
95
- n.loading ? (o(), u("span", dt, [...E[0] || (E[0] = [
96
- a("svg", {
96
+ r.loading ? (d(), p("span", kt, [...$[0] || ($[0] = [
97
+ l("svg", {
97
98
  viewBox: "0 0 1024 1024",
98
99
  width: "1em",
99
100
  height: "1em"
100
101
  }, [
101
- a("path", {
102
+ l("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
+ ])])) : Fe(A.$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
+ }), K = /* @__PURE__ */ Ce(bt, [["__scopeId", "data-v-bab126c7"]]), J = (r, y) => Me({
111
+ name: r,
111
112
  render() {
112
- return Se(
113
+ return Oe(
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
+ [Oe("path", { d: y })]
123
124
  );
124
125
  }
125
- }), fe = U(
126
+ }), Ue = J(
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 = J(
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 = J(
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 = J(
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 = J(
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 = J(
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 = J(
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
+ ), _t = J(
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
+ ), At = J(
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 = J(
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 = J(
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
+ ), $t = J(
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
+ ), xt = J(
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
+ ), It = ["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
+ }, Ut = ["innerHTML"], Tt = { class: "preview-controls" }, Bt = { class: "cm-button-group" }, Ht = {
168
169
  key: 0,
169
170
  class: "mobile-close-hint"
170
- }, xt = /* @__PURE__ */ Q({
171
+ }, Dt = /* @__PURE__ */ Me({
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 y = r, b = C(), w = C(), m = C(!1), A = C(""), $ = C(""), x = C(!1), H = C(""), D = C(!1), k = C(1), V = C({ x: 0, y: 0 }), L = C(!1), R = C({ x: 0, y: 0 }), S = C(1), O = C({ x: 0, y: 0 }), _ = C(!1), we = C({ x: 0, y: 0 }), z = C(""), re = C(/* @__PURE__ */ new Map()), me = C(!1);
179
+ let ke = 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 _e = (a) => {
187
+ const o = a.renderer.rules.fence;
188
+ a.renderer.rules.fence = (c, g, u, e, t) => {
189
+ const s = c[g], n = s.content.trim();
190
+ return (s.info ? s.info.trim() : "") === "mermaid" ? (ke++, `<div class="mermaid-container"><pre class="mermaid" data-mermaid-id="${`mermaid-${Date.now()}-${ke}`}">${n}</pre></div>`) : o(c, g, u, e, t);
190
191
  };
191
- }, j = new lt({
192
+ }, X = 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(a, o) {
207
+ return o && o.trim() ? `<pre class="hljs language-${o}"><code>${((g) => g.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;"))(a)}</code></pre>` : `<pre class="hljs"><code>${a}</code></pre>`;
207
208
  }
208
- }), ie = j.renderer.rules.image || function(e, t, l, g, r) {
209
- return r.renderToken(e, t, l);
209
+ }), ee = X.renderer.rules.image || function(a, o, c, g, u) {
210
+ return u.renderToken(a, o, c);
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
+ X.renderer.rules.image = function(a, o, c, g, u) {
213
+ const e = a[o], t = e.attrIndex("src");
214
+ if (t >= 0) {
215
+ const s = e.attrs[t][1], v = "img-" + ((E) => {
216
+ let P = 0;
217
+ for (let j = 0; j < E.length; j++) {
218
+ const pe = E.charCodeAt(j);
219
+ P = (P << 5) - P + pe, P = P & P;
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(P).toString(36);
222
+ })(s);
223
+ e.attrSet("id", v), e.attrSet("data-image-id", v), e.attrSet("key", v), e.attrSet("loading", "eager"), e.attrSet("decoding", "async"), e.attrSet("fetchpriority", "high"), e.attrSet("data-src", s), e.attrSet("data-cached", "true");
223
224
  }
224
- return ie(e, t, l, g, r);
225
- }, j.use(ot, {
225
+ return ee(a, o, c, g, u);
226
+ }, X.use(pt, {
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) => {
233
- if (!e) return "";
234
- 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];
229
+ }), X.use(_e);
230
+ const q = (a) => {
231
+ const o = a.match(/```[\w]*\n/g), c = a.match(/\n```/g), g = (o == null ? void 0 : o.length) || 0, u = (c == null ? void 0 : c.length) || 0;
232
+ return g > u && (a += "\n```"), a;
233
+ }, T = (a) => {
234
+ if (!a) return "";
235
+ a = a.replace(/;;\s*$/g, ""), a = a.replace(/;;\s*$/g, "");
236
+ const o = /^```(?:markdown|md)\s*\n([\s\S]*?)\n```$/, c = a.match(o);
237
+ if (c)
238
+ a = c[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 g = /^```\s*\n([\s\S]*?)\n```$/, u = a.match(g);
241
+ if (u) {
242
+ const e = u[1];
243
+ (/^#{1,6}\s/.test(e) || /^\*{1,2}[^*]+\*{1,2}/.test(e) || /^[-*+]\s/.test(e) || /^\d+\.\s/.test(e) || /!\[.*?\]\(.*?\)/.test(e) || /\[.*?\]\(.*?\)/.test(e) || /^\|.+\|/.test(e) || /^\|[\s-:]+\|/m.test(e)) && (a = e);
243
244
  }
244
245
  }
245
- if (p.isStreaming) {
246
+ if (y.isStreaming) {
246
247
  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, ""));
248
+ if (g.test(a)) {
249
+ const e = a.replace(g, "");
250
+ (/^#{1,6}\s/.test(e) || /^\|.+\|/.test(e) || /^\|[\s-:]+\|/m.test(e) || /!\[.*?\]\(.*?\)/.test(e) || /\[.*?\]\(.*?\)/.test(e)) && (a = a.replace(g, ""));
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(y.content)) {
253
+ const e = /\n```\s*$/;
254
+ e.test(a) && (a = a.replace(e, ""));
254
255
  }
255
256
  }
256
- return e = e.replace(
257
+ return a = a.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) => {
261
- if (!e.includes("<img"))
262
- 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 });
259
+ (g, u) => u
260
+ ), y.isStreaming && (a = q(a)), a;
261
+ }, te = (a) => {
262
+ if (!a.includes("<img"))
263
+ return a;
264
+ const o = /<img[^>]*?src="([^"]*)"[^>]*?>/g;
265
+ let c, g = a;
266
+ const u = [];
267
+ for (; (c = o.exec(a)) !== null; ) {
268
+ const e = c[0], t = c[1];
269
+ if (re.value.has(t)) {
270
+ const s = re.value.get(t);
271
+ e !== s && u.push({ original: e, cached: s });
271
272
  } else
272
- q.value.set(v, s);
273
+ re.value.set(t, e);
273
274
  }
274
- for (const { original: s, cached: v } of r)
275
- g = g.replace(s, v);
275
+ for (const { original: e, cached: t } of u)
276
+ g = g.replace(e, t);
276
277
  return g;
277
- }, we = (e) => {
278
- if (!i.value)
278
+ }, Ae = (a) => {
279
+ if (!w.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 o = w.value, c = /* @__PURE__ */ new Map();
282
+ if (y.isStreaming && o.children.length > 0 && o.querySelectorAll("img[data-image-id]").forEach((g) => {
283
+ const u = g.getAttribute("data-image-id");
284
+ u && c.set(u, g);
285
+ }), o.innerHTML = a, !y.isStreaming) {
286
+ oe(() => {
287
+ Be(), h();
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
+ c.size > 0 && o.querySelectorAll("img[data-image-id]").forEach((g) => {
292
+ const u = g.getAttribute("data-image-id");
293
+ if (u && c.has(u)) {
294
+ const e = c.get(u);
295
+ g.parentNode && e !== g && g.parentNode.replaceChild(e, g);
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
+ }, G = () => {
305
299
  try {
306
- if (!p.content) {
307
- se.value = "", i.value && (i.value.innerHTML = ""), p.isStreaming || q.value.clear();
300
+ if (!y.content) {
301
+ z.value = "", w.value && (w.value.innerHTML = ""), y.isStreaming || re.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();
313
- } 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>`);
304
+ if (document.hidden && y.isStreaming) {
305
+ me.value = !0;
306
+ return;
307
+ }
308
+ const a = T(y.content);
309
+ let o = X.render(a);
310
+ y.isStreaming && o.includes("<img") && (o = te(o)), o !== z.value && (z.value = o, Ae(o)), y.isStreaming || re.value.clear();
311
+ } catch (a) {
312
+ console.error("Markdown rendering error:", a), w.value && (w.value.innerHTML = `<pre style="white-space: pre-wrap; word-wrap: break-word;">${y.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
+ ye(() => y.content, G), ye(
316
+ () => y.isStreaming,
317
+ (a, o) => {
318
+ o && !a && oe(() => {
319
+ G();
322
320
  });
323
321
  }
324
322
  );
325
- const m = () => {
326
- _.value = window.innerWidth < 768;
327
- }, h = (e) => {
328
- let t = e;
329
- return t = t.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1"), [
323
+ const Q = () => {
324
+ !document.hidden && me.value && (me.value = !1, oe(() => {
325
+ G();
326
+ }));
327
+ };
328
+ document.addEventListener("visibilitychange", Q), He(() => {
329
+ document.removeEventListener("visibilitychange", Q);
330
+ });
331
+ const i = () => {
332
+ D.value = window.innerWidth < 768;
333
+ }, f = (a) => {
334
+ let o = a;
335
+ return o = o.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
339
  ].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;
340
+ o = o.replace(g, (u, e, t) => {
341
+ if (t.startsWith('"') && t.endsWith('"'))
342
+ return u;
343
+ let s = t.replace(/^["']+|["']+$/g, "").replace(/["]/g, '\\"');
344
+ return u.includes("[") ? `${e}["${s}"]` : u.includes("(") ? `${e}("${s}")` : u.includes("{") ? `${e}{"${s}"}` : u;
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");
345
- 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")
346
+ }), o;
347
+ }, h = async () => {
348
+ var o, c;
349
+ if (y.isStreaming || (await oe(), !b.value)) return;
350
+ const a = b.value.querySelectorAll(".mermaid");
351
+ if (a.length !== 0)
352
+ for (const g of Array.from(a)) {
353
+ const u = g;
354
+ let e = (o = u.textContent) == null ? void 0 : o.trim();
355
+ if (e && u.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
+ u.setAttribute("data-processed", "true"), e = f(e);
358
+ const t = u.getAttribute("data-mermaid-id") || `mermaid-${Date.now()}-${Math.random()}`, { svg: s } = await je.render(t, e), n = u.parentElement;
359
+ if (n) {
360
+ const v = document.createElement("div");
361
+ v.className = "mermaid-svg", v.innerHTML = s, v.setAttribute("data-mermaid-svg", "true"), v.style.cursor = "pointer", v.title = "Click to zoom", v.addEventListener("click", (E) => {
362
+ E.preventDefault(), E.stopPropagation(), H.value = s, S.value = 1, O.value = { x: 0, y: 0 }, x.value = !0;
363
+ }), n.replaceChild(v, u);
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 (t) {
366
+ console.error("Mermaid render failure:", t);
367
+ const s = document.createElement("div");
368
+ s.className = "mermaid-error", s.textContent = `Mermaid render error: ${t}`, (c = u.parentElement) == null || c.replaceChild(s, u);
363
369
  }
364
370
  }
365
- }, B = (e) => {
366
- 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) => {
380
- 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
371
+ }, I = (a) => {
372
+ a.preventDefault(), a.stopPropagation();
373
+ const o = a.target;
374
+ A.value = o.src, $.value = o.alt || "Image Preview", k.value = 1, V.value = { x: 0, y: 0 }, m.value = !0;
375
+ }, F = () => {
376
+ k.value <= 1 && (V.value = { x: 0, y: 0 });
377
+ }, ve = () => {
378
+ k.value = Math.min(k.value + 1, 10), F();
379
+ }, fe = () => {
380
+ k.value = Math.max(k.value - 1, 0.5), F();
381
+ }, ie = () => {
382
+ k.value = 1, V.value = { x: 0, y: 0 };
383
+ }, $e = () => {
384
+ k.value <= 1 && (m.value = !1);
385
+ }, se = (a) => {
386
+ a.preventDefault();
387
+ const o = a.deltaY > 0 ? -0.5 : 0.5, c = Math.max(0.5, Math.min(10, k.value + o));
388
+ k.value = c, F();
389
+ }, ae = (a) => {
390
+ var e;
391
+ if (k.value <= 1) return;
392
+ a.preventDefault(), L.value = !0, R.value = {
393
+ x: a.clientX - V.value.x,
394
+ y: a.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 o = a.target, c = (e = o.parentElement) == null ? void 0 : e.getBoundingClientRect(), g = (t) => {
397
+ if (!L.value || !c) return;
398
+ let s = t.clientX - R.value.x, n = t.clientY - R.value.y;
399
+ const v = o.offsetWidth, E = o.offsetHeight, P = v * k.value, j = E * k.value, pe = 0.3, De = c.width * (1 - pe - 0.5) - P / 2, Ie = P / 2 - c.width * (1 - pe - 0.5), Le = c.height * (1 - pe - 0.5) - j / 2, Se = j / 2 - c.height * (1 - pe - 0.5);
400
+ P > c.width ? s = Math.max(De, Math.min(Ie, s)) : s = 0, j > c.height ? n = Math.max(Le, Math.min(Se, n)) : n = 0, V.value = { x: s, y: n };
401
+ }, u = () => {
402
+ L.value = !1, document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", u);
397
403
  };
398
- document.addEventListener("mousemove", g), document.addEventListener("mouseup", r);
399
- }, Ve = (e) => {
400
- var P;
401
- 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
404
+ document.addEventListener("mousemove", g), document.addEventListener("mouseup", u);
405
+ }, ne = (a) => {
406
+ var n;
407
+ if (a.touches.length !== 1) return;
408
+ const o = a.touches[0], c = o.clientX, g = o.clientY;
409
+ if (k.value <= 1) return;
410
+ L.value = !0, R.value = {
411
+ x: c - V.value.x,
412
+ y: g - 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 u = a.target, e = (n = u.parentElement) == null ? void 0 : n.getBoundingClientRect(), t = (v) => {
415
+ if (!L.value || v.touches.length !== 1 || !e)
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 E = v.touches[0];
418
+ let P = E.clientX - R.value.x, j = E.clientY - R.value.y;
419
+ const pe = u.offsetWidth, De = u.offsetHeight, Ie = pe * k.value, Le = De * k.value, Se = 0.3, Qe = e.width * (1 - Se - 0.5) - Ie / 2, et = Ie / 2 - e.width * (1 - Se - 0.5), tt = e.height * (1 - Se - 0.5) - Le / 2, st = Le / 2 - e.height * (1 - Se - 0.5);
420
+ Ie > e.width ? P = Math.max(Qe, Math.min(et, P)) : P = 0, Le > e.height ? j = Math.max(tt, Math.min(st, j)) : j = 0, V.value = { x: P, y: j };
421
+ }, s = () => {
422
+ L.value = !1, document.removeEventListener("touchmove", t), document.removeEventListener("touchend", s);
417
423
  };
418
- document.addEventListener("touchmove", v, { passive: !1 }), document.addEventListener("touchend", w);
419
- }, Ze = () => {
424
+ document.addEventListener("touchmove", t, { passive: !1 }), document.addEventListener("touchend", s);
425
+ }, Z = () => {
420
426
  S.value = Math.min(S.value + 1, 10);
421
- }, qe = () => {
427
+ }, xe = () => {
422
428
  S.value = Math.max(S.value - 1, 0.5);
423
- }, $e = () => {
424
- S.value = 1, C.value = { x: 0, y: 0 };
425
- }, je = (e) => {
426
- 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;
429
+ }, ce = () => {
430
+ S.value = 1, O.value = { x: 0, y: 0 };
431
+ }, ge = (a) => {
432
+ a.preventDefault();
433
+ const o = a.deltaY > 0 ? -0.5 : 0.5;
434
+ S.value = Math.max(0.5, Math.min(10, S.value + o));
435
+ }, Te = (a) => {
436
+ var e, t;
431
437
  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
438
+ a.preventDefault(), _.value = !0, we.value = {
439
+ x: a.clientX - O.value.x,
440
+ y: a.clientY - O.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 c = (t = (e = a.target.closest(".mermaid-preview-content")) == null ? void 0 : e.parentElement) == null ? void 0 : t.getBoundingClientRect(), g = (s) => {
443
+ if (!_.value || !c) return;
444
+ let n = s.clientX - we.value.x, v = s.clientY - we.value.y;
445
+ O.value = { x: n, y: v };
446
+ }, u = () => {
447
+ _.value = !1, document.removeEventListener("mousemove", g), document.removeEventListener("mouseup", u);
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", g), document.addEventListener("mouseup", u);
450
+ }, ue = (a) => {
451
+ }, Be = () => {
452
+ y.isStreaming || oe(() => {
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((o) => {
457
+ const c = o;
458
+ c.getAttribute("data-processed") !== "true" && (c.setAttribute("data-processed", "true"), c.style.cursor = "pointer", c.addEventListener("click", I));
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), G(), Be(), h();
464
+ }), He(() => {
465
+ b.value && b.value.querySelectorAll(
460
466
  ".markdown-content img"
461
- ).forEach((t) => {
462
- t.removeEventListener("click", B);
467
+ ).forEach((o) => {
468
+ o.removeEventListener("click", I);
463
469
  });
464
- }), (e, t) => (o(), u("div", {
470
+ }), (a, o) => (d(), p("div", {
465
471
  class: "markdown-message",
466
472
  ref_key: "markdownContainer",
467
- ref: k
473
+ ref: b
468
474
  }, [
469
- a("div", {
475
+ l("div", {
470
476
  ref_key: "markdownContent",
471
- ref: i,
477
+ ref: w,
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),
477
- width: _.value ? "95vw" : "80vw",
478
- fullscreen: _.value,
480
+ M(Pe, {
481
+ visible: m.value,
482
+ "onUpdate:visible": o[2] || (o[2] = (c) => m.value = c),
483
+ width: D.value ? "95vw" : "80vw",
484
+ fullscreen: D.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: W(() => [
490
+ l("div", {
485
491
  class: "image-preview-container",
486
- onClick: t[1] || (t[1] = Z((l) => z.value = !1, ["self"]))
492
+ onClick: o[1] || (o[1] = he((c) => m.value = !1, ["self"]))
487
493
  }, [
488
- a("img", {
489
- src: $.value,
490
- alt: E.value,
494
+ l("img", {
495
+ src: A.value,
496
+ alt: $.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: be({
499
+ transform: `translate(${V.value.x}px, ${V.value.y}px) scale(${k.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: he(se, ["prevent"]),
502
+ onDblclick: ie,
503
+ onMousedown: ae,
504
+ onTouchstart: he(ne, ["prevent"]),
505
+ onClick: $e
506
+ }, null, 44, It),
507
+ l("div", Lt, [
508
+ l("div", zt, [
509
+ M(K, {
504
510
  size: "small",
505
- onClick: Ye,
506
- disabled: c.value <= 0.5
511
+ onClick: fe,
512
+ disabled: k.value <= 0.5
507
513
  }, {
508
- default: H(() => [
509
- f(I(Ie))
514
+ default: W(() => [
515
+ M(U(Ne))
510
516
  ]),
511
517
  _: 1
512
518
  }, 8, ["disabled"]),
513
- f(N, {
519
+ M(K, {
514
520
  size: "small",
515
- onClick: _e
521
+ onClick: ie
516
522
  }, {
517
- default: H(() => [
518
- ze(F(Math.round(c.value * 100)) + "% ", 1)
523
+ default: W(() => [
524
+ We(N(Math.round(k.value * 100)) + "% ", 1)
519
525
  ]),
520
526
  _: 1
521
527
  }),
522
- f(N, {
528
+ M(K, {
523
529
  size: "small",
524
- onClick: Ue,
525
- disabled: c.value >= 10
530
+ onClick: ve,
531
+ disabled: k.value >= 10
526
532
  }, {
527
- default: H(() => [
528
- f(I(Ee))
533
+ default: W(() => [
534
+ M(U(Ye))
529
535
  ]),
530
536
  _: 1
531
537
  }, 8, ["disabled"])
532
538
  ]),
533
- f(N, {
539
+ M(K, {
534
540
  size: "small",
535
- onClick: t[0] || (t[0] = (l) => z.value = !1),
541
+ onClick: o[0] || (o[0] = (c) => m.value = !1),
536
542
  type: "danger"
537
543
  }, {
538
- default: H(() => [
539
- f(I(fe))
544
+ default: W(() => [
545
+ M(U(Ue))
540
546
  ]),
541
547
  _: 1
542
548
  })
543
549
  ]),
544
- _.value ? (o(), u("div", Mt, "双击重置 · 轻触关闭")) : D("", !0)
550
+ D.value ? (d(), p("div", Et, "双击重置 · 轻触关闭")) : B("", !0)
545
551
  ])
546
552
  ]),
547
553
  _: 1
548
554
  }, 8, ["visible", "width", "fullscreen"]),
549
- f(Me, {
555
+ M(Pe, {
550
556
  visible: x.value,
551
- "onUpdate:visible": t[5] || (t[5] = (l) => x.value = l),
552
- width: _.value ? "95vw" : "90vw",
553
- fullscreen: _.value,
557
+ "onUpdate:visible": o[5] || (o[5] = (c) => x.value = c),
558
+ width: D.value ? "95vw" : "90vw",
559
+ fullscreen: D.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: W(() => [
565
+ l("div", {
560
566
  class: "mermaid-preview-container",
561
- onClick: t[4] || (t[4] = Z((l) => x.value = !1, ["self"]))
567
+ onClick: o[4] || (o[4] = he((c) => x.value = !1, ["self"]))
562
568
  }, [
563
- a("div", {
569
+ l("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: H.value,
572
+ style: be({
573
+ transform: `translate(${O.value.x}px, ${O.value.y}px) scale(${S.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: he(ge, ["prevent"]),
576
+ onDblclick: ce,
577
+ onMousedown: Te,
578
+ onTouchstart: he(ue, ["prevent"])
579
+ }, null, 44, Ut),
580
+ l("div", Tt, [
581
+ l("div", Bt, [
582
+ M(K, {
577
583
  size: "small",
578
- onClick: qe,
584
+ onClick: xe,
579
585
  disabled: S.value <= 0.5
580
586
  }, {
581
- default: H(() => [
582
- f(I(Ie))
587
+ default: W(() => [
588
+ M(U(Ne))
583
589
  ]),
584
590
  _: 1
585
591
  }, 8, ["disabled"]),
586
- f(N, {
592
+ M(K, {
587
593
  size: "small",
588
- onClick: $e
594
+ onClick: ce
589
595
  }, {
590
- default: H(() => [
591
- ze(F(Math.round(S.value * 100)) + "% ", 1)
596
+ default: W(() => [
597
+ We(N(Math.round(S.value * 100)) + "% ", 1)
592
598
  ]),
593
599
  _: 1
594
600
  }),
595
- f(N, {
601
+ M(K, {
596
602
  size: "small",
597
- onClick: Ze,
603
+ onClick: Z,
598
604
  disabled: S.value >= 10
599
605
  }, {
600
- default: H(() => [
601
- f(I(Ee))
606
+ default: W(() => [
607
+ M(U(Ye))
602
608
  ]),
603
609
  _: 1
604
610
  }, 8, ["disabled"])
605
611
  ]),
606
- f(N, {
612
+ M(K, {
607
613
  size: "small",
608
- onClick: t[3] || (t[3] = (l) => x.value = !1),
614
+ onClick: o[3] || (o[3] = (c) => x.value = !1),
609
615
  type: "danger"
610
616
  }, {
611
- default: H(() => [
612
- f(I(fe))
617
+ default: W(() => [
618
+ M(U(Ue))
613
619
  ]),
614
620
  _: 1
615
621
  })
616
622
  ]),
617
- _.value ? (o(), u("div", $t, "双击重置 · 轻触关闭")) : D("", !0)
623
+ D.value ? (d(), p("div", Ht, "双击重置 · 轻触关闭")) : B("", !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__ */ Ce(Dt, [["__scopeId", "data-v-c6385dde"]]), 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"], Ft = ["src", "alt", "onError"], Ot = {
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" }, es = { class: "progress-bar" }, ts = { class: "audio-time" }, ss = { class: "image-preview-container" }, as = ["src"], ns = {
643
646
  key: 0,
644
647
  class: "image-nav"
645
- }, Qt = { class: "image-counter" }, es = /* @__PURE__ */ Q({
648
+ }, os = { class: "image-counter" }, ls = /* @__PURE__ */ Me({
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 y = r, b = Y(() => {
654
659
  try {
655
- return p.message.metadata ? JSON.parse(p.message.metadata) : {};
660
+ return y.message.metadata ? JSON.parse(y.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
+ }), w = Y(
665
+ () => b.value.imageUrls || []
666
+ ), m = Y(() => b.value.audioUrl), A = C(/* @__PURE__ */ new Set()), $ = Y(
667
+ () => b.value.fileUrls || []
668
+ ), x = Y(() => $.value), H = Y(() => y.message.attachments && y.message.attachments.length > 0 ? y.message.attachments : b.value.attachments && Array.isArray(b.value.attachments) ? b.value.attachments : []), D = Y(() => {
669
+ const i = [];
670
+ return H.value && H.value.length > 0 ? H.value.forEach((f) => {
671
+ var I, F;
672
+ ((I = f.type) == null ? void 0 : I.startsWith("image/")) || ((F = f.name) == null ? void 0 : F.match(/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i)) || i.push({
673
+ url: f.url || f.download_url || f.file_url || "",
674
+ name: f.original_name || f.name || "Unknown File",
675
+ type: ee(f.original_name || f.name || "Unknown File")
676
+ });
677
+ }) : x.value && x.value.length > 0 && x.value.forEach((f) => {
678
+ i.push({
679
+ url: f,
680
+ name: X(f),
681
+ type: ee(f)
682
+ });
683
+ }), i;
684
+ }), k = C(!1), V = C(""), L = C(0), R = C(!1), S = C(!1), O = C(0), _ = C(0), we = Y(() => _.value > 0 ? O.value / _.value * 100 : 0);
685
+ let z = null;
686
+ const re = (i, f) => {
687
+ V.value = i, L.value = f, k.value = !0;
688
+ }, me = () => {
689
+ L.value > 0 && (L.value--, V.value = w.value[L.value]);
690
+ }, ke = () => {
691
+ L.value < w.value.length - 1 && (L.value++, V.value = w.value[L.value]);
692
+ }, _e = (i, f) => {
693
+ console.error("Image load failed:", f);
694
+ const h = i.target;
695
+ h.style.display = "none";
696
+ }, X = (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 f = i.lastIndexOf("/"), h = f >= 0 ? i.substring(f + 1) : i;
702
+ return decodeURIComponent(h) || "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
+ }, ee = (i) => {
707
+ var I;
708
+ return ((I = X(i).split(".").pop()) == null ? void 0 : I.toUpperCase()) || "FILE";
709
+ }, q = (i, f) => {
710
+ te(i, f);
711
+ }, T = (i) => !i || i.startsWith("http://") || i.startsWith("https://") || i.startsWith("blob:") ? i : (y.apiBaseUrl ? y.apiBaseUrl.replace(/\/$/, "") : "") + (i.startsWith("/") ? i : "/" + i), te = async (i, f) => {
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);
713
+ const h = T(i);
714
+ if (console.log("正在下载文件...", h), y.onDownload && (A.value = /* @__PURE__ */ new Set([...A.value, i]), await y.onDownload(i, f) !== !1)) {
715
+ const Z = new Set(A.value);
716
+ Z.delete(i), A.value = Z;
717
+ return;
718
+ }
719
+ A.value = /* @__PURE__ */ new Set([...A.value, i]);
720
+ const I = localStorage.getItem("token"), F = {};
721
+ if (I && (F.Authorization = I.startsWith("Bearer ") ? I : `Bearer ${I}`), typeof window < "u" && typeof window.plus < "u") {
722
+ const ne = window.plus, Z = ne.downloader.createDownload(
723
+ h,
724
+ {
725
+ method: "GET",
726
+ filename: "_downloads/" + (f || X(i))
727
+ },
728
+ (xe, ce) => {
729
+ const ge = new Set(A.value);
730
+ ge.delete(i), A.value = ge, ce === 200 || ce === 206 ? ne.runtime.openFile(xe.filename) : console.error("App 环境原生下载失败, status:", ce);
731
+ }
732
+ );
733
+ F.Authorization && Z.setRequestHeader(
734
+ "Authorization",
735
+ F.Authorization
736
+ ), Z.start();
737
+ return;
738
+ }
739
+ const ve = await fetch(h, { headers: F });
740
+ if (!ve.ok)
741
+ throw new Error(`下载失败: ${ve.status}`);
742
+ let fe = f;
743
+ const ie = ve.headers.get("Content-Disposition");
744
+ if (ie) {
745
+ const ne = ie.match(/filename\*=UTF-8''(.+)/i);
746
+ if (ne)
747
+ fe = decodeURIComponent(ne[1]);
748
+ else {
749
+ const Z = ie.match(/filename="?([^";\n]+)"?/i);
750
+ Z && (fe = Z[1]);
751
+ }
752
+ }
753
+ const $e = await ve.blob(), se = URL.createObjectURL($e), ae = document.createElement("a");
754
+ ae.href = se, ae.download = fe || f || X(i), document.body.appendChild(ae), ae.click(), document.body.removeChild(ae), URL.revokeObjectURL(se);
690
755
  } catch (h) {
691
- console.error("Download failed:", h), alert("下载失败");
756
+ console.error("下载文件失败:", h);
757
+ } finally {
758
+ const h = new Set(A.value);
759
+ h.delete(i), A.value = h;
692
760
  }
693
- }, pe = async () => {
694
- if ($.value)
761
+ }, Ae = async () => {
762
+ if (m.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
+ z || (z = new Audio(), z.src = T(m.value), z.addEventListener("loadedmetadata", () => {
765
+ _.value = (z == null ? void 0 : z.duration) || 0;
766
+ }), z.addEventListener("timeupdate", () => {
767
+ O.value = (z == null ? void 0 : z.currentTime) || 0;
768
+ }), z.addEventListener("ended", () => {
769
+ R.value = !1, O.value = 0;
770
+ }), z.addEventListener("error", (i) => {
771
+ console.error("Audio playback error:", i), S.value = !1, R.value = !1;
772
+ })), R.value ? (z.pause(), R.value = !1) : (S.value = !0, await z.play(), R.value = !0, S.value = !1);
773
+ } catch (i) {
774
+ console.error("Audio playback failed:", i), S.value = !1, R.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
+ }, G = (i) => {
777
+ const f = Math.floor(i / 60), h = Math.floor(i % 60);
778
+ return `${f}:${h.toString().padStart(2, "0")}`;
779
+ }, Q = (i) => {
780
+ k.value && (i.key === "ArrowLeft" ? me() : i.key === "ArrowRight" ? ke() : i.key === "Escape" && (k.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 ye(k, (i) => {
783
+ i ? document.addEventListener("keydown", Q) : document.removeEventListener("keydown", Q);
784
+ }), He(() => {
785
+ z && (z.pause(), z = null), document.removeEventListener("keydown", Q);
786
+ }), (i, f) => (d(), p("div", {
787
+ class: le(["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 ? (d(), p("div", Pt, [
790
+ M(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
+ ])) : B("", !0),
795
+ w.value && w.value.length > 0 ? (d(), p("div", Rt, [
796
+ l("div", {
797
+ class: le(["images-grid", `grid-${Math.min(w.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
+ (d(!0), p(ze, null, Ee(w.value.slice(0, 4), (h, I) => (d(), p("div", {
800
+ key: I,
740
801
  class: "image-item",
741
- onClick: (O) => ee(y, B)
802
+ onClick: (F) => re(h, I)
742
803
  }, [
743
- a("img", {
744
- src: y,
745
- alt: `图片 ${B + 1}`,
746
- onError: (O) => q(O, y),
804
+ l("img", {
805
+ src: h,
806
+ alt: `图片 ${I + 1}`,
807
+ onError: (F) => _e(F, h),
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, Ft),
810
+ I === 3 && w.value.length > 4 ? (d(), p("div", Ot, " +" + N(w.value.length - 4), 1)) : B("", !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
+ ])) : B("", !0),
814
+ D.value && D.value.length > 0 ? (d(), p("div", Wt, [
815
+ (d(!0), p(ze, null, Ee(D.value, (h, I) => (d(), p("div", {
816
+ key: I,
770
817
  class: "file-item",
771
- onClick: (O) => j(y)
818
+ onClick: (F) => q(h.url, h.name)
772
819
  }, [
773
- a("div", Ft, [
774
- f(I(Be), { class: "file-icon" })
775
- ]),
776
- a("div", Nt, [
777
- a("span", Ut, F(ae(y)), 1),
778
- a("span", Yt, F(ge(y)), 1)
820
+ l("div", Yt, [
821
+ M(U(Mt), { class: "file-icon" })
779
822
  ]),
780
- a("div", Wt, [
781
- f(N, {
823
+ l("div", {
824
+ class: "file-info",
825
+ title: h.name
826
+ }, [
827
+ l("span", Xt, N(h.name), 1),
828
+ l("span", qt, N(h.type), 1)
829
+ ], 8, Nt),
830
+ l("div", Zt, [
831
+ M(K, {
782
832
  size: "small",
783
833
  type: "text",
784
- onClick: Z((O) => ie(y), ["stop"])
834
+ disabled: A.value.has(h.url),
835
+ onClick: he((F) => te(h.url, h.name), ["stop"])
785
836
  }, {
786
- default: H(() => [
787
- f(I(Ae))
837
+ default: W(() => [
838
+ M(U(Xe), {
839
+ class: le({ "icon-spin": A.value.has(h.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
+ ])) : B("", !0),
847
+ m.value ? (d(), p("div", Kt, [
848
+ l("div", Jt, [
849
+ M(K, {
850
+ onClick: Ae,
851
+ loading: S.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: W(() => [
857
+ (d(), de(Ke(R.value ? U(Ct) : U(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
+ l("div", Gt, [
862
+ l("div", Qt, [
863
+ l("div", es, [
864
+ l("div", {
812
865
  class: "progress-fill",
813
- style: ve({ width: S.value + "%" })
866
+ style: be({ width: we.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
+ l("div", ts, [
871
+ l("span", null, N(G(O.value)), 1),
872
+ f[4] || (f[4] = l("span", null, "/", -1)),
873
+ l("span", null, N(G(_.value)), 1)
821
874
  ])
822
875
  ]),
823
- f(N, {
824
- onClick: h[0] || (h[0] = (y) => ie($.value)),
876
+ M(K, {
877
+ onClick: f[0] || (f[0] = (h) => te(m.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: W(() => [
883
+ M(U(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
+ ])) : B("", !0),
889
+ M(Pe, {
890
+ visible: k.value,
891
+ "onUpdate:visible": f[3] || (f[3] = (h) => k.value = h),
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: W(() => [
898
+ l("div", ss, [
899
+ l("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: f[1] || (f[1] = (h) => k.value = !1)
904
+ }, null, 8, as),
905
+ w.value && w.value.length > 1 ? (d(), p("div", ns, [
906
+ M(K, {
907
+ onClick: me,
908
+ disabled: L.value === 0,
856
909
  circle: "",
857
910
  class: "nav-btn"
858
911
  }, {
859
- default: H(() => [
860
- f(I(gt))
912
+ default: W(() => [
913
+ M(U(_t))
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
+ l("span", os, N(L.value + 1) + " / " + N(w.value.length), 1),
918
+ M(K, {
919
+ onClick: ke,
920
+ disabled: L.value === w.value.length - 1,
868
921
  circle: "",
869
922
  class: "nav-btn"
870
923
  }, {
871
- default: H(() => [
872
- f(I(ht))
924
+ default: W(() => [
925
+ M(U(At))
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
+ ])) : B("", !0),
930
+ M(K, {
931
+ onClick: f[2] || (f[2] = (h) => k.value = !1),
879
932
  class: "close-btn",
880
933
  circle: ""
881
934
  }, {
882
- default: H(() => [
883
- f(I(fe))
935
+ default: W(() => [
936
+ M(U(Ue))
884
937
  ]),
885
938
  _: 1
886
939
  })
@@ -890,104 +943,143 @@ 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 = {
894
- key: 0,
895
- class: "agent-steps"
896
- }, ss = { class: "steps-indicator" }, as = {
946
+ }), Re = /* @__PURE__ */ Ce(ls, [["__scopeId", "data-v-96cd8b34"]]), rs = ["aria-expanded"], is = { class: "steps-indicator" }, cs = {
897
947
  key: 0,
898
948
  class: "icon-running"
899
- }, ns = {
949
+ }, us = {
900
950
  key: 1,
951
+ class: "icon-error"
952
+ }, ds = {
953
+ key: 2,
901
954
  class: "icon-completed"
902
- }, ls = { class: "steps-summary" }, os = { class: "icon-chevron" }, is = { class: "steps-list" }, rs = { class: "step-icon" }, cs = {
955
+ }, ms = { class: "steps-copy" }, vs = { class: "steps-summary" }, fs = { class: "steps-meta" }, gs = { class: "steps-count" }, ps = { class: "icon-chevron" }, hs = {
956
+ class: "steps-progress",
957
+ "aria-hidden": "true"
958
+ }, ys = { class: "steps-list" }, ws = {
959
+ class: "step-rail",
960
+ "aria-hidden": "true"
961
+ }, ks = { class: "step-icon" }, bs = {
903
962
  key: 3,
904
963
  class: "icon-dot"
905
- }, ds = { class: "step-name" }, us = /* @__PURE__ */ Q({
964
+ }, Ms = { class: "step-name" }, Ss = { class: "step-status" }, Cs = /* @__PURE__ */ Me({
906
965
  __name: "AgentSteps",
907
966
  props: {
908
967
  steps: {}
909
968
  },
910
969
  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");
915
- }, 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"
924
- ).length;
925
- return _ === k.steps.length ? "处理完成" : `已完成 ${_}/${k.steps.length} 个步骤`;
926
- });
927
- return (T, _) => n.steps.length > 0 ? (o(), u("div", ts, [
928
- a("div", {
970
+ setup(r, { emit: y }) {
971
+ const b = r, w = C(!0), m = y, A = () => {
972
+ w.value = !w.value, oe(() => {
973
+ requestAnimationFrame(() => m("resize"));
974
+ });
975
+ }, $ = Y(
976
+ () => b.steps.some((S) => S.status === "running")
977
+ ), x = Y(() => b.steps.some((S) => S.status === "error")), H = Y(
978
+ () => b.steps.filter((S) => S.status === "completed").length
979
+ ), D = Y(() => b.steps.length === 0 ? 0 : Math.round(H.value / b.steps.length * 100)), k = Y(() => ({
980
+ width: `${D.value}%`
981
+ })), V = Y(() => $.value ? "智能处理流程" : x.value ? "需要关注" : "全部步骤已同步"), L = Y(() => {
982
+ const S = b.steps.find((O) => O.status === "running");
983
+ return S ? `正在处理 ${S.displayName}` : x.value ? "处理遇到问题" : H.value === b.steps.length ? "处理完成" : `已完成 ${H.value}/${b.steps.length} 个步骤`;
984
+ }), R = (S) => S === "running" ? "进行中" : S === "error" ? "异常" : "完成";
985
+ return (S, O) => r.steps.length > 0 ? (d(), p("div", {
986
+ key: 0,
987
+ class: le(["agent-steps", {
988
+ "is-running": $.value,
989
+ "is-error": x.value,
990
+ "is-collapsed": !w.value
991
+ }])
992
+ }, [
993
+ l("button", {
994
+ type: "button",
929
995
  class: "steps-header",
930
- onClick: $
996
+ "aria-expanded": w.value,
997
+ onClick: A
931
998
  }, [
932
- a("div", ss, [
933
- E.value ? (o(), u("div", as, [
934
- f(I(Te))
935
- ])) : (o(), u("div", ns, [
936
- f(I(He))
999
+ l("span", is, [
1000
+ $.value ? (d(), p("span", cs, [
1001
+ M(U(qe))
1002
+ ])) : x.value ? (d(), p("span", us, [
1003
+ M(U(Ue))
1004
+ ])) : (d(), p("span", ds, [
1005
+ M(U(Ze))
937
1006
  ]))
938
1007
  ]),
939
- a("span", ls, F(x.value), 1),
940
- a("div", os, [
941
- (o(), G(Pe(i.value ? I(ft) : I(pt))))
1008
+ l("span", ms, [
1009
+ l("span", vs, N(L.value), 1),
1010
+ l("span", fs, N(V.value), 1)
1011
+ ]),
1012
+ l("span", gs, N(H.value) + "/" + N(r.steps.length), 1),
1013
+ l("span", ps, [
1014
+ (d(), de(Ke(w.value ? U($t) : U(xt))))
942
1015
  ])
1016
+ ], 8, rs),
1017
+ l("div", hs, [
1018
+ l("span", {
1019
+ style: be(k.value)
1020
+ }, null, 4)
943
1021
  ]),
944
- at(a("div", is, [
945
- (o(!0), u(ue, null, me(n.steps, (c) => (o(), u("div", {
946
- key: c.name,
1022
+ nt(l("div", ys, [
1023
+ (d(!0), p(ze, null, Ee(r.steps, (_) => (d(), p("div", {
1024
+ key: _.name,
947
1025
  class: le(["step-item", {
948
- "is-running": c.status === "running",
949
- "is-completed": c.status === "completed",
950
- "is-error": c.status === "error"
1026
+ "is-running": _.status === "running",
1027
+ "is-completed": _.status === "completed",
1028
+ "is-error": _.status === "error"
951
1029
  }])
952
1030
  }, [
953
- a("div", rs, [
954
- c.status === "running" ? (o(), G(I(Te), {
955
- key: 0,
956
- 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))
1031
+ l("span", ws, [
1032
+ l("span", ks, [
1033
+ _.status === "running" ? (d(), de(U(qe), {
1034
+ key: 0,
1035
+ class: "icon-spin"
1036
+ })) : _.status === "completed" ? (d(), de(U(Ze), { key: 1 })) : _.status === "error" ? (d(), de(U(Ue), { key: 2 })) : (d(), p("span", bs))
1037
+ ])
958
1038
  ]),
959
- a("span", ds, F(c.displayName), 1)
1039
+ l("span", Ms, N(_.displayName), 1),
1040
+ l("span", Ss, N(R(_.status)), 1)
960
1041
  ], 2))), 128))
961
1042
  ], 512), [
962
- [nt, i.value]
1043
+ [ot, w.value]
963
1044
  ])
964
- ])) : D("", !0);
1045
+ ], 2)) : B("", !0);
965
1046
  }
966
- }), Ne = /* @__PURE__ */ oe(us, [["__scopeId", "data-v-181f5844"]]), ms = { class: "chat-message-list-root" }, vs = {
1047
+ }), Ge = /* @__PURE__ */ Ce(Cs, [["__scopeId", "data-v-5030f19a"]]), _s = { class: "chat-message-list-root" }, As = {
967
1048
  key: 0,
968
1049
  class: "bg-grid"
969
- }, gs = {
1050
+ }, $s = {
970
1051
  key: 0,
971
1052
  class: "welcome-screen"
972
- }, hs = { class: "welcome-content" }, fs = { class: "welcome-logo" }, ps = ["src"], ys = {
1053
+ }, xs = { class: "welcome-content" }, Is = { class: "welcome-logo" }, Ls = ["src"], zs = {
973
1054
  key: 1,
974
1055
  class: "default-logo"
975
- }, ws = { class: "welcome-title" }, ks = {
1056
+ }, Es = { class: "welcome-title" }, Us = {
976
1057
  key: 1,
977
1058
  class: "messages-container"
978
- }, Ms = {
1059
+ }, Ts = {
1060
+ key: 0,
1061
+ class: "user-message-wrapper"
1062
+ }, Bs = { class: "message-bubble user-bubble" }, Hs = {
979
1063
  key: 0,
980
- class: "message-bubble user-bubble"
981
- }, Cs = {
1064
+ class: "message-actions user-actions"
1065
+ }, Ds = ["onClick"], Ps = {
982
1066
  key: 1,
983
1067
  class: "message-content assistant-content"
984
- }, bs = { class: "message-bubble assistant-bubble" }, _s = {
1068
+ }, Rs = {
1069
+ key: 2,
1070
+ class: "a2ui-card-skeleton",
1071
+ "aria-hidden": "true"
1072
+ }, Vs = {
985
1073
  key: 1,
986
1074
  class: "message-actions"
987
- }, $s = ["onClick"], xs = {
1075
+ }, Fs = ["onClick"], Os = {
988
1076
  key: 0,
989
1077
  class: "message-row message-assistant"
990
- }, Ss = /* @__PURE__ */ Q({
1078
+ }, Ws = {
1079
+ key: 0,
1080
+ class: "loading-ring",
1081
+ viewBox: "0 0 36 36"
1082
+ }, js = /* @__PURE__ */ Me({
991
1083
  __name: "ChatMessageList",
992
1084
  props: {
993
1085
  messages: { default: () => [] },
@@ -1001,173 +1093,514 @@ const it = { class: "cm-dialog__body" }, rt = /* @__PURE__ */ Q({
1001
1093
  autoScroll: { type: Boolean, default: !0 },
1002
1094
  contentPaddingTop: { default: "80px" },
1003
1095
  contentPaddingBottom: { default: "140px" },
1004
- showBackground: { type: Boolean, default: !0 }
1096
+ showBackground: { type: Boolean, default: !0 },
1097
+ apiBaseUrl: { default: "" },
1098
+ enableA2UI: { type: Boolean, default: !0 },
1099
+ autoProvideA2UI: { type: Boolean, default: !0 },
1100
+ a2uiCatalog: {},
1101
+ hideA2UIRawContent: { type: Boolean, default: !0 },
1102
+ showA2UISkeleton: { type: Boolean, default: !0 },
1103
+ a2uiActionHandler: {}
1005
1104
  },
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;
1105
+ emits: [
1106
+ "copy",
1107
+ "scroll",
1108
+ "scroll-bottom",
1109
+ "a2ui-action",
1110
+ "a2ui-error"
1111
+ ],
1112
+ setup(r, { expose: y, emit: b }) {
1113
+ const w = /* @__PURE__ */ new WeakMap(), m = r, A = b, $ = C(null), x = C(!1), H = C(!0), D = C({}), k = C({});
1114
+ (() => {
1115
+ var s;
1116
+ if (!m.autoProvideA2UI) return;
1117
+ if (!m.a2uiCatalog)
1118
+ try {
1119
+ dt();
1120
+ return;
1121
+ } catch {
1122
+ }
1123
+ const e = (s = it()) == null ? void 0 : s.appContext.app, t = m.a2uiCatalog || mt;
1124
+ !e || w.get(e) === t || (vt({
1125
+ app: e,
1126
+ catalog: t,
1127
+ theme: ft
1128
+ }), w.set(e, t));
1129
+ })();
1130
+ const L = ct(), R = () => {
1131
+ if (!$.value) return !0;
1132
+ const { scrollTop: e, scrollHeight: t, clientHeight: s } = $.value;
1133
+ return t - e - s < 50;
1134
+ }, S = () => {
1135
+ H.value = R();
1136
+ }, O = (e) => {
1137
+ var s, n;
1138
+ return !e || typeof e != "object" || e.version !== "v0.9" || [
1139
+ e.createSurface,
1140
+ e.updateComponents,
1141
+ e.updateDataModel,
1142
+ e.deleteSurface
1143
+ ].filter(Boolean).length !== 1 ? !1 : e.createSurface ? we(e.createSurface) : e.updateComponents ? _e(e.updateComponents) : e.updateDataModel ? typeof ((s = _(e.updateDataModel)) == null ? void 0 : s.surfaceId) == "string" : e.deleteSurface ? typeof ((n = _(e.deleteSurface)) == null ? void 0 : n.surfaceId) == "string" : !1;
1144
+ }, _ = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : null, we = (e) => {
1145
+ const t = _(e);
1146
+ if (!t) return !1;
1147
+ const s = Object.keys(t);
1148
+ return typeof t.surfaceId == "string" && typeof t.catalogId == "string" && s.every((n) => n === "surfaceId" || n === "catalogId");
1149
+ }, z = (e) => Array.isArray(e) ? e.every((t) => {
1150
+ const s = _(t);
1151
+ return !!(s && typeof s.label == "string" && typeof s.value == "string");
1152
+ }) : !1, re = (e) => Array.isArray(e) && e.every((t) => typeof t == "string"), me = (e) => Array.isArray(e) ? e.every((t) => {
1153
+ const s = _(t);
1154
+ return !!(s && typeof s.label == "string" && typeof s.value == "string");
1155
+ }) : !1, ke = (e) => {
1156
+ const t = _(e);
1157
+ return !(!t || typeof t.id != "string" || typeof t.component != "string" || Object.prototype.hasOwnProperty.call(t, "props") || Object.prototype.hasOwnProperty.call(t, "componentType") || Object.prototype.hasOwnProperty.call(t, "component_type") || t.facts !== void 0 && !z(t.facts) || t.tags !== void 0 && !re(t.tags) || ["policyOptions", "audienceOptions", "detailOptions"].some(
1158
+ (n) => t[n] !== void 0 && !me(t[n])
1159
+ ));
1160
+ }, _e = (e) => {
1161
+ const t = _(e);
1162
+ return !t || typeof t.surfaceId != "string" || !Array.isArray(t.components) || t.components.length === 0 ? !1 : t.components.every(ke);
1163
+ }, X = (e) => {
1164
+ const t = e.trim();
1165
+ if (!t) return null;
1166
+ const s = t.match(/^```(?:json|a2ui|agui|ag-ui)?\s*([\s\S]*?)\s*```$/i), n = s ? s[1].trim() : t;
1167
+ if (!n.startsWith("{") && !n.startsWith("[")) return null;
1168
+ try {
1169
+ return JSON.parse(n);
1170
+ } catch {
1171
+ return null;
1172
+ }
1173
+ }, ee = (e) => {
1174
+ if (typeof e != "string") return null;
1175
+ const t = e.trim().toLowerCase();
1176
+ return t === "text_only" || t === "text-only" || t === "text" ? "text_only" : t === "ui_only" || t === "ui-only" || t === "ui" ? "ui_only" : t === "text_and_ui" || t === "text-and-ui" || t === "text+ui" || t === "both" ? "text_and_ui" : null;
1177
+ }, q = (e) => {
1178
+ const t = ee(e);
1179
+ if (t) return t;
1180
+ if (typeof e == "string") {
1181
+ const n = X(e);
1182
+ return n ? q(n) : null;
1183
+ }
1184
+ if (Array.isArray(e)) {
1185
+ for (const n of e) {
1186
+ const v = q(n);
1187
+ if (v) return v;
1188
+ }
1189
+ return null;
1190
+ }
1191
+ const s = _(e);
1192
+ return s && (ee(s.displayMode) || ee(s.display_mode) || ee(s.a2uiDisplayMode) || ee(s.a2ui_display_mode) || q(s.metadata) || q(s.payload) || q(s.data)) || null;
1193
+ }, T = (e) => {
1194
+ if (!e) return [];
1195
+ if (typeof e == "string") {
1196
+ const v = X(e);
1197
+ return v ? T(v) : Array.from(
1198
+ e.matchAll(/```(?:agui|ag-ui|a2ui|json)\s*\n([\s\S]*?)\n```/gi)
1199
+ ).flatMap((E) => {
1200
+ const P = X(E[1]);
1201
+ return P ? T(P) : [];
1202
+ });
1203
+ }
1204
+ if (Array.isArray(e)) {
1205
+ const v = e.map((E) => _(E)).filter((E) => !!E);
1206
+ return v.length === e.length && v.every(O) ? v : te(e);
1207
+ }
1208
+ if (typeof e != "object") return [];
1209
+ const t = e;
1210
+ if (O(t)) return [t];
1211
+ const s = te(t);
1212
+ if (s.length > 0) return s;
1213
+ const n = h(t);
1214
+ return n.length > 0 ? n : [];
1215
+ }, te = (e) => {
1216
+ if (!e) return [];
1217
+ if (typeof e == "string") {
1218
+ const s = X(e);
1219
+ return s ? te(s) : [];
1220
+ }
1221
+ if (typeof e != "object") return [];
1222
+ if (Array.isArray(e))
1223
+ return e.map((n) => _(n)).filter((n) => !!n).flatMap(G);
1224
+ const t = e;
1225
+ return t.protocol === "ag-ui" ? te(t.aguiEvents || t.agui_events) : Ae(t) ? G(t) : [];
1226
+ }, Ae = (e) => {
1227
+ const t = String(e.type || "").toUpperCase();
1228
+ return t ? t === "STATE_SNAPSHOT" ? Q(e.state).length > 0 : t === "STATE_DELTA" ? Q(e.delta).length > 0 : !0 : !1;
1229
+ }, G = (e) => {
1230
+ const t = String(e.type || "").toUpperCase();
1231
+ if (t === "STATE_SNAPSHOT") {
1232
+ const s = Q(e.state);
1233
+ return s.length > 0 ? s : f(e);
1234
+ }
1235
+ if (t === "STATE_DELTA") {
1236
+ const s = Q(e.delta);
1237
+ return s.length > 0 ? s : f(e);
1238
+ }
1239
+ return [];
1240
+ }, Q = (e) => {
1241
+ const t = _(e);
1242
+ return t ? [
1243
+ ...T(t.a2uiMessages),
1244
+ ...T(t.a2ui_messages),
1245
+ ...T(t.a2ui)
1246
+ ] : [];
1247
+ }, i = (e) => {
1248
+ const t = _(e);
1249
+ return t ? G(t) : [];
1250
+ }, f = (e) => [
1251
+ ...i(e.rawEvent),
1252
+ ...i(e.raw_event)
1253
+ ], h = (e) => {
1254
+ const t = [
1255
+ e.value,
1256
+ e.metadata,
1257
+ e.payload,
1258
+ e.data,
1259
+ e.a2uiMessages,
1260
+ e.a2ui_messages,
1261
+ e.a2ui,
1262
+ e.aguiEvents,
1263
+ e.agui_events,
1264
+ e.agui
1265
+ ];
1266
+ for (const s of t) {
1267
+ if (s === void 0 || s === e) continue;
1268
+ const n = T(s);
1269
+ if (n.length > 0) return n;
1270
+ }
1271
+ return [];
1272
+ }, I = (e) => [
1273
+ ...T(e.a2ui),
1274
+ ...T(e.a2uiMessage),
1275
+ ...T(e.a2uiMessages),
1276
+ ...T(e.a2ui_message),
1277
+ ...T(e.a2ui_messages),
1278
+ ...T(e.agui),
1279
+ ...T(e.aguiEvents),
1280
+ ...T(e.agui_events),
1281
+ ...T(e.metadata),
1282
+ ...T(e.content)
1283
+ ], F = (e) => q(e.displayMode) || q(e.display_mode) || q(e.a2uiDisplayMode) || q(e.a2ui_display_mode) || q(e.metadata) || null, ve = (e) => {
1284
+ var t, s, n, v;
1285
+ return ((t = e == null ? void 0 : e.createSurface) == null ? void 0 : t.surfaceId) || ((s = e == null ? void 0 : e.updateComponents) == null ? void 0 : s.surfaceId) || ((n = e == null ? void 0 : e.updateDataModel) == null ? void 0 : n.surfaceId) || ((v = e == null ? void 0 : e.deleteSurface) == null ? void 0 : v.surfaceId) || null;
1286
+ }, fe = (e, t) => String(e.id || `index-${t}`), ie = (e, t, s = !1) => {
1287
+ const n = { ...k.value }, v = { ...D.value }, E = s ? new Set(v[e] || []) : /* @__PURE__ */ new Set();
1288
+ for (const P of t) {
1289
+ const j = ve(P);
1290
+ j && (n[j] = e, E.add(j));
1291
+ }
1292
+ v[e] = Array.from(E), k.value = n, D.value = v;
1293
+ }, $e = () => {
1294
+ if (L.clearSurfaces(), D.value = {}, k.value = {}, !m.enableA2UI) return;
1295
+ const e = [];
1296
+ if (m.messages.forEach((t, s) => {
1297
+ const n = I(t);
1298
+ if (n.length === 0) return;
1299
+ const v = fe(t, s);
1300
+ ie(v, n), e.push(...n);
1301
+ }), e.length !== 0)
1302
+ try {
1303
+ L.processMessages(e);
1304
+ } catch (t) {
1305
+ console.warn("[rt-chat-messages] A2UI payload render failed", t), A("a2ui-error", t);
1306
+ }
1307
+ }, se = (e, t) => {
1308
+ if (!m.enableA2UI) return [];
1309
+ if (F(e) === "text_only") return [];
1310
+ const n = fe(e, t);
1311
+ return (D.value[n] || []).filter(
1312
+ (v) => k.value[v] === n
1313
+ );
1314
+ }, ae = (e) => {
1315
+ const t = typeof e.content == "string" ? e.content.trimStart() : "";
1316
+ if (!t || I(e).length > 0) return !1;
1317
+ const s = t.match(/^```([^\s\n`]*)?/);
1318
+ if (!s) return !1;
1319
+ const n = (s[1] || "").toLowerCase();
1320
+ return n ? ["a", "ag", "agu", "agui", "ag-", "ag-u", "ag-ui", "a2", "a2u", "a2ui"].includes(n) : !1;
1321
+ }, ne = (e, t) => !!(m.enableA2UI && m.showA2UISkeleton && m.isStreaming && t === m.messages.length - 1 && se(e, t).length === 0 && ae(e)), Z = (e, t) => {
1322
+ if (!m.hideA2UIRawContent || e.attachments && e.attachments.length > 0) return !0;
1323
+ if (ae(e) || !e.content) return !1;
1324
+ if (I(e).length === 0) return !0;
1325
+ const n = F(e);
1326
+ return n === "text_only" || n === "text_and_ui" ? !0 : n === "ui_only" ? !1 : se(e, t).length === 0;
1327
+ }, xe = async (e) => {
1328
+ var s;
1329
+ const t = (s = e == null ? void 0 : e.message) == null ? void 0 : s.action;
1330
+ A("a2ui-action", t, e);
1331
+ try {
1332
+ const n = m.a2uiActionHandler ? await m.a2uiActionHandler(e) : [], v = T(n);
1333
+ if (v.length > 0) {
1334
+ const E = k.value[t == null ? void 0 : t.surfaceId];
1335
+ E && ie(E, v, !0), L.processMessages(v), m.autoScroll && !x.value && (await oe(), ue("smooth"));
1336
+ }
1337
+ e.resolve(v);
1338
+ } catch (n) {
1339
+ A("a2ui-error", n), e.reject(n instanceof Error ? n : new Error(String(n)));
1340
+ }
1019
1341
  };
1020
- J(
1021
- () => i.messages.length,
1022
- async (d, M) => {
1023
- d > (M || 0) && (E.value = !1), i.autoScroll && !E.value && x();
1342
+ let ce = 0, ge = !1;
1343
+ const Te = () => {
1344
+ R() || (H.value = !1, x.value = !0);
1345
+ }, ue = async (e = "smooth", t = !1) => {
1346
+ if (await oe(), $.value) {
1347
+ if (t && (x.value = !1), x.value) return;
1348
+ H.value = !0, ge = !0, $.value.scrollTo({
1349
+ top: $.value.scrollHeight,
1350
+ behavior: e
1351
+ }), setTimeout(() => {
1352
+ ge = !1;
1353
+ }, 50);
1024
1354
  }
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({
1355
+ }, Be = (e) => {
1356
+ if (A("scroll", e), !$.value) return;
1357
+ const t = $.value.scrollTop, s = t < ce;
1358
+ ce = t, !ge && s && (x.value = !0, H.value = !1), R() && (H.value = !0, x.value = !1, A("scroll-bottom"));
1359
+ };
1360
+ ye(
1361
+ () => m.messages.length,
1362
+ async (e, t) => {
1363
+ e > (t || 0) && (x.value = !1, m.autoScroll && ue("instant"));
1364
+ }
1365
+ ), ye(
1366
+ () => [m.messages, m.enableA2UI],
1367
+ $e,
1368
+ { deep: !0, immediate: !0 }
1369
+ );
1370
+ let a = null;
1371
+ ye(
1372
+ () => m.messages,
1373
+ async () => {
1374
+ if (!m.isStreaming || !m.autoScroll || x.value || document.hidden)
1375
+ return;
1376
+ const e = m.messages[m.messages.length - 1];
1377
+ !e || e.role !== "assistant" || (a && cancelAnimationFrame(a), a = requestAnimationFrame(async () => {
1378
+ await oe(), $.value && !x.value && $.value.scrollTo({
1034
1379
  top: $.value.scrollHeight,
1035
1380
  behavior: "instant"
1036
1381
  });
1037
- }
1038
- }
1039
- ), J(
1040
- () => i.isTyping,
1041
- (d) => {
1042
- d && i.autoScroll && x();
1382
+ }));
1383
+ },
1384
+ { deep: !0 }
1385
+ ), ye(
1386
+ () => m.isTyping,
1387
+ (e) => {
1388
+ e && m.autoScroll && ue("instant");
1043
1389
  }
1044
1390
  );
1045
- const _ = (d) => {
1046
- z("copy", d), navigator.clipboard && d.content && navigator.clipboard.writeText(d.content);
1391
+ const o = (e) => {
1392
+ A("copy", e), navigator.clipboard && e.content && navigator.clipboard.writeText(e.content);
1047
1393
  };
1048
- J(
1049
- () => i.agentSteps,
1394
+ ye(
1395
+ () => m.agentSteps,
1050
1396
  () => {
1051
- i.autoScroll && !E.value && x();
1397
+ m.autoScroll && !x.value && ue();
1052
1398
  },
1053
1399
  { deep: !0 }
1054
1400
  );
1055
1401
  const c = () => {
1056
- i.autoScroll && !E.value && x();
1402
+ m.autoScroll && !x.value && ue();
1403
+ }, g = () => {
1404
+ !document.hidden && m.isStreaming && m.autoScroll && !x.value && oe(() => {
1405
+ $.value && ($.value.scrollTo({
1406
+ top: $.value.scrollHeight,
1407
+ behavior: "instant"
1408
+ }), H.value = !0);
1409
+ });
1057
1410
  };
1058
- return p({
1059
- scrollToBottom: x,
1411
+ let u;
1412
+ return Ve(() => {
1413
+ S(), u = L.onEvent(xe), document.addEventListener("visibilitychange", g);
1414
+ }), He(() => {
1415
+ u == null || u(), document.removeEventListener("visibilitychange", g);
1416
+ }), y({
1417
+ scrollToBottom: ue,
1060
1418
  containerRef: $
1061
- }), (d, M) => (o(), u("div", ms, [
1062
- n.showBackground ? (o(), u("div", vs)) : D("", !0),
1063
- a("div", {
1419
+ }), (e, t) => (d(), p("div", _s, [
1420
+ r.showBackground ? (d(), p("div", As)) : B("", !0),
1421
+ l("div", {
1064
1422
  class: "chat-message-list",
1065
1423
  ref_key: "containerRef",
1066
1424
  ref: $,
1067
- onScroll: T,
1068
- style: ve({
1069
- paddingTop: n.contentPaddingTop,
1070
- paddingBottom: n.contentPaddingBottom
1425
+ onScroll: Be,
1426
+ onWheel: Te,
1427
+ onTouchmove: Te,
1428
+ style: be({
1429
+ paddingTop: r.contentPaddingTop,
1430
+ paddingBottom: r.contentPaddingBottom
1071
1431
  })
1072
1432
  }, [
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", {
1433
+ r.showWelcome && r.messages.length === 0 ? (d(), p("div", $s, [
1434
+ Fe(e.$slots, "welcome", {}, () => [
1435
+ l("div", xs, [
1436
+ l("div", Is, [
1437
+ r.appLogo ? (d(), p("img", {
1078
1438
  key: 0,
1079
- src: n.appLogo,
1439
+ src: r.appLogo,
1080
1440
  alt: "Logo"
1081
- }, null, 8, ps)) : (o(), u("div", ys, [...M[0] || (M[0] = [
1082
- a("svg", {
1441
+ }, null, 8, Ls)) : (d(), p("div", zs, [...t[1] || (t[1] = [
1442
+ l("svg", {
1083
1443
  viewBox: "0 0 1024 1024",
1084
1444
  width: "32",
1085
1445
  height: "32"
1086
1446
  }, [
1087
- a("path", {
1447
+ l("path", {
1088
1448
  fill: "currentColor",
1089
1449
  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
1450
  })
1091
1451
  ], -1)
1092
1452
  ])]))
1093
1453
  ]),
1094
- a("h2", ws, F(n.appName), 1),
1095
- M[1] || (M[1] = a("p", { class: "welcome-desc" }, "今天有什么可以帮您?", -1))
1454
+ l("h2", Es, N(r.appName), 1),
1455
+ t[2] || (t[2] = l("p", { class: "welcome-desc" }, "今天有什么可以帮您?", -1))
1096
1456
  ])
1097
1457
  ], !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,
1458
+ ])) : (d(), p("div", Us, [
1459
+ (d(!0), p(ze, null, Ee(r.messages, (s, n) => (d(), p("div", {
1460
+ key: s.id || n,
1101
1461
  class: le([
1102
1462
  "message-row",
1103
- L.role === "user" ? "message-user" : "message-assistant"
1463
+ s.role === "user" ? "message-user" : "message-assistant"
1104
1464
  ])
1105
1465
  }, [
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, {
1466
+ s.role === "user" ? (d(), p("div", Ts, [
1467
+ l("div", Bs, [
1468
+ M(Re, {
1469
+ message: s,
1470
+ "is-user": !0,
1471
+ "api-base-url": r.apiBaseUrl
1472
+ }, null, 8, ["message", "api-base-url"])
1473
+ ]),
1474
+ s.content ? (d(), p("div", Hs, [
1475
+ l("button", {
1476
+ class: "action-btn",
1477
+ onClick: (v) => o(s),
1478
+ title: "复制"
1479
+ }, [...t[3] || (t[3] = [
1480
+ l("svg", {
1481
+ viewBox: "0 0 1024 1024",
1482
+ width: "12",
1483
+ height: "12"
1484
+ }, [
1485
+ l("path", {
1486
+ fill: "currentColor",
1487
+ 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"
1488
+ })
1489
+ ], -1),
1490
+ l("span", null, "复制", -1)
1491
+ ])], 8, Ds)
1492
+ ])) : B("", !0)
1493
+ ])) : (d(), p("div", Ps, [
1494
+ r.showAgentSteps && n === r.messages.length - 1 && r.agentSteps && r.agentSteps.length > 0 ? (d(), de(Ge, {
1113
1495
  key: 0,
1114
- steps: n.agentSteps,
1496
+ steps: r.agentSteps,
1115
1497
  onResize: c
1116
- }, null, 8, ["steps"])) : D("", !0),
1117
- a("div", bs, [
1118
- f(Ce, {
1119
- message: L,
1498
+ }, null, 8, ["steps"])) : B("", !0),
1499
+ l("div", {
1500
+ class: le(["message-bubble assistant-bubble", { "assistant-bubble-a2ui": se(s, n).length > 0 }])
1501
+ }, [
1502
+ Z(s, n) ? (d(), de(Re, {
1503
+ key: 0,
1504
+ message: s,
1120
1505
  "is-user": !1,
1121
- "is-streaming": n.isStreaming && S === n.messages.length - 1
1122
- }, null, 8, ["message", "is-streaming"])
1123
- ]),
1124
- L.content && !(n.isStreaming && S === n.messages.length - 1) ? (o(), u("div", _s, [
1125
- a("button", {
1506
+ "api-base-url": r.apiBaseUrl,
1507
+ "is-streaming": r.isStreaming && n === r.messages.length - 1
1508
+ }, null, 8, ["message", "api-base-url", "is-streaming"])) : B("", !0),
1509
+ se(s, n).length > 0 ? (d(), p("div", {
1510
+ key: 1,
1511
+ class: le(["a2ui-surfaces", { "a2ui-surfaces-with-content": Z(s, n) }])
1512
+ }, [
1513
+ (d(!0), p(ze, null, Ee(se(s, n), (v) => (d(), de(U(ut), {
1514
+ key: v,
1515
+ "surface-id": v
1516
+ }, null, 8, ["surface-id"]))), 128))
1517
+ ], 2)) : B("", !0),
1518
+ ne(s, n) ? (d(), p("div", Rs, [...t[4] || (t[4] = [
1519
+ lt('<div class="skeleton-header" data-v-eac8b914><div class="skeleton-avatar skeleton-shimmer" data-v-eac8b914></div><div class="skeleton-title-group" data-v-eac8b914><div class="skeleton-line skeleton-title skeleton-shimmer" data-v-eac8b914></div><div class="skeleton-line skeleton-subtitle skeleton-shimmer" data-v-eac8b914></div></div></div><div class="skeleton-line skeleton-summary skeleton-shimmer" data-v-eac8b914></div><div class="skeleton-line skeleton-summary short skeleton-shimmer" data-v-eac8b914></div><div class="skeleton-facts" data-v-eac8b914><div class="skeleton-fact skeleton-shimmer" data-v-eac8b914></div><div class="skeleton-fact skeleton-shimmer" data-v-eac8b914></div><div class="skeleton-fact skeleton-shimmer" data-v-eac8b914></div></div>', 4)
1520
+ ])])) : B("", !0)
1521
+ ], 2),
1522
+ Z(s, n) && s.content && !(r.isStreaming && n === r.messages.length - 1) ? (d(), p("div", Vs, [
1523
+ l("button", {
1126
1524
  class: "action-btn",
1127
- onClick: (C) => _(L),
1525
+ onClick: (v) => o(s),
1128
1526
  title: "复制"
1129
- }, [...M[2] || (M[2] = [
1130
- a("svg", {
1527
+ }, [...t[5] || (t[5] = [
1528
+ l("svg", {
1131
1529
  viewBox: "0 0 1024 1024",
1132
1530
  width: "12",
1133
1531
  height: "12"
1134
1532
  }, [
1135
- a("path", {
1533
+ l("path", {
1136
1534
  fill: "currentColor",
1137
1535
  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
1536
  })
1139
1537
  ], -1),
1140
- a("span", null, "复制", -1)
1141
- ])], 8, $s)
1142
- ])) : D("", !0)
1538
+ l("span", null, "复制", -1)
1539
+ ])], 8, Fs)
1540
+ ])) : B("", !0)
1143
1541
  ]))
1144
1542
  ], 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", {
1543
+ r.isTyping ? (d(), p("div", Os, [...t[6] || (t[6] = [
1544
+ l("div", { class: "typing-indicator" }, [
1545
+ l("div", { class: "typing-dot" }),
1546
+ l("div", {
1149
1547
  class: "typing-dot",
1150
1548
  style: { "animation-delay": "0.2s" }
1151
1549
  }),
1152
- a("div", {
1550
+ l("div", {
1153
1551
  class: "typing-dot",
1154
1552
  style: { "animation-delay": "0.4s" }
1155
1553
  })
1156
1554
  ], -1)
1157
- ])])) : D("", !0)
1555
+ ])])) : B("", !0)
1158
1556
  ]))
1159
- ], 36)
1557
+ ], 36),
1558
+ M(rt, { name: "fade-slide" }, {
1559
+ default: W(() => [
1560
+ H.value ? B("", !0) : (d(), p("button", {
1561
+ key: 0,
1562
+ class: "scroll-to-bottom-btn",
1563
+ style: be({ bottom: `calc(${r.contentPaddingBottom || "140px"} + 20px)` }),
1564
+ onClick: t[0] || (t[0] = (s) => ue("smooth", !0))
1565
+ }, [
1566
+ t[8] || (t[8] = l("div", { class: "btn-inner" }, [
1567
+ l("svg", {
1568
+ class: "arrow-icon",
1569
+ viewBox: "0 0 24 24",
1570
+ fill: "none",
1571
+ stroke: "currentColor"
1572
+ }, [
1573
+ l("path", {
1574
+ "stroke-linecap": "round",
1575
+ "stroke-linejoin": "round",
1576
+ "stroke-width": "2.5",
1577
+ d: "M19 9l-7 7-7-7"
1578
+ })
1579
+ ])
1580
+ ], -1)),
1581
+ r.isStreaming ? (d(), p("svg", Ws, [...t[7] || (t[7] = [
1582
+ l("circle", {
1583
+ class: "loading-circle",
1584
+ cx: "18",
1585
+ cy: "18",
1586
+ r: "16"
1587
+ }, null, -1)
1588
+ ])])) : B("", !0)
1589
+ ], 4))
1590
+ ]),
1591
+ _: 1
1592
+ })
1160
1593
  ]));
1161
1594
  }
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);
1595
+ }), Ys = /* @__PURE__ */ Ce(js, [["__scopeId", "data-v-eac8b914"]]), Js = {
1596
+ install(r) {
1597
+ r.component("ChatMessageList", Ys), r.component("MultimodalMessage", Re), r.component("MarkdownMessage", Je), r.component("AgentSteps", Ge);
1165
1598
  }
1166
1599
  };
1167
1600
  export {
1168
- Ne as AgentSteps,
1169
- zs as ChatMessageList,
1170
- Fe as MarkdownMessage,
1171
- Ce as MultimodalMessage,
1172
- As as default
1601
+ Ge as AgentSteps,
1602
+ Ys as ChatMessageList,
1603
+ Je as MarkdownMessage,
1604
+ Re as MultimodalMessage,
1605
+ Js as default
1173
1606
  };