@mcp-use/inspector 20.0.0-beta.3 → 20.0.0-beta.5

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.
Files changed (53) hide show
  1. package/dist/cdn/{ChatTab-BS5Tlm2y.js → ChatTab-B255lH5i.js} +6 -6
  2. package/dist/cdn/{ConnectionSettingsForm-BFsZpwK4.js → ConnectionSettingsForm-DF-NS58d.js} +1 -1
  3. package/dist/cdn/{ConnectionSettingsTab-DDk06dhT.js → ConnectionSettingsTab-dI-Cqe79.js} +1 -1
  4. package/dist/cdn/{MarkdownRenderer-_aYcof42.js → MarkdownRenderer-Ba7nA4Ie.js} +1 -1
  5. package/dist/cdn/{OAuthCallback-C4n2hqKU.js → OAuthCallback-Blc2Asxc.js} +1 -1
  6. package/dist/cdn/{PromptsTab-BajHFLa3.js → PromptsTab-BYKnY7Rp.js} +1 -1
  7. package/dist/cdn/{ResourcesTab-BgeMlTdR.js → ResourcesTab-BGualKW-.js} +5 -5
  8. package/dist/cdn/{SamplingTab-CnJB229N.js → SamplingTab-BeZBUeni.js} +3 -3
  9. package/dist/cdn/{ToolsTab-ACLxPxR6.js → ToolsTab-j6n4O_3s.js} +4 -4
  10. package/dist/cdn/{ViewPreview-DsPwZAwO.js → ViewPreview-DihyG6Qd.js} +4 -3
  11. package/dist/cdn/{WidgetWrapper-CwlpDv17.js → WidgetWrapper-B4H3Fek7.js} +2 -2
  12. package/dist/cdn/{dist-B0eL32Gb.js → dist-DbX5yidW.js} +3 -3
  13. package/dist/cdn/{index-browser-QDjRGsPo.js → index-browser-DkQOzkvX.js} +1 -1
  14. package/dist/cdn/inspector.js +5 -5
  15. package/dist/cdn/{react-Dn8PWXwP.js → react-BajV-X4P.js} +593 -585
  16. package/dist/cdn/{telemetry-gHF-tMli.js → telemetry-DabTAQ8x.js} +2 -2
  17. package/dist/cdn/{useConfig-BWcNCqwi.js → useConfig-Btmh8wjJ.js} +2 -2
  18. package/dist/cdn/{useViewHostProps-DIIlz3tJ.js → useViewHostProps-B6SKeeH9.js} +3 -2
  19. package/dist/cli.js +1 -1
  20. package/dist/client/hooks/useViewHostProps.d.ts +1 -1
  21. package/dist/client/hooks/useViewHostProps.d.ts.map +1 -1
  22. package/dist/client/index.js +2 -1
  23. package/dist/server/cdn-shell.js +2 -2
  24. package/dist/server/{chunk-HGPQON3P.js → chunk-DSTNUYWX.js} +1 -1
  25. package/dist/server/{chunk-W3PVQLOP.js → chunk-SQ4XNMLT.js} +1 -1
  26. package/dist/server/{chunk-H7UBATRR.js → chunk-ZCGLU5T7.js} +1 -1
  27. package/dist/server/cli.js +2 -2
  28. package/dist/server/index.js +3 -3
  29. package/dist/server/middleware.js +3 -3
  30. package/dist/server/version.js +1 -1
  31. package/dist/web/assets/{ChatTab-C2FtENBM.js → ChatTab-BCobuZDc.js} +1 -1
  32. package/dist/web/assets/{ConnectionSettingsTab-B2sUjytG.js → ConnectionSettingsTab-BjGkLwVu.js} +1 -1
  33. package/dist/web/assets/{ElicitationTab-DwH08kDC.js → ElicitationTab-D3ZUKHND.js} +1 -1
  34. package/dist/web/assets/{ManufactOAuthCallback-Btu4B6u6.js → ManufactOAuthCallback-CS3ydSZg.js} +1 -1
  35. package/dist/web/assets/{MarkdownRenderer-DpIEt9wb.js → MarkdownRenderer-BeeBfQhv.js} +1 -1
  36. package/dist/web/assets/{NotificationsTab-CHB8mtSz.js → NotificationsTab-Uj0_DrmK.js} +1 -1
  37. package/dist/web/assets/{OAuthCallback-DV4MgX4Z.js → OAuthCallback-C0ljgCiw.js} +1 -1
  38. package/dist/web/assets/{PromptsTab-0GIapoSs.js → PromptsTab-Bns2u0G-.js} +1 -1
  39. package/dist/web/assets/{ResourcesTab-N9xjsI_b.js → ResourcesTab-CO24312V.js} +1 -1
  40. package/dist/web/assets/{SamplingTab-Dw0vpi4t.js → SamplingTab-7gtN7FwU.js} +1 -1
  41. package/dist/web/assets/{ServerMetadataTab-D-eQpLBF.js → ServerMetadataTab-CQwqYSjL.js} +1 -1
  42. package/dist/web/assets/{ToolsTab-BMrMJ5JV.js → ToolsTab-bDdRxI1b.js} +1 -1
  43. package/dist/web/assets/{ViewPreview-N_cpEO0W.js → ViewPreview-Ba1Ec5uA.js} +1 -1
  44. package/dist/web/assets/{WidgetWrapper-pDgNVq9y.js → WidgetWrapper-CYHfzrtb.js} +1 -1
  45. package/dist/web/assets/{checkbox-CrnXSMh2.js → checkbox-CzBkaNKa.js} +1 -1
  46. package/dist/web/assets/{dist-CeWSydFI.js → dist-C5JjLJN9.js} +4 -4
  47. package/dist/web/assets/{index-Cfuv_gb3.js → index-TQ5V7cM9.js} +30 -13
  48. package/dist/web/assets/{shared-B1GD9FMm.js → shared-BF0rJNdE.js} +1 -1
  49. package/dist/web/assets/{tabs-subtle-CG5cjC_N.js → tabs-subtle-6D79T1xd.js} +1 -1
  50. package/dist/web/assets/{useConfig-BTp15Lle.js → useConfig-BAgALiZg.js} +1 -1
  51. package/dist/web/assets/{useViewHostProps-BQlaFC2Q.js → useViewHostProps-BYitt_6K.js} +1 -1
  52. package/dist/web/index.html +2 -2
  53. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import { n as e, o as t, r as n, t as r } from "./index-browser-QDjRGsPo.js";
1
+ import { n as e, o as t, r as n, t as r } from "./index-browser-DkQOzkvX.js";
2
2
  //#region src/client/telemetry/events.ts
3
3
  var i = class {
4
4
  name = "mcp_inspector_open";
@@ -162,7 +162,7 @@ function b() {
162
162
  let e = window.__INSPECTOR_VERSION__;
163
163
  if (e !== void 0 && e !== "") return e;
164
164
  }
165
- return "20.0.0-beta.2";
165
+ return "20.0.0-beta.4";
166
166
  } catch {
167
167
  return "0.0.0";
168
168
  }
@@ -1,6 +1,6 @@
1
1
  import { s as e, t } from "./react-BIs9pQ3H.js";
2
- import { o as n, t as r } from "./telemetry-gHF-tMli.js";
3
- import { t as i } from "./dist-B0eL32Gb.js";
2
+ import { o as n, t as r } from "./telemetry-DabTAQ8x.js";
3
+ import { t as i } from "./dist-DbX5yidW.js";
4
4
  //#region src/client/components/chat/types.ts
5
5
  var a = /* @__PURE__ */ e(t(), 1), o = {
6
6
  openai: "gpt-5.6-terra",
@@ -1,5 +1,5 @@
1
1
  import { s as e, t } from "./react-BIs9pQ3H.js";
2
- import { d as n } from "./react-Dn8PWXwP.js";
2
+ import { d as n } from "./react-BajV-X4P.js";
3
3
  import { i as r, r as i, s as a, t as o } from "./WidgetDebugContext-D4usL_MA.js";
4
4
  //#region src/client/console-log-bus.ts
5
5
  var s = /* @__PURE__ */ e(t(), 1), c = new class {
@@ -341,7 +341,8 @@ function C(e) {
341
341
  onDisplayModeChange: y,
342
342
  inlineMaxWidth: C,
343
343
  chromeless: w,
344
- onReady: T
344
+ onReady: T,
345
+ mockOpenAiFileApis: !0
345
346
  } : null;
346
347
  }
347
348
  //#endregion
package/dist/cli.js CHANGED
@@ -182,7 +182,7 @@ function registerInspectorStaticAssets(app2, basePath = "") {
182
182
  var package_default = {
183
183
  name: "@mcp-use/inspector",
184
184
  type: "module",
185
- version: "20.0.0-beta.2",
185
+ version: "20.0.0-beta.4",
186
186
  description: "MCP Inspector - A tool for inspecting and debugging MCP servers",
187
187
  author: "",
188
188
  license: "MIT",
@@ -15,5 +15,5 @@ export declare function useViewHostProps(options: {
15
15
  inlineMaxWidth?: number;
16
16
  chromeless?: boolean;
17
17
  onReady?: () => void;
18
- }): Pick<ViewRendererProps, "source" | "hostInfo" | "hostContext" | "cspMode" | "wrapTransport" | "onCspViolation" | "onModelContextUpdate" | "onLog" | "onResourceResolved" | "displayMode" | "onDisplayModeChange" | "inlineMaxWidth" | "chromeless" | "onReady"> | null;
18
+ }): Pick<ViewRendererProps, "source" | "hostInfo" | "hostContext" | "cspMode" | "wrapTransport" | "onCspViolation" | "onModelContextUpdate" | "onLog" | "onResourceResolved" | "displayMode" | "onDisplayModeChange" | "inlineMaxWidth" | "chromeless" | "onReady" | "mockOpenAiFileApis"> | null;
19
19
  //# sourceMappingURL=useViewHostProps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useViewHostProps.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useViewHostProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,eAAe,EACf,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAkClD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,IAAI,CACN,iBAAiB,EACf,QAAQ,GACR,UAAU,GACV,aAAa,GACb,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,sBAAsB,GACtB,OAAO,GACP,oBAAoB,GACpB,aAAa,GACb,qBAAqB,GACrB,gBAAgB,GAChB,YAAY,GACZ,SAAS,CACZ,GAAG,IAAI,CA8LP"}
1
+ {"version":3,"file":"useViewHostProps.d.ts","sourceRoot":"","sources":["../../../src/client/hooks/useViewHostProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,eAAe,EACf,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAkClD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAChD,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,IAAI,CACN,iBAAiB,EACf,QAAQ,GACR,UAAU,GACV,aAAa,GACb,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,sBAAsB,GACtB,OAAO,GACP,oBAAoB,GACpB,aAAa,GACb,qBAAqB,GACrB,gBAAgB,GAChB,YAAY,GACZ,SAAS,GACT,oBAAoB,CACvB,GAAG,IAAI,CA+LP"}
@@ -4696,7 +4696,8 @@ function useViewHostProps(options) {
4696
4696
  onDisplayModeChange,
4697
4697
  inlineMaxWidth,
4698
4698
  chromeless,
4699
- onReady
4699
+ onReady,
4700
+ mockOpenAiFileApis: true
4700
4701
  };
4701
4702
  }
4702
4703
 
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  registerInspectorCdnShell
3
- } from "./chunk-HGPQON3P.js";
3
+ } from "./chunk-DSTNUYWX.js";
4
4
  import "./chunk-M5TZA42I.js";
5
- import "./chunk-H7UBATRR.js";
5
+ import "./chunk-ZCGLU5T7.js";
6
6
  import "./chunk-H6ZCIKBS.js";
7
7
  import "./chunk-J4FNYLBF.js";
8
8
  import "./chunk-WFT4JHYI.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-M5TZA42I.js";
4
4
  import {
5
5
  getInspectorVersion
6
- } from "./chunk-H7UBATRR.js";
6
+ } from "./chunk-ZCGLU5T7.js";
7
7
  import {
8
8
  inspectorStylesUrl,
9
9
  resolveInspectorAssetUrls,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  registerInspectorCdnShell
3
- } from "./chunk-HGPQON3P.js";
3
+ } from "./chunk-DSTNUYWX.js";
4
4
  import {
5
5
  registerInspectorProxyRoutes
6
6
  } from "./chunk-UJLXHNQP.js";
@@ -2,7 +2,7 @@
2
2
  var package_default = {
3
3
  name: "@mcp-use/inspector",
4
4
  type: "module",
5
- version: "20.0.0-beta.2",
5
+ version: "20.0.0-beta.4",
6
6
  description: "MCP Inspector - A tool for inspecting and debugging MCP servers",
7
7
  author: "",
8
8
  license: "MIT",
@@ -5,11 +5,11 @@ import {
5
5
  } from "./chunk-KD7K27XK.js";
6
6
  import {
7
7
  registerInspectorCdnShell
8
- } from "./chunk-HGPQON3P.js";
8
+ } from "./chunk-DSTNUYWX.js";
9
9
  import "./chunk-M5TZA42I.js";
10
10
  import {
11
11
  getInspectorVersion
12
- } from "./chunk-H7UBATRR.js";
12
+ } from "./chunk-ZCGLU5T7.js";
13
13
  import "./chunk-H6ZCIKBS.js";
14
14
  import {
15
15
  registerInspectorProxyRoutes
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  mountInspector
3
- } from "./chunk-W3PVQLOP.js";
3
+ } from "./chunk-SQ4XNMLT.js";
4
4
  import {
5
5
  registerInspectorCdnShell
6
- } from "./chunk-HGPQON3P.js";
6
+ } from "./chunk-DSTNUYWX.js";
7
7
  import "./chunk-M5TZA42I.js";
8
- import "./chunk-H7UBATRR.js";
8
+ import "./chunk-ZCGLU5T7.js";
9
9
  import "./chunk-H6ZCIKBS.js";
10
10
  import {
11
11
  registerInspectorProxyRoutes
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  mountInspector
3
- } from "./chunk-W3PVQLOP.js";
4
- import "./chunk-HGPQON3P.js";
3
+ } from "./chunk-SQ4XNMLT.js";
4
+ import "./chunk-DSTNUYWX.js";
5
5
  import "./chunk-M5TZA42I.js";
6
- import "./chunk-H7UBATRR.js";
6
+ import "./chunk-ZCGLU5T7.js";
7
7
  import "./chunk-H6ZCIKBS.js";
8
8
  import "./chunk-UJLXHNQP.js";
9
9
  import "./chunk-IKTZUWSX.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  VERSION,
3
3
  getInspectorVersion
4
- } from "./chunk-H7UBATRR.js";
4
+ } from "./chunk-ZCGLU5T7.js";
5
5
  import "./chunk-PKBMQBKP.js";
6
6
  export {
7
7
  VERSION,
@@ -1,4 +1,4 @@
1
- import{s as e,t}from"./react-CU_d2d5K.js";import{Cr as n,Dr as r,En as i,G as a,Ir as o,Lr as s,Mn as c,Nn as l,Nr as u,Sr as d,Tn as f,Yn as p,_r as m,a as h,an as g,br as _,c as v,d as y,dr as b,f as x,fr as S,gr as C,in as w,kn as T,mn as E,mr as D,n as O,on as k,or as A,pn as j,pr as M,r as N,s as P,sr as F,t as ee,u as te,wr as I,xr as L}from"./input-CLYhA7PK.js";import{t as R}from"./jsx-runtime-Cjj9sGSy.js";import{n as z,t as B}from"./label-Cdim77Jw.js";import{m as V,t as ne}from"./AnimatePresence-C5p0yiY1.js";import{a as H,c as re,i as U,n as ie,o as W,p as G,r as ae,s as oe,t as K}from"./select-CJ57-Bor.js";import{a as q,c as J,i as se,l as ce,n as le,o as ue,r as Y,s as de,t as fe}from"./FormContext-DH2caWKO.js";import{t as pe}from"./createLucideIcon-B3b8EU0b.js";import{t as me}from"./refresh-cw-C9wQl8_d.js";import{A as he,At as ge,B as _e,Bt as ve,C as ye,D as be,Dt as xe,E as Se,F as Ce,G as we,H as Te,Ht as Ee,I as De,Kt as Oe,N as ke,O as Ae,P as je,Pt as Me,R as Ne,S as Pe,T as Fe,U as Ie,Ut as Le,V as Re,Vt as ze,Wt as Be,Zt as Ve,a as He,an as Ue,b as We,bn as Ge,c as Ke,cn as qe,d as Je,dn as Ye,et as X,f as Xe,fn as Ze,g as Qe,gt as $e,hn as et,i as tt,in as nt,l as Z,mn as rt,n as it,o as at,ot,p as st,pn as ct,qt as lt,r as ut,rn as dt,s as ft,sn as pt,u as mt,v as ht,vn as gt,vt as _t,wt as vt,x as yt,xn as bt,xt,y as St,yt as Ct,zt as wt}from"./index-Cfuv_gb3.js";import{a as Tt,c as Et,i as Dt,n as Ot,o as kt,r as At,s as jt}from"./dist-CeWSydFI.js";import{n as Mt,t as Nt}from"./MarkdownRenderer-DpIEt9wb.js";import{a as Pt,i as Ft,n as It,t as Lt}from"./tabs-subtle-CG5cjC_N.js";import{a as Rt,c as zt,i as Bt,l as Vt,n as Ht,o as Ut,r as Wt,s as Gt,t as Kt}from"./useConfig-BTp15Lle.js";import{t as qt}from"./textarea-DLAmNVf_.js";import{t as Jt}from"./checkbox-CrnXSMh2.js";import{n as Yt,t as Xt}from"./schemaHelpers-DLNTQr_6.js";import{t as Zt}from"./useViewHostProps-BQlaFC2Q.js";var Qt=pe(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),$t=pe(`arrow-left-from-line`,[[`path`,{d:`m9 6-6 6 6 6`,key:`7v63n9`}],[`path`,{d:`M3 12h14`,key:`13k4hi`}],[`path`,{d:`M21 19V5`,key:`b4bplr`}]]),en=pe(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),tn=pe(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),nn=pe(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),rn=pe(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),an=pe(`square-pen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),Q=e(t(),1),$=R(),on=Q.forwardRef(({className:e,children:t,...n},r)=>(0,$.jsx)(`div`,{ref:r,"data-slot":`scroll-area`,className:s(`relative overflow-hidden`,e),...n,children:(0,$.jsx)(`div`,{"data-slot":`scroll-area-viewport`,className:`h-full w-full overflow-y-auto overflow-x-hidden`,children:t})}));on.displayName=`ScrollArea`;function sn({count:e}){return(0,$.jsx)(`div`,{className:`flex flex-row absolute top-0 right-0 z-10 w-full items-center justify-between gap-2 ${te}`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full`,children:[(0,$.jsx)(`h2`,{className:y,children:`Chat History`}),(0,$.jsx)(u,{className:`bg-zinc-500/20 text-zinc-600 dark:text-zinc-400 border-transparent`,variant:`outline`,children:e})]})})}function cn({className:e,...t}){return(0,$.jsx)(`div`,{"data-slot":`skeleton`,className:s(`animate-pulse rounded-md bg-muted`,e),...t})}var ln=`New Chat`,un=`Chat`;function dn(e){return e===`New Chat`||e===`Chat`}var fn=`Generate a concise title (maximum 60 characters) for this chat based on the user's first message. Name the subject matter, task, or question — not the act of chatting. Never output meta phrases (e.g. do not use: greeting, introduction, initiation, conversation start, chat session). If there is no specific topic yet, reply with exactly: Chat. Return only the title, no quotes or extra text.`,pn=[`greeting`,`initiation`,`conversation start`,`introduction to`,`chat session`,`starting a chat`,`beginning of`];function mn(e){return typeof e.content==`string`?e.content.trim():String(e.content??``).trim()}function hn(e){for(let t of e){if(t.role!==`user`)continue;let e=mn(t);if(e)return e}return null}function gn(e){let t=e.toLowerCase();for(let e of pn)if(t.includes(e))return!0;return!1}function _n(e){let t=e.trim().split(/\r?\n/)[0].trim();if(!t)return!0;if(t.length>48)return!1;let n=t.replace(/\s+/g,` `).toLowerCase();return/^(hi|hello|hey|greetings?)[!.]?$/i.test(n)||/^(good morning|good afternoon|good evening)[!.]?$/i.test(n)||/^(hi|hello|hey)\s+(there|all|team|everyone)[!.]?$/i.test(n)}function vn(e){return e.length>60?`${e.substring(0,57)}...`:e}function yn(e){return e?.model?.trim()?e.provider===`ollama`?!0:!!e.apiKey?.trim():!1}async function bn(e,t,n){let r=t.trim();if(!r||!yn(e))return null;if(_n(r))return vn(r);try{let t=(await Tt({config:Et(e.provider,e.model,{apiKey:e.apiKey,temperature:e.temperature,baseUrl:e.baseUrl,maxTokens:128}),messages:[{role:`system`,content:fn},{role:`user`,content:r}],signal:n})).trim();if(!t)return null;let i=vn(t);return i===`Chat`||gn(i)?vn(r):i}catch{return null}}var xn=28,Sn=3,Cn=.72;function wn({chatId:e,title:t,className:n,onRevealComplete:r}){let[i,a]=(0,Q.useState)(t),[o,c]=(0,Q.useState)(0),[l,u]=(0,Q.useState)(1),d=(0,Q.useRef)(t),f=(0,Q.useRef)(null),p=(0,Q.useRef)(e);return(0,Q.useEffect)(()=>{if(p.current!==e){p.current=e,d.current=t,f.current=null,a(t),c(0),u(1);return}},[e,t]),(0,Q.useEffect)(()=>{let n=`${e}:${t}`;if(f.current===n){a(t),c(0),u(1);return}let i=d.current,o=dn(i)&&!dn(t)&&t!==i;if(d.current=t,!o){a(t),c(0),u(1);return}f.current=n;let s=0,l=t.length;a(``),c(Sn),u(Cn);let p,m=()=>{s+=1;let e=l>0?s/l:1;a(t.slice(0,s)),c(Sn*(1-e)),u(Cn+(1-Cn)*e),s<l?p=setTimeout(m,xn):r?.()};return p=setTimeout(m,xn),()=>{p&&clearTimeout(p)}},[e,t,r]),(0,$.jsx)(`span`,{className:s(`block truncate transition-[filter,opacity] duration-75`,n),style:{filter:o>0?`blur(${o}px)`:void 0,opacity:l},children:i})}function Tn({compact:e,hideAgentName:t}){return(0,$.jsxs)(`div`,{className:s(`flex items-center justify-between py-3 gap-2`,e?`px-4`:`px-3 rounded-lg`),children:[(0,$.jsxs)(`div`,{className:s(`flex-1 min-w-0 flex flex-col gap-1`,t?`gap-1.5`:`gap-1`),children:[(0,$.jsx)(cn,{className:`h-4 w-3/4`}),!t&&(0,$.jsx)(cn,{className:`h-3 w-1/2`})]}),(0,$.jsx)(cn,{className:`h-3 w-14 shrink-0`})]})}function En({chats:e,onDelete:t,onSelect:n,compact:r,hideAgentName:i,isLoading:o,currentChatId:c}){let[l,u]=Q.useState(``),d=e.filter(e=>e.type!==`agent_execution`),f=d.filter(e=>(e.title??``).toLowerCase().includes(l.toLowerCase())),p=e=>{let t=new Date(e),n=new Date;if(t.toDateString()===n.toDateString())return t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});let r=new Date(n);if(r.setDate(r.getDate()-1),t.toDateString()===r.toDateString())return`Yesterday`;let i=n.getTime()-t.getTime(),a=Math.floor(i/(1e3*60*60*24));return a<7?`${a} days ago`:t.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})},m=e=>(0,$.jsxs)(`div`,{className:s(`flex items-center justify-between py-3 hover:bg-muted/50 transition-colors gap-2 cursor-pointer`,r?`px-4`:`px-3 rounded-lg`,c===e.id&&`bg-muted/50`),children:[(0,$.jsxs)(`div`,{className:s(`flex-1 min-w-0 flex overflow-hidden`,i?`flex-col`:`flex-col gap-1`),children:[(0,$.jsx)(`p`,{className:`text-sm font-medium truncate w-full`,children:(0,$.jsx)(wn,{chatId:e.id,title:e.title},`${e.id}:${e.title}`)}),!i&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground truncate w-full`,children:e.agent_name})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:p(e.updated_at)})})]});return(0,$.jsxs)(`div`,{className:`flex h-full w-full flex-col`,children:[(0,$.jsx)(`div`,{className:`mb-4 px-3 sm:px-5`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(a,{className:`absolute left-3 top-2.5 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(ee,{placeholder:`Search chats...`,value:l,onChange:e=>u(e.target.value),className:`pl-9 h-8 border-gray-300 dark:border-zinc-600`})]})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:o&&d.length===0?(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(Tn,{compact:r,hideAgentName:i}),(0,$.jsx)(Tn,{compact:r,hideAgentName:i}),(0,$.jsx)(Tn,{compact:r,hideAgentName:i})]}):d.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-4 text-center min-h-[12rem]`,children:(0,$.jsx)(ve,{vertical:!0,noBorder:!0,message:`No chats`,className:`mt-0`})}):f.length===0?null:(0,$.jsx)(`div`,{className:`space-y-1`,children:f.map(e=>n?(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`block w-full text-left group cursor-pointer`,children:m(e)},e.id):(0,$.jsx)(`div`,{className:`block group cursor-pointer`,children:m(e)},e.id))})})]})}var Dn=20;function On({provider:e,enabled:t=!0,agentId:n,refetchKey:r,refetchInterval:i=!1}){let[a,o]=(0,Q.useState)(1),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(0),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useCallback)(async()=>{if(t){f(!0),m(null);try{let t=await e.listChats({...n?{agentId:n}:{},take:Dn*a,skip:0});c(t.items),u(t.total)}catch(e){m(e instanceof Error?e:Error(String(e)))}finally{f(!1)}}},[e,t,n,a]);(0,Q.useEffect)(()=>{t&&o(1)},[t]),(0,Q.useEffect)(()=>{g()},[g]),(0,Q.useEffect)(()=>{r!==void 0&&r!==h.current&&(h.current=r,t&&g())},[r,t,g]),(0,Q.useEffect)(()=>{if(!t||!i)return;let e=setInterval(()=>void g(),i);return()=>clearInterval(e)},[t,i,g]);let _=l>s.length;return{chats:s,total:l,isLoading:d,error:p,hasNextPage:_,loadMore:(0,Q.useCallback)(()=>{_&&!d&&o(e=>e+1)},[_,d]),refetch:(0,Q.useCallback)(()=>{g()},[g]),deleteChat:(0,Q.useCallback)(async t=>{await e.deleteChat(t),await g()},[e,g])}}function kn({provider:e,open:t,onOpenChange:n,currentChatId:r,container:i,agentId:a,agentDisplayNameFallback:o,onSelectChat:c,variant:l=`drawer`,containerClassName:u,refetchKey:d,refetchInterval:f=!1,onCurrentChatDeleted:p,onDeleteSuccess:m,onDeleteError:h}){let g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),{chats:v,isLoading:y,hasNextPage:b,loadMore:x,deleteChat:S}=On({provider:e,enabled:t,agentId:a,refetchKey:d,refetchInterval:o?f||3e3:f});(0,Q.useEffect)(()=>{if(!t||!_.current)return;let e=new IntersectionObserver(e=>{e[0]?.isIntersecting&&x()},{threshold:.5});return e.observe(_.current),()=>{e.disconnect()}},[t,b,y,x]);let C=async e=>{try{await S(e),m?.(),e===r&&p?.()}catch(e){console.error(`Failed to delete chat:`,e),h?.(e)}},w=v.map(e=>({...e,title:e.title||`New Chat`,agent_name:e.agent_name??o??`Unknown Agent`})),T=w.filter(e=>e.type!==`agent_execution`).length,E=(0,$.jsx)(En,{chats:w,onDelete:C,compact:l===`inline`,hideAgentName:!!o,isLoading:y&&v.length===0,currentChatId:r,onSelect:c?e=>{c(e),n(!1)}:void 0}),D=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[(0,$.jsx)(sn,{count:T}),(0,$.jsxs)(on,{ref:g,className:s(`min-h-0 flex-1 w-full pt-14 sm:pt-16 [&_[data-slot=scroll-area-viewport]]:block!`,l===`inline`?`p-0`:`px-3 sm:px-5`),children:[E,b&&(0,$.jsx)(`div`,{ref:_,className:`py-4 flex items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin`}),`Loading more...`]})})]})]});return l===`inline`?(0,$.jsx)(`div`,{className:s(`flex h-full min-h-0 flex-col`,u),children:D}):(0,$.jsx)(Ke,{open:t,onOpenChange:n,children:(0,$.jsx)(Z,{side:`left`,className:`w-[400px] sm:w-[400px] border-zinc-200 p-0 dark:border-zinc-700`,container:i,children:D})})}function An({onCollapse:e}){return(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsxs)(F,{type:`button`,variant:`ghost`,size:`icon-sm`,tabIndex:-1,"aria-label":`Collapse`,onClick:e,className:`border-border absolute top-1/2 right-0 z-30 size-7 min-h-7 min-w-7 -translate-y-1/2 translate-x-1/2 rounded-full border bg-background`,children:[(0,$.jsx)($t,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Collapse`})]}),nativeButton:!0}),(0,$.jsx)(N,{side:`right`,children:`Collapse`})]})}var jn=`mcp-inspector-chats`,Mn=`New Chat`,Nn=40;function Pn(){try{let e=localStorage.getItem(jn);if(!e)return{sessions:[],messages:{}};let t=JSON.parse(e);return{sessions:Array.isArray(t.sessions)?t.sessions:[],messages:t.messages&&typeof t.messages==`object`?t.messages:{}}}catch{return{sessions:[],messages:{}}}}function Fn(e){localStorage.setItem(jn,JSON.stringify(e))}function In(){return new Date().toISOString()}function Ln(e){let t=e.find(e=>e.role===`user`);if(!t)return;let n=typeof t.content==`string`?t.content.trim():String(t.content??``).trim();if(n)return n.length>Nn?`${n.slice(0,Nn)}…`:n}var Rn=class{saveTimers=new Map;async listChats(e){let{sessions:t}=Pn(),n=t;e.agentId&&(n=t.filter(t=>t.agent_id===e.agentId)),n=[...n].sort((e,t)=>new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime());let r=n.length,i=e.skip??0,a=e.take??r;return{items:n.slice(i,i+a),total:r}}async getMessages(e){let{messages:t}=Pn();return t[e]??[]}async createChat(e){let t=Pn(),n=In(),r={id:crypto.randomUUID(),title:e.title??Mn,agent_id:e.agentId,agent_name:e.agentName??`MCP Server`,created_at:n,updated_at:n};return t.sessions.push(r),t.messages[r.id]=[],Fn(t),r}async updateChat(e,t){let n=Pn(),r=n.sessions.findIndex(t=>t.id===e);if(r===-1)throw Error(`Chat not found: ${e}`);let i=n.sessions[r];return t.title!==void 0&&(i.title=t.title),i.updated_at=In(),n.sessions[r]=i,Fn(n),i}async deleteChat(e){let t=Pn();t.sessions=t.sessions.filter(t=>t.id!==e),delete t.messages[e],Fn(t)}async saveMessages(e,t){let n=this.saveTimers.get(e);n&&clearTimeout(n),await new Promise(n=>{let r=setTimeout(()=>{this.saveTimers.delete(e);let r=Pn();r.messages[e]=t;let i=r.sessions.findIndex(t=>t.id===e);if(i!==-1){let e=r.sessions[i];if(e.updated_at=In(),e.title===Mn){let n=Ln(t);n&&(e.title=n)}r.sessions[i]=e}Fn(r),n()},500);this.saveTimers.set(e,r)})}};function zn({activeChatId:e,storage:t,messages:n,isLoading:r,effectiveClientSide:i,llmConfig:a,activeChatTitle:o,titleGenerationReady:s=!0,onTitleGenerated:c,onHistoryRefetch:l}){let u=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{u.current=null},[e]),(0,Q.useEffect)(()=>{if(!e||!t||r||!s||o&&!dn(o))return;let d=hn(n);if(!d)return;let f=`${e}:${d}`;if(u.current===f)return;u.current=f;let p=!1;return(async()=>{let n=null;if(t.generateTitle?n=await t.generateTitle(e):i&&a&&(n=await bn(a,d),n&&await t.updateChat(e,{title:n})),!p){if(!n||n===`New Chat`){u.current=null;return}l?.(),c?.(e,n)}})().catch(()=>{p||(u.current=null)}),()=>{p=!0}},[e,t,n,r,i,a,o,s,c,l])}var Bn=[`#e0eaff`,`#f9ffbd`,`#dedede`,`#ffffff`],Vn=.54;function Hn({className:e,children:t,shaderPhase:n=`hidden`,onShaderFadeComplete:r,meshAnimationPaused:i=!1,...a}){let o=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=window.requestAnimationFrame(()=>l(!0));return()=>window.cancelAnimationFrame(e)},[]),(0,Q.useEffect)(()=>{n===`fading`&&!c&&r?.()},[n,c,r]);let u=n!==`hidden`,d=n===`visible`&&c,f=e=>{e.propertyName===`opacity`&&n===`fading`&&r?.()};return(0,$.jsxs)(`div`,{ref:o,className:s(`relative flex min-h-0 flex-1 flex-col overflow-hidden bg-white dark:bg-black`,e),...a,children:[u&&(0,$.jsxs)(`div`,{className:s(`pointer-events-none absolute inset-x-0 bottom-0 z-0 transition-opacity duration-500`,d?`opacity-100`:`opacity-0`),style:{height:`${Vn*100}%`},"aria-hidden":!0,onTransitionEnd:f,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-[#edf2ff] dark:bg-[#1e293b]`}),(0,$.jsx)(`div`,{className:s(`absolute inset-0`,c?`opacity-75 dark:opacity-45`:`opacity-0`),children:(0,$.jsx)(wt,{className:`absolute inset-0 h-full w-full`,colors:[...Bn],distortion:.8,swirl:.1,grainMixer:0,grainOverlay:.3,speed:+!i})}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-white/0 from-[12%] via-white/60 via-[38%] to-white dark:from-black/0 dark:from-[12%] dark:via-black/60 dark:via-[38%] dark:to-black`})]}),(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col`,children:t})]})}function Un(e){return e?e.apiKey===`server-managed`||e.baseUrl?.includes(`/inspector/llm`)===!0:!1}function Wn(e){if(!(e instanceof Error))return!1;let t=e.message.toLowerCase();return t.includes(`failed to fetch`)||t.includes(`networkerror`)||t.includes(`network request failed`)||t.includes(`load failed`)}function Gn(e,t){if(!t)return e>=502&&e<=504?{kind:`cloud_unavailable`}:null;if(e===402)return{kind:`credits_exhausted`,billingUrl:typeof t.upgradeUrl==`string`?t.upgradeUrl:typeof t.billingUrl==`string`?t.billingUrl:void 0,message:typeof t.message==`string`?t.message:`You've used your included free plan credits.`};if(e===429){if(t.loginRequired&&t.loginUrl)return{kind:`login_required`,loginUrl:String(t.loginUrl)};if(t.creditsExhausted)return{kind:`credits_exhausted`,billingUrl:typeof t.billingUrl==`string`?t.billingUrl:void 0,message:typeof t.message==`string`?t.message:`You've used your included free plan credits.`};if(t.error===`free_org_rate_limited`||typeof t.reason==`string`)return{kind:`credits_exhausted`,message:typeof t.message==`string`?t.message:`You've reached your included chat quota for this workspace.`}}return e>=502&&e<=504?{kind:`cloud_unavailable`}:null}function Kn(e){let t=e.match(/^OpenAI request failed \((\d+) /);if(!t)return null;let n=Number(t[1]),r=e.indexOf(`{`);if(r===-1)return null;try{let t=JSON.parse(e.slice(r));if(t&&typeof t==`object`&&!Array.isArray(t))return{status:n,body:t}}catch{}return null}function qn(e){if(e instanceof Error&&e.name===`LlmRequestError`){let t=e.status??0,n=e.body;return Gn(t,n&&typeof n==`object`&&!Array.isArray(n)?n:void 0)}if(e instanceof Error){let t=Kn(e.message);if(t)return Gn(t.status,t.body)}return Wn(e)?{kind:`cloud_unavailable`}:null}function Jn(e,t){return Gn(e,t)}var Yn=Q.createContext(null);function Xn(){let e=Q.useContext(Yn);if(!e)throw Error(`Command components must be used within <Command>`);return e}function Zn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}var Qn=Q.forwardRef(({className:e,...t},n)=>{let[r,i]=Q.useState(``),[a,o]=Q.useState(null),[c,l]=Q.useState(0),u=Q.useCallback(()=>(l(e=>e+1),()=>l(e=>Math.max(0,e-1))),[]);return(0,$.jsx)(Yn.Provider,{value:{search:r,setSearch:i,activeValue:a,setActiveValue:o,visibleCount:c,registerVisible:u},children:(0,$.jsx)(`div`,{ref:n,className:s(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})})});Qn.displayName=`Command`;var $n=Q.forwardRef(({className:e,...t},n)=>{let{search:r,setSearch:i}=Xn();return(0,$.jsx)(`div`,{className:`flex items-center border-b px-3`,children:(0,$.jsx)(`input`,{ref:n,value:r,onChange:e=>i(e.target.value),className:s(`flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})})});$n.displayName=`CommandInput`;var er=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:s(`max-h-[300px] overflow-y-auto overflow-x-hidden`,e),...t}));er.displayName=`CommandList`;var tr=Q.forwardRef(({className:e,...t},n)=>{let{visibleCount:r}=Xn();return r>0?null:(0,$.jsx)(`div`,{ref:n,className:s(`py-6 text-center text-sm`,e),...t})});tr.displayName=`CommandEmpty`;var nr=Q.forwardRef(({className:e,heading:t,children:n,...r},i)=>(0,$.jsxs)(`div`,{ref:i,className:s(`overflow-hidden p-1 text-foreground [&_[data-command-group-heading]]:px-2 [&_[data-command-group-heading]]:py-1.5 [&_[data-command-group-heading]]:text-xs [&_[data-command-group-heading]]:font-medium [&_[data-command-group-heading]]:text-muted-foreground`,e),...r,children:[t?(0,$.jsx)(`div`,{"data-command-group-heading":``,children:t}):null,n]}));nr.displayName=`CommandGroup`;var rr=Q.forwardRef(({className:e,value:t,keywords:n,onSelect:r,disabled:i,onClick:a,...o},c)=>{let{search:l,activeValue:u,setActiveValue:d,registerVisible:f}=Xn(),p=Array.isArray(n)?n.join(` `):n,m=Zn(p?`${t} ${p}`:t,l),h=u===t;return Q.useLayoutEffect(()=>{if(m)return f()},[m,f]),Q.useEffect(()=>{m&&u===null&&!i&&d(t)},[m,u,i,d,t]),m?(0,$.jsx)(`div`,{ref:c,role:`option`,"aria-selected":h,"data-selected":h,"data-disabled":i,className:s(`relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50`,e),onMouseEnter:()=>!i&&d(t),onClick:e=>{a?.(e),i||r?.(t)},...o}):null});rr.displayName=`CommandItem`;var ir=`mcp-inspector-models-cache`,ar=1440*60*1e3;function or(){try{let e=localStorage.getItem(ir);if(e)return JSON.parse(e)}catch(e){console.error(`Failed to load models cache:`,e)}return{}}function sr(e,t){try{let n=or();n[e]={models:t,timestamp:Date.now()},localStorage.setItem(ir,JSON.stringify(n))}catch(e){console.error(`Failed to save models cache:`,e)}}function cr(e){try{let t=or(),n=t[e];if(n){if(Date.now()-n.timestamp<ar)return n.models;delete t[e],localStorage.setItem(ir,JSON.stringify(t))}}catch(e){console.error(`Failed to get cached models:`,e)}return null}function lr(e,t){return!Vt(e)||!t?.trim()?e:`${e}:${e===`ollama`?jt(t):t.trim().toLowerCase()}`}var ur=`chat-config-source`;function dr(e){return e===`openai`||e===`anthropic`||e===`google`?e:`openrouter`}async function fr(e,t){let n={};t&&(n.Authorization=`Bearer ${t}`);let r;try{r=await fetch(`${e}/models`,{headers:n})}catch{throw Error(`Failed to reach the server. Check the URL is correct and that CORS is enabled on the server.`)}if(!r.ok)throw Error(`Failed to fetch models: ${r.statusText}`);if(!(r.headers.get(`content-type`)??``).includes(`application/json`))throw Error(`Invalid URL — response was not JSON`);let i=await r.json();if(!Array.isArray(i?.data))throw Error(`Unexpected response format — expected { data: [...] } from the OpenAI-compatible endpoint`);return i.data.map(e=>({id:e.id}))}async function pr(e){let t=await fetch(`https://api.openai.com/v1/models`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`Failed to fetch OpenAI models: ${t.statusText}`);return(await t.json()).data.map(e=>({id:e.id}))}async function mr(e){let t=await fetch(`https://api.anthropic.com/v1/models`,{headers:{"x-api-key":e,"anthropic-version":`2023-06-01`,"anthropic-dangerous-direct-browser-access":`true`}});if(!t.ok)throw Error(`Failed to fetch Anthropic models: ${t.statusText}`);return(await t.json()).data.map(e=>({id:e.id,displayName:e.display_name}))}async function hr(e){let t=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${e}`);if(!t.ok)throw Error(`Failed to fetch Google models: ${t.statusText}`);return((await t.json()).models||[]).map(e=>({id:e.name,displayName:e.displayName}))}async function gr(e){let t=await fetch(`https://openrouter.ai/api/v1/models`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`Failed to fetch OpenRouter models: ${t.statusText}`);return(await t.json()).data.map(e=>({id:e.id,displayName:e.name}))}async function _r(e,t){let n;try{n=await fetch(Dt(e,`/api/tags`),{headers:{...t.trim()?{Authorization:`Bearer ${t.trim()}`}:{}}})}catch(e){throw new At(e)}if(!n.ok)throw Error(`Failed to fetch Ollama models: ${n.statusText}`);return((await n.json()).models||[]).map(e=>({id:e.model||e.name||``}))}function vr({open:e,onOpenChange:t,tempProvider:n,tempModel:r,tempApiKey:i,tempBaseUrl:a,onProviderChange:o,onModelChange:c,onApiKeyChange:l,onBaseUrlChange:u,onSave:d,onClear:f,showClearButton:p=!1,buttonLabel:m=`Configure API Key`,hostedInspector:h=!1,freeTierInfo:g,managedCloudInfo:_,useManagedCloud:v=!1,onSaveManagedCloud:y}){let[b,x]=(0,Q.useState)([]),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(+!v),P=lr(n,a),te=!!(h||g||_),I=!!(_&&M===0);(0,Q.useEffect)(()=>{e&&N(+!v)},[e,v]),(0,Q.useEffect)(()=>{let t=zt(n),r=Vt(n);if(I||!e||!n||t&&!i.trim()||r&&!a.trim()){x([]),T(null);return}let o=setTimeout(async()=>{let e=cr(P);if(e){x(e),T(null);return}C(!0),T(null);try{let e=[];n===`openai-compatible`?e=await fr(a,i):n===`openai`?e=await pr(i):n===`anthropic`?e=await mr(i):n===`google`?e=await hr(i):n===`openrouter`?e=await gr(i):n===`ollama`&&(e=await _r(a,i)),sr(P,e),x(e)}catch(e){T(e instanceof Error?e.message:`Failed to fetch models. Please check your API key.`),x([])}finally{C(!1)}},500);return()=>clearTimeout(o)},[i,a,n,e,P,I]);let L=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!e||I){e||(L.current=null);return}let t=L.current;t!==null&&t!==n&&c(``),L.current=n},[n,e,c,I]);let R=Vt(n),z=!zt(n),V=e&&(!zt(n)||!!i.trim())&&(!R||!!a.trim()),ne=z?`API Key (optional)`:`API Key`,re=z?n===`ollama`?`Leave empty for local Ollama`:`Enter your API key (optional)`:`Enter your API key`,W=n===`openai-compatible`?`http://localhost:11434/v1`:Gt(n),G=n===`openai-compatible`?`Base URL of your OpenAI-compatible API. Local servers must have CORS enabled.`:null,oe=n===`ollama`?`Optional for local Ollama. Stored locally and never sent to our servers.`:`Your API key is stored locally and never sent to our servers.`,q=_?_.models.reduce((e,t)=>(e[t.provider]||(e[t.provider]=[]),e[t.provider].push(t),e),{}):{},J=_?.models.find(e=>e.id===_.selectedModelId),se=Object.keys(q),ce=J?.provider??se[0]??``,le=ce?q[ce]??[]:[],ue=!!f&&p&&(!_||M===1),Y=()=>{if(I&&y){y();return}d()},de=I?!!(_?.isLoading||!_?.selectedModelId||_?.models.length===0):zt(n)&&!i.trim()||R&&!a.trim()||!r.trim();return(0,$.jsx)(Ne,{open:e,onOpenChange:t,children:(0,$.jsxs)(_e,{className:`max-w-md`,"data-testid":`chat-config-dialog`,children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(we,{children:te?`Configure Chat`:`LLM Provider Configuration`}),(0,$.jsx)(Re,{children:_?`Pick a Manufact cloud model or bring your own API key.`:g?`Chat requires an LLM. You can chat for free if you have a Manufact account, or you can use your own API key (not sent to Manufact).`:`Configure your LLM provider and API key to start chatting with the MCP server`})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[g&&(0,$.jsxs)(`button`,{type:`button`,onClick:g.onLoginClick,"data-testid":`chat-config-sign-in-card`,className:`relative w-full cursor-pointer overflow-hidden rounded-2xl text-left transition-opacity hover:opacity-95 active:opacity-90`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-[#edf2ff]`,"aria-hidden":!0}),(0,$.jsx)(wt,{className:`absolute inset-0 h-full w-full`,grainOverlay:.15}),(0,$.jsxs)(`div`,{className:`relative flex items-center justify-between gap-4 px-4 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`text-sm font-medium text-black`,children:[(0,$.jsx)(`p`,{children:`Chat for free with a`}),(0,$.jsxs)(`p`,{className:`mt-1 flex items-center gap-1.5`,children:[(0,$.jsx)(ut,{symbolSize:14,textClassName:`text-sm`}),`account`]})]}),(0,$.jsx)(F,{size:`sm`,render:(0,$.jsx)(`span`,{"aria-hidden":`true`}),nativeButton:!1,tabIndex:-1,className:`pointer-events-none shrink-0`,children:`Sign in`})]})]}),_&&(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsxs)(Lt,{selectedIndex:M,onSelect:N,idPrefix:ur,className:`w-fit`,children:[(0,$.jsx)(It,{index:0,label:`Manufact cloud`}),(0,$.jsx)(It,{index:1,label:`API key`})]})}),(0,$.jsxs)(`div`,{className:s(`space-y-2`,_&&`!mt-2`),children:[(0,$.jsx)(B,{children:`Provider`}),I?(0,$.jsxs)(K,{value:ce,onValueChange:e=>{let t=_?.models.find(t=>t.provider===e);t&&_?.onModelChange(t.id)},children:[(0,$.jsx)(U,{className:`rounded-md`,leading:ce?(0,$.jsx)(He,{provider:dr(ce),className:`shrink-0`}):void 0,children:(0,$.jsx)(H,{})}),(0,$.jsx)(ie,{children:se.map(e=>(0,$.jsx)(ae,{value:e,label:ft(dr(e)),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:dr(e)}),(0,$.jsx)(`span`,{children:ft(dr(e))})]})},e))})]}):(0,$.jsxs)(K,{value:n,onValueChange:e=>o(e),children:[(0,$.jsx)(U,{className:`rounded-md`,leading:(0,$.jsx)(He,{provider:n,className:`shrink-0`}),children:(0,$.jsx)(H,{})}),(0,$.jsxs)(ie,{children:[(0,$.jsx)(ae,{value:`openai`,label:ft(`openai`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`openai`}),(0,$.jsx)(`span`,{children:ft(`openai`)})]})}),(0,$.jsx)(ae,{value:`anthropic`,label:ft(`anthropic`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`anthropic`}),(0,$.jsx)(`span`,{children:ft(`anthropic`)})]})}),(0,$.jsx)(ae,{value:`google`,label:ft(`google`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`google`}),(0,$.jsx)(`span`,{children:ft(`google`)})]})}),(0,$.jsx)(ae,{value:`ollama`,label:ft(`ollama`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`ollama`}),(0,$.jsx)(`span`,{children:ft(`ollama`)})]})}),(0,$.jsx)(ae,{value:`openrouter`,label:ft(`openrouter`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`openrouter`}),(0,$.jsx)(`span`,{children:ft(`openrouter`)})]})}),(0,$.jsx)(ae,{value:`openai-compatible`,label:ft(`openai-compatible`),children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:ft(`openai-compatible`)})})})]})]})]}),!I&&R&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:`Base URL`}),(0,$.jsx)(ee,{value:a,onChange:e=>u(e.target.value),placeholder:W,"data-testid":`chat-config-base-url-input`}),G&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G})]}),!I&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:ne}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(ee,{type:A?`text`:`password`,value:i,onChange:e=>l(e.target.value),placeholder:re,className:`pr-10`,"data-testid":`chat-config-api-key-input`}),(0,$.jsx)(F,{type:`button`,variant:`ghost`,size:`sm`,className:`absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent`,onClick:()=>j(!A),children:A?(0,$.jsx)(Ze,{className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(Ye,{className:`h-4 w-4 text-muted-foreground`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:oe})]}),I?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:`Model`}),_?.isLoading?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models…`})]}):le.length>0?(0,$.jsxs)(Se,{open:O,modal:!0,onOpenChange:k,children:[(0,$.jsx)(Ae,{render:(0,$.jsxs)(F,{variant:`outline`,role:`combobox`,"aria-expanded":O,className:`w-full justify-between rounded-md`,"data-testid":`chat-config-cloud-model-select`,children:[(0,$.jsx)(`span`,{className:`inline-flex min-w-0 items-center gap-2 truncate`,children:J?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(He,{provider:dr(J.provider),className:`shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:at(J.name,J.provider)})]}):`Select a model…`}),(0,$.jsx)(en,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(be,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(Qn,{children:[(0,$.jsx)($n,{placeholder:`Search models…`,className:`h-9`}),(0,$.jsxs)(er,{children:[(0,$.jsx)(tr,{children:`No model found.`}),(0,$.jsx)(nr,{children:le.map(e=>(0,$.jsxs)(rr,{value:e.id,keywords:[e.name,e.id,e.provider],onSelect:e=>{_?.onModelChange(e),k(!1)},children:[at(e.name,e.provider),(0,$.jsx)(gt,{className:s(`ml-auto h-4 w-4`,_?.selectedModelId===e.id?`opacity-100`:`opacity-0`)})]},e.id))})]})]})})]}):(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cloud models unavailable — try again or use your own key.`})]}):V&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:`Model`}),S?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models...`})]}):w?(0,$.jsx)(`div`,{className:`text-sm text-destructive`,children:w}):b.length>0?(0,$.jsxs)(Se,{open:E,modal:!0,onOpenChange:D,children:[(0,$.jsx)(Ae,{render:(0,$.jsxs)(F,{variant:`outline`,role:`combobox`,"aria-expanded":E,className:`w-full justify-between rounded-md`,"data-testid":`chat-config-model-select`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:r&&(b.find(e=>e.id===r)?.displayName||b.find(e=>e.id===r)?.id)||`Select a model...`}),(0,$.jsx)(en,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(be,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(Qn,{children:[(0,$.jsx)($n,{placeholder:`Search models...`,className:`h-9`}),(0,$.jsxs)(er,{children:[(0,$.jsx)(tr,{children:`No model found.`}),(0,$.jsx)(nr,{children:b.map(e=>(0,$.jsxs)(rr,{value:e.id,keywords:e.displayName,onSelect:e=>{c(e===r?``:e),D(!1)},children:[e.displayName||e.id,(0,$.jsx)(gt,{className:s(`ml-auto h-4 w-4`,r===e.id?`opacity-100`:`opacity-0`)})]},e.id))})]})]})})]}):(0,$.jsx)(ee,{value:r,onChange:e=>c(e.target.value),placeholder:`Enter model name manually`,"data-testid":`chat-config-model-input`})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[ue&&(0,$.jsx)(F,{variant:`outline`,onClick:f,children:`Clear Config`}),(0,$.jsxs)(F,{onClick:Y,disabled:de,className:ue?`ml-auto`:``,"data-testid":`chat-config-save-button`,children:[(0,$.jsx)(Ue,{className:`h-4 w-4 mr-2`}),`Save Configuration`]})]})]})]})})}var yr=`rounded-full bg-background/80 backdrop-blur-md supports-[backdrop-filter]:bg-background/60 dark:bg-zinc-950/75 dark:supports-[backdrop-filter]:bg-zinc-950/55`,br=s(yr,`w-fit`),xr=s(yr,`h-9 gap-1.5 px-3`),Sr=`chat-view`;function Cr({llmConfig:e,hasMessages:t,configDialogOpen:n,onConfigDialogOpenChange:r,onClearChat:i,tempProvider:a,tempModel:o,tempApiKey:c,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSaveConfig:m,onClearConfig:g,hideConfigButton:_,hostedInspector:v,freeTierInfo:y,managedCloudInfo:b,useManagedCloud:x,onSaveManagedCloud:S,showClearButton:C,clearButtonLabel:w,hideTitle:T,clearButtonHideIcon:E,clearButtonHideShortcut:D,clearButtonVariant:k,hideClearButton:A,onCopyChat:j,onExportChat:M,activeChatId:P,chatTitle:ee,showViewToggle:I,viewIndex:L=0,onViewIndexChange:R,elevatedHeader:z}){return(0,$.jsxs)(`div`,{className:s(`relative flex w-full items-center gap-2 overflow-visible`,te,z?`pointer-events-none absolute top-0 right-0 z-50`:`absolute top-0 right-0 z-10`),children:[(0,$.jsx)(`div`,{className:s(`flex min-w-0 flex-1 items-center`,z&&`pointer-events-auto`),children:!T&&(0,$.jsx)(`h2`,{className:s(`text-[15px] text-foreground [font-variation-settings:'wght'_550,'opsz'_20]`,br),children:P?(0,$.jsx)(wn,{chatId:P,title:ee??`Chat`},P):`Chat`})}),I&&R&&(0,$.jsx)(`div`,{className:s(`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 overflow-visible px-1`,z&&`pointer-events-auto`),children:(0,$.jsxs)(Lt,{selectedIndex:L,onSelect:R,idPrefix:Sr,className:`shrink-0 overflow-visible`,"data-testid":`chat-view-tabs`,children:[(0,$.jsx)(It,{label:`Conv`,index:0}),(0,$.jsx)(It,{label:`Raw`,index:1})]})}),(0,$.jsxs)(`div`,{className:s(`ml-auto flex shrink-0 items-center gap-2`,z&&`pointer-events-auto`),children:[!A&&t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[j&&(0,$.jsxs)(F,{"data-testid":`chat-copy-button`,variant:`ghost`,size:`sm`,className:xr,onClick:j,children:[(0,$.jsx)(et,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Copy`})]}),M&&(0,$.jsxs)(ze,{children:[(0,$.jsx)(Be,{render:(0,$.jsxs)(F,{"data-testid":`chat-export-button`,variant:`ghost`,size:`sm`,className:xr,children:[(0,$.jsx)(rt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Export`})]}),nativeButton:!0}),(0,$.jsxs)(Ee,{align:`end`,children:[(0,$.jsx)(Le,{"data-testid":`chat-export-json`,onClick:()=>M(`json`),children:`Export as JSON`}),(0,$.jsx)(Le,{"data-testid":`chat-export-markdown`,onClick:()=>M(`markdown`),children:`Export as Markdown`})]})]}),(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsxs)(F,{variant:k??`default`,size:`default`,className:`p-2 cursor-pointer ${D?`sm:px-3`:`sm:pr-1 sm:pl-3`}`,onClick:i,children:[!E&&(0,$.jsx)(an,{className:`h-4 w-4 sm:mr-2`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:w??`New Chat`}),!D&&(0,$.jsx)(`span`,{className:`hidden sm:inline text-[12px] border text-zinc-300 p-1 rounded-full border-zinc-300 dark:text-zinc-600 dark:border-zinc-500 ml-2`,children:`⌘O`})]}),nativeButton:!0}),(0,$.jsx)(N,{children:(0,$.jsx)(`p`,{children:w??`New Chat`})})]})]}),(!_||v||y||b)&&(0,$.jsx)(vr,{open:n,onOpenChange:r,tempProvider:a,tempModel:o,tempApiKey:c,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSave:m,onClear:g,showClearButton:C??(!!e&&!y&&!b),buttonLabel:e?`Change API Key`:`Configure API Key`,hostedInspector:v,freeTierInfo:y,managedCloudInfo:b,useManagedCloud:x,onSaveManagedCloud:S})]})]})}function wr({tools:e,disabledTools:t,onDisabledToolsChange:n,disabled:r}){let[i,a]=(0,Q.useState)(!1),o=e.length-t.size,c=t.size===0,l=t.size>0&&t.size<e.length,u=(0,Q.useCallback)(e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},[t,n]),d=(0,Q.useCallback)(()=>{n(c?new Set(e.map(e=>e.name)):new Set)},[c,e,n]),f=(0,Q.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return e.length===0?null:(0,$.jsxs)(Se,{open:i,onOpenChange:a,children:[(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsx)(Ae,{render:(0,$.jsxs)(F,{variant:`ghost`,size:`sm`,disabled:r,className:s(`h-auto gap-1 rounded-full px-2 py-2`,l?`text-amber-500 dark:text-amber-400`:`text-muted-foreground hover:text-foreground`),type:`button`,"data-testid":`chat-tool-selector`,children:[(0,$.jsx)(lt,{className:`h-4 w-4 shrink-0`}),l&&(0,$.jsx)(`span`,{className:`flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-amber-500 px-1 text-[9px] font-bold leading-none text-white`,children:o})]}),nativeButton:!0}),nativeButton:!0}),(0,$.jsx)(N,{side:`top`,children:(0,$.jsxs)(`p`,{children:[`Tools (`,o,`/`,e.length,`)`]})})]}),(0,$.jsxs)(be,{className:`w-72 gap-0 p-0`,align:`start`,side:`top`,sideOffset:8,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,$.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[`Allowed Tools (`,o,`/`,e.length,`)`]}),(0,$.jsx)(F,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:d,type:`button`,children:c?`Disable All`:`Enable All`})]}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-y-auto`,children:f.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2.5 w-full px-3 py-1.5 text-left hover:bg-accent/50 transition-colors cursor-pointer`,onClick:()=>u(e.name),children:[(0,$.jsx)(Jt,{checked:!t.has(e.name),className:`pointer-events-none`,tabIndex:-1}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-mono`,children:e.name})]},e.name))})]})]})}function Tr({inputValue:e,isConnected:t,isLoading:n,textareaRef:r,attachments:i,placeholder:a=`Ask a question`,className:c,showAttachButton:l=!0,tools:u,disabledTools:d,onDisabledToolsChange:f,onInputChange:p,onKeyDown:m,onKeyUp:h,onClick:g,onAttachmentAdd:_,onAttachmentRemove:v,inlineControls:y,trailingControls:b}){let x=o(),S=(0,Q.useRef)(null),C=e=>{let t=e.target.files;if(t&&t.length>0)for(let e=0;e<t.length;e++)_(t[e]);S.current&&(S.current.value=``)},w=i.length>0;return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[w&&(0,$.jsx)(`div`,{className:`absolute top-0 left-0 right-0 z-20 p-3 flex gap-2 flex-wrap`,children:i.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group bg-zinc-100/90 dark:bg-zinc-900/90 backdrop-blur-sm rounded-lg p-2 flex items-center gap-2 border border-zinc-200 dark:border-zinc-700`,"data-testid":`chat-attachment-${t}`,children:[(0,$.jsx)(pt,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,$.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium truncate max-w-[150px]`,children:e.name||`Image`}),e.size&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ye(e.size)})]}),(0,$.jsx)(`button`,{onClick:()=>v(t),className:`shrink-0 p-1 rounded-full hover:bg-zinc-200 dark:hover:bg-zinc-800 transition-colors`,title:`Remove attachment`,type:`button`,"data-testid":`chat-attachment-remove-${t}`,children:(0,$.jsx)(Oe,{className:`h-3 w-3`})})]},t))}),(0,$.jsx)(qt,{ref:r,value:e,onChange:e=>p(e.target.value),onKeyDown:m,onKeyUp:h,onClick:g,placeholder:t?a:`Server not connected`,className:s(`p-4 min-h-[150px] max-h-[300px]`,x.container,w&&`pt-20`,c),disabled:!t||n,"data-testid":`chat-input`}),(0,$.jsx)(`input`,{ref:S,type:`file`,accept:`image/*`,multiple:!0,onChange:C,className:`hidden`,"aria-label":`Upload images`}),(0,$.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 flex items-center justify-between gap-2 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1`,children:[l&&(0,$.jsx)(F,{variant:`ghost`,size:`sm`,onClick:()=>S.current?.click(),disabled:!t||n,className:`h-auto w-auto aspect-square rounded-full p-2 text-muted-foreground hover:text-foreground`,title:`Attach images`,type:`button`,"data-testid":`chat-attach-button`,children:(0,$.jsx)(nn,{className:`h-4 w-4`})}),u&&u.length>0&&d&&f&&(0,$.jsx)(wr,{tools:u,disabledTools:d,onDisabledToolsChange:f,disabled:!t||n}),y]}),b?(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:b}):null]})]})}function Er({promptResults:e,onDeletePromptResult:t}){return(0,$.jsx)(`div`,{className:`absolute top-4 left-4 right-4 flex gap-2 overflow-x-auto z-20 flex-nowrap`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:e.map(({promptName:e},n)=>(0,$.jsxs)(F,{type:`button`,className:`flex items-center gap-2 bg-zinc-200 text-zinc-700 dark:text-zinc-300 text-[10px] px-1.5 py-0.5 dark:bg-zinc-700 rounded-lg border border-zinc-200 dark:border-zinc-300 font-medium hover:bg-zinc-300 dark:hover:bg-zinc-600`,children:[(0,$.jsx)(dt,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,title:e,children:e}),(0,$.jsx)(`span`,{className:`ml-1 h-4 w-4 rounded-full bg-zinc-400 dark:bg-zinc-600 hover:bg-zinc-500 dark:hover:bg-zinc-500 flex items-center justify-center cursor-pointer shrink-0 transition-colors`,onClick:e=>{e.stopPropagation(),t(n)},title:`Remove prompt`,role:`button`,tabIndex:0,children:(0,$.jsx)(Oe,{className:`h-2.5 w-2.5 text-white`})})]},n))})}function Dr({isOpen:e,focusedIndex:t,prompts:n,selectedPrompt:r,onPromptSelect:i}){return e?((0,Q.useEffect)(()=>{if(t>=0){let e=document.getElementById(`prompt-${t}`);e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})}},[t]),(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 right-0 max-w-3xl w-full max-h-[300px] overflow-y-auto rounded-lg border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 shadow-lg z-30 flex flex-col gap-2 mb-1`,"data-testid":`chat-prompts-dropdown`,children:(0,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-zinc-900 dark:text-zinc-100 mb-2`,children:`Prompts`}),n.map((e,n)=>(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsxs)(F,{id:`prompt-${n}`,type:`button`,variant:`ghost`,className:s(`w-full flex items-center px-3 py-2 rounded-md hover:bg-zinc-200 dark:hover:bg-zinc-700 transition-colors text-left justify-start`,t===n&&`bg-zinc-200 dark:bg-zinc-700`),onClick:()=>i(e),"data-testid":`chat-prompt-option-${n}`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-center shrink-0`,children:(0,$.jsx)(dt,{className:`h-4 w-4 text-zinc-600 dark:text-zinc-400`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsxs)(`div`,{className:`text-sm font-medium text-zinc-900 dark:text-zinc-100 flex items-center gap-2`,children:[e.name,r?.name===e.name&&(0,$.jsx)(Ce,{className:`size-3 text-zinc-600 dark:text-zinc-400`})]})})]}),nativeButton:!0}),(0,$.jsx)(N,{children:e.description})]},n))]})})):null}var Or=Q.createContext(void 0);function kr(e=!1){let t=Q.useContext(Or);if(!t&&!e)throw Error(_(86));return t}var Ar=Q.createContext(void 0);function jr(){return Q.useContext(Ar)}var Mr=[V],Nr=Q.forwardRef(function(e,t){let{render:r,className:i,disabled:a,readOnly:o,required:s,onValueChange:c,value:u,defaultValue:d,form:f,name:p,inputRef:m,id:h,style:g,..._}=e,{setTouched:v,setFocused:y,validationMode:b,name:x,disabled:S,state:C,validation:w,setDirty:T,setFilled:D,validityData:O}=ue(),{labelId:k}=Y(),{clearErrors:A}=fe(),j=kr(!0),M=S||a,N=x??p,P=l(h),[F,ee]=z({controlled:u,default:d,name:`RadioGroup`,state:`value`}),[te,I]=Q.useState(!1),L=n((e,t)=>{c?.(e,t),!t.isCanceled&&ee(e)}),R=Q.useRef(null),B=Q.useRef(null),V=Q.useRef(null);function ne(e){let t;return m&&(typeof m==`function`?t=m(e):m.current=e),B.current=e,w.inputRef.current=e,t}let H=n((e,t=!1)=>{if(e){if(t){R.current===e&&(R.current=null);return}R.current??=e}}),re=n(e=>{if(!e||e.disabled)return;V.current||=e;let t=B.current;if(e.checked||t==null||t.disabled)return ne(e)}),U=n(()=>{let e=B.current;return!e||e.disabled||!e.checked?null:F??null});se(R,P,F??null,U,!M,p),ce(F,()=>{A(N),T(F!==O.initialValue),D(F!=null),w.change(F);let e=V.current;F==null&&e&&!e.disabled&&ne(e)});let ie=_[`aria-labelledby`]??k??j?.legendId,W={...C,disabled:M??!1,required:s??!1,readOnly:o??!1},G=Q.useMemo(()=>({...C,checkedValue:F,disabled:M,form:f,validation:w,name:N,readOnly:o,registerControlRef:H,registerInputRef:re,required:s,setCheckedValue:L,setTouched:I,touched:te}),[F,M,f,w,C,N,o,H,re,s,L,I,te]),ae={id:h,role:`radiogroup`,"aria-required":s||void 0,"aria-disabled":M||void 0,"aria-readonly":o||void 0,"aria-labelledby":ie,onFocus(){y(!0)},onBlur(e){E(e.currentTarget,e.relatedTarget)||(v(!0),y(!1),b===`onBlur`&&w.commit(F))},onKeyDownCapture(e){e.key.startsWith(`Arrow`)&&(I(!0),y(!0))}};return(0,$.jsx)(Ar.Provider,{value:G,children:(0,$.jsx)(Ft,{render:r,className:i,style:g,state:W,props:[ae,_,e=>w.getValidationProps(M??!1,e)],refs:[t],stateAttributesMapping:J,enableHomeAndEndKeys:!1,modifierKeys:Mr})})}),Pr=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),Fr={checked(e){return e?{[Pr.checked]:``}:{[Pr.unchecked]:``}},...A,...J},Ir=Q.createContext(void 0),Lr=Q.forwardRef(function(e,t){let{render:i,className:a,disabled:o=!1,readOnly:s=!1,required:u=!1,"aria-labelledby":f,value:h,inputRef:_,nativeButton:v=!1,id:y,style:x,...S}=e,T=jr(),{disabled:E,readOnly:O,required:k,form:A,checkedValue:j,touched:N=!1,validation:P,name:F}=T??{},ee=T?.setCheckedValue??D,te=T?.setTouched??D,I=T?.registerControlRef??D,L=T?.registerInputRef??D,{setTouched:R,setFilled:z,state:B,disabled:V}=ue(),ne=St(),{labelId:H,getDescriptionProps:U}=Y(),ie=V||ne.disabled||E||o,W=O||s,G=k||u,ae=A,K=T?j===h:h===``,q=Q.useRef(null),J=Q.useRef(null),se=n(e=>{e&&I(e,ie)}),ce=C(_,J,L);d(()=>{J.current?.checked&&z(!0)},[z]),d(()=>{if(J.current){if(ie&&K){L(null);return}q.current&&I(q.current,ie),L(J.current)}},[K,ie,I,L]);let le=l(),de=re({id:y,implicit:!1,controlRef:q}),fe=v?void 0:de,pe=Fe(f,H,J,!v,fe),me={role:`radio`,"aria-checked":K,"aria-required":G||void 0,"aria-readonly":W||void 0,"aria-labelledby":pe,[Pt]:K?``:void 0,id:v?de:le,onKeyDown(e){e.key===`Enter`&&e.preventDefault()},onClick(e){if(e.defaultPrevented||ie||W)return;e.preventDefault();let t=J.current;t&&t.dispatchEvent(new(r(t)).PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}))},onFocus(e){e.defaultPrevented||ie||W||!N||(J.current?.click(),te(!1))}},{getButtonProps:he,buttonRef:ge}=m({disabled:ie,native:v,composite:!1}),_e={type:`radio`,ref:ce,form:ae,id:fe,name:F,tabIndex:-1,style:F?g:w,"aria-hidden":!0,...h===void 0?M:{value:oe(h)},disabled:ie,checked:K,required:G,readOnly:W,onChange(e){if(e.nativeEvent.defaultPrevented||ie||W||h===void 0)return;let t=c(p,e.nativeEvent);ee(h,t),!t.isCanceled&&R(!0)},onFocus(){q.current?.focus()}},ve=Q.useMemo(()=>({...B,required:G,disabled:ie,readOnly:W,checked:K}),[B,ie,W,K,G]),ye=ve,be=T!==void 0,xe=[t,q,ge,se],Se=[me,S,he,U,P?e=>P.getValidationProps(ie,e):M],Ce=b(`span`,e,{enabled:!be,state:ve,ref:xe,props:Se,stateAttributesMapping:Fr});return(0,$.jsxs)(Ir.Provider,{value:ye,children:[be?(0,$.jsx)(bt,{tag:`span`,render:i,className:a,style:x,state:ve,refs:xe,props:Se,stateAttributesMapping:Fr}):Ce,(0,$.jsx)(`input`,{..._e,suppressHydrationWarning:!0})]})}),Rr=[];function zr(e){let{allValues:t=Rr,value:r=Rr,onValueChange:i}=e,a=Q.useRef(r),o=Q.useRef(new Map),[s,c]=Q.useState(`mixed`),u=l(),d=r.length===t.length,f=r.length!==t.length&&r.length>0,p=n(i),m=Q.useCallback(()=>({id:u,indeterminate:f,checked:d,"aria-controls":t.map(e=>`${u}-${e}`).join(` `),onCheckedChange(e,n){let i=a.current,l=t.filter(e=>o.current.get(e)&&i.includes(e)),u=t.filter(e=>!o.current.get(e)||o.current.get(e)&&i.includes(e));if(i.length===u.length||i.length===0){r.length===u.length?p(l,n):p(u,n);return}let d=`mixed`,f=i;s===`mixed`?(d=`on`,f=u):s===`on`&&(d=`off`,f=l),p(f,n),n.isCanceled||c(d)}}),[t,d,u,f,p,s,r.length]),h=Q.useCallback(e=>({checked:r.includes(e),onCheckedChange(t,n){let i=r.slice();t?i.push(e):i.splice(i.indexOf(e),1),p(i,n),n.isCanceled||(a.current=i,c(`mixed`))}}),[p,r]);return Q.useMemo(()=>({id:u,indeterminate:f,getParentProps:m,getChildProps:h,disabledStatesRef:o}),[u,f,m,h])}var Br=Q.forwardRef(function(e,t){let{allValues:r,className:i,defaultValue:a,disabled:o=!1,id:s,onValueChange:c,render:u,value:d,style:f,...p}=e,{disabled:m,name:h,state:g,validation:_,setFilled:v,setDirty:y,validityData:x}=ue(),{labelId:C,getDescriptionProps:w}=Y(),{clearErrors:T}=fe(),E=m||o,D=Q.useMemo(()=>{if(d===void 0)return a??[]},[d,a]),[O,k]=z({controlled:d,default:D,name:`CheckboxGroup`,state:`value`}),A=n((e,t)=>{c?.(e,t),!t.isCanceled&&k(e)}),j=zr({allValues:r,value:O,onValueChange:A}),M=l(s),N=Q.useRef(null),P=Q.useCallback(e=>{N.current==null&&e!=null&&!e.hasAttribute(`data-parent`)&&(N.current=e)},[]);se(N,M,O,void 0,!!h&&!E,h);let F=O??S;ce(F,()=>{h&&T(h);let e=Array.isArray(x.initialValue)?x.initialValue:S;v(F.length>0),y(!W(F,e)),_.change(F)});let ee={...g,disabled:E},te=Q.useMemo(()=>({allValues:r,value:O,defaultValue:D,setValue:A,parent:j,disabled:E,validation:_,registerControlRef:P}),[r,O,D,A,j,E,_,P]),I=b(`div`,e,{state:ee,ref:t,props:[{id:s,role:`group`,"aria-labelledby":C},p,w],stateAttributesMapping:J});return(0,$.jsx)(ht.Provider,{value:te,children:I})}),Vr=function(e){let t=l(),r=e.controlId===void 0?t:e.controlId,[i,a]=Q.useState(r),[o,s]=Q.useState(e.labelId),[c,u]=Q.useState([]),d=I(()=>new Map),{messageIds:f}=Y(),p=n((e,t)=>{let n=d.current;if(t===void 0){n.delete(e);return}n.set(e,t),a(e=>{if(n.size===0)return;let t;for(let r of n.values()){if(e!==void 0&&r===e)return e;t===void 0&&(t=r)}return t})}),m=Q.useCallback(e=>{let t=e[`aria-describedby`]?e[`aria-describedby`].split(` `):[];return t.push(...f,...c),{...e,"aria-describedby":Array.from(new Set(t)).join(` `)||void 0}},[f,c]),h=Q.useMemo(()=>({controlId:i,registerControlId:p,labelId:o,setLabelId:s,messageIds:c,setMessageIds:u,getDescriptionProps:m}),[i,p,o,s,c,u,m]);return(0,$.jsx)(le.Provider,{value:h,children:e.children})};function Hr(e,t){return{...e,state:{...e.state,valid:!t&&e.state.valid}}}var Ur=Object.keys(de);function Wr(e){if(!e||e.valid||!e.valueMissing)return!1;let t=!1;for(let n of Ur)n!==`valid`&&(n===`valueMissing`?t=e[n]:e[n]&&(t=!1));return t}function Gr(e){let t=null;for(let n of e)if(!n.disabled){if(!n.validity.valid)return n;t??=n}return t}function Kr(e,t){let n=!1;for(let r of t)r.setCustomValidity(``),n||=r===e;n||e.setCustomValidity(``)}function qr(e){let{formRef:t}=fe(),{setValidityData:r,validate:i,validityData:a,validationDebounceTime:o,invalid:s,markedDirtyRef:c,state:l,shouldValidateOnChange:u,getRegisteredFieldId:d}=e,{controlId:p,getDescriptionProps:m}=Y(),h=f(),g=Q.useRef(null),_=I(()=>new Set).current,v=Q.useRef(0),y=Q.useCallback(e=>{if(e)return _.add(e),()=>{_.delete(e)}},[_]),b=n(async(e,n=!1)=>{let o=Gr(_)??g.current;if(!o)return;v.current+=1;let f=v.current;function m(e,n=s){let r=d()??p;if(r==null)return;let i=t.current.fields.get(r);if(!i)return;let a=Hr(e,n);t.current.fields.set(r,{...i,validityData:a})}if(n){if(l.valid!==!1)return;let t=o.validity;if(!t.valueMissing){let t={value:e,state:{...de,valid:!0},error:``,errors:[],initialValue:a.initialValue};Kr(o,_),m(t,!1),r(t);return}let n=Ur.reduce((e,n)=>(e[n]=t[n],e),{});if(!n.valid&&!Wr(n))return}function y(e){let t=Ur.reduce((t,n)=>(t[n]=e.validity[n],t),{}),n=!1;for(let e of Ur)if(e!==`valid`){if(e===`valueMissing`&&t[e])n=!0;else if(t[e])return t}return n&&!c.current&&(t.valid=!0,t.valueMissing=!1),t}h.clear();let b=null,x=[],S=y(o),C,w=u();if(o.validationMessage&&!w)C=o.validationMessage,x=[o.validationMessage];else{let n=i(e,Array.from(t.current.fields.values()).reduce((e,t)=>(t.name&&(e[t.name]=t.getValue()),e),{}));if(typeof n==`object`&&n&&`then`in n){if(b=await n,f!==v.current)return}else b=n;b===null?w&&(Kr(o,_),S.customError=!1,o.validationMessage?(C=o.validationMessage,x=[o.validationMessage]):o.validity.valid&&!S.valid&&(S.valid=!0)):(S.valid=!1,S.customError=!0,Array.isArray(b)?(x=b,o.setCustomValidity(b.join(`
1
+ import{s as e,t}from"./react-CU_d2d5K.js";import{Cr as n,Dr as r,En as i,G as a,Ir as o,Lr as s,Mn as c,Nn as l,Nr as u,Sr as d,Tn as f,Yn as p,_r as m,a as h,an as g,br as _,c as v,d as y,dr as b,f as x,fr as S,gr as C,in as w,kn as T,mn as E,mr as D,n as O,on as k,or as A,pn as j,pr as M,r as N,s as P,sr as F,t as ee,u as te,wr as I,xr as L}from"./input-CLYhA7PK.js";import{t as R}from"./jsx-runtime-Cjj9sGSy.js";import{n as z,t as B}from"./label-Cdim77Jw.js";import{m as V,t as ne}from"./AnimatePresence-C5p0yiY1.js";import{a as H,c as re,i as U,n as ie,o as W,p as G,r as ae,s as oe,t as K}from"./select-CJ57-Bor.js";import{a as q,c as J,i as se,l as ce,n as le,o as ue,r as Y,s as de,t as fe}from"./FormContext-DH2caWKO.js";import{t as pe}from"./createLucideIcon-B3b8EU0b.js";import{t as me}from"./refresh-cw-C9wQl8_d.js";import{A as he,At as ge,B as _e,Bt as ve,C as ye,D as be,Dt as xe,E as Se,F as Ce,G as we,H as Te,Ht as Ee,I as De,Kt as Oe,N as ke,O as Ae,P as je,Pt as Me,R as Ne,S as Pe,T as Fe,U as Ie,Ut as Le,V as Re,Vt as ze,Wt as Be,Zt as Ve,a as He,an as Ue,b as We,bn as Ge,c as Ke,cn as qe,d as Je,dn as Ye,et as X,f as Xe,fn as Ze,g as Qe,gt as $e,hn as et,i as tt,in as nt,l as Z,mn as rt,n as it,o as at,ot,p as st,pn as ct,qt as lt,r as ut,rn as dt,s as ft,sn as pt,u as mt,v as ht,vn as gt,vt as _t,wt as vt,x as yt,xn as bt,xt,y as St,yt as Ct,zt as wt}from"./index-TQ5V7cM9.js";import{a as Tt,c as Et,i as Dt,n as Ot,o as kt,r as At,s as jt}from"./dist-C5JjLJN9.js";import{n as Mt,t as Nt}from"./MarkdownRenderer-BeeBfQhv.js";import{a as Pt,i as Ft,n as It,t as Lt}from"./tabs-subtle-6D79T1xd.js";import{a as Rt,c as zt,i as Bt,l as Vt,n as Ht,o as Ut,r as Wt,s as Gt,t as Kt}from"./useConfig-BAgALiZg.js";import{t as qt}from"./textarea-DLAmNVf_.js";import{t as Jt}from"./checkbox-CzBkaNKa.js";import{n as Yt,t as Xt}from"./schemaHelpers-DLNTQr_6.js";import{t as Zt}from"./useViewHostProps-BYitt_6K.js";var Qt=pe(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),$t=pe(`arrow-left-from-line`,[[`path`,{d:`m9 6-6 6 6 6`,key:`7v63n9`}],[`path`,{d:`M3 12h14`,key:`13k4hi`}],[`path`,{d:`M21 19V5`,key:`b4bplr`}]]),en=pe(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),tn=pe(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),nn=pe(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),rn=pe(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),an=pe(`square-pen`,[[`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`,key:`1m0v6g`}],[`path`,{d:`M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z`,key:`ohrbg2`}]]),Q=e(t(),1),$=R(),on=Q.forwardRef(({className:e,children:t,...n},r)=>(0,$.jsx)(`div`,{ref:r,"data-slot":`scroll-area`,className:s(`relative overflow-hidden`,e),...n,children:(0,$.jsx)(`div`,{"data-slot":`scroll-area-viewport`,className:`h-full w-full overflow-y-auto overflow-x-hidden`,children:t})}));on.displayName=`ScrollArea`;function sn({count:e}){return(0,$.jsx)(`div`,{className:`flex flex-row absolute top-0 right-0 z-10 w-full items-center justify-between gap-2 ${te}`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full`,children:[(0,$.jsx)(`h2`,{className:y,children:`Chat History`}),(0,$.jsx)(u,{className:`bg-zinc-500/20 text-zinc-600 dark:text-zinc-400 border-transparent`,variant:`outline`,children:e})]})})}function cn({className:e,...t}){return(0,$.jsx)(`div`,{"data-slot":`skeleton`,className:s(`animate-pulse rounded-md bg-muted`,e),...t})}var ln=`New Chat`,un=`Chat`;function dn(e){return e===`New Chat`||e===`Chat`}var fn=`Generate a concise title (maximum 60 characters) for this chat based on the user's first message. Name the subject matter, task, or question — not the act of chatting. Never output meta phrases (e.g. do not use: greeting, introduction, initiation, conversation start, chat session). If there is no specific topic yet, reply with exactly: Chat. Return only the title, no quotes or extra text.`,pn=[`greeting`,`initiation`,`conversation start`,`introduction to`,`chat session`,`starting a chat`,`beginning of`];function mn(e){return typeof e.content==`string`?e.content.trim():String(e.content??``).trim()}function hn(e){for(let t of e){if(t.role!==`user`)continue;let e=mn(t);if(e)return e}return null}function gn(e){let t=e.toLowerCase();for(let e of pn)if(t.includes(e))return!0;return!1}function _n(e){let t=e.trim().split(/\r?\n/)[0].trim();if(!t)return!0;if(t.length>48)return!1;let n=t.replace(/\s+/g,` `).toLowerCase();return/^(hi|hello|hey|greetings?)[!.]?$/i.test(n)||/^(good morning|good afternoon|good evening)[!.]?$/i.test(n)||/^(hi|hello|hey)\s+(there|all|team|everyone)[!.]?$/i.test(n)}function vn(e){return e.length>60?`${e.substring(0,57)}...`:e}function yn(e){return e?.model?.trim()?e.provider===`ollama`?!0:!!e.apiKey?.trim():!1}async function bn(e,t,n){let r=t.trim();if(!r||!yn(e))return null;if(_n(r))return vn(r);try{let t=(await Tt({config:Et(e.provider,e.model,{apiKey:e.apiKey,temperature:e.temperature,baseUrl:e.baseUrl,maxTokens:128}),messages:[{role:`system`,content:fn},{role:`user`,content:r}],signal:n})).trim();if(!t)return null;let i=vn(t);return i===`Chat`||gn(i)?vn(r):i}catch{return null}}var xn=28,Sn=3,Cn=.72;function wn({chatId:e,title:t,className:n,onRevealComplete:r}){let[i,a]=(0,Q.useState)(t),[o,c]=(0,Q.useState)(0),[l,u]=(0,Q.useState)(1),d=(0,Q.useRef)(t),f=(0,Q.useRef)(null),p=(0,Q.useRef)(e);return(0,Q.useEffect)(()=>{if(p.current!==e){p.current=e,d.current=t,f.current=null,a(t),c(0),u(1);return}},[e,t]),(0,Q.useEffect)(()=>{let n=`${e}:${t}`;if(f.current===n){a(t),c(0),u(1);return}let i=d.current,o=dn(i)&&!dn(t)&&t!==i;if(d.current=t,!o){a(t),c(0),u(1);return}f.current=n;let s=0,l=t.length;a(``),c(Sn),u(Cn);let p,m=()=>{s+=1;let e=l>0?s/l:1;a(t.slice(0,s)),c(Sn*(1-e)),u(Cn+(1-Cn)*e),s<l?p=setTimeout(m,xn):r?.()};return p=setTimeout(m,xn),()=>{p&&clearTimeout(p)}},[e,t,r]),(0,$.jsx)(`span`,{className:s(`block truncate transition-[filter,opacity] duration-75`,n),style:{filter:o>0?`blur(${o}px)`:void 0,opacity:l},children:i})}function Tn({compact:e,hideAgentName:t}){return(0,$.jsxs)(`div`,{className:s(`flex items-center justify-between py-3 gap-2`,e?`px-4`:`px-3 rounded-lg`),children:[(0,$.jsxs)(`div`,{className:s(`flex-1 min-w-0 flex flex-col gap-1`,t?`gap-1.5`:`gap-1`),children:[(0,$.jsx)(cn,{className:`h-4 w-3/4`}),!t&&(0,$.jsx)(cn,{className:`h-3 w-1/2`})]}),(0,$.jsx)(cn,{className:`h-3 w-14 shrink-0`})]})}function En({chats:e,onDelete:t,onSelect:n,compact:r,hideAgentName:i,isLoading:o,currentChatId:c}){let[l,u]=Q.useState(``),d=e.filter(e=>e.type!==`agent_execution`),f=d.filter(e=>(e.title??``).toLowerCase().includes(l.toLowerCase())),p=e=>{let t=new Date(e),n=new Date;if(t.toDateString()===n.toDateString())return t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});let r=new Date(n);if(r.setDate(r.getDate()-1),t.toDateString()===r.toDateString())return`Yesterday`;let i=n.getTime()-t.getTime(),a=Math.floor(i/(1e3*60*60*24));return a<7?`${a} days ago`:t.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})},m=e=>(0,$.jsxs)(`div`,{className:s(`flex items-center justify-between py-3 hover:bg-muted/50 transition-colors gap-2 cursor-pointer`,r?`px-4`:`px-3 rounded-lg`,c===e.id&&`bg-muted/50`),children:[(0,$.jsxs)(`div`,{className:s(`flex-1 min-w-0 flex overflow-hidden`,i?`flex-col`:`flex-col gap-1`),children:[(0,$.jsx)(`p`,{className:`text-sm font-medium truncate w-full`,children:(0,$.jsx)(wn,{chatId:e.id,title:e.title},`${e.id}:${e.title}`)}),!i&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground truncate w-full`,children:e.agent_name})]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2 shrink-0`,children:(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:p(e.updated_at)})})]});return(0,$.jsxs)(`div`,{className:`flex h-full w-full flex-col`,children:[(0,$.jsx)(`div`,{className:`mb-4 px-3 sm:px-5`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(a,{className:`absolute left-3 top-2.5 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(ee,{placeholder:`Search chats...`,value:l,onChange:e=>u(e.target.value),className:`pl-9 h-8 border-gray-300 dark:border-zinc-600`})]})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:o&&d.length===0?(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(Tn,{compact:r,hideAgentName:i}),(0,$.jsx)(Tn,{compact:r,hideAgentName:i}),(0,$.jsx)(Tn,{compact:r,hideAgentName:i})]}):d.length===0?(0,$.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-4 text-center min-h-[12rem]`,children:(0,$.jsx)(ve,{vertical:!0,noBorder:!0,message:`No chats`,className:`mt-0`})}):f.length===0?null:(0,$.jsx)(`div`,{className:`space-y-1`,children:f.map(e=>n?(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`block w-full text-left group cursor-pointer`,children:m(e)},e.id):(0,$.jsx)(`div`,{className:`block group cursor-pointer`,children:m(e)},e.id))})})]})}var Dn=20;function On({provider:e,enabled:t=!0,agentId:n,refetchKey:r,refetchInterval:i=!1}){let[a,o]=(0,Q.useState)(1),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(0),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useCallback)(async()=>{if(t){f(!0),m(null);try{let t=await e.listChats({...n?{agentId:n}:{},take:Dn*a,skip:0});c(t.items),u(t.total)}catch(e){m(e instanceof Error?e:Error(String(e)))}finally{f(!1)}}},[e,t,n,a]);(0,Q.useEffect)(()=>{t&&o(1)},[t]),(0,Q.useEffect)(()=>{g()},[g]),(0,Q.useEffect)(()=>{r!==void 0&&r!==h.current&&(h.current=r,t&&g())},[r,t,g]),(0,Q.useEffect)(()=>{if(!t||!i)return;let e=setInterval(()=>void g(),i);return()=>clearInterval(e)},[t,i,g]);let _=l>s.length;return{chats:s,total:l,isLoading:d,error:p,hasNextPage:_,loadMore:(0,Q.useCallback)(()=>{_&&!d&&o(e=>e+1)},[_,d]),refetch:(0,Q.useCallback)(()=>{g()},[g]),deleteChat:(0,Q.useCallback)(async t=>{await e.deleteChat(t),await g()},[e,g])}}function kn({provider:e,open:t,onOpenChange:n,currentChatId:r,container:i,agentId:a,agentDisplayNameFallback:o,onSelectChat:c,variant:l=`drawer`,containerClassName:u,refetchKey:d,refetchInterval:f=!1,onCurrentChatDeleted:p,onDeleteSuccess:m,onDeleteError:h}){let g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),{chats:v,isLoading:y,hasNextPage:b,loadMore:x,deleteChat:S}=On({provider:e,enabled:t,agentId:a,refetchKey:d,refetchInterval:o?f||3e3:f});(0,Q.useEffect)(()=>{if(!t||!_.current)return;let e=new IntersectionObserver(e=>{e[0]?.isIntersecting&&x()},{threshold:.5});return e.observe(_.current),()=>{e.disconnect()}},[t,b,y,x]);let C=async e=>{try{await S(e),m?.(),e===r&&p?.()}catch(e){console.error(`Failed to delete chat:`,e),h?.(e)}},w=v.map(e=>({...e,title:e.title||`New Chat`,agent_name:e.agent_name??o??`Unknown Agent`})),T=w.filter(e=>e.type!==`agent_execution`).length,E=(0,$.jsx)(En,{chats:w,onDelete:C,compact:l===`inline`,hideAgentName:!!o,isLoading:y&&v.length===0,currentChatId:r,onSelect:c?e=>{c(e),n(!1)}:void 0}),D=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[(0,$.jsx)(sn,{count:T}),(0,$.jsxs)(on,{ref:g,className:s(`min-h-0 flex-1 w-full pt-14 sm:pt-16 [&_[data-slot=scroll-area-viewport]]:block!`,l===`inline`?`p-0`:`px-3 sm:px-5`),children:[E,b&&(0,$.jsx)(`div`,{ref:_,className:`py-4 flex items-center justify-center`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin`}),`Loading more...`]})})]})]});return l===`inline`?(0,$.jsx)(`div`,{className:s(`flex h-full min-h-0 flex-col`,u),children:D}):(0,$.jsx)(Ke,{open:t,onOpenChange:n,children:(0,$.jsx)(Z,{side:`left`,className:`w-[400px] sm:w-[400px] border-zinc-200 p-0 dark:border-zinc-700`,container:i,children:D})})}function An({onCollapse:e}){return(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsxs)(F,{type:`button`,variant:`ghost`,size:`icon-sm`,tabIndex:-1,"aria-label":`Collapse`,onClick:e,className:`border-border absolute top-1/2 right-0 z-30 size-7 min-h-7 min-w-7 -translate-y-1/2 translate-x-1/2 rounded-full border bg-background`,children:[(0,$.jsx)($t,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Collapse`})]}),nativeButton:!0}),(0,$.jsx)(N,{side:`right`,children:`Collapse`})]})}var jn=`mcp-inspector-chats`,Mn=`New Chat`,Nn=40;function Pn(){try{let e=localStorage.getItem(jn);if(!e)return{sessions:[],messages:{}};let t=JSON.parse(e);return{sessions:Array.isArray(t.sessions)?t.sessions:[],messages:t.messages&&typeof t.messages==`object`?t.messages:{}}}catch{return{sessions:[],messages:{}}}}function Fn(e){localStorage.setItem(jn,JSON.stringify(e))}function In(){return new Date().toISOString()}function Ln(e){let t=e.find(e=>e.role===`user`);if(!t)return;let n=typeof t.content==`string`?t.content.trim():String(t.content??``).trim();if(n)return n.length>Nn?`${n.slice(0,Nn)}…`:n}var Rn=class{saveTimers=new Map;async listChats(e){let{sessions:t}=Pn(),n=t;e.agentId&&(n=t.filter(t=>t.agent_id===e.agentId)),n=[...n].sort((e,t)=>new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime());let r=n.length,i=e.skip??0,a=e.take??r;return{items:n.slice(i,i+a),total:r}}async getMessages(e){let{messages:t}=Pn();return t[e]??[]}async createChat(e){let t=Pn(),n=In(),r={id:crypto.randomUUID(),title:e.title??Mn,agent_id:e.agentId,agent_name:e.agentName??`MCP Server`,created_at:n,updated_at:n};return t.sessions.push(r),t.messages[r.id]=[],Fn(t),r}async updateChat(e,t){let n=Pn(),r=n.sessions.findIndex(t=>t.id===e);if(r===-1)throw Error(`Chat not found: ${e}`);let i=n.sessions[r];return t.title!==void 0&&(i.title=t.title),i.updated_at=In(),n.sessions[r]=i,Fn(n),i}async deleteChat(e){let t=Pn();t.sessions=t.sessions.filter(t=>t.id!==e),delete t.messages[e],Fn(t)}async saveMessages(e,t){let n=this.saveTimers.get(e);n&&clearTimeout(n),await new Promise(n=>{let r=setTimeout(()=>{this.saveTimers.delete(e);let r=Pn();r.messages[e]=t;let i=r.sessions.findIndex(t=>t.id===e);if(i!==-1){let e=r.sessions[i];if(e.updated_at=In(),e.title===Mn){let n=Ln(t);n&&(e.title=n)}r.sessions[i]=e}Fn(r),n()},500);this.saveTimers.set(e,r)})}};function zn({activeChatId:e,storage:t,messages:n,isLoading:r,effectiveClientSide:i,llmConfig:a,activeChatTitle:o,titleGenerationReady:s=!0,onTitleGenerated:c,onHistoryRefetch:l}){let u=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{u.current=null},[e]),(0,Q.useEffect)(()=>{if(!e||!t||r||!s||o&&!dn(o))return;let d=hn(n);if(!d)return;let f=`${e}:${d}`;if(u.current===f)return;u.current=f;let p=!1;return(async()=>{let n=null;if(t.generateTitle?n=await t.generateTitle(e):i&&a&&(n=await bn(a,d),n&&await t.updateChat(e,{title:n})),!p){if(!n||n===`New Chat`){u.current=null;return}l?.(),c?.(e,n)}})().catch(()=>{p||(u.current=null)}),()=>{p=!0}},[e,t,n,r,i,a,o,s,c,l])}var Bn=[`#e0eaff`,`#f9ffbd`,`#dedede`,`#ffffff`],Vn=.54;function Hn({className:e,children:t,shaderPhase:n=`hidden`,onShaderFadeComplete:r,meshAnimationPaused:i=!1,...a}){let o=(0,Q.useRef)(null),[c,l]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=window.requestAnimationFrame(()=>l(!0));return()=>window.cancelAnimationFrame(e)},[]),(0,Q.useEffect)(()=>{n===`fading`&&!c&&r?.()},[n,c,r]);let u=n!==`hidden`,d=n===`visible`&&c,f=e=>{e.propertyName===`opacity`&&n===`fading`&&r?.()};return(0,$.jsxs)(`div`,{ref:o,className:s(`relative flex min-h-0 flex-1 flex-col overflow-hidden bg-white dark:bg-black`,e),...a,children:[u&&(0,$.jsxs)(`div`,{className:s(`pointer-events-none absolute inset-x-0 bottom-0 z-0 transition-opacity duration-500`,d?`opacity-100`:`opacity-0`),style:{height:`${Vn*100}%`},"aria-hidden":!0,onTransitionEnd:f,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-[#edf2ff] dark:bg-[#1e293b]`}),(0,$.jsx)(`div`,{className:s(`absolute inset-0`,c?`opacity-75 dark:opacity-45`:`opacity-0`),children:(0,$.jsx)(wt,{className:`absolute inset-0 h-full w-full`,colors:[...Bn],distortion:.8,swirl:.1,grainMixer:0,grainOverlay:.3,speed:+!i})}),(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-white/0 from-[12%] via-white/60 via-[38%] to-white dark:from-black/0 dark:from-[12%] dark:via-black/60 dark:via-[38%] dark:to-black`})]}),(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col`,children:t})]})}function Un(e){return e?e.apiKey===`server-managed`||e.baseUrl?.includes(`/inspector/llm`)===!0:!1}function Wn(e){if(!(e instanceof Error))return!1;let t=e.message.toLowerCase();return t.includes(`failed to fetch`)||t.includes(`networkerror`)||t.includes(`network request failed`)||t.includes(`load failed`)}function Gn(e,t){if(!t)return e>=502&&e<=504?{kind:`cloud_unavailable`}:null;if(e===402)return{kind:`credits_exhausted`,billingUrl:typeof t.upgradeUrl==`string`?t.upgradeUrl:typeof t.billingUrl==`string`?t.billingUrl:void 0,message:typeof t.message==`string`?t.message:`You've used your included free plan credits.`};if(e===429){if(t.loginRequired&&t.loginUrl)return{kind:`login_required`,loginUrl:String(t.loginUrl)};if(t.creditsExhausted)return{kind:`credits_exhausted`,billingUrl:typeof t.billingUrl==`string`?t.billingUrl:void 0,message:typeof t.message==`string`?t.message:`You've used your included free plan credits.`};if(t.error===`free_org_rate_limited`||typeof t.reason==`string`)return{kind:`credits_exhausted`,message:typeof t.message==`string`?t.message:`You've reached your included chat quota for this workspace.`}}return e>=502&&e<=504?{kind:`cloud_unavailable`}:null}function Kn(e){let t=e.match(/^OpenAI request failed \((\d+) /);if(!t)return null;let n=Number(t[1]),r=e.indexOf(`{`);if(r===-1)return null;try{let t=JSON.parse(e.slice(r));if(t&&typeof t==`object`&&!Array.isArray(t))return{status:n,body:t}}catch{}return null}function qn(e){if(e instanceof Error&&e.name===`LlmRequestError`){let t=e.status??0,n=e.body;return Gn(t,n&&typeof n==`object`&&!Array.isArray(n)?n:void 0)}if(e instanceof Error){let t=Kn(e.message);if(t)return Gn(t.status,t.body)}return Wn(e)?{kind:`cloud_unavailable`}:null}function Jn(e,t){return Gn(e,t)}var Yn=Q.createContext(null);function Xn(){let e=Q.useContext(Yn);if(!e)throw Error(`Command components must be used within <Command>`);return e}function Zn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}var Qn=Q.forwardRef(({className:e,...t},n)=>{let[r,i]=Q.useState(``),[a,o]=Q.useState(null),[c,l]=Q.useState(0),u=Q.useCallback(()=>(l(e=>e+1),()=>l(e=>Math.max(0,e-1))),[]);return(0,$.jsx)(Yn.Provider,{value:{search:r,setSearch:i,activeValue:a,setActiveValue:o,visibleCount:c,registerVisible:u},children:(0,$.jsx)(`div`,{ref:n,className:s(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})})});Qn.displayName=`Command`;var $n=Q.forwardRef(({className:e,...t},n)=>{let{search:r,setSearch:i}=Xn();return(0,$.jsx)(`div`,{className:`flex items-center border-b px-3`,children:(0,$.jsx)(`input`,{ref:n,value:r,onChange:e=>i(e.target.value),className:s(`flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,e),...t})})});$n.displayName=`CommandInput`;var er=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:s(`max-h-[300px] overflow-y-auto overflow-x-hidden`,e),...t}));er.displayName=`CommandList`;var tr=Q.forwardRef(({className:e,...t},n)=>{let{visibleCount:r}=Xn();return r>0?null:(0,$.jsx)(`div`,{ref:n,className:s(`py-6 text-center text-sm`,e),...t})});tr.displayName=`CommandEmpty`;var nr=Q.forwardRef(({className:e,heading:t,children:n,...r},i)=>(0,$.jsxs)(`div`,{ref:i,className:s(`overflow-hidden p-1 text-foreground [&_[data-command-group-heading]]:px-2 [&_[data-command-group-heading]]:py-1.5 [&_[data-command-group-heading]]:text-xs [&_[data-command-group-heading]]:font-medium [&_[data-command-group-heading]]:text-muted-foreground`,e),...r,children:[t?(0,$.jsx)(`div`,{"data-command-group-heading":``,children:t}):null,n]}));nr.displayName=`CommandGroup`;var rr=Q.forwardRef(({className:e,value:t,keywords:n,onSelect:r,disabled:i,onClick:a,...o},c)=>{let{search:l,activeValue:u,setActiveValue:d,registerVisible:f}=Xn(),p=Array.isArray(n)?n.join(` `):n,m=Zn(p?`${t} ${p}`:t,l),h=u===t;return Q.useLayoutEffect(()=>{if(m)return f()},[m,f]),Q.useEffect(()=>{m&&u===null&&!i&&d(t)},[m,u,i,d,t]),m?(0,$.jsx)(`div`,{ref:c,role:`option`,"aria-selected":h,"data-selected":h,"data-disabled":i,className:s(`relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50`,e),onMouseEnter:()=>!i&&d(t),onClick:e=>{a?.(e),i||r?.(t)},...o}):null});rr.displayName=`CommandItem`;var ir=`mcp-inspector-models-cache`,ar=1440*60*1e3;function or(){try{let e=localStorage.getItem(ir);if(e)return JSON.parse(e)}catch(e){console.error(`Failed to load models cache:`,e)}return{}}function sr(e,t){try{let n=or();n[e]={models:t,timestamp:Date.now()},localStorage.setItem(ir,JSON.stringify(n))}catch(e){console.error(`Failed to save models cache:`,e)}}function cr(e){try{let t=or(),n=t[e];if(n){if(Date.now()-n.timestamp<ar)return n.models;delete t[e],localStorage.setItem(ir,JSON.stringify(t))}}catch(e){console.error(`Failed to get cached models:`,e)}return null}function lr(e,t){return!Vt(e)||!t?.trim()?e:`${e}:${e===`ollama`?jt(t):t.trim().toLowerCase()}`}var ur=`chat-config-source`;function dr(e){return e===`openai`||e===`anthropic`||e===`google`?e:`openrouter`}async function fr(e,t){let n={};t&&(n.Authorization=`Bearer ${t}`);let r;try{r=await fetch(`${e}/models`,{headers:n})}catch{throw Error(`Failed to reach the server. Check the URL is correct and that CORS is enabled on the server.`)}if(!r.ok)throw Error(`Failed to fetch models: ${r.statusText}`);if(!(r.headers.get(`content-type`)??``).includes(`application/json`))throw Error(`Invalid URL — response was not JSON`);let i=await r.json();if(!Array.isArray(i?.data))throw Error(`Unexpected response format — expected { data: [...] } from the OpenAI-compatible endpoint`);return i.data.map(e=>({id:e.id}))}async function pr(e){let t=await fetch(`https://api.openai.com/v1/models`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`Failed to fetch OpenAI models: ${t.statusText}`);return(await t.json()).data.map(e=>({id:e.id}))}async function mr(e){let t=await fetch(`https://api.anthropic.com/v1/models`,{headers:{"x-api-key":e,"anthropic-version":`2023-06-01`,"anthropic-dangerous-direct-browser-access":`true`}});if(!t.ok)throw Error(`Failed to fetch Anthropic models: ${t.statusText}`);return(await t.json()).data.map(e=>({id:e.id,displayName:e.display_name}))}async function hr(e){let t=await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${e}`);if(!t.ok)throw Error(`Failed to fetch Google models: ${t.statusText}`);return((await t.json()).models||[]).map(e=>({id:e.name,displayName:e.displayName}))}async function gr(e){let t=await fetch(`https://openrouter.ai/api/v1/models`,{headers:{Authorization:`Bearer ${e}`}});if(!t.ok)throw Error(`Failed to fetch OpenRouter models: ${t.statusText}`);return(await t.json()).data.map(e=>({id:e.id,displayName:e.name}))}async function _r(e,t){let n;try{n=await fetch(Dt(e,`/api/tags`),{headers:{...t.trim()?{Authorization:`Bearer ${t.trim()}`}:{}}})}catch(e){throw new At(e)}if(!n.ok)throw Error(`Failed to fetch Ollama models: ${n.statusText}`);return((await n.json()).models||[]).map(e=>({id:e.model||e.name||``}))}function vr({open:e,onOpenChange:t,tempProvider:n,tempModel:r,tempApiKey:i,tempBaseUrl:a,onProviderChange:o,onModelChange:c,onApiKeyChange:l,onBaseUrlChange:u,onSave:d,onClear:f,showClearButton:p=!1,buttonLabel:m=`Configure API Key`,hostedInspector:h=!1,freeTierInfo:g,managedCloudInfo:_,useManagedCloud:v=!1,onSaveManagedCloud:y}){let[b,x]=(0,Q.useState)([]),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(+!v),P=lr(n,a),te=!!(h||g||_),I=!!(_&&M===0);(0,Q.useEffect)(()=>{e&&N(+!v)},[e,v]),(0,Q.useEffect)(()=>{let t=zt(n),r=Vt(n);if(I||!e||!n||t&&!i.trim()||r&&!a.trim()){x([]),T(null);return}let o=setTimeout(async()=>{let e=cr(P);if(e){x(e),T(null);return}C(!0),T(null);try{let e=[];n===`openai-compatible`?e=await fr(a,i):n===`openai`?e=await pr(i):n===`anthropic`?e=await mr(i):n===`google`?e=await hr(i):n===`openrouter`?e=await gr(i):n===`ollama`&&(e=await _r(a,i)),sr(P,e),x(e)}catch(e){T(e instanceof Error?e.message:`Failed to fetch models. Please check your API key.`),x([])}finally{C(!1)}},500);return()=>clearTimeout(o)},[i,a,n,e,P,I]);let L=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!e||I){e||(L.current=null);return}let t=L.current;t!==null&&t!==n&&c(``),L.current=n},[n,e,c,I]);let R=Vt(n),z=!zt(n),V=e&&(!zt(n)||!!i.trim())&&(!R||!!a.trim()),ne=z?`API Key (optional)`:`API Key`,re=z?n===`ollama`?`Leave empty for local Ollama`:`Enter your API key (optional)`:`Enter your API key`,W=n===`openai-compatible`?`http://localhost:11434/v1`:Gt(n),G=n===`openai-compatible`?`Base URL of your OpenAI-compatible API. Local servers must have CORS enabled.`:null,oe=n===`ollama`?`Optional for local Ollama. Stored locally and never sent to our servers.`:`Your API key is stored locally and never sent to our servers.`,q=_?_.models.reduce((e,t)=>(e[t.provider]||(e[t.provider]=[]),e[t.provider].push(t),e),{}):{},J=_?.models.find(e=>e.id===_.selectedModelId),se=Object.keys(q),ce=J?.provider??se[0]??``,le=ce?q[ce]??[]:[],ue=!!f&&p&&(!_||M===1),Y=()=>{if(I&&y){y();return}d()},de=I?!!(_?.isLoading||!_?.selectedModelId||_?.models.length===0):zt(n)&&!i.trim()||R&&!a.trim()||!r.trim();return(0,$.jsx)(Ne,{open:e,onOpenChange:t,children:(0,$.jsxs)(_e,{className:`max-w-md`,"data-testid":`chat-config-dialog`,children:[(0,$.jsxs)(Ie,{children:[(0,$.jsx)(we,{children:te?`Configure Chat`:`LLM Provider Configuration`}),(0,$.jsx)(Re,{children:_?`Pick a Manufact cloud model or bring your own API key.`:g?`Chat requires an LLM. You can chat for free if you have a Manufact account, or you can use your own API key (not sent to Manufact).`:`Configure your LLM provider and API key to start chatting with the MCP server`})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[g&&(0,$.jsxs)(`button`,{type:`button`,onClick:g.onLoginClick,"data-testid":`chat-config-sign-in-card`,className:`relative w-full cursor-pointer overflow-hidden rounded-2xl text-left transition-opacity hover:opacity-95 active:opacity-90`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-[#edf2ff]`,"aria-hidden":!0}),(0,$.jsx)(wt,{className:`absolute inset-0 h-full w-full`,grainOverlay:.15}),(0,$.jsxs)(`div`,{className:`relative flex items-center justify-between gap-4 px-4 py-3.5`,children:[(0,$.jsxs)(`div`,{className:`text-sm font-medium text-black`,children:[(0,$.jsx)(`p`,{children:`Chat for free with a`}),(0,$.jsxs)(`p`,{className:`mt-1 flex items-center gap-1.5`,children:[(0,$.jsx)(ut,{symbolSize:14,textClassName:`text-sm`}),`account`]})]}),(0,$.jsx)(F,{size:`sm`,render:(0,$.jsx)(`span`,{"aria-hidden":`true`}),nativeButton:!1,tabIndex:-1,className:`pointer-events-none shrink-0`,children:`Sign in`})]})]}),_&&(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsxs)(Lt,{selectedIndex:M,onSelect:N,idPrefix:ur,className:`w-fit`,children:[(0,$.jsx)(It,{index:0,label:`Manufact cloud`}),(0,$.jsx)(It,{index:1,label:`API key`})]})}),(0,$.jsxs)(`div`,{className:s(`space-y-2`,_&&`!mt-2`),children:[(0,$.jsx)(B,{children:`Provider`}),I?(0,$.jsxs)(K,{value:ce,onValueChange:e=>{let t=_?.models.find(t=>t.provider===e);t&&_?.onModelChange(t.id)},children:[(0,$.jsx)(U,{className:`rounded-md`,leading:ce?(0,$.jsx)(He,{provider:dr(ce),className:`shrink-0`}):void 0,children:(0,$.jsx)(H,{})}),(0,$.jsx)(ie,{children:se.map(e=>(0,$.jsx)(ae,{value:e,label:ft(dr(e)),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:dr(e)}),(0,$.jsx)(`span`,{children:ft(dr(e))})]})},e))})]}):(0,$.jsxs)(K,{value:n,onValueChange:e=>o(e),children:[(0,$.jsx)(U,{className:`rounded-md`,leading:(0,$.jsx)(He,{provider:n,className:`shrink-0`}),children:(0,$.jsx)(H,{})}),(0,$.jsxs)(ie,{children:[(0,$.jsx)(ae,{value:`openai`,label:ft(`openai`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`openai`}),(0,$.jsx)(`span`,{children:ft(`openai`)})]})}),(0,$.jsx)(ae,{value:`anthropic`,label:ft(`anthropic`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`anthropic`}),(0,$.jsx)(`span`,{children:ft(`anthropic`)})]})}),(0,$.jsx)(ae,{value:`google`,label:ft(`google`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`google`}),(0,$.jsx)(`span`,{children:ft(`google`)})]})}),(0,$.jsx)(ae,{value:`ollama`,label:ft(`ollama`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`ollama`}),(0,$.jsx)(`span`,{children:ft(`ollama`)})]})}),(0,$.jsx)(ae,{value:`openrouter`,label:ft(`openrouter`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(He,{provider:`openrouter`}),(0,$.jsx)(`span`,{children:ft(`openrouter`)})]})}),(0,$.jsx)(ae,{value:`openai-compatible`,label:ft(`openai-compatible`),children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:ft(`openai-compatible`)})})})]})]})]}),!I&&R&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:`Base URL`}),(0,$.jsx)(ee,{value:a,onChange:e=>u(e.target.value),placeholder:W,"data-testid":`chat-config-base-url-input`}),G&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:G})]}),!I&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:ne}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(ee,{type:A?`text`:`password`,value:i,onChange:e=>l(e.target.value),placeholder:re,className:`pr-10`,"data-testid":`chat-config-api-key-input`}),(0,$.jsx)(F,{type:`button`,variant:`ghost`,size:`sm`,className:`absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent`,onClick:()=>j(!A),children:A?(0,$.jsx)(Ze,{className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(Ye,{className:`h-4 w-4 text-muted-foreground`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:oe})]}),I?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:`Model`}),_?.isLoading?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models…`})]}):le.length>0?(0,$.jsxs)(Se,{open:O,modal:!0,onOpenChange:k,children:[(0,$.jsx)(Ae,{render:(0,$.jsxs)(F,{variant:`outline`,role:`combobox`,"aria-expanded":O,className:`w-full justify-between rounded-md`,"data-testid":`chat-config-cloud-model-select`,children:[(0,$.jsx)(`span`,{className:`inline-flex min-w-0 items-center gap-2 truncate`,children:J?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(He,{provider:dr(J.provider),className:`shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:at(J.name,J.provider)})]}):`Select a model…`}),(0,$.jsx)(en,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(be,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(Qn,{children:[(0,$.jsx)($n,{placeholder:`Search models…`,className:`h-9`}),(0,$.jsxs)(er,{children:[(0,$.jsx)(tr,{children:`No model found.`}),(0,$.jsx)(nr,{children:le.map(e=>(0,$.jsxs)(rr,{value:e.id,keywords:[e.name,e.id,e.provider],onSelect:e=>{_?.onModelChange(e),k(!1)},children:[at(e.name,e.provider),(0,$.jsx)(gt,{className:s(`ml-auto h-4 w-4`,_?.selectedModelId===e.id?`opacity-100`:`opacity-0`)})]},e.id))})]})]})})]}):(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Cloud models unavailable — try again or use your own key.`})]}):V&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(B,{children:`Model`}),S?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models...`})]}):w?(0,$.jsx)(`div`,{className:`text-sm text-destructive`,children:w}):b.length>0?(0,$.jsxs)(Se,{open:E,modal:!0,onOpenChange:D,children:[(0,$.jsx)(Ae,{render:(0,$.jsxs)(F,{variant:`outline`,role:`combobox`,"aria-expanded":E,className:`w-full justify-between rounded-md`,"data-testid":`chat-config-model-select`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:r&&(b.find(e=>e.id===r)?.displayName||b.find(e=>e.id===r)?.id)||`Select a model...`}),(0,$.jsx)(en,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(be,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(Qn,{children:[(0,$.jsx)($n,{placeholder:`Search models...`,className:`h-9`}),(0,$.jsxs)(er,{children:[(0,$.jsx)(tr,{children:`No model found.`}),(0,$.jsx)(nr,{children:b.map(e=>(0,$.jsxs)(rr,{value:e.id,keywords:e.displayName,onSelect:e=>{c(e===r?``:e),D(!1)},children:[e.displayName||e.id,(0,$.jsx)(gt,{className:s(`ml-auto h-4 w-4`,r===e.id?`opacity-100`:`opacity-0`)})]},e.id))})]})]})})]}):(0,$.jsx)(ee,{value:r,onChange:e=>c(e.target.value),placeholder:`Enter model name manually`,"data-testid":`chat-config-model-input`})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[ue&&(0,$.jsx)(F,{variant:`outline`,onClick:f,children:`Clear Config`}),(0,$.jsxs)(F,{onClick:Y,disabled:de,className:ue?`ml-auto`:``,"data-testid":`chat-config-save-button`,children:[(0,$.jsx)(Ue,{className:`h-4 w-4 mr-2`}),`Save Configuration`]})]})]})]})})}var yr=`rounded-full bg-background/80 backdrop-blur-md supports-[backdrop-filter]:bg-background/60 dark:bg-zinc-950/75 dark:supports-[backdrop-filter]:bg-zinc-950/55`,br=s(yr,`w-fit`),xr=s(yr,`h-9 gap-1.5 px-3`),Sr=`chat-view`;function Cr({llmConfig:e,hasMessages:t,configDialogOpen:n,onConfigDialogOpenChange:r,onClearChat:i,tempProvider:a,tempModel:o,tempApiKey:c,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSaveConfig:m,onClearConfig:g,hideConfigButton:_,hostedInspector:v,freeTierInfo:y,managedCloudInfo:b,useManagedCloud:x,onSaveManagedCloud:S,showClearButton:C,clearButtonLabel:w,hideTitle:T,clearButtonHideIcon:E,clearButtonHideShortcut:D,clearButtonVariant:k,hideClearButton:A,onCopyChat:j,onExportChat:M,activeChatId:P,chatTitle:ee,showViewToggle:I,viewIndex:L=0,onViewIndexChange:R,elevatedHeader:z}){return(0,$.jsxs)(`div`,{className:s(`relative flex w-full items-center gap-2 overflow-visible`,te,z?`pointer-events-none absolute top-0 right-0 z-50`:`absolute top-0 right-0 z-10`),children:[(0,$.jsx)(`div`,{className:s(`flex min-w-0 flex-1 items-center`,z&&`pointer-events-auto`),children:!T&&(0,$.jsx)(`h2`,{className:s(`text-[15px] text-foreground [font-variation-settings:'wght'_550,'opsz'_20]`,br),children:P?(0,$.jsx)(wn,{chatId:P,title:ee??`Chat`},P):`Chat`})}),I&&R&&(0,$.jsx)(`div`,{className:s(`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 overflow-visible px-1`,z&&`pointer-events-auto`),children:(0,$.jsxs)(Lt,{selectedIndex:L,onSelect:R,idPrefix:Sr,className:`shrink-0 overflow-visible`,"data-testid":`chat-view-tabs`,children:[(0,$.jsx)(It,{label:`Conv`,index:0}),(0,$.jsx)(It,{label:`Raw`,index:1})]})}),(0,$.jsxs)(`div`,{className:s(`ml-auto flex shrink-0 items-center gap-2`,z&&`pointer-events-auto`),children:[!A&&t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[j&&(0,$.jsxs)(F,{"data-testid":`chat-copy-button`,variant:`ghost`,size:`sm`,className:xr,onClick:j,children:[(0,$.jsx)(et,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Copy`})]}),M&&(0,$.jsxs)(ze,{children:[(0,$.jsx)(Be,{render:(0,$.jsxs)(F,{"data-testid":`chat-export-button`,variant:`ghost`,size:`sm`,className:xr,children:[(0,$.jsx)(rt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Export`})]}),nativeButton:!0}),(0,$.jsxs)(Ee,{align:`end`,children:[(0,$.jsx)(Le,{"data-testid":`chat-export-json`,onClick:()=>M(`json`),children:`Export as JSON`}),(0,$.jsx)(Le,{"data-testid":`chat-export-markdown`,onClick:()=>M(`markdown`),children:`Export as Markdown`})]})]}),(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsxs)(F,{variant:k??`default`,size:`default`,className:`p-2 cursor-pointer ${D?`sm:px-3`:`sm:pr-1 sm:pl-3`}`,onClick:i,children:[!E&&(0,$.jsx)(an,{className:`h-4 w-4 sm:mr-2`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:w??`New Chat`}),!D&&(0,$.jsx)(`span`,{className:`hidden sm:inline text-[12px] border text-zinc-300 p-1 rounded-full border-zinc-300 dark:text-zinc-600 dark:border-zinc-500 ml-2`,children:`⌘O`})]}),nativeButton:!0}),(0,$.jsx)(N,{children:(0,$.jsx)(`p`,{children:w??`New Chat`})})]})]}),(!_||v||y||b)&&(0,$.jsx)(vr,{open:n,onOpenChange:r,tempProvider:a,tempModel:o,tempApiKey:c,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSave:m,onClear:g,showClearButton:C??(!!e&&!y&&!b),buttonLabel:e?`Change API Key`:`Configure API Key`,hostedInspector:v,freeTierInfo:y,managedCloudInfo:b,useManagedCloud:x,onSaveManagedCloud:S})]})]})}function wr({tools:e,disabledTools:t,onDisabledToolsChange:n,disabled:r}){let[i,a]=(0,Q.useState)(!1),o=e.length-t.size,c=t.size===0,l=t.size>0&&t.size<e.length,u=(0,Q.useCallback)(e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},[t,n]),d=(0,Q.useCallback)(()=>{n(c?new Set(e.map(e=>e.name)):new Set)},[c,e,n]),f=(0,Q.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return e.length===0?null:(0,$.jsxs)(Se,{open:i,onOpenChange:a,children:[(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsx)(Ae,{render:(0,$.jsxs)(F,{variant:`ghost`,size:`sm`,disabled:r,className:s(`h-auto gap-1 rounded-full px-2 py-2`,l?`text-amber-500 dark:text-amber-400`:`text-muted-foreground hover:text-foreground`),type:`button`,"data-testid":`chat-tool-selector`,children:[(0,$.jsx)(lt,{className:`h-4 w-4 shrink-0`}),l&&(0,$.jsx)(`span`,{className:`flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-amber-500 px-1 text-[9px] font-bold leading-none text-white`,children:o})]}),nativeButton:!0}),nativeButton:!0}),(0,$.jsx)(N,{side:`top`,children:(0,$.jsxs)(`p`,{children:[`Tools (`,o,`/`,e.length,`)`]})})]}),(0,$.jsxs)(be,{className:`w-72 gap-0 p-0`,align:`start`,side:`top`,sideOffset:8,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,$.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[`Allowed Tools (`,o,`/`,e.length,`)`]}),(0,$.jsx)(F,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:d,type:`button`,children:c?`Disable All`:`Enable All`})]}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-y-auto`,children:f.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2.5 w-full px-3 py-1.5 text-left hover:bg-accent/50 transition-colors cursor-pointer`,onClick:()=>u(e.name),children:[(0,$.jsx)(Jt,{checked:!t.has(e.name),className:`pointer-events-none`,tabIndex:-1}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-mono`,children:e.name})]},e.name))})]})]})}function Tr({inputValue:e,isConnected:t,isLoading:n,textareaRef:r,attachments:i,placeholder:a=`Ask a question`,className:c,showAttachButton:l=!0,tools:u,disabledTools:d,onDisabledToolsChange:f,onInputChange:p,onKeyDown:m,onKeyUp:h,onClick:g,onAttachmentAdd:_,onAttachmentRemove:v,inlineControls:y,trailingControls:b}){let x=o(),S=(0,Q.useRef)(null),C=e=>{let t=e.target.files;if(t&&t.length>0)for(let e=0;e<t.length;e++)_(t[e]);S.current&&(S.current.value=``)},w=i.length>0;return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[w&&(0,$.jsx)(`div`,{className:`absolute top-0 left-0 right-0 z-20 p-3 flex gap-2 flex-wrap`,children:i.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group bg-zinc-100/90 dark:bg-zinc-900/90 backdrop-blur-sm rounded-lg p-2 flex items-center gap-2 border border-zinc-200 dark:border-zinc-700`,"data-testid":`chat-attachment-${t}`,children:[(0,$.jsx)(pt,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,$.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium truncate max-w-[150px]`,children:e.name||`Image`}),e.size&&(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ye(e.size)})]}),(0,$.jsx)(`button`,{onClick:()=>v(t),className:`shrink-0 p-1 rounded-full hover:bg-zinc-200 dark:hover:bg-zinc-800 transition-colors`,title:`Remove attachment`,type:`button`,"data-testid":`chat-attachment-remove-${t}`,children:(0,$.jsx)(Oe,{className:`h-3 w-3`})})]},t))}),(0,$.jsx)(qt,{ref:r,value:e,onChange:e=>p(e.target.value),onKeyDown:m,onKeyUp:h,onClick:g,placeholder:t?a:`Server not connected`,className:s(`p-4 min-h-[150px] max-h-[300px]`,x.container,w&&`pt-20`,c),disabled:!t||n,"data-testid":`chat-input`}),(0,$.jsx)(`input`,{ref:S,type:`file`,accept:`image/*`,multiple:!0,onChange:C,className:`hidden`,"aria-label":`Upload images`}),(0,$.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 flex items-center justify-between gap-2 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1`,children:[l&&(0,$.jsx)(F,{variant:`ghost`,size:`sm`,onClick:()=>S.current?.click(),disabled:!t||n,className:`h-auto w-auto aspect-square rounded-full p-2 text-muted-foreground hover:text-foreground`,title:`Attach images`,type:`button`,"data-testid":`chat-attach-button`,children:(0,$.jsx)(nn,{className:`h-4 w-4`})}),u&&u.length>0&&d&&f&&(0,$.jsx)(wr,{tools:u,disabledTools:d,onDisabledToolsChange:f,disabled:!t||n}),y]}),b?(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:b}):null]})]})}function Er({promptResults:e,onDeletePromptResult:t}){return(0,$.jsx)(`div`,{className:`absolute top-4 left-4 right-4 flex gap-2 overflow-x-auto z-20 flex-nowrap`,style:{scrollbarWidth:`none`,msOverflowStyle:`none`},children:e.map(({promptName:e},n)=>(0,$.jsxs)(F,{type:`button`,className:`flex items-center gap-2 bg-zinc-200 text-zinc-700 dark:text-zinc-300 text-[10px] px-1.5 py-0.5 dark:bg-zinc-700 rounded-lg border border-zinc-200 dark:border-zinc-300 font-medium hover:bg-zinc-300 dark:hover:bg-zinc-600`,children:[(0,$.jsx)(dt,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,title:e,children:e}),(0,$.jsx)(`span`,{className:`ml-1 h-4 w-4 rounded-full bg-zinc-400 dark:bg-zinc-600 hover:bg-zinc-500 dark:hover:bg-zinc-500 flex items-center justify-center cursor-pointer shrink-0 transition-colors`,onClick:e=>{e.stopPropagation(),t(n)},title:`Remove prompt`,role:`button`,tabIndex:0,children:(0,$.jsx)(Oe,{className:`h-2.5 w-2.5 text-white`})})]},n))})}function Dr({isOpen:e,focusedIndex:t,prompts:n,selectedPrompt:r,onPromptSelect:i}){return e?((0,Q.useEffect)(()=>{if(t>=0){let e=document.getElementById(`prompt-${t}`);e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})}},[t]),(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 right-0 max-w-3xl w-full max-h-[300px] overflow-y-auto rounded-lg border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 shadow-lg z-30 flex flex-col gap-2 mb-1`,"data-testid":`chat-prompts-dropdown`,children:(0,$.jsxs)(`div`,{className:`p-2`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-zinc-900 dark:text-zinc-100 mb-2`,children:`Prompts`}),n.map((e,n)=>(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsxs)(F,{id:`prompt-${n}`,type:`button`,variant:`ghost`,className:s(`w-full flex items-center px-3 py-2 rounded-md hover:bg-zinc-200 dark:hover:bg-zinc-700 transition-colors text-left justify-start`,t===n&&`bg-zinc-200 dark:bg-zinc-700`),onClick:()=>i(e),"data-testid":`chat-prompt-option-${n}`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-center shrink-0`,children:(0,$.jsx)(dt,{className:`h-4 w-4 text-zinc-600 dark:text-zinc-400`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsxs)(`div`,{className:`text-sm font-medium text-zinc-900 dark:text-zinc-100 flex items-center gap-2`,children:[e.name,r?.name===e.name&&(0,$.jsx)(Ce,{className:`size-3 text-zinc-600 dark:text-zinc-400`})]})})]}),nativeButton:!0}),(0,$.jsx)(N,{children:e.description})]},n))]})})):null}var Or=Q.createContext(void 0);function kr(e=!1){let t=Q.useContext(Or);if(!t&&!e)throw Error(_(86));return t}var Ar=Q.createContext(void 0);function jr(){return Q.useContext(Ar)}var Mr=[V],Nr=Q.forwardRef(function(e,t){let{render:r,className:i,disabled:a,readOnly:o,required:s,onValueChange:c,value:u,defaultValue:d,form:f,name:p,inputRef:m,id:h,style:g,..._}=e,{setTouched:v,setFocused:y,validationMode:b,name:x,disabled:S,state:C,validation:w,setDirty:T,setFilled:D,validityData:O}=ue(),{labelId:k}=Y(),{clearErrors:A}=fe(),j=kr(!0),M=S||a,N=x??p,P=l(h),[F,ee]=z({controlled:u,default:d,name:`RadioGroup`,state:`value`}),[te,I]=Q.useState(!1),L=n((e,t)=>{c?.(e,t),!t.isCanceled&&ee(e)}),R=Q.useRef(null),B=Q.useRef(null),V=Q.useRef(null);function ne(e){let t;return m&&(typeof m==`function`?t=m(e):m.current=e),B.current=e,w.inputRef.current=e,t}let H=n((e,t=!1)=>{if(e){if(t){R.current===e&&(R.current=null);return}R.current??=e}}),re=n(e=>{if(!e||e.disabled)return;V.current||=e;let t=B.current;if(e.checked||t==null||t.disabled)return ne(e)}),U=n(()=>{let e=B.current;return!e||e.disabled||!e.checked?null:F??null});se(R,P,F??null,U,!M,p),ce(F,()=>{A(N),T(F!==O.initialValue),D(F!=null),w.change(F);let e=V.current;F==null&&e&&!e.disabled&&ne(e)});let ie=_[`aria-labelledby`]??k??j?.legendId,W={...C,disabled:M??!1,required:s??!1,readOnly:o??!1},G=Q.useMemo(()=>({...C,checkedValue:F,disabled:M,form:f,validation:w,name:N,readOnly:o,registerControlRef:H,registerInputRef:re,required:s,setCheckedValue:L,setTouched:I,touched:te}),[F,M,f,w,C,N,o,H,re,s,L,I,te]),ae={id:h,role:`radiogroup`,"aria-required":s||void 0,"aria-disabled":M||void 0,"aria-readonly":o||void 0,"aria-labelledby":ie,onFocus(){y(!0)},onBlur(e){E(e.currentTarget,e.relatedTarget)||(v(!0),y(!1),b===`onBlur`&&w.commit(F))},onKeyDownCapture(e){e.key.startsWith(`Arrow`)&&(I(!0),y(!0))}};return(0,$.jsx)(Ar.Provider,{value:G,children:(0,$.jsx)(Ft,{render:r,className:i,style:g,state:W,props:[ae,_,e=>w.getValidationProps(M??!1,e)],refs:[t],stateAttributesMapping:J,enableHomeAndEndKeys:!1,modifierKeys:Mr})})}),Pr=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),Fr={checked(e){return e?{[Pr.checked]:``}:{[Pr.unchecked]:``}},...A,...J},Ir=Q.createContext(void 0),Lr=Q.forwardRef(function(e,t){let{render:i,className:a,disabled:o=!1,readOnly:s=!1,required:u=!1,"aria-labelledby":f,value:h,inputRef:_,nativeButton:v=!1,id:y,style:x,...S}=e,T=jr(),{disabled:E,readOnly:O,required:k,form:A,checkedValue:j,touched:N=!1,validation:P,name:F}=T??{},ee=T?.setCheckedValue??D,te=T?.setTouched??D,I=T?.registerControlRef??D,L=T?.registerInputRef??D,{setTouched:R,setFilled:z,state:B,disabled:V}=ue(),ne=St(),{labelId:H,getDescriptionProps:U}=Y(),ie=V||ne.disabled||E||o,W=O||s,G=k||u,ae=A,K=T?j===h:h===``,q=Q.useRef(null),J=Q.useRef(null),se=n(e=>{e&&I(e,ie)}),ce=C(_,J,L);d(()=>{J.current?.checked&&z(!0)},[z]),d(()=>{if(J.current){if(ie&&K){L(null);return}q.current&&I(q.current,ie),L(J.current)}},[K,ie,I,L]);let le=l(),de=re({id:y,implicit:!1,controlRef:q}),fe=v?void 0:de,pe=Fe(f,H,J,!v,fe),me={role:`radio`,"aria-checked":K,"aria-required":G||void 0,"aria-readonly":W||void 0,"aria-labelledby":pe,[Pt]:K?``:void 0,id:v?de:le,onKeyDown(e){e.key===`Enter`&&e.preventDefault()},onClick(e){if(e.defaultPrevented||ie||W)return;e.preventDefault();let t=J.current;t&&t.dispatchEvent(new(r(t)).PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}))},onFocus(e){e.defaultPrevented||ie||W||!N||(J.current?.click(),te(!1))}},{getButtonProps:he,buttonRef:ge}=m({disabled:ie,native:v,composite:!1}),_e={type:`radio`,ref:ce,form:ae,id:fe,name:F,tabIndex:-1,style:F?g:w,"aria-hidden":!0,...h===void 0?M:{value:oe(h)},disabled:ie,checked:K,required:G,readOnly:W,onChange(e){if(e.nativeEvent.defaultPrevented||ie||W||h===void 0)return;let t=c(p,e.nativeEvent);ee(h,t),!t.isCanceled&&R(!0)},onFocus(){q.current?.focus()}},ve=Q.useMemo(()=>({...B,required:G,disabled:ie,readOnly:W,checked:K}),[B,ie,W,K,G]),ye=ve,be=T!==void 0,xe=[t,q,ge,se],Se=[me,S,he,U,P?e=>P.getValidationProps(ie,e):M],Ce=b(`span`,e,{enabled:!be,state:ve,ref:xe,props:Se,stateAttributesMapping:Fr});return(0,$.jsxs)(Ir.Provider,{value:ye,children:[be?(0,$.jsx)(bt,{tag:`span`,render:i,className:a,style:x,state:ve,refs:xe,props:Se,stateAttributesMapping:Fr}):Ce,(0,$.jsx)(`input`,{..._e,suppressHydrationWarning:!0})]})}),Rr=[];function zr(e){let{allValues:t=Rr,value:r=Rr,onValueChange:i}=e,a=Q.useRef(r),o=Q.useRef(new Map),[s,c]=Q.useState(`mixed`),u=l(),d=r.length===t.length,f=r.length!==t.length&&r.length>0,p=n(i),m=Q.useCallback(()=>({id:u,indeterminate:f,checked:d,"aria-controls":t.map(e=>`${u}-${e}`).join(` `),onCheckedChange(e,n){let i=a.current,l=t.filter(e=>o.current.get(e)&&i.includes(e)),u=t.filter(e=>!o.current.get(e)||o.current.get(e)&&i.includes(e));if(i.length===u.length||i.length===0){r.length===u.length?p(l,n):p(u,n);return}let d=`mixed`,f=i;s===`mixed`?(d=`on`,f=u):s===`on`&&(d=`off`,f=l),p(f,n),n.isCanceled||c(d)}}),[t,d,u,f,p,s,r.length]),h=Q.useCallback(e=>({checked:r.includes(e),onCheckedChange(t,n){let i=r.slice();t?i.push(e):i.splice(i.indexOf(e),1),p(i,n),n.isCanceled||(a.current=i,c(`mixed`))}}),[p,r]);return Q.useMemo(()=>({id:u,indeterminate:f,getParentProps:m,getChildProps:h,disabledStatesRef:o}),[u,f,m,h])}var Br=Q.forwardRef(function(e,t){let{allValues:r,className:i,defaultValue:a,disabled:o=!1,id:s,onValueChange:c,render:u,value:d,style:f,...p}=e,{disabled:m,name:h,state:g,validation:_,setFilled:v,setDirty:y,validityData:x}=ue(),{labelId:C,getDescriptionProps:w}=Y(),{clearErrors:T}=fe(),E=m||o,D=Q.useMemo(()=>{if(d===void 0)return a??[]},[d,a]),[O,k]=z({controlled:d,default:D,name:`CheckboxGroup`,state:`value`}),A=n((e,t)=>{c?.(e,t),!t.isCanceled&&k(e)}),j=zr({allValues:r,value:O,onValueChange:A}),M=l(s),N=Q.useRef(null),P=Q.useCallback(e=>{N.current==null&&e!=null&&!e.hasAttribute(`data-parent`)&&(N.current=e)},[]);se(N,M,O,void 0,!!h&&!E,h);let F=O??S;ce(F,()=>{h&&T(h);let e=Array.isArray(x.initialValue)?x.initialValue:S;v(F.length>0),y(!W(F,e)),_.change(F)});let ee={...g,disabled:E},te=Q.useMemo(()=>({allValues:r,value:O,defaultValue:D,setValue:A,parent:j,disabled:E,validation:_,registerControlRef:P}),[r,O,D,A,j,E,_,P]),I=b(`div`,e,{state:ee,ref:t,props:[{id:s,role:`group`,"aria-labelledby":C},p,w],stateAttributesMapping:J});return(0,$.jsx)(ht.Provider,{value:te,children:I})}),Vr=function(e){let t=l(),r=e.controlId===void 0?t:e.controlId,[i,a]=Q.useState(r),[o,s]=Q.useState(e.labelId),[c,u]=Q.useState([]),d=I(()=>new Map),{messageIds:f}=Y(),p=n((e,t)=>{let n=d.current;if(t===void 0){n.delete(e);return}n.set(e,t),a(e=>{if(n.size===0)return;let t;for(let r of n.values()){if(e!==void 0&&r===e)return e;t===void 0&&(t=r)}return t})}),m=Q.useCallback(e=>{let t=e[`aria-describedby`]?e[`aria-describedby`].split(` `):[];return t.push(...f,...c),{...e,"aria-describedby":Array.from(new Set(t)).join(` `)||void 0}},[f,c]),h=Q.useMemo(()=>({controlId:i,registerControlId:p,labelId:o,setLabelId:s,messageIds:c,setMessageIds:u,getDescriptionProps:m}),[i,p,o,s,c,u,m]);return(0,$.jsx)(le.Provider,{value:h,children:e.children})};function Hr(e,t){return{...e,state:{...e.state,valid:!t&&e.state.valid}}}var Ur=Object.keys(de);function Wr(e){if(!e||e.valid||!e.valueMissing)return!1;let t=!1;for(let n of Ur)n!==`valid`&&(n===`valueMissing`?t=e[n]:e[n]&&(t=!1));return t}function Gr(e){let t=null;for(let n of e)if(!n.disabled){if(!n.validity.valid)return n;t??=n}return t}function Kr(e,t){let n=!1;for(let r of t)r.setCustomValidity(``),n||=r===e;n||e.setCustomValidity(``)}function qr(e){let{formRef:t}=fe(),{setValidityData:r,validate:i,validityData:a,validationDebounceTime:o,invalid:s,markedDirtyRef:c,state:l,shouldValidateOnChange:u,getRegisteredFieldId:d}=e,{controlId:p,getDescriptionProps:m}=Y(),h=f(),g=Q.useRef(null),_=I(()=>new Set).current,v=Q.useRef(0),y=Q.useCallback(e=>{if(e)return _.add(e),()=>{_.delete(e)}},[_]),b=n(async(e,n=!1)=>{let o=Gr(_)??g.current;if(!o)return;v.current+=1;let f=v.current;function m(e,n=s){let r=d()??p;if(r==null)return;let i=t.current.fields.get(r);if(!i)return;let a=Hr(e,n);t.current.fields.set(r,{...i,validityData:a})}if(n){if(l.valid!==!1)return;let t=o.validity;if(!t.valueMissing){let t={value:e,state:{...de,valid:!0},error:``,errors:[],initialValue:a.initialValue};Kr(o,_),m(t,!1),r(t);return}let n=Ur.reduce((e,n)=>(e[n]=t[n],e),{});if(!n.valid&&!Wr(n))return}function y(e){let t=Ur.reduce((t,n)=>(t[n]=e.validity[n],t),{}),n=!1;for(let e of Ur)if(e!==`valid`){if(e===`valueMissing`&&t[e])n=!0;else if(t[e])return t}return n&&!c.current&&(t.valid=!0,t.valueMissing=!1),t}h.clear();let b=null,x=[],S=y(o),C,w=u();if(o.validationMessage&&!w)C=o.validationMessage,x=[o.validationMessage];else{let n=i(e,Array.from(t.current.fields.values()).reduce((e,t)=>(t.name&&(e[t.name]=t.getValue()),e),{}));if(typeof n==`object`&&n&&`then`in n){if(b=await n,f!==v.current)return}else b=n;b===null?w&&(Kr(o,_),S.customError=!1,o.validationMessage?(C=o.validationMessage,x=[o.validationMessage]):o.validity.valid&&!S.valid&&(S.valid=!0)):(S.valid=!1,S.customError=!0,Array.isArray(b)?(x=b,o.setCustomValidity(b.join(`
2
2
  `))):b&&(x=[b],o.setCustomValidity(b)))}let T={value:e,state:S,error:C??(Array.isArray(b)?b[0]:b??``),errors:x,initialValue:a.initialValue};m(T),r(T)}),x=n(e=>{h.clear();let t=u();t&&e!==``&&o?(v.current+=1,h.start(o,()=>{b(e)})):b(e,!t)}),S=Q.useCallback((e,t={})=>L(m(t),l.valid===!1&&!l.disabled&&!e?{"aria-invalid":!0}:M),[m,l.disabled,l.valid]);return Q.useMemo(()=>({getValidationProps:S,inputRef:g,registerInput:y,commit:b,change:x}),[S,y,b,x])}function Jr(e){let{commit:t,invalid:r,markedDirtyRef:i,name:a,setRegisteredFieldName:o,setRegisteredFieldId:s,setValidityData:c,validityData:l}=e,{formRef:u}=fe(),f=Q.useRef(null),p=Q.useRef(null),m=Q.useRef(null),h=n(()=>{let e=p.current;if(e)return e.getValue?e.getValue():e.value});function g(e){return e.value===void 0?h():e.value}let _=n(()=>{let e=p.current;if(i.current=!0,!e){t(l.value);return}t(g(e))});function v(){let e=p.current;!e||!e.id||u.current.fields.set(e.id,{getValue:h,name:a??e.name,controlRef:e.controlRef??m,validityData:Hr(l,r),validate:_})}function y(e=p.current?.id){e&&u.current.fields.delete(e)}function b(){let e=p.current;if(!e)return;let t=g(e);l.initialValue===null&&t!==null&&c(e=>({...e,initialValue:t}))}return d(()=>{let e=p.current;!e||!e.id||(o(a?void 0:e.name),u.current.fields.set(e.id,{getValue:h,name:a??e.name,controlRef:e.controlRef??m,validityData:Hr(l,r),validate:_}))},[u,h,r,a,o,_,l]),d(()=>{let e=u.current.fields;return()=>{let t=p.current?.id;t&&e.delete(t)}},[u]),[_,n((e,t)=>{if(!t){f.current===e&&(f.current=null,y(),p.current=null,o(void 0),s(void 0));return}let n=p.current?.id;f.current=e,p.current=t,a||o(t.name),s(t.id),n&&n!==t.id&&y(n),b(),v()})]}var Yr=Q.forwardRef(function(e,t){let{errors:r,validationMode:i,submitAttemptedRef:a}=fe(),{render:o,className:s,validate:c,validationDebounceTime:l=0,validationMode:u=i,name:f,disabled:p=!1,invalid:m,dirty:h,touched:g,actionsRef:_,style:v,...y}=e,x=kr(!0)?.disabled,S=n(c||(()=>null)),C=x||p,[w,T]=Q.useState(!1),[E,D]=Q.useState(!1),[O,k]=Q.useState(!1),[A,j]=Q.useState(!1),M=h??E,N=g??w,P=Q.useRef(M),F=Q.useRef(void 0),[ee,te]=Q.useState(),I=f??ee;d(()=>{h!==void 0&&(P.current=h)},[h]);let L=Q.useCallback(()=>F.current,[]),R=Q.useCallback(e=>{F.current=e},[]),z=n(e=>{h===void 0&&(e&&(P.current=!0),D(e))}),B=n(e=>{g===void 0&&T(e)}),V=n(()=>u===`onChange`||u===`onSubmit`&&a.current),ne=I&&Object.hasOwn(r,I)?r[I]:null,H=!!(Array.isArray(ne)?ne.length:ne),re=m===!0||H,[U,ie]=Q.useState({state:de,error:``,errors:[],value:null,initialValue:null}),W=C?null:!re&&U.state.valid,G=Q.useMemo(()=>({disabled:C,touched:N,dirty:M,valid:W,filled:O,focused:A}),[C,N,M,W,O,A]),ae=qr({setValidityData:ie,validate:S,validityData:U,validationDebounceTime:l,invalid:re,markedDirtyRef:P,state:G,shouldValidateOnChange:V,getRegisteredFieldId:L}),[oe,K]=Jr({commit:ae.commit,invalid:re,markedDirtyRef:P,name:f,setRegisteredFieldName:te,setRegisteredFieldId:R,setValidityData:ie,validityData:U});Q.useImperativeHandle(_,()=>({validate:oe}),[oe]);let se=Q.useMemo(()=>({invalid:re,name:I,validityData:U,setValidityData:ie,disabled:C,touched:N,setTouched:B,dirty:M,setDirty:z,filled:O,setFilled:k,focused:A,setFocused:j,validate:S,validationMode:u,validationDebounceTime:l,shouldValidateOnChange:V,state:G,markedDirtyRef:P,registerFieldControl:K,validation:ae}),[re,I,U,C,N,B,M,z,O,k,A,j,S,u,l,V,G,K,ae]),ce=b(`div`,e,{ref:t,state:G,props:y,stateAttributesMapping:J});return(0,$.jsx)(q.Provider,{value:se,children:ce})}),Xr=Q.forwardRef(function(e,t){return(0,$.jsx)(Vr,{children:(0,$.jsx)(Yr,{...e,ref:t})})}),Zr={...J,...A},Qr=Q.forwardRef(function(e,t){let{render:n,id:r,className:a,match:o,style:s,...c}=e,u=l(r),{validityData:f,state:p,name:m}=ue(!1),{setMessageIds:h}=Y(),{errors:g}=fe(),_=m&&Object.hasOwn(g,m)?g[m]:null,v=!!(Array.isArray(_)?_.length:_),y=typeof o==`string`,x=!1;x=o===!0?!0:p.disabled?!1:y?!!f.state[o]:v||f.state.valid===!1;let{mounted:S,transitionStatus:C,setMounted:w}=T(x);d(()=>{if(!(!x||!u))return h(e=>e.concat(u)),()=>{h(e=>e.filter(e=>e!==u))}},[x,u,h]);let E=Q.useRef(null),[D,O]=Q.useState(null),[k,A]=Q.useState(null),j=f.error;!y&&v?j=_:f.errors.length>1&&(j=f.errors);let M=j??``;Array.isArray(j)&&(M=j.length>1?(0,$.jsx)(`ul`,{children:j.map(e=>(0,$.jsx)(`li`,{children:e},e))}):j[0]??``);let N=Array.isArray(j)?JSON.stringify(j):j;x&&N!==k&&(A(N),O(M)),i({open:x,ref:E,onComplete(){x||w(!1)}});let P={...p,transitionStatus:C},F=b(`div`,e,{ref:[t,E],state:P,props:[{id:u,children:x?M:D},c],stateAttributesMapping:Zr,enabled:S});return S?F:null}),$r=Q.forwardRef(function(e,t){let{render:r,className:i,id:a,name:o,value:s,disabled:l=!1,onValueChange:u,defaultValue:f,autoFocus:m=!1,style:h,...g}=e,{state:_,name:v,disabled:y,setTouched:x,setDirty:S,validityData:C,setFocused:w,setFilled:T,validationMode:E,validation:D}=ue(),{clearErrors:O}=fe(),A=y||l,M=v??o,N={..._,disabled:A},{labelId:P}=Y(),F=re({id:a});d(()=>{let e=s!=null;D.inputRef.current?.value||e&&s!==``?T(!0):e&&s===``&&T(!1)},[D.inputRef,T,s]);let ee=Q.useRef(null);d(()=>{m&&ee.current===j(k(ee.current))&&w(!0)},[m,w]);let[te]=z({controlled:s,default:f,name:`FieldControl`,state:`value`}),I=s!==void 0,L=I?te:void 0,R=n(()=>D.inputRef.current?.value);return se(D.inputRef,F,L,R,!A,o),b(`input`,e,{ref:[t,ee],state:N,props:[{id:F,disabled:A,name:M,ref:D.inputRef,"aria-labelledby":P,autoFocus:m,...I?{value:L}:{defaultValue:f},onChange(e){let t=e.currentTarget.value;u?.(t,c(p,e.nativeEvent)),S(t!==C.initialValue),T(t!==``),e.nativeEvent.defaultPrevented||(O(M),D.change(t))},onFocus(){w(!0)},onBlur(e){x(!0),w(!1),E===`onBlur`&&D.commit(e.currentTarget.value)},onKeyDown(e){e.currentTarget.tagName===`INPUT`&&e.key===`Enter`&&(x(!0),D.commit(e.currentTarget.value))}},g,e=>D.getValidationProps(A,e)],stateAttributesMapping:J})}),ei=typeof window<`u`?Q.useLayoutEffect:Q.useEffect,ti=P.moderate,ni=.07,ri=(ti.duration+ni)*1e3+80,ii=ti.duration*1e3+80;function ai(e,t){let n=t.filter(t=>t.start>=e.start&&t.end<=e.end).sort((e,t)=>e.start-t.start);if(n.length!==2)return null;let[r,i]=n;return i.start===r.end+2?{up:r,lo:i,gap:r.end+1}:null}function oi(e,t,n,r){let i=n[e],a=n[t];if(!i||!a)return null;if(r===`y`)return{top:i.top,left:Math.min(i.left,a.left),width:Math.max(i.width,a.width),height:a.top+a.height-i.top};let o=Math.min(i.left,a.left),s=Math.max(i.left+i.width,a.left+a.width);return{top:Math.min(i.top,a.top),left:o,width:s-o,height:Math.max(i.height,a.height)}}function si(e,t){return t===`y`?e.top+e.height/2:e.left+e.width/2}function ci(e,t){return t===`y`?[e,e,0,0]:[e,0,0,e]}function li(e,t){return t===`y`?[0,0,e,e]:[0,e,e,0]}function ui(e){return[e,e,e,e]}function di(e,t,n,r,i){let a=si(n,r);if(r===`y`){let n=t.top+t.height;e.height=a-e.top,e.radii=ci(i,r),e.instant=!0,t.top=a,t.height=n-a,t.radii=li(i,r),t.instant=!0,t.enterFrom={top:a,left:t.left,width:t.width,height:n-a,radii:li(i,r)};return}let o=t.left+t.width;e.width=a-e.left,e.radii=ci(i,r),e.instant=!0,t.left=a,t.width=o-a,t.radii=li(i,r),t.instant=!0,t.enterFrom={top:t.top,left:a,width:o-a,height:t.height,radii:li(i,r)}}function fi(e,t,n,r=`y`){let[i,a]=(0,Q.useState)([]),o=(0,Q.useRef)([]),s=(0,Q.useRef)(0),c=(0,Q.useRef)(new Map);ei(()=>{let t=o.current,n=e,r=[];for(let e of n){let n=ai(e,t);n&&(e.id===n.up.id||e.id===n.lo.id)&&r.push({tid:++s.current,kind:`merge`,survivorId:e.id,otherId:e.id===n.up.id?n.lo.id:n.up.id,gapIndex:n.gap,phase:`converge`})}for(let e of t){let t=ai(e,n);t&&r.push({tid:++s.current,kind:`split`,survivorId:t.up.id,otherId:t.lo.id,gapIndex:t.gap,phase:`splitIn`})}o.current=n.map(e=>({...e}));for(let e of r)c.current.set(e.tid,setTimeout(()=>{c.current.delete(e.tid),a(t=>t.some(t=>t.tid===e.tid)?t.flatMap(t=>t.tid===e.tid?t.kind===`merge`?[{...t,phase:`commit`}]:[]:[t]):t)},e.kind===`merge`?ri:ii));let i=e=>e.kind===`merge`?n.some(t=>t.id===e.survivorId&&e.gapIndex>t.start&&e.gapIndex<t.end):n.some(t=>t.id===e.survivorId&&t.end===e.gapIndex-1)&&n.some(t=>t.id===e.otherId&&t.start===e.gapIndex+1);a(e=>{for(let t of e){if(i(t))continue;let e=c.current.get(t.tid);e!==void 0&&(clearTimeout(e),c.current.delete(t.tid))}return[...e.filter(i),...r]})},[e.map(e=>`${e.id}:${e.start}-${e.end}`).join(`|`)]),(0,Q.useEffect)(()=>{let e=c.current;return()=>e.forEach(clearTimeout)},[]),(0,Q.useEffect)(()=>{i.some(e=>e.phase===`splitIn`||e.phase===`commit`)&&a(e=>e.flatMap(e=>e.phase===`commit`?[]:[{...e,phase:e.phase===`splitIn`?`diverge`:e.phase}]))},[i]);let l=[];for(let i of e){let e=oi(i.start,i.end,t,r);e&&l.push({key:`sel-${i.id}`,...e,radii:ui(n),instant:!1,exitInstant:!1,delayCorners:!1})}let u=new Map(l.map(e=>[e.key,e]));for(let e of i){let i=t[e.gapIndex],a=u.get(`sel-${e.survivorId}`);if(!i||!a)continue;let o=si(i,r);if(e.kind===`merge`){if(e.phase===`commit`){a.instant=!0,r===`y`?l.push({key:`sel-${e.otherId}`,top:o,left:a.left,width:a.width,height:a.top+a.height-o,radii:li(n,r),instant:!0,exitInstant:!0,delayCorners:!1,opacity:0}):l.push({key:`sel-${e.otherId}`,top:a.top,left:o,width:a.left+a.width-o,height:a.height,radii:li(n,r),instant:!0,exitInstant:!0,delayCorners:!1,opacity:0});continue}let t=Math.min(.1,Math.max(ni,ni+o/Math.max(r===`y`?i.height:i.width,1)*.002));if(r===`y`){let i=a.top+a.height;a.height=o-a.top,a.radii=ci(n,r),a.delayCorners=!0,a.cornerDelay=t,l.push({key:`sel-${e.otherId}`,top:o,left:a.left,width:a.width,height:i-o,radii:li(n,r),enterFrom:{top:o,left:a.left,width:a.width,height:i-o,radii:ui(n)},instant:!1,exitInstant:!0,delayCorners:!0,cornerDelay:t})}else{let i=a.left+a.width;a.width=o-a.left,a.radii=ci(n,r),a.delayCorners=!0,a.cornerDelay=t,l.push({key:`sel-${e.otherId}`,top:a.top,left:o,width:i-o,height:a.height,radii:li(n,r),enterFrom:{top:a.top,left:o,width:i-o,height:a.height,radii:ui(n)},instant:!1,exitInstant:!0,delayCorners:!0,cornerDelay:t})}}else if(e.phase===`splitIn`){let t=u.get(`sel-${e.otherId}`);if(!t)continue;di(a,t,i,r,n)}}for(let i of o.current){let a=ai(i,e),o=a&&t[a.gap];if(!a||!o)continue;let s=u.get(`sel-${a.up.id}`),c=u.get(`sel-${a.lo.id}`);!s||!c||di(s,c,o,r,n)}return l}function pi({blocks:e,dimmed:t}){return(0,$.jsx)(ne,{children:e.map(e=>{let n=e.delayCorners?{...ti,delay:e.cornerDelay??ni}:ti,r=e.opacity??(t?.8:1);return(0,$.jsx)(x.div,{"aria-hidden":!0,className:`absolute bg-active pointer-events-none`,initial:e.enterFrom?{opacity:r,top:e.enterFrom.top,left:e.enterFrom.left,width:e.enterFrom.width,height:e.enterFrom.height,borderTopLeftRadius:e.enterFrom.radii[0],borderTopRightRadius:e.enterFrom.radii[1],borderBottomRightRadius:e.enterFrom.radii[2],borderBottomLeftRadius:e.enterFrom.radii[3]}:!1,animate:{top:e.top,left:e.left,width:e.width,height:e.height,borderTopLeftRadius:e.radii[0],borderTopRightRadius:e.radii[1],borderBottomRightRadius:e.radii[2],borderBottomLeftRadius:e.radii[3],opacity:r},exit:{opacity:0,transition:e.exitInstant?{duration:0}:ti.exit},transition:e.instant?{duration:0}:{...ti,borderTopLeftRadius:n,borderTopRightRadius:n,borderBottomRightRadius:n,borderBottomLeftRadius:n,opacity:{duration:.08}}},e.key)})})}function mi(e,t){return e.id??`q-${t}`}function hi(e,t){return e.id??`o-${t}`}var gi=[],_i=(0,Q.forwardRef)(function({questions:e,currentIndex:t,defaultCurrentIndex:n=0,onCurrentIndexChange:r,answers:i,defaultAnswers:a,onAnswersChange:c,onComplete:l,onSkip:u,skipLabel:d=`Skip`,intro:f,onCancel:p,cancelLabel:m=`Cancel`,footerLeading:h,className:g,..._},y){let[b,S]=(0,Q.useState)(n),C=t!==void 0,w=C?t:b,T=(0,Q.useCallback)(e=>{C||S(e),r?.(e)},[C,r]),[E,D]=(0,Q.useState)(a??{}),O=i!==void 0,k=O?i:E,A=(0,Q.useRef)(k);(0,Q.useEffect)(()=>{A.current=k},[k]);let j=(0,Q.useCallback)(e=>{let t=e(A.current);return A.current=t,O||D(t),c?.(t),t},[O,c]),M=o(),N=X(`arrow-left`),ee=X(`arrow-right`),te=(0,Q.useMemo)(()=>function(e){return(0,$.jsx)(N,{...e,className:s(e.className,`hidden sm:block`)})},[N]),I=(0,Q.useMemo)(()=>function(e){return(0,$.jsx)(ee,{...e,className:s(e.className,`hidden sm:block`)})},[ee]),[L]=(0,Q.useState)(()=>{if(typeof navigator>`u`)return!1;let e=navigator,t=e.userAgentData?.platform||e.platform||``;return/mac/i.test(t)}),R=(0,Q.useId)(),z=e.length,B=Math.max(0,Math.min(w,Math.max(0,z-1))),V=e[B],H=V?mi(V,B):``,re=k[H],U=!!V?.multiSelect,ie=V?.skippable!==!1,W=!!V?.freeText,ae=V?.freeTextMultiline!==!1,oe=!W&&!!V?.allowOther,K=(0,Q.useMemo)(()=>re?.selectedIds??[],[re]),q=re?.otherText??``,J=V?.options??[],se=oe?J.length:-1,ce=J.length+ +!!oe,le=(0,Q.useRef)(null),ue=!!V;(0,Q.useEffect)(()=>{if(!ue)return;let e=le.current;if(e)return gi.push(e),()=>{let t=gi.indexOf(e);t!==-1&&gi.splice(t,1)}},[ue]);let Y=(0,Q.useRef)(null),de=(0,Q.useRef)(null),fe=(0,Q.useRef)(0),pe=(0,Q.useRef)(new Map),{activeIndex:me,setActiveIndex:he,itemRects:ge,sessionRef:_e,handlers:ve,registerItem:ye,measureItems:be}=G(Y);(0,Q.useEffect)(()=>{be()},[be,H,ce,M]);let[xe,Se]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{Se(!1)},[H]),(0,Q.useEffect)(()=>{let e=de.current;if(!e)return;e.style.height=`0px`,e.style.height=`${e.scrollHeight}px`;let t=parseFloat(window.getComputedStyle(e).lineHeight)||18;Se(e.scrollHeight>t*1.5),be()},[q,be,H]),(0,Q.useEffect)(()=>{W&&de.current?.focus({preventScroll:!0})},[W,H]);let Ce=(0,Q.useRef)(null),[we,Te]=(0,Q.useState)(`auto`);(0,Q.useEffect)(()=>{let e=Ce.current;if(!e)return;let t=()=>Te(e.offsetHeight);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let[Ee,De]=(0,Q.useState)(null),[Oe,ke]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{he(null),De(null),ke(null)},[B,he]);let Ae=(0,Q.useRef)(!1),je=(0,Q.useCallback)(()=>{Y.current?.contains(document.activeElement)&&(Ae.current=!0)},[]);(0,Q.useEffect)(()=>{Ae.current&&(Ae.current=!1,(Y.current?.querySelector(`[data-proximity-index="0"]`))?.focus())},[B]);let Me=(0,Q.useCallback)(e=>{B>=z-1?l?.(e):(je(),T(B+1))},[B,z,l,T,je]),Ne=(0,Q.useCallback)(e=>{if(!V)return;let t=A.current[H]?.otherText;Me(j(n=>({...n,[H]:{questionId:H,selectedIds:[e],otherText:t||void 0,skipped:!1}})))},[V,H,j,Me]),Pe=(0,Q.useCallback)(e=>{V&&j(t=>{let n=t[H],r=new Set(n?.selectedIds??[]);return r.has(e)?r.delete(e):r.add(e),{...t,[H]:{questionId:H,selectedIds:Array.from(r),otherText:n?.otherText,skipped:!1}}})},[V,H,j]),Fe=(0,Q.useCallback)(e=>{V&&j(t=>({...t,[H]:{questionId:H,selectedIds:e,otherText:t[H]?.otherText,skipped:!1}}))},[V,H,j]),Ie=(0,Q.useCallback)(e=>{V&&(ke(null),j(t=>({...t,[H]:{questionId:H,selectedIds:t[H]?.selectedIds??[],otherText:e,skipped:!1}})))},[V,H,j]),Le=(0,Q.useCallback)(()=>{if(!V)return;let e=(A.current[H]?.otherText??``).trim();if(e){if(V.freeText&&V.freeTextValidate){let t=V.freeTextValidate(e);if(t){ke(t);return}}ke(null),Me(j(t=>({...t,[H]:{questionId:H,selectedIds:t[H]?.selectedIds??[],otherText:e,skipped:!1}})))}},[V,H,j,Me]),Re=(0,Q.useCallback)(()=>{if(!V)return;let e=j(e=>({...e,[H]:{questionId:H,selectedIds:e[H]?.selectedIds??[],otherText:e[H]?.otherText,skipped:!0}}));u?.(H,B),Me(e)},[V,H,j,u,B,Me]),ze=(0,Q.useCallback)(()=>{p?.()},[p]),Be=(0,Q.useCallback)(()=>{Me(k)},[Me,k]),Ve=(0,Q.useCallback)(()=>{B>0&&(je(),T(B-1))},[B,T,je]);(0,Q.useEffect)(()=>{if(!V)return;let e=e=>{if(e.metaKey||e.ctrlKey||e.altKey)return;let t=e.target;if(!t)return;let n=t.tagName;if(n===`INPUT`||n===`TEXTAREA`||t.isContentEditable)return;let r=le.current;if(!r||!r.contains(t)&&(gi.some(e=>e!==r&&e.contains(t))||gi[gi.length-1]!==r))return;let i=e.key;if(i<`1`||i>`9`)return;let a=parseInt(i,10)-1;if(a>=0&&a<J.length){e.preventDefault();let t=hi(J[a],a);U?Pe(t):Ne(t)}else a===J.length&&oe&&(e.preventDefault(),de.current?.focus())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[V,J,U,oe,Ne,Pe]);let He=e=>{(Y.current?.querySelector(`[data-proximity-index="${e}"]`))?.focus()},Ue=(0,Q.useCallback)(e=>{he(e),oe&&e===se?de.current?.focus():He(e)},[oe,se,he]),We=e=>{let t=e.target,n=t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable;if(n&&e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;if(n&&(e.key===`ArrowUp`||e.key===`ArrowDown`)&&t.tagName===`TEXTAREA`){let n=t;if(e.key===`ArrowUp`&&n.selectionStart>0||e.key===`ArrowDown`&&n.selectionEnd<n.value.length)return}let r=e.preventBaseUIHandler;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault(),e.stopPropagation(),r?.(),e.key===`ArrowLeft`?B>0&&Ve():ie&&z>1&&Re();return}if(ce!==0&&(e.key===`ArrowDown`||e.key===`ArrowUp`||e.key===`Home`||e.key===`End`)){e.preventDefault(),e.stopPropagation(),r?.();let t;if(e.key===`Home`)t=0;else if(e.key===`End`)t=ce-1;else{let r=n?se:me??-1;t=e.key===`ArrowDown`?r+1:r-1,t=(t+ce)%ce}Ue(t)}},Ge=e=>{if(e.key===`Enter`&&!(!(L?e.metaKey:e.ctrlKey)||!(U||W))){if(e.preventDefault(),W){q.trim().length>0&&Le();return}(K.length>0||q.trim().length>0)&&Be()}};if(!V)return(0,$.jsx)(`div`,{ref:y,className:s(`w-full max-w-[520px] p-5 bg-card border border-border`,M.container,g),..._,children:(0,$.jsx)(`p`,{className:`text-[13px] text-muted-foreground`,children:`No questions.`})});let Ke=me===null?null:ge[me],qe=Ee!==null&&!(oe&&Ee===se)?ge[Ee]:null,Je=(0,Q.useMemo)(()=>{let e=new Set;return J.forEach((t,n)=>{K.includes(hi(t,n))&&e.add(n)}),oe&&q.length>0&&e.add(se),e},[J,K,oe,q,se]),Ye=(0,Q.useMemo)(()=>{let e=[],t=[...Je].sort((e,t)=>e-t);for(let n of t){let t=e[e.length-1];t&&n===t.end+1?t.end=n:e.push({start:n,end:n})}let n=new Set,r=new Map,i=e.map(e=>{let t=null;for(let r=e.start;r<=e.end;r++){let e=pe.current.get(r);if(e!==void 0&&!n.has(e)){t=e;break}}let i=t??++fe.current;n.add(i);for(let t=e.start;t<=e.end;t++)r.set(t,i);return{...e,id:i}});return pe.current=r,i},[Je]),Xe=me!==null&&!Je.has(me),Ze=fi(Ye,ge,M.bgRadius),$e=z>1&&B>0,et=p!=null,tt=!et&&z>1&&ie,nt=U||W,Z=$e||tt||nt||et||h!=null,rt=J.findIndex((e,t)=>K.includes(hi(e,t))),it=(0,$.jsxs)(`div`,{ref:Y,role:U?`group`:`radiogroup`,"aria-labelledby":`${R}-${H}-title`,onMouseEnter:ve.onMouseEnter,onMouseMove:ve.onMouseMove,onMouseLeave:ve.onMouseLeave,onFocus:e=>{let t=e.target.closest(`[data-proximity-index]`)?.getAttribute(`data-proximity-index`);if(t!=null){let n=Number(t);he(n),De(e.target.matches(`:focus-visible`)?n:null)}},onBlur:e=>{Y.current?.contains(e.relatedTarget)||(De(null),he(null))},onKeyDown:We,className:`relative flex flex-col gap-0.5 -mx-3`,children:[(0,$.jsx)(ne,{children:(()=>{if(!oe)return null;let e=ge[se],t=Ee===se&&q.length===0;return!e||!t?null:(0,$.jsx)(x.div,{"aria-hidden":!0,className:s(`absolute pointer-events-none bg-card ring-1 ring-inset ring-border`,M.bg),initial:{opacity:0,top:e.top,left:e.left,width:e.width,height:e.height},animate:{opacity:1,top:e.top,left:e.left,width:e.width,height:e.height},exit:{opacity:0,transition:P.fast.exit},transition:{...P.fast,opacity:{duration:.08}}},`other-input`)})()}),(0,$.jsx)(ne,{children:Ke&&(0,$.jsx)(x.div,{"aria-hidden":!0,className:s(`absolute pointer-events-none bg-hover`,M.bg),initial:{opacity:0,top:Ke.top,left:Ke.left,width:Ke.width,height:Ke.height},animate:{opacity:1,top:Ke.top,left:Ke.left,width:Ke.width,height:Ke.height},exit:{opacity:0,transition:P.fast.exit},transition:{...P.fast,opacity:{duration:.08}}},`hover-${_e.current}`)}),(0,$.jsx)(pi,{blocks:Ze,dimmed:Xe}),(0,$.jsx)(ne,{children:qe&&(0,$.jsx)(x.div,{"aria-hidden":!0,className:s(`absolute pointer-events-none border border-[color:var(--focus-ring,#6B97FF)] z-20`,M.focusRing),initial:{opacity:0,top:qe.top-2,left:qe.left-2,width:qe.width+4,height:qe.height+4},animate:{opacity:1,top:qe.top-2,left:qe.left-2,width:qe.width+4,height:qe.height+4},exit:{opacity:0,transition:P.fast.exit},transition:{...P.fast,opacity:{duration:.08}}})}),J.map((e,t)=>{let n=hi(e,t),r=K.includes(n),i=!U&&me===t;return(0,$.jsx)(yi,{index:t,registerItem:ye,role:U?`checkbox`:`radio`,isSelected:r,tabIndex:t===rt||rt===-1&&t===0?0:-1,onClick:()=>U?Pe(n):Ne(n),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),U?Pe(n):Ne(n))},shape:M,"aria-checked":r,chipContent:t+1,chipFilled:r,isMulti:U,showArrow:i,bodyLayout:V.layout===`stacked`?`stacked`:`inline`,topAlign:V.layout===`stacked`,chipPosition:V.chipPosition??`right`,arrowIcon:(0,$.jsx)(ee,{size:14,strokeWidth:2,className:`h-3.5 w-3.5`}),hiddenControl:U?(0,$.jsx)(Qe,{name:n,className:`sr-only`,tabIndex:-1,"aria-hidden":!0}):(0,$.jsx)(Lr,{value:n,className:`sr-only`,tabIndex:-1,"aria-hidden":!0}),children:V.layout===`stacked`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{className:`inline-grid`,children:[(0,$.jsx)(`span`,{className:`col-start-1 row-start-1 invisible`,style:{fontVariationSettings:v.semibold},"aria-hidden":`true`,children:e.title}),(0,$.jsx)(`span`,{className:`col-start-1 row-start-1 text-foreground transition-[color,font-variation-settings] duration-80`,style:{fontVariationSettings:r?v.semibold:v.medium},children:e.title})]}),e.description&&(0,$.jsx)(`span`,{className:`text-[12px] text-muted-foreground leading-snug`,children:e.description})]}):(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:`inline-grid`,children:[(0,$.jsx)(`span`,{className:`col-start-1 row-start-1 invisible`,style:{fontVariationSettings:v.semibold},"aria-hidden":`true`,children:e.title}),(0,$.jsx)(`span`,{className:`col-start-1 row-start-1 text-foreground transition-[color,font-variation-settings] duration-80`,style:{fontVariationSettings:r?v.semibold:v.medium},children:e.title})]}),e.description&&(0,$.jsxs)($.Fragment,{children:[` `,(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]})]})},n)}),oe&&(0,$.jsx)(yi,{index:se,registerItem:ye,role:null,isSelected:q.length>0,tabIndex:-1,onClick:()=>de.current?.focus(),shape:M,chipContent:se+1,chipFilled:q.length>0,isMulti:U,topAlign:xe,chipPosition:V.chipPosition??`right`,ariaLabel:V.otherPlaceholder??`Describe in your own words`,showArrow:!U&&(Ee===se||me===se)&&q.trim().length>0,arrowIcon:(0,$.jsx)(ee,{size:14,strokeWidth:2,className:`h-3.5 w-3.5`}),onArrowClick:!U&&q.trim().length>0?Le:void 0,children:(0,$.jsx)(`span`,{className:`inline-grid w-full`,children:(0,$.jsx)(`textarea`,{ref:de,rows:1,value:q,placeholder:V.otherPlaceholder??`Describe in your own words…`,"aria-label":V.otherPlaceholder??`Describe in your own words`,onChange:e=>Ie(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.shiftKey||U||(e.preventDefault(),Le()))},onClick:e=>e.stopPropagation(),className:s(`col-start-1 row-start-1 block w-full bg-transparent border-0 p-0 m-0 outline-none resize-none overflow-hidden text-[13px] leading-snug text-foreground placeholder:text-muted-foreground`),style:{fontVariationSettings:v.medium}})})})]});return(0,$.jsxs)(`div`,{ref:e=>{le.current=e,typeof y==`function`?y(e):y&&(y.current=e)},className:s(`relative w-full max-w-[520px] overflow-hidden bg-card border border-border`,M.container,g),..._,onKeyDown:e=>{_.onKeyDown?.(e),Ge(e)},children:[(0,$.jsx)(`div`,{className:`flex items-center px-4 sm:px-5 pt-4 sm:pt-5 pb-2 text-[12px] text-muted-foreground`,children:(0,$.jsxs)(`span`,{children:[`Question `,B+1,` of `,z]})}),f!=null&&(0,$.jsx)(`div`,{className:`px-4 sm:px-5 pb-3 text-[13px] leading-snug text-muted-foreground`,children:f}),(0,$.jsxs)(Xr,{invalid:Oe!==null,className:`contents`,children:[(0,$.jsx)(x.div,{animate:{height:we},initial:!1,transition:P.slow,className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:Ce,className:s(`px-4 sm:px-5`,Z?`pb-1`:`pb-2.5 sm:pb-3`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h3`,{id:`${R}-${H}-title`,className:`text-[16px] text-foreground leading-snug`,style:{fontVariationSettings:v.semibold},children:V.title}),W?(0,$.jsx)(`div`,{onClick:()=>de.current?.focus(),className:s(`relative mt-1 -mx-3 px-3 py-2.5 cursor-text transition-colors`,ae?`min-h-[76px]`:`min-h-10`,M.bg,q.length>0?`bg-active`:`hover:bg-hover focus-within:bg-card focus-within:ring-1 focus-within:ring-inset focus-within:ring-border`),children:(0,$.jsx)($r,{value:q,onValueChange:Ie,render:(0,$.jsx)(`textarea`,{ref:de,rows:1,placeholder:V.freeTextPlaceholder??`Type your answer…`,"aria-labelledby":`${R}-${H}-title`,onKeyDown:e=>{e.key===`Enter`&&(e.shiftKey||e.metaKey||e.ctrlKey||ae||(e.preventDefault(),Le()))},className:`block w-full bg-transparent border-0 p-0 m-0 outline-none resize-none overflow-hidden text-[13px] leading-snug text-foreground placeholder:text-muted-foreground`,style:{fontVariationSettings:v.medium}})})}):U?(0,$.jsx)(Br,{value:K,onValueChange:Fe,render:it}):(0,$.jsx)(Nr,{value:K[0]??null,onValueChange:e=>{typeof e==`string`&&Ne(e)},render:it})]},H)})}),Z&&(0,$.jsx)(`div`,{className:`px-4 sm:px-5 pt-1 pb-2`,children:(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 -mx-2 sm:-mx-3`,children:[(0,$.jsxs)(`div`,{className:`relative flex flex-1 min-w-0 items-center gap-2`,children:[h!=null&&(0,$.jsx)(`div`,{className:`shrink-0 px-2 sm:px-3`,children:h}),(0,$.jsx)(ne,{mode:`popLayout`,initial:!1,children:$e&&(0,$.jsx)(x.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...P.fast,opacity:{duration:.1}},children:(0,$.jsx)(F,{variant:`ghost`,size:`sm`,leadingIcon:te,onClick:Ve,className:`pl-3 sm:pl-[6px]`,children:`Back`})},`back`)}),Oe&&(0,$.jsx)(Qr,{match:!0,render:(0,$.jsx)(x.p,{role:`alert`,initial:{opacity:0,y:-2},animate:{opacity:1,y:0},transition:{...P.fast,opacity:{duration:.12}},className:`min-w-0 px-2 sm:px-3 text-left text-[12px] leading-snug text-destructive`}),children:Oe},`ft-error`)]}),(0,$.jsx)(`div`,{className:`relative flex items-center gap-2`,children:(0,$.jsxs)(ne,{mode:`popLayout`,initial:!1,children:[et&&(0,$.jsx)(x.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...P.fast,opacity:{duration:.1}},children:(0,$.jsx)(F,{variant:`ghost`,size:`sm`,trailingIcon:I,onClick:ze,className:`pr-3 sm:pr-[6px]`,children:m})},`cancel`),tt&&(0,$.jsx)(x.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...P.fast,opacity:{duration:.1}},children:(0,$.jsx)(F,{variant:`ghost`,size:`sm`,trailingIcon:I,onClick:Re,className:`pr-3 sm:pr-[6px]`,children:d})},`skip`),nt&&(0,$.jsx)(x.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...P.fast,opacity:{duration:.1}},children:(0,$.jsx)(F,{variant:`primary`,size:`sm`,onClick:W?Le:Be,disabled:(W||K.length===0)&&q.trim().length===0,className:`pr-3 sm:pr-[6px]`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[V.nextLabel??(B>=z-1?`Finish`:`Continue`),(0,$.jsx)(`span`,{className:`hidden sm:contents`,children:(0,$.jsxs)(vi,{shape:M,tone:`inverted`,children:[L?`⌘`:`⌃`,`↵`]})})]})})},`continue`)]})})]})})]})]})});_i.displayName=`AskUserQuestions`;function vi({children:e,tone:t=`muted`,shape:n}){return(0,$.jsx)(`kbd`,{"aria-hidden":!0,suppressHydrationWarning:!0,className:s(`inline-flex items-center justify-center gap-0.5 px-1 min-w-[18px] h-[18px] text-[11px] leading-none font-sans tracking-wide`,t===`inverted`?`bg-background/15 text-background`:`bg-foreground/10 text-muted-foreground`,n.bg),children:e})}function yi({index:e,registerItem:t,role:n,isSelected:r,tabIndex:i,onClick:a,onKeyDown:o,shape:c,chipContent:l,chipFilled:u,isMulti:d,ariaLabel:f,showArrow:p,arrowIcon:m,onArrowClick:h,bodyLayout:g=`inline`,topAlign:_=!1,chipPosition:y=`right`,hiddenControl:b,children:S,...C}){let w=(0,Q.useRef)(null);(0,Q.useEffect)(()=>(t(e,w.current),()=>t(e,null)),[e,t]);let T=(0,$.jsx)(ne,{children:p&&(0,$.jsx)(x.span,{"aria-hidden":!h,role:h?`button`:void 0,onClick:h?e=>{e.stopPropagation(),h()}:void 0,className:s(`absolute inset-0 inline-flex items-center justify-center bg-foreground text-background`,c.bg,h&&`cursor-pointer`),initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:P.fast.exit},transition:{...P.fast,opacity:{duration:.08}},children:m})}),E=(0,$.jsxs)(`span`,{className:s(`shrink-0 w-7 h-7 relative inline-flex items-center justify-center`,_&&(g===`stacked`?`-mt-[1px]`:`-mt-[5px]`)),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:s(`absolute inline-flex items-center justify-center w-5 h-5 text-[11px] transition-[opacity,font-variation-settings] duration-80`,d&&c.bg,d?u?`bg-foreground text-background`:`border border-border text-muted-foreground`:u?`text-foreground`:`text-muted-foreground`,y===`right`&&p&&`opacity-0`),style:{fontVariationSettings:u?v.semibold:v.medium},children:l}),y===`right`&&T]}),D=y===`left`&&!d&&(0,$.jsx)(`span`,{className:s(`shrink-0 w-7 h-7 relative inline-flex items-center justify-center`,_&&(g===`stacked`?`-mt-[1px]`:`-mt-[5px]`)),children:T});return(0,$.jsxs)(`div`,{ref:w,"data-proximity-index":e,"data-state":r?`checked`:`unchecked`,role:n??void 0,"aria-checked":n===`radio`||n===`checkbox`?!!C[`aria-checked`]:void 0,"aria-label":f,tabIndex:i,onMouseDown:e=>{let t=e.target.closest(`button:not([tabindex="-1"]), a[href], input, select, textarea, [tabindex]:not([tabindex="-1"])`);t&&t!==e.currentTarget||(e.preventDefault(),e.currentTarget.focus())},onClick:a,onKeyDown:o,className:s(`relative z-10 flex cursor-pointer select-none outline-none`,y===`left`?`gap-2`:`gap-3`,_?`items-start`:`items-center`,g===`stacked`?`min-h-14 py-2`:`min-h-10 py-1.5`,y===`left`?d?`pl-1.5 pr-3`:`pl-1.5 pr-1.5`:`pl-3 pr-1.5`,c.item),children:[y===`left`&&E,(0,$.jsx)(`span`,{className:s(`min-w-0 flex-1 text-[13px] leading-snug`,g===`stacked`?`flex flex-col gap-0.5`:`inline-flex items-center gap-0`),children:S}),y===`right`?E:D,b]})}function bi(e){if(e.mode===`url`&&`url`in e)return[{id:`__url_confirm__`,title:`Confirm completion`,layout:`stacked`,options:[{id:`confirmed`,title:`I've completed the required action`,description:e.url}],skippable:!1,nextLabel:`Confirm`}];let t=`requestedSchema`in e?e.requestedSchema:void 0;if(!t||t.type!==`object`||!t.properties)return[{id:`__freeform__`,title:`Your response`,freeText:!0,freeTextPlaceholder:`Type your response…`,skippable:!1}];let n=t.properties,r=t.required??[];return Object.entries(n).map(([e,t])=>{let n=t,i=r.includes(e),a=n.title||e,o=n.description,s=n.type||`string`,c=Yt(n),l=Xt(n),u=Array.isArray(n.enum),d=s===`array`&&Array.isArray(n.items?.enum),f=s===`array`&&l.length>0,p={id:e,title:a,skippable:!i,layout:o&&o.length>60?`stacked`:`inline`};if(s===`boolean`)return{...p,options:[{id:`true`,title:`Yes`},{id:`false`,title:`No`}]};if(f||d){let e=f?l:n.items.enum.map(e=>({const:e,title:e}))??[];return{...p,multiSelect:!0,options:e.map(e=>({id:e.const,title:e.title||e.const}))}}if(c.length>0)return{...p,layout:`stacked`,options:c.map(e=>({id:e.const,title:e.title||e.const}))};if(u){let e=n.enum,t=n.enumNames;return{...p,options:e.map((e,n)=>({id:e,title:t?.[n]||e}))}}return s===`number`||s===`integer`?{...p,freeText:!0,freeTextMultiline:!1,freeTextPlaceholder:n.default===void 0?`Enter a number…`:String(n.default),freeTextValidate:e=>{let t=e.trim();if(!t)return i?`Required`:null;let n=s===`integer`?parseInt(t,10):parseFloat(t);return Number.isNaN(n)?`Enter a valid number`:null}}:s===`string`&&(n.format===`textarea`||(n.maxLength??0)>100)?{...p,freeText:!0,freeTextPlaceholder:n.default||`Type your answer…`}:{...p,freeText:!0,freeTextMultiline:!1,freeTextPlaceholder:n.default===void 0?`Type your answer…`:String(n.default),freeTextValidate:e=>!e.trim()&&i?`Required`:null}})}function xi(e,t,n){if(n.mode===`url`)return{};let r=`requestedSchema`in n?n.requestedSchema:void 0,i=r?.type===`object`&&r.properties?r.properties:{},a={};for(let n of e){let e=n.id??``;if(e===`__freeform__`){let n=t[e]?.otherText?.trim();n&&(a.response=n);continue}let r=t[e];if(!r||r.skipped)continue;let o=i[e]?.type||`string`;if(n.freeText){let t=r.otherText?.trim()??``;if(!t)continue;a[e]=o===`number`||o===`integer`?o===`integer`?parseInt(t,10):parseFloat(t):t;continue}if(n.multiSelect){a[e]=r.selectedIds;continue}if(o===`boolean`){a[e]=r.selectedIds[0]===`true`;continue}r.selectedIds[0]!==void 0&&(a[e]=r.selectedIds[0])}return a}function Si(e,t,n){if(n.mode===`url`)return[];let r=`requestedSchema`in n?n.requestedSchema:void 0;return(r?.type===`object`?r.required??[]:[]).filter(n=>{let r=t[n];if(!r||r.skipped)return!0;let i=e.find(e=>e.id===n);return i?i.freeText?!r.otherText?.trim():(i.multiSelect,r.selectedIds.length===0):!0})}function Ci(e,t){if(t.mode===`url`)return{};let n=`requestedSchema`in t?t.requestedSchema:void 0,r=n?.type===`object`&&n.properties?n.properties:{},i={};for(let t of e){let e=t.id;if(!e||e.startsWith(`__`))continue;let n=r[e];if(!(!n||n.default===void 0)){if(t.freeText){i[e]={questionId:e,selectedIds:[],otherText:String(n.default),skipped:!1};continue}if(t.multiSelect&&Array.isArray(n.default)){i[e]={questionId:e,selectedIds:n.default.map(String),skipped:!1};continue}if(n.type===`boolean`){i[e]={questionId:e,selectedIds:[String(n.default)],skipped:!1};continue}i[e]={questionId:e,selectedIds:[String(n.default)],skipped:!1}}}return i}function wi({request:e,onApprove:t,onReject:n,testId:r=`inline-elicitation`,actionTestIdPrefix:i=`inline-elicitation`}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(``),l=(0,Q.useMemo)(()=>bi(e.request),[e.request]),u=(0,Q.useMemo)(()=>Ci(l,e.request),[l,e.request]),d=(e.request.mode||`form`)===`url`,f=d&&`url`in e.request?e.request.url:void 0,p=(n,r)=>{o(!0),c(n),t(e.id,r)};return a?(0,$.jsxs)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`${r}-responded`,children:[`Elicitation `,s,` — the tool will continue executing.`]}):(0,$.jsx)(_i,{questions:l,defaultAnswers:u,onComplete:t=>{if(a)return;if(d){if(!t.__url_confirm__?.selectedIds.includes(`confirmed`)){ot.error(`Confirm you've completed the external action`);return}p(`accepted`,{action:`accept`});return}let n=Si(l,t,e.request);if(n.length>0){ot.error(`Missing required fields`,{description:`Please fill in: ${n.join(`, `)}`});return}p(`accepted`,{action:`accept`,content:xi(l,t,e.request)})},intro:(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`p`,{className:`text-foreground/90`,children:e.request.message}),d&&f&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border bg-muted/40 p-2`,children:[(0,$.jsx)(`code`,{className:`flex-1 text-xs font-mono break-all`,children:f}),(0,$.jsxs)(F,{size:`sm`,variant:`outline`,onClick:()=>window.open(f,`_blank`),"data-testid":`${i}-open-url`,children:[(0,$.jsx)(ct,{className:`h-3 w-3 mr-1`}),`Open`]})]})]}),onCancel:()=>n(e.id,`User cancelled elicitation request`),cancelLabel:`Cancel`,footerLeading:(0,$.jsx)(`button`,{type:`button`,className:`shrink-0 cursor-pointer text-[12px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,onClick:()=>p(`declined`,{action:`decline`}),"data-testid":`${i}-decline-button`,children:`Decline`}),className:`w-full max-w-none shadow-lg`,"data-testid":r})}function Ti({requests:e,onApprove:t,onReject:n}){return e.length===0?null:(0,$.jsx)(`div`,{className:`mb-3 space-y-3 pointer-events-auto`,"data-testid":`floating-elicitation-stack`,children:e.map(e=>(0,$.jsx)(x.div,{initial:{opacity:0,y:12,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},transition:P.moderate,children:(0,$.jsx)(wi,{request:e,onApprove:t,onReject:n})},e.id))})}var Ei=`You are a helpful assistant with access to MCP tools. Help users interact with the MCP server.`;function Di(e){let t=e?.trim();return t?t!==Ei:!1}function Oi({value:e,onSave:t,disabled:n,isSaving:r=!1,compact:i=!1}){let[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(e??``),[u,d]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{l(e??``)},[e]);let f=(0,Q.useCallback)(async()=>{d(!0);try{await t(c),o(!1)}finally{d(!1)}},[c,t]),p=r||u,m=Di(e),g=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-system-prompt-button`,onClick:()=>o(!0),disabled:n,className:i?s(`inline-flex h-auto w-auto aspect-square items-center justify-center rounded-full p-2 transition-colors disabled:pointer-events-none disabled:opacity-50`,m?`text-amber-500 dark:text-amber-400`:`text-muted-foreground hover:text-foreground`):s(`inline-flex h-9 items-center justify-center gap-1.5 rounded-full border border-input bg-secondary px-3 text-sm font-medium shadow-xs transition-colors hover:bg-secondary/80 disabled:pointer-events-none disabled:opacity-50`,m?`text-amber-600 dark:text-amber-400`:`text-secondary-foreground`),children:[(0,$.jsx)(rn,{className:`h-4 w-4`}),!i&&(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`System Prompt`})]});return(0,$.jsxs)(Ne,{open:a,onOpenChange:o,children:[i?(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:g,nativeButton:!0}),(0,$.jsx)(N,{side:`top`,children:(0,$.jsx)(`p`,{children:m?`Custom system prompt`:`System Prompt`})})]}):g,(0,$.jsxs)(_e,{className:`sm:max-w-xl`,children:[(0,$.jsx)(Ie,{children:(0,$.jsx)(we,{children:`System Prompt`})}),(0,$.jsx)(qt,{value:c,onChange:e=>l(e.target.value),placeholder:`Describe the assistant's behavior...`,className:`min-h-[160px] text-sm`}),(0,$.jsx)(Te,{children:(0,$.jsxs)(F,{size:`sm`,onClick:f,disabled:p||c===(e??``),className:`gap-1.5`,children:[p?(0,$.jsx)(nt,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(gt,{className:`h-3.5 w-3.5`}),`Save`]})})]})]})}function ki({inputValue:e,isConnected:t,isLoading:n,textareaRef:r,llmConfig:i,promptsDropdownOpen:a,promptFocusedIndex:o,prompts:c,selectedPrompt:l,promptResults:u,attachments:d,tools:f,disabledTools:p,onDisabledToolsChange:m,onInputChange:g,onKeyDown:_,onKeyUp:v,onClick:y,onSendMessage:b,onStopStreaming:x,onConfigDialogOpenChange:S,onPromptSelect:C,onDeletePromptResult:w,onAttachmentAdd:T,onAttachmentRemove:E,hideModelBadge:D,freeTierInfo:k,managedCloudInfo:A,modelBadgeMode:j=`byok`,modelDisplayName:M,followups:P=[],onFollowupSelect:ee,pendingElicitationRequests:te,onApproveElicitation:I,onRejectElicitation:L,systemPromptProvider:R}){let z=e.trim()||u.length>0||d.length>0,B=(te?.length??0)>0,V=i&&(!D||k||A)?(0,$.jsxs)(O,{children:[(0,$.jsx)(h,{render:(0,$.jsx)(tt,{provider:i.provider,model:i.model,displayName:M,mode:j,className:`shrink-0`,onClick:()=>S(!0)}),nativeButton:!0}),(0,$.jsx)(N,{children:(0,$.jsx)(`p`,{children:A||k?`Change model`:`Change API Key`})})]}):null;return(0,$.jsx)(`div`,{className:`w-full flex shrink-0 flex-col items-center px-2 pb-2 pt-0 sm:px-4 sm:pb-2 text-foreground`,children:(0,$.jsxs)(`div`,{className:`relative w-full max-w-3xl backdrop-blur-xl`,children:[B&&I&&L&&(0,$.jsx)(Ti,{requests:te,onApprove:I,onReject:L}),P.length>0&&(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:P.map(e=>(0,$.jsx)(F,{type:`button`,variant:`outline`,size:`sm`,className:`rounded-full`,onClick:()=>ee?.(e),disabled:n||!t,children:e},e))}),(0,$.jsx)(Dr,{isOpen:a,prompts:c,selectedPrompt:l,focusedIndex:o,onPromptSelect:C}),(0,$.jsx)(Er,{promptResults:u,onDeletePromptResult:w}),(0,$.jsx)(Tr,{inputValue:e,isConnected:t,isLoading:n,textareaRef:r,attachments:d,placeholder:`Ask a question or request an action...`,className:s(`bg-white/80 dark:text-white dark:bg-black backdrop-blur-sm border-gray-200 dark:border-zinc-800`,u.length>0&&`pt-16`),tools:f,disabledTools:p,onDisabledToolsChange:m,onInputChange:g,onKeyDown:_,onKeyUp:v,onClick:y,onAttachmentAdd:T,onAttachmentRemove:E,inlineControls:i&&R?(0,$.jsx)(Oi,{compact:!0,value:R.prompt,onSave:R.savePrompt,disabled:!t||n||R.disabled,isSaving:R.isSaving}):null,trailingControls:(0,$.jsxs)($.Fragment,{children:[V,(0,$.jsx)(F,{type:`button`,size:`sm`,className:s(`h-8 w-8 rounded-full p-0`,n&&`animate-spin`,!z&&!n&&`bg-zinc-400`),disabled:!n&&(!z||!t||B),title:n?`Stop streaming`:`Send`,onClick:n?x:b,"data-testid":`chat-send-button`,children:n?(0,$.jsx)(nt,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Ge,{className:`h-3.5 w-3.5`})})]})})]})})}function Ai({serverDisplayName:e,composerNotice:t,quickQuestions:n=[],onQuickQuestionSelect:r,...i}){return(0,$.jsx)(`div`,{className:`flex h-full flex-col items-center justify-center`,children:(0,$.jsxs)(De,{className:`w-full max-w-4xl mx-auto px-2 sm:px-4`,children:[(0,$.jsxs)(`div`,{className:`text-center mb-6 sm:mb-8`,children:[(0,$.jsxs)(`h1`,{className:`text-2xl sm:text-4xl font-light mb-2 dark:text-white`,"data-testid":`chat-landing-header`,children:[`Chat with `,e]}),(0,$.jsx)(`p`,{className:`mx-auto max-w-xl text-sm text-muted-foreground sm:text-base`,"data-testid":`chat-landing-description`,children:`Chat, inspect traces, preview widgets, and more.`})]}),(0,$.jsxs)(`div`,{className:`space-y-6`,children:[t,(0,$.jsx)(ki,{...i}),n.length>0&&(0,$.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2 px-2`,children:n.map(e=>(0,$.jsx)(F,{type:`button`,variant:`outline`,size:`sm`,className:`rounded-full bg-white/70 dark:bg-black/50 text-gray-900 dark:text-white`,onClick:()=>r?.(e),disabled:i.isLoading||!i.isConnected,children:e},e))})]})]})})}function ji({onConfigureClick:e}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-center`,children:[(0,$.jsx)(Ue,{className:`h-12 w-12 text-muted-foreground mb-4`}),(0,$.jsx)(`h3`,{className:`text-lg font-semibold mb-2`,children:`Configure Your LLM Provider`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4 max-w-md`,children:`To start chatting with the MCP server, you need to configure your LLM provider and API key. Your credentials are stored locally and used only for this chat.`}),(0,$.jsxs)(F,{onClick:e,"data-testid":`chat-configure-api-key-button`,children:[(0,$.jsx)(Ve,{className:`h-4 w-4 mr-2`}),`Configure API Key`]})]})}function Mi({children:e,as:t=`p`,className:n,duration:r=2,spread:i=2}){let a=x.create(t),o=(0,Q.useMemo)(()=>e.length*i,[e,i]);return(0,$.jsx)(a,{className:s(`relative inline-block bg-[length:250%_100%,auto] bg-clip-text`,`text-transparent [--base-color:#a1a1aa] [--base-gradient-color:#000]`,`[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--base-gradient-color),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]`,`dark:[--base-color:#71717a] dark:[--base-gradient-color:#ffffff] dark:[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--base-gradient-color),#0000_calc(50%+var(--spread)))]`,n),initial:{backgroundPosition:`100% center`},animate:{backgroundPosition:`0% center`},transition:{repeat:1/0,duration:r,ease:`linear`},style:{"--spread":`${o}px`,backgroundImage:`var(--bg), linear-gradient(var(--base-color), var(--base-color))`},children:e})}function Ni(e){let t=e.match(/```/g);return t&&t.length%2==1?`${e}\n\`\`\``:e}var Pi=(0,Q.memo)(function({content:e,isStreaming:t=!1}){let n=(0,Q.useMemo)(()=>t?Ni(e):e,[e,t]);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Nt,{className:s(`text-[14px] leading-relaxed text-foreground`,`[&_p]:mb-2 [&_p:last-child]:mb-0`,`[&_pre]:my-3 [&_ul]:mb-2 [&_ol]:mb-2`),content:n}),t?(0,$.jsx)(`span`,{className:`inline-block w-0.5 h-[1em] ml-0.5 -mt-1 align-middle bg-foreground/60 animate-pulse`,"aria-hidden":!0}):null]})});function Fi(){let[e,t]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(typeof window>`u`)return;let e=new AbortController,{signal:n}=e,r=()=>{let e=`ontouchstart`in window||navigator.maxTouchPoints>0,n=window.matchMedia(`(pointer: coarse)`).matches;t(e&&n)};return window.matchMedia(`(pointer: coarse)`).addEventListener(`change`,r,{signal:n}),window.addEventListener(`pointerdown`,r,{signal:n}),r(),()=>e.abort()},[]),e}function Ii({size:e}){return(0,$.jsxs)(`svg`,{width:Math.max(16,e*.35),height:Math.max(16,e*.35),viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z`}),(0,$.jsx)(`path`,{d:`M14 3v5h5`})]})}function Li({file:e,size:t,className:n}){let r=o(),i=e.type.startsWith(`image/`),[a,c]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!i){c(null);return}let t=URL.createObjectURL(e);return c(t),()=>URL.revokeObjectURL(t)},[i,e]);let l=i&&!a;return(0,$.jsx)(`div`,{className:s(`relative shrink-0 overflow-hidden bg-accent border border-border`,r.bg,n),style:{width:t,height:t},children:a?(0,$.jsx)(`img`,{src:a,alt:e.name,className:`absolute inset-0 w-full h-full object-cover`}):l?(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,$.jsx)(`div`,{className:`w-6 h-6 rounded-full border-2 border-border border-t-muted-foreground animate-spin`,"aria-label":`Loading preview`,role:`status`})}):(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-muted-foreground`,role:`img`,"aria-label":e.name,children:(0,$.jsx)(Ii,{size:t})})})}var Ri=(0,Q.forwardRef)(({from:e,files:t,thumbnailSize:n=64,time:r,actions:i,children:a,className:c,...l},u)=>{let d=o(),f=e===`user`,p=Fi(),m=f&&r!=null;return(0,$.jsxs)(x.div,{ref:u,layout:`position`,initial:{opacity:0,y:8,scale:.96},animate:{opacity:1,y:0,scale:1},transition:P.moderate,style:{transformOrigin:f?`bottom right`:`bottom left`},className:s(`group flex max-w-[80%] flex-col gap-1.5`,f?`items-end self-end`:`items-start self-start`,c),...l,children:[t&&t.length>0&&(0,$.jsx)(`div`,{className:s(`flex flex-wrap gap-1.5`,f?`justify-end`:`justify-start`),children:t.map((e,t)=>(0,$.jsx)(Li,{file:e,size:n},`${e.name}-${e.size}-${e.lastModified}-${t}`))}),a!=null&&a!==``&&(0,$.jsx)(`div`,{className:s(`py-2 text-[14px] whitespace-pre-wrap break-words`,f?s(d.bg,`px-3.5 text-pretty bg-[color-mix(in_oklab,var(--accent),var(--background)_45%)] text-accent-foreground`):`text-foreground`),children:a}),(m||i!=null)&&(0,$.jsxs)(`div`,{className:s(`flex items-center gap-2 px-1 text-[12px] leading-none text-muted-foreground select-none`,!p&&[`opacity-0 pointer-events-none transition-opacity duration-150`,`group-hover:opacity-100 group-hover:pointer-events-auto`,`group-focus-within:opacity-100 group-focus-within:pointer-events-auto`]),children:[m&&(0,$.jsx)(`span`,{className:`tabular-nums`,children:r}),i!=null&&(0,$.jsx)(`span`,{className:`flex items-center gap-0.5`,children:i})]})]})});Ri.displayName=`ChatMessage`;function zi({text:e}){let[t,n]=(0,Q.useState)(!1);return(0,$.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground flex items-center rounded p-0.5`,onClick:async()=>{await Ct(e),n(!0),setTimeout(()=>n(!1),2e3)},title:`Copy message content`,"data-testid":`copy-button`,children:t?(0,$.jsx)(gt,{className:`h-3.5 w-3.5`}):(0,$.jsx)(et,{className:`h-3.5 w-3.5`})})}function Bi(e,t){let n=e===1?`token`:`tokens`;return`${e.toLocaleString()} ${n} ${t}`}function Vi({variant:e,copyText:t,inputTokens:n,outputTokens:r}){let i=!!t,a=e===`user`&&n!=null?Bi(n,`in`):e===`assistant`&&r!=null?Bi(r,`out`):null;if(!i&&!a)return null;let o=i?(0,$.jsx)(zi,{text:t}):null,s=a?(0,$.jsx)(`span`,{className:`tabular-nums`,title:e===`user`?`Input tokens`:`Output tokens`,"data-testid":e===`user`?`message-input-tokens`:`message-output-tokens`,children:a}):null;return e===`user`?(0,$.jsxs)($.Fragment,{children:[s,o]}):(0,$.jsxs)($.Fragment,{children:[o,s]})}function Hi({content:e,timestamp:t,_isStreaming:n,outputTokens:r}){return!e||e.length===0?null:(0,$.jsxs)(`div`,{"data-testid":`chat-message-assistant`,children:[(0,$.jsx)(Ri,{from:`assistant`,actions:(0,$.jsx)(Vi,{variant:`assistant`,copyText:e,outputTokens:r}),"data-testid":`chat-message-content`,children:(0,$.jsx)(Pi,{content:e,isStreaming:n})}),t!=null&&(0,$.jsx)(`span`,{className:`sr-only`,children:new Date(t).toLocaleTimeString()})]})}function Ui({toolName:e,args:t,result:n,state:r=`result`,partialArgs:i}){let a=r===`call`&&i?i:t,o=()=>{switch(r){case`call`:return(0,$.jsx)(nt,{className:`h-4 w-4 animate-spin text-blue-500 dark:text-blue-400`});case`result`:return(0,$.jsx)(gt,{className:`h-4 w-4 text-emerald-800 dark:text-emerald-400`});case`error`:return(0,$.jsx)(Oe,{className:`h-4 w-4 text-red-500 dark:text-red-400`});default:return(0,$.jsx)(gt,{className:`h-4 w-4 text-emerald-800 dark:text-emerald-400`})}},c=()=>{switch(r){case`call`:return` bg-blue-500/20 dark:bg-blue-500/20`;case`result`:return` bg-emerald-500/20 dark:bg-emerald-500/20`;case`error`:return` bg-red-500/20 dark:bg-red-500/20`;default:return` bg-emerald-500/20 dark:bg-emerald-500/20`}},l=e=>typeof e==`object`?yt(e).preview:String(e);return(0,$.jsxs)(Ke,{children:[(0,$.jsx)(st,{render:(0,$.jsxs)(`div`,{className:`flex max-w-min items-center gap-3 p-1 rounded-full border bg-card hover:bg-accent/50 transition-colors cursor-pointer my-4`,"data-testid":`chat-tool-call-${e}`,children:[(0,$.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-zinc-100 dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-800 flex items-center justify-center shrink-0`,children:(0,$.jsx)(lt,{className:`size-4 text-muted-foreground`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsxs)(`span`,{className:`text-sm font-medium truncate`,children:[e,`(`,Object.keys(a).length>0?(0,$.jsxs)(`span`,{className:`bg-muted-foreground/20 rounded-full px-1.5 mx-1 py-0.5 text-xs`,children:[Object.keys(a).length,` args`]}):``,`)`]})})}),(0,$.jsx)(`div`,{className:s(`w-8 h-8 rounded-full flex items-center justify-center`,c()),"data-testid":`chat-tool-call-status-${r}`,children:o()})]}),nativeButton:!1}),(0,$.jsxs)(Z,{side:`right`,className:`w-[400px] sm:w-[540px] p-4 overflow-y-auto`,"data-testid":`chat-tool-drawer`,children:[(0,$.jsxs)(Je,{children:[(0,$.jsxs)(Xe,{className:`flex items-center gap-2`,children:[(0,$.jsx)(lt,{className:`h-5 w-5`}),`Tool Call Details`]}),(0,$.jsxs)(mt,{className:`flex items-center gap-2`,children:[e,` — `,r,r===`call`&&(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-blue-500 dark:text-blue-400`,children:[(0,$.jsx)(nt,{className:`h-3 w-3 animate-spin`}),`streaming…`]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-6 py-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`Arguments`}),(0,$.jsxs)(`div`,{className:`relative`,"data-testid":`chat-tool-drawer-args`,children:[(0,$.jsx)(`pre`,{className:`text-xs bg-muted/50 rounded-lg p-3 overflow-x-auto border font-mono leading-relaxed max-h-48 whitespace-pre-wrap break-words`,children:l(a)}),(0,$.jsx)(F,{variant:`ghost`,size:`sm`,onClick:()=>Ct(l(a)),className:`absolute top-2 right-2 h-6 w-6 p-0 opacity-70 hover:opacity-100`,title:`Copy arguments`,children:(0,$.jsx)(et,{className:`h-3 w-3`})})]})]}),n&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium mb-2`,children:`Result`}),(0,$.jsx)(`div`,{className:`relative`,"data-testid":`chat-tool-drawer-result`,children:typeof n==`string`?(0,$.jsxs)(`div`,{className:s(`p-3 rounded-lg border text-sm leading-relaxed max-h-48 overflow-x-auto whitespace-pre-wrap break-words max-w-full`,r===`error`?`bg-destructive/10 border-destructive/20 text-destructive-foreground`:`bg-muted/30 border-border`),children:[n.startsWith(`Error`)?(0,$.jsxs)(`div`,{className:`font-mono`,children:[(0,$.jsx)(`div`,{className:`font-semibold text-destructive mb-1`,children:`Error:`}),(0,$.jsx)(`div`,{className:`whitespace-pre-wrap break-words`,children:n.replace(/^Error:\s*/,``)})]}):(0,$.jsx)(`div`,{className:`whitespace-pre-wrap font-mono break-words`,children:n}),(0,$.jsx)(F,{variant:`ghost`,size:`sm`,onClick:()=>Ct(n),className:`absolute top-2 right-2 h-6 w-6 p-0 opacity-70 hover:opacity-100`,title:`Copy result`,children:(0,$.jsx)(et,{className:`h-3 w-3`})})]}):(0,$.jsxs)(`div`,{className:s(`p-3 rounded-lg border text-sm leading-relaxed max-h-96 overflow-y-auto max-w-full`,r===`error`?`bg-destructive/10 border-destructive/20 text-destructive-foreground`:`bg-muted/30 border-border`),children:[(0,$.jsx)(We,{data:n,filename:`tool-call-${e}-result-${Date.now()}.json`}),(0,$.jsx)(F,{variant:`ghost`,size:`sm`,onClick:()=>Ct(JSON.stringify(n,null,2)),className:`absolute top-2 right-2 h-6 w-6 p-0 opacity-70 hover:opacity-100`,title:`Copy result`,children:(0,$.jsx)(et,{className:`h-3 w-3`})})]})})]})]})]})]})}function Wi({widgetId:e}){let{getWidget:t}=it(),n=t(e)?.modelContext;if(!n?.content?.length&&!n?.structuredContent)return null;let r=n.content?.map(e=>e.text).join(` `)??JSON.stringify(n.structuredContent).slice(0,80);return(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1.5 text-[11px] text-muted-foreground bg-muted/30 border border-border/40 rounded-md mt-1`,children:[(0,$.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-blue-400 shrink-0`}),(0,$.jsx)(`span`,{className:`font-medium`,children:`State synced to model`}),(0,$.jsx)(`span`,{className:`truncate opacity-60 max-w-[300px]`,children:r})]})}function Gi({toolName:e,toolArgs:t,result:n,serverId:r,readResource:i,toolMeta:a,onSendFollowUp:o,partialToolArgs:s,cancelled:c}){let l=(0,Q.useMemo)(()=>`chat-tool-${e}-${Date.now()}-${Math.random().toString(36).substring(2,11)}`,[e]),u=(0,Q.useMemo)(()=>{if(!n)return null;if(typeof n==`string`)try{return JSON.parse(n)}catch{return n}return n},[n]),d=vt(a),f=d?a?.ui?.resourceUri??null:null,p=(0,Q.useMemo)(()=>t,[e,u]),m=(0,Q.useMemo)(()=>u,[e,u]),h=Zt({serverId:r??``,viewId:l,resourceUri:f??``,toolName:e,toolInput:p,toolOutput:m,toolMetadata:a,readResource:i??(async()=>({}))});return d&&f&&r&&i&&h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xt,{viewId:l,toolName:e,toolInput:p,toolOutput:m,partialToolInput:s,cancelled:c,className:`my-4`,onMessage:e=>{e.length>0&&o&&o(e)},...h}),(0,$.jsx)(Wi,{widgetId:l})]}):d&&!f?(0,$.jsx)(`div`,{className:`flex items-center justify-center w-full h-[200px] rounded border`,children:(0,$.jsx)(Ce,{className:`size-5`})}):d&&(!r||!i)?(0,$.jsx)(`div`,{className:`my-4 p-4 bg-red-50/30 dark:bg-red-950/20 border border-red-200/50 dark:border-red-800/50 rounded-lg`,children:(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:`Cannot render widget: Missing required props (serverId or readResource)`})}):null}function Ki(e){let t=atob(e.data),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return new File([n],e.name||`attachment`,{type:e.mimeType})}function qi({content:e,timestamp:t,attachments:n,inputTokens:r}){let i=(0,Q.useMemo)(()=>n?.map(Ki),[n]);return(!e||e.length===0)&&(!n||n.length===0)?null:(0,$.jsx)(`div`,{"data-testid":`chat-message-user`,className:`flex flex-col items-end`,children:(0,$.jsx)(Ri,{from:`user`,files:i,time:t?new Date(t).toLocaleTimeString():void 0,actions:e||r!=null?(0,$.jsx)(Vi,{variant:`user`,copyText:e||void 0,inputTokens:r}):void 0,"data-testid":`chat-message-content`,children:e&&e.length>0?e:void 0})})}var Ji={events:[],spans:[]};function Yi(e){if(!e||typeof e!=`object`)return;let t=e,n=(...e)=>{for(let n of e)if(typeof t[n]==`number`)return t[n]},r=n(`inputTokens`,`input_tokens`,`promptTokens`),i=n(`outputTokens`,`output_tokens`,`completionTokens`),a=n(`totalTokens`,`total_tokens`)??(r!==void 0&&i!==void 0?r+i:void 0);if(!(r===void 0&&i===void 0&&a===void 0))return{inputTokens:r,outputTokens:i,totalTokens:a}}var Xi=new Set([`apikey`,`authorization`,`accesstoken`,`refreshtoken`,`password`,`cookie`,`secret`]);function Zi(e){return Array.isArray(e)?e.map(Zi):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Xi.has(e.toLowerCase().replace(/[_-]/g,``))?`[REDACTED]`:Zi(t)]))}function Qi(e,t=120){let n;try{n=JSON.stringify(e)}catch{n=String(e)}return n.length>t?`${n.slice(0,t)}…`:n}function $i(e){switch(e.type){case`request`:return`LLM request`;case`text-delta`:return e.delta.trim()||`Text delta`;case`tool-call-start`:return e.toolName;case`tool-call-args`:return Qi(e.args);case`tool-result`:return Qi(e.result);case`usage`:return`${e.usage.totalTokens??`?`} tokens`;case`error`:return e.message;case`done`:return`Completed`;default:return e}}function ea(e,t){let n=(e,t)=>e===void 0&&t===void 0?void 0:(e??0)+(t??0);return{inputTokens:n(e?.inputTokens,t.inputTokens),outputTokens:n(e?.outputTokens,t.outputTokens),totalTokens:n(e?.totalTokens,t.totalTokens),cachedInputTokens:n(e?.cachedInputTokens,t.cachedInputTokens),reasoningTokens:n(e?.reasoningTokens,t.reasoningTokens)}}function ta(e,t){let n=e.spans.map(e=>({...e})),r=e.usage,i=[...n].reverse().find(e=>e.kind===`llm`&&e.status===`running`);if(t.type===`request`)n.push({id:`llm-${t.id}`,kind:`llm`,name:`LLM`,status:`running`,startedAt:t.timestamp,preview:$i(t)});else if((t.type===`text-delta`||t.type===`tool-call-start`)&&!i)i={id:`llm-${t.id}`,kind:`llm`,name:`LLM`,status:`running`,startedAt:t.timestamp,preview:t.type===`text-delta`?$i(t):`LLM response`},n.push(i),t.type===`tool-call-start`&&n.push({id:t.toolCallId,kind:`tool`,name:t.toolName,status:`running`,startedAt:t.timestamp,preview:$i(t)});else if(t.type===`tool-call-start`)n.push({id:t.toolCallId,kind:`tool`,name:t.toolName,status:`running`,startedAt:t.timestamp,preview:$i(t)});else if(t.type===`tool-call-args`){let e=n.find(e=>e.id===t.toolCallId);e&&(e.preview=$i(t))}else if(t.type===`tool-result`){let e=t.toolCallId?n.find(e=>e.id===t.toolCallId):[...n].reverse().find(e=>e.kind===`tool`&&e.name===t.toolName&&e.status===`running`);e&&(e.status=t.isError?`error`:`success`,e.endedAt=t.timestamp,e.preview=$i(t))}else t.type===`usage`?(r=ea(r,t.usage),i&&(i.usage=ea(i.usage,t.usage))):(t.type===`error`||t.type===`done`)&&i&&(i.status=t.type===`error`?`error`:`success`,i.endedAt=t.timestamp,i.preview=$i(t));return{events:[...e.events,t],spans:n,usage:r}}function na(e,t){let n=[],r=null;for(let t of e)t.type===`request`?(r&&n.push(r),r={request:t,response:[]}):r&&r.response.push(t);return r&&n.push(r),{turns:n,tokenUsage:t??null}}function ra(e){let t;for(let n of e)n.type===`usage`&&(t=ea(t,n.usage));return t}function ia(e){let t=[],n=0;for(;n<e.length;){if(e[n]?.role!==`user`){n++;continue}let r=e[n].id;n++;let i=null;for(;n<e.length&&e[n]?.role===`assistant`;)i=e[n].id,n++;t.push({userId:r,assistantId:i})}return t}function aa(e,t){let{turns:n}=na(t),r=ia(e),i=new Map,a=Math.min(n.length,r.length);for(let e=0;e<a;e++){let t=ra(n[e].response);if(!t)continue;let{userId:a,assistantId:o}=r[e];t.inputTokens!=null&&i.set(a,{...i.get(a),inputTokens:t.inputTokens}),o!=null&&t.outputTokens!=null&&i.set(o,{...i.get(o),outputTokens:t.outputTokens})}return i}var oa=(0,Q.memo)(({messages:e,isLoading:t,serverId:n,readResource:r,tools:i,sendMessage:a,messagesEndRef:o,traceEvents:s=[]})=>{let c=(0,Q.useMemo)(()=>aa(e,s),[e,s]),l=e=>{let t=e=>e.replace(/-/g,`_`),n=t(e);return i?.find(e=>t(e.name)===n)?._meta},u=e=>vt(l(e)),d=(0,Q.useCallback)(e=>{let t=e.filter(e=>e.type===`text`&&`text`in e).map(e=>e.text).join(`
3
3
  `),n=e.filter(e=>e.type===`image`&&`data`in e&&`mimeType`in e).map(e=>({type:`image`,data:e.data,mimeType:e.mimeType}));a?.(t,n.length>0?n:void 0)},[a]),f=t&&(()=>{if(e.length===0)return!0;let t=e[e.length-1];if(t.role===`user`)return!0;if(t.role===`assistant`){if(t.parts&&t.parts.length>0)return!1;let e=typeof t.content==`string`?t.content:Array.isArray(t.content)?t.content.map(e=>typeof e==`string`?e:e.text||JSON.stringify(e)).join(``):JSON.stringify(t.content);return!(e&&e.trim().length>0)}return!1})(),p=e[e.length-1],m=t&&p?.role===`assistant`,h=e=>{for(let t=e.length-1;t>=0;t--)if(e[t]?.type===`text`)return t;return-1},g=(e,t,n)=>m&&e.id===p?.id&&t===h(n),_=e=>m&&e.id===p?.id;return(0,$.jsxs)(`div`,{className:`space-y-6 max-w-3xl mx-auto px-2`,children:[e.map(e=>{let t=typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.map(e=>typeof e==`string`?e:e.text||JSON.stringify(e)).join(``):JSON.stringify(e.content);if(e.role===`user`)return(0,$.jsx)(qi,{content:t,timestamp:e.timestamp,attachments:e.attachments,inputTokens:c.get(e.id)?.inputTokens},e.id);if(e.role===`assistant`){let i=c.get(e.id)?.outputTokens,a=e.parts&&e.parts.length>0?h(e.parts):-1;return(0,$.jsx)(`div`,{className:`space-y-4`,children:e.parts&&e.parts.length>0?e.parts.map((t,o)=>{let s=t.type===`text`?`${e.id}-text-${o}`:`${e.id}-tool-${t.toolInvocation?.toolName}-${o}`;return t.type===`text`?(0,$.jsx)(Hi,{content:t.text||``,timestamp:o===e.parts.length-1?e.timestamp:void 0,_isStreaming:g(e,o,e.parts),outputTokens:o===a?i:void 0},s):t.type===`tool-invocation`&&t.toolInvocation?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Ui,{toolName:t.toolInvocation.toolName,args:t.toolInvocation.args,result:t.toolInvocation.result,state:t.toolInvocation.state===`error`?`error`:t.toolInvocation.state===`streaming`||t.toolInvocation.state===`pending`?`call`:`result`,partialArgs:t.toolInvocation.partialArgs}),(t.toolInvocation.result||t.toolInvocation.state===`streaming`||u(t.toolInvocation.toolName))&&(0,$.jsx)(`div`,{"data-tool-call-id":`${e.id}-${t.toolInvocation.toolName}-${o}`,children:(0,$.jsx)(Gi,{toolName:t.toolInvocation.toolName,toolArgs:t.toolInvocation.args,result:t.toolInvocation.result||null,serverId:n,readResource:r,toolMeta:l(t.toolInvocation.toolName),onSendFollowUp:d,partialToolArgs:t.toolInvocation.partialArgs,cancelled:t.toolInvocation.state===`error`&&t.toolInvocation.result===`Cancelled by user`})})]},s):null}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hi,{content:t,timestamp:e.timestamp,_isStreaming:_(e),outputTokens:i}),e.toolCalls&&e.toolCalls.length>0&&(0,$.jsx)(`div`,{className:`space-y-2`,children:e.toolCalls.map(t=>{let i=`${e.id}-${t.toolName}-${JSON.stringify(t.args).slice(0,50)}`;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Ui,{toolName:t.toolName,args:t.args,result:t.result,state:t.result?`result`:`call`}),(t.result||u(t.toolName))&&(0,$.jsx)(`div`,{"data-tool-call-id":i,children:(0,$.jsx)(Gi,{toolName:t.toolName,toolArgs:t.args,result:t.result||null,serverId:n,readResource:r,toolMeta:l(t.toolName),onSendFollowUp:d})})]},i)})})]})},e.id)}return null}),f&&(0,$.jsx)(`div`,{className:`flex items-start gap-3`,children:(0,$.jsx)(`div`,{className:`flex-1`,children:(0,$.jsx)(`div`,{className:`rounded-lg p-4 max-w-fit`,children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{className:`text-sm`,children:(0,$.jsx)(Mi,{duration:2,spread:1,children:`Thinking...`})})})})})}),(0,$.jsx)(`div`,{ref:o})]})});function sa({visible:e,onClick:t}){return(0,$.jsx)(`div`,{className:`pointer-events-none absolute bottom-2 left-0 right-0 z-30 flex justify-center`,children:(0,$.jsx)(ne,{children:e&&(0,$.jsx)(x.div,{initial:{opacity:0,y:8,scale:.96},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.96},transition:{duration:.18,ease:`easeOut`},children:(0,$.jsx)(F,{type:`button`,variant:`secondary`,className:`pointer-events-auto size-9 rounded-full border bg-background/95 p-0 shadow-lg backdrop-blur supports-[backdrop-filter]:bg-background/80`,onClick:t,"aria-label":`Scroll to bottom`,title:`Scroll to bottom`,"data-testid":`chat-scroll-to-bottom`,children:(0,$.jsx)(Qt,{className:`size-4`})})})})})}function ca({visible:e}){return(0,$.jsx)(`div`,{"aria-hidden":!0,className:s(`pointer-events-none absolute inset-x-0 top-0 z-[5] h-32 bg-[linear-gradient(to_bottom,var(--background)_0%,var(--background)_24%,transparent_46%)] transition-opacity duration-200 sm:h-36`,e?`opacity-100`:`opacity-0`)})}function la(e,{messageCount:t,isLoading:n,enabled:r=!0}){let i=(0,Q.useRef)(null),[a,o]=(0,Q.useState)(!0),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(!0),u=(0,Q.useRef)({length:0,loading:!1}),d=t>0,f=r&&d&&!a,p=(0,Q.useCallback)(()=>{let t=e.current;if(!t)return;let n=t.scrollHeight-(t.scrollTop+t.clientHeight)<=64;l.current=n,o(n),c(t.scrollTop>8)},[e]),m=(0,Q.useCallback)(t=>{let n=e.current;n&&(n.scrollTo({top:n.scrollHeight,behavior:t}),l.current=!0,o(!0))},[e]);return(0,Q.useEffect)(()=>{if(!r)return;let t=e.current;if(!t)return;p();let n=()=>p();t.addEventListener(`scroll`,n,{passive:!0});let i=typeof ResizeObserver<`u`?new ResizeObserver(()=>p()):null;return i?.observe(t),()=>{t.removeEventListener(`scroll`,n),i?.disconnect()}},[r,p,t,e]),(0,Q.useEffect)(()=>{if(!r||!d||!l.current)return;let e=u.current,i=t!==e.length,a=n!==e.loading;u.current={length:t,loading:n},!(!i&&!a)&&m(n?`auto`:`smooth`)},[r,d,n,t,m]),{messagesEndRef:i,showScrollToBottom:f,showTopFade:s,scrollToBottom:m}}function ua(e){return kt(e)}var da=e=>{let t=[];for(let n of e){if(n.error||n.result?.isError){let e={id:`prompt-error-${n.promptName}-${n.timestamp}`,role:`assistant`,content:n.error||`Prompt execution failed`,timestamp:n.timestamp};t.push(e);continue}let e=n.result;if(e&&`messages`in e&&Array.isArray(e.messages))for(let r of e.messages){let e=``,i=[];if(typeof r.content==`string`)e=r.content;else if(Array.isArray(r.content)){let t=[];for(let e of r.content)e.type===`text`&&e.text?t.push(e.text):e.type===`image`&&e.data?i.push({type:`image`,data:e.data,mimeType:e.mimeType||`image/png`}):e.type===`resource`&&t.push(`[Resource: ${e.resource?.uri||`embedded`}]`);e=t.join(`
4
4
  `)}else r.content&&typeof r.content==`object`&&(r.content.type===`text`&&r.content.text?e=r.content.text:r.content.type===`image`&&r.content.data?i.push({type:`image`,data:r.content.data,mimeType:r.content.mimeType||`image/png`}):e=JSON.stringify(r.content));!e&&i.length===0&&(e=`[no content]`);let a={id:`prompt-${n.promptName}-${n.timestamp}-${t.length}`,role:r.role,content:e||``,timestamp:n.timestamp,attachments:i.length>0?i:void 0};t.push(a)}}return t};function fa({mcpServerUrl:e,llmConfig:t,authConfig:n,mcpAuthTokens:r,isConnected:i,chatApiUrl:a,waitForChatApiUrl:o,widgetModelContexts:s,initialMessages:c,disabledTools:l,streamProtocol:u=`sse`,credentials:d,extraHeaders:f,body:p}){let[m,h]=(0,Q.useState)(c??[]),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)([]),[b,x]=(0,Q.useState)(Ji),[S,C]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(null),E=(0,Q.useRef)(null),D=(0,Q.useRef)(0),O=(0,Q.useCallback)(e=>{let t={...e,id:`trace-${++D.current}`,timestamp:Date.now()};x(e=>ta(e,t))},[]),k=(0,Q.useCallback)(async(c,g,b)=>{let x=[...v,...b??[]];if(!(c.trim()||g.length>0||x.length>0)||!t||!i)return;let S=[...da(g)];if(c.trim()||x.length>0){let e={id:`user-${Date.now()}`,role:`user`,content:c.trim(),timestamp:Date.now(),attachments:x.length>0?x:void 0};S.push(e)}h(e=>[...e,...S]),_(!0),y([]),E.current=new AbortController;try{let i=n,c=n?.type===`bearer`&&!!n.token,g=n?.type===`basic`&&!!(n.username||n.password);if(!c&&!g)if(r?.access_token)i={type:`oauth`,oauthTokens:r};else try{let t=`mcp:auth_${Rt(e)}_tokens`,n=localStorage.getItem(t);if(n){let e=JSON.parse(n);e?.access_token&&(i={type:`oauth`,oauthTokens:e})}}catch(e){console.warn(`Failed to retrieve OAuth tokens:`,e)}let _=[];if(s&&s.size>0){let e=[];for(let[,t]of s)t&&(t.content?.length?e.push(t.content.map(e=>e.text).join(`