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

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