@opentiny/tiny-robot 0.4.0-beta.0 → 0.4.1-alpha.0

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