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

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