@opentiny/tiny-robot 0.4.0-alpha.1 → 0.4.0-alpha.11

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