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