@opentiny/tiny-robot-chat 0.0.0 → 0.5.2-alpha.8

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/index.js ADDED
@@ -0,0 +1,2742 @@
1
+ import { defineComponent as J, shallowRef as q, computed as h, watch as ue, onUnmounted as Ne, openBlock as I, createBlock as W, unref as y, createCommentVNode as B, ref as me, toValue as G, createElementBlock as F, createElementVNode as V, resolveDynamicComponent as Ce, normalizeClass as X, createVNode as U, renderSlot as k, toDisplayString as Q, createTextVNode as Ie, mergeProps as N, Fragment as Ae, renderList as Qe, withCtx as E, createSlots as z, normalizeProps as D, guardReactiveProps as j, h as be, nextTick as He, useSlots as Xe, watchEffect as xe, reactive as _e } from "vue";
2
+ import { useScroll as et, useEventListener as tt, useResizeObserver as ot, useMutationObserver as nt, useBreakpoints as st, useWindowSize as at } from "@vueuse/core";
3
+ import { TrIconButton as ae, TrHistory as lt, TrMcpServerPicker as rt, TrDropdownMenu as it, TrSender as dt, TrLayout as ge, BubbleRenderers as ut, useAutoScroll as ct, TrWelcome as Te, TrPrompts as Me, TrBubbleProvider as ft, TrBubbleList as vt } from "@opentiny/tiny-robot";
4
+ import { IconArrowDown as mt, IconAi as le, IconCollapseLeft as he, IconNewSession as pe, IconCollapseRight as Ve, IconPlugin as bt, IconSearch as gt, IconThink as ht, IconAtom as pt, IconUser as yt, IconClose as Ct } from "@opentiny/tiny-robot-svgs";
5
+ import { sseStreamToGenerator as At, toolPlugin as wt, useConversation as St } from "@opentiny/tiny-robot-kit";
6
+ import { Client as kt } from "@modelcontextprotocol/sdk/client";
7
+ import { StreamableHTTPClientTransport as Et } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
8
+ const Ot = /* @__PURE__ */ J({
9
+ __name: "ScrollToBottom",
10
+ props: {
11
+ target: {}
12
+ },
13
+ setup(e) {
14
+ const t = e, n = q(0), { y: o, measure: u } = et(() => t.target, {
15
+ behavior: "smooth",
16
+ observe: !0
17
+ }), m = h(() => n.value > 80);
18
+ function d() {
19
+ const A = t.target;
20
+ n.value = A ? A.scrollHeight - A.clientHeight - A.scrollTop : 0;
21
+ }
22
+ let a;
23
+ function l() {
24
+ a === void 0 && (a = requestAnimationFrame(() => {
25
+ a = void 0, d();
26
+ }));
27
+ }
28
+ tt(() => t.target, "scroll", l), ot(() => t.target, l), nt(() => t.target, l, { childList: !0, subtree: !0 }), ue(
29
+ () => t.target,
30
+ () => l(),
31
+ { immediate: !0 }
32
+ ), Ne(() => {
33
+ a !== void 0 && cancelAnimationFrame(a);
34
+ });
35
+ function b() {
36
+ var A;
37
+ u(), o.value = ((A = t.target) == null ? void 0 : A.scrollHeight) ?? 0;
38
+ }
39
+ return (A, c) => m.value ? (I(), W(y(ae), {
40
+ key: 0,
41
+ class: "tr-chat-scroll-to-bottom",
42
+ icon: y(mt),
43
+ rounded: "",
44
+ size: "36",
45
+ "svg-size": "18",
46
+ type: "button",
47
+ "aria-label": "滚动到底部",
48
+ onClick: b
49
+ }, null, 8, ["icon"])) : B("", !0);
50
+ }
51
+ }), Y = (e, t) => {
52
+ const n = e.__vccOpts || e;
53
+ for (const [o, u] of t)
54
+ n[o] = u;
55
+ return n;
56
+ }, Tt = /* @__PURE__ */ Y(Ot, [["__scopeId", "data-v-ab8c6a28"]]);
57
+ function Mt(e) {
58
+ const t = me([]), n = /* @__PURE__ */ new Map();
59
+ return ue(
60
+ () => [G(e.conversations), G(e.defaultTitle)],
61
+ ([o, u]) => {
62
+ const m = /* @__PURE__ */ new Set(), d = [];
63
+ for (const a of o ?? []) {
64
+ m.add(a.id);
65
+ const b = n.get(a.id) ?? { id: a.id, title: a.title || u, raw: a };
66
+ for (const A of Object.keys(b))
67
+ A !== "raw" && !(A in a) && delete b[A];
68
+ Object.assign(b, a, {
69
+ id: a.id,
70
+ title: a.title || u,
71
+ raw: a
72
+ }), n.set(a.id, b), d.push(b);
73
+ }
74
+ for (const a of n.keys())
75
+ m.has(a) || n.delete(a);
76
+ t.value = d;
77
+ },
78
+ { immediate: !0, deep: !0 }
79
+ ), t;
80
+ }
81
+ const Rt = { class: "chat-left-aside" }, Lt = ["aria-label"], $t = { class: "chat-left-aside-brand" }, It = { class: "chat-left-aside-brand__title" }, Vt = { class: "chat-left-aside-action__label" }, Pt = /* @__PURE__ */ J({
82
+ __name: "ChatLeftAside",
83
+ props: {
84
+ conversation: {},
85
+ history: {},
86
+ brand: {},
87
+ labels: {},
88
+ isOpen: { type: Boolean },
89
+ isDock: { type: Boolean },
90
+ showHistory: { type: Boolean }
91
+ },
92
+ emits: ["createConversation", "switchConversation", "renameConversation", "deleteConversation", "historyAction", "open", "close", "toggle"],
93
+ setup(e, { emit: t }) {
94
+ const n = e, o = t, u = Mt({
95
+ conversations: () => n.conversation.items,
96
+ defaultTitle: () => n.labels.newConversationTitle
97
+ }), m = h(() => {
98
+ const { menuItems: r, ...i } = n.history;
99
+ return i;
100
+ }), d = h(() => n.history.menuItems ?? []);
101
+ function a() {
102
+ o("createConversation");
103
+ }
104
+ function l(r) {
105
+ o("switchConversation", r.raw);
106
+ }
107
+ function b(r, i) {
108
+ o("renameConversation", i.raw, r);
109
+ }
110
+ function A(r, i) {
111
+ o("historyAction", r, i.raw);
112
+ }
113
+ function c(r) {
114
+ return n.conversation.items.find((i) => i.id === r) ?? { id: r, title: n.labels.newConversationTitle };
115
+ }
116
+ function f(r) {
117
+ o("switchConversation", c(r));
118
+ }
119
+ function O(r, i) {
120
+ o("renameConversation", c(r), i);
121
+ }
122
+ function C(r) {
123
+ o("deleteConversation", c(r));
124
+ }
125
+ function L() {
126
+ o("open");
127
+ }
128
+ function T() {
129
+ o("close");
130
+ }
131
+ function p() {
132
+ o("toggle");
133
+ }
134
+ return (r, i) => (I(), F("aside", Rt, [
135
+ V("span", {
136
+ class: "chat-left-aside-logo",
137
+ "aria-label": e.brand.name || e.labels.newConversationTitle
138
+ }, [
139
+ (I(), W(Ce(e.brand.logo || y(le))))
140
+ ], 8, Lt),
141
+ V("div", {
142
+ class: X(["chat-left-aside-rail", { "is-hidden": !e.isDock || e.isOpen }])
143
+ }, [
144
+ U(y(ae), {
145
+ class: "chat-left-aside-rail__button",
146
+ icon: y(he),
147
+ size: "32",
148
+ "svg-size": "20",
149
+ "aria-label": e.labels.expandConversationList,
150
+ onClick: L
151
+ }, null, 8, ["icon", "aria-label"]),
152
+ U(y(ae), {
153
+ class: "chat-left-aside-rail__button",
154
+ icon: y(pe),
155
+ size: "32",
156
+ "svg-size": "20",
157
+ "aria-label": e.labels.createConversation,
158
+ onClick: a
159
+ }, null, 8, ["icon", "aria-label"])
160
+ ], 2),
161
+ V("div", {
162
+ class: X(["chat-left-aside-panel", { "is-hidden": !e.isOpen }])
163
+ }, [
164
+ k(r.$slots, "default", {
165
+ conversation: e.conversation,
166
+ isOpen: e.isOpen,
167
+ createConversation: a,
168
+ switchConversation: f,
169
+ renameConversation: O,
170
+ deleteConversation: C,
171
+ openLeftAside: L,
172
+ closeLeftAside: T,
173
+ toggleLeftAside: p
174
+ }, () => [
175
+ V("div", $t, [
176
+ V("span", It, Q(e.brand.name), 1),
177
+ U(y(ae), {
178
+ icon: y(Ve),
179
+ size: "32",
180
+ "svg-size": "20",
181
+ type: "button",
182
+ "aria-label": e.labels.collapseConversationList,
183
+ onClick: T
184
+ }, null, 8, ["icon", "aria-label"])
185
+ ]),
186
+ V("button", {
187
+ class: "chat-left-aside-action",
188
+ type: "button",
189
+ onClick: a
190
+ }, [
191
+ V("span", Vt, [
192
+ U(y(pe), { "font-size": "20" }),
193
+ Ie(" " + Q(e.labels.createConversation), 1)
194
+ ])
195
+ ]),
196
+ e.showHistory ? (I(), W(y(lt), N({ key: 0 }, m.value, {
197
+ class: "chat-left-aside-content",
198
+ data: [...y(u)],
199
+ selected: e.conversation.activeId ?? void 0,
200
+ "menu-items": d.value,
201
+ onItemClick: l,
202
+ onItemTitleChange: b,
203
+ onItemAction: A
204
+ }), null, 16, ["data", "selected", "menu-items"])) : B("", !0)
205
+ ], !0)
206
+ ], 2)
207
+ ]));
208
+ }
209
+ }), Bt = /* @__PURE__ */ Y(Pt, [["__scopeId", "data-v-110b6ae6"]]), Ut = "data:image/png;base64,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", Ft = {
210
+ key: 0,
211
+ class: "tr-chat-mcp-selector"
212
+ }, Wt = ["aria-label", "title"], Dt = { class: "tr-chat-mcp-selector__label" }, qt = {
213
+ key: 0,
214
+ class: "tr-chat-mcp-selector__count"
215
+ }, Kt = /* @__PURE__ */ J({
216
+ __name: "MCPSelector",
217
+ props: {
218
+ mcp: {},
219
+ labels: {}
220
+ },
221
+ emits: ["addServer", "removeServer", "updateServerEnabled", "updateToolEnabled"],
222
+ setup(e, { emit: t }) {
223
+ const n = e, o = t, u = q(!1), m = {
224
+ type: "drawer",
225
+ drawer: {
226
+ direction: "right"
227
+ }
228
+ }, d = h(() => n.mcp.servers ?? []), a = h(() => n.mcp.tools ?? {}), l = h(() => d.value.length > 0), b = h(() => d.value.filter((s) => s.installed && s.enabled).length), A = h(
229
+ () => d.value.some((s) => {
230
+ var v;
231
+ return !!(s.loading || (v = a.value[s.id]) != null && v.some((S) => S.loading));
232
+ })
233
+ ), c = h(
234
+ () => d.value.filter((s) => s.installed).map((s) => C(s, { includeTools: !0 }))
235
+ ), f = h(
236
+ () => d.value.map((s) => C(s, { includeTools: !1 }))
237
+ );
238
+ function O(s, v) {
239
+ var $;
240
+ const S = ($ = s.metadata) == null ? void 0 : $[v];
241
+ return typeof S == "string" ? S : void 0;
242
+ }
243
+ function C(s, v) {
244
+ const S = v.includeTools && s.installed ? a.value[s.id] ?? [] : [];
245
+ return {
246
+ id: s.id,
247
+ name: s.name,
248
+ icon: O(s, "icon") ?? Ut,
249
+ description: s.description ?? "",
250
+ enabled: s.enabled,
251
+ expanded: !0,
252
+ tools: S.map(($) => ({
253
+ id: $.id,
254
+ name: $.name,
255
+ description: $.description ?? "",
256
+ enabled: $.enabled
257
+ })),
258
+ addState: s.loading ? "loading" : s.installed ? "added" : "idle",
259
+ category: O(s, "category")
260
+ };
261
+ }
262
+ function L(s) {
263
+ return d.value.find((v) => v.id === s);
264
+ }
265
+ function T(s) {
266
+ const v = L(s.id);
267
+ !v || v.installed || v.loading || o("addServer", { id: s.id });
268
+ }
269
+ function p(s) {
270
+ const v = L(s.id);
271
+ !v || !v.installed || v.loading || o("removeServer", { id: s.id });
272
+ }
273
+ function r(s, v) {
274
+ const S = L(s.id);
275
+ !S || !S.installed || S.loading || S.enabled === v || o("updateServerEnabled", { id: s.id, enabled: v });
276
+ }
277
+ function i(s, v, S) {
278
+ var P;
279
+ const $ = L(s.id), w = (P = a.value[s.id]) == null ? void 0 : P.find((Z) => Z.id === v);
280
+ !$ || !$.installed || !w || w.loading || w.enabled === S || o("updateToolEnabled", { serverId: s.id, toolId: v, enabled: S });
281
+ }
282
+ return (s, v) => l.value ? (I(), F("div", Ft, [
283
+ V("button", {
284
+ class: X(["tr-chat-mcp-selector__button", { "tr-chat-mcp-selector__button--active": b.value > 0 }]),
285
+ type: "button",
286
+ "aria-label": e.labels.mcp,
287
+ title: e.labels.mcp,
288
+ onClick: v[0] || (v[0] = (S) => u.value = !0)
289
+ }, [
290
+ U(y(bt), {
291
+ size: 16,
292
+ class: "tr-chat-mcp-selector__icon"
293
+ }),
294
+ V("span", Dt, Q(e.labels.mcp), 1),
295
+ b.value > 0 ? (I(), F("span", qt, Q(b.value), 1)) : B("", !0)
296
+ ], 10, Wt),
297
+ U(y(rt), {
298
+ visible: u.value,
299
+ "onUpdate:visible": v[1] || (v[1] = (S) => u.value = S),
300
+ "active-count": b.value,
301
+ "popup-config": m,
302
+ "installed-plugins": c.value,
303
+ "market-plugins": f.value,
304
+ loading: A.value,
305
+ "market-loading": !1,
306
+ "show-custom-add-button": !1,
307
+ "allow-plugin-delete": !0,
308
+ "allow-tool-toggle": !0,
309
+ onPluginToggle: r,
310
+ onPluginAdd: T,
311
+ onPluginDelete: p,
312
+ onToolToggle: i
313
+ }, null, 8, ["visible", "active-count", "installed-plugins", "market-plugins", "loading"])
314
+ ])) : B("", !0);
315
+ }
316
+ }), zt = /* @__PURE__ */ Y(Kt, [["__scopeId", "data-v-6c32c620"]]), jt = ["low", "medium", "high", "max"], re = ["thinking", "search"], Jt = {
317
+ key: 0,
318
+ class: "tr-chat-model-features"
319
+ }, Zt = ["disabled", "aria-label", "title", "onClick"], Gt = { class: "tr-chat-model-features__label" }, Yt = /* @__PURE__ */ J({
320
+ __name: "ModelFeatures",
321
+ props: {
322
+ model: {},
323
+ labels: {}
324
+ },
325
+ emits: ["updateFeature"],
326
+ setup(e, { emit: t }) {
327
+ const n = e, o = t, u = {
328
+ thinking: "thinkingFeature",
329
+ search: "searchFeature"
330
+ }, m = {
331
+ thinking: ht,
332
+ search: gt
333
+ }, d = h(
334
+ () => re.map((f) => ({
335
+ id: f,
336
+ label: n.labels[u[f]],
337
+ icon: m[f]
338
+ }))
339
+ ), a = h(() => new Set(n.model.pendingFeatureIds ?? [])), l = h(() => {
340
+ var f;
341
+ return (f = n.model.options) == null ? void 0 : f.find((O) => O.id === n.model.selectedId);
342
+ }), b = h(
343
+ () => d.value.filter((f) => {
344
+ var O, C;
345
+ return (C = (O = l.value) == null ? void 0 : O.capabilities) == null ? void 0 : C[f.id];
346
+ })
347
+ );
348
+ function A(f) {
349
+ return a.value.has(f);
350
+ }
351
+ function c(f) {
352
+ var O;
353
+ A(f) || o("updateFeature", { id: f, enabled: !((O = n.model.features) != null && O[f]) });
354
+ }
355
+ return (f, O) => b.value.length ? (I(), F("div", Jt, [
356
+ (I(!0), F(Ae, null, Qe(b.value, (C) => {
357
+ var L;
358
+ return I(), F("button", {
359
+ key: C.id,
360
+ class: X(["tr-chat-model-features__button", { "tr-chat-model-features__button--active": (L = e.model.features) == null ? void 0 : L[C.id] }]),
361
+ type: "button",
362
+ disabled: A(C.id),
363
+ "aria-label": C.label,
364
+ title: C.label,
365
+ onClick: (T) => c(C.id)
366
+ }, [
367
+ (I(), W(Ce(C.icon), {
368
+ size: 16,
369
+ class: "tr-chat-model-features__icon"
370
+ })),
371
+ V("span", Gt, Q(C.label), 1)
372
+ ], 10, Zt);
373
+ }), 128))
374
+ ])) : B("", !0);
375
+ }
376
+ }), Nt = /* @__PURE__ */ Y(Yt, [["__scopeId", "data-v-e63ed58d"]]), Qt = ["disabled", "aria-label", "title"], Ht = { class: "tr-chat-model-selector__label" }, Xt = /* @__PURE__ */ J({
377
+ __name: "ModelSelector",
378
+ props: {
379
+ model: {},
380
+ labels: {}
381
+ },
382
+ emits: ["selectModel"],
383
+ setup(e, { emit: t }) {
384
+ const n = e, o = t, u = h(() => n.model.options ?? []), m = h(() => u.value.find((l) => l.id === n.model.selectedId)), d = h(
385
+ () => u.value.map((l) => ({
386
+ id: l.id,
387
+ text: l.label
388
+ }))
389
+ );
390
+ function a(l) {
391
+ n.model.selecting || l.id === n.model.selectedId || o("selectModel", { id: l.id });
392
+ }
393
+ return (l, b) => u.value.length ? (I(), W(y(it), {
394
+ key: 0,
395
+ class: "tr-chat-model-selector__menu",
396
+ items: d.value,
397
+ trigger: "click",
398
+ onItemClick: a
399
+ }, {
400
+ trigger: E(() => {
401
+ var A, c, f;
402
+ return [
403
+ V("button", {
404
+ class: "tr-chat-model-selector__button",
405
+ type: "button",
406
+ disabled: e.model.selecting,
407
+ "aria-label": ((A = m.value) == null ? void 0 : A.label) || e.labels.selectModel,
408
+ title: ((c = m.value) == null ? void 0 : c.label) || e.labels.selectModel
409
+ }, [
410
+ U(y(pt), {
411
+ size: 16,
412
+ class: "tr-chat-model-selector__icon"
413
+ }),
414
+ V("span", Ht, Q(((f = m.value) == null ? void 0 : f.label) || e.labels.selectModel), 1)
415
+ ], 8, Qt)
416
+ ];
417
+ }),
418
+ _: 1
419
+ }, 8, ["items"])) : B("", !0);
420
+ }
421
+ }), xt = /* @__PURE__ */ Y(Xt, [["__scopeId", "data-v-173603c5"]]), _t = { class: "chat-footer" }, eo = {
422
+ key: 0,
423
+ class: "model-actions"
424
+ }, to = /* @__PURE__ */ J({
425
+ __name: "ChatComposer",
426
+ props: {
427
+ sender: {},
428
+ value: {},
429
+ senderOptions: {},
430
+ labels: {},
431
+ model: {},
432
+ mcp: {}
433
+ },
434
+ emits: ["submit", "cancel", "clear", "update:value", "modelSelect", "modelFeatureChange", "mcpAddServer", "mcpRemoveServer", "mcpServerEnabledChange", "mcpToolEnabledChange"],
435
+ setup(e, { emit: t }) {
436
+ const n = e, o = t, u = h(() => {
437
+ var C;
438
+ return {
439
+ mode: "multiple",
440
+ clearable: !0,
441
+ placeholder: n.sender.loading ? n.labels.composerLoadingPlaceholder : n.labels.composerPlaceholder,
442
+ showWordLimit: !0,
443
+ maxLength: 1e3,
444
+ ...n.senderOptions,
445
+ defaultActions: {
446
+ ...n.senderOptions.defaultActions,
447
+ submit: {
448
+ ...(C = n.senderOptions.defaultActions) == null ? void 0 : C.submit,
449
+ disabled: n.sender.submitDisabled
450
+ }
451
+ },
452
+ modelValue: n.value,
453
+ loading: n.sender.loading,
454
+ disabled: n.sender.disabled
455
+ };
456
+ });
457
+ function m(C) {
458
+ o("update:value", C);
459
+ }
460
+ function d(C, L) {
461
+ o("submit", { text: C, structuredData: L });
462
+ }
463
+ function a() {
464
+ o("clear");
465
+ }
466
+ function l(C) {
467
+ o("modelSelect", C);
468
+ }
469
+ function b(C) {
470
+ o("modelFeatureChange", C);
471
+ }
472
+ function A(C) {
473
+ o("mcpAddServer", C);
474
+ }
475
+ function c(C) {
476
+ o("mcpRemoveServer", C);
477
+ }
478
+ function f(C) {
479
+ o("mcpServerEnabledChange", C);
480
+ }
481
+ function O(C) {
482
+ o("mcpToolEnabledChange", C);
483
+ }
484
+ return (C, L) => (I(), F("div", _t, [
485
+ k(C.$slots, "composer-before", {}, void 0, !0),
486
+ k(C.$slots, "default", {}, () => [
487
+ U(y(dt), N(u.value, {
488
+ "onUpdate:modelValue": m,
489
+ onSubmit: d,
490
+ onCancel: L[0] || (L[0] = (T) => o("cancel")),
491
+ onClear: a
492
+ }), z({ _: 2 }, [
493
+ C.$slots["sender-footer"] || e.model || e.mcp ? {
494
+ name: "footer",
495
+ fn: E(() => [
496
+ e.model || e.mcp ? (I(), F("div", eo, [
497
+ e.mcp ? (I(), W(zt, {
498
+ key: 0,
499
+ mcp: e.mcp,
500
+ labels: e.labels,
501
+ onAddServer: A,
502
+ onRemoveServer: c,
503
+ onUpdateServerEnabled: f,
504
+ onUpdateToolEnabled: O
505
+ }, null, 8, ["mcp", "labels"])) : B("", !0),
506
+ e.model ? (I(), W(xt, {
507
+ key: 1,
508
+ model: e.model,
509
+ labels: e.labels,
510
+ onSelectModel: l
511
+ }, null, 8, ["model", "labels"])) : B("", !0),
512
+ e.model ? (I(), W(Nt, {
513
+ key: 2,
514
+ model: e.model,
515
+ labels: e.labels,
516
+ onUpdateFeature: b
517
+ }, null, 8, ["model", "labels"])) : B("", !0)
518
+ ])) : B("", !0),
519
+ k(C.$slots, "sender-footer", {}, void 0, !0)
520
+ ]),
521
+ key: "0"
522
+ } : void 0,
523
+ C.$slots["sender-footer-right"] ? {
524
+ name: "footer-right",
525
+ fn: E(() => [
526
+ k(C.$slots, "sender-footer-right", {}, void 0, !0)
527
+ ]),
528
+ key: "1"
529
+ } : void 0
530
+ ]), 1040)
531
+ ], !0)
532
+ ]));
533
+ }
534
+ }), oo = /* @__PURE__ */ Y(to, [["__scopeId", "data-v-88ebb4ad"]]), Re = /* @__PURE__ */ J({
535
+ __name: "ChatComposerHost",
536
+ props: {
537
+ sender: {},
538
+ value: {},
539
+ senderOptions: {},
540
+ labels: {},
541
+ model: {},
542
+ mcp: {}
543
+ },
544
+ emits: ["submit", "cancel", "clear", "update:value", "modelSelect", "modelFeatureChange", "mcpAddServer", "mcpRemoveServer", "mcpServerEnabledChange", "mcpToolEnabledChange"],
545
+ setup(e, { emit: t }) {
546
+ const n = e, o = t;
547
+ function u(a) {
548
+ o("update:value", a);
549
+ }
550
+ function m(a) {
551
+ o("submit", a);
552
+ }
553
+ const d = h(() => ({
554
+ value: n.value,
555
+ loading: n.sender.loading,
556
+ disabled: n.sender.disabled,
557
+ submitDisabled: n.sender.submitDisabled,
558
+ setInputValue: u,
559
+ submit: m,
560
+ cancel: () => o("cancel"),
561
+ clear: () => o("clear")
562
+ }));
563
+ return (a, l) => (I(), W(oo, {
564
+ sender: n.sender,
565
+ value: n.value,
566
+ "sender-options": n.senderOptions,
567
+ labels: n.labels,
568
+ model: n.model,
569
+ mcp: n.mcp,
570
+ onSubmit: l[0] || (l[0] = (b) => o("submit", b)),
571
+ onCancel: l[1] || (l[1] = (b) => o("cancel")),
572
+ onClear: l[2] || (l[2] = (b) => o("clear")),
573
+ "onUpdate:value": l[3] || (l[3] = (b) => o("update:value", b)),
574
+ onModelSelect: l[4] || (l[4] = (b) => o("modelSelect", b)),
575
+ onModelFeatureChange: l[5] || (l[5] = (b) => o("modelFeatureChange", b)),
576
+ onMcpAddServer: l[6] || (l[6] = (b) => o("mcpAddServer", b)),
577
+ onMcpRemoveServer: l[7] || (l[7] = (b) => o("mcpRemoveServer", b)),
578
+ onMcpServerEnabledChange: l[8] || (l[8] = (b) => o("mcpServerEnabledChange", b)),
579
+ onMcpToolEnabledChange: l[9] || (l[9] = (b) => o("mcpToolEnabledChange", b))
580
+ }, z({ _: 2 }, [
581
+ a.$slots["composer-before"] ? {
582
+ name: "composer-before",
583
+ fn: E(() => [
584
+ k(a.$slots, "composer-before", D(j(d.value)))
585
+ ]),
586
+ key: "0"
587
+ } : void 0,
588
+ a.$slots["layout-footer"] ? {
589
+ name: "default",
590
+ fn: E(() => [
591
+ k(a.$slots, "layout-footer", D(j(d.value)))
592
+ ]),
593
+ key: "1"
594
+ } : void 0,
595
+ a.$slots["sender-footer"] ? {
596
+ name: "sender-footer",
597
+ fn: E(() => [
598
+ k(a.$slots, "sender-footer")
599
+ ]),
600
+ key: "2"
601
+ } : void 0,
602
+ a.$slots["sender-footer-right"] ? {
603
+ name: "sender-footer-right",
604
+ fn: E(() => [
605
+ k(a.$slots, "sender-footer-right")
606
+ ]),
607
+ key: "3"
608
+ } : void 0
609
+ ]), 1032, ["sender", "value", "sender-options", "labels", "model", "mcp"]));
610
+ }
611
+ }), no = {
612
+ key: 0,
613
+ class: "chat-notice"
614
+ }, so = { class: "chat-header" }, ao = { class: "chat-header__aside-cell" }, lo = ["aria-label"], ro = { class: "chat-header__title" }, io = { class: "chat-header__actions" }, uo = ["aria-label", "title"], co = ["aria-label"], fo = /* @__PURE__ */ J({
615
+ __name: "ChatHeader",
616
+ props: {
617
+ title: {},
618
+ isEmpty: { type: Boolean },
619
+ conversation: {},
620
+ isLeftAsideVisible: { type: Boolean },
621
+ isLeftAsideDrawer: { type: Boolean },
622
+ isLeftAsideOpen: { type: Boolean },
623
+ isRightAsideVisible: { type: Boolean },
624
+ isRightAsideOpen: { type: Boolean },
625
+ labels: {}
626
+ },
627
+ emits: ["createConversation", "openLeftAside", "closeLeftAside", "toggleLeftAside", "openRightAside"],
628
+ setup(e, { emit: t }) {
629
+ const n = t;
630
+ function o() {
631
+ n("createConversation");
632
+ }
633
+ function u() {
634
+ n("openLeftAside");
635
+ }
636
+ function m() {
637
+ n("closeLeftAside");
638
+ }
639
+ function d() {
640
+ n("toggleLeftAside");
641
+ }
642
+ function a() {
643
+ n("openRightAside");
644
+ }
645
+ return (l, b) => (I(), F(Ae, null, [
646
+ l.$slots.notice ? (I(), F("div", no, [
647
+ k(l.$slots, "notice", {}, void 0, !0)
648
+ ])) : B("", !0),
649
+ k(l.$slots, "default", {
650
+ title: e.title,
651
+ isEmpty: e.isEmpty,
652
+ conversation: e.conversation,
653
+ createConversation: o,
654
+ isLeftAsideOpen: e.isLeftAsideOpen,
655
+ openLeftAside: u,
656
+ closeLeftAside: m,
657
+ toggleLeftAside: d,
658
+ openRightAside: a
659
+ }, () => [
660
+ V("header", so, [
661
+ V("div", ao, [
662
+ e.isLeftAsideVisible && e.isLeftAsideDrawer ? (I(), W(y(ge).AsideToggle, {
663
+ key: 0,
664
+ side: "left"
665
+ }, {
666
+ default: E(({ isOpen: A }) => [
667
+ V("span", {
668
+ class: "chat-header__aside-toggle",
669
+ "aria-label": A ? e.labels.collapseConversationList : e.labels.expandConversationList
670
+ }, [
671
+ (I(), W(Ce(A ? y(Ve) : y(he)), { size: 20 }))
672
+ ], 8, lo)
673
+ ]),
674
+ _: 1
675
+ })) : B("", !0)
676
+ ]),
677
+ V("h3", ro, Q(e.title), 1),
678
+ V("div", io, [
679
+ e.isRightAsideVisible && !e.isRightAsideOpen ? (I(), F("button", {
680
+ key: 0,
681
+ class: "chat-header__aside-action",
682
+ type: "button",
683
+ "aria-label": e.labels.openRightAside,
684
+ title: e.labels.openRightAside,
685
+ onClick: a
686
+ }, [
687
+ U(y(he), { size: 18 })
688
+ ], 8, uo)) : B("", !0),
689
+ !e.isEmpty || !e.isLeftAsideVisible ? (I(), F("button", {
690
+ key: 1,
691
+ class: X(["chat-header__new", { "chat-header__new--visible": !e.isLeftAsideVisible }]),
692
+ type: "button",
693
+ "aria-label": e.labels.createConversation,
694
+ onClick: o
695
+ }, [
696
+ U(y(pe), { size: 20 })
697
+ ], 10, co)) : B("", !0)
698
+ ])
699
+ ])
700
+ ], !0)
701
+ ], 64));
702
+ }
703
+ }), vo = /* @__PURE__ */ Y(fo, [["__scopeId", "data-v-616b4d3a"]]), mo = {
704
+ key: 0,
705
+ class: "chat-welcome-content"
706
+ }, bo = /* @__PURE__ */ J({
707
+ __name: "ChatMessages",
708
+ props: {
709
+ messages: {},
710
+ scrollTarget: {},
711
+ options: {},
712
+ welcome: { type: [Boolean, Object] },
713
+ prompts: { type: [Boolean, Object] },
714
+ labels: {},
715
+ centerEmptyState: { type: Boolean },
716
+ centerWelcomeComposer: { type: Boolean }
717
+ },
718
+ emits: ["promptClick", "bubbleStateChange", "bubbleEvent"],
719
+ setup(e, { emit: t }) {
720
+ const n = e, o = t, u = be(le, { style: { fontSize: "28px" } }), m = be(yt, { style: { fontSize: "28px" } }), d = {
721
+ assistant: {
722
+ placement: "start",
723
+ avatar: u
724
+ },
725
+ user: {
726
+ placement: "end",
727
+ avatar: m
728
+ },
729
+ system: {
730
+ hidden: !0
731
+ }
732
+ }, a = h(() => n.messages.length === 0), l = h(() => n.messages.at(-1)), b = h(() => n.messages.map((s) => ({ ...s }))), A = h(() => n.options.autoScroll ?? !0), c = h(() => ({
733
+ fallbackContentRenderer: ut.Markdown,
734
+ ...n.options.bubbleProvider
735
+ })), f = h(() => {
736
+ const s = n.options.bubbleList, v = {
737
+ ...d,
738
+ ...Object.fromEntries(
739
+ Object.entries(s.roleConfigs ?? {}).map(([S, $]) => [
740
+ S,
741
+ {
742
+ ...d[S],
743
+ ...$
744
+ }
745
+ ])
746
+ )
747
+ };
748
+ return {
749
+ ...s,
750
+ roleConfigs: v,
751
+ autoScroll: !1
752
+ };
753
+ }), O = h(() => n.welcome === !1 ? null : n.welcome), C = h(() => n.prompts === !1 ? {
754
+ items: []
755
+ } : {
756
+ ...n.prompts,
757
+ items: [...n.prompts.items ?? []]
758
+ }), L = h(() => n.prompts !== !1 && C.value.items.length > 0), { scrollToBottom: T } = ct(
759
+ () => n.scrollTarget,
760
+ () => {
761
+ var s, v;
762
+ return A.value ? [n.messages.length, (s = l.value) == null ? void 0 : s.content, (v = l.value) == null ? void 0 : v.reasoning_content] : null;
763
+ }
764
+ );
765
+ ue(
766
+ () => {
767
+ var s;
768
+ return (s = l.value) == null ? void 0 : s.role;
769
+ },
770
+ async (s) => {
771
+ A.value && s === "user" && (await He(), T("smooth"));
772
+ }
773
+ );
774
+ function p(s, v) {
775
+ v.disabled || o("promptClick", s, v);
776
+ }
777
+ function r(s) {
778
+ o("bubbleStateChange", s);
779
+ }
780
+ function i(s) {
781
+ o("bubbleEvent", s);
782
+ }
783
+ return (s, v) => (I(), F("div", {
784
+ class: X(["chat-panel-content chat-panel-content--main", {
785
+ "is-message-state": !a.value
786
+ }])
787
+ }, [
788
+ k(s.$slots, "default", {}, () => [
789
+ a.value ? (I(), F("div", {
790
+ key: 0,
791
+ class: X(["chat-empty-content", {
792
+ "chat-empty-content--centered": n.centerEmptyState || n.centerWelcomeComposer
793
+ }])
794
+ }, [
795
+ s.$slots["welcome-composer"] ? (I(), F("div", mo, [
796
+ O.value ? (I(), W(y(Te), D(N({ key: 0 }, O.value)), {
797
+ footer: E(() => [
798
+ k(s.$slots, "welcome-footer", {}, void 0, !0),
799
+ k(s.$slots, "welcome-composer", {}, void 0, !0)
800
+ ]),
801
+ _: 3
802
+ }, 16)) : B("", !0),
803
+ L.value ? (I(), W(y(Me), N({ key: 1 }, C.value, { onItemClick: p }), z({ _: 2 }, [
804
+ s.$slots["prompts-footer"] ? {
805
+ name: "footer",
806
+ fn: E(() => [
807
+ k(s.$slots, "prompts-footer", {}, void 0, !0)
808
+ ]),
809
+ key: "0"
810
+ } : void 0
811
+ ]), 1040)) : B("", !0)
812
+ ])) : (I(), F(Ae, { key: 1 }, [
813
+ O.value ? (I(), W(y(Te), D(N({ key: 0 }, O.value)), z({ _: 2 }, [
814
+ s.$slots["welcome-footer"] ? {
815
+ name: "footer",
816
+ fn: E(() => [
817
+ k(s.$slots, "welcome-footer", {}, void 0, !0)
818
+ ]),
819
+ key: "0"
820
+ } : void 0
821
+ ]), 1040)) : B("", !0),
822
+ L.value ? (I(), W(y(Me), N({ key: 1 }, C.value, { onItemClick: p }), z({ _: 2 }, [
823
+ s.$slots["prompts-footer"] ? {
824
+ name: "footer",
825
+ fn: E(() => [
826
+ k(s.$slots, "prompts-footer", {}, void 0, !0)
827
+ ]),
828
+ key: "0"
829
+ } : void 0
830
+ ]), 1040)) : B("", !0)
831
+ ], 64))
832
+ ], 2)) : (I(), W(y(ft), D(N({ key: 1 }, c.value)), {
833
+ default: E(() => [
834
+ U(y(vt), N(f.value, {
835
+ class: "tr-chat-messages__bubble-list",
836
+ messages: b.value,
837
+ onStateChange: r,
838
+ onBubbleEvent: i
839
+ }), z({ _: 2 }, [
840
+ s.$slots["bubble-prefix"] ? {
841
+ name: "prefix",
842
+ fn: E(() => [
843
+ k(s.$slots, "bubble-prefix", {}, void 0, !0)
844
+ ]),
845
+ key: "0"
846
+ } : void 0,
847
+ s.$slots["bubble-suffix"] ? {
848
+ name: "suffix",
849
+ fn: E(() => [
850
+ k(s.$slots, "bubble-suffix", {}, void 0, !0)
851
+ ]),
852
+ key: "1"
853
+ } : void 0,
854
+ s.$slots["bubble-after"] ? {
855
+ name: "after",
856
+ fn: E(() => [
857
+ k(s.$slots, "bubble-after", {}, void 0, !0)
858
+ ]),
859
+ key: "2"
860
+ } : void 0,
861
+ s.$slots["bubble-content-footer"] ? {
862
+ name: "content-footer",
863
+ fn: E(() => [
864
+ k(s.$slots, "bubble-content-footer", {}, void 0, !0)
865
+ ]),
866
+ key: "3"
867
+ } : void 0
868
+ ]), 1040, ["messages"])
869
+ ]),
870
+ _: 3
871
+ }, 16))
872
+ ], !0)
873
+ ], 2));
874
+ }
875
+ }), go = /* @__PURE__ */ Y(bo, [["__scopeId", "data-v-d0b8924e"]]), ho = { class: "chat-right-aside" }, po = { class: "chat-right-aside__header" }, yo = ["aria-label", "title"], Co = { class: "chat-right-aside__body" }, Ao = /* @__PURE__ */ J({
876
+ __name: "ChatRightAside",
877
+ props: {
878
+ showClose: { type: Boolean, default: !0 },
879
+ labels: {}
880
+ },
881
+ emits: ["close"],
882
+ setup(e, { emit: t }) {
883
+ const n = t;
884
+ return (o, u) => (I(), F("section", ho, [
885
+ V("header", po, [
886
+ k(o.$slots, "title", {}, void 0, !0),
887
+ e.showClose ? (I(), F("button", {
888
+ key: 0,
889
+ class: "chat-right-aside__close",
890
+ type: "button",
891
+ "aria-label": e.labels.closeRightAside,
892
+ title: e.labels.closeRightAside,
893
+ onClick: u[0] || (u[0] = (m) => n("close"))
894
+ }, [
895
+ U(y(Ct), { class: "chat-right-aside__close-icon" })
896
+ ], 8, yo)) : B("", !0)
897
+ ]),
898
+ V("div", Co, [
899
+ k(o.$slots, "default", {}, void 0, !0)
900
+ ])
901
+ ]));
902
+ }
903
+ }), wo = /* @__PURE__ */ Y(Ao, [["__scopeId", "data-v-1013d8c6"]]);
904
+ function se(e, t) {
905
+ return typeof e == "number" ? e : t;
906
+ }
907
+ function So(e) {
908
+ const t = G(e.leftAside), n = G(e.rightAside), o = q(t !== !1 ? (t == null ? void 0 : t.open) ?? (t == null ? void 0 : t.defaultOpen) ?? !1 : !1), u = q(
909
+ n !== !1 ? (n == null ? void 0 : n.open) ?? (n == null ? void 0 : n.defaultOpen) ?? !1 : !1
910
+ ), m = h(() => G(e.isMobileViewport)), d = h(() => G(e.viewportWidth)), a = h(() => G(e.leftAside)), l = h(() => G(e.rightAside)), b = h(() => {
911
+ const p = a.value;
912
+ return p !== !1 ? (p == null ? void 0 : p.open) ?? o.value : !1;
913
+ }), A = h(() => {
914
+ const p = l.value;
915
+ return p !== !1 ? (p == null ? void 0 : p.open) ?? u.value : !1;
916
+ }), c = h(
917
+ () => {
918
+ var p;
919
+ return m.value ? "drawer" : a.value !== !1 ? (p = a.value) == null ? void 0 : p.mode : "dock";
920
+ }
921
+ ), f = h(
922
+ () => {
923
+ var p;
924
+ return m.value ? "drawer" : l.value !== !1 ? (p = l.value) == null ? void 0 : p.mode : "dock";
925
+ }
926
+ ), O = h(() => {
927
+ const p = a.value, r = se(p !== !1 ? p == null ? void 0 : p.width : void 0, 300);
928
+ return {
929
+ mode: c.value,
930
+ open: b.value,
931
+ expandedWidth: m.value && d.value > 0 ? Math.min(r, Math.floor(d.value * 0.86)) : r,
932
+ collapsedWidth: m.value || p === !1 ? 0 : se(p == null ? void 0 : p.collapsedWidth, 56),
933
+ collapseEffect: "overlay"
934
+ };
935
+ }), C = h(() => {
936
+ const p = l.value, r = m.value && d.value > 0 ? d.value : void 0;
937
+ return {
938
+ mode: f.value,
939
+ open: A.value,
940
+ expandedWidth: r ?? se(p !== !1 ? p == null ? void 0 : p.width : void 0, 320),
941
+ minExpandedWidth: r,
942
+ maxExpandedWidth: r,
943
+ collapsedWidth: m.value || p === !1 ? 0 : se(p == null ? void 0 : p.collapsedWidth, 0),
944
+ collapseEffect: "overlay"
945
+ };
946
+ });
947
+ function L(p, r = "user") {
948
+ var i;
949
+ b.value !== p && (a.value !== !1 && ((i = a.value) == null ? void 0 : i.open) === void 0 && (o.value = p), e.onLeftOpenChange({ open: p, source: r }));
950
+ }
951
+ function T(p, r = "user") {
952
+ var i;
953
+ A.value !== p && (l.value !== !1 && ((i = l.value) == null ? void 0 : i.open) === void 0 && (u.value = p), e.onRightOpenChange({ open: p, source: r }));
954
+ }
955
+ return ue(m, (p) => {
956
+ p && (L(!1, "viewport"), T(!1, "viewport"));
957
+ }), {
958
+ leftAsideOptions: O,
959
+ rightAsideOptions: C,
960
+ resolvedLeftAsideOpen: b,
961
+ resolvedRightAsideOpen: A,
962
+ isLeftAsideDock: h(() => c.value === "dock"),
963
+ isLeftAsideDrawer: h(() => c.value === "drawer"),
964
+ openLeftAside: () => L(!0),
965
+ closeLeftAside: () => L(!1),
966
+ toggleLeftAside: () => L(!b.value),
967
+ closeRightAside: () => T(!1),
968
+ openRightAside: () => T(!0),
969
+ handleLeftAsideOpenChange: (p) => L(p.open),
970
+ handleRightAsideOpenChange: (p) => T(p.open)
971
+ };
972
+ }
973
+ function ko() {
974
+ return {
975
+ newConversationTitle: "新对话",
976
+ createConversation: "新建会话",
977
+ renameConversation: "重命名",
978
+ deleteConversation: "删除",
979
+ expandConversationList: "展开会话列表",
980
+ collapseConversationList: "收起会话列表",
981
+ composerPlaceholder: "请输入你的问题...",
982
+ composerLoadingPlaceholder: "思考中...",
983
+ selectModel: "选择模型",
984
+ rightAsideTitle: "详情",
985
+ mcp: "MCP",
986
+ thinkingFeature: "深度思考",
987
+ searchFeature: "联网搜索",
988
+ welcomeTitle: "TinyRobot AI 助手",
989
+ welcomeDescription: "您好,我是TinyRobot,您专属的 AI 智能专家",
990
+ openRightAside: "打开详情",
991
+ closeRightAside: "关闭详情"
992
+ };
993
+ }
994
+ function Eo() {
995
+ const e = ko();
996
+ return {
997
+ layout: {
998
+ surface: {
999
+ mode: "normal"
1000
+ },
1001
+ emptyState: "start",
1002
+ composer: {
1003
+ welcome: "footer"
1004
+ },
1005
+ contentMaxWidth: 980,
1006
+ panelPadding: 12,
1007
+ panelGap: 12,
1008
+ leftAside: {
1009
+ mode: "dock",
1010
+ width: 300,
1011
+ collapsedWidth: 56,
1012
+ defaultOpen: !1
1013
+ },
1014
+ rightAside: !1
1015
+ },
1016
+ brand: {
1017
+ name: "TinyRobot",
1018
+ logo: le
1019
+ },
1020
+ labels: e,
1021
+ history: {
1022
+ menuItems: [
1023
+ { id: "rename", text: e.renameConversation },
1024
+ { id: "delete", text: e.deleteConversation }
1025
+ ]
1026
+ },
1027
+ bubble: {
1028
+ autoScroll: !0,
1029
+ bubbleList: {
1030
+ roleConfigs: {
1031
+ system: {
1032
+ hidden: !0
1033
+ }
1034
+ }
1035
+ }
1036
+ },
1037
+ welcome: {
1038
+ title: e.welcomeTitle,
1039
+ description: e.welcomeDescription,
1040
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1041
+ icon: be(le, { style: { fontSize: "40px" } })
1042
+ },
1043
+ prompts: {
1044
+ items: []
1045
+ },
1046
+ sender: {
1047
+ mode: "multiple",
1048
+ clearable: !0,
1049
+ maxLength: 1e3,
1050
+ showWordLimit: !0
1051
+ },
1052
+ model: {},
1053
+ mcp: {}
1054
+ };
1055
+ }
1056
+ function Oo(e) {
1057
+ return {
1058
+ conversation: {
1059
+ items: [],
1060
+ activeId: null,
1061
+ title: e.newConversationTitle
1062
+ },
1063
+ bubble: {
1064
+ messages: []
1065
+ },
1066
+ sender: {
1067
+ loading: !1,
1068
+ disabled: !1,
1069
+ submitDisabled: !1
1070
+ },
1071
+ model: void 0,
1072
+ mcp: void 0
1073
+ };
1074
+ }
1075
+ function To(e, t) {
1076
+ var o, u, m, d, a, l, b;
1077
+ const n = Oo(t);
1078
+ return {
1079
+ conversation: {
1080
+ items: ((o = e == null ? void 0 : e.conversation) == null ? void 0 : o.items) ?? n.conversation.items,
1081
+ activeId: ((u = e == null ? void 0 : e.conversation) == null ? void 0 : u.activeId) ?? n.conversation.activeId,
1082
+ title: ((m = e == null ? void 0 : e.conversation) == null ? void 0 : m.title) ?? n.conversation.title
1083
+ },
1084
+ bubble: {
1085
+ messages: ((d = e == null ? void 0 : e.bubble) == null ? void 0 : d.messages) ?? n.bubble.messages
1086
+ },
1087
+ sender: {
1088
+ loading: ((a = e == null ? void 0 : e.sender) == null ? void 0 : a.loading) ?? n.sender.loading,
1089
+ disabled: ((l = e == null ? void 0 : e.sender) == null ? void 0 : l.disabled) ?? n.sender.disabled,
1090
+ submitDisabled: ((b = e == null ? void 0 : e.sender) == null ? void 0 : b.submitDisabled) ?? n.sender.submitDisabled
1091
+ },
1092
+ request: e == null ? void 0 : e.request,
1093
+ model: (e == null ? void 0 : e.model) ?? n.model,
1094
+ mcp: (e == null ? void 0 : e.mcp) ?? n.mcp
1095
+ };
1096
+ }
1097
+ function Mo(e) {
1098
+ const t = Eo(), n = Ro(t.labels, e == null ? void 0 : e.labels);
1099
+ return {
1100
+ layout: Lo(t.layout, e == null ? void 0 : e.layout),
1101
+ brand: Vo(t.brand, e == null ? void 0 : e.brand),
1102
+ labels: n,
1103
+ header: (e == null ? void 0 : e.header) !== !1,
1104
+ history: Po(t.history, e == null ? void 0 : e.history, n),
1105
+ bubble: Bo(t.bubble, e == null ? void 0 : e.bubble),
1106
+ welcome: Uo(t.welcome, e == null ? void 0 : e.welcome, n),
1107
+ prompts: Fo(t.prompts, e == null ? void 0 : e.prompts),
1108
+ sender: Wo(t.sender, e == null ? void 0 : e.sender),
1109
+ model: Do(e == null ? void 0 : e.model),
1110
+ mcp: qo(e == null ? void 0 : e.mcp)
1111
+ };
1112
+ }
1113
+ function Ro(e, t) {
1114
+ return {
1115
+ ...e,
1116
+ ...H(t)
1117
+ };
1118
+ }
1119
+ function Lo(e, t) {
1120
+ var n, o, u;
1121
+ return {
1122
+ surface: {
1123
+ mode: ((n = t == null ? void 0 : t.surface) == null ? void 0 : n.mode) ?? e.surface.mode,
1124
+ floatingOptions: (o = t == null ? void 0 : t.surface) == null ? void 0 : o.floatingOptions
1125
+ },
1126
+ emptyState: (t == null ? void 0 : t.emptyState) ?? e.emptyState,
1127
+ composer: {
1128
+ welcome: ((u = t == null ? void 0 : t.composer) == null ? void 0 : u.welcome) ?? e.composer.welcome
1129
+ },
1130
+ contentMaxWidth: (t == null ? void 0 : t.contentMaxWidth) ?? e.contentMaxWidth,
1131
+ panelPadding: (t == null ? void 0 : t.panelPadding) ?? e.panelPadding,
1132
+ panelGap: (t == null ? void 0 : t.panelGap) ?? e.panelGap,
1133
+ leftAside: $o(e.leftAside, t == null ? void 0 : t.leftAside),
1134
+ rightAside: Io(t == null ? void 0 : t.rightAside)
1135
+ };
1136
+ }
1137
+ function $o(e, t) {
1138
+ return t === !1 ? !1 : {
1139
+ mode: (t == null ? void 0 : t.mode) ?? e.mode,
1140
+ width: (t == null ? void 0 : t.width) ?? e.width,
1141
+ collapsedWidth: (t == null ? void 0 : t.collapsedWidth) ?? e.collapsedWidth,
1142
+ open: t == null ? void 0 : t.open,
1143
+ defaultOpen: (t == null ? void 0 : t.defaultOpen) ?? e.defaultOpen
1144
+ };
1145
+ }
1146
+ function Io(e) {
1147
+ return e === !1 || !e ? !1 : {
1148
+ open: e == null ? void 0 : e.open,
1149
+ mode: (e == null ? void 0 : e.mode) ?? "dock",
1150
+ width: (e == null ? void 0 : e.width) ?? 320,
1151
+ collapsedWidth: (e == null ? void 0 : e.collapsedWidth) ?? 0,
1152
+ defaultOpen: (e == null ? void 0 : e.defaultOpen) ?? !0,
1153
+ showClose: (e == null ? void 0 : e.showClose) ?? !0
1154
+ };
1155
+ }
1156
+ function Vo(e, t) {
1157
+ return {
1158
+ ...e,
1159
+ ...H(t)
1160
+ };
1161
+ }
1162
+ function Po(e, t, n) {
1163
+ if (t === !1)
1164
+ return !1;
1165
+ const o = {
1166
+ ...e,
1167
+ menuItems: [
1168
+ { id: "rename", text: n.renameConversation },
1169
+ { id: "delete", text: n.deleteConversation }
1170
+ ]
1171
+ };
1172
+ return {
1173
+ ...o,
1174
+ ...H(t),
1175
+ menuItems: t != null && t.menuItems ? [...t.menuItems] : [...o.menuItems]
1176
+ };
1177
+ }
1178
+ function Bo(e, t) {
1179
+ var n, o;
1180
+ return {
1181
+ ...e,
1182
+ ...H(t),
1183
+ autoScroll: (t == null ? void 0 : t.autoScroll) ?? e.autoScroll,
1184
+ bubbleProvider: (t == null ? void 0 : t.bubbleProvider) ?? e.bubbleProvider,
1185
+ bubbleList: {
1186
+ ...e.bubbleList,
1187
+ ...H(t == null ? void 0 : t.bubbleList),
1188
+ roleConfigs: {
1189
+ ...(n = e.bubbleList) == null ? void 0 : n.roleConfigs,
1190
+ ...Ko((o = t == null ? void 0 : t.bubbleList) == null ? void 0 : o.roleConfigs)
1191
+ }
1192
+ }
1193
+ };
1194
+ }
1195
+ function Uo(e, t, n) {
1196
+ if (t === !1)
1197
+ return !1;
1198
+ const o = {
1199
+ ...e,
1200
+ title: n.welcomeTitle,
1201
+ description: n.welcomeDescription
1202
+ };
1203
+ return {
1204
+ ...o,
1205
+ ...H(t),
1206
+ title: (t == null ? void 0 : t.title) ?? o.title,
1207
+ description: (t == null ? void 0 : t.description) ?? o.description
1208
+ };
1209
+ }
1210
+ function Fo(e, t) {
1211
+ return t === !1 ? !1 : {
1212
+ ...e,
1213
+ ...H(t),
1214
+ items: [...(t == null ? void 0 : t.items) ?? e.items]
1215
+ };
1216
+ }
1217
+ function Wo(e, t) {
1218
+ return t === !1 ? !1 : {
1219
+ ...e,
1220
+ ...H(t)
1221
+ };
1222
+ }
1223
+ function Do(e) {
1224
+ return e === !1 ? !1 : e ?? {};
1225
+ }
1226
+ function qo(e) {
1227
+ return e === !1 ? !1 : e ?? {};
1228
+ }
1229
+ function H(e) {
1230
+ const t = {};
1231
+ if (!e)
1232
+ return t;
1233
+ for (const n of Object.keys(e))
1234
+ e[n] !== void 0 && (t[n] = e[n]);
1235
+ return t;
1236
+ }
1237
+ function Ko(e) {
1238
+ const t = {};
1239
+ if (!e)
1240
+ return t;
1241
+ for (const [n, o] of Object.entries(e))
1242
+ o !== void 0 && (t[n] = o);
1243
+ return t;
1244
+ }
1245
+ function zo(e) {
1246
+ if (e instanceof Error)
1247
+ return e.message || String(e);
1248
+ if (typeof e == "string")
1249
+ return e;
1250
+ if (e !== null && typeof e == "object")
1251
+ try {
1252
+ const t = JSON.stringify(e);
1253
+ if (t)
1254
+ return t;
1255
+ } catch {
1256
+ return String(e);
1257
+ }
1258
+ return String(e);
1259
+ }
1260
+ const jo = { class: "chat-panel-content chat-panel-content--header" }, Jo = { class: "chat-panel" }, Zo = {
1261
+ key: 0,
1262
+ class: "chat-request-error",
1263
+ role: "alert"
1264
+ }, Go = { class: "chat-scroll-actions" }, Yo = {
1265
+ key: 0,
1266
+ class: "chat-panel-content chat-panel-content--footer"
1267
+ }, No = { class: "chat-right-aside-title" }, Qo = /* @__PURE__ */ J({
1268
+ __name: "ChatUI",
1269
+ props: {
1270
+ data: {},
1271
+ ui: {},
1272
+ inputValue: {},
1273
+ defaultInputValue: {},
1274
+ floatingState: {}
1275
+ },
1276
+ emits: ["update:floating-state", "floating-drag-start", "floating-drag", "floating-drag-end", "floating-resize-start", "floating-resize", "floating-resize-end", "update:inputValue", "submit", "cancel", "clear", "create-conversation", "switch-conversation", "rename-conversation", "delete-conversation", "history-action", "prompt-click", "bubble-state-change", "bubble-event", "model-select", "model-feature-change", "mcp-add-server", "mcp-remove-server", "mcp-server-enabled-change", "mcp-tool-enabled-change", "left-aside-open-change", "right-aside-open-change"],
1277
+ setup(e, { emit: t }) {
1278
+ const n = e, o = t, u = Xe(), m = n.inputValue !== void 0, d = q(n.inputValue ?? n.defaultInputValue ?? ""), a = q(null), b = st({
1279
+ mobile: 0,
1280
+ desktop: 960
1281
+ }).smaller("desktop"), { width: A } = at(), c = h(() => Mo(n.ui)), f = h(() => To(n.data, c.value.labels)), O = h(() => m ? n.inputValue ?? "" : d.value), C = h(() => c.value.header !== !1), L = h(() => c.value.layout.leftAside), T = h(() => c.value.layout.rightAside), p = h(
1282
+ () => c.value.history === !1 ? { menuItems: [] } : c.value.history
1283
+ ), r = h(
1284
+ () => c.value.sender === !1 ? void 0 : c.value.sender
1285
+ ), i = h(() => c.value.model === !1 ? void 0 : f.value.model), s = h(() => c.value.mcp === !1 ? void 0 : f.value.mcp), v = h(() => c.value.sender !== !1), S = h(() => L.value !== !1), $ = h(() => T.value !== !1), w = So({
1286
+ leftAside: L,
1287
+ rightAside: T,
1288
+ isMobileViewport: b,
1289
+ viewportWidth: A,
1290
+ onLeftOpenChange: (g) => o("left-aside-open-change", g),
1291
+ onRightOpenChange: (g) => o("right-aside-open-change", g)
1292
+ }), P = h(
1293
+ () => c.value.bubble.bubbleList.roleConfigs ?? { system: { hidden: !0 } }
1294
+ ), Z = h(
1295
+ () => f.value.bubble.messages.filter((g) => !Ke(g.role))
1296
+ ), K = h(() => Z.value.length === 0), x = !!u["layout-main"], ee = h(() => K.value && c.value.layout.emptyState === "center"), ce = h(
1297
+ () => K.value && r.value !== void 0 && c.value.welcome !== !1 && c.value.layout.composer.welcome === "center" && !x
1298
+ ), te = h(() => {
1299
+ var g;
1300
+ return (g = f.value.request) == null ? void 0 : g.error;
1301
+ }), De = h(() => ({
1302
+ containerType: "inline-size",
1303
+ "--tr-layout-left-aside-bg": "var(--tr-chat-ui-left-aside-bg, var(--tr-container-bg-default))",
1304
+ "--tr-layout-right-aside-bg": "var(--tr-chat-ui-right-aside-bg, var(--tr-container-bg-default))",
1305
+ "--tr-layout-header-bg": "var(--tr-chat-ui-header-bg, var(--tr-container-bg-default))",
1306
+ "--tr-layout-main-bg": "var(--tr-chat-ui-main-bg, var(--tr-container-bg-default))",
1307
+ "--tr-layout-footer-bg": "var(--tr-chat-ui-footer-bg, var(--tr-container-bg-default))",
1308
+ "--tr-chat-ui-content-max-width": fe(c.value.layout.contentMaxWidth),
1309
+ "--tr-chat-ui-panel-padding": fe(c.value.layout.panelPadding),
1310
+ "--tr-chat-ui-panel-gap": fe(c.value.layout.panelGap)
1311
+ })), qe = h(() => {
1312
+ const g = c.value.layout, M = {
1313
+ leftAside: S.value ? w.leftAsideOptions.value : void 0,
1314
+ rightAside: $.value ? w.rightAsideOptions.value : void 0
1315
+ };
1316
+ return g.surface.mode === "floating" ? {
1317
+ ...M,
1318
+ mode: "floating",
1319
+ floatingState: n.floatingState,
1320
+ floatingOptions: g.surface.floatingOptions
1321
+ } : {
1322
+ ...M,
1323
+ mode: "normal"
1324
+ };
1325
+ });
1326
+ function fe(g) {
1327
+ return typeof g == "number" ? `${g}px` : g;
1328
+ }
1329
+ function Ke(g) {
1330
+ var M;
1331
+ return g ? !!((M = P.value[g]) != null && M.hidden) : !1;
1332
+ }
1333
+ function oe() {
1334
+ o("create-conversation"), w.isLeftAsideDrawer.value && w.closeLeftAside();
1335
+ }
1336
+ function we(g) {
1337
+ o("switch-conversation", { id: g.id }), w.isLeftAsideDrawer.value && w.closeLeftAside();
1338
+ }
1339
+ function Se(g, M) {
1340
+ o("rename-conversation", { id: g.id, title: M });
1341
+ }
1342
+ function ze(g, M) {
1343
+ o("history-action", { action: g, conversation: M });
1344
+ }
1345
+ function je(g) {
1346
+ o("delete-conversation", { id: g.id });
1347
+ }
1348
+ function Je(g, M) {
1349
+ ne(M.label), o("prompt-click", { event: g, item: M });
1350
+ }
1351
+ function ke(g) {
1352
+ o("submit", g);
1353
+ }
1354
+ function Ee() {
1355
+ o("cancel");
1356
+ }
1357
+ function Oe() {
1358
+ ne(""), o("clear");
1359
+ }
1360
+ function ne(g) {
1361
+ m || (d.value = g), o("update:inputValue", g);
1362
+ }
1363
+ function Ze(g) {
1364
+ o("bubble-state-change", g);
1365
+ }
1366
+ function Ge(g) {
1367
+ o("bubble-event", g);
1368
+ }
1369
+ return (g, M) => (I(), W(y(ge), N(qe.value, {
1370
+ class: "tr-chat-ui",
1371
+ style: De.value,
1372
+ onLeftAsideOpenChange: y(w).handleLeftAsideOpenChange,
1373
+ onRightAsideOpenChange: y(w).handleRightAsideOpenChange,
1374
+ "onUpdate:floatingState": M[12] || (M[12] = (R) => o("update:floating-state", R)),
1375
+ onFloatingDragStart: M[13] || (M[13] = (R) => o("floating-drag-start", R)),
1376
+ onFloatingDrag: M[14] || (M[14] = (R) => o("floating-drag", R)),
1377
+ onFloatingDragEnd: M[15] || (M[15] = (R) => o("floating-drag-end", R)),
1378
+ onFloatingResizeStart: M[16] || (M[16] = (R) => o("floating-resize-start", R)),
1379
+ onFloatingResize: M[17] || (M[17] = (R) => o("floating-resize", R)),
1380
+ onFloatingResizeEnd: M[18] || (M[18] = (R) => o("floating-resize-end", R))
1381
+ }), z({
1382
+ main: E(() => [
1383
+ V("section", Jo, [
1384
+ V("div", {
1385
+ ref_key: "scrollTarget",
1386
+ ref: a,
1387
+ class: "chat-main-scroll-host"
1388
+ }, [
1389
+ te.value !== void 0 && te.value !== null ? (I(), F("div", Zo, [
1390
+ k(g.$slots, "request-error", { error: te.value }, () => [
1391
+ Ie(Q(y(zo)(te.value)), 1)
1392
+ ], !0)
1393
+ ])) : B("", !0),
1394
+ U(go, {
1395
+ messages: Z.value,
1396
+ "scroll-target": a.value,
1397
+ options: c.value.bubble,
1398
+ welcome: c.value.welcome,
1399
+ prompts: c.value.prompts,
1400
+ labels: c.value.labels,
1401
+ "center-empty-state": ee.value,
1402
+ "center-welcome-composer": ce.value,
1403
+ onPromptClick: Je,
1404
+ onBubbleStateChange: Ze,
1405
+ onBubbleEvent: Ge
1406
+ }, z({ _: 2 }, [
1407
+ g.$slots["layout-main"] ? {
1408
+ name: "default",
1409
+ fn: E(() => [
1410
+ k(g.$slots, "layout-main", {
1411
+ messages: Z.value,
1412
+ request: f.value.request,
1413
+ conversation: f.value.conversation
1414
+ }, void 0, !0)
1415
+ ]),
1416
+ key: "0"
1417
+ } : void 0,
1418
+ g.$slots["welcome-footer"] ? {
1419
+ name: "welcome-footer",
1420
+ fn: E(() => [
1421
+ k(g.$slots, "welcome-footer", {}, void 0, !0)
1422
+ ]),
1423
+ key: "1"
1424
+ } : void 0,
1425
+ g.$slots["prompts-footer"] ? {
1426
+ name: "prompts-footer",
1427
+ fn: E(() => [
1428
+ k(g.$slots, "prompts-footer", {}, void 0, !0)
1429
+ ]),
1430
+ key: "2"
1431
+ } : void 0,
1432
+ ce.value && r.value ? {
1433
+ name: "welcome-composer",
1434
+ fn: E(() => [
1435
+ U(Re, {
1436
+ class: "chat-welcome-composer",
1437
+ sender: f.value.sender,
1438
+ value: O.value,
1439
+ "sender-options": r.value,
1440
+ labels: c.value.labels,
1441
+ model: i.value,
1442
+ mcp: s.value,
1443
+ onSubmit: ke,
1444
+ onCancel: Ee,
1445
+ onClear: Oe,
1446
+ "onUpdate:value": ne,
1447
+ onModelSelect: M[0] || (M[0] = (R) => o("model-select", R)),
1448
+ onModelFeatureChange: M[1] || (M[1] = (R) => o("model-feature-change", R)),
1449
+ onMcpAddServer: M[2] || (M[2] = (R) => o("mcp-add-server", R)),
1450
+ onMcpRemoveServer: M[3] || (M[3] = (R) => o("mcp-remove-server", R)),
1451
+ onMcpServerEnabledChange: M[4] || (M[4] = (R) => o("mcp-server-enabled-change", R)),
1452
+ onMcpToolEnabledChange: M[5] || (M[5] = (R) => o("mcp-tool-enabled-change", R))
1453
+ }, z({ _: 2 }, [
1454
+ g.$slots["composer-before"] ? {
1455
+ name: "composer-before",
1456
+ fn: E((R) => [
1457
+ k(g.$slots, "composer-before", D(j(R)), void 0, !0)
1458
+ ]),
1459
+ key: "0"
1460
+ } : void 0,
1461
+ g.$slots["layout-footer"] ? {
1462
+ name: "layout-footer",
1463
+ fn: E((R) => [
1464
+ k(g.$slots, "layout-footer", D(j(R)), void 0, !0)
1465
+ ]),
1466
+ key: "1"
1467
+ } : void 0,
1468
+ g.$slots["sender-footer"] ? {
1469
+ name: "sender-footer",
1470
+ fn: E(() => [
1471
+ k(g.$slots, "sender-footer", {}, void 0, !0)
1472
+ ]),
1473
+ key: "2"
1474
+ } : void 0,
1475
+ g.$slots["sender-footer-right"] ? {
1476
+ name: "sender-footer-right",
1477
+ fn: E(() => [
1478
+ k(g.$slots, "sender-footer-right", {}, void 0, !0)
1479
+ ]),
1480
+ key: "3"
1481
+ } : void 0
1482
+ ]), 1032, ["sender", "value", "sender-options", "labels", "model", "mcp"])
1483
+ ]),
1484
+ key: "3"
1485
+ } : void 0,
1486
+ g.$slots["bubble-prefix"] ? {
1487
+ name: "bubble-prefix",
1488
+ fn: E(() => [
1489
+ k(g.$slots, "bubble-prefix", {}, void 0, !0)
1490
+ ]),
1491
+ key: "4"
1492
+ } : void 0,
1493
+ g.$slots["bubble-suffix"] ? {
1494
+ name: "bubble-suffix",
1495
+ fn: E(() => [
1496
+ k(g.$slots, "bubble-suffix", {}, void 0, !0)
1497
+ ]),
1498
+ key: "5"
1499
+ } : void 0,
1500
+ g.$slots["bubble-after"] ? {
1501
+ name: "bubble-after",
1502
+ fn: E(() => [
1503
+ k(g.$slots, "bubble-after", {}, void 0, !0)
1504
+ ]),
1505
+ key: "6"
1506
+ } : void 0,
1507
+ g.$slots["bubble-content-footer"] ? {
1508
+ name: "bubble-content-footer",
1509
+ fn: E(() => [
1510
+ k(g.$slots, "bubble-content-footer", {}, void 0, !0)
1511
+ ]),
1512
+ key: "7"
1513
+ } : void 0
1514
+ ]), 1032, ["messages", "scroll-target", "options", "welcome", "prompts", "labels", "center-empty-state", "center-welcome-composer"])
1515
+ ], 512)
1516
+ ]),
1517
+ V("div", Go, [
1518
+ U(Tt, { target: a.value }, null, 8, ["target"])
1519
+ ]),
1520
+ U(y(ge).ProxyScrollbar, { "scroll-target": a.value }, null, 8, ["scroll-target"])
1521
+ ]),
1522
+ _: 2
1523
+ }, [
1524
+ S.value ? {
1525
+ name: "left-aside",
1526
+ fn: E(() => [
1527
+ U(Bt, {
1528
+ conversation: f.value.conversation,
1529
+ history: p.value,
1530
+ brand: c.value.brand,
1531
+ labels: c.value.labels,
1532
+ "is-open": y(w).resolvedLeftAsideOpen.value,
1533
+ "is-dock": y(w).isLeftAsideDock.value,
1534
+ "show-history": c.value.history !== !1,
1535
+ onCreateConversation: oe,
1536
+ onSwitchConversation: we,
1537
+ onRenameConversation: Se,
1538
+ onDeleteConversation: je,
1539
+ onHistoryAction: ze,
1540
+ onOpen: y(w).openLeftAside,
1541
+ onClose: y(w).closeLeftAside,
1542
+ onToggle: y(w).toggleLeftAside
1543
+ }, z({ _: 2 }, [
1544
+ g.$slots["layout-left-aside"] ? {
1545
+ name: "default",
1546
+ fn: E(() => [
1547
+ k(g.$slots, "layout-left-aside", {
1548
+ conversation: f.value.conversation,
1549
+ isOpen: y(w).resolvedLeftAsideOpen.value,
1550
+ createConversation: oe,
1551
+ switchConversation: (R) => we({ id: R }),
1552
+ renameConversation: (R, Ye) => Se({ id: R }, Ye),
1553
+ deleteConversation: (R) => o("delete-conversation", { id: R }),
1554
+ openLeftAside: y(w).openLeftAside,
1555
+ closeLeftAside: y(w).closeLeftAside,
1556
+ toggleLeftAside: y(w).toggleLeftAside
1557
+ }, void 0, !0)
1558
+ ]),
1559
+ key: "0"
1560
+ } : void 0
1561
+ ]), 1032, ["conversation", "history", "brand", "labels", "is-open", "is-dock", "show-history", "onOpen", "onClose", "onToggle"])
1562
+ ]),
1563
+ key: "0"
1564
+ } : void 0,
1565
+ C.value ? {
1566
+ name: "header",
1567
+ fn: E(() => [
1568
+ V("div", jo, [
1569
+ U(vo, {
1570
+ title: f.value.conversation.title,
1571
+ "is-empty": K.value,
1572
+ conversation: f.value.conversation,
1573
+ "is-left-aside-visible": S.value,
1574
+ "is-left-aside-drawer": y(w).isLeftAsideDrawer.value,
1575
+ "is-left-aside-open": y(w).resolvedLeftAsideOpen.value,
1576
+ "is-right-aside-visible": $.value,
1577
+ "is-right-aside-open": y(w).resolvedRightAsideOpen.value,
1578
+ labels: c.value.labels,
1579
+ onCreateConversation: oe,
1580
+ onOpenLeftAside: y(w).openLeftAside,
1581
+ onCloseLeftAside: y(w).closeLeftAside,
1582
+ onToggleLeftAside: y(w).toggleLeftAside,
1583
+ onOpenRightAside: y(w).openRightAside
1584
+ }, z({ _: 2 }, [
1585
+ g.$slots["header-notice"] ? {
1586
+ name: "notice",
1587
+ fn: E(() => [
1588
+ k(g.$slots, "header-notice", {}, void 0, !0)
1589
+ ]),
1590
+ key: "0"
1591
+ } : void 0,
1592
+ g.$slots["layout-header"] ? {
1593
+ name: "default",
1594
+ fn: E(() => [
1595
+ k(g.$slots, "layout-header", {
1596
+ title: f.value.conversation.title,
1597
+ isEmpty: K.value,
1598
+ conversation: f.value.conversation,
1599
+ createConversation: oe,
1600
+ isLeftAsideOpen: y(w).resolvedLeftAsideOpen.value,
1601
+ openLeftAside: y(w).openLeftAside,
1602
+ closeLeftAside: y(w).closeLeftAside,
1603
+ toggleLeftAside: y(w).toggleLeftAside,
1604
+ openRightAside: y(w).openRightAside,
1605
+ closeRightAside: y(w).closeRightAside
1606
+ }, void 0, !0)
1607
+ ]),
1608
+ key: "1"
1609
+ } : void 0
1610
+ ]), 1032, ["title", "is-empty", "conversation", "is-left-aside-visible", "is-left-aside-drawer", "is-left-aside-open", "is-right-aside-visible", "is-right-aside-open", "labels", "onOpenLeftAside", "onCloseLeftAside", "onToggleLeftAside", "onOpenRightAside"])
1611
+ ])
1612
+ ]),
1613
+ key: "1"
1614
+ } : void 0,
1615
+ v.value && r.value ? {
1616
+ name: "footer",
1617
+ fn: E(() => [
1618
+ ce.value ? B("", !0) : (I(), F("div", Yo, [
1619
+ U(Re, {
1620
+ sender: f.value.sender,
1621
+ value: O.value,
1622
+ "sender-options": r.value,
1623
+ labels: c.value.labels,
1624
+ model: i.value,
1625
+ mcp: s.value,
1626
+ onSubmit: ke,
1627
+ onCancel: Ee,
1628
+ onClear: Oe,
1629
+ "onUpdate:value": ne,
1630
+ onModelSelect: M[6] || (M[6] = (R) => o("model-select", R)),
1631
+ onModelFeatureChange: M[7] || (M[7] = (R) => o("model-feature-change", R)),
1632
+ onMcpAddServer: M[8] || (M[8] = (R) => o("mcp-add-server", R)),
1633
+ onMcpRemoveServer: M[9] || (M[9] = (R) => o("mcp-remove-server", R)),
1634
+ onMcpServerEnabledChange: M[10] || (M[10] = (R) => o("mcp-server-enabled-change", R)),
1635
+ onMcpToolEnabledChange: M[11] || (M[11] = (R) => o("mcp-tool-enabled-change", R))
1636
+ }, z({ _: 2 }, [
1637
+ g.$slots["composer-before"] ? {
1638
+ name: "composer-before",
1639
+ fn: E((R) => [
1640
+ k(g.$slots, "composer-before", D(j(R)), void 0, !0)
1641
+ ]),
1642
+ key: "0"
1643
+ } : void 0,
1644
+ g.$slots["layout-footer"] ? {
1645
+ name: "layout-footer",
1646
+ fn: E((R) => [
1647
+ k(g.$slots, "layout-footer", D(j(R)), void 0, !0)
1648
+ ]),
1649
+ key: "1"
1650
+ } : void 0,
1651
+ g.$slots["sender-footer"] ? {
1652
+ name: "sender-footer",
1653
+ fn: E(() => [
1654
+ k(g.$slots, "sender-footer", {}, void 0, !0)
1655
+ ]),
1656
+ key: "2"
1657
+ } : void 0,
1658
+ g.$slots["sender-footer-right"] ? {
1659
+ name: "sender-footer-right",
1660
+ fn: E(() => [
1661
+ k(g.$slots, "sender-footer-right", {}, void 0, !0)
1662
+ ]),
1663
+ key: "3"
1664
+ } : void 0
1665
+ ]), 1032, ["sender", "value", "sender-options", "labels", "model", "mcp"])
1666
+ ]))
1667
+ ]),
1668
+ key: "2"
1669
+ } : void 0,
1670
+ $.value ? {
1671
+ name: "right-aside",
1672
+ fn: E(() => [
1673
+ U(wo, {
1674
+ "show-close": T.value !== !1 ? T.value.showClose : !0,
1675
+ labels: c.value.labels,
1676
+ onClose: y(w).closeRightAside
1677
+ }, {
1678
+ title: E(() => [
1679
+ k(g.$slots, "layout-right-aside-title", {}, () => [
1680
+ V("h2", No, Q(c.value.labels.rightAsideTitle), 1)
1681
+ ], !0)
1682
+ ]),
1683
+ default: E(() => [
1684
+ k(g.$slots, "layout-right-aside", {}, void 0, !0)
1685
+ ]),
1686
+ _: 3
1687
+ }, 8, ["show-close", "labels", "onClose"])
1688
+ ]),
1689
+ key: "3"
1690
+ } : void 0
1691
+ ]), 1040, ["style", "onLeftAsideOpenChange", "onRightAsideOpenChange"]));
1692
+ }
1693
+ }), Ho = /* @__PURE__ */ Y(Qo, [["__scopeId", "data-v-b37c2cd2"]]);
1694
+ function Xo(e) {
1695
+ const t = q("");
1696
+ function n(u) {
1697
+ t.value = u;
1698
+ }
1699
+ async function o(u) {
1700
+ const m = u.text.trim();
1701
+ if (!m)
1702
+ return !1;
1703
+ const d = u.text;
1704
+ try {
1705
+ t.value = "", await Promise.resolve();
1706
+ const a = await e.send({
1707
+ ...u,
1708
+ text: m
1709
+ });
1710
+ return !a && t.value === "" && (t.value = d), a;
1711
+ } catch (a) {
1712
+ throw t.value === "" && (t.value = d), a;
1713
+ }
1714
+ }
1715
+ return {
1716
+ inputValue: t,
1717
+ setInputValue: n,
1718
+ send: o,
1719
+ abort: e.abort
1720
+ };
1721
+ }
1722
+ function xo(e) {
1723
+ const t = h(() => G(e.runtime)), n = h(() => t.value.activeConversation.value), o = q(!1), u = q(/* @__PURE__ */ new Set()), m = q(/* @__PURE__ */ new Set()), d = q(/* @__PURE__ */ new Set()), a = Xo({
1724
+ send: async (i) => await c("send", i, () => t.value.actions.send(i)) ?? !1
1725
+ }), l = h(() => {
1726
+ var P, Z;
1727
+ const i = n.value, s = t.value.composer.model, v = t.value.composer.mcp, S = {};
1728
+ for (const [K, x] of Object.entries((v == null ? void 0 : v.tools.value) ?? {}))
1729
+ x && (S[K] = x.map(
1730
+ (ee) => ({
1731
+ ...ee,
1732
+ loading: d.value.has(A(K, ee.id))
1733
+ })
1734
+ ));
1735
+ const $ = s ? {
1736
+ options: s.options.value,
1737
+ selectedId: s.selectedId.value,
1738
+ features: s.features.value,
1739
+ selecting: o.value,
1740
+ pendingFeatureIds: [...u.value]
1741
+ } : void 0, w = v ? {
1742
+ servers: v.servers.value.map(
1743
+ (K) => ({
1744
+ ...K,
1745
+ loading: !!(K.loading || m.value.has(K.id))
1746
+ })
1747
+ ),
1748
+ tools: S
1749
+ } : void 0;
1750
+ return {
1751
+ conversation: {
1752
+ items: t.value.conversations.value,
1753
+ activeId: (i == null ? void 0 : i.id) ?? null,
1754
+ title: G(e.title) || (i == null ? void 0 : i.title)
1755
+ },
1756
+ bubble: { messages: (i == null ? void 0 : i.messages) ?? [] },
1757
+ sender: {
1758
+ loading: (i == null ? void 0 : i.requestState) === "processing",
1759
+ disabled: !!((P = t.value.composer.disabled) != null && P.value),
1760
+ submitDisabled: !!((Z = t.value.composer.submitDisabled) != null && Z.value)
1761
+ },
1762
+ request: i ? {
1763
+ state: i.requestState,
1764
+ processingState: i.processingState,
1765
+ error: i.lastError ?? void 0
1766
+ } : void 0,
1767
+ model: $,
1768
+ mcp: w
1769
+ };
1770
+ });
1771
+ function b(i, s, v) {
1772
+ const S = new Set(i.value);
1773
+ v ? S.add(s) : S.delete(s), i.value = S;
1774
+ }
1775
+ function A(i, s) {
1776
+ return `${i}:${s}`;
1777
+ }
1778
+ async function c(i, s, v) {
1779
+ try {
1780
+ return await v();
1781
+ } catch (S) {
1782
+ e.onActionError({ action: i, payload: s, error: S });
1783
+ return;
1784
+ }
1785
+ }
1786
+ async function f(i, s, v) {
1787
+ if (!i.value.has(s)) {
1788
+ b(i, s, !0);
1789
+ try {
1790
+ await v();
1791
+ } finally {
1792
+ b(i, s, !1);
1793
+ }
1794
+ }
1795
+ }
1796
+ async function O(i) {
1797
+ const s = t.value.composer.model;
1798
+ if (!(!s || s.selectedId.value === i || o.value)) {
1799
+ o.value = !0;
1800
+ try {
1801
+ await c("select-model", { id: i }, () => s.select(i));
1802
+ } finally {
1803
+ o.value = !1;
1804
+ }
1805
+ }
1806
+ }
1807
+ async function C(i, s) {
1808
+ const v = t.value.composer.model;
1809
+ !v || v.features.value[i] === s || await f(
1810
+ u,
1811
+ i,
1812
+ () => c("set-model-feature", { id: i, enabled: s }, () => v.setFeature(i, s))
1813
+ );
1814
+ }
1815
+ async function L(i) {
1816
+ const s = t.value.composer.mcp;
1817
+ s && await f(m, i, () => c("add-mcp-server", { id: i }, () => s.addServer(i)));
1818
+ }
1819
+ async function T(i) {
1820
+ const s = t.value.composer.mcp;
1821
+ s && await f(
1822
+ m,
1823
+ i,
1824
+ () => c("remove-mcp-server", { id: i }, () => s.removeServer(i))
1825
+ );
1826
+ }
1827
+ async function p(i, s) {
1828
+ const v = t.value.composer.mcp, S = v == null ? void 0 : v.servers.value.find(($) => $.id === i);
1829
+ v && S && S.enabled !== s && await f(
1830
+ m,
1831
+ i,
1832
+ () => c("set-mcp-server-enabled", { id: i, enabled: s }, () => v.setServerEnabled(i, s))
1833
+ );
1834
+ }
1835
+ async function r(i, s, v) {
1836
+ var P;
1837
+ const S = t.value.composer.mcp, $ = (P = S == null ? void 0 : S.tools.value[i]) == null ? void 0 : P.find((Z) => Z.id === s), w = A(i, s);
1838
+ S && $ && $.enabled !== v && await f(
1839
+ d,
1840
+ w,
1841
+ () => c(
1842
+ "set-mcp-tool-enabled",
1843
+ { serverId: i, toolId: s, enabled: v },
1844
+ () => S.setToolEnabled(i, s, v)
1845
+ )
1846
+ );
1847
+ }
1848
+ return {
1849
+ data: l,
1850
+ inputValue: a.inputValue,
1851
+ setInputValue: a.setInputValue,
1852
+ send: (i) => a.send(i),
1853
+ abort: () => c("abort", void 0, () => {
1854
+ var i, s;
1855
+ return (s = (i = t.value.actions).abort) == null ? void 0 : s.call(i);
1856
+ }),
1857
+ createConversation: () => c("create-conversation", void 0, () => t.value.actions.createConversation()),
1858
+ switchConversation: (i) => c("switch-conversation", { id: i }, () => t.value.actions.switchConversation(i)),
1859
+ renameConversation: (i, s) => c("rename-conversation", { id: i, title: s }, () => t.value.actions.renameConversation(i, s)),
1860
+ deleteConversation: (i) => c("delete-conversation", { id: i }, () => t.value.actions.deleteConversation(i)),
1861
+ selectModel: O,
1862
+ setModelFeature: C,
1863
+ addMcpServer: L,
1864
+ removeMcpServer: T,
1865
+ setMcpServerEnabled: p,
1866
+ setMcpToolEnabled: r
1867
+ };
1868
+ }
1869
+ const Tn = /* @__PURE__ */ J({
1870
+ __name: "Chat",
1871
+ props: {
1872
+ runtime: {},
1873
+ ui: {},
1874
+ title: {},
1875
+ floatingState: {}
1876
+ },
1877
+ emits: ["update:floating-state", "floating-drag-start", "floating-drag", "floating-drag-end", "floating-resize-start", "floating-resize", "floating-resize-end", "runtime-action-error", "history-action", "prompt-click", "bubble-state-change", "bubble-event", "left-aside-open-change", "right-aside-open-change"],
1878
+ setup(e, { emit: t }) {
1879
+ const n = e, o = t, u = xo({
1880
+ runtime: () => n.runtime,
1881
+ title: () => n.title,
1882
+ onActionError: (d) => o("runtime-action-error", d)
1883
+ });
1884
+ function m(d) {
1885
+ if (d.action.id === "delete") {
1886
+ u.deleteConversation(d.conversation.id);
1887
+ return;
1888
+ }
1889
+ o("history-action", d);
1890
+ }
1891
+ return (d, a) => (I(), W(Ho, {
1892
+ data: y(u).data.value,
1893
+ ui: n.ui,
1894
+ "floating-state": n.floatingState,
1895
+ "input-value": y(u).inputValue.value,
1896
+ onCreateConversation: y(u).createConversation,
1897
+ onSwitchConversation: a[0] || (a[0] = ({ id: l }) => y(u).switchConversation(l)),
1898
+ onRenameConversation: a[1] || (a[1] = ({ id: l, title: b }) => y(u).renameConversation(l, b)),
1899
+ onDeleteConversation: a[2] || (a[2] = ({ id: l }) => y(u).deleteConversation(l)),
1900
+ onHistoryAction: m,
1901
+ onPromptClick: a[3] || (a[3] = (l) => o("prompt-click", l)),
1902
+ onBubbleStateChange: a[4] || (a[4] = (l) => o("bubble-state-change", l)),
1903
+ onBubbleEvent: a[5] || (a[5] = (l) => o("bubble-event", l)),
1904
+ onLeftAsideOpenChange: a[6] || (a[6] = (l) => o("left-aside-open-change", l)),
1905
+ onRightAsideOpenChange: a[7] || (a[7] = (l) => o("right-aside-open-change", l)),
1906
+ "onUpdate:floatingState": a[8] || (a[8] = (l) => o("update:floating-state", l)),
1907
+ onFloatingDragStart: a[9] || (a[9] = (l) => o("floating-drag-start", l)),
1908
+ onFloatingDrag: a[10] || (a[10] = (l) => o("floating-drag", l)),
1909
+ onFloatingDragEnd: a[11] || (a[11] = (l) => o("floating-drag-end", l)),
1910
+ onFloatingResizeStart: a[12] || (a[12] = (l) => o("floating-resize-start", l)),
1911
+ onFloatingResize: a[13] || (a[13] = (l) => o("floating-resize", l)),
1912
+ onFloatingResizeEnd: a[14] || (a[14] = (l) => o("floating-resize-end", l)),
1913
+ onSubmit: y(u).send,
1914
+ onCancel: y(u).abort,
1915
+ onClear: a[15] || (a[15] = () => y(u).setInputValue("")),
1916
+ "onUpdate:inputValue": y(u).setInputValue,
1917
+ onModelSelect: a[16] || (a[16] = ({ id: l }) => y(u).selectModel(l)),
1918
+ onModelFeatureChange: a[17] || (a[17] = ({ id: l, enabled: b }) => y(u).setModelFeature(l, b)),
1919
+ onMcpAddServer: a[18] || (a[18] = ({ id: l }) => y(u).addMcpServer(l)),
1920
+ onMcpRemoveServer: a[19] || (a[19] = ({ id: l }) => y(u).removeMcpServer(l)),
1921
+ onMcpServerEnabledChange: a[20] || (a[20] = ({ id: l, enabled: b }) => y(u).setMcpServerEnabled(l, b)),
1922
+ onMcpToolEnabledChange: a[21] || (a[21] = ({ serverId: l, toolId: b, enabled: A }) => y(u).setMcpToolEnabled(l, b, A))
1923
+ }, z({ _: 2 }, [
1924
+ d.$slots["layout-header"] ? {
1925
+ name: "layout-header",
1926
+ fn: E((l) => [
1927
+ k(d.$slots, "layout-header", D(j(l)))
1928
+ ]),
1929
+ key: "0"
1930
+ } : void 0,
1931
+ d.$slots["layout-left-aside"] ? {
1932
+ name: "layout-left-aside",
1933
+ fn: E((l) => [
1934
+ k(d.$slots, "layout-left-aside", D(j(l)))
1935
+ ]),
1936
+ key: "1"
1937
+ } : void 0,
1938
+ d.$slots["layout-right-aside"] ? {
1939
+ name: "layout-right-aside",
1940
+ fn: E(() => [
1941
+ k(d.$slots, "layout-right-aside")
1942
+ ]),
1943
+ key: "2"
1944
+ } : void 0,
1945
+ d.$slots["layout-right-aside-title"] ? {
1946
+ name: "layout-right-aside-title",
1947
+ fn: E(() => [
1948
+ k(d.$slots, "layout-right-aside-title")
1949
+ ]),
1950
+ key: "3"
1951
+ } : void 0,
1952
+ d.$slots["layout-main"] ? {
1953
+ name: "layout-main",
1954
+ fn: E((l) => [
1955
+ k(d.$slots, "layout-main", D(j(l)))
1956
+ ]),
1957
+ key: "4"
1958
+ } : void 0,
1959
+ d.$slots["layout-footer"] ? {
1960
+ name: "layout-footer",
1961
+ fn: E((l) => [
1962
+ k(d.$slots, "layout-footer", D(j(l)))
1963
+ ]),
1964
+ key: "5"
1965
+ } : void 0,
1966
+ d.$slots["composer-before"] ? {
1967
+ name: "composer-before",
1968
+ fn: E((l) => [
1969
+ k(d.$slots, "composer-before", D(j(l)))
1970
+ ]),
1971
+ key: "6"
1972
+ } : void 0,
1973
+ d.$slots["header-notice"] ? {
1974
+ name: "header-notice",
1975
+ fn: E(() => [
1976
+ k(d.$slots, "header-notice")
1977
+ ]),
1978
+ key: "7"
1979
+ } : void 0,
1980
+ d.$slots["request-error"] ? {
1981
+ name: "request-error",
1982
+ fn: E((l) => [
1983
+ k(d.$slots, "request-error", D(j(l)))
1984
+ ]),
1985
+ key: "8"
1986
+ } : void 0,
1987
+ d.$slots["welcome-footer"] ? {
1988
+ name: "welcome-footer",
1989
+ fn: E(() => [
1990
+ k(d.$slots, "welcome-footer")
1991
+ ]),
1992
+ key: "9"
1993
+ } : void 0,
1994
+ d.$slots["prompts-footer"] ? {
1995
+ name: "prompts-footer",
1996
+ fn: E(() => [
1997
+ k(d.$slots, "prompts-footer")
1998
+ ]),
1999
+ key: "10"
2000
+ } : void 0,
2001
+ d.$slots["bubble-prefix"] ? {
2002
+ name: "bubble-prefix",
2003
+ fn: E(() => [
2004
+ k(d.$slots, "bubble-prefix")
2005
+ ]),
2006
+ key: "11"
2007
+ } : void 0,
2008
+ d.$slots["bubble-suffix"] ? {
2009
+ name: "bubble-suffix",
2010
+ fn: E(() => [
2011
+ k(d.$slots, "bubble-suffix")
2012
+ ]),
2013
+ key: "12"
2014
+ } : void 0,
2015
+ d.$slots["bubble-after"] ? {
2016
+ name: "bubble-after",
2017
+ fn: E(() => [
2018
+ k(d.$slots, "bubble-after")
2019
+ ]),
2020
+ key: "13"
2021
+ } : void 0,
2022
+ d.$slots["bubble-content-footer"] ? {
2023
+ name: "bubble-content-footer",
2024
+ fn: E(() => [
2025
+ k(d.$slots, "bubble-content-footer")
2026
+ ]),
2027
+ key: "14"
2028
+ } : void 0,
2029
+ d.$slots["sender-footer"] ? {
2030
+ name: "sender-footer",
2031
+ fn: E(() => [
2032
+ k(d.$slots, "sender-footer")
2033
+ ]),
2034
+ key: "15"
2035
+ } : void 0,
2036
+ d.$slots["sender-footer-right"] ? {
2037
+ name: "sender-footer-right",
2038
+ fn: E(() => [
2039
+ k(d.$slots, "sender-footer-right")
2040
+ ]),
2041
+ key: "16"
2042
+ } : void 0
2043
+ ]), 1032, ["data", "ui", "floating-state", "input-value", "onCreateConversation", "onSubmit", "onCancel", "onUpdate:inputValue"]));
2044
+ }
2045
+ }), Pe = "run_config_metadata", ie = "run_config_context";
2046
+ function de(e) {
2047
+ if (e)
2048
+ return {
2049
+ ...e,
2050
+ features: e.features ? { ...e.features } : void 0,
2051
+ reasoning: e.reasoning ? { ...e.reasoning } : void 0,
2052
+ mcp: e.mcp ? {
2053
+ serverIds: [...e.mcp.serverIds],
2054
+ toolIds: Object.fromEntries(
2055
+ Object.entries(e.mcp.toolIds).map(([t, n]) => [t, [...n]])
2056
+ )
2057
+ } : void 0
2058
+ };
2059
+ }
2060
+ function Be(e) {
2061
+ return (e == null ? void 0 : e.servers.value.filter((t) => t.installed && t.enabled)) ?? [];
2062
+ }
2063
+ function Ue(e) {
2064
+ return e ? Be(e).every(
2065
+ (t) => !t.loading && Object.prototype.hasOwnProperty.call(e.tools.value, t.id)
2066
+ ) : !0;
2067
+ }
2068
+ function _o(e) {
2069
+ if (e === void 0)
2070
+ return;
2071
+ const t = Be(e);
2072
+ if (!(t.length === 0 || !Ue(e)))
2073
+ return {
2074
+ serverIds: t.map((n) => n.id),
2075
+ toolIds: Object.fromEntries(
2076
+ t.map((n) => [
2077
+ n.id,
2078
+ (e.tools.value[n.id] ?? []).filter((o) => o.enabled).map((o) => o.id)
2079
+ ])
2080
+ )
2081
+ };
2082
+ }
2083
+ function en(e) {
2084
+ var u, m;
2085
+ const t = e.model, n = (m = (u = e.model) == null ? void 0 : u.reasoning) == null ? void 0 : m.value, o = _o(e.mcp);
2086
+ if (!(!t && !n && !o))
2087
+ return de({
2088
+ modelId: (t == null ? void 0 : t.selectedId.value) ?? void 0,
2089
+ features: t ? { ...t.features.value } : void 0,
2090
+ reasoning: n,
2091
+ mcp: o
2092
+ });
2093
+ }
2094
+ function _(e) {
2095
+ return !!e && typeof e == "object" && !Array.isArray(e);
2096
+ }
2097
+ function tn(e) {
2098
+ if (!_(e) || !Array.isArray(e.serverIds) || !_(e.toolIds) || !e.serverIds.every((u) => typeof u == "string" && u.length > 0))
2099
+ return;
2100
+ const t = e.serverIds, n = new Set(t);
2101
+ if (n.size !== t.length)
2102
+ return;
2103
+ const o = Object.entries(e.toolIds);
2104
+ if (!(o.length !== t.length || !o.every(
2105
+ ([u, m]) => n.has(u) && Array.isArray(m) && m.every((d) => typeof d == "string" && d.length > 0) && new Set(m).size === m.length
2106
+ )) && !t.some((u) => !Object.prototype.hasOwnProperty.call(e.toolIds, u)))
2107
+ return {
2108
+ serverIds: [...t],
2109
+ toolIds: Object.fromEntries(o.map(([u, m]) => [u, [...m]]))
2110
+ };
2111
+ }
2112
+ function on(e) {
2113
+ var u;
2114
+ const t = (u = e == null ? void 0 : e.metadata) == null ? void 0 : u[Pe];
2115
+ if (!_(t) || t.modelId !== void 0 && typeof t.modelId != "string" || t.features !== void 0 && (!_(t.features) || Object.values(t.features).some((m) => typeof m != "boolean")))
2116
+ return;
2117
+ let n;
2118
+ if (t.reasoning !== void 0) {
2119
+ if (!_(t.reasoning) || typeof t.reasoning.enabled != "boolean" || t.reasoning.effort !== void 0 && (typeof t.reasoning.effort != "string" || !jt.includes(t.reasoning.effort)))
2120
+ return;
2121
+ n = {
2122
+ enabled: t.reasoning.enabled,
2123
+ effort: t.reasoning.effort
2124
+ };
2125
+ }
2126
+ const o = t.mcp === void 0 ? void 0 : tn(t.mcp);
2127
+ if (!(t.mcp !== void 0 && !o))
2128
+ return de({
2129
+ modelId: t.modelId,
2130
+ features: t.features,
2131
+ reasoning: n,
2132
+ mcp: o
2133
+ });
2134
+ }
2135
+ const Fe = "新对话";
2136
+ function We(e) {
2137
+ return e.trim().slice(0, 20) || Fe;
2138
+ }
2139
+ function nn(e) {
2140
+ return e || Fe;
2141
+ }
2142
+ const Le = (e) => ({
2143
+ id: e.id,
2144
+ title: nn(e.title),
2145
+ createdAt: e.createdAt,
2146
+ updatedAt: e.updatedAt,
2147
+ metadata: e.metadata
2148
+ });
2149
+ function sn(e) {
2150
+ const { conversation: t, lastError: n, titleGenerator: o, send: u, composer: m } = e, d = q({}), a = o ?? We, l = h(() => t.activeConversation.value), b = h(() => t.conversations.value.map(Le)), A = h(() => {
2151
+ const T = l.value;
2152
+ return T ? {
2153
+ ...Le(T),
2154
+ messages: T.engine.messages.value,
2155
+ requestState: T.engine.requestState.value,
2156
+ processingState: T.engine.processingState.value,
2157
+ lastError: d.value[T.id] ?? null
2158
+ } : null;
2159
+ });
2160
+ n && xe(() => {
2161
+ var T;
2162
+ n.value = ((T = A.value) == null ? void 0 : T.lastError) ?? null;
2163
+ });
2164
+ const c = m ?? {}, f = h(
2165
+ () => {
2166
+ var T;
2167
+ return !!((T = c.submitDisabled) != null && T.value) || !Ue(c.mcp);
2168
+ }
2169
+ ), O = {
2170
+ ...c,
2171
+ submitDisabled: f
2172
+ }, C = u ?? (async (T) => {
2173
+ const p = T.text.trim();
2174
+ if (!p)
2175
+ return;
2176
+ let r = l.value;
2177
+ r ? r.title || t.updateConversationTitle(r.id, a(p)) : r = t.createConversation({ title: a(p) });
2178
+ const i = Math.floor(Date.now() / 1e3);
2179
+ await r.engine.send({
2180
+ role: "user",
2181
+ content: p,
2182
+ metadata: {
2183
+ createdAt: i,
2184
+ updatedAt: i,
2185
+ ...T.runConfig ? {
2186
+ [Pe]: de(T.runConfig)
2187
+ } : {}
2188
+ }
2189
+ });
2190
+ });
2191
+ async function L(T) {
2192
+ var s, v, S, $;
2193
+ const p = T.text.trim();
2194
+ if (!p || (s = O.disabled) != null && s.value || (v = O.submitDisabled) != null && v.value)
2195
+ return !1;
2196
+ let r = ((S = t.activeConversation.value) == null ? void 0 : S.id) ?? null;
2197
+ const i = {
2198
+ ...T,
2199
+ text: p,
2200
+ runConfig: de(en(O))
2201
+ };
2202
+ try {
2203
+ const w = Promise.resolve(C(i));
2204
+ return r = (($ = t.activeConversation.value) == null ? void 0 : $.id) ?? r, r && (d.value = {
2205
+ ...d.value,
2206
+ [r]: null
2207
+ }), await w, !0;
2208
+ } catch (w) {
2209
+ throw r && (d.value = {
2210
+ ...d.value,
2211
+ [r]: w
2212
+ }), w;
2213
+ }
2214
+ }
2215
+ return {
2216
+ conversations: b,
2217
+ activeConversation: A,
2218
+ composer: O,
2219
+ actions: {
2220
+ send: L,
2221
+ abort: async () => {
2222
+ await t.abortActiveRequest();
2223
+ },
2224
+ createConversation: (T) => {
2225
+ t.createConversation(T);
2226
+ },
2227
+ switchConversation: async (T) => {
2228
+ await t.switchConversation(T);
2229
+ },
2230
+ renameConversation: (T, p) => {
2231
+ t.updateConversationTitle(T, p);
2232
+ },
2233
+ deleteConversation: async (T) => {
2234
+ await t.deleteConversation(T);
2235
+ const { [T]: p, ...r } = d.value;
2236
+ d.value = r;
2237
+ }
2238
+ }
2239
+ };
2240
+ }
2241
+ function an(e) {
2242
+ var l, b, A;
2243
+ const t = q(((l = e[0]) == null ? void 0 : l.id) ?? null), n = q(((A = (b = e[0]) == null ? void 0 : b.reasoning) == null ? void 0 : A.defaultEffort) ?? "high"), o = _e({}), u = h(() => e.find((c) => c.id === t.value));
2244
+ function m(c) {
2245
+ return e.find((f) => f.id === c);
2246
+ }
2247
+ function d(c) {
2248
+ var O, C, L, T, p;
2249
+ const f = c ? m(c) : void 0;
2250
+ re.forEach((r) => {
2251
+ var i;
2252
+ (i = f == null ? void 0 : f.capabilities) != null && i[r] || (o[r] = !1);
2253
+ }), (C = (O = f == null ? void 0 : f.reasoning) == null ? void 0 : O.efforts) != null && C.includes(n.value) || (n.value = ((L = f == null ? void 0 : f.reasoning) == null ? void 0 : L.defaultEffort) ?? ((p = (T = f == null ? void 0 : f.reasoning) == null ? void 0 : T.efforts) == null ? void 0 : p[0]) ?? "high");
2254
+ }
2255
+ return {
2256
+ model: {
2257
+ options: h(
2258
+ () => e.map(({ id: c, label: f, capabilities: O }) => ({
2259
+ id: c,
2260
+ label: f,
2261
+ capabilities: O
2262
+ }))
2263
+ ),
2264
+ selectedId: h(() => t.value),
2265
+ features: h(
2266
+ () => Object.fromEntries(
2267
+ re.map((c) => {
2268
+ var f, O;
2269
+ return [
2270
+ c,
2271
+ !!((O = (f = u.value) == null ? void 0 : f.capabilities) != null && O[c] && o[c])
2272
+ ];
2273
+ })
2274
+ )
2275
+ ),
2276
+ reasoning: h(() => {
2277
+ var O, C, L;
2278
+ const c = u.value, f = !!((O = c == null ? void 0 : c.capabilities) != null && O.thinking && o.thinking);
2279
+ return {
2280
+ enabled: f,
2281
+ effort: f && ((L = (C = c == null ? void 0 : c.reasoning) == null ? void 0 : C.efforts) != null && L.includes(n.value)) ? n.value : void 0
2282
+ };
2283
+ }),
2284
+ select(c) {
2285
+ if (c !== null && !m(c))
2286
+ throw new Error(`Unknown model: ${c}`);
2287
+ t.value = c, d(c);
2288
+ },
2289
+ setFeature(c, f) {
2290
+ var O, C, L;
2291
+ if (f) {
2292
+ if (!Object.prototype.hasOwnProperty.call(((O = u.value) == null ? void 0 : O.capabilities) ?? {}, c))
2293
+ throw new Error(`Unknown model feature: ${c}`);
2294
+ if (!((L = (C = u.value) == null ? void 0 : C.capabilities) != null && L[c]))
2295
+ throw new Error(`Current model does not support ${c}`);
2296
+ }
2297
+ o[c] = f;
2298
+ }
2299
+ },
2300
+ selectedModel: u,
2301
+ resolveModel: m
2302
+ };
2303
+ }
2304
+ const ye = "__chat_provider_model_id";
2305
+ function ln(e) {
2306
+ return {
2307
+ name: "chat-provider-request",
2308
+ onBeforeRequest({ customContext: t, requestBody: n }) {
2309
+ var d, a, l;
2310
+ const o = t[ie], u = o != null && o.modelId ? e(o.modelId) : null;
2311
+ if (o != null && o.modelId && !u)
2312
+ throw new Error(`Unknown model for this turn: ${o.modelId}`);
2313
+ if (!u || !o)
2314
+ return;
2315
+ n[ye] = u.id;
2316
+ const m = o;
2317
+ re.forEach((b) => {
2318
+ var O, C, L, T;
2319
+ const A = (O = u.featureBody) == null ? void 0 : O[b];
2320
+ if (!A) return;
2321
+ const f = (b === "thinking" ? ((C = m.reasoning) == null ? void 0 : C.enabled) ?? ((L = m.features) == null ? void 0 : L.thinking) : (T = m.features) == null ? void 0 : T[b]) ? A.enabled : A.disabled;
2322
+ f && Object.assign(n, f);
2323
+ }), (d = o == null ? void 0 : o.reasoning) != null && d.effort && ((a = u.reasoning) != null && a.effortParam) && ((l = u.reasoning.efforts) != null && l.includes(o.reasoning.effort)) && Object.assign(n, {
2324
+ [u.reasoning.effortParam]: o.reasoning.effort
2325
+ });
2326
+ }
2327
+ };
2328
+ }
2329
+ function rn(e) {
2330
+ return async (t, n) => {
2331
+ const o = t[ye];
2332
+ if (typeof o != "string" || !o)
2333
+ throw new Error("No model selected for this turn.");
2334
+ const u = e(o);
2335
+ if (!u)
2336
+ throw new Error(`Unknown model for this turn: ${o}`);
2337
+ const m = { ...t };
2338
+ delete m[ye];
2339
+ const d = u.timeout, a = d === void 0 ? void 0 : new AbortController(), l = a ? setTimeout(() => a.abort(new Error(`Provider request timed out after ${d}ms.`)), d) : void 0, b = a ? AbortSignal.any([n, a.signal]) : n, A = {
2340
+ "Content-Type": "application/json",
2341
+ ...u.headers
2342
+ }, c = Object.keys(A).some((f) => f.toLowerCase() === "authorization");
2343
+ u.apiKey && !c && (A.Authorization = `Bearer ${u.apiKey}`);
2344
+ try {
2345
+ const f = await fetch(u.apiUrl, {
2346
+ method: "POST",
2347
+ headers: A,
2348
+ body: JSON.stringify({
2349
+ ...m,
2350
+ model: u.id,
2351
+ stream: !0
2352
+ }),
2353
+ signal: b
2354
+ });
2355
+ if (!f.ok) {
2356
+ const O = await f.text().catch(() => "");
2357
+ throw new Error(`HTTP ${f.status}: ${f.statusText}${O ? ` - ${O}` : ""}`);
2358
+ }
2359
+ return async function* () {
2360
+ try {
2361
+ yield* At(f, { signal: b });
2362
+ } finally {
2363
+ l !== void 0 && clearTimeout(l);
2364
+ }
2365
+ }();
2366
+ } catch (f) {
2367
+ throw l !== void 0 && clearTimeout(l), f;
2368
+ }
2369
+ };
2370
+ }
2371
+ const dn = {
2372
+ openai: {
2373
+ label: "OpenAI",
2374
+ apiUrl: "https://api.openai.com/v1"
2375
+ },
2376
+ deepseek: {
2377
+ label: "DeepSeek",
2378
+ apiUrl: "https://api.deepseek.com/chat/completions",
2379
+ featureBody: {
2380
+ thinking: {
2381
+ enabled: {
2382
+ thinking: {
2383
+ type: "enabled"
2384
+ }
2385
+ },
2386
+ disabled: {
2387
+ thinking: {
2388
+ type: "disabled"
2389
+ }
2390
+ }
2391
+ }
2392
+ },
2393
+ reasoning: {
2394
+ efforts: ["high", "max"],
2395
+ defaultEffort: "high",
2396
+ effortParam: "reasoning_effort"
2397
+ }
2398
+ },
2399
+ qwen: {
2400
+ label: "DashScope",
2401
+ apiUrl: "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
2402
+ featureBody: {
2403
+ thinking: {
2404
+ enabled: {
2405
+ enable_thinking: !0
2406
+ },
2407
+ disabled: {
2408
+ enable_thinking: !1
2409
+ }
2410
+ },
2411
+ search: {
2412
+ enabled: {
2413
+ enable_search: !0
2414
+ }
2415
+ }
2416
+ }
2417
+ }
2418
+ };
2419
+ function un(e) {
2420
+ const t = e.trim().replace(/\/+$/, "");
2421
+ return t.endsWith("/chat/completions") ? t : `${t}/chat/completions`;
2422
+ }
2423
+ function cn(e) {
2424
+ const t = /* @__PURE__ */ new Set();
2425
+ return e.flatMap((n) => {
2426
+ const o = dn[n.type];
2427
+ if (!o)
2428
+ throw new Error(`Unknown provider type: ${String(n.type)}`);
2429
+ const u = n.label ?? o.label, m = un(n.apiUrl ?? o.apiUrl);
2430
+ return n.models.map((d) => {
2431
+ if (t.has(d.id))
2432
+ throw new Error(`Duplicate model id: ${d.id}`);
2433
+ return t.add(d.id), {
2434
+ ...d,
2435
+ providerType: n.type,
2436
+ providerLabel: u,
2437
+ apiUrl: m,
2438
+ apiKey: n.apiKey,
2439
+ headers: n.headers,
2440
+ timeout: n.timeout,
2441
+ featureBody: {
2442
+ ...o.featureBody,
2443
+ ...d.featureBody
2444
+ },
2445
+ reasoning: d.reasoning ?? o.reasoning
2446
+ };
2447
+ });
2448
+ });
2449
+ }
2450
+ function fn(e) {
2451
+ return [...e].reverse().find((t) => t.role === "user");
2452
+ }
2453
+ function vn() {
2454
+ return {
2455
+ name: "chat-run-config-context",
2456
+ onTurnStart({ currentTurn: e, setCustomContext: t }) {
2457
+ t({
2458
+ [ie]: on(fn(e))
2459
+ });
2460
+ }
2461
+ };
2462
+ }
2463
+ const ve = "__chat_tool_snapshot";
2464
+ function mn(e, t) {
2465
+ var n;
2466
+ for (const o of t.serverIds) {
2467
+ const u = (n = t.toolIds[o]) == null ? void 0 : n.find((m) => `${o}__${m}` === e);
2468
+ if (u)
2469
+ return { serverId: o, toolId: u };
2470
+ }
2471
+ return null;
2472
+ }
2473
+ function bn(e, t) {
2474
+ return wt({
2475
+ getTools: async ({ customContext: n, setCustomContext: o }) => {
2476
+ const u = n[ie], m = u == null ? void 0 : u.mcp;
2477
+ if (!m)
2478
+ return [];
2479
+ const d = m.serverIds.find(
2480
+ (l) => !Object.prototype.hasOwnProperty.call(m.toolIds, l)
2481
+ );
2482
+ if (d)
2483
+ throw new Error(`Tool selection is missing for this turn: ${d}`);
2484
+ let a = n[ve];
2485
+ return Array.isArray(a) || (a = (await e(m.serverIds, m.toolIds)).map((l) => ({ ...l })), o({
2486
+ [ve]: a
2487
+ })), a.map((l) => ({
2488
+ type: "function",
2489
+ function: {
2490
+ name: l.name,
2491
+ description: l.description ?? "",
2492
+ parameters: l.inputSchema ?? { type: "object", properties: {} }
2493
+ }
2494
+ }));
2495
+ },
2496
+ callTool: async (n, { customContext: o }) => {
2497
+ var f, O;
2498
+ const u = o[ie], m = u == null ? void 0 : u.mcp, d = ((f = n.function) == null ? void 0 : f.name) ?? "", a = m ? mn(d, m) : null, l = o[ve], b = Array.isArray(l) ? l.find((C) => C.name === d) : void 0;
2499
+ if (!m || !a || !b || b.serverId !== a.serverId || b.id !== a.toolId)
2500
+ throw new Error(`Tool is not enabled in this turn: ${d}`);
2501
+ const A = (O = n.function) == null ? void 0 : O.arguments;
2502
+ let c = {};
2503
+ if (A && A.trim())
2504
+ try {
2505
+ c = JSON.parse(A);
2506
+ } catch {
2507
+ throw new Error(`Invalid JSON arguments for MCP tool "${d}".`);
2508
+ }
2509
+ return t(b.serverId, b.originalName, c);
2510
+ }
2511
+ });
2512
+ }
2513
+ const gn = 3e4;
2514
+ function $e(e, t, n) {
2515
+ let o;
2516
+ const u = new Promise((m, d) => {
2517
+ o = setTimeout(() => d(new Error(`MCP ${n} timed out after ${t}ms.`)), t);
2518
+ });
2519
+ return Promise.race([e, u]).finally(() => {
2520
+ o !== void 0 && clearTimeout(o);
2521
+ });
2522
+ }
2523
+ function hn(e, t, n) {
2524
+ const o = typeof t.name == "string" && t.name ? t.name : `tool_${n + 1}`;
2525
+ return {
2526
+ serverId: e,
2527
+ id: o,
2528
+ name: `${e}__${o}`,
2529
+ originalName: o,
2530
+ description: t.description,
2531
+ inputSchema: typeof t.inputSchema == "object" && t.inputSchema !== null ? t.inputSchema : { type: "object", properties: {} }
2532
+ };
2533
+ }
2534
+ function pn(e, t) {
2535
+ var n;
2536
+ try {
2537
+ return new URL(t);
2538
+ } catch {
2539
+ const o = (n = globalThis.location) == null ? void 0 : n.origin;
2540
+ if (!o)
2541
+ throw new Error(`MCP server "${e}" requires an absolute baseUrl outside a browser environment.`);
2542
+ return new URL(t, o);
2543
+ }
2544
+ }
2545
+ function yn(e) {
2546
+ const t = /* @__PURE__ */ new Map();
2547
+ for (const r of e) {
2548
+ if (t.has(r.id)) throw new Error(`Duplicate MCP server id: ${r.id}`);
2549
+ t.set(r.id, r);
2550
+ }
2551
+ const n = me(
2552
+ e.map((r) => ({
2553
+ id: r.id,
2554
+ name: r.name,
2555
+ description: r.description,
2556
+ installed: r.installed === !0,
2557
+ enabled: !1,
2558
+ metadata: r.icon ? { icon: r.icon } : void 0,
2559
+ config: r
2560
+ }))
2561
+ ), o = me({}), u = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
2562
+ function l(r) {
2563
+ const i = n.value.find((s) => s.id === r);
2564
+ if (!i) throw new Error(`Unknown MCP server: ${r}`);
2565
+ return i;
2566
+ }
2567
+ function b(r) {
2568
+ const i = { ...o.value };
2569
+ delete i[r], o.value = i, u.delete(r), d.delete(r), m.delete(r), a.set(r, (a.get(r) ?? 0) + 1);
2570
+ }
2571
+ function A(r, i) {
2572
+ const s = o.value[r];
2573
+ s && (o.value = {
2574
+ ...o.value,
2575
+ [r]: s.map((v) => ({ ...v, enabled: i }))
2576
+ });
2577
+ }
2578
+ async function c(r, i) {
2579
+ var w;
2580
+ const s = t.get(r);
2581
+ if (!s) throw new Error(`Unknown MCP server: ${r}`);
2582
+ (w = s.validate) == null || w.call(s, r);
2583
+ const v = new kt({ name: `tiny-robot-chat-${r}`, version: "1.0.0" }), S = new Et(pn(r, s.baseUrl), {
2584
+ requestInit: { headers: s.headers }
2585
+ }), $ = s.timeout ?? gn;
2586
+ try {
2587
+ return await $e(v.connect(S), $, "connect"), await $e(i(v), $, "request");
2588
+ } finally {
2589
+ await v.close().catch(() => {
2590
+ });
2591
+ }
2592
+ }
2593
+ async function f(r, i = !1) {
2594
+ const s = u.get(r);
2595
+ if (!i && s) return s;
2596
+ const v = a.get(r) ?? 0, S = m.get(r);
2597
+ if ((S == null ? void 0 : S.generation) === v) return S.task;
2598
+ const $ = c(r, async (P) => (await P.listTools()).tools.map((K, x) => hn(r, K, x))), w = { generation: v, task: $ };
2599
+ m.set(r, w);
2600
+ try {
2601
+ const P = await $;
2602
+ return (a.get(r) ?? 0) === v && u.set(r, P), P;
2603
+ } finally {
2604
+ m.get(r) === w && m.delete(r);
2605
+ }
2606
+ }
2607
+ async function O(r, i = !0) {
2608
+ const s = d.get(r);
2609
+ if (s) {
2610
+ await s;
2611
+ return;
2612
+ }
2613
+ const v = C(r, i);
2614
+ d.set(r, v);
2615
+ try {
2616
+ await v;
2617
+ } finally {
2618
+ d.get(r) === v && d.delete(r);
2619
+ }
2620
+ }
2621
+ async function C(r, i) {
2622
+ const s = l(r);
2623
+ if (!s.installed) throw new Error(`MCP server is not installed: ${r}`);
2624
+ const v = a.get(r) ?? 0, S = s;
2625
+ let $ = !1;
2626
+ s.loading = !0, s.error = void 0;
2627
+ try {
2628
+ const w = await f(r, !0);
2629
+ if (!S.installed || (a.get(r) ?? 0) !== v) return;
2630
+ o.value = {
2631
+ ...o.value,
2632
+ [r]: w.map((P) => ({
2633
+ id: P.id,
2634
+ name: P.originalName,
2635
+ description: P.description,
2636
+ enabled: S.enabled && i
2637
+ }))
2638
+ };
2639
+ } catch (w) {
2640
+ throw (a.get(r) ?? 0) === v && (S.enabled = !1, S.error = w, $ = !0, b(r)), w;
2641
+ } finally {
2642
+ ((a.get(r) ?? 0) === v || $) && (S.loading = void 0);
2643
+ }
2644
+ }
2645
+ const L = {
2646
+ servers: h(() => n.value.map(({ config: r, ...i }) => ({ ...i }))),
2647
+ tools: h(
2648
+ () => Object.fromEntries(Object.entries(o.value).map(([r, i]) => [r, i.map((s) => ({ ...s }))]))
2649
+ ),
2650
+ async addServer(r) {
2651
+ const i = l(r);
2652
+ if (i.installed = !0, i.enabled = !0, o.value[r]) {
2653
+ A(r, !0);
2654
+ return;
2655
+ }
2656
+ await O(r), A(r, !0);
2657
+ },
2658
+ removeServer(r) {
2659
+ const i = l(r);
2660
+ i.installed = !1, i.enabled = !1, i.loading = void 0, i.error = void 0, b(r);
2661
+ },
2662
+ async setServerEnabled(r, i) {
2663
+ const s = l(r);
2664
+ if (i && !s.installed) throw new Error(`MCP server is not installed: ${r}`);
2665
+ if (s.enabled = i, s.error = void 0, i) {
2666
+ if (o.value[r]) {
2667
+ A(r, !0);
2668
+ return;
2669
+ }
2670
+ await O(r), A(r, !0);
2671
+ } else
2672
+ A(r, !1);
2673
+ },
2674
+ setToolEnabled(r, i, s) {
2675
+ const v = l(r), S = o.value[r];
2676
+ if (!v.installed) throw new Error(`MCP server is not installed: ${r}`);
2677
+ if (!S) throw new Error(`MCP tools are not loaded: ${r}`);
2678
+ if (!S.some((w) => w.id === i)) throw new Error(`Unknown MCP tool: ${r}/${i}`);
2679
+ const $ = S.map((w) => w.id === i ? { ...w, enabled: s } : w);
2680
+ o.value = {
2681
+ ...o.value,
2682
+ [r]: $
2683
+ }, s ? v.enabled = !0 : $.some((w) => w.enabled) || (v.enabled = !1);
2684
+ }
2685
+ };
2686
+ for (const r of n.value)
2687
+ r.installed && O(r.id, !1).catch(() => {
2688
+ });
2689
+ return { runtime: L, listTools: async (r, i) => {
2690
+ const s = [];
2691
+ for (const v of r) {
2692
+ if (!Object.prototype.hasOwnProperty.call(i, v))
2693
+ throw new Error(`MCP tool selection is missing for this turn: ${v}`);
2694
+ const S = u.get(v) ?? await f(v), $ = i[v];
2695
+ if ($.length === 0) continue;
2696
+ const w = S.filter((P) => $.includes(P.id));
2697
+ if (w.length !== $.length)
2698
+ throw new Error(`MCP tools selected for this turn no longer exist on "${v}".`);
2699
+ s.push(...w);
2700
+ }
2701
+ return s;
2702
+ }, callTool: (r, i, s) => c(r, (v) => v.callTool({ name: i, arguments: s })) };
2703
+ }
2704
+ function Mn(e) {
2705
+ var f;
2706
+ const t = e.conversation ?? {}, n = e.titleGenerator ?? We, o = t.useMessageOptions, u = o == null ? void 0 : o.responseProvider;
2707
+ if (e.mcp !== void 0 && e.mcpServers !== void 0)
2708
+ throw new Error("useLocalChatRuntime: mcp and mcpServers cannot be configured at the same time.");
2709
+ if ((f = e.modelProviders) != null && f.length && u)
2710
+ throw new Error("useLocalChatRuntime: modelProviders and responseProvider cannot be configured at the same time.");
2711
+ const m = e.modelProviders ? cn(e.modelProviders) : [], d = m.length > 0 ? an(m) : null, a = e.mcpServers !== void 0 ? yn(e.mcpServers) : e.mcp, l = e.composer ?? {}, b = [vn()];
2712
+ d && b.push(ln(d.resolveModel)), a && b.push(bn(a.listTools, a.callTool));
2713
+ const A = {
2714
+ ...o,
2715
+ plugins: [...b, ...(o == null ? void 0 : o.plugins) ?? []],
2716
+ responseProvider: d ? rn(d.resolveModel) : u
2717
+ };
2718
+ if (!A.responseProvider)
2719
+ throw new Error("useLocalChatRuntime requires conversation.useMessageOptions.responseProvider or modelProviders.");
2720
+ const c = St({
2721
+ autoSaveMessages: !0,
2722
+ ...t,
2723
+ useMessageOptions: A
2724
+ });
2725
+ return sn({
2726
+ conversation: c,
2727
+ titleGenerator: n,
2728
+ composer: {
2729
+ ...l,
2730
+ model: d == null ? void 0 : d.model,
2731
+ mcp: a == null ? void 0 : a.runtime
2732
+ }
2733
+ });
2734
+ }
2735
+ export {
2736
+ Tn as TrChat,
2737
+ Ho as TrChatUI,
2738
+ Mt as useChatHistoryItems,
2739
+ xo as useChatRuntimeAdapter,
2740
+ sn as useKitChatRuntime,
2741
+ Mn as useLocalChatRuntime
2742
+ };