@opentiny/tiny-robot 0.4.2-alpha.0 → 0.4.2-alpha.10

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