import{j as e}from"./vendor-react-RSDKEZ60.js";import{ap as t,aq as s,a0 as r,ar as n,b_ as i,I as a,b$ as o,c0 as c}from"./c818056db-BBpc4u6S.js";import{u as l}from"./vendor-intl-BNW8a19h.js";import{m as u,n as d}from"./vendor-ant-cds-CBh5POw1.js";import{P as h,R as g,C as m,D as f,E as C,V as p}from"./vendor-radix-qP6Vhe7Y.js";const b="_toastAnimation_14na3_2",y=6500;function w({children:t}){const s=l();return e.jsx(h,{swipeDirection:"right",label:s.formatMessage({defaultMessage:"Notification",id:"0V1V61s69r"}),children:t})}function x(){const t=l(),s=a(),r=u();return e.jsx(p,{className:"fixed top-0 z-toast flex flex-col gap-3 p-4 draggable-none pointer-events-none",style:{right:"var(--launch-drawer-width, 0px)",paddingTop:s?`var(--toast-top-offset, ${o+16}px)`:void 0,zIndex:r?d:void 0},label:t.formatMessage({defaultMessage:"Notifications (F8)",id:"1hc+xdSt1a"}),"aria-atomic":void 0})}function v({title:a,message:o,type:c,debugDetails:u,onOpenChange:d,duration:h=6500}){const p=l(),y="warning"===c||"danger"===c?t:s;return e.jsx(g,{duration:h,onOpenChange:d,type:"info"===c?"background":"foreground","aria-atomic":void 0,className:i("flex justify-end",b),children:e.jsxs("div",{"data-color-context":"danger"===c?"danger":"warning"===c?"warning":void 0,className:i("max-w-lg rounded-xl border-0.5 shadow-md p-2 text-sm overflow-hidden bg-bg-000 border-border-100 pointer-events-auto","warning"===c&&"bg-warning-900 border-warning-200","danger"===c&&"bg-danger-900 border-danger-200"),children:[e.jsxs("div",{className:i("flex gap-2 justify-between ml-1","warning"===c&&"text-warning-000","danger"===c&&"text-danger-000"),children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("div",{className:"h-6 flex items-center",children:e.jsx(y,{size:20,alt:p.formatMessage("info"===c?{defaultMessage:"Info",id:"jA0MYgRzao"}:"warning"===c?{defaultMessage:"Warning",id:"3SQit0fJui"}:{defaultMessage:"Error",id:"KN7zKn8z4F"})})}),e.jsxs("div",{className:"mt-0.5 min-w-0 break-words",children:[a&&e.jsx(m,{className:"font-base-bold",children:a}),e.jsx(f,{className:"select-text",children:o})]})]}),e.jsx(C,{asChild:!0,children:e.jsx(r,{variant:"ghost",size:"icon_xs","aria-label":p.formatMessage({defaultMessage:"Close",id:"rbrahOGMC3"}),colorized:!0,children:e.jsx(n,{size:12})})})]}),u&&e.jsx("div",{className:"bg-bg-000 border-border-300 -mx-2 -mb-2 mt-2 rounded-b-lg border-t-0.5 px-3 py-1.5 font-mono text-xs text-text-300",children:u})]})})}class R extends Error{constructor(e){super(e||"Authentication error"),this.name="UnauthedError"}}class N{_socket;_url;onclose;onerror;onmessage;onAuthError;onConnect;constructor(e){this._url=e}start(){if(this._socket)throw new Error("WebSocketClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((e,t)=>{this._socket=new WebSocket(this._url,["mcp"]),this._socket.onerror=e=>{const s="error"in e?e.error:new Error(`WebSocket error: ${JSON.stringify(e)}`);t(s),this.onerror?.(s)},this._socket.onopen=()=>{e()},this._socket.onclose=e=>{this.onclose?.(),e?.reason?.includes("mcp_auth_required")&&this.onerror?.(new R("mcp_auth_required"))},this._socket.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch(i){return void this.onerror?.(i)}const s=t;if("mcp_unauthorized"===s.error_code)return void this.onAuthError?.(new R(s.error||"Authentication required"));let r;try{r=c.parse(t)}catch(i){return void this.onerror?.(i)}const n=r;"connected"===n.method&&n.params?this.onConnect?.(n.params.used_auth):this.onmessage?.(r)}})}async close(){this._socket?.close()}send(e){return new Promise((t,s)=>{this._socket?(this._socket?.send(JSON.stringify(e)),t()):s(new Error("Not connected"))})}}class q{constructor(e,t,s=null){this.getClient=e,this.cachedClient=t,this.disconnectTimeout=s}debouncedDisconnectTimeout=null;inflightRequestCount=0;async refreshClient(){return this.cachedClient=await this.getClient(),this.cachedClient}disconnectIfNoOngoingRequests(){this.cachedClient&&0===this.inflightRequestCount&&(this.cachedClient.close(),this.cachedClient=void 0)}clearTimeout(){this.debouncedDisconnectTimeout&&(clearTimeout(this.debouncedDisconnectTimeout),this.debouncedDisconnectTimeout=null)}beforeRequest(){this.inflightRequestCount++,this.clearTimeout()}afterRequest(){this.inflightRequestCount--,this.clearTimeout(),null!==this.disconnectTimeout&&(this.debouncedDisconnectTimeout=setTimeout(()=>{this.disconnectIfNoOngoingRequests()},this.disconnectTimeout))}async useClient(e){this.beforeRequest();try{const t=void 0!==this.cachedClient?.transport?this.cachedClient:await this.refreshClient();return await e(t)}finally{this.afterRequest()}}async initialize(){await this.refreshClient()}async connect(e){throw await Promise.resolve(),new Error("Cannot call connect on a wrapped client")}async close(){return this.cachedClient?.close()}async registerCapabilities(e){return(await this.refreshClient()).registerCapabilities(e)}getServerCapabilities(){return this.cachedClient?.getServerCapabilities()}getServerVersion(){return this.cachedClient?.getServerVersion()}getInstructions(){return this.cachedClient?.getInstructions()}async ping(e){return(await this.refreshClient()).ping(e)}async complete(e,t){return this.useClient(s=>s.complete(e,t))}async setLoggingLevel(e,t){return this.useClient(s=>s.setLoggingLevel(e,t))}async getPrompt(e,t){return this.useClient(s=>s.getPrompt(e,t))}async listPrompts(e,t){return this.useClient(s=>s.listPrompts(e,t))}async listResources(e,t){return this.useClient(s=>s.listResources(e,t))}async listResourceTemplates(e,t){return this.useClient(s=>s.listResourceTemplates(e,t))}async readResource(e,t){return this.useClient(s=>s.readResource(e,t))}async subscribeResource(e,t){return this.useClient(s=>s.subscribeResource(e,t))}async unsubscribeResource(e,t){return this.useClient(s=>s.unsubscribeResource(e,t))}async callTool(e,t,s){return this.useClient(r=>r.callTool(e,t,s))}async listTools(e,t){return this.useClient(s=>s.listTools(e,t))}async sendRootsListChanged(){return this.useClient(e=>e.sendRootsListChanged())}async request(e,t,s){return this.useClient(r=>r.request(e,t,s))}async notification(e){return this.useClient(t=>t.notification(e))}async setRequestHandler(e,t){return(await this.refreshClient()).setRequestHandler(e,t)}async removeRequestHandler(e){return(await this.refreshClient()).removeRequestHandler(e)}async assertCanSetRequestHandler(e){return(await this.refreshClient()).assertCanSetRequestHandler(e)}async setNotificationHandler(e,t){return(await this.refreshClient()).setNotificationHandler(e,t)}async removeNotificationHandler(e){return(await this.refreshClient()).removeNotificationHandler(e)}async assertCapabilityForMethod(e){return(await this.refreshClient()).assertCapabilityForMethod(e)}async assertNotificationCapability(e){return(await this.refreshClient()).assertNotificationCapability(e)}async assertRequestHandlerCapability(e){return(await this.refreshClient()).assertRequestHandlerCapability(e)}get transport(){return this.cachedClient?.transport}onclose;onerror;fallbackRequestHandler;fallbackNotificationHandler}function _(e,t,s=null){return new q(e,t,s)}export{y as T,R as U,q as W,w as a,v as b,x as c,_ as d,N as e};
