@mcp-use/inspector 20.0.0-beta.7 → 20.0.0-beta.9

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 (59) hide show
  1. package/README.md +2 -18
  2. package/dist/cdn/{ChatTab-DtUGK07C.js → ChatTab-CU-Gf-GY.js} +6 -6
  3. package/dist/cdn/{ConnectionSettingsForm-CNuMa6jp.js → ConnectionSettingsForm-C4fEbp4v.js} +1 -1
  4. package/dist/cdn/{ConnectionSettingsTab-qSVQ1aIF.js → ConnectionSettingsTab-DXUrhGfL.js} +1 -1
  5. package/dist/cdn/{MCPAppsDebugControls-BpP-Ifap.js → MCPAppsDebugControls-Dp_o3k-P.js} +2 -2
  6. package/dist/cdn/{MarkdownRenderer-bX1BrKgI.js → MarkdownRenderer-COhmp4fm.js} +1 -1
  7. package/dist/cdn/{McpAppsViewPanel-jlsYQ7uS.js → McpAppsViewPanel-CMQZ28xs.js} +2 -2
  8. package/dist/cdn/{OAuthCallback--NZdLoWx.js → OAuthCallback-ClEnwZ9o.js} +1 -1
  9. package/dist/cdn/{PromptsTab-BlXDcau3.js → PromptsTab-DPjWr6W0.js} +1 -1
  10. package/dist/cdn/{ResourcesTab-D45_JojP.js → ResourcesTab-D8hOTjDs.js} +5 -5
  11. package/dist/cdn/{SamplingTab-r7tImM6L.js → SamplingTab-e1G8Qx1k.js} +3 -3
  12. package/dist/cdn/{ToolsTab-DOAO8HnS.js → ToolsTab-jNn6Cz6A.js} +5 -5
  13. package/dist/cdn/{ViewPreview-CBhrVdwx.js → ViewPreview-BpQYOKES.js} +2 -2
  14. package/dist/cdn/{dist-SxRsB1iS.js → dist-8Z7HZAGn.js} +2 -2
  15. package/dist/cdn/{index-browser-Dm3R1Mfe.js → index-browser-nWAQnCTk.js} +112 -200
  16. package/dist/cdn/inspector.css +1 -1
  17. package/dist/cdn/inspector.js +5 -5
  18. package/dist/cdn/{react-Bl-hSkvn.js → react-8UPT_kVF.js} +521 -607
  19. package/dist/cdn/{telemetry-TwPKZlFf.js → telemetry-X2tRdL3U.js} +37 -69
  20. package/dist/cdn/{useConfig-leHVjdjl.js → useConfig-BMqxaGDa.js} +2 -2
  21. package/dist/cdn/{useViewHostProps-CDOm2w6u.js → useViewHostProps-DMArgRGs.js} +1 -1
  22. package/dist/cli.js +61 -2
  23. package/dist/client/index.js +2 -7
  24. package/dist/client/telemetry/init.d.ts.map +1 -1
  25. package/dist/server/cdn-shell.d.ts.map +1 -1
  26. package/dist/server/cdn-shell.js +2 -2
  27. package/dist/server/{chunk-5GVQGIAX.js → chunk-3WVGQOQX.js} +1 -1
  28. package/dist/server/{chunk-UZZDBVKF.js → chunk-BIKA6WIX.js} +61 -2
  29. package/dist/server/{chunk-VFVFLXKP.js → chunk-KB6CHWZ4.js} +1 -1
  30. package/dist/server/cli.js +2 -2
  31. package/dist/server/index.js +3 -3
  32. package/dist/server/middleware.js +3 -3
  33. package/dist/server/version.js +1 -1
  34. package/dist/web/assets/{ChatTab-B6ubLbeA.js → ChatTab-fclW7HPg.js} +1 -1
  35. package/dist/web/assets/{ConnectionSettingsTab-Cb2eDgEu.js → ConnectionSettingsTab-DNl63AkH.js} +1 -1
  36. package/dist/web/assets/{ElicitationTab-CbnCrmu9.js → ElicitationTab-B73XazTU.js} +1 -1
  37. package/dist/web/assets/{MCPAppsDebugControls-sRglMhat.js → MCPAppsDebugControls-BYLu5GRy.js} +1 -1
  38. package/dist/web/assets/{ManufactOAuthCallback-D4uYGigW.js → ManufactOAuthCallback-Dp3icsBc.js} +1 -1
  39. package/dist/web/assets/{MarkdownRenderer-Cwxp9fLj.js → MarkdownRenderer-CcvZ7qUS.js} +1 -1
  40. package/dist/web/assets/{McpAppsViewPanel-jQYFoZNX.js → McpAppsViewPanel-KD_ZnjfO.js} +1 -1
  41. package/dist/web/assets/{NotificationsTab-DuSm762_.js → NotificationsTab-CV9kw9j-.js} +1 -1
  42. package/dist/web/assets/{OAuthCallback-VLHlUe2c.js → OAuthCallback-C9J2xEkV.js} +1 -1
  43. package/dist/web/assets/{PromptsTab-DK6XZxR8.js → PromptsTab-irNacYfj.js} +1 -1
  44. package/dist/web/assets/{ResourcesTab-CUE4MAtJ.js → ResourcesTab-C-4Fd-HY.js} +1 -1
  45. package/dist/web/assets/{SamplingTab-BYNkVCTu.js → SamplingTab-B7bM9cnF.js} +1 -1
  46. package/dist/web/assets/{ServerMetadataTab-DWjNFMbq.js → ServerMetadataTab-CnGUw9uD.js} +1 -1
  47. package/dist/web/assets/{ToolsTab-BisWWY2p.js → ToolsTab-DBHJRY9V.js} +2 -2
  48. package/dist/web/assets/{ViewPreview-COrmPpRr.js → ViewPreview-D7NNsxbe.js} +1 -1
  49. package/dist/web/assets/{checkbox-B6dtF73d.js → checkbox-C9WZqT8k.js} +1 -1
  50. package/dist/web/assets/{dist-9Oy7e0v8.js → dist-ChWdPMRV.js} +3 -3
  51. package/dist/web/assets/{index-BMaSsizY.js → index-B5OxiZlj.js} +13 -13
  52. package/dist/web/assets/index-bCIH1Sdx.css +1 -0
  53. package/dist/web/assets/{shared-CFs9CZfB.js → shared-BWLzd0mh.js} +1 -1
  54. package/dist/web/assets/{tabs-subtle-D2XkWhLL.js → tabs-subtle-DkVoZG5s.js} +1 -1
  55. package/dist/web/assets/{useConfig-B6tXvJOb.js → useConfig-CTtYs2lN.js} +1 -1
  56. package/dist/web/assets/{useViewHostProps-DZqOwiAm.js → useViewHostProps-DOJOoXbY.js} +1 -1
  57. package/dist/web/index.html +3 -3
  58. package/package.json +4 -4
  59. package/dist/web/assets/index-D7TVTIt9.css +0 -1
@@ -1,4 +1,4 @@
1
- import{s as e,t}from"./react-CU_d2d5K.js";import{En as n,G as r,Mn as i,Nn as a,Tn as o,Yn as s,a as c,an as l,c as u,d,f,in as p,kn as m,mn as h,n as g,on as _,or as v,pn as y,r as b,s as x,sr as S,t as C,u as w}from"./input-C0OQCUZy.js";import{n as T,t as E}from"./createLucideIcon-BEHeJH0M.js";import{H as D,O,V as k,_ as A,a as ee,c as j,d as M,g as N,h as P,m as F,o as I,s as L,t as R,u as te,v as z}from"./button-C8Xa2k4x.js";import{n as B,t as V}from"./label-CI7JWQOo.js";import{m as H,t as ne}from"./AnimatePresence-FfDQQNFJ.js";import{a as re,c as U,i as ie,n as W,o as G,p as ae,r as K,s as oe,t as q}from"./select-D6jzbLJn.js";import{a as J,c as se,i as ce,l as le,n as ue,o as Y,r as de,s as fe,t as pe}from"./FormContext-sV-yByKz.js";import{t as me}from"./refresh-cw-B5iaAZKn.js";import{A as he,B as ge,Bt as _e,C as ve,D as ye,E as be,F as xe,Ft as Se,G as Ce,Gt as we,H as Te,Ht as Ee,I as De,Jt as Oe,Kt as ke,N as Ae,O as je,Ot as Me,P as Ne,R as Pe,S as Fe,Sn as Ie,T as Le,Tn as Re,Tt as ze,U as Be,Ut as Ve,V as He,Vt as Ue,Wt as We,Xt as Ge,Zt as Ke,_n as qe,a as X,b as Je,bt as Ye,c as Xe,cn as Ze,d as Qe,dn as $e,et,f as Z,fn as tt,g as nt,gn as rt,gt as it,hn as at,i as ot,jt as st,k as ct,l as lt,ln as ut,n as dt,o as ft,ot as pt,p as mt,qt as ht,r as gt,s as _t,sn as vt,tn as yt,u as bt,v as xt,vn as St,wn as Ct,x as wt,y as Tt,yn as Et,yt as Dt}from"./index-BMaSsizY.js";import{a as Ot,c as kt,i as At,n as jt,o as Mt,r as Nt,s as Pt}from"./dist-9Oy7e0v8.js";import{n as Ft,t as It}from"./MarkdownRenderer-Cwxp9fLj.js";import{a as Lt,i as Rt,n as zt,t as Bt}from"./tabs-subtle-D2XkWhLL.js";import{a as Vt,c as Ht,i as Ut,l as Wt,n as Gt,o as Kt,r as qt,s as Jt,t as Yt}from"./useConfig-B6tXvJOb.js";import{t as Xt}from"./textarea-CRTXuRmE.js";import{t as Zt}from"./checkbox-B6dtF73d.js";import{n as Qt,t as $t}from"./schemaHelpers-DLNTQr_6.js";import{t as en}from"./McpAppsViewPanel-jQYFoZNX.js";var tn=E(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),nn=E(`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`}]]),rn=E(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),an=E(`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`}]]),on=E(`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`}]]),sn=E(`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`}]]),cn=E(`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),$=T(),ln=Q.forwardRef(({className:e,children:t,...n},r)=>(0,$.jsx)(`div`,{ref:r,"data-slot":`scroll-area`,className:D(`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})}));ln.displayName=`ScrollArea`;function un({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 ${w}`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full`,children:[(0,$.jsx)(`h2`,{className:d,children:`Chat History`}),(0,$.jsx)(S,{className:`bg-zinc-500/20 text-zinc-600 dark:text-zinc-400 border-transparent`,variant:`outline`,children:e})]})})}function dn({className:e,...t}){return(0,$.jsx)(`div`,{"data-slot":`skeleton`,className:D(`animate-pulse rounded-md bg-muted`,e),...t})}var fn=`New Chat`,pn=`Chat`;function mn(e){return e===`New Chat`||e===`Chat`}var hn=`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.`,gn=[`greeting`,`initiation`,`conversation start`,`introduction to`,`chat session`,`starting a chat`,`beginning of`];function _n(e){return typeof e.content==`string`?e.content.trim():String(e.content??``).trim()}function vn(e){for(let t of e){if(t.role!==`user`)continue;let e=_n(t);if(e)return e}return null}function yn(e){let t=e.toLowerCase();for(let e of gn)if(t.includes(e))return!0;return!1}function bn(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 xn(e){return e.length>60?`${e.substring(0,57)}...`:e}function Sn(e){return e?.model?.trim()?e.provider===`ollama`?!0:!!e.apiKey?.trim():!1}async function Cn(e,t,n){let r=t.trim();if(!r||!Sn(e))return null;if(bn(r))return xn(r);try{let t=(await Ot({config:kt(e.provider,e.model,{apiKey:e.apiKey,temperature:e.temperature,baseUrl:e.baseUrl,maxTokens:128}),messages:[{role:`system`,content:hn},{role:`user`,content:r}],signal:n})).trim();if(!t)return null;let i=xn(t);return i===`Chat`||yn(i)?xn(r):i}catch{return null}}var wn=28,Tn=3,En=.72;function Dn({chatId:e,title:t,className:n,onRevealComplete:r}){let[i,a]=(0,Q.useState)(t),[o,s]=(0,Q.useState)(0),[c,l]=(0,Q.useState)(1),u=(0,Q.useRef)(t),d=(0,Q.useRef)(null),f=(0,Q.useRef)(e);return(0,Q.useEffect)(()=>{if(f.current!==e){f.current=e,u.current=t,d.current=null,a(t),s(0),l(1);return}},[e,t]),(0,Q.useEffect)(()=>{let n=`${e}:${t}`;if(d.current===n){a(t),s(0),l(1);return}let i=u.current,o=mn(i)&&!mn(t)&&t!==i;if(u.current=t,!o){a(t),s(0),l(1);return}d.current=n;let c=0,f=t.length;a(``),s(Tn),l(En);let p,m=()=>{c+=1;let e=f>0?c/f:1;a(t.slice(0,c)),s(Tn*(1-e)),l(En+(1-En)*e),c<f?p=setTimeout(m,wn):r?.()};return p=setTimeout(m,wn),()=>{p&&clearTimeout(p)}},[e,t,r]),(0,$.jsx)(`span`,{className:D(`block truncate transition-[filter,opacity] duration-75`,n),style:{filter:o>0?`blur(${o}px)`:void 0,opacity:c},children:i})}function On({compact:e,hideAgentName:t}){return(0,$.jsxs)(`div`,{className:D(`flex items-center justify-between py-3 gap-2`,e?`px-4`:`px-3 rounded-lg`),children:[(0,$.jsxs)(`div`,{className:D(`flex-1 min-w-0 flex flex-col gap-1`,t?`gap-1.5`:`gap-1`),children:[(0,$.jsx)(dn,{className:`h-4 w-3/4`}),!t&&(0,$.jsx)(dn,{className:`h-3 w-1/2`})]}),(0,$.jsx)(dn,{className:`h-3 w-14 shrink-0`})]})}function kn({chats:e,onDelete:t,onSelect:n,compact:i,hideAgentName:a,isLoading:o,currentChatId:s}){let[c,l]=Q.useState(``),u=e.filter(e=>e.type!==`agent_execution`),d=u.filter(e=>(e.title??``).toLowerCase().includes(c.toLowerCase())),f=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`})},p=e=>(0,$.jsxs)(`div`,{className:D(`flex items-center justify-between py-3 hover:bg-muted/50 transition-colors gap-2 cursor-pointer`,i?`px-4`:`px-3 rounded-lg`,s===e.id&&`bg-muted/50`),children:[(0,$.jsxs)(`div`,{className:D(`flex-1 min-w-0 flex overflow-hidden`,a?`flex-col`:`flex-col gap-1`),children:[(0,$.jsx)(`p`,{className:`text-sm font-medium truncate w-full`,children:(0,$.jsx)(Dn,{chatId:e.id,title:e.title},`${e.id}:${e.title}`)}),!a&&(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:f(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)(r,{className:`absolute left-3 top-2.5 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(C,{placeholder:`Search chats...`,value:c,onChange:e=>l(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&&u.length===0?(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(On,{compact:i,hideAgentName:a}),(0,$.jsx)(On,{compact:i,hideAgentName:a}),(0,$.jsx)(On,{compact:i,hideAgentName:a})]}):u.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)(We,{vertical:!0,noBorder:!0,message:`No chats`,className:`mt-0`})}):d.length===0?null:(0,$.jsx)(`div`,{className:`space-y-1`,children:d.map(e=>n?(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`block w-full text-left group cursor-pointer`,children:p(e)},e.id):(0,$.jsx)(`div`,{className:`block group cursor-pointer`,children:p(e)},e.id))})})]})}var An=20;function jn({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:An*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 Mn({provider:e,open:t,onOpenChange:n,currentChatId:r,container:i,agentId:a,agentDisplayNameFallback:o,onSelectChat:s,variant:c=`drawer`,containerClassName:l,refetchKey:u,refetchInterval:d=!1,onCurrentChatDeleted:f,onDeleteSuccess:p,onDeleteError:m}){let h=(0,Q.useRef)(null),g=(0,Q.useRef)(null),{chats:_,isLoading:v,hasNextPage:y,loadMore:b,deleteChat:x}=jn({provider:e,enabled:t,agentId:a,refetchKey:u,refetchInterval:o?d||3e3:d});(0,Q.useEffect)(()=>{if(!t||!g.current)return;let e=new IntersectionObserver(e=>{e[0]?.isIntersecting&&b()},{threshold:.5});return e.observe(g.current),()=>{e.disconnect()}},[t,y,v,b]);let S=async e=>{try{await x(e),p?.(),e===r&&f?.()}catch(e){console.error(`Failed to delete chat:`,e),m?.(e)}},C=_.map(e=>({...e,title:e.title||`New Chat`,agent_name:e.agent_name??o??`Unknown Agent`})),w=C.filter(e=>e.type!==`agent_execution`).length,T=(0,$.jsx)(kn,{chats:C,onDelete:S,compact:c===`inline`,hideAgentName:!!o,isLoading:v&&_.length===0,currentChatId:r,onSelect:s?e=>{s(e),n(!1)}:void 0}),E=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[(0,$.jsx)(un,{count:w}),(0,$.jsxs)(ln,{ref:h,className:D(`min-h-0 flex-1 w-full pt-14 sm:pt-16 [&_[data-slot=scroll-area-viewport]]:block!`,c===`inline`?`p-0`:`px-3 sm:px-5`),children:[T,y&&(0,$.jsx)(`div`,{ref:g,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)(Ze,{className:`h-4 w-4 animate-spin`}),`Loading more...`]})})]})]});return c===`inline`?(0,$.jsx)(`div`,{className:D(`flex h-full min-h-0 flex-col`,l),children:E}):(0,$.jsx)(Xe,{open:t,onOpenChange:n,children:(0,$.jsx)(lt,{side:`left`,className:`w-[400px] sm:w-[400px] border-zinc-200 p-0 dark:border-zinc-700`,container:i,children:E})})}function Nn({onCollapse:e}){return(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsxs)(R,{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)(nn,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Collapse`})]}),nativeButton:!0}),(0,$.jsx)(b,{side:`right`,children:`Collapse`})]})}var Pn=`mcp-inspector-chats`,Fn=`New Chat`,In=40;function Ln(){try{let e=localStorage.getItem(Pn);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 Rn(e){localStorage.setItem(Pn,JSON.stringify(e))}function zn(){return new Date().toISOString()}function Bn(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>In?`${n.slice(0,In)}…`:n}var Vn=class{saveTimers=new Map;async listChats(e){let{sessions:t}=Ln(),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}=Ln();return t[e]??[]}async createChat(e){let t=Ln(),n=zn(),r={id:crypto.randomUUID(),title:e.title??Fn,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]=[],Rn(t),r}async updateChat(e,t){let n=Ln(),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=zn(),n.sessions[r]=i,Rn(n),i}async deleteChat(e){let t=Ln();t.sessions=t.sessions.filter(t=>t.id!==e),delete t.messages[e],Rn(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=Ln();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=zn(),e.title===Fn){let n=Bn(t);n&&(e.title=n)}r.sessions[i]=e}Rn(r),n()},500);this.saveTimers.set(e,r)})}};function Hn({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&&!mn(o))return;let d=vn(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 Cn(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 Un=[`#e0eaff`,`#f9ffbd`,`#dedede`,`#ffffff`],Wn=[`#27272a`,`#9a9448`,`#3f3f46`,`#18181b`];function Gn(e){return e===`dark`?Wn:Un}var Kn=.54,qn=.4,Jn=`linear-gradient(to top, black 0%, black 12%, rgba(0,0,0,0.55) 38%, transparent 100%)`;function Yn({className:e,children:t,shaderPhase:n=`hidden`,onShaderFadeComplete:r,meshAnimationPaused:i=!1,...a}){let o=(0,Q.useRef)(null),[s,c]=(0,Q.useState)(!1),{resolvedTheme:l}=ct(),u=Gn(l),d=l===`dark`,{paused:f,toggle:p}=Ee(_e),m=f||i;(0,Q.useEffect)(()=>{let e=window.requestAnimationFrame(()=>c(!0));return()=>window.cancelAnimationFrame(e)},[]),(0,Q.useEffect)(()=>{n===`fading`&&!s&&r?.()},[n,s,r]);let h=n!==`hidden`,g=n===`visible`&&s,_=e=>{e.propertyName===`opacity`&&n===`fading`&&r?.()};return(0,$.jsxs)(`div`,{ref:o,className:D(`relative flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,e),...a,children:[h&&(0,$.jsx)(`div`,{className:D(`pointer-events-none absolute inset-x-0 bottom-0 z-0 transition-opacity duration-500`,g?`opacity-100`:`opacity-0`),style:{height:`${Kn*100}%`},"aria-hidden":!0,onTransitionEnd:_,children:(0,$.jsxs)(`div`,{className:D(`absolute inset-0`,s?d?`opacity-90`:`opacity-75`:`opacity-0`),style:{maskImage:Jn,WebkitMaskImage:Jn},children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-[#edf2ff] dark:hidden`}),(0,$.jsx)(Ve,{className:`absolute inset-0 h-full w-full`,colors:[...u],distortion:.8,swirl:.1,grainMixer:0,grainOverlay:d?.12:.3,speed:m?0:qn})]})}),h&&(0,$.jsx)(Ue,{paused:f,onToggle:p,className:`absolute bottom-3 right-3 sm:bottom-5 sm:right-5`}),(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col`,children:t})]})}function Xn(e){return e?e.apiKey===`server-managed`||e.baseUrl?.includes(`/inspector/llm`)===!0:!1}function Zn(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 Qn(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 $n(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 er(e){if(e instanceof Error&&e.name===`LlmRequestError`){let t=e.status??0,n=e.body;return Qn(t,n&&typeof n==`object`&&!Array.isArray(n)?n:void 0)}if(e instanceof Error){let t=$n(e.message);if(t)return Qn(t.status,t.body)}return Zn(e)?{kind:`cloud_unavailable`}:null}function tr(e,t){return Qn(e,t)}var nr=Q.createContext(null);function rr(){let e=Q.useContext(nr);if(!e)throw Error(`Command components must be used within <Command>`);return e}function ir(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}var ar=Q.forwardRef(({className:e,...t},n)=>{let[r,i]=Q.useState(``),[a,o]=Q.useState(null),[s,c]=Q.useState(0),l=Q.useCallback(()=>(c(e=>e+1),()=>c(e=>Math.max(0,e-1))),[]);return(0,$.jsx)(nr.Provider,{value:{search:r,setSearch:i,activeValue:a,setActiveValue:o,visibleCount:s,registerVisible:l},children:(0,$.jsx)(`div`,{ref:n,className:D(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})})});ar.displayName=`Command`;var or=Q.forwardRef(({className:e,...t},n)=>{let{search:r,setSearch:i}=rr();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:D(`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})})});or.displayName=`CommandInput`;var sr=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:D(`max-h-[300px] overflow-y-auto overflow-x-hidden`,e),...t}));sr.displayName=`CommandList`;var cr=Q.forwardRef(({className:e,...t},n)=>{let{visibleCount:r}=rr();return r>0?null:(0,$.jsx)(`div`,{ref:n,className:D(`py-6 text-center text-sm`,e),...t})});cr.displayName=`CommandEmpty`;var lr=Q.forwardRef(({className:e,heading:t,children:n,...r},i)=>(0,$.jsxs)(`div`,{ref:i,className:D(`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]}));lr.displayName=`CommandGroup`;var ur=Q.forwardRef(({className:e,value:t,keywords:n,onSelect:r,disabled:i,onClick:a,...o},s)=>{let{search:c,activeValue:l,setActiveValue:u,registerVisible:d}=rr(),f=Array.isArray(n)?n.join(` `):n,p=ir(f?`${t} ${f}`:t,c),m=l===t;return Q.useLayoutEffect(()=>{if(p)return d()},[p,d]),Q.useEffect(()=>{p&&l===null&&!i&&u(t)},[p,l,i,u,t]),p?(0,$.jsx)(`div`,{ref:s,role:`option`,"aria-selected":m,"data-selected":m,"data-disabled":i,className:D(`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&&u(t),onClick:e=>{a?.(e),i||r?.(t)},...o}):null});ur.displayName=`CommandItem`;var dr=`mcp-inspector-models-cache`,fr=1440*60*1e3;function pr(){try{let e=localStorage.getItem(dr);if(e)return JSON.parse(e)}catch(e){console.error(`Failed to load models cache:`,e)}return{}}function mr(e,t){try{let n=pr();n[e]={models:t,timestamp:Date.now()},localStorage.setItem(dr,JSON.stringify(n))}catch(e){console.error(`Failed to save models cache:`,e)}}function hr(e){try{let t=pr(),n=t[e];if(n){if(Date.now()-n.timestamp<fr)return n.models;delete t[e],localStorage.setItem(dr,JSON.stringify(t))}}catch(e){console.error(`Failed to get cached models:`,e)}return null}function gr(e,t){return!Wt(e)||!t?.trim()?e:`${e}:${e===`ollama`?Pt(t):t.trim().toLowerCase()}`}var _r=`chat-config-source`;function vr(e){return e===`openai`||e===`anthropic`||e===`google`?e:`openrouter`}async function yr(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 br(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 xr(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 Sr(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 Cr(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 wr(e,t){let n;try{n=await fetch(At(e,`/api/tags`),{headers:{...t.trim()?{Authorization:`Bearer ${t.trim()}`}:{}}})}catch(e){throw new Nt(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 Tr({open:e,onOpenChange:t,tempProvider:n,tempModel:r,tempApiKey:i,tempBaseUrl:a,onProviderChange:o,onModelChange:s,onApiKeyChange:c,onBaseUrlChange:l,onSave:u,onClear:d,showClearButton:f=!1,buttonLabel:p=`Configure API Key`,hostedInspector:m=!1,freeTierInfo:h,managedCloudInfo:g,useManagedCloud:_=!1,onSaveManagedCloud:v}){let{resolvedTheme:y}=ct(),b=Gn(y),x=y===`dark`,[S,w]=(0,Q.useState)([]),[T,E]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(null),[A,ee]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(+!_),L=gr(n,a),te=!!(m||h||g),z=!!(g&&F===0);(0,Q.useEffect)(()=>{e&&I(+!_)},[e,_]),(0,Q.useEffect)(()=>{let t=Ht(n),r=Wt(n);if(z||!e||!n||t&&!i.trim()||r&&!a.trim()){w([]),k(null);return}let o=setTimeout(async()=>{let e=hr(L);if(e){w(e),k(null);return}E(!0),k(null);try{let e=[];n===`openai-compatible`?e=await yr(a,i):n===`openai`?e=await br(i):n===`anthropic`?e=await xr(i):n===`google`?e=await Sr(i):n===`openrouter`?e=await Cr(i):n===`ollama`&&(e=await wr(a,i)),mr(L,e),w(e)}catch(e){k(e instanceof Error?e.message:`Failed to fetch models. Please check your API key.`),w([])}finally{E(!1)}},500);return()=>clearTimeout(o)},[i,a,n,e,L,z]);let B=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!e||z){e||(B.current=null);return}let t=B.current;t!==null&&t!==n&&s(``),B.current=n},[n,e,s,z]);let H=Wt(n),ne=!Ht(n),U=e&&(!Ht(n)||!!i.trim())&&(!H||!!a.trim()),G=ne?`API Key (optional)`:`API Key`,ae=ne?n===`ollama`?`Leave empty for local Ollama`:`Enter your API key (optional)`:`Enter your API key`,oe=n===`openai-compatible`?`http://localhost:11434/v1`:Jt(n),J=n===`openai-compatible`?`Base URL of your OpenAI-compatible API. Local servers must have CORS enabled.`:null,se=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.`,ce=g?g.models.reduce((e,t)=>(e[t.provider]||(e[t.provider]=[]),e[t.provider].push(t),e),{}):{},le=g?.models.find(e=>e.id===g.selectedModelId),ue=Object.keys(ce),Y=le?.provider??ue[0]??``,de=Y?ce[Y]??[]:[],fe=!!d&&f&&(!g||F===1),pe=()=>{if(z&&v){v();return}u()},me=z?!!(g?.isLoading||!g?.selectedModelId||g?.models.length===0):Ht(n)&&!i.trim()||H&&!a.trim()||!r.trim();return(0,$.jsx)(Pe,{open:e,onOpenChange:t,children:(0,$.jsxs)(ge,{className:`max-w-md`,"data-testid":`chat-config-dialog`,children:[(0,$.jsxs)(Be,{children:[(0,$.jsx)(Ce,{children:te?`Configure Chat`:`LLM Provider Configuration`}),(0,$.jsx)(He,{children:g?`Pick a Manufact cloud model or bring your own API key.`:h?`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:[h&&(0,$.jsxs)(`button`,{type:`button`,onClick:h.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] dark:bg-background`,"aria-hidden":!0}),(0,$.jsx)(`div`,{className:`absolute inset-0 dark:opacity-90`,children:(0,$.jsx)(Ve,{className:`absolute inset-0 h-full w-full`,colors:[...b],grainOverlay:x?.1:.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-foreground`,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)(gt,{symbolSize:14,textClassName:`text-sm`}),`account`]})]}),(0,$.jsx)(R,{size:`sm`,render:(0,$.jsx)(`span`,{"aria-hidden":`true`}),nativeButton:!1,tabIndex:-1,className:`pointer-events-none shrink-0`,children:`Sign in`})]})]}),g&&(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsxs)(Bt,{selectedIndex:F,onSelect:I,idPrefix:_r,className:`w-fit`,children:[(0,$.jsx)(zt,{index:0,label:`Manufact cloud`}),(0,$.jsx)(zt,{index:1,label:`API key`})]})}),(0,$.jsxs)(`div`,{className:D(`space-y-2`,g&&`!mt-2`),children:[(0,$.jsx)(V,{children:`Provider`}),z?(0,$.jsxs)(q,{value:Y,onValueChange:e=>{let t=g?.models.find(t=>t.provider===e);t&&g?.onModelChange(t.id)},children:[(0,$.jsx)(ie,{className:`rounded-md`,leading:Y?(0,$.jsx)(X,{provider:vr(Y),className:`shrink-0`}):void 0,children:(0,$.jsx)(re,{})}),(0,$.jsx)(W,{children:ue.map(e=>(0,$.jsx)(K,{value:e,label:_t(vr(e)),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:vr(e)}),(0,$.jsx)(`span`,{children:_t(vr(e))})]})},e))})]}):(0,$.jsxs)(q,{value:n,onValueChange:e=>o(e),children:[(0,$.jsx)(ie,{className:`rounded-md`,leading:(0,$.jsx)(X,{provider:n,className:`shrink-0`}),children:(0,$.jsx)(re,{})}),(0,$.jsxs)(W,{children:[(0,$.jsx)(K,{value:`openai`,label:_t(`openai`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`openai`}),(0,$.jsx)(`span`,{children:_t(`openai`)})]})}),(0,$.jsx)(K,{value:`anthropic`,label:_t(`anthropic`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`anthropic`}),(0,$.jsx)(`span`,{children:_t(`anthropic`)})]})}),(0,$.jsx)(K,{value:`google`,label:_t(`google`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`google`}),(0,$.jsx)(`span`,{children:_t(`google`)})]})}),(0,$.jsx)(K,{value:`ollama`,label:_t(`ollama`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`ollama`}),(0,$.jsx)(`span`,{children:_t(`ollama`)})]})}),(0,$.jsx)(K,{value:`openrouter`,label:_t(`openrouter`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`openrouter`}),(0,$.jsx)(`span`,{children:_t(`openrouter`)})]})}),(0,$.jsx)(K,{value:`openai-compatible`,label:_t(`openai-compatible`),children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:_t(`openai-compatible`)})})})]})]})]}),!z&&H&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:`Base URL`}),(0,$.jsx)(C,{value:a,onChange:e=>l(e.target.value),placeholder:oe,"data-testid":`chat-config-base-url-input`}),J&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:J})]}),!z&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:G}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(C,{type:N?`text`:`password`,value:i,onChange:e=>c(e.target.value),placeholder:ae,className:`pr-10`,"data-testid":`chat-config-api-key-input`}),(0,$.jsx)(R,{type:`button`,variant:`ghost`,size:`sm`,className:`absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent`,onClick:()=>P(!N),children:N?(0,$.jsx)(rt,{className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(at,{className:`h-4 w-4 text-muted-foreground`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:se})]}),z?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:`Model`}),g?.isLoading?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Ze,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models…`})]}):de.length>0?(0,$.jsxs)(be,{open:j,modal:!0,onOpenChange:M,children:[(0,$.jsx)(je,{render:(0,$.jsxs)(R,{variant:`outline`,role:`combobox`,"aria-expanded":j,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:le?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{provider:vr(le.provider),className:`shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ft(le.name,le.provider)})]}):`Select a model…`}),(0,$.jsx)(rn,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(ye,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(ar,{children:[(0,$.jsx)(or,{placeholder:`Search models…`,className:`h-9`}),(0,$.jsxs)(sr,{children:[(0,$.jsx)(cr,{children:`No model found.`}),(0,$.jsx)(lr,{children:de.map(e=>(0,$.jsxs)(ur,{value:e.id,keywords:[e.name,e.id,e.provider],onSelect:e=>{g?.onModelChange(e),M(!1)},children:[ft(e.name,e.provider),(0,$.jsx)(Ie,{className:D(`ml-auto h-4 w-4`,g?.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.`})]}):U&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:`Model`}),T?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Ze,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models...`})]}):O?(0,$.jsx)(`div`,{className:`text-sm text-destructive`,children:O}):S.length>0?(0,$.jsxs)(be,{open:A,modal:!0,onOpenChange:ee,children:[(0,$.jsx)(je,{render:(0,$.jsxs)(R,{variant:`outline`,role:`combobox`,"aria-expanded":A,className:`w-full justify-between rounded-md`,"data-testid":`chat-config-model-select`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:r&&(S.find(e=>e.id===r)?.displayName||S.find(e=>e.id===r)?.id)||`Select a model...`}),(0,$.jsx)(rn,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(ye,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(ar,{children:[(0,$.jsx)(or,{placeholder:`Search models...`,className:`h-9`}),(0,$.jsxs)(sr,{children:[(0,$.jsx)(cr,{children:`No model found.`}),(0,$.jsx)(lr,{children:S.map(e=>(0,$.jsxs)(ur,{value:e.id,keywords:e.displayName,onSelect:e=>{s(e===r?``:e),ee(!1)},children:[e.displayName||e.id,(0,$.jsx)(Ie,{className:D(`ml-auto h-4 w-4`,r===e.id?`opacity-100`:`opacity-0`)})]},e.id))})]})]})})]}):(0,$.jsx)(C,{value:r,onChange:e=>s(e.target.value),placeholder:`Enter model name manually`,"data-testid":`chat-config-model-input`})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[fe&&(0,$.jsx)(R,{variant:`outline`,onClick:d,children:`Clear Config`}),(0,$.jsxs)(R,{onClick:pe,disabled:me,className:fe?`ml-auto`:``,"data-testid":`chat-config-save-button`,children:[(0,$.jsx)(ut,{className:`h-4 w-4 mr-2`}),`Save Configuration`]})]})]})]})})}var Er=`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`,Dr=D(Er,`w-fit`),Or=D(Er,`h-9 gap-1.5 px-3`),kr=`chat-view`;function Ar({llmConfig:e,hasMessages:t,configDialogOpen:n,onConfigDialogOpenChange:r,onClearChat:i,tempProvider:a,tempModel:o,tempApiKey:s,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSaveConfig:m,onClearConfig:h,hideConfigButton:_,hostedInspector:v,freeTierInfo:y,managedCloudInfo:x,useManagedCloud:S,onSaveManagedCloud:C,showClearButton:T,clearButtonLabel:E,hideTitle:O,clearButtonHideIcon:k,clearButtonHideShortcut:A,clearButtonVariant:ee,hideClearButton:j,onCopyChat:M,onExportChat:N,activeChatId:P,chatTitle:F,showViewToggle:I,viewIndex:L=0,onViewIndexChange:te,elevatedHeader:z}){return(0,$.jsxs)(`div`,{className:D(`relative flex w-full items-center gap-2 overflow-visible`,w,z?`pointer-events-none absolute top-0 right-0 z-50`:`absolute top-0 right-0 z-10`),children:[(0,$.jsx)(`div`,{className:D(`flex min-w-0 flex-1 items-center`,z&&`pointer-events-auto`),children:!O&&(0,$.jsx)(`h2`,{className:D(`text-[15px] text-foreground [font-variation-settings:'wght'_550,'opsz'_20]`,Dr),children:P?(0,$.jsx)(Dn,{chatId:P,title:F??`Chat`},P):`Chat`})}),I&&te&&(0,$.jsx)(`div`,{className:D(`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)(Bt,{selectedIndex:L,onSelect:te,idPrefix:kr,className:`shrink-0 overflow-visible`,"data-testid":`chat-view-tabs`,children:[(0,$.jsx)(zt,{label:`Conv`,index:0}),(0,$.jsx)(zt,{label:`Raw`,index:1})]})}),(0,$.jsxs)(`div`,{className:D(`ml-auto flex shrink-0 items-center gap-2`,z&&`pointer-events-auto`),children:[!j&&t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[M&&(0,$.jsxs)(R,{"data-testid":`chat-copy-button`,variant:`ghost`,size:`sm`,className:Or,onClick:M,children:[(0,$.jsx)(Et,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Copy`})]}),N&&(0,$.jsxs)(we,{children:[(0,$.jsx)(Oe,{render:(0,$.jsxs)(R,{"data-testid":`chat-export-button`,variant:`ghost`,size:`sm`,className:Or,children:[(0,$.jsx)(St,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Export`})]}),nativeButton:!0}),(0,$.jsxs)(ke,{align:`end`,children:[(0,$.jsx)(ht,{"data-testid":`chat-export-json`,onClick:()=>N(`json`),children:`Export as JSON`}),(0,$.jsx)(ht,{"data-testid":`chat-export-markdown`,onClick:()=>N(`markdown`),children:`Export as Markdown`})]})]}),(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsxs)(R,{variant:ee??`default`,size:`default`,className:`p-2 cursor-pointer ${A?`sm:px-3`:`sm:pr-1 sm:pl-3`}`,onClick:i,children:[!k&&(0,$.jsx)(cn,{className:`h-4 w-4 sm:mr-2`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:E??`New Chat`}),!A&&(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)(b,{children:(0,$.jsx)(`p`,{children:E??`New Chat`})})]})]}),(!_||v||y||x)&&(0,$.jsx)(Tr,{open:n,onOpenChange:r,tempProvider:a,tempModel:o,tempApiKey:s,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSave:m,onClear:h,showClearButton:T??(!!e&&!y&&!x),buttonLabel:e?`Change API Key`:`Configure API Key`,hostedInspector:v,freeTierInfo:y,managedCloudInfo:x,useManagedCloud:S,onSaveManagedCloud:C})]})]})}function jr({tools:e,disabledTools:t,onDisabledToolsChange:n,disabled:r}){let[i,a]=(0,Q.useState)(!1),o=e.length-t.size,s=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(s?new Set(e.map(e=>e.name)):new Set)},[s,e,n]),f=(0,Q.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return e.length===0?null:(0,$.jsxs)(be,{open:i,onOpenChange:a,children:[(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(je,{render:(0,$.jsxs)(R,{variant:`ghost`,size:`sm`,disabled:r,className:D(`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)(Ke,{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)(b,{side:`top`,children:(0,$.jsxs)(`p`,{children:[`Tools (`,o,`/`,e.length,`)`]})})]}),(0,$.jsxs)(ye,{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)(R,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:d,type:`button`,children:s?`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)(Zt,{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 Mr({inputValue:e,isConnected:t,isLoading:n,textareaRef:r,attachments:i,placeholder:a=`Ask a question`,className:o,showAttachButton:s=!0,tools:c,disabledTools:l,onDisabledToolsChange:u,onInputChange:d,onKeyDown:f,onKeyUp:p,onClick:m,onAttachmentAdd:h,onAttachmentRemove:g,inlineControls:_,trailingControls:v}){let y=k(),b=(0,Q.useRef)(null),x=e=>{let t=e.target.files;if(t&&t.length>0)for(let e=0;e<t.length;e++)h(t[e]);b.current&&(b.current.value=``)},S=i.length>0;return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[S&&(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)($e,{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:ve(e.size)})]}),(0,$.jsx)(`button`,{onClick:()=>g(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)(Ge,{className:`h-3 w-3`})})]},t))}),(0,$.jsx)(Xt,{ref:r,value:e,onChange:e=>d(e.target.value),onKeyDown:f,onKeyUp:p,onClick:m,placeholder:t?a:`Server not connected`,className:D(`p-4 min-h-[150px] max-h-[300px]`,y.container,S&&`pt-20`,o),disabled:!t||n,"data-testid":`chat-input`}),(0,$.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,multiple:!0,onChange:x,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:[s&&(0,$.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>b.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)(on,{className:`h-4 w-4`})}),c&&c.length>0&&l&&u&&(0,$.jsx)(jr,{tools:c,disabledTools:l,onDisabledToolsChange:u,disabled:!t||n}),_]}),v?(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:v}):null]})]})}function Nr({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)(R,{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)(vt,{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)(Ge,{className:`h-2.5 w-2.5 text-white`})})]},n))})}function Pr({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)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsxs)(R,{id:`prompt-${n}`,type:`button`,variant:`ghost`,className:D(`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)(vt,{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)(xe,{className:`size-3 text-zinc-600 dark:text-zinc-400`})]})})]}),nativeButton:!0}),(0,$.jsx)(b,{children:e.description})]},n))]})})):null}var Fr=Q.createContext(void 0);function Ir(e=!1){let t=Q.useContext(Fr);if(!t&&!e)throw Error(F(86));return t}var Lr=Q.createContext(void 0);function Rr(){return Q.useContext(Lr)}var zr=[H],Br=Q.forwardRef(function(e,t){let{render:n,className:r,disabled:i,readOnly:o,required:s,onValueChange:c,value:l,defaultValue:u,form:d,name:f,inputRef:p,id:m,style:g,..._}=e,{setTouched:v,setFocused:y,validationMode:b,name:x,disabled:S,state:C,validation:w,setDirty:T,setFilled:E,validityData:D}=Y(),{labelId:O}=de(),{clearErrors:k}=pe(),ee=Ir(!0),j=S||i,M=x??f,N=a(m),[P,F]=B({controlled:l,default:u,name:`RadioGroup`,state:`value`}),[I,L]=Q.useState(!1),R=A((e,t)=>{c?.(e,t),!t.isCanceled&&F(e)}),te=Q.useRef(null),z=Q.useRef(null),V=Q.useRef(null);function H(e){let t;return p&&(typeof p==`function`?t=p(e):p.current=e),z.current=e,w.inputRef.current=e,t}let ne=A((e,t=!1)=>{if(e){if(t){te.current===e&&(te.current=null);return}te.current??=e}}),re=A(e=>{if(!e||e.disabled)return;V.current||=e;let t=z.current;if(e.checked||t==null||t.disabled)return H(e)}),U=A(()=>{let e=z.current;return!e||e.disabled||!e.checked?null:P??null});ce(te,N,P??null,U,!j,f),le(P,()=>{k(M),T(P!==D.initialValue),E(P!=null),w.change(P);let e=V.current;P==null&&e&&!e.disabled&&H(e)});let ie=_[`aria-labelledby`]??O??ee?.legendId,W={...C,disabled:j??!1,required:s??!1,readOnly:o??!1},G=Q.useMemo(()=>({...C,checkedValue:P,disabled:j,form:d,validation:w,name:M,readOnly:o,registerControlRef:ne,registerInputRef:re,required:s,setCheckedValue:R,setTouched:L,touched:I}),[P,j,d,w,C,M,o,ne,re,s,R,L,I]),ae={id:m,role:`radiogroup`,"aria-required":s||void 0,"aria-disabled":j||void 0,"aria-readonly":o||void 0,"aria-labelledby":ie,onFocus(){y(!0)},onBlur(e){h(e.currentTarget,e.relatedTarget)||(v(!0),y(!1),b===`onBlur`&&w.commit(P))},onKeyDownCapture(e){e.key.startsWith(`Arrow`)&&(L(!0),y(!0))}};return(0,$.jsx)(Lr.Provider,{value:G,children:(0,$.jsx)(Rt,{render:n,className:r,style:g,state:W,props:[ae,_,e=>w.getValidationProps(j??!1,e)],refs:[t],stateAttributesMapping:se,enableHomeAndEndKeys:!1,modifierKeys:zr})})}),Vr=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}({}),Hr={checked(e){return e?{[Vr.checked]:``}:{[Vr.unchecked]:``}},...v,...se},Ur=Q.createContext(void 0),Wr=Q.forwardRef(function(e,t){let{render:n,className:r,disabled:o=!1,readOnly:c=!1,required:u=!1,"aria-labelledby":d,value:f,inputRef:m,nativeButton:h=!1,id:g,style:_,...v}=e,y=Rr(),{disabled:b,readOnly:x,required:S,form:C,checkedValue:w,touched:T=!1,validation:E,name:D}=y??{},k=y?.setCheckedValue??j,P=y?.setTouched??j,F=y?.registerControlRef??j,I=y?.registerInputRef??j,{setTouched:R,setFilled:z,state:B,disabled:V}=Y(),H=Tt(),{labelId:ne,getDescriptionProps:re}=de(),ie=V||H.disabled||b||o,W=x||c,G=S||u,ae=C,K=y?w===f:f===``,q=Q.useRef(null),J=Q.useRef(null),se=A(e=>{e&&F(e,ie)}),ce=te(m,J,I);N(()=>{J.current?.checked&&z(!0)},[z]),N(()=>{if(J.current){if(ie&&K){I(null);return}q.current&&F(q.current,ie),I(J.current)}},[K,ie,F,I]);let le=a(),ue=U({id:g,implicit:!1,controlRef:q}),fe=h?void 0:ue,pe=Le(d,ne,J,!h,fe),me={role:`radio`,"aria-checked":K,"aria-required":G||void 0,"aria-readonly":W||void 0,"aria-labelledby":pe,[Lt]:K?``:void 0,id:h?ue: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(O(t)).PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}))},onFocus(e){e.defaultPrevented||ie||W||!T||(J.current?.click(),P(!1))}},{getButtonProps:he,buttonRef:ge}=M({disabled:ie,native:h,composite:!1}),_e={type:`radio`,ref:ce,form:ae,id:fe,name:D,tabIndex:-1,style:D?l:p,"aria-hidden":!0,...f===void 0?L:{value:oe(f)},disabled:ie,checked:K,required:G,readOnly:W,onChange(e){if(e.nativeEvent.defaultPrevented||ie||W||f===void 0)return;let t=i(s,e.nativeEvent);k(f,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=y!==void 0,xe=[t,q,ge,se],Se=[me,v,he,re,E?e=>E.getValidationProps(ie,e):L],Ce=ee(`span`,e,{enabled:!be,state:ve,ref:xe,props:Se,stateAttributesMapping:Hr});return(0,$.jsxs)(Ur.Provider,{value:ye,children:[be?(0,$.jsx)(Re,{tag:`span`,render:n,className:r,style:_,state:ve,refs:xe,props:Se,stateAttributesMapping:Hr}):Ce,(0,$.jsx)(`input`,{..._e,suppressHydrationWarning:!0})]})}),Gr=[];function Kr(e){let{allValues:t=Gr,value:n=Gr,onValueChange:r}=e,i=Q.useRef(n),o=Q.useRef(new Map),[s,c]=Q.useState(`mixed`),l=a(),u=n.length===t.length,d=n.length!==t.length&&n.length>0,f=A(r),p=Q.useCallback(()=>({id:l,indeterminate:d,checked:u,"aria-controls":t.map(e=>`${l}-${e}`).join(` `),onCheckedChange(e,r){let a=i.current,l=t.filter(e=>o.current.get(e)&&a.includes(e)),u=t.filter(e=>!o.current.get(e)||o.current.get(e)&&a.includes(e));if(a.length===u.length||a.length===0){n.length===u.length?f(l,r):f(u,r);return}let d=`mixed`,p=a;s===`mixed`?(d=`on`,p=u):s===`on`&&(d=`off`,p=l),f(p,r),r.isCanceled||c(d)}}),[t,u,l,d,f,s,n.length]),m=Q.useCallback(e=>({checked:n.includes(e),onCheckedChange(t,r){let a=n.slice();t?a.push(e):a.splice(a.indexOf(e),1),f(a,r),r.isCanceled||(i.current=a,c(`mixed`))}}),[f,n]);return Q.useMemo(()=>({id:l,indeterminate:d,getParentProps:p,getChildProps:m,disabledStatesRef:o}),[l,d,p,m])}var qr=Q.forwardRef(function(e,t){let{allValues:n,className:r,defaultValue:i,disabled:o=!1,id:s,onValueChange:c,render:l,value:u,style:d,...f}=e,{disabled:p,name:m,state:h,validation:g,setFilled:_,setDirty:v,validityData:y}=Y(),{labelId:b,getDescriptionProps:x}=de(),{clearErrors:S}=pe(),C=p||o,w=Q.useMemo(()=>{if(u===void 0)return i??[]},[u,i]),[T,E]=B({controlled:u,default:w,name:`CheckboxGroup`,state:`value`}),D=A((e,t)=>{c?.(e,t),!t.isCanceled&&E(e)}),O=Kr({allValues:n,value:T,onValueChange:D}),k=a(s),j=Q.useRef(null),M=Q.useCallback(e=>{j.current==null&&e!=null&&!e.hasAttribute(`data-parent`)&&(j.current=e)},[]);ce(j,k,T,void 0,!!m&&!C,m);let N=T??I;le(N,()=>{m&&S(m);let e=Array.isArray(y.initialValue)?y.initialValue:I;_(N.length>0),v(!G(N,e)),g.change(N)});let P={...h,disabled:C},F=Q.useMemo(()=>({allValues:n,value:T,defaultValue:w,setValue:D,parent:O,disabled:C,validation:g,registerControlRef:M}),[n,T,w,D,O,C,g,M]),L=ee(`div`,e,{state:P,ref:t,props:[{id:s,role:`group`,"aria-labelledby":b},f,x],stateAttributesMapping:se});return(0,$.jsx)(xt.Provider,{value:F,children:L})}),Jr=function(e){let t=a(),n=e.controlId===void 0?t:e.controlId,[r,i]=Q.useState(n),[o,s]=Q.useState(e.labelId),[c,l]=Q.useState([]),u=z(()=>new Map),{messageIds:d}=de(),f=A((e,t)=>{let n=u.current;if(t===void 0){n.delete(e);return}n.set(e,t),i(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})}),p=Q.useCallback(e=>{let t=e[`aria-describedby`]?e[`aria-describedby`].split(` `):[];return t.push(...d,...c),{...e,"aria-describedby":Array.from(new Set(t)).join(` `)||void 0}},[d,c]),m=Q.useMemo(()=>({controlId:r,registerControlId:f,labelId:o,setLabelId:s,messageIds:c,setMessageIds:l,getDescriptionProps:p}),[r,f,o,s,c,l,p]);return(0,$.jsx)(ue.Provider,{value:m,children:e.children})};function Yr(e,t){return{...e,state:{...e.state,valid:!t&&e.state.valid}}}var Xr=Object.keys(fe);function Zr(e){if(!e||e.valid||!e.valueMissing)return!1;let t=!1;for(let n of Xr)n!==`valid`&&(n===`valueMissing`?t=e[n]:e[n]&&(t=!1));return t}function Qr(e){let t=null;for(let n of e)if(!n.disabled){if(!n.validity.valid)return n;t??=n}return t}function $r(e,t){let n=!1;for(let r of t)r.setCustomValidity(``),n||=r===e;n||e.setCustomValidity(``)}function ei(e){let{formRef:t}=pe(),{setValidityData:n,validate:r,validityData:i,validationDebounceTime:a,invalid:s,markedDirtyRef:c,state:l,shouldValidateOnChange:u,getRegisteredFieldId:d}=e,{controlId:f,getDescriptionProps:p}=de(),m=o(),h=Q.useRef(null),g=z(()=>new Set).current,_=Q.useRef(0),v=Q.useCallback(e=>{if(e)return g.add(e),()=>{g.delete(e)}},[g]),y=A(async(e,a=!1)=>{let o=Qr(g)??h.current;if(!o)return;_.current+=1;let p=_.current;function v(e,n=s){let r=d()??f;if(r==null)return;let i=t.current.fields.get(r);if(!i)return;let a=Yr(e,n);t.current.fields.set(r,{...i,validityData:a})}if(a){if(l.valid!==!1)return;let t=o.validity;if(!t.valueMissing){let t={value:e,state:{...fe,valid:!0},error:``,errors:[],initialValue:i.initialValue};$r(o,g),v(t,!1),n(t);return}let r=Xr.reduce((e,n)=>(e[n]=t[n],e),{});if(!r.valid&&!Zr(r))return}function y(e){let t=Xr.reduce((t,n)=>(t[n]=e.validity[n],t),{}),n=!1;for(let e of Xr)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}m.clear();let b=null,x=[],S=y(o),C,w=u();if(o.validationMessage&&!w)C=o.validationMessage,x=[o.validationMessage];else{let n=r(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,p!==_.current)return}else b=n;b===null?w&&($r(o,g),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{En as n,G as r,Mn as i,Nn as a,Tn as o,Yn as s,a as c,an as l,c as u,d,f,in as p,kn as m,mn as h,n as g,on as _,or as v,pn as y,r as b,s as x,sr as S,t as C,u as w}from"./input-C0OQCUZy.js";import{n as T,t as E}from"./createLucideIcon-BEHeJH0M.js";import{H as D,O,V as k,_ as A,a as ee,c as j,d as M,g as N,h as P,m as F,o as I,s as L,t as R,u as te,v as z}from"./button-C8Xa2k4x.js";import{n as B,t as V}from"./label-CI7JWQOo.js";import{m as H,t as ne}from"./AnimatePresence-FfDQQNFJ.js";import{a as re,c as U,i as ie,n as W,o as G,p as ae,r as K,s as oe,t as q}from"./select-D6jzbLJn.js";import{a as J,c as se,i as ce,l as le,n as ue,o as Y,r as de,s as fe,t as pe}from"./FormContext-sV-yByKz.js";import{t as me}from"./refresh-cw-B5iaAZKn.js";import{A as he,B as ge,Bt as _e,C as ve,D as ye,E as be,F as xe,Ft as Se,G as Ce,Gt as we,H as Te,Ht as Ee,I as De,Jt as Oe,Kt as ke,N as Ae,O as je,Ot as Me,P as Ne,R as Pe,S as Fe,Sn as Ie,T as Le,Tn as Re,Tt as ze,U as Be,Ut as Ve,V as He,Vt as Ue,Wt as We,Xt as Ge,Zt as Ke,_n as qe,a as X,b as Je,bt as Ye,c as Xe,cn as Ze,d as Qe,dn as $e,et,f as Z,fn as tt,g as nt,gn as rt,gt as it,hn as at,i as ot,jt as st,k as ct,l as lt,ln as ut,n as dt,o as ft,ot as pt,p as mt,qt as ht,r as gt,s as _t,sn as vt,tn as yt,u as bt,v as xt,vn as St,wn as Ct,x as wt,y as Tt,yn as Et,yt as Dt}from"./index-B5OxiZlj.js";import{a as Ot,c as kt,i as At,n as jt,o as Mt,r as Nt,s as Pt}from"./dist-ChWdPMRV.js";import{n as Ft,t as It}from"./MarkdownRenderer-CcvZ7qUS.js";import{a as Lt,i as Rt,n as zt,t as Bt}from"./tabs-subtle-DkVoZG5s.js";import{a as Vt,c as Ht,i as Ut,l as Wt,n as Gt,o as Kt,r as qt,s as Jt,t as Yt}from"./useConfig-CTtYs2lN.js";import{t as Xt}from"./textarea-CRTXuRmE.js";import{t as Zt}from"./checkbox-C9WZqT8k.js";import{n as Qt,t as $t}from"./schemaHelpers-DLNTQr_6.js";import{t as en}from"./McpAppsViewPanel-KD_ZnjfO.js";var tn=E(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),nn=E(`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`}]]),rn=E(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),an=E(`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`}]]),on=E(`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`}]]),sn=E(`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`}]]),cn=E(`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),$=T(),ln=Q.forwardRef(({className:e,children:t,...n},r)=>(0,$.jsx)(`div`,{ref:r,"data-slot":`scroll-area`,className:D(`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})}));ln.displayName=`ScrollArea`;function un({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 ${w}`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-full`,children:[(0,$.jsx)(`h2`,{className:d,children:`Chat History`}),(0,$.jsx)(S,{className:`bg-zinc-500/20 text-zinc-600 dark:text-zinc-400 border-transparent`,variant:`outline`,children:e})]})})}function dn({className:e,...t}){return(0,$.jsx)(`div`,{"data-slot":`skeleton`,className:D(`animate-pulse rounded-md bg-muted`,e),...t})}var fn=`New Chat`,pn=`Chat`;function mn(e){return e===`New Chat`||e===`Chat`}var hn=`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.`,gn=[`greeting`,`initiation`,`conversation start`,`introduction to`,`chat session`,`starting a chat`,`beginning of`];function _n(e){return typeof e.content==`string`?e.content.trim():String(e.content??``).trim()}function vn(e){for(let t of e){if(t.role!==`user`)continue;let e=_n(t);if(e)return e}return null}function yn(e){let t=e.toLowerCase();for(let e of gn)if(t.includes(e))return!0;return!1}function bn(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 xn(e){return e.length>60?`${e.substring(0,57)}...`:e}function Sn(e){return e?.model?.trim()?e.provider===`ollama`?!0:!!e.apiKey?.trim():!1}async function Cn(e,t,n){let r=t.trim();if(!r||!Sn(e))return null;if(bn(r))return xn(r);try{let t=(await Ot({config:kt(e.provider,e.model,{apiKey:e.apiKey,temperature:e.temperature,baseUrl:e.baseUrl,maxTokens:128}),messages:[{role:`system`,content:hn},{role:`user`,content:r}],signal:n})).trim();if(!t)return null;let i=xn(t);return i===`Chat`||yn(i)?xn(r):i}catch{return null}}var wn=28,Tn=3,En=.72;function Dn({chatId:e,title:t,className:n,onRevealComplete:r}){let[i,a]=(0,Q.useState)(t),[o,s]=(0,Q.useState)(0),[c,l]=(0,Q.useState)(1),u=(0,Q.useRef)(t),d=(0,Q.useRef)(null),f=(0,Q.useRef)(e);return(0,Q.useEffect)(()=>{if(f.current!==e){f.current=e,u.current=t,d.current=null,a(t),s(0),l(1);return}},[e,t]),(0,Q.useEffect)(()=>{let n=`${e}:${t}`;if(d.current===n){a(t),s(0),l(1);return}let i=u.current,o=mn(i)&&!mn(t)&&t!==i;if(u.current=t,!o){a(t),s(0),l(1);return}d.current=n;let c=0,f=t.length;a(``),s(Tn),l(En);let p,m=()=>{c+=1;let e=f>0?c/f:1;a(t.slice(0,c)),s(Tn*(1-e)),l(En+(1-En)*e),c<f?p=setTimeout(m,wn):r?.()};return p=setTimeout(m,wn),()=>{p&&clearTimeout(p)}},[e,t,r]),(0,$.jsx)(`span`,{className:D(`block truncate transition-[filter,opacity] duration-75`,n),style:{filter:o>0?`blur(${o}px)`:void 0,opacity:c},children:i})}function On({compact:e,hideAgentName:t}){return(0,$.jsxs)(`div`,{className:D(`flex items-center justify-between py-3 gap-2`,e?`px-4`:`px-3 rounded-lg`),children:[(0,$.jsxs)(`div`,{className:D(`flex-1 min-w-0 flex flex-col gap-1`,t?`gap-1.5`:`gap-1`),children:[(0,$.jsx)(dn,{className:`h-4 w-3/4`}),!t&&(0,$.jsx)(dn,{className:`h-3 w-1/2`})]}),(0,$.jsx)(dn,{className:`h-3 w-14 shrink-0`})]})}function kn({chats:e,onDelete:t,onSelect:n,compact:i,hideAgentName:a,isLoading:o,currentChatId:s}){let[c,l]=Q.useState(``),u=e.filter(e=>e.type!==`agent_execution`),d=u.filter(e=>(e.title??``).toLowerCase().includes(c.toLowerCase())),f=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`})},p=e=>(0,$.jsxs)(`div`,{className:D(`flex items-center justify-between py-3 hover:bg-muted/50 transition-colors gap-2 cursor-pointer`,i?`px-4`:`px-3 rounded-lg`,s===e.id&&`bg-muted/50`),children:[(0,$.jsxs)(`div`,{className:D(`flex-1 min-w-0 flex overflow-hidden`,a?`flex-col`:`flex-col gap-1`),children:[(0,$.jsx)(`p`,{className:`text-sm font-medium truncate w-full`,children:(0,$.jsx)(Dn,{chatId:e.id,title:e.title},`${e.id}:${e.title}`)}),!a&&(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:f(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)(r,{className:`absolute left-3 top-2.5 h-4 w-4 text-muted-foreground`}),(0,$.jsx)(C,{placeholder:`Search chats...`,value:c,onChange:e=>l(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&&u.length===0?(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(On,{compact:i,hideAgentName:a}),(0,$.jsx)(On,{compact:i,hideAgentName:a}),(0,$.jsx)(On,{compact:i,hideAgentName:a})]}):u.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)(We,{vertical:!0,noBorder:!0,message:`No chats`,className:`mt-0`})}):d.length===0?null:(0,$.jsx)(`div`,{className:`space-y-1`,children:d.map(e=>n?(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.id),className:`block w-full text-left group cursor-pointer`,children:p(e)},e.id):(0,$.jsx)(`div`,{className:`block group cursor-pointer`,children:p(e)},e.id))})})]})}var An=20;function jn({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:An*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 Mn({provider:e,open:t,onOpenChange:n,currentChatId:r,container:i,agentId:a,agentDisplayNameFallback:o,onSelectChat:s,variant:c=`drawer`,containerClassName:l,refetchKey:u,refetchInterval:d=!1,onCurrentChatDeleted:f,onDeleteSuccess:p,onDeleteError:m}){let h=(0,Q.useRef)(null),g=(0,Q.useRef)(null),{chats:_,isLoading:v,hasNextPage:y,loadMore:b,deleteChat:x}=jn({provider:e,enabled:t,agentId:a,refetchKey:u,refetchInterval:o?d||3e3:d});(0,Q.useEffect)(()=>{if(!t||!g.current)return;let e=new IntersectionObserver(e=>{e[0]?.isIntersecting&&b()},{threshold:.5});return e.observe(g.current),()=>{e.disconnect()}},[t,y,v,b]);let S=async e=>{try{await x(e),p?.(),e===r&&f?.()}catch(e){console.error(`Failed to delete chat:`,e),m?.(e)}},C=_.map(e=>({...e,title:e.title||`New Chat`,agent_name:e.agent_name??o??`Unknown Agent`})),w=C.filter(e=>e.type!==`agent_execution`).length,T=(0,$.jsx)(kn,{chats:C,onDelete:S,compact:c===`inline`,hideAgentName:!!o,isLoading:v&&_.length===0,currentChatId:r,onSelect:s?e=>{s(e),n(!1)}:void 0}),E=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[(0,$.jsx)(un,{count:w}),(0,$.jsxs)(ln,{ref:h,className:D(`min-h-0 flex-1 w-full pt-14 sm:pt-16 [&_[data-slot=scroll-area-viewport]]:block!`,c===`inline`?`p-0`:`px-3 sm:px-5`),children:[T,y&&(0,$.jsx)(`div`,{ref:g,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)(Ze,{className:`h-4 w-4 animate-spin`}),`Loading more...`]})})]})]});return c===`inline`?(0,$.jsx)(`div`,{className:D(`flex h-full min-h-0 flex-col`,l),children:E}):(0,$.jsx)(Xe,{open:t,onOpenChange:n,children:(0,$.jsx)(lt,{side:`left`,className:`w-[400px] sm:w-[400px] border-zinc-200 p-0 dark:border-zinc-700`,container:i,children:E})})}function Nn({onCollapse:e}){return(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsxs)(R,{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)(nn,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Collapse`})]}),nativeButton:!0}),(0,$.jsx)(b,{side:`right`,children:`Collapse`})]})}var Pn=`mcp-inspector-chats`,Fn=`New Chat`,In=40;function Ln(){try{let e=localStorage.getItem(Pn);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 Rn(e){localStorage.setItem(Pn,JSON.stringify(e))}function zn(){return new Date().toISOString()}function Bn(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>In?`${n.slice(0,In)}…`:n}var Vn=class{saveTimers=new Map;async listChats(e){let{sessions:t}=Ln(),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}=Ln();return t[e]??[]}async createChat(e){let t=Ln(),n=zn(),r={id:crypto.randomUUID(),title:e.title??Fn,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]=[],Rn(t),r}async updateChat(e,t){let n=Ln(),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=zn(),n.sessions[r]=i,Rn(n),i}async deleteChat(e){let t=Ln();t.sessions=t.sessions.filter(t=>t.id!==e),delete t.messages[e],Rn(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=Ln();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=zn(),e.title===Fn){let n=Bn(t);n&&(e.title=n)}r.sessions[i]=e}Rn(r),n()},500);this.saveTimers.set(e,r)})}};function Hn({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&&!mn(o))return;let d=vn(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 Cn(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 Un=[`#e0eaff`,`#f9ffbd`,`#dedede`,`#ffffff`],Wn=[`#27272a`,`#9a9448`,`#3f3f46`,`#18181b`];function Gn(e){return e===`dark`?Wn:Un}var Kn=.54,qn=.4,Jn=`linear-gradient(to top, black 0%, black 12%, rgba(0,0,0,0.55) 38%, transparent 100%)`;function Yn({className:e,children:t,shaderPhase:n=`hidden`,onShaderFadeComplete:r,meshAnimationPaused:i=!1,...a}){let o=(0,Q.useRef)(null),[s,c]=(0,Q.useState)(!1),{resolvedTheme:l}=ct(),u=Gn(l),d=l===`dark`,{paused:f,toggle:p}=Ee(_e),m=f||i;(0,Q.useEffect)(()=>{let e=window.requestAnimationFrame(()=>c(!0));return()=>window.cancelAnimationFrame(e)},[]),(0,Q.useEffect)(()=>{n===`fading`&&!s&&r?.()},[n,s,r]);let h=n!==`hidden`,g=n===`visible`&&s,_=e=>{e.propertyName===`opacity`&&n===`fading`&&r?.()};return(0,$.jsxs)(`div`,{ref:o,className:D(`relative flex min-h-0 flex-1 flex-col overflow-hidden bg-background`,e),...a,children:[h&&(0,$.jsx)(`div`,{className:D(`pointer-events-none absolute inset-x-0 bottom-0 z-0 transition-opacity duration-500`,g?`opacity-100`:`opacity-0`),style:{height:`${Kn*100}%`},"aria-hidden":!0,onTransitionEnd:_,children:(0,$.jsxs)(`div`,{className:D(`absolute inset-0`,s?d?`opacity-90`:`opacity-75`:`opacity-0`),style:{maskImage:Jn,WebkitMaskImage:Jn},children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-[#edf2ff] dark:hidden`}),(0,$.jsx)(Ve,{className:`absolute inset-0 h-full w-full`,colors:[...u],distortion:.8,swirl:.1,grainMixer:0,grainOverlay:d?.12:.3,speed:m?0:qn})]})}),h&&(0,$.jsx)(Ue,{paused:f,onToggle:p,className:`absolute bottom-3 right-3 sm:bottom-5 sm:right-5`}),(0,$.jsx)(`div`,{className:`relative z-10 flex min-h-0 flex-1 flex-col`,children:t})]})}function Xn(e){return e?e.apiKey===`server-managed`||e.baseUrl?.includes(`/inspector/llm`)===!0:!1}function Zn(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 Qn(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 $n(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 er(e){if(e instanceof Error&&e.name===`LlmRequestError`){let t=e.status??0,n=e.body;return Qn(t,n&&typeof n==`object`&&!Array.isArray(n)?n:void 0)}if(e instanceof Error){let t=$n(e.message);if(t)return Qn(t.status,t.body)}return Zn(e)?{kind:`cloud_unavailable`}:null}function tr(e,t){return Qn(e,t)}var nr=Q.createContext(null);function rr(){let e=Q.useContext(nr);if(!e)throw Error(`Command components must be used within <Command>`);return e}function ir(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}var ar=Q.forwardRef(({className:e,...t},n)=>{let[r,i]=Q.useState(``),[a,o]=Q.useState(null),[s,c]=Q.useState(0),l=Q.useCallback(()=>(c(e=>e+1),()=>c(e=>Math.max(0,e-1))),[]);return(0,$.jsx)(nr.Provider,{value:{search:r,setSearch:i,activeValue:a,setActiveValue:o,visibleCount:s,registerVisible:l},children:(0,$.jsx)(`div`,{ref:n,className:D(`flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground`,e),...t})})});ar.displayName=`Command`;var or=Q.forwardRef(({className:e,...t},n)=>{let{search:r,setSearch:i}=rr();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:D(`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})})});or.displayName=`CommandInput`;var sr=Q.forwardRef(({className:e,...t},n)=>(0,$.jsx)(`div`,{ref:n,className:D(`max-h-[300px] overflow-y-auto overflow-x-hidden`,e),...t}));sr.displayName=`CommandList`;var cr=Q.forwardRef(({className:e,...t},n)=>{let{visibleCount:r}=rr();return r>0?null:(0,$.jsx)(`div`,{ref:n,className:D(`py-6 text-center text-sm`,e),...t})});cr.displayName=`CommandEmpty`;var lr=Q.forwardRef(({className:e,heading:t,children:n,...r},i)=>(0,$.jsxs)(`div`,{ref:i,className:D(`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]}));lr.displayName=`CommandGroup`;var ur=Q.forwardRef(({className:e,value:t,keywords:n,onSelect:r,disabled:i,onClick:a,...o},s)=>{let{search:c,activeValue:l,setActiveValue:u,registerVisible:d}=rr(),f=Array.isArray(n)?n.join(` `):n,p=ir(f?`${t} ${f}`:t,c),m=l===t;return Q.useLayoutEffect(()=>{if(p)return d()},[p,d]),Q.useEffect(()=>{p&&l===null&&!i&&u(t)},[p,l,i,u,t]),p?(0,$.jsx)(`div`,{ref:s,role:`option`,"aria-selected":m,"data-selected":m,"data-disabled":i,className:D(`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&&u(t),onClick:e=>{a?.(e),i||r?.(t)},...o}):null});ur.displayName=`CommandItem`;var dr=`mcp-inspector-models-cache`,fr=1440*60*1e3;function pr(){try{let e=localStorage.getItem(dr);if(e)return JSON.parse(e)}catch(e){console.error(`Failed to load models cache:`,e)}return{}}function mr(e,t){try{let n=pr();n[e]={models:t,timestamp:Date.now()},localStorage.setItem(dr,JSON.stringify(n))}catch(e){console.error(`Failed to save models cache:`,e)}}function hr(e){try{let t=pr(),n=t[e];if(n){if(Date.now()-n.timestamp<fr)return n.models;delete t[e],localStorage.setItem(dr,JSON.stringify(t))}}catch(e){console.error(`Failed to get cached models:`,e)}return null}function gr(e,t){return!Wt(e)||!t?.trim()?e:`${e}:${e===`ollama`?Pt(t):t.trim().toLowerCase()}`}var _r=`chat-config-source`;function vr(e){return e===`openai`||e===`anthropic`||e===`google`?e:`openrouter`}async function yr(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 br(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 xr(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 Sr(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 Cr(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 wr(e,t){let n;try{n=await fetch(At(e,`/api/tags`),{headers:{...t.trim()?{Authorization:`Bearer ${t.trim()}`}:{}}})}catch(e){throw new Nt(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 Tr({open:e,onOpenChange:t,tempProvider:n,tempModel:r,tempApiKey:i,tempBaseUrl:a,onProviderChange:o,onModelChange:s,onApiKeyChange:c,onBaseUrlChange:l,onSave:u,onClear:d,showClearButton:f=!1,buttonLabel:p=`Configure API Key`,hostedInspector:m=!1,freeTierInfo:h,managedCloudInfo:g,useManagedCloud:_=!1,onSaveManagedCloud:v}){let{resolvedTheme:y}=ct(),b=Gn(y),x=y===`dark`,[S,w]=(0,Q.useState)([]),[T,E]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(null),[A,ee]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(+!_),L=gr(n,a),te=!!(m||h||g),z=!!(g&&F===0);(0,Q.useEffect)(()=>{e&&I(+!_)},[e,_]),(0,Q.useEffect)(()=>{let t=Ht(n),r=Wt(n);if(z||!e||!n||t&&!i.trim()||r&&!a.trim()){w([]),k(null);return}let o=setTimeout(async()=>{let e=hr(L);if(e){w(e),k(null);return}E(!0),k(null);try{let e=[];n===`openai-compatible`?e=await yr(a,i):n===`openai`?e=await br(i):n===`anthropic`?e=await xr(i):n===`google`?e=await Sr(i):n===`openrouter`?e=await Cr(i):n===`ollama`&&(e=await wr(a,i)),mr(L,e),w(e)}catch(e){k(e instanceof Error?e.message:`Failed to fetch models. Please check your API key.`),w([])}finally{E(!1)}},500);return()=>clearTimeout(o)},[i,a,n,e,L,z]);let B=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!e||z){e||(B.current=null);return}let t=B.current;t!==null&&t!==n&&s(``),B.current=n},[n,e,s,z]);let H=Wt(n),ne=!Ht(n),U=e&&(!Ht(n)||!!i.trim())&&(!H||!!a.trim()),G=ne?`API Key (optional)`:`API Key`,ae=ne?n===`ollama`?`Leave empty for local Ollama`:`Enter your API key (optional)`:`Enter your API key`,oe=n===`openai-compatible`?`http://localhost:11434/v1`:Jt(n),J=n===`openai-compatible`?`Base URL of your OpenAI-compatible API. Local servers must have CORS enabled.`:null,se=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.`,ce=g?g.models.reduce((e,t)=>(e[t.provider]||(e[t.provider]=[]),e[t.provider].push(t),e),{}):{},le=g?.models.find(e=>e.id===g.selectedModelId),ue=Object.keys(ce),Y=le?.provider??ue[0]??``,de=Y?ce[Y]??[]:[],fe=!!d&&f&&(!g||F===1),pe=()=>{if(z&&v){v();return}u()},me=z?!!(g?.isLoading||!g?.selectedModelId||g?.models.length===0):Ht(n)&&!i.trim()||H&&!a.trim()||!r.trim();return(0,$.jsx)(Pe,{open:e,onOpenChange:t,children:(0,$.jsxs)(ge,{className:`max-w-md`,"data-testid":`chat-config-dialog`,children:[(0,$.jsxs)(Be,{children:[(0,$.jsx)(Ce,{children:te?`Configure Chat`:`LLM Provider Configuration`}),(0,$.jsx)(He,{children:g?`Pick a Manufact cloud model or bring your own API key.`:h?`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:[h&&(0,$.jsxs)(`button`,{type:`button`,onClick:h.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] dark:bg-background`,"aria-hidden":!0}),(0,$.jsx)(`div`,{className:`absolute inset-0 dark:opacity-90`,children:(0,$.jsx)(Ve,{className:`absolute inset-0 h-full w-full`,colors:[...b],grainOverlay:x?.1:.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-foreground`,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)(gt,{symbolSize:14,textClassName:`text-sm`}),`account`]})]}),(0,$.jsx)(R,{size:`sm`,render:(0,$.jsx)(`span`,{"aria-hidden":`true`}),nativeButton:!1,tabIndex:-1,className:`pointer-events-none shrink-0`,children:`Sign in`})]})]}),g&&(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsxs)(Bt,{selectedIndex:F,onSelect:I,idPrefix:_r,className:`w-fit`,children:[(0,$.jsx)(zt,{index:0,label:`Manufact cloud`}),(0,$.jsx)(zt,{index:1,label:`API key`})]})}),(0,$.jsxs)(`div`,{className:D(`space-y-2`,g&&`!mt-2`),children:[(0,$.jsx)(V,{children:`Provider`}),z?(0,$.jsxs)(q,{value:Y,onValueChange:e=>{let t=g?.models.find(t=>t.provider===e);t&&g?.onModelChange(t.id)},children:[(0,$.jsx)(ie,{className:`rounded-md`,leading:Y?(0,$.jsx)(X,{provider:vr(Y),className:`shrink-0`}):void 0,children:(0,$.jsx)(re,{})}),(0,$.jsx)(W,{children:ue.map(e=>(0,$.jsx)(K,{value:e,label:_t(vr(e)),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:vr(e)}),(0,$.jsx)(`span`,{children:_t(vr(e))})]})},e))})]}):(0,$.jsxs)(q,{value:n,onValueChange:e=>o(e),children:[(0,$.jsx)(ie,{className:`rounded-md`,leading:(0,$.jsx)(X,{provider:n,className:`shrink-0`}),children:(0,$.jsx)(re,{})}),(0,$.jsxs)(W,{children:[(0,$.jsx)(K,{value:`openai`,label:_t(`openai`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`openai`}),(0,$.jsx)(`span`,{children:_t(`openai`)})]})}),(0,$.jsx)(K,{value:`anthropic`,label:_t(`anthropic`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`anthropic`}),(0,$.jsx)(`span`,{children:_t(`anthropic`)})]})}),(0,$.jsx)(K,{value:`google`,label:_t(`google`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`google`}),(0,$.jsx)(`span`,{children:_t(`google`)})]})}),(0,$.jsx)(K,{value:`ollama`,label:_t(`ollama`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`ollama`}),(0,$.jsx)(`span`,{children:_t(`ollama`)})]})}),(0,$.jsx)(K,{value:`openrouter`,label:_t(`openrouter`),children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{provider:`openrouter`}),(0,$.jsx)(`span`,{children:_t(`openrouter`)})]})}),(0,$.jsx)(K,{value:`openai-compatible`,label:_t(`openai-compatible`),children:(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(`span`,{children:_t(`openai-compatible`)})})})]})]})]}),!z&&H&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:`Base URL`}),(0,$.jsx)(C,{value:a,onChange:e=>l(e.target.value),placeholder:oe,"data-testid":`chat-config-base-url-input`}),J&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:J})]}),!z&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:G}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(C,{type:N?`text`:`password`,value:i,onChange:e=>c(e.target.value),placeholder:ae,className:`pr-10`,"data-testid":`chat-config-api-key-input`}),(0,$.jsx)(R,{type:`button`,variant:`ghost`,size:`sm`,className:`absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent`,onClick:()=>P(!N),children:N?(0,$.jsx)(rt,{className:`h-4 w-4 text-muted-foreground`}):(0,$.jsx)(at,{className:`h-4 w-4 text-muted-foreground`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:se})]}),z?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:`Model`}),g?.isLoading?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Ze,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models…`})]}):de.length>0?(0,$.jsxs)(be,{open:j,modal:!0,onOpenChange:M,children:[(0,$.jsx)(je,{render:(0,$.jsxs)(R,{variant:`outline`,role:`combobox`,"aria-expanded":j,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:le?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{provider:vr(le.provider),className:`shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:ft(le.name,le.provider)})]}):`Select a model…`}),(0,$.jsx)(rn,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(ye,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(ar,{children:[(0,$.jsx)(or,{placeholder:`Search models…`,className:`h-9`}),(0,$.jsxs)(sr,{children:[(0,$.jsx)(cr,{children:`No model found.`}),(0,$.jsx)(lr,{children:de.map(e=>(0,$.jsxs)(ur,{value:e.id,keywords:[e.name,e.id,e.provider],onSelect:e=>{g?.onModelChange(e),M(!1)},children:[ft(e.name,e.provider),(0,$.jsx)(Ie,{className:D(`ml-auto h-4 w-4`,g?.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.`})]}):U&&(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(V,{children:`Model`}),T?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Ze,{className:`h-4 w-4 animate-spin`}),(0,$.jsx)(`span`,{children:`Loading models...`})]}):O?(0,$.jsx)(`div`,{className:`text-sm text-destructive`,children:O}):S.length>0?(0,$.jsxs)(be,{open:A,modal:!0,onOpenChange:ee,children:[(0,$.jsx)(je,{render:(0,$.jsxs)(R,{variant:`outline`,role:`combobox`,"aria-expanded":A,className:`w-full justify-between rounded-md`,"data-testid":`chat-config-model-select`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:r&&(S.find(e=>e.id===r)?.displayName||S.find(e=>e.id===r)?.id)||`Select a model...`}),(0,$.jsx)(rn,{className:`ml-2 h-4 w-4 shrink-0 opacity-50`})]}),nativeButton:!0}),(0,$.jsx)(ye,{className:`w-full p-0`,align:`start`,children:(0,$.jsxs)(ar,{children:[(0,$.jsx)(or,{placeholder:`Search models...`,className:`h-9`}),(0,$.jsxs)(sr,{children:[(0,$.jsx)(cr,{children:`No model found.`}),(0,$.jsx)(lr,{children:S.map(e=>(0,$.jsxs)(ur,{value:e.id,keywords:e.displayName,onSelect:e=>{s(e===r?``:e),ee(!1)},children:[e.displayName||e.id,(0,$.jsx)(Ie,{className:D(`ml-auto h-4 w-4`,r===e.id?`opacity-100`:`opacity-0`)})]},e.id))})]})]})})]}):(0,$.jsx)(C,{value:r,onChange:e=>s(e.target.value),placeholder:`Enter model name manually`,"data-testid":`chat-config-model-input`})]}),(0,$.jsxs)(`div`,{className:`flex justify-between`,children:[fe&&(0,$.jsx)(R,{variant:`outline`,onClick:d,children:`Clear Config`}),(0,$.jsxs)(R,{onClick:pe,disabled:me,className:fe?`ml-auto`:``,"data-testid":`chat-config-save-button`,children:[(0,$.jsx)(ut,{className:`h-4 w-4 mr-2`}),`Save Configuration`]})]})]})]})})}var Er=`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`,Dr=D(Er,`w-fit`),Or=D(Er,`h-9 gap-1.5 px-3`),kr=`chat-view`;function Ar({llmConfig:e,hasMessages:t,configDialogOpen:n,onConfigDialogOpenChange:r,onClearChat:i,tempProvider:a,tempModel:o,tempApiKey:s,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSaveConfig:m,onClearConfig:h,hideConfigButton:_,hostedInspector:v,freeTierInfo:y,managedCloudInfo:x,useManagedCloud:S,onSaveManagedCloud:C,showClearButton:T,clearButtonLabel:E,hideTitle:O,clearButtonHideIcon:k,clearButtonHideShortcut:A,clearButtonVariant:ee,hideClearButton:j,onCopyChat:M,onExportChat:N,activeChatId:P,chatTitle:F,showViewToggle:I,viewIndex:L=0,onViewIndexChange:te,elevatedHeader:z}){return(0,$.jsxs)(`div`,{className:D(`relative flex w-full items-center gap-2 overflow-visible`,w,z?`pointer-events-none absolute top-0 right-0 z-50`:`absolute top-0 right-0 z-10`),children:[(0,$.jsx)(`div`,{className:D(`flex min-w-0 flex-1 items-center`,z&&`pointer-events-auto`),children:!O&&(0,$.jsx)(`h2`,{className:D(`text-[15px] text-foreground [font-variation-settings:'wght'_550,'opsz'_20]`,Dr),children:P?(0,$.jsx)(Dn,{chatId:P,title:F??`Chat`},P):`Chat`})}),I&&te&&(0,$.jsx)(`div`,{className:D(`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)(Bt,{selectedIndex:L,onSelect:te,idPrefix:kr,className:`shrink-0 overflow-visible`,"data-testid":`chat-view-tabs`,children:[(0,$.jsx)(zt,{label:`Conv`,index:0}),(0,$.jsx)(zt,{label:`Raw`,index:1})]})}),(0,$.jsxs)(`div`,{className:D(`ml-auto flex shrink-0 items-center gap-2`,z&&`pointer-events-auto`),children:[!j&&t&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[M&&(0,$.jsxs)(R,{"data-testid":`chat-copy-button`,variant:`ghost`,size:`sm`,className:Or,onClick:M,children:[(0,$.jsx)(Et,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Copy`})]}),N&&(0,$.jsxs)(we,{children:[(0,$.jsx)(Oe,{render:(0,$.jsxs)(R,{"data-testid":`chat-export-button`,variant:`ghost`,size:`sm`,className:Or,children:[(0,$.jsx)(St,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Export`})]}),nativeButton:!0}),(0,$.jsxs)(ke,{align:`end`,children:[(0,$.jsx)(ht,{"data-testid":`chat-export-json`,onClick:()=>N(`json`),children:`Export as JSON`}),(0,$.jsx)(ht,{"data-testid":`chat-export-markdown`,onClick:()=>N(`markdown`),children:`Export as Markdown`})]})]}),(0,$.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsxs)(R,{variant:ee??`default`,size:`default`,className:`p-2 cursor-pointer ${A?`sm:px-3`:`sm:pr-1 sm:pl-3`}`,onClick:i,children:[!k&&(0,$.jsx)(cn,{className:`h-4 w-4 sm:mr-2`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:E??`New Chat`}),!A&&(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)(b,{children:(0,$.jsx)(`p`,{children:E??`New Chat`})})]})]}),(!_||v||y||x)&&(0,$.jsx)(Tr,{open:n,onOpenChange:r,tempProvider:a,tempModel:o,tempApiKey:s,tempBaseUrl:l,onProviderChange:u,onModelChange:d,onApiKeyChange:f,onBaseUrlChange:p,onSave:m,onClear:h,showClearButton:T??(!!e&&!y&&!x),buttonLabel:e?`Change API Key`:`Configure API Key`,hostedInspector:v,freeTierInfo:y,managedCloudInfo:x,useManagedCloud:S,onSaveManagedCloud:C})]})]})}function jr({tools:e,disabledTools:t,onDisabledToolsChange:n,disabled:r}){let[i,a]=(0,Q.useState)(!1),o=e.length-t.size,s=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(s?new Set(e.map(e=>e.name)):new Set)},[s,e,n]),f=(0,Q.useMemo)(()=>[...e].sort((e,t)=>e.name.localeCompare(t.name)),[e]);return e.length===0?null:(0,$.jsxs)(be,{open:i,onOpenChange:a,children:[(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(je,{render:(0,$.jsxs)(R,{variant:`ghost`,size:`sm`,disabled:r,className:D(`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)(Ke,{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)(b,{side:`top`,children:(0,$.jsxs)(`p`,{children:[`Tools (`,o,`/`,e.length,`)`]})})]}),(0,$.jsxs)(ye,{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)(R,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:d,type:`button`,children:s?`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)(Zt,{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 Mr({inputValue:e,isConnected:t,isLoading:n,textareaRef:r,attachments:i,placeholder:a=`Ask a question`,className:o,showAttachButton:s=!0,tools:c,disabledTools:l,onDisabledToolsChange:u,onInputChange:d,onKeyDown:f,onKeyUp:p,onClick:m,onAttachmentAdd:h,onAttachmentRemove:g,inlineControls:_,trailingControls:v}){let y=k(),b=(0,Q.useRef)(null),x=e=>{let t=e.target.files;if(t&&t.length>0)for(let e=0;e<t.length;e++)h(t[e]);b.current&&(b.current.value=``)},S=i.length>0;return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[S&&(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)($e,{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:ve(e.size)})]}),(0,$.jsx)(`button`,{onClick:()=>g(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)(Ge,{className:`h-3 w-3`})})]},t))}),(0,$.jsx)(Xt,{ref:r,value:e,onChange:e=>d(e.target.value),onKeyDown:f,onKeyUp:p,onClick:m,placeholder:t?a:`Server not connected`,className:D(`p-4 min-h-[150px] max-h-[300px]`,y.container,S&&`pt-20`,o),disabled:!t||n,"data-testid":`chat-input`}),(0,$.jsx)(`input`,{ref:b,type:`file`,accept:`image/*`,multiple:!0,onChange:x,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:[s&&(0,$.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>b.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)(on,{className:`h-4 w-4`})}),c&&c.length>0&&l&&u&&(0,$.jsx)(jr,{tools:c,disabledTools:l,onDisabledToolsChange:u,disabled:!t||n}),_]}),v?(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:v}):null]})]})}function Nr({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)(R,{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)(vt,{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)(Ge,{className:`h-2.5 w-2.5 text-white`})})]},n))})}function Pr({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)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsxs)(R,{id:`prompt-${n}`,type:`button`,variant:`ghost`,className:D(`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)(vt,{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)(xe,{className:`size-3 text-zinc-600 dark:text-zinc-400`})]})})]}),nativeButton:!0}),(0,$.jsx)(b,{children:e.description})]},n))]})})):null}var Fr=Q.createContext(void 0);function Ir(e=!1){let t=Q.useContext(Fr);if(!t&&!e)throw Error(F(86));return t}var Lr=Q.createContext(void 0);function Rr(){return Q.useContext(Lr)}var zr=[H],Br=Q.forwardRef(function(e,t){let{render:n,className:r,disabled:i,readOnly:o,required:s,onValueChange:c,value:l,defaultValue:u,form:d,name:f,inputRef:p,id:m,style:g,..._}=e,{setTouched:v,setFocused:y,validationMode:b,name:x,disabled:S,state:C,validation:w,setDirty:T,setFilled:E,validityData:D}=Y(),{labelId:O}=de(),{clearErrors:k}=pe(),ee=Ir(!0),j=S||i,M=x??f,N=a(m),[P,F]=B({controlled:l,default:u,name:`RadioGroup`,state:`value`}),[I,L]=Q.useState(!1),R=A((e,t)=>{c?.(e,t),!t.isCanceled&&F(e)}),te=Q.useRef(null),z=Q.useRef(null),V=Q.useRef(null);function H(e){let t;return p&&(typeof p==`function`?t=p(e):p.current=e),z.current=e,w.inputRef.current=e,t}let ne=A((e,t=!1)=>{if(e){if(t){te.current===e&&(te.current=null);return}te.current??=e}}),re=A(e=>{if(!e||e.disabled)return;V.current||=e;let t=z.current;if(e.checked||t==null||t.disabled)return H(e)}),U=A(()=>{let e=z.current;return!e||e.disabled||!e.checked?null:P??null});ce(te,N,P??null,U,!j,f),le(P,()=>{k(M),T(P!==D.initialValue),E(P!=null),w.change(P);let e=V.current;P==null&&e&&!e.disabled&&H(e)});let ie=_[`aria-labelledby`]??O??ee?.legendId,W={...C,disabled:j??!1,required:s??!1,readOnly:o??!1},G=Q.useMemo(()=>({...C,checkedValue:P,disabled:j,form:d,validation:w,name:M,readOnly:o,registerControlRef:ne,registerInputRef:re,required:s,setCheckedValue:R,setTouched:L,touched:I}),[P,j,d,w,C,M,o,ne,re,s,R,L,I]),ae={id:m,role:`radiogroup`,"aria-required":s||void 0,"aria-disabled":j||void 0,"aria-readonly":o||void 0,"aria-labelledby":ie,onFocus(){y(!0)},onBlur(e){h(e.currentTarget,e.relatedTarget)||(v(!0),y(!1),b===`onBlur`&&w.commit(P))},onKeyDownCapture(e){e.key.startsWith(`Arrow`)&&(L(!0),y(!0))}};return(0,$.jsx)(Lr.Provider,{value:G,children:(0,$.jsx)(Rt,{render:n,className:r,style:g,state:W,props:[ae,_,e=>w.getValidationProps(j??!1,e)],refs:[t],stateAttributesMapping:se,enableHomeAndEndKeys:!1,modifierKeys:zr})})}),Vr=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}({}),Hr={checked(e){return e?{[Vr.checked]:``}:{[Vr.unchecked]:``}},...v,...se},Ur=Q.createContext(void 0),Wr=Q.forwardRef(function(e,t){let{render:n,className:r,disabled:o=!1,readOnly:c=!1,required:u=!1,"aria-labelledby":d,value:f,inputRef:m,nativeButton:h=!1,id:g,style:_,...v}=e,y=Rr(),{disabled:b,readOnly:x,required:S,form:C,checkedValue:w,touched:T=!1,validation:E,name:D}=y??{},k=y?.setCheckedValue??j,P=y?.setTouched??j,F=y?.registerControlRef??j,I=y?.registerInputRef??j,{setTouched:R,setFilled:z,state:B,disabled:V}=Y(),H=Tt(),{labelId:ne,getDescriptionProps:re}=de(),ie=V||H.disabled||b||o,W=x||c,G=S||u,ae=C,K=y?w===f:f===``,q=Q.useRef(null),J=Q.useRef(null),se=A(e=>{e&&F(e,ie)}),ce=te(m,J,I);N(()=>{J.current?.checked&&z(!0)},[z]),N(()=>{if(J.current){if(ie&&K){I(null);return}q.current&&F(q.current,ie),I(J.current)}},[K,ie,F,I]);let le=a(),ue=U({id:g,implicit:!1,controlRef:q}),fe=h?void 0:ue,pe=Le(d,ne,J,!h,fe),me={role:`radio`,"aria-checked":K,"aria-required":G||void 0,"aria-readonly":W||void 0,"aria-labelledby":pe,[Lt]:K?``:void 0,id:h?ue: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(O(t)).PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}))},onFocus(e){e.defaultPrevented||ie||W||!T||(J.current?.click(),P(!1))}},{getButtonProps:he,buttonRef:ge}=M({disabled:ie,native:h,composite:!1}),_e={type:`radio`,ref:ce,form:ae,id:fe,name:D,tabIndex:-1,style:D?l:p,"aria-hidden":!0,...f===void 0?L:{value:oe(f)},disabled:ie,checked:K,required:G,readOnly:W,onChange(e){if(e.nativeEvent.defaultPrevented||ie||W||f===void 0)return;let t=i(s,e.nativeEvent);k(f,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=y!==void 0,xe=[t,q,ge,se],Se=[me,v,he,re,E?e=>E.getValidationProps(ie,e):L],Ce=ee(`span`,e,{enabled:!be,state:ve,ref:xe,props:Se,stateAttributesMapping:Hr});return(0,$.jsxs)(Ur.Provider,{value:ye,children:[be?(0,$.jsx)(Re,{tag:`span`,render:n,className:r,style:_,state:ve,refs:xe,props:Se,stateAttributesMapping:Hr}):Ce,(0,$.jsx)(`input`,{..._e,suppressHydrationWarning:!0})]})}),Gr=[];function Kr(e){let{allValues:t=Gr,value:n=Gr,onValueChange:r}=e,i=Q.useRef(n),o=Q.useRef(new Map),[s,c]=Q.useState(`mixed`),l=a(),u=n.length===t.length,d=n.length!==t.length&&n.length>0,f=A(r),p=Q.useCallback(()=>({id:l,indeterminate:d,checked:u,"aria-controls":t.map(e=>`${l}-${e}`).join(` `),onCheckedChange(e,r){let a=i.current,l=t.filter(e=>o.current.get(e)&&a.includes(e)),u=t.filter(e=>!o.current.get(e)||o.current.get(e)&&a.includes(e));if(a.length===u.length||a.length===0){n.length===u.length?f(l,r):f(u,r);return}let d=`mixed`,p=a;s===`mixed`?(d=`on`,p=u):s===`on`&&(d=`off`,p=l),f(p,r),r.isCanceled||c(d)}}),[t,u,l,d,f,s,n.length]),m=Q.useCallback(e=>({checked:n.includes(e),onCheckedChange(t,r){let a=n.slice();t?a.push(e):a.splice(a.indexOf(e),1),f(a,r),r.isCanceled||(i.current=a,c(`mixed`))}}),[f,n]);return Q.useMemo(()=>({id:l,indeterminate:d,getParentProps:p,getChildProps:m,disabledStatesRef:o}),[l,d,p,m])}var qr=Q.forwardRef(function(e,t){let{allValues:n,className:r,defaultValue:i,disabled:o=!1,id:s,onValueChange:c,render:l,value:u,style:d,...f}=e,{disabled:p,name:m,state:h,validation:g,setFilled:_,setDirty:v,validityData:y}=Y(),{labelId:b,getDescriptionProps:x}=de(),{clearErrors:S}=pe(),C=p||o,w=Q.useMemo(()=>{if(u===void 0)return i??[]},[u,i]),[T,E]=B({controlled:u,default:w,name:`CheckboxGroup`,state:`value`}),D=A((e,t)=>{c?.(e,t),!t.isCanceled&&E(e)}),O=Kr({allValues:n,value:T,onValueChange:D}),k=a(s),j=Q.useRef(null),M=Q.useCallback(e=>{j.current==null&&e!=null&&!e.hasAttribute(`data-parent`)&&(j.current=e)},[]);ce(j,k,T,void 0,!!m&&!C,m);let N=T??I;le(N,()=>{m&&S(m);let e=Array.isArray(y.initialValue)?y.initialValue:I;_(N.length>0),v(!G(N,e)),g.change(N)});let P={...h,disabled:C},F=Q.useMemo(()=>({allValues:n,value:T,defaultValue:w,setValue:D,parent:O,disabled:C,validation:g,registerControlRef:M}),[n,T,w,D,O,C,g,M]),L=ee(`div`,e,{state:P,ref:t,props:[{id:s,role:`group`,"aria-labelledby":b},f,x],stateAttributesMapping:se});return(0,$.jsx)(xt.Provider,{value:F,children:L})}),Jr=function(e){let t=a(),n=e.controlId===void 0?t:e.controlId,[r,i]=Q.useState(n),[o,s]=Q.useState(e.labelId),[c,l]=Q.useState([]),u=z(()=>new Map),{messageIds:d}=de(),f=A((e,t)=>{let n=u.current;if(t===void 0){n.delete(e);return}n.set(e,t),i(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})}),p=Q.useCallback(e=>{let t=e[`aria-describedby`]?e[`aria-describedby`].split(` `):[];return t.push(...d,...c),{...e,"aria-describedby":Array.from(new Set(t)).join(` `)||void 0}},[d,c]),m=Q.useMemo(()=>({controlId:r,registerControlId:f,labelId:o,setLabelId:s,messageIds:c,setMessageIds:l,getDescriptionProps:p}),[r,f,o,s,c,l,p]);return(0,$.jsx)(ue.Provider,{value:m,children:e.children})};function Yr(e,t){return{...e,state:{...e.state,valid:!t&&e.state.valid}}}var Xr=Object.keys(fe);function Zr(e){if(!e||e.valid||!e.valueMissing)return!1;let t=!1;for(let n of Xr)n!==`valid`&&(n===`valueMissing`?t=e[n]:e[n]&&(t=!1));return t}function Qr(e){let t=null;for(let n of e)if(!n.disabled){if(!n.validity.valid)return n;t??=n}return t}function $r(e,t){let n=!1;for(let r of t)r.setCustomValidity(``),n||=r===e;n||e.setCustomValidity(``)}function ei(e){let{formRef:t}=pe(),{setValidityData:n,validate:r,validityData:i,validationDebounceTime:a,invalid:s,markedDirtyRef:c,state:l,shouldValidateOnChange:u,getRegisteredFieldId:d}=e,{controlId:f,getDescriptionProps:p}=de(),m=o(),h=Q.useRef(null),g=z(()=>new Set).current,_=Q.useRef(0),v=Q.useCallback(e=>{if(e)return g.add(e),()=>{g.delete(e)}},[g]),y=A(async(e,a=!1)=>{let o=Qr(g)??h.current;if(!o)return;_.current+=1;let p=_.current;function v(e,n=s){let r=d()??f;if(r==null)return;let i=t.current.fields.get(r);if(!i)return;let a=Yr(e,n);t.current.fields.set(r,{...i,validityData:a})}if(a){if(l.valid!==!1)return;let t=o.validity;if(!t.valueMissing){let t={value:e,state:{...fe,valid:!0},error:``,errors:[],initialValue:i.initialValue};$r(o,g),v(t,!1),n(t);return}let r=Xr.reduce((e,n)=>(e[n]=t[n],e),{});if(!r.valid&&!Zr(r))return}function y(e){let t=Xr.reduce((t,n)=>(t[n]=e.validity[n],t),{}),n=!1;for(let e of Xr)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}m.clear();let b=null,x=[],S=y(o),C,w=u();if(o.validationMessage&&!w)C=o.validationMessage,x=[o.validationMessage];else{let n=r(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,p!==_.current)return}else b=n;b===null?w&&($r(o,g),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:i.initialValue};v(T),n(T)}),b=A(e=>{m.clear();let t=u();t&&e!==``&&a?(_.current+=1,m.start(a,()=>{y(e)})):y(e,!t)}),x=Q.useCallback((e,t={})=>P(p(t),l.valid===!1&&!l.disabled&&!e?{"aria-invalid":!0}:L),[p,l.disabled,l.valid]);return Q.useMemo(()=>({getValidationProps:x,inputRef:h,registerInput:v,commit:y,change:b}),[x,v,y,b])}function ti(e){let{commit:t,invalid:n,markedDirtyRef:r,name:i,setRegisteredFieldName:a,setRegisteredFieldId:o,setValidityData:s,validityData:c}=e,{formRef:l}=pe(),u=Q.useRef(null),d=Q.useRef(null),f=Q.useRef(null),p=A(()=>{let e=d.current;if(e)return e.getValue?e.getValue():e.value});function m(e){return e.value===void 0?p():e.value}let h=A(()=>{let e=d.current;if(r.current=!0,!e){t(c.value);return}t(m(e))});function g(){let e=d.current;!e||!e.id||l.current.fields.set(e.id,{getValue:p,name:i??e.name,controlRef:e.controlRef??f,validityData:Yr(c,n),validate:h})}function _(e=d.current?.id){e&&l.current.fields.delete(e)}function v(){let e=d.current;if(!e)return;let t=m(e);c.initialValue===null&&t!==null&&s(e=>({...e,initialValue:t}))}return N(()=>{let e=d.current;!e||!e.id||(a(i?void 0:e.name),l.current.fields.set(e.id,{getValue:p,name:i??e.name,controlRef:e.controlRef??f,validityData:Yr(c,n),validate:h}))},[l,p,n,i,a,h,c]),N(()=>{let e=l.current.fields;return()=>{let t=d.current?.id;t&&e.delete(t)}},[l]),[h,A((e,t)=>{if(!t){u.current===e&&(u.current=null,_(),d.current=null,a(void 0),o(void 0));return}let n=d.current?.id;u.current=e,d.current=t,i||a(t.name),o(t.id),n&&n!==t.id&&_(n),v(),g()})]}var ni=Q.forwardRef(function(e,t){let{errors:n,validationMode:r,submitAttemptedRef:i}=pe(),{render:a,className:o,validate:s,validationDebounceTime:c=0,validationMode:l=r,name:u,disabled:d=!1,invalid:f,dirty:p,touched:m,actionsRef:h,style:g,..._}=e,v=Ir(!0)?.disabled,y=A(s||(()=>null)),b=v||d,[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),[T,E]=Q.useState(!1),[D,O]=Q.useState(!1),k=p??C,j=m??x,M=Q.useRef(k),P=Q.useRef(void 0),[F,I]=Q.useState(),L=u??F;N(()=>{p!==void 0&&(M.current=p)},[p]);let R=Q.useCallback(()=>P.current,[]),te=Q.useCallback(e=>{P.current=e},[]),z=A(e=>{p===void 0&&(e&&(M.current=!0),w(e))}),B=A(e=>{m===void 0&&S(e)}),V=A(()=>l===`onChange`||l===`onSubmit`&&i.current),H=L&&Object.hasOwn(n,L)?n[L]:null,ne=!!(Array.isArray(H)?H.length:H),re=f===!0||ne,[U,ie]=Q.useState({state:fe,error:``,errors:[],value:null,initialValue:null}),W=b?null:!re&&U.state.valid,G=Q.useMemo(()=>({disabled:b,touched:j,dirty:k,valid:W,filled:T,focused:D}),[b,j,k,W,T,D]),ae=ei({setValidityData:ie,validate:y,validityData:U,validationDebounceTime:c,invalid:re,markedDirtyRef:M,state:G,shouldValidateOnChange:V,getRegisteredFieldId:R}),[K,oe]=ti({commit:ae.commit,invalid:re,markedDirtyRef:M,name:u,setRegisteredFieldName:I,setRegisteredFieldId:te,setValidityData:ie,validityData:U});Q.useImperativeHandle(h,()=>({validate:K}),[K]);let q=Q.useMemo(()=>({invalid:re,name:L,validityData:U,setValidityData:ie,disabled:b,touched:j,setTouched:B,dirty:k,setDirty:z,filled:T,setFilled:E,focused:D,setFocused:O,validate:y,validationMode:l,validationDebounceTime:c,shouldValidateOnChange:V,state:G,markedDirtyRef:M,registerFieldControl:oe,validation:ae}),[re,L,U,b,j,B,k,z,T,E,D,O,y,l,c,V,G,oe,ae]),ce=ee(`div`,e,{ref:t,state:G,props:_,stateAttributesMapping:se});return(0,$.jsx)(J.Provider,{value:q,children:ce})}),ri=Q.forwardRef(function(e,t){return(0,$.jsx)(Jr,{children:(0,$.jsx)(ni,{...e,ref:t})})}),ii={...se,...v},ai=Q.forwardRef(function(e,t){let{render:r,id:i,className:o,match:s,style:c,...l}=e,u=a(i),{validityData:d,state:f,name:p}=Y(!1),{setMessageIds:h}=de(),{errors:g}=pe(),_=p&&Object.hasOwn(g,p)?g[p]:null,v=!!(Array.isArray(_)?_.length:_),y=typeof s==`string`,b=!1;b=s===!0?!0:f.disabled?!1:y?!!d.state[s]:v||d.state.valid===!1;let{mounted:x,transitionStatus:S,setMounted:C}=m(b);N(()=>{if(!(!b||!u))return h(e=>e.concat(u)),()=>{h(e=>e.filter(e=>e!==u))}},[b,u,h]);let w=Q.useRef(null),[T,E]=Q.useState(null),[D,O]=Q.useState(null),k=d.error;!y&&v?k=_:d.errors.length>1&&(k=d.errors);let A=k??``;Array.isArray(k)&&(A=k.length>1?(0,$.jsx)(`ul`,{children:k.map(e=>(0,$.jsx)(`li`,{children:e},e))}):k[0]??``);let j=Array.isArray(k)?JSON.stringify(k):k;b&&j!==D&&(O(j),E(A)),n({open:b,ref:w,onComplete(){b||C(!1)}});let M={...f,transitionStatus:S},P=ee(`div`,e,{ref:[t,w],state:M,props:[{id:u,children:b?A:T},l],stateAttributesMapping:ii,enabled:x});return x?P:null}),oi=Q.forwardRef(function(e,t){let{render:n,className:r,id:a,name:o,value:c,disabled:l=!1,onValueChange:u,defaultValue:d,autoFocus:f=!1,style:p,...m}=e,{state:h,name:g,disabled:v,setTouched:b,setDirty:x,validityData:S,setFocused:C,setFilled:w,validationMode:T,validation:E}=Y(),{clearErrors:D}=pe(),O=v||l,k=g??o,j={...h,disabled:O},{labelId:M}=de(),P=U({id:a});N(()=>{let e=c!=null;E.inputRef.current?.value||e&&c!==``?w(!0):e&&c===``&&w(!1)},[E.inputRef,w,c]);let F=Q.useRef(null);N(()=>{f&&F.current===y(_(F.current))&&C(!0)},[f,C]);let[I]=B({controlled:c,default:d,name:`FieldControl`,state:`value`}),L=c!==void 0,R=L?I:void 0,te=A(()=>E.inputRef.current?.value);return ce(E.inputRef,P,R,te,!O,o),ee(`input`,e,{ref:[t,F],state:j,props:[{id:P,disabled:O,name:k,ref:E.inputRef,"aria-labelledby":M,autoFocus:f,...L?{value:R}:{defaultValue:d},onChange(e){let t=e.currentTarget.value;u?.(t,i(s,e.nativeEvent)),x(t!==S.initialValue),w(t!==``),e.nativeEvent.defaultPrevented||(D(k),E.change(t))},onFocus(){C(!0)},onBlur(e){b(!0),C(!1),T===`onBlur`&&E.commit(e.currentTarget.value)},onKeyDown(e){e.currentTarget.tagName===`INPUT`&&e.key===`Enter`&&(b(!0),E.commit(e.currentTarget.value))}},m,e=>E.getValidationProps(O,e)],stateAttributesMapping:se})}),si=typeof window<`u`?Q.useLayoutEffect:Q.useEffect,ci=x.moderate,li=.07,ui=(ci.duration+li)*1e3+80,di=ci.duration*1e3+80;function fi(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 pi(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 mi(e,t){return t===`y`?e.top+e.height/2:e.left+e.width/2}function hi(e,t){return t===`y`?[e,e,0,0]:[e,0,0,e]}function gi(e,t){return t===`y`?[0,0,e,e]:[0,e,e,0]}function _i(e){return[e,e,e,e]}function vi(e,t,n,r,i){let a=mi(n,r);if(r===`y`){let n=t.top+t.height;e.height=a-e.top,e.radii=hi(i,r),e.instant=!0,t.top=a,t.height=n-a,t.radii=gi(i,r),t.instant=!0,t.enterFrom={top:a,left:t.left,width:t.width,height:n-a,radii:gi(i,r)};return}let o=t.left+t.width;e.width=a-e.left,e.radii=hi(i,r),e.instant=!0,t.left=a,t.width=o-a,t.radii=gi(i,r),t.instant=!0,t.enterFrom={top:t.top,left:a,width:o-a,height:t.height,radii:gi(i,r)}}function yi(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);si(()=>{let t=o.current,n=e,r=[];for(let e of n){let n=fi(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=fi(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`?ui:di));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=pi(i.start,i.end,t,r);e&&l.push({key:`sel-${i.id}`,...e,radii:_i(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=mi(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:gi(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:gi(n,r),instant:!0,exitInstant:!0,delayCorners:!1,opacity:0});continue}let t=Math.min(.1,Math.max(li,li+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=hi(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:gi(n,r),enterFrom:{top:o,left:a.left,width:a.width,height:i-o,radii:_i(n)},instant:!1,exitInstant:!0,delayCorners:!0,cornerDelay:t})}else{let i=a.left+a.width;a.width=o-a.left,a.radii=hi(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:gi(n,r),enterFrom:{top:a.top,left:o,width:i-o,height:a.height,radii:_i(n)},instant:!1,exitInstant:!0,delayCorners:!0,cornerDelay:t})}}else if(e.phase===`splitIn`){let t=u.get(`sel-${e.otherId}`);if(!t)continue;vi(a,t,i,r,n)}}for(let i of o.current){let a=fi(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||vi(s,c,o,r,n)}return l}function bi({blocks:e,dimmed:t}){return(0,$.jsx)(ne,{children:e.map(e=>{let n=e.delayCorners?{...ci,delay:e.cornerDelay??li}:ci,r=e.opacity??(t?.8:1);return(0,$.jsx)(f.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}:ci.exit},transition:e.instant?{duration:0}:{...ci,borderTopLeftRadius:n,borderTopRightRadius:n,borderBottomRightRadius:n,borderBottomLeftRadius:n,opacity:{duration:.08}}},e.key)})})}function xi(e,t){return e.id??`q-${t}`}function Si(e,t){return e.id??`o-${t}`}var Ci=[],wi=(0,Q.forwardRef)(function({questions:e,currentIndex:t,defaultCurrentIndex:n=0,onCurrentIndexChange:r,answers:i,defaultAnswers:a,onAnswersChange:o,onComplete:s,onSkip:c,skipLabel:l=`Skip`,intro:d,onCancel:p,cancelLabel:m=`Cancel`,footerLeading:h,className:g,..._},v){let[y,b]=(0,Q.useState)(n),S=t!==void 0,C=S?t:y,w=(0,Q.useCallback)(e=>{S||b(e),r?.(e)},[S,r]),[T,E]=(0,Q.useState)(a??{}),O=i!==void 0,A=O?i:T,ee=(0,Q.useRef)(A);(0,Q.useEffect)(()=>{ee.current=A},[A]);let j=(0,Q.useCallback)(e=>{let t=e(ee.current);return ee.current=t,O||E(t),o?.(t),t},[O,o]),M=k(),N=et(`arrow-left`),P=et(`arrow-right`),F=(0,Q.useMemo)(()=>function(e){return(0,$.jsx)(N,{...e,className:D(e.className,`hidden sm:block`)})},[N]),I=(0,Q.useMemo)(()=>function(e){return(0,$.jsx)(P,{...e,className:D(e.className,`hidden sm:block`)})},[P]),[L]=(0,Q.useState)(()=>{if(typeof navigator>`u`)return!1;let e=navigator,t=e.userAgentData?.platform||e.platform||``;return/mac/i.test(t)}),te=(0,Q.useId)(),z=e.length,B=Math.max(0,Math.min(C,Math.max(0,z-1))),V=e[B],H=V?xi(V,B):``,re=A[H],U=!!V?.multiSelect,ie=V?.skippable!==!1,W=!!V?.freeText,G=V?.freeTextMultiline!==!1,K=!W&&!!V?.allowOther,oe=(0,Q.useMemo)(()=>re?.selectedIds??[],[re]),q=re?.otherText??``,J=V?.options??[],se=K?J.length:-1,ce=J.length+ +!!K,le=(0,Q.useRef)(null),ue=!!V;(0,Q.useEffect)(()=>{if(!ue)return;let e=le.current;if(e)return Ci.push(e),()=>{let t=Ci.indexOf(e);t!==-1&&Ci.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}=ae(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?s?.(e):(je(),w(B+1))},[B,z,s,w,je]),Ne=(0,Q.useCallback)(e=>{if(!V)return;let t=ee.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=(ee.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}}));c?.(H,B),Me(e)},[V,H,j,c,B,Me]),ze=(0,Q.useCallback)(()=>{p?.()},[p]),Be=(0,Q.useCallback)(()=>{Me(A)},[Me,A]),Ve=(0,Q.useCallback)(()=>{B>0&&(je(),w(B-1))},[B,w,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)&&(Ci.some(e=>e!==r&&e.contains(t))||Ci[Ci.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=Si(J[a],a);U?Pe(t):Ne(t)}else a===J.length&&K&&(e.preventDefault(),de.current?.focus())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[V,J,U,K,Ne,Pe]);let He=e=>{(Y.current?.querySelector(`[data-proximity-index="${e}"]`))?.focus()},Ue=(0,Q.useCallback)(e=>{he(e),K&&e===se?de.current?.focus():He(e)},[K,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}(oe.length>0||q.trim().length>0)&&Be()}};if(!V)return(0,$.jsx)(`div`,{ref:v,className:D(`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&&!(K&&Ee===se)?ge[Ee]:null,X=(0,Q.useMemo)(()=>{let e=new Set;return J.forEach((t,n)=>{oe.includes(Si(t,n))&&e.add(n)}),K&&q.length>0&&e.add(se),e},[J,oe,K,q,se]),Je=(0,Q.useMemo)(()=>{let e=[],t=[...X].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},[X]),Ye=me!==null&&!X.has(me),Xe=yi(Je,ge,M.bgRadius),Ze=z>1&&B>0,Qe=p!=null,$e=!Qe&&z>1&&ie,Z=U||W,tt=Ze||$e||Z||Qe||h!=null,rt=J.findIndex((e,t)=>oe.includes(Si(e,t))),it=(0,$.jsxs)(`div`,{ref:Y,role:U?`group`:`radiogroup`,"aria-labelledby":`${te}-${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(!K)return null;let e=ge[se],t=Ee===se&&q.length===0;return!e||!t?null:(0,$.jsx)(f.div,{"aria-hidden":!0,className:D(`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:x.fast.exit},transition:{...x.fast,opacity:{duration:.08}}},`other-input`)})()}),(0,$.jsx)(ne,{children:Ke&&(0,$.jsx)(f.div,{"aria-hidden":!0,className:D(`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:x.fast.exit},transition:{...x.fast,opacity:{duration:.08}}},`hover-${_e.current}`)}),(0,$.jsx)(bi,{blocks:Xe,dimmed:Ye}),(0,$.jsx)(ne,{children:qe&&(0,$.jsx)(f.div,{"aria-hidden":!0,className:D(`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:x.fast.exit},transition:{...x.fast,opacity:{duration:.08}}})}),J.map((e,t)=>{let n=Si(e,t),r=oe.includes(n),i=!U&&me===t;return(0,$.jsx)(Ei,{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)(P,{size:14,strokeWidth:2,className:`h-3.5 w-3.5`}),hiddenControl:U?(0,$.jsx)(nt,{name:n,className:`sr-only`,tabIndex:-1,"aria-hidden":!0}):(0,$.jsx)(Wr,{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:u.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?u.semibold:u.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:u.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?u.semibold:u.medium},children:e.title})]}),e.description&&(0,$.jsxs)($.Fragment,{children:[` `,(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]})]})},n)}),K&&(0,$.jsx)(Ei,{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)(P,{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:D(`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:u.medium}})})})]});return(0,$.jsxs)(`div`,{ref:e=>{le.current=e,typeof v==`function`?v(e):v&&(v.current=e)},className:D(`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]})}),d!=null&&(0,$.jsx)(`div`,{className:`px-4 sm:px-5 pb-3 text-[13px] leading-snug text-muted-foreground`,children:d}),(0,$.jsxs)(ri,{invalid:Oe!==null,className:`contents`,children:[(0,$.jsx)(f.div,{animate:{height:we},initial:!1,transition:x.slow,className:`overflow-hidden`,children:(0,$.jsx)(`div`,{ref:Ce,className:D(`px-4 sm:px-5`,tt?`pb-1`:`pb-2.5 sm:pb-3`),children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h3`,{id:`${te}-${H}-title`,className:`text-[16px] text-foreground leading-snug`,style:{fontVariationSettings:u.semibold},children:V.title}),W?(0,$.jsx)(`div`,{onClick:()=>de.current?.focus(),className:D(`relative mt-1 -mx-3 px-3 py-2.5 cursor-text transition-colors`,G?`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)(oi,{value:q,onValueChange:Ie,render:(0,$.jsx)(`textarea`,{ref:de,rows:1,placeholder:V.freeTextPlaceholder??`Type your answer…`,"aria-labelledby":`${te}-${H}-title`,onKeyDown:e=>{e.key===`Enter`&&(e.shiftKey||e.metaKey||e.ctrlKey||G||(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:u.medium}})})}):U?(0,$.jsx)(qr,{value:oe,onValueChange:Fe,render:it}):(0,$.jsx)(Br,{value:oe[0]??null,onValueChange:e=>{typeof e==`string`&&Ne(e)},render:it})]},H)})}),tt&&(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:Ze&&(0,$.jsx)(f.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...x.fast,opacity:{duration:.1}},children:(0,$.jsx)(R,{variant:`ghost`,size:`sm`,leadingIcon:F,onClick:Ve,className:`pl-3 sm:pl-[6px]`,children:`Back`})},`back`)}),Oe&&(0,$.jsx)(ai,{match:!0,render:(0,$.jsx)(f.p,{role:`alert`,initial:{opacity:0,y:-2},animate:{opacity:1,y:0},transition:{...x.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:[Qe&&(0,$.jsx)(f.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...x.fast,opacity:{duration:.1}},children:(0,$.jsx)(R,{variant:`ghost`,size:`sm`,trailingIcon:I,onClick:ze,className:`pr-3 sm:pr-[6px]`,children:m})},`cancel`),$e&&(0,$.jsx)(f.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...x.fast,opacity:{duration:.1}},children:(0,$.jsx)(R,{variant:`ghost`,size:`sm`,trailingIcon:I,onClick:Re,className:`pr-3 sm:pr-[6px]`,children:l})},`skip`),Z&&(0,$.jsx)(f.div,{layout:`position`,initial:{opacity:0,scale:.85},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.85},transition:{...x.fast,opacity:{duration:.1}},children:(0,$.jsx)(R,{variant:`primary`,size:`sm`,onClick:W?Le:Be,disabled:(W||oe.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)(Ti,{shape:M,tone:`inverted`,children:[L?`⌘`:`⌃`,`↵`]})})]})})},`continue`)]})})]})})]})]})});wi.displayName=`AskUserQuestions`;function Ti({children:e,tone:t=`muted`,shape:n}){return(0,$.jsx)(`kbd`,{"aria-hidden":!0,suppressHydrationWarning:!0,className:D(`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 Ei({index:e,registerItem:t,role:n,isSelected:r,tabIndex:i,onClick:a,onKeyDown:o,shape:s,chipContent:c,chipFilled:l,isMulti:d,ariaLabel:p,showArrow:m,arrowIcon:h,onArrowClick:g,bodyLayout:_=`inline`,topAlign:v=!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:m&&(0,$.jsx)(f.span,{"aria-hidden":!g,role:g?`button`:void 0,onClick:g?e=>{e.stopPropagation(),g()}:void 0,className:D(`absolute inset-0 inline-flex items-center justify-center bg-foreground text-background`,s.bg,g&&`cursor-pointer`),initial:{opacity:0,scale:.6},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.6,transition:x.fast.exit},transition:{...x.fast,opacity:{duration:.08}},children:h})}),E=(0,$.jsxs)(`span`,{className:D(`shrink-0 w-7 h-7 relative inline-flex items-center justify-center`,v&&(_===`stacked`?`-mt-[1px]`:`-mt-[5px]`)),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:D(`absolute inline-flex items-center justify-center w-5 h-5 text-[11px] transition-[opacity,font-variation-settings] duration-80`,d&&s.bg,d?l?`bg-foreground text-background`:`border border-border text-muted-foreground`:l?`text-foreground`:`text-muted-foreground`,y===`right`&&m&&`opacity-0`),style:{fontVariationSettings:l?u.semibold:u.medium},children:c}),y===`right`&&T]}),O=y===`left`&&!d&&(0,$.jsx)(`span`,{className:D(`shrink-0 w-7 h-7 relative inline-flex items-center justify-center`,v&&(_===`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":p,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:D(`relative z-10 flex cursor-pointer select-none outline-none`,y===`left`?`gap-2`:`gap-3`,v?`items-start`:`items-center`,_===`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`,s.item),children:[y===`left`&&E,(0,$.jsx)(`span`,{className:D(`min-w-0 flex-1 text-[13px] leading-snug`,_===`stacked`?`flex flex-col gap-0.5`:`inline-flex items-center gap-0`),children:S}),y===`right`?E:O,b]})}function Di(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=Qt(n),l=$t(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 Oi(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 ki(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 Ai(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 ji({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)(()=>Di(e.request),[e.request]),u=(0,Q.useMemo)(()=>Ai(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)(wi,{questions:l,defaultAnswers:u,onComplete:t=>{if(a)return;if(d){if(!t.__url_confirm__?.selectedIds.includes(`confirmed`)){pt.error(`Confirm you've completed the external action`);return}p(`accepted`,{action:`accept`});return}let n=ki(l,t,e.request);if(n.length>0){pt.error(`Missing required fields`,{description:`Please fill in: ${n.join(`, `)}`});return}p(`accepted`,{action:`accept`,content:Oi(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)(R,{size:`sm`,variant:`outline`,onClick:()=>window.open(f,`_blank`),"data-testid":`${i}-open-url`,children:[(0,$.jsx)(qe,{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 Mi({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)(f.div,{initial:{opacity:0,y:12,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},transition:x.moderate,children:(0,$.jsx)(ji,{request:e,onApprove:t,onReject:n})},e.id))})}var Ni=`You are a helpful assistant with access to MCP tools. Help users interact with the MCP server.`;function Pi(e){let t=e?.trim();return t?t!==Ni:!1}function Fi({value:e,onSave:t,disabled:n,isSaving:r=!1,compact:i=!1}){let[a,o]=(0,Q.useState)(!1),[s,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(s),o(!1)}finally{d(!1)}},[s,t]),p=r||u,m=Pi(e),h=(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-system-prompt-button`,onClick:()=>o(!0),disabled:n,className:i?D(`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`):D(`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)(sn,{className:`h-4 w-4`}),!i&&(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`System Prompt`})]});return(0,$.jsxs)(Pe,{open:a,onOpenChange:o,children:[i?(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:h,nativeButton:!0}),(0,$.jsx)(b,{side:`top`,children:(0,$.jsx)(`p`,{children:m?`Custom system prompt`:`System Prompt`})})]}):h,(0,$.jsxs)(ge,{className:`sm:max-w-xl`,children:[(0,$.jsx)(Be,{children:(0,$.jsx)(Ce,{children:`System Prompt`})}),(0,$.jsx)(Xt,{value:s,onChange:e=>l(e.target.value),placeholder:`Describe the assistant's behavior...`,className:`min-h-[160px] text-sm`}),(0,$.jsx)(Te,{children:(0,$.jsxs)(R,{size:`sm`,onClick:f,disabled:p||s===(e??``),className:`gap-1.5`,children:[p?(0,$.jsx)(Ze,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Ie,{className:`h-3.5 w-3.5`}),`Save`]})})]})]})}function Ii({inputValue:e,isConnected:t,isLoading:n,textareaRef:r,llmConfig:i,promptsDropdownOpen:a,promptFocusedIndex:o,prompts:s,selectedPrompt:l,promptResults:u,attachments:d,tools:f,disabledTools:p,onDisabledToolsChange:m,onInputChange:h,onKeyDown:_,onKeyUp:v,onClick:y,onSendMessage:x,onStopStreaming:S,onConfigDialogOpenChange:C,onPromptSelect:w,onDeletePromptResult:T,onAttachmentAdd:E,onAttachmentRemove:O,hideModelBadge:k,freeTierInfo:A,managedCloudInfo:ee,modelBadgeMode:j=`byok`,modelDisplayName:M,followups:N=[],onFollowupSelect:P,pendingElicitationRequests:F,onApproveElicitation:I,onRejectElicitation:L,systemPromptProvider:te}){let z=e.trim()||u.length>0||d.length>0,B=(F?.length??0)>0,V=i&&(!k||A||ee)?(0,$.jsxs)(g,{children:[(0,$.jsx)(c,{render:(0,$.jsx)(ot,{provider:i.provider,model:i.model,displayName:M,mode:j,className:`shrink-0`,onClick:()=>C(!0)}),nativeButton:!0}),(0,$.jsx)(b,{children:(0,$.jsx)(`p`,{children:ee||A?`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)(Mi,{requests:F,onApprove:I,onReject:L}),N.length>0&&(0,$.jsx)(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:N.map(e=>(0,$.jsx)(R,{type:`button`,variant:`outline`,size:`sm`,className:`rounded-full`,onClick:()=>P?.(e),disabled:n||!t,children:e},e))}),(0,$.jsx)(Pr,{isOpen:a,prompts:s,selectedPrompt:l,focusedIndex:o,onPromptSelect:w}),(0,$.jsx)(Nr,{promptResults:u,onDeletePromptResult:T}),(0,$.jsx)(Mr,{inputValue:e,isConnected:t,isLoading:n,textareaRef:r,attachments:d,placeholder:`Ask a question or request an action...`,className:D(`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:h,onKeyDown:_,onKeyUp:v,onClick:y,onAttachmentAdd:E,onAttachmentRemove:O,inlineControls:i&&te?(0,$.jsx)(Fi,{compact:!0,value:te.prompt,onSave:te.savePrompt,disabled:!t||n||te.disabled,isSaving:te.isSaving}):null,trailingControls:(0,$.jsxs)($.Fragment,{children:[V,(0,$.jsx)(R,{type:`button`,size:`sm`,className:D(`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?S:x,"data-testid":`chat-send-button`,children:n?(0,$.jsx)(Ze,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`})})]})})]})})}function Li({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)(Ii,{...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)(R,{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 Ri({onConfigureClick:e}){return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-center`,children:[(0,$.jsx)(ut,{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)(R,{onClick:e,"data-testid":`chat-configure-api-key-button`,children:[(0,$.jsx)(yt,{className:`h-4 w-4 mr-2`}),`Configure API Key`]})]})}function zi({children:e,as:t=`p`,className:n,duration:r=2,spread:i=2}){let a=f.create(t),o=(0,Q.useMemo)(()=>e.length*i,[e,i]);return(0,$.jsx)(a,{className:D(`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 Bi(e){let t=e.match(/```/g);return t&&t.length%2==1?`${e}\n\`\`\``:e}var Vi=(0,Q.memo)(function({content:e,isStreaming:t=!1}){let n=(0,Q.useMemo)(()=>t?Bi(e):e,[e,t]);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(It,{className:D(`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 Hi(){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 Ui({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 Wi({file:e,size:t,className:n}){let r=k(),i=e.type.startsWith(`image/`),[a,o]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!i){o(null);return}let t=URL.createObjectURL(e);return o(t),()=>URL.revokeObjectURL(t)},[i,e]);let s=i&&!a;return(0,$.jsx)(`div`,{className:D(`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`}):s?(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)(Ui,{size:t})})})}var Gi=(0,Q.forwardRef)(({from:e,files:t,thumbnailSize:n=64,time:r,actions:i,children:a,className:o,...s},c)=>{let l=k(),u=e===`user`,d=Hi(),p=u&&r!=null;return(0,$.jsxs)(f.div,{ref:c,layout:`position`,initial:{opacity:0,y:8,scale:.96},animate:{opacity:1,y:0,scale:1},transition:x.moderate,style:{transformOrigin:u?`bottom right`:`bottom left`},className:D(`group flex max-w-[80%] flex-col gap-1.5`,u?`items-end self-end`:`items-start self-start`,o),...s,children:[t&&t.length>0&&(0,$.jsx)(`div`,{className:D(`flex flex-wrap gap-1.5`,u?`justify-end`:`justify-start`),children:t.map((e,t)=>(0,$.jsx)(Wi,{file:e,size:n},`${e.name}-${e.size}-${e.lastModified}-${t}`))}),a!=null&&a!==``&&(0,$.jsx)(`div`,{className:D(`py-2 text-[14px] whitespace-pre-wrap break-words`,u?D(l.bg,`px-3.5 text-pretty bg-[color-mix(in_oklab,var(--accent),var(--background)_45%)] text-accent-foreground`):`text-foreground`),children:a}),(p||i!=null)&&(0,$.jsxs)(`div`,{className:D(`flex items-center gap-2 px-1 text-[12px] leading-none text-muted-foreground select-none`,!d&&[`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:[p&&(0,$.jsx)(`span`,{className:`tabular-nums`,children:r}),i!=null&&(0,$.jsx)(`span`,{className:`flex items-center gap-0.5`,children:i})]})]})});Gi.displayName=`ChatMessage`;function Ki({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 Ye(e),n(!0),setTimeout(()=>n(!1),2e3)},title:`Copy message content`,"data-testid":`copy-button`,children:t?(0,$.jsx)(Ie,{className:`h-3.5 w-3.5`}):(0,$.jsx)(Et,{className:`h-3.5 w-3.5`})})}function qi(e,t){let n=e===1?`token`:`tokens`;return`${e.toLocaleString()} ${n} ${t}`}function Ji({variant:e,copyText:t,inputTokens:n,outputTokens:r}){let i=!!t,a=e===`user`&&n!=null?qi(n,`in`):e===`assistant`&&r!=null?qi(r,`out`):null;if(!i&&!a)return null;let o=i?(0,$.jsx)(Ki,{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 Yi({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)(Gi,{from:`assistant`,actions:(0,$.jsx)(Ji,{variant:`assistant`,copyText:e,outputTokens:r}),"data-testid":`chat-message-content`,children:(0,$.jsx)(Vi,{content:e,isStreaming:n})}),t!=null&&(0,$.jsx)(`span`,{className:`sr-only`,children:new Date(t).toLocaleTimeString()})]})}function Xi({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)(Ze,{className:`h-4 w-4 animate-spin text-blue-500 dark:text-blue-400`});case`result`:return(0,$.jsx)(Ie,{className:`h-4 w-4 text-emerald-800 dark:text-emerald-400`});case`error`:return(0,$.jsx)(Ge,{className:`h-4 w-4 text-red-500 dark:text-red-400`});default:return(0,$.jsx)(Ie,{className:`h-4 w-4 text-emerald-800 dark:text-emerald-400`})}},s=()=>{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`}},c=e=>typeof e==`object`?wt(e).preview:String(e);return(0,$.jsxs)(Xe,{children:[(0,$.jsx)(mt,{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)(Ke,{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:D(`w-8 h-8 rounded-full flex items-center justify-center`,s()),"data-testid":`chat-tool-call-status-${r}`,children:o()})]}),nativeButton:!1}),(0,$.jsxs)(lt,{side:`right`,className:`w-[400px] sm:w-[540px] p-4 overflow-y-auto`,"data-testid":`chat-tool-drawer`,children:[(0,$.jsxs)(Qe,{children:[(0,$.jsxs)(Z,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Ke,{className:`h-5 w-5`}),`Tool Call Details`]}),(0,$.jsxs)(bt,{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)(Ze,{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:c(a)}),(0,$.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>Ye(c(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:D(`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)(R,{variant:`ghost`,size:`sm`,onClick:()=>Ye(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:D(`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)(Je,{data:n,filename:`tool-call-${e}-result-${Date.now()}.json`}),(0,$.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>Ye(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 Zi({widgetId:e}){let{getWidget:t}=dt(),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 Qi({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,d]=(0,Q.useState)(`inline`),f=(0,Q.useMemo)(()=>{if(!n)return null;if(typeof n==`string`)try{return JSON.parse(n)}catch{return n}return n},[n]),p=ze(a),m=p?a?.ui?.resourceUri??null:null,h=(0,Q.useMemo)(()=>t,[e,f]),g=(0,Q.useMemo)(()=>f,[e,f]);return p&&m&&r&&i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(en,{serverId:r,viewId:l,toolName:e,resourceUri:m,toolInput:h,toolOutput:g,toolMetadata:a,readResource:i,displayMode:u,onDisplayModeChange:d,onSendFollowUp:o,partialToolInput:s,cancelled:c,noWrapper:!0,className:`my-4`}),(0,$.jsx)(Zi,{widgetId:l})]}):p&&!m?(0,$.jsx)(`div`,{className:`flex items-center justify-center w-full h-[200px] rounded border`,children:(0,$.jsx)(xe,{className:`size-5`})}):p&&(!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 $i(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 ea({content:e,timestamp:t,attachments:n,inputTokens:r}){let i=(0,Q.useMemo)(()=>n?.map($i),[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)(Gi,{from:`user`,files:i,time:t?new Date(t).toLocaleTimeString():void 0,actions:e||r!=null?(0,$.jsx)(Ji,{variant:`user`,copyText:e||void 0,inputTokens:r}):void 0,"data-testid":`chat-message-content`,children:e&&e.length>0?e:void 0})})}var ta={events:[],spans:[]};function na(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 ra=new Set([`apikey`,`authorization`,`accesstoken`,`refreshtoken`,`password`,`cookie`,`secret`]);function ia(e){return Array.isArray(e)?e.map(ia):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,ra.has(e.toLowerCase().replace(/[_-]/g,``))?`[REDACTED]`:ia(t)]))}function aa(e,t=120){let n;try{n=JSON.stringify(e)}catch{n=String(e)}return n.length>t?`${n.slice(0,t)}…`:n}function oa(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 aa(e.args);case`tool-result`:return aa(e.result);case`usage`:return`${e.usage.totalTokens??`?`} tokens`;case`error`:return e.message;case`done`:return`Completed`;default:return e}}function sa(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 ca(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:oa(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`?oa(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:oa(t)});else if(t.type===`tool-call-start`)n.push({id:t.toolCallId,kind:`tool`,name:t.toolName,status:`running`,startedAt:t.timestamp,preview:oa(t)});else if(t.type===`tool-call-args`){let e=n.find(e=>e.id===t.toolCallId);e&&(e.preview=oa(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=oa(t))}else t.type===`usage`?(r=sa(r,t.usage),i&&(i.usage=sa(i.usage,t.usage))):(t.type===`error`||t.type===`done`)&&i&&(i.status=t.type===`error`?`error`:`success`,i.endedAt=t.timestamp,i.preview=oa(t));return{events:[...e.events,t],spans:n,usage:r}}function la(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 ua(e){let t;for(let n of e)n.type===`usage`&&(t=sa(t,n.usage));return t}function da(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 fa(e,t){let{turns:n}=la(t),r=da(e),i=new Map,a=Math.min(n.length,r.length);for(let e=0;e<a;e++){let t=ua(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 pa=(0,Q.memo)(({messages:e,isLoading:t,serverId:n,readResource:r,tools:i,sendMessage:a,messagesEndRef:o,traceEvents:s=[]})=>{let c=(0,Q.useMemo)(()=>fa(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=>ze(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)(ea,{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?.toolCallId??`${t.toolInvocation?.toolName}-${o}`}`;return t.type===`text`?(0,$.jsx)(Yi,{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)(Xi,{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)(Qi,{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)(Yi,{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)(Xi,{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)(Qi,{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)(zi,{duration:2,spread:1,children:`Thinking...`})})})})})}),(0,$.jsx)(`div`,{ref:o})]})});function ma({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)(f.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)(R,{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)(tn,{className:`size-4`})})})})})}function ha({visible:e}){return(0,$.jsx)(`div`,{"aria-hidden":!0,className:D(`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 ga(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 _a(e){return Mt(e)}var va=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 ya(e){if(!e)return;let t=ba(e);if(t)return t;let n=[],r=!1,i=!1;for(let t of e){if(r){i?i=!1:t===`\\`?i=!0:t===`"`&&(r=!1);continue}t===`"`?r=!0:t===`{`?n.push(`}`):t===`[`?n.push(`]`):(t===`}`||t===`]`)&&n[n.length-1]===t&&n.pop()}let a=e;return r&&i&&(a=a.slice(0,-1)),r&&(a+=`"`),a+=[...n].reverse().join(``),ba(a)}function ba(e){try{let t=JSON.parse(e);return t!==null&&!Array.isArray(t)&&typeof t==`object`?t:void 0}catch{return}}function xa({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)(ta),[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=>ca(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=[...va(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_${Vt(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(`
@@ -1 +1 @@
1
- import{s as e,t}from"./react-CU_d2d5K.js";import{d as n,l as r,u as i}from"./input-C0OQCUZy.js";import{n as a}from"./createLucideIcon-BEHeJH0M.js";import{t as o}from"./button-C8Xa2k4x.js";import{L as s,dt as c,ft as l,lt as u,mt as d,ot as f,pt as p,tn as m,ut as h}from"./index-BMaSsizY.js";import{t as g}from"./inspector-settings-layout-yjKRJDai.js";import{n as _}from"./ListTabHeader-CrGae306.js";var v=e(t(),1);function y(e,t){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(`auto`),[m,g]=(0,v.useState)(`auto`),[_,y]=(0,v.useState)([]),[b,x]=(0,v.useState)(`10000`),[S,C]=(0,v.useState)(`True`),[w,T]=(0,v.useState)(`60000`),[E,D]=(0,v.useState)(h()),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(``),[M,N]=(0,v.useState)(``);return(0,v.useEffect)(()=>{if(!e||!t)return;let n=d(e,c(e.id));a(n.url),r(n.name||n.url);let i=n.proxyConfig?.proxyAddress||(typeof n.autoProxyFallback==`object`?n.autoProxyFallback.proxyAddress:void 0);s(n.connectionMode||`auto`),g(l(n.protocolNegotiation)),D(i||h());let o=n.headers||{};y(Object.entries(o).map(([e,t],n)=>({id:`header-${n}`,name:e,value:String(t)}))),k(n.oauth?.clientId||``),j(n.oauth?.clientSecret||``),N(n.oauth?.scope||``),n.requestTimeout!==void 0&&x(String(n.requestTimeout)),n.resetTimeoutOnProgress!==void 0&&C(n.resetTimeoutOnProgress?`True`:`False`),n.maxTotalTimeout!==void 0&&T(String(n.maxTotalTimeout))},[e,t]),{alias:n,setAlias:r,url:i,setUrl:a,connectionMode:o,setConnectionMode:s,protocolMode:m,setProtocolMode:g,customHeaders:_,setCustomHeaders:y,requestTimeout:b,setRequestTimeout:x,resetTimeoutOnProgress:S,setResetTimeoutOnProgress:C,maxTotalTimeout:w,setMaxTotalTimeout:T,proxyAddress:E,setProxyAddress:D,clientId:O,setClientId:k,clientSecret:A,setClientSecret:j,scope:M,setScope:N,buildConfig:()=>{if(!i.trim())return null;let e=i.trim();try{let t=new URL(e);if(!(t.protocol===`http:`||t.protocol===`https:`))return f.error(`Invalid URL protocol. Please use http:// or https://`),null}catch{try{let t=`https://${e}`,n=new URL(t);if(!(n.protocol===`http:`||n.protocol===`https:`))return f.error(`Invalid URL protocol. Please use http:// or https://`),null;e=t}catch{return f.error(`Invalid URL format. Please enter a valid URL.`),null}}let t=_.reduce((e,t)=>(t.name&&t.value&&(e[t.name]=t.value),e),{}),r=o===`proxy`&&E.trim()?{proxyAddress:E.trim(),headers:t}:void 0,a=o===`auto`&&E.trim()?{enabled:!0,proxyAddress:E.trim()}:!1,s=u(O,A,M),c=Number.parseInt(b,10),l=Number.parseInt(w,10);return{url:e,name:n.trim()||e,transportType:`http`,connectionMode:o,protocolNegotiation:p(m),proxyConfig:r,headers:Object.keys(t).length>0?t:void 0,autoProxyFallback:a,...s?{oauth:s}:{},...Number.isFinite(c)?{requestTimeout:c}:{},resetTimeoutOnProgress:S===`True`,...Number.isFinite(l)?{maxTotalTimeout:l}:{}}}}}var b=a();function x({connection:e,onSave:t}){let a=y(e,!0),[c,l]=(0,v.useState)(!1);return(0,b.jsxs)(`div`,{className:`h-full overflow-y-auto overscroll-none`,onScroll:e=>l(e.currentTarget.scrollTop>0),children:[(0,b.jsxs)(`div`,{className:`${r(c)} flex flex-row items-center justify-between gap-2 ${i}`,children:[(0,b.jsxs)(`h2`,{className:`${n} flex items-center gap-1.5`,children:[(0,b.jsx)(m,{className:_,"aria-hidden":!0}),`Connection Settings`]}),(0,b.jsx)(o,{"data-testid":`connection-form-save-button`,size:`sm`,onClick:()=>{let e=a.buildConfig();e&&t(e)},children:`Save`})]}),(0,b.jsx)(`div`,{className:g,children:(0,b.jsx)(s,{alias:a.alias,setAlias:a.setAlias,url:a.url,setUrl:a.setUrl,connectionMode:a.connectionMode,setConnectionMode:a.setConnectionMode,protocolMode:a.protocolMode,setProtocolMode:a.setProtocolMode,customHeaders:a.customHeaders,setCustomHeaders:a.setCustomHeaders,requestTimeout:a.requestTimeout,setRequestTimeout:a.setRequestTimeout,resetTimeoutOnProgress:a.resetTimeoutOnProgress,setResetTimeoutOnProgress:a.setResetTimeoutOnProgress,maxTotalTimeout:a.maxTotalTimeout,setMaxTotalTimeout:a.setMaxTotalTimeout,proxyAddress:a.proxyAddress,setProxyAddress:a.setProxyAddress,clientId:a.clientId,setClientId:a.setClientId,clientSecret:a.clientSecret,setClientSecret:a.setClientSecret,scope:a.scope,setScope:a.setScope,showConnectButton:!1,showExportButton:!1,inlineSections:!0,cardSections:!0})})]})}export{x as ConnectionSettingsTab};
1
+ import{s as e,t}from"./react-CU_d2d5K.js";import{d as n,l as r,u as i}from"./input-C0OQCUZy.js";import{n as a}from"./createLucideIcon-BEHeJH0M.js";import{t as o}from"./button-C8Xa2k4x.js";import{L as s,dt as c,ft as l,lt as u,mt as d,ot as f,pt as p,tn as m,ut as h}from"./index-B5OxiZlj.js";import{t as g}from"./inspector-settings-layout-yjKRJDai.js";import{n as _}from"./ListTabHeader-CrGae306.js";var v=e(t(),1);function y(e,t){let[n,r]=(0,v.useState)(``),[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(`auto`),[m,g]=(0,v.useState)(`auto`),[_,y]=(0,v.useState)([]),[b,x]=(0,v.useState)(`10000`),[S,C]=(0,v.useState)(`True`),[w,T]=(0,v.useState)(`60000`),[E,D]=(0,v.useState)(h()),[O,k]=(0,v.useState)(``),[A,j]=(0,v.useState)(``),[M,N]=(0,v.useState)(``);return(0,v.useEffect)(()=>{if(!e||!t)return;let n=d(e,c(e.id));a(n.url),r(n.name||n.url);let i=n.proxyConfig?.proxyAddress||(typeof n.autoProxyFallback==`object`?n.autoProxyFallback.proxyAddress:void 0);s(n.connectionMode||`auto`),g(l(n.protocolNegotiation)),D(i||h());let o=n.headers||{};y(Object.entries(o).map(([e,t],n)=>({id:`header-${n}`,name:e,value:String(t)}))),k(n.oauth?.clientId||``),j(n.oauth?.clientSecret||``),N(n.oauth?.scope||``),n.requestTimeout!==void 0&&x(String(n.requestTimeout)),n.resetTimeoutOnProgress!==void 0&&C(n.resetTimeoutOnProgress?`True`:`False`),n.maxTotalTimeout!==void 0&&T(String(n.maxTotalTimeout))},[e,t]),{alias:n,setAlias:r,url:i,setUrl:a,connectionMode:o,setConnectionMode:s,protocolMode:m,setProtocolMode:g,customHeaders:_,setCustomHeaders:y,requestTimeout:b,setRequestTimeout:x,resetTimeoutOnProgress:S,setResetTimeoutOnProgress:C,maxTotalTimeout:w,setMaxTotalTimeout:T,proxyAddress:E,setProxyAddress:D,clientId:O,setClientId:k,clientSecret:A,setClientSecret:j,scope:M,setScope:N,buildConfig:()=>{if(!i.trim())return null;let e=i.trim();try{let t=new URL(e);if(!(t.protocol===`http:`||t.protocol===`https:`))return f.error(`Invalid URL protocol. Please use http:// or https://`),null}catch{try{let t=`https://${e}`,n=new URL(t);if(!(n.protocol===`http:`||n.protocol===`https:`))return f.error(`Invalid URL protocol. Please use http:// or https://`),null;e=t}catch{return f.error(`Invalid URL format. Please enter a valid URL.`),null}}let t=_.reduce((e,t)=>(t.name&&t.value&&(e[t.name]=t.value),e),{}),r=o===`proxy`&&E.trim()?{proxyAddress:E.trim(),headers:t}:void 0,a=o===`auto`&&E.trim()?{enabled:!0,proxyAddress:E.trim()}:!1,s=u(O,A,M),c=Number.parseInt(b,10),l=Number.parseInt(w,10);return{url:e,name:n.trim()||e,transportType:`http`,connectionMode:o,protocolNegotiation:p(m),proxyConfig:r,headers:Object.keys(t).length>0?t:void 0,autoProxyFallback:a,...s?{oauth:s}:{},...Number.isFinite(c)?{requestTimeout:c}:{},resetTimeoutOnProgress:S===`True`,...Number.isFinite(l)?{maxTotalTimeout:l}:{}}}}}var b=a();function x({connection:e,onSave:t}){let a=y(e,!0),[c,l]=(0,v.useState)(!1);return(0,b.jsxs)(`div`,{className:`h-full overflow-y-auto overscroll-none`,onScroll:e=>l(e.currentTarget.scrollTop>0),children:[(0,b.jsxs)(`div`,{className:`${r(c)} flex flex-row items-center justify-between gap-2 ${i}`,children:[(0,b.jsxs)(`h2`,{className:`${n} flex items-center gap-1.5`,children:[(0,b.jsx)(m,{className:_,"aria-hidden":!0}),`Connection Settings`]}),(0,b.jsx)(o,{"data-testid":`connection-form-save-button`,size:`sm`,onClick:()=>{let e=a.buildConfig();e&&t(e)},children:`Save`})]}),(0,b.jsx)(`div`,{className:g,children:(0,b.jsx)(s,{alias:a.alias,setAlias:a.setAlias,url:a.url,setUrl:a.setUrl,connectionMode:a.connectionMode,setConnectionMode:a.setConnectionMode,protocolMode:a.protocolMode,setProtocolMode:a.setProtocolMode,customHeaders:a.customHeaders,setCustomHeaders:a.setCustomHeaders,requestTimeout:a.requestTimeout,setRequestTimeout:a.setRequestTimeout,resetTimeoutOnProgress:a.resetTimeoutOnProgress,setResetTimeoutOnProgress:a.setResetTimeoutOnProgress,maxTotalTimeout:a.maxTotalTimeout,setMaxTotalTimeout:a.setMaxTotalTimeout,proxyAddress:a.proxyAddress,setProxyAddress:a.setProxyAddress,clientId:a.clientId,setClientId:a.setClientId,clientSecret:a.clientSecret,setClientSecret:a.setClientSecret,scope:a.scope,setScope:a.setScope,showConnectButton:!1,showExportButton:!1,inlineSections:!0,cardSections:!0})})]})}export{x as ConnectionSettingsTab};
@@ -1 +1 @@
1
- import{s as e,t}from"./react-CU_d2d5K.js";import{a as n,n as r,r as i,sr as a,t as o}from"./input-C0OQCUZy.js";import{n as s}from"./createLucideIcon-BEHeJH0M.js";import{t as c}from"./button-C8Xa2k4x.js";import{t as l}from"./label-CI7JWQOo.js";import{a as u,i as d,n as f,o as p,r as m,t as h}from"./shared-CFs9CZfB.js";import{t as g}from"./maximize-2-Br1WQzT2.js";import{P as _,Sn as v,Wt as y,Xt as b,_n as x,b as S,bt as C,en as w,jt as T,ot as E,vn as D,xt as O,yn as k}from"./index-BMaSsizY.js";import{t as A}from"./textarea-CRTXuRmE.js";import{t as j}from"./checkbox-B6dtF73d.js";import{n as M,t as N}from"./schemaHelpers-DLNTQr_6.js";var P=e(t(),1),F=s();function I({requests:e,selectedRequest:t,onRequestSelect:n,focusedIndex:r,formatRelativeTime:i}){return e.length===0?(0,F.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-4 text-center`,children:(0,F.jsx)(y,{vertical:!0,noBorder:!0,message:`No elicitation requests`})}):(0,F.jsx)(`div`,{children:e.map((e,o)=>{let s=e.request.mode||`form`,c=s===`form`&&`requestedSchema`in e.request&&e.request.requestedSchema;return(0,F.jsx)(m,{id:`elicitation-request-${e.id}`,"data-testid":`elicitation-request-item-${o}`,isSelected:t?.id===e.id,isFocused:r===o,title:(0,F.jsxs)(`span`,{className:`flex items-center gap-3`,children:[e.serverName,(0,F.jsx)(a,{variant:`outline`,className:s===`url`?`bg-blue-500/20 text-blue-600 dark:text-blue-400 border-blue-500/50`:`bg-green-500/20 text-green-600 dark:text-green-400 border-green-500/50`,children:s})]}),description:(()=>{let t=i(e.timestamp),n=[];return c&&n.push(`with schema`),s===`url`&&n.push(`external action`),t+(n.length>0?` | ${n.join(`, `)}`:``)})(),onClick:()=>n(e)},e.id)})})}function L({request:e,formData:t,onFieldChange:n,idPrefix:r,testIdPrefix:i,fieldContainerClassName:a=`space-y-2`,textareaRows:s=4,showOuterLabelForBoolean:c=!0,emptyFallback:u}){return(0,F.jsx)(F.Fragment,{children:(0,P.useMemo)(()=>{if(!(`requestedSchema`in e.request))return null;let d=e.request.requestedSchema;if(!d||d.type!==`object`||!d.properties)return u??(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No form schema available`});let f=d.properties,p=d.required||[];return(0,F.jsx)(`div`,{className:`space-y-4`,children:Object.entries(f).map(([e,u])=>{let d=u,f=p.includes(e),m=d.type||`string`,h=d.title||e,g=d.description,_=M(d),v=_.length>0,y=Array.isArray(d.enum),b=m===`array`&&Array.isArray(d.items?.enum),x=N(d),S=m===`array`&&x.length>0,C=Array.isArray(t[e])?t[e]:[],w=`${r}-${e}`,T=`${i}-${e}`;return(0,F.jsxs)(`div`,{className:a,children:[(m!==`boolean`||c)&&(0,F.jsxs)(l,{htmlFor:w,children:[h,f&&(0,F.jsx)(`span`,{className:`text-red-500 ml-1`,children:`*`})]}),g&&(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:g}),m===`boolean`?(0,F.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,F.jsx)(j,{id:w,"data-testid":T,checked:t[e]||!1,onCheckedChange:t=>n(e,t)}),(0,F.jsxs)(l,{htmlFor:w,className:`text-sm font-normal cursor-pointer`,children:[h,!c&&f&&(0,F.jsx)(`span`,{className:`text-red-500 ml-1`,children:`*`})]})]}):m===`number`||m===`integer`?(0,F.jsx)(o,{id:w,"data-testid":T,type:`number`,value:t[e]??``,onChange:t=>{let r=m===`integer`?parseInt(t.target.value,10):parseFloat(t.target.value);n(e,isNaN(r)?``:r)},placeholder:d.default?.toString()||``}):v?(0,F.jsxs)(`select`,{id:w,"data-testid":T,value:t[e]||``,onChange:t=>n(e,t.target.value),className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:[(0,F.jsx)(`option`,{value:``,children:`Select...`}),_.map(e=>(0,F.jsx)(`option`,{value:e.const,children:e.title||e.const},e.const))]}):y?(0,F.jsxs)(`select`,{id:w,"data-testid":T,value:t[e]||``,onChange:t=>n(e,t.target.value),className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:[(0,F.jsx)(`option`,{value:``,children:`Select...`}),d.enum.map((e,t)=>(0,F.jsx)(`option`,{value:e,children:d.enumNames?.[t]||e},e))]}):b?(0,F.jsx)(`div`,{className:`space-y-2`,"data-testid":T,children:d.items.enum.map(t=>{let r=`${w}-${t}`;return(0,F.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,F.jsx)(j,{id:r,checked:C.includes(t),onCheckedChange:r=>{n(e,r?[...C,t]:C.filter(e=>e!==t))}}),(0,F.jsx)(l,{htmlFor:r,className:`text-sm font-normal cursor-pointer`,children:t})]},t)})}):S?(0,F.jsx)(`div`,{className:`space-y-2`,"data-testid":T,children:x.map(t=>{let r=`${w}-${t.const}`;return(0,F.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,F.jsx)(j,{id:r,checked:C.includes(t.const),onCheckedChange:r=>{n(e,r?[...C,t.const]:C.filter(e=>e!==t.const))}}),(0,F.jsx)(l,{htmlFor:r,className:`text-sm font-normal cursor-pointer`,children:t.title||t.const})]},t.const)})}):m===`string`&&(d.format===`textarea`||d.maxLength>100)?(0,F.jsx)(A,{id:w,"data-testid":T,value:t[e]||``,onChange:t=>n(e,t.target.value),placeholder:d.default||``,rows:s}):(0,F.jsx)(o,{id:w,"data-testid":T,type:`text`,value:t[e]||``,onChange:t=>n(e,t.target.value),placeholder:d.default||``})]},e)})})},[e,t,n,r,i,a,s,c,u])})}function R(e){let[t,n]=(0,P.useState)({}),[r,i]=(0,P.useState)(!1),a=e?.request.mode||`form`,o=a===`form`,s=a===`url`;return(0,P.useEffect)(()=>{if(e&&o&&`requestedSchema`in e.request){let t=e.request.requestedSchema,r={};if(t?.type===`object`&&t.properties)for(let[e,n]of Object.entries(t.properties)){let t=n;t.default===void 0?t.type===`array`?r[e]=[]:t.type===`boolean`?r[e]=!1:t.type===`number`||t.type===`integer`?r[e]=0:r[e]=``:r[e]=t.default}n(r)}i(!1)},[e?.id,o]),{formData:t,setFieldValue:(0,P.useCallback)((e,t)=>{n(n=>({...n,[e]:t}))},[]),getMissingRequiredFields:(0,P.useCallback)(()=>!e||!o||!(`requestedSchema`in e.request)?[]:(e.request.requestedSchema?.required??[]).filter(e=>t[e]===void 0||t[e]===``||t[e]===null),[e,t,o]),urlCompleted:r,setUrlCompleted:i,mode:a,isFormMode:o,isUrlMode:s}}function z({request:t,onApprove:o,onReject:s,onClose:u,previewMode:d,onTogglePreview:f,isCopied:p,onCopy:m,onDownload:h,onFullscreen:_}){let{formData:y,setFieldValue:C,getMissingRequiredFields:w,urlCompleted:O,setUrlCompleted:A,mode:M,isFormMode:N,isUrlMode:P}=R(t);return t?(0,F.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b dark:border-zinc-700`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:t.serverName}),(0,F.jsx)(a,{variant:`outline`,className:P?`bg-blue-500/20 text-blue-600 dark:text-blue-400 border-blue-500/50`:`bg-green-500/20 text-green-600 dark:text-green-400 border-green-500/50`,children:M}),(0,F.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:new Date(t.timestamp).toLocaleString()})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsxs)(r,{children:[(0,F.jsx)(n,{render:(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:m,className:`h-8 w-8 p-0`,children:p?(0,F.jsx)(v,{className:`h-4 w-4 text-green-600`}):(0,F.jsx)(k,{className:`h-4 w-4`})}),nativeButton:!0}),(0,F.jsx)(i,{children:`Copy request`})]}),(0,F.jsxs)(r,{children:[(0,F.jsx)(n,{render:(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:h,className:`h-8 w-8 p-0`,children:(0,F.jsx)(D,{className:`h-4 w-4`})}),nativeButton:!0}),(0,F.jsx)(i,{children:`Download request`})]}),(0,F.jsxs)(r,{children:[(0,F.jsx)(n,{render:(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:_,className:`h-8 w-8 p-0`,children:(0,F.jsx)(g,{className:`h-4 w-4`})}),nativeButton:!0}),(0,F.jsx)(i,{children:`Fullscreen`})]}),(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:u,className:`h-8 w-8 p-0`,children:(0,F.jsx)(b,{className:`h-4 w-4`})})]})]}),(0,F.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-6`,children:[(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:`Message`}),(0,F.jsx)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:t.request.message})]}),P&&`url`in t.request&&(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:`External Action Required`}),(0,F.jsxs)(`div`,{className:`bg-muted rounded-lg p-4 space-y-3`,children:[(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This request requires you to complete an action at an external URL:`}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2 p-2 bg-background rounded border`,children:[(0,F.jsx)(`code`,{className:`flex-1 text-xs font-mono break-all`,children:t.request.url}),(0,F.jsxs)(c,{size:`sm`,variant:`outline`,onClick:()=>{t&&P&&`url`in t.request&&(window.open(t.request.url,`_blank`),A(!0))},className:`flex items-center gap-2`,children:[(0,F.jsx)(x,{className:`h-4 w-4`}),`Open URL`]})]}),(0,F.jsxs)(`div`,{className:`flex items-center space-x-2 pt-2`,children:[(0,F.jsx)(j,{id:`url-completed`,checked:O,onCheckedChange:e=>A(!!e)}),(0,F.jsx)(l,{htmlFor:`url-completed`,className:`text-sm font-normal cursor-pointer`,children:`I have completed the required action`})]})]})]}),N&&(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:`Form Data`}),(0,F.jsx)(L,{request:t,formData:y,onFieldChange:C,idPrefix:`field`,testIdPrefix:`elicitation-field`,emptyFallback:(0,F.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:`No form schema available`})})]}),N&&`requestedSchema`in t.request&&t.request.requestedSchema&&(0,F.jsxs)(`details`,{className:`space-y-2`,children:[(0,F.jsx)(`summary`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100 cursor-pointer`,children:`Schema (for reference)`}),(0,F.jsx)(`div`,{className:`bg-muted rounded-lg p-3 max-h-64 overflow-auto`,children:(0,F.jsx)(S,{data:t.request.requestedSchema})})]})]}),(0,F.jsxs)(`div`,{className:`flex gap-2 p-4 border-t dark:border-zinc-700`,children:[(0,F.jsx)(c,{onClick:()=>{if(t){if(N){let e=w();if(e.length>0){E.error(`Missing required fields`,{description:`Please fill in: ${e.join(`, `)}`});return}o(t.id,{action:`accept`,content:y})}else P&&o(t.id,{action:`accept`});u(),T(()=>import(`./react-CU_d2d5K.js`).then(t=>e(t.t(),1)).then(e=>{let t=E(e.createElement(`div`,{className:`space-y-3`},e.createElement(`div`,null,e.createElement(`strong`,null,`Elicitation Response Sent`),e.createElement(`p`,{className:`text-sm text-muted-foreground mt-1`},`The tool will continue executing.`)),e.createElement(`div`,{className:`flex gap-2`},e.createElement(`button`,{"data-testid":`elicitation-view-tool-result`,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90`,onClick:()=>{let e=new globalThis.CustomEvent(`navigate-to-tool-result`,{detail:{toolName:null}});window.dispatchEvent(e),E.dismiss(t)}},`View Tool Result`))),{duration:5e3})}),[])}},className:`flex-1`,disabled:P&&!O,"data-testid":`elicitation-accept-button`,children:`Accept`}),(0,F.jsx)(c,{onClick:()=>{t&&(o(t.id,{action:`decline`}),u())},variant:`outline`,className:`flex-1`,"data-testid":`elicitation-decline-button`,children:`Decline`}),(0,F.jsx)(c,{onClick:()=>{t&&(s(t.id,`User cancelled elicitation request`),u())},variant:`outline`,className:`flex-1`,"data-testid":`elicitation-cancel-button`,children:`Cancel`})]})]}):(0,F.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 text-center`,children:(0,F.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:`Select an elicitation request to view details`})})}function B({pendingRequests:e=[],onApprove:t,onReject:n,serverId:r,isConnected:i}){let{selectedElicitationRequestId:a,setSelectedElicitationRequestId:o}=_(),[s,c]=(0,P.useState)(null),[l,m]=(0,P.useState)(``),[g,v]=(0,P.useState)(-1),[y,x]=(0,P.useState)(!0),[S,T]=(0,P.useState)(!1),[E,D]=(0,P.useState)(!0),[k,A]=(0,P.useState)(!1),j=(0,P.useRef)(null),M=(0,P.useRef)(null),N=(0,P.useRef)(null),L=(0,P.useRef)(!1);(0,P.useEffect)(()=>{if(console.log(`[ElicitationTab] Auto-selection check:`,{selectedElicitationRequestId:a,pendingRequestsCount:e.length,currentSelectedId:s?.id}),a&&e.length>0){let t=e.find(e=>e.id===a);console.log(`[ElicitationTab] Found request for auto-selection:`,!!t,t?.id),t&&(console.log(`[ElicitationTab] Auto-selecting request:`,t.id),o(null),c(t),setTimeout(()=>{let e=document.getElementById(`elicitation-request-${t.id}`);console.log(`[ElicitationTab] Scrolling to element:`,!!e),e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})},100))}},[a,e,o]),(0,P.useEffect)(()=>{let t=t=>{let n=t.detail.requestId;console.log(`[ElicitationTab] Custom navigate event received:`,n);let r=e.find(e=>e.id===n);r&&(console.log(`[ElicitationTab] Selecting request from event:`,n),c(r),setTimeout(()=>{let e=document.getElementById(`elicitation-request-${n}`);e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})},200))};return window.addEventListener(`navigate-to-elicitation`,t),()=>window.removeEventListener(`navigate-to-elicitation`,t)},[e]),(0,P.useEffect)(()=>{y&&e.length>0&&j.current&&!L.current&&(j.current.scrollTop=0)},[e.length,y]),(0,P.useEffect)(()=>{let e=j.current;if(!e)return;let t=()=>{e.scrollTop>0&&(L.current=!0,x(!1))};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[]),(0,P.useEffect)(()=>{e.length===0&&(L.current=!1,x(!0))},[e.length]),(0,P.useEffect)(()=>{S&&N.current&&N.current.focus()},[S]);let R=(0,P.useCallback)(()=>{l.trim()||T(!1)},[l]),B=(0,P.useMemo)(()=>{if(!l.trim())return e;let t=l.toLowerCase();return e.filter(e=>e.serverName.toLowerCase().includes(t)||e.request.message.toLowerCase().includes(t)||JSON.stringify(e.request||{}).toLowerCase().includes(t))},[e,l]);(0,P.useEffect)(()=>{v(-1)},[l]),(0,P.useEffect)(()=>{let e=e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.contentEditable===`true`||e.metaKey||e.ctrlKey||e.altKey)return;let n=B;if(e.key===`ArrowDown`)e.preventDefault(),v(e=>{let t=e+1;return t>=n.length?0:t});else if(e.key===`ArrowUp`)e.preventDefault(),v(e=>{let t=e-1;return t<0?n.length-1:t});else if(e.key===`Enter`&&g>=0){e.preventDefault();let t=B[g];t&&V(t)}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[g,B]),(0,P.useEffect)(()=>{if(g>=0){let e=`elicitation-request-${B[g]?.id}`,t=document.getElementById(e);t&&t.scrollIntoView({behavior:`smooth`,block:`nearest`})}},[g,B]);let V=(0,P.useCallback)(e=>{c(e)},[]),H=(0,P.useCallback)(()=>{window.confirm(`Are you sure you want to cancel all elicitation requests? This cannot be undone.`)&&(e.forEach(e=>{n(e.id,`User cancelled all requests`)}),c(null))},[e,n]),U=(0,P.useCallback)(async()=>{if(s)try{await C(JSON.stringify({id:s.id,serverName:s.serverName,timestamp:s.timestamp,request:s.request},null,2)),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){console.error(`[ElicitationTab] Failed to copy request:`,e)}},[s]),W=(0,P.useCallback)(()=>{if(s)try{let e=new globalThis.Blob([JSON.stringify({id:s.id,serverName:s.serverName,timestamp:s.timestamp,request:s.request},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`elicitation-request-${Date.now()}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)}catch(e){console.error(`[ElicitationTab] Failed to download request:`,e)}},[s]),G=(0,P.useCallback)(async()=>{if(M.current)try{document.fullscreenElement?await document.exitFullscreen():await M.current.requestFullscreen()}catch(e){console.error(`[ElicitationTab] Failed to toggle fullscreen:`,e)}},[]);return i?(0,F.jsxs)(p,{orientation:`horizontal`,className:`h-full`,children:[(0,F.jsx)(u,{defaultSize:40,minSize:30,children:(0,F.jsx)(p,{orientation:`vertical`,className:`h-full border-r dark:border-zinc-700`,children:(0,F.jsx)(u,{defaultSize:75,minSize:30,className:`h-full overflow-hidden`,children:(0,F.jsx)(f,{scrollRef:j,children:t=>(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(h,{isScrolled:t,title:`Elicitation`,icon:w,titleTestId:`elicitation-tab-header`,count:B.length,isSearchExpanded:S,searchQuery:l,searchPlaceholder:`Search requests...`,onSearchExpand:()=>T(!0),onSearchChange:m,onSearchBlur:R,bulkAction:{icon:b,label:`Cancel all`,onClick:H,disabled:e.length===0},searchInputRef:N}),(0,F.jsx)(I,{requests:B,selectedRequest:s,onRequestSelect:V,focusedIndex:g,formatRelativeTime:O})]})})})})}),(0,F.jsx)(d,{}),(0,F.jsx)(u,{defaultSize:60,minSize:40,children:(0,F.jsx)(`div`,{ref:M,className:`h-full bg-white dark:bg-zinc-900`,children:(0,F.jsx)(z,{request:s,onApprove:t,onReject:n,onClose:()=>c(null),previewMode:E,onTogglePreview:()=>D(!E),isCopied:k,onCopy:U,onDownload:W,onFullscreen:G})})})]}):(0,F.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 text-center`,children:[(0,F.jsx)(w,{className:`h-12 w-12 text-gray-400 dark:text-gray-600 mb-3`}),(0,F.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:`Not connected to server`})]})}export{B as ElicitationTab};
1
+ import{s as e,t}from"./react-CU_d2d5K.js";import{a as n,n as r,r as i,sr as a,t as o}from"./input-C0OQCUZy.js";import{n as s}from"./createLucideIcon-BEHeJH0M.js";import{t as c}from"./button-C8Xa2k4x.js";import{t as l}from"./label-CI7JWQOo.js";import{a as u,i as d,n as f,o as p,r as m,t as h}from"./shared-BWLzd0mh.js";import{t as g}from"./maximize-2-Br1WQzT2.js";import{P as _,Sn as v,Wt as y,Xt as b,_n as x,b as S,bt as C,en as w,jt as T,ot as E,vn as D,xt as O,yn as k}from"./index-B5OxiZlj.js";import{t as A}from"./textarea-CRTXuRmE.js";import{t as j}from"./checkbox-C9WZqT8k.js";import{n as M,t as N}from"./schemaHelpers-DLNTQr_6.js";var P=e(t(),1),F=s();function I({requests:e,selectedRequest:t,onRequestSelect:n,focusedIndex:r,formatRelativeTime:i}){return e.length===0?(0,F.jsx)(`div`,{className:`flex flex-1 flex-col items-center justify-center p-4 text-center`,children:(0,F.jsx)(y,{vertical:!0,noBorder:!0,message:`No elicitation requests`})}):(0,F.jsx)(`div`,{children:e.map((e,o)=>{let s=e.request.mode||`form`,c=s===`form`&&`requestedSchema`in e.request&&e.request.requestedSchema;return(0,F.jsx)(m,{id:`elicitation-request-${e.id}`,"data-testid":`elicitation-request-item-${o}`,isSelected:t?.id===e.id,isFocused:r===o,title:(0,F.jsxs)(`span`,{className:`flex items-center gap-3`,children:[e.serverName,(0,F.jsx)(a,{variant:`outline`,className:s===`url`?`bg-blue-500/20 text-blue-600 dark:text-blue-400 border-blue-500/50`:`bg-green-500/20 text-green-600 dark:text-green-400 border-green-500/50`,children:s})]}),description:(()=>{let t=i(e.timestamp),n=[];return c&&n.push(`with schema`),s===`url`&&n.push(`external action`),t+(n.length>0?` | ${n.join(`, `)}`:``)})(),onClick:()=>n(e)},e.id)})})}function L({request:e,formData:t,onFieldChange:n,idPrefix:r,testIdPrefix:i,fieldContainerClassName:a=`space-y-2`,textareaRows:s=4,showOuterLabelForBoolean:c=!0,emptyFallback:u}){return(0,F.jsx)(F.Fragment,{children:(0,P.useMemo)(()=>{if(!(`requestedSchema`in e.request))return null;let d=e.request.requestedSchema;if(!d||d.type!==`object`||!d.properties)return u??(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No form schema available`});let f=d.properties,p=d.required||[];return(0,F.jsx)(`div`,{className:`space-y-4`,children:Object.entries(f).map(([e,u])=>{let d=u,f=p.includes(e),m=d.type||`string`,h=d.title||e,g=d.description,_=M(d),v=_.length>0,y=Array.isArray(d.enum),b=m===`array`&&Array.isArray(d.items?.enum),x=N(d),S=m===`array`&&x.length>0,C=Array.isArray(t[e])?t[e]:[],w=`${r}-${e}`,T=`${i}-${e}`;return(0,F.jsxs)(`div`,{className:a,children:[(m!==`boolean`||c)&&(0,F.jsxs)(l,{htmlFor:w,children:[h,f&&(0,F.jsx)(`span`,{className:`text-red-500 ml-1`,children:`*`})]}),g&&(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:g}),m===`boolean`?(0,F.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,F.jsx)(j,{id:w,"data-testid":T,checked:t[e]||!1,onCheckedChange:t=>n(e,t)}),(0,F.jsxs)(l,{htmlFor:w,className:`text-sm font-normal cursor-pointer`,children:[h,!c&&f&&(0,F.jsx)(`span`,{className:`text-red-500 ml-1`,children:`*`})]})]}):m===`number`||m===`integer`?(0,F.jsx)(o,{id:w,"data-testid":T,type:`number`,value:t[e]??``,onChange:t=>{let r=m===`integer`?parseInt(t.target.value,10):parseFloat(t.target.value);n(e,isNaN(r)?``:r)},placeholder:d.default?.toString()||``}):v?(0,F.jsxs)(`select`,{id:w,"data-testid":T,value:t[e]||``,onChange:t=>n(e,t.target.value),className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:[(0,F.jsx)(`option`,{value:``,children:`Select...`}),_.map(e=>(0,F.jsx)(`option`,{value:e.const,children:e.title||e.const},e.const))]}):y?(0,F.jsxs)(`select`,{id:w,"data-testid":T,value:t[e]||``,onChange:t=>n(e,t.target.value),className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:[(0,F.jsx)(`option`,{value:``,children:`Select...`}),d.enum.map((e,t)=>(0,F.jsx)(`option`,{value:e,children:d.enumNames?.[t]||e},e))]}):b?(0,F.jsx)(`div`,{className:`space-y-2`,"data-testid":T,children:d.items.enum.map(t=>{let r=`${w}-${t}`;return(0,F.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,F.jsx)(j,{id:r,checked:C.includes(t),onCheckedChange:r=>{n(e,r?[...C,t]:C.filter(e=>e!==t))}}),(0,F.jsx)(l,{htmlFor:r,className:`text-sm font-normal cursor-pointer`,children:t})]},t)})}):S?(0,F.jsx)(`div`,{className:`space-y-2`,"data-testid":T,children:x.map(t=>{let r=`${w}-${t.const}`;return(0,F.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,F.jsx)(j,{id:r,checked:C.includes(t.const),onCheckedChange:r=>{n(e,r?[...C,t.const]:C.filter(e=>e!==t.const))}}),(0,F.jsx)(l,{htmlFor:r,className:`text-sm font-normal cursor-pointer`,children:t.title||t.const})]},t.const)})}):m===`string`&&(d.format===`textarea`||d.maxLength>100)?(0,F.jsx)(A,{id:w,"data-testid":T,value:t[e]||``,onChange:t=>n(e,t.target.value),placeholder:d.default||``,rows:s}):(0,F.jsx)(o,{id:w,"data-testid":T,type:`text`,value:t[e]||``,onChange:t=>n(e,t.target.value),placeholder:d.default||``})]},e)})})},[e,t,n,r,i,a,s,c,u])})}function R(e){let[t,n]=(0,P.useState)({}),[r,i]=(0,P.useState)(!1),a=e?.request.mode||`form`,o=a===`form`,s=a===`url`;return(0,P.useEffect)(()=>{if(e&&o&&`requestedSchema`in e.request){let t=e.request.requestedSchema,r={};if(t?.type===`object`&&t.properties)for(let[e,n]of Object.entries(t.properties)){let t=n;t.default===void 0?t.type===`array`?r[e]=[]:t.type===`boolean`?r[e]=!1:t.type===`number`||t.type===`integer`?r[e]=0:r[e]=``:r[e]=t.default}n(r)}i(!1)},[e?.id,o]),{formData:t,setFieldValue:(0,P.useCallback)((e,t)=>{n(n=>({...n,[e]:t}))},[]),getMissingRequiredFields:(0,P.useCallback)(()=>!e||!o||!(`requestedSchema`in e.request)?[]:(e.request.requestedSchema?.required??[]).filter(e=>t[e]===void 0||t[e]===``||t[e]===null),[e,t,o]),urlCompleted:r,setUrlCompleted:i,mode:a,isFormMode:o,isUrlMode:s}}function z({request:t,onApprove:o,onReject:s,onClose:u,previewMode:d,onTogglePreview:f,isCopied:p,onCopy:m,onDownload:h,onFullscreen:_}){let{formData:y,setFieldValue:C,getMissingRequiredFields:w,urlCompleted:O,setUrlCompleted:A,mode:M,isFormMode:N,isUrlMode:P}=R(t);return t?(0,F.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b dark:border-zinc-700`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100`,children:t.serverName}),(0,F.jsx)(a,{variant:`outline`,className:P?`bg-blue-500/20 text-blue-600 dark:text-blue-400 border-blue-500/50`:`bg-green-500/20 text-green-600 dark:text-green-400 border-green-500/50`,children:M}),(0,F.jsx)(`span`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:new Date(t.timestamp).toLocaleString()})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsxs)(r,{children:[(0,F.jsx)(n,{render:(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:m,className:`h-8 w-8 p-0`,children:p?(0,F.jsx)(v,{className:`h-4 w-4 text-green-600`}):(0,F.jsx)(k,{className:`h-4 w-4`})}),nativeButton:!0}),(0,F.jsx)(i,{children:`Copy request`})]}),(0,F.jsxs)(r,{children:[(0,F.jsx)(n,{render:(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:h,className:`h-8 w-8 p-0`,children:(0,F.jsx)(D,{className:`h-4 w-4`})}),nativeButton:!0}),(0,F.jsx)(i,{children:`Download request`})]}),(0,F.jsxs)(r,{children:[(0,F.jsx)(n,{render:(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:_,className:`h-8 w-8 p-0`,children:(0,F.jsx)(g,{className:`h-4 w-4`})}),nativeButton:!0}),(0,F.jsx)(i,{children:`Fullscreen`})]}),(0,F.jsx)(c,{variant:`ghost`,size:`sm`,onClick:u,className:`h-8 w-8 p-0`,children:(0,F.jsx)(b,{className:`h-4 w-4`})})]})]}),(0,F.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-6`,children:[(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:`Message`}),(0,F.jsx)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:t.request.message})]}),P&&`url`in t.request&&(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:`External Action Required`}),(0,F.jsxs)(`div`,{className:`bg-muted rounded-lg p-4 space-y-3`,children:[(0,F.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This request requires you to complete an action at an external URL:`}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2 p-2 bg-background rounded border`,children:[(0,F.jsx)(`code`,{className:`flex-1 text-xs font-mono break-all`,children:t.request.url}),(0,F.jsxs)(c,{size:`sm`,variant:`outline`,onClick:()=>{t&&P&&`url`in t.request&&(window.open(t.request.url,`_blank`),A(!0))},className:`flex items-center gap-2`,children:[(0,F.jsx)(x,{className:`h-4 w-4`}),`Open URL`]})]}),(0,F.jsxs)(`div`,{className:`flex items-center space-x-2 pt-2`,children:[(0,F.jsx)(j,{id:`url-completed`,checked:O,onCheckedChange:e=>A(!!e)}),(0,F.jsx)(l,{htmlFor:`url-completed`,className:`text-sm font-normal cursor-pointer`,children:`I have completed the required action`})]})]})]}),N&&(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`h4`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:`Form Data`}),(0,F.jsx)(L,{request:t,formData:y,onFieldChange:C,idPrefix:`field`,testIdPrefix:`elicitation-field`,emptyFallback:(0,F.jsx)(`div`,{className:`text-sm text-gray-500 dark:text-gray-400`,children:`No form schema available`})})]}),N&&`requestedSchema`in t.request&&t.request.requestedSchema&&(0,F.jsxs)(`details`,{className:`space-y-2`,children:[(0,F.jsx)(`summary`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100 cursor-pointer`,children:`Schema (for reference)`}),(0,F.jsx)(`div`,{className:`bg-muted rounded-lg p-3 max-h-64 overflow-auto`,children:(0,F.jsx)(S,{data:t.request.requestedSchema})})]})]}),(0,F.jsxs)(`div`,{className:`flex gap-2 p-4 border-t dark:border-zinc-700`,children:[(0,F.jsx)(c,{onClick:()=>{if(t){if(N){let e=w();if(e.length>0){E.error(`Missing required fields`,{description:`Please fill in: ${e.join(`, `)}`});return}o(t.id,{action:`accept`,content:y})}else P&&o(t.id,{action:`accept`});u(),T(()=>import(`./react-CU_d2d5K.js`).then(t=>e(t.t(),1)).then(e=>{let t=E(e.createElement(`div`,{className:`space-y-3`},e.createElement(`div`,null,e.createElement(`strong`,null,`Elicitation Response Sent`),e.createElement(`p`,{className:`text-sm text-muted-foreground mt-1`},`The tool will continue executing.`)),e.createElement(`div`,{className:`flex gap-2`},e.createElement(`button`,{"data-testid":`elicitation-view-tool-result`,className:`px-3 py-1.5 text-xs font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90`,onClick:()=>{let e=new globalThis.CustomEvent(`navigate-to-tool-result`,{detail:{toolName:null}});window.dispatchEvent(e),E.dismiss(t)}},`View Tool Result`))),{duration:5e3})}),[])}},className:`flex-1`,disabled:P&&!O,"data-testid":`elicitation-accept-button`,children:`Accept`}),(0,F.jsx)(c,{onClick:()=>{t&&(o(t.id,{action:`decline`}),u())},variant:`outline`,className:`flex-1`,"data-testid":`elicitation-decline-button`,children:`Decline`}),(0,F.jsx)(c,{onClick:()=>{t&&(s(t.id,`User cancelled elicitation request`),u())},variant:`outline`,className:`flex-1`,"data-testid":`elicitation-cancel-button`,children:`Cancel`})]})]}):(0,F.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 text-center`,children:(0,F.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:`Select an elicitation request to view details`})})}function B({pendingRequests:e=[],onApprove:t,onReject:n,serverId:r,isConnected:i}){let{selectedElicitationRequestId:a,setSelectedElicitationRequestId:o}=_(),[s,c]=(0,P.useState)(null),[l,m]=(0,P.useState)(``),[g,v]=(0,P.useState)(-1),[y,x]=(0,P.useState)(!0),[S,T]=(0,P.useState)(!1),[E,D]=(0,P.useState)(!0),[k,A]=(0,P.useState)(!1),j=(0,P.useRef)(null),M=(0,P.useRef)(null),N=(0,P.useRef)(null),L=(0,P.useRef)(!1);(0,P.useEffect)(()=>{if(console.log(`[ElicitationTab] Auto-selection check:`,{selectedElicitationRequestId:a,pendingRequestsCount:e.length,currentSelectedId:s?.id}),a&&e.length>0){let t=e.find(e=>e.id===a);console.log(`[ElicitationTab] Found request for auto-selection:`,!!t,t?.id),t&&(console.log(`[ElicitationTab] Auto-selecting request:`,t.id),o(null),c(t),setTimeout(()=>{let e=document.getElementById(`elicitation-request-${t.id}`);console.log(`[ElicitationTab] Scrolling to element:`,!!e),e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})},100))}},[a,e,o]),(0,P.useEffect)(()=>{let t=t=>{let n=t.detail.requestId;console.log(`[ElicitationTab] Custom navigate event received:`,n);let r=e.find(e=>e.id===n);r&&(console.log(`[ElicitationTab] Selecting request from event:`,n),c(r),setTimeout(()=>{let e=document.getElementById(`elicitation-request-${n}`);e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})},200))};return window.addEventListener(`navigate-to-elicitation`,t),()=>window.removeEventListener(`navigate-to-elicitation`,t)},[e]),(0,P.useEffect)(()=>{y&&e.length>0&&j.current&&!L.current&&(j.current.scrollTop=0)},[e.length,y]),(0,P.useEffect)(()=>{let e=j.current;if(!e)return;let t=()=>{e.scrollTop>0&&(L.current=!0,x(!1))};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[]),(0,P.useEffect)(()=>{e.length===0&&(L.current=!1,x(!0))},[e.length]),(0,P.useEffect)(()=>{S&&N.current&&N.current.focus()},[S]);let R=(0,P.useCallback)(()=>{l.trim()||T(!1)},[l]),B=(0,P.useMemo)(()=>{if(!l.trim())return e;let t=l.toLowerCase();return e.filter(e=>e.serverName.toLowerCase().includes(t)||e.request.message.toLowerCase().includes(t)||JSON.stringify(e.request||{}).toLowerCase().includes(t))},[e,l]);(0,P.useEffect)(()=>{v(-1)},[l]),(0,P.useEffect)(()=>{let e=e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.contentEditable===`true`||e.metaKey||e.ctrlKey||e.altKey)return;let n=B;if(e.key===`ArrowDown`)e.preventDefault(),v(e=>{let t=e+1;return t>=n.length?0:t});else if(e.key===`ArrowUp`)e.preventDefault(),v(e=>{let t=e-1;return t<0?n.length-1:t});else if(e.key===`Enter`&&g>=0){e.preventDefault();let t=B[g];t&&V(t)}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[g,B]),(0,P.useEffect)(()=>{if(g>=0){let e=`elicitation-request-${B[g]?.id}`,t=document.getElementById(e);t&&t.scrollIntoView({behavior:`smooth`,block:`nearest`})}},[g,B]);let V=(0,P.useCallback)(e=>{c(e)},[]),H=(0,P.useCallback)(()=>{window.confirm(`Are you sure you want to cancel all elicitation requests? This cannot be undone.`)&&(e.forEach(e=>{n(e.id,`User cancelled all requests`)}),c(null))},[e,n]),U=(0,P.useCallback)(async()=>{if(s)try{await C(JSON.stringify({id:s.id,serverName:s.serverName,timestamp:s.timestamp,request:s.request},null,2)),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){console.error(`[ElicitationTab] Failed to copy request:`,e)}},[s]),W=(0,P.useCallback)(()=>{if(s)try{let e=new globalThis.Blob([JSON.stringify({id:s.id,serverName:s.serverName,timestamp:s.timestamp,request:s.request},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`elicitation-request-${Date.now()}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)}catch(e){console.error(`[ElicitationTab] Failed to download request:`,e)}},[s]),G=(0,P.useCallback)(async()=>{if(M.current)try{document.fullscreenElement?await document.exitFullscreen():await M.current.requestFullscreen()}catch(e){console.error(`[ElicitationTab] Failed to toggle fullscreen:`,e)}},[]);return i?(0,F.jsxs)(p,{orientation:`horizontal`,className:`h-full`,children:[(0,F.jsx)(u,{defaultSize:40,minSize:30,children:(0,F.jsx)(p,{orientation:`vertical`,className:`h-full border-r dark:border-zinc-700`,children:(0,F.jsx)(u,{defaultSize:75,minSize:30,className:`h-full overflow-hidden`,children:(0,F.jsx)(f,{scrollRef:j,children:t=>(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(h,{isScrolled:t,title:`Elicitation`,icon:w,titleTestId:`elicitation-tab-header`,count:B.length,isSearchExpanded:S,searchQuery:l,searchPlaceholder:`Search requests...`,onSearchExpand:()=>T(!0),onSearchChange:m,onSearchBlur:R,bulkAction:{icon:b,label:`Cancel all`,onClick:H,disabled:e.length===0},searchInputRef:N}),(0,F.jsx)(I,{requests:B,selectedRequest:s,onRequestSelect:V,focusedIndex:g,formatRelativeTime:O})]})})})})}),(0,F.jsx)(d,{}),(0,F.jsx)(u,{defaultSize:60,minSize:40,children:(0,F.jsx)(`div`,{ref:M,className:`h-full bg-white dark:bg-zinc-900`,children:(0,F.jsx)(z,{request:s,onApprove:t,onReject:n,onClose:()=>c(null),previewMode:E,onTogglePreview:()=>D(!E),isCopied:k,onCopy:U,onDownload:W,onFullscreen:G})})})]}):(0,F.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 text-center`,children:[(0,F.jsx)(w,{className:`h-12 w-12 text-gray-400 dark:text-gray-600 mb-3`}),(0,F.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:`Not connected to server`})]})}export{B as ElicitationTab};