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

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