@opentiny/tiny-robot 0.4.0-alpha.3 → 0.4.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index2.js CHANGED
@@ -1,450 +1,491 @@
1
- import { defineComponent as E, createElementBlock as R, openBlock as _, renderSlot as x, ref as A, computed as g, watch as Z, unref as B, normalizeClass as V, createVNode as W, watchEffect as z, Fragment as D, createElementVNode as h, createBlock as k, withDirectives as ee, toDisplayString as X, vShow as te, resolveDynamicComponent as U, normalizeProps as F, guardReactiveProps as G, createCommentVNode as ae, useCssModule as Ye, renderList as J, mergeProps as P, markRaw as w, inject as L, provide as M, toValue as S, reactive as Je, withCtx as $, onMounted as ve, onUnmounted as Ve, nextTick as he } from "vue";
2
- import { _ as N } from "./_plugin-vue_export-helper.js";
3
- import { IconLoading as ye, IconAtom as We, IconArrowDown as Re, IconPlugin as me, IconError as ze, IconCancelled as Xe } from "@opentiny/tiny-robot-svgs";
4
- import { u as je, a as qe, w as Ze, b as Qe } from "./index5.js";
5
- const xe = Symbol("bubble-message-group"), Be = Symbol("bubble-box-renderer-matches"), Ce = Symbol("bubble-box-fallback-renderer"), Ee = Symbol(
1
+ import { defineComponent as E, createElementBlock as x, openBlock as b, renderSlot as B, ref as T, computed as v, watch as H, unref as R, normalizeClass as j, createVNode as z, watchEffect as Z, nextTick as ne, Fragment as D, createElementVNode as h, createBlock as k, withDirectives as ee, toDisplayString as V, vShow as te, resolveDynamicComponent as Y, normalizeProps as F, guardReactiveProps as G, createCommentVNode as le, useCssModule as Je, renderList as W, mergeProps as P, markRaw as w, inject as L, provide as $, toValue as S, reactive as We, readonly as je, withCtx as M, onMounted as ye, onUnmounted as ze } from "vue";
2
+ import { _ as A } from "./_plugin-vue_export-helper.js";
3
+ import { IconLoading as Re, IconAtom as Ve, IconArrowDown as xe, IconPlugin as _e, IconError as Xe, IconCancelled as qe } from "@opentiny/tiny-robot-svgs";
4
+ import { u as Ze, a as Qe, w as et, b as tt } from "./index5.js";
5
+ const Be = Symbol("bubble-message-group"), Ce = Symbol("bubble-box-renderer-matches"), Ee = Symbol("bubble-box-fallback-renderer"), ke = Symbol(
6
6
  "bubble-box-prop-fallback-renderer"
7
- ), ke = Symbol("bubble-content-renderer-matches"), Ie = Symbol(
7
+ ), Ie = Symbol("bubble-content-renderer-matches"), Se = Symbol(
8
8
  "bubble-content-fallback-renderer"
9
- ), Se = Symbol(
9
+ ), Le = Symbol(
10
10
  "bubble-content-prop-fallback-renderer"
11
- ), re = Symbol("bubble-store"), Le = Symbol("bubble-state-change-fn"), $e = Symbol("bubble-list-context"), H = {
11
+ ), ae = Symbol("bubble-store"), Te = Symbol("bubble-state-change-fn"), Me = Symbol("bubble-list-context"), K = {
12
12
  LOADING: -1,
13
13
  NORMAL: 0,
14
14
  CONTENT: 10,
15
15
  ROLE: 20
16
- }, et = {
16
+ }, nt = {
17
17
  class: "tr-bubble__box",
18
18
  "data-box-type": "box"
19
- }, tt = /* @__PURE__ */ E({
19
+ }, st = /* @__PURE__ */ E({
20
20
  __name: "Box",
21
21
  props: {
22
22
  placement: {},
23
23
  shape: {}
24
24
  },
25
- setup(t) {
26
- return (n, e) => (_(), R("div", et, [
27
- x(n.$slots, "default", {}, void 0, !0)
25
+ setup(e) {
26
+ return (t, n) => (b(), x("div", nt, [
27
+ B(t.$slots, "default", {}, void 0, !0)
28
28
  ]));
29
29
  }
30
- }), le = /* @__PURE__ */ N(tt, [["__scopeId", "data-v-98101726"]]), nt = ["src", "alt"], st = /* @__PURE__ */ E({
30
+ }), ce = /* @__PURE__ */ A(st, [["__scopeId", "data-v-98101726"]]), ot = ["src", "alt"], rt = /* @__PURE__ */ E({
31
31
  __name: "Image",
32
32
  props: {
33
33
  message: {},
34
34
  contentIndex: {}
35
35
  },
36
- setup(t) {
37
- const n = t, e = A(!1), s = A(!1), { contentItem: r } = fe(n), c = g(() => r.value ? typeof r.value.image_url == "string" ? r.value.image_url : r.value.image_url.url : null);
38
- Z(c, () => {
39
- e.value = !1, s.value = !1;
36
+ setup(e) {
37
+ const t = e, n = T(!1), s = T(!1), { contentItem: r } = pe(t), u = v(() => r.value ? typeof r.value.image_url == "string" ? r.value.image_url : r.value.image_url.url : null);
38
+ H(u, () => {
39
+ n.value = !1, s.value = !1;
40
40
  });
41
- const a = () => {
42
- e.value = !0, s.value = !1;
43
- }, u = () => {
44
- s.value = !0, e.value = !0;
41
+ const o = () => {
42
+ n.value = !0, s.value = !1;
43
+ }, a = () => {
44
+ s.value = !0, n.value = !0;
45
45
  };
46
- return (b, y) => {
47
- var I;
48
- return _(), R("img", {
49
- class: V(["tr-bubble__image", { loading: !e.value }]),
50
- src: c.value,
51
- alt: (I = B(r)) == null ? void 0 : I.text,
46
+ return (d, g) => {
47
+ var y;
48
+ return b(), x("img", {
49
+ class: j(["tr-bubble__image", { loading: !n.value }]),
50
+ src: u.value,
51
+ alt: (y = R(r)) == null ? void 0 : y.text,
52
52
  loading: "lazy",
53
- onLoad: a,
54
- onError: u,
53
+ onLoad: o,
54
+ onError: a,
55
55
  "data-type": "image"
56
- }, null, 42, nt);
56
+ }, null, 42, ot);
57
57
  };
58
58
  }
59
- }), Me = /* @__PURE__ */ N(st, [["__scopeId", "data-v-02161cd1"]]), ot = {
59
+ }), $e = /* @__PURE__ */ A(rt, [["__scopeId", "data-v-02161cd1"]]), at = {
60
60
  class: "tr-bubble__loading",
61
61
  "data-type": "loading"
62
- }, rt = /* @__PURE__ */ E({
62
+ }, lt = /* @__PURE__ */ E({
63
63
  __name: "Loading",
64
64
  props: {
65
65
  message: {},
66
66
  contentIndex: {}
67
67
  },
68
- setup(t) {
69
- return (n, e) => (_(), R("div", ot, [
70
- W(B(ye))
68
+ setup(e) {
69
+ return (t, n) => (b(), x("div", at, [
70
+ z(R(Re))
71
71
  ]));
72
72
  }
73
- }), Te = /* @__PURE__ */ N(rt, [["__scopeId", "data-v-bc1b5ff4"]]), at = {
73
+ }), Ae = /* @__PURE__ */ A(lt, [["__scopeId", "data-v-bc1b5ff4"]]), ct = {
74
74
  class: "tr-bubble__reasoning",
75
75
  "data-type": "reasoning"
76
- }, lt = { class: "title" }, ct = { class: "detail" }, ut = { class: "detail" }, it = /* @__PURE__ */ E({
76
+ }, ut = { class: "title" }, it = { class: "detail" }, dt = /* @__PURE__ */ E({
77
77
  __name: "Reasoning",
78
78
  props: {
79
79
  message: {},
80
80
  contentIndex: {}
81
81
  },
82
- setup(t) {
83
- const n = t, { restMessage: e, restProps: s } = Ue(n, ["reasoning_content"]), r = ue(e, n.contentIndex), c = A(!1);
84
- z(() => {
85
- var b;
86
- c.value = ((b = n.message.state) == null ? void 0 : b.open) ?? !1;
82
+ setup(e) {
83
+ const t = e, { restMessage: n, restProps: s } = Ye(t, ["reasoning_content"]), r = ie(n, t.contentIndex), u = T(!1);
84
+ Z(() => {
85
+ var g;
86
+ u.value = ((g = t.message.state) == null ? void 0 : g.open) ?? !1;
87
87
  });
88
- const a = He(), u = () => {
89
- c.value = !c.value, a("open", c.value);
90
- };
91
- return (b, y) => {
92
- var I;
93
- return _(), R(D, null, [
94
- h("div", at, [
88
+ const o = Ke(), a = () => {
89
+ u.value = !u.value, o("open", u.value);
90
+ }, d = T(null);
91
+ return H(
92
+ () => t.message.reasoning_content,
93
+ () => {
94
+ ne(() => {
95
+ d.value && d.value.scrollTo({
96
+ top: d.value.scrollHeight,
97
+ behavior: "smooth"
98
+ });
99
+ });
100
+ }
101
+ ), (g, y) => {
102
+ var C;
103
+ return b(), x(D, null, [
104
+ h("div", ct, [
95
105
  h("div", {
96
106
  class: "header",
97
- onClick: u
107
+ onClick: a
98
108
  }, [
99
- W(B(We)),
100
- h("span", lt, X((I = n.message.state) != null && I.thinking ? "正在思考" : "已思考"), 1),
101
- W(B(Re), {
102
- class: V(["expand-icon", { "-rotate-90": !c.value }])
109
+ z(R(Ve)),
110
+ h("span", ut, V((C = t.message.state) != null && C.thinking ? "正在思考" : "已思考"), 1),
111
+ z(R(xe), {
112
+ class: j(["expand-icon", { "-rotate-90": !u.value }])
103
113
  }, null, 8, ["class"])
104
114
  ]),
105
- ee(h("div", ct, [
115
+ ee(h("div", it, [
106
116
  y[0] || (y[0] = h("div", { class: "side-border" }, [
107
117
  h("div", { class: "dot-wrapper" }, [
108
118
  h("div", { class: "dot" })
109
119
  ]),
110
120
  h("div", { class: "border-line" })
111
121
  ], -1)),
112
- h("p", ut, X(n.message.reasoning_content), 1)
122
+ h("p", {
123
+ class: "detail-content",
124
+ ref_key: "detailRef",
125
+ ref: d
126
+ }, V(t.message.reasoning_content), 513)
113
127
  ], 512), [
114
- [te, c.value]
128
+ [te, u.value]
115
129
  ])
116
130
  ]),
117
- (_(), k(U(B(r)), F(G(B(s))), null, 16))
131
+ (b(), k(Y(R(r)), F(G(R(s))), null, 16))
118
132
  ], 64);
119
133
  };
120
134
  }
121
- }), Ae = /* @__PURE__ */ N(it, [["__scopeId", "data-v-b7c07b23"]]), dt = {
135
+ }), Ne = /* @__PURE__ */ A(dt, [["__scopeId", "data-v-398dff88"]]), ft = {
122
136
  key: 0,
123
137
  class: "tr-bubble__text",
124
138
  "data-type": "text"
125
- }, ft = /* @__PURE__ */ E({
139
+ }, pt = /* @__PURE__ */ E({
126
140
  __name: "Text",
127
141
  props: {
128
142
  message: {},
129
143
  contentIndex: {}
130
144
  },
131
- setup(t) {
132
- const n = t, { contentText: e } = fe(n);
133
- return (s, r) => B(e) ? (_(), R("p", dt, X(B(e)), 1)) : ae("", !0);
145
+ setup(e) {
146
+ const t = e, { contentText: n } = pe(t);
147
+ return (s, r) => R(n) ? (b(), x("p", ft, V(R(n)), 1)) : le("", !0);
134
148
  }
135
- }), ce = /* @__PURE__ */ N(ft, [["__scopeId", "data-v-93592ecb"]]), Ne = /* @__PURE__ */ E({
149
+ }), ue = /* @__PURE__ */ A(pt, [["__scopeId", "data-v-93592ecb"]]), Oe = /* @__PURE__ */ E({
136
150
  __name: "ToolRole",
137
151
  props: {
138
152
  message: {},
139
153
  contentIndex: {}
140
154
  },
141
- setup(t) {
142
- const n = t, e = de();
143
- return z(() => {
144
- n.message.tool_call_id && (e.toolCallResults || (e.toolCallResults = {}), e.toolCallResults[n.message.tool_call_id] = n.message.content ?? "");
145
- }), (s, r) => ae("", !0);
155
+ setup(e) {
156
+ const t = e, n = fe();
157
+ return Z(() => {
158
+ t.message.tool_call_id && (n.toolCallResults || (n.toolCallResults = {}), n.toolCallResults[t.message.tool_call_id] = t.message.content ?? "");
159
+ }), (s, r) => le("", !0);
146
160
  }
147
- });
148
- let se = null;
149
- const pt = () => (se || (se = import("./index4.js")), se);
150
- let Y = null;
151
- const mt = async () => {
152
- if (Y)
153
- return Y;
154
- try {
155
- const [t, n] = await Promise.all([import("markdown-it"), import("dompurify")]);
156
- return Y = { markdown: t.default, dompurify: n.default }, Y;
157
- } catch {
158
- return console.warn("[BubbleMarkdownRenderer] install markdown-it and dompurify to use markdown renderer"), Y = null, null;
159
- }
160
- }, _t = {
161
+ }), mt = {
161
162
  class: "tr-bubble__tool-call",
162
163
  "data-type": "tool-call"
163
- }, bt = { class: "header" }, gt = { class: "header-left" }, vt = { class: "title" }, ht = { class: "header-right" }, yt = { class: "divider" }, Rt = ["innerHTML"], xt = /* @__PURE__ */ E({
164
+ }, _t = { class: "header" }, bt = { class: "header-left" }, gt = { class: "title" }, vt = { class: "header-right" }, ht = { class: "divider" }, yt = ["innerHTML"], Rt = /* @__PURE__ */ E({
164
165
  __name: "Tool",
165
166
  props: {
166
167
  message: {},
167
168
  contentIndex: {},
168
- toolIndex: {}
169
+ toolCallIndex: {}
169
170
  },
170
- setup(t) {
171
- const n = ["running", "success", "failed", "cancelled"], e = t, s = g(() => {
172
- var o, l;
173
- return (l = (o = e.message) == null ? void 0 : o.tool_calls) == null ? void 0 : l[e.toolIndex];
174
- }), r = g(() => {
175
- var l, f, v;
176
- const o = (l = s.value) == null ? void 0 : l.id;
177
- return o ? (v = (f = e.message.state) == null ? void 0 : f.toolCall) == null ? void 0 : v[o] : null;
178
- }), c = de(), a = g(() => {
179
- var l;
180
- const o = (l = r.value) == null ? void 0 : l.status;
181
- return o && n.includes(o) ? o : c.toolCallDefaultStatus && n.includes(c.toolCallDefaultStatus) ? c.toolCallDefaultStatus : "";
182
- }), u = /* @__PURE__ */ new Map([
183
- ["running", { text: "正在调用", icon: ye }],
184
- ["success", { text: "已调用", icon: me }],
185
- ["failed", { text: "调用失败", icon: ze }],
186
- ["cancelled", { text: "已取消", icon: Xe }]
187
- ]), b = g(() => u.get(a.value) || { text: "", icon: me }), y = Ye(), I = (o, l = 2) => {
188
- if (!o)
189
- return "";
190
- let f = "";
171
+ setup(e) {
172
+ const t = e, { toolCall: n, toolCallWithResult: s, state: r } = Ft(t), u = /* @__PURE__ */ new Map([
173
+ ["running", { text: "正在调用", icon: Re }],
174
+ ["success", { text: "已调用", icon: _e }],
175
+ ["failed", { text: "调用失败", icon: Xe }],
176
+ ["cancelled", { text: "已取消", icon: qe }]
177
+ ]), o = v(() => {
178
+ var c;
179
+ return u.get(((c = r.value) == null ? void 0 : c.status) || "") || { text: "", icon: _e };
180
+ }), a = (c, l = 2) => {
181
+ let m = "";
191
182
  try {
192
- typeof o == "string" ? f = JSON.stringify(JSON.parse(o), null, l) : f = JSON.stringify(o, null, l);
183
+ typeof c == "string" ? m = JSON.stringify(JSON.parse(c), null, l) : m = JSON.stringify(c, null, l);
193
184
  } catch {
194
185
  }
195
- return f = f.replace(
186
+ return m;
187
+ }, d = Je(), g = (c) => {
188
+ if (!c)
189
+ return "";
190
+ let l = c;
191
+ return l = l.replace(
196
192
  /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,
197
- (v) => {
198
- let C = "number";
199
- return /^"/.test(v) ? C = /:$/.test(v) ? "key" : "string" : /true|false/.test(v) ? C = "boolean" : /null/.test(v) && (C = "null"), `<span class="${y[C]}">${v}</span>`;
193
+ (m) => {
194
+ let I = "number";
195
+ return /^"/.test(m) ? I = /:$/.test(m) ? "key" : "string" : /true|false/.test(m) ? I = "boolean" : /null/.test(m) && (I = "null"), `<span class="${d[I]}">${m}</span>`;
200
196
  }
201
- ), f;
202
- }, T = A(""), m = g(() => {
203
- var l, f;
204
- const o = (l = s.value) == null ? void 0 : l.id;
205
- if (o)
206
- return (f = c.toolCallResults) == null ? void 0 : f[o];
207
- });
208
- z(() => {
209
- var f;
210
- const o = (f = s.value) == null ? void 0 : f.function.arguments, l = m.value;
211
- pt().then(({ jsonrepair: v }) => {
212
- const C = v(typeof o == "string" ? o || "{}" : JSON.stringify(o));
213
- T.value = I(
214
- {
215
- arguments: JSON.parse(C),
216
- result: l ? JSON.parse(v(l || "{}")) : void 0
217
- },
218
- 2
219
- );
220
- }).catch((v) => {
221
- console.warn(v);
197
+ ), l;
198
+ }, y = v(() => a(s.value, 2)), C = v(() => g(y.value)), f = T(null);
199
+ H(y, (c, l) => {
200
+ l === "" || l === "{}" || ne(() => {
201
+ f.value && f.value.scrollTo({
202
+ top: f.value.scrollHeight,
203
+ behavior: "smooth"
204
+ });
222
205
  });
223
206
  });
224
- const p = A(!1);
225
- z(() => {
226
- var o;
227
- p.value = !!(((o = r.value) == null ? void 0 : o.open) ?? c.toolCallDefaultOpen);
207
+ const p = T(!1);
208
+ Z(() => {
209
+ p.value = r.value.open ?? !1;
228
210
  });
229
- const i = He(), d = () => {
230
- var l, f;
211
+ const i = Ke(), _ = () => {
212
+ var l, m;
231
213
  p.value = !p.value;
232
- const o = (l = s.value) == null ? void 0 : l.id;
233
- o && i("toolCall", {
234
- ...(f = e.message.state) == null ? void 0 : f.toolCall,
235
- [o]: { ...r.value, open: p.value }
214
+ const c = (l = n.value) == null ? void 0 : l.id;
215
+ c && i("toolCall", {
216
+ ...(m = t.message.state) == null ? void 0 : m.toolCall,
217
+ [c]: { ...r.value, open: p.value }
236
218
  });
237
219
  };
238
- return (o, l) => {
239
- var f;
240
- return _(), R("div", _t, [
241
- h("div", bt, [
242
- h("div", gt, [
243
- (_(), k(U(b.value.icon), {
244
- class: V(["header-icon", `icon-${a.value}`])
220
+ return (c, l) => {
221
+ var m;
222
+ return b(), x("div", mt, [
223
+ h("div", _t, [
224
+ h("div", bt, [
225
+ (b(), k(Y(o.value.icon), {
226
+ class: j(["header-icon", `icon-${R(r).status}`])
245
227
  }, null, 8, ["class"])),
246
228
  h("span", null, [
247
- h("span", null, X(b.value.text) + " ", 1),
248
- h("span", vt, X(((f = s.value) == null ? void 0 : f.function.name) || "Untitled"), 1)
229
+ h("span", null, V(o.value.text) + " ", 1),
230
+ h("span", gt, V(((m = R(n)) == null ? void 0 : m.function.name) || "Untitled"), 1)
249
231
  ])
250
232
  ]),
251
- h("div", ht, [
252
- W(B(Re), {
253
- class: V(["expand-icon", { "-rotate-90": !p.value }]),
254
- onClick: d
233
+ h("div", vt, [
234
+ z(R(xe), {
235
+ class: j(["expand-icon", { "-rotate-90": !p.value }]),
236
+ onClick: _
255
237
  }, null, 8, ["class"])
256
238
  ])
257
239
  ]),
258
- ee(h("div", yt, null, 512), [
240
+ ee(h("div", ht, null, 512), [
259
241
  [te, p.value]
260
242
  ]),
261
243
  ee(h("div", {
262
244
  class: "detail",
263
- innerHTML: T.value
264
- }, null, 8, Rt), [
245
+ innerHTML: C.value,
246
+ ref_key: "detailRef",
247
+ ref: f
248
+ }, null, 8, yt), [
265
249
  [te, p.value]
266
250
  ])
267
251
  ]);
268
252
  };
269
253
  }
270
- }), Bt = "_key_1b448_2", Ct = "_number_1b448_6", Et = "_string_1b448_10", kt = "_boolean_1b448_14", It = {
271
- key: Bt,
272
- number: Ct,
273
- string: Et,
274
- boolean: kt,
254
+ }), xt = "_key_1b448_2", Bt = "_number_1b448_6", Ct = "_string_1b448_10", Et = "_boolean_1b448_14", kt = {
255
+ key: xt,
256
+ number: Bt,
257
+ string: Ct,
258
+ boolean: Et,
275
259
  null: "_null_1b448_18"
276
- }, St = {
277
- $style: It
278
- }, Oe = /* @__PURE__ */ N(xt, [["__cssModules", St], ["__scopeId", "data-v-3526e01c"]]), we = /* @__PURE__ */ E({
260
+ }, It = {
261
+ $style: kt
262
+ }, we = /* @__PURE__ */ A(Rt, [["__cssModules", It], ["__scopeId", "data-v-9d7f5409"]]), De = /* @__PURE__ */ E({
279
263
  __name: "Tools",
280
264
  props: {
281
265
  message: {},
282
266
  contentIndex: {}
283
267
  },
284
- setup(t) {
285
- const n = t, { restMessage: e, restProps: s } = Ue(n, ["tool_calls"]), r = ue(e, n.contentIndex);
286
- return (c, a) => (_(), R(D, null, [
287
- (_(), k(U(B(r)), F(G(B(s))), null, 16)),
288
- (_(!0), R(D, null, J(n.message.tool_calls, (u, b) => (_(), k(Oe, P({
289
- key: u.id
290
- }, { ref_for: !0 }, n, { "tool-index": b }), null, 16, ["tool-index"]))), 128))
268
+ setup(e) {
269
+ const t = e, { restMessage: n, restProps: s } = Ye(t, ["tool_calls"]), r = ie(n, t.contentIndex);
270
+ return (u, o) => (b(), x(D, null, [
271
+ (b(), k(Y(R(r)), F(G(R(s))), null, 16)),
272
+ (b(!0), x(D, null, W(t.message.tool_calls, (a, d) => (b(), k(we, P({
273
+ key: a.id
274
+ }, { ref_for: !0 }, t, { "tool-call-index": d }), null, 16, ["tool-call-index"]))), 128))
291
275
  ], 64));
292
276
  }
293
- }), De = [
277
+ }), Fe = [
294
278
  {
295
- find: (t, n, e) => {
296
- const s = n.at(0);
297
- return n.length === 1 && Array.isArray(s) && typeof e == "number" && s[e].type === "image_url";
279
+ find: (e, t, n) => {
280
+ const s = t.at(0);
281
+ return t.length === 1 && Array.isArray(s) && typeof n == "number" && s[n].type === "image_url";
298
282
  },
299
- renderer: w(le),
300
- priority: H.NORMAL,
283
+ renderer: w(ce),
284
+ priority: K.NORMAL,
301
285
  attributes: { "data-box-type": "image" }
302
286
  }
303
- ], Fe = [
287
+ ], Pe = [
304
288
  {
305
- find: (t) => !!t.loading,
306
- renderer: w(Te),
307
- priority: H.LOADING
289
+ find: (e) => !!e.loading,
290
+ renderer: w(Ae),
291
+ priority: K.LOADING
308
292
  },
309
293
  {
310
- find: (t) => typeof t.reasoning_content == "string",
311
- renderer: w(Ae),
312
- priority: H.NORMAL
294
+ find: (e) => typeof e.reasoning_content == "string",
295
+ renderer: w(Ne),
296
+ priority: K.NORMAL
313
297
  },
314
298
  {
315
- find: (t) => Array.isArray(t.tool_calls) && t.tool_calls.length > 0,
316
- renderer: w(we),
317
- priority: H.NORMAL
299
+ find: (e) => Array.isArray(e.tool_calls) && e.tool_calls.length > 0,
300
+ renderer: w(De),
301
+ priority: K.NORMAL
318
302
  },
319
303
  {
320
- find: (t, n, e) => Array.isArray(n) && typeof e == "number" && n[e].type === "image_url",
321
- renderer: w(Me),
322
- priority: H.CONTENT
304
+ find: (e, t, n) => Array.isArray(t) && typeof n == "number" && t[n].type === "image_url",
305
+ renderer: w($e),
306
+ priority: K.CONTENT
323
307
  },
324
308
  {
325
- find: (t) => t.role === "tool",
326
- renderer: w(Ne),
327
- priority: H.ROLE
309
+ find: (e) => e.role === "tool",
310
+ renderer: w(Oe),
311
+ priority: K.ROLE
328
312
  }
329
- ], Pe = w(le), Ge = w(ce), _e = Symbol("BUBBLE_CONTENT_RESOLVER_KEY"), Q = (t) => {
330
- const n = L(_e, void 0), e = n ?? t;
331
- return !n && t && M(_e, t), e ? (r) => {
332
- const c = S(e);
333
- return c == null ? void 0 : c(r);
313
+ ], Ge = w(ce), He = w(ue), be = Symbol("BUBBLE_CONTENT_RESOLVER_KEY"), Q = (e) => {
314
+ const t = L(be, void 0), n = t ?? e;
315
+ return !t && e && $(be, e), n ? (r) => {
316
+ const u = S(n);
317
+ return u == null ? void 0 : u(r);
334
318
  } : (r) => r.content;
335
319
  };
336
- function Lt(t) {
337
- const { boxRendererMatches: n, fallbackBoxRenderer: e } = t;
338
- n && M(Be, n), e && M(Ce, e);
320
+ function St(e) {
321
+ const { boxRendererMatches: t, fallbackBoxRenderer: n } = e;
322
+ t && $(Ce, t), n && $(Ee, n);
339
323
  }
340
- function $t(t) {
341
- const { fallbackBoxRenderer: n } = t;
342
- n && M(Ee, n);
324
+ function Lt(e) {
325
+ const { fallbackBoxRenderer: t } = e;
326
+ t && $(ke, t);
343
327
  }
344
- function Mt(t, n) {
345
- const e = L(Be, De), s = L(Ce, void 0), r = L(Ee, void 0), c = Q();
346
- return g(() => {
347
- const a = S(t), u = S(e).find(
348
- (b) => b.find(
349
- a,
350
- a.map((y) => c(y)),
351
- n
328
+ function Tt(e, t) {
329
+ const n = L(Ce, Fe), s = L(Ee, void 0), r = L(ke, void 0), u = Q();
330
+ return v(() => {
331
+ const o = S(e), a = S(n).find(
332
+ (d) => d.find(
333
+ o,
334
+ o.map((g) => u(g)),
335
+ t
352
336
  )
353
337
  );
354
- return u ? {
355
- renderer: u.renderer,
356
- attributes: u.attributes
338
+ return a ? {
339
+ renderer: a.renderer,
340
+ attributes: a.attributes
357
341
  } : {
358
- renderer: S(r) || S(s) || Pe
342
+ renderer: S(r) || S(s) || Ge
359
343
  };
360
344
  });
361
345
  }
362
- function Tt(t) {
363
- const { contentRendererMatches: n, fallbackContentRenderer: e } = t;
364
- n && M(ke, n), e && M(Ie, e);
346
+ function Mt(e) {
347
+ const { contentRendererMatches: t, fallbackContentRenderer: n } = e;
348
+ t && $(Ie, t), n && $(Se, n);
365
349
  }
366
- function At(t) {
367
- const { fallbackContentRenderer: n } = t;
368
- n && M(Se, n);
350
+ function $t(e) {
351
+ const { fallbackContentRenderer: t } = e;
352
+ t && $(Le, t);
369
353
  }
370
- function ue(t, n) {
371
- const e = L(ke, Fe), s = L(Ie, void 0), r = L(Se, void 0), c = Q();
372
- return g(() => {
373
- const a = S(t), u = S(e).find((b) => b.find(a, c(a), n));
374
- return u ? u.renderer : S(r) || S(s) || Ge;
354
+ function ie(e, t) {
355
+ const n = L(Ie, Pe), s = L(Se, void 0), r = L(Le, void 0), u = Q();
356
+ return v(() => {
357
+ const o = S(e), a = S(n).find((d) => d.find(o, u(o), t));
358
+ return a ? a.renderer : S(r) || S(s) || He;
375
359
  });
376
360
  }
377
- function Nt(t) {
378
- M(Le, t);
361
+ function At(e) {
362
+ $(Te, e);
379
363
  }
380
- function He() {
381
- return L(Le, (t, n) => {
382
- console.warn(`[Bubble] State change function not found for key: ${t}`);
364
+ function Ke() {
365
+ return L(Te, (e, t) => {
366
+ console.warn(`[Bubble] State change function not found for key: ${e}`);
383
367
  });
384
368
  }
385
- function ie(t) {
386
- const n = L(re, void 0);
387
- if (n)
388
- return n;
389
- const e = Je(t || {});
390
- return M(re, e), e;
369
+ function de(e) {
370
+ const t = L(ae, void 0);
371
+ if (t)
372
+ return t;
373
+ const n = We(e || {});
374
+ return $(ae, n), n;
391
375
  }
392
- function de() {
393
- return L(re, {});
376
+ function fe() {
377
+ return L(ae, {});
394
378
  }
395
- function Ke(t) {
396
- let n = null;
397
- n = Z(
398
- t,
399
- (e) => {
400
- n && (n(), n = null), e && e.addEventListener("copy", (s) => {
401
- var a;
379
+ function Ue(e) {
380
+ let t = null;
381
+ t = H(
382
+ e,
383
+ (n) => {
384
+ t && (t(), t = null), n && n.addEventListener("copy", (s) => {
385
+ var o;
402
386
  const r = window.getSelection();
403
- if (!e.contains((r == null ? void 0 : r.anchorNode) || null)) return;
387
+ if (!n.contains((r == null ? void 0 : r.anchorNode) || null)) return;
404
388
  s.preventDefault();
405
- const c = (r == null ? void 0 : r.toString().replace(/\n{2,}/g, `
389
+ const u = (r == null ? void 0 : r.toString().replace(/\n{2,}/g, `
406
390
  `)) || "";
407
- (a = s.clipboardData) == null || a.setData("text/plain", c);
391
+ (o = s.clipboardData) == null || o.setData("text/plain", u);
408
392
  });
409
393
  },
410
394
  { immediate: !0, flush: "post" }
411
395
  );
412
396
  }
413
- const fe = (t) => {
414
- const n = Q(), e = g(() => n(t.message)), s = g(() => {
415
- const c = e.value;
416
- return Array.isArray(c) ? c.at(t.contentIndex ?? 0) : void 0;
417
- }), r = g(() => {
418
- var a;
419
- const c = e.value;
420
- return Array.isArray(c) ? String(((a = c.at(t.contentIndex ?? 0)) == null ? void 0 : a.text) || "") : c || "";
397
+ const pe = (e) => {
398
+ const t = Q(), n = v(() => t(e.message)), s = v(() => {
399
+ const u = n.value;
400
+ return Array.isArray(u) ? u.at(e.contentIndex ?? 0) : void 0;
401
+ }), r = v(() => {
402
+ var o;
403
+ const u = n.value;
404
+ return Array.isArray(u) ? String(((o = u.at(e.contentIndex ?? 0)) == null ? void 0 : o.text) || "") : u || "";
421
405
  });
422
406
  return {
423
- content: e,
407
+ content: n,
424
408
  contentItem: s,
425
409
  contentText: r
426
410
  };
427
411
  };
428
- function Ot(t) {
429
- M(xe, t);
412
+ function Nt(e) {
413
+ $(Be, e);
430
414
  }
431
- function wt() {
432
- return L(xe, void 0);
415
+ function Ot() {
416
+ return L(Be, void 0);
433
417
  }
434
- function Ue(t, n) {
435
- const e = g(() => {
436
- const r = Object.entries(t.message).filter(([c]) => !n.includes(c));
418
+ function Ye(e, t) {
419
+ const n = v(() => {
420
+ const r = Object.entries(e.message).filter(([u]) => !t.includes(u));
437
421
  return Object.fromEntries(r);
438
- }), s = g(() => ({
439
- ...t,
440
- message: e.value
422
+ }), s = v(() => ({
423
+ ...e,
424
+ message: n.value
441
425
  }));
442
426
  return {
443
- restMessage: e,
427
+ restMessage: n,
444
428
  restProps: s
445
429
  };
446
430
  }
447
- const be = /* @__PURE__ */ E({
431
+ let oe = null;
432
+ const wt = () => (oe || (oe = import("./index4.js")), oe);
433
+ let J = null;
434
+ const Dt = async () => {
435
+ if (J)
436
+ return J;
437
+ try {
438
+ const [e, t] = await Promise.all([import("markdown-it"), import("dompurify")]);
439
+ return J = { markdown: e.default, dompurify: t.default }, J;
440
+ } catch {
441
+ return console.warn("[BubbleMarkdownRenderer] install markdown-it and dompurify to use markdown renderer"), J = null, null;
442
+ }
443
+ }, ge = ["running", "success", "failed", "cancelled"], Ft = (e) => {
444
+ const t = v(() => {
445
+ var o, a;
446
+ return (a = (o = e.message) == null ? void 0 : o.tool_calls) == null ? void 0 : a[e.toolCallIndex];
447
+ }), n = fe(), s = v(() => {
448
+ var y, C, f;
449
+ let o = n.toolCallDefaultStatus;
450
+ o && !ge.includes(o) && (o = void 0);
451
+ const a = n.toolCallDefaultOpen;
452
+ let d = {
453
+ status: o,
454
+ open: a
455
+ };
456
+ const g = (y = t.value) == null ? void 0 : y.id;
457
+ if (g) {
458
+ const p = (f = (C = e.message.state) == null ? void 0 : C.toolCall) == null ? void 0 : f[g];
459
+ if (p) {
460
+ const { status: i, open: _, ...c } = p;
461
+ i && ge.includes(i) && (d.status = i), _ !== void 0 && (d.open = _), d = { ...d, ...c };
462
+ }
463
+ }
464
+ return d;
465
+ }), r = v(() => {
466
+ var a, d;
467
+ const o = (a = t.value) == null ? void 0 : a.id;
468
+ if (o)
469
+ return (d = n.toolCallResults) == null ? void 0 : d[o];
470
+ }), u = T({});
471
+ return Z(() => {
472
+ var d;
473
+ const o = (d = t.value) == null ? void 0 : d.function.arguments, a = r.value;
474
+ wt().then(({ jsonrepair: g }) => {
475
+ const y = g(typeof o == "string" ? o || "{}" : JSON.stringify(o));
476
+ u.value = {
477
+ arguments: JSON.parse(y),
478
+ result: a ? JSON.parse(g(a || "{}")) : void 0
479
+ };
480
+ }).catch((g) => {
481
+ console.warn(g);
482
+ });
483
+ }), {
484
+ toolCall: t,
485
+ toolCallWithResult: je(u),
486
+ state: s
487
+ };
488
+ }, ve = /* @__PURE__ */ E({
448
489
  __name: "BubbleBoxWrapper",
449
490
  props: {
450
491
  role: {},
@@ -453,37 +494,37 @@ const be = /* @__PURE__ */ E({
453
494
  messages: {},
454
495
  contentIndex: {}
455
496
  },
456
- setup(t) {
457
- const n = t, e = Mt(() => n.messages, n.contentIndex);
458
- return (s, r) => (_(), k(U(B(e).renderer), P({
459
- "data-role": n.role,
460
- "data-placement": n.placement,
461
- "data-shape": n.shape
462
- }, B(e).attributes), {
463
- default: $(() => [
464
- x(s.$slots, "default")
497
+ setup(e) {
498
+ const t = e, n = Tt(() => t.messages, t.contentIndex);
499
+ return (s, r) => (b(), k(Y(R(n).renderer), P({
500
+ "data-role": t.role,
501
+ "data-placement": t.placement,
502
+ "data-shape": t.shape
503
+ }, R(n).attributes), {
504
+ default: M(() => [
505
+ B(s.$slots, "default")
465
506
  ]),
466
507
  _: 3
467
508
  }, 16, ["data-role", "data-placement", "data-shape"]));
468
509
  }
469
- }), oe = /* @__PURE__ */ E({
510
+ }), re = /* @__PURE__ */ E({
470
511
  __name: "BubbleContentWrapper",
471
512
  props: {
472
513
  message: {},
473
514
  contentIndex: {}
474
515
  },
475
516
  emits: ["state-change"],
476
- setup(t, { emit: n }) {
477
- const e = t, s = ue(() => e.message, e.contentIndex), r = n;
478
- return Nt((a, u) => {
517
+ setup(e, { emit: t }) {
518
+ const n = e, s = ie(() => n.message, n.contentIndex), r = t;
519
+ return At((o, a) => {
479
520
  r("state-change", {
480
- key: a,
481
- value: u,
482
- contentIndex: e.contentIndex
521
+ key: o,
522
+ value: a,
523
+ contentIndex: n.contentIndex
483
524
  });
484
- }), (a, u) => (_(), k(U(B(s)), F(G(e)), null, 16));
525
+ }), (o, a) => (b(), k(Y(R(s)), F(G(n)), null, 16));
485
526
  }
486
- }), Dt = ["data-role", "data-placement"], Ft = { class: "tr-bubble__body" }, Pt = { class: "tr-bubble__content" }, Gt = { class: "tr-bubble__after" }, Ht = /* @__PURE__ */ E({
527
+ }), Pt = ["data-role", "data-placement"], Gt = { class: "tr-bubble__body" }, Ht = { class: "tr-bubble__content" }, Kt = { class: "tr-bubble__after" }, Ut = /* @__PURE__ */ E({
487
528
  __name: "Bubble",
488
529
  props: {
489
530
  content: {},
@@ -500,172 +541,173 @@ const be = /* @__PURE__ */ E({
500
541
  placement: { default: "start" },
501
542
  shape: { default: "corner" },
502
543
  contentRenderMode: { default: "single" },
503
- contentResolver: { type: Function, default: (t) => t.content },
544
+ contentResolver: { type: Function, default: (e) => e.content },
504
545
  fallbackBoxRenderer: {},
505
546
  fallbackContentRenderer: {}
506
547
  },
507
548
  emits: ["state-change"],
508
- setup(t, { emit: n }) {
509
- const e = t, s = Q(() => e.contentResolver), r = n;
510
- ie();
511
- const c = wt(), a = g(() => S(c)), u = g(() => {
549
+ setup(e, { emit: t }) {
550
+ const n = e, s = Q(() => n.contentResolver), r = t;
551
+ de();
552
+ const u = Ot(), o = v(() => S(u)), a = v(() => {
512
553
  var O;
513
- if ((O = a.value) != null && O.messages.length)
514
- return a.value.messages;
515
- const { role: m, content: p, reasoning_content: i, tool_calls: d, tool_call_id: o, name: l, id: f, loading: v, state: C } = e;
516
- return [{ role: m, content: p, reasoning_content: i, tool_calls: d, tool_call_id: o, name: l, id: f, loading: v, state: C }];
554
+ if ((O = o.value) != null && O.messages.length)
555
+ return o.value.messages;
556
+ const { role: f, content: p, reasoning_content: i, tool_calls: _, tool_call_id: c, name: l, id: m, loading: I, state: N } = n;
557
+ return [{ role: f, content: p, reasoning_content: i, tool_calls: _, tool_call_id: c, name: l, id: m, loading: I, state: N }];
517
558
  });
518
- $t({ fallbackBoxRenderer: () => e.fallbackBoxRenderer }), At({ fallbackContentRenderer: () => e.fallbackContentRenderer });
519
- const b = g(() => u.value.length === 0 ? !0 : e.hidden), y = g(() => {
520
- if (e.contentRenderMode === "split" && u.value.length === 1) {
521
- const m = s(u.value.at(0));
522
- if (Array.isArray(m))
523
- return m;
559
+ Lt({ fallbackBoxRenderer: () => n.fallbackBoxRenderer }), $t({ fallbackContentRenderer: () => n.fallbackContentRenderer });
560
+ const d = v(() => a.value.length === 0 ? !0 : n.hidden), g = v(() => {
561
+ if (n.contentRenderMode === "split" && a.value.length === 1) {
562
+ const f = s(a.value.at(0));
563
+ if (Array.isArray(f))
564
+ return f;
524
565
  }
525
566
  return null;
526
- }), I = L($e, !1), T = A(null);
527
- return I || Ke(T), (m, p) => ee((_(), R("div", {
567
+ }), y = L(Me, !1), C = T(null);
568
+ return y || Ue(C), (f, p) => ee((b(), x("div", {
528
569
  class: "tr-bubble",
529
570
  ref_key: "bubbleRef",
530
- ref: T,
531
- "data-role": e.role,
532
- "data-placement": e.placement
571
+ ref: C,
572
+ "data-role": n.role,
573
+ "data-placement": n.placement
533
574
  }, [
534
- x(m.$slots, "prefix", {
535
- messages: u.value,
536
- role: t.role
575
+ B(f.$slots, "prefix", {
576
+ messages: a.value,
577
+ role: e.role
537
578
  }, void 0, !0),
538
- h("div", Ft, [
539
- e.avatar ? (_(), k(U(e.avatar), {
579
+ h("div", Gt, [
580
+ n.avatar ? (b(), k(Y(n.avatar), {
540
581
  key: 0,
541
- class: V(["tr-bubble__avatar", m.$style["tr-bubble__avatar"]])
542
- }, null, 8, ["class"])) : ae("", !0),
543
- h("div", Pt, [
544
- y.value ? (_(!0), R(D, { key: 0 }, J(y.value, (i, d) => (_(), k(be, {
545
- key: d,
582
+ class: j(["tr-bubble__avatar", f.$style["tr-bubble__avatar"]])
583
+ }, null, 8, ["class"])) : le("", !0),
584
+ h("div", Ht, [
585
+ g.value ? (b(!0), x(D, { key: 0 }, W(g.value, (i, _) => (b(), k(ve, {
586
+ key: _,
546
587
  class: "tr-bubble__box",
547
- role: e.role,
548
- placement: e.placement,
549
- shape: e.shape,
550
- messages: u.value,
551
- "content-index": d
588
+ role: n.role,
589
+ placement: n.placement,
590
+ shape: n.shape,
591
+ messages: a.value,
592
+ "content-index": _
552
593
  }, {
553
- default: $(() => [
554
- W(oe, {
555
- message: u.value.at(0),
556
- "content-index": d,
557
- onStateChange: p[0] || (p[0] = (o) => r("state-change", { ...o, messageIndex: 0 }))
594
+ default: M(() => [
595
+ z(re, {
596
+ message: a.value.at(0),
597
+ "content-index": _,
598
+ onStateChange: p[0] || (p[0] = (c) => r("state-change", { ...c, messageIndex: 0 }))
558
599
  }, null, 8, ["message", "content-index"]),
559
- x(m.$slots, "content-footer", {
560
- messages: u.value,
561
- role: e.role,
562
- contentIndex: d
600
+ B(f.$slots, "content-footer", {
601
+ messages: a.value,
602
+ role: n.role,
603
+ contentIndex: _
563
604
  }, void 0, !0)
564
605
  ]),
565
606
  _: 2
566
- }, 1032, ["role", "placement", "shape", "messages", "content-index"]))), 128)) : (_(), k(be, {
607
+ }, 1032, ["role", "placement", "shape", "messages", "content-index"]))), 128)) : (b(), k(ve, {
567
608
  key: 1,
568
- role: e.role,
569
- placement: e.placement,
570
- shape: e.shape,
571
- messages: u.value
609
+ role: n.role,
610
+ placement: n.placement,
611
+ shape: n.shape,
612
+ messages: a.value
572
613
  }, {
573
- default: $(() => [
574
- (_(!0), R(D, null, J(u.value, (i, d) => (_(), R(D, {
575
- key: `message-${d}`
614
+ default: M(() => [
615
+ (b(!0), x(D, null, W(a.value, (i, _) => (b(), x(D, {
616
+ key: `message-${_}`
576
617
  }, [
577
- Array.isArray(B(s)(i)) ? (_(!0), R(D, { key: 0 }, J(B(s)(i), (o, l) => (_(), k(oe, {
618
+ Array.isArray(R(s)(i)) ? (b(!0), x(D, { key: 0 }, W(R(s)(i), (c, l) => (b(), k(re, {
578
619
  key: `content-${l}`,
579
620
  message: i,
580
621
  "content-index": l,
581
- onStateChange: (f) => r("state-change", { ...f, messageIndex: d })
582
- }, null, 8, ["message", "content-index", "onStateChange"]))), 128)) : (_(), k(oe, {
622
+ onStateChange: (m) => r("state-change", { ...m, messageIndex: _ })
623
+ }, null, 8, ["message", "content-index", "onStateChange"]))), 128)) : (b(), k(re, {
583
624
  key: 1,
584
625
  message: i,
585
- onStateChange: (o) => r("state-change", { ...o, messageIndex: d })
626
+ onStateChange: (c) => r("state-change", { ...c, messageIndex: _ })
586
627
  }, null, 8, ["message", "onStateChange"]))
587
628
  ], 64))), 128)),
588
- x(m.$slots, "content-footer", {
589
- messages: u.value,
590
- role: e.role
629
+ B(f.$slots, "content-footer", {
630
+ messages: a.value,
631
+ role: n.role
591
632
  }, void 0, !0)
592
633
  ]),
593
634
  _: 3
594
635
  }, 8, ["role", "placement", "shape", "messages"]))
595
636
  ]),
596
- h("div", Gt, [
597
- x(m.$slots, "after", {
598
- messages: u.value,
599
- role: t.role
637
+ h("div", Kt, [
638
+ B(f.$slots, "after", {
639
+ messages: a.value,
640
+ role: e.role
600
641
  }, void 0, !0)
601
642
  ])
602
643
  ]),
603
- x(m.$slots, "suffix", {
604
- messages: u.value,
605
- role: t.role
644
+ B(f.$slots, "suffix", {
645
+ messages: a.value,
646
+ role: e.role
606
647
  }, void 0, !0)
607
- ], 8, Dt)), [
608
- [te, !b.value]
648
+ ], 8, Pt)), [
649
+ [te, !d.value]
609
650
  ]);
610
651
  }
611
- }), Kt = {
652
+ }), Yt = {
612
653
  "tr-bubble__avatar": "_tr-bubble__avatar_1r87c_2"
613
- }, Ut = {
614
- $style: Kt
615
- }, K = /* @__PURE__ */ N(Ht, [["__cssModules", Ut], ["__scopeId", "data-v-9468260c"]]);
616
- function ge(t, n) {
617
- const e = Z(t, (s, r) => {
618
- r === !0 && s === !1 && (n(), e());
654
+ }, Jt = {
655
+ $style: Yt
656
+ }, U = /* @__PURE__ */ A(Ut, [["__cssModules", Jt], ["__scopeId", "data-v-9468260c"]]);
657
+ function he(e, t) {
658
+ const n = H(e, (s, r) => {
659
+ r === !0 && s === !1 && (t(), n());
619
660
  });
620
- return e;
661
+ return n;
621
662
  }
622
- function Yt(t, n, e) {
623
- const { scrollOnMount: s = !0, bottomThreshold: r = 20, scrollThrottle: c = 0 } = e ?? {}, a = A(!0);
624
- let u = !1;
625
- const b = /* @__PURE__ */ new Set(), y = () => qe(t), { y: I, isScrolling: T } = je(y, { throttle: c }), m = (d) => d.scrollHeight - d.scrollTop - d.clientHeight <= r, p = async (d = "auto") => {
626
- const o = S(y);
627
- if (o && (await he(), o.scrollTo({ top: o.scrollHeight, behavior: d }), d === "smooth" && !m(o))) {
628
- const l = ge(T, () => {
629
- o.scrollTo({ top: o.scrollHeight, behavior: "auto" }), b.delete(l);
663
+ function Wt(e, t, n) {
664
+ const { scrollOnMount: s = !0, bottomThreshold: r = 20, scrollThrottle: u = 0 } = n ?? {}, o = T(!0);
665
+ let a = !1;
666
+ const d = /* @__PURE__ */ new Set(), g = () => Qe(e), { y, isScrolling: C, arrivedState: f } = Ze(g, { throttle: u }), p = (c) => c.scrollHeight - c.scrollTop - c.clientHeight <= r, i = async (c = "auto") => {
667
+ const l = S(g);
668
+ if (l && (await ne(), l.scrollTo({ top: l.scrollHeight, behavior: c }), c === "smooth" && !p(l))) {
669
+ const m = he(C, () => {
670
+ l.scrollTo({ top: l.scrollHeight, behavior: "auto" }), d.delete(m);
630
671
  });
631
- b.add(l);
672
+ d.add(m);
632
673
  }
633
- }, i = () => {
634
- u || !a.value || (u = !0, requestAnimationFrame(async () => {
635
- u = !1, await p("auto");
674
+ }, _ = () => {
675
+ a || !o.value || (a = !0, requestAnimationFrame(async () => {
676
+ a = !1, await i("auto");
636
677
  }));
637
678
  };
638
- return Z(
639
- I,
679
+ return H(
680
+ y,
640
681
  () => {
641
- const d = S(y);
642
- d && (a.value = m(d));
682
+ const c = S(g);
683
+ c && (o.value = p(c));
643
684
  },
644
685
  { flush: "post" }
645
- ), Ze(
646
- n,
686
+ ), et(
687
+ t,
647
688
  () => {
648
- i();
689
+ _();
649
690
  },
650
691
  { flush: "post", throttle: 100 }
651
- ), ve(() => {
652
- s && p("smooth");
653
- }), Ve(() => {
654
- b.forEach((d) => {
655
- d();
656
- }), b.clear();
657
- }), Qe("keydown", (d) => {
658
- if (d.key === "End" && !a.value) {
659
- const o = ge(T, () => {
660
- p("auto"), b.delete(o);
692
+ ), ye(() => {
693
+ s && i("smooth");
694
+ }), ze(() => {
695
+ d.forEach((c) => {
696
+ c();
697
+ }), d.clear();
698
+ }), tt("keydown", (c) => {
699
+ if (c.key === "End" && !o.value) {
700
+ const l = he(C, () => {
701
+ i("auto"), d.delete(l);
661
702
  });
662
- b.add(o);
703
+ d.add(l);
663
704
  }
664
705
  }), {
665
- scrollToBottom: p
706
+ scrollToBottom: i,
707
+ arrivedState: f
666
708
  };
667
709
  }
668
- const Jt = /* @__PURE__ */ E({
710
+ const jt = /* @__PURE__ */ E({
669
711
  __name: "BubbleItem",
670
712
  props: {
671
713
  messageGroup: {},
@@ -674,30 +716,30 @@ const Jt = /* @__PURE__ */ E({
674
716
  contentResolver: { type: Function }
675
717
  },
676
718
  emits: ["state-change"],
677
- setup(t, { emit: n }) {
678
- const e = t, s = n;
679
- return Ot(() => e.messageGroup), (r, c) => (_(), k(K, P(t.roleConfig, {
680
- role: t.messageGroup.role,
681
- "content-render-mode": t.contentRenderMode,
682
- "content-resolver": t.contentResolver,
683
- onStateChange: c[0] || (c[0] = (a) => s("state-change", a))
719
+ setup(e, { emit: t }) {
720
+ const n = e, s = t;
721
+ return Nt(() => n.messageGroup), (r, u) => (b(), k(U, P(e.roleConfig, {
722
+ role: e.messageGroup.role,
723
+ "content-render-mode": e.contentRenderMode,
724
+ "content-resolver": e.contentResolver,
725
+ onStateChange: u[0] || (u[0] = (o) => s("state-change", o))
684
726
  }), {
685
- prefix: $((a) => [
686
- x(r.$slots, "prefix", F(G(a)))
727
+ prefix: M((o) => [
728
+ B(r.$slots, "prefix", F(G(o)))
687
729
  ]),
688
- suffix: $((a) => [
689
- x(r.$slots, "suffix", F(G(a)))
730
+ suffix: M((o) => [
731
+ B(r.$slots, "suffix", F(G(o)))
690
732
  ]),
691
- "content-footer": $((a) => [
692
- x(r.$slots, "content-footer", F(G(a)))
733
+ "content-footer": M((o) => [
734
+ B(r.$slots, "content-footer", F(G(o)))
693
735
  ]),
694
- after: $((a) => [
695
- x(r.$slots, "after", F(G(a)))
736
+ after: M((o) => [
737
+ B(r.$slots, "after", F(G(o)))
696
738
  ]),
697
739
  _: 3
698
740
  }, 16, ["role", "content-render-mode", "content-resolver"]));
699
741
  }
700
- }), Vt = /* @__PURE__ */ E({
742
+ }), zt = /* @__PURE__ */ E({
701
743
  __name: "BubbleList",
702
744
  props: {
703
745
  messages: {},
@@ -706,111 +748,111 @@ const Jt = /* @__PURE__ */ E({
706
748
  fallbackRole: { default: "assistant" },
707
749
  roleConfigs: {},
708
750
  contentRenderMode: {},
709
- contentResolver: { type: Function, default: (t) => t.content },
751
+ contentResolver: { type: Function, default: (e) => e.content },
710
752
  autoScroll: { type: Boolean }
711
753
  },
712
754
  emits: ["state-change"],
713
- setup(t, { expose: n, emit: e }) {
714
- const s = t, r = e;
715
- ie(), M($e, !0);
716
- const c = Q(() => s.contentResolver), a = (m) => {
755
+ setup(e, { expose: t, emit: n }) {
756
+ const s = e, r = n;
757
+ de(), $(Me, !0);
758
+ const u = Q(() => s.contentResolver), o = (f) => {
717
759
  var p, i;
718
- return m ? !!((i = (p = s.roleConfigs) == null ? void 0 : p[m]) != null && i.hidden) : !1;
719
- }, u = A(null);
720
- let b = async () => {
760
+ return f ? !!((i = (p = s.roleConfigs) == null ? void 0 : p[f]) != null && i.hidden) : !1;
761
+ }, a = T(null);
762
+ let d = async () => {
721
763
  };
722
764
  if (s.autoScroll) {
723
- const m = g(() => s.messages.at(-1)), { scrollToBottom: p } = Yt(u, () => {
724
- var i, d;
765
+ const f = v(() => s.messages.at(-1)), { scrollToBottom: p } = Wt(a, () => {
766
+ var i, _;
725
767
  return [
726
768
  s.messages.length,
727
- (i = m.value) == null ? void 0 : i.content,
728
- (d = m.value) == null ? void 0 : d.reasoning_content
769
+ (i = f.value) == null ? void 0 : i.content,
770
+ (_ = f.value) == null ? void 0 : _.reasoning_content
729
771
  ];
730
772
  });
731
- b = p, Z(
773
+ d = p, H(
732
774
  () => {
733
775
  var i;
734
- return (i = m.value) == null ? void 0 : i.role;
776
+ return (i = f.value) == null ? void 0 : i.role;
735
777
  },
736
778
  async (i) => {
737
- i === "user" && (await he(), p("smooth"));
779
+ i === "user" && (await ne(), p("smooth"));
738
780
  }
739
781
  );
740
782
  }
741
- Ke(u);
742
- const y = (m) => {
783
+ Ue(a);
784
+ const g = (f) => {
743
785
  const p = [];
744
- let i = !1, d = !1;
745
- for (const [o, l] of m.entries()) {
746
- const f = p[p.length - 1], v = Array.isArray(c(l)), C = l.role || "", O = a(l.role);
747
- v ? (p.push({
748
- role: C,
786
+ let i = !1, _ = !1;
787
+ for (const [c, l] of f.entries()) {
788
+ const m = p[p.length - 1], I = Array.isArray(u(l)), N = l.role || "", O = o(l.role);
789
+ I ? (p.push({
790
+ role: N,
749
791
  messages: [l],
750
- messageIndexes: [o],
751
- startIndex: o
752
- }), i = !0) : f && !i && (d && O || f.role === C && d === O) ? (f.messages.push(l), f.messageIndexes.push(o)) : (p.push({
753
- role: C,
792
+ messageIndexes: [c],
793
+ startIndex: c
794
+ }), i = !0) : m && !i && (_ && O || m.role === N && _ === O) ? (m.messages.push(l), m.messageIndexes.push(c)) : (p.push({
795
+ role: N,
754
796
  messages: [l],
755
- messageIndexes: [o],
756
- startIndex: o
757
- }), i = !1), d = O;
797
+ messageIndexes: [c],
798
+ startIndex: c
799
+ }), i = !1), _ = O;
758
800
  }
759
801
  return p;
760
- }, I = (m, p) => {
802
+ }, y = (f, p) => {
761
803
  const i = [];
762
- let d = !1, o = !1;
763
- for (const [l, f] of m.entries()) {
764
- const v = i[i.length - 1], C = f.role === p, O = Array.isArray(c(f)), pe = f.role || "", ne = a(f.role);
804
+ let _ = !1, c = !1;
805
+ for (const [l, m] of f.entries()) {
806
+ const I = i[i.length - 1], N = m.role === p, O = Array.isArray(u(m)), me = m.role || "", se = o(m.role);
765
807
  O ? (i.push({
766
- role: pe,
767
- messages: [f],
808
+ role: me,
809
+ messages: [m],
768
810
  messageIndexes: [l],
769
811
  startIndex: l
770
- }), d = !0) : v && !d && (o && ne || v.role === p === C && o === ne) ? (v.messages.push(f), v.messageIndexes.push(l)) : (i.push({
771
- role: C ? p : pe,
772
- messages: [f],
812
+ }), _ = !0) : I && !_ && (c && se || I.role === p === N && c === se) ? (I.messages.push(m), I.messageIndexes.push(l)) : (i.push({
813
+ role: N ? p : me,
814
+ messages: [m],
773
815
  messageIndexes: [l],
774
816
  startIndex: l
775
- }), d = !1), o = ne;
817
+ }), _ = !1), c = se;
776
818
  }
777
819
  return i;
778
- }, T = g(() => s.messages.length === 0 ? [] : typeof s.groupStrategy == "function" ? s.groupStrategy(s.messages, s.dividerRole) : s.groupStrategy === "consecutive" ? y(s.messages) : I(s.messages, s.dividerRole));
779
- return n({
780
- scrollToBottom: b
781
- }), (m, p) => (_(), R("div", {
820
+ }, C = v(() => s.messages.length === 0 ? [] : typeof s.groupStrategy == "function" ? s.groupStrategy(s.messages, s.dividerRole) : s.groupStrategy === "consecutive" ? g(s.messages) : y(s.messages, s.dividerRole));
821
+ return t({
822
+ scrollToBottom: d
823
+ }), (f, p) => (b(), x("div", {
782
824
  class: "tr-bubble-list",
783
825
  ref_key: "listRef",
784
- ref: u
826
+ ref: a
785
827
  }, [
786
- (_(!0), R(D, null, J(T.value, (i, d) => {
787
- var o;
788
- return _(), k(Jt, {
789
- key: d,
828
+ (b(!0), x(D, null, W(C.value, (i, _) => {
829
+ var c;
830
+ return b(), k(jt, {
831
+ key: _,
790
832
  role: i.role || s.fallbackRole,
791
- "role-config": (o = s.roleConfigs) == null ? void 0 : o[i.role || s.fallbackRole],
833
+ "role-config": (c = s.roleConfigs) == null ? void 0 : c[i.role || s.fallbackRole],
792
834
  "message-group": i,
793
835
  "content-render-mode": s.contentRenderMode,
794
836
  "content-resolver": s.contentResolver,
795
837
  onStateChange: (l) => r("state-change", { ...l, messageIndex: i.startIndex + l.messageIndex })
796
838
  }, {
797
- prefix: $((l) => [
798
- x(m.$slots, "prefix", P({ ref_for: !0 }, l, {
839
+ prefix: M((l) => [
840
+ B(f.$slots, "prefix", P({ ref_for: !0 }, l, {
799
841
  messageIndexes: i.messageIndexes
800
842
  }), void 0, !0)
801
843
  ]),
802
- suffix: $((l) => [
803
- x(m.$slots, "suffix", P({ ref_for: !0 }, l, {
844
+ suffix: M((l) => [
845
+ B(f.$slots, "suffix", P({ ref_for: !0 }, l, {
804
846
  messageIndexes: i.messageIndexes
805
847
  }), void 0, !0)
806
848
  ]),
807
- "content-footer": $((l) => [
808
- x(m.$slots, "content-footer", P({ ref_for: !0 }, l, {
849
+ "content-footer": M((l) => [
850
+ B(f.$slots, "content-footer", P({ ref_for: !0 }, l, {
809
851
  messageIndexes: i.messageIndexes
810
852
  }), void 0, !0)
811
853
  ]),
812
- after: $((l) => [
813
- x(m.$slots, "after", P({ ref_for: !0 }, l, {
854
+ after: M((l) => [
855
+ B(f.$slots, "after", P({ ref_for: !0 }, l, {
814
856
  messageIndexes: i.messageIndexes
815
857
  }), void 0, !0)
816
858
  ]),
@@ -819,7 +861,7 @@ const Jt = /* @__PURE__ */ E({
819
861
  }), 128))
820
862
  ], 512));
821
863
  }
822
- }), j = /* @__PURE__ */ N(Vt, [["__scopeId", "data-v-e6f64f99"]]), q = /* @__PURE__ */ E({
864
+ }), X = /* @__PURE__ */ A(zt, [["__scopeId", "data-v-e6f64f99"]]), q = /* @__PURE__ */ E({
823
865
  __name: "BubbleProvider",
824
866
  props: {
825
867
  boxRendererMatches: {},
@@ -828,75 +870,76 @@ const Jt = /* @__PURE__ */ E({
828
870
  fallbackContentRenderer: { type: [Object, Function] },
829
871
  store: {}
830
872
  },
831
- setup(t) {
832
- const n = t;
833
- ie(n.store);
834
- const e = g(() => (n.boxRendererMatches || []).concat(De).sort((a, u) => (a.priority ?? 0) - (u.priority ?? 0))), s = g(() => (n.contentRendererMatches || []).concat(Fe).sort((a, u) => (a.priority ?? 0) - (u.priority ?? 0))), r = g(() => n.fallbackBoxRenderer || Pe), c = g(() => n.fallbackContentRenderer || Ge);
835
- return Lt({ boxRendererMatches: e, fallbackBoxRenderer: r }), Tt({ contentRendererMatches: s, fallbackContentRenderer: c }), (a, u) => x(a.$slots, "default");
873
+ setup(e) {
874
+ const t = e;
875
+ de(t.store);
876
+ const n = v(() => (t.boxRendererMatches || []).concat(Fe).sort((o, a) => (o.priority ?? 0) - (a.priority ?? 0))), s = v(() => (t.contentRendererMatches || []).concat(Pe).sort((o, a) => (o.priority ?? 0) - (a.priority ?? 0))), r = v(() => t.fallbackBoxRenderer || Ge), u = v(() => t.fallbackContentRenderer || He);
877
+ return St({ boxRendererMatches: n, fallbackBoxRenderer: r }), Mt({ contentRendererMatches: s, fallbackContentRenderer: u }), (o, a) => B(o.$slots, "default");
836
878
  }
837
- }), Wt = ["innerHTML"], zt = /* @__PURE__ */ E({
879
+ }), Vt = ["innerHTML"], Xt = /* @__PURE__ */ E({
838
880
  __name: "Markdown",
839
881
  props: {
840
882
  message: {},
841
883
  contentIndex: {}
842
884
  },
843
- setup(t) {
844
- const n = t, { contentText: e } = fe(n), s = A(null);
845
- ve(async () => {
846
- s.value = await mt();
885
+ setup(e) {
886
+ const t = e, { contentText: n } = pe(t), s = T(null);
887
+ ye(async () => {
888
+ s.value = await Dt();
847
889
  });
848
- const { mdConfig: r, dompurifyConfig: c } = de(), a = A("");
849
- return z(() => {
890
+ const { mdConfig: r, dompurifyConfig: u } = fe(), o = T("");
891
+ return Z(() => {
850
892
  if (s.value) {
851
- const { markdown: u, dompurify: b } = s.value;
852
- a.value = u(r || {}).render(e.value), b.sanitize(a.value, c);
893
+ const { markdown: a, dompurify: d } = s.value;
894
+ o.value = a(r || {}).render(n.value), d.sanitize(o.value, u);
853
895
  }
854
- }), (u, b) => a.value ? (_(), R("div", {
896
+ }), (a, d) => o.value ? (b(), x("div", {
855
897
  key: 0,
856
898
  class: "tr-bubble__markdown markdown-body",
857
899
  "data-type": "markdown",
858
- innerHTML: a.value
859
- }, null, 8, Wt)) : (_(), k(ce, F(P({ key: 1 }, n)), null, 16));
900
+ innerHTML: o.value
901
+ }, null, 8, Vt)) : (b(), k(ue, F(P({ key: 1 }, t)), null, 16));
860
902
  }
861
- }), Xt = /* @__PURE__ */ N(zt, [["__scopeId", "data-v-a7de666c"]]), sn = {
862
- Box: le,
863
- Image: Me,
864
- Loading: Te,
865
- Markdown: Xt,
866
- Reasoning: Ae,
867
- Text: ce,
868
- Tool: Oe,
869
- ToolRole: Ne,
870
- Tools: we
903
+ }), qt = /* @__PURE__ */ A(Xt, [["__scopeId", "data-v-a7de666c"]]), rn = {
904
+ Box: ce,
905
+ Image: $e,
906
+ Loading: Ae,
907
+ Markdown: qt,
908
+ Reasoning: Ne,
909
+ Text: ue,
910
+ Tool: we,
911
+ ToolRole: Oe,
912
+ Tools: De
871
913
  };
872
- K.name = "TrBubble";
873
- const jt = function(t) {
874
- t.component(K.name, K);
914
+ U.name = "TrBubble";
915
+ const Zt = function(e) {
916
+ e.component(U.name, U);
875
917
  };
876
- K.install = jt;
877
- const on = K;
878
- j.name = "TrBubbleList";
879
- const qt = function(t) {
880
- t.component(j.name, j);
918
+ U.install = Zt;
919
+ const an = U;
920
+ X.name = "TrBubbleList";
921
+ const Qt = function(e) {
922
+ e.component(X.name, X);
881
923
  };
882
- j.install = qt;
883
- const rn = j;
924
+ X.install = Qt;
925
+ const ln = X;
884
926
  q.name = "TrBubbleProvider";
885
- const Zt = function(t) {
886
- t.component(q.name, q);
927
+ const en = function(e) {
928
+ e.component(q.name, q);
887
929
  };
888
- q.install = Zt;
889
- const an = q;
930
+ q.install = en;
931
+ const cn = q;
890
932
  export {
891
- on as B,
892
- rn as a,
893
- an as b,
894
- H as c,
895
- sn as d,
896
- ue as e,
897
- He as f,
898
- fe as g,
899
- Ue as h,
900
- Yt as i,
901
- Mt as u
933
+ an as B,
934
+ ln as a,
935
+ cn as b,
936
+ K as c,
937
+ rn as d,
938
+ ie as e,
939
+ Ke as f,
940
+ pe as g,
941
+ Ye as h,
942
+ Ft as i,
943
+ Wt as j,
944
+ Tt as u
902
945
  };