@opentiny/tiny-robot 0.4.0-alpha.13 → 0.4.0-alpha.15

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