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

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