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

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